
(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 7 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 y (+ x z) x))
double code(double x, double y, double z) {
return fma(y, (x + z), x);
}
function code(x, y, z) return fma(y, Float64(x + z), x) end
code[x_, y_, z_] := N[(y * N[(x + z), $MachinePrecision] + x), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(y, x + z, x\right)
\end{array}
Initial program 100.0%
+-commutative100.0%
fma-def100.0%
+-commutative100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x y z)
:precision binary64
(if (<= y -2.25e+89)
(* y x)
(if (<= y -1.85e-37)
(* y z)
(if (<= y 6.2e-17)
x
(if (or (<= y 1.32e+56)
(not
(or (<= y 7.6e+162)
(and (not (<= y 2.4e+256)) (<= y 2.1e+296)))))
(* y z)
(* y x))))))
double code(double x, double y, double z) {
double tmp;
if (y <= -2.25e+89) {
tmp = y * x;
} else if (y <= -1.85e-37) {
tmp = y * z;
} else if (y <= 6.2e-17) {
tmp = x;
} else if ((y <= 1.32e+56) || !((y <= 7.6e+162) || (!(y <= 2.4e+256) && (y <= 2.1e+296)))) {
tmp = y * z;
} 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 (y <= (-2.25d+89)) then
tmp = y * x
else if (y <= (-1.85d-37)) then
tmp = y * z
else if (y <= 6.2d-17) then
tmp = x
else if ((y <= 1.32d+56) .or. (.not. (y <= 7.6d+162) .or. (.not. (y <= 2.4d+256)) .and. (y <= 2.1d+296))) then
tmp = y * z
else
tmp = y * x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= -2.25e+89) {
tmp = y * x;
} else if (y <= -1.85e-37) {
tmp = y * z;
} else if (y <= 6.2e-17) {
tmp = x;
} else if ((y <= 1.32e+56) || !((y <= 7.6e+162) || (!(y <= 2.4e+256) && (y <= 2.1e+296)))) {
tmp = y * z;
} else {
tmp = y * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -2.25e+89: tmp = y * x elif y <= -1.85e-37: tmp = y * z elif y <= 6.2e-17: tmp = x elif (y <= 1.32e+56) or not ((y <= 7.6e+162) or (not (y <= 2.4e+256) and (y <= 2.1e+296))): tmp = y * z else: tmp = y * x return tmp
function code(x, y, z) tmp = 0.0 if (y <= -2.25e+89) tmp = Float64(y * x); elseif (y <= -1.85e-37) tmp = Float64(y * z); elseif (y <= 6.2e-17) tmp = x; elseif ((y <= 1.32e+56) || !((y <= 7.6e+162) || (!(y <= 2.4e+256) && (y <= 2.1e+296)))) tmp = Float64(y * z); else tmp = Float64(y * x); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -2.25e+89) tmp = y * x; elseif (y <= -1.85e-37) tmp = y * z; elseif (y <= 6.2e-17) tmp = x; elseif ((y <= 1.32e+56) || ~(((y <= 7.6e+162) || (~((y <= 2.4e+256)) && (y <= 2.1e+296))))) tmp = y * z; else tmp = y * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -2.25e+89], N[(y * x), $MachinePrecision], If[LessEqual[y, -1.85e-37], N[(y * z), $MachinePrecision], If[LessEqual[y, 6.2e-17], x, If[Or[LessEqual[y, 1.32e+56], N[Not[Or[LessEqual[y, 7.6e+162], And[N[Not[LessEqual[y, 2.4e+256]], $MachinePrecision], LessEqual[y, 2.1e+296]]]], $MachinePrecision]], N[(y * z), $MachinePrecision], N[(y * x), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.25 \cdot 10^{+89}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;y \leq -1.85 \cdot 10^{-37}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;y \leq 6.2 \cdot 10^{-17}:\\
\;\;\;\;x\\
\mathbf{elif}\;y \leq 1.32 \cdot 10^{+56} \lor \neg \left(y \leq 7.6 \cdot 10^{+162} \lor \neg \left(y \leq 2.4 \cdot 10^{+256}\right) \land y \leq 2.1 \cdot 10^{+296}\right):\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;y \cdot x\\
\end{array}
\end{array}
if y < -2.25e89 or 1.32e56 < y < 7.60000000000000049e162 or 2.40000000000000014e256 < y < 2.10000000000000005e296Initial program 100.0%
+-commutative100.0%
fma-def100.0%
+-commutative100.0%
Simplified100.0%
Taylor expanded in x around -inf 97.1%
+-commutative97.1%
mul-1-neg97.1%
unsub-neg97.1%
sub-neg97.1%
metadata-eval97.1%
+-commutative97.1%
mul-1-neg97.1%
unsub-neg97.1%
Simplified97.1%
Taylor expanded in y around inf 100.0%
neg-mul-1100.0%
distribute-lft-out--97.1%
distribute-rgt-neg-in97.1%
distribute-lft-neg-out97.1%
cancel-sign-sub97.1%
distribute-lft-in100.0%
+-commutative100.0%
Simplified100.0%
Taylor expanded in x around inf 70.4%
*-commutative70.4%
Simplified70.4%
if -2.25e89 < y < -1.85e-37 or 6.1999999999999997e-17 < y < 1.32e56 or 7.60000000000000049e162 < y < 2.40000000000000014e256 or 2.10000000000000005e296 < y Initial program 100.0%
+-commutative100.0%
fma-def100.0%
+-commutative100.0%
Simplified100.0%
Taylor expanded in x around -inf 98.6%
+-commutative98.6%
mul-1-neg98.6%
unsub-neg98.6%
sub-neg98.6%
metadata-eval98.6%
+-commutative98.6%
mul-1-neg98.6%
unsub-neg98.6%
Simplified98.6%
Taylor expanded in z around inf 73.0%
if -1.85e-37 < y < 6.1999999999999997e-17Initial program 100.0%
+-commutative100.0%
fma-def100.0%
+-commutative100.0%
Simplified100.0%
Taylor expanded in y around 0 76.9%
Final simplification74.1%
(FPCore (x y z) :precision binary64 (if (or (<= y -8.6e-29) (not (<= y 4.5e-17))) (* y (+ x z)) x))
double code(double x, double y, double z) {
double tmp;
if ((y <= -8.6e-29) || !(y <= 4.5e-17)) {
tmp = y * (x + z);
} else {
tmp = 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 ((y <= (-8.6d-29)) .or. (.not. (y <= 4.5d-17))) then
tmp = y * (x + z)
else
tmp = x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -8.6e-29) || !(y <= 4.5e-17)) {
tmp = y * (x + z);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -8.6e-29) or not (y <= 4.5e-17): tmp = y * (x + z) else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -8.6e-29) || !(y <= 4.5e-17)) tmp = Float64(y * Float64(x + z)); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -8.6e-29) || ~((y <= 4.5e-17))) tmp = y * (x + z); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -8.6e-29], N[Not[LessEqual[y, 4.5e-17]], $MachinePrecision]], N[(y * N[(x + z), $MachinePrecision]), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -8.6 \cdot 10^{-29} \lor \neg \left(y \leq 4.5 \cdot 10^{-17}\right):\\
\;\;\;\;y \cdot \left(x + z\right)\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -8.5999999999999996e-29 or 4.49999999999999978e-17 < y Initial program 100.0%
+-commutative100.0%
fma-def100.0%
+-commutative100.0%
Simplified100.0%
Taylor expanded in x around -inf 97.8%
+-commutative97.8%
mul-1-neg97.8%
unsub-neg97.8%
sub-neg97.8%
metadata-eval97.8%
+-commutative97.8%
mul-1-neg97.8%
unsub-neg97.8%
Simplified97.8%
Taylor expanded in y around inf 97.1%
neg-mul-197.1%
distribute-lft-out--94.9%
distribute-rgt-neg-in94.9%
distribute-lft-neg-out94.9%
cancel-sign-sub94.9%
distribute-lft-in97.1%
+-commutative97.1%
Simplified97.1%
if -8.5999999999999996e-29 < y < 4.49999999999999978e-17Initial program 100.0%
+-commutative100.0%
fma-def100.0%
+-commutative100.0%
Simplified100.0%
Taylor expanded in y around 0 76.5%
Final simplification87.4%
(FPCore (x y z) :precision binary64 (if (or (<= y -350.0) (not (<= y 1.0))) (* y (+ x z)) (+ x (* y z))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -350.0) || !(y <= 1.0)) {
tmp = y * (x + z);
} else {
tmp = x + (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 ((y <= (-350.0d0)) .or. (.not. (y <= 1.0d0))) then
tmp = y * (x + z)
else
tmp = x + (y * z)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -350.0) || !(y <= 1.0)) {
tmp = y * (x + z);
} else {
tmp = x + (y * z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -350.0) or not (y <= 1.0): tmp = y * (x + z) else: tmp = x + (y * z) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -350.0) || !(y <= 1.0)) tmp = Float64(y * Float64(x + z)); else tmp = Float64(x + Float64(y * z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -350.0) || ~((y <= 1.0))) tmp = y * (x + z); else tmp = x + (y * z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -350.0], N[Not[LessEqual[y, 1.0]], $MachinePrecision]], N[(y * N[(x + z), $MachinePrecision]), $MachinePrecision], N[(x + N[(y * z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -350 \lor \neg \left(y \leq 1\right):\\
\;\;\;\;y \cdot \left(x + z\right)\\
\mathbf{else}:\\
\;\;\;\;x + y \cdot z\\
\end{array}
\end{array}
if y < -350 or 1 < y Initial program 100.0%
+-commutative100.0%
fma-def100.0%
+-commutative100.0%
Simplified100.0%
Taylor expanded in x around -inf 97.6%
+-commutative97.6%
mul-1-neg97.6%
unsub-neg97.6%
sub-neg97.6%
metadata-eval97.6%
+-commutative97.6%
mul-1-neg97.6%
unsub-neg97.6%
Simplified97.6%
Taylor expanded in y around inf 99.5%
neg-mul-199.5%
distribute-lft-out--97.1%
distribute-rgt-neg-in97.1%
distribute-lft-neg-out97.1%
cancel-sign-sub97.1%
distribute-lft-in99.5%
+-commutative99.5%
Simplified99.5%
if -350 < y < 1Initial program 100.0%
Taylor expanded in z around inf 99.0%
Final simplification99.3%
(FPCore (x y z) :precision binary64 (if (or (<= y -350.0) (not (<= y 3.2e+32))) (* y x) x))
double code(double x, double y, double z) {
double tmp;
if ((y <= -350.0) || !(y <= 3.2e+32)) {
tmp = y * x;
} else {
tmp = 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 ((y <= (-350.0d0)) .or. (.not. (y <= 3.2d+32))) then
tmp = y * x
else
tmp = x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -350.0) || !(y <= 3.2e+32)) {
tmp = y * x;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -350.0) or not (y <= 3.2e+32): tmp = y * x else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -350.0) || !(y <= 3.2e+32)) tmp = Float64(y * x); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -350.0) || ~((y <= 3.2e+32))) tmp = y * x; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -350.0], N[Not[LessEqual[y, 3.2e+32]], $MachinePrecision]], N[(y * x), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -350 \lor \neg \left(y \leq 3.2 \cdot 10^{+32}\right):\\
\;\;\;\;y \cdot x\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -350 or 3.1999999999999999e32 < y Initial program 100.0%
+-commutative100.0%
fma-def100.0%
+-commutative100.0%
Simplified100.0%
Taylor expanded in x around -inf 97.5%
+-commutative97.5%
mul-1-neg97.5%
unsub-neg97.5%
sub-neg97.5%
metadata-eval97.5%
+-commutative97.5%
mul-1-neg97.5%
unsub-neg97.5%
Simplified97.5%
Taylor expanded in y around inf 99.5%
neg-mul-199.5%
distribute-lft-out--97.0%
distribute-rgt-neg-in97.0%
distribute-lft-neg-out97.0%
cancel-sign-sub97.0%
distribute-lft-in99.5%
+-commutative99.5%
Simplified99.5%
Taylor expanded in x around inf 57.4%
*-commutative57.4%
Simplified57.4%
if -350 < y < 3.1999999999999999e32Initial program 100.0%
+-commutative100.0%
fma-def100.0%
+-commutative100.0%
Simplified100.0%
Taylor expanded in y around 0 69.2%
Final simplification63.6%
(FPCore (x y z) :precision binary64 (+ x (* y (+ x z))))
double code(double x, double y, double z) {
return x + (y * (x + z));
}
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 * (x + z))
end function
public static double code(double x, double y, double z) {
return x + (y * (x + z));
}
def code(x, y, z): return x + (y * (x + z))
function code(x, y, z) return Float64(x + Float64(y * Float64(x + z))) end
function tmp = code(x, y, z) tmp = x + (y * (x + z)); end
code[x_, y_, z_] := N[(x + N[(y * N[(x + z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + y \cdot \left(x + z\right)
\end{array}
Initial program 100.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%
+-commutative100.0%
fma-def100.0%
+-commutative100.0%
Simplified100.0%
Taylor expanded in y around 0 38.1%
Final simplification38.1%
herbie shell --seed 2023308
(FPCore (x y z)
:name "Main:bigenough2 from A"
:precision binary64
(+ x (* y (+ z x))))