Average Error: 13.0 → 14.1
Time: 16.8s
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{\mathsf{fma}\left(\left(\frac{\frac{1}{\sqrt{\sqrt{\mathsf{fma}\left(p, \left(p \cdot 4\right), \left(x \cdot x\right)\right)}}} \cdot x}{\sqrt{\sqrt{\mathsf{fma}\left(p, \left(p \cdot 4\right), \left(x \cdot x\right)\right)}}}\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{\mathsf{fma}\left(\left(\frac{\frac{1}{\sqrt{\sqrt{\mathsf{fma}\left(p, \left(p \cdot 4\right), \left(x \cdot x\right)\right)}}} \cdot x}{\sqrt{\sqrt{\mathsf{fma}\left(p, \left(p \cdot 4\right), \left(x \cdot x\right)\right)}}}\right), 0.5, 0.5\right)}
double f(double p, double x) {
        double r7233489 = 0.5;
        double r7233490 = 1.0;
        double r7233491 = x;
        double r7233492 = 4.0;
        double r7233493 = p;
        double r7233494 = r7233492 * r7233493;
        double r7233495 = r7233494 * r7233493;
        double r7233496 = r7233491 * r7233491;
        double r7233497 = r7233495 + r7233496;
        double r7233498 = sqrt(r7233497);
        double r7233499 = r7233491 / r7233498;
        double r7233500 = r7233490 + r7233499;
        double r7233501 = r7233489 * r7233500;
        double r7233502 = sqrt(r7233501);
        return r7233502;
}

double f(double p, double x) {
        double r7233503 = 1.0;
        double r7233504 = p;
        double r7233505 = 4.0;
        double r7233506 = r7233504 * r7233505;
        double r7233507 = x;
        double r7233508 = r7233507 * r7233507;
        double r7233509 = fma(r7233504, r7233506, r7233508);
        double r7233510 = sqrt(r7233509);
        double r7233511 = sqrt(r7233510);
        double r7233512 = r7233503 / r7233511;
        double r7233513 = r7233512 * r7233507;
        double r7233514 = r7233513 / r7233511;
        double r7233515 = 0.5;
        double r7233516 = fma(r7233514, r7233515, r7233515);
        double r7233517 = sqrt(r7233516);
        return r7233517;
}

Error

Bits error versus p

Bits error versus x

Target

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

Derivation

  1. Initial program 13.0

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

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

    \[\leadsto \sqrt{\mathsf{fma}\left(\left(\frac{x}{\color{blue}{\sqrt{\sqrt{\mathsf{fma}\left(p, \left(4 \cdot p\right), \left(x \cdot x\right)\right)}} \cdot \sqrt{\sqrt{\mathsf{fma}\left(p, \left(4 \cdot p\right), \left(x \cdot x\right)\right)}}}}\right), 0.5, 0.5\right)}\]
  5. Applied associate-/r*14.0

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

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

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

Reproduce

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