Average Error: 13.7 → 13.7
Time: 13.5s
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{0.5 \cdot \frac{{1}^{3} + {\left(\frac{x}{\sqrt{\mathsf{fma}\left(p, p \cdot 4, x \cdot x\right)}}\right)}^{3}}{\mathsf{fma}\left(\frac{x}{\sqrt{\mathsf{fma}\left(p, p \cdot 4, x \cdot x\right)}}, \frac{x}{\sqrt{\mathsf{fma}\left(p, p \cdot 4, x \cdot x\right)}} - 1, 1 \cdot 1\right)}}\]
\sqrt{0.5 \cdot \left(1 + \frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}\right)}
\sqrt{0.5 \cdot \frac{{1}^{3} + {\left(\frac{x}{\sqrt{\mathsf{fma}\left(p, p \cdot 4, x \cdot x\right)}}\right)}^{3}}{\mathsf{fma}\left(\frac{x}{\sqrt{\mathsf{fma}\left(p, p \cdot 4, x \cdot x\right)}}, \frac{x}{\sqrt{\mathsf{fma}\left(p, p \cdot 4, x \cdot x\right)}} - 1, 1 \cdot 1\right)}}
double f(double p, double x) {
        double r254715 = 0.5;
        double r254716 = 1.0;
        double r254717 = x;
        double r254718 = 4.0;
        double r254719 = p;
        double r254720 = r254718 * r254719;
        double r254721 = r254720 * r254719;
        double r254722 = r254717 * r254717;
        double r254723 = r254721 + r254722;
        double r254724 = sqrt(r254723);
        double r254725 = r254717 / r254724;
        double r254726 = r254716 + r254725;
        double r254727 = r254715 * r254726;
        double r254728 = sqrt(r254727);
        return r254728;
}

double f(double p, double x) {
        double r254729 = 0.5;
        double r254730 = 1.0;
        double r254731 = 3.0;
        double r254732 = pow(r254730, r254731);
        double r254733 = x;
        double r254734 = p;
        double r254735 = 4.0;
        double r254736 = r254734 * r254735;
        double r254737 = r254733 * r254733;
        double r254738 = fma(r254734, r254736, r254737);
        double r254739 = sqrt(r254738);
        double r254740 = r254733 / r254739;
        double r254741 = pow(r254740, r254731);
        double r254742 = r254732 + r254741;
        double r254743 = r254740 - r254730;
        double r254744 = r254730 * r254730;
        double r254745 = fma(r254740, r254743, r254744);
        double r254746 = r254742 / r254745;
        double r254747 = r254729 * r254746;
        double r254748 = sqrt(r254747);
        return r254748;
}

Error

Bits error versus p

Bits error versus x

Target

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

    \[\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 flip3-+13.7

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

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

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

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

Reproduce

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