
(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 (or (<= x -4e-89) (not (<= x 1.7e-23))) (* x (+ y 1.0)) (* y z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -4e-89) || !(x <= 1.7e-23)) {
tmp = x * (y + 1.0);
} 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 ((x <= (-4d-89)) .or. (.not. (x <= 1.7d-23))) then
tmp = x * (y + 1.0d0)
else
tmp = y * z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -4e-89) || !(x <= 1.7e-23)) {
tmp = x * (y + 1.0);
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -4e-89) or not (x <= 1.7e-23): tmp = x * (y + 1.0) else: tmp = y * z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -4e-89) || !(x <= 1.7e-23)) tmp = Float64(x * Float64(y + 1.0)); else tmp = Float64(y * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -4e-89) || ~((x <= 1.7e-23))) tmp = x * (y + 1.0); else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -4e-89], N[Not[LessEqual[x, 1.7e-23]], $MachinePrecision]], N[(x * N[(y + 1.0), $MachinePrecision]), $MachinePrecision], N[(y * z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -4 \cdot 10^{-89} \lor \neg \left(x \leq 1.7 \cdot 10^{-23}\right):\\
\;\;\;\;x \cdot \left(y + 1\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if x < -4.00000000000000015e-89 or 1.7e-23 < x Initial program 100.0%
Taylor expanded in x around inf 83.0%
+-commutative83.0%
Simplified83.0%
if -4.00000000000000015e-89 < x < 1.7e-23Initial program 100.0%
distribute-lft-in99.9%
flip-+55.2%
Applied egg-rr55.2%
distribute-lft-out--55.2%
difference-of-squares55.2%
+-commutative55.2%
distribute-lft-in55.2%
distribute-lft-out--55.2%
Simplified55.2%
*-un-lft-identity55.2%
*-commutative55.2%
metadata-eval55.2%
div-inv55.2%
*-commutative55.2%
associate-/l*55.0%
Applied egg-rr55.0%
associate-/l*75.8%
frac-2neg75.8%
*-inverses99.7%
associate-/l/99.7%
*-un-lft-identity99.7%
distribute-frac-neg99.7%
+-commutative99.7%
distribute-neg-frac99.7%
metadata-eval99.7%
Applied egg-rr99.7%
Taylor expanded in x around 0 71.3%
Final simplification78.6%
(FPCore (x y z) :precision binary64 (if (or (<= y -3.4e-75) (not (<= y 1.1e-33))) (* y (+ x z)) (* x (+ y 1.0))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -3.4e-75) || !(y <= 1.1e-33)) {
tmp = y * (x + z);
} else {
tmp = x * (y + 1.0);
}
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 <= (-3.4d-75)) .or. (.not. (y <= 1.1d-33))) then
tmp = y * (x + z)
else
tmp = x * (y + 1.0d0)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -3.4e-75) || !(y <= 1.1e-33)) {
tmp = y * (x + z);
} else {
tmp = x * (y + 1.0);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -3.4e-75) or not (y <= 1.1e-33): tmp = y * (x + z) else: tmp = x * (y + 1.0) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -3.4e-75) || !(y <= 1.1e-33)) tmp = Float64(y * Float64(x + z)); else tmp = Float64(x * Float64(y + 1.0)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -3.4e-75) || ~((y <= 1.1e-33))) tmp = y * (x + z); else tmp = x * (y + 1.0); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -3.4e-75], N[Not[LessEqual[y, 1.1e-33]], $MachinePrecision]], N[(y * N[(x + z), $MachinePrecision]), $MachinePrecision], N[(x * N[(y + 1.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -3.4 \cdot 10^{-75} \lor \neg \left(y \leq 1.1 \cdot 10^{-33}\right):\\
\;\;\;\;y \cdot \left(x + z\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(y + 1\right)\\
\end{array}
\end{array}
if y < -3.40000000000000015e-75 or 1.10000000000000003e-33 < y Initial program 100.0%
distribute-lft-in93.2%
flip-+36.4%
Applied egg-rr36.4%
distribute-lft-out--36.4%
difference-of-squares36.8%
+-commutative36.8%
distribute-lft-in36.8%
distribute-lft-out--36.8%
Simplified36.8%
*-un-lft-identity36.8%
*-commutative36.8%
metadata-eval36.8%
div-inv36.8%
*-commutative36.8%
associate-/l*36.7%
Applied egg-rr36.7%
associate-/l*66.8%
frac-2neg66.8%
*-inverses99.7%
associate-/l/99.7%
*-un-lft-identity99.7%
distribute-frac-neg99.7%
+-commutative99.7%
distribute-neg-frac99.7%
metadata-eval99.7%
Applied egg-rr99.7%
Taylor expanded in y around inf 92.7%
if -3.40000000000000015e-75 < y < 1.10000000000000003e-33Initial program 100.0%
Taylor expanded in x around inf 82.6%
+-commutative82.6%
Simplified82.6%
Final simplification88.5%
(FPCore (x y z) :precision binary64 (if (or (<= y -42000.0) (not (<= y 3.35e-6))) (* y (+ x z)) (+ x (* y z))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -42000.0) || !(y <= 3.35e-6)) {
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 <= (-42000.0d0)) .or. (.not. (y <= 3.35d-6))) 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 <= -42000.0) || !(y <= 3.35e-6)) {
tmp = y * (x + z);
} else {
tmp = x + (y * z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -42000.0) or not (y <= 3.35e-6): tmp = y * (x + z) else: tmp = x + (y * z) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -42000.0) || !(y <= 3.35e-6)) 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 <= -42000.0) || ~((y <= 3.35e-6))) tmp = y * (x + z); else tmp = x + (y * z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -42000.0], N[Not[LessEqual[y, 3.35e-6]], $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 -42000 \lor \neg \left(y \leq 3.35 \cdot 10^{-6}\right):\\
\;\;\;\;y \cdot \left(x + z\right)\\
\mathbf{else}:\\
\;\;\;\;x + y \cdot z\\
\end{array}
\end{array}
if y < -42000 or 3.35e-6 < y Initial program 99.9%
distribute-lft-in91.9%
flip-+30.0%
Applied egg-rr30.0%
distribute-lft-out--30.0%
difference-of-squares30.4%
+-commutative30.4%
distribute-lft-in30.4%
distribute-lft-out--30.4%
Simplified30.4%
*-un-lft-identity30.4%
*-commutative30.4%
metadata-eval30.4%
div-inv30.4%
*-commutative30.4%
associate-/l*30.3%
Applied egg-rr30.3%
associate-/l*60.2%
frac-2neg60.2%
*-inverses99.7%
associate-/l/99.7%
*-un-lft-identity99.7%
distribute-frac-neg99.7%
+-commutative99.7%
distribute-neg-frac99.7%
metadata-eval99.7%
Applied egg-rr99.7%
Taylor expanded in y around inf 98.9%
if -42000 < y < 3.35e-6Initial program 100.0%
Taylor expanded in z around inf 98.9%
Final simplification98.9%
(FPCore (x y z) :precision binary64 (if (or (<= y -3.4e-76) (not (<= y 2.5e-33))) (* y z) x))
double code(double x, double y, double z) {
double tmp;
if ((y <= -3.4e-76) || !(y <= 2.5e-33)) {
tmp = y * 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 <= (-3.4d-76)) .or. (.not. (y <= 2.5d-33))) then
tmp = y * z
else
tmp = x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -3.4e-76) || !(y <= 2.5e-33)) {
tmp = y * z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -3.4e-76) or not (y <= 2.5e-33): tmp = y * z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -3.4e-76) || !(y <= 2.5e-33)) tmp = Float64(y * z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -3.4e-76) || ~((y <= 2.5e-33))) tmp = y * z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -3.4e-76], N[Not[LessEqual[y, 2.5e-33]], $MachinePrecision]], N[(y * z), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -3.4 \cdot 10^{-76} \lor \neg \left(y \leq 2.5 \cdot 10^{-33}\right):\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -3.3999999999999999e-76 or 2.50000000000000014e-33 < y Initial program 100.0%
distribute-lft-in93.2%
flip-+36.4%
Applied egg-rr36.4%
distribute-lft-out--36.4%
difference-of-squares36.8%
+-commutative36.8%
distribute-lft-in36.8%
distribute-lft-out--36.8%
Simplified36.8%
*-un-lft-identity36.8%
*-commutative36.8%
metadata-eval36.8%
div-inv36.8%
*-commutative36.8%
associate-/l*36.7%
Applied egg-rr36.7%
associate-/l*66.8%
frac-2neg66.8%
*-inverses99.7%
associate-/l/99.7%
*-un-lft-identity99.7%
distribute-frac-neg99.7%
+-commutative99.7%
distribute-neg-frac99.7%
metadata-eval99.7%
Applied egg-rr99.7%
Taylor expanded in x around 0 51.8%
if -3.3999999999999999e-76 < y < 2.50000000000000014e-33Initial program 100.0%
Taylor expanded in y around 0 82.6%
Final simplification64.7%
(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%
Taylor expanded in y around 0 39.1%
Final simplification39.1%
herbie shell --seed 2023311
(FPCore (x y z)
:name "Main:bigenough2 from A"
:precision binary64
(+ x (* y (+ z x))))