Average Error: 12.7 → 12.7
Time: 6.0s
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{{1}^{3} + {\left(\frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}\right)}^{3}}{\mathsf{fma}\left(1, \mathsf{expm1}\left(\mathsf{log1p}\left(1 - \frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}\right)\right), \frac{x \cdot x}{\mathsf{fma}\left(4 \cdot p, 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{{1}^{3} + {\left(\frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}\right)}^{3}}{\mathsf{fma}\left(1, \mathsf{expm1}\left(\mathsf{log1p}\left(1 - \frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}\right)\right), \frac{x \cdot x}{\mathsf{fma}\left(4 \cdot p, p, x \cdot x\right)}\right)}}
double f(double p, double x) {
        double r263813 = 0.5;
        double r263814 = 1.0;
        double r263815 = x;
        double r263816 = 4.0;
        double r263817 = p;
        double r263818 = r263816 * r263817;
        double r263819 = r263818 * r263817;
        double r263820 = r263815 * r263815;
        double r263821 = r263819 + r263820;
        double r263822 = sqrt(r263821);
        double r263823 = r263815 / r263822;
        double r263824 = r263814 + r263823;
        double r263825 = r263813 * r263824;
        double r263826 = sqrt(r263825);
        return r263826;
}

double f(double p, double x) {
        double r263827 = 0.5;
        double r263828 = 1.0;
        double r263829 = 3.0;
        double r263830 = pow(r263828, r263829);
        double r263831 = x;
        double r263832 = 4.0;
        double r263833 = p;
        double r263834 = r263832 * r263833;
        double r263835 = r263834 * r263833;
        double r263836 = r263831 * r263831;
        double r263837 = r263835 + r263836;
        double r263838 = sqrt(r263837);
        double r263839 = r263831 / r263838;
        double r263840 = pow(r263839, r263829);
        double r263841 = r263830 + r263840;
        double r263842 = r263828 - r263839;
        double r263843 = log1p(r263842);
        double r263844 = expm1(r263843);
        double r263845 = fma(r263834, r263833, r263836);
        double r263846 = r263836 / r263845;
        double r263847 = fma(r263828, r263844, r263846);
        double r263848 = r263841 / r263847;
        double r263849 = r263827 * r263848;
        double r263850 = sqrt(r263849);
        return r263850;
}

Error

Bits error versus p

Bits error versus x

Target

Original12.7
Target12.7
Herbie12.7
\[\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 12.7

    \[\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-+12.7

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

    \[\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(1, 1 - \frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}, \frac{x \cdot x}{\mathsf{fma}\left(4 \cdot p, p, x \cdot x\right)}\right)}}}\]
  5. Using strategy rm
  6. Applied expm1-log1p-u12.7

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

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

Reproduce

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