Average Error: 20.2 → 0.5
Time: 6.5s
Precision: binary64
Cost: 14404
\[\frac{1}{\sqrt{x}} - \frac{1}{\sqrt{x + 1}} \]
\[\begin{array}{l} \mathbf{if}\;x \leq 0.006265619711436925:\\ \;\;\;\;{x}^{-0.5} - {\left(x + 1\right)}^{-0.5}\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \frac{{x}^{-0.5}}{x} + \frac{1}{{x}^{2.5}} \cdot \left(\frac{-0.2734375}{x \cdot x} + \left(-0.375 + \frac{0.3125}{x}\right)\right)\\ \end{array} \]
(FPCore (x) :precision binary64 (- (/ 1.0 (sqrt x)) (/ 1.0 (sqrt (+ x 1.0)))))
(FPCore (x)
 :precision binary64
 (if (<= x 0.006265619711436925)
   (- (pow x -0.5) (pow (+ x 1.0) -0.5))
   (+
    (* 0.5 (/ (pow x -0.5) x))
    (*
     (/ 1.0 (pow x 2.5))
     (+ (/ -0.2734375 (* x x)) (+ -0.375 (/ 0.3125 x)))))))
double code(double x) {
	return (1.0 / sqrt(x)) - (1.0 / sqrt((x + 1.0)));
}
double code(double x) {
	double tmp;
	if (x <= 0.006265619711436925) {
		tmp = pow(x, -0.5) - pow((x + 1.0), -0.5);
	} else {
		tmp = (0.5 * (pow(x, -0.5) / x)) + ((1.0 / pow(x, 2.5)) * ((-0.2734375 / (x * x)) + (-0.375 + (0.3125 / 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 <= 0.006265619711436925d0) then
        tmp = (x ** (-0.5d0)) - ((x + 1.0d0) ** (-0.5d0))
    else
        tmp = (0.5d0 * ((x ** (-0.5d0)) / x)) + ((1.0d0 / (x ** 2.5d0)) * (((-0.2734375d0) / (x * x)) + ((-0.375d0) + (0.3125d0 / 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 <= 0.006265619711436925) {
		tmp = Math.pow(x, -0.5) - Math.pow((x + 1.0), -0.5);
	} else {
		tmp = (0.5 * (Math.pow(x, -0.5) / x)) + ((1.0 / Math.pow(x, 2.5)) * ((-0.2734375 / (x * x)) + (-0.375 + (0.3125 / 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 <= 0.006265619711436925:
		tmp = math.pow(x, -0.5) - math.pow((x + 1.0), -0.5)
	else:
		tmp = (0.5 * (math.pow(x, -0.5) / x)) + ((1.0 / math.pow(x, 2.5)) * ((-0.2734375 / (x * x)) + (-0.375 + (0.3125 / 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 <= 0.006265619711436925)
		tmp = Float64((x ^ -0.5) - (Float64(x + 1.0) ^ -0.5));
	else
		tmp = Float64(Float64(0.5 * Float64((x ^ -0.5) / x)) + Float64(Float64(1.0 / (x ^ 2.5)) * Float64(Float64(-0.2734375 / Float64(x * x)) + Float64(-0.375 + Float64(0.3125 / 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 <= 0.006265619711436925)
		tmp = (x ^ -0.5) - ((x + 1.0) ^ -0.5);
	else
		tmp = (0.5 * ((x ^ -0.5) / x)) + ((1.0 / (x ^ 2.5)) * ((-0.2734375 / (x * x)) + (-0.375 + (0.3125 / 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, 0.006265619711436925], N[(N[Power[x, -0.5], $MachinePrecision] - N[Power[N[(x + 1.0), $MachinePrecision], -0.5], $MachinePrecision]), $MachinePrecision], N[(N[(0.5 * N[(N[Power[x, -0.5], $MachinePrecision] / x), $MachinePrecision]), $MachinePrecision] + N[(N[(1.0 / N[Power[x, 2.5], $MachinePrecision]), $MachinePrecision] * N[(N[(-0.2734375 / N[(x * x), $MachinePrecision]), $MachinePrecision] + N[(-0.375 + N[(0.3125 / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\frac{1}{\sqrt{x}} - \frac{1}{\sqrt{x + 1}}
\begin{array}{l}
\mathbf{if}\;x \leq 0.006265619711436925:\\
\;\;\;\;{x}^{-0.5} - {\left(x + 1\right)}^{-0.5}\\

\mathbf{else}:\\
\;\;\;\;0.5 \cdot \frac{{x}^{-0.5}}{x} + \frac{1}{{x}^{2.5}} \cdot \left(\frac{-0.2734375}{x \cdot x} + \left(-0.375 + \frac{0.3125}{x}\right)\right)\\


\end{array}

Error

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original20.2
Target0.6
Herbie0.5
\[\frac{1}{\left(x + 1\right) \cdot \sqrt{x} + x \cdot \sqrt{x + 1}} \]

Derivation

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

    1. Initial program 0.3

      \[\frac{1}{\sqrt{x}} - \frac{1}{\sqrt{x + 1}} \]
    2. Applied egg-rr0.0

      \[\leadsto \color{blue}{{x}^{-0.5} + \left(-{\left(1 + x\right)}^{-0.5}\right)} \]
    3. Applied egg-rr0.0

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

    if 0.006265619711436925 < x

    1. Initial program 40.0

      \[\frac{1}{\sqrt{x}} - \frac{1}{\sqrt{x + 1}} \]
    2. Applied egg-rr40.0

      \[\leadsto \color{blue}{{x}^{-0.5} + \left(-{\left(1 + x\right)}^{-0.5}\right)} \]
    3. Taylor expanded in x around -inf 64.0

      \[\leadsto \color{blue}{-0.2734375 \cdot \frac{e^{-0.5 \cdot \left(-1 \cdot \log \left(\frac{-1}{x}\right) + \log -1\right)}}{{x}^{4}} + \left(0.3125 \cdot \frac{e^{-0.5 \cdot \left(-1 \cdot \log \left(\frac{-1}{x}\right) + \log -1\right)}}{{x}^{3}} + \left(0.5 \cdot \frac{e^{-0.5 \cdot \left(-1 \cdot \log \left(\frac{-1}{x}\right) + \log -1\right)}}{x} + -0.375 \cdot \frac{e^{-0.5 \cdot \left(-1 \cdot \log \left(\frac{-1}{x}\right) + \log -1\right)}}{{x}^{2}}\right)\right)} \]
    4. Simplified1.0

      \[\leadsto \color{blue}{0.5 \cdot \frac{{x}^{-0.5}}{x} + \frac{1}{{x}^{2.5}} \cdot \left(\frac{-0.2734375}{x \cdot x} + \left(-0.375 + \frac{0.3125}{x}\right)\right)} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification0.5

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq 0.006265619711436925:\\ \;\;\;\;{x}^{-0.5} - {\left(x + 1\right)}^{-0.5}\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \frac{{x}^{-0.5}}{x} + \frac{1}{{x}^{2.5}} \cdot \left(\frac{-0.2734375}{x \cdot x} + \left(-0.375 + \frac{0.3125}{x}\right)\right)\\ \end{array} \]

Alternatives

Alternative 1
Error0.5
Cost13380
\[\begin{array}{l} \mathbf{if}\;x \leq 0.006265619711436925:\\ \;\;\;\;{x}^{-0.5} - {\left(x + 1\right)}^{-0.5}\\ \mathbf{else}:\\ \;\;\;\;\frac{{x}^{-0.5}}{x} \cdot \left(0.5 + \left(\frac{0.3125}{x \cdot x} + \frac{-0.375}{x}\right)\right)\\ \end{array} \]
Alternative 2
Error0.6
Cost7556
\[\begin{array}{l} \mathbf{if}\;x \leq 0.006265619711436925:\\ \;\;\;\;{x}^{-0.5} + \frac{-1}{1 + x \cdot 0.5}\\ \mathbf{else}:\\ \;\;\;\;\frac{{x}^{-0.5}}{x} \cdot \left(0.5 + \left(\frac{0.3125}{x \cdot x} + \frac{-0.375}{x}\right)\right)\\ \end{array} \]
Alternative 3
Error0.8
Cost7172
\[\begin{array}{l} \mathbf{if}\;x \leq 0.006265619711436925:\\ \;\;\;\;\left({x}^{-0.5} + x \cdot 0.5\right) + -1\\ \mathbf{else}:\\ \;\;\;\;\frac{{x}^{-0.5}}{x} \cdot \left(0.5 + \frac{-0.375}{x}\right)\\ \end{array} \]
Alternative 4
Error0.8
Cost7172
\[\begin{array}{l} \mathbf{if}\;x \leq 0.006265619711436925:\\ \;\;\;\;{x}^{-0.5} + \frac{-1}{1 + x \cdot 0.5}\\ \mathbf{else}:\\ \;\;\;\;\frac{{x}^{-0.5}}{x} \cdot \left(0.5 + \frac{-0.375}{x}\right)\\ \end{array} \]
Alternative 5
Error1.0
Cost7044
\[\begin{array}{l} \mathbf{if}\;x \leq 0.006265619711436925:\\ \;\;\;\;\left({x}^{-0.5} + x \cdot 0.5\right) + -1\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot {x}^{-1.5}\\ \end{array} \]
Alternative 6
Error2.1
Cost6788
\[\begin{array}{l} \mathbf{if}\;x \leq 0.006265619711436925:\\ \;\;\;\;{x}^{-0.5}\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot {x}^{-1.5}\\ \end{array} \]
Alternative 7
Error1.1
Cost6788
\[\begin{array}{l} \mathbf{if}\;x \leq 0.006265619711436925:\\ \;\;\;\;{x}^{-0.5} + -1\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot {x}^{-1.5}\\ \end{array} \]
Alternative 8
Error31.4
Cost6528
\[{x}^{-0.5} \]
Alternative 9
Error61.5
Cost192
\[x \cdot 0.5 \]

Error

Reproduce

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