Average Error: 13.4 → 14.8
Time: 5.5s
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{0.5 \cdot \frac{{1}^{3} + {\left(\frac{\frac{x}{\left|\sqrt[3]{\left(4 \cdot p\right) \cdot p + x \cdot x}\right|}}{\sqrt{\sqrt[3]{\left(4 \cdot p\right) \cdot p + x \cdot x}}}\right)}^{3}}{\mathsf{fma}\left(\frac{\frac{x}{\left|\sqrt[3]{\left(4 \cdot p\right) \cdot p + x \cdot x}\right|}}{\sqrt{\sqrt[3]{\left(4 \cdot p\right) \cdot p + x \cdot x}}} - 1, \frac{\frac{x}{\left|{\left(\mathsf{fma}\left(4, {p}^{2}, {x}^{2}\right)\right)}^{\frac{1}{6}}\right|}}{\left|{\left(4 \cdot {p}^{2} + {x}^{2}\right)}^{\frac{1}{3}}\right|}, 1 \cdot 1\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{\frac{x}{\left|\sqrt[3]{\left(4 \cdot p\right) \cdot p + x \cdot x}\right|}}{\sqrt{\sqrt[3]{\left(4 \cdot p\right) \cdot p + x \cdot x}}}\right)}^{3}}{\mathsf{fma}\left(\frac{\frac{x}{\left|\sqrt[3]{\left(4 \cdot p\right) \cdot p + x \cdot x}\right|}}{\sqrt{\sqrt[3]{\left(4 \cdot p\right) \cdot p + x \cdot x}}} - 1, \frac{\frac{x}{\left|{\left(\mathsf{fma}\left(4, {p}^{2}, {x}^{2}\right)\right)}^{\frac{1}{6}}\right|}}{\left|{\left(4 \cdot {p}^{2} + {x}^{2}\right)}^{\frac{1}{3}}\right|}, 1 \cdot 1\right)}}
double f(double p, double x) {
        double r265273 = 0.5;
        double r265274 = 1.0;
        double r265275 = x;
        double r265276 = 4.0;
        double r265277 = p;
        double r265278 = r265276 * r265277;
        double r265279 = r265278 * r265277;
        double r265280 = r265275 * r265275;
        double r265281 = r265279 + r265280;
        double r265282 = sqrt(r265281);
        double r265283 = r265275 / r265282;
        double r265284 = r265274 + r265283;
        double r265285 = r265273 * r265284;
        double r265286 = sqrt(r265285);
        return r265286;
}

double f(double p, double x) {
        double r265287 = 0.5;
        double r265288 = 1.0;
        double r265289 = 3.0;
        double r265290 = pow(r265288, r265289);
        double r265291 = x;
        double r265292 = 4.0;
        double r265293 = p;
        double r265294 = r265292 * r265293;
        double r265295 = r265294 * r265293;
        double r265296 = r265291 * r265291;
        double r265297 = r265295 + r265296;
        double r265298 = cbrt(r265297);
        double r265299 = fabs(r265298);
        double r265300 = r265291 / r265299;
        double r265301 = sqrt(r265298);
        double r265302 = r265300 / r265301;
        double r265303 = pow(r265302, r265289);
        double r265304 = r265290 + r265303;
        double r265305 = r265302 - r265288;
        double r265306 = 2.0;
        double r265307 = pow(r265293, r265306);
        double r265308 = pow(r265291, r265306);
        double r265309 = fma(r265292, r265307, r265308);
        double r265310 = 0.16666666666666666;
        double r265311 = pow(r265309, r265310);
        double r265312 = fabs(r265311);
        double r265313 = r265291 / r265312;
        double r265314 = r265292 * r265307;
        double r265315 = r265314 + r265308;
        double r265316 = 0.3333333333333333;
        double r265317 = pow(r265315, r265316);
        double r265318 = fabs(r265317);
        double r265319 = r265313 / r265318;
        double r265320 = r265288 * r265288;
        double r265321 = fma(r265305, r265319, r265320);
        double r265322 = r265304 / r265321;
        double r265323 = r265287 * r265322;
        double r265324 = sqrt(r265323);
        return r265324;
}

Error

Bits error versus p

Bits error versus x

Target

Original13.4
Target13.4
Herbie14.8
\[\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. Using strategy rm
  3. Applied add-cube-cbrt14.8

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

    \[\leadsto \sqrt{0.5 \cdot \left(1 + \frac{x}{\color{blue}{\sqrt{\sqrt[3]{\left(4 \cdot p\right) \cdot p + x \cdot x} \cdot \sqrt[3]{\left(4 \cdot p\right) \cdot p + x \cdot x}} \cdot \sqrt{\sqrt[3]{\left(4 \cdot p\right) \cdot p + x \cdot x}}}}\right)}\]
  5. Applied associate-/r*14.8

    \[\leadsto \sqrt{0.5 \cdot \left(1 + \color{blue}{\frac{\frac{x}{\sqrt{\sqrt[3]{\left(4 \cdot p\right) \cdot p + x \cdot x} \cdot \sqrt[3]{\left(4 \cdot p\right) \cdot p + x \cdot x}}}}{\sqrt{\sqrt[3]{\left(4 \cdot p\right) \cdot p + x \cdot x}}}}\right)}\]
  6. Simplified14.8

    \[\leadsto \sqrt{0.5 \cdot \left(1 + \frac{\color{blue}{\frac{x}{\left|\sqrt[3]{\left(4 \cdot p\right) \cdot p + x \cdot x}\right|}}}{\sqrt{\sqrt[3]{\left(4 \cdot p\right) \cdot p + x \cdot x}}}\right)}\]
  7. Using strategy rm
  8. Applied flip3-+14.8

    \[\leadsto \sqrt{0.5 \cdot \color{blue}{\frac{{1}^{3} + {\left(\frac{\frac{x}{\left|\sqrt[3]{\left(4 \cdot p\right) \cdot p + x \cdot x}\right|}}{\sqrt{\sqrt[3]{\left(4 \cdot p\right) \cdot p + x \cdot x}}}\right)}^{3}}{1 \cdot 1 + \left(\frac{\frac{x}{\left|\sqrt[3]{\left(4 \cdot p\right) \cdot p + x \cdot x}\right|}}{\sqrt{\sqrt[3]{\left(4 \cdot p\right) \cdot p + x \cdot x}}} \cdot \frac{\frac{x}{\left|\sqrt[3]{\left(4 \cdot p\right) \cdot p + x \cdot x}\right|}}{\sqrt{\sqrt[3]{\left(4 \cdot p\right) \cdot p + x \cdot x}}} - 1 \cdot \frac{\frac{x}{\left|\sqrt[3]{\left(4 \cdot p\right) \cdot p + x \cdot x}\right|}}{\sqrt{\sqrt[3]{\left(4 \cdot p\right) \cdot p + x \cdot x}}}\right)}}}\]
  9. Simplified14.8

    \[\leadsto \sqrt{0.5 \cdot \frac{{1}^{3} + {\left(\frac{\frac{x}{\left|\sqrt[3]{\left(4 \cdot p\right) \cdot p + x \cdot x}\right|}}{\sqrt{\sqrt[3]{\left(4 \cdot p\right) \cdot p + x \cdot x}}}\right)}^{3}}{\color{blue}{\mathsf{fma}\left(\frac{\frac{x}{\left|\sqrt[3]{\left(4 \cdot p\right) \cdot p + x \cdot x}\right|}}{\sqrt{\sqrt[3]{\left(4 \cdot p\right) \cdot p + x \cdot x}}} - 1, \frac{\frac{x}{\left|{\left(\mathsf{fma}\left(4, {p}^{2}, {x}^{2}\right)\right)}^{\frac{1}{6}}\right|}}{\left|{\left(4 \cdot {p}^{2} + {x}^{2}\right)}^{\frac{1}{3}}\right|}, 1 \cdot 1\right)}}}\]
  10. Final simplification14.8

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

Reproduce

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