Average Error: 13.2 → 13.2
Time: 7.7s
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 r408043 = 0.5;
        double r408044 = 1.0;
        double r408045 = x;
        double r408046 = 4.0;
        double r408047 = p;
        double r408048 = r408046 * r408047;
        double r408049 = r408048 * r408047;
        double r408050 = r408045 * r408045;
        double r408051 = r408049 + r408050;
        double r408052 = sqrt(r408051);
        double r408053 = r408045 / r408052;
        double r408054 = r408044 + r408053;
        double r408055 = r408043 * r408054;
        double r408056 = sqrt(r408055);
        return r408056;
}

double f(double p, double x) {
        double r408057 = x;
        double r408058 = 4.0;
        double r408059 = p;
        double r408060 = r408058 * r408059;
        double r408061 = r408060 * r408059;
        double r408062 = r408057 * r408057;
        double r408063 = r408061 + r408062;
        double r408064 = sqrt(r408063);
        double r408065 = r408057 / r408064;
        double r408066 = 1.1238977166951507e-10;
        bool r408067 = r408065 <= r408066;
        double r408068 = 0.5;
        double r408069 = 1.0;
        double r408070 = r408069 * r408069;
        double r408071 = r408065 * r408065;
        double r408072 = r408070 - r408071;
        double r408073 = r408068 * r408072;
        double r408074 = sqrt(r408073);
        double r408075 = r408069 - r408065;
        double r408076 = sqrt(r408075);
        double r408077 = r408074 / r408076;
        double r408078 = cbrt(r408063);
        double r408079 = r408078 * r408078;
        double r408080 = r408079 * r408078;
        double r408081 = sqrt(r408080);
        double r408082 = r408057 / r408081;
        double r408083 = r408069 + r408082;
        double r408084 = r408068 * r408083;
        double r408085 = sqrt(r408084);
        double r408086 = exp(r408085);
        double r408087 = log(r408086);
        double r408088 = r408067 ? r408077 : r408087;
        return r408088;
}

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