Average Error: 13.1 → 13.4
Time: 17.3s
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{\frac{\mathsf{fma}\left(1 \cdot 1, 1, \frac{x \cdot x}{\sqrt{\mathsf{fma}\left(p \cdot 4, p, x \cdot x\right)}} \cdot \frac{1}{\frac{\mathsf{fma}\left(p \cdot 4, p, x \cdot x\right)}{x}}\right)}{\mathsf{fma}\left(1, 1 - \frac{x}{\sqrt{\mathsf{fma}\left(p \cdot 4, p, x \cdot x\right)}}, \frac{x \cdot x}{\mathsf{fma}\left(p \cdot 4, p, 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{\frac{\mathsf{fma}\left(1 \cdot 1, 1, \frac{x \cdot x}{\sqrt{\mathsf{fma}\left(p \cdot 4, p, x \cdot x\right)}} \cdot \frac{1}{\frac{\mathsf{fma}\left(p \cdot 4, p, x \cdot x\right)}{x}}\right)}{\mathsf{fma}\left(1, 1 - \frac{x}{\sqrt{\mathsf{fma}\left(p \cdot 4, p, x \cdot x\right)}}, \frac{x \cdot x}{\mathsf{fma}\left(p \cdot 4, p, x \cdot x\right)}\right)} \cdot 0.5}
double f(double p, double x) {
        double r10988689 = 0.5;
        double r10988690 = 1.0;
        double r10988691 = x;
        double r10988692 = 4.0;
        double r10988693 = p;
        double r10988694 = r10988692 * r10988693;
        double r10988695 = r10988694 * r10988693;
        double r10988696 = r10988691 * r10988691;
        double r10988697 = r10988695 + r10988696;
        double r10988698 = sqrt(r10988697);
        double r10988699 = r10988691 / r10988698;
        double r10988700 = r10988690 + r10988699;
        double r10988701 = r10988689 * r10988700;
        double r10988702 = sqrt(r10988701);
        return r10988702;
}

double f(double p, double x) {
        double r10988703 = 1.0;
        double r10988704 = r10988703 * r10988703;
        double r10988705 = x;
        double r10988706 = r10988705 * r10988705;
        double r10988707 = p;
        double r10988708 = 4.0;
        double r10988709 = r10988707 * r10988708;
        double r10988710 = fma(r10988709, r10988707, r10988706);
        double r10988711 = sqrt(r10988710);
        double r10988712 = r10988706 / r10988711;
        double r10988713 = 1.0;
        double r10988714 = r10988710 / r10988705;
        double r10988715 = r10988713 / r10988714;
        double r10988716 = r10988712 * r10988715;
        double r10988717 = fma(r10988704, r10988703, r10988716);
        double r10988718 = r10988705 / r10988711;
        double r10988719 = r10988703 - r10988718;
        double r10988720 = r10988706 / r10988710;
        double r10988721 = fma(r10988703, r10988719, r10988720);
        double r10988722 = r10988717 / r10988721;
        double r10988723 = 0.5;
        double r10988724 = r10988722 * r10988723;
        double r10988725 = sqrt(r10988724);
        return r10988725;
}

Error

Bits error versus p

Bits error versus x

Target

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

    \[\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 div-inv13.4

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

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

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

    \[\leadsto \sqrt{\frac{\mathsf{fma}\left(1 \cdot 1, 1, \frac{x \cdot x}{\sqrt{\mathsf{fma}\left(p \cdot 4, p, x \cdot x\right)}} \cdot \frac{x}{\mathsf{fma}\left(p \cdot 4, p, x \cdot x\right)}\right)}{\color{blue}{\mathsf{fma}\left(1, 1 - \frac{x}{\sqrt{\mathsf{fma}\left(p \cdot 4, p, x \cdot x\right)}}, \frac{x \cdot x}{\mathsf{fma}\left(p \cdot 4, p, x \cdot x\right)}\right)}} \cdot 0.5}\]
  9. Using strategy rm
  10. Applied clear-num13.4

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

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

Reproduce

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