
(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 (+ (/ (- x z) (* y 0.25)) 2.0))
double code(double x, double y, double z) {
return ((x - z) / (y * 0.25)) + 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 = ((x - z) / (y * 0.25d0)) + 2.0d0
end function
public static double code(double x, double y, double z) {
return ((x - z) / (y * 0.25)) + 2.0;
}
def code(x, y, z): return ((x - z) / (y * 0.25)) + 2.0
function code(x, y, z) return Float64(Float64(Float64(x - z) / Float64(y * 0.25)) + 2.0) end
function tmp = code(x, y, z) tmp = ((x - z) / (y * 0.25)) + 2.0; end
code[x_, y_, z_] := N[(N[(N[(x - z), $MachinePrecision] / N[(y * 0.25), $MachinePrecision]), $MachinePrecision] + 2.0), $MachinePrecision]
\begin{array}{l}
\\
\frac{x - z}{y \cdot 0.25} + 2
\end{array}
Initial program 99.2%
+-commutative99.2%
associate-*l/99.8%
+-commutative99.8%
associate--l+99.8%
+-commutative99.8%
distribute-lft-in99.8%
associate-+l+99.8%
associate-*l/99.8%
*-commutative99.8%
associate-*l*99.8%
metadata-eval99.8%
*-rgt-identity99.8%
*-inverses99.8%
metadata-eval99.8%
Simplified99.8%
clear-num99.8%
div-inv99.8%
metadata-eval99.8%
associate-*l/100.0%
*-un-lft-identity100.0%
Applied egg-rr100.0%
Final simplification100.0%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (+ 1.0 (* (/ z y) -4.0))) (t_1 (+ 1.0 (/ (* x 4.0) y))))
(if (<= x -2.5e+23)
t_1
(if (<= x -1.55e-73)
t_0
(if (<= x -3.85e-205) 2.0 (if (<= x 2.8e-37) t_0 t_1))))))
double code(double x, double y, double z) {
double t_0 = 1.0 + ((z / y) * -4.0);
double t_1 = 1.0 + ((x * 4.0) / y);
double tmp;
if (x <= -2.5e+23) {
tmp = t_1;
} else if (x <= -1.55e-73) {
tmp = t_0;
} else if (x <= -3.85e-205) {
tmp = 2.0;
} else if (x <= 2.8e-37) {
tmp = t_0;
} else {
tmp = t_1;
}
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 = 1.0d0 + ((z / y) * (-4.0d0))
t_1 = 1.0d0 + ((x * 4.0d0) / y)
if (x <= (-2.5d+23)) then
tmp = t_1
else if (x <= (-1.55d-73)) then
tmp = t_0
else if (x <= (-3.85d-205)) then
tmp = 2.0d0
else if (x <= 2.8d-37) then
tmp = t_0
else
tmp = t_1
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = 1.0 + ((z / y) * -4.0);
double t_1 = 1.0 + ((x * 4.0) / y);
double tmp;
if (x <= -2.5e+23) {
tmp = t_1;
} else if (x <= -1.55e-73) {
tmp = t_0;
} else if (x <= -3.85e-205) {
tmp = 2.0;
} else if (x <= 2.8e-37) {
tmp = t_0;
} else {
tmp = t_1;
}
return tmp;
}
def code(x, y, z): t_0 = 1.0 + ((z / y) * -4.0) t_1 = 1.0 + ((x * 4.0) / y) tmp = 0 if x <= -2.5e+23: tmp = t_1 elif x <= -1.55e-73: tmp = t_0 elif x <= -3.85e-205: tmp = 2.0 elif x <= 2.8e-37: tmp = t_0 else: tmp = t_1 return tmp
function code(x, y, z) t_0 = Float64(1.0 + Float64(Float64(z / y) * -4.0)) t_1 = Float64(1.0 + Float64(Float64(x * 4.0) / y)) tmp = 0.0 if (x <= -2.5e+23) tmp = t_1; elseif (x <= -1.55e-73) tmp = t_0; elseif (x <= -3.85e-205) tmp = 2.0; elseif (x <= 2.8e-37) tmp = t_0; else tmp = t_1; end return tmp end
function tmp_2 = code(x, y, z) t_0 = 1.0 + ((z / y) * -4.0); t_1 = 1.0 + ((x * 4.0) / y); tmp = 0.0; if (x <= -2.5e+23) tmp = t_1; elseif (x <= -1.55e-73) tmp = t_0; elseif (x <= -3.85e-205) tmp = 2.0; elseif (x <= 2.8e-37) tmp = t_0; else tmp = t_1; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(1.0 + N[(N[(z / y), $MachinePrecision] * -4.0), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(1.0 + N[(N[(x * 4.0), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, -2.5e+23], t$95$1, If[LessEqual[x, -1.55e-73], t$95$0, If[LessEqual[x, -3.85e-205], 2.0, If[LessEqual[x, 2.8e-37], t$95$0, t$95$1]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := 1 + \frac{z}{y} \cdot -4\\
t_1 := 1 + \frac{x \cdot 4}{y}\\
\mathbf{if}\;x \leq -2.5 \cdot 10^{+23}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;x \leq -1.55 \cdot 10^{-73}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq -3.85 \cdot 10^{-205}:\\
\;\;\;\;2\\
\mathbf{elif}\;x \leq 2.8 \cdot 10^{-37}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if x < -2.5e23 or 2.8000000000000001e-37 < x Initial program 99.3%
Taylor expanded in x around inf 65.6%
if -2.5e23 < x < -1.54999999999999985e-73 or -3.85e-205 < x < 2.8000000000000001e-37Initial program 99.0%
Taylor expanded in z around inf 61.3%
*-commutative61.3%
Simplified61.3%
if -1.54999999999999985e-73 < x < -3.85e-205Initial program 99.9%
Taylor expanded in y around inf 62.3%
Final simplification63.7%
(FPCore (x y z) :precision binary64 (if (<= y -1.52e+78) 2.0 (if (<= y 9.5e+38) (+ 1.0 (* z (/ -4.0 y))) 2.0)))
double code(double x, double y, double z) {
double tmp;
if (y <= -1.52e+78) {
tmp = 2.0;
} else if (y <= 9.5e+38) {
tmp = 1.0 + (z * (-4.0 / y));
} 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 <= (-1.52d+78)) then
tmp = 2.0d0
else if (y <= 9.5d+38) then
tmp = 1.0d0 + (z * ((-4.0d0) / y))
else
tmp = 2.0d0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= -1.52e+78) {
tmp = 2.0;
} else if (y <= 9.5e+38) {
tmp = 1.0 + (z * (-4.0 / y));
} else {
tmp = 2.0;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -1.52e+78: tmp = 2.0 elif y <= 9.5e+38: tmp = 1.0 + (z * (-4.0 / y)) else: tmp = 2.0 return tmp
function code(x, y, z) tmp = 0.0 if (y <= -1.52e+78) tmp = 2.0; elseif (y <= 9.5e+38) tmp = Float64(1.0 + Float64(z * Float64(-4.0 / y))); else tmp = 2.0; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -1.52e+78) tmp = 2.0; elseif (y <= 9.5e+38) tmp = 1.0 + (z * (-4.0 / y)); else tmp = 2.0; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -1.52e+78], 2.0, If[LessEqual[y, 9.5e+38], N[(1.0 + N[(z * N[(-4.0 / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 2.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.52 \cdot 10^{+78}:\\
\;\;\;\;2\\
\mathbf{elif}\;y \leq 9.5 \cdot 10^{+38}:\\
\;\;\;\;1 + z \cdot \frac{-4}{y}\\
\mathbf{else}:\\
\;\;\;\;2\\
\end{array}
\end{array}
if y < -1.52e78 or 9.4999999999999995e38 < y Initial program 98.9%
Taylor expanded in y around inf 70.0%
if -1.52e78 < y < 9.4999999999999995e38Initial program 99.4%
Taylor expanded in z around inf 48.5%
associate-*r/47.9%
metadata-eval47.9%
associate-*r*47.9%
neg-mul-147.9%
associate-*l/48.4%
*-commutative48.4%
distribute-lft-neg-out48.4%
distribute-rgt-neg-in48.4%
distribute-neg-frac48.4%
metadata-eval48.4%
Simplified48.4%
Final simplification56.1%
(FPCore (x y z) :precision binary64 (if (<= y -1.1e+86) 2.0 (if (<= y 8.2e+39) (+ 1.0 (* (/ z y) -4.0)) 2.0)))
double code(double x, double y, double z) {
double tmp;
if (y <= -1.1e+86) {
tmp = 2.0;
} else if (y <= 8.2e+39) {
tmp = 1.0 + ((z / y) * -4.0);
} 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 <= (-1.1d+86)) then
tmp = 2.0d0
else if (y <= 8.2d+39) then
tmp = 1.0d0 + ((z / y) * (-4.0d0))
else
tmp = 2.0d0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= -1.1e+86) {
tmp = 2.0;
} else if (y <= 8.2e+39) {
tmp = 1.0 + ((z / y) * -4.0);
} else {
tmp = 2.0;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -1.1e+86: tmp = 2.0 elif y <= 8.2e+39: tmp = 1.0 + ((z / y) * -4.0) else: tmp = 2.0 return tmp
function code(x, y, z) tmp = 0.0 if (y <= -1.1e+86) tmp = 2.0; elseif (y <= 8.2e+39) tmp = Float64(1.0 + Float64(Float64(z / y) * -4.0)); else tmp = 2.0; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -1.1e+86) tmp = 2.0; elseif (y <= 8.2e+39) tmp = 1.0 + ((z / y) * -4.0); else tmp = 2.0; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -1.1e+86], 2.0, If[LessEqual[y, 8.2e+39], N[(1.0 + N[(N[(z / y), $MachinePrecision] * -4.0), $MachinePrecision]), $MachinePrecision], 2.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.1 \cdot 10^{+86}:\\
\;\;\;\;2\\
\mathbf{elif}\;y \leq 8.2 \cdot 10^{+39}:\\
\;\;\;\;1 + \frac{z}{y} \cdot -4\\
\mathbf{else}:\\
\;\;\;\;2\\
\end{array}
\end{array}
if y < -1.10000000000000002e86 or 8.20000000000000008e39 < y Initial program 98.9%
Taylor expanded in y around inf 70.0%
if -1.10000000000000002e86 < y < 8.20000000000000008e39Initial program 99.4%
Taylor expanded in z around inf 48.5%
*-commutative48.5%
Simplified48.5%
Final simplification56.1%
(FPCore (x y z) :precision binary64 (+ 2.0 (* (- x z) (/ 4.0 y))))
double code(double x, double y, double z) {
return 2.0 + ((x - z) * (4.0 / 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 + ((x - z) * (4.0d0 / y))
end function
public static double code(double x, double y, double z) {
return 2.0 + ((x - z) * (4.0 / y));
}
def code(x, y, z): return 2.0 + ((x - z) * (4.0 / y))
function code(x, y, z) return Float64(2.0 + Float64(Float64(x - z) * Float64(4.0 / y))) end
function tmp = code(x, y, z) tmp = 2.0 + ((x - z) * (4.0 / y)); end
code[x_, y_, z_] := N[(2.0 + N[(N[(x - z), $MachinePrecision] * N[(4.0 / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
2 + \left(x - z\right) \cdot \frac{4}{y}
\end{array}
Initial program 99.2%
+-commutative99.2%
associate-*l/99.8%
+-commutative99.8%
associate--l+99.8%
+-commutative99.8%
distribute-lft-in99.8%
associate-+l+99.8%
associate-*l/99.8%
*-commutative99.8%
associate-*l*99.8%
metadata-eval99.8%
*-rgt-identity99.8%
*-inverses99.8%
metadata-eval99.8%
Simplified99.8%
Final simplification99.8%
(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 99.2%
Taylor expanded in y around inf 32.9%
Final simplification32.9%
herbie shell --seed 2024079
(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)))