| Alternative 1 | |
|---|---|
| Accuracy | 99.3% |
| Cost | 39881 |
(FPCore (x eps) :precision binary64 (- (pow (+ x eps) 5.0) (pow x 5.0)))
(FPCore (x eps)
:precision binary64
(let* ((t_0 (- (pow (+ x eps) 5.0) (pow x 5.0))))
(if (<= t_0 -5e-305)
(+ (pow eps 5.0) (* x (* 5.0 (pow eps 4.0))))
(if (<= t_0 0.0)
(* eps (+ (* eps (* 10.0 (pow x 3.0))) (* 5.0 (pow x 4.0))))
t_0))))double code(double x, double eps) {
return pow((x + eps), 5.0) - pow(x, 5.0);
}
double code(double x, double eps) {
double t_0 = pow((x + eps), 5.0) - pow(x, 5.0);
double tmp;
if (t_0 <= -5e-305) {
tmp = pow(eps, 5.0) + (x * (5.0 * pow(eps, 4.0)));
} else if (t_0 <= 0.0) {
tmp = eps * ((eps * (10.0 * pow(x, 3.0))) + (5.0 * pow(x, 4.0)));
} else {
tmp = t_0;
}
return tmp;
}
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
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
real(8) :: t_0
real(8) :: tmp
t_0 = ((x + eps) ** 5.0d0) - (x ** 5.0d0)
if (t_0 <= (-5d-305)) then
tmp = (eps ** 5.0d0) + (x * (5.0d0 * (eps ** 4.0d0)))
else if (t_0 <= 0.0d0) then
tmp = eps * ((eps * (10.0d0 * (x ** 3.0d0))) + (5.0d0 * (x ** 4.0d0)))
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double eps) {
return Math.pow((x + eps), 5.0) - Math.pow(x, 5.0);
}
public static double code(double x, double eps) {
double t_0 = Math.pow((x + eps), 5.0) - Math.pow(x, 5.0);
double tmp;
if (t_0 <= -5e-305) {
tmp = Math.pow(eps, 5.0) + (x * (5.0 * Math.pow(eps, 4.0)));
} else if (t_0 <= 0.0) {
tmp = eps * ((eps * (10.0 * Math.pow(x, 3.0))) + (5.0 * Math.pow(x, 4.0)));
} else {
tmp = t_0;
}
return tmp;
}
def code(x, eps): return math.pow((x + eps), 5.0) - math.pow(x, 5.0)
def code(x, eps): t_0 = math.pow((x + eps), 5.0) - math.pow(x, 5.0) tmp = 0 if t_0 <= -5e-305: tmp = math.pow(eps, 5.0) + (x * (5.0 * math.pow(eps, 4.0))) elif t_0 <= 0.0: tmp = eps * ((eps * (10.0 * math.pow(x, 3.0))) + (5.0 * math.pow(x, 4.0))) else: tmp = t_0 return tmp
function code(x, eps) return Float64((Float64(x + eps) ^ 5.0) - (x ^ 5.0)) end
function code(x, eps) t_0 = Float64((Float64(x + eps) ^ 5.0) - (x ^ 5.0)) tmp = 0.0 if (t_0 <= -5e-305) tmp = Float64((eps ^ 5.0) + Float64(x * Float64(5.0 * (eps ^ 4.0)))); elseif (t_0 <= 0.0) tmp = Float64(eps * Float64(Float64(eps * Float64(10.0 * (x ^ 3.0))) + Float64(5.0 * (x ^ 4.0)))); else tmp = t_0; end return tmp end
function tmp = code(x, eps) tmp = ((x + eps) ^ 5.0) - (x ^ 5.0); end
function tmp_2 = code(x, eps) t_0 = ((x + eps) ^ 5.0) - (x ^ 5.0); tmp = 0.0; if (t_0 <= -5e-305) tmp = (eps ^ 5.0) + (x * (5.0 * (eps ^ 4.0))); elseif (t_0 <= 0.0) tmp = eps * ((eps * (10.0 * (x ^ 3.0))) + (5.0 * (x ^ 4.0))); else tmp = t_0; end tmp_2 = tmp; end
code[x_, eps_] := N[(N[Power[N[(x + eps), $MachinePrecision], 5.0], $MachinePrecision] - N[Power[x, 5.0], $MachinePrecision]), $MachinePrecision]
code[x_, eps_] := Block[{t$95$0 = N[(N[Power[N[(x + eps), $MachinePrecision], 5.0], $MachinePrecision] - N[Power[x, 5.0], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, -5e-305], N[(N[Power[eps, 5.0], $MachinePrecision] + N[(x * N[(5.0 * N[Power[eps, 4.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$0, 0.0], N[(eps * N[(N[(eps * N[(10.0 * N[Power[x, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(5.0 * N[Power[x, 4.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$0]]]
{\left(x + \varepsilon\right)}^{5} - {x}^{5}
\begin{array}{l}
t_0 := {\left(x + \varepsilon\right)}^{5} - {x}^{5}\\
\mathbf{if}\;t_0 \leq -5 \cdot 10^{-305}:\\
\;\;\;\;{\varepsilon}^{5} + x \cdot \left(5 \cdot {\varepsilon}^{4}\right)\\
\mathbf{elif}\;t_0 \leq 0:\\
\;\;\;\;\varepsilon \cdot \left(\varepsilon \cdot \left(10 \cdot {x}^{3}\right) + 5 \cdot {x}^{4}\right)\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
Results
if (-.f64 (pow.f64 (+.f64 x eps) 5) (pow.f64 x 5)) < -4.99999999999999985e-305Initial program 97.6%
Taylor expanded in x around 0 93.2%
Simplified93.2%
[Start]93.2 | \[ {\varepsilon}^{5} + \left(4 \cdot {\varepsilon}^{4} + {\varepsilon}^{4}\right) \cdot x
\] |
|---|---|
+-commutative [<=]93.2 | \[ {\varepsilon}^{5} + \color{blue}{\left({\varepsilon}^{4} + 4 \cdot {\varepsilon}^{4}\right)} \cdot x
\] |
*-commutative [=>]93.2 | \[ {\varepsilon}^{5} + \color{blue}{x \cdot \left({\varepsilon}^{4} + 4 \cdot {\varepsilon}^{4}\right)}
\] |
distribute-rgt1-in [=>]93.2 | \[ {\varepsilon}^{5} + x \cdot \color{blue}{\left(\left(4 + 1\right) \cdot {\varepsilon}^{4}\right)}
\] |
metadata-eval [=>]93.2 | \[ {\varepsilon}^{5} + x \cdot \left(\color{blue}{5} \cdot {\varepsilon}^{4}\right)
\] |
if -4.99999999999999985e-305 < (-.f64 (pow.f64 (+.f64 x eps) 5) (pow.f64 x 5)) < 0.0Initial program 86.4%
Taylor expanded in eps around 0 99.7%
Simplified99.7%
[Start]99.7 | \[ {\varepsilon}^{2} \cdot \left(4 \cdot {x}^{3} + \left(2 \cdot {x}^{2} + 4 \cdot {x}^{2}\right) \cdot x\right) + \varepsilon \cdot \left(4 \cdot {x}^{4} + {x}^{4}\right)
\] |
|---|---|
fma-def [=>]99.7 | \[ \color{blue}{\mathsf{fma}\left({\varepsilon}^{2}, 4 \cdot {x}^{3} + \left(2 \cdot {x}^{2} + 4 \cdot {x}^{2}\right) \cdot x, \varepsilon \cdot \left(4 \cdot {x}^{4} + {x}^{4}\right)\right)}
\] |
unpow2 [=>]99.7 | \[ \mathsf{fma}\left(\color{blue}{\varepsilon \cdot \varepsilon}, 4 \cdot {x}^{3} + \left(2 \cdot {x}^{2} + 4 \cdot {x}^{2}\right) \cdot x, \varepsilon \cdot \left(4 \cdot {x}^{4} + {x}^{4}\right)\right)
\] |
fma-def [=>]99.7 | \[ \mathsf{fma}\left(\varepsilon \cdot \varepsilon, \color{blue}{\mathsf{fma}\left(4, {x}^{3}, \left(2 \cdot {x}^{2} + 4 \cdot {x}^{2}\right) \cdot x\right)}, \varepsilon \cdot \left(4 \cdot {x}^{4} + {x}^{4}\right)\right)
\] |
*-commutative [=>]99.7 | \[ \mathsf{fma}\left(\varepsilon \cdot \varepsilon, \mathsf{fma}\left(4, {x}^{3}, \color{blue}{x \cdot \left(2 \cdot {x}^{2} + 4 \cdot {x}^{2}\right)}\right), \varepsilon \cdot \left(4 \cdot {x}^{4} + {x}^{4}\right)\right)
\] |
distribute-rgt-out [=>]99.7 | \[ \mathsf{fma}\left(\varepsilon \cdot \varepsilon, \mathsf{fma}\left(4, {x}^{3}, x \cdot \color{blue}{\left({x}^{2} \cdot \left(2 + 4\right)\right)}\right), \varepsilon \cdot \left(4 \cdot {x}^{4} + {x}^{4}\right)\right)
\] |
unpow2 [=>]99.7 | \[ \mathsf{fma}\left(\varepsilon \cdot \varepsilon, \mathsf{fma}\left(4, {x}^{3}, x \cdot \left(\color{blue}{\left(x \cdot x\right)} \cdot \left(2 + 4\right)\right)\right), \varepsilon \cdot \left(4 \cdot {x}^{4} + {x}^{4}\right)\right)
\] |
metadata-eval [=>]99.7 | \[ \mathsf{fma}\left(\varepsilon \cdot \varepsilon, \mathsf{fma}\left(4, {x}^{3}, x \cdot \left(\left(x \cdot x\right) \cdot \color{blue}{6}\right)\right), \varepsilon \cdot \left(4 \cdot {x}^{4} + {x}^{4}\right)\right)
\] |
distribute-lft1-in [=>]99.7 | \[ \mathsf{fma}\left(\varepsilon \cdot \varepsilon, \mathsf{fma}\left(4, {x}^{3}, x \cdot \left(\left(x \cdot x\right) \cdot 6\right)\right), \varepsilon \cdot \color{blue}{\left(\left(4 + 1\right) \cdot {x}^{4}\right)}\right)
\] |
metadata-eval [=>]99.7 | \[ \mathsf{fma}\left(\varepsilon \cdot \varepsilon, \mathsf{fma}\left(4, {x}^{3}, x \cdot \left(\left(x \cdot x\right) \cdot 6\right)\right), \varepsilon \cdot \left(\color{blue}{5} \cdot {x}^{4}\right)\right)
\] |
Applied egg-rr99.7%
[Start]99.7 | \[ \mathsf{fma}\left(\varepsilon \cdot \varepsilon, \mathsf{fma}\left(4, {x}^{3}, x \cdot \left(\left(x \cdot x\right) \cdot 6\right)\right), \varepsilon \cdot \left(5 \cdot {x}^{4}\right)\right)
\] |
|---|---|
fma-udef [=>]99.7 | \[ \mathsf{fma}\left(\varepsilon \cdot \varepsilon, \color{blue}{4 \cdot {x}^{3} + x \cdot \left(\left(x \cdot x\right) \cdot 6\right)}, \varepsilon \cdot \left(5 \cdot {x}^{4}\right)\right)
\] |
+-commutative [=>]99.7 | \[ \mathsf{fma}\left(\varepsilon \cdot \varepsilon, \color{blue}{x \cdot \left(\left(x \cdot x\right) \cdot 6\right) + 4 \cdot {x}^{3}}, \varepsilon \cdot \left(5 \cdot {x}^{4}\right)\right)
\] |
*-commutative [=>]99.7 | \[ \mathsf{fma}\left(\varepsilon \cdot \varepsilon, x \cdot \color{blue}{\left(6 \cdot \left(x \cdot x\right)\right)} + 4 \cdot {x}^{3}, \varepsilon \cdot \left(5 \cdot {x}^{4}\right)\right)
\] |
associate-*r* [=>]99.7 | \[ \mathsf{fma}\left(\varepsilon \cdot \varepsilon, \color{blue}{\left(x \cdot 6\right) \cdot \left(x \cdot x\right)} + 4 \cdot {x}^{3}, \varepsilon \cdot \left(5 \cdot {x}^{4}\right)\right)
\] |
cube-mult [=>]99.7 | \[ \mathsf{fma}\left(\varepsilon \cdot \varepsilon, \left(x \cdot 6\right) \cdot \left(x \cdot x\right) + 4 \cdot \color{blue}{\left(x \cdot \left(x \cdot x\right)\right)}, \varepsilon \cdot \left(5 \cdot {x}^{4}\right)\right)
\] |
associate-*r* [=>]99.7 | \[ \mathsf{fma}\left(\varepsilon \cdot \varepsilon, \left(x \cdot 6\right) \cdot \left(x \cdot x\right) + \color{blue}{\left(4 \cdot x\right) \cdot \left(x \cdot x\right)}, \varepsilon \cdot \left(5 \cdot {x}^{4}\right)\right)
\] |
distribute-rgt-out [=>]99.7 | \[ \mathsf{fma}\left(\varepsilon \cdot \varepsilon, \color{blue}{\left(x \cdot x\right) \cdot \left(x \cdot 6 + 4 \cdot x\right)}, \varepsilon \cdot \left(5 \cdot {x}^{4}\right)\right)
\] |
Applied egg-rr99.7%
[Start]99.7 | \[ \mathsf{fma}\left(\varepsilon \cdot \varepsilon, \left(x \cdot x\right) \cdot \left(x \cdot 6 + 4 \cdot x\right), \varepsilon \cdot \left(5 \cdot {x}^{4}\right)\right)
\] |
|---|---|
*-commutative [=>]99.7 | \[ \mathsf{fma}\left(\varepsilon \cdot \varepsilon, \left(x \cdot x\right) \cdot \left(x \cdot 6 + \color{blue}{x \cdot 4}\right), \varepsilon \cdot \left(5 \cdot {x}^{4}\right)\right)
\] |
distribute-lft-out [=>]99.7 | \[ \mathsf{fma}\left(\varepsilon \cdot \varepsilon, \left(x \cdot x\right) \cdot \color{blue}{\left(x \cdot \left(6 + 4\right)\right)}, \varepsilon \cdot \left(5 \cdot {x}^{4}\right)\right)
\] |
metadata-eval [=>]99.7 | \[ \mathsf{fma}\left(\varepsilon \cdot \varepsilon, \left(x \cdot x\right) \cdot \left(x \cdot \color{blue}{10}\right), \varepsilon \cdot \left(5 \cdot {x}^{4}\right)\right)
\] |
Applied egg-rr99.7%
[Start]99.7 | \[ \mathsf{fma}\left(\varepsilon \cdot \varepsilon, \left(x \cdot x\right) \cdot \left(x \cdot 10\right), \varepsilon \cdot \left(5 \cdot {x}^{4}\right)\right)
\] |
|---|---|
fma-udef [=>]99.7 | \[ \color{blue}{\left(\varepsilon \cdot \varepsilon\right) \cdot \left(\left(x \cdot x\right) \cdot \left(x \cdot 10\right)\right) + \varepsilon \cdot \left(5 \cdot {x}^{4}\right)}
\] |
associate-*l* [=>]99.7 | \[ \color{blue}{\varepsilon \cdot \left(\varepsilon \cdot \left(\left(x \cdot x\right) \cdot \left(x \cdot 10\right)\right)\right)} + \varepsilon \cdot \left(5 \cdot {x}^{4}\right)
\] |
distribute-lft-out [=>]99.7 | \[ \color{blue}{\varepsilon \cdot \left(\varepsilon \cdot \left(\left(x \cdot x\right) \cdot \left(x \cdot 10\right)\right) + 5 \cdot {x}^{4}\right)}
\] |
associate-*r* [=>]99.7 | \[ \varepsilon \cdot \left(\varepsilon \cdot \color{blue}{\left(\left(\left(x \cdot x\right) \cdot x\right) \cdot 10\right)} + 5 \cdot {x}^{4}\right)
\] |
*-commutative [=>]99.7 | \[ \varepsilon \cdot \left(\varepsilon \cdot \color{blue}{\left(10 \cdot \left(\left(x \cdot x\right) \cdot x\right)\right)} + 5 \cdot {x}^{4}\right)
\] |
pow3 [=>]99.7 | \[ \varepsilon \cdot \left(\varepsilon \cdot \left(10 \cdot \color{blue}{{x}^{3}}\right) + 5 \cdot {x}^{4}\right)
\] |
if 0.0 < (-.f64 (pow.f64 (+.f64 x eps) 5) (pow.f64 x 5)) Initial program 97.7%
Final simplification98.9%
| Alternative 1 | |
|---|---|
| Accuracy | 99.3% |
| Cost | 39881 |
| Alternative 2 | |
|---|---|
| Accuracy | 98.9% |
| Cost | 39880 |
| Alternative 3 | |
|---|---|
| Accuracy | 97.7% |
| Cost | 7684 |
| Alternative 4 | |
|---|---|
| Accuracy | 97.6% |
| Cost | 6793 |
| Alternative 5 | |
|---|---|
| Accuracy | 83.1% |
| Cost | 1216 |
| Alternative 6 | |
|---|---|
| Accuracy | 82.8% |
| Cost | 704 |
| Alternative 7 | |
|---|---|
| Accuracy | 82.8% |
| Cost | 704 |
| Alternative 8 | |
|---|---|
| Accuracy | 82.8% |
| Cost | 704 |
herbie shell --seed 2023138
(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)))