Average Error: 13.1 → 14.1
Time: 5.9s
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 code(double p, double x) {
	return sqrt((0.5 * (1.0 + (x / sqrt((((4.0 * p) * p) + (x * x)))))));
}
double code(double p, double x) {
	double VAR;
	if ((x <= -1.1394059361264092e+138)) {
		VAR = log(exp(sqrt((0.5 * (((-(x * x) * (1.0 / (((4.0 * p) * p) + (x * x)))) + (1.0 * 1.0)) / (1.0 - (x * (1.0 / sqrt((((4.0 * p) * p) + (x * x)))))))))));
	} else {
		double VAR_1;
		if ((x <= -4.708638998895936e+125)) {
			VAR_1 = exp(((log((sqrt(2.0) * sqrt(0.5))) + log((-1.0 / x))) - log((-1.0 / p))));
		} else {
			double VAR_2;
			if ((x <= -1.4053102055050533e+20)) {
				VAR_2 = log(exp(sqrt((0.5 * (((-(x * x) * (1.0 / (((4.0 * p) * p) + (x * x)))) + (1.0 * 1.0)) / (1.0 - (x * (1.0 / sqrt((((4.0 * p) * p) + (x * x)))))))))));
			} else {
				double VAR_3;
				if ((x <= -454354590.67968696)) {
					VAR_3 = exp(((log((sqrt(2.0) * sqrt(0.5))) + log((-1.0 / x))) - log((-1.0 / p))));
				} else {
					VAR_3 = log(exp(sqrt((0.5 * (1.0 + ((cbrt(x) * cbrt(x)) * (cbrt(x) / sqrt((((4.0 * p) * p) + (x * x))))))))));
				}
				VAR_2 = VAR_3;
			}
			VAR_1 = VAR_2;
		}
		VAR = VAR_1;
	}
	return VAR;
}

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