
(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 -1.1e-64) (not (<= z 5.5e-128))) (+ x (* y z)) (+ x (* x y))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -1.1e-64) || !(z <= 5.5e-128)) {
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.1d-64)) .or. (.not. (z <= 5.5d-128))) 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.1e-64) || !(z <= 5.5e-128)) {
tmp = x + (y * z);
} else {
tmp = x + (x * y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -1.1e-64) or not (z <= 5.5e-128): tmp = x + (y * z) else: tmp = x + (x * y) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -1.1e-64) || !(z <= 5.5e-128)) 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.1e-64) || ~((z <= 5.5e-128))) tmp = x + (y * z); else tmp = x + (x * y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -1.1e-64], N[Not[LessEqual[z, 5.5e-128]], $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.1 \cdot 10^{-64} \lor \neg \left(z \leq 5.5 \cdot 10^{-128}\right):\\
\;\;\;\;x + y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x + x \cdot y\\
\end{array}
\end{array}
if z < -1.1e-64 or 5.5000000000000004e-128 < z Initial program 100.0%
Taylor expanded in z around inf 90.3%
if -1.1e-64 < z < 5.5000000000000004e-128Initial program 100.0%
Taylor expanded in z around 0 92.7%
*-commutative92.7%
Simplified92.7%
Final simplification91.1%
(FPCore (x y z) :precision binary64 (if (or (<= x -9.5e-73) (not (<= x 3.5e-86))) (+ x (* x y)) (* y z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -9.5e-73) || !(x <= 3.5e-86)) {
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 <= (-9.5d-73)) .or. (.not. (x <= 3.5d-86))) 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 <= -9.5e-73) || !(x <= 3.5e-86)) {
tmp = x + (x * y);
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -9.5e-73) or not (x <= 3.5e-86): tmp = x + (x * y) else: tmp = y * z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -9.5e-73) || !(x <= 3.5e-86)) 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 <= -9.5e-73) || ~((x <= 3.5e-86))) tmp = x + (x * y); else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -9.5e-73], N[Not[LessEqual[x, 3.5e-86]], $MachinePrecision]], N[(x + N[(x * y), $MachinePrecision]), $MachinePrecision], N[(y * z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -9.5 \cdot 10^{-73} \lor \neg \left(x \leq 3.5 \cdot 10^{-86}\right):\\
\;\;\;\;x + x \cdot y\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if x < -9.50000000000000005e-73 or 3.50000000000000021e-86 < x Initial program 100.0%
Taylor expanded in z around 0 79.1%
*-commutative79.1%
Simplified79.1%
if -9.50000000000000005e-73 < x < 3.50000000000000021e-86Initial program 100.0%
Taylor expanded in z around inf 93.6%
Taylor expanded in x around 0 72.7%
Final simplification76.4%
(FPCore (x y z) :precision binary64 (if (or (<= y -1.1e-10) (not (<= y 1.0))) (* x y) x))
double code(double x, double y, double z) {
double tmp;
if ((y <= -1.1e-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 <= (-1.1d-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 <= -1.1e-10) || !(y <= 1.0)) {
tmp = x * y;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -1.1e-10) or not (y <= 1.0): tmp = x * y else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -1.1e-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 <= -1.1e-10) || ~((y <= 1.0))) tmp = x * y; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -1.1e-10], N[Not[LessEqual[y, 1.0]], $MachinePrecision]], N[(x * y), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.1 \cdot 10^{-10} \lor \neg \left(y \leq 1\right):\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -1.09999999999999995e-10 or 1 < y Initial program 100.0%
Taylor expanded in z around 0 49.6%
*-commutative49.6%
Simplified49.6%
Taylor expanded in y around inf 48.8%
if -1.09999999999999995e-10 < y < 1Initial program 100.0%
Taylor expanded in y around 0 69.4%
Final simplification58.4%
(FPCore (x y z) :precision binary64 (if (<= y -5e-18) (* y z) (if (<= y 1.0) x (* x y))))
double code(double x, double y, double z) {
double tmp;
if (y <= -5e-18) {
tmp = y * z;
} else if (y <= 1.0) {
tmp = x;
} else {
tmp = 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 <= (-5d-18)) then
tmp = y * z
else if (y <= 1.0d0) then
tmp = x
else
tmp = x * y
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= -5e-18) {
tmp = y * z;
} else if (y <= 1.0) {
tmp = x;
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -5e-18: tmp = y * z elif y <= 1.0: tmp = x else: tmp = x * y return tmp
function code(x, y, z) tmp = 0.0 if (y <= -5e-18) tmp = Float64(y * z); elseif (y <= 1.0) tmp = x; else tmp = Float64(x * y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -5e-18) tmp = y * z; elseif (y <= 1.0) tmp = x; else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -5e-18], N[(y * z), $MachinePrecision], If[LessEqual[y, 1.0], x, N[(x * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -5 \cdot 10^{-18}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;y \leq 1:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if y < -5.00000000000000036e-18Initial program 100.0%
Taylor expanded in z around inf 61.3%
Taylor expanded in x around 0 61.8%
if -5.00000000000000036e-18 < y < 1Initial program 100.0%
Taylor expanded in y around 0 70.5%
if 1 < y Initial program 100.0%
Taylor expanded in z around 0 56.7%
*-commutative56.7%
Simplified56.7%
Taylor expanded in y around inf 56.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 y around 0 33.9%
herbie shell --seed 2024113
(FPCore (x y z)
:name "Main:bigenough2 from A"
:precision binary64
(+ x (* y (+ z x))))