Average Error: 16.0 → 6.9
Time: 1.7m
Precision: 64
Internal Precision: 576
$\frac{1}{\sqrt{0.5 \cdot \left(\left(4 + {\left(\frac{x}{p}\right)}^{2}\right) + q \cdot \frac{x}{p}\right)}}$
$\begin{array}{l} \mathbf{if}\;\frac{\sqrt{\frac{1}{\frac{x}{p} \cdot \frac{x}{p} + 4}}}{\sqrt{0.5}} \le 3.5137538467732 \cdot 10^{-310}:\\ \;\;\;\;\frac{1}{\sqrt{0.5} \cdot \left(\frac{x}{p} + \frac{1}{2} \cdot q\right)}\\ \mathbf{else}:\\ \;\;\;\;{\left(0.5 \cdot \left(\left(4 + {\left(\frac{x}{p}\right)}^{2}\right) + q \cdot \frac{x}{p}\right)\right)}^{\left(-\frac{1}{2}\right)}\\ \end{array}$

# Try it out

Results

 In Out
Enter valid numbers for all inputs

# Derivation

1. Split input into 2 regimes
2. ## if (/ (sqrt (/ 1 (+ (* (/ x p) (/ x p)) 4))) (sqrt 0.5)) < 3.5137538467732e-310

1. Initial program 47.5

$\frac{1}{\sqrt{0.5 \cdot \left(\left(4 + {\left(\frac{x}{p}\right)}^{2}\right) + q \cdot \frac{x}{p}\right)}}$
2. Using strategy rm
3. Applied sqrt-prod47.5

$\leadsto \frac{1}{\color{blue}{\sqrt{0.5} \cdot \sqrt{\left(4 + {\left(\frac{x}{p}\right)}^{2}\right) + q \cdot \frac{x}{p}}}}$
4. Applied simplify33.1

$\leadsto \frac{1}{\sqrt{0.5} \cdot \color{blue}{\sqrt{\frac{x}{p} \cdot \left(\frac{x}{p} + q\right) + 4}}}$
5. Taylor expanded around inf 18.9

$\leadsto \frac{1}{\sqrt{0.5} \cdot \color{blue}{\left(\frac{x}{p} + \frac{1}{2} \cdot q\right)}}$

## if 3.5137538467732e-310 < (/ (sqrt (/ 1 (+ (* (/ x p) (/ x p)) 4))) (sqrt 0.5))

1. Initial program 2.2

$\frac{1}{\sqrt{0.5 \cdot \left(\left(4 + {\left(\frac{x}{p}\right)}^{2}\right) + q \cdot \frac{x}{p}\right)}}$
2. Using strategy rm
3. Applied pow1/22.2

$\leadsto \frac{1}{\color{blue}{{\left(0.5 \cdot \left(\left(4 + {\left(\frac{x}{p}\right)}^{2}\right) + q \cdot \frac{x}{p}\right)\right)}^{\frac{1}{2}}}}$
4. Applied pow-flip1.6

$\leadsto \color{blue}{{\left(0.5 \cdot \left(\left(4 + {\left(\frac{x}{p}\right)}^{2}\right) + q \cdot \frac{x}{p}\right)\right)}^{\left(-\frac{1}{2}\right)}}$
3. Recombined 2 regimes into one program.

# Runtime

Time bar (total: 1.7m)Debug log

herbie shell --seed '#(2775764126 3555076145 3898259844 1891440260 2599947619 1948460636)'
(FPCore (x p q)
:name "1/sqrt(0.5*(4 + (x/p)^2 + q*(x/p)))"
(/ 1 (sqrt (* 0.5 (+ (+ 4 (pow (/ x p) 2)) (* q (/ x p)))))))