# We disable autosave for technical reasons.
# Replace 0 by 120 in next line to restore default.
%autosave 0
import awalipy # If import fails, check that
# Python version used as Jupyter
# kernel matches the one
# Awalipy was compiled with.
A Transducer is an automaton with multiple tapes. It is built from a list of alphabets.
T = awalipy.Transducer(["012","01"])
Adding states is the same as for automata
stt_0 = T.add_state()
stt_1 = T.add_state()
T.set_initial(stt_0)
T.set_final(stt_0)
Transitions of transducer bear multiple labels (in the example, two). The third argument of set_transition
is now a list of labels.
tr_0 = T.set_transition(stt_0,stt_0,['0','0'])
tr_1 = T.set_transition(stt_0,stt_0,['1','1'])
tr_2 = T.set_transition(stt_0,stt_1,['2','0'])
tr_3 = T.set_transition(stt_1,stt_0,['0','1'])
tr_4 = T.set_transition(stt_1,stt_1,['2','1'])
tr_5 = T.set_transition(stt_1,stt_1,['1','0'])
Displaying a Transducer is the same as for automata.
T.display(True)
T
NB: the mention "(i)" following a state means that the state is initial. Similarly, "(f)" means final and "(i,f)" means initial and final.
By default, transducers allow epsilon on any number of tapes.
stt_2 = T.add_state()
Adding an epsilon-transition, that is, with epsilon on all tapes.
tr_6 = T.set_eps_transition(stt_2,stt_1)
tr_7 = T.set_transition(stt_1,stt_2,["",""])
T.display()
Adding a transition with epsilon on only one tape.
tr_8 = T.set_transition(stt_2,stt_0,["0",""])
tr_9 = T.set_transition(stt_2,stt_2,["","1"])
T.display()
Let us consider the automaton A
T.display()
tr_10 = T.set_transition(stt_0,stt_2,["0","1"])
T.display()
Deleting the transition we just added by id.
T.del_transition(tr_10)
T.display()
Deleting a transition by triplet (origin, destination, label list)
T.del_transition(stt_2,stt_2,["","1"])
T.display()
Deleting all transitions from a state to another (order matters).
T.del_transition(stt_2,stt_1)
T.display()
Deleting a state (and all outgoing and incomings transitions)
T.del_state(stt_2)
T.display()
Saving an automaton to file. The format used is JavaScript Object Notation (JSON) hence the extension ".json" .
T.save("fibo_LR_additioner.json")
ls *json
Loading an automaton.
B = awalipy.load("fibo_LR_additioner.json")
B.display()
Listing the example automata given with the library. Some of them are transducers
awalipy.list_example_automata()
Loading an example automaton (given with the library): just use the name of the automaton given above, without extension.
L = awalipy.load("gray")
L.display()
s = awalipy.RatExp("0")
for i in range(20):
print (str(i) + " is represented as " + str(s))
s = L(s)
Accessing and browsing is essentially the same for transducers and automata.
T.display()
Getting the list of states, or transitions
(It cannot be assumed that the ids of states are [0,1,...,n] for some n )
T.states(), T.transitions()
Getting the list of initial states,of final states.
T.initial_states(), T.final_states()
List of transitions adjacent of a state
T.outgoing(stt_1), T.incoming(stt_1)
List of transitions from a state to another.
T.outin(stt_0,stt_1)
List of states reachable from a state in one transition.
T.successors(stt_0), T.successors(stt_0, ["1","0"])
List of states that may reach a state in one transition.
T.predecessors(stt_0), T.predecessors(stt_0, ["0","0"])