Average Error: 13.4 → 13.4
Time: 16.8s
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{e^{\sqrt[3]{{\left(\log \left(\frac{x}{\sqrt{\mathsf{fma}\left(4 \cdot p, p, x \cdot x\right)}} + 1\right)\right)}^{3}}} \cdot 0.5}\]
\sqrt{0.5 \cdot \left(1 + \frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}\right)}
\sqrt{e^{\sqrt[3]{{\left(\log \left(\frac{x}{\sqrt{\mathsf{fma}\left(4 \cdot p, p, x \cdot x\right)}} + 1\right)\right)}^{3}}} \cdot 0.5}
double f(double p, double x) {
        double r219640 = 0.5;
        double r219641 = 1.0;
        double r219642 = x;
        double r219643 = 4.0;
        double r219644 = p;
        double r219645 = r219643 * r219644;
        double r219646 = r219645 * r219644;
        double r219647 = r219642 * r219642;
        double r219648 = r219646 + r219647;
        double r219649 = sqrt(r219648);
        double r219650 = r219642 / r219649;
        double r219651 = r219641 + r219650;
        double r219652 = r219640 * r219651;
        double r219653 = sqrt(r219652);
        return r219653;
}

double f(double p, double x) {
        double r219654 = x;
        double r219655 = 4.0;
        double r219656 = p;
        double r219657 = r219655 * r219656;
        double r219658 = r219654 * r219654;
        double r219659 = fma(r219657, r219656, r219658);
        double r219660 = sqrt(r219659);
        double r219661 = r219654 / r219660;
        double r219662 = 1.0;
        double r219663 = r219661 + r219662;
        double r219664 = log(r219663);
        double r219665 = 3.0;
        double r219666 = pow(r219664, r219665);
        double r219667 = cbrt(r219666);
        double r219668 = exp(r219667);
        double r219669 = 0.5;
        double r219670 = r219668 * r219669;
        double r219671 = sqrt(r219670);
        return r219671;
}

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-exp-log13.4

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

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

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

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

Reproduce

herbie shell --seed 2019198 +o rules:numerics
(FPCore (p x)
  :name "Given's Rotation SVD example"
  :pre (< 1e-150 (fabs x) 1e+150)

  :herbie-target
  (sqrt (+ 0.5 (/ (copysign 0.5 x) (hypot 1.0 (/ (* 2.0 p) x)))))

  (sqrt (* 0.5 (+ 1.0 (/ x (sqrt (+ (* (* 4.0 p) p) (* x x))))))))