Average Error: 13.4 → 14.8
Time: 5.6s
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 r313516 = 0.5;
        double r313517 = 1.0;
        double r313518 = x;
        double r313519 = 4.0;
        double r313520 = p;
        double r313521 = r313519 * r313520;
        double r313522 = r313521 * r313520;
        double r313523 = r313518 * r313518;
        double r313524 = r313522 + r313523;
        double r313525 = sqrt(r313524);
        double r313526 = r313518 / r313525;
        double r313527 = r313517 + r313526;
        double r313528 = r313516 * r313527;
        double r313529 = sqrt(r313528);
        return r313529;
}

double f(double p, double x) {
        double r313530 = 0.5;
        double r313531 = 1.0;
        double r313532 = 3.0;
        double r313533 = pow(r313531, r313532);
        double r313534 = x;
        double r313535 = 4.0;
        double r313536 = p;
        double r313537 = r313535 * r313536;
        double r313538 = r313537 * r313536;
        double r313539 = r313534 * r313534;
        double r313540 = r313538 + r313539;
        double r313541 = cbrt(r313540);
        double r313542 = fabs(r313541);
        double r313543 = r313534 / r313542;
        double r313544 = sqrt(r313541);
        double r313545 = r313543 / r313544;
        double r313546 = pow(r313545, r313532);
        double r313547 = r313533 + r313546;
        double r313548 = r313545 - r313531;
        double r313549 = 2.0;
        double r313550 = pow(r313536, r313549);
        double r313551 = pow(r313534, r313549);
        double r313552 = fma(r313535, r313550, r313551);
        double r313553 = 0.16666666666666666;
        double r313554 = pow(r313552, r313553);
        double r313555 = fabs(r313554);
        double r313556 = r313534 / r313555;
        double r313557 = r313535 * r313550;
        double r313558 = r313557 + r313551;
        double r313559 = 0.3333333333333333;
        double r313560 = pow(r313558, r313559);
        double r313561 = fabs(r313560);
        double r313562 = r313556 / r313561;
        double r313563 = r313531 * r313531;
        double r313564 = fma(r313548, r313562, r313563);
        double r313565 = r313547 / r313564;
        double r313566 = r313530 * r313565;
        double r313567 = sqrt(r313566);
        return r313567;
}

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