So your question was wrong. I'm not saying an individual sequence ends
in alternating evens and odds, but that the last number of different
sequences is alternately even or odd.
Take the Sequence vector [1,4]. That means a sequence of operations
(Seed=n)->(3n+1)(n/2)(3n+1)(n/2)(n/2)(n/2)(n/2)->(n=Hailstone)
The function that describes that sequence of operations is
32*H_i - 5
S_i = ----------
9
There are an infinite number of seeds that give us that sequence of
operations and result in integer hailstone.
They are
S_i: 3, 35, 67, 99... (32*i + 3).
Note that all the seeds are odd, but that the hailstones alternate
between even or odd:
H_i: 1, 10, 19, 28... (9*i + 1)
>
> > That's why I was asking if you always stop on an odd number. You must
> > adjust your formulae (which you've done and confused me at first) to
> > accomplish this since the general rule gives stopping points on even
> > and odd numbers (which is what I use).
>
> > I'm not saying there's anything wrong, just that there are
> > consequences that have to be accounted for.
>
> Don't leave me hanging! I've been wracking my brain trying to figure
> out why you insist on even H_i's. An even H_0 maybe, but why
> even H_i ' s?
Because even H_i's come out of the function even when you supply only
odd seeds.
Does that matter? Sometimes.
Take for example the seeds and hailstones of [1,2].
8*H_i - 5
S_i = ---------
9
S_i: 3, 11, 19, 27, 35, 43, 51, 59, 67, 75...
H_i: 4, 13, 22, 31, 40, 49, 58, 67, 76, 85...
Note that the number 67 is on the S_i list AND on the H_i list.
What that means is
8*H_8 - 5
S_8 = ---------
9
and that
8*S_8 - 5
S_7 = ---------
9
In other words, we can plug the seed of H_8 into the function
as a hailstone to get S_7. Thus, H_8 is the hailstone of a
Second Generation Type [1,2] Sequence Vector. Generation counts
how many times a base Sequence Vector type can repeat and still
produce an integer.
1st Generation Type [1,2] = [1,2]
2nd Generation Type [1,2] = [1,2,1,2]
3rd Generation Type [1,2] = [1,2,1,2,1,2]
4th Generation Type [1,2] = [1,2,1,2,1,2,1,2]
5th Generation Type [1,2] = [1,2,1,2,1,2,1,2,1,2]
For Type [1,2], every 9th 1st Generation is a 2nd Generation,
every 9th 2nd Generation is a 3rd Generation, every 9th 3rd
Generation is a 4th Generation, etc. But its's not always that
easy. For some Sequence Vectors, you get very complicated
generation rules like
every 27th 1st generation is a 2nd generation starting from the 5th
every 27th 2nd generation is a 3rd generation starting from the 11th
every 27th 3rd generation is a 4th generation starting from the 23rd
every 27th 4th generation is a 5th generation starting from the 17th
And the goofy rules are different for every Sequence Vector.
Trying to solve THAT makes the simple H_i = H_0 + ( 2 * 3 ^ V) * i
a doddle:
def gen0_recursive(k,xyz):
"""Find first member of generation k of Hailstone Function.
gen0(k,xyz)
k: generation
xyz: HailstoneFunctionParameters
Locates the first _a_ for the requested generation k of the
Hailstone Function.
Needs to know _d_ and _c_ from previous generation, so it calls
itself recursively until generation 1.
At generation 1, results are simple linear congruence of x,y,z.
a: the first solution to the Hailstone Function
g: seed that genertes _a_
d: difference between _a_ and _g_
j: index of _a_ where d == 0 (mod y**k)
c: a[j] the
returns [0,0,0,0] if k invalid
returns GenerationParameters [a,g,d,c]
"""
if k<1: return [0,0,0,0]
if k==1:
# divm finds n such that
# n*x == a (mod y)
#
# this is the first gen 1 _a_
#
a = gmpy.divm(xyz[2],xyz[0],xyz[1])
g = seed(a,xyz)
d = a - g
c = a
return [a,g,d,c]
else:
prev_gen = gen0(k-1,xyz)
j = gmpy.divm(xyz[1]**(k-1)-prev_gen[2],xyz[1]-
xyz[0],xyz[1]**(k-1))/xyz[1]**(k-2)
a = j*xyz[1]**(k-1) + prev_gen[3]
g = seed(a,xyz)
c = a
d = a - g
return [a,g,d,c]
You see, I really DO need the even hailstones otherwise the generation
calculation would break down.
Why do we care about Generations? Because the Crossover Point is
invariant under generation. Thus, [1,2], [1,2,1,2], [1,2,1,2,1,2]
and [1,2,1,2,1,2,1,2] all have the same Crossover Point. Think
about it. If [1,2] is a loop cycle, then [1,2,1,2] represents two
cycles of the loop, [1,2,1,2,1,2] represents 3 cycles of the loop,
etc. and the cycle keeps returning to the same number.
Also, if a Sequence Vector is a loop cycle, every cyclic permutaion
of the Sequence Vector is also a loop cycle. The Crossover Points
of all those loop cycles are then the odd numbers of the loop cycle.
For example, if [1,2,3,4,5,6,7,8] is a loop cycle, then there are
8 cyclic permutations, whose Crossover Points describe the loop
cycle
[1,2,3,4,5,6,7,8]
[2,3,4,5,6,7,8,1]
[3,4,5,6,7,8,1,2]
[4,5,6,7,8,1,2,3]
[5,6,7,8,1,2,3,4]
[6,7,8,1,2,3,4,5]
[7,8,1,2,3,4,5,6]
[8,1,2,3,4,5,6,7]
Sequence length: 8, cyclic permutions: 8
Now a loop cycle that doesn't have as many cyclic permutations
as elements must be an nth generation of some smaller Type
Sequence Vector. Thus, the Sequnce Vector [1,2,1.2,1,2,1,2]
has only 2 cyclic permutations
[1,2,1,2,1,2,1,2]
[2,1,2,1,2,1,2,1]
because it's a 4th generation Type [1,2] and need not be
considered as a length 8 loop cycle.