
(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 (- (/ (- y x) z) -0.5)))
double code(double x, double y, double z) {
return -4.0 * (((y - x) / z) - -0.5);
}
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) * (((y - x) / z) - (-0.5d0))
end function
public static double code(double x, double y, double z) {
return -4.0 * (((y - x) / z) - -0.5);
}
def code(x, y, z): return -4.0 * (((y - x) / z) - -0.5)
function code(x, y, z) return Float64(-4.0 * Float64(Float64(Float64(y - x) / z) - -0.5)) end
function tmp = code(x, y, z) tmp = -4.0 * (((y - x) / z) - -0.5); end
code[x_, y_, z_] := N[(-4.0 * N[(N[(N[(y - x), $MachinePrecision] / z), $MachinePrecision] - -0.5), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
-4 \cdot \left(\frac{y - x}{z} - -0.5\right)
\end{array}
Initial program 100.0%
remove-double-neg100.0%
neg-mul-1100.0%
times-frac100.0%
metadata-eval100.0%
div-sub100.0%
distribute-frac-neg2100.0%
distribute-frac-neg100.0%
sub-neg100.0%
+-commutative100.0%
distribute-neg-out100.0%
remove-double-neg100.0%
sub-neg100.0%
*-commutative100.0%
neg-mul-1100.0%
times-frac100.0%
metadata-eval100.0%
*-inverses100.0%
metadata-eval100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* 4.0 (/ x z))))
(if (<= x -4.9e+27)
t_0
(if (<= x 1.46e-269) (* -4.0 (/ y z)) (if (<= x 1.5e-21) -2.0 t_0)))))
double code(double x, double y, double z) {
double t_0 = 4.0 * (x / z);
double tmp;
if (x <= -4.9e+27) {
tmp = t_0;
} else if (x <= 1.46e-269) {
tmp = -4.0 * (y / z);
} else if (x <= 1.5e-21) {
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 * (x / z)
if (x <= (-4.9d+27)) then
tmp = t_0
else if (x <= 1.46d-269) then
tmp = (-4.0d0) * (y / z)
else if (x <= 1.5d-21) 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 tmp;
if (x <= -4.9e+27) {
tmp = t_0;
} else if (x <= 1.46e-269) {
tmp = -4.0 * (y / z);
} else if (x <= 1.5e-21) {
tmp = -2.0;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = 4.0 * (x / z) tmp = 0 if x <= -4.9e+27: tmp = t_0 elif x <= 1.46e-269: tmp = -4.0 * (y / z) elif x <= 1.5e-21: tmp = -2.0 else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(4.0 * Float64(x / z)) tmp = 0.0 if (x <= -4.9e+27) tmp = t_0; elseif (x <= 1.46e-269) tmp = Float64(-4.0 * Float64(y / z)); elseif (x <= 1.5e-21) tmp = -2.0; else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = 4.0 * (x / z); tmp = 0.0; if (x <= -4.9e+27) tmp = t_0; elseif (x <= 1.46e-269) tmp = -4.0 * (y / z); elseif (x <= 1.5e-21) 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]}, If[LessEqual[x, -4.9e+27], t$95$0, If[LessEqual[x, 1.46e-269], N[(-4.0 * N[(y / z), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 1.5e-21], -2.0, t$95$0]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := 4 \cdot \frac{x}{z}\\
\mathbf{if}\;x \leq -4.9 \cdot 10^{+27}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq 1.46 \cdot 10^{-269}:\\
\;\;\;\;-4 \cdot \frac{y}{z}\\
\mathbf{elif}\;x \leq 1.5 \cdot 10^{-21}:\\
\;\;\;\;-2\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if x < -4.90000000000000015e27 or 1.49999999999999996e-21 < x Initial program 100.0%
*-commutative100.0%
associate-/l*99.7%
associate--l-99.7%
Simplified99.7%
Taylor expanded in x around inf 64.8%
if -4.90000000000000015e27 < x < 1.45999999999999999e-269Initial program 100.0%
*-commutative100.0%
associate-/l*99.8%
associate--l-99.8%
Simplified99.8%
Taylor expanded in y around inf 57.3%
*-commutative57.3%
Simplified57.3%
if 1.45999999999999999e-269 < x < 1.49999999999999996e-21Initial program 100.0%
*-commutative100.0%
associate-/l*99.8%
associate--l-99.8%
Simplified99.8%
Taylor expanded in z around inf 63.4%
Final simplification62.6%
(FPCore (x y z) :precision binary64 (if (or (<= z -455.0) (not (<= z 3.4e+39))) (* -4.0 (- (/ x (- z)) -0.5)) (* (- x y) (/ 4.0 z))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -455.0) || !(z <= 3.4e+39)) {
tmp = -4.0 * ((x / -z) - -0.5);
} else {
tmp = (x - y) * (4.0 / 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 <= (-455.0d0)) .or. (.not. (z <= 3.4d+39))) then
tmp = (-4.0d0) * ((x / -z) - (-0.5d0))
else
tmp = (x - y) * (4.0d0 / z)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -455.0) || !(z <= 3.4e+39)) {
tmp = -4.0 * ((x / -z) - -0.5);
} else {
tmp = (x - y) * (4.0 / z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -455.0) or not (z <= 3.4e+39): tmp = -4.0 * ((x / -z) - -0.5) else: tmp = (x - y) * (4.0 / z) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -455.0) || !(z <= 3.4e+39)) tmp = Float64(-4.0 * Float64(Float64(x / Float64(-z)) - -0.5)); else tmp = Float64(Float64(x - y) * Float64(4.0 / z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -455.0) || ~((z <= 3.4e+39))) tmp = -4.0 * ((x / -z) - -0.5); else tmp = (x - y) * (4.0 / z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -455.0], N[Not[LessEqual[z, 3.4e+39]], $MachinePrecision]], N[(-4.0 * N[(N[(x / (-z)), $MachinePrecision] - -0.5), $MachinePrecision]), $MachinePrecision], N[(N[(x - y), $MachinePrecision] * N[(4.0 / z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -455 \lor \neg \left(z \leq 3.4 \cdot 10^{+39}\right):\\
\;\;\;\;-4 \cdot \left(\frac{x}{-z} - -0.5\right)\\
\mathbf{else}:\\
\;\;\;\;\left(x - y\right) \cdot \frac{4}{z}\\
\end{array}
\end{array}
if z < -455 or 3.3999999999999999e39 < z Initial program 100.0%
remove-double-neg100.0%
neg-mul-1100.0%
times-frac100.0%
metadata-eval100.0%
div-sub100.0%
distribute-frac-neg2100.0%
distribute-frac-neg100.0%
sub-neg100.0%
+-commutative100.0%
distribute-neg-out100.0%
remove-double-neg100.0%
sub-neg100.0%
*-commutative100.0%
neg-mul-1100.0%
times-frac100.0%
metadata-eval100.0%
*-inverses100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in y around 0 85.9%
neg-mul-185.9%
distribute-neg-frac85.9%
Simplified85.9%
if -455 < z < 3.3999999999999999e39Initial program 100.0%
*-commutative100.0%
associate-/l*99.8%
associate--l-99.8%
Simplified99.8%
Taylor expanded in z around 0 93.7%
associate-*r/93.7%
*-commutative93.7%
associate-/l*93.5%
Simplified93.5%
Final simplification90.0%
(FPCore (x y z) :precision binary64 (if (or (<= x -2.6e+172) (not (<= x 5e+117))) (* 4.0 (/ x z)) (* 4.0 (- -0.5 (/ y z)))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -2.6e+172) || !(x <= 5e+117)) {
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 <= (-2.6d+172)) .or. (.not. (x <= 5d+117))) 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 <= -2.6e+172) || !(x <= 5e+117)) {
tmp = 4.0 * (x / z);
} else {
tmp = 4.0 * (-0.5 - (y / z));
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -2.6e+172) or not (x <= 5e+117): 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 <= -2.6e+172) || !(x <= 5e+117)) 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 <= -2.6e+172) || ~((x <= 5e+117))) 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, -2.6e+172], N[Not[LessEqual[x, 5e+117]], $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 -2.6 \cdot 10^{+172} \lor \neg \left(x \leq 5 \cdot 10^{+117}\right):\\
\;\;\;\;4 \cdot \frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;4 \cdot \left(-0.5 - \frac{y}{z}\right)\\
\end{array}
\end{array}
if x < -2.6e172 or 4.99999999999999983e117 < x Initial program 100.0%
*-commutative100.0%
associate-/l*99.7%
associate--l-99.7%
Simplified99.7%
Taylor expanded in x around inf 80.1%
if -2.6e172 < x < 4.99999999999999983e117Initial program 100.0%
*-commutative100.0%
associate-/l*99.8%
associate--l-99.8%
Simplified99.8%
Taylor expanded in x around 0 81.0%
associate-*r/81.0%
metadata-eval81.0%
+-commutative81.0%
*-commutative81.0%
fma-undefine81.0%
associate-*r*81.0%
neg-mul-181.0%
associate-/l*81.0%
fma-undefine81.0%
*-commutative81.0%
distribute-neg-in81.0%
sub-neg81.0%
div-sub81.0%
distribute-neg-frac81.0%
associate-/l*81.0%
*-inverses81.0%
metadata-eval81.0%
metadata-eval81.0%
Simplified81.0%
Final simplification80.7%
(FPCore (x y z) :precision binary64 (if (or (<= x -2.8e-22) (not (<= x 27500.0))) (* (- x y) (/ 4.0 z)) (* 4.0 (- -0.5 (/ y z)))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -2.8e-22) || !(x <= 27500.0)) {
tmp = (x - y) * (4.0 / 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.8d-22)) .or. (.not. (x <= 27500.0d0))) then
tmp = (x - y) * (4.0d0 / 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.8e-22) || !(x <= 27500.0)) {
tmp = (x - y) * (4.0 / z);
} else {
tmp = 4.0 * (-0.5 - (y / z));
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -2.8e-22) or not (x <= 27500.0): tmp = (x - y) * (4.0 / z) else: tmp = 4.0 * (-0.5 - (y / z)) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -2.8e-22) || !(x <= 27500.0)) tmp = Float64(Float64(x - y) * Float64(4.0 / 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.8e-22) || ~((x <= 27500.0))) tmp = (x - y) * (4.0 / z); else tmp = 4.0 * (-0.5 - (y / z)); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -2.8e-22], N[Not[LessEqual[x, 27500.0]], $MachinePrecision]], N[(N[(x - y), $MachinePrecision] * N[(4.0 / 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.8 \cdot 10^{-22} \lor \neg \left(x \leq 27500\right):\\
\;\;\;\;\left(x - y\right) \cdot \frac{4}{z}\\
\mathbf{else}:\\
\;\;\;\;4 \cdot \left(-0.5 - \frac{y}{z}\right)\\
\end{array}
\end{array}
if x < -2.79999999999999995e-22 or 27500 < x Initial program 100.0%
*-commutative100.0%
associate-/l*99.7%
associate--l-99.7%
Simplified99.7%
Taylor expanded in z around 0 86.2%
associate-*r/86.2%
*-commutative86.2%
associate-/l*85.9%
Simplified85.9%
if -2.79999999999999995e-22 < x < 27500Initial program 100.0%
*-commutative100.0%
associate-/l*99.8%
associate--l-99.8%
Simplified99.8%
Taylor expanded in x around 0 94.2%
associate-*r/94.2%
metadata-eval94.2%
+-commutative94.2%
*-commutative94.2%
fma-undefine94.2%
associate-*r*94.2%
neg-mul-194.2%
associate-/l*94.2%
fma-undefine94.2%
*-commutative94.2%
distribute-neg-in94.2%
sub-neg94.2%
div-sub94.2%
distribute-neg-frac94.2%
associate-/l*94.2%
*-inverses94.2%
metadata-eval94.2%
metadata-eval94.2%
Simplified94.2%
Final simplification89.7%
(FPCore (x y z) :precision binary64 (if (or (<= x -2.8e-22) (not (<= x 1.5e-21))) (* 4.0 (/ x z)) -2.0))
double code(double x, double y, double z) {
double tmp;
if ((x <= -2.8e-22) || !(x <= 1.5e-21)) {
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.8d-22)) .or. (.not. (x <= 1.5d-21))) 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.8e-22) || !(x <= 1.5e-21)) {
tmp = 4.0 * (x / z);
} else {
tmp = -2.0;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -2.8e-22) or not (x <= 1.5e-21): tmp = 4.0 * (x / z) else: tmp = -2.0 return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -2.8e-22) || !(x <= 1.5e-21)) 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.8e-22) || ~((x <= 1.5e-21))) tmp = 4.0 * (x / z); else tmp = -2.0; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -2.8e-22], N[Not[LessEqual[x, 1.5e-21]], $MachinePrecision]], N[(4.0 * N[(x / z), $MachinePrecision]), $MachinePrecision], -2.0]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.8 \cdot 10^{-22} \lor \neg \left(x \leq 1.5 \cdot 10^{-21}\right):\\
\;\;\;\;4 \cdot \frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;-2\\
\end{array}
\end{array}
if x < -2.79999999999999995e-22 or 1.49999999999999996e-21 < x Initial program 100.0%
*-commutative100.0%
associate-/l*99.7%
associate--l-99.7%
Simplified99.7%
Taylor expanded in x around inf 63.0%
if -2.79999999999999995e-22 < x < 1.49999999999999996e-21Initial program 100.0%
*-commutative100.0%
associate-/l*99.8%
associate--l-99.8%
Simplified99.8%
Taylor expanded in z around inf 51.8%
Final simplification58.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%
*-commutative100.0%
associate-/l*99.7%
associate--l-99.7%
Simplified99.7%
Taylor expanded in z around inf 31.5%
Final simplification31.5%
(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 2024078
(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))