Average Error: 13.1 → 14.1
Time: 15.0s
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 \left(1 + \frac{1}{\sqrt{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}} \cdot \frac{-x}{-\sqrt{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}}\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 \left(1 + \frac{1}{\sqrt{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}} \cdot \frac{-x}{-\sqrt{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}}\right)}
double f(double p, double x) {
        double r751 = 0.5;
        double r752 = 1.0;
        double r753 = x;
        double r754 = 4.0;
        double r755 = p;
        double r756 = r754 * r755;
        double r757 = r756 * r755;
        double r758 = r753 * r753;
        double r759 = r757 + r758;
        double r760 = sqrt(r759);
        double r761 = r753 / r760;
        double r762 = r752 + r761;
        double r763 = r751 * r762;
        double r764 = sqrt(r763);
        return r764;
}

double f(double p, double x) {
        double r765 = 0.5;
        double r766 = 1.0;
        double r767 = 1.0;
        double r768 = 4.0;
        double r769 = p;
        double r770 = r768 * r769;
        double r771 = r770 * r769;
        double r772 = x;
        double r773 = r772 * r772;
        double r774 = r771 + r773;
        double r775 = sqrt(r774);
        double r776 = sqrt(r775);
        double r777 = r767 / r776;
        double r778 = -r772;
        double r779 = -r776;
        double r780 = r778 / r779;
        double r781 = r777 * r780;
        double r782 = r766 + r781;
        double r783 = r765 * r782;
        double r784 = sqrt(r783);
        return r784;
}

Error

Bits error versus p

Bits error versus x

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original13.1
Target13.1
Herbie14.1
\[\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.1

    \[\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 add-sqr-sqrt13.1

    \[\leadsto \sqrt{0.5 \cdot \left(1 + \frac{x}{\sqrt{\color{blue}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x} \cdot \sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}}}\right)}\]
  4. Applied sqrt-prod14.1

    \[\leadsto \sqrt{0.5 \cdot \left(1 + \frac{x}{\color{blue}{\sqrt{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}} \cdot \sqrt{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}}}\right)}\]
  5. Applied *-un-lft-identity14.1

    \[\leadsto \sqrt{0.5 \cdot \left(1 + \frac{\color{blue}{1 \cdot x}}{\sqrt{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}} \cdot \sqrt{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}}\right)}\]
  6. Applied times-frac14.1

    \[\leadsto \sqrt{0.5 \cdot \left(1 + \color{blue}{\frac{1}{\sqrt{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}} \cdot \frac{x}{\sqrt{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}}}\right)}\]
  7. Using strategy rm
  8. Applied frac-2neg14.1

    \[\leadsto \sqrt{0.5 \cdot \left(1 + \frac{1}{\sqrt{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}} \cdot \color{blue}{\frac{-x}{-\sqrt{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}}}\right)}\]
  9. Final simplification14.1

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

Reproduce

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