Average Error: 12.9 → 14.0
Time: 5.3s
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{0.5 \cdot \left(1 + \frac{1}{\sqrt{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}} \cdot \frac{x}{\sqrt{\left|\sqrt[3]{\left(4 \cdot p\right) \cdot p + x \cdot x}\right| \cdot \sqrt{\sqrt[3]{\left(4 \cdot p\right) \cdot p + x \cdot x}}}}\right)}\]
\sqrt{0.5 \cdot \left(1 + \frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}\right)}
\sqrt{0.5 \cdot \left(1 + \frac{1}{\sqrt{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}} \cdot \frac{x}{\sqrt{\left|\sqrt[3]{\left(4 \cdot p\right) \cdot p + x \cdot x}\right| \cdot \sqrt{\sqrt[3]{\left(4 \cdot p\right) \cdot p + x \cdot x}}}}\right)}
double f(double p, double x) {
        double r348555 = 0.5;
        double r348556 = 1.0;
        double r348557 = x;
        double r348558 = 4.0;
        double r348559 = p;
        double r348560 = r348558 * r348559;
        double r348561 = r348560 * r348559;
        double r348562 = r348557 * r348557;
        double r348563 = r348561 + r348562;
        double r348564 = sqrt(r348563);
        double r348565 = r348557 / r348564;
        double r348566 = r348556 + r348565;
        double r348567 = r348555 * r348566;
        double r348568 = sqrt(r348567);
        return r348568;
}

double f(double p, double x) {
        double r348569 = 0.5;
        double r348570 = 1.0;
        double r348571 = 1.0;
        double r348572 = 4.0;
        double r348573 = p;
        double r348574 = r348572 * r348573;
        double r348575 = r348574 * r348573;
        double r348576 = x;
        double r348577 = r348576 * r348576;
        double r348578 = r348575 + r348577;
        double r348579 = sqrt(r348578);
        double r348580 = sqrt(r348579);
        double r348581 = r348571 / r348580;
        double r348582 = cbrt(r348578);
        double r348583 = fabs(r348582);
        double r348584 = sqrt(r348582);
        double r348585 = r348583 * r348584;
        double r348586 = sqrt(r348585);
        double r348587 = r348576 / r348586;
        double r348588 = r348581 * r348587;
        double r348589 = r348570 + r348588;
        double r348590 = r348569 * r348589;
        double r348591 = sqrt(r348590);
        return r348591;
}

Error

Bits error versus p

Bits error versus x

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original12.9
Target12.9
Herbie14.0
\[\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. Using strategy rm
  3. Applied add-sqr-sqrt12.9

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

    \[\leadsto \sqrt{0.5 \cdot \left(1 + \frac{x}{\color{blue}{\sqrt{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}} \cdot \sqrt{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}}}\right)}\]
  5. Applied *-un-lft-identity13.9

    \[\leadsto \sqrt{0.5 \cdot \left(1 + \frac{\color{blue}{1 \cdot x}}{\sqrt{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}} \cdot \sqrt{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}}\right)}\]
  6. Applied times-frac13.9

    \[\leadsto \sqrt{0.5 \cdot \left(1 + \color{blue}{\frac{1}{\sqrt{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}} \cdot \frac{x}{\sqrt{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}}}\right)}\]
  7. Using strategy rm
  8. Applied add-cube-cbrt14.0

    \[\leadsto \sqrt{0.5 \cdot \left(1 + \frac{1}{\sqrt{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}} \cdot \frac{x}{\sqrt{\sqrt{\color{blue}{\left(\sqrt[3]{\left(4 \cdot p\right) \cdot p + x \cdot x} \cdot \sqrt[3]{\left(4 \cdot p\right) \cdot p + x \cdot x}\right) \cdot \sqrt[3]{\left(4 \cdot p\right) \cdot p + x \cdot x}}}}}\right)}\]
  9. Applied sqrt-prod14.0

    \[\leadsto \sqrt{0.5 \cdot \left(1 + \frac{1}{\sqrt{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}} \cdot \frac{x}{\sqrt{\color{blue}{\sqrt{\sqrt[3]{\left(4 \cdot p\right) \cdot p + x \cdot x} \cdot \sqrt[3]{\left(4 \cdot p\right) \cdot p + x \cdot x}} \cdot \sqrt{\sqrt[3]{\left(4 \cdot p\right) \cdot p + x \cdot x}}}}}\right)}\]
  10. Simplified14.0

    \[\leadsto \sqrt{0.5 \cdot \left(1 + \frac{1}{\sqrt{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}} \cdot \frac{x}{\sqrt{\color{blue}{\left|\sqrt[3]{\left(4 \cdot p\right) \cdot p + x \cdot x}\right|} \cdot \sqrt{\sqrt[3]{\left(4 \cdot p\right) \cdot p + x \cdot x}}}}\right)}\]
  11. Final simplification14.0

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

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))))))))