Average Error: 12.9 → 13.1
Time: 31.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)}\]
\[\sqrt{0.5 \cdot \left(\left(\sqrt[3]{\log \left(e^{\frac{x}{\sqrt{\mathsf{fma}\left(4, p \cdot p, x \cdot x\right)}}} \cdot e\right)} \cdot \sqrt[3]{\log \left(e^{\frac{x}{\sqrt{\mathsf{fma}\left(4, p \cdot p, x \cdot x\right)}}} \cdot e\right)}\right) \cdot \sqrt[3]{\frac{x}{\sqrt{\mathsf{fma}\left(4, p \cdot p, x \cdot x\right)}} + 1}\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 \left(\left(\sqrt[3]{\log \left(e^{\frac{x}{\sqrt{\mathsf{fma}\left(4, p \cdot p, x \cdot x\right)}}} \cdot e\right)} \cdot \sqrt[3]{\log \left(e^{\frac{x}{\sqrt{\mathsf{fma}\left(4, p \cdot p, x \cdot x\right)}}} \cdot e\right)}\right) \cdot \sqrt[3]{\frac{x}{\sqrt{\mathsf{fma}\left(4, p \cdot p, x \cdot x\right)}} + 1}\right)}
double f(double p, double x) {
        double r4107263 = 0.5;
        double r4107264 = 1.0;
        double r4107265 = x;
        double r4107266 = 4.0;
        double r4107267 = p;
        double r4107268 = r4107266 * r4107267;
        double r4107269 = r4107268 * r4107267;
        double r4107270 = r4107265 * r4107265;
        double r4107271 = r4107269 + r4107270;
        double r4107272 = sqrt(r4107271);
        double r4107273 = r4107265 / r4107272;
        double r4107274 = r4107264 + r4107273;
        double r4107275 = r4107263 * r4107274;
        double r4107276 = sqrt(r4107275);
        return r4107276;
}

double f(double p, double x) {
        double r4107277 = 0.5;
        double r4107278 = x;
        double r4107279 = 4.0;
        double r4107280 = p;
        double r4107281 = r4107280 * r4107280;
        double r4107282 = r4107278 * r4107278;
        double r4107283 = fma(r4107279, r4107281, r4107282);
        double r4107284 = sqrt(r4107283);
        double r4107285 = r4107278 / r4107284;
        double r4107286 = exp(r4107285);
        double r4107287 = exp(1.0);
        double r4107288 = r4107286 * r4107287;
        double r4107289 = log(r4107288);
        double r4107290 = cbrt(r4107289);
        double r4107291 = r4107290 * r4107290;
        double r4107292 = 1.0;
        double r4107293 = r4107285 + r4107292;
        double r4107294 = cbrt(r4107293);
        double r4107295 = r4107291 * r4107294;
        double r4107296 = r4107277 * r4107295;
        double r4107297 = sqrt(r4107296);
        return r4107297;
}

Error

Bits error versus p

Bits error versus x

Target

Original12.9
Target12.9
Herbie13.1
\[\sqrt{\frac{1}{2} + \frac{\mathsf{copysign}\left(\frac{1}{2}, x\right)}{\mathsf{hypot}\left(1, \frac{2 \cdot p}{x}\right)}}\]

Derivation

  1. Initial program 12.9

    \[\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 add-log-exp12.9

    \[\leadsto \sqrt{0.5 \cdot \left(1 + \color{blue}{\log \left(e^{\frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}}\right)}\right)}\]
  4. Applied add-log-exp12.9

    \[\leadsto \sqrt{0.5 \cdot \left(\color{blue}{\log \left(e^{1}\right)} + \log \left(e^{\frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}}\right)\right)}\]
  5. Applied sum-log12.9

    \[\leadsto \sqrt{0.5 \cdot \color{blue}{\log \left(e^{1} \cdot e^{\frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}}\right)}}\]
  6. Simplified12.9

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

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

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

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

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

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

Reproduce

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