Average Error: 30.4 → 15.2
Time: 8.0s
Precision: binary64
\[\sqrt{2 \cdot {x}^{2}}\]
\[\begin{array}{l} \mathbf{if}\;x \leq -2.8491681377424 \cdot 10^{-310}:\\ \;\;\;\;\sqrt{2 \cdot {x}^{2}}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{2} \cdot {x}^{1}\\ \end{array}\]
\sqrt{2 \cdot {x}^{2}}
\begin{array}{l}
\mathbf{if}\;x \leq -2.8491681377424 \cdot 10^{-310}:\\
\;\;\;\;\sqrt{2 \cdot {x}^{2}}\\

\mathbf{else}:\\
\;\;\;\;\sqrt{2} \cdot {x}^{1}\\

\end{array}
(FPCore (x) :precision binary64 (sqrt (* 2.0 (pow x 2.0))))
(FPCore (x)
 :precision binary64
 (if (<= x -2.8491681377424e-310)
   (sqrt (* 2.0 (pow x 2.0)))
   (* (sqrt 2.0) (pow x 1.0))))
double code(double x) {
	return ((double) sqrt(((double) (2.0 * ((double) pow(x, 2.0))))));
}
double code(double x) {
	double tmp;
	if ((x <= -2.8491681377424e-310)) {
		tmp = ((double) sqrt(((double) (2.0 * ((double) pow(x, 2.0))))));
	} else {
		tmp = ((double) (((double) sqrt(2.0)) * ((double) pow(x, 1.0))));
	}
	return tmp;
}

Error

Bits error versus x

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Derivation

  1. Split input into 2 regimes
  2. if x < -2.849168137742421e-310

    1. Initial program Error: 30.5 bits

      \[\sqrt{2 \cdot {x}^{2}}\]

    if -2.849168137742421e-310 < x

    1. Initial program Error: 30.2 bits

      \[\sqrt{2 \cdot {x}^{2}}\]
    2. Taylor expanded around -inf Error: 64.0 bits

      \[\leadsto \sqrt{\color{blue}{2 \cdot {\left(\frac{{-1}^{2}}{{\left(e^{2 \cdot \left(\log 1 + \log \left(\frac{-1}{x}\right)\right)}\right)}^{1}}\right)}^{1}}}\]
    3. SimplifiedError: 30.6 bits

      \[\leadsto \sqrt{\color{blue}{2 \cdot {\left(\frac{{-1}^{2}}{{\left({\left(\frac{-1}{x}\right)}^{2}\right)}^{1}}\right)}^{1}}}\]
    4. Taylor expanded around 0 Error: 5.7 bits

      \[\leadsto \color{blue}{\sqrt{2} \cdot e^{1 \cdot \left(\log 1 + \log x\right)}}\]
    5. SimplifiedError: 0.4 bits

      \[\leadsto \color{blue}{\sqrt{2} \cdot {x}^{1}}\]
  3. Recombined 2 regimes into one program.
  4. Final simplificationError: 15.2 bits

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -2.8491681377424 \cdot 10^{-310}:\\ \;\;\;\;\sqrt{2 \cdot {x}^{2}}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{2} \cdot {x}^{1}\\ \end{array}\]

Reproduce

herbie shell --seed 2020204 
(FPCore (x)
  :name "sqrt D"
  :precision binary64
  (sqrt (* 2.0 (pow x 2.0))))