
(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 (or (<= y -3.55e+21) (not (<= y 1.0))) (* y (+ x z)) (+ x (* y z))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -3.55e+21) || !(y <= 1.0)) {
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 <= (-3.55d+21)) .or. (.not. (y <= 1.0d0))) 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 <= -3.55e+21) || !(y <= 1.0)) {
tmp = y * (x + z);
} else {
tmp = x + (y * z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -3.55e+21) or not (y <= 1.0): tmp = y * (x + z) else: tmp = x + (y * z) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -3.55e+21) || !(y <= 1.0)) 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 <= -3.55e+21) || ~((y <= 1.0))) tmp = y * (x + z); else tmp = x + (y * z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -3.55e+21], N[Not[LessEqual[y, 1.0]], $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 -3.55 \cdot 10^{+21} \lor \neg \left(y \leq 1\right):\\
\;\;\;\;y \cdot \left(x + z\right)\\
\mathbf{else}:\\
\;\;\;\;x + y \cdot z\\
\end{array}
\end{array}
if y < -3.55e21 or 1 < y Initial program 100.0%
Taylor expanded in x around 0 95.2%
Taylor expanded in y around inf 100.0%
if -3.55e21 < y < 1Initial program 100.0%
Taylor expanded in z around inf 99.6%
Final simplification99.8%
(FPCore (x y z) :precision binary64 (if (or (<= y -0.0023) (not (<= y 1.5e-35))) (* y (+ x z)) (+ x (* x y))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -0.0023) || !(y <= 1.5e-35)) {
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 ((y <= (-0.0023d0)) .or. (.not. (y <= 1.5d-35))) 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 ((y <= -0.0023) || !(y <= 1.5e-35)) {
tmp = y * (x + z);
} else {
tmp = x + (x * y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -0.0023) or not (y <= 1.5e-35): tmp = y * (x + z) else: tmp = x + (x * y) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -0.0023) || !(y <= 1.5e-35)) 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 ((y <= -0.0023) || ~((y <= 1.5e-35))) tmp = y * (x + z); else tmp = x + (x * y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -0.0023], N[Not[LessEqual[y, 1.5e-35]], $MachinePrecision]], N[(y * N[(x + z), $MachinePrecision]), $MachinePrecision], N[(x + N[(x * y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -0.0023 \lor \neg \left(y \leq 1.5 \cdot 10^{-35}\right):\\
\;\;\;\;y \cdot \left(x + z\right)\\
\mathbf{else}:\\
\;\;\;\;x + x \cdot y\\
\end{array}
\end{array}
if y < -0.0023 or 1.49999999999999994e-35 < y Initial program 100.0%
Taylor expanded in x around 0 95.5%
Taylor expanded in y around inf 98.6%
if -0.0023 < y < 1.49999999999999994e-35Initial program 100.0%
Taylor expanded in z around 0 75.2%
*-commutative75.2%
Simplified75.2%
Final simplification87.3%
(FPCore (x y z) :precision binary64 (if (or (<= y -5.8e-21) (not (<= y 7.6e-36))) (* y (+ x z)) x))
double code(double x, double y, double z) {
double tmp;
if ((y <= -5.8e-21) || !(y <= 7.6e-36)) {
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 <= (-5.8d-21)) .or. (.not. (y <= 7.6d-36))) 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 <= -5.8e-21) || !(y <= 7.6e-36)) {
tmp = y * (x + z);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -5.8e-21) or not (y <= 7.6e-36): tmp = y * (x + z) else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -5.8e-21) || !(y <= 7.6e-36)) 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 <= -5.8e-21) || ~((y <= 7.6e-36))) tmp = y * (x + z); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -5.8e-21], N[Not[LessEqual[y, 7.6e-36]], $MachinePrecision]], N[(y * N[(x + z), $MachinePrecision]), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -5.8 \cdot 10^{-21} \lor \neg \left(y \leq 7.6 \cdot 10^{-36}\right):\\
\;\;\;\;y \cdot \left(x + z\right)\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -5.8e-21 or 7.59999999999999942e-36 < y Initial program 100.0%
Taylor expanded in x around 0 95.5%
Taylor expanded in y around inf 97.9%
if -5.8e-21 < y < 7.59999999999999942e-36Initial program 100.0%
Taylor expanded in z around 0 75.6%
*-commutative75.6%
Simplified75.6%
Taylor expanded in y around 0 75.6%
Final simplification87.3%
(FPCore (x y z) :precision binary64 (if (or (<= y -2.9e-23) (not (<= y 3.8e-35))) (* y z) x))
double code(double x, double y, double z) {
double tmp;
if ((y <= -2.9e-23) || !(y <= 3.8e-35)) {
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.9d-23)) .or. (.not. (y <= 3.8d-35))) 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.9e-23) || !(y <= 3.8e-35)) {
tmp = y * z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -2.9e-23) or not (y <= 3.8e-35): tmp = y * z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -2.9e-23) || !(y <= 3.8e-35)) tmp = Float64(y * z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -2.9e-23) || ~((y <= 3.8e-35))) tmp = y * z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -2.9e-23], N[Not[LessEqual[y, 3.8e-35]], $MachinePrecision]], N[(y * z), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.9 \cdot 10^{-23} \lor \neg \left(y \leq 3.8 \cdot 10^{-35}\right):\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -2.9000000000000002e-23 or 3.8000000000000001e-35 < y Initial program 100.0%
Taylor expanded in z around inf 60.1%
Taylor expanded in x around 0 58.1%
if -2.9000000000000002e-23 < y < 3.8000000000000001e-35Initial program 100.0%
Taylor expanded in z around 0 75.6%
*-commutative75.6%
Simplified75.6%
Taylor expanded in y around 0 75.6%
Final simplification66.4%
(FPCore (x y z) :precision binary64 (if (or (<= y -0.55) (not (<= y 2.5e+16))) (* x y) x))
double code(double x, double y, double z) {
double tmp;
if ((y <= -0.55) || !(y <= 2.5e+16)) {
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 <= (-0.55d0)) .or. (.not. (y <= 2.5d+16))) 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 <= -0.55) || !(y <= 2.5e+16)) {
tmp = x * y;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -0.55) or not (y <= 2.5e+16): tmp = x * y else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -0.55) || !(y <= 2.5e+16)) tmp = Float64(x * y); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -0.55) || ~((y <= 2.5e+16))) tmp = x * y; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -0.55], N[Not[LessEqual[y, 2.5e+16]], $MachinePrecision]], N[(x * y), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -0.55 \lor \neg \left(y \leq 2.5 \cdot 10^{+16}\right):\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -0.55000000000000004 or 2.5e16 < y Initial program 100.0%
Taylor expanded in x around 0 95.1%
Taylor expanded in y around inf 100.0%
Taylor expanded in x around inf 50.5%
*-commutative50.5%
Simplified50.5%
if -0.55000000000000004 < y < 2.5e16Initial program 100.0%
Taylor expanded in z around 0 71.2%
*-commutative71.2%
Simplified71.2%
Taylor expanded in y around 0 70.8%
Final simplification61.1%
(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 61.3%
*-commutative61.3%
Simplified61.3%
Taylor expanded in y around 0 38.1%
herbie shell --seed 2024160
(FPCore (x y z)
:name "Main:bigenough2 from A"
:precision binary64
(+ x (* y (+ z x))))