
(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 (or (<= z -6e+173)
(and (not (<= z -8e+81)) (or (<= z -1.9e-16) (not (<= z 0.16)))))
(+ x (* y z))
(* x (+ y 1.0))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -6e+173) || (!(z <= -8e+81) && ((z <= -1.9e-16) || !(z <= 0.16)))) {
tmp = x + (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 <= (-6d+173)) .or. (.not. (z <= (-8d+81))) .and. (z <= (-1.9d-16)) .or. (.not. (z <= 0.16d0))) then
tmp = x + (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 <= -6e+173) || (!(z <= -8e+81) && ((z <= -1.9e-16) || !(z <= 0.16)))) {
tmp = x + (y * z);
} else {
tmp = x * (y + 1.0);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -6e+173) or (not (z <= -8e+81) and ((z <= -1.9e-16) or not (z <= 0.16))): tmp = x + (y * z) else: tmp = x * (y + 1.0) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -6e+173) || (!(z <= -8e+81) && ((z <= -1.9e-16) || !(z <= 0.16)))) tmp = Float64(x + 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 <= -6e+173) || (~((z <= -8e+81)) && ((z <= -1.9e-16) || ~((z <= 0.16))))) tmp = x + (y * z); else tmp = x * (y + 1.0); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -6e+173], And[N[Not[LessEqual[z, -8e+81]], $MachinePrecision], Or[LessEqual[z, -1.9e-16], N[Not[LessEqual[z, 0.16]], $MachinePrecision]]]], N[(x + N[(y * z), $MachinePrecision]), $MachinePrecision], N[(x * N[(y + 1.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -6 \cdot 10^{+173} \lor \neg \left(z \leq -8 \cdot 10^{+81}\right) \land \left(z \leq -1.9 \cdot 10^{-16} \lor \neg \left(z \leq 0.16\right)\right):\\
\;\;\;\;x + y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(y + 1\right)\\
\end{array}
\end{array}
if z < -5.9999999999999995e173 or -7.99999999999999937e81 < z < -1.90000000000000006e-16 or 0.160000000000000003 < z Initial program 100.0%
Taylor expanded in z around inf 96.0%
if -5.9999999999999995e173 < z < -7.99999999999999937e81 or -1.90000000000000006e-16 < z < 0.160000000000000003Initial program 100.0%
Taylor expanded in x around inf 88.9%
+-commutative88.9%
Simplified88.9%
Final simplification92.1%
(FPCore (x y z) :precision binary64 (if (or (<= z -6e+173) (not (<= z 3.3e+100))) (* y z) (* x (+ y 1.0))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -6e+173) || !(z <= 3.3e+100)) {
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 <= (-6d+173)) .or. (.not. (z <= 3.3d+100))) 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 <= -6e+173) || !(z <= 3.3e+100)) {
tmp = y * z;
} else {
tmp = x * (y + 1.0);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -6e+173) or not (z <= 3.3e+100): tmp = y * z else: tmp = x * (y + 1.0) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -6e+173) || !(z <= 3.3e+100)) 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 <= -6e+173) || ~((z <= 3.3e+100))) tmp = y * z; else tmp = x * (y + 1.0); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -6e+173], N[Not[LessEqual[z, 3.3e+100]], $MachinePrecision]], N[(y * z), $MachinePrecision], N[(x * N[(y + 1.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -6 \cdot 10^{+173} \lor \neg \left(z \leq 3.3 \cdot 10^{+100}\right):\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(y + 1\right)\\
\end{array}
\end{array}
if z < -5.9999999999999995e173 or 3.3000000000000001e100 < z Initial program 100.0%
Taylor expanded in z around inf 100.0%
Taylor expanded in x around 0 78.7%
if -5.9999999999999995e173 < z < 3.3000000000000001e100Initial program 100.0%
Taylor expanded in x around inf 82.7%
+-commutative82.7%
Simplified82.7%
Final simplification81.5%
(FPCore (x y z) :precision binary64 (if (or (<= y -1.7e-13) (not (<= y 1.0))) (* y x) x))
double code(double x, double y, double z) {
double tmp;
if ((y <= -1.7e-13) || !(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.7d-13)) .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.7e-13) || !(y <= 1.0)) {
tmp = y * x;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -1.7e-13) or not (y <= 1.0): tmp = y * x else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -1.7e-13) || !(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.7e-13) || ~((y <= 1.0))) tmp = y * x; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -1.7e-13], N[Not[LessEqual[y, 1.0]], $MachinePrecision]], N[(y * x), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.7 \cdot 10^{-13} \lor \neg \left(y \leq 1\right):\\
\;\;\;\;y \cdot x\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -1.70000000000000008e-13 or 1 < y Initial program 100.0%
Taylor expanded in x around inf 53.9%
+-commutative53.9%
Simplified53.9%
Taylor expanded in y around inf 52.7%
if -1.70000000000000008e-13 < y < 1Initial program 100.0%
Taylor expanded in y around 0 74.8%
Final simplification64.2%
(FPCore (x y z) :precision binary64 (if (<= y -1.7e-13) (* y x) (if (<= y 4.2e-29) x (* y z))))
double code(double x, double y, double z) {
double tmp;
if (y <= -1.7e-13) {
tmp = y * x;
} else if (y <= 4.2e-29) {
tmp = 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 <= (-1.7d-13)) then
tmp = y * x
else if (y <= 4.2d-29) then
tmp = 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 <= -1.7e-13) {
tmp = y * x;
} else if (y <= 4.2e-29) {
tmp = x;
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -1.7e-13: tmp = y * x elif y <= 4.2e-29: tmp = x else: tmp = y * z return tmp
function code(x, y, z) tmp = 0.0 if (y <= -1.7e-13) tmp = Float64(y * x); elseif (y <= 4.2e-29) tmp = x; else tmp = Float64(y * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -1.7e-13) tmp = y * x; elseif (y <= 4.2e-29) tmp = x; else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -1.7e-13], N[(y * x), $MachinePrecision], If[LessEqual[y, 4.2e-29], x, N[(y * z), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.7 \cdot 10^{-13}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;y \leq 4.2 \cdot 10^{-29}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if y < -1.70000000000000008e-13Initial program 100.0%
Taylor expanded in x around inf 54.4%
+-commutative54.4%
Simplified54.4%
Taylor expanded in y around inf 53.9%
if -1.70000000000000008e-13 < y < 4.19999999999999979e-29Initial program 100.0%
Taylor expanded in y around 0 75.7%
if 4.19999999999999979e-29 < y Initial program 100.0%
Taylor expanded in z around inf 54.3%
Taylor expanded in x around 0 51.7%
Final simplification64.4%
(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 40.3%
Final simplification40.3%
herbie shell --seed 2023336
(FPCore (x y z)
:name "Main:bigenough2 from A"
:precision binary64
(+ x (* y (+ z x))))