Average Error: 13.4 → 13.4
Time: 5.8s
Precision: 64
\[1.00000000000000001 \cdot 10^{-150} \lt \left|x\right| \lt 9.99999999999999981 \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{\log \left(e^{{1}^{3} + {\left(\frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}\right)}^{3}}\right)}{\mathsf{fma}\left(\frac{x}{\mathsf{fma}\left(4 \cdot p, p, x \cdot x\right)}, x, 1 \cdot \left(1 - \frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}\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{\log \left(e^{{1}^{3} + {\left(\frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}\right)}^{3}}\right)}{\mathsf{fma}\left(\frac{x}{\mathsf{fma}\left(4 \cdot p, p, x \cdot x\right)}, x, 1 \cdot \left(1 - \frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}\right)\right)}}
double f(double p, double x) {
        double r333918 = 0.5;
        double r333919 = 1.0;
        double r333920 = x;
        double r333921 = 4.0;
        double r333922 = p;
        double r333923 = r333921 * r333922;
        double r333924 = r333923 * r333922;
        double r333925 = r333920 * r333920;
        double r333926 = r333924 + r333925;
        double r333927 = sqrt(r333926);
        double r333928 = r333920 / r333927;
        double r333929 = r333919 + r333928;
        double r333930 = r333918 * r333929;
        double r333931 = sqrt(r333930);
        return r333931;
}

double f(double p, double x) {
        double r333932 = 0.5;
        double r333933 = 1.0;
        double r333934 = 3.0;
        double r333935 = pow(r333933, r333934);
        double r333936 = x;
        double r333937 = 4.0;
        double r333938 = p;
        double r333939 = r333937 * r333938;
        double r333940 = r333939 * r333938;
        double r333941 = r333936 * r333936;
        double r333942 = r333940 + r333941;
        double r333943 = sqrt(r333942);
        double r333944 = r333936 / r333943;
        double r333945 = pow(r333944, r333934);
        double r333946 = r333935 + r333945;
        double r333947 = exp(r333946);
        double r333948 = log(r333947);
        double r333949 = fma(r333939, r333938, r333941);
        double r333950 = r333936 / r333949;
        double r333951 = r333933 - r333944;
        double r333952 = r333933 * r333951;
        double r333953 = fma(r333950, r333936, r333952);
        double r333954 = r333948 / r333953;
        double r333955 = r333932 * r333954;
        double r333956 = sqrt(r333955);
        return r333956;
}

Error

Bits error versus p

Bits error versus x

Target

Original13.4
Target13.4
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.4

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

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

    \[\leadsto \sqrt{0.5 \cdot \frac{{1}^{3} + {\left(\frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}\right)}^{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{\left(4 \cdot p\right) \cdot p + x \cdot x}}\right)\right)}}}\]
  5. Using strategy rm
  6. Applied add-log-exp13.4

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

    \[\leadsto \sqrt{0.5 \cdot \frac{\color{blue}{\log \left(e^{{1}^{3}}\right)} + \log \left(e^{{\left(\frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}\right)}^{3}}\right)}{\mathsf{fma}\left(\frac{x}{\mathsf{fma}\left(4 \cdot p, p, x \cdot x\right)}, x, 1 \cdot \left(1 - \frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}\right)\right)}}\]
  8. Applied sum-log13.4

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

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

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

Reproduce

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