Showing posts with label orbits simulator. Show all posts
Showing posts with label orbits simulator. Show all posts

Wednesday, April 27, 2016

Modelling a Subset problem: An interesting sequence obtained from an orbits simulator (III)

This is the third part of the previous posts about the topic "an interesting sequence obtained from an orbit simulator" and its second part.

Several months have passes and still I do not know very much about the properties of my initial subset problem, so what I am trying to do is first trying to write all more properly, so instead of talking about an example (an orbits simulator) I am trying to explain the algorithm mathematically. So here is what so far I was able to do:

It seems that my original problem could fit into this area:

>Partition Problem > multi-way partition problem

Which is defined as (Wikipedia) "the optimization version of the partition problem. Here, the goal is to divide a set or multiset of n integers into a given number k of subsets, minimizing the difference between the smallest and the largest subset sums."

For that reason I am using as a lead paper to gather ideas:  "Korf, Richard E. (2009). [Multi-Way Number Partitioning (PDF)][2]. IJCAI."

...but I am not really sure if my defined problem could be included in that kind of generic problems because instead of using a set of integers I am using a "FIFO first-in-first-out pile" of integers F, and the subsets are created "on the fly", meaning that you just can take the head element when using the algorithm that creates the partitions to populate the generated subsets. Here is the description / algorithm of the problem:

1. Initially there is a FIFO set F and an empty list S of subsets. Every time a subset is generated it will have an index i, for instance S_i. The first subset will be S_0, then S_1, etc. The main rule is that in every moment the sum of the elements of any S_j will be smaller or equal to the sum of the elements of any S_i with an index i smaller than j.

2. Take the head element of the FIFO set and

a) If the sum of the elements of the subset with greatest index $S_k$ is smaller or equal to the new element, then create a new subset $S_{k+1}$ and insert the element.

b) If not, then insert the element in the existing subset S_j with the greatest possible index j such as when the element is aggregated the sum of the subset S_j is still smaller or equal than any sum of any subset S_i with lower index i than j. If no subset with index greater than 0 complies with the rule, then the element is inserted into S_0 (if S_0 still was not generated, it is created and then the element is inserted).

3. Repeat from step 2 until the FIFO set is empty.

Example with a FIFO set F= N^{+} containing the natural numbers not including 0 in strictly increasing order {1,2,3,4,5...}:

1. Take the head element, 1 , a) look for the existing subset available at S with the greatest index. As S is still S empty, create one (in this case S_0) and add it S_0={1}.

2. Take head element, 2, and a) go the the subset with available with the greatest index, in this case S_0. As 2 is not smaller than the sum of the elements of the subset (1) then applying b) 2 is inserted into S_0.

3. Take the head element, 3, and go the the existing subset with a greatest index (in this case there is only one S_0). a) As the new element 3 is smaller or equal to the sum of the elements of S_0 (3) it is possible to create a new subset. So the element is added to S_1, S_1 = {3}.

So far we got two subsets S={S_0,S_1} and the sum of S_j <=  the sum of S_i for all i<j.

4. If the process is repeated for the next element head of the pile, 4, as the sum of S_1 is 3 not >= 4 then we can not create a new subset, so we try to add 4 to S_1, but if we add 4 to S_1 then the sum of S_0 (3) will not be greater or equal to the sum of S_1 that would be 3+4=7 so we can not add 4 to S_1. We go down one level, now we try to add 4 to S_0 as there are not other subsets lower than S_0 we can add 4 to S_0.

So far the subsets are:

S={S_0={1,2,4}, S_1={3}}

After some repetitions of this algorithm, the subsets look like this (this image was already shown in the first post I did about the topic):




There are two interesting subsets there, S_0 and the set of first elements of each S_i, I will call it F.

S_0={1,2,4,5,8,12,17,19...}. S_0 will always be the subset with the greatest value of the sum of its elements.

F={1,3,7,11,16,25...}. The elements of this subset are those elements of the initial FIFO set capable of forcing the generation of a new subset.

Tried to find them at OEIS, but unluckily they are not included.

When I thought about this problem for the first time (in the first post above mentioned) I was thinking about an application of this algorithm regarding a model for energy levels in different orbits. Imagine a "nucleus" that can have several orbits around, initially there are no orbits, then arrives a chunk of energy 1 and it is located in the lower orbit equivalent to S_0, then arrives another chunk of energy 2 but it can not be located in a second orbit or level of energy because the energy of a greater level can not be greater than the energy in the lower levels, so it remains at level S_0. But when the next chunk 3 arrives, it can be located in a new level of energy because there is at least the same quantity of energy in the lower levels.

By doing the algorithm as above, always the lower levels (the levels closer to the "nucleus") have more energy than the outer levels, and always any level of energy. Or saying the same from the mathematical model: the previously generated subsets will always have a sum greater or equal than any other lately generated subsets.

Basically I am lost about how to catalog this (and then expand it, study the properties, etc.) so I have also asked a question regarding to this topic at MSE (link here).

Monday, July 20, 2015

An interesting sequence obtained from an orbits simulator: Fibonacci (II)

In the previous post I wrote an orbit simulator that produces a very intriguing sequence. I am still reviewing it, and still did not see any special property of it, but using the same orbits algorithm and instead of  using the sequence of natural numbers, using Fibonacci numbers the results are much more interesting!

Here are the results of the first terms, when the sequence is the Fibonacci numbers, due to the relationship of the Fibonacci terms, only two orbits are generated. A third orbit will never be possible!


Observing the two orbits it is easy to see that the odd terms of the first orbit divide the odd terms of the second orbit in the same position. And here is the surprise, when dividing the second orbit terms by the first orbit terms, the appearing sequence is:

{1, 7, 29, 123, 521, 2207, 9349, 39603, 167761, 710647, 3010349, 12752043, 54018521, ...}

Which is the generalized Pell equation with second term of 7, and can be found at OEIS here.

In the other hand the odd terms of the second orbit are Fibonacci(6n+5).

The second orbit appears as well as a sequence at OEIS (A015448). a(0)=1, a(1)=1, and a(n) = 4*a(n-1) + a(n-2) for n>=2.

About the first orbit, only the odd terms appear as A033887:  a(n) = Fibonacci(3n+1).

The results are quite interesting and I hope they will help me to find some relationship when using the natural numbers sequence instead of Fibonacci.

Wednesday, July 15, 2015

An interesting sequence obtained from an orbits simulator

I have obtained an interesting sequence by making a simulation of a system with a total of k "orbits", system_k = {o_0,o_1..o_k-1} where the orbits are filled with natural numbers following the algorithm explained below. The orbit closer to the "nucleus" is o_0. Applying the rules below I can obtain a sequence that I suspected would be easy to find at OEIS, but it was not there.

The main rule to generate the sequence is: an orbit o_i can never have a set of numbers whose sum is greater than o_i-1 (in other words, the more internal orbit it is, the "heavier" it is) and the most external orbit only can have one number. The rules to settle numbers follow this algorithm:

1. number to settle n = 1.

2. current orbit = the most external orbit = o_k-1

3. If the current orbit is not o_0 and the sum of the numbers currently settled in the current orbit plus n are less or equal than the sum of the numbers currently settled in the immediately lower closer orbit then add n to the current orbit. If the current orbit is the most external one, finish.

4. In other case, if the current orbit is not o_0 then current orbit = immediately lower closer orbit and try again step (3). If the current orbit is o_0 directly settle n into it. If it was a system of total orbits = 1 then finish. If not, n=n+1 and go to step (2).

By doing this the algorithm finishes when a number n is settled for the first time the most external orbit of the system.

(Q) What I wanted to simulate is: for the interval of [1,T] orbits, how many numbers are necessary to settle until one number is finally settled in the outer orbit? 

E.g. this are the results applying the algorithm to some orbits:



It is easy to see that the system_i is a subset of the system_i+1. It means that finding the answer to the question (Q) is the same as generating a T orbits system (system_t) and checking which one was the first number n settled on each orbit of the system.

When the test is run this is the sequence S of numbers required to settle a number in the outer orbit for a number of [1..49] orbits:

S={1,3,7,11,16,25,32,40,49,59,73,85,98,112,127,147,164,182,201,221,242,272,295,319,344,370,397,425,454,484,515,553,586,620,655,691}

The sequence can not be found at OEIS, but the idea is simple so I suspect that probably there is this same sequence somewhere and can not find it.

I wonder if there is a reference about a similar sequence like this, applying a similar algorithm, and if the sequence S is somehow predictable (there is a closed-form expression).

Some extra information:

This is how system_31 loos like:


And this is the Python code in case somebody wanted to play with it:

def orbits():
    from sympy import totient,mobius
    from gmpy2 import is_prime,is_square
  
    orbits=[[],[]]
    total_orbits = 2
    current_orbit = total_orbits
    for n in range (1,100):
        while True:
            valn = n
            if (current_orbit>1) and (sum(orbits[current_orbit-1])+valn) <= (sum(orbits[current_orbit-2])):
                orbits[current_orbit-1].append(valn)
                break

            else:
                current_orbit = current_orbit -1
                if current_orbit == 1 or current_orbit==0:
                    orbits[0].append(valn)
                    break

        if (current_orbit == total_orbits) and current_orbit!=0:
            total_orbits = total_orbits + 1
            orbits.append([])
            current_orbit = total_orbits
        else:
            current_orbit = total_orbits

    for o in orbits:
        mystr=""
        for n in o:
            mystr = mystr + str(n) + "\t"
        print(mystr)
  
    mystr=""
    for o in orbits:
        for n in o:      
            mystr = mystr + str(n) + "\t"
            break
    print(mystr)
orbits()