
(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%
+-commutativeN/A
associate-+l+N/A
accelerator-lowering-fma.f64N/A
div-invN/A
accelerator-lowering-fma.f64N/A
metadata-eval100.0
Applied egg-rr100.0%
(FPCore (x y z) :precision binary64 (let* ((t_0 (+ (* y x) (/ x 2.0)))) (if (<= t_0 -1e+142) (* y x) (if (<= t_0 1e+147) z (* y x)))))
double code(double x, double y, double z) {
double t_0 = (y * x) + (x / 2.0);
double tmp;
if (t_0 <= -1e+142) {
tmp = y * x;
} else if (t_0 <= 1e+147) {
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) :: t_0
real(8) :: tmp
t_0 = (y * x) + (x / 2.0d0)
if (t_0 <= (-1d+142)) then
tmp = y * x
else if (t_0 <= 1d+147) then
tmp = z
else
tmp = y * x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = (y * x) + (x / 2.0);
double tmp;
if (t_0 <= -1e+142) {
tmp = y * x;
} else if (t_0 <= 1e+147) {
tmp = z;
} else {
tmp = y * x;
}
return tmp;
}
def code(x, y, z): t_0 = (y * x) + (x / 2.0) tmp = 0 if t_0 <= -1e+142: tmp = y * x elif t_0 <= 1e+147: tmp = z else: tmp = y * x return tmp
function code(x, y, z) t_0 = Float64(Float64(y * x) + Float64(x / 2.0)) tmp = 0.0 if (t_0 <= -1e+142) tmp = Float64(y * x); elseif (t_0 <= 1e+147) tmp = z; else tmp = Float64(y * x); end return tmp end
function tmp_2 = code(x, y, z) t_0 = (y * x) + (x / 2.0); tmp = 0.0; if (t_0 <= -1e+142) tmp = y * x; elseif (t_0 <= 1e+147) tmp = z; else tmp = y * x; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(y * x), $MachinePrecision] + N[(x / 2.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, -1e+142], N[(y * x), $MachinePrecision], If[LessEqual[t$95$0, 1e+147], z, N[(y * x), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := y \cdot x + \frac{x}{2}\\
\mathbf{if}\;t\_0 \leq -1 \cdot 10^{+142}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;t\_0 \leq 10^{+147}:\\
\;\;\;\;z\\
\mathbf{else}:\\
\;\;\;\;y \cdot x\\
\end{array}
\end{array}
if (+.f64 (/.f64 x #s(literal 2 binary64)) (*.f64 y x)) < -1.00000000000000005e142 or 9.9999999999999998e146 < (+.f64 (/.f64 x #s(literal 2 binary64)) (*.f64 y x)) Initial program 100.0%
Taylor expanded in y around inf
+-rgt-identityN/A
accelerator-lowering-fma.f6462.7
Simplified62.7%
+-rgt-identityN/A
*-commutativeN/A
*-lowering-*.f6462.7
Applied egg-rr62.7%
if -1.00000000000000005e142 < (+.f64 (/.f64 x #s(literal 2 binary64)) (*.f64 y x)) < 9.9999999999999998e146Initial program 100.0%
Taylor expanded in x around 0
Simplified55.0%
Final simplification58.8%
(FPCore (x y z) :precision binary64 (if (<= y -0.5) (fma y x z) (if (<= y 8.6e-7) (fma x 0.5 z) (fma y x z))))
double code(double x, double y, double z) {
double tmp;
if (y <= -0.5) {
tmp = fma(y, x, z);
} else if (y <= 8.6e-7) {
tmp = fma(x, 0.5, z);
} else {
tmp = fma(y, x, z);
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (y <= -0.5) tmp = fma(y, x, z); elseif (y <= 8.6e-7) tmp = fma(x, 0.5, z); else tmp = fma(y, x, z); end return tmp end
code[x_, y_, z_] := If[LessEqual[y, -0.5], N[(y * x + z), $MachinePrecision], If[LessEqual[y, 8.6e-7], N[(x * 0.5 + z), $MachinePrecision], N[(y * x + z), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -0.5:\\
\;\;\;\;\mathsf{fma}\left(y, x, z\right)\\
\mathbf{elif}\;y \leq 8.6 \cdot 10^{-7}:\\
\;\;\;\;\mathsf{fma}\left(x, 0.5, z\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(y, x, z\right)\\
\end{array}
\end{array}
if y < -0.5 or 8.6000000000000002e-7 < y Initial program 100.0%
+-commutativeN/A
associate-+l+N/A
accelerator-lowering-fma.f64N/A
div-invN/A
accelerator-lowering-fma.f64N/A
metadata-eval100.0
Applied egg-rr100.0%
Taylor expanded in x around 0
Simplified98.2%
if -0.5 < y < 8.6000000000000002e-7Initial program 100.0%
Taylor expanded in y around 0
+-commutativeN/A
*-commutativeN/A
accelerator-lowering-fma.f6499.7
Simplified99.7%
(FPCore (x y z) :precision binary64 (if (<= y -1.02e+35) (* y x) (if (<= y 1.14e+83) (fma x 0.5 z) (* y x))))
double code(double x, double y, double z) {
double tmp;
if (y <= -1.02e+35) {
tmp = y * x;
} else if (y <= 1.14e+83) {
tmp = fma(x, 0.5, z);
} else {
tmp = y * x;
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (y <= -1.02e+35) tmp = Float64(y * x); elseif (y <= 1.14e+83) tmp = fma(x, 0.5, z); else tmp = Float64(y * x); end return tmp end
code[x_, y_, z_] := If[LessEqual[y, -1.02e+35], N[(y * x), $MachinePrecision], If[LessEqual[y, 1.14e+83], N[(x * 0.5 + z), $MachinePrecision], N[(y * x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.02 \cdot 10^{+35}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;y \leq 1.14 \cdot 10^{+83}:\\
\;\;\;\;\mathsf{fma}\left(x, 0.5, z\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot x\\
\end{array}
\end{array}
if y < -1.02000000000000007e35 or 1.14000000000000003e83 < y Initial program 100.0%
Taylor expanded in y around inf
+-rgt-identityN/A
accelerator-lowering-fma.f6480.7
Simplified80.7%
+-rgt-identityN/A
*-commutativeN/A
*-lowering-*.f6480.7
Applied egg-rr80.7%
if -1.02000000000000007e35 < y < 1.14000000000000003e83Initial program 100.0%
Taylor expanded in y around 0
+-commutativeN/A
*-commutativeN/A
accelerator-lowering-fma.f6492.8
Simplified92.8%
(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%
div-invN/A
*-commutativeN/A
distribute-lft-outN/A
*-commutativeN/A
accelerator-lowering-fma.f64N/A
+-commutativeN/A
+-lowering-+.f64N/A
metadata-eval100.0
Applied egg-rr100.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%
Taylor expanded in x around 0
Simplified30.5%
herbie shell --seed 2024195
(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))