Average Error: 13.1 → 14.1
Time: 6.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}\;x \le -1.1394059361264092 \cdot 10^{138}:\\ \;\;\;\;\log \left(e^{\sqrt{0.5 \cdot \frac{\left(-x \cdot x\right) \cdot \frac{1}{\left(4 \cdot p\right) \cdot p + x \cdot x} + 1 \cdot 1}{1 - x \cdot \frac{1}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}}}}\right)\\ \mathbf{elif}\;x \le -4.7086389988959359 \cdot 10^{125}:\\ \;\;\;\;e^{\left(\log \left(\sqrt{2} \cdot \sqrt{0.5}\right) + \log \left(\frac{-1}{x}\right)\right) - \log \left(\frac{-1}{p}\right)}\\ \mathbf{elif}\;x \le -140531020550505330000:\\ \;\;\;\;\log \left(e^{\sqrt{0.5 \cdot \frac{\left(-x \cdot x\right) \cdot \frac{1}{\left(4 \cdot p\right) \cdot p + x \cdot x} + 1 \cdot 1}{1 - x \cdot \frac{1}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}}}}\right)\\ \mathbf{elif}\;x \le -454354590.679686964:\\ \;\;\;\;e^{\left(\log \left(\sqrt{2} \cdot \sqrt{0.5}\right) + \log \left(\frac{-1}{x}\right)\right) - \log \left(\frac{-1}{p}\right)}\\ \mathbf{else}:\\ \;\;\;\;\log \left(e^{\sqrt{0.5 \cdot \left(1 + \left(\sqrt[3]{x} \cdot \sqrt[3]{x}\right) \cdot \frac{\sqrt[3]{x}}{\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}\;x \le -1.1394059361264092 \cdot 10^{138}:\\
\;\;\;\;\log \left(e^{\sqrt{0.5 \cdot \frac{\left(-x \cdot x\right) \cdot \frac{1}{\left(4 \cdot p\right) \cdot p + x \cdot x} + 1 \cdot 1}{1 - x \cdot \frac{1}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}}}}\right)\\

\mathbf{elif}\;x \le -4.7086389988959359 \cdot 10^{125}:\\
\;\;\;\;e^{\left(\log \left(\sqrt{2} \cdot \sqrt{0.5}\right) + \log \left(\frac{-1}{x}\right)\right) - \log \left(\frac{-1}{p}\right)}\\

\mathbf{elif}\;x \le -140531020550505330000:\\
\;\;\;\;\log \left(e^{\sqrt{0.5 \cdot \frac{\left(-x \cdot x\right) \cdot \frac{1}{\left(4 \cdot p\right) \cdot p + x \cdot x} + 1 \cdot 1}{1 - x \cdot \frac{1}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}}}}\right)\\

\mathbf{elif}\;x \le -454354590.679686964:\\
\;\;\;\;e^{\left(\log \left(\sqrt{2} \cdot \sqrt{0.5}\right) + \log \left(\frac{-1}{x}\right)\right) - \log \left(\frac{-1}{p}\right)}\\

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

\end{array}
double f(double p, double x) {
        double r393381 = 0.5;
        double r393382 = 1.0;
        double r393383 = x;
        double r393384 = 4.0;
        double r393385 = p;
        double r393386 = r393384 * r393385;
        double r393387 = r393386 * r393385;
        double r393388 = r393383 * r393383;
        double r393389 = r393387 + r393388;
        double r393390 = sqrt(r393389);
        double r393391 = r393383 / r393390;
        double r393392 = r393382 + r393391;
        double r393393 = r393381 * r393392;
        double r393394 = sqrt(r393393);
        return r393394;
}

double f(double p, double x) {
        double r393395 = x;
        double r393396 = -1.1394059361264092e+138;
        bool r393397 = r393395 <= r393396;
        double r393398 = 0.5;
        double r393399 = r393395 * r393395;
        double r393400 = -r393399;
        double r393401 = 1.0;
        double r393402 = 4.0;
        double r393403 = p;
        double r393404 = r393402 * r393403;
        double r393405 = r393404 * r393403;
        double r393406 = r393405 + r393399;
        double r393407 = r393401 / r393406;
        double r393408 = r393400 * r393407;
        double r393409 = 1.0;
        double r393410 = r393409 * r393409;
        double r393411 = r393408 + r393410;
        double r393412 = sqrt(r393406);
        double r393413 = r393401 / r393412;
        double r393414 = r393395 * r393413;
        double r393415 = r393409 - r393414;
        double r393416 = r393411 / r393415;
        double r393417 = r393398 * r393416;
        double r393418 = sqrt(r393417);
        double r393419 = exp(r393418);
        double r393420 = log(r393419);
        double r393421 = -4.708638998895936e+125;
        bool r393422 = r393395 <= r393421;
        double r393423 = 2.0;
        double r393424 = sqrt(r393423);
        double r393425 = sqrt(r393398);
        double r393426 = r393424 * r393425;
        double r393427 = log(r393426);
        double r393428 = -1.0;
        double r393429 = r393428 / r393395;
        double r393430 = log(r393429);
        double r393431 = r393427 + r393430;
        double r393432 = r393428 / r393403;
        double r393433 = log(r393432);
        double r393434 = r393431 - r393433;
        double r393435 = exp(r393434);
        double r393436 = -1.4053102055050533e+20;
        bool r393437 = r393395 <= r393436;
        double r393438 = -454354590.67968696;
        bool r393439 = r393395 <= r393438;
        double r393440 = cbrt(r393395);
        double r393441 = r393440 * r393440;
        double r393442 = r393440 / r393412;
        double r393443 = r393441 * r393442;
        double r393444 = r393409 + r393443;
        double r393445 = r393398 * r393444;
        double r393446 = sqrt(r393445);
        double r393447 = exp(r393446);
        double r393448 = log(r393447);
        double r393449 = r393439 ? r393435 : r393448;
        double r393450 = r393437 ? r393420 : r393449;
        double r393451 = r393422 ? r393435 : r393450;
        double r393452 = r393397 ? r393420 : r393451;
        return r393452;
}

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. Split input into 3 regimes
  2. if x < -1.1394059361264092e+138 or -4.708638998895936e+125 < x < -1.4053102055050533e+20

    1. Initial program 29.6

      \[\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-inv30.8

      \[\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 add-log-exp30.8

      \[\leadsto \color{blue}{\log \left(e^{\sqrt{0.5 \cdot \left(1 + x \cdot \frac{1}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}\right)}}\right)}\]
    6. Using strategy rm
    7. Applied flip-+30.8

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

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

    if -1.1394059361264092e+138 < x < -4.708638998895936e+125 or -1.4053102055050533e+20 < x < -454354590.67968696

    1. Initial program 30.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 div-inv30.9

      \[\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 add-log-exp30.9

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

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

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

    if -454354590.67968696 < x

    1. Initial program 8.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-inv8.1

      \[\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 add-log-exp8.1

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

      \[\leadsto \log \left(e^{\sqrt{0.5 \cdot \left(1 + \color{blue}{\left(\left(\sqrt[3]{x} \cdot \sqrt[3]{x}\right) \cdot \sqrt[3]{x}\right)} \cdot \frac{1}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}\right)}}\right)\]
    8. Applied associate-*l*8.2

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

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

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

Reproduce

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