Average Error: 12.8 → 13.3
Time: 17.8s
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]{\sqrt{\mathsf{fma}\left(\frac{x}{\sqrt{\mathsf{fma}\left(p, 4 \cdot p, x \cdot x\right)}}, 0.5, 0.5\right)}} \cdot \left(\sqrt[3]{\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[3]{\sqrt{\mathsf{fma}\left(\frac{x}{\sqrt{\mathsf{fma}\left(p, 4 \cdot p, x \cdot x\right)}}, 0.5, 0.5\right)}}\right)\]
\sqrt{0.5 \cdot \left(1 + \frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}\right)}
\sqrt[3]{\sqrt{\mathsf{fma}\left(\frac{x}{\sqrt{\mathsf{fma}\left(p, 4 \cdot p, x \cdot x\right)}}, 0.5, 0.5\right)}} \cdot \left(\sqrt[3]{\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[3]{\sqrt{\mathsf{fma}\left(\frac{x}{\sqrt{\mathsf{fma}\left(p, 4 \cdot p, x \cdot x\right)}}, 0.5, 0.5\right)}}\right)
double f(double p, double x) {
        double r4463601 = 0.5;
        double r4463602 = 1.0;
        double r4463603 = x;
        double r4463604 = 4.0;
        double r4463605 = p;
        double r4463606 = r4463604 * r4463605;
        double r4463607 = r4463606 * r4463605;
        double r4463608 = r4463603 * r4463603;
        double r4463609 = r4463607 + r4463608;
        double r4463610 = sqrt(r4463609);
        double r4463611 = r4463603 / r4463610;
        double r4463612 = r4463602 + r4463611;
        double r4463613 = r4463601 * r4463612;
        double r4463614 = sqrt(r4463613);
        return r4463614;
}

double f(double p, double x) {
        double r4463615 = x;
        double r4463616 = p;
        double r4463617 = 4.0;
        double r4463618 = r4463617 * r4463616;
        double r4463619 = r4463615 * r4463615;
        double r4463620 = fma(r4463616, r4463618, r4463619);
        double r4463621 = sqrt(r4463620);
        double r4463622 = r4463615 / r4463621;
        double r4463623 = 0.5;
        double r4463624 = fma(r4463622, r4463623, r4463623);
        double r4463625 = sqrt(r4463624);
        double r4463626 = cbrt(r4463625);
        double r4463627 = r4463626 * r4463626;
        double r4463628 = r4463626 * r4463627;
        return r4463628;
}

Error

Bits error versus p

Bits error versus x

Target

Original12.8
Target12.8
Herbie13.3
\[\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 12.8

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

    \[\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-cube-cbrt13.3

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

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

Reproduce

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