
(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 (+ 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%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f64100.0
Applied rewrites100.0%
(FPCore (x y z) :precision binary64 (if (or (<= y -15200.0) (not (<= y 46000000.0))) (* (+ z x) y) (fma y x x)))
double code(double x, double y, double z) {
double tmp;
if ((y <= -15200.0) || !(y <= 46000000.0)) {
tmp = (z + x) * y;
} else {
tmp = fma(y, x, x);
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if ((y <= -15200.0) || !(y <= 46000000.0)) tmp = Float64(Float64(z + x) * y); else tmp = fma(y, x, x); end return tmp end
code[x_, y_, z_] := If[Or[LessEqual[y, -15200.0], N[Not[LessEqual[y, 46000000.0]], $MachinePrecision]], N[(N[(z + x), $MachinePrecision] * y), $MachinePrecision], N[(y * x + x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -15200 \lor \neg \left(y \leq 46000000\right):\\
\;\;\;\;\left(z + x\right) \cdot y\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(y, x, x\right)\\
\end{array}
\end{array}
if y < -15200 or 4.6e7 < 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.f6496.0
Applied rewrites96.0%
Taylor expanded in y around -inf
distribute-lft-inN/A
mul-1-negN/A
*-commutativeN/A
*-commutativeN/A
associate-*l*N/A
distribute-rgt-neg-inN/A
mul-1-negN/A
remove-double-negN/A
lower-*.f64N/A
+-commutativeN/A
lower-+.f6499.6
Applied rewrites99.6%
if -15200 < y < 4.6e7Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
+-commutativeN/A
distribute-lft1-inN/A
lower-fma.f6475.2
Applied rewrites75.2%
Final simplification87.0%
(FPCore (x y z) :precision binary64 (if (or (<= z -2.4e+160) (not (<= z 7.2e+87))) (* z y) (fma y x x)))
double code(double x, double y, double z) {
double tmp;
if ((z <= -2.4e+160) || !(z <= 7.2e+87)) {
tmp = z * y;
} else {
tmp = fma(y, x, x);
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if ((z <= -2.4e+160) || !(z <= 7.2e+87)) tmp = Float64(z * y); else tmp = fma(y, x, x); end return tmp end
code[x_, y_, z_] := If[Or[LessEqual[z, -2.4e+160], N[Not[LessEqual[z, 7.2e+87]], $MachinePrecision]], N[(z * y), $MachinePrecision], N[(y * x + x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -2.4 \cdot 10^{+160} \lor \neg \left(z \leq 7.2 \cdot 10^{+87}\right):\\
\;\;\;\;z \cdot y\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(y, x, x\right)\\
\end{array}
\end{array}
if z < -2.4000000000000001e160 or 7.19999999999999988e87 < z Initial program 100.0%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f6477.4
Applied rewrites77.4%
if -2.4000000000000001e160 < z < 7.19999999999999988e87Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
+-commutativeN/A
distribute-lft1-inN/A
lower-fma.f6480.8
Applied rewrites80.8%
Final simplification79.7%
(FPCore (x y z) :precision binary64 (if (or (<= z -2.3e-49) (not (<= z 5.2e-68))) (* z y) (* y x)))
double code(double x, double y, double z) {
double tmp;
if ((z <= -2.3e-49) || !(z <= 5.2e-68)) {
tmp = z * y;
} 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 ((z <= (-2.3d-49)) .or. (.not. (z <= 5.2d-68))) then
tmp = z * y
else
tmp = y * x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -2.3e-49) || !(z <= 5.2e-68)) {
tmp = z * y;
} else {
tmp = y * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -2.3e-49) or not (z <= 5.2e-68): tmp = z * y else: tmp = y * x return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -2.3e-49) || !(z <= 5.2e-68)) tmp = Float64(z * y); else tmp = Float64(y * x); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -2.3e-49) || ~((z <= 5.2e-68))) tmp = z * y; else tmp = y * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -2.3e-49], N[Not[LessEqual[z, 5.2e-68]], $MachinePrecision]], N[(z * y), $MachinePrecision], N[(y * x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -2.3 \cdot 10^{-49} \lor \neg \left(z \leq 5.2 \cdot 10^{-68}\right):\\
\;\;\;\;z \cdot y\\
\mathbf{else}:\\
\;\;\;\;y \cdot x\\
\end{array}
\end{array}
if z < -2.2999999999999999e-49 or 5.1999999999999996e-68 < z Initial program 100.0%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f6456.1
Applied rewrites56.1%
if -2.2999999999999999e-49 < z < 5.1999999999999996e-68Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
+-commutativeN/A
distribute-lft1-inN/A
lower-fma.f6489.8
Applied rewrites89.8%
Taylor expanded in y around inf
Applied rewrites49.5%
Final simplification53.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.f6463.0
Applied rewrites63.0%
Taylor expanded in y around inf
Applied rewrites26.4%
Final simplification26.4%
herbie shell --seed 2024320
(FPCore (x y z)
:name "Main:bigenough2 from A"
:precision binary64
(+ x (* y (+ z x))))