I am trying find an strictly increasing iterative sequence that gives this set sorted: $$[a+\sqrt{b}: a,b \in \mathbb{N_0}].$$ These are a subset of constructable numbers. When I look at it, there are obvious patterns, but I cannot seem to find an efficient algorithm to find them without deleting or sorting. I don't know if this is even possible. Any help is appreciated.
I can generate the first 20 using Mathematica:
Take[Sort[Flatten[Table[Select[DeleteDuplicates[Total[Tuples@{Table[i,{i,0,k}], Table[Sqrt[i],{i,0,k}]}, {2}]],# <= k&],{k,60,60}]],Less],20]
$$\left\{0,1,\sqrt{2},\sqrt{3},2,\sqrt{5},1+\sqrt{2},\sqrt{6},\sqrt{7},1+\sqrt{3},2\sqrt{2},3,\sqrt{10},1+\sqrt{5},\sqrt{11},2+\sqrt{2},1+\sqrt{6},2\sqrt{3},\sqrt{13},1+\sqrt{7}\right\}$$
First, here is a subroutine: figuring out the number of elements of $S$ less than $\sqrt k$ for some integer $k$. (Call this number $r_k$; we will refer to it later.)
If $\sqrt k$ is an integer, then $r_k$ is easier to find and has a closed form. In $S \cap [0,\sqrt k)$, there are
Apart from the first $\sqrt k$ cases, there are $2j$ values of $b$ in the range strictly between $j^2$ and $(j+1)^2$, which appear $\sqrt k - j$ times. So we have $$r_k = \sqrt k + \sum_{j=1}^{\sqrt k} 2j(\sqrt k - j) = \frac{(k+2)\sqrt k}{3}.$$
If $k$ is not an integer, things are harder, but at least we don't have to worry about edge cases as much. Fix $a$; then $a + \sqrt b < \sqrt k$ if and only if $b < (\sqrt k - a)^2$ or $b < a^2 + k - 2a\sqrt k$. Including $0$, there are $a^2 + k - \lfloor 2a\sqrt{k}\rfloor$ values of $b$ in this range. However, to avoid duplicates, we don't want $\sqrt b$ to be a positive integer; there are $\lfloor \sqrt k\rfloor - a$ cases to exclude. Summing over all values of $a$ from $0$ to $\lfloor \sqrt k\rfloor$, we have $$ r_k = \sum_{a=0}^{\lfloor \sqrt k\rfloor} (a^2 + a + k - \lfloor 2a\sqrt{k}\rfloor - \lfloor \sqrt k\rfloor). $$
We will use the formula for $r_k$ to recursively generate the sorted elements of $S \cap [n,n+1)$ using the sorted elements of $S \cap [n-1,n)$. There are two cases:
To make this happen, loop through $S \cap [n-1,n)$ and add $1$ to each element you find, but keep track of the next element of the form $\sqrt b$ you have to include. When you get to the $(r_b - r_{n^2}+1)$-th position, put in $\sqrt b$ instead, and move on to waiting to include $\sqrt{b+1}$ at the appropriate moment.
Here is a Mathematica implementation; for an integer
n,sequence[n]will generate all the elements of $S$ less thannin order, by joining together the appropriate intervals.Alternatively, here is a simpler solution if some amount of comparing values in $S$ is permissible. Here, we still use the idea that each element of $S$ is either $\sqrt b$ or else $1 + x$ where $x$ is a smaller element of $S$, but we don't try to intelligently calculate which it should be. At each step, we just compare the least unused element of each type, and use the smaller of the two.
Use
s[n]to generate the firstnelements of $S$, in order: