Average Error: 13.5 → 13.5
Time: 2.0m
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(\frac{x}{\sqrt{\mathsf{fma}\left(p, 4 \cdot p, x \cdot x\right)}}, 0.5, 0.5\right)} \cdot \sqrt[3]{\mathsf{fma}\left(\frac{x}{\sqrt{\sqrt{\mathsf{fma}\left(p, 4 \cdot p, x \cdot x\right)}} \cdot \sqrt{\sqrt{\mathsf{fma}\left(p, 4 \cdot p, x \cdot x\right)}}}, 0.5, 0.5\right)}\right) \cdot \sqrt[3]{\mathsf{fma}\left(\frac{x}{\sqrt{\mathsf{fma}\left(p, 4 \cdot p, x \cdot x\right)}}, 0.5, 0.5\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(\frac{x}{\sqrt{\mathsf{fma}\left(p, 4 \cdot p, x \cdot x\right)}}, 0.5, 0.5\right)} \cdot \sqrt[3]{\mathsf{fma}\left(\frac{x}{\sqrt{\sqrt{\mathsf{fma}\left(p, 4 \cdot p, x \cdot x\right)}} \cdot \sqrt{\sqrt{\mathsf{fma}\left(p, 4 \cdot p, x \cdot x\right)}}}, 0.5, 0.5\right)}\right) \cdot \sqrt[3]{\mathsf{fma}\left(\frac{x}{\sqrt{\mathsf{fma}\left(p, 4 \cdot p, x \cdot x\right)}}, 0.5, 0.5\right)}}
double f(double p, double x) {
        double r10550483 = 0.5;
        double r10550484 = 1.0;
        double r10550485 = x;
        double r10550486 = 4.0;
        double r10550487 = p;
        double r10550488 = r10550486 * r10550487;
        double r10550489 = r10550488 * r10550487;
        double r10550490 = r10550485 * r10550485;
        double r10550491 = r10550489 + r10550490;
        double r10550492 = sqrt(r10550491);
        double r10550493 = r10550485 / r10550492;
        double r10550494 = r10550484 + r10550493;
        double r10550495 = r10550483 * r10550494;
        double r10550496 = sqrt(r10550495);
        return r10550496;
}

double f(double p, double x) {
        double r10550497 = x;
        double r10550498 = p;
        double r10550499 = 4.0;
        double r10550500 = r10550499 * r10550498;
        double r10550501 = r10550497 * r10550497;
        double r10550502 = fma(r10550498, r10550500, r10550501);
        double r10550503 = sqrt(r10550502);
        double r10550504 = r10550497 / r10550503;
        double r10550505 = 0.5;
        double r10550506 = fma(r10550504, r10550505, r10550505);
        double r10550507 = cbrt(r10550506);
        double r10550508 = sqrt(r10550503);
        double r10550509 = r10550508 * r10550508;
        double r10550510 = r10550497 / r10550509;
        double r10550511 = fma(r10550510, r10550505, r10550505);
        double r10550512 = cbrt(r10550511);
        double r10550513 = r10550507 * r10550512;
        double r10550514 = r10550513 * r10550507;
        double r10550515 = sqrt(r10550514);
        return r10550515;
}

Error

Bits error versus p

Bits error versus x

Target

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

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

    \[\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 add-cube-cbrt13.5

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

    \[\leadsto \sqrt{\left(\sqrt[3]{\mathsf{fma}\left(\frac{x}{\sqrt{\mathsf{fma}\left(p, 4 \cdot p, x \cdot x\right)}}, 0.5, 0.5\right)} \cdot \sqrt[3]{\mathsf{fma}\left(\frac{x}{\sqrt{\color{blue}{\sqrt{\mathsf{fma}\left(p, 4 \cdot p, x \cdot x\right)} \cdot \sqrt{\mathsf{fma}\left(p, 4 \cdot p, x \cdot x\right)}}}}, 0.5, 0.5\right)}\right) \cdot \sqrt[3]{\mathsf{fma}\left(\frac{x}{\sqrt{\mathsf{fma}\left(p, 4 \cdot p, x \cdot x\right)}}, 0.5, 0.5\right)}}\]
  7. Applied sqrt-prod13.5

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

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

Reproduce

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