Average Error: 13.6 → 13.9
Time: 16.9s
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)}\]
\[\log \left(e^{\sqrt{\left(\left(\sqrt[3]{1 + \frac{x}{\sqrt{\mathsf{fma}\left(4 \cdot p, p, x \cdot x\right)}}} \cdot \sqrt[3]{1 + \frac{x}{\sqrt{\mathsf{fma}\left(4 \cdot p, p, x \cdot x\right)}}}\right) \cdot \sqrt[3]{\log \left(e^{1 + \frac{x}{\sqrt{\mathsf{fma}\left(4 \cdot p, p, x \cdot x\right)}}}\right)}\right) \cdot 0.5}}\right)\]
\sqrt{0.5 \cdot \left(1 + \frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}\right)}
\log \left(e^{\sqrt{\left(\left(\sqrt[3]{1 + \frac{x}{\sqrt{\mathsf{fma}\left(4 \cdot p, p, x \cdot x\right)}}} \cdot \sqrt[3]{1 + \frac{x}{\sqrt{\mathsf{fma}\left(4 \cdot p, p, x \cdot x\right)}}}\right) \cdot \sqrt[3]{\log \left(e^{1 + \frac{x}{\sqrt{\mathsf{fma}\left(4 \cdot p, p, x \cdot x\right)}}}\right)}\right) \cdot 0.5}}\right)
double f(double p, double x) {
        double r129386 = 0.5;
        double r129387 = 1.0;
        double r129388 = x;
        double r129389 = 4.0;
        double r129390 = p;
        double r129391 = r129389 * r129390;
        double r129392 = r129391 * r129390;
        double r129393 = r129388 * r129388;
        double r129394 = r129392 + r129393;
        double r129395 = sqrt(r129394);
        double r129396 = r129388 / r129395;
        double r129397 = r129387 + r129396;
        double r129398 = r129386 * r129397;
        double r129399 = sqrt(r129398);
        return r129399;
}

double f(double p, double x) {
        double r129400 = 1.0;
        double r129401 = x;
        double r129402 = 4.0;
        double r129403 = p;
        double r129404 = r129402 * r129403;
        double r129405 = r129401 * r129401;
        double r129406 = fma(r129404, r129403, r129405);
        double r129407 = sqrt(r129406);
        double r129408 = r129401 / r129407;
        double r129409 = r129400 + r129408;
        double r129410 = cbrt(r129409);
        double r129411 = r129410 * r129410;
        double r129412 = exp(r129409);
        double r129413 = log(r129412);
        double r129414 = cbrt(r129413);
        double r129415 = r129411 * r129414;
        double r129416 = 0.5;
        double r129417 = r129415 * r129416;
        double r129418 = sqrt(r129417);
        double r129419 = exp(r129418);
        double r129420 = log(r129419);
        return r129420;
}

Error

Bits error versus p

Bits error versus x

Target

Original13.6
Target13.6
Herbie13.9
\[\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(1 + \frac{x}{\sqrt{\mathsf{fma}\left(4 \cdot p, p, x \cdot x\right)}}\right) \cdot 0.5}}\]
  3. Using strategy rm
  4. Applied add-log-exp13.6

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

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

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

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

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

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

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

Reproduce

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