
(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 -4.3e-22) (* y z) (if (<= y 1.0) x (if (<= y 1.8e+270) (* y x) (* y z)))))
double code(double x, double y, double z) {
double tmp;
if (y <= -4.3e-22) {
tmp = y * z;
} else if (y <= 1.0) {
tmp = x;
} else if (y <= 1.8e+270) {
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 <= (-4.3d-22)) then
tmp = y * z
else if (y <= 1.0d0) then
tmp = x
else if (y <= 1.8d+270) 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 <= -4.3e-22) {
tmp = y * z;
} else if (y <= 1.0) {
tmp = x;
} else if (y <= 1.8e+270) {
tmp = y * x;
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -4.3e-22: tmp = y * z elif y <= 1.0: tmp = x elif y <= 1.8e+270: tmp = y * x else: tmp = y * z return tmp
function code(x, y, z) tmp = 0.0 if (y <= -4.3e-22) tmp = Float64(y * z); elseif (y <= 1.0) tmp = x; elseif (y <= 1.8e+270) 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 <= -4.3e-22) tmp = y * z; elseif (y <= 1.0) tmp = x; elseif (y <= 1.8e+270) tmp = y * x; else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -4.3e-22], N[(y * z), $MachinePrecision], If[LessEqual[y, 1.0], x, If[LessEqual[y, 1.8e+270], N[(y * x), $MachinePrecision], N[(y * z), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -4.3 \cdot 10^{-22}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;y \leq 1:\\
\;\;\;\;x\\
\mathbf{elif}\;y \leq 1.8 \cdot 10^{+270}:\\
\;\;\;\;y \cdot x\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if y < -4.30000000000000037e-22 or 1.8000000000000001e270 < y Initial program 100.0%
Taylor expanded in x around 0 58.9%
if -4.30000000000000037e-22 < y < 1Initial program 100.0%
Taylor expanded in y around 0 74.2%
if 1 < y < 1.8000000000000001e270Initial program 100.0%
Taylor expanded in x around inf 67.8%
+-commutative67.8%
Simplified67.8%
Taylor expanded in y around inf 66.1%
*-commutative66.1%
Simplified66.1%
Final simplification67.7%
(FPCore (x y z) :precision binary64 (if (or (<= z -3.8e+78) (not (<= z 2.55e+30))) (* y z) (* x (+ y 1.0))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -3.8e+78) || !(z <= 2.55e+30)) {
tmp = y * 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 <= (-3.8d+78)) .or. (.not. (z <= 2.55d+30))) then
tmp = y * 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 <= -3.8e+78) || !(z <= 2.55e+30)) {
tmp = y * z;
} else {
tmp = x * (y + 1.0);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -3.8e+78) or not (z <= 2.55e+30): tmp = y * z else: tmp = x * (y + 1.0) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -3.8e+78) || !(z <= 2.55e+30)) tmp = Float64(y * 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 <= -3.8e+78) || ~((z <= 2.55e+30))) tmp = y * z; else tmp = x * (y + 1.0); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -3.8e+78], N[Not[LessEqual[z, 2.55e+30]], $MachinePrecision]], N[(y * z), $MachinePrecision], N[(x * N[(y + 1.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -3.8 \cdot 10^{+78} \lor \neg \left(z \leq 2.55 \cdot 10^{+30}\right):\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(y + 1\right)\\
\end{array}
\end{array}
if z < -3.7999999999999999e78 or 2.55000000000000018e30 < z Initial program 100.0%
Taylor expanded in x around 0 70.7%
if -3.7999999999999999e78 < z < 2.55000000000000018e30Initial program 100.0%
Taylor expanded in x around inf 84.0%
+-commutative84.0%
Simplified84.0%
Final simplification78.6%
(FPCore (x y z) :precision binary64 (if (or (<= y -3.6e-21) (not (<= y 3e-70))) (* y (+ x z)) x))
double code(double x, double y, double z) {
double tmp;
if ((y <= -3.6e-21) || !(y <= 3e-70)) {
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 <= (-3.6d-21)) .or. (.not. (y <= 3d-70))) 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 <= -3.6e-21) || !(y <= 3e-70)) {
tmp = y * (x + z);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -3.6e-21) or not (y <= 3e-70): tmp = y * (x + z) else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -3.6e-21) || !(y <= 3e-70)) 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 <= -3.6e-21) || ~((y <= 3e-70))) tmp = y * (x + z); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -3.6e-21], N[Not[LessEqual[y, 3e-70]], $MachinePrecision]], N[(y * N[(x + z), $MachinePrecision]), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -3.6 \cdot 10^{-21} \lor \neg \left(y \leq 3 \cdot 10^{-70}\right):\\
\;\;\;\;y \cdot \left(x + z\right)\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -3.59999999999999989e-21 or 3.0000000000000001e-70 < y Initial program 100.0%
Taylor expanded in y around inf 94.9%
+-commutative94.9%
Simplified94.9%
if -3.59999999999999989e-21 < y < 3.0000000000000001e-70Initial program 100.0%
Taylor expanded in y around 0 79.2%
Final simplification88.4%
(FPCore (x y z) :precision binary64 (if (or (<= y -1.2e-16) (not (<= y 1.0))) (* y x) x))
double code(double x, double y, double z) {
double tmp;
if ((y <= -1.2e-16) || !(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.2d-16)) .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.2e-16) || !(y <= 1.0)) {
tmp = y * x;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -1.2e-16) or not (y <= 1.0): tmp = y * x else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -1.2e-16) || !(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.2e-16) || ~((y <= 1.0))) tmp = y * x; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -1.2e-16], N[Not[LessEqual[y, 1.0]], $MachinePrecision]], N[(y * x), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.2 \cdot 10^{-16} \lor \neg \left(y \leq 1\right):\\
\;\;\;\;y \cdot x\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -1.20000000000000002e-16 or 1 < y Initial program 100.0%
Taylor expanded in x around inf 53.5%
+-commutative53.5%
Simplified53.5%
Taylor expanded in y around inf 52.9%
*-commutative52.9%
Simplified52.9%
if -1.20000000000000002e-16 < y < 1Initial program 100.0%
Taylor expanded in y around 0 73.7%
Final simplification62.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 37.1%
Final simplification37.1%
herbie shell --seed 2023299
(FPCore (x y z)
:name "Main:bigenough2 from A"
:precision binary64
(+ x (* y (+ z x))))