
(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 8 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.7%
sub-neg99.7%
distribute-rgt-neg-in99.7%
metadata-eval99.7%
Simplified99.7%
Taylor expanded in z around 0 100.0%
Final simplification100.0%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* 4.0 (/ x z))) (t_1 (* y (/ -4.0 z))))
(if (<= x -1.26e+74)
t_0
(if (<= x -9e+42)
t_1
(if (<= x -2.4e-156)
-2.0
(if (<= x -1.55e-188)
t_1
(if (<= x 1.1e-286)
-2.0
(if (<= x 1.2e-242)
t_1
(if (<= x 1.3e-178)
-2.0
(if (<= x 1.18e-145)
t_1
(if (<= x 4.1e-75)
-2.0
(if (<= x 2.4e+64) t_1 t_0))))))))))))
double code(double x, double y, double z) {
double t_0 = 4.0 * (x / z);
double t_1 = y * (-4.0 / z);
double tmp;
if (x <= -1.26e+74) {
tmp = t_0;
} else if (x <= -9e+42) {
tmp = t_1;
} else if (x <= -2.4e-156) {
tmp = -2.0;
} else if (x <= -1.55e-188) {
tmp = t_1;
} else if (x <= 1.1e-286) {
tmp = -2.0;
} else if (x <= 1.2e-242) {
tmp = t_1;
} else if (x <= 1.3e-178) {
tmp = -2.0;
} else if (x <= 1.18e-145) {
tmp = t_1;
} else if (x <= 4.1e-75) {
tmp = -2.0;
} else if (x <= 2.4e+64) {
tmp = t_1;
} 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) :: t_1
real(8) :: tmp
t_0 = 4.0d0 * (x / z)
t_1 = y * ((-4.0d0) / z)
if (x <= (-1.26d+74)) then
tmp = t_0
else if (x <= (-9d+42)) then
tmp = t_1
else if (x <= (-2.4d-156)) then
tmp = -2.0d0
else if (x <= (-1.55d-188)) then
tmp = t_1
else if (x <= 1.1d-286) then
tmp = -2.0d0
else if (x <= 1.2d-242) then
tmp = t_1
else if (x <= 1.3d-178) then
tmp = -2.0d0
else if (x <= 1.18d-145) then
tmp = t_1
else if (x <= 4.1d-75) then
tmp = -2.0d0
else if (x <= 2.4d+64) then
tmp = t_1
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = 4.0 * (x / z);
double t_1 = y * (-4.0 / z);
double tmp;
if (x <= -1.26e+74) {
tmp = t_0;
} else if (x <= -9e+42) {
tmp = t_1;
} else if (x <= -2.4e-156) {
tmp = -2.0;
} else if (x <= -1.55e-188) {
tmp = t_1;
} else if (x <= 1.1e-286) {
tmp = -2.0;
} else if (x <= 1.2e-242) {
tmp = t_1;
} else if (x <= 1.3e-178) {
tmp = -2.0;
} else if (x <= 1.18e-145) {
tmp = t_1;
} else if (x <= 4.1e-75) {
tmp = -2.0;
} else if (x <= 2.4e+64) {
tmp = t_1;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = 4.0 * (x / z) t_1 = y * (-4.0 / z) tmp = 0 if x <= -1.26e+74: tmp = t_0 elif x <= -9e+42: tmp = t_1 elif x <= -2.4e-156: tmp = -2.0 elif x <= -1.55e-188: tmp = t_1 elif x <= 1.1e-286: tmp = -2.0 elif x <= 1.2e-242: tmp = t_1 elif x <= 1.3e-178: tmp = -2.0 elif x <= 1.18e-145: tmp = t_1 elif x <= 4.1e-75: tmp = -2.0 elif x <= 2.4e+64: tmp = t_1 else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(4.0 * Float64(x / z)) t_1 = Float64(y * Float64(-4.0 / z)) tmp = 0.0 if (x <= -1.26e+74) tmp = t_0; elseif (x <= -9e+42) tmp = t_1; elseif (x <= -2.4e-156) tmp = -2.0; elseif (x <= -1.55e-188) tmp = t_1; elseif (x <= 1.1e-286) tmp = -2.0; elseif (x <= 1.2e-242) tmp = t_1; elseif (x <= 1.3e-178) tmp = -2.0; elseif (x <= 1.18e-145) tmp = t_1; elseif (x <= 4.1e-75) tmp = -2.0; elseif (x <= 2.4e+64) tmp = t_1; else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = 4.0 * (x / z); t_1 = y * (-4.0 / z); tmp = 0.0; if (x <= -1.26e+74) tmp = t_0; elseif (x <= -9e+42) tmp = t_1; elseif (x <= -2.4e-156) tmp = -2.0; elseif (x <= -1.55e-188) tmp = t_1; elseif (x <= 1.1e-286) tmp = -2.0; elseif (x <= 1.2e-242) tmp = t_1; elseif (x <= 1.3e-178) tmp = -2.0; elseif (x <= 1.18e-145) tmp = t_1; elseif (x <= 4.1e-75) tmp = -2.0; elseif (x <= 2.4e+64) tmp = t_1; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(4.0 * N[(x / z), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(y * N[(-4.0 / z), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, -1.26e+74], t$95$0, If[LessEqual[x, -9e+42], t$95$1, If[LessEqual[x, -2.4e-156], -2.0, If[LessEqual[x, -1.55e-188], t$95$1, If[LessEqual[x, 1.1e-286], -2.0, If[LessEqual[x, 1.2e-242], t$95$1, If[LessEqual[x, 1.3e-178], -2.0, If[LessEqual[x, 1.18e-145], t$95$1, If[LessEqual[x, 4.1e-75], -2.0, If[LessEqual[x, 2.4e+64], t$95$1, t$95$0]]]]]]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := 4 \cdot \frac{x}{z}\\
t_1 := y \cdot \frac{-4}{z}\\
\mathbf{if}\;x \leq -1.26 \cdot 10^{+74}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;x \leq -9 \cdot 10^{+42}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;x \leq -2.4 \cdot 10^{-156}:\\
\;\;\;\;-2\\
\mathbf{elif}\;x \leq -1.55 \cdot 10^{-188}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;x \leq 1.1 \cdot 10^{-286}:\\
\;\;\;\;-2\\
\mathbf{elif}\;x \leq 1.2 \cdot 10^{-242}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;x \leq 1.3 \cdot 10^{-178}:\\
\;\;\;\;-2\\
\mathbf{elif}\;x \leq 1.18 \cdot 10^{-145}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;x \leq 4.1 \cdot 10^{-75}:\\
\;\;\;\;-2\\
\mathbf{elif}\;x \leq 2.4 \cdot 10^{+64}:\\
\;\;\;\;t_1\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if x < -1.26000000000000008e74 or 2.39999999999999999e64 < x Initial program 100.0%
associate-*l/99.7%
sub-neg99.7%
distribute-rgt-neg-in99.7%
metadata-eval99.7%
Simplified99.7%
Taylor expanded in x around inf 71.8%
if -1.26000000000000008e74 < x < -9.00000000000000025e42 or -2.4e-156 < x < -1.5500000000000001e-188 or 1.1e-286 < x < 1.2e-242 or 1.29999999999999999e-178 < x < 1.18000000000000006e-145 or 4.10000000000000002e-75 < x < 2.39999999999999999e64Initial program 100.0%
associate-/l*99.7%
Simplified99.7%
Taylor expanded in y around inf 75.6%
associate-*r/75.6%
neg-mul-175.6%
Simplified75.6%
frac-2neg75.6%
frac-2neg75.6%
metadata-eval75.6%
metadata-eval75.6%
distribute-frac-neg75.6%
remove-double-neg75.6%
frac-2neg75.6%
distribute-frac-neg75.6%
remove-double-neg75.6%
associate-/r/75.6%
Applied egg-rr75.6%
Taylor expanded in z around 0 75.9%
associate-*r/75.9%
associate-*l/75.6%
Simplified75.6%
if -9.00000000000000025e42 < x < -2.4e-156 or -1.5500000000000001e-188 < x < 1.1e-286 or 1.2e-242 < x < 1.29999999999999999e-178 or 1.18000000000000006e-145 < x < 4.10000000000000002e-75Initial program 100.0%
associate-*l/99.6%
sub-neg99.6%
distribute-rgt-neg-in99.6%
metadata-eval99.6%
Simplified99.6%
Taylor expanded in z around inf 58.7%
Final simplification67.9%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* 4.0 (/ x z))) (t_1 (/ (* y -4.0) z)))
(if (<= x -1.7e+74)
t_0
(if (<= x -2.1e+41)
t_1
(if (<= x -1.5e-156)
-2.0
(if (<= x -1.15e-185)
t_1
(if (<= x 1.15e-286)
-2.0
(if (<= x 2e-242)
t_1
(if (<= x 9e-179)
-2.0
(if (<= x 7e-144)
(* y (/ -4.0 z))
(if (<= x 2.3e-75)
-2.0
(if (<= x 1.36e+65) t_1 t_0))))))))))))
double code(double x, double y, double z) {
double t_0 = 4.0 * (x / z);
double t_1 = (y * -4.0) / z;
double tmp;
if (x <= -1.7e+74) {
tmp = t_0;
} else if (x <= -2.1e+41) {
tmp = t_1;
} else if (x <= -1.5e-156) {
tmp = -2.0;
} else if (x <= -1.15e-185) {
tmp = t_1;
} else if (x <= 1.15e-286) {
tmp = -2.0;
} else if (x <= 2e-242) {
tmp = t_1;
} else if (x <= 9e-179) {
tmp = -2.0;
} else if (x <= 7e-144) {
tmp = y * (-4.0 / z);
} else if (x <= 2.3e-75) {
tmp = -2.0;
} else if (x <= 1.36e+65) {
tmp = t_1;
} 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) :: t_1
real(8) :: tmp
t_0 = 4.0d0 * (x / z)
t_1 = (y * (-4.0d0)) / z
if (x <= (-1.7d+74)) then
tmp = t_0
else if (x <= (-2.1d+41)) then
tmp = t_1
else if (x <= (-1.5d-156)) then
tmp = -2.0d0
else if (x <= (-1.15d-185)) then
tmp = t_1
else if (x <= 1.15d-286) then
tmp = -2.0d0
else if (x <= 2d-242) then
tmp = t_1
else if (x <= 9d-179) then
tmp = -2.0d0
else if (x <= 7d-144) then
tmp = y * ((-4.0d0) / z)
else if (x <= 2.3d-75) then
tmp = -2.0d0
else if (x <= 1.36d+65) then
tmp = t_1
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = 4.0 * (x / z);
double t_1 = (y * -4.0) / z;
double tmp;
if (x <= -1.7e+74) {
tmp = t_0;
} else if (x <= -2.1e+41) {
tmp = t_1;
} else if (x <= -1.5e-156) {
tmp = -2.0;
} else if (x <= -1.15e-185) {
tmp = t_1;
} else if (x <= 1.15e-286) {
tmp = -2.0;
} else if (x <= 2e-242) {
tmp = t_1;
} else if (x <= 9e-179) {
tmp = -2.0;
} else if (x <= 7e-144) {
tmp = y * (-4.0 / z);
} else if (x <= 2.3e-75) {
tmp = -2.0;
} else if (x <= 1.36e+65) {
tmp = t_1;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = 4.0 * (x / z) t_1 = (y * -4.0) / z tmp = 0 if x <= -1.7e+74: tmp = t_0 elif x <= -2.1e+41: tmp = t_1 elif x <= -1.5e-156: tmp = -2.0 elif x <= -1.15e-185: tmp = t_1 elif x <= 1.15e-286: tmp = -2.0 elif x <= 2e-242: tmp = t_1 elif x <= 9e-179: tmp = -2.0 elif x <= 7e-144: tmp = y * (-4.0 / z) elif x <= 2.3e-75: tmp = -2.0 elif x <= 1.36e+65: tmp = t_1 else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(4.0 * Float64(x / z)) t_1 = Float64(Float64(y * -4.0) / z) tmp = 0.0 if (x <= -1.7e+74) tmp = t_0; elseif (x <= -2.1e+41) tmp = t_1; elseif (x <= -1.5e-156) tmp = -2.0; elseif (x <= -1.15e-185) tmp = t_1; elseif (x <= 1.15e-286) tmp = -2.0; elseif (x <= 2e-242) tmp = t_1; elseif (x <= 9e-179) tmp = -2.0; elseif (x <= 7e-144) tmp = Float64(y * Float64(-4.0 / z)); elseif (x <= 2.3e-75) tmp = -2.0; elseif (x <= 1.36e+65) tmp = t_1; else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = 4.0 * (x / z); t_1 = (y * -4.0) / z; tmp = 0.0; if (x <= -1.7e+74) tmp = t_0; elseif (x <= -2.1e+41) tmp = t_1; elseif (x <= -1.5e-156) tmp = -2.0; elseif (x <= -1.15e-185) tmp = t_1; elseif (x <= 1.15e-286) tmp = -2.0; elseif (x <= 2e-242) tmp = t_1; elseif (x <= 9e-179) tmp = -2.0; elseif (x <= 7e-144) tmp = y * (-4.0 / z); elseif (x <= 2.3e-75) tmp = -2.0; elseif (x <= 1.36e+65) tmp = t_1; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(4.0 * N[(x / z), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(y * -4.0), $MachinePrecision] / z), $MachinePrecision]}, If[LessEqual[x, -1.7e+74], t$95$0, If[LessEqual[x, -2.1e+41], t$95$1, If[LessEqual[x, -1.5e-156], -2.0, If[LessEqual[x, -1.15e-185], t$95$1, If[LessEqual[x, 1.15e-286], -2.0, If[LessEqual[x, 2e-242], t$95$1, If[LessEqual[x, 9e-179], -2.0, If[LessEqual[x, 7e-144], N[(y * N[(-4.0 / z), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 2.3e-75], -2.0, If[LessEqual[x, 1.36e+65], t$95$1, t$95$0]]]]]]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := 4 \cdot \frac{x}{z}\\
t_1 := \frac{y \cdot -4}{z}\\
\mathbf{if}\;x \leq -1.7 \cdot 10^{+74}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;x \leq -2.1 \cdot 10^{+41}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;x \leq -1.5 \cdot 10^{-156}:\\
\;\;\;\;-2\\
\mathbf{elif}\;x \leq -1.15 \cdot 10^{-185}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;x \leq 1.15 \cdot 10^{-286}:\\
\;\;\;\;-2\\
\mathbf{elif}\;x \leq 2 \cdot 10^{-242}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;x \leq 9 \cdot 10^{-179}:\\
\;\;\;\;-2\\
\mathbf{elif}\;x \leq 7 \cdot 10^{-144}:\\
\;\;\;\;y \cdot \frac{-4}{z}\\
\mathbf{elif}\;x \leq 2.3 \cdot 10^{-75}:\\
\;\;\;\;-2\\
\mathbf{elif}\;x \leq 1.36 \cdot 10^{+65}:\\
\;\;\;\;t_1\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if x < -1.7e74 or 1.3600000000000001e65 < x Initial program 100.0%
associate-*l/99.7%
sub-neg99.7%
distribute-rgt-neg-in99.7%
metadata-eval99.7%
Simplified99.7%
Taylor expanded in x around inf 71.8%
if -1.7e74 < x < -2.1e41 or -1.5e-156 < x < -1.15e-185 or 1.1500000000000001e-286 < x < 2e-242 or 2.3e-75 < x < 1.3600000000000001e65Initial program 100.0%
associate-*l/99.7%
sub-neg99.7%
distribute-rgt-neg-in99.7%
metadata-eval99.7%
Simplified99.7%
Taylor expanded in y around inf 73.7%
*-commutative73.7%
associate-*l/73.7%
Simplified73.7%
if -2.1e41 < x < -1.5e-156 or -1.15e-185 < x < 1.1500000000000001e-286 or 2e-242 < x < 8.99999999999999984e-179 or 6.9999999999999997e-144 < x < 2.3e-75Initial program 100.0%
associate-*l/99.6%
sub-neg99.6%
distribute-rgt-neg-in99.6%
metadata-eval99.6%
Simplified99.6%
Taylor expanded in z around inf 58.7%
if 8.99999999999999984e-179 < x < 6.9999999999999997e-144Initial program 100.0%
associate-/l*99.8%
Simplified99.8%
Taylor expanded in y around inf 89.0%
associate-*r/89.0%
neg-mul-189.0%
Simplified89.0%
frac-2neg89.0%
frac-2neg89.0%
metadata-eval89.0%
metadata-eval89.0%
distribute-frac-neg89.0%
remove-double-neg89.0%
frac-2neg89.0%
distribute-frac-neg89.0%
remove-double-neg89.0%
associate-/r/89.2%
Applied egg-rr89.2%
Taylor expanded in z around 0 89.2%
associate-*r/89.2%
associate-*l/89.2%
Simplified89.2%
Final simplification67.9%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* 4.0 (- -0.5 (/ y z)))) (t_1 (+ (* 4.0 (/ x z)) -2.0)))
(if (<= x -6.5e+76)
t_1
(if (<= x -3e+15)
t_0
(if (<= x -5.6e-55)
t_1
(if (<= x 4.1e+18) t_0 (* 4.0 (/ (- x y) z))))))))
double code(double x, double y, double z) {
double t_0 = 4.0 * (-0.5 - (y / z));
double t_1 = (4.0 * (x / z)) + -2.0;
double tmp;
if (x <= -6.5e+76) {
tmp = t_1;
} else if (x <= -3e+15) {
tmp = t_0;
} else if (x <= -5.6e-55) {
tmp = t_1;
} else if (x <= 4.1e+18) {
tmp = t_0;
} else {
tmp = 4.0 * ((x - y) / z);
}
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 = 4.0d0 * ((-0.5d0) - (y / z))
t_1 = (4.0d0 * (x / z)) + (-2.0d0)
if (x <= (-6.5d+76)) then
tmp = t_1
else if (x <= (-3d+15)) then
tmp = t_0
else if (x <= (-5.6d-55)) then
tmp = t_1
else if (x <= 4.1d+18) then
tmp = t_0
else
tmp = 4.0d0 * ((x - y) / z)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = 4.0 * (-0.5 - (y / z));
double t_1 = (4.0 * (x / z)) + -2.0;
double tmp;
if (x <= -6.5e+76) {
tmp = t_1;
} else if (x <= -3e+15) {
tmp = t_0;
} else if (x <= -5.6e-55) {
tmp = t_1;
} else if (x <= 4.1e+18) {
tmp = t_0;
} else {
tmp = 4.0 * ((x - y) / z);
}
return tmp;
}
def code(x, y, z): t_0 = 4.0 * (-0.5 - (y / z)) t_1 = (4.0 * (x / z)) + -2.0 tmp = 0 if x <= -6.5e+76: tmp = t_1 elif x <= -3e+15: tmp = t_0 elif x <= -5.6e-55: tmp = t_1 elif x <= 4.1e+18: tmp = t_0 else: tmp = 4.0 * ((x - y) / z) return tmp
function code(x, y, z) t_0 = Float64(4.0 * Float64(-0.5 - Float64(y / z))) t_1 = Float64(Float64(4.0 * Float64(x / z)) + -2.0) tmp = 0.0 if (x <= -6.5e+76) tmp = t_1; elseif (x <= -3e+15) tmp = t_0; elseif (x <= -5.6e-55) tmp = t_1; elseif (x <= 4.1e+18) tmp = t_0; else tmp = Float64(4.0 * Float64(Float64(x - y) / z)); end return tmp end
function tmp_2 = code(x, y, z) t_0 = 4.0 * (-0.5 - (y / z)); t_1 = (4.0 * (x / z)) + -2.0; tmp = 0.0; if (x <= -6.5e+76) tmp = t_1; elseif (x <= -3e+15) tmp = t_0; elseif (x <= -5.6e-55) tmp = t_1; elseif (x <= 4.1e+18) tmp = t_0; else tmp = 4.0 * ((x - y) / z); end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(4.0 * N[(-0.5 - N[(y / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(4.0 * N[(x / z), $MachinePrecision]), $MachinePrecision] + -2.0), $MachinePrecision]}, If[LessEqual[x, -6.5e+76], t$95$1, If[LessEqual[x, -3e+15], t$95$0, If[LessEqual[x, -5.6e-55], t$95$1, If[LessEqual[x, 4.1e+18], t$95$0, N[(4.0 * N[(N[(x - y), $MachinePrecision] / z), $MachinePrecision]), $MachinePrecision]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := 4 \cdot \left(-0.5 - \frac{y}{z}\right)\\
t_1 := 4 \cdot \frac{x}{z} + -2\\
\mathbf{if}\;x \leq -6.5 \cdot 10^{+76}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;x \leq -3 \cdot 10^{+15}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;x \leq -5.6 \cdot 10^{-55}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;x \leq 4.1 \cdot 10^{+18}:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;4 \cdot \frac{x - y}{z}\\
\end{array}
\end{array}
if x < -6.5000000000000005e76 or -3e15 < x < -5.59999999999999968e-55Initial program 100.0%
associate-*l/99.8%
sub-neg99.8%
distribute-rgt-neg-in99.8%
metadata-eval99.8%
Simplified99.8%
Taylor expanded in y around 0 95.9%
+-commutative95.9%
metadata-eval95.9%
cancel-sign-sub-inv95.9%
div-sub95.9%
associate-/l*95.9%
*-lft-identity95.9%
associate-*l/95.9%
lft-mult-inverse95.9%
metadata-eval95.9%
sub-neg95.9%
metadata-eval95.9%
distribute-lft-in95.9%
metadata-eval95.9%
Simplified95.9%
if -6.5000000000000005e76 < x < -3e15 or -5.59999999999999968e-55 < x < 4.1e18Initial program 100.0%
associate-*l/99.7%
sub-neg99.7%
distribute-rgt-neg-in99.7%
metadata-eval99.7%
Simplified99.7%
Taylor expanded in x around 0 97.5%
div-sub97.6%
associate-/l*97.6%
*-lft-identity97.6%
associate-*l/97.4%
lft-mult-inverse97.6%
metadata-eval97.6%
Simplified97.6%
if 4.1e18 < x Initial program 100.0%
associate-*l/99.7%
sub-neg99.7%
distribute-rgt-neg-in99.7%
metadata-eval99.7%
Simplified99.7%
Taylor expanded in z around 0 83.9%
Final simplification93.9%
(FPCore (x y z) :precision binary64 (if (or (<= x -3.1e+88) (not (<= x 1.3e+201))) (* 4.0 (/ x z)) (* 4.0 (- -0.5 (/ y z)))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -3.1e+88) || !(x <= 1.3e+201)) {
tmp = 4.0 * (x / z);
} else {
tmp = 4.0 * (-0.5 - (y / z));
}
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+88)) .or. (.not. (x <= 1.3d+201))) then
tmp = 4.0d0 * (x / z)
else
tmp = 4.0d0 * ((-0.5d0) - (y / z))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -3.1e+88) || !(x <= 1.3e+201)) {
tmp = 4.0 * (x / z);
} else {
tmp = 4.0 * (-0.5 - (y / z));
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -3.1e+88) or not (x <= 1.3e+201): tmp = 4.0 * (x / z) else: tmp = 4.0 * (-0.5 - (y / z)) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -3.1e+88) || !(x <= 1.3e+201)) tmp = Float64(4.0 * Float64(x / z)); else tmp = Float64(4.0 * Float64(-0.5 - Float64(y / z))); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -3.1e+88) || ~((x <= 1.3e+201))) tmp = 4.0 * (x / z); else tmp = 4.0 * (-0.5 - (y / z)); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -3.1e+88], N[Not[LessEqual[x, 1.3e+201]], $MachinePrecision]], N[(4.0 * N[(x / z), $MachinePrecision]), $MachinePrecision], N[(4.0 * N[(-0.5 - N[(y / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -3.1 \cdot 10^{+88} \lor \neg \left(x \leq 1.3 \cdot 10^{+201}\right):\\
\;\;\;\;4 \cdot \frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;4 \cdot \left(-0.5 - \frac{y}{z}\right)\\
\end{array}
\end{array}
if x < -3.1000000000000001e88 or 1.29999999999999993e201 < x Initial program 100.0%
associate-*l/99.8%
sub-neg99.8%
distribute-rgt-neg-in99.8%
metadata-eval99.8%
Simplified99.8%
Taylor expanded in x around inf 88.2%
if -3.1000000000000001e88 < x < 1.29999999999999993e201Initial program 100.0%
associate-*l/99.7%
sub-neg99.7%
distribute-rgt-neg-in99.7%
metadata-eval99.7%
Simplified99.7%
Taylor expanded in x around 0 87.0%
div-sub87.1%
associate-/l*87.1%
*-lft-identity87.1%
associate-*l/86.9%
lft-mult-inverse87.1%
metadata-eval87.1%
Simplified87.1%
Final simplification87.3%
(FPCore (x y z) :precision binary64 (if (or (<= x -2.75e+88) (not (<= x 1.26e+17))) (* 4.0 (/ (- x y) z)) (* 4.0 (- -0.5 (/ y z)))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -2.75e+88) || !(x <= 1.26e+17)) {
tmp = 4.0 * ((x - y) / z);
} else {
tmp = 4.0 * (-0.5 - (y / z));
}
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.75d+88)) .or. (.not. (x <= 1.26d+17))) then
tmp = 4.0d0 * ((x - y) / z)
else
tmp = 4.0d0 * ((-0.5d0) - (y / z))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -2.75e+88) || !(x <= 1.26e+17)) {
tmp = 4.0 * ((x - y) / z);
} else {
tmp = 4.0 * (-0.5 - (y / z));
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -2.75e+88) or not (x <= 1.26e+17): tmp = 4.0 * ((x - y) / z) else: tmp = 4.0 * (-0.5 - (y / z)) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -2.75e+88) || !(x <= 1.26e+17)) tmp = Float64(4.0 * Float64(Float64(x - y) / z)); else tmp = Float64(4.0 * Float64(-0.5 - Float64(y / z))); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -2.75e+88) || ~((x <= 1.26e+17))) tmp = 4.0 * ((x - y) / z); else tmp = 4.0 * (-0.5 - (y / z)); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -2.75e+88], N[Not[LessEqual[x, 1.26e+17]], $MachinePrecision]], N[(4.0 * N[(N[(x - y), $MachinePrecision] / z), $MachinePrecision]), $MachinePrecision], N[(4.0 * N[(-0.5 - N[(y / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.75 \cdot 10^{+88} \lor \neg \left(x \leq 1.26 \cdot 10^{+17}\right):\\
\;\;\;\;4 \cdot \frac{x - y}{z}\\
\mathbf{else}:\\
\;\;\;\;4 \cdot \left(-0.5 - \frac{y}{z}\right)\\
\end{array}
\end{array}
if x < -2.75e88 or 1.26e17 < x Initial program 100.0%
associate-*l/99.7%
sub-neg99.7%
distribute-rgt-neg-in99.7%
metadata-eval99.7%
Simplified99.7%
Taylor expanded in z around 0 86.3%
if -2.75e88 < x < 1.26e17Initial program 100.0%
associate-*l/99.7%
sub-neg99.7%
distribute-rgt-neg-in99.7%
metadata-eval99.7%
Simplified99.7%
Taylor expanded in x around 0 93.4%
div-sub93.5%
associate-/l*93.5%
*-lft-identity93.5%
associate-*l/93.3%
lft-mult-inverse93.5%
metadata-eval93.5%
Simplified93.5%
Final simplification90.6%
(FPCore (x y z) :precision binary64 (if (or (<= x -2.75e+88) (not (<= x 2.8e+16))) (* 4.0 (/ x z)) -2.0))
double code(double x, double y, double z) {
double tmp;
if ((x <= -2.75e+88) || !(x <= 2.8e+16)) {
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 ((x <= (-2.75d+88)) .or. (.not. (x <= 2.8d+16))) 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 ((x <= -2.75e+88) || !(x <= 2.8e+16)) {
tmp = 4.0 * (x / z);
} else {
tmp = -2.0;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -2.75e+88) or not (x <= 2.8e+16): tmp = 4.0 * (x / z) else: tmp = -2.0 return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -2.75e+88) || !(x <= 2.8e+16)) 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 ((x <= -2.75e+88) || ~((x <= 2.8e+16))) tmp = 4.0 * (x / z); else tmp = -2.0; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -2.75e+88], N[Not[LessEqual[x, 2.8e+16]], $MachinePrecision]], N[(4.0 * N[(x / z), $MachinePrecision]), $MachinePrecision], -2.0]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.75 \cdot 10^{+88} \lor \neg \left(x \leq 2.8 \cdot 10^{+16}\right):\\
\;\;\;\;4 \cdot \frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;-2\\
\end{array}
\end{array}
if x < -2.75e88 or 2.8e16 < x Initial program 100.0%
associate-*l/99.7%
sub-neg99.7%
distribute-rgt-neg-in99.7%
metadata-eval99.7%
Simplified99.7%
Taylor expanded in x around inf 69.0%
if -2.75e88 < x < 2.8e16Initial program 100.0%
associate-*l/99.7%
sub-neg99.7%
distribute-rgt-neg-in99.7%
metadata-eval99.7%
Simplified99.7%
Taylor expanded in z around inf 45.5%
Final simplification54.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 100.0%
associate-*l/99.7%
sub-neg99.7%
distribute-rgt-neg-in99.7%
metadata-eval99.7%
Simplified99.7%
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 2023171
(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))