Average Error: 13.1 → 13.1
Time: 4.7s
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 \frac{{1}^{3} + {\left(\frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}\right)}^{3}}{\mathsf{fma}\left(\frac{\frac{x}{\sqrt{\mathsf{fma}\left(4 \cdot p, p, x \cdot x\right)}}}{\sqrt{\mathsf{fma}\left(4 \cdot p, p, x \cdot x\right)}}, x, 1 \cdot \left(1 - \frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}\right)\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 \frac{{1}^{3} + {\left(\frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}\right)}^{3}}{\mathsf{fma}\left(\frac{\frac{x}{\sqrt{\mathsf{fma}\left(4 \cdot p, p, x \cdot x\right)}}}{\sqrt{\mathsf{fma}\left(4 \cdot p, p, x \cdot x\right)}}, x, 1 \cdot \left(1 - \frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}\right)\right)}}
double f(double p, double x) {
        double r307585 = 0.5;
        double r307586 = 1.0;
        double r307587 = x;
        double r307588 = 4.0;
        double r307589 = p;
        double r307590 = r307588 * r307589;
        double r307591 = r307590 * r307589;
        double r307592 = r307587 * r307587;
        double r307593 = r307591 + r307592;
        double r307594 = sqrt(r307593);
        double r307595 = r307587 / r307594;
        double r307596 = r307586 + r307595;
        double r307597 = r307585 * r307596;
        double r307598 = sqrt(r307597);
        return r307598;
}

double f(double p, double x) {
        double r307599 = 0.5;
        double r307600 = 1.0;
        double r307601 = 3.0;
        double r307602 = pow(r307600, r307601);
        double r307603 = x;
        double r307604 = 4.0;
        double r307605 = p;
        double r307606 = r307604 * r307605;
        double r307607 = r307606 * r307605;
        double r307608 = r307603 * r307603;
        double r307609 = r307607 + r307608;
        double r307610 = sqrt(r307609);
        double r307611 = r307603 / r307610;
        double r307612 = pow(r307611, r307601);
        double r307613 = r307602 + r307612;
        double r307614 = fma(r307606, r307605, r307608);
        double r307615 = sqrt(r307614);
        double r307616 = r307603 / r307615;
        double r307617 = r307616 / r307615;
        double r307618 = r307600 - r307611;
        double r307619 = r307600 * r307618;
        double r307620 = fma(r307617, r307603, r307619);
        double r307621 = r307613 / r307620;
        double r307622 = r307599 * r307621;
        double r307623 = sqrt(r307622);
        return r307623;
}

Error

Bits error versus p

Bits error versus x

Target

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

    \[\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 flip3-+13.1

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

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

    \[\leadsto \sqrt{0.5 \cdot \frac{{1}^{3} + {\left(\frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}\right)}^{3}}{\mathsf{fma}\left(\frac{x}{\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)}}}, x, 1 \cdot \left(1 - \frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}\right)\right)}}\]
  7. Applied associate-/r*13.1

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

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

Reproduce

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