Average Error: 30.3 → 0.4
Time: 1.4s
Precision: binary64
\[\sqrt{x \cdot x + x \cdot x}\]
\[\begin{array}{l} \mathbf{if}\;x \leq -3.6043309604501 \cdot 10^{-310}:\\ \;\;\;\;-x \cdot \sqrt{2}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{x} \cdot \sqrt{x + x}\\ \end{array}\]
\sqrt{x \cdot x + x \cdot x}
\begin{array}{l}
\mathbf{if}\;x \leq -3.6043309604501 \cdot 10^{-310}:\\
\;\;\;\;-x \cdot \sqrt{2}\\

\mathbf{else}:\\
\;\;\;\;\sqrt{x} \cdot \sqrt{x + x}\\

\end{array}
(FPCore (x) :precision binary64 (sqrt (+ (* x x) (* x x))))
(FPCore (x)
 :precision binary64
 (if (<= x -3.6043309604501e-310)
   (- (* x (sqrt 2.0)))
   (* (sqrt x) (sqrt (+ x x)))))
double code(double x) {
	return sqrt((x * x) + (x * x));
}
double code(double x) {
	double tmp;
	if (x <= -3.6043309604501e-310) {
		tmp = -(x * sqrt(2.0));
	} else {
		tmp = sqrt(x) * sqrt(x + x);
	}
	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 < -3.60433096045008e-310

    1. Initial program 30.2

      \[\sqrt{x \cdot x + x \cdot x}\]
    2. Simplified30.2

      \[\leadsto \color{blue}{\sqrt{x \cdot \left(x + x\right)}}\]
    3. Taylor expanded around -inf 0.4

      \[\leadsto \color{blue}{-1 \cdot \left(x \cdot \sqrt{2}\right)}\]
    4. Simplified0.4

      \[\leadsto \color{blue}{-x \cdot \sqrt{2}}\]

    if -3.60433096045008e-310 < x

    1. Initial program 30.3

      \[\sqrt{x \cdot x + x \cdot x}\]
    2. Simplified30.3

      \[\leadsto \color{blue}{\sqrt{x \cdot \left(x + x\right)}}\]
    3. Using strategy rm
    4. Applied sqrt-prod_binary640.3

      \[\leadsto \color{blue}{\sqrt{x} \cdot \sqrt{x + x}}\]
  3. Recombined 2 regimes into one program.
  4. Final simplification0.4

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

Reproduce

herbie shell --seed 2020253 
(FPCore (x)
  :name "sqrt A"
  :precision binary64
  (sqrt (+ (* x x) (* x x))))