Average Error: 13.2 → 14.0
Time: 21.7s
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{e^{\log \left(\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)}}\]
\sqrt{0.5 \cdot \left(1 + \frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}\right)}
\sqrt{e^{\log \left(\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)}}
double f(double p, double x) {
        double r6550314 = 0.5;
        double r6550315 = 1.0;
        double r6550316 = x;
        double r6550317 = 4.0;
        double r6550318 = p;
        double r6550319 = r6550317 * r6550318;
        double r6550320 = r6550319 * r6550318;
        double r6550321 = r6550316 * r6550316;
        double r6550322 = r6550320 + r6550321;
        double r6550323 = sqrt(r6550322);
        double r6550324 = r6550316 / r6550323;
        double r6550325 = r6550315 + r6550324;
        double r6550326 = r6550314 * r6550325;
        double r6550327 = sqrt(r6550326);
        return r6550327;
}

double f(double p, double x) {
        double r6550328 = x;
        double r6550329 = p;
        double r6550330 = 4.0;
        double r6550331 = r6550330 * r6550329;
        double r6550332 = r6550328 * r6550328;
        double r6550333 = fma(r6550329, r6550331, r6550332);
        double r6550334 = sqrt(r6550333);
        double r6550335 = sqrt(r6550334);
        double r6550336 = r6550335 * r6550335;
        double r6550337 = r6550328 / r6550336;
        double r6550338 = 0.5;
        double r6550339 = fma(r6550337, r6550338, r6550338);
        double r6550340 = log(r6550339);
        double r6550341 = exp(r6550340);
        double r6550342 = sqrt(r6550341);
        return r6550342;
}

Error

Bits error versus p

Bits error versus x

Target

Original13.2
Target13.2
Herbie14.0
\[\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 add-exp-log13.2

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

    \[\leadsto \sqrt{e^{\log \left(\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)}}\]
  7. Final simplification14.0

    \[\leadsto \sqrt{e^{\log \left(\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)}}\]

Reproduce

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