
(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 5 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 (or (<= x -4e+20)
(and (not (<= x -6.6e-19)) (or (<= x -6e-78) (not (<= x 106.0)))))
(+ x (* x y))
(* y z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -4e+20) || (!(x <= -6.6e-19) && ((x <= -6e-78) || !(x <= 106.0)))) {
tmp = x + (x * y);
} 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 <= (-4d+20)) .or. (.not. (x <= (-6.6d-19))) .and. (x <= (-6d-78)) .or. (.not. (x <= 106.0d0))) then
tmp = x + (x * y)
else
tmp = y * z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -4e+20) || (!(x <= -6.6e-19) && ((x <= -6e-78) || !(x <= 106.0)))) {
tmp = x + (x * y);
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -4e+20) or (not (x <= -6.6e-19) and ((x <= -6e-78) or not (x <= 106.0))): tmp = x + (x * y) else: tmp = y * z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -4e+20) || (!(x <= -6.6e-19) && ((x <= -6e-78) || !(x <= 106.0)))) tmp = Float64(x + Float64(x * y)); else tmp = Float64(y * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -4e+20) || (~((x <= -6.6e-19)) && ((x <= -6e-78) || ~((x <= 106.0))))) tmp = x + (x * y); else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -4e+20], And[N[Not[LessEqual[x, -6.6e-19]], $MachinePrecision], Or[LessEqual[x, -6e-78], N[Not[LessEqual[x, 106.0]], $MachinePrecision]]]], N[(x + N[(x * y), $MachinePrecision]), $MachinePrecision], N[(y * z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -4 \cdot 10^{+20} \lor \neg \left(x \leq -6.6 \cdot 10^{-19}\right) \land \left(x \leq -6 \cdot 10^{-78} \lor \neg \left(x \leq 106\right)\right):\\
\;\;\;\;x + x \cdot y\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if x < -4e20 or -6.5999999999999995e-19 < x < -5.99999999999999975e-78 or 106 < x Initial program 100.0%
Taylor expanded in z around 0 86.8%
*-commutative86.8%
Simplified86.8%
if -4e20 < x < -6.5999999999999995e-19 or -5.99999999999999975e-78 < x < 106Initial program 100.0%
Taylor expanded in z around inf 89.5%
Taylor expanded in x around 0 71.4%
Final simplification80.0%
(FPCore (x y z) :precision binary64 (if (or (<= x -4.2e+30) (not (<= x 1e+119))) (+ x (* x y)) (+ x (* y z))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -4.2e+30) || !(x <= 1e+119)) {
tmp = x + (x * y);
} 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 ((x <= (-4.2d+30)) .or. (.not. (x <= 1d+119))) then
tmp = x + (x * y)
else
tmp = x + (y * z)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -4.2e+30) || !(x <= 1e+119)) {
tmp = x + (x * y);
} else {
tmp = x + (y * z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -4.2e+30) or not (x <= 1e+119): tmp = x + (x * y) else: tmp = x + (y * z) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -4.2e+30) || !(x <= 1e+119)) tmp = Float64(x + Float64(x * y)); else tmp = Float64(x + Float64(y * z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -4.2e+30) || ~((x <= 1e+119))) tmp = x + (x * y); else tmp = x + (y * z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -4.2e+30], N[Not[LessEqual[x, 1e+119]], $MachinePrecision]], N[(x + N[(x * y), $MachinePrecision]), $MachinePrecision], N[(x + N[(y * z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -4.2 \cdot 10^{+30} \lor \neg \left(x \leq 10^{+119}\right):\\
\;\;\;\;x + x \cdot y\\
\mathbf{else}:\\
\;\;\;\;x + y \cdot z\\
\end{array}
\end{array}
if x < -4.2e30 or 9.99999999999999944e118 < x Initial program 100.0%
Taylor expanded in z around 0 94.4%
*-commutative94.4%
Simplified94.4%
if -4.2e30 < x < 9.99999999999999944e118Initial program 100.0%
Taylor expanded in z around inf 87.0%
Final simplification89.9%
(FPCore (x y z) :precision binary64 (if (or (<= y -1.25e-5) (not (<= y 1.55e-38))) (* y z) x))
double code(double x, double y, double z) {
double tmp;
if ((y <= -1.25e-5) || !(y <= 1.55e-38)) {
tmp = y * 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 <= (-1.25d-5)) .or. (.not. (y <= 1.55d-38))) then
tmp = y * z
else
tmp = x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -1.25e-5) || !(y <= 1.55e-38)) {
tmp = y * z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -1.25e-5) or not (y <= 1.55e-38): tmp = y * z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -1.25e-5) || !(y <= 1.55e-38)) tmp = Float64(y * z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -1.25e-5) || ~((y <= 1.55e-38))) tmp = y * z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -1.25e-5], N[Not[LessEqual[y, 1.55e-38]], $MachinePrecision]], N[(y * z), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.25 \cdot 10^{-5} \lor \neg \left(y \leq 1.55 \cdot 10^{-38}\right):\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -1.25000000000000006e-5 or 1.54999999999999991e-38 < y Initial program 100.0%
Taylor expanded in z around inf 57.2%
Taylor expanded in x around 0 55.5%
if -1.25000000000000006e-5 < y < 1.54999999999999991e-38Initial program 100.0%
Taylor expanded in z around inf 99.3%
Taylor expanded in x around inf 77.0%
Final simplification64.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 z around inf 75.5%
Taylor expanded in x around inf 35.9%
herbie shell --seed 2024097
(FPCore (x y z)
:name "Main:bigenough2 from A"
:precision binary64
(+ x (* y (+ z x))))