Showing posts with label reverse engineering. Show all posts
Showing posts with label reverse engineering. Show all posts

Thursday, 25 June 2026

Reverse Engineering Part 3

In my previous post, Reverse Engineering Part 2, I ended up being quite satisfied with the reverse engineering that created as output an homogenous linear recurrence relation of order 3 after input of any positive integer greater than 9. I used 28206 and 28207 as examples to illustrate the process.

This got me thinking about creating as output an homogenous linear recurrence relation of order 2 after input of any positive integer greater than 9. I explained in my post Reverse Engineering Part 1 that Gemini's algorithm had failed when attempting this. I was trying to get Gemini to create the following:$$ \begin{align} &\text{a}(n)=p \times \text{a}(n-1)+q \times \text{a}(n-2) \\ &\text{where} -9 \leq p,q \leq 9 \text{ with } p \neq 0 \text{ and } q \neq 0 \\ &\text{ and } 0 \leq \text{a}(n-1), \text{a}(n-2) \leq 9 \end{align}$$So I asked Gemini to relax the conditions by specifying that \( |p + q|\) should be as small as possible. When applied to 28207 this produced values \(p=39\) and \(q=-38\). Not quite what I wanted. So in the end I specified that \(|p^2+q^2+a(0)^2+a(1)^2|\) should be as small as possible. Applied to 28206, this was the result (permalink):

Target Number: 28206
--------------------------------------------------
Constants found: p = 13, q = 1
Constraint check: Minimum p^2 + q^2 + a(0)^2 + a(1)^2 = 395
Seed numbers:    a(0) = 9, a(1) = 12
--------------------------------------------------
Sequence progression:
  a(0) = 9
  a(1) = 12
  a(2) = 165
  a(3) = 2157
  a(4) = 28206
--------------------------------------------------
Comma-separated sequence:
9, 12, 165, 2157, 28206

Applied to 28207, this was the result (permalink):

 Target Number: 28207

--------------------------------------------------
Constants found: p = 6, q = 5
Constraint check: Minimum p^2 + q^2 + a(0)^2 + a(1)^2 = 231
Seed numbers:    a(0) = 11, a(1) = 7
--------------------------------------------------
Sequence progression:
  a(0) = 11
  a(1) = 7
  a(2) = 97
  a(3) = 617
  a(4) = 4187
  a(5) = 28207
--------------------------------------------------
Comma-separated sequence:
11, 7, 97, 617, 4187, 28207

Overall I'm quite happy with these sequences. All terms are positive, the coefficients and seed values are not large and the terms increase steadily toward their targets, avoiding any wild gyrations. I have incorporated this program into my daily number analysis. 

Wednesday, 24 June 2026

Reverse Engineering Part 1

I have a sub-program in my daily number analysis program that will work backwards to find Fibonacci seed numbers that will generate a sequence of terms that leads to my daily number. For example, today I am 28206 days old, and my sub-program generates the following output:

Fibonacci Sequence: Smallest Starting Pair for Target 28206
Starting numbers: a = 126, b = 118
Sequence length to target: 13
Full sequence: [126, 118, 244, 362, 606, 968, 1574, 2542, 4116, 6658, 10774, 17432, 28206]

This can be expressed as:$$ \begin{align} \text{a}(n)=\text{a}(n-1) + \text{a}(n-2)  \\ \text{where } \text{a}(0)=126 \text{ and } \text{a}(1)=118 \end{align}$$These large initial values disturbed me and I wondered if the addition of coefficients \(p\) and \(q\) might reduce the size of the seed numbers required.

I asked Gemini the following:

I would like you to write a program in SageMath that will accept any positive integer \(n > 9\) as input and work backwards to find two seed numbers \( \text{a}(0) \text{ and } \text{a}(1)\) that, combined with constants \(p\) and \(q\), will lead to \(n\) via a Fibonacci-like sequence generated by \( \text{a}(n) = p \times \text{a}(n-1) + q \times \text{a}(n-2)\). The restrictions are that the seed numbers must be between 1 and 9 and the constants \(p\) and \(q\) must also be between -9 and 9.  In the case of more than one combination of constants and seed numbers being found, the criterion is that \(p + q\) should be the minimum possible. The default value for n can be taken as 28206. The program should run in SageMathCell and a Jupyter notebook. The output should show the sequence as it progresses from its starting seed numbers to the final number n. The members of the sequence should also be displayed as comma-separated values.

Unfortunately these restraints proved too restrictive and so I turned to Tribonacci numbers looking for three seed numbers, each between 0 and 9, and three constants \(p, q, r\), each lying between -9 and 9 so that:$$\text{a}(n) = p \times \text{a}(n-1) + q \times \text{a}(n-2) + r \times \text{a}(n-3) $$This proved more productive with Gemini creating the program and producing the following output (permalink):

Target Number: 28206
------------------------------
Constants found: p = -9, q = -6, r = -3
Constraint check: Minimum p + q + r = -18
Seed numbers:    a(0) = 2, a(1) = 4, a(2) = 2
------------------------------
Sequence progression:
  a(0) = 2
  a(1) = 4
  a(2) = 2
  a(3) = -48
  a(4) = 408
  a(5) = -3390
  a(6) = 28206
------------------------------
Comma-separated sequence:
2, 4, 2, -48, 408, -3390, 28206

For me, this is a more satisfactory output with the recursion looking like this: $$ \begin{align} &\text{a}(n) = -9 \times \text{a}(n-1) -6 \times \text{a}(n-2) -3 \times \text{a}(n-3) \\ &\text{with } \text{a}(0)=2, \text{a}(1)=4, \text{a}(2)=2 \end{align}$$What we have here is an homogenous linear recurrence relation of order 3 with coefficients and boundary conditions (seed values) as shown. The sequence is defined by two tuples: the coefficient tuple C and initial value tuple I and written as (C, I). In the example just shown, the representation would be:$$((-9, -6, -3), (2,4,2))$$Let's look at the next number 28207 characterised by ((-4, -9, -8), (3, 5, 1)):

Target Number for Reverse Tribonacci: 28207
------------------------------
Constants found: p = -4, q = -9, r = -8
Constraint check: Minimum p + q + r = -21
Seed numbers:    a(0) = 3, a(1) = 5, a(2) = 1
------------------------------
Sequence progression:
  a(0) = 3
  a(1) = 5
  a(2) = 1
  a(3) = -73
  a(4) = 243
  a(5) = -323
  a(6) = -311
  a(7) = 2207
  a(8) = -3445
  a(9) = -3595
  a(10) = 27729
  a(11) = -51001
  a(12) = -16797
  a(13) = 304365
  a(14) = -658279
  a(15) = 28207
------------------------------
Comma-separated sequence:
3, 5, 1, -73, 243, -323, -311, 2207, -3445, -3595, 27729, -51001, -16797, 304365, -658279, 28207

Figure 1 shows the trajectory of the sequence which begins to fluctuate wildly but the negative by negative multiplication quickly homes in on the target number (28207).

Figure 1

I've now incorporated this information into my daily number analysis.

Friday, 16 January 2026

Fibonacci-Related Numbers

My diurnal age today is \( \textbf{28047} \) and this number has the interesting property that it's part of a Fibonacci sequence with seed numbers of 3 and 9. This leads to the following sequence of numbers:

3, 9, 12, 21, 33, 54, 87, 141, 228, 369, 597, 966, 1563, 2529, 4092, 6621, 10713, 17334, 28047, ...

These initial numbers form part of OEIS A022379

The thought occurred to me that given two seed digits between 0 and 9, there ought to be a limited set of numbers from 10 to let's say 40000 that are generated by two single digit seeds. I got Gemini to write a Python program (permalink) to investigate this and it turns out that there are 651 numbers with this property. Here they are:

10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 107, 108, 109, 110, 111, 112, 113, 115, 116, 117, 118, 120, 121, 123, 124, 125, 126, 128, 129, 131, 133, 134, 136, 137, 138, 139, 141, 142, 144, 146, 147, 149, 150, 152, 154, 155, 157, 159, 160, 162, 163, 165, 167, 168, 170, 173, 175, 176, 178, 180, 181, 183, 186, 188, 189, 191, 194, 196, 199, 201, 202, 204, 207, 209, 212, 215, 217, 220, 222, 223, 225, 228, 230, 233, 236, 238, 241, 243, 246, 249, 251, 254, 257, 259, 262, 264, 267, 270, 272, 275, 280, 283, 285, 288, 291, 293, 296, 301, 304, 306, 309, 314, 317, 322, 325, 327, 330, 335, 338, 343, 348, 351, 356, 359, 361, 364, 369, 372, 377, 382, 385, 390, 393, 398, 403, 406, 411, 416, 419, 424, 427, 432, 437, 440, 445, 453, 458, 461, 466, 471, 474, 479, 487, 492, 495, 500, 508, 513, 521, 526, 529, 534, 542, 547, 555, 563, 568, 576, 581, 584, 589, 597, 602, 610, 618, 623, 631, 636, 644, 652, 657, 665, 673, 678, 686, 691, 699, 707, 712, 720, 733, 741, 746, 754, 762, 767, 775, 788, 796, 801, 809, 822, 830, 843, 851, 856, 864, 877, 885, 898, 911, 919, 932, 940, 945, 953, 966, 974, 987, 1000, 1008, 1021, 1029, 1042, 1055, 1063, 1076, 1089, 1097, 1110, 1118, 1131, 1144, 1152, 1165, 1186, 1199, 1207, 1220, 1233, 1241, 1254, 1275, 1288, 1296, 1309, 1330, 1343, 1364, 1377, 1385, 1398, 1419, 1432, 1453, 1474, 1487, 1508, 1521, 1529, 1542, 1563, 1576, 1597, 1618, 1631, 1652, 1665, 1686, 1707, 1720, 1741, 1762, 1775, 1796, 1809, 1830, 1851, 1864, 1885, 1919, 1940, 1953, 1974, 1995, 2008, 2029, 2063, 2084, 2097, 2118, 2152, 2173, 2207, 2228, 2241, 2262, 2296, 2317, 2351, 2385, 2406, 2440, 2461, 2474, 2495, 2529, 2550, 2584, 2618, 2639, 2673, 2694, 2728, 2762, 2783, 2817, 2851, 2872, 2906, 2927, 2961, 2995, 3016, 3050, 3105, 3139, 3160, 3194, 3228, 3249, 3283, 3338, 3372, 3393, 3427, 3482, 3516, 3571, 3605, 3626, 3660, 3715, 3749, 3804, 3859, 3893, 3948, 3982, 4003, 4037, 4092, 4126, 4181, 4236, 4270, 4325, 4359, 4414, 4469, 4503, 4558, 4613, 4647, 4702, 4736, 4791, 4846, 4880, 4935, 5024, 5079, 5113, 5168, 5223, 5257, 5312, 5401, 5456, 5490, 5545, 5634, 5689, 5778, 5833, 5867, 5922, 6011, 6066, 6155, 6244, 6299, 6388, 6443, 6477, 6532, 6621, 6676, 6765, 6854, 6909, 6998, 7053, 7142, 7231, 7286, 7375, 7464, 7519, 7608, 7663, 7752, 7841, 7896, 7985, 8129, 8218, 8273, 8362, 8451, 8506, 8595, 8739, 8828, 8883, 8972, 9116, 9205, 9349, 9438, 9493, 9582, 9726, 9815, 9959, 10103, 10192, 10336, 10425, 10480, 10569, 10713, 10802, 10946, 11090, 11179, 11323, 11412, 11556, 11700, 11789, 11933, 12077, 12166, 12310, 12399, 12543, 12687, 12776, 12920, 13153, 13297, 13386, 13530, 13674, 13763, 13907, 14140, 14284, 14373, 14517, 14750, 14894, 15127, 15271, 15360, 15504, 15737, 15881, 16114, 16347, 16491, 16724, 16868, 16957, 17101, 17334, 17478, 17711, 17944, 18088, 18321, 18465, 18698, 18931, 19075, 19308, 19541, 19685, 19918, 20062, 20295, 20528, 20672, 20905, 21282, 21515, 21659, 21892, 22125, 22269, 22502, 22879, 23112, 23256, 23489, 23866, 24099, 24476, 24709, 24853, 25086, 25463, 25696, 26073, 26450, 26683, 27060, 27293, 27437, 27670, 28047, 28280, 28657, 29034, 29267, 29644, 29877, 30254, 30631, 30864, 31241, 31618, 31851, 32228, 32461, 32838, 33215, 33448, 33825, 34435, 34812, 35045, 35422, 35799, 36032, 36409, 37019, 37396, 37629, 38006, 38616, 38993, 39603, 39980

The following code (permalink) can be used to find the seeds of any number in this list. It's not impressive code I'm sure but it seems to do the job. Let's try with the last number in the previous list, 39980.

c=39980 L=[] b=round(c/((1+sqrt(5))/2)) L.append(c);L.append(b) a=0 while b>=a and c>b: a=c-b if a <b: c=b b=a L.append(a) L.reverse() if len(str(L[1]))==2: a=L[1]-L[0] b=L[0] print("Seed numbers for Fibonacci sequence are", a,"and",b) X=[a,b] L.remove(L[0]) print(X+L) else: print("Seed numbers for Fibonacci sequence are", L[0],"and",L[1]) print(L)


Seed numbers for Fibonacci sequence are 9 and 4

[9, 4, 13, 17, 30, 47, 77, 124, 201, 325, 526, 851, 1377, 2228, 3605, 5833, 9438, 15271, 24709, 39980]


Interestingly, 39980 is listed in the OEIS as OEIS A022132 but the seeds are listed as 4 and 13 but this is equivalent of course to seeds of 9 and 4. Zero can be a seed number in the first position but it can't then be followed by another zero and so there are 10 x 9 = 90 distinct pairs of single digit seeds. 

Two different pairs of single digit seeds can lead to the same sequence. For example:
  • seeds of 1 and 3 \( \rightarrow\) 1, 3, 4, 7, 11, 18, 29, ...
  • seeds of 2 and 1 \( \rightarrow \) 2, 1, 3, 4, 7, 11, 18, 29, ...
Figure 1 shows a plot of these Fibonacci-related numbers and it's interesting that they form a definite exponential curve with the density of points noticeably thinning out as the numbers become larger.


Figure 1
ADDENDUM:

After completing this post, I discovered that I'd already covered this topic in a post from Thursday, 12th June 2025 titled Fibonacci Numbers Derived From Single Digits. However, in that post I only considered seed digits where the first was smaller than the second and so I discounted a number like 59 because it requires seed digits of 7 and 3 such that the sequence 7, 3, 10, 13, 23, 36, 59 is generated.