
(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 8 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 -3e+205)
(* y x)
(if (<= y -3.2e+48)
(* y z)
(if (<= y -1.7e+21)
(* y x)
(if (<= y -5.4e-70)
(* y z)
(if (<= y 2.9e-39) x (if (<= y 50000000000.0) (* y z) (* y x))))))))
double code(double x, double y, double z) {
double tmp;
if (y <= -3e+205) {
tmp = y * x;
} else if (y <= -3.2e+48) {
tmp = y * z;
} else if (y <= -1.7e+21) {
tmp = y * x;
} else if (y <= -5.4e-70) {
tmp = y * z;
} else if (y <= 2.9e-39) {
tmp = x;
} else if (y <= 50000000000.0) {
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 <= (-3d+205)) then
tmp = y * x
else if (y <= (-3.2d+48)) then
tmp = y * z
else if (y <= (-1.7d+21)) then
tmp = y * x
else if (y <= (-5.4d-70)) then
tmp = y * z
else if (y <= 2.9d-39) then
tmp = x
else if (y <= 50000000000.0d0) 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 <= -3e+205) {
tmp = y * x;
} else if (y <= -3.2e+48) {
tmp = y * z;
} else if (y <= -1.7e+21) {
tmp = y * x;
} else if (y <= -5.4e-70) {
tmp = y * z;
} else if (y <= 2.9e-39) {
tmp = x;
} else if (y <= 50000000000.0) {
tmp = y * z;
} else {
tmp = y * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -3e+205: tmp = y * x elif y <= -3.2e+48: tmp = y * z elif y <= -1.7e+21: tmp = y * x elif y <= -5.4e-70: tmp = y * z elif y <= 2.9e-39: tmp = x elif y <= 50000000000.0: tmp = y * z else: tmp = y * x return tmp
function code(x, y, z) tmp = 0.0 if (y <= -3e+205) tmp = Float64(y * x); elseif (y <= -3.2e+48) tmp = Float64(y * z); elseif (y <= -1.7e+21) tmp = Float64(y * x); elseif (y <= -5.4e-70) tmp = Float64(y * z); elseif (y <= 2.9e-39) tmp = x; elseif (y <= 50000000000.0) 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 <= -3e+205) tmp = y * x; elseif (y <= -3.2e+48) tmp = y * z; elseif (y <= -1.7e+21) tmp = y * x; elseif (y <= -5.4e-70) tmp = y * z; elseif (y <= 2.9e-39) tmp = x; elseif (y <= 50000000000.0) tmp = y * z; else tmp = y * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -3e+205], N[(y * x), $MachinePrecision], If[LessEqual[y, -3.2e+48], N[(y * z), $MachinePrecision], If[LessEqual[y, -1.7e+21], N[(y * x), $MachinePrecision], If[LessEqual[y, -5.4e-70], N[(y * z), $MachinePrecision], If[LessEqual[y, 2.9e-39], x, If[LessEqual[y, 50000000000.0], N[(y * z), $MachinePrecision], N[(y * x), $MachinePrecision]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -3 \cdot 10^{+205}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;y \leq -3.2 \cdot 10^{+48}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;y \leq -1.7 \cdot 10^{+21}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;y \leq -5.4 \cdot 10^{-70}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;y \leq 2.9 \cdot 10^{-39}:\\
\;\;\;\;x\\
\mathbf{elif}\;y \leq 50000000000:\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;y \cdot x\\
\end{array}
\end{array}
if y < -2.9999999999999999e205 or -3.2000000000000001e48 < y < -1.7e21 or 5e10 < y Initial program 100.0%
Taylor expanded in x around 0 97.9%
Taylor expanded in y around inf 99.7%
+-commutative99.7%
Simplified99.7%
Taylor expanded in z around 0 65.8%
*-commutative65.8%
Simplified65.8%
if -2.9999999999999999e205 < y < -3.2000000000000001e48 or -1.7e21 < y < -5.4000000000000003e-70 or 2.89999999999999988e-39 < y < 5e10Initial program 100.0%
Taylor expanded in x around 0 98.4%
Taylor expanded in x around 0 63.1%
if -5.4000000000000003e-70 < y < 2.89999999999999988e-39Initial program 100.0%
Taylor expanded in y around 0 75.7%
(FPCore (x y z) :precision binary64 (if (or (<= y -2.6e+20) (not (<= y 1.0))) (* y (+ x z)) (+ x (* y z))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -2.6e+20) || !(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 <= (-2.6d+20)) .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 <= -2.6e+20) || !(y <= 1.0)) {
tmp = y * (x + z);
} else {
tmp = x + (y * z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -2.6e+20) 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 <= -2.6e+20) || !(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 <= -2.6e+20) || ~((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, -2.6e+20], 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 -2.6 \cdot 10^{+20} \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 < -2.6e20 or 1 < y Initial program 100.0%
Taylor expanded in x around 0 97.7%
Taylor expanded in y around inf 99.8%
+-commutative99.8%
Simplified99.8%
if -2.6e20 < y < 1Initial program 100.0%
Taylor expanded in z around inf 97.7%
Final simplification98.8%
(FPCore (x y z) :precision binary64 (if (or (<= x -3e+15) (not (<= x 2.1e+69))) (* x (+ y 1.0)) (* y (+ x z))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -3e+15) || !(x <= 2.1e+69)) {
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 <= (-3d+15)) .or. (.not. (x <= 2.1d+69))) 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 <= -3e+15) || !(x <= 2.1e+69)) {
tmp = x * (y + 1.0);
} else {
tmp = y * (x + z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -3e+15) or not (x <= 2.1e+69): tmp = x * (y + 1.0) else: tmp = y * (x + z) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -3e+15) || !(x <= 2.1e+69)) 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 <= -3e+15) || ~((x <= 2.1e+69))) tmp = x * (y + 1.0); else tmp = y * (x + z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -3e+15], N[Not[LessEqual[x, 2.1e+69]], $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 -3 \cdot 10^{+15} \lor \neg \left(x \leq 2.1 \cdot 10^{+69}\right):\\
\;\;\;\;x \cdot \left(y + 1\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(x + z\right)\\
\end{array}
\end{array}
if x < -3e15 or 2.10000000000000015e69 < x Initial program 100.0%
Taylor expanded in x around inf 94.8%
+-commutative94.8%
Simplified94.8%
if -3e15 < x < 2.10000000000000015e69Initial program 100.0%
Taylor expanded in x around 0 100.0%
Taylor expanded in y around inf 80.7%
+-commutative80.7%
Simplified80.7%
Final simplification86.9%
(FPCore (x y z) :precision binary64 (if (or (<= x -5.1e-117) (not (<= x 1.1e-104))) (* x (+ y 1.0)) (* y z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -5.1e-117) || !(x <= 1.1e-104)) {
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 <= (-5.1d-117)) .or. (.not. (x <= 1.1d-104))) 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 <= -5.1e-117) || !(x <= 1.1e-104)) {
tmp = x * (y + 1.0);
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -5.1e-117) or not (x <= 1.1e-104): tmp = x * (y + 1.0) else: tmp = y * z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -5.1e-117) || !(x <= 1.1e-104)) 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 <= -5.1e-117) || ~((x <= 1.1e-104))) tmp = x * (y + 1.0); else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -5.1e-117], N[Not[LessEqual[x, 1.1e-104]], $MachinePrecision]], N[(x * N[(y + 1.0), $MachinePrecision]), $MachinePrecision], N[(y * z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -5.1 \cdot 10^{-117} \lor \neg \left(x \leq 1.1 \cdot 10^{-104}\right):\\
\;\;\;\;x \cdot \left(y + 1\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if x < -5.1000000000000002e-117 or 1.10000000000000006e-104 < x Initial program 100.0%
Taylor expanded in x around inf 81.6%
+-commutative81.6%
Simplified81.6%
if -5.1000000000000002e-117 < x < 1.10000000000000006e-104Initial program 100.0%
Taylor expanded in x around 0 100.0%
Taylor expanded in x around 0 81.4%
Final simplification81.6%
(FPCore (x y z) :precision binary64 (if (or (<= y -2.6e+20) (not (<= y 1.0))) (* y x) x))
double code(double x, double y, double z) {
double tmp;
if ((y <= -2.6e+20) || !(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 <= (-2.6d+20)) .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 <= -2.6e+20) || !(y <= 1.0)) {
tmp = y * x;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -2.6e+20) or not (y <= 1.0): tmp = y * x else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -2.6e+20) || !(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 <= -2.6e+20) || ~((y <= 1.0))) tmp = y * x; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -2.6e+20], N[Not[LessEqual[y, 1.0]], $MachinePrecision]], N[(y * x), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.6 \cdot 10^{+20} \lor \neg \left(y \leq 1\right):\\
\;\;\;\;y \cdot x\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -2.6e20 or 1 < y Initial program 100.0%
Taylor expanded in x around 0 97.7%
Taylor expanded in y around inf 99.8%
+-commutative99.8%
Simplified99.8%
Taylor expanded in z around 0 58.4%
*-commutative58.4%
Simplified58.4%
if -2.6e20 < y < 1Initial program 100.0%
Taylor expanded in y around 0 64.6%
Final simplification61.5%
(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 2024086
(FPCore (x y z)
:name "Main:bigenough2 from A"
:precision binary64
(+ x (* y (+ z x))))