
(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.1e+22) (not (<= z 1e-46))) (+ x (* y z)) (+ x (* x y))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -2.1e+22) || !(z <= 1e-46)) {
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.1d+22)) .or. (.not. (z <= 1d-46))) 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.1e+22) || !(z <= 1e-46)) {
tmp = x + (y * z);
} else {
tmp = x + (x * y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -2.1e+22) or not (z <= 1e-46): tmp = x + (y * z) else: tmp = x + (x * y) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -2.1e+22) || !(z <= 1e-46)) 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.1e+22) || ~((z <= 1e-46))) tmp = x + (y * z); else tmp = x + (x * y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -2.1e+22], N[Not[LessEqual[z, 1e-46]], $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.1 \cdot 10^{+22} \lor \neg \left(z \leq 10^{-46}\right):\\
\;\;\;\;x + y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x + x \cdot y\\
\end{array}
\end{array}
if z < -2.0999999999999998e22 or 1.00000000000000002e-46 < z Initial program 100.0%
Taylor expanded in z around inf 93.0%
if -2.0999999999999998e22 < z < 1.00000000000000002e-46Initial program 100.0%
Taylor expanded in z around 0 84.8%
*-commutative84.8%
Simplified84.8%
Final simplification89.1%
(FPCore (x y z) :precision binary64 (if (<= z -5.8e+56) (* y z) (if (<= z 3.8e-13) (+ x (* x y)) (* y z))))
double code(double x, double y, double z) {
double tmp;
if (z <= -5.8e+56) {
tmp = y * z;
} else if (z <= 3.8e-13) {
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 (z <= (-5.8d+56)) then
tmp = y * z
else if (z <= 3.8d-13) 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 (z <= -5.8e+56) {
tmp = y * z;
} else if (z <= 3.8e-13) {
tmp = x + (x * y);
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -5.8e+56: tmp = y * z elif z <= 3.8e-13: tmp = x + (x * y) else: tmp = y * z return tmp
function code(x, y, z) tmp = 0.0 if (z <= -5.8e+56) tmp = Float64(y * z); elseif (z <= 3.8e-13) 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 (z <= -5.8e+56) tmp = y * z; elseif (z <= 3.8e-13) tmp = x + (x * y); else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -5.8e+56], N[(y * z), $MachinePrecision], If[LessEqual[z, 3.8e-13], N[(x + N[(x * y), $MachinePrecision]), $MachinePrecision], N[(y * z), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -5.8 \cdot 10^{+56}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;z \leq 3.8 \cdot 10^{-13}:\\
\;\;\;\;x + x \cdot y\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if z < -5.80000000000000014e56 or 3.8e-13 < z Initial program 100.0%
Taylor expanded in z around inf 93.2%
Taylor expanded in x around 0 71.9%
if -5.80000000000000014e56 < z < 3.8e-13Initial program 100.0%
Taylor expanded in z around 0 83.7%
*-commutative83.7%
Simplified83.7%
Final simplification77.9%
(FPCore (x y z) :precision binary64 (if (<= y -4.7e-107) (* y z) (if (<= y 2.2e-82) x (* y z))))
double code(double x, double y, double z) {
double tmp;
if (y <= -4.7e-107) {
tmp = y * z;
} else if (y <= 2.2e-82) {
tmp = x;
} 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 (y <= (-4.7d-107)) then
tmp = y * z
else if (y <= 2.2d-82) then
tmp = x
else
tmp = y * z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= -4.7e-107) {
tmp = y * z;
} else if (y <= 2.2e-82) {
tmp = x;
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -4.7e-107: tmp = y * z elif y <= 2.2e-82: tmp = x else: tmp = y * z return tmp
function code(x, y, z) tmp = 0.0 if (y <= -4.7e-107) tmp = Float64(y * z); elseif (y <= 2.2e-82) tmp = x; else tmp = Float64(y * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -4.7e-107) tmp = y * z; elseif (y <= 2.2e-82) tmp = x; else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -4.7e-107], N[(y * z), $MachinePrecision], If[LessEqual[y, 2.2e-82], x, N[(y * z), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -4.7 \cdot 10^{-107}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;y \leq 2.2 \cdot 10^{-82}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if y < -4.69999999999999998e-107 or 2.19999999999999986e-82 < y Initial program 100.0%
Taylor expanded in z around inf 67.0%
Taylor expanded in x around 0 56.2%
if -4.69999999999999998e-107 < y < 2.19999999999999986e-82Initial program 100.0%
Taylor expanded in z around inf 100.0%
Taylor expanded in x around inf 76.2%
Final simplification63.5%
(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 79.0%
Taylor expanded in x around inf 36.3%
Final simplification36.3%
herbie shell --seed 2023287
(FPCore (x y z)
:name "Main:bigenough2 from A"
:precision binary64
(+ x (* y (+ z x))))