Average Error: 19.6 → 0.2
Time: 12.0s
Precision: binary64
Cost: 14276
\[\frac{1}{\sqrt{x}} - \frac{1}{\sqrt{x + 1}} \]
\[\begin{array}{l} \mathbf{if}\;x \leq 5500:\\ \;\;\;\;{x}^{-0.5} - {\left(1 + x\right)}^{-0.5}\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(1 + \left(x - x\right)\right) \cdot \frac{1}{x + \left(0.5 + \frac{-0.125}{x}\right)}}{\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 5500.0)
   (- (pow x -0.5) (pow (+ 1.0 x) -0.5))
   (/
    (* (+ 1.0 (- x x)) (/ 1.0 (+ x (+ 0.5 (/ -0.125 x)))))
    (+ (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 <= 5500.0) {
		tmp = pow(x, -0.5) - pow((1.0 + x), -0.5);
	} else {
		tmp = ((1.0 + (x - x)) * (1.0 / (x + (0.5 + (-0.125 / x))))) / (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 <= 5500.0d0) then
        tmp = (x ** (-0.5d0)) - ((1.0d0 + x) ** (-0.5d0))
    else
        tmp = ((1.0d0 + (x - x)) * (1.0d0 / (x + (0.5d0 + ((-0.125d0) / x))))) / (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 <= 5500.0) {
		tmp = Math.pow(x, -0.5) - Math.pow((1.0 + x), -0.5);
	} else {
		tmp = ((1.0 + (x - x)) * (1.0 / (x + (0.5 + (-0.125 / x))))) / (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 <= 5500.0:
		tmp = math.pow(x, -0.5) - math.pow((1.0 + x), -0.5)
	else:
		tmp = ((1.0 + (x - x)) * (1.0 / (x + (0.5 + (-0.125 / x))))) / (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 <= 5500.0)
		tmp = Float64((x ^ -0.5) - (Float64(1.0 + x) ^ -0.5));
	else
		tmp = Float64(Float64(Float64(1.0 + Float64(x - x)) * Float64(1.0 / Float64(x + Float64(0.5 + Float64(-0.125 / x))))) / 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 <= 5500.0)
		tmp = (x ^ -0.5) - ((1.0 + x) ^ -0.5);
	else
		tmp = ((1.0 + (x - x)) * (1.0 / (x + (0.5 + (-0.125 / x))))) / (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, 5500.0], N[(N[Power[x, -0.5], $MachinePrecision] - N[Power[N[(1.0 + x), $MachinePrecision], -0.5], $MachinePrecision]), $MachinePrecision], N[(N[(N[(1.0 + N[(x - x), $MachinePrecision]), $MachinePrecision] * N[(1.0 / N[(x + N[(0.5 + N[(-0.125 / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $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 5500:\\
\;\;\;\;{x}^{-0.5} - {\left(1 + x\right)}^{-0.5}\\

\mathbf{else}:\\
\;\;\;\;\frac{\left(1 + \left(x - x\right)\right) \cdot \frac{1}{x + \left(0.5 + \frac{-0.125}{x}\right)}}{\sqrt{x} + \sqrt{1 + x}}\\


\end{array}

Error

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

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

Derivation

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

    1. Initial program 0.3

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

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

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

      [Start]0.1

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

      sub-neg [<=]0.1

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

    if 5500 < x

    1. Initial program 38.8

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

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

      \[\leadsto \frac{\left(1 + \left(x - x\right)\right) \cdot \frac{1}{\color{blue}{\left(0.5 + x\right) - 0.125 \cdot \frac{1}{x}}}}{\sqrt{x} + \sqrt{1 + x}} \]
    4. Simplified0.3

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

      [Start]0.3

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

      +-commutative [=>]0.3

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

      associate--l+ [=>]0.3

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

      associate-*r/ [=>]0.3

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

      metadata-eval [=>]0.3

      \[ \frac{\left(1 + \left(x - x\right)\right) \cdot \frac{1}{x + \left(0.5 - \frac{\color{blue}{0.125}}{x}\right)}}{\sqrt{x} + \sqrt{1 + x}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification0.2

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

Alternatives

Alternative 1
Error0.2
Cost27332
\[\begin{array}{l} t_0 := \sqrt{1 + x}\\ \mathbf{if}\;\frac{1}{\sqrt{x}} + \frac{-1}{t_0} \leq 5 \cdot 10^{-10}:\\ \;\;\;\;\frac{\left(1 + \left(x - x\right)\right) \cdot \frac{1}{x + 0.5}}{\sqrt{x} + t_0}\\ \mathbf{else}:\\ \;\;\;\;{x}^{-0.5} - {\left(1 + x\right)}^{-0.5}\\ \end{array} \]
Alternative 2
Error0.5
Cost27204
\[\begin{array}{l} t_0 := \sqrt{1 + x}\\ \mathbf{if}\;\frac{1}{\sqrt{x}} + \frac{-1}{t_0} \leq 2 \cdot 10^{-16}:\\ \;\;\;\;\frac{\left(1 + \left(x - x\right)\right) \cdot \frac{1}{x}}{\sqrt{x} + t_0}\\ \mathbf{else}:\\ \;\;\;\;{x}^{-0.5} - \frac{1}{t_0}\\ \end{array} \]
Alternative 3
Error0.3
Cost26240
\[\frac{\frac{1}{\sqrt{x} + \sqrt{1 + x}}}{\mathsf{hypot}\left(x, \sqrt{x}\right)} \]
Alternative 4
Error0.7
Cost26240
\[\frac{1}{\left(\sqrt{x} + \sqrt{1 + x}\right) \cdot \mathsf{hypot}\left(x, \sqrt{x}\right)} \]
Alternative 5
Error0.5
Cost13636
\[\begin{array}{l} t_0 := \sqrt{1 + x}\\ \mathbf{if}\;x \leq 85000000:\\ \;\;\;\;{x}^{-0.5} - \frac{1}{t_0}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\sqrt{x} + t_0} \cdot \frac{1}{x}\\ \end{array} \]
Alternative 6
Error9.8
Cost13448
\[\begin{array}{l} \mathbf{if}\;x \leq 1.7:\\ \;\;\;\;{x}^{-0.5} + \frac{-1}{1 + x \cdot 0.5}\\ \mathbf{elif}\;x \leq 5.6 \cdot 10^{+102}:\\ \;\;\;\;0.5 \cdot \sqrt{\frac{1}{{x}^{3}}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(1 + \left(x - x\right)\right) \cdot \frac{1}{x + 0.5}}{1 + \sqrt{x}}\\ \end{array} \]
Alternative 7
Error9.3
Cost13448
\[\begin{array}{l} \mathbf{if}\;x \leq 120000000:\\ \;\;\;\;{x}^{-0.5} - {\left(1 + x\right)}^{-0.5}\\ \mathbf{elif}\;x \leq 5.6 \cdot 10^{+102}:\\ \;\;\;\;0.5 \cdot \sqrt{\frac{1}{{x}^{3}}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(1 + \left(x - x\right)\right) \cdot \frac{1}{x + 0.5}}{1 + \sqrt{x}}\\ \end{array} \]
Alternative 8
Error9.3
Cost13448
\[\begin{array}{l} \mathbf{if}\;x \leq 85000000:\\ \;\;\;\;{x}^{-0.5} - \frac{1}{\sqrt{1 + x}}\\ \mathbf{elif}\;x \leq 5.6 \cdot 10^{+102}:\\ \;\;\;\;0.5 \cdot \sqrt{\frac{1}{{x}^{3}}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(1 + \left(x - x\right)\right) \cdot \frac{1}{x + 0.5}}{1 + \sqrt{x}}\\ \end{array} \]
Alternative 9
Error17.8
Cost7492
\[\begin{array}{l} \mathbf{if}\;x \leq 0.49:\\ \;\;\;\;{x}^{-0.5} + \frac{-1}{1 + x \cdot 0.5}\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(1 + \left(x - x\right)\right) \cdot \frac{1}{x + 0.5}}{1 + \sqrt{x}}\\ \end{array} \]
Alternative 10
Error19.9
Cost7236
\[\begin{array}{l} \mathbf{if}\;x \leq 2.6:\\ \;\;\;\;{x}^{-0.5} + \frac{-1}{1 + x \cdot 0.5}\\ \mathbf{else}:\\ \;\;\;\;\frac{2}{\left(1 + \sqrt{\frac{1}{x}}\right) \cdot \left(x \cdot x\right)}\\ \end{array} \]
Alternative 11
Error19.9
Cost7236
\[\begin{array}{l} \mathbf{if}\;x \leq 2.6:\\ \;\;\;\;{x}^{-0.5} + \frac{-1}{1 + x \cdot 0.5}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{\frac{2}{x}}{x}}{1 + \sqrt{\frac{1}{x}}}\\ \end{array} \]
Alternative 12
Error19.9
Cost7172
\[\begin{array}{l} \mathbf{if}\;x \leq 5.8:\\ \;\;\;\;{x}^{-0.5} + \frac{-1}{1 + x \cdot 0.5}\\ \mathbf{else}:\\ \;\;\;\;\left(1 + \left(x - x\right)\right) \cdot \left(\frac{1}{0.25 - x \cdot x} \cdot \left(0.5 - x\right)\right)\\ \end{array} \]
Alternative 13
Error20.0
Cost7108
\[\begin{array}{l} \mathbf{if}\;x \leq 1.35:\\ \;\;\;\;\left(x \cdot 0.5 + \sqrt{\frac{1}{x}}\right) + -1\\ \mathbf{else}:\\ \;\;\;\;\left(1 + \left(x - x\right)\right) \cdot \left(\frac{1}{0.25 - x \cdot x} \cdot \left(0.5 - x\right)\right)\\ \end{array} \]
Alternative 14
Error20.1
Cost6788
\[\begin{array}{l} \mathbf{if}\;x \leq 0.58:\\ \;\;\;\;{x}^{-0.5} + -1\\ \mathbf{else}:\\ \;\;\;\;\left(1 + \left(x - x\right)\right) \cdot \left(\frac{1}{0.25 - x \cdot x} \cdot \left(0.5 - x\right)\right)\\ \end{array} \]
Alternative 15
Error21.0
Cost6660
\[\begin{array}{l} \mathbf{if}\;x \leq 0.095:\\ \;\;\;\;{x}^{-0.5}\\ \mathbf{else}:\\ \;\;\;\;\left(1 + \left(x - x\right)\right) \cdot \left(\frac{1}{0.25 - x \cdot x} \cdot \left(0.5 - x\right)\right)\\ \end{array} \]
Alternative 16
Error49.1
Cost1088
\[\left(1 + \left(x - x\right)\right) \cdot \left(\frac{1}{0.25 - x \cdot x} \cdot \left(0.5 - x\right)\right) \]
Alternative 17
Error59.2
Cost704
\[\left(1 + \left(x - x\right)\right) \cdot \frac{1}{x + 0.5} \]
Alternative 18
Error59.3
Cost576
\[\left(1 + \left(x - x\right)\right) \cdot \frac{1}{x} \]
Alternative 19
Error62.8
Cost64
\[-1 \]
Alternative 20
Error60.3
Cost64
\[2 \]

Error

Reproduce

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