
(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 (<= z -2.3e-123) (not (<= z 9e-37))) (+ x (* y z)) (+ x (* x y))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -2.3e-123) || !(z <= 9e-37)) {
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 <= (-2.3d-123)) .or. (.not. (z <= 9d-37))) 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 <= -2.3e-123) || !(z <= 9e-37)) {
tmp = x + (y * z);
} else {
tmp = x + (x * y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -2.3e-123) or not (z <= 9e-37): tmp = x + (y * z) else: tmp = x + (x * y) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -2.3e-123) || !(z <= 9e-37)) 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 <= -2.3e-123) || ~((z <= 9e-37))) tmp = x + (y * z); else tmp = x + (x * y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -2.3e-123], N[Not[LessEqual[z, 9e-37]], $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 -2.3 \cdot 10^{-123} \lor \neg \left(z \leq 9 \cdot 10^{-37}\right):\\
\;\;\;\;x + y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x + x \cdot y\\
\end{array}
\end{array}
if z < -2.29999999999999987e-123 or 9.00000000000000081e-37 < z Initial program 100.0%
Taylor expanded in z around inf 86.7%
if -2.29999999999999987e-123 < z < 9.00000000000000081e-37Initial program 100.0%
Taylor expanded in z around 0 87.9%
*-commutative87.9%
Simplified87.9%
Final simplification87.2%
(FPCore (x y z) :precision binary64 (if (or (<= x -2e-197) (not (<= x 4.2e-131))) (+ x (* x y)) (* y z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -2e-197) || !(x <= 4.2e-131)) {
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 <= (-2d-197)) .or. (.not. (x <= 4.2d-131))) 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 <= -2e-197) || !(x <= 4.2e-131)) {
tmp = x + (x * y);
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -2e-197) or not (x <= 4.2e-131): tmp = x + (x * y) else: tmp = y * z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -2e-197) || !(x <= 4.2e-131)) 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 <= -2e-197) || ~((x <= 4.2e-131))) tmp = x + (x * y); else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -2e-197], N[Not[LessEqual[x, 4.2e-131]], $MachinePrecision]], N[(x + N[(x * y), $MachinePrecision]), $MachinePrecision], N[(y * z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2 \cdot 10^{-197} \lor \neg \left(x \leq 4.2 \cdot 10^{-131}\right):\\
\;\;\;\;x + x \cdot y\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if x < -2e-197 or 4.19999999999999994e-131 < x Initial program 100.0%
Taylor expanded in z around 0 73.3%
*-commutative73.3%
Simplified73.3%
if -2e-197 < x < 4.19999999999999994e-131Initial program 100.0%
Taylor expanded in z around inf 94.4%
Taylor expanded in x around 0 78.1%
Final simplification74.2%
(FPCore (x y z) :precision binary64 (if (or (<= y -9.8e-17) (not (<= y 9.2e-76))) (* y z) x))
double code(double x, double y, double z) {
double tmp;
if ((y <= -9.8e-17) || !(y <= 9.2e-76)) {
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 <= (-9.8d-17)) .or. (.not. (y <= 9.2d-76))) 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 <= -9.8e-17) || !(y <= 9.2e-76)) {
tmp = y * z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -9.8e-17) or not (y <= 9.2e-76): tmp = y * z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -9.8e-17) || !(y <= 9.2e-76)) tmp = Float64(y * z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -9.8e-17) || ~((y <= 9.2e-76))) tmp = y * z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -9.8e-17], N[Not[LessEqual[y, 9.2e-76]], $MachinePrecision]], N[(y * z), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -9.8 \cdot 10^{-17} \lor \neg \left(y \leq 9.2 \cdot 10^{-76}\right):\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -9.80000000000000024e-17 or 9.20000000000000025e-76 < y Initial program 100.0%
Taylor expanded in z around inf 59.0%
Taylor expanded in x around 0 54.0%
if -9.80000000000000024e-17 < y < 9.20000000000000025e-76Initial program 100.0%
Taylor expanded in z around 0 80.1%
*-commutative80.1%
Simplified80.1%
Taylor expanded in y around 0 80.1%
Final simplification66.3%
(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 41.1%
herbie shell --seed 2024165
(FPCore (x y z)
:name "Main:bigenough2 from A"
:precision binary64
(+ x (* y (+ z x))))