Average Error: 13.4 → 13.4
Time: 22.3s
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)}\]
\[\sqrt{\mathsf{fma}\left(0.5, \frac{x}{\sqrt{\mathsf{fma}\left(p \cdot 4, p, x \cdot x\right)}}, 0.5\right)}\]
\sqrt{0.5 \cdot \left(1 + \frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}\right)}
\sqrt{\mathsf{fma}\left(0.5, \frac{x}{\sqrt{\mathsf{fma}\left(p \cdot 4, p, x \cdot x\right)}}, 0.5\right)}
double f(double p, double x) {
        double r7909606 = 0.5;
        double r7909607 = 1.0;
        double r7909608 = x;
        double r7909609 = 4.0;
        double r7909610 = p;
        double r7909611 = r7909609 * r7909610;
        double r7909612 = r7909611 * r7909610;
        double r7909613 = r7909608 * r7909608;
        double r7909614 = r7909612 + r7909613;
        double r7909615 = sqrt(r7909614);
        double r7909616 = r7909608 / r7909615;
        double r7909617 = r7909607 + r7909616;
        double r7909618 = r7909606 * r7909617;
        double r7909619 = sqrt(r7909618);
        return r7909619;
}

double f(double p, double x) {
        double r7909620 = 0.5;
        double r7909621 = x;
        double r7909622 = p;
        double r7909623 = 4.0;
        double r7909624 = r7909622 * r7909623;
        double r7909625 = r7909621 * r7909621;
        double r7909626 = fma(r7909624, r7909622, r7909625);
        double r7909627 = sqrt(r7909626);
        double r7909628 = r7909621 / r7909627;
        double r7909629 = fma(r7909620, r7909628, r7909620);
        double r7909630 = sqrt(r7909629);
        return r7909630;
}

Error

Bits error versus p

Bits error versus x

Target

Original13.4
Target13.4
Herbie13.4
\[\sqrt{\frac{1}{2} + \frac{\mathsf{copysign}\left(\frac{1}{2}, x\right)}{\mathsf{hypot}\left(1, \frac{2 \cdot p}{x}\right)}}\]

Derivation

  1. Initial program 13.4

    \[\sqrt{0.5 \cdot \left(1 + \frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}\right)}\]
  2. Simplified13.4

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

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

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

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

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

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

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

Reproduce

herbie shell --seed 2019146 +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))))))))