Average Error: 13.1 → 14.0
Time: 26.8s
Precision: 64
\[10^{-150} \lt \left|x\right| \lt 10^{+150}\]
\[\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{fma}\left(\left(x \cdot \frac{1}{\sqrt{\sqrt{\mathsf{fma}\left(p, \left(p \cdot 4\right), \left(x \cdot x\right)\right)}} \cdot \sqrt{\sqrt{\mathsf{fma}\left(p, \left(p \cdot 4\right), \left(x \cdot x\right)\right)}}}\right), 0.5, 0.5\right)}}\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{fma}\left(\left(x \cdot \frac{1}{\sqrt{\sqrt{\mathsf{fma}\left(p, \left(p \cdot 4\right), \left(x \cdot x\right)\right)}} \cdot \sqrt{\sqrt{\mathsf{fma}\left(p, \left(p \cdot 4\right), \left(x \cdot x\right)\right)}}}\right), 0.5, 0.5\right)}}\right)
double f(double p, double x) {
        double r55799550 = 0.5;
        double r55799551 = 1.0;
        double r55799552 = x;
        double r55799553 = 4.0;
        double r55799554 = p;
        double r55799555 = r55799553 * r55799554;
        double r55799556 = r55799555 * r55799554;
        double r55799557 = r55799552 * r55799552;
        double r55799558 = r55799556 + r55799557;
        double r55799559 = sqrt(r55799558);
        double r55799560 = r55799552 / r55799559;
        double r55799561 = r55799551 + r55799560;
        double r55799562 = r55799550 * r55799561;
        double r55799563 = sqrt(r55799562);
        return r55799563;
}

double f(double p, double x) {
        double r55799564 = x;
        double r55799565 = 1.0;
        double r55799566 = p;
        double r55799567 = 4.0;
        double r55799568 = r55799566 * r55799567;
        double r55799569 = r55799564 * r55799564;
        double r55799570 = fma(r55799566, r55799568, r55799569);
        double r55799571 = sqrt(r55799570);
        double r55799572 = sqrt(r55799571);
        double r55799573 = r55799572 * r55799572;
        double r55799574 = r55799565 / r55799573;
        double r55799575 = r55799564 * r55799574;
        double r55799576 = 0.5;
        double r55799577 = fma(r55799575, r55799576, r55799576);
        double r55799578 = sqrt(r55799577);
        double r55799579 = exp(r55799578);
        double r55799580 = log(r55799579);
        return r55799580;
}

Error

Bits error versus p

Bits error versus x

Target

Original13.1
Target13.2
Herbie14.0
\[\sqrt{\frac{1}{2} + \frac{\mathsf{copysign}\left(\frac{1}{2}, x\right)}{\mathsf{hypot}\left(1, \left(\frac{2 \cdot p}{x}\right)\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. Simplified13.1

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

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

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

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

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

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

Reproduce

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

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

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