Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Using piecewise-defined functions for recursive integer sequence

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