
(FPCore (x y z) :precision binary64 (+ 1.0 (/ (* 4.0 (- (+ x (* y 0.75)) z)) y)))
double code(double x, double y, double z) {
return 1.0 + ((4.0 * ((x + (y * 0.75)) - z)) / y);
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = 1.0d0 + ((4.0d0 * ((x + (y * 0.75d0)) - z)) / y)
end function
public static double code(double x, double y, double z) {
return 1.0 + ((4.0 * ((x + (y * 0.75)) - z)) / y);
}
def code(x, y, z): return 1.0 + ((4.0 * ((x + (y * 0.75)) - z)) / y)
function code(x, y, z) return Float64(1.0 + Float64(Float64(4.0 * Float64(Float64(x + Float64(y * 0.75)) - z)) / y)) end
function tmp = code(x, y, z) tmp = 1.0 + ((4.0 * ((x + (y * 0.75)) - z)) / y); end
code[x_, y_, z_] := N[(1.0 + N[(N[(4.0 * N[(N[(x + N[(y * 0.75), $MachinePrecision]), $MachinePrecision] - z), $MachinePrecision]), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
1 + \frac{4 \cdot \left(\left(x + y \cdot 0.75\right) - z\right)}{y}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 6 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (+ 1.0 (/ (* 4.0 (- (+ x (* y 0.75)) z)) y)))
double code(double x, double y, double z) {
return 1.0 + ((4.0 * ((x + (y * 0.75)) - z)) / y);
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = 1.0d0 + ((4.0d0 * ((x + (y * 0.75d0)) - z)) / y)
end function
public static double code(double x, double y, double z) {
return 1.0 + ((4.0 * ((x + (y * 0.75)) - z)) / y);
}
def code(x, y, z): return 1.0 + ((4.0 * ((x + (y * 0.75)) - z)) / y)
function code(x, y, z) return Float64(1.0 + Float64(Float64(4.0 * Float64(Float64(x + Float64(y * 0.75)) - z)) / y)) end
function tmp = code(x, y, z) tmp = 1.0 + ((4.0 * ((x + (y * 0.75)) - z)) / y); end
code[x_, y_, z_] := N[(1.0 + N[(N[(4.0 * N[(N[(x + N[(y * 0.75), $MachinePrecision]), $MachinePrecision] - z), $MachinePrecision]), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
1 + \frac{4 \cdot \left(\left(x + y \cdot 0.75\right) - z\right)}{y}
\end{array}
(FPCore (x y z) :precision binary64 (+ 4.0 (* 4.0 (/ (- x z) y))))
double code(double x, double y, double z) {
return 4.0 + (4.0 * ((x - z) / y));
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = 4.0d0 + (4.0d0 * ((x - z) / y))
end function
public static double code(double x, double y, double z) {
return 4.0 + (4.0 * ((x - z) / y));
}
def code(x, y, z): return 4.0 + (4.0 * ((x - z) / y))
function code(x, y, z) return Float64(4.0 + Float64(4.0 * Float64(Float64(x - z) / y))) end
function tmp = code(x, y, z) tmp = 4.0 + (4.0 * ((x - z) / y)); end
code[x_, y_, z_] := N[(4.0 + N[(4.0 * N[(N[(x - z), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
4 + 4 \cdot \frac{x - z}{y}
\end{array}
Initial program 99.2%
associate-/l*100.0%
associate--l+100.0%
Simplified100.0%
Taylor expanded in y around inf 100.0%
*-commutative100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (/ (* z -4.0) y)) (t_1 (* 4.0 (/ x y))))
(if (<= y -2.3e+43)
4.0
(if (<= y -6e-183)
t_1
(if (<= y 2.4e-291)
t_0
(if (<= y 2.65e-42) t_1 (if (<= y 0.0145) t_0 4.0)))))))
double code(double x, double y, double z) {
double t_0 = (z * -4.0) / y;
double t_1 = 4.0 * (x / y);
double tmp;
if (y <= -2.3e+43) {
tmp = 4.0;
} else if (y <= -6e-183) {
tmp = t_1;
} else if (y <= 2.4e-291) {
tmp = t_0;
} else if (y <= 2.65e-42) {
tmp = t_1;
} else if (y <= 0.0145) {
tmp = t_0;
} else {
tmp = 4.0;
}
return tmp;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: t_0
real(8) :: t_1
real(8) :: tmp
t_0 = (z * (-4.0d0)) / y
t_1 = 4.0d0 * (x / y)
if (y <= (-2.3d+43)) then
tmp = 4.0d0
else if (y <= (-6d-183)) then
tmp = t_1
else if (y <= 2.4d-291) then
tmp = t_0
else if (y <= 2.65d-42) then
tmp = t_1
else if (y <= 0.0145d0) then
tmp = t_0
else
tmp = 4.0d0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = (z * -4.0) / y;
double t_1 = 4.0 * (x / y);
double tmp;
if (y <= -2.3e+43) {
tmp = 4.0;
} else if (y <= -6e-183) {
tmp = t_1;
} else if (y <= 2.4e-291) {
tmp = t_0;
} else if (y <= 2.65e-42) {
tmp = t_1;
} else if (y <= 0.0145) {
tmp = t_0;
} else {
tmp = 4.0;
}
return tmp;
}
def code(x, y, z): t_0 = (z * -4.0) / y t_1 = 4.0 * (x / y) tmp = 0 if y <= -2.3e+43: tmp = 4.0 elif y <= -6e-183: tmp = t_1 elif y <= 2.4e-291: tmp = t_0 elif y <= 2.65e-42: tmp = t_1 elif y <= 0.0145: tmp = t_0 else: tmp = 4.0 return tmp
function code(x, y, z) t_0 = Float64(Float64(z * -4.0) / y) t_1 = Float64(4.0 * Float64(x / y)) tmp = 0.0 if (y <= -2.3e+43) tmp = 4.0; elseif (y <= -6e-183) tmp = t_1; elseif (y <= 2.4e-291) tmp = t_0; elseif (y <= 2.65e-42) tmp = t_1; elseif (y <= 0.0145) tmp = t_0; else tmp = 4.0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = (z * -4.0) / y; t_1 = 4.0 * (x / y); tmp = 0.0; if (y <= -2.3e+43) tmp = 4.0; elseif (y <= -6e-183) tmp = t_1; elseif (y <= 2.4e-291) tmp = t_0; elseif (y <= 2.65e-42) tmp = t_1; elseif (y <= 0.0145) tmp = t_0; else tmp = 4.0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(z * -4.0), $MachinePrecision] / y), $MachinePrecision]}, Block[{t$95$1 = N[(4.0 * N[(x / y), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -2.3e+43], 4.0, If[LessEqual[y, -6e-183], t$95$1, If[LessEqual[y, 2.4e-291], t$95$0, If[LessEqual[y, 2.65e-42], t$95$1, If[LessEqual[y, 0.0145], t$95$0, 4.0]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{z \cdot -4}{y}\\
t_1 := 4 \cdot \frac{x}{y}\\
\mathbf{if}\;y \leq -2.3 \cdot 10^{+43}:\\
\;\;\;\;4\\
\mathbf{elif}\;y \leq -6 \cdot 10^{-183}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;y \leq 2.4 \cdot 10^{-291}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 2.65 \cdot 10^{-42}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;y \leq 0.0145:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;4\\
\end{array}
\end{array}
if y < -2.3000000000000002e43 or 0.0145000000000000007 < y Initial program 98.2%
associate-/l*100.0%
associate--l+100.0%
Simplified100.0%
Taylor expanded in y around inf 68.6%
if -2.3000000000000002e43 < y < -5.9999999999999996e-183 or 2.40000000000000012e-291 < y < 2.65e-42Initial program 100.0%
associate-/l*100.0%
associate--l+100.0%
Simplified100.0%
Taylor expanded in x around inf 61.0%
*-commutative61.0%
Simplified61.0%
if -5.9999999999999996e-183 < y < 2.40000000000000012e-291 or 2.65e-42 < y < 0.0145000000000000007Initial program 100.0%
associate-/l*100.0%
associate--l+100.0%
Simplified100.0%
Taylor expanded in z around inf 75.8%
*-commutative75.8%
associate-*l/75.8%
Simplified75.8%
Final simplification66.8%
(FPCore (x y z) :precision binary64 (if (or (<= y -2.95e-15) (not (<= y 0.48))) (+ 4.0 (* 4.0 (/ x y))) (* 4.0 (/ (- x z) y))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -2.95e-15) || !(y <= 0.48)) {
tmp = 4.0 + (4.0 * (x / y));
} else {
tmp = 4.0 * ((x - z) / y);
}
return tmp;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: tmp
if ((y <= (-2.95d-15)) .or. (.not. (y <= 0.48d0))) then
tmp = 4.0d0 + (4.0d0 * (x / y))
else
tmp = 4.0d0 * ((x - z) / y)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -2.95e-15) || !(y <= 0.48)) {
tmp = 4.0 + (4.0 * (x / y));
} else {
tmp = 4.0 * ((x - z) / y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -2.95e-15) or not (y <= 0.48): tmp = 4.0 + (4.0 * (x / y)) else: tmp = 4.0 * ((x - z) / y) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -2.95e-15) || !(y <= 0.48)) tmp = Float64(4.0 + Float64(4.0 * Float64(x / y))); else tmp = Float64(4.0 * Float64(Float64(x - z) / y)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -2.95e-15) || ~((y <= 0.48))) tmp = 4.0 + (4.0 * (x / y)); else tmp = 4.0 * ((x - z) / y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -2.95e-15], N[Not[LessEqual[y, 0.48]], $MachinePrecision]], N[(4.0 + N[(4.0 * N[(x / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(4.0 * N[(N[(x - z), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.95 \cdot 10^{-15} \lor \neg \left(y \leq 0.48\right):\\
\;\;\;\;4 + 4 \cdot \frac{x}{y}\\
\mathbf{else}:\\
\;\;\;\;4 \cdot \frac{x - z}{y}\\
\end{array}
\end{array}
if y < -2.94999999999999982e-15 or 0.47999999999999998 < y Initial program 98.4%
associate-/l*99.9%
associate--l+99.9%
Simplified99.9%
Taylor expanded in y around inf 100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in x around inf 89.0%
if -2.94999999999999982e-15 < y < 0.47999999999999998Initial program 100.0%
associate-/l*100.0%
associate--l+100.0%
Simplified100.0%
Taylor expanded in y around 0 95.2%
*-commutative95.2%
Simplified95.2%
Final simplification92.3%
(FPCore (x y z) :precision binary64 (if (<= y -5.4e+79) 4.0 (if (<= y 1.2e+89) (* 4.0 (/ (- x z) y)) 4.0)))
double code(double x, double y, double z) {
double tmp;
if (y <= -5.4e+79) {
tmp = 4.0;
} else if (y <= 1.2e+89) {
tmp = 4.0 * ((x - z) / y);
} else {
tmp = 4.0;
}
return tmp;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: tmp
if (y <= (-5.4d+79)) then
tmp = 4.0d0
else if (y <= 1.2d+89) then
tmp = 4.0d0 * ((x - z) / y)
else
tmp = 4.0d0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= -5.4e+79) {
tmp = 4.0;
} else if (y <= 1.2e+89) {
tmp = 4.0 * ((x - z) / y);
} else {
tmp = 4.0;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -5.4e+79: tmp = 4.0 elif y <= 1.2e+89: tmp = 4.0 * ((x - z) / y) else: tmp = 4.0 return tmp
function code(x, y, z) tmp = 0.0 if (y <= -5.4e+79) tmp = 4.0; elseif (y <= 1.2e+89) tmp = Float64(4.0 * Float64(Float64(x - z) / y)); else tmp = 4.0; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -5.4e+79) tmp = 4.0; elseif (y <= 1.2e+89) tmp = 4.0 * ((x - z) / y); else tmp = 4.0; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -5.4e+79], 4.0, If[LessEqual[y, 1.2e+89], N[(4.0 * N[(N[(x - z), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision], 4.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -5.4 \cdot 10^{+79}:\\
\;\;\;\;4\\
\mathbf{elif}\;y \leq 1.2 \cdot 10^{+89}:\\
\;\;\;\;4 \cdot \frac{x - z}{y}\\
\mathbf{else}:\\
\;\;\;\;4\\
\end{array}
\end{array}
if y < -5.3999999999999999e79 or 1.20000000000000002e89 < y Initial program 98.8%
associate-/l*99.9%
associate--l+99.9%
Simplified99.9%
Taylor expanded in y around inf 75.3%
if -5.3999999999999999e79 < y < 1.20000000000000002e89Initial program 99.4%
associate-/l*100.0%
associate--l+100.0%
Simplified100.0%
Taylor expanded in y around 0 88.3%
*-commutative88.3%
Simplified88.3%
Final simplification83.9%
(FPCore (x y z) :precision binary64 (if (<= y -2.5e+43) 4.0 (if (<= y 2.9e+88) (* 4.0 (/ x y)) 4.0)))
double code(double x, double y, double z) {
double tmp;
if (y <= -2.5e+43) {
tmp = 4.0;
} else if (y <= 2.9e+88) {
tmp = 4.0 * (x / y);
} else {
tmp = 4.0;
}
return tmp;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: tmp
if (y <= (-2.5d+43)) then
tmp = 4.0d0
else if (y <= 2.9d+88) then
tmp = 4.0d0 * (x / y)
else
tmp = 4.0d0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= -2.5e+43) {
tmp = 4.0;
} else if (y <= 2.9e+88) {
tmp = 4.0 * (x / y);
} else {
tmp = 4.0;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -2.5e+43: tmp = 4.0 elif y <= 2.9e+88: tmp = 4.0 * (x / y) else: tmp = 4.0 return tmp
function code(x, y, z) tmp = 0.0 if (y <= -2.5e+43) tmp = 4.0; elseif (y <= 2.9e+88) tmp = Float64(4.0 * Float64(x / y)); else tmp = 4.0; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -2.5e+43) tmp = 4.0; elseif (y <= 2.9e+88) tmp = 4.0 * (x / y); else tmp = 4.0; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -2.5e+43], 4.0, If[LessEqual[y, 2.9e+88], N[(4.0 * N[(x / y), $MachinePrecision]), $MachinePrecision], 4.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.5 \cdot 10^{+43}:\\
\;\;\;\;4\\
\mathbf{elif}\;y \leq 2.9 \cdot 10^{+88}:\\
\;\;\;\;4 \cdot \frac{x}{y}\\
\mathbf{else}:\\
\;\;\;\;4\\
\end{array}
\end{array}
if y < -2.5000000000000002e43 or 2.9e88 < y Initial program 98.9%
associate-/l*100.0%
associate--l+100.0%
Simplified100.0%
Taylor expanded in y around inf 73.0%
if -2.5000000000000002e43 < y < 2.9e88Initial program 99.4%
associate-/l*100.0%
associate--l+100.0%
Simplified100.0%
Taylor expanded in x around inf 51.6%
*-commutative51.6%
Simplified51.6%
Final simplification59.5%
(FPCore (x y z) :precision binary64 4.0)
double code(double x, double y, double z) {
return 4.0;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = 4.0d0
end function
public static double code(double x, double y, double z) {
return 4.0;
}
def code(x, y, z): return 4.0
function code(x, y, z) return 4.0 end
function tmp = code(x, y, z) tmp = 4.0; end
code[x_, y_, z_] := 4.0
\begin{array}{l}
\\
4
\end{array}
Initial program 99.2%
associate-/l*100.0%
associate--l+100.0%
Simplified100.0%
Taylor expanded in y around inf 34.4%
herbie shell --seed 2024111
(FPCore (x y z)
:name "Data.Array.Repa.Algorithms.ColorRamp:rampColorHotToCold from repa-algorithms-3.4.0.1, A"
:precision binary64
(+ 1.0 (/ (* 4.0 (- (+ x (* y 0.75)) z)) y)))