Average Error: 13.4 → 13.4
Time: 6.9s
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 r293950 = 0.5;
        double r293951 = 1.0;
        double r293952 = x;
        double r293953 = 4.0;
        double r293954 = p;
        double r293955 = r293953 * r293954;
        double r293956 = r293955 * r293954;
        double r293957 = r293952 * r293952;
        double r293958 = r293956 + r293957;
        double r293959 = sqrt(r293958);
        double r293960 = r293952 / r293959;
        double r293961 = r293951 + r293960;
        double r293962 = r293950 * r293961;
        double r293963 = sqrt(r293962);
        return r293963;
}

double f(double p, double x) {
        double r293964 = 0.5;
        double r293965 = 1.0;
        double r293966 = 3.0;
        double r293967 = pow(r293965, r293966);
        double r293968 = x;
        double r293969 = 4.0;
        double r293970 = p;
        double r293971 = r293969 * r293970;
        double r293972 = r293971 * r293970;
        double r293973 = r293968 * r293968;
        double r293974 = r293972 + r293973;
        double r293975 = sqrt(r293974);
        double r293976 = r293968 / r293975;
        double r293977 = pow(r293976, r293966);
        double r293978 = r293967 + r293977;
        double r293979 = exp(r293978);
        double r293980 = log(r293979);
        double r293981 = fma(r293971, r293970, r293973);
        double r293982 = r293968 / r293981;
        double r293983 = r293965 - r293976;
        double r293984 = r293965 * r293983;
        double r293985 = fma(r293982, r293968, r293984);
        double r293986 = r293980 / r293985;
        double r293987 = r293964 * r293986;
        double r293988 = sqrt(r293987);
        return r293988;
}

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))))))))