
(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 9 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-define100.0%
+-commutative100.0%
Simplified100.0%
(FPCore (x y z)
:precision binary64
(if (<= y -1.65e+125)
(* y x)
(if (or (<= y -6e-52)
(not
(or (<= y 7.5e-164) (and (not (<= y 8e-153)) (<= y 1.92e-131)))))
(* y z)
x)))
double code(double x, double y, double z) {
double tmp;
if (y <= -1.65e+125) {
tmp = y * x;
} else if ((y <= -6e-52) || !((y <= 7.5e-164) || (!(y <= 8e-153) && (y <= 1.92e-131)))) {
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 <= (-1.65d+125)) then
tmp = y * x
else if ((y <= (-6d-52)) .or. (.not. (y <= 7.5d-164) .or. (.not. (y <= 8d-153)) .and. (y <= 1.92d-131))) 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 <= -1.65e+125) {
tmp = y * x;
} else if ((y <= -6e-52) || !((y <= 7.5e-164) || (!(y <= 8e-153) && (y <= 1.92e-131)))) {
tmp = y * z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -1.65e+125: tmp = y * x elif (y <= -6e-52) or not ((y <= 7.5e-164) or (not (y <= 8e-153) and (y <= 1.92e-131))): tmp = y * z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (y <= -1.65e+125) tmp = Float64(y * x); elseif ((y <= -6e-52) || !((y <= 7.5e-164) || (!(y <= 8e-153) && (y <= 1.92e-131)))) tmp = Float64(y * z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -1.65e+125) tmp = y * x; elseif ((y <= -6e-52) || ~(((y <= 7.5e-164) || (~((y <= 8e-153)) && (y <= 1.92e-131))))) tmp = y * z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -1.65e+125], N[(y * x), $MachinePrecision], If[Or[LessEqual[y, -6e-52], N[Not[Or[LessEqual[y, 7.5e-164], And[N[Not[LessEqual[y, 8e-153]], $MachinePrecision], LessEqual[y, 1.92e-131]]]], $MachinePrecision]], N[(y * z), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.65 \cdot 10^{+125}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;y \leq -6 \cdot 10^{-52} \lor \neg \left(y \leq 7.5 \cdot 10^{-164} \lor \neg \left(y \leq 8 \cdot 10^{-153}\right) \land y \leq 1.92 \cdot 10^{-131}\right):\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -1.65000000000000003e125Initial program 100.0%
+-commutative100.0%
fma-define100.0%
+-commutative100.0%
Simplified100.0%
fma-undefine100.0%
+-commutative100.0%
+-commutative100.0%
distribute-lft-in95.0%
associate-+r+95.0%
Applied egg-rr95.0%
Taylor expanded in y around inf 100.0%
+-commutative100.0%
Simplified100.0%
Taylor expanded in z around 0 61.6%
*-commutative61.6%
Simplified61.6%
if -1.65000000000000003e125 < y < -6e-52 or 7.5000000000000006e-164 < y < 8.00000000000000031e-153 or 1.92000000000000012e-131 < y Initial program 100.0%
+-commutative100.0%
fma-define100.0%
+-commutative100.0%
Simplified100.0%
fma-undefine100.0%
+-commutative100.0%
+-commutative100.0%
distribute-lft-in96.8%
associate-+r+96.8%
Applied egg-rr96.8%
Taylor expanded in x around 0 59.8%
if -6e-52 < y < 7.5000000000000006e-164 or 8.00000000000000031e-153 < y < 1.92000000000000012e-131Initial program 100.0%
Taylor expanded in y around 0 77.1%
Final simplification66.2%
(FPCore (x y z) :precision binary64 (if (or (<= y -1.0) (not (<= y 1.0))) (* y (+ x z)) (+ x (* y z))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -1.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 <= (-1.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 <= -1.0) || !(y <= 1.0)) {
tmp = y * (x + z);
} else {
tmp = x + (y * z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -1.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 <= -1.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 <= -1.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, -1.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 -1 \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 < -1 or 1 < y Initial program 100.0%
+-commutative100.0%
fma-define100.0%
+-commutative100.0%
Simplified100.0%
fma-undefine100.0%
+-commutative100.0%
+-commutative100.0%
distribute-lft-in95.4%
associate-+r+95.4%
Applied egg-rr95.4%
Taylor expanded in y around inf 99.3%
+-commutative99.3%
Simplified99.3%
if -1 < y < 1Initial program 100.0%
Taylor expanded in z around inf 99.2%
Final simplification99.2%
(FPCore (x y z) :precision binary64 (if (or (<= x -1.7e+35) (not (<= x 3.1e+88))) (* x (+ y 1.0)) (* y (+ x z))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1.7e+35) || !(x <= 3.1e+88)) {
tmp = x * (y + 1.0);
} else {
tmp = y * (x + 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 <= (-1.7d+35)) .or. (.not. (x <= 3.1d+88))) then
tmp = x * (y + 1.0d0)
else
tmp = y * (x + z)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -1.7e+35) || !(x <= 3.1e+88)) {
tmp = x * (y + 1.0);
} else {
tmp = y * (x + z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -1.7e+35) or not (x <= 3.1e+88): tmp = x * (y + 1.0) else: tmp = y * (x + z) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -1.7e+35) || !(x <= 3.1e+88)) tmp = Float64(x * Float64(y + 1.0)); else tmp = Float64(y * Float64(x + z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -1.7e+35) || ~((x <= 3.1e+88))) tmp = x * (y + 1.0); else tmp = y * (x + z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -1.7e+35], N[Not[LessEqual[x, 3.1e+88]], $MachinePrecision]], N[(x * N[(y + 1.0), $MachinePrecision]), $MachinePrecision], N[(y * N[(x + z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.7 \cdot 10^{+35} \lor \neg \left(x \leq 3.1 \cdot 10^{+88}\right):\\
\;\;\;\;x \cdot \left(y + 1\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(x + z\right)\\
\end{array}
\end{array}
if x < -1.7000000000000001e35 or 3.1000000000000001e88 < x Initial program 100.0%
Taylor expanded in x around inf 92.2%
+-commutative92.2%
Simplified92.2%
if -1.7000000000000001e35 < x < 3.1000000000000001e88Initial program 100.0%
+-commutative100.0%
fma-define100.0%
+-commutative100.0%
Simplified100.0%
fma-undefine100.0%
+-commutative100.0%
+-commutative100.0%
distribute-lft-in100.0%
associate-+r+100.0%
Applied egg-rr100.0%
Taylor expanded in y around inf 79.1%
+-commutative79.1%
Simplified79.1%
Final simplification83.9%
(FPCore (x y z) :precision binary64 (if (or (<= x -1.12e-110) (not (<= x 4.3e-131))) (* x (+ y 1.0)) (* y z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1.12e-110) || !(x <= 4.3e-131)) {
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 <= (-1.12d-110)) .or. (.not. (x <= 4.3d-131))) 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 <= -1.12e-110) || !(x <= 4.3e-131)) {
tmp = x * (y + 1.0);
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -1.12e-110) or not (x <= 4.3e-131): tmp = x * (y + 1.0) else: tmp = y * z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -1.12e-110) || !(x <= 4.3e-131)) 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 <= -1.12e-110) || ~((x <= 4.3e-131))) tmp = x * (y + 1.0); else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -1.12e-110], N[Not[LessEqual[x, 4.3e-131]], $MachinePrecision]], N[(x * N[(y + 1.0), $MachinePrecision]), $MachinePrecision], N[(y * z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.12 \cdot 10^{-110} \lor \neg \left(x \leq 4.3 \cdot 10^{-131}\right):\\
\;\;\;\;x \cdot \left(y + 1\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if x < -1.11999999999999998e-110 or 4.30000000000000019e-131 < x Initial program 100.0%
Taylor expanded in x around inf 76.5%
+-commutative76.5%
Simplified76.5%
if -1.11999999999999998e-110 < x < 4.30000000000000019e-131Initial program 100.0%
+-commutative100.0%
fma-define100.0%
+-commutative100.0%
Simplified100.0%
fma-undefine100.0%
+-commutative100.0%
+-commutative100.0%
distribute-lft-in100.0%
associate-+r+100.0%
Applied egg-rr100.0%
Taylor expanded in x around 0 75.5%
Final simplification76.2%
(FPCore (x y z) :precision binary64 (if (<= x -1.55e+36) (+ x (* y x)) (if (<= x 6.8e+87) (* y (+ x z)) (* x (+ y 1.0)))))
double code(double x, double y, double z) {
double tmp;
if (x <= -1.55e+36) {
tmp = x + (y * x);
} else if (x <= 6.8e+87) {
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 (x <= (-1.55d+36)) then
tmp = x + (y * x)
else if (x <= 6.8d+87) 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 (x <= -1.55e+36) {
tmp = x + (y * x);
} else if (x <= 6.8e+87) {
tmp = y * (x + z);
} else {
tmp = x * (y + 1.0);
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -1.55e+36: tmp = x + (y * x) elif x <= 6.8e+87: tmp = y * (x + z) else: tmp = x * (y + 1.0) return tmp
function code(x, y, z) tmp = 0.0 if (x <= -1.55e+36) tmp = Float64(x + Float64(y * x)); elseif (x <= 6.8e+87) 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 (x <= -1.55e+36) tmp = x + (y * x); elseif (x <= 6.8e+87) tmp = y * (x + z); else tmp = x * (y + 1.0); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -1.55e+36], N[(x + N[(y * x), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 6.8e+87], N[(y * N[(x + z), $MachinePrecision]), $MachinePrecision], N[(x * N[(y + 1.0), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.55 \cdot 10^{+36}:\\
\;\;\;\;x + y \cdot x\\
\mathbf{elif}\;x \leq 6.8 \cdot 10^{+87}:\\
\;\;\;\;y \cdot \left(x + z\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(y + 1\right)\\
\end{array}
\end{array}
if x < -1.55e36Initial program 100.0%
Taylor expanded in z around 0 88.4%
*-commutative88.4%
Simplified88.4%
if -1.55e36 < x < 6.8000000000000004e87Initial program 100.0%
+-commutative100.0%
fma-define100.0%
+-commutative100.0%
Simplified100.0%
fma-undefine100.0%
+-commutative100.0%
+-commutative100.0%
distribute-lft-in100.0%
associate-+r+100.0%
Applied egg-rr100.0%
Taylor expanded in y around inf 79.1%
+-commutative79.1%
Simplified79.1%
if 6.8000000000000004e87 < x Initial program 100.0%
Taylor expanded in x around inf 97.6%
+-commutative97.6%
Simplified97.6%
Final simplification83.9%
(FPCore (x y z) :precision binary64 (if (or (<= y -1.0) (not (<= y 1.0))) (* y x) x))
double code(double x, double y, double z) {
double tmp;
if ((y <= -1.0) || !(y <= 1.0)) {
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 <= (-1.0d0)) .or. (.not. (y <= 1.0d0))) 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 <= -1.0) || !(y <= 1.0)) {
tmp = y * x;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -1.0) or not (y <= 1.0): tmp = y * x else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -1.0) || !(y <= 1.0)) tmp = Float64(y * x); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -1.0) || ~((y <= 1.0))) tmp = y * x; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -1.0], N[Not[LessEqual[y, 1.0]], $MachinePrecision]], N[(y * x), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1 \lor \neg \left(y \leq 1\right):\\
\;\;\;\;y \cdot x\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -1 or 1 < y Initial program 100.0%
+-commutative100.0%
fma-define100.0%
+-commutative100.0%
Simplified100.0%
fma-undefine100.0%
+-commutative100.0%
+-commutative100.0%
distribute-lft-in95.4%
associate-+r+95.4%
Applied egg-rr95.4%
Taylor expanded in y around inf 99.3%
+-commutative99.3%
Simplified99.3%
Taylor expanded in z around 0 49.8%
*-commutative50.4%
Simplified49.8%
if -1 < y < 1Initial program 100.0%
Taylor expanded in y around 0 66.4%
Final simplification57.9%
(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 34.0%
herbie shell --seed 2024108
(FPCore (x y z)
:name "Main:bigenough2 from A"
:precision binary64
(+ x (* y (+ z x))))