
(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 -6e-176) (not (<= x 1e-15))) (+ x (* y x)) (* y z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -6e-176) || !(x <= 1e-15)) {
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 <= (-6d-176)) .or. (.not. (x <= 1d-15))) 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 <= -6e-176) || !(x <= 1e-15)) {
tmp = x + (y * x);
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -6e-176) or not (x <= 1e-15): tmp = x + (y * x) else: tmp = y * z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -6e-176) || !(x <= 1e-15)) 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 <= -6e-176) || ~((x <= 1e-15))) tmp = x + (y * x); else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -6e-176], N[Not[LessEqual[x, 1e-15]], $MachinePrecision]], N[(x + N[(y * x), $MachinePrecision]), $MachinePrecision], N[(y * z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -6 \cdot 10^{-176} \lor \neg \left(x \leq 10^{-15}\right):\\
\;\;\;\;x + y \cdot x\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if x < -6e-176 or 1.0000000000000001e-15 < x Initial program 100.0%
Taylor expanded in z around 0 85.2%
*-commutative85.2%
Simplified85.2%
if -6e-176 < x < 1.0000000000000001e-15Initial program 100.0%
Taylor expanded in z around inf 94.4%
Taylor expanded in x around 0 73.2%
Final simplification81.6%
(FPCore (x y z) :precision binary64 (if (or (<= x -1.2e-41) (not (<= x 4.4e-8))) (+ x (* y x)) (+ x (* y z))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1.2e-41) || !(x <= 4.4e-8)) {
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 <= (-1.2d-41)) .or. (.not. (x <= 4.4d-8))) 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 <= -1.2e-41) || !(x <= 4.4e-8)) {
tmp = x + (y * x);
} else {
tmp = x + (y * z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -1.2e-41) or not (x <= 4.4e-8): tmp = x + (y * x) else: tmp = x + (y * z) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -1.2e-41) || !(x <= 4.4e-8)) 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 <= -1.2e-41) || ~((x <= 4.4e-8))) tmp = x + (y * x); else tmp = x + (y * z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -1.2e-41], N[Not[LessEqual[x, 4.4e-8]], $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 -1.2 \cdot 10^{-41} \lor \neg \left(x \leq 4.4 \cdot 10^{-8}\right):\\
\;\;\;\;x + y \cdot x\\
\mathbf{else}:\\
\;\;\;\;x + y \cdot z\\
\end{array}
\end{array}
if x < -1.20000000000000011e-41 or 4.3999999999999997e-8 < x Initial program 100.0%
Taylor expanded in z around 0 91.8%
*-commutative91.8%
Simplified91.8%
if -1.20000000000000011e-41 < x < 4.3999999999999997e-8Initial program 100.0%
Taylor expanded in z around inf 92.1%
Final simplification92.0%
(FPCore (x y z) :precision binary64 (if (<= y -5e-46) (* y z) (if (<= y 0.00052) x (* y z))))
double code(double x, double y, double z) {
double tmp;
if (y <= -5e-46) {
tmp = y * z;
} else if (y <= 0.00052) {
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 <= (-5d-46)) then
tmp = y * z
else if (y <= 0.00052d0) 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 <= -5e-46) {
tmp = y * z;
} else if (y <= 0.00052) {
tmp = x;
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -5e-46: tmp = y * z elif y <= 0.00052: tmp = x else: tmp = y * z return tmp
function code(x, y, z) tmp = 0.0 if (y <= -5e-46) tmp = Float64(y * z); elseif (y <= 0.00052) tmp = x; else tmp = Float64(y * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -5e-46) tmp = y * z; elseif (y <= 0.00052) tmp = x; else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -5e-46], N[(y * z), $MachinePrecision], If[LessEqual[y, 0.00052], x, N[(y * z), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -5 \cdot 10^{-46}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;y \leq 0.00052:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if y < -4.99999999999999992e-46 or 5.19999999999999954e-4 < y Initial program 100.0%
Taylor expanded in z around inf 55.2%
Taylor expanded in x around 0 52.0%
if -4.99999999999999992e-46 < y < 5.19999999999999954e-4Initial program 100.0%
Taylor expanded in y around 0 80.0%
Final simplification66.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 44.2%
Final simplification44.2%
herbie shell --seed 2023293
(FPCore (x y z)
:name "Main:bigenough2 from A"
:precision binary64
(+ x (* y (+ z x))))