Average Error: 13.3 → 10.9
Time: 11.6s
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 -1:\\ \;\;\;\;\sqrt{0.5 \cdot e^{\log 2 + 2 \cdot \left(\log \left(\frac{-1}{x}\right) - \log \left(\frac{-1}{p}\right)\right)}}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{0.5 \cdot e^{\sqrt[3]{{\left(\sqrt[3]{{\left(\sqrt[3]{{\left(\log \left(1 + \frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}\right)\right)}^{3}}\right)}^{3}}\right)}^{3}}}}\\ \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 -1:\\
\;\;\;\;\sqrt{0.5 \cdot e^{\log 2 + 2 \cdot \left(\log \left(\frac{-1}{x}\right) - \log \left(\frac{-1}{p}\right)\right)}}\\

\mathbf{else}:\\
\;\;\;\;\sqrt{0.5 \cdot e^{\sqrt[3]{{\left(\sqrt[3]{{\left(\sqrt[3]{{\left(\log \left(1 + \frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}\right)\right)}^{3}}\right)}^{3}}\right)}^{3}}}}\\

\end{array}
double f(double p, double x) {
        double r376280 = 0.5;
        double r376281 = 1.0;
        double r376282 = x;
        double r376283 = 4.0;
        double r376284 = p;
        double r376285 = r376283 * r376284;
        double r376286 = r376285 * r376284;
        double r376287 = r376282 * r376282;
        double r376288 = r376286 + r376287;
        double r376289 = sqrt(r376288);
        double r376290 = r376282 / r376289;
        double r376291 = r376281 + r376290;
        double r376292 = r376280 * r376291;
        double r376293 = sqrt(r376292);
        return r376293;
}

double f(double p, double x) {
        double r376294 = x;
        double r376295 = 4.0;
        double r376296 = p;
        double r376297 = r376295 * r376296;
        double r376298 = r376297 * r376296;
        double r376299 = r376294 * r376294;
        double r376300 = r376298 + r376299;
        double r376301 = sqrt(r376300);
        double r376302 = r376294 / r376301;
        double r376303 = -1.0;
        bool r376304 = r376302 <= r376303;
        double r376305 = 0.5;
        double r376306 = 2.0;
        double r376307 = log(r376306);
        double r376308 = 2.0;
        double r376309 = -1.0;
        double r376310 = r376309 / r376294;
        double r376311 = log(r376310);
        double r376312 = r376309 / r376296;
        double r376313 = log(r376312);
        double r376314 = r376311 - r376313;
        double r376315 = r376308 * r376314;
        double r376316 = r376307 + r376315;
        double r376317 = exp(r376316);
        double r376318 = r376305 * r376317;
        double r376319 = sqrt(r376318);
        double r376320 = 1.0;
        double r376321 = r376320 + r376302;
        double r376322 = log(r376321);
        double r376323 = 3.0;
        double r376324 = pow(r376322, r376323);
        double r376325 = cbrt(r376324);
        double r376326 = pow(r376325, r376323);
        double r376327 = cbrt(r376326);
        double r376328 = pow(r376327, r376323);
        double r376329 = cbrt(r376328);
        double r376330 = exp(r376329);
        double r376331 = r376305 * r376330;
        double r376332 = sqrt(r376331);
        double r376333 = r376304 ? r376319 : r376332;
        return r376333;
}

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.3
Target13.3
Herbie10.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)))) < -1.0

    1. Initial program 54.2

      \[\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-exp-log54.2

      \[\leadsto \sqrt{0.5 \cdot \color{blue}{e^{\log \left(1 + \frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}\right)}}}\]
    4. Taylor expanded around -inf 44.1

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

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

    if -1.0 < (/ x (sqrt (+ (* (* 4.0 p) p) (* x x))))

    1. Initial program 0.2

      \[\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-exp-log0.2

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

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

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

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

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

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

      \[\leadsto \sqrt{0.5 \cdot e^{\sqrt[3]{{\left(\sqrt[3]{{\left(\sqrt[3]{\color{blue}{{\left(\log \left(1 + \frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}\right)\right)}^{3}}}\right)}^{3}}\right)}^{3}}}}\]
  3. Recombined 2 regimes into one program.
  4. Final simplification10.9

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}} \le -1:\\ \;\;\;\;\sqrt{0.5 \cdot e^{\log 2 + 2 \cdot \left(\log \left(\frac{-1}{x}\right) - \log \left(\frac{-1}{p}\right)\right)}}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{0.5 \cdot e^{\sqrt[3]{{\left(\sqrt[3]{{\left(\sqrt[3]{{\left(\log \left(1 + \frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}\right)\right)}^{3}}\right)}^{3}}\right)}^{3}}}}\\ \end{array}\]

Reproduce

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