
(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%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f64100.0
Applied rewrites100.0%
Final simplification100.0%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* y (+ x z)))) (if (<= y -4.9e-30) t_0 (if (<= y 2.95e-53) (fma y x x) t_0))))
double code(double x, double y, double z) {
double t_0 = y * (x + z);
double tmp;
if (y <= -4.9e-30) {
tmp = t_0;
} else if (y <= 2.95e-53) {
tmp = fma(y, x, x);
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y, z) t_0 = Float64(y * Float64(x + z)) tmp = 0.0 if (y <= -4.9e-30) tmp = t_0; elseif (y <= 2.95e-53) tmp = fma(y, x, x); else tmp = t_0; end return tmp end
code[x_, y_, z_] := Block[{t$95$0 = N[(y * N[(x + z), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -4.9e-30], t$95$0, If[LessEqual[y, 2.95e-53], N[(y * x + x), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := y \cdot \left(x + z\right)\\
\mathbf{if}\;y \leq -4.9 \cdot 10^{-30}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 2.95 \cdot 10^{-53}:\\
\;\;\;\;\mathsf{fma}\left(y, x, x\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -4.89999999999999971e-30 or 2.95e-53 < y Initial program 100.0%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lift-+.f64N/A
distribute-rgt-inN/A
associate-+l+N/A
lower-fma.f64N/A
*-commutativeN/A
lower-fma.f6498.6
Applied rewrites98.6%
Taylor expanded in y around -inf
distribute-lft-inN/A
*-commutativeN/A
associate-*r*N/A
neg-mul-1N/A
mul-1-negN/A
remove-double-negN/A
lower-*.f64N/A
+-commutativeN/A
lower-+.f6495.4
Applied rewrites95.4%
if -4.89999999999999971e-30 < y < 2.95e-53Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
+-commutativeN/A
distribute-lft1-inN/A
lower-fma.f6480.2
Applied rewrites80.2%
Final simplification88.7%
(FPCore (x y z) :precision binary64 (if (<= z -2.45e+114) (* y z) (if (<= z 1.8e+24) (fma y x x) (* y z))))
double code(double x, double y, double z) {
double tmp;
if (z <= -2.45e+114) {
tmp = y * z;
} else if (z <= 1.8e+24) {
tmp = fma(y, x, x);
} else {
tmp = y * z;
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (z <= -2.45e+114) tmp = Float64(y * z); elseif (z <= 1.8e+24) tmp = fma(y, x, x); else tmp = Float64(y * z); end return tmp end
code[x_, y_, z_] := If[LessEqual[z, -2.45e+114], N[(y * z), $MachinePrecision], If[LessEqual[z, 1.8e+24], N[(y * x + x), $MachinePrecision], N[(y * z), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -2.45 \cdot 10^{+114}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;z \leq 1.8 \cdot 10^{+24}:\\
\;\;\;\;\mathsf{fma}\left(y, x, x\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if z < -2.45e114 or 1.79999999999999992e24 < z Initial program 100.0%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f6469.3
Applied rewrites69.3%
if -2.45e114 < z < 1.79999999999999992e24Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
+-commutativeN/A
distribute-lft1-inN/A
lower-fma.f6482.3
Applied rewrites82.3%
Final simplification77.5%
(FPCore (x y z) :precision binary64 (if (<= z -2.7e+86) (* y z) (if (<= z 1.1e-124) (* y x) (* y z))))
double code(double x, double y, double z) {
double tmp;
if (z <= -2.7e+86) {
tmp = y * z;
} else if (z <= 1.1e-124) {
tmp = y * x;
} else {
tmp = y * z;
}
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 (z <= (-2.7d+86)) then
tmp = y * z
else if (z <= 1.1d-124) then
tmp = y * x
else
tmp = y * z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (z <= -2.7e+86) {
tmp = y * z;
} else if (z <= 1.1e-124) {
tmp = y * x;
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -2.7e+86: tmp = y * z elif z <= 1.1e-124: tmp = y * x else: tmp = y * z return tmp
function code(x, y, z) tmp = 0.0 if (z <= -2.7e+86) tmp = Float64(y * z); elseif (z <= 1.1e-124) tmp = Float64(y * x); else tmp = Float64(y * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -2.7e+86) tmp = y * z; elseif (z <= 1.1e-124) tmp = y * x; else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -2.7e+86], N[(y * z), $MachinePrecision], If[LessEqual[z, 1.1e-124], N[(y * x), $MachinePrecision], N[(y * z), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -2.7 \cdot 10^{+86}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;z \leq 1.1 \cdot 10^{-124}:\\
\;\;\;\;y \cdot x\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if z < -2.70000000000000018e86 or 1.0999999999999999e-124 < z Initial program 100.0%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f6461.1
Applied rewrites61.1%
if -2.70000000000000018e86 < z < 1.0999999999999999e-124Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
+-commutativeN/A
distribute-lft1-inN/A
lower-fma.f6487.0
Applied rewrites87.0%
Taylor expanded in y around inf
Applied rewrites39.7%
Final simplification50.7%
(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 x around inf
*-commutativeN/A
+-commutativeN/A
distribute-lft1-inN/A
lower-fma.f6464.7
Applied rewrites64.7%
Taylor expanded in y around inf
Applied rewrites28.5%
herbie shell --seed 2024298
(FPCore (x y z)
:name "Main:bigenough2 from A"
:precision binary64
(+ x (* y (+ z x))))