Average Error: 13.4 → 13.4
Time: 18.0s
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{\frac{{\left(\frac{x}{\sqrt{\mathsf{fma}\left(4 \cdot p, p, x \cdot x\right)}}\right)}^{3} + {1}^{3}}{\mathsf{fma}\left(1, 1 - \frac{x}{\sqrt{\mathsf{fma}\left(4 \cdot p, p, x \cdot x\right)}}, \frac{x \cdot x}{\mathsf{fma}\left(4 \cdot p, p, 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{\frac{{\left(\frac{x}{\sqrt{\mathsf{fma}\left(4 \cdot p, p, x \cdot x\right)}}\right)}^{3} + {1}^{3}}{\mathsf{fma}\left(1, 1 - \frac{x}{\sqrt{\mathsf{fma}\left(4 \cdot p, p, x \cdot x\right)}}, \frac{x \cdot x}{\mathsf{fma}\left(4 \cdot p, p, x \cdot x\right)}\right)} \cdot 0.5}
double f(double p, double x) {
        double r202053 = 0.5;
        double r202054 = 1.0;
        double r202055 = x;
        double r202056 = 4.0;
        double r202057 = p;
        double r202058 = r202056 * r202057;
        double r202059 = r202058 * r202057;
        double r202060 = r202055 * r202055;
        double r202061 = r202059 + r202060;
        double r202062 = sqrt(r202061);
        double r202063 = r202055 / r202062;
        double r202064 = r202054 + r202063;
        double r202065 = r202053 * r202064;
        double r202066 = sqrt(r202065);
        return r202066;
}

double f(double p, double x) {
        double r202067 = x;
        double r202068 = 4.0;
        double r202069 = p;
        double r202070 = r202068 * r202069;
        double r202071 = r202067 * r202067;
        double r202072 = fma(r202070, r202069, r202071);
        double r202073 = sqrt(r202072);
        double r202074 = r202067 / r202073;
        double r202075 = 3.0;
        double r202076 = pow(r202074, r202075);
        double r202077 = 1.0;
        double r202078 = pow(r202077, r202075);
        double r202079 = r202076 + r202078;
        double r202080 = r202077 - r202074;
        double r202081 = r202071 / r202072;
        double r202082 = fma(r202077, r202080, r202081);
        double r202083 = r202079 / r202082;
        double r202084 = 0.5;
        double r202085 = r202083 * r202084;
        double r202086 = sqrt(r202085);
        return r202086;
}

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. Simplified13.4

    \[\leadsto \color{blue}{\sqrt{\left(\frac{x}{\sqrt{\mathsf{fma}\left(4 \cdot p, p, x \cdot x\right)}} + 1\right) \cdot 0.5}}\]
  3. Using strategy rm
  4. Applied flip3-+13.4

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

    \[\leadsto \sqrt{\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(1, 1 - \frac{x}{\sqrt{\mathsf{fma}\left(4 \cdot p, p, x \cdot x\right)}}, \frac{x \cdot x}{\mathsf{fma}\left(4 \cdot p, p, x \cdot x\right)}\right)}} \cdot 0.5}\]
  6. Final simplification13.4

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

Reproduce

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

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