Ask Your Question
0

sage recursive functions programming

asked 2013-01-10 13:23:15 -0500

anonymous user

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 flag offensive close merge delete

Comments

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?

ppurka gravatar imageppurka ( 2013-01-10 19:18:32 -0500 )edit

This sounds like homework...

benjaminfjones gravatar imagebenjaminfjones ( 2013-01-10 19:58:21 -0500 )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.

tsang gravatar imagetsang ( 2013-01-14 11:23:46 -0500 )edit

1 answer

Sort by ยป oldest newest most voted
0

answered 2013-01-11 10:08:57 -0500

Rolandb gravatar image

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)

Does this answer your question? Roland

edit flag offensive delete link more

Comments

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.

tsang gravatar imagetsang ( 2013-01-14 11:25:24 -0500 )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

Stats

Asked: 2013-01-10 13:23:15 -0500

Seen: 799 times

Last updated: Jan 11 '13