Average Error: 13.5 → 14.8
Time: 18.2s
Precision: 64
\[1.000000000000000006295358232172963997211 \cdot 10^{-150} \lt \left|x\right| \lt 9.999999999999999808355961724373745905731 \cdot 10^{149}\]
\[\sqrt{0.5 \cdot \left(1 + \frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}\right)}\]
\[\sqrt{0.5 \cdot \sqrt[3]{{\left(1 + \frac{x}{\left(\sqrt{\left|\sqrt[3]{\mathsf{fma}\left(4, {p}^{2}, x \cdot x\right)}\right|} \cdot \sqrt{\sqrt{\mathsf{fma}\left(4, {p}^{2}, x \cdot x\right)}}\right) \cdot \sqrt{\sqrt{\sqrt[3]{\mathsf{fma}\left(4, {p}^{2}, x \cdot x\right)}}}}\right)}^{3}}}\]
\sqrt{0.5 \cdot \left(1 + \frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}\right)}
\sqrt{0.5 \cdot \sqrt[3]{{\left(1 + \frac{x}{\left(\sqrt{\left|\sqrt[3]{\mathsf{fma}\left(4, {p}^{2}, x \cdot x\right)}\right|} \cdot \sqrt{\sqrt{\mathsf{fma}\left(4, {p}^{2}, x \cdot x\right)}}\right) \cdot \sqrt{\sqrt{\sqrt[3]{\mathsf{fma}\left(4, {p}^{2}, x \cdot x\right)}}}}\right)}^{3}}}
double f(double p, double x) {
        double r165605 = 0.5;
        double r165606 = 1.0;
        double r165607 = x;
        double r165608 = 4.0;
        double r165609 = p;
        double r165610 = r165608 * r165609;
        double r165611 = r165610 * r165609;
        double r165612 = r165607 * r165607;
        double r165613 = r165611 + r165612;
        double r165614 = sqrt(r165613);
        double r165615 = r165607 / r165614;
        double r165616 = r165606 + r165615;
        double r165617 = r165605 * r165616;
        double r165618 = sqrt(r165617);
        return r165618;
}

double f(double p, double x) {
        double r165619 = 0.5;
        double r165620 = 1.0;
        double r165621 = x;
        double r165622 = 4.0;
        double r165623 = p;
        double r165624 = 2.0;
        double r165625 = pow(r165623, r165624);
        double r165626 = r165621 * r165621;
        double r165627 = fma(r165622, r165625, r165626);
        double r165628 = cbrt(r165627);
        double r165629 = fabs(r165628);
        double r165630 = sqrt(r165629);
        double r165631 = sqrt(r165627);
        double r165632 = sqrt(r165631);
        double r165633 = r165630 * r165632;
        double r165634 = sqrt(r165628);
        double r165635 = sqrt(r165634);
        double r165636 = r165633 * r165635;
        double r165637 = r165621 / r165636;
        double r165638 = r165620 + r165637;
        double r165639 = 3.0;
        double r165640 = pow(r165638, r165639);
        double r165641 = cbrt(r165640);
        double r165642 = r165619 * r165641;
        double r165643 = sqrt(r165642);
        return r165643;
}

Error

Bits error versus p

Bits error versus x

Target

Original13.5
Target13.5
Herbie14.8
\[\sqrt{0.5 + \frac{\mathsf{copysign}\left(0.5, x\right)}{\mathsf{hypot}\left(1, \frac{2 \cdot p}{x}\right)}}\]

Derivation

  1. Initial program 13.5

    \[\sqrt{0.5 \cdot \left(1 + \frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}\right)}\]
  2. Using strategy rm
  3. Applied add-sqr-sqrt13.5

    \[\leadsto \sqrt{0.5 \cdot \left(1 + \frac{x}{\sqrt{\color{blue}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x} \cdot \sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}}}\right)}\]
  4. Applied sqrt-prod14.5

    \[\leadsto \sqrt{0.5 \cdot \left(1 + \frac{x}{\color{blue}{\sqrt{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}} \cdot \sqrt{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}}}\right)}\]
  5. Simplified14.5

    \[\leadsto \sqrt{0.5 \cdot \left(1 + \frac{x}{\color{blue}{\sqrt{\sqrt{\mathsf{fma}\left(4, {p}^{2}, x \cdot x\right)}}} \cdot \sqrt{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}}\right)}\]
  6. Simplified14.5

    \[\leadsto \sqrt{0.5 \cdot \left(1 + \frac{x}{\sqrt{\sqrt{\mathsf{fma}\left(4, {p}^{2}, x \cdot x\right)}} \cdot \color{blue}{\sqrt{\sqrt{\mathsf{fma}\left(4, {p}^{2}, x \cdot x\right)}}}}\right)}\]
  7. Using strategy rm
  8. Applied add-cube-cbrt14.8

    \[\leadsto \sqrt{0.5 \cdot \left(1 + \frac{x}{\sqrt{\sqrt{\mathsf{fma}\left(4, {p}^{2}, x \cdot x\right)}} \cdot \sqrt{\sqrt{\color{blue}{\left(\sqrt[3]{\mathsf{fma}\left(4, {p}^{2}, x \cdot x\right)} \cdot \sqrt[3]{\mathsf{fma}\left(4, {p}^{2}, x \cdot x\right)}\right) \cdot \sqrt[3]{\mathsf{fma}\left(4, {p}^{2}, x \cdot x\right)}}}}}\right)}\]
  9. Applied sqrt-prod14.8

    \[\leadsto \sqrt{0.5 \cdot \left(1 + \frac{x}{\sqrt{\sqrt{\mathsf{fma}\left(4, {p}^{2}, x \cdot x\right)}} \cdot \sqrt{\color{blue}{\sqrt{\sqrt[3]{\mathsf{fma}\left(4, {p}^{2}, x \cdot x\right)} \cdot \sqrt[3]{\mathsf{fma}\left(4, {p}^{2}, x \cdot x\right)}} \cdot \sqrt{\sqrt[3]{\mathsf{fma}\left(4, {p}^{2}, x \cdot x\right)}}}}}\right)}\]
  10. Applied sqrt-prod14.7

    \[\leadsto \sqrt{0.5 \cdot \left(1 + \frac{x}{\sqrt{\sqrt{\mathsf{fma}\left(4, {p}^{2}, x \cdot x\right)}} \cdot \color{blue}{\left(\sqrt{\sqrt{\sqrt[3]{\mathsf{fma}\left(4, {p}^{2}, x \cdot x\right)} \cdot \sqrt[3]{\mathsf{fma}\left(4, {p}^{2}, x \cdot x\right)}}} \cdot \sqrt{\sqrt{\sqrt[3]{\mathsf{fma}\left(4, {p}^{2}, x \cdot x\right)}}}\right)}}\right)}\]
  11. Applied associate-*r*14.8

    \[\leadsto \sqrt{0.5 \cdot \left(1 + \frac{x}{\color{blue}{\left(\sqrt{\sqrt{\mathsf{fma}\left(4, {p}^{2}, x \cdot x\right)}} \cdot \sqrt{\sqrt{\sqrt[3]{\mathsf{fma}\left(4, {p}^{2}, x \cdot x\right)} \cdot \sqrt[3]{\mathsf{fma}\left(4, {p}^{2}, x \cdot x\right)}}}\right) \cdot \sqrt{\sqrt{\sqrt[3]{\mathsf{fma}\left(4, {p}^{2}, x \cdot x\right)}}}}}\right)}\]
  12. Simplified14.8

    \[\leadsto \sqrt{0.5 \cdot \left(1 + \frac{x}{\color{blue}{\left(\sqrt{\left|\sqrt[3]{\mathsf{fma}\left(4, {p}^{2}, x \cdot x\right)}\right|} \cdot \sqrt{\sqrt{\mathsf{fma}\left(4, {p}^{2}, x \cdot x\right)}}\right)} \cdot \sqrt{\sqrt{\sqrt[3]{\mathsf{fma}\left(4, {p}^{2}, x \cdot x\right)}}}}\right)}\]
  13. Using strategy rm
  14. Applied add-cbrt-cube14.8

    \[\leadsto \sqrt{0.5 \cdot \color{blue}{\sqrt[3]{\left(\left(1 + \frac{x}{\left(\sqrt{\left|\sqrt[3]{\mathsf{fma}\left(4, {p}^{2}, x \cdot x\right)}\right|} \cdot \sqrt{\sqrt{\mathsf{fma}\left(4, {p}^{2}, x \cdot x\right)}}\right) \cdot \sqrt{\sqrt{\sqrt[3]{\mathsf{fma}\left(4, {p}^{2}, x \cdot x\right)}}}}\right) \cdot \left(1 + \frac{x}{\left(\sqrt{\left|\sqrt[3]{\mathsf{fma}\left(4, {p}^{2}, x \cdot x\right)}\right|} \cdot \sqrt{\sqrt{\mathsf{fma}\left(4, {p}^{2}, x \cdot x\right)}}\right) \cdot \sqrt{\sqrt{\sqrt[3]{\mathsf{fma}\left(4, {p}^{2}, x \cdot x\right)}}}}\right)\right) \cdot \left(1 + \frac{x}{\left(\sqrt{\left|\sqrt[3]{\mathsf{fma}\left(4, {p}^{2}, x \cdot x\right)}\right|} \cdot \sqrt{\sqrt{\mathsf{fma}\left(4, {p}^{2}, x \cdot x\right)}}\right) \cdot \sqrt{\sqrt{\sqrt[3]{\mathsf{fma}\left(4, {p}^{2}, x \cdot x\right)}}}}\right)}}}\]
  15. Simplified14.8

    \[\leadsto \sqrt{0.5 \cdot \sqrt[3]{\color{blue}{{\left(1 + \frac{x}{\left(\sqrt{\left|\sqrt[3]{\mathsf{fma}\left(4, {p}^{2}, x \cdot x\right)}\right|} \cdot \sqrt{\sqrt{\mathsf{fma}\left(4, {p}^{2}, x \cdot x\right)}}\right) \cdot \sqrt{\sqrt{\sqrt[3]{\mathsf{fma}\left(4, {p}^{2}, x \cdot x\right)}}}}\right)}^{3}}}}\]
  16. Final simplification14.8

    \[\leadsto \sqrt{0.5 \cdot \sqrt[3]{{\left(1 + \frac{x}{\left(\sqrt{\left|\sqrt[3]{\mathsf{fma}\left(4, {p}^{2}, x \cdot x\right)}\right|} \cdot \sqrt{\sqrt{\mathsf{fma}\left(4, {p}^{2}, x \cdot x\right)}}\right) \cdot \sqrt{\sqrt{\sqrt[3]{\mathsf{fma}\left(4, {p}^{2}, x \cdot x\right)}}}}\right)}^{3}}}\]

Reproduce

herbie shell --seed 2019325 +o rules:numerics
(FPCore (p x)
  :name "Given's Rotation SVD example"
  :precision binary64
  :pre (< 1e-150 (fabs x) 1e+150)

  :herbie-target
  (sqrt (+ 0.5 (/ (copysign 0.5 x) (hypot 1 (/ (* 2 p) x)))))

  (sqrt (* 0.5 (+ 1 (/ x (sqrt (+ (* (* 4 p) p) (* x x))))))))