Average Error: 13.1 → 13.3
Time: 20.3s
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)}\]
\[\log \left(e^{\sqrt{0.5 \cdot \frac{\frac{x \cdot x}{\left(4 \cdot p\right) \cdot p + x \cdot x} \cdot \left(x \cdot {\left(\left(4 \cdot p\right) \cdot p + x \cdot x\right)}^{\frac{-1}{2}}\right) + \left(1 \cdot 1\right) \cdot 1}{\left(x \cdot {\left(\left(4 \cdot p\right) \cdot p + x \cdot x\right)}^{\frac{-1}{2}} - 1\right) \cdot \left(x \cdot {\left(\left(4 \cdot p\right) \cdot p + x \cdot x\right)}^{\frac{-1}{2}}\right) + 1 \cdot 1}}}\right)\]
\sqrt{0.5 \cdot \left(1 + \frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}\right)}
\log \left(e^{\sqrt{0.5 \cdot \frac{\frac{x \cdot x}{\left(4 \cdot p\right) \cdot p + x \cdot x} \cdot \left(x \cdot {\left(\left(4 \cdot p\right) \cdot p + x \cdot x\right)}^{\frac{-1}{2}}\right) + \left(1 \cdot 1\right) \cdot 1}{\left(x \cdot {\left(\left(4 \cdot p\right) \cdot p + x \cdot x\right)}^{\frac{-1}{2}} - 1\right) \cdot \left(x \cdot {\left(\left(4 \cdot p\right) \cdot p + x \cdot x\right)}^{\frac{-1}{2}}\right) + 1 \cdot 1}}}\right)
double f(double p, double x) {
        double r10106729 = 0.5;
        double r10106730 = 1.0;
        double r10106731 = x;
        double r10106732 = 4.0;
        double r10106733 = p;
        double r10106734 = r10106732 * r10106733;
        double r10106735 = r10106734 * r10106733;
        double r10106736 = r10106731 * r10106731;
        double r10106737 = r10106735 + r10106736;
        double r10106738 = sqrt(r10106737);
        double r10106739 = r10106731 / r10106738;
        double r10106740 = r10106730 + r10106739;
        double r10106741 = r10106729 * r10106740;
        double r10106742 = sqrt(r10106741);
        return r10106742;
}

double f(double p, double x) {
        double r10106743 = 0.5;
        double r10106744 = x;
        double r10106745 = r10106744 * r10106744;
        double r10106746 = 4.0;
        double r10106747 = p;
        double r10106748 = r10106746 * r10106747;
        double r10106749 = r10106748 * r10106747;
        double r10106750 = r10106749 + r10106745;
        double r10106751 = r10106745 / r10106750;
        double r10106752 = -0.5;
        double r10106753 = pow(r10106750, r10106752);
        double r10106754 = r10106744 * r10106753;
        double r10106755 = r10106751 * r10106754;
        double r10106756 = 1.0;
        double r10106757 = r10106756 * r10106756;
        double r10106758 = r10106757 * r10106756;
        double r10106759 = r10106755 + r10106758;
        double r10106760 = r10106754 - r10106756;
        double r10106761 = r10106760 * r10106754;
        double r10106762 = r10106761 + r10106757;
        double r10106763 = r10106759 / r10106762;
        double r10106764 = r10106743 * r10106763;
        double r10106765 = sqrt(r10106764);
        double r10106766 = exp(r10106765);
        double r10106767 = log(r10106766);
        return r10106767;
}

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

    \[\leadsto \sqrt{0.5 \cdot \left(1 + \color{blue}{x \cdot \frac{1}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}}\right)}\]
  4. Using strategy rm
  5. Applied pow1/213.3

    \[\leadsto \sqrt{0.5 \cdot \left(1 + x \cdot \frac{1}{\color{blue}{{\left(\left(4 \cdot p\right) \cdot p + x \cdot x\right)}^{\frac{1}{2}}}}\right)}\]
  6. Applied pow-flip13.3

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

    \[\leadsto \sqrt{0.5 \cdot \left(1 + x \cdot {\left(\left(4 \cdot p\right) \cdot p + x \cdot x\right)}^{\color{blue}{\frac{-1}{2}}}\right)}\]
  8. Using strategy rm
  9. Applied add-log-exp13.3

    \[\leadsto \color{blue}{\log \left(e^{\sqrt{0.5 \cdot \left(1 + x \cdot {\left(\left(4 \cdot p\right) \cdot p + x \cdot x\right)}^{\frac{-1}{2}}\right)}}\right)}\]
  10. Using strategy rm
  11. Applied flip3-+13.3

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

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

    \[\leadsto \log \left(e^{\sqrt{0.5 \cdot \frac{\left(1 \cdot 1\right) \cdot 1 + \left(x \cdot {\left(\left(4 \cdot p\right) \cdot p + x \cdot x\right)}^{\frac{-1}{2}}\right) \cdot \frac{x \cdot x}{\left(4 \cdot p\right) \cdot p + x \cdot x}}{\color{blue}{1 \cdot 1 + \left(x \cdot {\left(\left(4 \cdot p\right) \cdot p + x \cdot x\right)}^{\frac{-1}{2}}\right) \cdot \left(x \cdot {\left(\left(4 \cdot p\right) \cdot p + x \cdot x\right)}^{\frac{-1}{2}} - 1\right)}}}}\right)\]
  14. Final simplification13.3

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

Reproduce

herbie shell --seed 2019170 
(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))))))))