Average Error: 32.4 → 0
Time: 25.9s
Precision: binary64
Cost: 385
\[\frac{x}{x} - \frac{1}{x} \cdot \sqrt{x \cdot x}\]
\[\begin{array}{l} \mathbf{if}\;x \leq -3.11516202745543 \cdot 10^{-310}:\\ \;\;\;\;2\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array}\]
\frac{x}{x} - \frac{1}{x} \cdot \sqrt{x \cdot x}
\begin{array}{l}
\mathbf{if}\;x \leq -3.11516202745543 \cdot 10^{-310}:\\
\;\;\;\;2\\

\mathbf{else}:\\
\;\;\;\;0\\

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

Error

Bits error versus x

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original32.4
Target0
Herbie0
\[\begin{array}{l} \mathbf{if}\;x < 0:\\ \;\;\;\;2\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array}\]

Alternatives

Alternative 1
Error0
Cost6720
\[1 - \frac{x}{\left|x\right|}\]
Alternative 2
Error30.2
Cost64
\[2\]

Error

Time

Derivation

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

    1. Initial program 28.3

      \[\frac{x}{x} - \frac{1}{x} \cdot \sqrt{x \cdot x}\]
    2. Taylor expanded around -inf 0

      \[\leadsto \color{blue}{2}\]
    3. Simplified0

      \[\leadsto \color{blue}{2}\]

    if -3.115162027455434e-310 < x

    1. Initial program 36.7

      \[\frac{x}{x} - \frac{1}{x} \cdot \sqrt{x \cdot x}\]
    2. Taylor expanded around 0 0

      \[\leadsto \color{blue}{0}\]
    3. Simplified0

      \[\leadsto \color{blue}{0}\]
  3. Recombined 2 regimes into one program.
  4. Final simplification0

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

Reproduce

herbie shell --seed 2021040 
(FPCore (x)
  :name "sqrt sqr"
  :precision binary64

  :herbie-target
  (if (< x 0.0) 2.0 0.0)

  (- (/ x x) (* (/ 1.0 x) (sqrt (* x x)))))