
(FPCore (x eps) :precision binary64 (- (pow (+ x eps) 5.0) (pow x 5.0)))
double code(double x, double eps) {
return pow((x + eps), 5.0) - pow(x, 5.0);
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
code = ((x + eps) ** 5.0d0) - (x ** 5.0d0)
end function
public static double code(double x, double eps) {
return Math.pow((x + eps), 5.0) - Math.pow(x, 5.0);
}
def code(x, eps): return math.pow((x + eps), 5.0) - math.pow(x, 5.0)
function code(x, eps) return Float64((Float64(x + eps) ^ 5.0) - (x ^ 5.0)) end
function tmp = code(x, eps) tmp = ((x + eps) ^ 5.0) - (x ^ 5.0); end
code[x_, eps_] := N[(N[Power[N[(x + eps), $MachinePrecision], 5.0], $MachinePrecision] - N[Power[x, 5.0], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
{\left(x + \varepsilon\right)}^{5} - {x}^{5}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 11 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x eps) :precision binary64 (- (pow (+ x eps) 5.0) (pow x 5.0)))
double code(double x, double eps) {
return pow((x + eps), 5.0) - pow(x, 5.0);
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
code = ((x + eps) ** 5.0d0) - (x ** 5.0d0)
end function
public static double code(double x, double eps) {
return Math.pow((x + eps), 5.0) - Math.pow(x, 5.0);
}
def code(x, eps): return math.pow((x + eps), 5.0) - math.pow(x, 5.0)
function code(x, eps) return Float64((Float64(x + eps) ^ 5.0) - (x ^ 5.0)) end
function tmp = code(x, eps) tmp = ((x + eps) ^ 5.0) - (x ^ 5.0); end
code[x_, eps_] := N[(N[Power[N[(x + eps), $MachinePrecision], 5.0], $MachinePrecision] - N[Power[x, 5.0], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
{\left(x + \varepsilon\right)}^{5} - {x}^{5}
\end{array}
(FPCore (x eps)
:precision binary64
(if (<= x -8.2e-53)
(*
(fma
(* (fma (* (+ eps x) 10.0) x (* (* 5.0 eps) eps)) x)
eps
(* (pow x 4.0) 5.0))
eps)
(if (<= x 5e-60)
(* (fma (/ x eps) 5.0 1.0) (pow eps 5.0))
(*
(fma (* (* x x) eps) 5.0 (* (* (* eps eps) (+ eps x)) 10.0))
(* x x)))))
double code(double x, double eps) {
double tmp;
if (x <= -8.2e-53) {
tmp = fma((fma(((eps + x) * 10.0), x, ((5.0 * eps) * eps)) * x), eps, (pow(x, 4.0) * 5.0)) * eps;
} else if (x <= 5e-60) {
tmp = fma((x / eps), 5.0, 1.0) * pow(eps, 5.0);
} else {
tmp = fma(((x * x) * eps), 5.0, (((eps * eps) * (eps + x)) * 10.0)) * (x * x);
}
return tmp;
}
function code(x, eps) tmp = 0.0 if (x <= -8.2e-53) tmp = Float64(fma(Float64(fma(Float64(Float64(eps + x) * 10.0), x, Float64(Float64(5.0 * eps) * eps)) * x), eps, Float64((x ^ 4.0) * 5.0)) * eps); elseif (x <= 5e-60) tmp = Float64(fma(Float64(x / eps), 5.0, 1.0) * (eps ^ 5.0)); else tmp = Float64(fma(Float64(Float64(x * x) * eps), 5.0, Float64(Float64(Float64(eps * eps) * Float64(eps + x)) * 10.0)) * Float64(x * x)); end return tmp end
code[x_, eps_] := If[LessEqual[x, -8.2e-53], N[(N[(N[(N[(N[(N[(eps + x), $MachinePrecision] * 10.0), $MachinePrecision] * x + N[(N[(5.0 * eps), $MachinePrecision] * eps), $MachinePrecision]), $MachinePrecision] * x), $MachinePrecision] * eps + N[(N[Power[x, 4.0], $MachinePrecision] * 5.0), $MachinePrecision]), $MachinePrecision] * eps), $MachinePrecision], If[LessEqual[x, 5e-60], N[(N[(N[(x / eps), $MachinePrecision] * 5.0 + 1.0), $MachinePrecision] * N[Power[eps, 5.0], $MachinePrecision]), $MachinePrecision], N[(N[(N[(N[(x * x), $MachinePrecision] * eps), $MachinePrecision] * 5.0 + N[(N[(N[(eps * eps), $MachinePrecision] * N[(eps + x), $MachinePrecision]), $MachinePrecision] * 10.0), $MachinePrecision]), $MachinePrecision] * N[(x * x), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -8.2 \cdot 10^{-53}:\\
\;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(\left(\varepsilon + x\right) \cdot 10, x, \left(5 \cdot \varepsilon\right) \cdot \varepsilon\right) \cdot x, \varepsilon, {x}^{4} \cdot 5\right) \cdot \varepsilon\\
\mathbf{elif}\;x \leq 5 \cdot 10^{-60}:\\
\;\;\;\;\mathsf{fma}\left(\frac{x}{\varepsilon}, 5, 1\right) \cdot {\varepsilon}^{5}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\left(x \cdot x\right) \cdot \varepsilon, 5, \left(\left(\varepsilon \cdot \varepsilon\right) \cdot \left(\varepsilon + x\right)\right) \cdot 10\right) \cdot \left(x \cdot x\right)\\
\end{array}
\end{array}
if x < -8.2000000000000001e-53Initial program 32.2%
Taylor expanded in eps around 0
Applied rewrites95.0%
Taylor expanded in x around 0
Applied rewrites95.0%
if -8.2000000000000001e-53 < x < 5.0000000000000001e-60Initial program 100.0%
Taylor expanded in eps around inf
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
distribute-lft1-inN/A
metadata-evalN/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f64N/A
lower-pow.f64100.0
Applied rewrites100.0%
if 5.0000000000000001e-60 < x Initial program 41.4%
Taylor expanded in eps around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites89.7%
Taylor expanded in x around 0
Applied rewrites25.5%
Taylor expanded in x around 0
Applied rewrites89.9%
(FPCore (x eps)
:precision binary64
(if (<= x -8.2e-53)
(* (* (* (fma (* x x) 5.0 (* (* eps (+ eps x)) 10.0)) x) x) eps)
(if (<= x 5e-60)
(* (fma (/ x eps) 5.0 1.0) (pow eps 5.0))
(*
(fma (* (* x x) eps) 5.0 (* (* (* eps eps) (+ eps x)) 10.0))
(* x x)))))
double code(double x, double eps) {
double tmp;
if (x <= -8.2e-53) {
tmp = ((fma((x * x), 5.0, ((eps * (eps + x)) * 10.0)) * x) * x) * eps;
} else if (x <= 5e-60) {
tmp = fma((x / eps), 5.0, 1.0) * pow(eps, 5.0);
} else {
tmp = fma(((x * x) * eps), 5.0, (((eps * eps) * (eps + x)) * 10.0)) * (x * x);
}
return tmp;
}
function code(x, eps) tmp = 0.0 if (x <= -8.2e-53) tmp = Float64(Float64(Float64(fma(Float64(x * x), 5.0, Float64(Float64(eps * Float64(eps + x)) * 10.0)) * x) * x) * eps); elseif (x <= 5e-60) tmp = Float64(fma(Float64(x / eps), 5.0, 1.0) * (eps ^ 5.0)); else tmp = Float64(fma(Float64(Float64(x * x) * eps), 5.0, Float64(Float64(Float64(eps * eps) * Float64(eps + x)) * 10.0)) * Float64(x * x)); end return tmp end
code[x_, eps_] := If[LessEqual[x, -8.2e-53], N[(N[(N[(N[(N[(x * x), $MachinePrecision] * 5.0 + N[(N[(eps * N[(eps + x), $MachinePrecision]), $MachinePrecision] * 10.0), $MachinePrecision]), $MachinePrecision] * x), $MachinePrecision] * x), $MachinePrecision] * eps), $MachinePrecision], If[LessEqual[x, 5e-60], N[(N[(N[(x / eps), $MachinePrecision] * 5.0 + 1.0), $MachinePrecision] * N[Power[eps, 5.0], $MachinePrecision]), $MachinePrecision], N[(N[(N[(N[(x * x), $MachinePrecision] * eps), $MachinePrecision] * 5.0 + N[(N[(N[(eps * eps), $MachinePrecision] * N[(eps + x), $MachinePrecision]), $MachinePrecision] * 10.0), $MachinePrecision]), $MachinePrecision] * N[(x * x), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -8.2 \cdot 10^{-53}:\\
\;\;\;\;\left(\left(\mathsf{fma}\left(x \cdot x, 5, \left(\varepsilon \cdot \left(\varepsilon + x\right)\right) \cdot 10\right) \cdot x\right) \cdot x\right) \cdot \varepsilon\\
\mathbf{elif}\;x \leq 5 \cdot 10^{-60}:\\
\;\;\;\;\mathsf{fma}\left(\frac{x}{\varepsilon}, 5, 1\right) \cdot {\varepsilon}^{5}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\left(x \cdot x\right) \cdot \varepsilon, 5, \left(\left(\varepsilon \cdot \varepsilon\right) \cdot \left(\varepsilon + x\right)\right) \cdot 10\right) \cdot \left(x \cdot x\right)\\
\end{array}
\end{array}
if x < -8.2000000000000001e-53Initial program 32.2%
Taylor expanded in eps around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites94.8%
Taylor expanded in x around 0
Applied rewrites94.9%
if -8.2000000000000001e-53 < x < 5.0000000000000001e-60Initial program 100.0%
Taylor expanded in eps around inf
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
distribute-lft1-inN/A
metadata-evalN/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f64N/A
lower-pow.f64100.0
Applied rewrites100.0%
if 5.0000000000000001e-60 < x Initial program 41.4%
Taylor expanded in eps around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites89.7%
Taylor expanded in x around 0
Applied rewrites25.5%
Taylor expanded in x around 0
Applied rewrites89.9%
(FPCore (x eps)
:precision binary64
(if (<= x -8e-53)
(* (* (* (fma (* x x) 5.0 (* (* eps (+ eps x)) 10.0)) x) x) eps)
(if (<= x 5e-60)
(pow eps 5.0)
(*
(fma (* (* x x) eps) 5.0 (* (* (* eps eps) (+ eps x)) 10.0))
(* x x)))))
double code(double x, double eps) {
double tmp;
if (x <= -8e-53) {
tmp = ((fma((x * x), 5.0, ((eps * (eps + x)) * 10.0)) * x) * x) * eps;
} else if (x <= 5e-60) {
tmp = pow(eps, 5.0);
} else {
tmp = fma(((x * x) * eps), 5.0, (((eps * eps) * (eps + x)) * 10.0)) * (x * x);
}
return tmp;
}
function code(x, eps) tmp = 0.0 if (x <= -8e-53) tmp = Float64(Float64(Float64(fma(Float64(x * x), 5.0, Float64(Float64(eps * Float64(eps + x)) * 10.0)) * x) * x) * eps); elseif (x <= 5e-60) tmp = eps ^ 5.0; else tmp = Float64(fma(Float64(Float64(x * x) * eps), 5.0, Float64(Float64(Float64(eps * eps) * Float64(eps + x)) * 10.0)) * Float64(x * x)); end return tmp end
code[x_, eps_] := If[LessEqual[x, -8e-53], N[(N[(N[(N[(N[(x * x), $MachinePrecision] * 5.0 + N[(N[(eps * N[(eps + x), $MachinePrecision]), $MachinePrecision] * 10.0), $MachinePrecision]), $MachinePrecision] * x), $MachinePrecision] * x), $MachinePrecision] * eps), $MachinePrecision], If[LessEqual[x, 5e-60], N[Power[eps, 5.0], $MachinePrecision], N[(N[(N[(N[(x * x), $MachinePrecision] * eps), $MachinePrecision] * 5.0 + N[(N[(N[(eps * eps), $MachinePrecision] * N[(eps + x), $MachinePrecision]), $MachinePrecision] * 10.0), $MachinePrecision]), $MachinePrecision] * N[(x * x), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -8 \cdot 10^{-53}:\\
\;\;\;\;\left(\left(\mathsf{fma}\left(x \cdot x, 5, \left(\varepsilon \cdot \left(\varepsilon + x\right)\right) \cdot 10\right) \cdot x\right) \cdot x\right) \cdot \varepsilon\\
\mathbf{elif}\;x \leq 5 \cdot 10^{-60}:\\
\;\;\;\;{\varepsilon}^{5}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\left(x \cdot x\right) \cdot \varepsilon, 5, \left(\left(\varepsilon \cdot \varepsilon\right) \cdot \left(\varepsilon + x\right)\right) \cdot 10\right) \cdot \left(x \cdot x\right)\\
\end{array}
\end{array}
if x < -8.00000000000000025e-53Initial program 32.2%
Taylor expanded in eps around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites94.8%
Taylor expanded in x around 0
Applied rewrites94.9%
if -8.00000000000000025e-53 < x < 5.0000000000000001e-60Initial program 100.0%
Taylor expanded in x around 0
lower-pow.f64100.0
Applied rewrites100.0%
if 5.0000000000000001e-60 < x Initial program 41.4%
Taylor expanded in eps around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites89.7%
Taylor expanded in x around 0
Applied rewrites25.5%
Taylor expanded in x around 0
Applied rewrites89.9%
(FPCore (x eps)
:precision binary64
(if (<= x -8.2e-53)
(* (* (* (fma (* x x) 5.0 (* (* eps (+ eps x)) 10.0)) x) x) eps)
(if (<= x 5e-60)
(* (* (* (fma (fma x 5.0 eps) eps (* (* 10.0 x) x)) eps) eps) eps)
(*
(fma (* (* x x) eps) 5.0 (* (* (* eps eps) (+ eps x)) 10.0))
(* x x)))))
double code(double x, double eps) {
double tmp;
if (x <= -8.2e-53) {
tmp = ((fma((x * x), 5.0, ((eps * (eps + x)) * 10.0)) * x) * x) * eps;
} else if (x <= 5e-60) {
tmp = ((fma(fma(x, 5.0, eps), eps, ((10.0 * x) * x)) * eps) * eps) * eps;
} else {
tmp = fma(((x * x) * eps), 5.0, (((eps * eps) * (eps + x)) * 10.0)) * (x * x);
}
return tmp;
}
function code(x, eps) tmp = 0.0 if (x <= -8.2e-53) tmp = Float64(Float64(Float64(fma(Float64(x * x), 5.0, Float64(Float64(eps * Float64(eps + x)) * 10.0)) * x) * x) * eps); elseif (x <= 5e-60) tmp = Float64(Float64(Float64(fma(fma(x, 5.0, eps), eps, Float64(Float64(10.0 * x) * x)) * eps) * eps) * eps); else tmp = Float64(fma(Float64(Float64(x * x) * eps), 5.0, Float64(Float64(Float64(eps * eps) * Float64(eps + x)) * 10.0)) * Float64(x * x)); end return tmp end
code[x_, eps_] := If[LessEqual[x, -8.2e-53], N[(N[(N[(N[(N[(x * x), $MachinePrecision] * 5.0 + N[(N[(eps * N[(eps + x), $MachinePrecision]), $MachinePrecision] * 10.0), $MachinePrecision]), $MachinePrecision] * x), $MachinePrecision] * x), $MachinePrecision] * eps), $MachinePrecision], If[LessEqual[x, 5e-60], N[(N[(N[(N[(N[(x * 5.0 + eps), $MachinePrecision] * eps + N[(N[(10.0 * x), $MachinePrecision] * x), $MachinePrecision]), $MachinePrecision] * eps), $MachinePrecision] * eps), $MachinePrecision] * eps), $MachinePrecision], N[(N[(N[(N[(x * x), $MachinePrecision] * eps), $MachinePrecision] * 5.0 + N[(N[(N[(eps * eps), $MachinePrecision] * N[(eps + x), $MachinePrecision]), $MachinePrecision] * 10.0), $MachinePrecision]), $MachinePrecision] * N[(x * x), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -8.2 \cdot 10^{-53}:\\
\;\;\;\;\left(\left(\mathsf{fma}\left(x \cdot x, 5, \left(\varepsilon \cdot \left(\varepsilon + x\right)\right) \cdot 10\right) \cdot x\right) \cdot x\right) \cdot \varepsilon\\
\mathbf{elif}\;x \leq 5 \cdot 10^{-60}:\\
\;\;\;\;\left(\left(\mathsf{fma}\left(\mathsf{fma}\left(x, 5, \varepsilon\right), \varepsilon, \left(10 \cdot x\right) \cdot x\right) \cdot \varepsilon\right) \cdot \varepsilon\right) \cdot \varepsilon\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\left(x \cdot x\right) \cdot \varepsilon, 5, \left(\left(\varepsilon \cdot \varepsilon\right) \cdot \left(\varepsilon + x\right)\right) \cdot 10\right) \cdot \left(x \cdot x\right)\\
\end{array}
\end{array}
if x < -8.2000000000000001e-53Initial program 32.2%
Taylor expanded in eps around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites94.8%
Taylor expanded in x around 0
Applied rewrites94.9%
if -8.2000000000000001e-53 < x < 5.0000000000000001e-60Initial program 100.0%
Taylor expanded in eps around -inf
mul-1-negN/A
*-commutativeN/A
distribute-lft-neg-inN/A
lower-*.f64N/A
Applied rewrites93.7%
Taylor expanded in x around 0
Applied rewrites99.9%
Applied rewrites99.8%
Applied rewrites99.9%
if 5.0000000000000001e-60 < x Initial program 41.4%
Taylor expanded in eps around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites89.7%
Taylor expanded in x around 0
Applied rewrites25.5%
Taylor expanded in x around 0
Applied rewrites89.9%
(FPCore (x eps) :precision binary64 (if (or (<= x -8.2e-53) (not (<= x 5e-60))) (* (* (* (fma (* x x) 5.0 (* (* eps (+ eps x)) 10.0)) x) x) eps) (* (* (* (fma (fma x 5.0 eps) eps (* (* 10.0 x) x)) eps) eps) eps)))
double code(double x, double eps) {
double tmp;
if ((x <= -8.2e-53) || !(x <= 5e-60)) {
tmp = ((fma((x * x), 5.0, ((eps * (eps + x)) * 10.0)) * x) * x) * eps;
} else {
tmp = ((fma(fma(x, 5.0, eps), eps, ((10.0 * x) * x)) * eps) * eps) * eps;
}
return tmp;
}
function code(x, eps) tmp = 0.0 if ((x <= -8.2e-53) || !(x <= 5e-60)) tmp = Float64(Float64(Float64(fma(Float64(x * x), 5.0, Float64(Float64(eps * Float64(eps + x)) * 10.0)) * x) * x) * eps); else tmp = Float64(Float64(Float64(fma(fma(x, 5.0, eps), eps, Float64(Float64(10.0 * x) * x)) * eps) * eps) * eps); end return tmp end
code[x_, eps_] := If[Or[LessEqual[x, -8.2e-53], N[Not[LessEqual[x, 5e-60]], $MachinePrecision]], N[(N[(N[(N[(N[(x * x), $MachinePrecision] * 5.0 + N[(N[(eps * N[(eps + x), $MachinePrecision]), $MachinePrecision] * 10.0), $MachinePrecision]), $MachinePrecision] * x), $MachinePrecision] * x), $MachinePrecision] * eps), $MachinePrecision], N[(N[(N[(N[(N[(x * 5.0 + eps), $MachinePrecision] * eps + N[(N[(10.0 * x), $MachinePrecision] * x), $MachinePrecision]), $MachinePrecision] * eps), $MachinePrecision] * eps), $MachinePrecision] * eps), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -8.2 \cdot 10^{-53} \lor \neg \left(x \leq 5 \cdot 10^{-60}\right):\\
\;\;\;\;\left(\left(\mathsf{fma}\left(x \cdot x, 5, \left(\varepsilon \cdot \left(\varepsilon + x\right)\right) \cdot 10\right) \cdot x\right) \cdot x\right) \cdot \varepsilon\\
\mathbf{else}:\\
\;\;\;\;\left(\left(\mathsf{fma}\left(\mathsf{fma}\left(x, 5, \varepsilon\right), \varepsilon, \left(10 \cdot x\right) \cdot x\right) \cdot \varepsilon\right) \cdot \varepsilon\right) \cdot \varepsilon\\
\end{array}
\end{array}
if x < -8.2000000000000001e-53 or 5.0000000000000001e-60 < x Initial program 35.6%
Taylor expanded in eps around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites92.9%
Taylor expanded in x around 0
Applied rewrites93.0%
if -8.2000000000000001e-53 < x < 5.0000000000000001e-60Initial program 100.0%
Taylor expanded in eps around -inf
mul-1-negN/A
*-commutativeN/A
distribute-lft-neg-inN/A
lower-*.f64N/A
Applied rewrites93.7%
Taylor expanded in x around 0
Applied rewrites99.9%
Applied rewrites99.8%
Applied rewrites99.9%
Final simplification98.6%
(FPCore (x eps)
:precision binary64
(let* ((t_0 (fma (* x x) 5.0 (* (* eps (+ eps x)) 10.0))))
(if (<= x -8.2e-53)
(* (* (* t_0 x) x) eps)
(if (<= x 5e-60)
(* (* (* (fma (fma x 5.0 eps) eps (* (* 10.0 x) x)) eps) eps) eps)
(* (* t_0 (* x x)) eps)))))
double code(double x, double eps) {
double t_0 = fma((x * x), 5.0, ((eps * (eps + x)) * 10.0));
double tmp;
if (x <= -8.2e-53) {
tmp = ((t_0 * x) * x) * eps;
} else if (x <= 5e-60) {
tmp = ((fma(fma(x, 5.0, eps), eps, ((10.0 * x) * x)) * eps) * eps) * eps;
} else {
tmp = (t_0 * (x * x)) * eps;
}
return tmp;
}
function code(x, eps) t_0 = fma(Float64(x * x), 5.0, Float64(Float64(eps * Float64(eps + x)) * 10.0)) tmp = 0.0 if (x <= -8.2e-53) tmp = Float64(Float64(Float64(t_0 * x) * x) * eps); elseif (x <= 5e-60) tmp = Float64(Float64(Float64(fma(fma(x, 5.0, eps), eps, Float64(Float64(10.0 * x) * x)) * eps) * eps) * eps); else tmp = Float64(Float64(t_0 * Float64(x * x)) * eps); end return tmp end
code[x_, eps_] := Block[{t$95$0 = N[(N[(x * x), $MachinePrecision] * 5.0 + N[(N[(eps * N[(eps + x), $MachinePrecision]), $MachinePrecision] * 10.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, -8.2e-53], N[(N[(N[(t$95$0 * x), $MachinePrecision] * x), $MachinePrecision] * eps), $MachinePrecision], If[LessEqual[x, 5e-60], N[(N[(N[(N[(N[(x * 5.0 + eps), $MachinePrecision] * eps + N[(N[(10.0 * x), $MachinePrecision] * x), $MachinePrecision]), $MachinePrecision] * eps), $MachinePrecision] * eps), $MachinePrecision] * eps), $MachinePrecision], N[(N[(t$95$0 * N[(x * x), $MachinePrecision]), $MachinePrecision] * eps), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \mathsf{fma}\left(x \cdot x, 5, \left(\varepsilon \cdot \left(\varepsilon + x\right)\right) \cdot 10\right)\\
\mathbf{if}\;x \leq -8.2 \cdot 10^{-53}:\\
\;\;\;\;\left(\left(t\_0 \cdot x\right) \cdot x\right) \cdot \varepsilon\\
\mathbf{elif}\;x \leq 5 \cdot 10^{-60}:\\
\;\;\;\;\left(\left(\mathsf{fma}\left(\mathsf{fma}\left(x, 5, \varepsilon\right), \varepsilon, \left(10 \cdot x\right) \cdot x\right) \cdot \varepsilon\right) \cdot \varepsilon\right) \cdot \varepsilon\\
\mathbf{else}:\\
\;\;\;\;\left(t\_0 \cdot \left(x \cdot x\right)\right) \cdot \varepsilon\\
\end{array}
\end{array}
if x < -8.2000000000000001e-53Initial program 32.2%
Taylor expanded in eps around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites94.8%
Taylor expanded in x around 0
Applied rewrites94.9%
if -8.2000000000000001e-53 < x < 5.0000000000000001e-60Initial program 100.0%
Taylor expanded in eps around -inf
mul-1-negN/A
*-commutativeN/A
distribute-lft-neg-inN/A
lower-*.f64N/A
Applied rewrites93.7%
Taylor expanded in x around 0
Applied rewrites99.9%
Applied rewrites99.8%
Applied rewrites99.9%
if 5.0000000000000001e-60 < x Initial program 41.4%
Taylor expanded in eps around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites89.7%
Taylor expanded in x around 0
Applied rewrites25.5%
Taylor expanded in x around 0
Applied rewrites89.7%
(FPCore (x eps) :precision binary64 (if (or (<= x -8.2e-53) (not (<= x 5e-60))) (* (* (* (fma (* x x) 5.0 (* (* eps x) 10.0)) x) x) eps) (* (* (* (fma (fma x 5.0 eps) eps (* (* 10.0 x) x)) eps) eps) eps)))
double code(double x, double eps) {
double tmp;
if ((x <= -8.2e-53) || !(x <= 5e-60)) {
tmp = ((fma((x * x), 5.0, ((eps * x) * 10.0)) * x) * x) * eps;
} else {
tmp = ((fma(fma(x, 5.0, eps), eps, ((10.0 * x) * x)) * eps) * eps) * eps;
}
return tmp;
}
function code(x, eps) tmp = 0.0 if ((x <= -8.2e-53) || !(x <= 5e-60)) tmp = Float64(Float64(Float64(fma(Float64(x * x), 5.0, Float64(Float64(eps * x) * 10.0)) * x) * x) * eps); else tmp = Float64(Float64(Float64(fma(fma(x, 5.0, eps), eps, Float64(Float64(10.0 * x) * x)) * eps) * eps) * eps); end return tmp end
code[x_, eps_] := If[Or[LessEqual[x, -8.2e-53], N[Not[LessEqual[x, 5e-60]], $MachinePrecision]], N[(N[(N[(N[(N[(x * x), $MachinePrecision] * 5.0 + N[(N[(eps * x), $MachinePrecision] * 10.0), $MachinePrecision]), $MachinePrecision] * x), $MachinePrecision] * x), $MachinePrecision] * eps), $MachinePrecision], N[(N[(N[(N[(N[(x * 5.0 + eps), $MachinePrecision] * eps + N[(N[(10.0 * x), $MachinePrecision] * x), $MachinePrecision]), $MachinePrecision] * eps), $MachinePrecision] * eps), $MachinePrecision] * eps), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -8.2 \cdot 10^{-53} \lor \neg \left(x \leq 5 \cdot 10^{-60}\right):\\
\;\;\;\;\left(\left(\mathsf{fma}\left(x \cdot x, 5, \left(\varepsilon \cdot x\right) \cdot 10\right) \cdot x\right) \cdot x\right) \cdot \varepsilon\\
\mathbf{else}:\\
\;\;\;\;\left(\left(\mathsf{fma}\left(\mathsf{fma}\left(x, 5, \varepsilon\right), \varepsilon, \left(10 \cdot x\right) \cdot x\right) \cdot \varepsilon\right) \cdot \varepsilon\right) \cdot \varepsilon\\
\end{array}
\end{array}
if x < -8.2000000000000001e-53 or 5.0000000000000001e-60 < x Initial program 35.6%
Taylor expanded in eps around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites92.9%
Taylor expanded in x around 0
Applied rewrites93.0%
Taylor expanded in x around inf
Applied rewrites91.6%
if -8.2000000000000001e-53 < x < 5.0000000000000001e-60Initial program 100.0%
Taylor expanded in eps around -inf
mul-1-negN/A
*-commutativeN/A
distribute-lft-neg-inN/A
lower-*.f64N/A
Applied rewrites93.7%
Taylor expanded in x around 0
Applied rewrites99.9%
Applied rewrites99.8%
Applied rewrites99.9%
Final simplification98.3%
(FPCore (x eps) :precision binary64 (* (* (* (fma (* x x) 5.0 (* (* eps x) 10.0)) x) x) eps))
double code(double x, double eps) {
return ((fma((x * x), 5.0, ((eps * x) * 10.0)) * x) * x) * eps;
}
function code(x, eps) return Float64(Float64(Float64(fma(Float64(x * x), 5.0, Float64(Float64(eps * x) * 10.0)) * x) * x) * eps) end
code[x_, eps_] := N[(N[(N[(N[(N[(x * x), $MachinePrecision] * 5.0 + N[(N[(eps * x), $MachinePrecision] * 10.0), $MachinePrecision]), $MachinePrecision] * x), $MachinePrecision] * x), $MachinePrecision] * eps), $MachinePrecision]
\begin{array}{l}
\\
\left(\left(\mathsf{fma}\left(x \cdot x, 5, \left(\varepsilon \cdot x\right) \cdot 10\right) \cdot x\right) \cdot x\right) \cdot \varepsilon
\end{array}
Initial program 87.7%
Taylor expanded in eps around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites84.2%
Taylor expanded in x around 0
Applied rewrites84.3%
Taylor expanded in x around inf
Applied rewrites83.9%
(FPCore (x eps) :precision binary64 (* (* (* (* (fma 10.0 eps (* 5.0 x)) x) x) x) eps))
double code(double x, double eps) {
return (((fma(10.0, eps, (5.0 * x)) * x) * x) * x) * eps;
}
function code(x, eps) return Float64(Float64(Float64(Float64(fma(10.0, eps, Float64(5.0 * x)) * x) * x) * x) * eps) end
code[x_, eps_] := N[(N[(N[(N[(N[(10.0 * eps + N[(5.0 * x), $MachinePrecision]), $MachinePrecision] * x), $MachinePrecision] * x), $MachinePrecision] * x), $MachinePrecision] * eps), $MachinePrecision]
\begin{array}{l}
\\
\left(\left(\left(\mathsf{fma}\left(10, \varepsilon, 5 \cdot x\right) \cdot x\right) \cdot x\right) \cdot x\right) \cdot \varepsilon
\end{array}
Initial program 87.7%
Taylor expanded in eps around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites84.2%
Taylor expanded in x around 0
Applied rewrites84.3%
Taylor expanded in eps around 0
Applied rewrites83.9%
(FPCore (x eps) :precision binary64 (* (* (* (* (* x x) 5.0) x) x) eps))
double code(double x, double eps) {
return ((((x * x) * 5.0) * x) * x) * eps;
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
code = ((((x * x) * 5.0d0) * x) * x) * eps
end function
public static double code(double x, double eps) {
return ((((x * x) * 5.0) * x) * x) * eps;
}
def code(x, eps): return ((((x * x) * 5.0) * x) * x) * eps
function code(x, eps) return Float64(Float64(Float64(Float64(Float64(x * x) * 5.0) * x) * x) * eps) end
function tmp = code(x, eps) tmp = ((((x * x) * 5.0) * x) * x) * eps; end
code[x_, eps_] := N[(N[(N[(N[(N[(x * x), $MachinePrecision] * 5.0), $MachinePrecision] * x), $MachinePrecision] * x), $MachinePrecision] * eps), $MachinePrecision]
\begin{array}{l}
\\
\left(\left(\left(\left(x \cdot x\right) \cdot 5\right) \cdot x\right) \cdot x\right) \cdot \varepsilon
\end{array}
Initial program 87.7%
Taylor expanded in eps around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites84.2%
Taylor expanded in x around 0
Applied rewrites84.3%
Taylor expanded in x around inf
Applied rewrites83.5%
(FPCore (x eps) :precision binary64 (* (* (* x x) (* 10.0 (* eps eps))) eps))
double code(double x, double eps) {
return ((x * x) * (10.0 * (eps * eps))) * eps;
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
code = ((x * x) * (10.0d0 * (eps * eps))) * eps
end function
public static double code(double x, double eps) {
return ((x * x) * (10.0 * (eps * eps))) * eps;
}
def code(x, eps): return ((x * x) * (10.0 * (eps * eps))) * eps
function code(x, eps) return Float64(Float64(Float64(x * x) * Float64(10.0 * Float64(eps * eps))) * eps) end
function tmp = code(x, eps) tmp = ((x * x) * (10.0 * (eps * eps))) * eps; end
code[x_, eps_] := N[(N[(N[(x * x), $MachinePrecision] * N[(10.0 * N[(eps * eps), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * eps), $MachinePrecision]
\begin{array}{l}
\\
\left(\left(x \cdot x\right) \cdot \left(10 \cdot \left(\varepsilon \cdot \varepsilon\right)\right)\right) \cdot \varepsilon
\end{array}
Initial program 87.7%
Taylor expanded in eps around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites84.2%
Taylor expanded in x around 0
Applied rewrites71.1%
Applied rewrites71.1%
herbie shell --seed 2024343
(FPCore (x eps)
:name "ENA, Section 1.4, Exercise 4b, n=5"
:precision binary64
:pre (and (and (<= -1000000000.0 x) (<= x 1000000000.0)) (and (<= -1.0 eps) (<= eps 1.0)))
(- (pow (+ x eps) 5.0) (pow x 5.0)))