?

Average Error: 32.1 → 0.0
Time: 14.7s
Precision: binary64
Cost: 516

?

\[\frac{x}{x} - \frac{1}{x} \cdot \sqrt{x \cdot x} \]
\[\begin{array}{l} \mathbf{if}\;x \leq -4 \cdot 10^{-310}:\\ \;\;\;\;\frac{x - \left(-x\right)}{x}\\ \mathbf{else}:\\ \;\;\;\;\frac{x - x}{x}\\ \end{array} \]
(FPCore (x) :precision binary64 (- (/ x x) (* (/ 1.0 x) (sqrt (* x x)))))
(FPCore (x)
 :precision binary64
 (if (<= x -4e-310) (/ (- x (- x)) x) (/ (- x x) x)))
double code(double x) {
	return (x / x) - ((1.0 / x) * sqrt((x * x)));
}
double code(double x) {
	double tmp;
	if (x <= -4e-310) {
		tmp = (x - -x) / x;
	} else {
		tmp = (x - x) / x;
	}
	return tmp;
}
real(8) function code(x)
    real(8), intent (in) :: x
    code = (x / x) - ((1.0d0 / x) * sqrt((x * x)))
end function
real(8) function code(x)
    real(8), intent (in) :: x
    real(8) :: tmp
    if (x <= (-4d-310)) then
        tmp = (x - -x) / x
    else
        tmp = (x - x) / x
    end if
    code = tmp
end function
public static double code(double x) {
	return (x / x) - ((1.0 / x) * Math.sqrt((x * x)));
}
public static double code(double x) {
	double tmp;
	if (x <= -4e-310) {
		tmp = (x - -x) / x;
	} else {
		tmp = (x - x) / x;
	}
	return tmp;
}
def code(x):
	return (x / x) - ((1.0 / x) * math.sqrt((x * x)))
def code(x):
	tmp = 0
	if x <= -4e-310:
		tmp = (x - -x) / x
	else:
		tmp = (x - x) / x
	return tmp
function code(x)
	return Float64(Float64(x / x) - Float64(Float64(1.0 / x) * sqrt(Float64(x * x))))
end
function code(x)
	tmp = 0.0
	if (x <= -4e-310)
		tmp = Float64(Float64(x - Float64(-x)) / x);
	else
		tmp = Float64(Float64(x - x) / x);
	end
	return tmp
end
function tmp = code(x)
	tmp = (x / x) - ((1.0 / x) * sqrt((x * x)));
end
function tmp_2 = code(x)
	tmp = 0.0;
	if (x <= -4e-310)
		tmp = (x - -x) / x;
	else
		tmp = (x - x) / x;
	end
	tmp_2 = tmp;
end
code[x_] := N[(N[(x / x), $MachinePrecision] - N[(N[(1.0 / x), $MachinePrecision] * N[Sqrt[N[(x * x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
code[x_] := If[LessEqual[x, -4e-310], N[(N[(x - (-x)), $MachinePrecision] / x), $MachinePrecision], N[(N[(x - x), $MachinePrecision] / x), $MachinePrecision]]
\frac{x}{x} - \frac{1}{x} \cdot \sqrt{x \cdot x}
\begin{array}{l}
\mathbf{if}\;x \leq -4 \cdot 10^{-310}:\\
\;\;\;\;\frac{x - \left(-x\right)}{x}\\

\mathbf{else}:\\
\;\;\;\;\frac{x - x}{x}\\


\end{array}

Error?

Try it out?

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

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

Derivation?

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

    1. Initial program 28.6

      \[\frac{x}{x} - \frac{1}{x} \cdot \sqrt{x \cdot x} \]
    2. Simplified28.6

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

      [Start]28.6

      \[ \frac{x}{x} - \frac{1}{x} \cdot \sqrt{x \cdot x} \]

      rational_best-simplify-1 [=>]28.6

      \[ \frac{x}{x} - \color{blue}{\sqrt{x \cdot x} \cdot \frac{1}{x}} \]

      rational_best-simplify-55 [=>]28.6

      \[ \frac{x}{x} - \color{blue}{1 \cdot \frac{\sqrt{x \cdot x}}{x}} \]

      rational_best-simplify-1 [=>]28.6

      \[ \frac{x}{x} - \color{blue}{\frac{\sqrt{x \cdot x}}{x} \cdot 1} \]

      rational_best-simplify-7 [=>]28.6

      \[ \frac{x}{x} - \color{blue}{\frac{\sqrt{x \cdot x}}{x}} \]

      rational_best-simplify-66 [=>]28.6

      \[ \color{blue}{\frac{x - \sqrt{x \cdot x}}{x}} \]
    3. Taylor expanded in x around -inf 0.1

      \[\leadsto \frac{x - \color{blue}{-1 \cdot x}}{x} \]
    4. Simplified0.1

      \[\leadsto \frac{x - \color{blue}{\left(-x\right)}}{x} \]
      Proof

      [Start]0.1

      \[ \frac{x - -1 \cdot x}{x} \]

      rational_best-simplify-1 [=>]0.1

      \[ \frac{x - \color{blue}{x \cdot -1}}{x} \]

      rational_best-simplify-11 [<=]0.1

      \[ \frac{x - \color{blue}{\left(-x\right)}}{x} \]

    if -3.999999999999988e-310 < x

    1. Initial program 35.4

      \[\frac{x}{x} - \frac{1}{x} \cdot \sqrt{x \cdot x} \]
    2. Simplified30.5

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

      [Start]35.4

      \[ \frac{x}{x} - \frac{1}{x} \cdot \sqrt{x \cdot x} \]

      rational_best-simplify-1 [=>]35.4

      \[ \frac{x}{x} - \color{blue}{\sqrt{x \cdot x} \cdot \frac{1}{x}} \]

      rational_best-simplify-55 [=>]30.5

      \[ \frac{x}{x} - \color{blue}{1 \cdot \frac{\sqrt{x \cdot x}}{x}} \]

      rational_best-simplify-1 [=>]30.5

      \[ \frac{x}{x} - \color{blue}{\frac{\sqrt{x \cdot x}}{x} \cdot 1} \]

      rational_best-simplify-7 [=>]30.5

      \[ \frac{x}{x} - \color{blue}{\frac{\sqrt{x \cdot x}}{x}} \]

      rational_best-simplify-66 [=>]30.5

      \[ \color{blue}{\frac{x - \sqrt{x \cdot x}}{x}} \]
    3. Taylor expanded in x around 0 0

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -4 \cdot 10^{-310}:\\ \;\;\;\;\frac{x - \left(-x\right)}{x}\\ \mathbf{else}:\\ \;\;\;\;\frac{x - x}{x}\\ \end{array} \]

Alternatives

Alternative 1
Error30.3
Cost320
\[\frac{x - x}{x} \]

Error

Reproduce?

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