Average Error: 19.2 → 18.9
Time: 30.7s
Precision: 64
Internal Precision: 1088
\[\frac{1}{\sqrt{x}} - \frac{1}{\sqrt{x + 1}}\]
↓
\[\begin{array}{l}
\mathbf{if}\;\frac{(\left({x}^{\left(-\frac{1}{2}\right)}\right) \cdot \left({x}^{\left(-\frac{1}{2}\right)}\right) + \left(\frac{-1}{x + 1}\right))_*}{{x}^{\left(-\frac{1}{2}\right)} + \frac{1}{\sqrt{x + 1}}} \le 6.746107001627108 \cdot 10^{-82}:\\
\;\;\;\;\frac{\frac{\frac{1}{x}}{\sqrt{x}} - \frac{\frac{1}{x + 1}}{\sqrt{x + 1}}}{\frac{\frac{1}{\sqrt{x}}}{\sqrt{x + 1}} + \left(\frac{1}{x} + \frac{1}{x + 1}\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{(\left({x}^{\left(-\frac{1}{2}\right)}\right) \cdot \left({x}^{\left(-\frac{1}{2}\right)}\right) + \left(\frac{-1}{x + 1}\right))_*}{{x}^{\left(-\frac{1}{2}\right)} + \frac{1}{\sqrt{x + 1}}}\\
\end{array}\]
Target
| Original | 19.2 |
|---|
| Target | 0.6 |
|---|
| Herbie | 18.9 |
|---|
\[\frac{1}{\left(x + 1\right) \cdot \sqrt{x} + x \cdot \sqrt{x + 1}}\]
Derivation
- Split input into 2 regimes
if (/ (fma (pow x (- 1/2)) (pow x (- 1/2)) (/ (- 1) (+ x 1))) (+ (pow x (- 1/2)) (/ 1 (sqrt (+ x 1))))) < 6.746107001627108e-82
Initial program 34.8
\[\frac{1}{\sqrt{x}} - \frac{1}{\sqrt{x + 1}}\]
- Using strategy
rm Applied add-sqr-sqrt48.3
\[\leadsto \frac{1}{\sqrt{x}} - \color{blue}{\sqrt{\frac{1}{\sqrt{x + 1}}} \cdot \sqrt{\frac{1}{\sqrt{x + 1}}}}\]
- Using strategy
rm Applied flip3--35.1
\[\leadsto \color{blue}{\frac{{\left(\frac{1}{\sqrt{x}}\right)}^{3} - {\left(\sqrt{\frac{1}{\sqrt{x + 1}}} \cdot \sqrt{\frac{1}{\sqrt{x + 1}}}\right)}^{3}}{\frac{1}{\sqrt{x}} \cdot \frac{1}{\sqrt{x}} + \left(\left(\sqrt{\frac{1}{\sqrt{x + 1}}} \cdot \sqrt{\frac{1}{\sqrt{x + 1}}}\right) \cdot \left(\sqrt{\frac{1}{\sqrt{x + 1}}} \cdot \sqrt{\frac{1}{\sqrt{x + 1}}}\right) + \frac{1}{\sqrt{x}} \cdot \left(\sqrt{\frac{1}{\sqrt{x + 1}}} \cdot \sqrt{\frac{1}{\sqrt{x + 1}}}\right)\right)}}\]
Applied simplify34.8
\[\leadsto \frac{\color{blue}{\frac{\frac{1}{x}}{\sqrt{x}} - \frac{\frac{1}{x + 1}}{\sqrt{x + 1}}}}{\frac{1}{\sqrt{x}} \cdot \frac{1}{\sqrt{x}} + \left(\left(\sqrt{\frac{1}{\sqrt{x + 1}}} \cdot \sqrt{\frac{1}{\sqrt{x + 1}}}\right) \cdot \left(\sqrt{\frac{1}{\sqrt{x + 1}}} \cdot \sqrt{\frac{1}{\sqrt{x + 1}}}\right) + \frac{1}{\sqrt{x}} \cdot \left(\sqrt{\frac{1}{\sqrt{x + 1}}} \cdot \sqrt{\frac{1}{\sqrt{x + 1}}}\right)\right)}\]
Applied simplify34.8
\[\leadsto \frac{\frac{\frac{1}{x}}{\sqrt{x}} - \frac{\frac{1}{x + 1}}{\sqrt{x + 1}}}{\color{blue}{\frac{\frac{1}{\sqrt{x}}}{\sqrt{x + 1}} + \left(\frac{1}{x} + \frac{1}{x + 1}\right)}}\]
if 6.746107001627108e-82 < (/ (fma (pow x (- 1/2)) (pow x (- 1/2)) (/ (- 1) (+ x 1))) (+ (pow x (- 1/2)) (/ 1 (sqrt (+ x 1)))))
Initial program 9.6
\[\frac{1}{\sqrt{x}} - \frac{1}{\sqrt{x + 1}}\]
- Using strategy
rm Applied pow1/29.6
\[\leadsto \frac{1}{\color{blue}{{x}^{\frac{1}{2}}}} - \frac{1}{\sqrt{x + 1}}\]
Applied pow-flip9.3
\[\leadsto \color{blue}{{x}^{\left(-\frac{1}{2}\right)}} - \frac{1}{\sqrt{x + 1}}\]
- Using strategy
rm Applied flip--9.3
\[\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 simplify9.1
\[\leadsto \frac{\color{blue}{(\left({x}^{\left(-\frac{1}{2}\right)}\right) \cdot \left({x}^{\left(-\frac{1}{2}\right)}\right) + \left(\frac{-1}{x + 1}\right))_*}}{{x}^{\left(-\frac{1}{2}\right)} + \frac{1}{\sqrt{x + 1}}}\]
- Recombined 2 regimes into one program.
Runtime
herbie shell --seed '#(1071246582 2318319007 2683472949 3810440501 3233274817 2724848749)' +o rules:numerics
(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)))))