Average Error: 13.9 → 13.9
Time: 15.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{\log \left(e^{\frac{x}{\sqrt{\mathsf{fma}\left(p \cdot p, 4, x \cdot x\right)}} + 1}\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{\log \left(e^{\frac{x}{\sqrt{\mathsf{fma}\left(p \cdot p, 4, x \cdot x\right)}} + 1}\right) \cdot 0.5}
double f(double p, double x) {
        double r8865536 = 0.5;
        double r8865537 = 1.0;
        double r8865538 = x;
        double r8865539 = 4.0;
        double r8865540 = p;
        double r8865541 = r8865539 * r8865540;
        double r8865542 = r8865541 * r8865540;
        double r8865543 = r8865538 * r8865538;
        double r8865544 = r8865542 + r8865543;
        double r8865545 = sqrt(r8865544);
        double r8865546 = r8865538 / r8865545;
        double r8865547 = r8865537 + r8865546;
        double r8865548 = r8865536 * r8865547;
        double r8865549 = sqrt(r8865548);
        return r8865549;
}

double f(double p, double x) {
        double r8865550 = x;
        double r8865551 = p;
        double r8865552 = r8865551 * r8865551;
        double r8865553 = 4.0;
        double r8865554 = r8865550 * r8865550;
        double r8865555 = fma(r8865552, r8865553, r8865554);
        double r8865556 = sqrt(r8865555);
        double r8865557 = r8865550 / r8865556;
        double r8865558 = 1.0;
        double r8865559 = r8865557 + r8865558;
        double r8865560 = exp(r8865559);
        double r8865561 = log(r8865560);
        double r8865562 = 0.5;
        double r8865563 = r8865561 * r8865562;
        double r8865564 = sqrt(r8865563);
        return r8865564;
}

Error

Bits error versus p

Bits error versus x

Target

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

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

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

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

    \[\leadsto \sqrt{\left(1 + x \cdot \color{blue}{\left(\sqrt{\frac{1}{\sqrt{\mathsf{fma}\left(p, 4 \cdot p, x \cdot x\right)}}} \cdot \sqrt{\frac{1}{\sqrt{\mathsf{fma}\left(p, 4 \cdot p, x \cdot x\right)}}}\right)}\right) \cdot 0.5}\]
  7. Applied associate-*r*15.0

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

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

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

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

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

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

Reproduce

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