Average Error: 13.2 → 13.2
Time: 1.9m
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[3]{\mathsf{fma}\left(0.5, \frac{x}{\sqrt{\mathsf{fma}\left(p \cdot 4, p, x \cdot x\right)}}, 0.5\right) \cdot \sqrt{\mathsf{fma}\left(0.5, \frac{x}{\sqrt{\mathsf{fma}\left(p \cdot 4, p, x \cdot x\right)}}, 0.5\right)}}\]
\sqrt{0.5 \cdot \left(1 + \frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}\right)}
\sqrt[3]{\mathsf{fma}\left(0.5, \frac{x}{\sqrt{\mathsf{fma}\left(p \cdot 4, p, x \cdot x\right)}}, 0.5\right) \cdot \sqrt{\mathsf{fma}\left(0.5, \frac{x}{\sqrt{\mathsf{fma}\left(p \cdot 4, p, x \cdot x\right)}}, 0.5\right)}}
double f(double p, double x) {
        double r8891826 = 0.5;
        double r8891827 = 1.0;
        double r8891828 = x;
        double r8891829 = 4.0;
        double r8891830 = p;
        double r8891831 = r8891829 * r8891830;
        double r8891832 = r8891831 * r8891830;
        double r8891833 = r8891828 * r8891828;
        double r8891834 = r8891832 + r8891833;
        double r8891835 = sqrt(r8891834);
        double r8891836 = r8891828 / r8891835;
        double r8891837 = r8891827 + r8891836;
        double r8891838 = r8891826 * r8891837;
        double r8891839 = sqrt(r8891838);
        return r8891839;
}

double f(double p, double x) {
        double r8891840 = 0.5;
        double r8891841 = x;
        double r8891842 = p;
        double r8891843 = 4.0;
        double r8891844 = r8891842 * r8891843;
        double r8891845 = r8891841 * r8891841;
        double r8891846 = fma(r8891844, r8891842, r8891845);
        double r8891847 = sqrt(r8891846);
        double r8891848 = r8891841 / r8891847;
        double r8891849 = fma(r8891840, r8891848, r8891840);
        double r8891850 = sqrt(r8891849);
        double r8891851 = r8891849 * r8891850;
        double r8891852 = cbrt(r8891851);
        return r8891852;
}

Error

Bits error versus p

Bits error versus x

Target

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

Derivation

  1. Initial program 13.2

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

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

    \[\leadsto \color{blue}{\sqrt[3]{\left(\sqrt{\mathsf{fma}\left(\frac{x}{\sqrt{\mathsf{fma}\left(p, 4 \cdot p, x \cdot x\right)}}, 0.5, 0.5\right)} \cdot \sqrt{\mathsf{fma}\left(\frac{x}{\sqrt{\mathsf{fma}\left(p, 4 \cdot p, x \cdot x\right)}}, 0.5, 0.5\right)}\right) \cdot \sqrt{\mathsf{fma}\left(\frac{x}{\sqrt{\mathsf{fma}\left(p, 4 \cdot p, x \cdot x\right)}}, 0.5, 0.5\right)}}}\]
  5. Simplified13.2

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

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

Reproduce

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