Average Error: 13.3 → 5.8
Time: 9.2s
Precision: binary64
\[10^{-150} < \left|x\right| \land \left|x\right| < 10^{+150}\]
\[\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{p \cdot \left(4 \cdot p\right) + x \cdot x}} \leq -0.9999999999833178:\\ \;\;\;\;\sqrt{0.5 \cdot \left(2 \cdot \frac{p}{\frac{x}{\frac{p}{x}}}\right)}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{0.5 \cdot \sqrt[3]{{\left(1 + \frac{x}{\sqrt{x \cdot x + 4 \cdot \left(p \cdot p\right)}}\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{p \cdot \left(4 \cdot p\right) + x \cdot x}} \leq -0.9999999999833178:\\
\;\;\;\;\sqrt{0.5 \cdot \left(2 \cdot \frac{p}{\frac{x}{\frac{p}{x}}}\right)}\\

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

\end{array}
(FPCore (p x)
 :precision binary64
 (sqrt (* 0.5 (+ 1.0 (/ x (sqrt (+ (* (* 4.0 p) p) (* x x))))))))
(FPCore (p x)
 :precision binary64
 (if (<= (/ x (sqrt (+ (* p (* 4.0 p)) (* x x)))) -0.9999999999833178)
   (sqrt (* 0.5 (* 2.0 (/ p (/ x (/ p x))))))
   (sqrt
    (*
     0.5
     (cbrt (pow (+ 1.0 (/ x (sqrt (+ (* x x) (* 4.0 (* p p)))))) 3.0))))))
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 tmp;
	if ((x / sqrt((p * (4.0 * p)) + (x * x))) <= -0.9999999999833178) {
		tmp = sqrt(0.5 * (2.0 * (p / (x / (p / x)))));
	} else {
		tmp = sqrt(0.5 * cbrt(pow((1.0 + (x / sqrt((x * x) + (4.0 * (p * p))))), 3.0)));
	}
	return tmp;
}

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
Herbie5.8
\[\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 (/.f64 x (sqrt.f64 (+.f64 (*.f64 (*.f64 4 p) p) (*.f64 x x)))) < -0.99999999998331779

    1. Initial program 53.2

      \[\sqrt{0.5 \cdot \left(1 + \frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}\right)}\]
    2. Taylor expanded around -inf 30.7

      \[\leadsto \sqrt{0.5 \cdot \color{blue}{\left(2 \cdot \frac{{p}^{2}}{{x}^{2}}\right)}}\]
    3. Simplified23.2

      \[\leadsto \sqrt{0.5 \cdot \color{blue}{\left(2 \cdot \frac{p}{\frac{x \cdot x}{p}}\right)}}\]
    4. Using strategy rm
    5. Applied associate-/l*_binary64_241023.1

      \[\leadsto \sqrt{0.5 \cdot \left(2 \cdot \frac{p}{\color{blue}{\frac{x}{\frac{p}{x}}}}\right)}\]

    if -0.99999999998331779 < (/.f64 x (sqrt.f64 (+.f64 (*.f64 (*.f64 4 p) p) (*.f64 x x))))

    1. Initial program 0.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 add-cbrt-cube_binary64_25010.1

      \[\leadsto \sqrt{0.5 \cdot \color{blue}{\sqrt[3]{\left(\left(1 + \frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}\right) \cdot \left(1 + \frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}\right)\right) \cdot \left(1 + \frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}\right)}}}\]
    4. Simplified0.1

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{x}{\sqrt{p \cdot \left(4 \cdot p\right) + x \cdot x}} \leq -0.9999999999833178:\\ \;\;\;\;\sqrt{0.5 \cdot \left(2 \cdot \frac{p}{\frac{x}{\frac{p}{x}}}\right)}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{0.5 \cdot \sqrt[3]{{\left(1 + \frac{x}{\sqrt{x \cdot x + 4 \cdot \left(p \cdot p\right)}}\right)}^{3}}}\\ \end{array}\]

Reproduce

herbie shell --seed 2021050 
(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.0 (/ (* 2.0 p) x)))))

  (sqrt (* 0.5 (+ 1.0 (/ x (sqrt (+ (* (* 4.0 p) p) (* x x))))))))