
(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 8 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 (fma x (+ y 0.5) z))
double code(double x, double y, double z) {
return fma(x, (y + 0.5), z);
}
function code(x, y, z) return fma(x, Float64(y + 0.5), z) end
code[x_, y_, z_] := N[(x * N[(y + 0.5), $MachinePrecision] + z), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(x, y + 0.5, z\right)
\end{array}
Initial program 100.0%
+-commutative100.0%
remove-double-neg100.0%
distribute-frac-neg100.0%
sub-neg100.0%
neg-mul-1100.0%
associate-/l*99.9%
associate-/r/100.0%
distribute-rgt-out--100.0%
fma-def100.0%
sub-neg100.0%
metadata-eval100.0%
metadata-eval100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x y z)
:precision binary64
(if (<= y -9.2e+17)
(* x y)
(if (<= y -1.55e-97)
z
(if (<= y -5.1e-213)
(* x 0.5)
(if (<= y -4.7e-296)
z
(if (<= y 5e-246)
(* x 0.5)
(if (<= y 2e-108)
z
(if (<= y 9.6e-52)
(* x 0.5)
(if (<= y 1.55e+55) z (* x y))))))))))
double code(double x, double y, double z) {
double tmp;
if (y <= -9.2e+17) {
tmp = x * y;
} else if (y <= -1.55e-97) {
tmp = z;
} else if (y <= -5.1e-213) {
tmp = x * 0.5;
} else if (y <= -4.7e-296) {
tmp = z;
} else if (y <= 5e-246) {
tmp = x * 0.5;
} else if (y <= 2e-108) {
tmp = z;
} else if (y <= 9.6e-52) {
tmp = x * 0.5;
} else if (y <= 1.55e+55) {
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 <= (-9.2d+17)) then
tmp = x * y
else if (y <= (-1.55d-97)) then
tmp = z
else if (y <= (-5.1d-213)) then
tmp = x * 0.5d0
else if (y <= (-4.7d-296)) then
tmp = z
else if (y <= 5d-246) then
tmp = x * 0.5d0
else if (y <= 2d-108) then
tmp = z
else if (y <= 9.6d-52) then
tmp = x * 0.5d0
else if (y <= 1.55d+55) 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 <= -9.2e+17) {
tmp = x * y;
} else if (y <= -1.55e-97) {
tmp = z;
} else if (y <= -5.1e-213) {
tmp = x * 0.5;
} else if (y <= -4.7e-296) {
tmp = z;
} else if (y <= 5e-246) {
tmp = x * 0.5;
} else if (y <= 2e-108) {
tmp = z;
} else if (y <= 9.6e-52) {
tmp = x * 0.5;
} else if (y <= 1.55e+55) {
tmp = z;
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -9.2e+17: tmp = x * y elif y <= -1.55e-97: tmp = z elif y <= -5.1e-213: tmp = x * 0.5 elif y <= -4.7e-296: tmp = z elif y <= 5e-246: tmp = x * 0.5 elif y <= 2e-108: tmp = z elif y <= 9.6e-52: tmp = x * 0.5 elif y <= 1.55e+55: tmp = z else: tmp = x * y return tmp
function code(x, y, z) tmp = 0.0 if (y <= -9.2e+17) tmp = Float64(x * y); elseif (y <= -1.55e-97) tmp = z; elseif (y <= -5.1e-213) tmp = Float64(x * 0.5); elseif (y <= -4.7e-296) tmp = z; elseif (y <= 5e-246) tmp = Float64(x * 0.5); elseif (y <= 2e-108) tmp = z; elseif (y <= 9.6e-52) tmp = Float64(x * 0.5); elseif (y <= 1.55e+55) tmp = z; else tmp = Float64(x * y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -9.2e+17) tmp = x * y; elseif (y <= -1.55e-97) tmp = z; elseif (y <= -5.1e-213) tmp = x * 0.5; elseif (y <= -4.7e-296) tmp = z; elseif (y <= 5e-246) tmp = x * 0.5; elseif (y <= 2e-108) tmp = z; elseif (y <= 9.6e-52) tmp = x * 0.5; elseif (y <= 1.55e+55) tmp = z; else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -9.2e+17], N[(x * y), $MachinePrecision], If[LessEqual[y, -1.55e-97], z, If[LessEqual[y, -5.1e-213], N[(x * 0.5), $MachinePrecision], If[LessEqual[y, -4.7e-296], z, If[LessEqual[y, 5e-246], N[(x * 0.5), $MachinePrecision], If[LessEqual[y, 2e-108], z, If[LessEqual[y, 9.6e-52], N[(x * 0.5), $MachinePrecision], If[LessEqual[y, 1.55e+55], z, N[(x * y), $MachinePrecision]]]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -9.2 \cdot 10^{+17}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;y \leq -1.55 \cdot 10^{-97}:\\
\;\;\;\;z\\
\mathbf{elif}\;y \leq -5.1 \cdot 10^{-213}:\\
\;\;\;\;x \cdot 0.5\\
\mathbf{elif}\;y \leq -4.7 \cdot 10^{-296}:\\
\;\;\;\;z\\
\mathbf{elif}\;y \leq 5 \cdot 10^{-246}:\\
\;\;\;\;x \cdot 0.5\\
\mathbf{elif}\;y \leq 2 \cdot 10^{-108}:\\
\;\;\;\;z\\
\mathbf{elif}\;y \leq 9.6 \cdot 10^{-52}:\\
\;\;\;\;x \cdot 0.5\\
\mathbf{elif}\;y \leq 1.55 \cdot 10^{+55}:\\
\;\;\;\;z\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if y < -9.2e17 or 1.54999999999999997e55 < y Initial program 100.0%
associate-+l+100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in y around inf 72.7%
if -9.2e17 < y < -1.55000000000000001e-97 or -5.0999999999999997e-213 < y < -4.7e-296 or 4.9999999999999997e-246 < y < 2.00000000000000008e-108 or 9.6000000000000007e-52 < y < 1.54999999999999997e55Initial program 100.0%
associate-+l+100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in x around 0 67.9%
if -1.55000000000000001e-97 < y < -5.0999999999999997e-213 or -4.7e-296 < y < 4.9999999999999997e-246 or 2.00000000000000008e-108 < y < 9.6000000000000007e-52Initial program 100.0%
associate-+l+100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in x around inf 71.9%
Taylor expanded in y around 0 71.9%
*-commutative71.9%
Simplified71.9%
Final simplification70.8%
(FPCore (x y z) :precision binary64 (if (or (<= x -4.6e-12) (not (<= x 8e-64))) (* x (+ y 0.5)) z))
double code(double x, double y, double z) {
double tmp;
if ((x <= -4.6e-12) || !(x <= 8e-64)) {
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 <= (-4.6d-12)) .or. (.not. (x <= 8d-64))) 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 <= -4.6e-12) || !(x <= 8e-64)) {
tmp = x * (y + 0.5);
} else {
tmp = z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -4.6e-12) or not (x <= 8e-64): tmp = x * (y + 0.5) else: tmp = z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -4.6e-12) || !(x <= 8e-64)) 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 <= -4.6e-12) || ~((x <= 8e-64))) tmp = x * (y + 0.5); else tmp = z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -4.6e-12], N[Not[LessEqual[x, 8e-64]], $MachinePrecision]], N[(x * N[(y + 0.5), $MachinePrecision]), $MachinePrecision], z]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -4.6 \cdot 10^{-12} \lor \neg \left(x \leq 8 \cdot 10^{-64}\right):\\
\;\;\;\;x \cdot \left(y + 0.5\right)\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array}
\end{array}
if x < -4.59999999999999979e-12 or 7.99999999999999972e-64 < x Initial program 100.0%
associate-+l+100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in x around inf 82.3%
if -4.59999999999999979e-12 < x < 7.99999999999999972e-64Initial program 100.0%
associate-+l+100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in x around 0 71.9%
Final simplification77.7%
(FPCore (x y z) :precision binary64 (if (or (<= z -3.6e+14) (not (<= z 1.6e-56))) (+ z (* x y)) (* x (+ y 0.5))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -3.6e+14) || !(z <= 1.6e-56)) {
tmp = z + (x * y);
} else {
tmp = x * (y + 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 ((z <= (-3.6d+14)) .or. (.not. (z <= 1.6d-56))) then
tmp = z + (x * y)
else
tmp = x * (y + 0.5d0)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -3.6e+14) || !(z <= 1.6e-56)) {
tmp = z + (x * y);
} else {
tmp = x * (y + 0.5);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -3.6e+14) or not (z <= 1.6e-56): tmp = z + (x * y) else: tmp = x * (y + 0.5) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -3.6e+14) || !(z <= 1.6e-56)) tmp = Float64(z + Float64(x * y)); else tmp = Float64(x * Float64(y + 0.5)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -3.6e+14) || ~((z <= 1.6e-56))) tmp = z + (x * y); else tmp = x * (y + 0.5); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -3.6e+14], N[Not[LessEqual[z, 1.6e-56]], $MachinePrecision]], N[(z + N[(x * y), $MachinePrecision]), $MachinePrecision], N[(x * N[(y + 0.5), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -3.6 \cdot 10^{+14} \lor \neg \left(z \leq 1.6 \cdot 10^{-56}\right):\\
\;\;\;\;z + x \cdot y\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(y + 0.5\right)\\
\end{array}
\end{array}
if z < -3.6e14 or 1.59999999999999993e-56 < z 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%
distribute-rgt-neg-out100.0%
unsub-neg100.0%
neg-mul-1100.0%
associate-/l*99.9%
associate-/r/100.0%
distribute-rgt-out--100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in y around inf 86.6%
mul-1-neg86.6%
distribute-rgt-neg-out86.6%
Simplified86.6%
*-commutative86.6%
cancel-sign-sub86.6%
*-commutative86.6%
+-commutative86.6%
Applied egg-rr86.6%
if -3.6e14 < z < 1.59999999999999993e-56Initial program 100.0%
associate-+l+100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in x around inf 89.8%
Final simplification87.9%
(FPCore (x y z) :precision binary64 (if (or (<= y -0.5) (not (<= y 3.4e-12))) (+ z (* x y)) (- z (* x -0.5))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -0.5) || !(y <= 3.4e-12)) {
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 <= 3.4d-12))) 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 <= 3.4e-12)) {
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 <= 3.4e-12): 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 <= 3.4e-12)) 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 <= 3.4e-12))) 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, 3.4e-12]], $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 3.4 \cdot 10^{-12}\right):\\
\;\;\;\;z + x \cdot y\\
\mathbf{else}:\\
\;\;\;\;z - x \cdot -0.5\\
\end{array}
\end{array}
if y < -0.5 or 3.4000000000000001e-12 < 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%
distribute-rgt-neg-out100.0%
unsub-neg100.0%
neg-mul-1100.0%
associate-/l*100.0%
associate-/r/100.0%
distribute-rgt-out--100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in y around inf 99.5%
mul-1-neg99.5%
distribute-rgt-neg-out99.5%
Simplified99.5%
*-commutative99.5%
cancel-sign-sub99.5%
*-commutative99.5%
+-commutative99.5%
Applied egg-rr99.5%
if -0.5 < y < 3.4000000000000001e-12Initial 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%
distribute-rgt-neg-out100.0%
unsub-neg100.0%
neg-mul-1100.0%
associate-/l*99.8%
associate-/r/100.0%
distribute-rgt-out--100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in y around 0 99.4%
*-commutative99.4%
Simplified99.4%
Final simplification99.5%
(FPCore (x y z) :precision binary64 (if (<= z -2.6e+14) z (if (<= z 3.7e-109) (* x 0.5) z)))
double code(double x, double y, double z) {
double tmp;
if (z <= -2.6e+14) {
tmp = z;
} else if (z <= 3.7e-109) {
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 (z <= (-2.6d+14)) then
tmp = z
else if (z <= 3.7d-109) 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 (z <= -2.6e+14) {
tmp = z;
} else if (z <= 3.7e-109) {
tmp = x * 0.5;
} else {
tmp = z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -2.6e+14: tmp = z elif z <= 3.7e-109: tmp = x * 0.5 else: tmp = z return tmp
function code(x, y, z) tmp = 0.0 if (z <= -2.6e+14) tmp = z; elseif (z <= 3.7e-109) tmp = Float64(x * 0.5); else tmp = z; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -2.6e+14) tmp = z; elseif (z <= 3.7e-109) tmp = x * 0.5; else tmp = z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -2.6e+14], z, If[LessEqual[z, 3.7e-109], N[(x * 0.5), $MachinePrecision], z]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -2.6 \cdot 10^{+14}:\\
\;\;\;\;z\\
\mathbf{elif}\;z \leq 3.7 \cdot 10^{-109}:\\
\;\;\;\;x \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array}
\end{array}
if z < -2.6e14 or 3.69999999999999981e-109 < z Initial program 100.0%
associate-+l+100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in x around 0 62.9%
if -2.6e14 < z < 3.69999999999999981e-109Initial program 100.0%
associate-+l+100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in x around inf 90.9%
Taylor expanded in y around 0 43.6%
*-commutative43.6%
Simplified43.6%
Final simplification55.3%
(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%
distribute-rgt-neg-out100.0%
unsub-neg100.0%
neg-mul-1100.0%
associate-/l*99.9%
associate-/r/100.0%
distribute-rgt-out--100.0%
metadata-eval100.0%
Simplified100.0%
Final simplification100.0%
(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 42.3%
Final simplification42.3%
herbie shell --seed 2023332
(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))