Average Error: 13.1 → 13.1
Time: 18.3s
Precision: 64
\[10^{-150} \lt \left|x\right| \lt 10^{+150}\]
\[\sqrt{0.5 \cdot \left(1 + \frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}\right)}\]
\[\sqrt{\mathsf{fma}\left(\frac{x}{\sqrt{\mathsf{fma}\left(p, 4 \cdot p, x \cdot x\right)}}, 0.5, 0.5\right)}\]
\sqrt{0.5 \cdot \left(1 + \frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}\right)}
\sqrt{\mathsf{fma}\left(\frac{x}{\sqrt{\mathsf{fma}\left(p, 4 \cdot p, x \cdot x\right)}}, 0.5, 0.5\right)}
double f(double p, double x) {
        double r3780955 = 0.5;
        double r3780956 = 1.0;
        double r3780957 = x;
        double r3780958 = 4.0;
        double r3780959 = p;
        double r3780960 = r3780958 * r3780959;
        double r3780961 = r3780960 * r3780959;
        double r3780962 = r3780957 * r3780957;
        double r3780963 = r3780961 + r3780962;
        double r3780964 = sqrt(r3780963);
        double r3780965 = r3780957 / r3780964;
        double r3780966 = r3780956 + r3780965;
        double r3780967 = r3780955 * r3780966;
        double r3780968 = sqrt(r3780967);
        return r3780968;
}

double f(double p, double x) {
        double r3780969 = x;
        double r3780970 = p;
        double r3780971 = 4.0;
        double r3780972 = r3780971 * r3780970;
        double r3780973 = r3780969 * r3780969;
        double r3780974 = fma(r3780970, r3780972, r3780973);
        double r3780975 = sqrt(r3780974);
        double r3780976 = r3780969 / r3780975;
        double r3780977 = 0.5;
        double r3780978 = fma(r3780976, r3780977, r3780977);
        double r3780979 = sqrt(r3780978);
        return r3780979;
}

Error

Bits error versus p

Bits error versus x

Target

Original13.1
Target13.1
Herbie13.1
\[\sqrt{\frac{1}{2} + \frac{\mathsf{copysign}\left(\frac{1}{2}, 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{\mathsf{fma}\left(\frac{x}{\sqrt{\mathsf{fma}\left(p, 4 \cdot p, x \cdot x\right)}}, 0.5, 0.5\right)}}\]
  3. Using strategy rm
  4. Applied div-inv13.3

    \[\leadsto \sqrt{\mathsf{fma}\left(\color{blue}{x \cdot \frac{1}{\sqrt{\mathsf{fma}\left(p, 4 \cdot p, x \cdot x\right)}}}, 0.5, 0.5\right)}\]
  5. Using strategy rm
  6. Applied associate-*r/13.1

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

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

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

Reproduce

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

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

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