Average Error: 12.9 → 12.9
Time: 31.4s
Precision: 64
\[1.000000000000000006295358232172963997211 \cdot 10^{-150} \lt \left|x\right| \lt 9.999999999999999808355961724373745905731 \cdot 10^{149}\]
\[\sqrt{0.5 \cdot \left(1 + \frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}\right)}\]
\[\sqrt{\frac{\frac{\mathsf{fma}\left(\left(\left(1 \cdot 1\right) \cdot 1\right) \cdot \left(\left(1 \cdot 1\right) \cdot 1\right), \left(1 \cdot 1\right) \cdot 1, \left(\frac{x \cdot x}{\mathsf{fma}\left(p, 4 \cdot p, x \cdot x\right)} \cdot \frac{x}{\sqrt{\mathsf{fma}\left(p, 4 \cdot p, x \cdot x\right)}}\right) \cdot \left(\left(\frac{x \cdot x}{\mathsf{fma}\left(p, 4 \cdot p, x \cdot x\right)} \cdot \frac{x}{\sqrt{\mathsf{fma}\left(p, 4 \cdot p, x \cdot x\right)}}\right) \cdot \left(\frac{x \cdot x}{\mathsf{fma}\left(p, 4 \cdot p, x \cdot x\right)} \cdot \frac{x}{\sqrt{\mathsf{fma}\left(p, 4 \cdot p, x \cdot x\right)}}\right)\right)\right)}{\mathsf{fma}\left(\left(1 \cdot 1\right) \cdot 1 - \frac{x \cdot x}{\mathsf{fma}\left(p, 4 \cdot p, x \cdot x\right)} \cdot \frac{x}{\sqrt{\mathsf{fma}\left(p, 4 \cdot p, x \cdot x\right)}}, \left(1 \cdot 1\right) \cdot 1, \left(\frac{x \cdot x}{\mathsf{fma}\left(p, 4 \cdot p, x \cdot x\right)} \cdot \frac{x}{\sqrt{\mathsf{fma}\left(p, 4 \cdot p, x \cdot x\right)}}\right) \cdot \left(\frac{x \cdot x}{\mathsf{fma}\left(p, 4 \cdot p, x \cdot x\right)} \cdot \frac{x}{\sqrt{\mathsf{fma}\left(p, 4 \cdot p, x \cdot x\right)}}\right)\right)}}{\mathsf{fma}\left(1, 1 - \frac{x}{\sqrt{\mathsf{fma}\left(p, 4 \cdot p, x \cdot x\right)}}, \frac{x \cdot x}{\mathsf{fma}\left(p, 4 \cdot p, x \cdot x\right)}\right)} \cdot 0.5}\]
\sqrt{0.5 \cdot \left(1 + \frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}\right)}
\sqrt{\frac{\frac{\mathsf{fma}\left(\left(\left(1 \cdot 1\right) \cdot 1\right) \cdot \left(\left(1 \cdot 1\right) \cdot 1\right), \left(1 \cdot 1\right) \cdot 1, \left(\frac{x \cdot x}{\mathsf{fma}\left(p, 4 \cdot p, x \cdot x\right)} \cdot \frac{x}{\sqrt{\mathsf{fma}\left(p, 4 \cdot p, x \cdot x\right)}}\right) \cdot \left(\left(\frac{x \cdot x}{\mathsf{fma}\left(p, 4 \cdot p, x \cdot x\right)} \cdot \frac{x}{\sqrt{\mathsf{fma}\left(p, 4 \cdot p, x \cdot x\right)}}\right) \cdot \left(\frac{x \cdot x}{\mathsf{fma}\left(p, 4 \cdot p, x \cdot x\right)} \cdot \frac{x}{\sqrt{\mathsf{fma}\left(p, 4 \cdot p, x \cdot x\right)}}\right)\right)\right)}{\mathsf{fma}\left(\left(1 \cdot 1\right) \cdot 1 - \frac{x \cdot x}{\mathsf{fma}\left(p, 4 \cdot p, x \cdot x\right)} \cdot \frac{x}{\sqrt{\mathsf{fma}\left(p, 4 \cdot p, x \cdot x\right)}}, \left(1 \cdot 1\right) \cdot 1, \left(\frac{x \cdot x}{\mathsf{fma}\left(p, 4 \cdot p, x \cdot x\right)} \cdot \frac{x}{\sqrt{\mathsf{fma}\left(p, 4 \cdot p, x \cdot x\right)}}\right) \cdot \left(\frac{x \cdot x}{\mathsf{fma}\left(p, 4 \cdot p, x \cdot x\right)} \cdot \frac{x}{\sqrt{\mathsf{fma}\left(p, 4 \cdot p, x \cdot x\right)}}\right)\right)}}{\mathsf{fma}\left(1, 1 - \frac{x}{\sqrt{\mathsf{fma}\left(p, 4 \cdot p, x \cdot x\right)}}, \frac{x \cdot x}{\mathsf{fma}\left(p, 4 \cdot p, x \cdot x\right)}\right)} \cdot 0.5}
double f(double p, double x) {
        double r10560695 = 0.5;
        double r10560696 = 1.0;
        double r10560697 = x;
        double r10560698 = 4.0;
        double r10560699 = p;
        double r10560700 = r10560698 * r10560699;
        double r10560701 = r10560700 * r10560699;
        double r10560702 = r10560697 * r10560697;
        double r10560703 = r10560701 + r10560702;
        double r10560704 = sqrt(r10560703);
        double r10560705 = r10560697 / r10560704;
        double r10560706 = r10560696 + r10560705;
        double r10560707 = r10560695 * r10560706;
        double r10560708 = sqrt(r10560707);
        return r10560708;
}

double f(double p, double x) {
        double r10560709 = 1.0;
        double r10560710 = r10560709 * r10560709;
        double r10560711 = r10560710 * r10560709;
        double r10560712 = r10560711 * r10560711;
        double r10560713 = x;
        double r10560714 = r10560713 * r10560713;
        double r10560715 = p;
        double r10560716 = 4.0;
        double r10560717 = r10560716 * r10560715;
        double r10560718 = fma(r10560715, r10560717, r10560714);
        double r10560719 = r10560714 / r10560718;
        double r10560720 = sqrt(r10560718);
        double r10560721 = r10560713 / r10560720;
        double r10560722 = r10560719 * r10560721;
        double r10560723 = r10560722 * r10560722;
        double r10560724 = r10560722 * r10560723;
        double r10560725 = fma(r10560712, r10560711, r10560724);
        double r10560726 = r10560711 - r10560722;
        double r10560727 = fma(r10560726, r10560711, r10560723);
        double r10560728 = r10560725 / r10560727;
        double r10560729 = r10560709 - r10560721;
        double r10560730 = fma(r10560709, r10560729, r10560719);
        double r10560731 = r10560728 / r10560730;
        double r10560732 = 0.5;
        double r10560733 = r10560731 * r10560732;
        double r10560734 = sqrt(r10560733);
        return r10560734;
}

Error

Bits error versus p

Bits error versus x

Target

Original12.9
Target12.9
Herbie12.9
\[\sqrt{0.5 + \frac{\mathsf{copysign}\left(0.5, x\right)}{\mathsf{hypot}\left(1, \frac{2 \cdot p}{x}\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{\left(\frac{x}{\sqrt{\mathsf{fma}\left(p \cdot 4, p, x \cdot x\right)}} + 1\right) \cdot 0.5}}\]
  3. Using strategy rm
  4. Applied flip3-+12.9

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

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

    \[\leadsto \sqrt{\frac{\mathsf{fma}\left(\frac{x}{\sqrt{\mathsf{fma}\left(p, 4 \cdot p, x \cdot x\right)}}, \frac{x \cdot x}{\mathsf{fma}\left(p, 4 \cdot p, x \cdot x\right)}, \left(1 \cdot 1\right) \cdot 1\right)}{\color{blue}{\mathsf{fma}\left(1, 1 - \frac{x}{\sqrt{\mathsf{fma}\left(p, 4 \cdot p, x \cdot x\right)}}, \frac{x \cdot x}{\mathsf{fma}\left(p, 4 \cdot p, x \cdot x\right)}\right)}} \cdot 0.5}\]
  7. Using strategy rm
  8. Applied expm1-log1p-u12.9

    \[\leadsto \sqrt{\frac{\mathsf{fma}\left(\frac{x}{\sqrt{\mathsf{fma}\left(p, 4 \cdot p, x \cdot x\right)}}, \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{x \cdot x}{\mathsf{fma}\left(p, 4 \cdot p, x \cdot x\right)}\right)\right)}, \left(1 \cdot 1\right) \cdot 1\right)}{\mathsf{fma}\left(1, 1 - \frac{x}{\sqrt{\mathsf{fma}\left(p, 4 \cdot p, x \cdot x\right)}}, \frac{x \cdot x}{\mathsf{fma}\left(p, 4 \cdot p, x \cdot x\right)}\right)} \cdot 0.5}\]
  9. Using strategy rm
  10. Applied fma-udef12.9

    \[\leadsto \sqrt{\frac{\color{blue}{\frac{x}{\sqrt{\mathsf{fma}\left(p, 4 \cdot p, x \cdot x\right)}} \cdot \mathsf{expm1}\left(\mathsf{log1p}\left(\frac{x \cdot x}{\mathsf{fma}\left(p, 4 \cdot p, x \cdot x\right)}\right)\right) + \left(1 \cdot 1\right) \cdot 1}}{\mathsf{fma}\left(1, 1 - \frac{x}{\sqrt{\mathsf{fma}\left(p, 4 \cdot p, x \cdot x\right)}}, \frac{x \cdot x}{\mathsf{fma}\left(p, 4 \cdot p, x \cdot x\right)}\right)} \cdot 0.5}\]
  11. Using strategy rm
  12. Applied flip3-+12.9

    \[\leadsto \sqrt{\frac{\color{blue}{\frac{{\left(\frac{x}{\sqrt{\mathsf{fma}\left(p, 4 \cdot p, x \cdot x\right)}} \cdot \mathsf{expm1}\left(\mathsf{log1p}\left(\frac{x \cdot x}{\mathsf{fma}\left(p, 4 \cdot p, x \cdot x\right)}\right)\right)\right)}^{3} + {\left(\left(1 \cdot 1\right) \cdot 1\right)}^{3}}{\left(\frac{x}{\sqrt{\mathsf{fma}\left(p, 4 \cdot p, x \cdot x\right)}} \cdot \mathsf{expm1}\left(\mathsf{log1p}\left(\frac{x \cdot x}{\mathsf{fma}\left(p, 4 \cdot p, x \cdot x\right)}\right)\right)\right) \cdot \left(\frac{x}{\sqrt{\mathsf{fma}\left(p, 4 \cdot p, x \cdot x\right)}} \cdot \mathsf{expm1}\left(\mathsf{log1p}\left(\frac{x \cdot x}{\mathsf{fma}\left(p, 4 \cdot p, x \cdot x\right)}\right)\right)\right) + \left(\left(\left(1 \cdot 1\right) \cdot 1\right) \cdot \left(\left(1 \cdot 1\right) \cdot 1\right) - \left(\frac{x}{\sqrt{\mathsf{fma}\left(p, 4 \cdot p, x \cdot x\right)}} \cdot \mathsf{expm1}\left(\mathsf{log1p}\left(\frac{x \cdot x}{\mathsf{fma}\left(p, 4 \cdot p, x \cdot x\right)}\right)\right)\right) \cdot \left(\left(1 \cdot 1\right) \cdot 1\right)\right)}}}{\mathsf{fma}\left(1, 1 - \frac{x}{\sqrt{\mathsf{fma}\left(p, 4 \cdot p, x \cdot x\right)}}, \frac{x \cdot x}{\mathsf{fma}\left(p, 4 \cdot p, x \cdot x\right)}\right)} \cdot 0.5}\]
  13. Simplified12.9

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

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

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

Reproduce

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

  :herbie-target
  (sqrt (+ 0.5 (/ (copysign 0.5 x) (hypot 1.0 (/ (* 2.0 p) x)))))

  (sqrt (* 0.5 (+ 1.0 (/ x (sqrt (+ (* (* 4.0 p) p) (* x x))))))))