Average Error: 13.4 → 13.4
Time: 17.5s
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{\frac{\log \left(e^{{1}^{3} + {\left(\frac{x}{\sqrt{\mathsf{fma}\left(4 \cdot p, p, x \cdot x\right)}}\right)}^{3}}\right)}{\mathsf{fma}\left(1, 1, \frac{x}{\sqrt{\mathsf{fma}\left(4 \cdot p, p, x \cdot x\right)}} \cdot \left(\frac{x}{\sqrt{\mathsf{fma}\left(4 \cdot p, p, x \cdot x\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{\frac{\log \left(e^{{1}^{3} + {\left(\frac{x}{\sqrt{\mathsf{fma}\left(4 \cdot p, p, x \cdot x\right)}}\right)}^{3}}\right)}{\mathsf{fma}\left(1, 1, \frac{x}{\sqrt{\mathsf{fma}\left(4 \cdot p, p, x \cdot x\right)}} \cdot \left(\frac{x}{\sqrt{\mathsf{fma}\left(4 \cdot p, p, x \cdot x\right)}} - 1\right)\right)} \cdot 0.5}
double f(double p, double x) {
        double r195569 = 0.5;
        double r195570 = 1.0;
        double r195571 = x;
        double r195572 = 4.0;
        double r195573 = p;
        double r195574 = r195572 * r195573;
        double r195575 = r195574 * r195573;
        double r195576 = r195571 * r195571;
        double r195577 = r195575 + r195576;
        double r195578 = sqrt(r195577);
        double r195579 = r195571 / r195578;
        double r195580 = r195570 + r195579;
        double r195581 = r195569 * r195580;
        double r195582 = sqrt(r195581);
        return r195582;
}

double f(double p, double x) {
        double r195583 = 1.0;
        double r195584 = 3.0;
        double r195585 = pow(r195583, r195584);
        double r195586 = x;
        double r195587 = 4.0;
        double r195588 = p;
        double r195589 = r195587 * r195588;
        double r195590 = r195586 * r195586;
        double r195591 = fma(r195589, r195588, r195590);
        double r195592 = sqrt(r195591);
        double r195593 = r195586 / r195592;
        double r195594 = pow(r195593, r195584);
        double r195595 = r195585 + r195594;
        double r195596 = exp(r195595);
        double r195597 = log(r195596);
        double r195598 = r195593 - r195583;
        double r195599 = r195593 * r195598;
        double r195600 = fma(r195583, r195583, r195599);
        double r195601 = r195597 / r195600;
        double r195602 = 0.5;
        double r195603 = r195601 * r195602;
        double r195604 = sqrt(r195603);
        return r195604;
}

Error

Bits error versus p

Bits error versus x

Target

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

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

    \[\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-sqr-sqrt13.4

    \[\leadsto \sqrt{\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)}}}} + 1\right) \cdot 0.5}\]
  5. Applied sqrt-prod14.3

    \[\leadsto \sqrt{\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)}}}} + 1\right) \cdot 0.5}\]
  6. Applied associate-/r*14.3

    \[\leadsto \sqrt{\left(\color{blue}{\frac{\frac{x}{\sqrt{\sqrt{\mathsf{fma}\left(4 \cdot p, p, x \cdot x\right)}}}}{\sqrt{\sqrt{\mathsf{fma}\left(4 \cdot p, p, x \cdot x\right)}}}} + 1\right) \cdot 0.5}\]
  7. Using strategy rm
  8. Applied flip3-+14.3

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

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

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

    \[\leadsto \sqrt{\frac{{1}^{3} + \color{blue}{\log \left(e^{{\left(\frac{x}{\sqrt{\mathsf{fma}\left(4 \cdot p, p, x \cdot x\right)}}\right)}^{3}}\right)}}{\mathsf{fma}\left(1, 1, \frac{x}{\sqrt{\mathsf{fma}\left(4 \cdot p, p, x \cdot x\right)}} \cdot \left(\frac{x}{\sqrt{\mathsf{fma}\left(4 \cdot p, p, x \cdot x\right)}} - 1\right)\right)} \cdot 0.5}\]
  13. Applied add-log-exp13.4

    \[\leadsto \sqrt{\frac{\color{blue}{\log \left(e^{{1}^{3}}\right)} + \log \left(e^{{\left(\frac{x}{\sqrt{\mathsf{fma}\left(4 \cdot p, p, x \cdot x\right)}}\right)}^{3}}\right)}{\mathsf{fma}\left(1, 1, \frac{x}{\sqrt{\mathsf{fma}\left(4 \cdot p, p, x \cdot x\right)}} \cdot \left(\frac{x}{\sqrt{\mathsf{fma}\left(4 \cdot p, p, x \cdot x\right)}} - 1\right)\right)} \cdot 0.5}\]
  14. Applied sum-log13.4

    \[\leadsto \sqrt{\frac{\color{blue}{\log \left(e^{{1}^{3}} \cdot e^{{\left(\frac{x}{\sqrt{\mathsf{fma}\left(4 \cdot p, p, x \cdot x\right)}}\right)}^{3}}\right)}}{\mathsf{fma}\left(1, 1, \frac{x}{\sqrt{\mathsf{fma}\left(4 \cdot p, p, x \cdot x\right)}} \cdot \left(\frac{x}{\sqrt{\mathsf{fma}\left(4 \cdot p, p, x \cdot x\right)}} - 1\right)\right)} \cdot 0.5}\]
  15. Simplified13.4

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

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

Reproduce

herbie shell --seed 2019235 +o rules:numerics
(FPCore (p x)
  :name "Given's Rotation SVD example"
  :precision binary64
  :pre (< 1.00000000000000001e-150 (fabs x) 9.99999999999999981e149)

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