
(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 (<= z -20.0)
z
(if (or (<= z 9.4e+42) (and (not (<= z 3e+145)) (<= z 2.3e+183)))
(* x (+ y 0.5))
z)))
double code(double x, double y, double z) {
double tmp;
if (z <= -20.0) {
tmp = z;
} else if ((z <= 9.4e+42) || (!(z <= 3e+145) && (z <= 2.3e+183))) {
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 (z <= (-20.0d0)) then
tmp = z
else if ((z <= 9.4d+42) .or. (.not. (z <= 3d+145)) .and. (z <= 2.3d+183)) 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 (z <= -20.0) {
tmp = z;
} else if ((z <= 9.4e+42) || (!(z <= 3e+145) && (z <= 2.3e+183))) {
tmp = x * (y + 0.5);
} else {
tmp = z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -20.0: tmp = z elif (z <= 9.4e+42) or (not (z <= 3e+145) and (z <= 2.3e+183)): tmp = x * (y + 0.5) else: tmp = z return tmp
function code(x, y, z) tmp = 0.0 if (z <= -20.0) tmp = z; elseif ((z <= 9.4e+42) || (!(z <= 3e+145) && (z <= 2.3e+183))) 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 (z <= -20.0) tmp = z; elseif ((z <= 9.4e+42) || (~((z <= 3e+145)) && (z <= 2.3e+183))) tmp = x * (y + 0.5); else tmp = z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -20.0], z, If[Or[LessEqual[z, 9.4e+42], And[N[Not[LessEqual[z, 3e+145]], $MachinePrecision], LessEqual[z, 2.3e+183]]], N[(x * N[(y + 0.5), $MachinePrecision]), $MachinePrecision], z]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -20:\\
\;\;\;\;z\\
\mathbf{elif}\;z \leq 9.4 \cdot 10^{+42} \lor \neg \left(z \leq 3 \cdot 10^{+145}\right) \land z \leq 2.3 \cdot 10^{+183}:\\
\;\;\;\;x \cdot \left(y + 0.5\right)\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array}
\end{array}
if z < -20 or 9.39999999999999971e42 < z < 3.0000000000000002e145 or 2.2999999999999998e183 < 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*100.0%
associate-/r/100.0%
distribute-rgt-out--100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in y around inf 91.0%
associate-*r*91.0%
neg-mul-191.0%
Simplified91.0%
Taylor expanded in z around inf 76.7%
if -20 < z < 9.39999999999999971e42 or 3.0000000000000002e145 < z < 2.2999999999999998e183Initial program 100.0%
associate-+l+100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in x around inf 86.9%
+-commutative86.9%
Simplified86.9%
Final simplification81.9%
(FPCore (x y z)
:precision binary64
(if (<= z -2.3e-44)
z
(if (<= z 7.5e-296)
(* x y)
(if (<= z 5.8e-226) (* x 0.5) (if (<= z 4e+32) (* x y) z)))))
double code(double x, double y, double z) {
double tmp;
if (z <= -2.3e-44) {
tmp = z;
} else if (z <= 7.5e-296) {
tmp = x * y;
} else if (z <= 5.8e-226) {
tmp = x * 0.5;
} else if (z <= 4e+32) {
tmp = x * y;
} 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.3d-44)) then
tmp = z
else if (z <= 7.5d-296) then
tmp = x * y
else if (z <= 5.8d-226) then
tmp = x * 0.5d0
else if (z <= 4d+32) then
tmp = x * y
else
tmp = z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (z <= -2.3e-44) {
tmp = z;
} else if (z <= 7.5e-296) {
tmp = x * y;
} else if (z <= 5.8e-226) {
tmp = x * 0.5;
} else if (z <= 4e+32) {
tmp = x * y;
} else {
tmp = z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -2.3e-44: tmp = z elif z <= 7.5e-296: tmp = x * y elif z <= 5.8e-226: tmp = x * 0.5 elif z <= 4e+32: tmp = x * y else: tmp = z return tmp
function code(x, y, z) tmp = 0.0 if (z <= -2.3e-44) tmp = z; elseif (z <= 7.5e-296) tmp = Float64(x * y); elseif (z <= 5.8e-226) tmp = Float64(x * 0.5); elseif (z <= 4e+32) tmp = Float64(x * y); else tmp = z; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -2.3e-44) tmp = z; elseif (z <= 7.5e-296) tmp = x * y; elseif (z <= 5.8e-226) tmp = x * 0.5; elseif (z <= 4e+32) tmp = x * y; else tmp = z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -2.3e-44], z, If[LessEqual[z, 7.5e-296], N[(x * y), $MachinePrecision], If[LessEqual[z, 5.8e-226], N[(x * 0.5), $MachinePrecision], If[LessEqual[z, 4e+32], N[(x * y), $MachinePrecision], z]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -2.3 \cdot 10^{-44}:\\
\;\;\;\;z\\
\mathbf{elif}\;z \leq 7.5 \cdot 10^{-296}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;z \leq 5.8 \cdot 10^{-226}:\\
\;\;\;\;x \cdot 0.5\\
\mathbf{elif}\;z \leq 4 \cdot 10^{+32}:\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array}
\end{array}
if z < -2.29999999999999998e-44 or 4.00000000000000021e32 < 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*100.0%
associate-/r/100.0%
distribute-rgt-out--100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in y around inf 86.5%
associate-*r*86.5%
neg-mul-186.5%
Simplified86.5%
Taylor expanded in z around inf 69.7%
if -2.29999999999999998e-44 < z < 7.49999999999999991e-296 or 5.80000000000000003e-226 < z < 4.00000000000000021e32Initial program 100.0%
associate-+l+100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in x around inf 88.6%
+-commutative88.6%
Simplified88.6%
Taylor expanded in y around inf 55.4%
if 7.49999999999999991e-296 < z < 5.80000000000000003e-226Initial program 100.0%
associate-+l+100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in x around inf 100.0%
+-commutative100.0%
Simplified100.0%
Taylor expanded in y around 0 100.0%
*-commutative100.0%
Simplified100.0%
Final simplification64.6%
(FPCore (x y z) :precision binary64 (if (or (<= z -9.5e-16) (not (<= z 0.029))) (+ z (* x y)) (* x (+ y 0.5))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -9.5e-16) || !(z <= 0.029)) {
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 <= (-9.5d-16)) .or. (.not. (z <= 0.029d0))) 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 <= -9.5e-16) || !(z <= 0.029)) {
tmp = z + (x * y);
} else {
tmp = x * (y + 0.5);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -9.5e-16) or not (z <= 0.029): tmp = z + (x * y) else: tmp = x * (y + 0.5) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -9.5e-16) || !(z <= 0.029)) 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 <= -9.5e-16) || ~((z <= 0.029))) tmp = z + (x * y); else tmp = x * (y + 0.5); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -9.5e-16], N[Not[LessEqual[z, 0.029]], $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 -9.5 \cdot 10^{-16} \lor \neg \left(z \leq 0.029\right):\\
\;\;\;\;z + x \cdot y\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(y + 0.5\right)\\
\end{array}
\end{array}
if z < -9.5000000000000005e-16 or 0.0290000000000000015 < 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*100.0%
associate-/r/100.0%
distribute-rgt-out--100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in y around inf 88.5%
associate-*r*88.5%
neg-mul-188.5%
Simplified88.5%
cancel-sign-sub88.5%
+-commutative88.5%
Applied egg-rr88.5%
if -9.5000000000000005e-16 < z < 0.0290000000000000015Initial program 100.0%
associate-+l+100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in x around inf 88.5%
+-commutative88.5%
Simplified88.5%
Final simplification88.5%
(FPCore (x y z) :precision binary64 (if (or (<= y -102000.0) (not (<= y 0.00132))) (+ z (* x y)) (- z (* x -0.5))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -102000.0) || !(y <= 0.00132)) {
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 <= (-102000.0d0)) .or. (.not. (y <= 0.00132d0))) 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 <= -102000.0) || !(y <= 0.00132)) {
tmp = z + (x * y);
} else {
tmp = z - (x * -0.5);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -102000.0) or not (y <= 0.00132): tmp = z + (x * y) else: tmp = z - (x * -0.5) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -102000.0) || !(y <= 0.00132)) 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 <= -102000.0) || ~((y <= 0.00132))) tmp = z + (x * y); else tmp = z - (x * -0.5); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -102000.0], N[Not[LessEqual[y, 0.00132]], $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 -102000 \lor \neg \left(y \leq 0.00132\right):\\
\;\;\;\;z + x \cdot y\\
\mathbf{else}:\\
\;\;\;\;z - x \cdot -0.5\\
\end{array}
\end{array}
if y < -102000 or 0.00132 < 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.4%
associate-*r*99.4%
neg-mul-199.4%
Simplified99.4%
cancel-sign-sub99.4%
+-commutative99.4%
Applied egg-rr99.4%
if -102000 < y < 0.00132Initial 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 0 99.4%
*-commutative99.4%
Simplified99.4%
Final simplification99.4%
(FPCore (x y z) :precision binary64 (if (<= z -8e-16) z (if (<= z 0.065) (* x 0.5) z)))
double code(double x, double y, double z) {
double tmp;
if (z <= -8e-16) {
tmp = z;
} else if (z <= 0.065) {
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 <= (-8d-16)) then
tmp = z
else if (z <= 0.065d0) 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 <= -8e-16) {
tmp = z;
} else if (z <= 0.065) {
tmp = x * 0.5;
} else {
tmp = z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -8e-16: tmp = z elif z <= 0.065: tmp = x * 0.5 else: tmp = z return tmp
function code(x, y, z) tmp = 0.0 if (z <= -8e-16) tmp = z; elseif (z <= 0.065) tmp = Float64(x * 0.5); else tmp = z; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -8e-16) tmp = z; elseif (z <= 0.065) tmp = x * 0.5; else tmp = z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -8e-16], z, If[LessEqual[z, 0.065], N[(x * 0.5), $MachinePrecision], z]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -8 \cdot 10^{-16}:\\
\;\;\;\;z\\
\mathbf{elif}\;z \leq 0.065:\\
\;\;\;\;x \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array}
\end{array}
if z < -7.9999999999999998e-16 or 0.065000000000000002 < 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*100.0%
associate-/r/100.0%
distribute-rgt-out--100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in y around inf 88.4%
associate-*r*88.4%
neg-mul-188.4%
Simplified88.4%
Taylor expanded in z around inf 69.5%
if -7.9999999999999998e-16 < z < 0.065000000000000002Initial program 100.0%
associate-+l+100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in x around inf 88.6%
+-commutative88.6%
Simplified88.6%
Taylor expanded in y around 0 42.7%
*-commutative42.7%
Simplified42.7%
Final simplification57.6%
(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%
+-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 75.5%
associate-*r*75.5%
neg-mul-175.5%
Simplified75.5%
Taylor expanded in z around inf 44.3%
Final simplification44.3%
herbie shell --seed 2024040
(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))