Average Error: 12.9 → 13.9
Time: 15.5s
Precision: 64
\[1.00000000000000001 \cdot 10^{-150} \lt \left|x\right| \lt 9.99999999999999981 \cdot 10^{149}\]
\[\sqrt{0.5 \cdot \left(1 + \frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}\right)}\]
\[\sqrt{\left(\frac{x}{\sqrt{\sqrt{\mathsf{fma}\left(4 \cdot p, p, x \cdot x\right)}} \cdot \sqrt{\sqrt{\mathsf{fma}\left(4 \cdot p, p, x \cdot x\right)}}} + 1\right) \cdot 0.5}\]
\sqrt{0.5 \cdot \left(1 + \frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}\right)}
\sqrt{\left(\frac{x}{\sqrt{\sqrt{\mathsf{fma}\left(4 \cdot p, p, x \cdot x\right)}} \cdot \sqrt{\sqrt{\mathsf{fma}\left(4 \cdot p, p, x \cdot x\right)}}} + 1\right) \cdot 0.5}
double f(double p, double x) {
        double r369871 = 0.5;
        double r369872 = 1.0;
        double r369873 = x;
        double r369874 = 4.0;
        double r369875 = p;
        double r369876 = r369874 * r369875;
        double r369877 = r369876 * r369875;
        double r369878 = r369873 * r369873;
        double r369879 = r369877 + r369878;
        double r369880 = sqrt(r369879);
        double r369881 = r369873 / r369880;
        double r369882 = r369872 + r369881;
        double r369883 = r369871 * r369882;
        double r369884 = sqrt(r369883);
        return r369884;
}

double f(double p, double x) {
        double r369885 = x;
        double r369886 = 4.0;
        double r369887 = p;
        double r369888 = r369886 * r369887;
        double r369889 = r369885 * r369885;
        double r369890 = fma(r369888, r369887, r369889);
        double r369891 = sqrt(r369890);
        double r369892 = sqrt(r369891);
        double r369893 = r369892 * r369892;
        double r369894 = r369885 / r369893;
        double r369895 = 1.0;
        double r369896 = r369894 + r369895;
        double r369897 = 0.5;
        double r369898 = r369896 * r369897;
        double r369899 = sqrt(r369898);
        return r369899;
}

Error

Bits error versus p

Bits error versus x

Target

Original12.9
Target12.9
Herbie13.9
\[\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 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{\left(\frac{x}{\sqrt{\mathsf{fma}\left(4 \cdot p, p, x \cdot x\right)}} + 1\right) \cdot 0.5}}\]
  3. Using strategy rm
  4. Applied add-sqr-sqrt12.9

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

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

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

Reproduce

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