sage recursive functions programming Anonymous

Hi everyone, can anybody please help me with this please? I am still relatively new to sage programming.

I have two states here a and b, and function f to compute binary strings.

If f is at state a, then f(1) = 0, also return to state a, while f(0)=1, but goes to next state b.

b is the identity state, when f is at b, b(0)=0, and stays at state b, while b(1)=1, but goes back to state a.

for example: suppose start from state a, then we have f(100) = a(100) = 0a(00) = 01b(0) = 010 similarly, suppose we start from state b, then we have f(100) = b(100) = 1a(00) = 11b(0) = 110

Therefore, any binary strings can be calculated by the function and output another binary strings.

Can anybody please help me on how to program this in sage please? Thanks a lot.

edit retag close merge delete

This is not really a sage specific thing. This is simply implementing a recursive mathematical definition into a python program/function. So, are you asking whether Sage has some library or class which works with states?

Hi, thanks for reply. It is not homework, but part of research program, trying to program automatons, which is self-similar groups. I basically really weak with programming, but need to try to test some group structures.

Sort by » oldest newest most voted

Hi, I have used a Boolean to distinguish the states: 'a'=True and 'b'=False.

@cached_function def recur(string,initial_state):

if string=='': return ''
else:
start=eval(string)
return str((initial_state+start)%2)+recur(string[1:],start)

more

I will try a little bit with this, thanks heaps. If I still cannot make it work, I may try to ask you again, thanks a lot.