
(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%
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 (let* ((t_0 (+ (* x y) (/ x 2.0)))) (if (or (<= t_0 -1.5e-62) (not (<= t_0 5e+90))) (* x (+ y 0.5)) z)))
double code(double x, double y, double z) {
double t_0 = (x * y) + (x / 2.0);
double tmp;
if ((t_0 <= -1.5e-62) || !(t_0 <= 5e+90)) {
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) :: t_0
real(8) :: tmp
t_0 = (x * y) + (x / 2.0d0)
if ((t_0 <= (-1.5d-62)) .or. (.not. (t_0 <= 5d+90))) 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 t_0 = (x * y) + (x / 2.0);
double tmp;
if ((t_0 <= -1.5e-62) || !(t_0 <= 5e+90)) {
tmp = x * (y + 0.5);
} else {
tmp = z;
}
return tmp;
}
def code(x, y, z): t_0 = (x * y) + (x / 2.0) tmp = 0 if (t_0 <= -1.5e-62) or not (t_0 <= 5e+90): tmp = x * (y + 0.5) else: tmp = z return tmp
function code(x, y, z) t_0 = Float64(Float64(x * y) + Float64(x / 2.0)) tmp = 0.0 if ((t_0 <= -1.5e-62) || !(t_0 <= 5e+90)) tmp = Float64(x * Float64(y + 0.5)); else tmp = z; end return tmp end
function tmp_2 = code(x, y, z) t_0 = (x * y) + (x / 2.0); tmp = 0.0; if ((t_0 <= -1.5e-62) || ~((t_0 <= 5e+90))) tmp = x * (y + 0.5); else tmp = z; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(x * y), $MachinePrecision] + N[(x / 2.0), $MachinePrecision]), $MachinePrecision]}, If[Or[LessEqual[t$95$0, -1.5e-62], N[Not[LessEqual[t$95$0, 5e+90]], $MachinePrecision]], N[(x * N[(y + 0.5), $MachinePrecision]), $MachinePrecision], z]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot y + \frac{x}{2}\\
\mathbf{if}\;t\_0 \leq -1.5 \cdot 10^{-62} \lor \neg \left(t\_0 \leq 5 \cdot 10^{+90}\right):\\
\;\;\;\;x \cdot \left(y + 0.5\right)\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array}
\end{array}
if (+.f64 (/.f64 x #s(literal 2 binary64)) (*.f64 y x)) < -1.5000000000000001e-62 or 5.0000000000000004e90 < (+.f64 (/.f64 x #s(literal 2 binary64)) (*.f64 y x)) 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%
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 z around 0 81.2%
if -1.5000000000000001e-62 < (+.f64 (/.f64 x #s(literal 2 binary64)) (*.f64 y x)) < 5.0000000000000004e90Initial 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%
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 z around inf 72.8%
Final simplification77.9%
(FPCore (x y z)
:precision binary64
(if (<= y -4.6e+35)
(* x y)
(if (<= y -1.4e-123)
z
(if (<= y 2.75e-143) (* x 0.5) (if (<= y 4.3e+52) z (* x y))))))
double code(double x, double y, double z) {
double tmp;
if (y <= -4.6e+35) {
tmp = x * y;
} else if (y <= -1.4e-123) {
tmp = z;
} else if (y <= 2.75e-143) {
tmp = x * 0.5;
} else if (y <= 4.3e+52) {
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 <= (-4.6d+35)) then
tmp = x * y
else if (y <= (-1.4d-123)) then
tmp = z
else if (y <= 2.75d-143) then
tmp = x * 0.5d0
else if (y <= 4.3d+52) 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 <= -4.6e+35) {
tmp = x * y;
} else if (y <= -1.4e-123) {
tmp = z;
} else if (y <= 2.75e-143) {
tmp = x * 0.5;
} else if (y <= 4.3e+52) {
tmp = z;
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -4.6e+35: tmp = x * y elif y <= -1.4e-123: tmp = z elif y <= 2.75e-143: tmp = x * 0.5 elif y <= 4.3e+52: tmp = z else: tmp = x * y return tmp
function code(x, y, z) tmp = 0.0 if (y <= -4.6e+35) tmp = Float64(x * y); elseif (y <= -1.4e-123) tmp = z; elseif (y <= 2.75e-143) tmp = Float64(x * 0.5); elseif (y <= 4.3e+52) tmp = z; else tmp = Float64(x * y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -4.6e+35) tmp = x * y; elseif (y <= -1.4e-123) tmp = z; elseif (y <= 2.75e-143) tmp = x * 0.5; elseif (y <= 4.3e+52) tmp = z; else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -4.6e+35], N[(x * y), $MachinePrecision], If[LessEqual[y, -1.4e-123], z, If[LessEqual[y, 2.75e-143], N[(x * 0.5), $MachinePrecision], If[LessEqual[y, 4.3e+52], z, N[(x * y), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -4.6 \cdot 10^{+35}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;y \leq -1.4 \cdot 10^{-123}:\\
\;\;\;\;z\\
\mathbf{elif}\;y \leq 2.75 \cdot 10^{-143}:\\
\;\;\;\;x \cdot 0.5\\
\mathbf{elif}\;y \leq 4.3 \cdot 10^{+52}:\\
\;\;\;\;z\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if y < -4.5999999999999996e35 or 4.3e52 < 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%
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 75.6%
if -4.5999999999999996e35 < y < -1.3999999999999999e-123 or 2.75000000000000021e-143 < y < 4.3e52Initial 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%
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 z around inf 65.1%
if -1.3999999999999999e-123 < y < 2.75000000000000021e-143Initial 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%
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 z around 0 61.8%
Taylor expanded in y around 0 61.8%
*-commutative61.8%
Simplified61.8%
(FPCore (x y z) :precision binary64 (if (or (<= y -0.5) (not (<= y 1.75e-9))) (+ z (* x y)) (- z (* x -0.5))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -0.5) || !(y <= 1.75e-9)) {
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 <= 1.75d-9))) 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 <= 1.75e-9)) {
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 <= 1.75e-9): 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 <= 1.75e-9)) 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 <= 1.75e-9))) 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, 1.75e-9]], $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 1.75 \cdot 10^{-9}\right):\\
\;\;\;\;z + x \cdot y\\
\mathbf{else}:\\
\;\;\;\;z - x \cdot -0.5\\
\end{array}
\end{array}
if y < -0.5 or 1.75e-9 < 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%
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 99.1%
mul-1-neg99.1%
distribute-rgt-neg-out99.1%
Simplified99.1%
sub-neg99.1%
distribute-rgt-neg-out99.1%
remove-double-neg99.1%
+-commutative99.1%
Applied egg-rr99.1%
if -0.5 < y < 1.75e-9Initial 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%
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 99.0%
*-commutative99.0%
Simplified99.0%
Final simplification99.0%
(FPCore (x y z) :precision binary64 (if (or (<= z -2.5e+25) (not (<= z 1.55e+18))) (+ z (* x y)) (* x (+ y 0.5))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -2.5e+25) || !(z <= 1.55e+18)) {
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 <= (-2.5d+25)) .or. (.not. (z <= 1.55d+18))) 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 <= -2.5e+25) || !(z <= 1.55e+18)) {
tmp = z + (x * y);
} else {
tmp = x * (y + 0.5);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -2.5e+25) or not (z <= 1.55e+18): tmp = z + (x * y) else: tmp = x * (y + 0.5) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -2.5e+25) || !(z <= 1.55e+18)) 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 <= -2.5e+25) || ~((z <= 1.55e+18))) tmp = z + (x * y); else tmp = x * (y + 0.5); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -2.5e+25], N[Not[LessEqual[z, 1.55e+18]], $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 -2.5 \cdot 10^{+25} \lor \neg \left(z \leq 1.55 \cdot 10^{+18}\right):\\
\;\;\;\;z + x \cdot y\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(y + 0.5\right)\\
\end{array}
\end{array}
if z < -2.50000000000000012e25 or 1.55e18 < 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%
*-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 94.3%
mul-1-neg94.3%
distribute-rgt-neg-out94.3%
Simplified94.3%
sub-neg94.3%
distribute-rgt-neg-out94.3%
remove-double-neg94.3%
+-commutative94.3%
Applied egg-rr94.3%
if -2.50000000000000012e25 < z < 1.55e18Initial 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%
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 z around 0 83.6%
Final simplification88.7%
(FPCore (x y z) :precision binary64 (if (<= z -3.7e+25) z (if (<= z 5.5e-84) (* x 0.5) z)))
double code(double x, double y, double z) {
double tmp;
if (z <= -3.7e+25) {
tmp = z;
} else if (z <= 5.5e-84) {
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 <= (-3.7d+25)) then
tmp = z
else if (z <= 5.5d-84) 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 <= -3.7e+25) {
tmp = z;
} else if (z <= 5.5e-84) {
tmp = x * 0.5;
} else {
tmp = z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -3.7e+25: tmp = z elif z <= 5.5e-84: tmp = x * 0.5 else: tmp = z return tmp
function code(x, y, z) tmp = 0.0 if (z <= -3.7e+25) tmp = z; elseif (z <= 5.5e-84) tmp = Float64(x * 0.5); else tmp = z; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -3.7e+25) tmp = z; elseif (z <= 5.5e-84) tmp = x * 0.5; else tmp = z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -3.7e+25], z, If[LessEqual[z, 5.5e-84], N[(x * 0.5), $MachinePrecision], z]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -3.7 \cdot 10^{+25}:\\
\;\;\;\;z\\
\mathbf{elif}\;z \leq 5.5 \cdot 10^{-84}:\\
\;\;\;\;x \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array}
\end{array}
if z < -3.6999999999999999e25 or 5.50000000000000019e-84 < 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%
*-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 z around inf 60.7%
if -3.6999999999999999e25 < z < 5.50000000000000019e-84Initial 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%
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 z around 0 86.0%
Taylor expanded in y around 0 47.8%
*-commutative47.8%
Simplified47.8%
(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%
+-commutative100.0%
remove-double-neg100.0%
distribute-neg-in100.0%
distribute-frac-neg100.0%
distribute-rgt-neg-out100.0%
unsub-neg100.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 z around inf 40.2%
herbie shell --seed 2024193
(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))