Average Error: 13.0 → 13.0
Time: 22.8s
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{0.5 \cdot \log \left(e^{1 + \frac{x}{\sqrt{\mathsf{fma}\left(4 \cdot p, p, x \cdot x\right)}}}\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 \log \left(e^{1 + \frac{x}{\sqrt{\mathsf{fma}\left(4 \cdot p, p, x \cdot x\right)}}}\right)}
double f(double p, double x) {
        double r236183 = 0.5;
        double r236184 = 1.0;
        double r236185 = x;
        double r236186 = 4.0;
        double r236187 = p;
        double r236188 = r236186 * r236187;
        double r236189 = r236188 * r236187;
        double r236190 = r236185 * r236185;
        double r236191 = r236189 + r236190;
        double r236192 = sqrt(r236191);
        double r236193 = r236185 / r236192;
        double r236194 = r236184 + r236193;
        double r236195 = r236183 * r236194;
        double r236196 = sqrt(r236195);
        return r236196;
}

double f(double p, double x) {
        double r236197 = 0.5;
        double r236198 = 1.0;
        double r236199 = x;
        double r236200 = 4.0;
        double r236201 = p;
        double r236202 = r236200 * r236201;
        double r236203 = r236199 * r236199;
        double r236204 = fma(r236202, r236201, r236203);
        double r236205 = sqrt(r236204);
        double r236206 = r236199 / r236205;
        double r236207 = r236198 + r236206;
        double r236208 = exp(r236207);
        double r236209 = log(r236208);
        double r236210 = r236197 * r236209;
        double r236211 = sqrt(r236210);
        return r236211;
}

Error

Bits error versus p

Bits error versus x

Target

Original13.0
Target13.0
Herbie13.0
\[\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.0

    \[\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-sqr-sqrt13.0

    \[\leadsto \sqrt{0.5 \cdot \left(1 + \frac{x}{\sqrt{\color{blue}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x} \cdot \sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}}}\right)}\]
  4. Applied sqrt-prod14.1

    \[\leadsto \sqrt{0.5 \cdot \left(1 + \frac{x}{\color{blue}{\sqrt{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}} \cdot \sqrt{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}}}\right)}\]
  5. Simplified14.1

    \[\leadsto \sqrt{0.5 \cdot \left(1 + \frac{x}{\color{blue}{\sqrt{\sqrt{\mathsf{fma}\left(4 \cdot p, p, x \cdot x\right)}}} \cdot \sqrt{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}}\right)}\]
  6. Simplified14.1

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

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

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

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

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

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

Reproduce

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

  :herbie-target
  (sqrt (+ 0.5 (/ (copysign 0.5 x) (hypot 1 (/ (* 2 p) x)))))

  (sqrt (* 0.5 (+ 1 (/ x (sqrt (+ (* (* 4 p) p) (* x x))))))))