Average Error: 22.9 → 14.6
Time: 28.6s
Precision: 64
Internal Precision: 2624
$\sqrt{0.5 \cdot \left(1 - \frac{q}{\sqrt{\left(4 \cdot p\right) \cdot p + q \cdot q}}\right)}$
$\begin{array}{l} \mathbf{if}\;q \le -1.397231497318746 \cdot 10^{+154}:\\ \;\;\;\;\sqrt{1.0}\\ \mathbf{elif}\;q \le -1.57392654159745 \cdot 10^{-162}:\\ \;\;\;\;\sqrt{0.5 - \frac{0.5 \cdot q}{\sqrt{\sqrt{4 \cdot \left(p \cdot p\right) + q \cdot q}} \cdot \sqrt{\sqrt{4 \cdot \left(p \cdot p\right) + q \cdot q}}}}\\ \mathbf{elif}\;q \le 7.740752769404736 \cdot 10^{-170}:\\ \;\;\;\;\sqrt{0.5}\\ \mathbf{elif}\;q \le 1.2863023292917973 \cdot 10^{+146}:\\ \;\;\;\;\log \left(e^{\sqrt{0.5 - \frac{0.5 \cdot q}{\sqrt{\sqrt[3]{4 \cdot \left(p \cdot p\right) + q \cdot q}} \cdot \left|\sqrt[3]{4 \cdot \left(p \cdot p\right) + q \cdot q}\right|}}}\right)\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array}$

# Try it out

Results

 In Out
Enter valid numbers for all inputs

# Derivation

1. Split input into 5 regimes
2. ## if q < -1.397231497318746e+154

1. Initial program 45.2

$\sqrt{0.5 \cdot \left(1 - \frac{q}{\sqrt{\left(4 \cdot p\right) \cdot p + q \cdot q}}\right)}$
2. Initial simplification45.2

$\leadsto \sqrt{0.5 - \frac{0.5 \cdot q}{\sqrt{\left(p \cdot p\right) \cdot 4 + q \cdot q}}}$
3. Taylor expanded around -inf 6.9

$\leadsto \color{blue}{\sqrt{1.0}}$

## if -1.397231497318746e+154 < q < -1.57392654159745e-162

1. Initial program 0.2

$\sqrt{0.5 \cdot \left(1 - \frac{q}{\sqrt{\left(4 \cdot p\right) \cdot p + q \cdot q}}\right)}$
2. Initial simplification0.2

$\leadsto \sqrt{0.5 - \frac{0.5 \cdot q}{\sqrt{\left(p \cdot p\right) \cdot 4 + q \cdot q}}}$
3. Using strategy rm

$\leadsto \sqrt{0.5 - \frac{0.5 \cdot q}{\sqrt{\color{blue}{\sqrt{\left(p \cdot p\right) \cdot 4 + q \cdot q} \cdot \sqrt{\left(p \cdot p\right) \cdot 4 + q \cdot q}}}}}$
5. Applied sqrt-prod0.2

$\leadsto \sqrt{0.5 - \frac{0.5 \cdot q}{\color{blue}{\sqrt{\sqrt{\left(p \cdot p\right) \cdot 4 + q \cdot q}} \cdot \sqrt{\sqrt{\left(p \cdot p\right) \cdot 4 + q \cdot q}}}}}$

## if -1.57392654159745e-162 < q < 7.740752769404736e-170

1. Initial program 16.0

$\sqrt{0.5 \cdot \left(1 - \frac{q}{\sqrt{\left(4 \cdot p\right) \cdot p + q \cdot q}}\right)}$
2. Initial simplification16.0

$\leadsto \sqrt{0.5 - \frac{0.5 \cdot q}{\sqrt{\left(p \cdot p\right) \cdot 4 + q \cdot q}}}$
3. Taylor expanded around 0 7.6

$\leadsto \sqrt{\color{blue}{0.5}}$

## if 7.740752769404736e-170 < q < 1.2863023292917973e+146

1. Initial program 24.7

$\sqrt{0.5 \cdot \left(1 - \frac{q}{\sqrt{\left(4 \cdot p\right) \cdot p + q \cdot q}}\right)}$
2. Initial simplification24.7

$\leadsto \sqrt{0.5 - \frac{0.5 \cdot q}{\sqrt{\left(p \cdot p\right) \cdot 4 + q \cdot q}}}$
3. Using strategy rm

$\leadsto \sqrt{0.5 - \frac{0.5 \cdot q}{\sqrt{\color{blue}{\left(\sqrt[3]{\left(p \cdot p\right) \cdot 4 + q \cdot q} \cdot \sqrt[3]{\left(p \cdot p\right) \cdot 4 + q \cdot q}\right) \cdot \sqrt[3]{\left(p \cdot p\right) \cdot 4 + q \cdot q}}}}}$
5. Applied sqrt-prod27.0

$\leadsto \sqrt{0.5 - \frac{0.5 \cdot q}{\color{blue}{\sqrt{\sqrt[3]{\left(p \cdot p\right) \cdot 4 + q \cdot q} \cdot \sqrt[3]{\left(p \cdot p\right) \cdot 4 + q \cdot q}} \cdot \sqrt{\sqrt[3]{\left(p \cdot p\right) \cdot 4 + q \cdot q}}}}}$
6. Simplified27.0

$\leadsto \sqrt{0.5 - \frac{0.5 \cdot q}{\color{blue}{\left|\sqrt[3]{q \cdot q + \left(p \cdot p\right) \cdot 4}\right|} \cdot \sqrt{\sqrt[3]{\left(p \cdot p\right) \cdot 4 + q \cdot q}}}}$
7. Using strategy rm

$\leadsto \color{blue}{\log \left(e^{\sqrt{0.5 - \frac{0.5 \cdot q}{\left|\sqrt[3]{q \cdot q + \left(p \cdot p\right) \cdot 4}\right| \cdot \sqrt{\sqrt[3]{\left(p \cdot p\right) \cdot 4 + q \cdot q}}}}}\right)}$

## if 1.2863023292917973e+146 < q

1. Initial program 52.5

$\sqrt{0.5 \cdot \left(1 - \frac{q}{\sqrt{\left(4 \cdot p\right) \cdot p + q \cdot q}}\right)}$
2. Initial simplification52.5

$\leadsto \sqrt{0.5 - \frac{0.5 \cdot q}{\sqrt{\left(p \cdot p\right) \cdot 4 + q \cdot q}}}$
3. Taylor expanded around inf 38.4

$\leadsto \color{blue}{0}$
3. Recombined 5 regimes into one program.
4. Final simplification14.6

$\leadsto \begin{array}{l} \mathbf{if}\;q \le -1.397231497318746 \cdot 10^{+154}:\\ \;\;\;\;\sqrt{1.0}\\ \mathbf{elif}\;q \le -1.57392654159745 \cdot 10^{-162}:\\ \;\;\;\;\sqrt{0.5 - \frac{0.5 \cdot q}{\sqrt{\sqrt{4 \cdot \left(p \cdot p\right) + q \cdot q}} \cdot \sqrt{\sqrt{4 \cdot \left(p \cdot p\right) + q \cdot q}}}}\\ \mathbf{elif}\;q \le 7.740752769404736 \cdot 10^{-170}:\\ \;\;\;\;\sqrt{0.5}\\ \mathbf{elif}\;q \le 1.2863023292917973 \cdot 10^{+146}:\\ \;\;\;\;\log \left(e^{\sqrt{0.5 - \frac{0.5 \cdot q}{\sqrt{\sqrt[3]{4 \cdot \left(p \cdot p\right) + q \cdot q}} \cdot \left|\sqrt[3]{4 \cdot \left(p \cdot p\right) + q \cdot q}\right|}}}\right)\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array}$

# Runtime

Time bar (total: 28.6s)Debug log

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