Average Error: 13.7 → 13.7
Time: 18.3s
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{\sqrt[3]{\left(\frac{x}{\sqrt{\mathsf{fma}\left(\left(p \cdot p\right), 4, \left(x \cdot x\right)\right)}} + 1\right) \cdot \left(\left(\frac{x}{\sqrt{\mathsf{fma}\left(\left(p \cdot p\right), 4, \left(x \cdot x\right)\right)}} + 1\right) \cdot \left(\frac{x}{\sqrt{\mathsf{fma}\left(\left(p \cdot p\right), 4, \left(x \cdot x\right)\right)}} + 1\right)\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{\sqrt[3]{\left(\frac{x}{\sqrt{\mathsf{fma}\left(\left(p \cdot p\right), 4, \left(x \cdot x\right)\right)}} + 1\right) \cdot \left(\left(\frac{x}{\sqrt{\mathsf{fma}\left(\left(p \cdot p\right), 4, \left(x \cdot x\right)\right)}} + 1\right) \cdot \left(\frac{x}{\sqrt{\mathsf{fma}\left(\left(p \cdot p\right), 4, \left(x \cdot x\right)\right)}} + 1\right)\right)} \cdot 0.5}
double f(double p, double x) {
        double r5677503 = 0.5;
        double r5677504 = 1.0;
        double r5677505 = x;
        double r5677506 = 4.0;
        double r5677507 = p;
        double r5677508 = r5677506 * r5677507;
        double r5677509 = r5677508 * r5677507;
        double r5677510 = r5677505 * r5677505;
        double r5677511 = r5677509 + r5677510;
        double r5677512 = sqrt(r5677511);
        double r5677513 = r5677505 / r5677512;
        double r5677514 = r5677504 + r5677513;
        double r5677515 = r5677503 * r5677514;
        double r5677516 = sqrt(r5677515);
        return r5677516;
}

double f(double p, double x) {
        double r5677517 = x;
        double r5677518 = p;
        double r5677519 = r5677518 * r5677518;
        double r5677520 = 4.0;
        double r5677521 = r5677517 * r5677517;
        double r5677522 = fma(r5677519, r5677520, r5677521);
        double r5677523 = sqrt(r5677522);
        double r5677524 = r5677517 / r5677523;
        double r5677525 = 1.0;
        double r5677526 = r5677524 + r5677525;
        double r5677527 = r5677526 * r5677526;
        double r5677528 = r5677526 * r5677527;
        double r5677529 = cbrt(r5677528);
        double r5677530 = 0.5;
        double r5677531 = r5677529 * r5677530;
        double r5677532 = sqrt(r5677531);
        return r5677532;
}

Error

Bits error versus p

Bits error versus x

Target

Original13.7
Target13.6
Herbie13.7
\[\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 13.7

    \[\sqrt{0.5 \cdot \left(1 + \frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}\right)}\]
  2. Using strategy rm
  3. Applied div-inv13.9

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

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

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

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

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

Reproduce

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