sage recursive functions programming

Anonymous

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.

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?

( 2013-01-11 02:18:32 +0100 )edit

This sounds like homework...

( 2013-01-11 02:58:21 +0100 )edit

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.

( 2013-01-14 18:23:46 +0100 )edit

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[0])
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.

( 2013-01-14 18:25:24 +0100 )edit