Average Error: 13.7 → 13.7
Time: 33.7s
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)}\]
\[\log \left(\sqrt{e^{\sqrt{0.5 + \log \left(e^{\frac{x}{\sqrt{\mathsf{fma}\left(p, \left(4 \cdot p\right), \left(x \cdot x\right)\right)}} \cdot 0.5}\right)}}}\right) + \log \left(\sqrt{e^{\sqrt{\mathsf{fma}\left(\left(\frac{x}{\sqrt{\mathsf{fma}\left(p, \left(4 \cdot p\right), \left(x \cdot x\right)\right)}}\right), 0.5, 0.5\right)}}}\right)\]
\sqrt{0.5 \cdot \left(1 + \frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}\right)}
\log \left(\sqrt{e^{\sqrt{0.5 + \log \left(e^{\frac{x}{\sqrt{\mathsf{fma}\left(p, \left(4 \cdot p\right), \left(x \cdot x\right)\right)}} \cdot 0.5}\right)}}}\right) + \log \left(\sqrt{e^{\sqrt{\mathsf{fma}\left(\left(\frac{x}{\sqrt{\mathsf{fma}\left(p, \left(4 \cdot p\right), \left(x \cdot x\right)\right)}}\right), 0.5, 0.5\right)}}}\right)
double f(double p, double x) {
        double r52055566 = 0.5;
        double r52055567 = 1.0;
        double r52055568 = x;
        double r52055569 = 4.0;
        double r52055570 = p;
        double r52055571 = r52055569 * r52055570;
        double r52055572 = r52055571 * r52055570;
        double r52055573 = r52055568 * r52055568;
        double r52055574 = r52055572 + r52055573;
        double r52055575 = sqrt(r52055574);
        double r52055576 = r52055568 / r52055575;
        double r52055577 = r52055567 + r52055576;
        double r52055578 = r52055566 * r52055577;
        double r52055579 = sqrt(r52055578);
        return r52055579;
}

double f(double p, double x) {
        double r52055580 = 0.5;
        double r52055581 = x;
        double r52055582 = p;
        double r52055583 = 4.0;
        double r52055584 = r52055583 * r52055582;
        double r52055585 = r52055581 * r52055581;
        double r52055586 = fma(r52055582, r52055584, r52055585);
        double r52055587 = sqrt(r52055586);
        double r52055588 = r52055581 / r52055587;
        double r52055589 = r52055588 * r52055580;
        double r52055590 = exp(r52055589);
        double r52055591 = log(r52055590);
        double r52055592 = r52055580 + r52055591;
        double r52055593 = sqrt(r52055592);
        double r52055594 = exp(r52055593);
        double r52055595 = sqrt(r52055594);
        double r52055596 = log(r52055595);
        double r52055597 = fma(r52055588, r52055580, r52055580);
        double r52055598 = sqrt(r52055597);
        double r52055599 = exp(r52055598);
        double r52055600 = sqrt(r52055599);
        double r52055601 = log(r52055600);
        double r52055602 = r52055596 + r52055601;
        return r52055602;
}

Error

Bits error versus p

Bits error versus x

Target

Original13.7
Target13.7
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. Simplified13.7

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

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

    \[\leadsto \log \color{blue}{\left(\sqrt{e^{\sqrt{\mathsf{fma}\left(\left(\frac{x}{\sqrt{\mathsf{fma}\left(p, \left(4 \cdot p\right), \left(x \cdot x\right)\right)}}\right), 0.5, 0.5\right)}}} \cdot \sqrt{e^{\sqrt{\mathsf{fma}\left(\left(\frac{x}{\sqrt{\mathsf{fma}\left(p, \left(4 \cdot p\right), \left(x \cdot x\right)\right)}}\right), 0.5, 0.5\right)}}}\right)}\]
  7. Applied log-prod13.7

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

    \[\leadsto \log \left(\sqrt{e^{\sqrt{\mathsf{fma}\left(\left(\frac{x}{\sqrt{\mathsf{fma}\left(p, \left(4 \cdot p\right), \left(x \cdot x\right)\right)}}\right), 0.5, 0.5\right)}}}\right) + \log \left(\sqrt{e^{\sqrt{\color{blue}{\log \left(e^{\mathsf{fma}\left(\left(\frac{x}{\sqrt{\mathsf{fma}\left(p, \left(4 \cdot p\right), \left(x \cdot x\right)\right)}}\right), 0.5, 0.5\right)}\right)}}}}\right)\]
  10. Using strategy rm
  11. Applied fma-udef13.7

    \[\leadsto \log \left(\sqrt{e^{\sqrt{\mathsf{fma}\left(\left(\frac{x}{\sqrt{\mathsf{fma}\left(p, \left(4 \cdot p\right), \left(x \cdot x\right)\right)}}\right), 0.5, 0.5\right)}}}\right) + \log \left(\sqrt{e^{\sqrt{\log \left(e^{\color{blue}{\frac{x}{\sqrt{\mathsf{fma}\left(p, \left(4 \cdot p\right), \left(x \cdot x\right)\right)}} \cdot 0.5 + 0.5}}\right)}}}\right)\]
  12. Applied exp-sum13.7

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

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

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

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

Reproduce

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