
(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-define100.0%
+-commutative100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x y z)
:precision binary64
(if (<= y -7.5e+129)
(* y z)
(if (<= y -6.3e+35)
(* y x)
(if (<= y -2.8e-11)
(* y z)
(if (<= y 1.18e-32)
x
(if (or (<= y 4.2e+173) (not (<= y 5.8e+242))) (* y z) (* y x)))))))
double code(double x, double y, double z) {
double tmp;
if (y <= -7.5e+129) {
tmp = y * z;
} else if (y <= -6.3e+35) {
tmp = y * x;
} else if (y <= -2.8e-11) {
tmp = y * z;
} else if (y <= 1.18e-32) {
tmp = x;
} else if ((y <= 4.2e+173) || !(y <= 5.8e+242)) {
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 <= (-7.5d+129)) then
tmp = y * z
else if (y <= (-6.3d+35)) then
tmp = y * x
else if (y <= (-2.8d-11)) then
tmp = y * z
else if (y <= 1.18d-32) then
tmp = x
else if ((y <= 4.2d+173) .or. (.not. (y <= 5.8d+242))) 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 <= -7.5e+129) {
tmp = y * z;
} else if (y <= -6.3e+35) {
tmp = y * x;
} else if (y <= -2.8e-11) {
tmp = y * z;
} else if (y <= 1.18e-32) {
tmp = x;
} else if ((y <= 4.2e+173) || !(y <= 5.8e+242)) {
tmp = y * z;
} else {
tmp = y * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -7.5e+129: tmp = y * z elif y <= -6.3e+35: tmp = y * x elif y <= -2.8e-11: tmp = y * z elif y <= 1.18e-32: tmp = x elif (y <= 4.2e+173) or not (y <= 5.8e+242): tmp = y * z else: tmp = y * x return tmp
function code(x, y, z) tmp = 0.0 if (y <= -7.5e+129) tmp = Float64(y * z); elseif (y <= -6.3e+35) tmp = Float64(y * x); elseif (y <= -2.8e-11) tmp = Float64(y * z); elseif (y <= 1.18e-32) tmp = x; elseif ((y <= 4.2e+173) || !(y <= 5.8e+242)) 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 <= -7.5e+129) tmp = y * z; elseif (y <= -6.3e+35) tmp = y * x; elseif (y <= -2.8e-11) tmp = y * z; elseif (y <= 1.18e-32) tmp = x; elseif ((y <= 4.2e+173) || ~((y <= 5.8e+242))) tmp = y * z; else tmp = y * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -7.5e+129], N[(y * z), $MachinePrecision], If[LessEqual[y, -6.3e+35], N[(y * x), $MachinePrecision], If[LessEqual[y, -2.8e-11], N[(y * z), $MachinePrecision], If[LessEqual[y, 1.18e-32], x, If[Or[LessEqual[y, 4.2e+173], N[Not[LessEqual[y, 5.8e+242]], $MachinePrecision]], N[(y * z), $MachinePrecision], N[(y * x), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -7.5 \cdot 10^{+129}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;y \leq -6.3 \cdot 10^{+35}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;y \leq -2.8 \cdot 10^{-11}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;y \leq 1.18 \cdot 10^{-32}:\\
\;\;\;\;x\\
\mathbf{elif}\;y \leq 4.2 \cdot 10^{+173} \lor \neg \left(y \leq 5.8 \cdot 10^{+242}\right):\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;y \cdot x\\
\end{array}
\end{array}
if y < -7.4999999999999998e129 or -6.29999999999999969e35 < y < -2.8e-11 or 1.17999999999999997e-32 < y < 4.2e173 or 5.79999999999999994e242 < y Initial program 100.0%
Taylor expanded in x around 0 67.9%
if -7.4999999999999998e129 < y < -6.29999999999999969e35 or 4.2e173 < y < 5.79999999999999994e242Initial program 100.0%
Taylor expanded in y around inf 100.0%
+-commutative100.0%
Simplified100.0%
Taylor expanded in z around 0 79.1%
*-commutative79.1%
Simplified79.1%
if -2.8e-11 < y < 1.17999999999999997e-32Initial program 100.0%
Taylor expanded in y around 0 80.1%
Final simplification75.2%
(FPCore (x y z)
:precision binary64
(if (or (<= x -5e-90)
(not
(or (<= x -2.55e-138) (and (not (<= x -3.8e-173)) (<= x 3000.0)))))
(* x (+ y 1.0))
(* y z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -5e-90) || !((x <= -2.55e-138) || (!(x <= -3.8e-173) && (x <= 3000.0)))) {
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 <= (-5d-90)) .or. (.not. (x <= (-2.55d-138)) .or. (.not. (x <= (-3.8d-173))) .and. (x <= 3000.0d0))) 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 <= -5e-90) || !((x <= -2.55e-138) || (!(x <= -3.8e-173) && (x <= 3000.0)))) {
tmp = x * (y + 1.0);
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -5e-90) or not ((x <= -2.55e-138) or (not (x <= -3.8e-173) and (x <= 3000.0))): tmp = x * (y + 1.0) else: tmp = y * z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -5e-90) || !((x <= -2.55e-138) || (!(x <= -3.8e-173) && (x <= 3000.0)))) 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 <= -5e-90) || ~(((x <= -2.55e-138) || (~((x <= -3.8e-173)) && (x <= 3000.0))))) tmp = x * (y + 1.0); else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -5e-90], N[Not[Or[LessEqual[x, -2.55e-138], And[N[Not[LessEqual[x, -3.8e-173]], $MachinePrecision], LessEqual[x, 3000.0]]]], $MachinePrecision]], N[(x * N[(y + 1.0), $MachinePrecision]), $MachinePrecision], N[(y * z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -5 \cdot 10^{-90} \lor \neg \left(x \leq -2.55 \cdot 10^{-138} \lor \neg \left(x \leq -3.8 \cdot 10^{-173}\right) \land x \leq 3000\right):\\
\;\;\;\;x \cdot \left(y + 1\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if x < -5.00000000000000019e-90 or -2.5500000000000001e-138 < x < -3.8000000000000003e-173 or 3e3 < x Initial program 100.0%
Taylor expanded in x around inf 86.2%
+-commutative86.2%
Simplified86.2%
if -5.00000000000000019e-90 < x < -2.5500000000000001e-138 or -3.8000000000000003e-173 < x < 3e3Initial program 100.0%
Taylor expanded in x around 0 73.1%
Final simplification81.1%
(FPCore (x y z) :precision binary64 (if (or (<= y -1.12e-10) (not (<= y 2.2e-36))) (* y (+ x z)) (* x (+ y 1.0))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -1.12e-10) || !(y <= 2.2e-36)) {
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 <= (-1.12d-10)) .or. (.not. (y <= 2.2d-36))) 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 <= -1.12e-10) || !(y <= 2.2e-36)) {
tmp = y * (x + z);
} else {
tmp = x * (y + 1.0);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -1.12e-10) or not (y <= 2.2e-36): tmp = y * (x + z) else: tmp = x * (y + 1.0) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -1.12e-10) || !(y <= 2.2e-36)) 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 <= -1.12e-10) || ~((y <= 2.2e-36))) tmp = y * (x + z); else tmp = x * (y + 1.0); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -1.12e-10], N[Not[LessEqual[y, 2.2e-36]], $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 -1.12 \cdot 10^{-10} \lor \neg \left(y \leq 2.2 \cdot 10^{-36}\right):\\
\;\;\;\;y \cdot \left(x + z\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(y + 1\right)\\
\end{array}
\end{array}
if y < -1.12e-10 or 2.1999999999999999e-36 < y Initial program 100.0%
Taylor expanded in y around inf 97.1%
+-commutative97.1%
Simplified97.1%
if -1.12e-10 < y < 2.1999999999999999e-36Initial program 100.0%
Taylor expanded in x around inf 80.9%
+-commutative80.9%
Simplified80.9%
Final simplification89.4%
(FPCore (x y z) :precision binary64 (if (or (<= y -4.1e-10) (not (<= y 105000000.0))) (* y x) x))
double code(double x, double y, double z) {
double tmp;
if ((y <= -4.1e-10) || !(y <= 105000000.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 <= (-4.1d-10)) .or. (.not. (y <= 105000000.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 <= -4.1e-10) || !(y <= 105000000.0)) {
tmp = y * x;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -4.1e-10) or not (y <= 105000000.0): tmp = y * x else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -4.1e-10) || !(y <= 105000000.0)) tmp = Float64(y * x); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -4.1e-10) || ~((y <= 105000000.0))) tmp = y * x; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -4.1e-10], N[Not[LessEqual[y, 105000000.0]], $MachinePrecision]], N[(y * x), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -4.1 \cdot 10^{-10} \lor \neg \left(y \leq 105000000\right):\\
\;\;\;\;y \cdot x\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -4.0999999999999998e-10 or 1.05e8 < y Initial program 100.0%
Taylor expanded in y around inf 99.8%
+-commutative99.8%
Simplified99.8%
Taylor expanded in z around 0 48.6%
*-commutative48.6%
Simplified48.6%
if -4.0999999999999998e-10 < y < 1.05e8Initial program 100.0%
Taylor expanded in y around 0 76.5%
Final simplification63.1%
(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 41.0%
Final simplification41.0%
herbie shell --seed 2024082
(FPCore (x y z)
:name "Main:bigenough2 from A"
:precision binary64
(+ x (* y (+ z x))))