
(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 6 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 (<= y -2.7e+231)
(* x y)
(if (<= y -1.45e+146)
(* y z)
(if (<= y -2e+47)
(* x y)
(if (or (<= y -3.6e-27) (not (<= y 2.1e-11))) (* y z) x)))))
double code(double x, double y, double z) {
double tmp;
if (y <= -2.7e+231) {
tmp = x * y;
} else if (y <= -1.45e+146) {
tmp = y * z;
} else if (y <= -2e+47) {
tmp = x * y;
} else if ((y <= -3.6e-27) || !(y <= 2.1e-11)) {
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 <= (-2.7d+231)) then
tmp = x * y
else if (y <= (-1.45d+146)) then
tmp = y * z
else if (y <= (-2d+47)) then
tmp = x * y
else if ((y <= (-3.6d-27)) .or. (.not. (y <= 2.1d-11))) 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 <= -2.7e+231) {
tmp = x * y;
} else if (y <= -1.45e+146) {
tmp = y * z;
} else if (y <= -2e+47) {
tmp = x * y;
} else if ((y <= -3.6e-27) || !(y <= 2.1e-11)) {
tmp = y * z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -2.7e+231: tmp = x * y elif y <= -1.45e+146: tmp = y * z elif y <= -2e+47: tmp = x * y elif (y <= -3.6e-27) or not (y <= 2.1e-11): tmp = y * z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (y <= -2.7e+231) tmp = Float64(x * y); elseif (y <= -1.45e+146) tmp = Float64(y * z); elseif (y <= -2e+47) tmp = Float64(x * y); elseif ((y <= -3.6e-27) || !(y <= 2.1e-11)) tmp = Float64(y * z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -2.7e+231) tmp = x * y; elseif (y <= -1.45e+146) tmp = y * z; elseif (y <= -2e+47) tmp = x * y; elseif ((y <= -3.6e-27) || ~((y <= 2.1e-11))) tmp = y * z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -2.7e+231], N[(x * y), $MachinePrecision], If[LessEqual[y, -1.45e+146], N[(y * z), $MachinePrecision], If[LessEqual[y, -2e+47], N[(x * y), $MachinePrecision], If[Or[LessEqual[y, -3.6e-27], N[Not[LessEqual[y, 2.1e-11]], $MachinePrecision]], N[(y * z), $MachinePrecision], x]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.7 \cdot 10^{+231}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;y \leq -1.45 \cdot 10^{+146}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;y \leq -2 \cdot 10^{+47}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;y \leq -3.6 \cdot 10^{-27} \lor \neg \left(y \leq 2.1 \cdot 10^{-11}\right):\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -2.6999999999999999e231 or -1.4499999999999999e146 < y < -2.0000000000000001e47Initial program 99.9%
Taylor expanded in z around 0 70.7%
*-commutative70.7%
Simplified70.7%
Taylor expanded in y around inf 70.7%
if -2.6999999999999999e231 < y < -1.4499999999999999e146 or -2.0000000000000001e47 < y < -3.5999999999999999e-27 or 2.0999999999999999e-11 < y Initial program 100.0%
Taylor expanded in z around inf 63.4%
Taylor expanded in x around 0 61.0%
if -3.5999999999999999e-27 < y < 2.0999999999999999e-11Initial program 100.0%
Taylor expanded in z around 0 77.1%
*-commutative77.1%
Simplified77.1%
Taylor expanded in y around 0 77.1%
Final simplification70.3%
(FPCore (x y z) :precision binary64 (if (or (<= x -3.8e-66) (not (<= x 4.6e-135))) (+ x (* x y)) (* y z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -3.8e-66) || !(x <= 4.6e-135)) {
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 <= (-3.8d-66)) .or. (.not. (x <= 4.6d-135))) 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 <= -3.8e-66) || !(x <= 4.6e-135)) {
tmp = x + (x * y);
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -3.8e-66) or not (x <= 4.6e-135): tmp = x + (x * y) else: tmp = y * z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -3.8e-66) || !(x <= 4.6e-135)) 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 <= -3.8e-66) || ~((x <= 4.6e-135))) tmp = x + (x * y); else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -3.8e-66], N[Not[LessEqual[x, 4.6e-135]], $MachinePrecision]], N[(x + N[(x * y), $MachinePrecision]), $MachinePrecision], N[(y * z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -3.8 \cdot 10^{-66} \lor \neg \left(x \leq 4.6 \cdot 10^{-135}\right):\\
\;\;\;\;x + x \cdot y\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if x < -3.7999999999999998e-66 or 4.5999999999999998e-135 < x Initial program 100.0%
Taylor expanded in z around 0 84.2%
*-commutative84.2%
Simplified84.2%
if -3.7999999999999998e-66 < x < 4.5999999999999998e-135Initial program 100.0%
Taylor expanded in z around inf 92.4%
Taylor expanded in x around 0 71.4%
Final simplification79.4%
(FPCore (x y z) :precision binary64 (if (or (<= z -122.0) (not (<= z 8.8e-32))) (+ x (* y z)) (+ x (* x y))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -122.0) || !(z <= 8.8e-32)) {
tmp = x + (y * 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 <= (-122.0d0)) .or. (.not. (z <= 8.8d-32))) then
tmp = x + (y * 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 <= -122.0) || !(z <= 8.8e-32)) {
tmp = x + (y * z);
} else {
tmp = x + (x * y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -122.0) or not (z <= 8.8e-32): tmp = x + (y * z) else: tmp = x + (x * y) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -122.0) || !(z <= 8.8e-32)) tmp = Float64(x + Float64(y * z)); else tmp = Float64(x + Float64(x * y)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -122.0) || ~((z <= 8.8e-32))) tmp = x + (y * z); else tmp = x + (x * y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -122.0], N[Not[LessEqual[z, 8.8e-32]], $MachinePrecision]], N[(x + N[(y * z), $MachinePrecision]), $MachinePrecision], N[(x + N[(x * y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -122 \lor \neg \left(z \leq 8.8 \cdot 10^{-32}\right):\\
\;\;\;\;x + y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x + x \cdot y\\
\end{array}
\end{array}
if z < -122 or 8.7999999999999999e-32 < z Initial program 100.0%
Taylor expanded in z around inf 90.4%
if -122 < z < 8.7999999999999999e-32Initial program 100.0%
Taylor expanded in z around 0 87.7%
*-commutative87.7%
Simplified87.7%
Final simplification89.1%
(FPCore (x y z) :precision binary64 (if (or (<= y -480000000.0) (not (<= y 1.0))) (* x y) x))
double code(double x, double y, double z) {
double tmp;
if ((y <= -480000000.0) || !(y <= 1.0)) {
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 <= (-480000000.0d0)) .or. (.not. (y <= 1.0d0))) 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 <= -480000000.0) || !(y <= 1.0)) {
tmp = x * y;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -480000000.0) or not (y <= 1.0): tmp = x * y else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -480000000.0) || !(y <= 1.0)) tmp = Float64(x * y); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -480000000.0) || ~((y <= 1.0))) tmp = x * y; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -480000000.0], N[Not[LessEqual[y, 1.0]], $MachinePrecision]], N[(x * y), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -480000000 \lor \neg \left(y \leq 1\right):\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -4.8e8 or 1 < y Initial program 100.0%
Taylor expanded in z around 0 51.7%
*-commutative51.7%
Simplified51.7%
Taylor expanded in y around inf 51.7%
if -4.8e8 < y < 1Initial program 100.0%
Taylor expanded in z around 0 74.6%
*-commutative74.6%
Simplified74.6%
Taylor expanded in y around 0 74.2%
Final simplification63.2%
(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 0 63.5%
*-commutative63.5%
Simplified63.5%
Taylor expanded in y around 0 39.4%
Final simplification39.4%
herbie shell --seed 2023309
(FPCore (x y z)
:name "Main:bigenough2 from A"
:precision binary64
(+ x (* y (+ z x))))