Average Error: 19.5 → 19.3
Time: 33.7s
Precision: 64
Internal Precision: 1152
\[\frac{1}{\sqrt{x}} - \frac{1}{\sqrt{x + 1}}\]
↓
\[\begin{array}{l}
\mathbf{if}\;\frac{{x}^{\left(-\frac{1}{2}\right)} \cdot {x}^{\left(-\frac{1}{2}\right)} - \frac{1}{x + 1}}{{x}^{\left(-\frac{1}{2}\right)} + \frac{1}{\sqrt{x + 1}}} \le 4.381860511644953 \cdot 10^{-78}:\\
\;\;\;\;\left(\sqrt{\frac{1}{\sqrt{x}}} + \sqrt{\frac{1}{\sqrt{x + 1}}}\right) \cdot e^{\log \left(\sqrt{\frac{1}{\sqrt{x}}} - \sqrt{\frac{1}{\sqrt{x + 1}}}\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{{x}^{\left(-\frac{1}{2}\right)} \cdot {x}^{\left(-\frac{1}{2}\right)} - \frac{1}{x + 1}}{{x}^{\left(-\frac{1}{2}\right)} + \frac{1}{\sqrt{x + 1}}}\\
\end{array}\]
Target
| Original | 19.5 |
|---|
| Target | 0.7 |
|---|
| Herbie | 19.3 |
|---|
\[\frac{1}{\left(x + 1\right) \cdot \sqrt{x} + x \cdot \sqrt{x + 1}}\]
Derivation
- Split input into 2 regimes
if (/ (- (* (pow x (- 1/2)) (pow x (- 1/2))) (/ 1 (+ x 1))) (+ (pow x (- 1/2)) (/ 1 (sqrt (+ x 1))))) < 4.381860511644953e-78
Initial program 37.5
\[\frac{1}{\sqrt{x}} - \frac{1}{\sqrt{x + 1}}\]
- Using strategy
rm Applied add-sqr-sqrt49.2
\[\leadsto \frac{1}{\sqrt{x}} - \color{blue}{\sqrt{\frac{1}{\sqrt{x + 1}}} \cdot \sqrt{\frac{1}{\sqrt{x + 1}}}}\]
Applied add-sqr-sqrt37.5
\[\leadsto \color{blue}{\sqrt{\frac{1}{\sqrt{x}}} \cdot \sqrt{\frac{1}{\sqrt{x}}}} - \sqrt{\frac{1}{\sqrt{x + 1}}} \cdot \sqrt{\frac{1}{\sqrt{x + 1}}}\]
Applied difference-of-squares37.5
\[\leadsto \color{blue}{\left(\sqrt{\frac{1}{\sqrt{x}}} + \sqrt{\frac{1}{\sqrt{x + 1}}}\right) \cdot \left(\sqrt{\frac{1}{\sqrt{x}}} - \sqrt{\frac{1}{\sqrt{x + 1}}}\right)}\]
- Using strategy
rm Applied add-exp-log37.5
\[\leadsto \left(\sqrt{\frac{1}{\sqrt{x}}} + \sqrt{\frac{1}{\sqrt{x + 1}}}\right) \cdot \color{blue}{e^{\log \left(\sqrt{\frac{1}{\sqrt{x}}} - \sqrt{\frac{1}{\sqrt{x + 1}}}\right)}}\]
if 4.381860511644953e-78 < (/ (- (* (pow x (- 1/2)) (pow x (- 1/2))) (/ 1 (+ x 1))) (+ (pow x (- 1/2)) (/ 1 (sqrt (+ x 1)))))
Initial program 6.2
\[\frac{1}{\sqrt{x}} - \frac{1}{\sqrt{x + 1}}\]
- Using strategy
rm Applied pow1/26.2
\[\leadsto \frac{1}{\color{blue}{{x}^{\frac{1}{2}}}} - \frac{1}{\sqrt{x + 1}}\]
Applied pow-flip5.9
\[\leadsto \color{blue}{{x}^{\left(-\frac{1}{2}\right)}} - \frac{1}{\sqrt{x + 1}}\]
- Using strategy
rm Applied flip--6.0
\[\leadsto \color{blue}{\frac{{x}^{\left(-\frac{1}{2}\right)} \cdot {x}^{\left(-\frac{1}{2}\right)} - \frac{1}{\sqrt{x + 1}} \cdot \frac{1}{\sqrt{x + 1}}}{{x}^{\left(-\frac{1}{2}\right)} + \frac{1}{\sqrt{x + 1}}}}\]
Applied simplify5.8
\[\leadsto \frac{\color{blue}{{x}^{\left(-\frac{1}{2}\right)} \cdot {x}^{\left(-\frac{1}{2}\right)} - \frac{1}{x + 1}}}{{x}^{\left(-\frac{1}{2}\right)} + \frac{1}{\sqrt{x + 1}}}\]
- Recombined 2 regimes into one program.
Runtime
herbie shell --seed '#(1070131407 1246090267 3027482374 2150728003 2026520792 2347815650)'
(FPCore (x)
:name "2isqrt (example 3.6)"
:herbie-target
(/ 1 (+ (* (+ x 1) (sqrt x)) (* x (sqrt (+ x 1)))))
(- (/ 1 (sqrt x)) (/ 1 (sqrt (+ x 1)))))