
(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 (+ 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 (if (<= z -5.6e-48) (* y z) (if (<= z -2.7e-219) (* x y) (if (<= z 2.85e-19) x (* y z)))))
double code(double x, double y, double z) {
double tmp;
if (z <= -5.6e-48) {
tmp = y * z;
} else if (z <= -2.7e-219) {
tmp = x * y;
} else if (z <= 2.85e-19) {
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 (z <= (-5.6d-48)) then
tmp = y * z
else if (z <= (-2.7d-219)) then
tmp = x * y
else if (z <= 2.85d-19) 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 (z <= -5.6e-48) {
tmp = y * z;
} else if (z <= -2.7e-219) {
tmp = x * y;
} else if (z <= 2.85e-19) {
tmp = x;
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -5.6e-48: tmp = y * z elif z <= -2.7e-219: tmp = x * y elif z <= 2.85e-19: tmp = x else: tmp = y * z return tmp
function code(x, y, z) tmp = 0.0 if (z <= -5.6e-48) tmp = Float64(y * z); elseif (z <= -2.7e-219) tmp = Float64(x * y); elseif (z <= 2.85e-19) tmp = x; else tmp = Float64(y * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -5.6e-48) tmp = y * z; elseif (z <= -2.7e-219) tmp = x * y; elseif (z <= 2.85e-19) tmp = x; else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -5.6e-48], N[(y * z), $MachinePrecision], If[LessEqual[z, -2.7e-219], N[(x * y), $MachinePrecision], If[LessEqual[z, 2.85e-19], x, N[(y * z), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -5.6 \cdot 10^{-48}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;z \leq -2.7 \cdot 10^{-219}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;z \leq 2.85 \cdot 10^{-19}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if z < -5.6000000000000001e-48 or 2.84999999999999976e-19 < z Initial program 100.0%
Taylor expanded in z around inf 91.3%
Taylor expanded in x around 0 74.6%
if -5.6000000000000001e-48 < z < -2.7e-219Initial program 100.0%
Taylor expanded in z around 0 79.3%
*-commutative79.3%
Simplified79.3%
Taylor expanded in y around inf 54.0%
if -2.7e-219 < z < 2.84999999999999976e-19Initial program 100.0%
Taylor expanded in y around 0 55.7%
(FPCore (x y z) :precision binary64 (if (or (<= y -9.5e+14) (not (<= y 8.5e-8))) (* y (+ x z)) (+ x (* y z))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -9.5e+14) || !(y <= 8.5e-8)) {
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 <= (-9.5d+14)) .or. (.not. (y <= 8.5d-8))) 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 <= -9.5e+14) || !(y <= 8.5e-8)) {
tmp = y * (x + z);
} else {
tmp = x + (y * z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -9.5e+14) or not (y <= 8.5e-8): tmp = y * (x + z) else: tmp = x + (y * z) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -9.5e+14) || !(y <= 8.5e-8)) 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 <= -9.5e+14) || ~((y <= 8.5e-8))) tmp = y * (x + z); else tmp = x + (y * z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -9.5e+14], N[Not[LessEqual[y, 8.5e-8]], $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 -9.5 \cdot 10^{+14} \lor \neg \left(y \leq 8.5 \cdot 10^{-8}\right):\\
\;\;\;\;y \cdot \left(x + z\right)\\
\mathbf{else}:\\
\;\;\;\;x + y \cdot z\\
\end{array}
\end{array}
if y < -9.5e14 or 8.49999999999999935e-8 < y Initial program 100.0%
Taylor expanded in x around 0 95.5%
Taylor expanded in y around inf 98.8%
if -9.5e14 < y < 8.49999999999999935e-8Initial program 100.0%
Taylor expanded in z around inf 98.7%
Final simplification98.7%
(FPCore (x y z) :precision binary64 (if (or (<= z -3.1e+87) (not (<= z 2.5e-20))) (* y (+ x z)) (+ x (* x y))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -3.1e+87) || !(z <= 2.5e-20)) {
tmp = y * (x + z);
} else {
tmp = x + (x * y);
}
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.1d+87)) .or. (.not. (z <= 2.5d-20))) then
tmp = y * (x + z)
else
tmp = x + (x * y)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -3.1e+87) || !(z <= 2.5e-20)) {
tmp = y * (x + z);
} else {
tmp = x + (x * y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -3.1e+87) or not (z <= 2.5e-20): tmp = y * (x + z) else: tmp = x + (x * y) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -3.1e+87) || !(z <= 2.5e-20)) tmp = Float64(y * Float64(x + z)); else tmp = Float64(x + Float64(x * y)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -3.1e+87) || ~((z <= 2.5e-20))) tmp = y * (x + z); else tmp = x + (x * y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -3.1e+87], N[Not[LessEqual[z, 2.5e-20]], $MachinePrecision]], N[(y * N[(x + z), $MachinePrecision]), $MachinePrecision], N[(x + N[(x * y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -3.1 \cdot 10^{+87} \lor \neg \left(z \leq 2.5 \cdot 10^{-20}\right):\\
\;\;\;\;y \cdot \left(x + z\right)\\
\mathbf{else}:\\
\;\;\;\;x + x \cdot y\\
\end{array}
\end{array}
if z < -3.1e87 or 2.4999999999999999e-20 < z Initial program 100.0%
Taylor expanded in x around 0 95.0%
Taylor expanded in y around inf 89.1%
if -3.1e87 < z < 2.4999999999999999e-20Initial program 100.0%
Taylor expanded in z around 0 83.8%
*-commutative83.8%
Simplified83.8%
Final simplification86.3%
(FPCore (x y z) :precision binary64 (if (or (<= y -4.1e-48) (not (<= y 7.2e-51))) (* y (+ x z)) x))
double code(double x, double y, double z) {
double tmp;
if ((y <= -4.1e-48) || !(y <= 7.2e-51)) {
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 <= (-4.1d-48)) .or. (.not. (y <= 7.2d-51))) 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 <= -4.1e-48) || !(y <= 7.2e-51)) {
tmp = y * (x + z);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -4.1e-48) or not (y <= 7.2e-51): tmp = y * (x + z) else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -4.1e-48) || !(y <= 7.2e-51)) 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 <= -4.1e-48) || ~((y <= 7.2e-51))) tmp = y * (x + z); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -4.1e-48], N[Not[LessEqual[y, 7.2e-51]], $MachinePrecision]], N[(y * N[(x + z), $MachinePrecision]), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -4.1 \cdot 10^{-48} \lor \neg \left(y \leq 7.2 \cdot 10^{-51}\right):\\
\;\;\;\;y \cdot \left(x + z\right)\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -4.10000000000000014e-48 or 7.2000000000000001e-51 < y Initial program 100.0%
Taylor expanded in x around 0 96.3%
Taylor expanded in y around inf 92.0%
if -4.10000000000000014e-48 < y < 7.2000000000000001e-51Initial program 100.0%
Taylor expanded in y around 0 71.5%
Final simplification84.5%
(FPCore (x y z) :precision binary64 (if (or (<= y -1.0) (not (<= y 0.00035))) (* x y) x))
double code(double x, double y, double z) {
double tmp;
if ((y <= -1.0) || !(y <= 0.00035)) {
tmp = x * y;
} 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.0d0)) .or. (.not. (y <= 0.00035d0))) then
tmp = x * y
else
tmp = x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -1.0) || !(y <= 0.00035)) {
tmp = x * y;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -1.0) or not (y <= 0.00035): tmp = x * y else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -1.0) || !(y <= 0.00035)) tmp = Float64(x * y); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -1.0) || ~((y <= 0.00035))) tmp = x * y; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -1.0], N[Not[LessEqual[y, 0.00035]], $MachinePrecision]], N[(x * y), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1 \lor \neg \left(y \leq 0.00035\right):\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -1 or 3.49999999999999996e-4 < y Initial program 100.0%
Taylor expanded in z around 0 46.5%
*-commutative46.5%
Simplified46.5%
Taylor expanded in y around inf 45.3%
if -1 < y < 3.49999999999999996e-4Initial program 100.0%
Taylor expanded in y around 0 63.3%
Final simplification53.8%
(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 31.5%
herbie shell --seed 2024112
(FPCore (x y z)
:name "Main:bigenough2 from A"
:precision binary64
(+ x (* y (+ z x))))