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

\mathbf{else}:\\
\;\;\;\;\sqrt{0.5 \cdot \sqrt[3]{{\left(1 + \frac{x}{\sqrt{\sqrt{\sqrt[3]{4 \cdot \left(p \cdot p\right) + x \cdot x}} \cdot \left|\sqrt[3]{4 \cdot \left(p \cdot p\right) + x \cdot x}\right|} \cdot \sqrt{\sqrt{\sqrt[3]{4 \cdot \left(p \cdot p\right) + x \cdot x}} \cdot \left|\sqrt[3]{4 \cdot \left(p \cdot p\right) + x \cdot x}\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 -1.2830507578319113e-149)
   (sqrt
    (*
     0.5
     (/
      (+ (pow 1.0 3.0) (pow (/ x (sqrt (+ (* 4.0 (* p p)) (* x x)))) 3.0))
      (+
       (* x (/ x (+ (* 4.0 (* p p)) (* x x))))
       (* 1.0 (- 1.0 (/ x (exp (log (sqrt (+ (* 4.0 (* p p)) (* x x))))))))))))
   (sqrt
    (*
     0.5
     (cbrt
      (pow
       (+
        1.0
        (/
         x
         (*
          (sqrt
           (*
            (sqrt (cbrt (+ (* 4.0 (* p p)) (* x x))))
            (fabs (cbrt (+ (* 4.0 (* p p)) (* x x))))))
          (sqrt
           (*
            (sqrt (cbrt (+ (* 4.0 (* p p)) (* x x))))
            (fabs (cbrt (+ (* 4.0 (* p p)) (* x x)))))))))
       3.0))))))
double code(double p, double x) {
	return ((double) sqrt(((double) (0.5 * ((double) (1.0 + (x / ((double) sqrt(((double) (((double) (((double) (4.0 * p)) * p)) + ((double) (x * x)))))))))))));
}
double code(double p, double x) {
	double tmp;
	if ((x <= -1.2830507578319113e-149)) {
		tmp = ((double) sqrt(((double) (0.5 * (((double) (((double) pow(1.0, 3.0)) + ((double) pow((x / ((double) sqrt(((double) (((double) (4.0 * ((double) (p * p)))) + ((double) (x * x))))))), 3.0)))) / ((double) (((double) (x * (x / ((double) (((double) (4.0 * ((double) (p * p)))) + ((double) (x * x))))))) + ((double) (1.0 * ((double) (1.0 - (x / ((double) exp(((double) log(((double) sqrt(((double) (((double) (4.0 * ((double) (p * p)))) + ((double) (x * x))))))))))))))))))))));
	} else {
		tmp = ((double) sqrt(((double) (0.5 * ((double) cbrt(((double) pow(((double) (1.0 + (x / ((double) (((double) sqrt(((double) (((double) sqrt(((double) cbrt(((double) (((double) (4.0 * ((double) (p * p)))) + ((double) (x * x)))))))) * ((double) fabs(((double) cbrt(((double) (((double) (4.0 * ((double) (p * p)))) + ((double) (x * x)))))))))))) * ((double) sqrt(((double) (((double) sqrt(((double) cbrt(((double) (((double) (4.0 * ((double) (p * p)))) + ((double) (x * x)))))))) * ((double) fabs(((double) cbrt(((double) (((double) (4.0 * ((double) (p * p)))) + ((double) (x * x))))))))))))))))), 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.0
Target13.0
Herbie13.0
\[\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 < -1.2830507578319113e-149

    1. Initial program Error: 26.0 bits

      \[\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 flip3-+Error: 26.0 bits

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

      \[\leadsto \sqrt{0.5 \cdot \frac{\color{blue}{{1}^{3} + {\left(\frac{x}{\sqrt{4 \cdot \left(p \cdot p\right) + x \cdot x}}\right)}^{3}}}{1 \cdot 1 + \left(\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 \cdot \frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}\right)}}\]
    5. SimplifiedError: 26.0 bits

      \[\leadsto \sqrt{0.5 \cdot \frac{{1}^{3} + {\left(\frac{x}{\sqrt{4 \cdot \left(p \cdot p\right) + x \cdot x}}\right)}^{3}}{\color{blue}{x \cdot \frac{x}{4 \cdot \left(p \cdot p\right) + x \cdot x} + 1 \cdot \left(1 - \frac{x}{\sqrt{4 \cdot \left(p \cdot p\right) + x \cdot x}}\right)}}}\]
    6. Using strategy rm
    7. Applied add-exp-logError: 26.0 bits

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

    if -1.2830507578319113e-149 < x

    1. Initial program Error: 0.1 bits

      \[\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-cube-cbrtError: 0.2 bits

      \[\leadsto \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)}\]
    4. Applied sqrt-prodError: 0.2 bits

      \[\leadsto \sqrt{0.5 \cdot \left(1 + \frac{x}{\color{blue}{\sqrt{\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}} \cdot \sqrt{\sqrt[3]{\left(4 \cdot p\right) \cdot p + x \cdot x}}}}\right)}\]
    5. Applied associate-/r*Error: 0.2 bits

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

      \[\leadsto \sqrt{0.5 \cdot \left(1 + \frac{\color{blue}{\frac{x}{\left|\sqrt[3]{4 \cdot \left(p \cdot p\right) + x \cdot x}\right|}}}{\sqrt{\sqrt[3]{\left(4 \cdot p\right) \cdot p + x \cdot x}}}\right)}\]
    7. Using strategy rm
    8. Applied add-cbrt-cubeError: 0.1 bits

      \[\leadsto \sqrt{0.5 \cdot \color{blue}{\sqrt[3]{\left(\left(1 + \frac{\frac{x}{\left|\sqrt[3]{4 \cdot \left(p \cdot p\right) + x \cdot x}\right|}}{\sqrt{\sqrt[3]{\left(4 \cdot p\right) \cdot p + x \cdot x}}}\right) \cdot \left(1 + \frac{\frac{x}{\left|\sqrt[3]{4 \cdot \left(p \cdot p\right) + x \cdot x}\right|}}{\sqrt{\sqrt[3]{\left(4 \cdot p\right) \cdot p + x \cdot x}}}\right)\right) \cdot \left(1 + \frac{\frac{x}{\left|\sqrt[3]{4 \cdot \left(p \cdot p\right) + x \cdot x}\right|}}{\sqrt{\sqrt[3]{\left(4 \cdot p\right) \cdot p + x \cdot x}}}\right)}}}\]
    9. SimplifiedError: 0.1 bits

      \[\leadsto \sqrt{0.5 \cdot \sqrt[3]{\color{blue}{{\left(1 + \frac{x}{\sqrt{\sqrt[3]{4 \cdot \left(p \cdot p\right) + x \cdot x}} \cdot \left|\sqrt[3]{4 \cdot \left(p \cdot p\right) + x \cdot x}\right|}\right)}^{3}}}}\]
    10. Using strategy rm
    11. Applied add-sqr-sqrtError: 0.1 bits

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

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

Reproduce

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