
(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 y x (fma 0.5 x z)))
double code(double x, double y, double z) {
return fma(y, x, fma(0.5, x, z));
}
function code(x, y, z) return fma(y, x, fma(0.5, x, z)) end
code[x_, y_, z_] := N[(y * x + N[(0.5 * x + z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(y, x, \mathsf{fma}\left(0.5, x, z\right)\right)
\end{array}
Initial program 100.0%
lift-+.f64N/A
lift-+.f64N/A
+-commutativeN/A
associate-+l+N/A
lift-*.f64N/A
lower-fma.f64N/A
lift-/.f64N/A
clear-numN/A
associate-/r/N/A
lower-fma.f64N/A
metadata-eval100.0
Applied rewrites100.0%
(FPCore (x y z) :precision binary64 (let* ((t_0 (+ (* x y) (/ x 2.0))) (t_1 (* (- y -0.5) x))) (if (<= t_0 -4e+166) t_1 (if (<= t_0 5e+161) (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 <= -4e+166) {
tmp = t_1;
} else if (t_0 <= 5e+161) {
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 <= -4e+166) tmp = t_1; elseif (t_0 <= 5e+161) 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, -4e+166], t$95$1, If[LessEqual[t$95$0, 5e+161], 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 -4 \cdot 10^{+166}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;t\_0 \leq 5 \cdot 10^{+161}:\\
\;\;\;\;\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)) < -3.99999999999999976e166 or 4.9999999999999997e161 < (+.f64 (/.f64 x #s(literal 2 binary64)) (*.f64 y x)) Initial program 100.0%
Taylor expanded in y around 0
+-commutativeN/A
lower-fma.f6426.5
Applied rewrites26.5%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
metadata-evalN/A
sub-negN/A
lower--.f6495.2
Applied rewrites95.2%
if -3.99999999999999976e166 < (+.f64 (/.f64 x #s(literal 2 binary64)) (*.f64 y x)) < 4.9999999999999997e161Initial program 100.0%
Taylor expanded in y around 0
+-commutativeN/A
lower-fma.f6482.0
Applied rewrites82.0%
Final simplification86.7%
(FPCore (x y z) :precision binary64 (if (<= y -6.4e+19) (* x y) (if (<= y 1.4e+16) (fma 0.5 x z) (* x y))))
double code(double x, double y, double z) {
double tmp;
if (y <= -6.4e+19) {
tmp = x * y;
} else if (y <= 1.4e+16) {
tmp = fma(0.5, x, z);
} else {
tmp = x * y;
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (y <= -6.4e+19) tmp = Float64(x * y); elseif (y <= 1.4e+16) tmp = fma(0.5, x, z); else tmp = Float64(x * y); end return tmp end
code[x_, y_, z_] := If[LessEqual[y, -6.4e+19], N[(x * y), $MachinePrecision], If[LessEqual[y, 1.4e+16], N[(0.5 * x + z), $MachinePrecision], N[(x * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -6.4 \cdot 10^{+19}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;y \leq 1.4 \cdot 10^{+16}:\\
\;\;\;\;\mathsf{fma}\left(0.5, x, z\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if y < -6.4e19 or 1.4e16 < y Initial program 100.0%
Taylor expanded in y around 0
+-commutativeN/A
lower-fma.f6426.8
Applied rewrites26.8%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f6474.7
Applied rewrites74.7%
if -6.4e19 < y < 1.4e16Initial program 100.0%
Taylor expanded in y around 0
+-commutativeN/A
lower-fma.f6497.3
Applied rewrites97.3%
Final simplification86.0%
(FPCore (x y z) :precision binary64 (if (<= y -9.8e-8) (* x y) (if (<= y 0.5) (* 0.5 x) (* x y))))
double code(double x, double y, double z) {
double tmp;
if (y <= -9.8e-8) {
tmp = x * y;
} else if (y <= 0.5) {
tmp = 0.5 * x;
} 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 <= (-9.8d-8)) then
tmp = x * y
else if (y <= 0.5d0) then
tmp = 0.5d0 * x
else
tmp = x * y
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= -9.8e-8) {
tmp = x * y;
} else if (y <= 0.5) {
tmp = 0.5 * x;
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -9.8e-8: tmp = x * y elif y <= 0.5: tmp = 0.5 * x else: tmp = x * y return tmp
function code(x, y, z) tmp = 0.0 if (y <= -9.8e-8) tmp = Float64(x * y); elseif (y <= 0.5) tmp = Float64(0.5 * x); else tmp = Float64(x * y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -9.8e-8) tmp = x * y; elseif (y <= 0.5) tmp = 0.5 * x; else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -9.8e-8], N[(x * y), $MachinePrecision], If[LessEqual[y, 0.5], N[(0.5 * x), $MachinePrecision], N[(x * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -9.8 \cdot 10^{-8}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;y \leq 0.5:\\
\;\;\;\;0.5 \cdot x\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if y < -9.8000000000000004e-8 or 0.5 < y Initial program 100.0%
Taylor expanded in y around 0
+-commutativeN/A
lower-fma.f6430.6
Applied rewrites30.6%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f6470.3
Applied rewrites70.3%
if -9.8000000000000004e-8 < y < 0.5Initial program 100.0%
Taylor expanded in y around 0
+-commutativeN/A
lower-fma.f6499.4
Applied rewrites99.4%
Taylor expanded in x around inf
Applied rewrites47.4%
Final simplification59.8%
(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 (* 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.f6462.0
Applied rewrites62.0%
Taylor expanded in x around inf
Applied rewrites23.2%
herbie shell --seed 2024295
(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))