
(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 4 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 (- -2.0 (* 4.0 (/ (- y x) z))))
double code(double x, double y, double z) {
return -2.0 - (4.0 * ((y - x) / z));
}
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) - (4.0d0 * ((y - x) / z))
end function
public static double code(double x, double y, double z) {
return -2.0 - (4.0 * ((y - x) / z));
}
def code(x, y, z): return -2.0 - (4.0 * ((y - x) / z))
function code(x, y, z) return Float64(-2.0 - Float64(4.0 * Float64(Float64(y - x) / z))) end
function tmp = code(x, y, z) tmp = -2.0 - (4.0 * ((y - x) / z)); end
code[x_, y_, z_] := N[(-2.0 - N[(4.0 * N[(N[(y - x), $MachinePrecision] / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
-2 - 4 \cdot \frac{y - x}{z}
\end{array}
Initial program 100.0%
associate-/l*100.0%
div-sub100.0%
remove-double-neg100.0%
distribute-lft-neg-out100.0%
distribute-frac-neg100.0%
neg-sub0100.0%
associate-+l-100.0%
div-sub97.7%
associate--r+97.7%
add097.7%
div-sub100.0%
distribute-rgt-in100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x y z) :precision binary64 (if (or (<= x -2.05e+132) (not (<= x 3.5e+98))) (+ -2.0 (* 4.0 (/ x z))) (- -2.0 (* 4.0 (/ y z)))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -2.05e+132) || !(x <= 3.5e+98)) {
tmp = -2.0 + (4.0 * (x / z));
} else {
tmp = -2.0 - (4.0 * (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.05d+132)) .or. (.not. (x <= 3.5d+98))) then
tmp = (-2.0d0) + (4.0d0 * (x / z))
else
tmp = (-2.0d0) - (4.0d0 * (y / z))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -2.05e+132) || !(x <= 3.5e+98)) {
tmp = -2.0 + (4.0 * (x / z));
} else {
tmp = -2.0 - (4.0 * (y / z));
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -2.05e+132) or not (x <= 3.5e+98): tmp = -2.0 + (4.0 * (x / z)) else: tmp = -2.0 - (4.0 * (y / z)) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -2.05e+132) || !(x <= 3.5e+98)) tmp = Float64(-2.0 + Float64(4.0 * Float64(x / z))); else tmp = Float64(-2.0 - Float64(4.0 * Float64(y / z))); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -2.05e+132) || ~((x <= 3.5e+98))) tmp = -2.0 + (4.0 * (x / z)); else tmp = -2.0 - (4.0 * (y / z)); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -2.05e+132], N[Not[LessEqual[x, 3.5e+98]], $MachinePrecision]], N[(-2.0 + N[(4.0 * N[(x / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(-2.0 - N[(4.0 * N[(y / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.05 \cdot 10^{+132} \lor \neg \left(x \leq 3.5 \cdot 10^{+98}\right):\\
\;\;\;\;-2 + 4 \cdot \frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;-2 - 4 \cdot \frac{y}{z}\\
\end{array}
\end{array}
if x < -2.04999999999999996e132 or 3.5e98 < x Initial program 100.0%
associate-/l*100.0%
div-sub100.0%
remove-double-neg100.0%
distribute-lft-neg-out100.0%
distribute-frac-neg100.0%
neg-sub0100.0%
associate-+l-100.0%
div-sub96.2%
associate--r+96.2%
add096.2%
div-sub100.0%
distribute-rgt-in100.0%
Simplified100.0%
Taylor expanded in x around inf 88.6%
if -2.04999999999999996e132 < x < 3.5e98Initial program 100.0%
associate-/l*100.0%
div-sub100.0%
remove-double-neg100.0%
distribute-lft-neg-out100.0%
distribute-frac-neg100.0%
neg-sub0100.0%
associate-+l-100.0%
div-sub98.3%
associate--r+98.3%
add098.3%
div-sub100.0%
distribute-rgt-in100.0%
Simplified100.0%
Taylor expanded in x around 0 91.2%
neg-mul-191.2%
distribute-neg-frac291.2%
Simplified91.2%
Final simplification90.4%
(FPCore (x y z) :precision binary64 (+ -2.0 (* x (/ 4.0 z))))
double code(double x, double y, double z) {
return -2.0 + (x * (4.0 / z));
}
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) + (x * (4.0d0 / z))
end function
public static double code(double x, double y, double z) {
return -2.0 + (x * (4.0 / z));
}
def code(x, y, z): return -2.0 + (x * (4.0 / z))
function code(x, y, z) return Float64(-2.0 + Float64(x * Float64(4.0 / z))) end
function tmp = code(x, y, z) tmp = -2.0 + (x * (4.0 / z)); end
code[x_, y_, z_] := N[(-2.0 + N[(x * N[(4.0 / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
-2 + x \cdot \frac{4}{z}
\end{array}
Initial program 100.0%
associate-/l*100.0%
div-sub100.0%
remove-double-neg100.0%
distribute-lft-neg-out100.0%
distribute-frac-neg100.0%
neg-sub0100.0%
associate-+l-100.0%
div-sub97.7%
associate--r+97.7%
add097.7%
div-sub100.0%
distribute-rgt-in100.0%
Simplified100.0%
Taylor expanded in x around inf 59.1%
Taylor expanded in x around 0 59.1%
associate-*r/59.1%
*-commutative59.1%
associate-*r/59.1%
Simplified59.1%
Final simplification59.1%
(FPCore (x y z) :precision binary64 (+ -2.0 (* 4.0 (/ x z))))
double code(double x, double y, double z) {
return -2.0 + (4.0 * (x / z));
}
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) + (4.0d0 * (x / z))
end function
public static double code(double x, double y, double z) {
return -2.0 + (4.0 * (x / z));
}
def code(x, y, z): return -2.0 + (4.0 * (x / z))
function code(x, y, z) return Float64(-2.0 + Float64(4.0 * Float64(x / z))) end
function tmp = code(x, y, z) tmp = -2.0 + (4.0 * (x / z)); end
code[x_, y_, z_] := N[(-2.0 + N[(4.0 * N[(x / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
-2 + 4 \cdot \frac{x}{z}
\end{array}
Initial program 100.0%
associate-/l*100.0%
div-sub100.0%
remove-double-neg100.0%
distribute-lft-neg-out100.0%
distribute-frac-neg100.0%
neg-sub0100.0%
associate-+l-100.0%
div-sub97.7%
associate--r+97.7%
add097.7%
div-sub100.0%
distribute-rgt-in100.0%
Simplified100.0%
Taylor expanded in x around inf 59.1%
Final simplification59.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 2024046
(FPCore (x y z)
:name "Data.Array.Repa.Algorithms.ColorRamp:rampColorHotToCold from repa-algorithms-3.4.0.1, B"
:precision binary64
:alt
(- (* 4.0 (/ x z)) (+ 2.0 (* 4.0 (/ y z))))
(/ (* 4.0 (- (- x y) (* z 0.5))) z))