
(FPCore (x y z) :precision binary64 (+ 1.0 (/ (* 4.0 (- (+ x (* y 0.25)) z)) y)))
double code(double x, double y, double z) {
return 1.0 + ((4.0 * ((x + (y * 0.25)) - 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.25d0)) - z)) / y)
end function
public static double code(double x, double y, double z) {
return 1.0 + ((4.0 * ((x + (y * 0.25)) - z)) / y);
}
def code(x, y, z): return 1.0 + ((4.0 * ((x + (y * 0.25)) - z)) / y)
function code(x, y, z) return Float64(1.0 + Float64(Float64(4.0 * Float64(Float64(x + Float64(y * 0.25)) - z)) / y)) end
function tmp = code(x, y, z) tmp = 1.0 + ((4.0 * ((x + (y * 0.25)) - z)) / y); end
code[x_, y_, z_] := N[(1.0 + N[(N[(4.0 * N[(N[(x + N[(y * 0.25), $MachinePrecision]), $MachinePrecision] - z), $MachinePrecision]), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
1 + \frac{4 \cdot \left(\left(x + y \cdot 0.25\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.25)) z)) y)))
double code(double x, double y, double z) {
return 1.0 + ((4.0 * ((x + (y * 0.25)) - 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.25d0)) - z)) / y)
end function
public static double code(double x, double y, double z) {
return 1.0 + ((4.0 * ((x + (y * 0.25)) - z)) / y);
}
def code(x, y, z): return 1.0 + ((4.0 * ((x + (y * 0.25)) - z)) / y)
function code(x, y, z) return Float64(1.0 + Float64(Float64(4.0 * Float64(Float64(x + Float64(y * 0.25)) - z)) / y)) end
function tmp = code(x, y, z) tmp = 1.0 + ((4.0 * ((x + (y * 0.25)) - z)) / y); end
code[x_, y_, z_] := N[(1.0 + N[(N[(4.0 * N[(N[(x + N[(y * 0.25), $MachinePrecision]), $MachinePrecision] - z), $MachinePrecision]), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
1 + \frac{4 \cdot \left(\left(x + y \cdot 0.25\right) - z\right)}{y}
\end{array}
(FPCore (x y z) :precision binary64 (+ (* 4.0 (/ (- x z) y)) 2.0))
double code(double x, double y, double z) {
return (4.0 * ((x - z) / y)) + 2.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 * ((x - z) / y)) + 2.0d0
end function
public static double code(double x, double y, double z) {
return (4.0 * ((x - z) / y)) + 2.0;
}
def code(x, y, z): return (4.0 * ((x - z) / y)) + 2.0
function code(x, y, z) return Float64(Float64(4.0 * Float64(Float64(x - z) / y)) + 2.0) end
function tmp = code(x, y, z) tmp = (4.0 * ((x - z) / y)) + 2.0; end
code[x_, y_, z_] := N[(N[(4.0 * N[(N[(x - z), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision] + 2.0), $MachinePrecision]
\begin{array}{l}
\\
4 \cdot \frac{x - z}{y} + 2
\end{array}
Initial program 100.0%
associate-/l*99.8%
associate--l+99.8%
Simplified99.8%
Taylor expanded in y around 0 100.0%
+-commutative100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x y z) :precision binary64 (if (or (<= x -2.5e+32) (not (<= x 2.8e+105))) (+ 2.0 (* 4.0 (/ x y))) (+ 2.0 (* z (/ -4.0 y)))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -2.5e+32) || !(x <= 2.8e+105)) {
tmp = 2.0 + (4.0 * (x / y));
} else {
tmp = 2.0 + (z * (-4.0 / 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 ((x <= (-2.5d+32)) .or. (.not. (x <= 2.8d+105))) then
tmp = 2.0d0 + (4.0d0 * (x / y))
else
tmp = 2.0d0 + (z * ((-4.0d0) / y))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -2.5e+32) || !(x <= 2.8e+105)) {
tmp = 2.0 + (4.0 * (x / y));
} else {
tmp = 2.0 + (z * (-4.0 / y));
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -2.5e+32) or not (x <= 2.8e+105): tmp = 2.0 + (4.0 * (x / y)) else: tmp = 2.0 + (z * (-4.0 / y)) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -2.5e+32) || !(x <= 2.8e+105)) tmp = Float64(2.0 + Float64(4.0 * Float64(x / y))); else tmp = Float64(2.0 + Float64(z * Float64(-4.0 / y))); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -2.5e+32) || ~((x <= 2.8e+105))) tmp = 2.0 + (4.0 * (x / y)); else tmp = 2.0 + (z * (-4.0 / y)); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -2.5e+32], N[Not[LessEqual[x, 2.8e+105]], $MachinePrecision]], N[(2.0 + N[(4.0 * N[(x / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(2.0 + N[(z * N[(-4.0 / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.5 \cdot 10^{+32} \lor \neg \left(x \leq 2.8 \cdot 10^{+105}\right):\\
\;\;\;\;2 + 4 \cdot \frac{x}{y}\\
\mathbf{else}:\\
\;\;\;\;2 + z \cdot \frac{-4}{y}\\
\end{array}
\end{array}
if x < -2.4999999999999999e32 or 2.8000000000000001e105 < x Initial program 100.0%
associate-*l/99.8%
+-commutative99.8%
associate--l+99.8%
distribute-lft-in99.8%
associate-+r+99.8%
*-commutative99.8%
+-commutative99.8%
fma-def99.8%
*-commutative99.8%
associate-*l*99.8%
associate-*r/99.8%
metadata-eval99.8%
rgt-mult-inverse99.8%
metadata-eval99.8%
Simplified99.8%
Taylor expanded in z around 0 82.8%
+-commutative82.8%
Simplified82.8%
if -2.4999999999999999e32 < x < 2.8000000000000001e105Initial program 99.9%
associate-/l*99.8%
associate--l+99.8%
Simplified99.8%
Taylor expanded in y around 0 100.0%
+-commutative100.0%
Simplified100.0%
Taylor expanded in x around 0 90.6%
associate-*r/90.6%
associate-*l/90.5%
metadata-eval90.5%
associate-/r*90.5%
neg-mul-190.5%
*-commutative90.5%
neg-mul-190.5%
associate-/r*90.5%
metadata-eval90.5%
Simplified90.5%
Final simplification87.4%
(FPCore (x y z) :precision binary64 (if (or (<= x -1.9e+29) (not (<= x 2.9e+105))) (+ 2.0 (* 4.0 (/ x y))) (+ 2.0 (* (/ z y) -4.0))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1.9e+29) || !(x <= 2.9e+105)) {
tmp = 2.0 + (4.0 * (x / y));
} else {
tmp = 2.0 + ((z / y) * -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 ((x <= (-1.9d+29)) .or. (.not. (x <= 2.9d+105))) then
tmp = 2.0d0 + (4.0d0 * (x / y))
else
tmp = 2.0d0 + ((z / y) * (-4.0d0))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -1.9e+29) || !(x <= 2.9e+105)) {
tmp = 2.0 + (4.0 * (x / y));
} else {
tmp = 2.0 + ((z / y) * -4.0);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -1.9e+29) or not (x <= 2.9e+105): tmp = 2.0 + (4.0 * (x / y)) else: tmp = 2.0 + ((z / y) * -4.0) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -1.9e+29) || !(x <= 2.9e+105)) tmp = Float64(2.0 + Float64(4.0 * Float64(x / y))); else tmp = Float64(2.0 + Float64(Float64(z / y) * -4.0)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -1.9e+29) || ~((x <= 2.9e+105))) tmp = 2.0 + (4.0 * (x / y)); else tmp = 2.0 + ((z / y) * -4.0); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -1.9e+29], N[Not[LessEqual[x, 2.9e+105]], $MachinePrecision]], N[(2.0 + N[(4.0 * N[(x / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(2.0 + N[(N[(z / y), $MachinePrecision] * -4.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.9 \cdot 10^{+29} \lor \neg \left(x \leq 2.9 \cdot 10^{+105}\right):\\
\;\;\;\;2 + 4 \cdot \frac{x}{y}\\
\mathbf{else}:\\
\;\;\;\;2 + \frac{z}{y} \cdot -4\\
\end{array}
\end{array}
if x < -1.89999999999999985e29 or 2.9000000000000001e105 < x Initial program 100.0%
associate-*l/99.8%
+-commutative99.8%
associate--l+99.8%
distribute-lft-in99.8%
associate-+r+99.8%
*-commutative99.8%
+-commutative99.8%
fma-def99.8%
*-commutative99.8%
associate-*l*99.8%
associate-*r/99.8%
metadata-eval99.8%
rgt-mult-inverse99.8%
metadata-eval99.8%
Simplified99.8%
Taylor expanded in z around 0 82.8%
+-commutative82.8%
Simplified82.8%
if -1.89999999999999985e29 < x < 2.9000000000000001e105Initial program 99.9%
associate-*l/99.8%
+-commutative99.8%
associate--l+99.8%
distribute-lft-in99.8%
associate-+r+99.8%
*-commutative99.8%
+-commutative99.8%
fma-def99.9%
*-commutative99.9%
associate-*l*99.9%
associate-*r/99.9%
metadata-eval99.9%
rgt-mult-inverse99.9%
metadata-eval99.9%
Simplified99.9%
Taylor expanded in x around 0 90.6%
+-commutative90.6%
*-commutative90.6%
Simplified90.6%
Final simplification87.4%
(FPCore (x y z) :precision binary64 (if (<= y -9e+64) 2.0 (if (<= y 7.8e+113) (+ 1.0 (/ 4.0 (/ y x))) 2.0)))
double code(double x, double y, double z) {
double tmp;
if (y <= -9e+64) {
tmp = 2.0;
} else if (y <= 7.8e+113) {
tmp = 1.0 + (4.0 / (y / x));
} else {
tmp = 2.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 <= (-9d+64)) then
tmp = 2.0d0
else if (y <= 7.8d+113) then
tmp = 1.0d0 + (4.0d0 / (y / x))
else
tmp = 2.0d0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= -9e+64) {
tmp = 2.0;
} else if (y <= 7.8e+113) {
tmp = 1.0 + (4.0 / (y / x));
} else {
tmp = 2.0;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -9e+64: tmp = 2.0 elif y <= 7.8e+113: tmp = 1.0 + (4.0 / (y / x)) else: tmp = 2.0 return tmp
function code(x, y, z) tmp = 0.0 if (y <= -9e+64) tmp = 2.0; elseif (y <= 7.8e+113) tmp = Float64(1.0 + Float64(4.0 / Float64(y / x))); else tmp = 2.0; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -9e+64) tmp = 2.0; elseif (y <= 7.8e+113) tmp = 1.0 + (4.0 / (y / x)); else tmp = 2.0; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -9e+64], 2.0, If[LessEqual[y, 7.8e+113], N[(1.0 + N[(4.0 / N[(y / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 2.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -9 \cdot 10^{+64}:\\
\;\;\;\;2\\
\mathbf{elif}\;y \leq 7.8 \cdot 10^{+113}:\\
\;\;\;\;1 + \frac{4}{\frac{y}{x}}\\
\mathbf{else}:\\
\;\;\;\;2\\
\end{array}
\end{array}
if y < -8.99999999999999946e64 or 7.80000000000000039e113 < y Initial program 100.0%
associate-/l*99.8%
associate--l+99.8%
Simplified99.8%
Taylor expanded in y around inf 70.9%
if -8.99999999999999946e64 < y < 7.80000000000000039e113Initial program 100.0%
associate-/l*99.8%
associate--l+99.8%
Simplified99.8%
Taylor expanded in x around inf 50.0%
associate-*r/50.0%
associate-/l*49.9%
Simplified49.9%
Final simplification57.7%
(FPCore (x y z) :precision binary64 (+ 2.0 (* 4.0 (/ x y))))
double code(double x, double y, double z) {
return 2.0 + (4.0 * (x / y));
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = 2.0d0 + (4.0d0 * (x / y))
end function
public static double code(double x, double y, double z) {
return 2.0 + (4.0 * (x / y));
}
def code(x, y, z): return 2.0 + (4.0 * (x / y))
function code(x, y, z) return Float64(2.0 + Float64(4.0 * Float64(x / y))) end
function tmp = code(x, y, z) tmp = 2.0 + (4.0 * (x / y)); end
code[x_, y_, z_] := N[(2.0 + N[(4.0 * N[(x / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
2 + 4 \cdot \frac{x}{y}
\end{array}
Initial program 100.0%
associate-*l/99.8%
+-commutative99.8%
associate--l+99.8%
distribute-lft-in99.8%
associate-+r+99.8%
*-commutative99.8%
+-commutative99.8%
fma-def99.8%
*-commutative99.8%
associate-*l*99.8%
associate-*r/99.8%
metadata-eval99.8%
rgt-mult-inverse99.8%
metadata-eval99.8%
Simplified99.8%
Taylor expanded in z around 0 66.9%
+-commutative66.9%
Simplified66.9%
Final simplification66.9%
(FPCore (x y z) :precision binary64 2.0)
double code(double x, double y, double z) {
return 2.0;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = 2.0d0
end function
public static double code(double x, double y, double z) {
return 2.0;
}
def code(x, y, z): return 2.0
function code(x, y, z) return 2.0 end
function tmp = code(x, y, z) tmp = 2.0; end
code[x_, y_, z_] := 2.0
\begin{array}{l}
\\
2
\end{array}
Initial program 100.0%
associate-/l*99.8%
associate--l+99.8%
Simplified99.8%
Taylor expanded in y around inf 34.4%
Final simplification34.4%
herbie shell --seed 2023171
(FPCore (x y z)
:name "Data.Array.Repa.Algorithms.ColorRamp:rampColorHotToCold from repa-algorithms-3.4.0.1, C"
:precision binary64
(+ 1.0 (/ (* 4.0 (- (+ x (* y 0.25)) z)) y)))