Average Error: 13.0 → 13.0
Time: 15.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{0.5 \cdot \frac{{\left(\frac{x}{\sqrt{\mathsf{fma}\left(4 \cdot p, p, x \cdot x\right)}}\right)}^{3} + {1}^{3}}{\mathsf{fma}\left(\frac{x}{\mathsf{fma}\left(4 \cdot p, p, x \cdot x\right)}, x, 1 \cdot \left(1 - \frac{x}{\sqrt{\mathsf{fma}\left(4 \cdot p, p, x \cdot x\right)}}\right)\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{{\left(\frac{x}{\sqrt{\mathsf{fma}\left(4 \cdot p, p, x \cdot x\right)}}\right)}^{3} + {1}^{3}}{\mathsf{fma}\left(\frac{x}{\mathsf{fma}\left(4 \cdot p, p, x \cdot x\right)}, x, 1 \cdot \left(1 - \frac{x}{\sqrt{\mathsf{fma}\left(4 \cdot p, p, x \cdot x\right)}}\right)\right)}}
double f(double p, double x) {
        double r226830 = 0.5;
        double r226831 = 1.0;
        double r226832 = x;
        double r226833 = 4.0;
        double r226834 = p;
        double r226835 = r226833 * r226834;
        double r226836 = r226835 * r226834;
        double r226837 = r226832 * r226832;
        double r226838 = r226836 + r226837;
        double r226839 = sqrt(r226838);
        double r226840 = r226832 / r226839;
        double r226841 = r226831 + r226840;
        double r226842 = r226830 * r226841;
        double r226843 = sqrt(r226842);
        return r226843;
}

double f(double p, double x) {
        double r226844 = 0.5;
        double r226845 = x;
        double r226846 = 4.0;
        double r226847 = p;
        double r226848 = r226846 * r226847;
        double r226849 = r226845 * r226845;
        double r226850 = fma(r226848, r226847, r226849);
        double r226851 = sqrt(r226850);
        double r226852 = r226845 / r226851;
        double r226853 = 3.0;
        double r226854 = pow(r226852, r226853);
        double r226855 = 1.0;
        double r226856 = pow(r226855, r226853);
        double r226857 = r226854 + r226856;
        double r226858 = r226845 / r226850;
        double r226859 = r226855 - r226852;
        double r226860 = r226855 * r226859;
        double r226861 = fma(r226858, r226845, r226860);
        double r226862 = r226857 / r226861;
        double r226863 = r226844 * r226862;
        double r226864 = sqrt(r226863);
        return r226864;
}

Error

Bits error versus p

Bits error versus x

Target

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

    \[\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.0

    \[\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.0

    \[\leadsto \sqrt{0.5 \cdot \frac{\color{blue}{{\left(\frac{x}{\sqrt{\mathsf{fma}\left(4 \cdot p, p, 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.0

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

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

Reproduce

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

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

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