
(FPCore (x y z) :precision binary64 (+ x (* y (+ z x))))
double code(double x, double y, double z) {
return x + (y * (z + x));
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = x + (y * (z + x))
end function
public static double code(double x, double y, double z) {
return x + (y * (z + x));
}
def code(x, y, z): return x + (y * (z + x))
function code(x, y, z) return Float64(x + Float64(y * Float64(z + x))) end
function tmp = code(x, y, z) tmp = x + (y * (z + x)); end
code[x_, y_, z_] := N[(x + N[(y * N[(z + x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + y \cdot \left(z + x\right)
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 5 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (+ x (* y (+ z x))))
double code(double x, double y, double z) {
return x + (y * (z + x));
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = x + (y * (z + x))
end function
public static double code(double x, double y, double z) {
return x + (y * (z + x));
}
def code(x, y, z): return x + (y * (z + x))
function code(x, y, z) return Float64(x + Float64(y * Float64(z + x))) end
function tmp = code(x, y, z) tmp = x + (y * (z + x)); end
code[x_, y_, z_] := N[(x + N[(y * N[(z + x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + y \cdot \left(z + x\right)
\end{array}
(FPCore (x y z) :precision binary64 (fma (+ x z) y x))
double code(double x, double y, double z) {
return fma((x + z), y, x);
}
function code(x, y, z) return fma(Float64(x + z), y, x) end
code[x_, y_, z_] := N[(N[(x + z), $MachinePrecision] * y + x), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(x + z, y, x\right)
\end{array}
Initial program 100.0%
+-commutativeN/A
*-commutativeN/A
accelerator-lowering-fma.f64N/A
+-commutativeN/A
+-lowering-+.f64100.0
Applied egg-rr100.0%
(FPCore (x y z) :precision binary64 (if (<= x -7.5e+105) (fma y x x) (if (<= x 9e-13) (fma z y x) (fma y x x))))
double code(double x, double y, double z) {
double tmp;
if (x <= -7.5e+105) {
tmp = fma(y, x, x);
} else if (x <= 9e-13) {
tmp = fma(z, y, x);
} else {
tmp = fma(y, x, x);
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (x <= -7.5e+105) tmp = fma(y, x, x); elseif (x <= 9e-13) tmp = fma(z, y, x); else tmp = fma(y, x, x); end return tmp end
code[x_, y_, z_] := If[LessEqual[x, -7.5e+105], N[(y * x + x), $MachinePrecision], If[LessEqual[x, 9e-13], N[(z * y + x), $MachinePrecision], N[(y * x + x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -7.5 \cdot 10^{+105}:\\
\;\;\;\;\mathsf{fma}\left(y, x, x\right)\\
\mathbf{elif}\;x \leq 9 \cdot 10^{-13}:\\
\;\;\;\;\mathsf{fma}\left(z, y, x\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(y, x, x\right)\\
\end{array}
\end{array}
if x < -7.5000000000000002e105 or 9e-13 < x Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
+-commutativeN/A
distribute-lft1-inN/A
accelerator-lowering-fma.f6494.7
Simplified94.7%
if -7.5000000000000002e105 < x < 9e-13Initial program 100.0%
Taylor expanded in z around inf
Simplified83.9%
+-commutativeN/A
*-commutativeN/A
accelerator-lowering-fma.f6483.9
Applied egg-rr83.9%
(FPCore (x y z) :precision binary64 (if (<= x -2e-72) (fma y x x) (if (<= x 5.5e-125) (* z y) (fma y x x))))
double code(double x, double y, double z) {
double tmp;
if (x <= -2e-72) {
tmp = fma(y, x, x);
} else if (x <= 5.5e-125) {
tmp = z * y;
} else {
tmp = fma(y, x, x);
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (x <= -2e-72) tmp = fma(y, x, x); elseif (x <= 5.5e-125) tmp = Float64(z * y); else tmp = fma(y, x, x); end return tmp end
code[x_, y_, z_] := If[LessEqual[x, -2e-72], N[(y * x + x), $MachinePrecision], If[LessEqual[x, 5.5e-125], N[(z * y), $MachinePrecision], N[(y * x + x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2 \cdot 10^{-72}:\\
\;\;\;\;\mathsf{fma}\left(y, x, x\right)\\
\mathbf{elif}\;x \leq 5.5 \cdot 10^{-125}:\\
\;\;\;\;z \cdot y\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(y, x, x\right)\\
\end{array}
\end{array}
if x < -1.9999999999999999e-72 or 5.4999999999999997e-125 < x Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
+-commutativeN/A
distribute-lft1-inN/A
accelerator-lowering-fma.f6481.9
Simplified81.9%
if -1.9999999999999999e-72 < x < 5.4999999999999997e-125Initial program 100.0%
Taylor expanded in x around 0
+-rgt-identityN/A
accelerator-lowering-fma.f6473.6
Simplified73.6%
+-rgt-identityN/A
*-commutativeN/A
*-lowering-*.f6473.6
Applied egg-rr73.6%
(FPCore (x y z) :precision binary64 (if (<= y -2.9e-20) (* z y) (if (<= y 4e-17) x (* z y))))
double code(double x, double y, double z) {
double tmp;
if (y <= -2.9e-20) {
tmp = z * y;
} else if (y <= 4e-17) {
tmp = x;
} else {
tmp = z * 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 <= (-2.9d-20)) then
tmp = z * y
else if (y <= 4d-17) then
tmp = x
else
tmp = z * y
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= -2.9e-20) {
tmp = z * y;
} else if (y <= 4e-17) {
tmp = x;
} else {
tmp = z * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -2.9e-20: tmp = z * y elif y <= 4e-17: tmp = x else: tmp = z * y return tmp
function code(x, y, z) tmp = 0.0 if (y <= -2.9e-20) tmp = Float64(z * y); elseif (y <= 4e-17) tmp = x; else tmp = Float64(z * y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -2.9e-20) tmp = z * y; elseif (y <= 4e-17) tmp = x; else tmp = z * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -2.9e-20], N[(z * y), $MachinePrecision], If[LessEqual[y, 4e-17], x, N[(z * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.9 \cdot 10^{-20}:\\
\;\;\;\;z \cdot y\\
\mathbf{elif}\;y \leq 4 \cdot 10^{-17}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;z \cdot y\\
\end{array}
\end{array}
if y < -2.9e-20 or 4.00000000000000029e-17 < y Initial program 100.0%
Taylor expanded in x around 0
+-rgt-identityN/A
accelerator-lowering-fma.f6448.0
Simplified48.0%
+-rgt-identityN/A
*-commutativeN/A
*-lowering-*.f6448.0
Applied egg-rr48.0%
if -2.9e-20 < y < 4.00000000000000029e-17Initial program 100.0%
Taylor expanded in y around 0
Simplified75.6%
(FPCore (x y z) :precision binary64 x)
double code(double x, double y, double z) {
return x;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = x
end function
public static double code(double x, double y, double z) {
return x;
}
def code(x, y, z): return x
function code(x, y, z) return x end
function tmp = code(x, y, z) tmp = x; end
code[x_, y_, z_] := x
\begin{array}{l}
\\
x
\end{array}
Initial program 100.0%
Taylor expanded in y around 0
Simplified37.3%
herbie shell --seed 2024196
(FPCore (x y z)
:name "Main:bigenough2 from A"
:precision binary64
(+ x (* y (+ z x))))