Average Error: 13.2 → 13.5
Time: 22.1s
Precision: 64
\[10^{-150} \lt \left|x\right| \lt 10^{+150}\]
\[\sqrt{0.5 \cdot \left(1 + \frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}\right)}\]
\[\sqrt{\left(\sqrt[3]{\mathsf{fma}\left(x \cdot \frac{1}{\sqrt{\mathsf{fma}\left(p, p \cdot 4, x \cdot x\right)}}, 0.5, 0.5\right)} \cdot \sqrt[3]{\mathsf{fma}\left(x \cdot \frac{1}{\sqrt{\mathsf{fma}\left(p, p \cdot 4, x \cdot x\right)}}, 0.5, 0.5\right)}\right) \cdot \sqrt[3]{e^{\log \left(\mathsf{fma}\left(x \cdot \frac{1}{\sqrt{\mathsf{fma}\left(p, p \cdot 4, x \cdot x\right)}}, 0.5, 0.5\right)\right)}}}\]
\sqrt{0.5 \cdot \left(1 + \frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}\right)}
\sqrt{\left(\sqrt[3]{\mathsf{fma}\left(x \cdot \frac{1}{\sqrt{\mathsf{fma}\left(p, p \cdot 4, x \cdot x\right)}}, 0.5, 0.5\right)} \cdot \sqrt[3]{\mathsf{fma}\left(x \cdot \frac{1}{\sqrt{\mathsf{fma}\left(p, p \cdot 4, x \cdot x\right)}}, 0.5, 0.5\right)}\right) \cdot \sqrt[3]{e^{\log \left(\mathsf{fma}\left(x \cdot \frac{1}{\sqrt{\mathsf{fma}\left(p, p \cdot 4, x \cdot x\right)}}, 0.5, 0.5\right)\right)}}}
double f(double p, double x) {
        double r5152347 = 0.5;
        double r5152348 = 1.0;
        double r5152349 = x;
        double r5152350 = 4.0;
        double r5152351 = p;
        double r5152352 = r5152350 * r5152351;
        double r5152353 = r5152352 * r5152351;
        double r5152354 = r5152349 * r5152349;
        double r5152355 = r5152353 + r5152354;
        double r5152356 = sqrt(r5152355);
        double r5152357 = r5152349 / r5152356;
        double r5152358 = r5152348 + r5152357;
        double r5152359 = r5152347 * r5152358;
        double r5152360 = sqrt(r5152359);
        return r5152360;
}

double f(double p, double x) {
        double r5152361 = x;
        double r5152362 = 1.0;
        double r5152363 = p;
        double r5152364 = 4.0;
        double r5152365 = r5152363 * r5152364;
        double r5152366 = r5152361 * r5152361;
        double r5152367 = fma(r5152363, r5152365, r5152366);
        double r5152368 = sqrt(r5152367);
        double r5152369 = r5152362 / r5152368;
        double r5152370 = r5152361 * r5152369;
        double r5152371 = 0.5;
        double r5152372 = fma(r5152370, r5152371, r5152371);
        double r5152373 = cbrt(r5152372);
        double r5152374 = r5152373 * r5152373;
        double r5152375 = log(r5152372);
        double r5152376 = exp(r5152375);
        double r5152377 = cbrt(r5152376);
        double r5152378 = r5152374 * r5152377;
        double r5152379 = sqrt(r5152378);
        return r5152379;
}

Error

Bits error versus p

Bits error versus x

Target

Original13.2
Target13.2
Herbie13.5
\[\sqrt{\frac{1}{2} + \frac{\mathsf{copysign}\left(\frac{1}{2}, x\right)}{\mathsf{hypot}\left(1, \frac{2 \cdot p}{x}\right)}}\]

Derivation

  1. Initial program 13.2

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

    \[\leadsto \color{blue}{\sqrt{\mathsf{fma}\left(\frac{x}{\sqrt{\mathsf{fma}\left(p, 4 \cdot p, x \cdot x\right)}}, 0.5, 0.5\right)}}\]
  3. Using strategy rm
  4. Applied div-inv13.4

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

    \[\leadsto \sqrt{\color{blue}{\left(\sqrt[3]{\mathsf{fma}\left(x \cdot \frac{1}{\sqrt{\mathsf{fma}\left(p, 4 \cdot p, x \cdot x\right)}}, 0.5, 0.5\right)} \cdot \sqrt[3]{\mathsf{fma}\left(x \cdot \frac{1}{\sqrt{\mathsf{fma}\left(p, 4 \cdot p, x \cdot x\right)}}, 0.5, 0.5\right)}\right) \cdot \sqrt[3]{\mathsf{fma}\left(x \cdot \frac{1}{\sqrt{\mathsf{fma}\left(p, 4 \cdot p, x \cdot x\right)}}, 0.5, 0.5\right)}}}\]
  7. Using strategy rm
  8. Applied add-exp-log13.5

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

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

Reproduce

herbie shell --seed 2019141 +o rules:numerics
(FPCore (p x)
  :name "Given's Rotation SVD example"
  :pre (< 1e-150 (fabs x) 1e+150)

  :herbie-target
  (sqrt (+ 1/2 (/ (copysign 1/2 x) (hypot 1 (/ (* 2 p) x)))))

  (sqrt (* 0.5 (+ 1 (/ x (sqrt (+ (* (* 4 p) p) (* x x))))))))