Average Error: 12.9 → 13.6
Time: 14.0s
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)}\]
\[\left(\sqrt[3]{\sqrt{\mathsf{fma}\left(\left(x \cdot \frac{1}{\sqrt{\mathsf{fma}\left(p, \left(p \cdot 4\right), \left(x \cdot x\right)\right)}}\right), 0.5, 0.5\right)}} \cdot \sqrt[3]{\sqrt{\mathsf{fma}\left(\left(x \cdot \frac{1}{\sqrt{\mathsf{fma}\left(p, \left(p \cdot 4\right), \left(x \cdot x\right)\right)}}\right), 0.5, 0.5\right)}}\right) \cdot \sqrt[3]{\sqrt{\mathsf{fma}\left(\left(x \cdot \frac{1}{\sqrt{\mathsf{fma}\left(p, \left(p \cdot 4\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)}
\left(\sqrt[3]{\sqrt{\mathsf{fma}\left(\left(x \cdot \frac{1}{\sqrt{\mathsf{fma}\left(p, \left(p \cdot 4\right), \left(x \cdot x\right)\right)}}\right), 0.5, 0.5\right)}} \cdot \sqrt[3]{\sqrt{\mathsf{fma}\left(\left(x \cdot \frac{1}{\sqrt{\mathsf{fma}\left(p, \left(p \cdot 4\right), \left(x \cdot x\right)\right)}}\right), 0.5, 0.5\right)}}\right) \cdot \sqrt[3]{\sqrt{\mathsf{fma}\left(\left(x \cdot \frac{1}{\sqrt{\mathsf{fma}\left(p, \left(p \cdot 4\right), \left(x \cdot x\right)\right)}}\right), 0.5, 0.5\right)}}
double f(double p, double x) {
        double r2853865 = 0.5;
        double r2853866 = 1.0;
        double r2853867 = x;
        double r2853868 = 4.0;
        double r2853869 = p;
        double r2853870 = r2853868 * r2853869;
        double r2853871 = r2853870 * r2853869;
        double r2853872 = r2853867 * r2853867;
        double r2853873 = r2853871 + r2853872;
        double r2853874 = sqrt(r2853873);
        double r2853875 = r2853867 / r2853874;
        double r2853876 = r2853866 + r2853875;
        double r2853877 = r2853865 * r2853876;
        double r2853878 = sqrt(r2853877);
        return r2853878;
}

double f(double p, double x) {
        double r2853879 = x;
        double r2853880 = 1.0;
        double r2853881 = p;
        double r2853882 = 4.0;
        double r2853883 = r2853881 * r2853882;
        double r2853884 = r2853879 * r2853879;
        double r2853885 = fma(r2853881, r2853883, r2853884);
        double r2853886 = sqrt(r2853885);
        double r2853887 = r2853880 / r2853886;
        double r2853888 = r2853879 * r2853887;
        double r2853889 = 0.5;
        double r2853890 = fma(r2853888, r2853889, r2853889);
        double r2853891 = sqrt(r2853890);
        double r2853892 = cbrt(r2853891);
        double r2853893 = r2853892 * r2853892;
        double r2853894 = r2853893 * r2853892;
        return r2853894;
}

Error

Bits error versus p

Bits error versus x

Target

Original12.9
Target12.9
Herbie13.6
\[\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 12.9

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

    \[\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 div-inv13.1

    \[\leadsto \sqrt{\mathsf{fma}\left(\color{blue}{\left(x \cdot \frac{1}{\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-cbrt13.6

    \[\leadsto \color{blue}{\left(\sqrt[3]{\sqrt{\mathsf{fma}\left(\left(x \cdot \frac{1}{\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]{\sqrt{\mathsf{fma}\left(\left(x \cdot \frac{1}{\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]{\sqrt{\mathsf{fma}\left(\left(x \cdot \frac{1}{\sqrt{\mathsf{fma}\left(p, \left(4 \cdot p\right), \left(x \cdot x\right)\right)}}\right), 0.5, 0.5\right)}}}\]
  7. Final simplification13.6

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

Reproduce

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