Average Error: 13.1 → 13.1
Time: 18.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)}\]
\[\log \left(e^{\sqrt{\mathsf{expm1}\left(\mathsf{log1p}\left(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{\mathsf{expm1}\left(\mathsf{log1p}\left(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 r235319 = 0.5;
        double r235320 = 1.0;
        double r235321 = x;
        double r235322 = 4.0;
        double r235323 = p;
        double r235324 = r235322 * r235323;
        double r235325 = r235324 * r235323;
        double r235326 = r235321 * r235321;
        double r235327 = r235325 + r235326;
        double r235328 = sqrt(r235327);
        double r235329 = r235321 / r235328;
        double r235330 = r235320 + r235329;
        double r235331 = r235319 * r235330;
        double r235332 = sqrt(r235331);
        return r235332;
}

double f(double p, double x) {
        double r235333 = 1.0;
        double r235334 = x;
        double r235335 = 4.0;
        double r235336 = p;
        double r235337 = r235335 * r235336;
        double r235338 = r235334 * r235334;
        double r235339 = fma(r235337, r235336, r235338);
        double r235340 = sqrt(r235339);
        double r235341 = r235334 / r235340;
        double r235342 = r235333 + r235341;
        double r235343 = log1p(r235342);
        double r235344 = expm1(r235343);
        double r235345 = 0.5;
        double r235346 = r235344 * r235345;
        double r235347 = sqrt(r235346);
        double r235348 = exp(r235347);
        double r235349 = log(r235348);
        return r235349;
}

Error

Bits error versus p

Bits error versus x

Target

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

    \[\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-exp13.1

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

    \[\leadsto \log \color{blue}{\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 div-inv13.3

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

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

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

    \[\leadsto \log \left(e^{\sqrt{\mathsf{expm1}\left(\mathsf{log1p}\left(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 2019322 +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))))))))