
(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 6 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%
*-commutative100.0%
associate-/l*100.0%
*-commutative100.0%
distribute-rgt-out--100.0%
fma-define100.0%
sub-neg100.0%
metadata-eval100.0%
metadata-eval100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x y z) :precision binary64 (if (or (<= y -175000.0) (not (<= y 1.26e+108))) (* x (+ y 0.5)) (+ z (* x 0.5))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -175000.0) || !(y <= 1.26e+108)) {
tmp = x * (y + 0.5);
} 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 <= (-175000.0d0)) .or. (.not. (y <= 1.26d+108))) then
tmp = x * (y + 0.5d0)
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 <= -175000.0) || !(y <= 1.26e+108)) {
tmp = x * (y + 0.5);
} else {
tmp = z + (x * 0.5);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -175000.0) or not (y <= 1.26e+108): tmp = x * (y + 0.5) else: tmp = z + (x * 0.5) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -175000.0) || !(y <= 1.26e+108)) tmp = Float64(x * Float64(y + 0.5)); else tmp = Float64(z + Float64(x * 0.5)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -175000.0) || ~((y <= 1.26e+108))) tmp = x * (y + 0.5); else tmp = z + (x * 0.5); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -175000.0], N[Not[LessEqual[y, 1.26e+108]], $MachinePrecision]], N[(x * N[(y + 0.5), $MachinePrecision]), $MachinePrecision], N[(z + N[(x * 0.5), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -175000 \lor \neg \left(y \leq 1.26 \cdot 10^{+108}\right):\\
\;\;\;\;x \cdot \left(y + 0.5\right)\\
\mathbf{else}:\\
\;\;\;\;z + x \cdot 0.5\\
\end{array}
\end{array}
if y < -175000 or 1.2600000000000001e108 < y Initial program 100.0%
+-commutative100.0%
remove-double-neg100.0%
distribute-frac-neg100.0%
sub-neg100.0%
neg-mul-1100.0%
*-commutative100.0%
associate-/l*100.0%
*-commutative100.0%
distribute-rgt-out--100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in x around inf 75.7%
if -175000 < y < 1.2600000000000001e108Initial program 100.0%
+-commutative100.0%
remove-double-neg100.0%
distribute-frac-neg100.0%
sub-neg100.0%
neg-mul-1100.0%
*-commutative100.0%
associate-/l*100.0%
*-commutative100.0%
distribute-rgt-out--100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in y around 0 94.6%
*-commutative94.6%
Simplified94.6%
Final simplification87.6%
(FPCore (x y z) :precision binary64 (if (<= z -2.2e+68) z (if (<= z 8e+177) (* x (+ y 0.5)) z)))
double code(double x, double y, double z) {
double tmp;
if (z <= -2.2e+68) {
tmp = z;
} else if (z <= 8e+177) {
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 <= (-2.2d+68)) then
tmp = z
else if (z <= 8d+177) 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 <= -2.2e+68) {
tmp = z;
} else if (z <= 8e+177) {
tmp = x * (y + 0.5);
} else {
tmp = z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -2.2e+68: tmp = z elif z <= 8e+177: tmp = x * (y + 0.5) else: tmp = z return tmp
function code(x, y, z) tmp = 0.0 if (z <= -2.2e+68) tmp = z; elseif (z <= 8e+177) 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 <= -2.2e+68) tmp = z; elseif (z <= 8e+177) tmp = x * (y + 0.5); else tmp = z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -2.2e+68], z, If[LessEqual[z, 8e+177], N[(x * N[(y + 0.5), $MachinePrecision]), $MachinePrecision], z]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -2.2 \cdot 10^{+68}:\\
\;\;\;\;z\\
\mathbf{elif}\;z \leq 8 \cdot 10^{+177}:\\
\;\;\;\;x \cdot \left(y + 0.5\right)\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array}
\end{array}
if z < -2.19999999999999987e68 or 8.0000000000000001e177 < z Initial program 100.0%
+-commutative100.0%
remove-double-neg100.0%
distribute-frac-neg100.0%
sub-neg100.0%
neg-mul-1100.0%
*-commutative100.0%
associate-/l*100.0%
*-commutative100.0%
distribute-rgt-out--100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in x around 0 70.3%
if -2.19999999999999987e68 < z < 8.0000000000000001e177Initial program 100.0%
+-commutative100.0%
remove-double-neg100.0%
distribute-frac-neg100.0%
sub-neg100.0%
neg-mul-1100.0%
*-commutative100.0%
associate-/l*100.0%
*-commutative100.0%
distribute-rgt-out--100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in x around inf 78.9%
Final simplification76.7%
(FPCore (x y z) :precision binary64 (if (or (<= y -215000000.0) (not (<= y 7.2e+107))) (* x y) z))
double code(double x, double y, double z) {
double tmp;
if ((y <= -215000000.0) || !(y <= 7.2e+107)) {
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 ((y <= (-215000000.0d0)) .or. (.not. (y <= 7.2d+107))) 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 ((y <= -215000000.0) || !(y <= 7.2e+107)) {
tmp = x * y;
} else {
tmp = z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -215000000.0) or not (y <= 7.2e+107): tmp = x * y else: tmp = z return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -215000000.0) || !(y <= 7.2e+107)) tmp = Float64(x * y); else tmp = z; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -215000000.0) || ~((y <= 7.2e+107))) tmp = x * y; else tmp = z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -215000000.0], N[Not[LessEqual[y, 7.2e+107]], $MachinePrecision]], N[(x * y), $MachinePrecision], z]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -215000000 \lor \neg \left(y \leq 7.2 \cdot 10^{+107}\right):\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array}
\end{array}
if y < -2.15e8 or 7.1999999999999995e107 < y Initial program 100.0%
+-commutative100.0%
remove-double-neg100.0%
distribute-frac-neg100.0%
sub-neg100.0%
neg-mul-1100.0%
*-commutative100.0%
associate-/l*100.0%
*-commutative100.0%
distribute-rgt-out--100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in y around inf 75.6%
if -2.15e8 < y < 7.1999999999999995e107Initial program 100.0%
+-commutative100.0%
remove-double-neg100.0%
distribute-frac-neg100.0%
sub-neg100.0%
neg-mul-1100.0%
*-commutative100.0%
associate-/l*100.0%
*-commutative100.0%
distribute-rgt-out--100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in x around 0 41.5%
Final simplification54.1%
(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-frac-neg100.0%
sub-neg100.0%
neg-mul-1100.0%
*-commutative100.0%
associate-/l*100.0%
*-commutative100.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-frac-neg100.0%
sub-neg100.0%
neg-mul-1100.0%
*-commutative100.0%
associate-/l*100.0%
*-commutative100.0%
distribute-rgt-out--100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in x around 0 35.5%
Final simplification35.5%
herbie shell --seed 2024066
(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))