| Alternative 1 | |
|---|---|
| Error | 0.3 |
| Cost | 13252 |
\[\begin{array}{l}
\mathbf{if}\;x \leq 29500000:\\
\;\;\;\;\sqrt{1 + x} - \sqrt{x}\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot {x}^{-0.5}\\
\end{array}
\]
(FPCore (x) :precision binary64 (- (sqrt (+ x 1.0)) (sqrt x)))
(FPCore (x) :precision binary64 (/ 1.0 (fma (pow x 0.25) (pow x 0.25) (sqrt (+ 1.0 x)))))
double code(double x) {
return sqrt((x + 1.0)) - sqrt(x);
}
double code(double x) {
return 1.0 / fma(pow(x, 0.25), pow(x, 0.25), sqrt((1.0 + x)));
}
function code(x) return Float64(sqrt(Float64(x + 1.0)) - sqrt(x)) end
function code(x) return Float64(1.0 / fma((x ^ 0.25), (x ^ 0.25), sqrt(Float64(1.0 + x)))) end
code[x_] := N[(N[Sqrt[N[(x + 1.0), $MachinePrecision]], $MachinePrecision] - N[Sqrt[x], $MachinePrecision]), $MachinePrecision]
code[x_] := N[(1.0 / N[(N[Power[x, 0.25], $MachinePrecision] * N[Power[x, 0.25], $MachinePrecision] + N[Sqrt[N[(1.0 + x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\sqrt{x + 1} - \sqrt{x}
\frac{1}{\mathsf{fma}\left({x}^{0.25}, {x}^{0.25}, \sqrt{1 + x}\right)}
| Original | 29.6 |
|---|---|
| Target | 0.2 |
| Herbie | 0.2 |
Initial program 29.6
Applied egg-rr29.0
Simplified0.2
[Start]29.0 | \[ \left(x + \left(1 - x\right)\right) \cdot \frac{1}{\sqrt{x + 1} + \sqrt{x}}
\] |
|---|---|
*-commutative [=>]29.0 | \[ \color{blue}{\frac{1}{\sqrt{x + 1} + \sqrt{x}} \cdot \left(x + \left(1 - x\right)\right)}
\] |
associate-*l/ [=>]29.0 | \[ \color{blue}{\frac{1 \cdot \left(x + \left(1 - x\right)\right)}{\sqrt{x + 1} + \sqrt{x}}}
\] |
*-lft-identity [=>]29.0 | \[ \frac{\color{blue}{x + \left(1 - x\right)}}{\sqrt{x + 1} + \sqrt{x}}
\] |
+-commutative [=>]29.0 | \[ \frac{\color{blue}{\left(1 - x\right) + x}}{\sqrt{x + 1} + \sqrt{x}}
\] |
associate-+l- [=>]0.2 | \[ \frac{\color{blue}{1 - \left(x - x\right)}}{\sqrt{x + 1} + \sqrt{x}}
\] |
+-inverses [=>]0.2 | \[ \frac{1 - \color{blue}{0}}{\sqrt{x + 1} + \sqrt{x}}
\] |
metadata-eval [=>]0.2 | \[ \frac{\color{blue}{1}}{\sqrt{x + 1} + \sqrt{x}}
\] |
+-commutative [=>]0.2 | \[ \frac{1}{\sqrt{\color{blue}{1 + x}} + \sqrt{x}}
\] |
Applied egg-rr0.2
Final simplification0.2
| Alternative 1 | |
|---|---|
| Error | 0.3 |
| Cost | 13252 |
| Alternative 2 | |
|---|---|
| Error | 0.2 |
| Cost | 13248 |
| Alternative 3 | |
|---|---|
| Error | 1.0 |
| Cost | 7108 |
| Alternative 4 | |
|---|---|
| Error | 1.3 |
| Cost | 6852 |
| Alternative 5 | |
|---|---|
| Error | 2.1 |
| Cost | 6788 |
| Alternative 6 | |
|---|---|
| Error | 31.0 |
| Cost | 448 |
| Alternative 7 | |
|---|---|
| Error | 31.0 |
| Cost | 64 |
herbie shell --seed 2023034
(FPCore (x)
:name "2sqrt (example 3.1)"
:precision binary64
:herbie-target
(/ 1.0 (+ (sqrt (+ x 1.0)) (sqrt x)))
(- (sqrt (+ x 1.0)) (sqrt x)))