Average Error: 12.9 → 12.9
Time: 6.2s
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)}\]
\[\begin{array}{l} \mathbf{if}\;\frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}} \le 4.5334810319720984 \cdot 10^{-6}:\\ \;\;\;\;\sqrt{0.5 \cdot \frac{1 \cdot 1 - \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 - \frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}}}\\ \mathbf{else}:\\ \;\;\;\;\log \left(\sqrt{e^{\sqrt{0.5 \cdot \left(1 + \frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}\right)}}}\right) + \log \left(\sqrt{e^{\sqrt{0.5 \cdot \left(1 + \frac{x}{\sqrt{\left(\sqrt[3]{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}} \cdot \sqrt[3]{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}\right) \cdot \sqrt[3]{\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)}}}\right)\\ \end{array}\]
\sqrt{0.5 \cdot \left(1 + \frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}\right)}
\begin{array}{l}
\mathbf{if}\;\frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}} \le 4.5334810319720984 \cdot 10^{-6}:\\
\;\;\;\;\sqrt{0.5 \cdot \frac{1 \cdot 1 - \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 - \frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}}}\\

\mathbf{else}:\\
\;\;\;\;\log \left(\sqrt{e^{\sqrt{0.5 \cdot \left(1 + \frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}\right)}}}\right) + \log \left(\sqrt{e^{\sqrt{0.5 \cdot \left(1 + \frac{x}{\sqrt{\left(\sqrt[3]{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}} \cdot \sqrt[3]{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}\right) \cdot \sqrt[3]{\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)}}}\right)\\

\end{array}
double f(double p, double x) {
        double r316808 = 0.5;
        double r316809 = 1.0;
        double r316810 = x;
        double r316811 = 4.0;
        double r316812 = p;
        double r316813 = r316811 * r316812;
        double r316814 = r316813 * r316812;
        double r316815 = r316810 * r316810;
        double r316816 = r316814 + r316815;
        double r316817 = sqrt(r316816);
        double r316818 = r316810 / r316817;
        double r316819 = r316809 + r316818;
        double r316820 = r316808 * r316819;
        double r316821 = sqrt(r316820);
        return r316821;
}

double f(double p, double x) {
        double r316822 = x;
        double r316823 = 4.0;
        double r316824 = p;
        double r316825 = r316823 * r316824;
        double r316826 = r316825 * r316824;
        double r316827 = r316822 * r316822;
        double r316828 = r316826 + r316827;
        double r316829 = sqrt(r316828);
        double r316830 = r316822 / r316829;
        double r316831 = 4.533481031972098e-06;
        bool r316832 = r316830 <= r316831;
        double r316833 = 0.5;
        double r316834 = 1.0;
        double r316835 = r316834 * r316834;
        double r316836 = r316830 * r316830;
        double r316837 = r316835 - r316836;
        double r316838 = r316834 - r316830;
        double r316839 = r316837 / r316838;
        double r316840 = r316833 * r316839;
        double r316841 = sqrt(r316840);
        double r316842 = r316834 + r316830;
        double r316843 = r316833 * r316842;
        double r316844 = sqrt(r316843);
        double r316845 = exp(r316844);
        double r316846 = sqrt(r316845);
        double r316847 = log(r316846);
        double r316848 = cbrt(r316829);
        double r316849 = r316848 * r316848;
        double r316850 = r316849 * r316848;
        double r316851 = sqrt(r316850);
        double r316852 = sqrt(r316829);
        double r316853 = r316851 * r316852;
        double r316854 = r316822 / r316853;
        double r316855 = r316834 + r316854;
        double r316856 = r316833 * r316855;
        double r316857 = sqrt(r316856);
        double r316858 = exp(r316857);
        double r316859 = sqrt(r316858);
        double r316860 = log(r316859);
        double r316861 = r316847 + r316860;
        double r316862 = r316832 ? r316841 : r316861;
        return r316862;
}

Error

Bits error versus p

Bits error versus x

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

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. Split input into 2 regimes
  2. if (/ x (sqrt (+ (* (* 4.0 p) p) (* x x)))) < 4.533481031972098e-06

    1. Initial program 17.4

      \[\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 flip-+17.4

      \[\leadsto \sqrt{0.5 \cdot \color{blue}{\frac{1 \cdot 1 - \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 - \frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}}}}\]

    if 4.533481031972098e-06 < (/ x (sqrt (+ (* (* 4.0 p) p) (* x x))))

    1. Initial program 0.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 add-log-exp0.0

      \[\leadsto \color{blue}{\log \left(e^{\sqrt{0.5 \cdot \left(1 + \frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}\right)}}\right)}\]
    4. Using strategy rm
    5. Applied add-sqr-sqrt0.0

      \[\leadsto \log \color{blue}{\left(\sqrt{e^{\sqrt{0.5 \cdot \left(1 + \frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}\right)}}} \cdot \sqrt{e^{\sqrt{0.5 \cdot \left(1 + \frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}\right)}}}\right)}\]
    6. Applied log-prod0.0

      \[\leadsto \color{blue}{\log \left(\sqrt{e^{\sqrt{0.5 \cdot \left(1 + \frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}\right)}}}\right) + \log \left(\sqrt{e^{\sqrt{0.5 \cdot \left(1 + \frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}\right)}}}\right)}\]
    7. Using strategy rm
    8. Applied add-sqr-sqrt0.0

      \[\leadsto \log \left(\sqrt{e^{\sqrt{0.5 \cdot \left(1 + \frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}\right)}}}\right) + \log \left(\sqrt{e^{\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)}}}\right)\]
    9. Applied sqrt-prod0.0

      \[\leadsto \log \left(\sqrt{e^{\sqrt{0.5 \cdot \left(1 + \frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}\right)}}}\right) + \log \left(\sqrt{e^{\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)}}}\right)\]
    10. Using strategy rm
    11. Applied add-cube-cbrt0.0

      \[\leadsto \log \left(\sqrt{e^{\sqrt{0.5 \cdot \left(1 + \frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}\right)}}}\right) + \log \left(\sqrt{e^{\sqrt{0.5 \cdot \left(1 + \frac{x}{\sqrt{\color{blue}{\left(\sqrt[3]{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}} \cdot \sqrt[3]{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}\right) \cdot \sqrt[3]{\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)}}}\right)\]
  3. Recombined 2 regimes into one program.
  4. Final simplification12.9

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}} \le 4.5334810319720984 \cdot 10^{-6}:\\ \;\;\;\;\sqrt{0.5 \cdot \frac{1 \cdot 1 - \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 - \frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}}}\\ \mathbf{else}:\\ \;\;\;\;\log \left(\sqrt{e^{\sqrt{0.5 \cdot \left(1 + \frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}\right)}}}\right) + \log \left(\sqrt{e^{\sqrt{0.5 \cdot \left(1 + \frac{x}{\sqrt{\left(\sqrt[3]{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}} \cdot \sqrt[3]{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}\right) \cdot \sqrt[3]{\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)}}}\right)\\ \end{array}\]

Reproduce

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