Ask Your Question

Using piecewise-defined functions for recursive integer sequence

asked 2019-12-30 16:46:55 +0200

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

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2019-12-31 09:49:06 +0200

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

edit flag offensive delete link more


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

geroyx gravatar imagegeroyx ( 2019-12-31 14:46:09 +0200 )edit

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 ( 2020-01-01 09:48:08 +0200 )edit

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 ( 2020-01-01 10:20:30 +0200 )edit

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


Asked: 2019-12-30 16:46:55 +0200

Seen: 460 times

Last updated: Dec 31 '19