
(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 (or (<= z -2.3e+91) (not (<= z 4.4e-21))) (* y z) (+ x (* x y))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -2.3e+91) || !(z <= 4.4e-21)) {
tmp = 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+91)) .or. (.not. (z <= 4.4d-21))) then
tmp = 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+91) || !(z <= 4.4e-21)) {
tmp = y * z;
} else {
tmp = x + (x * y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -2.3e+91) or not (z <= 4.4e-21): tmp = y * z else: tmp = x + (x * y) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -2.3e+91) || !(z <= 4.4e-21)) tmp = 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+91) || ~((z <= 4.4e-21))) tmp = y * z; else tmp = x + (x * y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -2.3e+91], N[Not[LessEqual[z, 4.4e-21]], $MachinePrecision]], N[(y * z), $MachinePrecision], N[(x + N[(x * y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -2.3 \cdot 10^{+91} \lor \neg \left(z \leq 4.4 \cdot 10^{-21}\right):\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x + x \cdot y\\
\end{array}
\end{array}
if z < -2.29999999999999991e91 or 4.4000000000000001e-21 < z Initial program 100.0%
Taylor expanded in z around inf 98.2%
Taylor expanded in x around 0 68.0%
if -2.29999999999999991e91 < z < 4.4000000000000001e-21Initial program 100.0%
Taylor expanded in z around 0 83.7%
*-commutative83.7%
Simplified83.7%
Final simplification76.7%
(FPCore (x y z) :precision binary64 (if (or (<= z -1.8e-99) (not (<= z 5e-58))) (+ x (* y z)) (+ x (* x y))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -1.8e-99) || !(z <= 5e-58)) {
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 <= (-1.8d-99)) .or. (.not. (z <= 5d-58))) 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 <= -1.8e-99) || !(z <= 5e-58)) {
tmp = x + (y * z);
} else {
tmp = x + (x * y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -1.8e-99) or not (z <= 5e-58): tmp = x + (y * z) else: tmp = x + (x * y) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -1.8e-99) || !(z <= 5e-58)) 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 <= -1.8e-99) || ~((z <= 5e-58))) tmp = x + (y * z); else tmp = x + (x * y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -1.8e-99], N[Not[LessEqual[z, 5e-58]], $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 -1.8 \cdot 10^{-99} \lor \neg \left(z \leq 5 \cdot 10^{-58}\right):\\
\;\;\;\;x + y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x + x \cdot y\\
\end{array}
\end{array}
if z < -1.8e-99 or 4.99999999999999977e-58 < z Initial program 100.0%
Taylor expanded in z around inf 92.7%
if -1.8e-99 < z < 4.99999999999999977e-58Initial program 100.0%
Taylor expanded in z around 0 90.2%
*-commutative90.2%
Simplified90.2%
Final simplification91.7%
(FPCore (x y z) :precision binary64 (if (or (<= y -7.6e-10) (not (<= y 1.0))) (* x y) x))
double code(double x, double y, double z) {
double tmp;
if ((y <= -7.6e-10) || !(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 <= (-7.6d-10)) .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 <= -7.6e-10) || !(y <= 1.0)) {
tmp = x * y;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -7.6e-10) or not (y <= 1.0): tmp = x * y else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -7.6e-10) || !(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 <= -7.6e-10) || ~((y <= 1.0))) tmp = x * y; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -7.6e-10], N[Not[LessEqual[y, 1.0]], $MachinePrecision]], N[(x * y), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -7.6 \cdot 10^{-10} \lor \neg \left(y \leq 1\right):\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -7.5999999999999996e-10 or 1 < y Initial program 100.0%
Taylor expanded in z around 0 49.8%
*-commutative49.8%
Simplified49.8%
Taylor expanded in y around inf 48.4%
if -7.5999999999999996e-10 < y < 1Initial program 100.0%
Taylor expanded in y around 0 73.5%
Final simplification62.1%
(FPCore (x y z) :precision binary64 (if (or (<= y -9e-14) (not (<= y 6.2e-38))) (* y z) x))
double code(double x, double y, double z) {
double tmp;
if ((y <= -9e-14) || !(y <= 6.2e-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 <= (-9d-14)) .or. (.not. (y <= 6.2d-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 <= -9e-14) || !(y <= 6.2e-38)) {
tmp = y * z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -9e-14) or not (y <= 6.2e-38): tmp = y * z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -9e-14) || !(y <= 6.2e-38)) tmp = Float64(y * z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -9e-14) || ~((y <= 6.2e-38))) tmp = y * z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -9e-14], N[Not[LessEqual[y, 6.2e-38]], $MachinePrecision]], N[(y * z), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -9 \cdot 10^{-14} \lor \neg \left(y \leq 6.2 \cdot 10^{-38}\right):\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -8.9999999999999995e-14 or 6.19999999999999966e-38 < y Initial program 100.0%
Taylor expanded in z around inf 58.6%
Taylor expanded in x around 0 56.4%
if -8.9999999999999995e-14 < y < 6.19999999999999966e-38Initial program 100.0%
Taylor expanded in y around 0 76.6%
Final simplification66.7%
(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 41.2%
Final simplification41.2%
herbie shell --seed 2023322
(FPCore (x y z)
:name "Main:bigenough2 from A"
:precision binary64
(+ x (* y (+ z x))))