Average Error: 13.9 → 13.9
Time: 16.0s
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 r12698084 = 0.5;
        double r12698085 = 1.0;
        double r12698086 = x;
        double r12698087 = 4.0;
        double r12698088 = p;
        double r12698089 = r12698087 * r12698088;
        double r12698090 = r12698089 * r12698088;
        double r12698091 = r12698086 * r12698086;
        double r12698092 = r12698090 + r12698091;
        double r12698093 = sqrt(r12698092);
        double r12698094 = r12698086 / r12698093;
        double r12698095 = r12698085 + r12698094;
        double r12698096 = r12698084 * r12698095;
        double r12698097 = sqrt(r12698096);
        return r12698097;
}

double f(double p, double x) {
        double r12698098 = x;
        double r12698099 = p;
        double r12698100 = r12698099 * r12698099;
        double r12698101 = 4.0;
        double r12698102 = r12698098 * r12698098;
        double r12698103 = fma(r12698100, r12698101, r12698102);
        double r12698104 = sqrt(r12698103);
        double r12698105 = r12698098 / r12698104;
        double r12698106 = 1.0;
        double r12698107 = r12698105 + r12698106;
        double r12698108 = exp(r12698107);
        double r12698109 = log(r12698108);
        double r12698110 = 0.5;
        double r12698111 = r12698109 * r12698110;
        double r12698112 = sqrt(r12698111);
        return r12698112;
}

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))))))))