First time here? Check out the FAQ!

Ask Your Question
0

Using piecewise-defined functions for recursive integer sequence

asked 5 years ago

geroyx gravatar image

I have

image description

with div --> // ("integer part" of division).

I wonder how to use piecewise-defined functions for calculating n(i) and Q(i).
This does not work:

r = 1
m = 7
n(i) = piecewise([([0,0], r//m), ((0,oo), 10*(n(i-1)-Q(i-1)*m))])
Q(i) = piecewise([([0,0], 0), ((1,oo), n(i)//m)])

print n(0)
print n(1)
print n(5)

image description

Preview: (hide)

1 Answer

Sort by » oldest newest most voted
1

answered 5 years ago

Jingenbl gravatar image

r = 10

m = 2

def fonction_n(k):

if k == 0:

    return r//m

return 10 * (fonction_n(k-1) -  fonction_q(k-1) * m)

def fonction_q(k):

if k == 0:

    return 0

return fonction_n(k)//m

It is possible to derecursify this functions

happy new year

Preview: (hide)
link

Comments

With def ....: if... it is clear. I ask myself: Is there a way with piecewise.

geroyx gravatar imagegeroyx ( 5 years ago )

it is not a sagemath problem but an interesting mathematical question, right?

I write two or three equations, just to see if the answer is within pen's reach

Jingenbl gravatar imageJingenbl ( 5 years ago )

define F(x)=10(x%n)

so n(k)=F(F(F....(F(r//m)...) with k iterations.

What do you mean by a piecewise function , when the function is defined for three variables k, r and m ?

happy new year

Jingenbl gravatar imageJingenbl ( 5 years ago )

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: 5 years ago

Seen: 548 times

Last updated: Dec 31 '19