
(FPCore (x y z) :precision binary64 (/ (* 4.0 (- (- x y) (* z 0.5))) z))
double code(double x, double y, double z) {
return (4.0 * ((x - y) - (z * 0.5))) / z;
}
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 - y) - (z * 0.5d0))) / z
end function
public static double code(double x, double y, double z) {
return (4.0 * ((x - y) - (z * 0.5))) / z;
}
def code(x, y, z): return (4.0 * ((x - y) - (z * 0.5))) / z
function code(x, y, z) return Float64(Float64(4.0 * Float64(Float64(x - y) - Float64(z * 0.5))) / z) end
function tmp = code(x, y, z) tmp = (4.0 * ((x - y) - (z * 0.5))) / z; end
code[x_, y_, z_] := N[(N[(4.0 * N[(N[(x - y), $MachinePrecision] - N[(z * 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / z), $MachinePrecision]
\begin{array}{l}
\\
\frac{4 \cdot \left(\left(x - y\right) - z \cdot 0.5\right)}{z}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 7 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (/ (* 4.0 (- (- x y) (* z 0.5))) z))
double code(double x, double y, double z) {
return (4.0 * ((x - y) - (z * 0.5))) / z;
}
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 - y) - (z * 0.5d0))) / z
end function
public static double code(double x, double y, double z) {
return (4.0 * ((x - y) - (z * 0.5))) / z;
}
def code(x, y, z): return (4.0 * ((x - y) - (z * 0.5))) / z
function code(x, y, z) return Float64(Float64(4.0 * Float64(Float64(x - y) - Float64(z * 0.5))) / z) end
function tmp = code(x, y, z) tmp = (4.0 * ((x - y) - (z * 0.5))) / z; end
code[x_, y_, z_] := N[(N[(4.0 * N[(N[(x - y), $MachinePrecision] - N[(z * 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / z), $MachinePrecision]
\begin{array}{l}
\\
\frac{4 \cdot \left(\left(x - y\right) - z \cdot 0.5\right)}{z}
\end{array}
(FPCore (x y z) :precision binary64 (- (* 4.0 (/ (- x y) z)) 2.0))
double code(double x, double y, double z) {
return (4.0 * ((x - y) / z)) - 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 - y) / z)) - 2.0d0
end function
public static double code(double x, double y, double z) {
return (4.0 * ((x - y) / z)) - 2.0;
}
def code(x, y, z): return (4.0 * ((x - y) / z)) - 2.0
function code(x, y, z) return Float64(Float64(4.0 * Float64(Float64(x - y) / z)) - 2.0) end
function tmp = code(x, y, z) tmp = (4.0 * ((x - y) / z)) - 2.0; end
code[x_, y_, z_] := N[(N[(4.0 * N[(N[(x - y), $MachinePrecision] / z), $MachinePrecision]), $MachinePrecision] - 2.0), $MachinePrecision]
\begin{array}{l}
\\
4 \cdot \frac{x - y}{z} - 2
\end{array}
Initial program 100.0%
associate-/l*99.8%
Simplified99.8%
Taylor expanded in z around 0 100.0%
Final simplification100.0%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* 4.0 (/ x z))))
(if (<= z -5.2e+58)
-2.0
(if (<= z -1.1e-246)
t_0
(if (<= z -2.7e-287) (/ (* y -4.0) z) (if (<= z 3.6e+83) t_0 -2.0))))))
double code(double x, double y, double z) {
double t_0 = 4.0 * (x / z);
double tmp;
if (z <= -5.2e+58) {
tmp = -2.0;
} else if (z <= -1.1e-246) {
tmp = t_0;
} else if (z <= -2.7e-287) {
tmp = (y * -4.0) / z;
} else if (z <= 3.6e+83) {
tmp = t_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) :: t_0
real(8) :: tmp
t_0 = 4.0d0 * (x / z)
if (z <= (-5.2d+58)) then
tmp = -2.0d0
else if (z <= (-1.1d-246)) then
tmp = t_0
else if (z <= (-2.7d-287)) then
tmp = (y * (-4.0d0)) / z
else if (z <= 3.6d+83) then
tmp = t_0
else
tmp = -2.0d0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = 4.0 * (x / z);
double tmp;
if (z <= -5.2e+58) {
tmp = -2.0;
} else if (z <= -1.1e-246) {
tmp = t_0;
} else if (z <= -2.7e-287) {
tmp = (y * -4.0) / z;
} else if (z <= 3.6e+83) {
tmp = t_0;
} else {
tmp = -2.0;
}
return tmp;
}
def code(x, y, z): t_0 = 4.0 * (x / z) tmp = 0 if z <= -5.2e+58: tmp = -2.0 elif z <= -1.1e-246: tmp = t_0 elif z <= -2.7e-287: tmp = (y * -4.0) / z elif z <= 3.6e+83: tmp = t_0 else: tmp = -2.0 return tmp
function code(x, y, z) t_0 = Float64(4.0 * Float64(x / z)) tmp = 0.0 if (z <= -5.2e+58) tmp = -2.0; elseif (z <= -1.1e-246) tmp = t_0; elseif (z <= -2.7e-287) tmp = Float64(Float64(y * -4.0) / z); elseif (z <= 3.6e+83) tmp = t_0; else tmp = -2.0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = 4.0 * (x / z); tmp = 0.0; if (z <= -5.2e+58) tmp = -2.0; elseif (z <= -1.1e-246) tmp = t_0; elseif (z <= -2.7e-287) tmp = (y * -4.0) / z; elseif (z <= 3.6e+83) tmp = t_0; else tmp = -2.0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(4.0 * N[(x / z), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[z, -5.2e+58], -2.0, If[LessEqual[z, -1.1e-246], t$95$0, If[LessEqual[z, -2.7e-287], N[(N[(y * -4.0), $MachinePrecision] / z), $MachinePrecision], If[LessEqual[z, 3.6e+83], t$95$0, -2.0]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := 4 \cdot \frac{x}{z}\\
\mathbf{if}\;z \leq -5.2 \cdot 10^{+58}:\\
\;\;\;\;-2\\
\mathbf{elif}\;z \leq -1.1 \cdot 10^{-246}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;z \leq -2.7 \cdot 10^{-287}:\\
\;\;\;\;\frac{y \cdot -4}{z}\\
\mathbf{elif}\;z \leq 3.6 \cdot 10^{+83}:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;-2\\
\end{array}
\end{array}
if z < -5.19999999999999976e58 or 3.5999999999999997e83 < z Initial program 100.0%
associate-/l*99.8%
Simplified99.8%
Taylor expanded in z around inf 67.1%
if -5.19999999999999976e58 < z < -1.09999999999999999e-246 or -2.7000000000000001e-287 < z < 3.5999999999999997e83Initial program 100.0%
associate-/l*99.8%
Simplified99.8%
Taylor expanded in x around inf 59.0%
if -1.09999999999999999e-246 < z < -2.7000000000000001e-287Initial program 100.0%
associate-/l*99.9%
Simplified99.9%
Taylor expanded in y around inf 75.3%
*-commutative75.3%
associate-*l/75.3%
Simplified75.3%
Final simplification62.9%
(FPCore (x y z) :precision binary64 (if (or (<= y -7.6e+92) (not (<= y 1.9e+138))) (/ (* y -4.0) z) (+ (* 4.0 (/ x z)) -2.0)))
double code(double x, double y, double z) {
double tmp;
if ((y <= -7.6e+92) || !(y <= 1.9e+138)) {
tmp = (y * -4.0) / z;
} else {
tmp = (4.0 * (x / z)) + -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 <= (-7.6d+92)) .or. (.not. (y <= 1.9d+138))) then
tmp = (y * (-4.0d0)) / z
else
tmp = (4.0d0 * (x / z)) + (-2.0d0)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -7.6e+92) || !(y <= 1.9e+138)) {
tmp = (y * -4.0) / z;
} else {
tmp = (4.0 * (x / z)) + -2.0;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -7.6e+92) or not (y <= 1.9e+138): tmp = (y * -4.0) / z else: tmp = (4.0 * (x / z)) + -2.0 return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -7.6e+92) || !(y <= 1.9e+138)) tmp = Float64(Float64(y * -4.0) / z); else tmp = Float64(Float64(4.0 * Float64(x / z)) + -2.0); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -7.6e+92) || ~((y <= 1.9e+138))) tmp = (y * -4.0) / z; else tmp = (4.0 * (x / z)) + -2.0; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -7.6e+92], N[Not[LessEqual[y, 1.9e+138]], $MachinePrecision]], N[(N[(y * -4.0), $MachinePrecision] / z), $MachinePrecision], N[(N[(4.0 * N[(x / z), $MachinePrecision]), $MachinePrecision] + -2.0), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -7.6 \cdot 10^{+92} \lor \neg \left(y \leq 1.9 \cdot 10^{+138}\right):\\
\;\;\;\;\frac{y \cdot -4}{z}\\
\mathbf{else}:\\
\;\;\;\;4 \cdot \frac{x}{z} + -2\\
\end{array}
\end{array}
if y < -7.6000000000000001e92 or 1.90000000000000006e138 < y Initial program 100.0%
associate-/l*99.8%
Simplified99.8%
Taylor expanded in y around inf 78.1%
*-commutative78.1%
associate-*l/78.1%
Simplified78.1%
if -7.6000000000000001e92 < y < 1.90000000000000006e138Initial program 100.0%
associate-/l*99.8%
Simplified99.8%
Taylor expanded in y around 0 87.4%
div-sub87.4%
sub-neg87.4%
associate-/l*87.4%
*-inverses87.4%
metadata-eval87.4%
metadata-eval87.4%
distribute-lft-in87.4%
metadata-eval87.4%
Simplified87.4%
Final simplification85.0%
(FPCore (x y z) :precision binary64 (if (or (<= y -1.35e-13) (not (<= y 5.4e+17))) (- (* -4.0 (/ y z)) 2.0) (+ (* 4.0 (/ x z)) -2.0)))
double code(double x, double y, double z) {
double tmp;
if ((y <= -1.35e-13) || !(y <= 5.4e+17)) {
tmp = (-4.0 * (y / z)) - 2.0;
} else {
tmp = (4.0 * (x / z)) + -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.35d-13)) .or. (.not. (y <= 5.4d+17))) then
tmp = ((-4.0d0) * (y / z)) - 2.0d0
else
tmp = (4.0d0 * (x / z)) + (-2.0d0)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -1.35e-13) || !(y <= 5.4e+17)) {
tmp = (-4.0 * (y / z)) - 2.0;
} else {
tmp = (4.0 * (x / z)) + -2.0;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -1.35e-13) or not (y <= 5.4e+17): tmp = (-4.0 * (y / z)) - 2.0 else: tmp = (4.0 * (x / z)) + -2.0 return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -1.35e-13) || !(y <= 5.4e+17)) tmp = Float64(Float64(-4.0 * Float64(y / z)) - 2.0); else tmp = Float64(Float64(4.0 * Float64(x / z)) + -2.0); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -1.35e-13) || ~((y <= 5.4e+17))) tmp = (-4.0 * (y / z)) - 2.0; else tmp = (4.0 * (x / z)) + -2.0; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -1.35e-13], N[Not[LessEqual[y, 5.4e+17]], $MachinePrecision]], N[(N[(-4.0 * N[(y / z), $MachinePrecision]), $MachinePrecision] - 2.0), $MachinePrecision], N[(N[(4.0 * N[(x / z), $MachinePrecision]), $MachinePrecision] + -2.0), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.35 \cdot 10^{-13} \lor \neg \left(y \leq 5.4 \cdot 10^{+17}\right):\\
\;\;\;\;-4 \cdot \frac{y}{z} - 2\\
\mathbf{else}:\\
\;\;\;\;4 \cdot \frac{x}{z} + -2\\
\end{array}
\end{array}
if y < -1.35000000000000005e-13 or 5.4e17 < y Initial program 100.0%
associate-/l*99.8%
Simplified99.8%
Taylor expanded in z around 0 100.0%
Taylor expanded in x around 0 84.3%
neg-mul-184.3%
distribute-neg-frac84.3%
Simplified84.3%
Taylor expanded in y around 0 84.3%
if -1.35000000000000005e-13 < y < 5.4e17Initial program 100.0%
associate-/l*99.8%
Simplified99.8%
Taylor expanded in y around 0 93.7%
div-sub93.7%
sub-neg93.7%
associate-/l*93.7%
*-inverses93.7%
metadata-eval93.7%
metadata-eval93.7%
distribute-lft-in93.7%
metadata-eval93.7%
Simplified93.7%
Final simplification89.7%
(FPCore (x y z) :precision binary64 (if (<= y -6e-13) (- (* -4.0 (/ y z)) 2.0) (if (<= y 8600000000.0) (+ (* 4.0 (/ x z)) -2.0) (/ 4.0 (/ z (- x y))))))
double code(double x, double y, double z) {
double tmp;
if (y <= -6e-13) {
tmp = (-4.0 * (y / z)) - 2.0;
} else if (y <= 8600000000.0) {
tmp = (4.0 * (x / z)) + -2.0;
} else {
tmp = 4.0 / (z / (x - 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 <= (-6d-13)) then
tmp = ((-4.0d0) * (y / z)) - 2.0d0
else if (y <= 8600000000.0d0) then
tmp = (4.0d0 * (x / z)) + (-2.0d0)
else
tmp = 4.0d0 / (z / (x - y))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= -6e-13) {
tmp = (-4.0 * (y / z)) - 2.0;
} else if (y <= 8600000000.0) {
tmp = (4.0 * (x / z)) + -2.0;
} else {
tmp = 4.0 / (z / (x - y));
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -6e-13: tmp = (-4.0 * (y / z)) - 2.0 elif y <= 8600000000.0: tmp = (4.0 * (x / z)) + -2.0 else: tmp = 4.0 / (z / (x - y)) return tmp
function code(x, y, z) tmp = 0.0 if (y <= -6e-13) tmp = Float64(Float64(-4.0 * Float64(y / z)) - 2.0); elseif (y <= 8600000000.0) tmp = Float64(Float64(4.0 * Float64(x / z)) + -2.0); else tmp = Float64(4.0 / Float64(z / Float64(x - y))); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -6e-13) tmp = (-4.0 * (y / z)) - 2.0; elseif (y <= 8600000000.0) tmp = (4.0 * (x / z)) + -2.0; else tmp = 4.0 / (z / (x - y)); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -6e-13], N[(N[(-4.0 * N[(y / z), $MachinePrecision]), $MachinePrecision] - 2.0), $MachinePrecision], If[LessEqual[y, 8600000000.0], N[(N[(4.0 * N[(x / z), $MachinePrecision]), $MachinePrecision] + -2.0), $MachinePrecision], N[(4.0 / N[(z / N[(x - y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -6 \cdot 10^{-13}:\\
\;\;\;\;-4 \cdot \frac{y}{z} - 2\\
\mathbf{elif}\;y \leq 8600000000:\\
\;\;\;\;4 \cdot \frac{x}{z} + -2\\
\mathbf{else}:\\
\;\;\;\;\frac{4}{\frac{z}{x - y}}\\
\end{array}
\end{array}
if y < -5.99999999999999968e-13Initial program 100.0%
associate-/l*99.8%
Simplified99.8%
Taylor expanded in z around 0 100.0%
Taylor expanded in x around 0 90.5%
neg-mul-190.5%
distribute-neg-frac90.5%
Simplified90.5%
Taylor expanded in y around 0 90.5%
if -5.99999999999999968e-13 < y < 8.6e9Initial program 100.0%
associate-/l*99.8%
Simplified99.8%
Taylor expanded in y around 0 94.7%
div-sub94.7%
sub-neg94.7%
associate-/l*94.7%
*-inverses94.7%
metadata-eval94.7%
metadata-eval94.7%
distribute-lft-in94.7%
metadata-eval94.7%
Simplified94.7%
if 8.6e9 < y Initial program 100.0%
associate-/l*99.7%
Simplified99.7%
Taylor expanded in z around 0 84.2%
Final simplification91.5%
(FPCore (x y z) :precision binary64 (if (<= z -1.06e+58) -2.0 (if (<= z 5.5e+72) (* 4.0 (/ x z)) -2.0)))
double code(double x, double y, double z) {
double tmp;
if (z <= -1.06e+58) {
tmp = -2.0;
} else if (z <= 5.5e+72) {
tmp = 4.0 * (x / z);
} 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 (z <= (-1.06d+58)) then
tmp = -2.0d0
else if (z <= 5.5d+72) then
tmp = 4.0d0 * (x / z)
else
tmp = -2.0d0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (z <= -1.06e+58) {
tmp = -2.0;
} else if (z <= 5.5e+72) {
tmp = 4.0 * (x / z);
} else {
tmp = -2.0;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -1.06e+58: tmp = -2.0 elif z <= 5.5e+72: tmp = 4.0 * (x / z) else: tmp = -2.0 return tmp
function code(x, y, z) tmp = 0.0 if (z <= -1.06e+58) tmp = -2.0; elseif (z <= 5.5e+72) tmp = Float64(4.0 * Float64(x / z)); else tmp = -2.0; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -1.06e+58) tmp = -2.0; elseif (z <= 5.5e+72) tmp = 4.0 * (x / z); else tmp = -2.0; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -1.06e+58], -2.0, If[LessEqual[z, 5.5e+72], N[(4.0 * N[(x / z), $MachinePrecision]), $MachinePrecision], -2.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.06 \cdot 10^{+58}:\\
\;\;\;\;-2\\
\mathbf{elif}\;z \leq 5.5 \cdot 10^{+72}:\\
\;\;\;\;4 \cdot \frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;-2\\
\end{array}
\end{array}
if z < -1.05999999999999997e58 or 5.5e72 < z Initial program 100.0%
associate-/l*99.8%
Simplified99.8%
Taylor expanded in z around inf 67.1%
if -1.05999999999999997e58 < z < 5.5e72Initial program 100.0%
associate-/l*99.8%
Simplified99.8%
Taylor expanded in x around inf 57.1%
Final simplification61.0%
(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%
Simplified99.8%
Taylor expanded in z around inf 33.1%
Final simplification33.1%
(FPCore (x y z) :precision binary64 (- (* 4.0 (/ x z)) (+ 2.0 (* 4.0 (/ y z)))))
double code(double x, double y, double z) {
return (4.0 * (x / z)) - (2.0 + (4.0 * (y / z)));
}
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)) - (2.0d0 + (4.0d0 * (y / z)))
end function
public static double code(double x, double y, double z) {
return (4.0 * (x / z)) - (2.0 + (4.0 * (y / z)));
}
def code(x, y, z): return (4.0 * (x / z)) - (2.0 + (4.0 * (y / z)))
function code(x, y, z) return Float64(Float64(4.0 * Float64(x / z)) - Float64(2.0 + Float64(4.0 * Float64(y / z)))) end
function tmp = code(x, y, z) tmp = (4.0 * (x / z)) - (2.0 + (4.0 * (y / z))); end
code[x_, y_, z_] := N[(N[(4.0 * N[(x / z), $MachinePrecision]), $MachinePrecision] - N[(2.0 + N[(4.0 * N[(y / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
4 \cdot \frac{x}{z} - \left(2 + 4 \cdot \frac{y}{z}\right)
\end{array}
herbie shell --seed 2023240
(FPCore (x y z)
:name "Data.Array.Repa.Algorithms.ColorRamp:rampColorHotToCold from repa-algorithms-3.4.0.1, B"
:precision binary64
:herbie-target
(- (* 4.0 (/ x z)) (+ 2.0 (* 4.0 (/ y z))))
(/ (* 4.0 (- (- x y) (* z 0.5))) z))