
(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 x 0.5 z)))
double code(double x, double y, double z) {
return fma(y, x, fma(x, 0.5, z));
}
function code(x, y, z) return fma(y, x, fma(x, 0.5, z)) end
code[x_, y_, z_] := N[(y * x + N[(x * 0.5 + z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(y, x, \mathsf{fma}\left(x, 0.5, 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
div-invN/A
lower-fma.f64N/A
metadata-eval100.0
Applied rewrites100.0%
(FPCore (x y z) :precision binary64 (let* ((t_0 (+ (/ x 2.0) (* y x))) (t_1 (* x (+ y 0.5)))) (if (<= t_0 -2e+128) t_1 (if (<= t_0 1e+190) (fma x 0.5 z) t_1))))
double code(double x, double y, double z) {
double t_0 = (x / 2.0) + (y * x);
double t_1 = x * (y + 0.5);
double tmp;
if (t_0 <= -2e+128) {
tmp = t_1;
} else if (t_0 <= 1e+190) {
tmp = fma(x, 0.5, z);
} else {
tmp = t_1;
}
return tmp;
}
function code(x, y, z) t_0 = Float64(Float64(x / 2.0) + Float64(y * x)) t_1 = Float64(x * Float64(y + 0.5)) tmp = 0.0 if (t_0 <= -2e+128) tmp = t_1; elseif (t_0 <= 1e+190) tmp = fma(x, 0.5, z); else tmp = t_1; end return tmp end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(x / 2.0), $MachinePrecision] + N[(y * x), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(x * N[(y + 0.5), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, -2e+128], t$95$1, If[LessEqual[t$95$0, 1e+190], N[(x * 0.5 + z), $MachinePrecision], t$95$1]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{x}{2} + y \cdot x\\
t_1 := x \cdot \left(y + 0.5\right)\\
\mathbf{if}\;t\_0 \leq -2 \cdot 10^{+128}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;t\_0 \leq 10^{+190}:\\
\;\;\;\;\mathsf{fma}\left(x, 0.5, z\right)\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if (+.f64 (/.f64 x #s(literal 2 binary64)) (*.f64 y x)) < -2.0000000000000002e128 or 1.0000000000000001e190 < (+.f64 (/.f64 x #s(literal 2 binary64)) (*.f64 y x)) Initial program 100.0%
Taylor expanded in x around inf
lower-*.f64N/A
lower-+.f6493.7
Applied rewrites93.7%
if -2.0000000000000002e128 < (+.f64 (/.f64 x #s(literal 2 binary64)) (*.f64 y x)) < 1.0000000000000001e190Initial program 100.0%
Taylor expanded in y around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f6486.0
Applied rewrites86.0%
Final simplification88.6%
(FPCore (x y z) :precision binary64 (let* ((t_0 (+ z (* y x)))) (if (<= y -0.5) t_0 (if (<= y 0.5) (fma x 0.5 z) t_0))))
double code(double x, double y, double z) {
double t_0 = z + (y * x);
double tmp;
if (y <= -0.5) {
tmp = t_0;
} else if (y <= 0.5) {
tmp = fma(x, 0.5, z);
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y, z) t_0 = Float64(z + Float64(y * x)) tmp = 0.0 if (y <= -0.5) tmp = t_0; elseif (y <= 0.5) tmp = fma(x, 0.5, z); else tmp = t_0; end return tmp end
code[x_, y_, z_] := Block[{t$95$0 = N[(z + N[(y * x), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -0.5], t$95$0, If[LessEqual[y, 0.5], N[(x * 0.5 + z), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := z + y \cdot x\\
\mathbf{if}\;y \leq -0.5:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 0.5:\\
\;\;\;\;\mathsf{fma}\left(x, 0.5, z\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -0.5 or 0.5 < y Initial program 100.0%
Taylor expanded in y around inf
lower-*.f6498.8
Applied rewrites98.8%
if -0.5 < y < 0.5Initial program 100.0%
Taylor expanded in y around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f6498.5
Applied rewrites98.5%
Final simplification98.7%
(FPCore (x y z) :precision binary64 (if (<= y -4e+124) (* y x) (if (<= y 8.8e+17) (fma x 0.5 z) (* y x))))
double code(double x, double y, double z) {
double tmp;
if (y <= -4e+124) {
tmp = y * x;
} else if (y <= 8.8e+17) {
tmp = fma(x, 0.5, z);
} else {
tmp = y * x;
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (y <= -4e+124) tmp = Float64(y * x); elseif (y <= 8.8e+17) tmp = fma(x, 0.5, z); else tmp = Float64(y * x); end return tmp end
code[x_, y_, z_] := If[LessEqual[y, -4e+124], N[(y * x), $MachinePrecision], If[LessEqual[y, 8.8e+17], N[(x * 0.5 + z), $MachinePrecision], N[(y * x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -4 \cdot 10^{+124}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;y \leq 8.8 \cdot 10^{+17}:\\
\;\;\;\;\mathsf{fma}\left(x, 0.5, z\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot x\\
\end{array}
\end{array}
if y < -3.99999999999999979e124 or 8.8e17 < y Initial program 100.0%
Taylor expanded in y around inf
lower-*.f6478.9
Applied rewrites78.9%
if -3.99999999999999979e124 < y < 8.8e17Initial program 100.0%
Taylor expanded in y around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f6492.5
Applied rewrites92.5%
Final simplification87.2%
(FPCore (x y z) :precision binary64 (if (<= y -0.5) (* y x) (if (<= y 1.95e+15) (* x 0.5) (* y x))))
double code(double x, double y, double z) {
double tmp;
if (y <= -0.5) {
tmp = y * x;
} else if (y <= 1.95e+15) {
tmp = x * 0.5;
} 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 <= (-0.5d0)) then
tmp = y * x
else if (y <= 1.95d+15) then
tmp = x * 0.5d0
else
tmp = y * x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= -0.5) {
tmp = y * x;
} else if (y <= 1.95e+15) {
tmp = x * 0.5;
} else {
tmp = y * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -0.5: tmp = y * x elif y <= 1.95e+15: tmp = x * 0.5 else: tmp = y * x return tmp
function code(x, y, z) tmp = 0.0 if (y <= -0.5) tmp = Float64(y * x); elseif (y <= 1.95e+15) tmp = Float64(x * 0.5); else tmp = Float64(y * x); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -0.5) tmp = y * x; elseif (y <= 1.95e+15) tmp = x * 0.5; else tmp = y * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -0.5], N[(y * x), $MachinePrecision], If[LessEqual[y, 1.95e+15], N[(x * 0.5), $MachinePrecision], N[(y * x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -0.5:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;y \leq 1.95 \cdot 10^{+15}:\\
\;\;\;\;x \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;y \cdot x\\
\end{array}
\end{array}
if y < -0.5 or 1.95e15 < y Initial program 100.0%
Taylor expanded in y around inf
lower-*.f6470.9
Applied rewrites70.9%
if -0.5 < y < 1.95e15Initial program 100.0%
Taylor expanded in x around inf
lower-*.f64N/A
lower-+.f6448.7
Applied rewrites48.7%
Taylor expanded in y around 0
Applied rewrites46.7%
Final simplification58.5%
(FPCore (x y z) :precision binary64 (* y x))
double code(double x, double y, double z) {
return 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 = y * x
end function
public static double code(double x, double y, double z) {
return y * x;
}
def code(x, y, z): return y * x
function code(x, y, z) return Float64(y * x) end
function tmp = code(x, y, z) tmp = y * x; end
code[x_, y_, z_] := N[(y * x), $MachinePrecision]
\begin{array}{l}
\\
y \cdot x
\end{array}
Initial program 100.0%
Taylor expanded in y around inf
lower-*.f6436.4
Applied rewrites36.4%
Final simplification36.4%
herbie shell --seed 2024221
(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))