Average Error: 13.1 → 13.3
Time: 21.3s
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{\left(1 + x \cdot \frac{1}{\sqrt{\mathsf{fma}\left(p, p \cdot 4, x \cdot x\right)}}\right) \cdot 0.5}\]
\sqrt{0.5 \cdot \left(1 + \frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}\right)}
\sqrt{\left(1 + x \cdot \frac{1}{\sqrt{\mathsf{fma}\left(p, p \cdot 4, x \cdot x\right)}}\right) \cdot 0.5}
double f(double p, double x) {
        double r9206812 = 0.5;
        double r9206813 = 1.0;
        double r9206814 = x;
        double r9206815 = 4.0;
        double r9206816 = p;
        double r9206817 = r9206815 * r9206816;
        double r9206818 = r9206817 * r9206816;
        double r9206819 = r9206814 * r9206814;
        double r9206820 = r9206818 + r9206819;
        double r9206821 = sqrt(r9206820);
        double r9206822 = r9206814 / r9206821;
        double r9206823 = r9206813 + r9206822;
        double r9206824 = r9206812 * r9206823;
        double r9206825 = sqrt(r9206824);
        return r9206825;
}

double f(double p, double x) {
        double r9206826 = 1.0;
        double r9206827 = x;
        double r9206828 = 1.0;
        double r9206829 = p;
        double r9206830 = 4.0;
        double r9206831 = r9206829 * r9206830;
        double r9206832 = r9206827 * r9206827;
        double r9206833 = fma(r9206829, r9206831, r9206832);
        double r9206834 = sqrt(r9206833);
        double r9206835 = r9206828 / r9206834;
        double r9206836 = r9206827 * r9206835;
        double r9206837 = r9206826 + r9206836;
        double r9206838 = 0.5;
        double r9206839 = r9206837 * r9206838;
        double r9206840 = sqrt(r9206839);
        return r9206840;
}

Error

Bits error versus p

Bits error versus x

Target

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

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

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

Reproduce

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