Average Error: 13.3 → 10.9
Time: 11.5s
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 r307513 = 0.5;
        double r307514 = 1.0;
        double r307515 = x;
        double r307516 = 4.0;
        double r307517 = p;
        double r307518 = r307516 * r307517;
        double r307519 = r307518 * r307517;
        double r307520 = r307515 * r307515;
        double r307521 = r307519 + r307520;
        double r307522 = sqrt(r307521);
        double r307523 = r307515 / r307522;
        double r307524 = r307514 + r307523;
        double r307525 = r307513 * r307524;
        double r307526 = sqrt(r307525);
        return r307526;
}

double f(double p, double x) {
        double r307527 = x;
        double r307528 = 4.0;
        double r307529 = p;
        double r307530 = r307528 * r307529;
        double r307531 = r307530 * r307529;
        double r307532 = r307527 * r307527;
        double r307533 = r307531 + r307532;
        double r307534 = sqrt(r307533);
        double r307535 = r307527 / r307534;
        double r307536 = -1.0;
        bool r307537 = r307535 <= r307536;
        double r307538 = 0.5;
        double r307539 = 2.0;
        double r307540 = log(r307539);
        double r307541 = 2.0;
        double r307542 = -1.0;
        double r307543 = r307542 / r307527;
        double r307544 = log(r307543);
        double r307545 = r307542 / r307529;
        double r307546 = log(r307545);
        double r307547 = r307544 - r307546;
        double r307548 = r307541 * r307547;
        double r307549 = r307540 + r307548;
        double r307550 = exp(r307549);
        double r307551 = r307538 * r307550;
        double r307552 = sqrt(r307551);
        double r307553 = 1.0;
        double r307554 = r307553 + r307535;
        double r307555 = log(r307554);
        double r307556 = 3.0;
        double r307557 = pow(r307555, r307556);
        double r307558 = cbrt(r307557);
        double r307559 = pow(r307558, r307556);
        double r307560 = cbrt(r307559);
        double r307561 = pow(r307560, r307556);
        double r307562 = cbrt(r307561);
        double r307563 = exp(r307562);
        double r307564 = r307538 * r307563;
        double r307565 = sqrt(r307564);
        double r307566 = r307537 ? r307552 : r307565;
        return r307566;
}

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))))))))