?

Average Accuracy: 69.7% → 99.7%
Time: 12.1s
Precision: binary64
Cost: 13636

?

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

\mathbf{else}:\\
\;\;\;\;\frac{\frac{1}{x + 0.5}}{\sqrt{x} + \sqrt{1 + x}}\\


\end{array}

Error?

Try it out?

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original69.7%
Target98.9%
Herbie99.7%
\[\frac{1}{\left(x + 1\right) \cdot \sqrt{x} + x \cdot \sqrt{x + 1}} \]

Derivation?

  1. Split input into 2 regimes
  2. if x < 165000

    1. Initial program 99.4%

      \[\frac{1}{\sqrt{x}} - \frac{1}{\sqrt{x + 1}} \]
    2. Applied egg-rr99.8%

      \[\leadsto \color{blue}{{x}^{-0.5} + \left(-{\left(1 + x\right)}^{-0.5}\right)} \]
    3. Simplified99.8%

      \[\leadsto \color{blue}{{x}^{-0.5} - {\left(1 + x\right)}^{-0.5}} \]
      Proof

      [Start]99.8

      \[ {x}^{-0.5} + \left(-{\left(1 + x\right)}^{-0.5}\right) \]

      sub-neg [<=]99.8

      \[ \color{blue}{{x}^{-0.5} - {\left(1 + x\right)}^{-0.5}} \]

    if 165000 < x

    1. Initial program 38.5%

      \[\frac{1}{\sqrt{x}} - \frac{1}{\sqrt{x + 1}} \]
    2. Applied egg-rr83.3%

      \[\leadsto \color{blue}{\frac{1 + \left(x - x\right)}{\sqrt{x + x \cdot x} \cdot \left(\sqrt{x} + \sqrt{1 + x}\right)}} \]
    3. Simplified83.3%

      \[\leadsto \color{blue}{\frac{1}{\sqrt{x + x \cdot x} \cdot \left(\sqrt{1 + x} + \sqrt{x}\right)}} \]
      Proof

      [Start]83.3

      \[ \frac{1 + \left(x - x\right)}{\sqrt{x + x \cdot x} \cdot \left(\sqrt{x} + \sqrt{1 + x}\right)} \]

      +-commutative [=>]83.3

      \[ \frac{\color{blue}{\left(x - x\right) + 1}}{\sqrt{x + x \cdot x} \cdot \left(\sqrt{x} + \sqrt{1 + x}\right)} \]

      +-inverses [=>]83.3

      \[ \frac{\color{blue}{0} + 1}{\sqrt{x + x \cdot x} \cdot \left(\sqrt{x} + \sqrt{1 + x}\right)} \]

      metadata-eval [=>]83.3

      \[ \frac{\color{blue}{1}}{\sqrt{x + x \cdot x} \cdot \left(\sqrt{x} + \sqrt{1 + x}\right)} \]

      +-commutative [=>]83.3

      \[ \frac{1}{\sqrt{x + x \cdot x} \cdot \color{blue}{\left(\sqrt{1 + x} + \sqrt{x}\right)}} \]
    4. Taylor expanded in x around inf 98.2%

      \[\leadsto \frac{1}{\color{blue}{\left(0.5 + x\right)} \cdot \left(\sqrt{1 + x} + \sqrt{x}\right)} \]
    5. Simplified98.2%

      \[\leadsto \frac{1}{\color{blue}{\left(x + 0.5\right)} \cdot \left(\sqrt{1 + x} + \sqrt{x}\right)} \]
      Proof

      [Start]98.2

      \[ \frac{1}{\left(0.5 + x\right) \cdot \left(\sqrt{1 + x} + \sqrt{x}\right)} \]

      +-commutative [=>]98.2

      \[ \frac{1}{\color{blue}{\left(x + 0.5\right)} \cdot \left(\sqrt{1 + x} + \sqrt{x}\right)} \]
    6. Applied egg-rr37.7%

      \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\frac{1}{\left(x + 0.5\right) \cdot \left(\sqrt{1 + x} + \sqrt{x}\right)}\right)} - 1} \]
    7. Simplified99.5%

      \[\leadsto \color{blue}{\frac{\frac{1}{0.5 + x}}{\sqrt{1 + x} + \sqrt{x}}} \]
      Proof

      [Start]37.7

      \[ e^{\mathsf{log1p}\left(\frac{1}{\left(x + 0.5\right) \cdot \left(\sqrt{1 + x} + \sqrt{x}\right)}\right)} - 1 \]

      expm1-def [=>]98.2

      \[ \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{1}{\left(x + 0.5\right) \cdot \left(\sqrt{1 + x} + \sqrt{x}\right)}\right)\right)} \]

      expm1-log1p [=>]98.2

      \[ \color{blue}{\frac{1}{\left(x + 0.5\right) \cdot \left(\sqrt{1 + x} + \sqrt{x}\right)}} \]

      associate-/r* [=>]99.5

      \[ \color{blue}{\frac{\frac{1}{x + 0.5}}{\sqrt{1 + x} + \sqrt{x}}} \]

      +-commutative [=>]99.5

      \[ \frac{\frac{1}{\color{blue}{0.5 + x}}}{\sqrt{1 + x} + \sqrt{x}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification99.7%

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq 165000:\\ \;\;\;\;{x}^{-0.5} - {\left(1 + x\right)}^{-0.5}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{1}{x + 0.5}}{\sqrt{x} + \sqrt{1 + x}}\\ \end{array} \]

Alternatives

Alternative 1
Accuracy99.2%
Cost26820
\[\begin{array}{l} t_0 := \sqrt{1 + x}\\ \mathbf{if}\;\frac{1}{\sqrt{x}} + \frac{-1}{t_0} \leq 5 \cdot 10^{-19}:\\ \;\;\;\;\frac{\frac{1}{x}}{\sqrt{x} + t_0}\\ \mathbf{else}:\\ \;\;\;\;{x}^{-0.5} - {\left(1 + x\right)}^{-0.5}\\ \end{array} \]
Alternative 2
Accuracy99.2%
Cost26692
\[\begin{array}{l} \mathbf{if}\;\frac{1}{\sqrt{x}} + \frac{-1}{\sqrt{1 + x}} \leq 5 \cdot 10^{-19}:\\ \;\;\;\;\frac{\sqrt{x}}{x} \cdot \frac{0.5}{1 + x}\\ \mathbf{else}:\\ \;\;\;\;{x}^{-0.5} - {\left(1 + x\right)}^{-0.5}\\ \end{array} \]
Alternative 3
Accuracy98.9%
Cost26368
\[\frac{1}{\frac{\mathsf{hypot}\left(x, \sqrt{x}\right)}{\frac{1}{\sqrt{x} + \sqrt{1 + x}}}} \]
Alternative 4
Accuracy98.1%
Cost7108
\[\begin{array}{l} \mathbf{if}\;x \leq 0.42:\\ \;\;\;\;{x}^{-0.5} + -1\\ \mathbf{else}:\\ \;\;\;\;\frac{\sqrt{x}}{x} \cdot \frac{0.5}{1 + x}\\ \end{array} \]
Alternative 5
Accuracy72.1%
Cost6980
\[\begin{array}{l} \mathbf{if}\;x \leq 0.64:\\ \;\;\;\;{x}^{-0.5} + -1\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{x \cdot \left(1 + \sqrt{x}\right)}\\ \end{array} \]
Alternative 6
Accuracy67.7%
Cost6916
\[\begin{array}{l} \mathbf{if}\;x \leq 4:\\ \;\;\;\;{x}^{-0.5} + -1\\ \mathbf{else}:\\ \;\;\;\;1 + \left(-1 - {x}^{-0.5}\right)\\ \end{array} \]
Alternative 7
Accuracy53.5%
Cost6788
\[\begin{array}{l} \mathbf{if}\;x \leq 0.6:\\ \;\;\;\;{x}^{-0.5} + -1\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{x + 0.5}\\ \end{array} \]
Alternative 8
Accuracy7.4%
Cost320
\[\frac{1}{x + 0.5} \]
Alternative 9
Accuracy7.4%
Cost192
\[\frac{1}{x} \]
Alternative 10
Accuracy5.8%
Cost64
\[2 \]

Error

Reproduce?

herbie shell --seed 2023129 
(FPCore (x)
  :name "2isqrt (example 3.6)"
  :precision binary64

  :herbie-target
  (/ 1.0 (+ (* (+ x 1.0) (sqrt x)) (* x (sqrt (+ x 1.0)))))

  (- (/ 1.0 (sqrt x)) (/ 1.0 (sqrt (+ x 1.0)))))