Average Error: 13.3 → 13.3
Time: 18.3s
Precision: 64
\[1.000000000000000006295358232172963997211 \cdot 10^{-150} \lt \left|x\right| \lt 9.999999999999999808355961724373745905731 \cdot 10^{149}\]
\[\sqrt{0.5 \cdot \left(1 + \frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}\right)}\]
\[\sqrt[3]{\sqrt{\left(1 + \frac{x}{\sqrt{\mathsf{fma}\left(4 \cdot p, p, x \cdot x\right)}}\right) \cdot 0.5} \cdot \left(\left(1 + \frac{x}{\sqrt{\mathsf{fma}\left(4 \cdot p, p, x \cdot x\right)}}\right) \cdot 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]{\sqrt{\left(1 + \frac{x}{\sqrt{\mathsf{fma}\left(4 \cdot p, p, x \cdot x\right)}}\right) \cdot 0.5} \cdot \left(\left(1 + \frac{x}{\sqrt{\mathsf{fma}\left(4 \cdot p, p, x \cdot x\right)}}\right) \cdot 0.5\right)}
double f(double p, double x) {
        double r14885615 = 0.5;
        double r14885616 = 1.0;
        double r14885617 = x;
        double r14885618 = 4.0;
        double r14885619 = p;
        double r14885620 = r14885618 * r14885619;
        double r14885621 = r14885620 * r14885619;
        double r14885622 = r14885617 * r14885617;
        double r14885623 = r14885621 + r14885622;
        double r14885624 = sqrt(r14885623);
        double r14885625 = r14885617 / r14885624;
        double r14885626 = r14885616 + r14885625;
        double r14885627 = r14885615 * r14885626;
        double r14885628 = sqrt(r14885627);
        return r14885628;
}

double f(double p, double x) {
        double r14885629 = 1.0;
        double r14885630 = x;
        double r14885631 = 4.0;
        double r14885632 = p;
        double r14885633 = r14885631 * r14885632;
        double r14885634 = r14885630 * r14885630;
        double r14885635 = fma(r14885633, r14885632, r14885634);
        double r14885636 = sqrt(r14885635);
        double r14885637 = r14885630 / r14885636;
        double r14885638 = r14885629 + r14885637;
        double r14885639 = 0.5;
        double r14885640 = r14885638 * r14885639;
        double r14885641 = sqrt(r14885640);
        double r14885642 = r14885641 * r14885640;
        double r14885643 = cbrt(r14885642);
        return r14885643;
}

Error

Bits error versus p

Bits error versus x

Target

Original13.3
Target13.3
Herbie13.3
\[\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 13.3

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

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

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

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

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

Reproduce

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

  :herbie-target
  (sqrt (+ 0.5 (/ (copysign 0.5 x) (hypot 1.0 (/ (* 2.0 p) x)))))

  (sqrt (* 0.5 (+ 1.0 (/ x (sqrt (+ (* (* 4.0 p) p) (* x x))))))))