
(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 6 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 z y (fma x y x)))
double code(double x, double y, double z) {
return fma(z, y, fma(x, y, x));
}
function code(x, y, z) return fma(z, y, fma(x, y, x)) end
code[x_, y_, z_] := N[(z * y + N[(x * y + x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(z, y, \mathsf{fma}\left(x, y, x\right)\right)
\end{array}
Initial program 100.0%
+-commutativeN/A
distribute-rgt-inN/A
associate-+l+N/A
accelerator-lowering-fma.f64N/A
accelerator-lowering-fma.f64100.0
Applied egg-rr100.0%
(FPCore (x y z) :precision binary64 (if (<= x -2.75e+104) (fma y x x) (if (<= x 4.7e-34) (fma z y x) (fma y x x))))
double code(double x, double y, double z) {
double tmp;
if (x <= -2.75e+104) {
tmp = fma(y, x, x);
} else if (x <= 4.7e-34) {
tmp = fma(z, y, x);
} else {
tmp = fma(y, x, x);
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (x <= -2.75e+104) tmp = fma(y, x, x); elseif (x <= 4.7e-34) tmp = fma(z, y, x); else tmp = fma(y, x, x); end return tmp end
code[x_, y_, z_] := If[LessEqual[x, -2.75e+104], N[(y * x + x), $MachinePrecision], If[LessEqual[x, 4.7e-34], N[(z * y + x), $MachinePrecision], N[(y * x + x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.75 \cdot 10^{+104}:\\
\;\;\;\;\mathsf{fma}\left(y, x, x\right)\\
\mathbf{elif}\;x \leq 4.7 \cdot 10^{-34}:\\
\;\;\;\;\mathsf{fma}\left(z, y, x\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(y, x, x\right)\\
\end{array}
\end{array}
if x < -2.75000000000000008e104 or 4.70000000000000002e-34 < x Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
+-commutativeN/A
distribute-lft1-inN/A
accelerator-lowering-fma.f6491.9
Simplified91.9%
if -2.75000000000000008e104 < x < 4.70000000000000002e-34Initial program 100.0%
Taylor expanded in z around inf
Simplified87.3%
+-commutativeN/A
*-commutativeN/A
accelerator-lowering-fma.f6487.3
Applied egg-rr87.3%
(FPCore (x y z) :precision binary64 (if (<= x -1.2e-48) (fma y x x) (if (<= x 6.5e-78) (* z y) (fma y x x))))
double code(double x, double y, double z) {
double tmp;
if (x <= -1.2e-48) {
tmp = fma(y, x, x);
} else if (x <= 6.5e-78) {
tmp = z * y;
} else {
tmp = fma(y, x, x);
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (x <= -1.2e-48) tmp = fma(y, x, x); elseif (x <= 6.5e-78) tmp = Float64(z * y); else tmp = fma(y, x, x); end return tmp end
code[x_, y_, z_] := If[LessEqual[x, -1.2e-48], N[(y * x + x), $MachinePrecision], If[LessEqual[x, 6.5e-78], N[(z * y), $MachinePrecision], N[(y * x + x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.2 \cdot 10^{-48}:\\
\;\;\;\;\mathsf{fma}\left(y, x, x\right)\\
\mathbf{elif}\;x \leq 6.5 \cdot 10^{-78}:\\
\;\;\;\;z \cdot y\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(y, x, x\right)\\
\end{array}
\end{array}
if x < -1.2e-48 or 6.5000000000000003e-78 < x Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
+-commutativeN/A
distribute-lft1-inN/A
accelerator-lowering-fma.f6485.5
Simplified85.5%
if -1.2e-48 < x < 6.5000000000000003e-78Initial program 100.0%
Taylor expanded in x around 0
+-rgt-identityN/A
accelerator-lowering-fma.f6474.0
Simplified74.0%
+-rgt-identityN/A
*-commutativeN/A
*-lowering-*.f6474.0
Applied egg-rr74.0%
(FPCore (x y z) :precision binary64 (if (<= y -8.2e-21) (* z y) (if (<= y 7e-8) x (* z y))))
double code(double x, double y, double z) {
double tmp;
if (y <= -8.2e-21) {
tmp = z * y;
} else if (y <= 7e-8) {
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 <= (-8.2d-21)) then
tmp = z * y
else if (y <= 7d-8) 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 <= -8.2e-21) {
tmp = z * y;
} else if (y <= 7e-8) {
tmp = x;
} else {
tmp = z * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -8.2e-21: tmp = z * y elif y <= 7e-8: tmp = x else: tmp = z * y return tmp
function code(x, y, z) tmp = 0.0 if (y <= -8.2e-21) tmp = Float64(z * y); elseif (y <= 7e-8) tmp = x; else tmp = Float64(z * y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -8.2e-21) tmp = z * y; elseif (y <= 7e-8) tmp = x; else tmp = z * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -8.2e-21], N[(z * y), $MachinePrecision], If[LessEqual[y, 7e-8], x, N[(z * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -8.2 \cdot 10^{-21}:\\
\;\;\;\;z \cdot y\\
\mathbf{elif}\;y \leq 7 \cdot 10^{-8}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;z \cdot y\\
\end{array}
\end{array}
if y < -8.19999999999999988e-21 or 7.00000000000000048e-8 < y Initial program 100.0%
Taylor expanded in x around 0
+-rgt-identityN/A
accelerator-lowering-fma.f6450.8
Simplified50.8%
+-rgt-identityN/A
*-commutativeN/A
*-lowering-*.f6450.8
Applied egg-rr50.8%
if -8.19999999999999988e-21 < y < 7.00000000000000048e-8Initial program 100.0%
Taylor expanded in y around 0
Simplified78.7%
(FPCore (x y z) :precision binary64 (fma (+ z x) y x))
double code(double x, double y, double z) {
return fma((z + x), y, x);
}
function code(x, y, z) return fma(Float64(z + x), y, x) end
code[x_, y_, z_] := N[(N[(z + x), $MachinePrecision] * y + x), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(z + x, 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%
Final simplification100.0%
(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
Simplified39.3%
herbie shell --seed 2024195
(FPCore (x y z)
:name "Main:bigenough2 from A"
:precision binary64
(+ x (* y (+ z x))))