Average Error: 12.9 → 13.0
Time: 16.1s
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{\log \left(e^{{\left(\frac{x}{\sqrt{\mathsf{fma}\left(4, {p}^{2}, {x}^{2}\right)}}\right)}^{3} + {1}^{3}}\right)}{\mathsf{fma}\left(x, \frac{x}{\mathsf{fma}\left(4, {p}^{2}, {x}^{2}\right)}, 1 \cdot \left(1 - \frac{x}{\sqrt{\mathsf{fma}\left(4, {p}^{2}, {x}^{2}\right)}}\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{\log \left(e^{{\left(\frac{x}{\sqrt{\mathsf{fma}\left(4, {p}^{2}, {x}^{2}\right)}}\right)}^{3} + {1}^{3}}\right)}{\mathsf{fma}\left(x, \frac{x}{\mathsf{fma}\left(4, {p}^{2}, {x}^{2}\right)}, 1 \cdot \left(1 - \frac{x}{\sqrt{\mathsf{fma}\left(4, {p}^{2}, {x}^{2}\right)}}\right)\right)}}
double f(double p, double x) {
        double r173420 = 0.5;
        double r173421 = 1.0;
        double r173422 = x;
        double r173423 = 4.0;
        double r173424 = p;
        double r173425 = r173423 * r173424;
        double r173426 = r173425 * r173424;
        double r173427 = r173422 * r173422;
        double r173428 = r173426 + r173427;
        double r173429 = sqrt(r173428);
        double r173430 = r173422 / r173429;
        double r173431 = r173421 + r173430;
        double r173432 = r173420 * r173431;
        double r173433 = sqrt(r173432);
        return r173433;
}

double f(double p, double x) {
        double r173434 = 0.5;
        double r173435 = x;
        double r173436 = 4.0;
        double r173437 = p;
        double r173438 = 2.0;
        double r173439 = pow(r173437, r173438);
        double r173440 = pow(r173435, r173438);
        double r173441 = fma(r173436, r173439, r173440);
        double r173442 = sqrt(r173441);
        double r173443 = r173435 / r173442;
        double r173444 = 3.0;
        double r173445 = pow(r173443, r173444);
        double r173446 = 1.0;
        double r173447 = pow(r173446, r173444);
        double r173448 = r173445 + r173447;
        double r173449 = exp(r173448);
        double r173450 = log(r173449);
        double r173451 = r173435 / r173441;
        double r173452 = r173446 - r173443;
        double r173453 = r173446 * r173452;
        double r173454 = fma(r173435, r173451, r173453);
        double r173455 = r173450 / r173454;
        double r173456 = r173434 * r173455;
        double r173457 = sqrt(r173456);
        return r173457;
}

Error

Bits error versus p

Bits error versus x

Target

Original12.9
Target12.9
Herbie13.0
\[\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.9

    \[\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 div-inv13.2

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

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

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

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

    \[\leadsto \sqrt{0.5 \cdot \frac{{\left(\frac{x}{\sqrt{\mathsf{fma}\left(4, {p}^{2}, {x}^{2}\right)}}\right)}^{3} + {1}^{3}}{\color{blue}{\mathsf{fma}\left(x, \frac{x}{\mathsf{fma}\left(4, {p}^{2}, {x}^{2}\right)}, 1 \cdot \left(1 - \frac{x}{\sqrt{\mathsf{fma}\left(4, {p}^{2}, {x}^{2}\right)}}\right)\right)}}}\]
  9. Using strategy rm
  10. Applied add-log-exp13.0

    \[\leadsto \sqrt{0.5 \cdot \frac{{\left(\frac{x}{\sqrt{\mathsf{fma}\left(4, {p}^{2}, {x}^{2}\right)}}\right)}^{3} + \color{blue}{\log \left(e^{{1}^{3}}\right)}}{\mathsf{fma}\left(x, \frac{x}{\mathsf{fma}\left(4, {p}^{2}, {x}^{2}\right)}, 1 \cdot \left(1 - \frac{x}{\sqrt{\mathsf{fma}\left(4, {p}^{2}, {x}^{2}\right)}}\right)\right)}}\]
  11. Applied add-log-exp13.0

    \[\leadsto \sqrt{0.5 \cdot \frac{\color{blue}{\log \left(e^{{\left(\frac{x}{\sqrt{\mathsf{fma}\left(4, {p}^{2}, {x}^{2}\right)}}\right)}^{3}}\right)} + \log \left(e^{{1}^{3}}\right)}{\mathsf{fma}\left(x, \frac{x}{\mathsf{fma}\left(4, {p}^{2}, {x}^{2}\right)}, 1 \cdot \left(1 - \frac{x}{\sqrt{\mathsf{fma}\left(4, {p}^{2}, {x}^{2}\right)}}\right)\right)}}\]
  12. Applied sum-log13.0

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

    \[\leadsto \sqrt{0.5 \cdot \frac{\log \color{blue}{\left(e^{{\left(\frac{x}{\sqrt{\mathsf{fma}\left(4, {p}^{2}, {x}^{2}\right)}}\right)}^{3} + {1}^{3}}\right)}}{\mathsf{fma}\left(x, \frac{x}{\mathsf{fma}\left(4, {p}^{2}, {x}^{2}\right)}, 1 \cdot \left(1 - \frac{x}{\sqrt{\mathsf{fma}\left(4, {p}^{2}, {x}^{2}\right)}}\right)\right)}}\]
  14. Final simplification13.0

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

Reproduce

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