
(FPCore (x y z) :precision binary64 (+ (+ (/ x 2.0) (* y x)) z))
double code(double x, double y, double z) {
return ((x / 2.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 = ((x / 2.0d0) + (y * x)) + z
end function
public static double code(double x, double y, double z) {
return ((x / 2.0) + (y * x)) + z;
}
def code(x, y, z): return ((x / 2.0) + (y * x)) + z
function code(x, y, z) return Float64(Float64(Float64(x / 2.0) + Float64(y * x)) + z) end
function tmp = code(x, y, z) tmp = ((x / 2.0) + (y * x)) + z; end
code[x_, y_, z_] := N[(N[(N[(x / 2.0), $MachinePrecision] + N[(y * x), $MachinePrecision]), $MachinePrecision] + z), $MachinePrecision]
\begin{array}{l}
\\
\left(\frac{x}{2} + y \cdot x\right) + z
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 7 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (+ (+ (/ x 2.0) (* y x)) z))
double code(double x, double y, double z) {
return ((x / 2.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 = ((x / 2.0d0) + (y * x)) + z
end function
public static double code(double x, double y, double z) {
return ((x / 2.0) + (y * x)) + z;
}
def code(x, y, z): return ((x / 2.0) + (y * x)) + z
function code(x, y, z) return Float64(Float64(Float64(x / 2.0) + Float64(y * x)) + z) end
function tmp = code(x, y, z) tmp = ((x / 2.0) + (y * x)) + z; end
code[x_, y_, z_] := N[(N[(N[(x / 2.0), $MachinePrecision] + N[(y * x), $MachinePrecision]), $MachinePrecision] + z), $MachinePrecision]
\begin{array}{l}
\\
\left(\frac{x}{2} + y \cdot x\right) + z
\end{array}
(FPCore (x y z) :precision binary64 (+ z (* x (- y -0.5))))
double code(double x, double y, double z) {
return z + (x * (y - -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 = z + (x * (y - (-0.5d0)))
end function
public static double code(double x, double y, double z) {
return z + (x * (y - -0.5));
}
def code(x, y, z): return z + (x * (y - -0.5))
function code(x, y, z) return Float64(z + Float64(x * Float64(y - -0.5))) end
function tmp = code(x, y, z) tmp = z + (x * (y - -0.5)); end
code[x_, y_, z_] := N[(z + N[(x * N[(y - -0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
z + x \cdot \left(y - -0.5\right)
\end{array}
Initial program 100.0%
+-commutative100.0%
remove-double-neg100.0%
distribute-neg-in100.0%
distribute-frac-neg100.0%
distribute-rgt-neg-out100.0%
unsub-neg100.0%
+-commutative100.0%
+-commutative100.0%
*-commutative100.0%
cancel-sign-sub-inv100.0%
neg-mul-1100.0%
*-commutative100.0%
associate-/l*100.0%
distribute-lft-out--100.0%
metadata-eval100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x y z)
:precision binary64
(if (<= y -800000.0)
(* x y)
(if (<= y -4.4e-159)
z
(if (<= y 5.7e-303) (* x 0.5) (if (<= y 9.2e+37) z (* x y))))))
double code(double x, double y, double z) {
double tmp;
if (y <= -800000.0) {
tmp = x * y;
} else if (y <= -4.4e-159) {
tmp = z;
} else if (y <= 5.7e-303) {
tmp = x * 0.5;
} else if (y <= 9.2e+37) {
tmp = z;
} else {
tmp = x * y;
}
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 <= (-800000.0d0)) then
tmp = x * y
else if (y <= (-4.4d-159)) then
tmp = z
else if (y <= 5.7d-303) then
tmp = x * 0.5d0
else if (y <= 9.2d+37) then
tmp = z
else
tmp = x * y
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= -800000.0) {
tmp = x * y;
} else if (y <= -4.4e-159) {
tmp = z;
} else if (y <= 5.7e-303) {
tmp = x * 0.5;
} else if (y <= 9.2e+37) {
tmp = z;
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -800000.0: tmp = x * y elif y <= -4.4e-159: tmp = z elif y <= 5.7e-303: tmp = x * 0.5 elif y <= 9.2e+37: tmp = z else: tmp = x * y return tmp
function code(x, y, z) tmp = 0.0 if (y <= -800000.0) tmp = Float64(x * y); elseif (y <= -4.4e-159) tmp = z; elseif (y <= 5.7e-303) tmp = Float64(x * 0.5); elseif (y <= 9.2e+37) tmp = z; else tmp = Float64(x * y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -800000.0) tmp = x * y; elseif (y <= -4.4e-159) tmp = z; elseif (y <= 5.7e-303) tmp = x * 0.5; elseif (y <= 9.2e+37) tmp = z; else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -800000.0], N[(x * y), $MachinePrecision], If[LessEqual[y, -4.4e-159], z, If[LessEqual[y, 5.7e-303], N[(x * 0.5), $MachinePrecision], If[LessEqual[y, 9.2e+37], z, N[(x * y), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -800000:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;y \leq -4.4 \cdot 10^{-159}:\\
\;\;\;\;z\\
\mathbf{elif}\;y \leq 5.7 \cdot 10^{-303}:\\
\;\;\;\;x \cdot 0.5\\
\mathbf{elif}\;y \leq 9.2 \cdot 10^{+37}:\\
\;\;\;\;z\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if y < -8e5 or 9.2000000000000001e37 < y Initial program 100.0%
associate-+l+100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in y around inf 73.5%
if -8e5 < y < -4.4e-159 or 5.69999999999999981e-303 < y < 9.2000000000000001e37Initial program 100.0%
associate-+l+100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in x around 0 60.2%
if -4.4e-159 < y < 5.69999999999999981e-303Initial program 100.0%
associate-+l+100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in x around inf 82.6%
Taylor expanded in y around 0 82.6%
*-commutative82.6%
Simplified82.6%
(FPCore (x y z) :precision binary64 (if (or (<= y -0.5) (not (<= y 7.6e-5))) (+ z (* x y)) (- z (* x -0.5))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -0.5) || !(y <= 7.6e-5)) {
tmp = z + (x * y);
} else {
tmp = z - (x * -0.5);
}
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 <= (-0.5d0)) .or. (.not. (y <= 7.6d-5))) then
tmp = z + (x * y)
else
tmp = z - (x * (-0.5d0))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -0.5) || !(y <= 7.6e-5)) {
tmp = z + (x * y);
} else {
tmp = z - (x * -0.5);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -0.5) or not (y <= 7.6e-5): tmp = z + (x * y) else: tmp = z - (x * -0.5) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -0.5) || !(y <= 7.6e-5)) tmp = Float64(z + Float64(x * y)); else tmp = Float64(z - Float64(x * -0.5)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -0.5) || ~((y <= 7.6e-5))) tmp = z + (x * y); else tmp = z - (x * -0.5); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -0.5], N[Not[LessEqual[y, 7.6e-5]], $MachinePrecision]], N[(z + N[(x * y), $MachinePrecision]), $MachinePrecision], N[(z - N[(x * -0.5), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -0.5 \lor \neg \left(y \leq 7.6 \cdot 10^{-5}\right):\\
\;\;\;\;z + x \cdot y\\
\mathbf{else}:\\
\;\;\;\;z - x \cdot -0.5\\
\end{array}
\end{array}
if y < -0.5 or 7.6000000000000004e-5 < y Initial program 100.0%
+-commutative100.0%
remove-double-neg100.0%
distribute-neg-in100.0%
distribute-frac-neg100.0%
distribute-rgt-neg-out100.0%
unsub-neg100.0%
+-commutative100.0%
+-commutative100.0%
*-commutative100.0%
cancel-sign-sub-inv100.0%
neg-mul-1100.0%
*-commutative100.0%
associate-/l*100.0%
distribute-lft-out--100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in y around inf 98.6%
mul-1-neg98.6%
distribute-rgt-neg-out98.6%
Simplified98.6%
sub-neg98.6%
+-commutative98.6%
distribute-rgt-neg-out98.6%
remove-double-neg98.6%
Applied egg-rr98.6%
if -0.5 < y < 7.6000000000000004e-5Initial program 100.0%
+-commutative100.0%
remove-double-neg100.0%
distribute-neg-in100.0%
distribute-frac-neg100.0%
distribute-rgt-neg-out100.0%
unsub-neg100.0%
+-commutative100.0%
+-commutative100.0%
*-commutative100.0%
cancel-sign-sub-inv100.0%
neg-mul-1100.0%
*-commutative100.0%
associate-/l*100.0%
distribute-lft-out--100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in y around 0 98.2%
*-commutative98.2%
Simplified98.2%
Final simplification98.4%
(FPCore (x y z) :precision binary64 (if (or (<= x -7e+37) (not (<= x 1.26e-120))) (* x (+ y 0.5)) (+ z (* x y))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -7e+37) || !(x <= 1.26e-120)) {
tmp = x * (y + 0.5);
} else {
tmp = z + (x * y);
}
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 <= (-7d+37)) .or. (.not. (x <= 1.26d-120))) then
tmp = x * (y + 0.5d0)
else
tmp = z + (x * y)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -7e+37) || !(x <= 1.26e-120)) {
tmp = x * (y + 0.5);
} else {
tmp = z + (x * y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -7e+37) or not (x <= 1.26e-120): tmp = x * (y + 0.5) else: tmp = z + (x * y) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -7e+37) || !(x <= 1.26e-120)) tmp = Float64(x * Float64(y + 0.5)); else tmp = Float64(z + Float64(x * y)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -7e+37) || ~((x <= 1.26e-120))) tmp = x * (y + 0.5); else tmp = z + (x * y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -7e+37], N[Not[LessEqual[x, 1.26e-120]], $MachinePrecision]], N[(x * N[(y + 0.5), $MachinePrecision]), $MachinePrecision], N[(z + N[(x * y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -7 \cdot 10^{+37} \lor \neg \left(x \leq 1.26 \cdot 10^{-120}\right):\\
\;\;\;\;x \cdot \left(y + 0.5\right)\\
\mathbf{else}:\\
\;\;\;\;z + x \cdot y\\
\end{array}
\end{array}
if x < -7e37 or 1.25999999999999992e-120 < x Initial program 100.0%
associate-+l+100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in x around inf 87.2%
if -7e37 < x < 1.25999999999999992e-120Initial program 100.0%
+-commutative100.0%
remove-double-neg100.0%
distribute-neg-in100.0%
distribute-frac-neg100.0%
distribute-rgt-neg-out100.0%
unsub-neg100.0%
+-commutative100.0%
+-commutative100.0%
*-commutative100.0%
cancel-sign-sub-inv100.0%
neg-mul-1100.0%
*-commutative100.0%
associate-/l*100.0%
distribute-lft-out--100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in y around inf 92.4%
mul-1-neg92.4%
distribute-rgt-neg-out92.4%
Simplified92.4%
sub-neg92.4%
+-commutative92.4%
distribute-rgt-neg-out92.4%
remove-double-neg92.4%
Applied egg-rr92.4%
Final simplification89.4%
(FPCore (x y z) :precision binary64 (if (or (<= x -4e-59) (not (<= x 3.1e-134))) (* x (+ y 0.5)) z))
double code(double x, double y, double z) {
double tmp;
if ((x <= -4e-59) || !(x <= 3.1e-134)) {
tmp = x * (y + 0.5);
} else {
tmp = 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 <= (-4d-59)) .or. (.not. (x <= 3.1d-134))) then
tmp = x * (y + 0.5d0)
else
tmp = z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -4e-59) || !(x <= 3.1e-134)) {
tmp = x * (y + 0.5);
} else {
tmp = z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -4e-59) or not (x <= 3.1e-134): tmp = x * (y + 0.5) else: tmp = z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -4e-59) || !(x <= 3.1e-134)) tmp = Float64(x * Float64(y + 0.5)); else tmp = z; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -4e-59) || ~((x <= 3.1e-134))) tmp = x * (y + 0.5); else tmp = z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -4e-59], N[Not[LessEqual[x, 3.1e-134]], $MachinePrecision]], N[(x * N[(y + 0.5), $MachinePrecision]), $MachinePrecision], z]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -4 \cdot 10^{-59} \lor \neg \left(x \leq 3.1 \cdot 10^{-134}\right):\\
\;\;\;\;x \cdot \left(y + 0.5\right)\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array}
\end{array}
if x < -4.0000000000000001e-59 or 3.10000000000000006e-134 < x Initial program 100.0%
associate-+l+100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in x around inf 84.7%
if -4.0000000000000001e-59 < x < 3.10000000000000006e-134Initial program 100.0%
associate-+l+100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in x around 0 83.0%
Final simplification84.1%
(FPCore (x y z) :precision binary64 (if (or (<= x -1050000000.0) (not (<= x 1.26e-120))) (* x 0.5) z))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1050000000.0) || !(x <= 1.26e-120)) {
tmp = x * 0.5;
} else {
tmp = 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 <= (-1050000000.0d0)) .or. (.not. (x <= 1.26d-120))) then
tmp = x * 0.5d0
else
tmp = z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -1050000000.0) || !(x <= 1.26e-120)) {
tmp = x * 0.5;
} else {
tmp = z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -1050000000.0) or not (x <= 1.26e-120): tmp = x * 0.5 else: tmp = z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -1050000000.0) || !(x <= 1.26e-120)) tmp = Float64(x * 0.5); else tmp = z; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -1050000000.0) || ~((x <= 1.26e-120))) tmp = x * 0.5; else tmp = z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -1050000000.0], N[Not[LessEqual[x, 1.26e-120]], $MachinePrecision]], N[(x * 0.5), $MachinePrecision], z]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1050000000 \lor \neg \left(x \leq 1.26 \cdot 10^{-120}\right):\\
\;\;\;\;x \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array}
\end{array}
if x < -1.05e9 or 1.25999999999999992e-120 < x Initial program 100.0%
associate-+l+100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in x around inf 86.8%
Taylor expanded in y around 0 36.7%
*-commutative36.7%
Simplified36.7%
if -1.05e9 < x < 1.25999999999999992e-120Initial program 100.0%
associate-+l+100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in x around 0 74.3%
Final simplification52.6%
(FPCore (x y z) :precision binary64 z)
double code(double x, double y, double z) {
return z;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = z
end function
public static double code(double x, double y, double z) {
return z;
}
def code(x, y, z): return z
function code(x, y, z) return z end
function tmp = code(x, y, z) tmp = z; end
code[x_, y_, z_] := z
\begin{array}{l}
\\
z
\end{array}
Initial program 100.0%
associate-+l+100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in x around 0 40.1%
herbie shell --seed 2024180
(FPCore (x y z)
:name "Data.Histogram.Bin.BinF:$cfromIndex from histogram-fill-0.8.4.1"
:precision binary64
(+ (+ (/ x 2.0) (* y x)) z))