# The period() method for BinaryRecurrenceSequence not functioning when the period mod m is non-simple

BinaryRecurrenceSequence is not throwing an error when there is not a simple period.

For instance, the sequence given by S = BinaryRecurrenceSequence(3,2,u0=0,u1=1) considered mod 4 has terms when considered individually: 0, 1, 3, 3, 3, ..... It does (eventually) have a period, it's just not a simple one.

When, however I try S.period(4), sagemath just stops working without throwing an error and I have to kill the kernel. Is there a method to test whether there are non-simple periods, or which otherwise picks up on sequences like this?

Often I run scripts over multiple sequences with different values for the coefficients, so it's not a case of being able to test each sequence in turn whether there will be an issue.

edit retag close merge delete

Sort by ยป oldest newest most voted

This is definitely a bug, which I reported at https://github.com/sagemath/sage/issu...

Meanwhile you can use a custom (not efficient though) period computing function such as

def myperiod(S,mod):
T = dict()
k = 0
while True:
t = (S(k)%mod,S(k+1)%mod)
if t in T:
return k-T[t]
T[t] = k
k += 1

print( myperiod( BinaryRecurrenceSequence(3,2,u0=0,u1=1), 4 ) )
more

Thank you - that's helpful! And also for reporting it as a bug :)

( 2024-06-03 14:45:35 +0200 )edit