
(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.7%
/-rgt-identity99.7%
metadata-eval99.7%
metadata-eval99.7%
/-rgt-identity99.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 (/ y z))))
(if (<= y -4.2e+23)
t_0
(if (<= y -1.15e-156)
-2.0
(if (<= y -1.3e-298) (* 4.0 (/ x z)) (if (<= y 2.8e+82) -2.0 t_0))))))
double code(double x, double y, double z) {
double t_0 = -4.0 * (y / z);
double tmp;
if (y <= -4.2e+23) {
tmp = t_0;
} else if (y <= -1.15e-156) {
tmp = -2.0;
} else if (y <= -1.3e-298) {
tmp = 4.0 * (x / z);
} else if (y <= 2.8e+82) {
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) :: tmp
t_0 = (-4.0d0) * (y / z)
if (y <= (-4.2d+23)) then
tmp = t_0
else if (y <= (-1.15d-156)) then
tmp = -2.0d0
else if (y <= (-1.3d-298)) then
tmp = 4.0d0 * (x / z)
else if (y <= 2.8d+82) 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 * (y / z);
double tmp;
if (y <= -4.2e+23) {
tmp = t_0;
} else if (y <= -1.15e-156) {
tmp = -2.0;
} else if (y <= -1.3e-298) {
tmp = 4.0 * (x / z);
} else if (y <= 2.8e+82) {
tmp = -2.0;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = -4.0 * (y / z) tmp = 0 if y <= -4.2e+23: tmp = t_0 elif y <= -1.15e-156: tmp = -2.0 elif y <= -1.3e-298: tmp = 4.0 * (x / z) elif y <= 2.8e+82: tmp = -2.0 else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(-4.0 * Float64(y / z)) tmp = 0.0 if (y <= -4.2e+23) tmp = t_0; elseif (y <= -1.15e-156) tmp = -2.0; elseif (y <= -1.3e-298) tmp = Float64(4.0 * Float64(x / z)); elseif (y <= 2.8e+82) tmp = -2.0; else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = -4.0 * (y / z); tmp = 0.0; if (y <= -4.2e+23) tmp = t_0; elseif (y <= -1.15e-156) tmp = -2.0; elseif (y <= -1.3e-298) tmp = 4.0 * (x / z); elseif (y <= 2.8e+82) tmp = -2.0; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(-4.0 * N[(y / z), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -4.2e+23], t$95$0, If[LessEqual[y, -1.15e-156], -2.0, If[LessEqual[y, -1.3e-298], N[(4.0 * N[(x / z), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 2.8e+82], -2.0, t$95$0]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := -4 \cdot \frac{y}{z}\\
\mathbf{if}\;y \leq -4.2 \cdot 10^{+23}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;y \leq -1.15 \cdot 10^{-156}:\\
\;\;\;\;-2\\
\mathbf{elif}\;y \leq -1.3 \cdot 10^{-298}:\\
\;\;\;\;4 \cdot \frac{x}{z}\\
\mathbf{elif}\;y \leq 2.8 \cdot 10^{+82}:\\
\;\;\;\;-2\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if y < -4.2000000000000003e23 or 2.8e82 < y Initial program 99.9%
associate-*l/99.6%
/-rgt-identity99.6%
metadata-eval99.6%
metadata-eval99.6%
/-rgt-identity99.6%
sub-neg99.6%
distribute-rgt-neg-in99.6%
metadata-eval99.6%
Simplified99.6%
Taylor expanded in y around inf 74.3%
if -4.2000000000000003e23 < y < -1.15e-156 or -1.2999999999999999e-298 < y < 2.8e82Initial program 100.0%
associate-*l/99.8%
/-rgt-identity99.8%
metadata-eval99.8%
metadata-eval99.8%
/-rgt-identity99.8%
sub-neg99.8%
distribute-rgt-neg-in99.8%
metadata-eval99.8%
Simplified99.8%
Taylor expanded in z around inf 54.3%
if -1.15e-156 < y < -1.2999999999999999e-298Initial program 100.0%
associate-*l/99.7%
/-rgt-identity99.7%
metadata-eval99.7%
metadata-eval99.7%
/-rgt-identity99.7%
sub-neg99.7%
distribute-rgt-neg-in99.7%
metadata-eval99.7%
Simplified99.7%
Taylor expanded in x around inf 59.7%
Final simplification63.6%
(FPCore (x y z) :precision binary64 (if (or (<= z -3.8e+88) (not (<= z 1.04e+37))) (- (* -4.0 (/ y z)) 2.0) (* 4.0 (/ (- x y) z))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -3.8e+88) || !(z <= 1.04e+37)) {
tmp = (-4.0 * (y / z)) - 2.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) :: tmp
if ((z <= (-3.8d+88)) .or. (.not. (z <= 1.04d+37))) then
tmp = ((-4.0d0) * (y / z)) - 2.0d0
else
tmp = 4.0d0 * ((x - y) / z)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -3.8e+88) || !(z <= 1.04e+37)) {
tmp = (-4.0 * (y / z)) - 2.0;
} else {
tmp = 4.0 * ((x - y) / z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -3.8e+88) or not (z <= 1.04e+37): tmp = (-4.0 * (y / z)) - 2.0 else: tmp = 4.0 * ((x - y) / z) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -3.8e+88) || !(z <= 1.04e+37)) tmp = Float64(Float64(-4.0 * Float64(y / z)) - 2.0); else tmp = Float64(4.0 * Float64(Float64(x - y) / z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -3.8e+88) || ~((z <= 1.04e+37))) tmp = (-4.0 * (y / z)) - 2.0; else tmp = 4.0 * ((x - y) / z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -3.8e+88], N[Not[LessEqual[z, 1.04e+37]], $MachinePrecision]], N[(N[(-4.0 * N[(y / z), $MachinePrecision]), $MachinePrecision] - 2.0), $MachinePrecision], N[(4.0 * N[(N[(x - y), $MachinePrecision] / z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -3.8 \cdot 10^{+88} \lor \neg \left(z \leq 1.04 \cdot 10^{+37}\right):\\
\;\;\;\;-4 \cdot \frac{y}{z} - 2\\
\mathbf{else}:\\
\;\;\;\;4 \cdot \frac{x - y}{z}\\
\end{array}
\end{array}
if z < -3.7999999999999997e88 or 1.0400000000000001e37 < z Initial program 100.0%
*-commutative100.0%
associate-/l*100.0%
div-sub100.0%
*-lft-identity100.0%
metadata-eval100.0%
associate-/l*99.9%
associate-/r/99.8%
fma-neg99.8%
metadata-eval99.8%
/-rgt-identity99.8%
associate-/r/99.8%
distribute-lft-neg-in99.8%
distribute-frac-neg99.8%
*-commutative99.8%
distribute-lft-neg-in99.8%
associate-/l*99.8%
metadata-eval99.8%
*-inverses99.8%
metadata-eval99.8%
metadata-eval99.8%
Simplified99.8%
Taylor expanded in x around 0 90.9%
if -3.7999999999999997e88 < z < 1.0400000000000001e37Initial program 100.0%
associate-*l/99.7%
/-rgt-identity99.7%
metadata-eval99.7%
metadata-eval99.7%
/-rgt-identity99.7%
sub-neg99.7%
distribute-rgt-neg-in99.7%
metadata-eval99.7%
Simplified99.7%
Taylor expanded in z around 0 91.1%
Final simplification91.0%
(FPCore (x y z) :precision binary64 (if (<= z -6.5e+121) -2.0 (if (<= z 4.9e+122) (* 4.0 (/ (- x y) z)) -2.0)))
double code(double x, double y, double z) {
double tmp;
if (z <= -6.5e+121) {
tmp = -2.0;
} else if (z <= 4.9e+122) {
tmp = 4.0 * ((x - y) / 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 <= (-6.5d+121)) then
tmp = -2.0d0
else if (z <= 4.9d+122) then
tmp = 4.0d0 * ((x - y) / 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 <= -6.5e+121) {
tmp = -2.0;
} else if (z <= 4.9e+122) {
tmp = 4.0 * ((x - y) / z);
} else {
tmp = -2.0;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -6.5e+121: tmp = -2.0 elif z <= 4.9e+122: tmp = 4.0 * ((x - y) / z) else: tmp = -2.0 return tmp
function code(x, y, z) tmp = 0.0 if (z <= -6.5e+121) tmp = -2.0; elseif (z <= 4.9e+122) tmp = Float64(4.0 * Float64(Float64(x - y) / z)); else tmp = -2.0; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -6.5e+121) tmp = -2.0; elseif (z <= 4.9e+122) tmp = 4.0 * ((x - y) / z); else tmp = -2.0; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -6.5e+121], -2.0, If[LessEqual[z, 4.9e+122], N[(4.0 * N[(N[(x - y), $MachinePrecision] / z), $MachinePrecision]), $MachinePrecision], -2.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -6.5 \cdot 10^{+121}:\\
\;\;\;\;-2\\
\mathbf{elif}\;z \leq 4.9 \cdot 10^{+122}:\\
\;\;\;\;4 \cdot \frac{x - y}{z}\\
\mathbf{else}:\\
\;\;\;\;-2\\
\end{array}
\end{array}
if z < -6.50000000000000019e121 or 4.8999999999999998e122 < z Initial program 99.9%
associate-*l/99.7%
/-rgt-identity99.7%
metadata-eval99.7%
metadata-eval99.7%
/-rgt-identity99.7%
sub-neg99.7%
distribute-rgt-neg-in99.7%
metadata-eval99.7%
Simplified99.7%
Taylor expanded in z around inf 73.2%
if -6.50000000000000019e121 < z < 4.8999999999999998e122Initial program 100.0%
associate-*l/99.7%
/-rgt-identity99.7%
metadata-eval99.7%
metadata-eval99.7%
/-rgt-identity99.7%
sub-neg99.7%
distribute-rgt-neg-in99.7%
metadata-eval99.7%
Simplified99.7%
Taylor expanded in z around 0 88.7%
Final simplification83.3%
(FPCore (x y z) :precision binary64 (if (or (<= y -1.16e+15) (not (<= y 2.9e+81))) (* -4.0 (/ y z)) -2.0))
double code(double x, double y, double z) {
double tmp;
if ((y <= -1.16e+15) || !(y <= 2.9e+81)) {
tmp = -4.0 * (y / 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 ((y <= (-1.16d+15)) .or. (.not. (y <= 2.9d+81))) then
tmp = (-4.0d0) * (y / z)
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.16e+15) || !(y <= 2.9e+81)) {
tmp = -4.0 * (y / z);
} else {
tmp = -2.0;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -1.16e+15) or not (y <= 2.9e+81): tmp = -4.0 * (y / z) else: tmp = -2.0 return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -1.16e+15) || !(y <= 2.9e+81)) tmp = Float64(-4.0 * Float64(y / z)); else tmp = -2.0; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -1.16e+15) || ~((y <= 2.9e+81))) tmp = -4.0 * (y / z); else tmp = -2.0; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -1.16e+15], N[Not[LessEqual[y, 2.9e+81]], $MachinePrecision]], N[(-4.0 * N[(y / z), $MachinePrecision]), $MachinePrecision], -2.0]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.16 \cdot 10^{+15} \lor \neg \left(y \leq 2.9 \cdot 10^{+81}\right):\\
\;\;\;\;-4 \cdot \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;-2\\
\end{array}
\end{array}
if y < -1.16e15 or 2.9e81 < y Initial program 99.9%
associate-*l/99.6%
/-rgt-identity99.6%
metadata-eval99.6%
metadata-eval99.6%
/-rgt-identity99.6%
sub-neg99.6%
distribute-rgt-neg-in99.6%
metadata-eval99.6%
Simplified99.6%
Taylor expanded in y around inf 74.3%
if -1.16e15 < y < 2.9e81Initial program 100.0%
associate-*l/99.7%
/-rgt-identity99.7%
metadata-eval99.7%
metadata-eval99.7%
/-rgt-identity99.7%
sub-neg99.7%
distribute-rgt-neg-in99.7%
metadata-eval99.7%
Simplified99.7%
Taylor expanded in z around inf 51.2%
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.7%
/-rgt-identity99.7%
metadata-eval99.7%
metadata-eval99.7%
/-rgt-identity99.7%
sub-neg99.7%
distribute-rgt-neg-in99.7%
metadata-eval99.7%
Simplified99.7%
Taylor expanded in z around inf 34.1%
Final simplification34.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 2023321
(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))