
(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.4e+117)
(* y x)
(if (<= y -2.2e+73)
(* y z)
(if (<= y -1.0)
(* y x)
(if (<= y 6.2e-98)
x
(if (<= y 2.1e+52)
(* y z)
(if (or (<= y 1.35e+93) (and (not (<= y 4.2e+197)) (<= y 3.1e+297)))
(* y x)
(* y z))))))))
double code(double x, double y, double z) {
double tmp;
if (y <= -2.4e+117) {
tmp = y * x;
} else if (y <= -2.2e+73) {
tmp = y * z;
} else if (y <= -1.0) {
tmp = y * x;
} else if (y <= 6.2e-98) {
tmp = x;
} else if (y <= 2.1e+52) {
tmp = y * z;
} else if ((y <= 1.35e+93) || (!(y <= 4.2e+197) && (y <= 3.1e+297))) {
tmp = y * x;
} 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 (y <= (-2.4d+117)) then
tmp = y * x
else if (y <= (-2.2d+73)) then
tmp = y * z
else if (y <= (-1.0d0)) then
tmp = y * x
else if (y <= 6.2d-98) then
tmp = x
else if (y <= 2.1d+52) then
tmp = y * z
else if ((y <= 1.35d+93) .or. (.not. (y <= 4.2d+197)) .and. (y <= 3.1d+297)) then
tmp = y * x
else
tmp = y * z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= -2.4e+117) {
tmp = y * x;
} else if (y <= -2.2e+73) {
tmp = y * z;
} else if (y <= -1.0) {
tmp = y * x;
} else if (y <= 6.2e-98) {
tmp = x;
} else if (y <= 2.1e+52) {
tmp = y * z;
} else if ((y <= 1.35e+93) || (!(y <= 4.2e+197) && (y <= 3.1e+297))) {
tmp = y * x;
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -2.4e+117: tmp = y * x elif y <= -2.2e+73: tmp = y * z elif y <= -1.0: tmp = y * x elif y <= 6.2e-98: tmp = x elif y <= 2.1e+52: tmp = y * z elif (y <= 1.35e+93) or (not (y <= 4.2e+197) and (y <= 3.1e+297)): tmp = y * x else: tmp = y * z return tmp
function code(x, y, z) tmp = 0.0 if (y <= -2.4e+117) tmp = Float64(y * x); elseif (y <= -2.2e+73) tmp = Float64(y * z); elseif (y <= -1.0) tmp = Float64(y * x); elseif (y <= 6.2e-98) tmp = x; elseif (y <= 2.1e+52) tmp = Float64(y * z); elseif ((y <= 1.35e+93) || (!(y <= 4.2e+197) && (y <= 3.1e+297))) tmp = Float64(y * x); else tmp = Float64(y * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -2.4e+117) tmp = y * x; elseif (y <= -2.2e+73) tmp = y * z; elseif (y <= -1.0) tmp = y * x; elseif (y <= 6.2e-98) tmp = x; elseif (y <= 2.1e+52) tmp = y * z; elseif ((y <= 1.35e+93) || (~((y <= 4.2e+197)) && (y <= 3.1e+297))) tmp = y * x; else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -2.4e+117], N[(y * x), $MachinePrecision], If[LessEqual[y, -2.2e+73], N[(y * z), $MachinePrecision], If[LessEqual[y, -1.0], N[(y * x), $MachinePrecision], If[LessEqual[y, 6.2e-98], x, If[LessEqual[y, 2.1e+52], N[(y * z), $MachinePrecision], If[Or[LessEqual[y, 1.35e+93], And[N[Not[LessEqual[y, 4.2e+197]], $MachinePrecision], LessEqual[y, 3.1e+297]]], N[(y * x), $MachinePrecision], N[(y * z), $MachinePrecision]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.4 \cdot 10^{+117}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;y \leq -2.2 \cdot 10^{+73}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;y \leq -1:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;y \leq 6.2 \cdot 10^{-98}:\\
\;\;\;\;x\\
\mathbf{elif}\;y \leq 2.1 \cdot 10^{+52}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;y \leq 1.35 \cdot 10^{+93} \lor \neg \left(y \leq 4.2 \cdot 10^{+197}\right) \land y \leq 3.1 \cdot 10^{+297}:\\
\;\;\;\;y \cdot x\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if y < -2.3999999999999999e117 or -2.2e73 < y < -1 or 2.1e52 < y < 1.35e93 or 4.20000000000000013e197 < y < 3.09999999999999985e297Initial program 100.0%
Taylor expanded in x around inf 67.8%
Taylor expanded in y around inf 67.8%
if -2.3999999999999999e117 < y < -2.2e73 or 6.2e-98 < y < 2.1e52 or 1.35e93 < y < 4.20000000000000013e197 or 3.09999999999999985e297 < y Initial program 100.0%
Taylor expanded in x around 0 63.7%
if -1 < y < 6.2e-98Initial program 100.0%
Taylor expanded in y around 0 72.9%
Final simplification68.9%
(FPCore (x y z) :precision binary64 (if (or (<= y -0.054) (not (<= y 6.2e-98))) (* y (+ x z)) x))
double code(double x, double y, double z) {
double tmp;
if ((y <= -0.054) || !(y <= 6.2e-98)) {
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 <= (-0.054d0)) .or. (.not. (y <= 6.2d-98))) 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 <= -0.054) || !(y <= 6.2e-98)) {
tmp = y * (x + z);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -0.054) or not (y <= 6.2e-98): tmp = y * (x + z) else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -0.054) || !(y <= 6.2e-98)) 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 <= -0.054) || ~((y <= 6.2e-98))) tmp = y * (x + z); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -0.054], N[Not[LessEqual[y, 6.2e-98]], $MachinePrecision]], N[(y * N[(x + z), $MachinePrecision]), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -0.054 \lor \neg \left(y \leq 6.2 \cdot 10^{-98}\right):\\
\;\;\;\;y \cdot \left(x + z\right)\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -0.0539999999999999994 or 6.2e-98 < y Initial program 100.0%
Taylor expanded in y around inf 93.1%
if -0.0539999999999999994 < y < 6.2e-98Initial program 100.0%
Taylor expanded in y around 0 72.9%
Final simplification84.5%
(FPCore (x y z) :precision binary64 (if (or (<= z -1.86e+84) (not (<= z 2.1e-21))) (* y (+ x z)) (* x (+ y 1.0))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -1.86e+84) || !(z <= 2.1e-21)) {
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 ((z <= (-1.86d+84)) .or. (.not. (z <= 2.1d-21))) 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 ((z <= -1.86e+84) || !(z <= 2.1e-21)) {
tmp = y * (x + z);
} else {
tmp = x * (y + 1.0);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -1.86e+84) or not (z <= 2.1e-21): tmp = y * (x + z) else: tmp = x * (y + 1.0) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -1.86e+84) || !(z <= 2.1e-21)) 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 ((z <= -1.86e+84) || ~((z <= 2.1e-21))) tmp = y * (x + z); else tmp = x * (y + 1.0); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -1.86e+84], N[Not[LessEqual[z, 2.1e-21]], $MachinePrecision]], N[(y * N[(x + z), $MachinePrecision]), $MachinePrecision], N[(x * N[(y + 1.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.86 \cdot 10^{+84} \lor \neg \left(z \leq 2.1 \cdot 10^{-21}\right):\\
\;\;\;\;y \cdot \left(x + z\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(y + 1\right)\\
\end{array}
\end{array}
if z < -1.86000000000000006e84 or 2.10000000000000013e-21 < z Initial program 100.0%
Taylor expanded in y around inf 86.0%
if -1.86000000000000006e84 < z < 2.10000000000000013e-21Initial program 100.0%
Taylor expanded in x around inf 86.1%
Final simplification86.1%
(FPCore (x y z) :precision binary64 (if (<= y -1.0) (* y x) (if (<= y 13000000.0) x (* y x))))
double code(double x, double y, double z) {
double tmp;
if (y <= -1.0) {
tmp = y * x;
} else if (y <= 13000000.0) {
tmp = x;
} 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 <= (-1.0d0)) then
tmp = y * x
else if (y <= 13000000.0d0) then
tmp = x
else
tmp = y * x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= -1.0) {
tmp = y * x;
} else if (y <= 13000000.0) {
tmp = x;
} else {
tmp = y * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -1.0: tmp = y * x elif y <= 13000000.0: tmp = x else: tmp = y * x return tmp
function code(x, y, z) tmp = 0.0 if (y <= -1.0) tmp = Float64(y * x); elseif (y <= 13000000.0) tmp = x; else tmp = Float64(y * x); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -1.0) tmp = y * x; elseif (y <= 13000000.0) tmp = x; else tmp = y * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -1.0], N[(y * x), $MachinePrecision], If[LessEqual[y, 13000000.0], x, N[(y * x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;y \leq 13000000:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;y \cdot x\\
\end{array}
\end{array}
if y < -1 or 1.3e7 < y Initial program 100.0%
Taylor expanded in x around inf 55.7%
Taylor expanded in y around inf 55.6%
if -1 < y < 1.3e7Initial program 100.0%
Taylor expanded in y around 0 67.0%
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 36.2%
Final simplification36.2%
herbie shell --seed 2023257
(FPCore (x y z)
:name "Main:bigenough2 from A"
:precision binary64
(+ x (* y (+ z x))))