
(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 (+ 0.5 y) x z))
double code(double x, double y, double z) {
return fma((0.5 + y), x, z);
}
function code(x, y, z) return fma(Float64(0.5 + y), x, z) end
code[x_, y_, z_] := N[(N[(0.5 + y), $MachinePrecision] * x + z), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(0.5 + y, x, z\right)
\end{array}
Initial program 100.0%
associate-+l+100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in x around 0 100.0%
+-commutative100.0%
fma-def100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x y z)
:precision binary64
(if (<= y -7.5e+54)
(* y x)
(if (<= y -2.9e-61)
z
(if (<= y -1.6e-203)
(* 0.5 x)
(if (<= y 2.85e-300)
z
(if (<= y 6.2e-157)
(* 0.5 x)
(if (<= y 5.2e-88)
z
(if (<= y 2e-31) (* 0.5 x) (if (<= y 1.25e+19) z (* y x))))))))))
double code(double x, double y, double z) {
double tmp;
if (y <= -7.5e+54) {
tmp = y * x;
} else if (y <= -2.9e-61) {
tmp = z;
} else if (y <= -1.6e-203) {
tmp = 0.5 * x;
} else if (y <= 2.85e-300) {
tmp = z;
} else if (y <= 6.2e-157) {
tmp = 0.5 * x;
} else if (y <= 5.2e-88) {
tmp = z;
} else if (y <= 2e-31) {
tmp = 0.5 * x;
} else if (y <= 1.25e+19) {
tmp = z;
} else {
tmp = y * x;
}
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 <= (-7.5d+54)) then
tmp = y * x
else if (y <= (-2.9d-61)) then
tmp = z
else if (y <= (-1.6d-203)) then
tmp = 0.5d0 * x
else if (y <= 2.85d-300) then
tmp = z
else if (y <= 6.2d-157) then
tmp = 0.5d0 * x
else if (y <= 5.2d-88) then
tmp = z
else if (y <= 2d-31) then
tmp = 0.5d0 * x
else if (y <= 1.25d+19) then
tmp = z
else
tmp = y * x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= -7.5e+54) {
tmp = y * x;
} else if (y <= -2.9e-61) {
tmp = z;
} else if (y <= -1.6e-203) {
tmp = 0.5 * x;
} else if (y <= 2.85e-300) {
tmp = z;
} else if (y <= 6.2e-157) {
tmp = 0.5 * x;
} else if (y <= 5.2e-88) {
tmp = z;
} else if (y <= 2e-31) {
tmp = 0.5 * x;
} else if (y <= 1.25e+19) {
tmp = z;
} else {
tmp = y * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -7.5e+54: tmp = y * x elif y <= -2.9e-61: tmp = z elif y <= -1.6e-203: tmp = 0.5 * x elif y <= 2.85e-300: tmp = z elif y <= 6.2e-157: tmp = 0.5 * x elif y <= 5.2e-88: tmp = z elif y <= 2e-31: tmp = 0.5 * x elif y <= 1.25e+19: tmp = z else: tmp = y * x return tmp
function code(x, y, z) tmp = 0.0 if (y <= -7.5e+54) tmp = Float64(y * x); elseif (y <= -2.9e-61) tmp = z; elseif (y <= -1.6e-203) tmp = Float64(0.5 * x); elseif (y <= 2.85e-300) tmp = z; elseif (y <= 6.2e-157) tmp = Float64(0.5 * x); elseif (y <= 5.2e-88) tmp = z; elseif (y <= 2e-31) tmp = Float64(0.5 * x); elseif (y <= 1.25e+19) tmp = z; else tmp = Float64(y * x); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -7.5e+54) tmp = y * x; elseif (y <= -2.9e-61) tmp = z; elseif (y <= -1.6e-203) tmp = 0.5 * x; elseif (y <= 2.85e-300) tmp = z; elseif (y <= 6.2e-157) tmp = 0.5 * x; elseif (y <= 5.2e-88) tmp = z; elseif (y <= 2e-31) tmp = 0.5 * x; elseif (y <= 1.25e+19) tmp = z; else tmp = y * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -7.5e+54], N[(y * x), $MachinePrecision], If[LessEqual[y, -2.9e-61], z, If[LessEqual[y, -1.6e-203], N[(0.5 * x), $MachinePrecision], If[LessEqual[y, 2.85e-300], z, If[LessEqual[y, 6.2e-157], N[(0.5 * x), $MachinePrecision], If[LessEqual[y, 5.2e-88], z, If[LessEqual[y, 2e-31], N[(0.5 * x), $MachinePrecision], If[LessEqual[y, 1.25e+19], z, N[(y * x), $MachinePrecision]]]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -7.5 \cdot 10^{+54}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;y \leq -2.9 \cdot 10^{-61}:\\
\;\;\;\;z\\
\mathbf{elif}\;y \leq -1.6 \cdot 10^{-203}:\\
\;\;\;\;0.5 \cdot x\\
\mathbf{elif}\;y \leq 2.85 \cdot 10^{-300}:\\
\;\;\;\;z\\
\mathbf{elif}\;y \leq 6.2 \cdot 10^{-157}:\\
\;\;\;\;0.5 \cdot x\\
\mathbf{elif}\;y \leq 5.2 \cdot 10^{-88}:\\
\;\;\;\;z\\
\mathbf{elif}\;y \leq 2 \cdot 10^{-31}:\\
\;\;\;\;0.5 \cdot x\\
\mathbf{elif}\;y \leq 1.25 \cdot 10^{+19}:\\
\;\;\;\;z\\
\mathbf{else}:\\
\;\;\;\;y \cdot x\\
\end{array}
\end{array}
if y < -7.50000000000000042e54 or 1.25e19 < y Initial program 100.0%
associate-+l+100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in y around inf 73.6%
if -7.50000000000000042e54 < y < -2.8999999999999999e-61 or -1.6e-203 < y < 2.8499999999999999e-300 or 6.1999999999999996e-157 < y < 5.20000000000000027e-88 or 2e-31 < y < 1.25e19Initial program 100.0%
associate-+l+100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in x around 0 73.7%
if -2.8999999999999999e-61 < y < -1.6e-203 or 2.8499999999999999e-300 < y < 6.1999999999999996e-157 or 5.20000000000000027e-88 < y < 2e-31Initial program 100.0%
associate-+l+100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in x around inf 71.0%
Taylor expanded in y around 0 71.0%
Final simplification73.0%
(FPCore (x y z) :precision binary64 (if (or (<= z -1.1e-66) (not (<= z 5.5e-7))) (+ z (* y x)) (* (+ 0.5 y) x)))
double code(double x, double y, double z) {
double tmp;
if ((z <= -1.1e-66) || !(z <= 5.5e-7)) {
tmp = z + (y * x);
} else {
tmp = (0.5 + y) * x;
}
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 <= (-1.1d-66)) .or. (.not. (z <= 5.5d-7))) then
tmp = z + (y * x)
else
tmp = (0.5d0 + y) * x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -1.1e-66) || !(z <= 5.5e-7)) {
tmp = z + (y * x);
} else {
tmp = (0.5 + y) * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -1.1e-66) or not (z <= 5.5e-7): tmp = z + (y * x) else: tmp = (0.5 + y) * x return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -1.1e-66) || !(z <= 5.5e-7)) tmp = Float64(z + Float64(y * x)); else tmp = Float64(Float64(0.5 + y) * x); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -1.1e-66) || ~((z <= 5.5e-7))) tmp = z + (y * x); else tmp = (0.5 + y) * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -1.1e-66], N[Not[LessEqual[z, 5.5e-7]], $MachinePrecision]], N[(z + N[(y * x), $MachinePrecision]), $MachinePrecision], N[(N[(0.5 + y), $MachinePrecision] * x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.1 \cdot 10^{-66} \lor \neg \left(z \leq 5.5 \cdot 10^{-7}\right):\\
\;\;\;\;z + y \cdot x\\
\mathbf{else}:\\
\;\;\;\;\left(0.5 + y\right) \cdot x\\
\end{array}
\end{array}
if z < -1.1000000000000001e-66 or 5.5000000000000003e-7 < z Initial program 100.0%
associate-+l+100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in x around 0 100.0%
*-commutative100.0%
flip-+84.5%
associate-*r/81.2%
metadata-eval81.2%
Applied egg-rr81.2%
*-commutative81.2%
associate-/l*84.0%
Simplified84.0%
Taylor expanded in y around inf 87.8%
if -1.1000000000000001e-66 < z < 5.5000000000000003e-7Initial program 100.0%
associate-+l+100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in x around inf 87.1%
Final simplification87.5%
(FPCore (x y z) :precision binary64 (if (or (<= y -500000000000.0) (not (<= y 0.5))) (+ z (* y x)) (+ z (* 0.5 x))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -500000000000.0) || !(y <= 0.5)) {
tmp = z + (y * x);
} else {
tmp = z + (0.5 * x);
}
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 <= (-500000000000.0d0)) .or. (.not. (y <= 0.5d0))) then
tmp = z + (y * x)
else
tmp = z + (0.5d0 * x)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -500000000000.0) || !(y <= 0.5)) {
tmp = z + (y * x);
} else {
tmp = z + (0.5 * x);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -500000000000.0) or not (y <= 0.5): tmp = z + (y * x) else: tmp = z + (0.5 * x) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -500000000000.0) || !(y <= 0.5)) tmp = Float64(z + Float64(y * x)); else tmp = Float64(z + Float64(0.5 * x)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -500000000000.0) || ~((y <= 0.5))) tmp = z + (y * x); else tmp = z + (0.5 * x); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -500000000000.0], N[Not[LessEqual[y, 0.5]], $MachinePrecision]], N[(z + N[(y * x), $MachinePrecision]), $MachinePrecision], N[(z + N[(0.5 * x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -500000000000 \lor \neg \left(y \leq 0.5\right):\\
\;\;\;\;z + y \cdot x\\
\mathbf{else}:\\
\;\;\;\;z + 0.5 \cdot x\\
\end{array}
\end{array}
if y < -5e11 or 0.5 < y Initial program 99.9%
associate-+l+99.9%
*-commutative99.9%
Simplified99.9%
Taylor expanded in x around 0 100.0%
*-commutative100.0%
flip-+68.5%
associate-*r/61.7%
metadata-eval61.7%
Applied egg-rr61.7%
*-commutative61.7%
associate-/l*66.1%
Simplified66.1%
Taylor expanded in y around inf 99.7%
if -5e11 < y < 0.5Initial program 100.0%
associate-+l+100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in y around 0 99.4%
Final simplification99.5%
(FPCore (x y z) :precision binary64 (if (<= z -1.95e+137) z (if (<= z 0.00045) (* (+ 0.5 y) x) z)))
double code(double x, double y, double z) {
double tmp;
if (z <= -1.95e+137) {
tmp = z;
} else if (z <= 0.00045) {
tmp = (0.5 + y) * x;
} 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 <= (-1.95d+137)) then
tmp = z
else if (z <= 0.00045d0) then
tmp = (0.5d0 + y) * x
else
tmp = z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (z <= -1.95e+137) {
tmp = z;
} else if (z <= 0.00045) {
tmp = (0.5 + y) * x;
} else {
tmp = z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -1.95e+137: tmp = z elif z <= 0.00045: tmp = (0.5 + y) * x else: tmp = z return tmp
function code(x, y, z) tmp = 0.0 if (z <= -1.95e+137) tmp = z; elseif (z <= 0.00045) tmp = Float64(Float64(0.5 + y) * x); else tmp = z; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -1.95e+137) tmp = z; elseif (z <= 0.00045) tmp = (0.5 + y) * x; else tmp = z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -1.95e+137], z, If[LessEqual[z, 0.00045], N[(N[(0.5 + y), $MachinePrecision] * x), $MachinePrecision], z]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.95 \cdot 10^{+137}:\\
\;\;\;\;z\\
\mathbf{elif}\;z \leq 0.00045:\\
\;\;\;\;\left(0.5 + y\right) \cdot x\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array}
\end{array}
if z < -1.95000000000000015e137 or 4.4999999999999999e-4 < z Initial program 100.0%
associate-+l+100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in x around 0 76.5%
if -1.95000000000000015e137 < z < 4.4999999999999999e-4Initial program 100.0%
associate-+l+100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in x around inf 81.1%
Final simplification79.1%
(FPCore (x y z) :precision binary64 (if (<= z -1.6e-67) z (if (<= z 5.5e-7) (* 0.5 x) z)))
double code(double x, double y, double z) {
double tmp;
if (z <= -1.6e-67) {
tmp = z;
} else if (z <= 5.5e-7) {
tmp = 0.5 * x;
} 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 <= (-1.6d-67)) then
tmp = z
else if (z <= 5.5d-7) then
tmp = 0.5d0 * x
else
tmp = z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (z <= -1.6e-67) {
tmp = z;
} else if (z <= 5.5e-7) {
tmp = 0.5 * x;
} else {
tmp = z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -1.6e-67: tmp = z elif z <= 5.5e-7: tmp = 0.5 * x else: tmp = z return tmp
function code(x, y, z) tmp = 0.0 if (z <= -1.6e-67) tmp = z; elseif (z <= 5.5e-7) tmp = Float64(0.5 * x); else tmp = z; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -1.6e-67) tmp = z; elseif (z <= 5.5e-7) tmp = 0.5 * x; else tmp = z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -1.6e-67], z, If[LessEqual[z, 5.5e-7], N[(0.5 * x), $MachinePrecision], z]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.6 \cdot 10^{-67}:\\
\;\;\;\;z\\
\mathbf{elif}\;z \leq 5.5 \cdot 10^{-7}:\\
\;\;\;\;0.5 \cdot x\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array}
\end{array}
if z < -1.60000000000000011e-67 or 5.5000000000000003e-7 < z Initial program 100.0%
associate-+l+100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in x around 0 68.7%
if -1.60000000000000011e-67 < z < 5.5000000000000003e-7Initial program 100.0%
associate-+l+100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in x around inf 87.1%
Taylor expanded in y around 0 43.3%
Final simplification57.4%
(FPCore (x y z) :precision binary64 (+ z (* (+ 0.5 y) x)))
double code(double x, double y, double z) {
return z + ((0.5 + y) * x);
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = z + ((0.5d0 + y) * x)
end function
public static double code(double x, double y, double z) {
return z + ((0.5 + y) * x);
}
def code(x, y, z): return z + ((0.5 + y) * x)
function code(x, y, z) return Float64(z + Float64(Float64(0.5 + y) * x)) end
function tmp = code(x, y, z) tmp = z + ((0.5 + y) * x); end
code[x_, y_, z_] := N[(z + N[(N[(0.5 + y), $MachinePrecision] * x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
z + \left(0.5 + y\right) \cdot x
\end{array}
Initial program 100.0%
associate-+l+100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in x around 0 100.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 44.1%
Final simplification44.1%
herbie shell --seed 2023195
(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))