Average Error: 13.2 → 13.2
Time: 8.1s
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.1238977166951507 \cdot 10^{-10}:\\ \;\;\;\;\frac{\sqrt{0.5 \cdot \left(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}}\right)}}{\sqrt{1 - \frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}}}\\ \mathbf{else}:\\ \;\;\;\;\log \left(e^{\sqrt{0.5 \cdot \left(1 + \frac{x}{\sqrt{\left(\sqrt[3]{\left(4 \cdot p\right) \cdot p + x \cdot x} \cdot \sqrt[3]{\left(4 \cdot p\right) \cdot p + x \cdot x}\right) \cdot \sqrt[3]{\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 1.1238977166951507 \cdot 10^{-10}:\\
\;\;\;\;\frac{\sqrt{0.5 \cdot \left(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}}\right)}}{\sqrt{1 - \frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}}}\\

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

\end{array}
double f(double p, double x) {
        double r405633 = 0.5;
        double r405634 = 1.0;
        double r405635 = x;
        double r405636 = 4.0;
        double r405637 = p;
        double r405638 = r405636 * r405637;
        double r405639 = r405638 * r405637;
        double r405640 = r405635 * r405635;
        double r405641 = r405639 + r405640;
        double r405642 = sqrt(r405641);
        double r405643 = r405635 / r405642;
        double r405644 = r405634 + r405643;
        double r405645 = r405633 * r405644;
        double r405646 = sqrt(r405645);
        return r405646;
}

double f(double p, double x) {
        double r405647 = x;
        double r405648 = 4.0;
        double r405649 = p;
        double r405650 = r405648 * r405649;
        double r405651 = r405650 * r405649;
        double r405652 = r405647 * r405647;
        double r405653 = r405651 + r405652;
        double r405654 = sqrt(r405653);
        double r405655 = r405647 / r405654;
        double r405656 = 1.1238977166951507e-10;
        bool r405657 = r405655 <= r405656;
        double r405658 = 0.5;
        double r405659 = 1.0;
        double r405660 = r405659 * r405659;
        double r405661 = r405655 * r405655;
        double r405662 = r405660 - r405661;
        double r405663 = r405658 * r405662;
        double r405664 = sqrt(r405663);
        double r405665 = r405659 - r405655;
        double r405666 = sqrt(r405665);
        double r405667 = r405664 / r405666;
        double r405668 = cbrt(r405653);
        double r405669 = r405668 * r405668;
        double r405670 = r405669 * r405668;
        double r405671 = sqrt(r405670);
        double r405672 = r405647 / r405671;
        double r405673 = r405659 + r405672;
        double r405674 = r405658 * r405673;
        double r405675 = sqrt(r405674);
        double r405676 = exp(r405675);
        double r405677 = log(r405676);
        double r405678 = r405657 ? r405667 : r405677;
        return r405678;
}

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.2
Target13.2
Herbie13.2
\[\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.1238977166951507e-10

    1. Initial program 18.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 flip-+18.0

      \[\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}}}}}\]
    4. Applied associate-*r/18.0

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

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

    if 1.1238977166951507e-10 < (/ 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-cube-cbrt0.0

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

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

Reproduce

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