Former Fibonacci Magic Square Building Analysis Updated (too long of a title)

Continuing the same line of thought (Fibonacci MSBA) I wondered what would be required to find a neat algorithm for creating families of larger MSs. I quickly found out I was limited in terms of tools, because I had only 3×3, which meant I could try only to extend to larger odd-sided squares. Even-sided and Odd-sided squares do not allow the same methods. At least – not all methods allowed by each are the same.
So… I chose my first even-sided to be 4×4, instead of 2×2.

It took a bit of fiddling around. I wanted to follow the same general principal – create the ‘0’ square, then use it to build a family above it.
It does not take any significant amount of time to find that Tribonacci does not work.
The general formula is T1 + T2 + T3 = T4
The fact that you have not 2 but 3 smaller values (T1 to T3) means that for each subset that you want to create, you have 3 values to reuse, instead of 2. And you can alternate signs only so far. Each value can be only negative or positive, so you are bound to repeat a signed value.

Sidetrack:
If you do not care about repeating values, you can easily create a 4×4 using Tribonacci:

7-1324
-244713
1374-24
42-137

I did not bother so generalize the table here, cause I myself do care about the repeats.
But it’s worth looking at, because some useful things become apparent.

So… What do we learn from the failed square above?
– First, we need another equivalence grouping in order to ensure unique sides (as opposed to ~bonacci).
– Second, we don’t have center cell, nor we have center row and column, but that does not get in the way of our reflections.

The happy thought was that a very easy way of creating an even number of values that can be brought to 0 is to just use an even number of consecutive values and couple them outwards-in. As in:
1, 2, 3, 4, 5, 6
The sum of the outer ones is the same as the sum of the intermediate ones, is the same as the sum of the inner ones. 1+6 = 2+5 = 3+4. Which means that if you have 2 couples (a total of 4 values) – you can subtract one of the couples from the other to get the desired 0.
The first dead reckoning attempt started with the numbers 1 through 16. I started combining them from both ends. Why 16? Clearly too large of a range, but I did not want to think at this point about clashing couples in the middle, so… Somewhere along the way I messed up a sum, so I had to start over, but I have already noticed the pattern that would form:

1-38-6
-24-75
-57-42
6-831

Notice that? I was quite pleased when I did. There’s in fact a bit too much pattern in that square. Notice the way each small 2×2 square is filled in. Top-left and top-right corners, for example. You start with 1 and go down when going Odd-Even, but for 5-8 it is the other way around? Do you have to? Also, for the smaller values (1-4) you go outside-in and the same for 5-8. Do you have to?
No, of course not.
Here is an equally valid and much more clean looking variation of the square (Ok, not the square, only the cell pattern):

1357
2468
----
----

See?

The generalization is obvious now. The fact that I started with consecutive integers obscures the important properties a bit (what I mentioned about too much of pattern a moment ago).
The true pattern (and algorithm) is the following:
Ingredients: A sequence of 8 integers, such that the difference between each 2 consecutive integers is a constant. (in the above example it is the trivial ‘1’).
Steps: Fill in one of the sides and the underlying row/column in a zig-zag pattern with the ingredients (keeping their order).
This should result in rows (or columns) where neighbouring cells have the same difference. And this will also be the difference between a cell and the corresponding one from the next row/column.

Meaning:
V1, V2 .. V7, V8
where Vn = Vn-1 + X

V1V3V5V7
V2V4V6V8

When you do that, you have the base to crate a ‘0’ square:
– Mirror the values
– Dispense the negatives
The way to do the second of those last steps is the following:
Start row by row (or columns by column; I should stop clarifying that, it is obvious). On each row alternate – either the largest and smallest or the two intermediate values remain positive, while the rest become negative.
Like this:

-V1V3V5-V7
V2-V4-V6V8
-V8V6V4-V2
V7-V5-V3V1

Um… I am sure there was something else. It will get back to me later, I guess. For now – that is it. You create your seed sequence, you fill in, reflect, then negate half the values. You get a 4×4 ‘0’ square and you are free to build upon it as you wish. Again, as with the 3×3 before and as it is with all ‘0’ squares – the possible magic constants are always a multiple of the length of the sides. So 4 in this case.

Fibonacci Magic Square Building Analysis

So…

After I’ve slept over it.

The Fibonacci works well, because the algorithm creates a base case with a ‘0’ MC.

The schema again:

C-B
-0A
-D-
C-DB
-A0A
-BD-C

I was just doodling last night and just kind of figured it out to make it work, but now that I look at it, it is obvious why it had to be this way.
Starting in order of the Fib numbers…
Ok, Ok, let’s do it properly.

F3-F4F2
-F10F1
-F2F4-F3

Let us build it with a few simple steps.

So, three principles to the arrangement:

0. We place a zero in the middle.

1. We are considering the sides – the lines that do not go through the center. In order to bring each one of them to 0 using the Fib numbers, we simply take advantage of the fact that, by definition, we will get to 0 if we take any Fib number (2 and above) and remove the previous two. Meaning that we need two consecutive Fib numbers with one sign (positive or negative) and the next Fib number with the opposite sign.

1.1 We have 4 Fib numbers and we need them to cover 4 sides. The way to do it is to use the fact that 4 consecutive numbers form 2 overlapping subsets of 3 consecutive numbers each – F1 to F3 and F2 to F4.
Given that F2 and F3 are part of the two subsets, we place them in neighboring corners. Now F3 will form one of the subsets with F2 on their shared side and the other subset on the other side. Similar for F2.

F3-F2
---
---

1.2 From the subsets we know that F2 is the middle value in subset 1 and the lowest value in subset 2. Correspondingly, F3 will be the highest value in subset one and the middle value in subset 2. This means that the top side (in this rotation), that already contains F2 and F3, will be part of the two subsets.
This is where we note that at this stage we have four sides with a total of four copies of the two subsets. For now, we will forget about the sign of the numbers and focus on the values.
Once we have the F2 and F3 placed, the rest is almost automatic. We have one choice to make, which is completely arbitrary, because it gets cancelled later on by the symmetries of the MS.
We need to place either F1 or F4 between F2 and F3 that are already on the board. Let’s choose F4. This means that the newly formed side is the larger subset.
We copy each of the values across the center, resulting in another copy of the subset, just in reverse order looking in the same direction (from left to right in this case). Only two cells remain and we fill them in with the value we did not choose the last time. In this case – F1.
We get:

F3F4F2
F10F1
F2F4F3

1.2 We pick a side and start multiplying by -1. The rule that governs the multiplication is what we mentioned earlier – in each of the subsets, the two smaller values have the same sign, which is also opposite to the sign of the largest value.
At the top we simply convert F4 to -F4. So F2 and F3 remain positive. This means that on the right F1 will have the same sign as the F2 and F3 will become -F3. On the left F3 is the highest value, so F1 and F2 there will be multiplied by -1. This also automatically takes care of the bottom row.

F3-F4F2
-F10F1
-F2F4-F3

1.3 Sanity check – across the center each Fib number stands opposite its negative, so along with the zero at the center, so each diagonal results in a zero.

1.4 Versions – the only notable thing so far is that if we had chosen to place F1 at the top, instead of F4, we would have gotten a schema that is flipped along the F2 diagonal. It is not immediately obvious to me why F2 and not F3. Needs some looking into.

-F3F1F2
F40-F4
-F2-F1F3

Consequence of this whole thing. We are not using the fact that the numbers are part of the Fibonacci sequence. We are merely using the property that numbers in the Fibonacci sequence have – each equals the sum of the previous two. Which means that we can also freely use the Lucas sequence or any other that shares the same building principle.

Next:
– What about Tribonacci? Can we extend the algorithm to cover 4×4 MS? There are some nice complications that are visible from the start – we will need longer Fib subsets, but we still have only four sides. Also, we have outer sides and inner sides. Delight!

 

Back on the track

I had to stop all game dev for a while – finally I got my first job as a developer. This, of course, meant I had to bank on my reserves of discipline and concentrate solely on the job, to get above the initial curve without hickups.

All the more – my job involves mainly Python and then some Angular for color. So…

I waited patiently for 6 months and I can say that at least most of the time I know what I am doing. Not that I have somehow become really good or don;t need to pay attention anymore, but I found that I can break my self-imposed gamedev restraint and can actually spend some time after hours to what really matters.

So… Back to the drawing board!

som’mathing

So… I was playing around with this here WP platform.

I haven’t kept a wordpress blog in a while and I kinda got back my taste for it, after posting the first two posts in the TankUp dev journal.

And as I love the tags concept as a tool, I decided I’ll use a 3-tag system as a time marker – ‘flashback’, ‘this just in’ and ‘flash forward’. The meaning of those is, I think, easily discernible – flashbacks are about what I have already done with the project (in time those will dwindle out), ‘this just in’ will follow my latest progress and ‘flash forward’ will be about things I need to get on with in the future.

The ‘problem’  is with the ‘this just in’s – this did not ‘just in’, unless I immediately post here, after I have uploaded my latest changes in the GitHub repo. So why use ‘just’. Obviously because it sounds cool.

But I figured a way of describing the timing of events so that I can use justify the ‘just’. Here is how it goes:

You have two timelines (A and B), conforming to the following conditions:

– both are discrete

– events in the two discrete timelines do not have duration

– both are co-dependent on a third timeline, which is continuous (C, also ‘control timeline’)

Result: At any point in the third timeline, the two latest events in the discrete timelines are considered simultaneous

In this case timeline A is the timelog of the GitHub submissions in the TankUp repo; timeline B is the sequence of ‘this just in’ posts here about the TankUp project.

The latest event in timeline A is, as defined in this system, simultaneous with the latest event in timeline B, regardless of the time interval that separates their projections on the control timeline (C)

Cool, eh!