Average Error: 13.6 → 13.7
Time: 10.4s
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{\left(\sqrt[3]{{\left(\frac{x}{\sqrt{\sqrt{\mathsf{fma}\left(4 \cdot p, p, x \cdot x\right)}} \cdot \sqrt{\sqrt{\mathsf{fma}\left(4 \cdot p, p, x \cdot x\right)}}}\right)}^{3}} + 1\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{\left(\sqrt[3]{{\left(\frac{x}{\sqrt{\sqrt{\mathsf{fma}\left(4 \cdot p, p, x \cdot x\right)}} \cdot \sqrt{\sqrt{\mathsf{fma}\left(4 \cdot p, p, x \cdot x\right)}}}\right)}^{3}} + 1\right) \cdot 0.5}
double f(double p, double x) {
        double r541660 = 0.5;
        double r541661 = 1.0;
        double r541662 = x;
        double r541663 = 4.0;
        double r541664 = p;
        double r541665 = r541663 * r541664;
        double r541666 = r541665 * r541664;
        double r541667 = r541662 * r541662;
        double r541668 = r541666 + r541667;
        double r541669 = sqrt(r541668);
        double r541670 = r541662 / r541669;
        double r541671 = r541661 + r541670;
        double r541672 = r541660 * r541671;
        double r541673 = sqrt(r541672);
        return r541673;
}

double f(double p, double x) {
        double r541674 = x;
        double r541675 = 4.0;
        double r541676 = p;
        double r541677 = r541675 * r541676;
        double r541678 = r541674 * r541674;
        double r541679 = fma(r541677, r541676, r541678);
        double r541680 = sqrt(r541679);
        double r541681 = sqrt(r541680);
        double r541682 = r541681 * r541681;
        double r541683 = r541674 / r541682;
        double r541684 = 3.0;
        double r541685 = pow(r541683, r541684);
        double r541686 = cbrt(r541685);
        double r541687 = 1.0;
        double r541688 = r541686 + r541687;
        double r541689 = 0.5;
        double r541690 = r541688 * r541689;
        double r541691 = sqrt(r541690);
        return r541691;
}

Error

Bits error versus p

Bits error versus x

Target

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

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

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

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

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

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

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

    \[\leadsto \sqrt{\left(\sqrt[3]{{\left(\frac{x}{\sqrt{\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)}}}}\right)}^{3}} + 1\right) \cdot 0.5}\]
  10. Applied sqrt-prod13.7

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

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

Reproduce

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