Average Error: 13.0 → 13.0
Time: 4.8s
Precision: 64
\[1.00000000000000001 \cdot 10^{-150} \lt \left|x\right| \lt 9.99999999999999981 \cdot 10^{149}\]
\[\sqrt{0.5 \cdot \left(1 + \frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}\right)}\]
\[\sqrt{0.5 \cdot \frac{{1}^{3} + {\left(\frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}\right)}^{3}}{\mathsf{fma}\left(\frac{x}{\mathsf{fma}\left(4 \cdot p, p, x \cdot x\right)}, x, 1 \cdot \left(1 - \frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}\right)\right)}}\]
\sqrt{0.5 \cdot \left(1 + \frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}\right)}
\sqrt{0.5 \cdot \frac{{1}^{3} + {\left(\frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}\right)}^{3}}{\mathsf{fma}\left(\frac{x}{\mathsf{fma}\left(4 \cdot p, p, x \cdot x\right)}, x, 1 \cdot \left(1 - \frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}\right)\right)}}
double f(double p, double x) {
        double r315649 = 0.5;
        double r315650 = 1.0;
        double r315651 = x;
        double r315652 = 4.0;
        double r315653 = p;
        double r315654 = r315652 * r315653;
        double r315655 = r315654 * r315653;
        double r315656 = r315651 * r315651;
        double r315657 = r315655 + r315656;
        double r315658 = sqrt(r315657);
        double r315659 = r315651 / r315658;
        double r315660 = r315650 + r315659;
        double r315661 = r315649 * r315660;
        double r315662 = sqrt(r315661);
        return r315662;
}

double f(double p, double x) {
        double r315663 = 0.5;
        double r315664 = 1.0;
        double r315665 = 3.0;
        double r315666 = pow(r315664, r315665);
        double r315667 = x;
        double r315668 = 4.0;
        double r315669 = p;
        double r315670 = r315668 * r315669;
        double r315671 = r315670 * r315669;
        double r315672 = r315667 * r315667;
        double r315673 = r315671 + r315672;
        double r315674 = sqrt(r315673);
        double r315675 = r315667 / r315674;
        double r315676 = pow(r315675, r315665);
        double r315677 = r315666 + r315676;
        double r315678 = fma(r315670, r315669, r315672);
        double r315679 = r315667 / r315678;
        double r315680 = r315664 - r315675;
        double r315681 = r315664 * r315680;
        double r315682 = fma(r315679, r315667, r315681);
        double r315683 = r315677 / r315682;
        double r315684 = r315663 * r315683;
        double r315685 = sqrt(r315684);
        return r315685;
}

Error

Bits error versus p

Bits error versus x

Target

Original13.0
Target13.0
Herbie13.0
\[\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 13.0

    \[\sqrt{0.5 \cdot \left(1 + \frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}\right)}\]
  2. Using strategy rm
  3. Applied flip3-+13.0

    \[\leadsto \sqrt{0.5 \cdot \color{blue}{\frac{{1}^{3} + {\left(\frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}\right)}^{3}}{1 \cdot 1 + \left(\frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}} \cdot \frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}} - 1 \cdot \frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}\right)}}}\]
  4. Simplified13.0

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

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

Reproduce

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

  :herbie-target
  (sqrt (+ 0.5 (/ (copysign 0.5 x) (hypot 1 (/ (* 2 p) x)))))

  (sqrt (* 0.5 (+ 1 (/ x (sqrt (+ (* (* 4 p) p) (* x x))))))))