
(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 6 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))) (t_1 (/ (* y -4.0) z)))
(if (<= x -11.8)
t_0
(if (<= x -8.2e-252)
t_1
(if (<= x 1.7e-245)
-2.0
(if (<= x 6e-233) t_1 (if (<= x 9e-11) -2.0 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 <= -11.8) {
tmp = t_0;
} else if (x <= -8.2e-252) {
tmp = t_1;
} else if (x <= 1.7e-245) {
tmp = -2.0;
} else if (x <= 6e-233) {
tmp = t_1;
} else if (x <= 9e-11) {
tmp = -2.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) :: t_1
real(8) :: tmp
t_0 = 4.0d0 * (x / z)
t_1 = (y * (-4.0d0)) / z
if (x <= (-11.8d0)) then
tmp = t_0
else if (x <= (-8.2d-252)) then
tmp = t_1
else if (x <= 1.7d-245) then
tmp = -2.0d0
else if (x <= 6d-233) then
tmp = t_1
else if (x <= 9d-11) then
tmp = -2.0d0
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 <= -11.8) {
tmp = t_0;
} else if (x <= -8.2e-252) {
tmp = t_1;
} else if (x <= 1.7e-245) {
tmp = -2.0;
} else if (x <= 6e-233) {
tmp = t_1;
} else if (x <= 9e-11) {
tmp = -2.0;
} 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 <= -11.8: tmp = t_0 elif x <= -8.2e-252: tmp = t_1 elif x <= 1.7e-245: tmp = -2.0 elif x <= 6e-233: tmp = t_1 elif x <= 9e-11: tmp = -2.0 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 <= -11.8) tmp = t_0; elseif (x <= -8.2e-252) tmp = t_1; elseif (x <= 1.7e-245) tmp = -2.0; elseif (x <= 6e-233) tmp = t_1; elseif (x <= 9e-11) tmp = -2.0; 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 <= -11.8) tmp = t_0; elseif (x <= -8.2e-252) tmp = t_1; elseif (x <= 1.7e-245) tmp = -2.0; elseif (x <= 6e-233) tmp = t_1; elseif (x <= 9e-11) tmp = -2.0; 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, -11.8], t$95$0, If[LessEqual[x, -8.2e-252], t$95$1, If[LessEqual[x, 1.7e-245], -2.0, If[LessEqual[x, 6e-233], t$95$1, If[LessEqual[x, 9e-11], -2.0, 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 -11.8:\\
\;\;\;\;t_0\\
\mathbf{elif}\;x \leq -8.2 \cdot 10^{-252}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;x \leq 1.7 \cdot 10^{-245}:\\
\;\;\;\;-2\\
\mathbf{elif}\;x \leq 6 \cdot 10^{-233}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;x \leq 9 \cdot 10^{-11}:\\
\;\;\;\;-2\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if x < -11.800000000000001 or 8.9999999999999999e-11 < x Initial program 100.0%
associate-/l*99.8%
Simplified99.8%
Taylor expanded in x around inf 71.2%
if -11.800000000000001 < x < -8.20000000000000028e-252 or 1.7e-245 < x < 5.99999999999999997e-233Initial program 100.0%
associate-/l*99.6%
Simplified99.6%
Taylor expanded in y around inf 64.3%
associate-*r/64.3%
Simplified64.3%
if -8.20000000000000028e-252 < x < 1.7e-245 or 5.99999999999999997e-233 < x < 8.9999999999999999e-11Initial program 100.0%
associate-/l*99.9%
Simplified99.9%
Taylor expanded in z around inf 62.4%
Final simplification67.4%
(FPCore (x y z) :precision binary64 (if (or (<= y -1.05e+103) (not (<= y 2.45e+135))) (/ (* y -4.0) z) (+ (* 4.0 (/ x z)) -2.0)))
double code(double x, double y, double z) {
double tmp;
if ((y <= -1.05e+103) || !(y <= 2.45e+135)) {
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 <= (-1.05d+103)) .or. (.not. (y <= 2.45d+135))) 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 <= -1.05e+103) || !(y <= 2.45e+135)) {
tmp = (y * -4.0) / z;
} else {
tmp = (4.0 * (x / z)) + -2.0;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -1.05e+103) or not (y <= 2.45e+135): 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 <= -1.05e+103) || !(y <= 2.45e+135)) 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 <= -1.05e+103) || ~((y <= 2.45e+135))) 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, -1.05e+103], N[Not[LessEqual[y, 2.45e+135]], $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 -1.05 \cdot 10^{+103} \lor \neg \left(y \leq 2.45 \cdot 10^{+135}\right):\\
\;\;\;\;\frac{y \cdot -4}{z}\\
\mathbf{else}:\\
\;\;\;\;4 \cdot \frac{x}{z} + -2\\
\end{array}
\end{array}
if y < -1.0500000000000001e103 or 2.4500000000000001e135 < y Initial program 100.0%
associate-/l*99.8%
Simplified99.8%
Taylor expanded in y around inf 77.1%
associate-*r/77.1%
Simplified77.1%
if -1.0500000000000001e103 < y < 2.4500000000000001e135Initial program 100.0%
associate-/l*99.8%
Simplified99.8%
Taylor expanded in y around 0 87.2%
div-sub87.2%
sub-neg87.2%
associate-/l*87.2%
*-inverses87.2%
metadata-eval87.2%
metadata-eval87.2%
distribute-lft-in87.2%
metadata-eval87.2%
Simplified87.2%
Final simplification84.3%
(FPCore (x y z) :precision binary64 (if (or (<= x -45.0) (not (<= x 1.5e-5))) (+ (* 4.0 (/ x z)) -2.0) (- (* -4.0 (/ y z)) 2.0)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -45.0) || !(x <= 1.5e-5)) {
tmp = (4.0 * (x / z)) + -2.0;
} else {
tmp = (-4.0 * (y / 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 ((x <= (-45.0d0)) .or. (.not. (x <= 1.5d-5))) then
tmp = (4.0d0 * (x / z)) + (-2.0d0)
else
tmp = ((-4.0d0) * (y / z)) - 2.0d0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -45.0) || !(x <= 1.5e-5)) {
tmp = (4.0 * (x / z)) + -2.0;
} else {
tmp = (-4.0 * (y / z)) - 2.0;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -45.0) or not (x <= 1.5e-5): tmp = (4.0 * (x / z)) + -2.0 else: tmp = (-4.0 * (y / z)) - 2.0 return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -45.0) || !(x <= 1.5e-5)) tmp = Float64(Float64(4.0 * Float64(x / z)) + -2.0); else tmp = Float64(Float64(-4.0 * Float64(y / z)) - 2.0); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -45.0) || ~((x <= 1.5e-5))) tmp = (4.0 * (x / z)) + -2.0; else tmp = (-4.0 * (y / z)) - 2.0; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -45.0], N[Not[LessEqual[x, 1.5e-5]], $MachinePrecision]], N[(N[(4.0 * N[(x / z), $MachinePrecision]), $MachinePrecision] + -2.0), $MachinePrecision], N[(N[(-4.0 * N[(y / z), $MachinePrecision]), $MachinePrecision] - 2.0), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -45 \lor \neg \left(x \leq 1.5 \cdot 10^{-5}\right):\\
\;\;\;\;4 \cdot \frac{x}{z} + -2\\
\mathbf{else}:\\
\;\;\;\;-4 \cdot \frac{y}{z} - 2\\
\end{array}
\end{array}
if x < -45 or 1.50000000000000004e-5 < x Initial program 100.0%
associate-/l*99.8%
Simplified99.8%
Taylor expanded in y around 0 88.9%
div-sub88.9%
sub-neg88.9%
associate-/l*88.9%
*-inverses88.9%
metadata-eval88.9%
metadata-eval88.9%
distribute-lft-in88.9%
metadata-eval88.9%
Simplified88.9%
if -45 < x < 1.50000000000000004e-5Initial program 100.0%
associate-/l*99.8%
Simplified99.8%
Taylor expanded in z around 0 100.0%
Taylor expanded in x around 0 94.6%
Final simplification91.6%
(FPCore (x y z) :precision binary64 (if (or (<= x -5e-43) (not (<= x 2.9e-11))) (* 4.0 (/ x z)) -2.0))
double code(double x, double y, double z) {
double tmp;
if ((x <= -5e-43) || !(x <= 2.9e-11)) {
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 <= (-5d-43)) .or. (.not. (x <= 2.9d-11))) 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 <= -5e-43) || !(x <= 2.9e-11)) {
tmp = 4.0 * (x / z);
} else {
tmp = -2.0;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -5e-43) or not (x <= 2.9e-11): tmp = 4.0 * (x / z) else: tmp = -2.0 return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -5e-43) || !(x <= 2.9e-11)) 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 <= -5e-43) || ~((x <= 2.9e-11))) tmp = 4.0 * (x / z); else tmp = -2.0; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -5e-43], N[Not[LessEqual[x, 2.9e-11]], $MachinePrecision]], N[(4.0 * N[(x / z), $MachinePrecision]), $MachinePrecision], -2.0]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -5 \cdot 10^{-43} \lor \neg \left(x \leq 2.9 \cdot 10^{-11}\right):\\
\;\;\;\;4 \cdot \frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;-2\\
\end{array}
\end{array}
if x < -5.00000000000000019e-43 or 2.9e-11 < x Initial program 100.0%
associate-/l*99.7%
Simplified99.7%
Taylor expanded in x around inf 67.5%
if -5.00000000000000019e-43 < x < 2.9e-11Initial program 100.0%
associate-/l*99.8%
Simplified99.8%
Taylor expanded in z around inf 53.1%
Final simplification61.3%
(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.4%
Final simplification33.4%
(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 2023178
(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))