
(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 (+ y 0.5) x z))
double code(double x, double y, double z) {
return fma((y + 0.5), x, z);
}
function code(x, y, z) return fma(Float64(y + 0.5), x, z) end
code[x_, y_, z_] := N[(N[(y + 0.5), $MachinePrecision] * x + z), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(y + 0.5, 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%
Final simplification100.0%
(FPCore (x y z) :precision binary64 (let* ((t_0 (+ (* x y) (/ x 2.0))) (t_1 (* (- y -0.5) x))) (if (<= t_0 -2e+156) t_1 (if (<= t_0 5e+41) (fma 0.5 x z) t_1))))
double code(double x, double y, double z) {
double t_0 = (x * y) + (x / 2.0);
double t_1 = (y - -0.5) * x;
double tmp;
if (t_0 <= -2e+156) {
tmp = t_1;
} else if (t_0 <= 5e+41) {
tmp = fma(0.5, x, z);
} else {
tmp = t_1;
}
return tmp;
}
function code(x, y, z) t_0 = Float64(Float64(x * y) + Float64(x / 2.0)) t_1 = Float64(Float64(y - -0.5) * x) tmp = 0.0 if (t_0 <= -2e+156) tmp = t_1; elseif (t_0 <= 5e+41) tmp = fma(0.5, x, z); else tmp = t_1; end return tmp end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(x * y), $MachinePrecision] + N[(x / 2.0), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(y - -0.5), $MachinePrecision] * x), $MachinePrecision]}, If[LessEqual[t$95$0, -2e+156], t$95$1, If[LessEqual[t$95$0, 5e+41], N[(0.5 * x + z), $MachinePrecision], t$95$1]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot y + \frac{x}{2}\\
t_1 := \left(y - -0.5\right) \cdot x\\
\mathbf{if}\;t\_0 \leq -2 \cdot 10^{+156}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;t\_0 \leq 5 \cdot 10^{+41}:\\
\;\;\;\;\mathsf{fma}\left(0.5, x, z\right)\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if (+.f64 (/.f64 x #s(literal 2 binary64)) (*.f64 y x)) < -2e156 or 5.00000000000000022e41 < (+.f64 (/.f64 x #s(literal 2 binary64)) (*.f64 y x)) Initial program 100.0%
Taylor expanded in y around 0
+-commutativeN/A
lower-fma.f6442.2
Applied rewrites42.2%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
metadata-evalN/A
sub-negN/A
lower--.f6492.0
Applied rewrites92.0%
if -2e156 < (+.f64 (/.f64 x #s(literal 2 binary64)) (*.f64 y x)) < 5.00000000000000022e41Initial program 100.0%
Taylor expanded in y around 0
+-commutativeN/A
lower-fma.f6485.8
Applied rewrites85.8%
Final simplification88.6%
(FPCore (x y z) :precision binary64 (if (<= y -8e+59) (* x y) (if (<= y 1500000000000.0) (fma 0.5 x z) (* x y))))
double code(double x, double y, double z) {
double tmp;
if (y <= -8e+59) {
tmp = x * y;
} else if (y <= 1500000000000.0) {
tmp = fma(0.5, x, z);
} else {
tmp = x * y;
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (y <= -8e+59) tmp = Float64(x * y); elseif (y <= 1500000000000.0) tmp = fma(0.5, x, z); else tmp = Float64(x * y); end return tmp end
code[x_, y_, z_] := If[LessEqual[y, -8e+59], N[(x * y), $MachinePrecision], If[LessEqual[y, 1500000000000.0], N[(0.5 * x + z), $MachinePrecision], N[(x * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -8 \cdot 10^{+59}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;y \leq 1500000000000:\\
\;\;\;\;\mathsf{fma}\left(0.5, x, z\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if y < -7.99999999999999977e59 or 1.5e12 < y Initial program 100.0%
Taylor expanded in y around 0
+-commutativeN/A
lower-fma.f6425.0
Applied rewrites25.0%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f6476.6
Applied rewrites76.6%
if -7.99999999999999977e59 < y < 1.5e12Initial program 100.0%
Taylor expanded in y around 0
+-commutativeN/A
lower-fma.f6494.4
Applied rewrites94.4%
Final simplification87.2%
(FPCore (x y z) :precision binary64 (if (<= y -0.5) (* x y) (if (<= y 3.7e-7) (* x 0.5) (* x y))))
double code(double x, double y, double z) {
double tmp;
if (y <= -0.5) {
tmp = x * y;
} else if (y <= 3.7e-7) {
tmp = x * 0.5;
} 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 <= (-0.5d0)) then
tmp = x * y
else if (y <= 3.7d-7) then
tmp = x * 0.5d0
else
tmp = x * y
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= -0.5) {
tmp = x * y;
} else if (y <= 3.7e-7) {
tmp = x * 0.5;
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -0.5: tmp = x * y elif y <= 3.7e-7: tmp = x * 0.5 else: tmp = x * y return tmp
function code(x, y, z) tmp = 0.0 if (y <= -0.5) tmp = Float64(x * y); elseif (y <= 3.7e-7) tmp = Float64(x * 0.5); else tmp = Float64(x * y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -0.5) tmp = x * y; elseif (y <= 3.7e-7) tmp = x * 0.5; else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -0.5], N[(x * y), $MachinePrecision], If[LessEqual[y, 3.7e-7], N[(x * 0.5), $MachinePrecision], N[(x * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -0.5:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;y \leq 3.7 \cdot 10^{-7}:\\
\;\;\;\;x \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if y < -0.5 or 3.70000000000000004e-7 < y Initial program 100.0%
Taylor expanded in y around 0
+-commutativeN/A
lower-fma.f6432.9
Applied rewrites32.9%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f6468.3
Applied rewrites68.3%
if -0.5 < y < 3.70000000000000004e-7Initial program 100.0%
Taylor expanded in y around 0
+-commutativeN/A
lower-fma.f6499.5
Applied rewrites99.5%
Taylor expanded in x around inf
Applied rewrites47.1%
Final simplification57.7%
(FPCore (x y z) :precision binary64 (* x 0.5))
double code(double x, double y, double z) {
return x * 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 = x * 0.5d0
end function
public static double code(double x, double y, double z) {
return x * 0.5;
}
def code(x, y, z): return x * 0.5
function code(x, y, z) return Float64(x * 0.5) end
function tmp = code(x, y, z) tmp = x * 0.5; end
code[x_, y_, z_] := N[(x * 0.5), $MachinePrecision]
\begin{array}{l}
\\
x \cdot 0.5
\end{array}
Initial program 100.0%
Taylor expanded in y around 0
+-commutativeN/A
lower-fma.f6466.2
Applied rewrites66.2%
Taylor expanded in x around inf
Applied rewrites25.1%
Final simplification25.1%
herbie shell --seed 2024296
(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))