Average Error: 13.3 → 13.3
Time: 16.4s
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)}\]
\[\frac{\sqrt{\mathsf{fma}\left(1 \cdot 1, 1, \frac{x}{\sqrt{\mathsf{fma}\left(p \cdot p, 4, x \cdot x\right)}} \cdot \mathsf{expm1}\left(\mathsf{log1p}\left(\frac{x \cdot x}{\mathsf{fma}\left(p \cdot p, 4, x \cdot x\right)}\right)\right)\right) \cdot 0.5}}{\sqrt{\mathsf{fma}\left(1, 1 - \frac{x}{\sqrt{\mathsf{fma}\left(p \cdot p, 4, x \cdot x\right)}}, \sqrt[3]{\frac{x \cdot x}{\mathsf{fma}\left(p \cdot p, 4, x \cdot x\right)}} \cdot \left(\sqrt[3]{\frac{x \cdot x}{\mathsf{fma}\left(p \cdot p, 4, x \cdot x\right)}} \cdot \sqrt[3]{\frac{x \cdot x}{\mathsf{fma}\left(p \cdot p, 4, x \cdot x\right)}}\right)\right)}}\]
\sqrt{0.5 \cdot \left(1 + \frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}\right)}
\frac{\sqrt{\mathsf{fma}\left(1 \cdot 1, 1, \frac{x}{\sqrt{\mathsf{fma}\left(p \cdot p, 4, x \cdot x\right)}} \cdot \mathsf{expm1}\left(\mathsf{log1p}\left(\frac{x \cdot x}{\mathsf{fma}\left(p \cdot p, 4, x \cdot x\right)}\right)\right)\right) \cdot 0.5}}{\sqrt{\mathsf{fma}\left(1, 1 - \frac{x}{\sqrt{\mathsf{fma}\left(p \cdot p, 4, x \cdot x\right)}}, \sqrt[3]{\frac{x \cdot x}{\mathsf{fma}\left(p \cdot p, 4, x \cdot x\right)}} \cdot \left(\sqrt[3]{\frac{x \cdot x}{\mathsf{fma}\left(p \cdot p, 4, x \cdot x\right)}} \cdot \sqrt[3]{\frac{x \cdot x}{\mathsf{fma}\left(p \cdot p, 4, x \cdot x\right)}}\right)\right)}}
double f(double p, double x) {
        double r10695976 = 0.5;
        double r10695977 = 1.0;
        double r10695978 = x;
        double r10695979 = 4.0;
        double r10695980 = p;
        double r10695981 = r10695979 * r10695980;
        double r10695982 = r10695981 * r10695980;
        double r10695983 = r10695978 * r10695978;
        double r10695984 = r10695982 + r10695983;
        double r10695985 = sqrt(r10695984);
        double r10695986 = r10695978 / r10695985;
        double r10695987 = r10695977 + r10695986;
        double r10695988 = r10695976 * r10695987;
        double r10695989 = sqrt(r10695988);
        return r10695989;
}

double f(double p, double x) {
        double r10695990 = 1.0;
        double r10695991 = r10695990 * r10695990;
        double r10695992 = x;
        double r10695993 = p;
        double r10695994 = r10695993 * r10695993;
        double r10695995 = 4.0;
        double r10695996 = r10695992 * r10695992;
        double r10695997 = fma(r10695994, r10695995, r10695996);
        double r10695998 = sqrt(r10695997);
        double r10695999 = r10695992 / r10695998;
        double r10696000 = r10695996 / r10695997;
        double r10696001 = log1p(r10696000);
        double r10696002 = expm1(r10696001);
        double r10696003 = r10695999 * r10696002;
        double r10696004 = fma(r10695991, r10695990, r10696003);
        double r10696005 = 0.5;
        double r10696006 = r10696004 * r10696005;
        double r10696007 = sqrt(r10696006);
        double r10696008 = r10695990 - r10695999;
        double r10696009 = cbrt(r10696000);
        double r10696010 = r10696009 * r10696009;
        double r10696011 = r10696009 * r10696010;
        double r10696012 = fma(r10695990, r10696008, r10696011);
        double r10696013 = sqrt(r10696012);
        double r10696014 = r10696007 / r10696013;
        return r10696014;
}

Error

Bits error versus p

Bits error versus x

Target

Original13.3
Target13.3
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.3

    \[\sqrt{0.5 \cdot \left(1 + \frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}\right)}\]
  2. Simplified13.3

    \[\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 flip3-+13.3

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

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

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

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

    \[\leadsto \frac{\sqrt{0.5 \cdot \mathsf{fma}\left(1 \cdot 1, 1, \frac{x}{\sqrt{\mathsf{fma}\left(p \cdot p, 4, x \cdot x\right)}} \cdot \frac{x \cdot x}{\mathsf{fma}\left(p \cdot p, 4, x \cdot x\right)}\right)}}{\color{blue}{\sqrt{\mathsf{fma}\left(1, 1 - \frac{x}{\sqrt{\mathsf{fma}\left(p \cdot p, 4, x \cdot x\right)}}, \frac{x \cdot x}{\mathsf{fma}\left(p \cdot p, 4, x \cdot x\right)}\right)}}}\]
  9. Using strategy rm
  10. Applied expm1-log1p-u13.3

    \[\leadsto \frac{\sqrt{0.5 \cdot \mathsf{fma}\left(1 \cdot 1, 1, \frac{x}{\sqrt{\mathsf{fma}\left(p \cdot p, 4, x \cdot x\right)}} \cdot \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{x \cdot x}{\mathsf{fma}\left(p \cdot p, 4, x \cdot x\right)}\right)\right)}\right)}}{\sqrt{\mathsf{fma}\left(1, 1 - \frac{x}{\sqrt{\mathsf{fma}\left(p \cdot p, 4, x \cdot x\right)}}, \frac{x \cdot x}{\mathsf{fma}\left(p \cdot p, 4, x \cdot x\right)}\right)}}\]
  11. Using strategy rm
  12. Applied add-cube-cbrt13.3

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

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

Reproduce

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