# Has this self-similar sequence the ratio $(\sqrt2+1)^2$?

This is inspired by a math.SE question, where an infinite sequence of pairwise distinct natural numbers $$a_1=1, a_2, a_3, ...$$ has been defined as follows:
$$a_n$$ is the smallest number such that $$s_n:=\sqrt{a_n+\sqrt{a_{n-1}+\sqrt{\cdots+\sqrt{a_1}}}}$$ is an integer.
It turns out that this sequence, which BTW is still not in the OEIS, is in fact a permutation of $$\mathbb N$$. Moreover, the images show that both $$(a_n)$$and $$(s_n)$$ exhibit an interesting self-similarity, with two alternating structures and the ratio converging rapidly towards, as it seems, $$3+2\sqrt2=(\sqrt2+1)^2\approx 5.828427$$ (see this other answer). Below I have displayed the first $$632$$ entries in a way that makes it easy to see which numbers generate what is perceived on the pictures as lines.

1,
3, 2,
7, 6,
13, 5,
22, 4,
33, 10, 12, 21, 11,
32, 19, 20,
31, 30,

43, 9, 45, 18, 44, 29,
58, 8, 60, 17, 59, 28,
75, 16, 76, 27,
94, 15, 95, 26,
115, 14, 116, 25,
138, 24,
163, 23,
190,  35,  42,  57,  41,  74, 40,  93, 39, 114, 38, 137, 37, 162, 36,
189,  50,  56,  73,  55,  92, 54, 113, 53, 136, 52, 161, 51,
188,  67,  72,  91,  71, 112, 70, 135, 69, 160, 68,
187,  86,  90, 111,  89, 134, 88, 159, 87,
186, 107, 110, 133, 109, 158, 108,
185, 130, 132, 157, 131,
184, 155, 156,
183, 182,

211, 34, 218, 49, 217, 66, 216, 85, 215, 106, 214, 129, 213, 154, 212, 181,
242, 48, 248, 65, 247, 84, 246, 105, 245, 128, 244, 153, 243, 180,
275, 47, 281, 64, 280, 83, 279, 104, 278, 127, 277, 152, 276, 179,
310, 46, 316, 63, 315, 82, 314, 103, 313, 126, 312, 151, 311, 178,
347, 62, 352, 81, 351, 102, 350, 125, 349, 150, 348, 177,
386, 61, 391, 80, 390, 101, 389, 124, 388, 149, 387, 176,
427, 79, 431, 100, 430, 123, 429, 148, 428, 175,
470, 78, 474,  99, 473, 122, 472, 147, 471, 174,
515, 77, 519,  98, 518, 121, 517, 146, 516, 173,
562,  97, 565, 120, 564, 145, 563, 172,
611,  96, 614, 119, 613, 144, 612, 171,
662, 118, 664, 143, 663, 170,
715, 117, 717, 142, 716, 169,
770, 141, 771, 168,
827, 140, 828, 167,
886, 139, 887, 166,
947, 165,
1010, 164,
1075, 192, 210, 241, 209, 274, 208, 309, 207, 346, 206, 385, 205, 426, 204, 469, 203, 514, 202, 561, 201, 610, 200, 661, 199, 714, 198, 769, 197, 826, 196, 885, 195, 946, 194, 1009, 193,
1074, 223, 240, 273, 239, 308, 238, 345, 237, 384, 236, 425, 235, 468, 234, 513, 233, 560, 232, 609, 231, 660, 230, 713, 229, 768, 228, 825, 227, 884, 226, 945, 225, 1008, 224,
1073, 256, 272, 307, 271, 344, 270, 383, 269, 424, 268, 467, 267, 512, 266, 559, 265, 608, 264, 659, 263, 712, 262, 767, 261, 824, 260, 883, 259, 944, 258, 1007, 257,
1072, 291, 306, 343, 305, 382, 304, 423, 303, 466, 302, 511, 301, 558, 300, 607, 299, 658, 298, 711, 297, 766, 296, 823, 295, 882, 294, 943, 293, 1006, 292,
1071, 328, 342, 381, 341, 422, 340, 465, 339, 510, 338, 557, 337, 606, 336, 657, 335, 710, 334, 765, 333, 822, 332, 881, 331, 942, 330, 1005, 329,
1070, 367, 380, 421, 379, 464, 378, 509, 377, 556, 376, 605, 375, 656, 374, 709, 373, 764, 372, 821, 371, 880, 370, 941, 369, 1004, 368,
1069, 408, 420, 463, 419, 508, 418, 555, 417, 604, 416, 655, 415, 708, 414, 763, 413, 820, 412, 879, 411, 940, 410, 1003, 409,
1068, 451, 462, 507, 461, 554, 460, 603, 459, 654, 458, 707, 457, 762, 456, 819, 455, 878, 454, 939, 453, 1002, 452,
1067, 496, 506, 553, 505, 602, 504, 653, 503, 706, 502, 761, 501, 818, 500, 877, 499, 938, 498, 1001, 497,
1066, 543, 552, 601, 551, 652, 550, 705, 549, 760, 548, 817, 547, 876, 546, 937, 545, 1000, 544,
1065, 592, 600, 651, 599, 704, 598, 759, 597, 816, 596, 875, 595, 936, 594, 999, 593,
1064, 643, 650, 703, 649, 758, 648, 815, 647, 874, 646, 935, 645, 998, 644,
1063, 696, 702, 757, 701, 814, 700, 873, 699, 934, 698, 997, 697,
1062, 751, 756, 813, 755, 872, 754, 933, 753, 996, 752,
1061, 808, 812, 871, 811, 932, 810, 995, 809,
1060, 867, 870, 931, 869, 994, 868,
1059, 928, 930, 993, 929,
1058, 991, 992,
1057, 1056,

1123, 191, ....


Once the data arranged like that, the patterns seem quite predictable. However, every other block (e.g. the penultimate one, starting with $$211=a_{113}$$) has "paragraphs" of lengths $$2$$ or $$3$$, except possibly the first one. Now it can be seen by construction that from one block to the (over-)next one, the 2-3-sequence of the block is generated by the preceding one in a similar way as the "rabbit sequence", a.k.a. the "Fibonacci word" https://oeis.org/A005614, by the laws (essentially) $$3\to22, 2\to323$$ plus boundary conditions that are much harder to predict...
So this partly explains the self-similarity. But:

How can one possibly prove that the asymptotic ratio is $$3+2\sqrt2$$?

Each block consists of a bunch of "horizontal" and a bunch of "vertical" monotonous subsequences of decreasing lenghts. For every other block, those come in roughly "L-shaped" pairs. The numbers of "L-shapes" per block are clearly distinguishible, e.g. $$8$$ of them in the range of $$n=49,\dots,112$$ (starting after $$a_{48}=190$$) and $$19$$ for $$n=270,\dots,630$$ (starting after $$a_{269}=1075$$, the beginning of the last block). Those numbers $$(c_j)=3,8,19,46,\dots$$ seem to form the Fibonacci type sequence https://oeis.org/A078343 with $$c_j = \frac14 \Bigl[(3 \sqrt{2} - 2) (1 + \sqrt{2})^j - (3 \sqrt{2}+2) (1 - \sqrt{2})^j\Bigr],$$ which is another indication in favor of the conjectured ratio, but I am not sure whether the recursion $$c_j=2c_{j-1}+c_{j-2}$$ can be shown by induction.

You can also have a look at https://codegolf.stackexchange.com/a/145234/14614, which displays the differences $$a_{n+1}-a_n$$, and at the image of the inverse map $$a_n\mapsto n$$ quoted below from one of the comments. (Note that the isolated point at $$a_n=191$$ corresponds to $$n=632$$, which is just where my above table stops.) Both show a lot of beauty, but they also show that the self-similarity is somewhat less strict than for the fractal sequences mentioned here.