
(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 -0.003) (not (<= y 1.28e-102))) (* (+ z x) y) (fma y x x)))
double code(double x, double y, double z) {
double tmp;
if ((y <= -0.003) || !(y <= 1.28e-102)) {
tmp = (z + x) * y;
} else {
tmp = fma(y, x, x);
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if ((y <= -0.003) || !(y <= 1.28e-102)) tmp = Float64(Float64(z + x) * y); else tmp = fma(y, x, x); end return tmp end
code[x_, y_, z_] := If[Or[LessEqual[y, -0.003], N[Not[LessEqual[y, 1.28e-102]], $MachinePrecision]], N[(N[(z + x), $MachinePrecision] * y), $MachinePrecision], N[(y * x + x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -0.003 \lor \neg \left(y \leq 1.28 \cdot 10^{-102}\right):\\
\;\;\;\;\left(z + x\right) \cdot y\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(y, x, x\right)\\
\end{array}
\end{array}
if y < -0.0030000000000000001 or 1.27999999999999991e-102 < y Initial program 100.0%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f6454.2
Applied rewrites54.2%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
lower-+.f6493.2
Applied rewrites93.2%
if -0.0030000000000000001 < y < 1.27999999999999991e-102Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
+-commutativeN/A
distribute-lft1-inN/A
lower-fma.f6475.5
Applied rewrites75.5%
Final simplification85.9%
(FPCore (x y z) :precision binary64 (if (or (<= x -11.5) (not (<= x 2.15e-112))) (fma y x x) (* z y)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -11.5) || !(x <= 2.15e-112)) {
tmp = fma(y, x, x);
} else {
tmp = z * y;
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if ((x <= -11.5) || !(x <= 2.15e-112)) tmp = fma(y, x, x); else tmp = Float64(z * y); end return tmp end
code[x_, y_, z_] := If[Or[LessEqual[x, -11.5], N[Not[LessEqual[x, 2.15e-112]], $MachinePrecision]], N[(y * x + x), $MachinePrecision], N[(z * y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -11.5 \lor \neg \left(x \leq 2.15 \cdot 10^{-112}\right):\\
\;\;\;\;\mathsf{fma}\left(y, x, x\right)\\
\mathbf{else}:\\
\;\;\;\;z \cdot y\\
\end{array}
\end{array}
if x < -11.5 or 2.1499999999999999e-112 < x Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
+-commutativeN/A
distribute-lft1-inN/A
lower-fma.f6484.5
Applied rewrites84.5%
if -11.5 < x < 2.1499999999999999e-112Initial program 100.0%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f6474.7
Applied rewrites74.7%
Final simplification80.6%
(FPCore (x y z) :precision binary64 (if (or (<= x -3900000.0) (not (<= x 1.25e+55))) (* y x) (* z y)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -3900000.0) || !(x <= 1.25e+55)) {
tmp = y * 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 ((x <= (-3900000.0d0)) .or. (.not. (x <= 1.25d+55))) then
tmp = y * x
else
tmp = z * y
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -3900000.0) || !(x <= 1.25e+55)) {
tmp = y * x;
} else {
tmp = z * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -3900000.0) or not (x <= 1.25e+55): tmp = y * x else: tmp = z * y return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -3900000.0) || !(x <= 1.25e+55)) tmp = Float64(y * x); else tmp = Float64(z * y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -3900000.0) || ~((x <= 1.25e+55))) tmp = y * x; else tmp = z * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -3900000.0], N[Not[LessEqual[x, 1.25e+55]], $MachinePrecision]], N[(y * x), $MachinePrecision], N[(z * y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -3900000 \lor \neg \left(x \leq 1.25 \cdot 10^{+55}\right):\\
\;\;\;\;y \cdot x\\
\mathbf{else}:\\
\;\;\;\;z \cdot y\\
\end{array}
\end{array}
if x < -3.9e6 or 1.25000000000000011e55 < x Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
+-commutativeN/A
distribute-lft1-inN/A
lower-fma.f6489.4
Applied rewrites89.4%
Taylor expanded in y around inf
Applied rewrites42.7%
if -3.9e6 < x < 1.25000000000000011e55Initial program 100.0%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f6467.9
Applied rewrites67.9%
Final simplification55.4%
(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.f6461.4
Applied rewrites61.4%
Taylor expanded in y around inf
Applied rewrites27.5%
herbie shell --seed 2024337
(FPCore (x y z)
:name "Main:bigenough2 from A"
:precision binary64
(+ x (* y (+ z x))))