Average Error: 13.9 → 13.9
Time: 16.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{\log \left(e^{1 + \frac{x}{\sqrt{\mathsf{fma}\left(p, p \cdot 4, x \cdot x\right)}}}\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^{1 + \frac{x}{\sqrt{\mathsf{fma}\left(p, p \cdot 4, x \cdot x\right)}}}\right) \cdot 0.5}
double f(double p, double x) {
        double r7755383 = 0.5;
        double r7755384 = 1.0;
        double r7755385 = x;
        double r7755386 = 4.0;
        double r7755387 = p;
        double r7755388 = r7755386 * r7755387;
        double r7755389 = r7755388 * r7755387;
        double r7755390 = r7755385 * r7755385;
        double r7755391 = r7755389 + r7755390;
        double r7755392 = sqrt(r7755391);
        double r7755393 = r7755385 / r7755392;
        double r7755394 = r7755384 + r7755393;
        double r7755395 = r7755383 * r7755394;
        double r7755396 = sqrt(r7755395);
        return r7755396;
}

double f(double p, double x) {
        double r7755397 = 1.0;
        double r7755398 = x;
        double r7755399 = p;
        double r7755400 = 4.0;
        double r7755401 = r7755399 * r7755400;
        double r7755402 = r7755398 * r7755398;
        double r7755403 = fma(r7755399, r7755401, r7755402);
        double r7755404 = sqrt(r7755403);
        double r7755405 = r7755398 / r7755404;
        double r7755406 = r7755397 + r7755405;
        double r7755407 = exp(r7755406);
        double r7755408 = log(r7755407);
        double r7755409 = 0.5;
        double r7755410 = r7755408 * r7755409;
        double r7755411 = sqrt(r7755410);
        return r7755411;
}

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 add-log-exp13.9

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

    \[\leadsto \sqrt{\log \left(e^{1 + \frac{x}{\sqrt{\mathsf{fma}\left(p, p \cdot 4, x \cdot x\right)}}}\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))))))))