Average Error: 13.4 → 14.8
Time: 5.5s
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 \frac{{1}^{3} + {\left(\frac{\frac{x}{\left|\sqrt[3]{\left(4 \cdot p\right) \cdot p + x \cdot x}\right|}}{\sqrt{\sqrt[3]{\left(4 \cdot p\right) \cdot p + x \cdot x}}}\right)}^{3}}{\mathsf{fma}\left(\frac{\frac{x}{\left|\sqrt[3]{\left(4 \cdot p\right) \cdot p + x \cdot x}\right|}}{\sqrt{\sqrt[3]{\left(4 \cdot p\right) \cdot p + x \cdot x}}} - 1, \frac{\frac{x}{\left|{\left(\mathsf{fma}\left(4, {p}^{2}, {x}^{2}\right)\right)}^{\frac{1}{6}}\right|}}{\left|{\left(4 \cdot {p}^{2} + {x}^{2}\right)}^{\frac{1}{3}}\right|}, 1 \cdot 1\right)}}\]
\sqrt{0.5 \cdot \left(1 + \frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}\right)}
\sqrt{0.5 \cdot \frac{{1}^{3} + {\left(\frac{\frac{x}{\left|\sqrt[3]{\left(4 \cdot p\right) \cdot p + x \cdot x}\right|}}{\sqrt{\sqrt[3]{\left(4 \cdot p\right) \cdot p + x \cdot x}}}\right)}^{3}}{\mathsf{fma}\left(\frac{\frac{x}{\left|\sqrt[3]{\left(4 \cdot p\right) \cdot p + x \cdot x}\right|}}{\sqrt{\sqrt[3]{\left(4 \cdot p\right) \cdot p + x \cdot x}}} - 1, \frac{\frac{x}{\left|{\left(\mathsf{fma}\left(4, {p}^{2}, {x}^{2}\right)\right)}^{\frac{1}{6}}\right|}}{\left|{\left(4 \cdot {p}^{2} + {x}^{2}\right)}^{\frac{1}{3}}\right|}, 1 \cdot 1\right)}}
double f(double p, double x) {
        double r244670 = 0.5;
        double r244671 = 1.0;
        double r244672 = x;
        double r244673 = 4.0;
        double r244674 = p;
        double r244675 = r244673 * r244674;
        double r244676 = r244675 * r244674;
        double r244677 = r244672 * r244672;
        double r244678 = r244676 + r244677;
        double r244679 = sqrt(r244678);
        double r244680 = r244672 / r244679;
        double r244681 = r244671 + r244680;
        double r244682 = r244670 * r244681;
        double r244683 = sqrt(r244682);
        return r244683;
}

double f(double p, double x) {
        double r244684 = 0.5;
        double r244685 = 1.0;
        double r244686 = 3.0;
        double r244687 = pow(r244685, r244686);
        double r244688 = x;
        double r244689 = 4.0;
        double r244690 = p;
        double r244691 = r244689 * r244690;
        double r244692 = r244691 * r244690;
        double r244693 = r244688 * r244688;
        double r244694 = r244692 + r244693;
        double r244695 = cbrt(r244694);
        double r244696 = fabs(r244695);
        double r244697 = r244688 / r244696;
        double r244698 = sqrt(r244695);
        double r244699 = r244697 / r244698;
        double r244700 = pow(r244699, r244686);
        double r244701 = r244687 + r244700;
        double r244702 = r244699 - r244685;
        double r244703 = 2.0;
        double r244704 = pow(r244690, r244703);
        double r244705 = pow(r244688, r244703);
        double r244706 = fma(r244689, r244704, r244705);
        double r244707 = 0.16666666666666666;
        double r244708 = pow(r244706, r244707);
        double r244709 = fabs(r244708);
        double r244710 = r244688 / r244709;
        double r244711 = r244689 * r244704;
        double r244712 = r244711 + r244705;
        double r244713 = 0.3333333333333333;
        double r244714 = pow(r244712, r244713);
        double r244715 = fabs(r244714);
        double r244716 = r244710 / r244715;
        double r244717 = r244685 * r244685;
        double r244718 = fma(r244702, r244716, r244717);
        double r244719 = r244701 / r244718;
        double r244720 = r244684 * r244719;
        double r244721 = sqrt(r244720);
        return r244721;
}

Error

Bits error versus p

Bits error versus x

Target

Original13.4
Target13.4
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.4

    \[\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-cube-cbrt14.8

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

    \[\leadsto \sqrt{0.5 \cdot \left(1 + \frac{x}{\color{blue}{\sqrt{\sqrt[3]{\left(4 \cdot p\right) \cdot p + x \cdot x} \cdot \sqrt[3]{\left(4 \cdot p\right) \cdot p + x \cdot x}} \cdot \sqrt{\sqrt[3]{\left(4 \cdot p\right) \cdot p + x \cdot x}}}}\right)}\]
  5. Applied associate-/r*14.8

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

    \[\leadsto \sqrt{0.5 \cdot \left(1 + \frac{\color{blue}{\frac{x}{\left|\sqrt[3]{\left(4 \cdot p\right) \cdot p + x \cdot x}\right|}}}{\sqrt{\sqrt[3]{\left(4 \cdot p\right) \cdot p + x \cdot x}}}\right)}\]
  7. Using strategy rm
  8. Applied flip3-+14.8

    \[\leadsto \sqrt{0.5 \cdot \color{blue}{\frac{{1}^{3} + {\left(\frac{\frac{x}{\left|\sqrt[3]{\left(4 \cdot p\right) \cdot p + x \cdot x}\right|}}{\sqrt{\sqrt[3]{\left(4 \cdot p\right) \cdot p + x \cdot x}}}\right)}^{3}}{1 \cdot 1 + \left(\frac{\frac{x}{\left|\sqrt[3]{\left(4 \cdot p\right) \cdot p + x \cdot x}\right|}}{\sqrt{\sqrt[3]{\left(4 \cdot p\right) \cdot p + x \cdot x}}} \cdot \frac{\frac{x}{\left|\sqrt[3]{\left(4 \cdot p\right) \cdot p + x \cdot x}\right|}}{\sqrt{\sqrt[3]{\left(4 \cdot p\right) \cdot p + x \cdot x}}} - 1 \cdot \frac{\frac{x}{\left|\sqrt[3]{\left(4 \cdot p\right) \cdot p + x \cdot x}\right|}}{\sqrt{\sqrt[3]{\left(4 \cdot p\right) \cdot p + x \cdot x}}}\right)}}}\]
  9. Simplified14.8

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

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

Reproduce

herbie shell --seed 2020001 +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))))))))