Loading [MathJax]/jax/output/HTML-CSS/jax.js
Ask Your Question
0

ternary recurrence sequence

asked 1 year ago

brennan gravatar image

updated 1 year ago

Max Alekseyev gravatar image

Is there a built in general recurrence sequence function like the binary recurrence sequence?

def a(n):
    return BinaryRecurrenceSequence(a,b,c,d)

returns the sequence U0=c, U1=d, and Un=aUn1+bUn2.

I would like something that returns Un=aUn1+bUn2+cUn3

Any help is much appreciated!

Preview: (hide)

1 Answer

Sort by » oldest newest most voted
0

answered 1 year ago

Max Alekseyev gravatar image

updated 1 year ago

If you need to compute Un efficiently - here is a way:

a=1
b=2
c=3
u0=u1=u2=1     # initial values
x = polygen(QQ)
C = companion_matrix(x^3-a*x^2-b*x-c)

def U(n):
    return (vector([u0,u1,u2]) * C^n)[0]

Alternatively you can use LFSR as described at https://doc.sagemath.org/html/en/refe...

Preview: (hide)
link

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 1 year ago

Seen: 155 times

Last updated: Mar 19 '24