
(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 (fma y (+ x z) x))
double code(double x, double y, double z) {
return fma(y, (x + z), x);
}
function code(x, y, z) return fma(y, Float64(x + z), x) end
code[x_, y_, z_] := N[(y * N[(x + z), $MachinePrecision] + x), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(y, x + z, x\right)
\end{array}
Initial program 100.0%
+-commutative100.0%
fma-def100.0%
+-commutative100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x y z) :precision binary64 (if (or (<= x -3.9e-87) (not (<= x 6.5e-117))) (+ x (* y x)) (* y z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -3.9e-87) || !(x <= 6.5e-117)) {
tmp = x + (y * 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 ((x <= (-3.9d-87)) .or. (.not. (x <= 6.5d-117))) then
tmp = x + (y * x)
else
tmp = y * z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -3.9e-87) || !(x <= 6.5e-117)) {
tmp = x + (y * x);
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -3.9e-87) or not (x <= 6.5e-117): tmp = x + (y * x) else: tmp = y * z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -3.9e-87) || !(x <= 6.5e-117)) tmp = Float64(x + Float64(y * x)); else tmp = Float64(y * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -3.9e-87) || ~((x <= 6.5e-117))) tmp = x + (y * x); else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -3.9e-87], N[Not[LessEqual[x, 6.5e-117]], $MachinePrecision]], N[(x + N[(y * x), $MachinePrecision]), $MachinePrecision], N[(y * z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -3.9 \cdot 10^{-87} \lor \neg \left(x \leq 6.5 \cdot 10^{-117}\right):\\
\;\;\;\;x + y \cdot x\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if x < -3.8999999999999998e-87 or 6.5000000000000001e-117 < x Initial program 100.0%
Taylor expanded in z around 0 81.3%
*-commutative81.3%
Simplified81.3%
if -3.8999999999999998e-87 < x < 6.5000000000000001e-117Initial program 100.0%
Taylor expanded in z around inf 92.1%
Taylor expanded in x around 0 79.2%
Final simplification80.6%
(FPCore (x y z) :precision binary64 (if (or (<= x -3.3e+112) (not (<= x 2.8e+21))) (+ x (* y x)) (+ x (* y z))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -3.3e+112) || !(x <= 2.8e+21)) {
tmp = x + (y * x);
} 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 ((x <= (-3.3d+112)) .or. (.not. (x <= 2.8d+21))) then
tmp = x + (y * x)
else
tmp = x + (y * z)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -3.3e+112) || !(x <= 2.8e+21)) {
tmp = x + (y * x);
} else {
tmp = x + (y * z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -3.3e+112) or not (x <= 2.8e+21): tmp = x + (y * x) else: tmp = x + (y * z) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -3.3e+112) || !(x <= 2.8e+21)) tmp = Float64(x + Float64(y * x)); else tmp = Float64(x + Float64(y * z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -3.3e+112) || ~((x <= 2.8e+21))) tmp = x + (y * x); else tmp = x + (y * z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -3.3e+112], N[Not[LessEqual[x, 2.8e+21]], $MachinePrecision]], N[(x + N[(y * x), $MachinePrecision]), $MachinePrecision], N[(x + N[(y * z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -3.3 \cdot 10^{+112} \lor \neg \left(x \leq 2.8 \cdot 10^{+21}\right):\\
\;\;\;\;x + y \cdot x\\
\mathbf{else}:\\
\;\;\;\;x + y \cdot z\\
\end{array}
\end{array}
if x < -3.2999999999999999e112 or 2.8e21 < x Initial program 100.0%
Taylor expanded in z around 0 90.0%
*-commutative90.0%
Simplified90.0%
if -3.2999999999999999e112 < x < 2.8e21Initial program 100.0%
Taylor expanded in z around inf 87.5%
Final simplification88.7%
(FPCore (x y z) :precision binary64 (if (or (<= y -0.000106) (not (<= y 2.1e-19))) (* y z) x))
double code(double x, double y, double z) {
double tmp;
if ((y <= -0.000106) || !(y <= 2.1e-19)) {
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 <= (-0.000106d0)) .or. (.not. (y <= 2.1d-19))) 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 <= -0.000106) || !(y <= 2.1e-19)) {
tmp = y * z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -0.000106) or not (y <= 2.1e-19): tmp = y * z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -0.000106) || !(y <= 2.1e-19)) tmp = Float64(y * z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -0.000106) || ~((y <= 2.1e-19))) tmp = y * z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -0.000106], N[Not[LessEqual[y, 2.1e-19]], $MachinePrecision]], N[(y * z), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -0.000106 \lor \neg \left(y \leq 2.1 \cdot 10^{-19}\right):\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -1.06e-4 or 2.0999999999999999e-19 < y Initial program 100.0%
Taylor expanded in z around inf 57.1%
Taylor expanded in x around 0 55.7%
if -1.06e-4 < y < 2.0999999999999999e-19Initial program 100.0%
Taylor expanded in y around 0 79.2%
Final simplification65.5%
(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 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 35.4%
Final simplification35.4%
herbie shell --seed 2023334
(FPCore (x y z)
:name "Main:bigenough2 from A"
:precision binary64
(+ x (* y (+ z x))))