Average Error: 13.1 → 14.1
Time: 13.5s
Precision: 64
\[10^{-150} \lt \left|x\right| \lt 10^{+150}\]
\[\sqrt{0.5 \cdot \left(1 + \frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}\right)}\]
\[\sqrt{\left(\sqrt[3]{\mathsf{fma}\left(\left(\frac{x}{\sqrt{\sqrt{\mathsf{fma}\left(p, \left(4 \cdot p\right), \left(x \cdot x\right)\right)}} \cdot \sqrt{\sqrt{\mathsf{fma}\left(p, \left(4 \cdot p\right), \left(x \cdot x\right)\right)}}}\right), 0.5, 0.5\right)} \cdot \sqrt[3]{\mathsf{fma}\left(\left(\frac{x}{\sqrt{\sqrt{\mathsf{fma}\left(p, \left(4 \cdot p\right), \left(x \cdot x\right)\right)}} \cdot \sqrt{\sqrt{\mathsf{fma}\left(p, \left(4 \cdot p\right), \left(x \cdot x\right)\right)}}}\right), 0.5, 0.5\right)}\right) \cdot \sqrt[3]{\mathsf{fma}\left(\left(\frac{x}{\sqrt{\sqrt{\mathsf{fma}\left(p, \left(4 \cdot p\right), \left(x \cdot x\right)\right)}} \cdot \sqrt{\sqrt{\mathsf{fma}\left(p, \left(4 \cdot p\right), \left(x \cdot x\right)\right)}}}\right), 0.5, 0.5\right)}}\]
\sqrt{0.5 \cdot \left(1 + \frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}\right)}
\sqrt{\left(\sqrt[3]{\mathsf{fma}\left(\left(\frac{x}{\sqrt{\sqrt{\mathsf{fma}\left(p, \left(4 \cdot p\right), \left(x \cdot x\right)\right)}} \cdot \sqrt{\sqrt{\mathsf{fma}\left(p, \left(4 \cdot p\right), \left(x \cdot x\right)\right)}}}\right), 0.5, 0.5\right)} \cdot \sqrt[3]{\mathsf{fma}\left(\left(\frac{x}{\sqrt{\sqrt{\mathsf{fma}\left(p, \left(4 \cdot p\right), \left(x \cdot x\right)\right)}} \cdot \sqrt{\sqrt{\mathsf{fma}\left(p, \left(4 \cdot p\right), \left(x \cdot x\right)\right)}}}\right), 0.5, 0.5\right)}\right) \cdot \sqrt[3]{\mathsf{fma}\left(\left(\frac{x}{\sqrt{\sqrt{\mathsf{fma}\left(p, \left(4 \cdot p\right), \left(x \cdot x\right)\right)}} \cdot \sqrt{\sqrt{\mathsf{fma}\left(p, \left(4 \cdot p\right), \left(x \cdot x\right)\right)}}}\right), 0.5, 0.5\right)}}
double f(double p, double x) {
        double r4613751 = 0.5;
        double r4613752 = 1.0;
        double r4613753 = x;
        double r4613754 = 4.0;
        double r4613755 = p;
        double r4613756 = r4613754 * r4613755;
        double r4613757 = r4613756 * r4613755;
        double r4613758 = r4613753 * r4613753;
        double r4613759 = r4613757 + r4613758;
        double r4613760 = sqrt(r4613759);
        double r4613761 = r4613753 / r4613760;
        double r4613762 = r4613752 + r4613761;
        double r4613763 = r4613751 * r4613762;
        double r4613764 = sqrt(r4613763);
        return r4613764;
}

double f(double p, double x) {
        double r4613765 = x;
        double r4613766 = p;
        double r4613767 = 4.0;
        double r4613768 = r4613767 * r4613766;
        double r4613769 = r4613765 * r4613765;
        double r4613770 = fma(r4613766, r4613768, r4613769);
        double r4613771 = sqrt(r4613770);
        double r4613772 = sqrt(r4613771);
        double r4613773 = r4613772 * r4613772;
        double r4613774 = r4613765 / r4613773;
        double r4613775 = 0.5;
        double r4613776 = fma(r4613774, r4613775, r4613775);
        double r4613777 = cbrt(r4613776);
        double r4613778 = r4613777 * r4613777;
        double r4613779 = r4613778 * r4613777;
        double r4613780 = sqrt(r4613779);
        return r4613780;
}

Error

Bits error versus p

Bits error versus x

Target

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

Derivation

  1. Initial program 13.1

    \[\sqrt{0.5 \cdot \left(1 + \frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}\right)}\]
  2. Simplified13.1

    \[\leadsto \color{blue}{\sqrt{\mathsf{fma}\left(\left(\frac{x}{\sqrt{\mathsf{fma}\left(p, \left(4 \cdot p\right), \left(x \cdot x\right)\right)}}\right), 0.5, 0.5\right)}}\]
  3. Using strategy rm
  4. Applied add-sqr-sqrt14.1

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

    \[\leadsto \sqrt{\color{blue}{\left(\sqrt[3]{\mathsf{fma}\left(\left(\frac{x}{\sqrt{\sqrt{\mathsf{fma}\left(p, \left(4 \cdot p\right), \left(x \cdot x\right)\right)}} \cdot \sqrt{\sqrt{\mathsf{fma}\left(p, \left(4 \cdot p\right), \left(x \cdot x\right)\right)}}}\right), 0.5, 0.5\right)} \cdot \sqrt[3]{\mathsf{fma}\left(\left(\frac{x}{\sqrt{\sqrt{\mathsf{fma}\left(p, \left(4 \cdot p\right), \left(x \cdot x\right)\right)}} \cdot \sqrt{\sqrt{\mathsf{fma}\left(p, \left(4 \cdot p\right), \left(x \cdot x\right)\right)}}}\right), 0.5, 0.5\right)}\right) \cdot \sqrt[3]{\mathsf{fma}\left(\left(\frac{x}{\sqrt{\sqrt{\mathsf{fma}\left(p, \left(4 \cdot p\right), \left(x \cdot x\right)\right)}} \cdot \sqrt{\sqrt{\mathsf{fma}\left(p, \left(4 \cdot p\right), \left(x \cdot x\right)\right)}}}\right), 0.5, 0.5\right)}}}\]
  7. Final simplification14.1

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

Reproduce

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

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

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