| Alternative 1 | |
|---|---|
| Accuracy | 90.4% |
| Cost | 73288 |

(FPCore (x n) :precision binary64 (- (pow (+ x 1.0) (/ 1.0 n)) (pow x (/ 1.0 n))))
(FPCore (x n)
:precision binary64
(let* ((t_0 (pow x (/ 1.0 n))) (t_1 (- (pow (+ x 1.0) (/ 1.0 n)) t_0)))
(if (<= t_1 (- INFINITY))
(- 1.0 t_0)
(if (<= t_1 0.0)
(+
(fma 0.5 (/ (pow (log1p x) 2.0) (* n n)) (/ (- (log1p x) (log x)) n))
(* (/ (pow (log x) 2.0) (* n n)) -0.5))
(if (<= t_1 INFINITY) (- (exp (/ x n)) t_0) (/ t_0 (* x n)))))))double code(double x, double n) {
return pow((x + 1.0), (1.0 / n)) - pow(x, (1.0 / n));
}
double code(double x, double n) {
double t_0 = pow(x, (1.0 / n));
double t_1 = pow((x + 1.0), (1.0 / n)) - t_0;
double tmp;
if (t_1 <= -((double) INFINITY)) {
tmp = 1.0 - t_0;
} else if (t_1 <= 0.0) {
tmp = fma(0.5, (pow(log1p(x), 2.0) / (n * n)), ((log1p(x) - log(x)) / n)) + ((pow(log(x), 2.0) / (n * n)) * -0.5);
} else if (t_1 <= ((double) INFINITY)) {
tmp = exp((x / n)) - t_0;
} else {
tmp = t_0 / (x * n);
}
return tmp;
}
function code(x, n) return Float64((Float64(x + 1.0) ^ Float64(1.0 / n)) - (x ^ Float64(1.0 / n))) end
function code(x, n) t_0 = x ^ Float64(1.0 / n) t_1 = Float64((Float64(x + 1.0) ^ Float64(1.0 / n)) - t_0) tmp = 0.0 if (t_1 <= Float64(-Inf)) tmp = Float64(1.0 - t_0); elseif (t_1 <= 0.0) tmp = Float64(fma(0.5, Float64((log1p(x) ^ 2.0) / Float64(n * n)), Float64(Float64(log1p(x) - log(x)) / n)) + Float64(Float64((log(x) ^ 2.0) / Float64(n * n)) * -0.5)); elseif (t_1 <= Inf) tmp = Float64(exp(Float64(x / n)) - t_0); else tmp = Float64(t_0 / Float64(x * n)); end return tmp end
code[x_, n_] := N[(N[Power[N[(x + 1.0), $MachinePrecision], N[(1.0 / n), $MachinePrecision]], $MachinePrecision] - N[Power[x, N[(1.0 / n), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
code[x_, n_] := Block[{t$95$0 = N[Power[x, N[(1.0 / n), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[(N[Power[N[(x + 1.0), $MachinePrecision], N[(1.0 / n), $MachinePrecision]], $MachinePrecision] - t$95$0), $MachinePrecision]}, If[LessEqual[t$95$1, (-Infinity)], N[(1.0 - t$95$0), $MachinePrecision], If[LessEqual[t$95$1, 0.0], N[(N[(0.5 * N[(N[Power[N[Log[1 + x], $MachinePrecision], 2.0], $MachinePrecision] / N[(n * n), $MachinePrecision]), $MachinePrecision] + N[(N[(N[Log[1 + x], $MachinePrecision] - N[Log[x], $MachinePrecision]), $MachinePrecision] / n), $MachinePrecision]), $MachinePrecision] + N[(N[(N[Power[N[Log[x], $MachinePrecision], 2.0], $MachinePrecision] / N[(n * n), $MachinePrecision]), $MachinePrecision] * -0.5), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$1, Infinity], N[(N[Exp[N[(x / n), $MachinePrecision]], $MachinePrecision] - t$95$0), $MachinePrecision], N[(t$95$0 / N[(x * n), $MachinePrecision]), $MachinePrecision]]]]]]
{\left(x + 1\right)}^{\left(\frac{1}{n}\right)} - {x}^{\left(\frac{1}{n}\right)}
\begin{array}{l}
t_0 := {x}^{\left(\frac{1}{n}\right)}\\
t_1 := {\left(x + 1\right)}^{\left(\frac{1}{n}\right)} - t_0\\
\mathbf{if}\;t_1 \leq -\infty:\\
\;\;\;\;1 - t_0\\
\mathbf{elif}\;t_1 \leq 0:\\
\;\;\;\;\mathsf{fma}\left(0.5, \frac{{\left(\mathsf{log1p}\left(x\right)\right)}^{2}}{n \cdot n}, \frac{\mathsf{log1p}\left(x\right) - \log x}{n}\right) + \frac{{\log x}^{2}}{n \cdot n} \cdot -0.5\\
\mathbf{elif}\;t_1 \leq \infty:\\
\;\;\;\;e^{\frac{x}{n}} - t_0\\
\mathbf{else}:\\
\;\;\;\;\frac{t_0}{x \cdot n}\\
\end{array}
Herbie found 16 alternatives:
| Alternative | Accuracy | Speedup |
|---|
if (-.f64 (pow.f64 (+.f64 x 1) (/.f64 1 n)) (pow.f64 x (/.f64 1 n))) < -inf.0Initial program 100.0%
Taylor expanded in x around 0 100.0%
Simplified100.0%
[Start]100.0% | \[ 1 - e^{\frac{\log x}{n}}
\] |
|---|---|
*-rgt-identity [<=]100.0% | \[ 1 - e^{\frac{\color{blue}{\log x \cdot 1}}{n}}
\] |
associate-*r/ [<=]100.0% | \[ 1 - e^{\color{blue}{\log x \cdot \frac{1}{n}}}
\] |
unpow-1 [<=]100.0% | \[ 1 - e^{\log x \cdot \color{blue}{{n}^{-1}}}
\] |
exp-to-pow [=>]100.0% | \[ 1 - \color{blue}{{x}^{\left({n}^{-1}\right)}}
\] |
unpow-1 [=>]100.0% | \[ 1 - {x}^{\color{blue}{\left(\frac{1}{n}\right)}}
\] |
if -inf.0 < (-.f64 (pow.f64 (+.f64 x 1) (/.f64 1 n)) (pow.f64 x (/.f64 1 n))) < 0.0Initial program 28.3%
Taylor expanded in n around inf 82.4%
Simplified82.4%
[Start]82.4% | \[ \left(0.5 \cdot \frac{{\log \left(1 + x\right)}^{2}}{{n}^{2}} + \frac{\log \left(1 + x\right)}{n}\right) - \left(\frac{\log x}{n} + 0.5 \cdot \frac{{\log x}^{2}}{{n}^{2}}\right)
\] |
|---|---|
associate--r+ [=>]74.5% | \[ \color{blue}{\left(\left(0.5 \cdot \frac{{\log \left(1 + x\right)}^{2}}{{n}^{2}} + \frac{\log \left(1 + x\right)}{n}\right) - \frac{\log x}{n}\right) - 0.5 \cdot \frac{{\log x}^{2}}{{n}^{2}}}
\] |
sub-neg [=>]74.5% | \[ \color{blue}{\left(\left(0.5 \cdot \frac{{\log \left(1 + x\right)}^{2}}{{n}^{2}} + \frac{\log \left(1 + x\right)}{n}\right) - \frac{\log x}{n}\right) + \left(-0.5 \cdot \frac{{\log x}^{2}}{{n}^{2}}\right)}
\] |
if 0.0 < (-.f64 (pow.f64 (+.f64 x 1) (/.f64 1 n)) (pow.f64 x (/.f64 1 n))) < +inf.0Initial program 56.1%
Taylor expanded in n around 0 56.1%
Simplified99.9%
[Start]56.1% | \[ e^{\frac{\log \left(1 + x\right)}{n}} - e^{\frac{\log x}{n}}
\] |
|---|---|
log1p-def [=>]99.9% | \[ e^{\frac{\color{blue}{\mathsf{log1p}\left(x\right)}}{n}} - e^{\frac{\log x}{n}}
\] |
*-rgt-identity [<=]99.9% | \[ e^{\frac{\mathsf{log1p}\left(x\right)}{n}} - e^{\frac{\color{blue}{\log x \cdot 1}}{n}}
\] |
associate-*r/ [<=]99.9% | \[ e^{\frac{\mathsf{log1p}\left(x\right)}{n}} - e^{\color{blue}{\log x \cdot \frac{1}{n}}}
\] |
unpow-1 [<=]99.9% | \[ e^{\frac{\mathsf{log1p}\left(x\right)}{n}} - e^{\log x \cdot \color{blue}{{n}^{-1}}}
\] |
exp-to-pow [=>]99.9% | \[ e^{\frac{\mathsf{log1p}\left(x\right)}{n}} - \color{blue}{{x}^{\left({n}^{-1}\right)}}
\] |
/-rgt-identity [<=]99.9% | \[ e^{\frac{\mathsf{log1p}\left(x\right)}{n}} - {x}^{\color{blue}{\left(\frac{{n}^{-1}}{1}\right)}}
\] |
metadata-eval [<=]99.9% | \[ e^{\frac{\mathsf{log1p}\left(x\right)}{n}} - {x}^{\left(\frac{{n}^{-1}}{\color{blue}{\frac{2}{2}}}\right)}
\] |
associate-/l* [<=]99.9% | \[ e^{\frac{\mathsf{log1p}\left(x\right)}{n}} - {x}^{\color{blue}{\left(\frac{{n}^{-1} \cdot 2}{2}\right)}}
\] |
*-commutative [<=]99.9% | \[ e^{\frac{\mathsf{log1p}\left(x\right)}{n}} - {x}^{\left(\frac{\color{blue}{2 \cdot {n}^{-1}}}{2}\right)}
\] |
*-commutative [=>]99.9% | \[ e^{\frac{\mathsf{log1p}\left(x\right)}{n}} - {x}^{\left(\frac{\color{blue}{{n}^{-1} \cdot 2}}{2}\right)}
\] |
associate-/l* [=>]99.9% | \[ e^{\frac{\mathsf{log1p}\left(x\right)}{n}} - {x}^{\color{blue}{\left(\frac{{n}^{-1}}{\frac{2}{2}}\right)}}
\] |
metadata-eval [=>]99.9% | \[ e^{\frac{\mathsf{log1p}\left(x\right)}{n}} - {x}^{\left(\frac{{n}^{-1}}{\color{blue}{1}}\right)}
\] |
/-rgt-identity [=>]99.9% | \[ e^{\frac{\mathsf{log1p}\left(x\right)}{n}} - {x}^{\color{blue}{\left({n}^{-1}\right)}}
\] |
unpow-1 [=>]99.9% | \[ e^{\frac{\mathsf{log1p}\left(x\right)}{n}} - {x}^{\color{blue}{\left(\frac{1}{n}\right)}}
\] |
Taylor expanded in x around 0 99.9%
if +inf.0 < (-.f64 (pow.f64 (+.f64 x 1) (/.f64 1 n)) (pow.f64 x (/.f64 1 n))) Initial program 0.0%
Taylor expanded in x around inf 100.0%
Simplified100.0%
[Start]100.0% | \[ \frac{e^{-1 \cdot \frac{\log \left(\frac{1}{x}\right)}{n}}}{n \cdot x}
\] |
|---|---|
log-rec [=>]100.0% | \[ \frac{e^{-1 \cdot \frac{\color{blue}{-\log x}}{n}}}{n \cdot x}
\] |
mul-1-neg [<=]100.0% | \[ \frac{e^{-1 \cdot \frac{\color{blue}{-1 \cdot \log x}}{n}}}{n \cdot x}
\] |
mul-1-neg [=>]100.0% | \[ \frac{e^{-1 \cdot \frac{\color{blue}{-\log x}}{n}}}{n \cdot x}
\] |
distribute-frac-neg [=>]100.0% | \[ \frac{e^{-1 \cdot \color{blue}{\left(-\frac{\log x}{n}\right)}}}{n \cdot x}
\] |
neg-mul-1 [<=]100.0% | \[ \frac{e^{\color{blue}{-\left(-\frac{\log x}{n}\right)}}}{n \cdot x}
\] |
remove-double-neg [=>]100.0% | \[ \frac{e^{\color{blue}{\frac{\log x}{n}}}}{n \cdot x}
\] |
*-rgt-identity [<=]100.0% | \[ \frac{e^{\frac{\color{blue}{\log x \cdot 1}}{n}}}{n \cdot x}
\] |
associate-*r/ [<=]100.0% | \[ \frac{e^{\color{blue}{\log x \cdot \frac{1}{n}}}}{n \cdot x}
\] |
unpow-1 [<=]100.0% | \[ \frac{e^{\log x \cdot \color{blue}{{n}^{-1}}}}{n \cdot x}
\] |
exp-to-pow [=>]100.0% | \[ \frac{\color{blue}{{x}^{\left({n}^{-1}\right)}}}{n \cdot x}
\] |
unpow-1 [=>]100.0% | \[ \frac{{x}^{\color{blue}{\left(\frac{1}{n}\right)}}}{n \cdot x}
\] |
*-commutative [=>]100.0% | \[ \frac{{x}^{\left(\frac{1}{n}\right)}}{\color{blue}{x \cdot n}}
\] |
Final simplification90.7%
| Alternative 1 | |
|---|---|
| Accuracy | 90.4% |
| Cost | 73288 |
| Alternative 2 | |
|---|---|
| Accuracy | 90.3% |
| Cost | 54028 |
| Alternative 3 | |
|---|---|
| Accuracy | 77.5% |
| Cost | 8528 |
| Alternative 4 | |
|---|---|
| Accuracy | 78.4% |
| Cost | 7820 |
| Alternative 5 | |
|---|---|
| Accuracy | 78.4% |
| Cost | 7820 |
| Alternative 6 | |
|---|---|
| Accuracy | 58.8% |
| Cost | 7696 |
| Alternative 7 | |
|---|---|
| Accuracy | 78.4% |
| Cost | 7692 |
| Alternative 8 | |
|---|---|
| Accuracy | 75.9% |
| Cost | 7368 |
| Alternative 9 | |
|---|---|
| Accuracy | 67.3% |
| Cost | 7048 |
| Alternative 10 | |
|---|---|
| Accuracy | 67.3% |
| Cost | 7048 |
| Alternative 11 | |
|---|---|
| Accuracy | 59.3% |
| Cost | 6852 |
| Alternative 12 | |
|---|---|
| Accuracy | 45.2% |
| Cost | 1348 |
| Alternative 13 | |
|---|---|
| Accuracy | 44.8% |
| Cost | 836 |
| Alternative 14 | |
|---|---|
| Accuracy | 35.4% |
| Cost | 585 |
| Alternative 15 | |
|---|---|
| Accuracy | 20.1% |
| Cost | 324 |
| Alternative 16 | |
|---|---|
| Accuracy | 11.4% |
| Cost | 64 |
herbie shell --seed 2023272
(FPCore (x n)
:name "2nthrt (problem 3.4.6)"
:precision binary64
(- (pow (+ x 1.0) (/ 1.0 n)) (pow x (/ 1.0 n))))