Average Error: 12.9 → 12.9
Time: 38.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{\mathsf{fma}\left(\left(\frac{x}{\sqrt{\mathsf{fma}\left(x, x, \left(\left(p \cdot p\right) \cdot 4\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{x}{\sqrt{\mathsf{fma}\left(x, x, \left(\left(p \cdot p\right) \cdot 4\right)\right)}}\right), 0.5, 0.5\right)}
double f(double p, double x) {
        double r99688157 = 0.5;
        double r99688158 = 1.0;
        double r99688159 = x;
        double r99688160 = 4.0;
        double r99688161 = p;
        double r99688162 = r99688160 * r99688161;
        double r99688163 = r99688162 * r99688161;
        double r99688164 = r99688159 * r99688159;
        double r99688165 = r99688163 + r99688164;
        double r99688166 = sqrt(r99688165);
        double r99688167 = r99688159 / r99688166;
        double r99688168 = r99688158 + r99688167;
        double r99688169 = r99688157 * r99688168;
        double r99688170 = sqrt(r99688169);
        return r99688170;
}

double f(double p, double x) {
        double r99688171 = x;
        double r99688172 = p;
        double r99688173 = r99688172 * r99688172;
        double r99688174 = 4.0;
        double r99688175 = r99688173 * r99688174;
        double r99688176 = fma(r99688171, r99688171, r99688175);
        double r99688177 = sqrt(r99688176);
        double r99688178 = r99688171 / r99688177;
        double r99688179 = 0.5;
        double r99688180 = fma(r99688178, r99688179, r99688179);
        double r99688181 = sqrt(r99688180);
        return r99688181;
}

Error

Bits error versus p

Bits error versus x

Target

Original12.9
Target12.9
Herbie12.9
\[\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 12.9

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

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

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

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

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

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

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

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

Reproduce

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