
(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 5 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%
lift-+.f64N/A
lift-+.f64N/A
lift-/.f64N/A
div-invN/A
lift-*.f64N/A
*-commutativeN/A
distribute-lft-outN/A
*-commutativeN/A
lower-fma.f64N/A
lower-+.f64N/A
metadata-eval100.0
Applied rewrites100.0%
(FPCore (x y z) :precision binary64 (if (<= y -6.8e+55) (* y x) (if (<= y 5e+66) (fma 0.5 x z) (* (- y -0.5) x))))
double code(double x, double y, double z) {
double tmp;
if (y <= -6.8e+55) {
tmp = y * x;
} else if (y <= 5e+66) {
tmp = fma(0.5, x, z);
} else {
tmp = (y - -0.5) * x;
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (y <= -6.8e+55) tmp = Float64(y * x); elseif (y <= 5e+66) tmp = fma(0.5, x, z); else tmp = Float64(Float64(y - -0.5) * x); end return tmp end
code[x_, y_, z_] := If[LessEqual[y, -6.8e+55], N[(y * x), $MachinePrecision], If[LessEqual[y, 5e+66], N[(0.5 * x + z), $MachinePrecision], N[(N[(y - -0.5), $MachinePrecision] * x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -6.8 \cdot 10^{+55}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;y \leq 5 \cdot 10^{+66}:\\
\;\;\;\;\mathsf{fma}\left(0.5, x, z\right)\\
\mathbf{else}:\\
\;\;\;\;\left(y - -0.5\right) \cdot x\\
\end{array}
\end{array}
if y < -6.7999999999999996e55Initial program 100.0%
Taylor expanded in y around 0
+-commutativeN/A
lower-fma.f6411.1
Applied rewrites11.1%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f6487.0
Applied rewrites87.0%
if -6.7999999999999996e55 < y < 4.99999999999999991e66Initial program 100.0%
Taylor expanded in y around 0
+-commutativeN/A
lower-fma.f6489.9
Applied rewrites89.9%
if 4.99999999999999991e66 < y Initial program 100.0%
Taylor expanded in y around 0
+-commutativeN/A
lower-fma.f6421.6
Applied rewrites21.6%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
metadata-evalN/A
sub-negN/A
lower--.f6478.8
Applied rewrites78.8%
(FPCore (x y z) :precision binary64 (if (or (<= y -6.8e+55) (not (<= y 5e+66))) (* y x) (fma 0.5 x z)))
double code(double x, double y, double z) {
double tmp;
if ((y <= -6.8e+55) || !(y <= 5e+66)) {
tmp = y * x;
} else {
tmp = fma(0.5, x, z);
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if ((y <= -6.8e+55) || !(y <= 5e+66)) tmp = Float64(y * x); else tmp = fma(0.5, x, z); end return tmp end
code[x_, y_, z_] := If[Or[LessEqual[y, -6.8e+55], N[Not[LessEqual[y, 5e+66]], $MachinePrecision]], N[(y * x), $MachinePrecision], N[(0.5 * x + z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -6.8 \cdot 10^{+55} \lor \neg \left(y \leq 5 \cdot 10^{+66}\right):\\
\;\;\;\;y \cdot x\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(0.5, x, z\right)\\
\end{array}
\end{array}
if y < -6.7999999999999996e55 or 4.99999999999999991e66 < y Initial program 100.0%
Taylor expanded in y around 0
+-commutativeN/A
lower-fma.f6416.6
Applied rewrites16.6%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f6482.7
Applied rewrites82.7%
if -6.7999999999999996e55 < y < 4.99999999999999991e66Initial program 100.0%
Taylor expanded in y around 0
+-commutativeN/A
lower-fma.f6489.9
Applied rewrites89.9%
Final simplification87.1%
(FPCore (x y z) :precision binary64 (if (or (<= y -1.8e-14) (not (<= y 86.0))) (* y x) (* 0.5 x)))
double code(double x, double y, double z) {
double tmp;
if ((y <= -1.8e-14) || !(y <= 86.0)) {
tmp = y * x;
} else {
tmp = 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 <= (-1.8d-14)) .or. (.not. (y <= 86.0d0))) then
tmp = y * x
else
tmp = 0.5d0 * x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -1.8e-14) || !(y <= 86.0)) {
tmp = y * x;
} else {
tmp = 0.5 * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -1.8e-14) or not (y <= 86.0): tmp = y * x else: tmp = 0.5 * x return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -1.8e-14) || !(y <= 86.0)) tmp = Float64(y * x); else tmp = Float64(0.5 * x); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -1.8e-14) || ~((y <= 86.0))) tmp = y * x; else tmp = 0.5 * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -1.8e-14], N[Not[LessEqual[y, 86.0]], $MachinePrecision]], N[(y * x), $MachinePrecision], N[(0.5 * x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.8 \cdot 10^{-14} \lor \neg \left(y \leq 86\right):\\
\;\;\;\;y \cdot x\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot x\\
\end{array}
\end{array}
if y < -1.7999999999999999e-14 or 86 < y Initial program 100.0%
Taylor expanded in y around 0
+-commutativeN/A
lower-fma.f6430.2
Applied rewrites30.2%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f6468.1
Applied rewrites68.1%
if -1.7999999999999999e-14 < y < 86Initial program 100.0%
Taylor expanded in y around 0
+-commutativeN/A
lower-fma.f6498.3
Applied rewrites98.3%
Taylor expanded in x around inf
Applied rewrites47.1%
Final simplification58.4%
(FPCore (x y z) :precision binary64 (* 0.5 x))
double code(double x, double y, double z) {
return 0.5 * x;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = 0.5d0 * x
end function
public static double code(double x, double y, double z) {
return 0.5 * x;
}
def code(x, y, z): return 0.5 * x
function code(x, y, z) return Float64(0.5 * x) end
function tmp = code(x, y, z) tmp = 0.5 * x; end
code[x_, y_, z_] := N[(0.5 * x), $MachinePrecision]
\begin{array}{l}
\\
0.5 \cdot x
\end{array}
Initial program 100.0%
Taylor expanded in y around 0
+-commutativeN/A
lower-fma.f6461.6
Applied rewrites61.6%
Taylor expanded in x around inf
Applied rewrites23.6%
herbie shell --seed 2024314
(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))