
(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 7 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 (+ 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}
Initial program 99.9%
Final simplification99.9%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (+ 1.0 (/ -4.0 (/ y z)))))
(if (<= z -9.1e+51)
t_0
(if (<= z -9.2e-213) (+ 1.0 (/ 4.0 (/ y x))) (if (<= z 5e+80) 4.0 t_0)))))
double code(double x, double y, double z) {
double t_0 = 1.0 + (-4.0 / (y / z));
double tmp;
if (z <= -9.1e+51) {
tmp = t_0;
} else if (z <= -9.2e-213) {
tmp = 1.0 + (4.0 / (y / x));
} else if (z <= 5e+80) {
tmp = 4.0;
} else {
tmp = t_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) :: tmp
t_0 = 1.0d0 + ((-4.0d0) / (y / z))
if (z <= (-9.1d+51)) then
tmp = t_0
else if (z <= (-9.2d-213)) then
tmp = 1.0d0 + (4.0d0 / (y / x))
else if (z <= 5d+80) then
tmp = 4.0d0
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = 1.0 + (-4.0 / (y / z));
double tmp;
if (z <= -9.1e+51) {
tmp = t_0;
} else if (z <= -9.2e-213) {
tmp = 1.0 + (4.0 / (y / x));
} else if (z <= 5e+80) {
tmp = 4.0;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = 1.0 + (-4.0 / (y / z)) tmp = 0 if z <= -9.1e+51: tmp = t_0 elif z <= -9.2e-213: tmp = 1.0 + (4.0 / (y / x)) elif z <= 5e+80: tmp = 4.0 else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(1.0 + Float64(-4.0 / Float64(y / z))) tmp = 0.0 if (z <= -9.1e+51) tmp = t_0; elseif (z <= -9.2e-213) tmp = Float64(1.0 + Float64(4.0 / Float64(y / x))); elseif (z <= 5e+80) tmp = 4.0; else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = 1.0 + (-4.0 / (y / z)); tmp = 0.0; if (z <= -9.1e+51) tmp = t_0; elseif (z <= -9.2e-213) tmp = 1.0 + (4.0 / (y / x)); elseif (z <= 5e+80) tmp = 4.0; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(1.0 + N[(-4.0 / N[(y / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[z, -9.1e+51], t$95$0, If[LessEqual[z, -9.2e-213], N[(1.0 + N[(4.0 / N[(y / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[z, 5e+80], 4.0, t$95$0]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := 1 + \frac{-4}{\frac{y}{z}}\\
\mathbf{if}\;z \leq -9.1 \cdot 10^{+51}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;z \leq -9.2 \cdot 10^{-213}:\\
\;\;\;\;1 + \frac{4}{\frac{y}{x}}\\
\mathbf{elif}\;z \leq 5 \cdot 10^{+80}:\\
\;\;\;\;4\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if z < -9.0999999999999994e51 or 4.99999999999999961e80 < z Initial program 100.0%
Taylor expanded in z around inf 76.6%
associate-*r/76.6%
associate-/l*76.5%
Simplified76.5%
if -9.0999999999999994e51 < z < -9.20000000000000011e-213Initial program 99.9%
Taylor expanded in x around inf 50.8%
associate-*r/50.8%
associate-/l*50.6%
Simplified50.6%
if -9.20000000000000011e-213 < z < 4.99999999999999961e80Initial program 99.9%
Taylor expanded in y around inf 60.5%
Final simplification64.7%
(FPCore (x y z) :precision binary64 (if (or (<= z -1.9e+86) (not (<= z 6e+81))) (+ 1.0 (/ -4.0 (/ y z))) 4.0))
double code(double x, double y, double z) {
double tmp;
if ((z <= -1.9e+86) || !(z <= 6e+81)) {
tmp = 1.0 + (-4.0 / (y / z));
} 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 ((z <= (-1.9d+86)) .or. (.not. (z <= 6d+81))) then
tmp = 1.0d0 + ((-4.0d0) / (y / z))
else
tmp = 4.0d0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -1.9e+86) || !(z <= 6e+81)) {
tmp = 1.0 + (-4.0 / (y / z));
} else {
tmp = 4.0;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -1.9e+86) or not (z <= 6e+81): tmp = 1.0 + (-4.0 / (y / z)) else: tmp = 4.0 return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -1.9e+86) || !(z <= 6e+81)) tmp = Float64(1.0 + Float64(-4.0 / Float64(y / z))); else tmp = 4.0; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -1.9e+86) || ~((z <= 6e+81))) tmp = 1.0 + (-4.0 / (y / z)); else tmp = 4.0; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -1.9e+86], N[Not[LessEqual[z, 6e+81]], $MachinePrecision]], N[(1.0 + N[(-4.0 / N[(y / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 4.0]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.9 \cdot 10^{+86} \lor \neg \left(z \leq 6 \cdot 10^{+81}\right):\\
\;\;\;\;1 + \frac{-4}{\frac{y}{z}}\\
\mathbf{else}:\\
\;\;\;\;4\\
\end{array}
\end{array}
if z < -1.89999999999999989e86 or 5.99999999999999995e81 < z Initial program 100.0%
Taylor expanded in z around inf 80.2%
associate-*r/80.2%
associate-/l*80.1%
Simplified80.1%
if -1.89999999999999989e86 < z < 5.99999999999999995e81Initial program 99.9%
Taylor expanded in y around inf 53.1%
Final simplification63.0%
(FPCore (x y z) :precision binary64 (if (or (<= x -3.1e+36) (not (<= x 5.8e+96))) (+ 1.0 (/ 4.0 (/ y x))) (+ 4.0 (/ (* z -4.0) y))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -3.1e+36) || !(x <= 5.8e+96)) {
tmp = 1.0 + (4.0 / (y / x));
} else {
tmp = 4.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 <= (-3.1d+36)) .or. (.not. (x <= 5.8d+96))) then
tmp = 1.0d0 + (4.0d0 / (y / x))
else
tmp = 4.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 <= -3.1e+36) || !(x <= 5.8e+96)) {
tmp = 1.0 + (4.0 / (y / x));
} else {
tmp = 4.0 + ((z * -4.0) / y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -3.1e+36) or not (x <= 5.8e+96): tmp = 1.0 + (4.0 / (y / x)) else: tmp = 4.0 + ((z * -4.0) / y) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -3.1e+36) || !(x <= 5.8e+96)) tmp = Float64(1.0 + Float64(4.0 / Float64(y / x))); else tmp = Float64(4.0 + Float64(Float64(z * -4.0) / y)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -3.1e+36) || ~((x <= 5.8e+96))) tmp = 1.0 + (4.0 / (y / x)); else tmp = 4.0 + ((z * -4.0) / y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -3.1e+36], N[Not[LessEqual[x, 5.8e+96]], $MachinePrecision]], N[(1.0 + N[(4.0 / N[(y / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(4.0 + N[(N[(z * -4.0), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -3.1 \cdot 10^{+36} \lor \neg \left(x \leq 5.8 \cdot 10^{+96}\right):\\
\;\;\;\;1 + \frac{4}{\frac{y}{x}}\\
\mathbf{else}:\\
\;\;\;\;4 + \frac{z \cdot -4}{y}\\
\end{array}
\end{array}
if x < -3.0999999999999999e36 or 5.79999999999999955e96 < x Initial program 99.9%
Taylor expanded in x around inf 72.3%
associate-*r/72.3%
associate-/l*72.2%
Simplified72.2%
if -3.0999999999999999e36 < x < 5.79999999999999955e96Initial program 99.9%
associate-*l/99.7%
+-commutative99.7%
associate--l+99.7%
distribute-lft-in99.7%
associate-+r+99.7%
*-commutative99.7%
+-commutative99.7%
fma-def99.7%
associate-*r*99.8%
associate-*l/99.9%
associate-/l*99.9%
*-inverses99.9%
metadata-eval99.9%
metadata-eval99.9%
metadata-eval99.9%
Simplified99.9%
Taylor expanded in x around 0 93.0%
associate-*r/93.0%
Simplified93.0%
Final simplification85.5%
(FPCore (x y z) :precision binary64 (if (or (<= x -1e+31) (not (<= x 8e+27))) (+ 4.0 (/ (* 4.0 x) y)) (+ 4.0 (/ (* z -4.0) y))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1e+31) || !(x <= 8e+27)) {
tmp = 4.0 + ((4.0 * x) / y);
} else {
tmp = 4.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 <= (-1d+31)) .or. (.not. (x <= 8d+27))) then
tmp = 4.0d0 + ((4.0d0 * x) / y)
else
tmp = 4.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 <= -1e+31) || !(x <= 8e+27)) {
tmp = 4.0 + ((4.0 * x) / y);
} else {
tmp = 4.0 + ((z * -4.0) / y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -1e+31) or not (x <= 8e+27): tmp = 4.0 + ((4.0 * x) / y) else: tmp = 4.0 + ((z * -4.0) / y) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -1e+31) || !(x <= 8e+27)) tmp = Float64(4.0 + Float64(Float64(4.0 * x) / y)); else tmp = Float64(4.0 + Float64(Float64(z * -4.0) / y)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -1e+31) || ~((x <= 8e+27))) tmp = 4.0 + ((4.0 * x) / y); else tmp = 4.0 + ((z * -4.0) / y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -1e+31], N[Not[LessEqual[x, 8e+27]], $MachinePrecision]], N[(4.0 + N[(N[(4.0 * x), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision], N[(4.0 + N[(N[(z * -4.0), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1 \cdot 10^{+31} \lor \neg \left(x \leq 8 \cdot 10^{+27}\right):\\
\;\;\;\;4 + \frac{4 \cdot x}{y}\\
\mathbf{else}:\\
\;\;\;\;4 + \frac{z \cdot -4}{y}\\
\end{array}
\end{array}
if x < -9.9999999999999996e30 or 8.0000000000000001e27 < x Initial program 99.9%
associate-*l/99.7%
+-commutative99.7%
associate--l+99.7%
distribute-lft-in99.7%
associate-+r+99.7%
*-commutative99.7%
+-commutative99.7%
fma-def99.7%
associate-*r*99.7%
associate-*l/99.8%
associate-/l*99.8%
*-inverses99.8%
metadata-eval99.8%
metadata-eval99.8%
metadata-eval99.8%
Simplified99.8%
Taylor expanded in z around 0 86.6%
associate-*r/86.6%
Simplified86.6%
if -9.9999999999999996e30 < x < 8.0000000000000001e27Initial program 99.9%
associate-*l/99.7%
+-commutative99.7%
associate--l+99.7%
distribute-lft-in99.7%
associate-+r+99.7%
*-commutative99.7%
+-commutative99.7%
fma-def99.7%
associate-*r*99.8%
associate-*l/99.9%
associate-/l*99.9%
*-inverses99.9%
metadata-eval99.9%
metadata-eval99.9%
metadata-eval99.9%
Simplified99.9%
Taylor expanded in x around 0 94.4%
associate-*r/94.4%
Simplified94.4%
Final simplification91.1%
(FPCore (x y z) :precision binary64 (+ 4.0 (* (- x z) (/ 4.0 y))))
double code(double x, double y, double z) {
return 4.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 = 4.0d0 + ((x - z) * (4.0d0 / y))
end function
public static double code(double x, double y, double z) {
return 4.0 + ((x - z) * (4.0 / y));
}
def code(x, y, z): return 4.0 + ((x - z) * (4.0 / y))
function code(x, y, z) return Float64(4.0 + Float64(Float64(x - z) * Float64(4.0 / y))) end
function tmp = code(x, y, z) tmp = 4.0 + ((x - z) * (4.0 / y)); end
code[x_, y_, z_] := N[(4.0 + N[(N[(x - z), $MachinePrecision] * N[(4.0 / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
4 + \left(x - z\right) \cdot \frac{4}{y}
\end{array}
Initial program 99.9%
associate-*l/99.7%
+-commutative99.7%
associate--l+99.7%
distribute-lft-in99.7%
associate-+r+99.7%
*-commutative99.7%
+-commutative99.7%
fma-def99.7%
associate-*r*99.8%
associate-*l/99.8%
associate-/l*99.8%
*-inverses99.8%
metadata-eval99.8%
metadata-eval99.8%
metadata-eval99.8%
Simplified99.8%
fma-udef99.8%
Applied egg-rr99.8%
Final simplification99.8%
(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.9%
Taylor expanded in y around inf 38.5%
Final simplification38.5%
herbie shell --seed 2023257
(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)))