Automaton.language() does not pass **kwargs to FSMProcessIterator

59 views
Skip to first unread message

Lucca Jimenez-Könings

unread,
Nov 23, 2022, 10:59:57 AM11/23/22
to sage-devel
import itertools
stateTransitions = [
    ('q0', 'q1', '0'),
    ('q1', 'q1', '0'),
    ('q1', 'q2', '1'),
    ('q2', 'q3', '0'),
   
]
DFA = Automaton(stateTransitions, initial_states=['q0'], final_states=['q3'])
list(islice(DFA.language(initial_states=['q1']), None, 10))


I am trying to determine outputs for an automaton from each of its states. For that I want to use its language method(link), as it returns all words that are accepted by the automaton.

The documentation states that:

kwargs – will be passed on to the process iterator. See process() for a description. 

process() 
 takes, among others, an initial_state as one of its named arguments. Again, in it's documentation(link):

  • initial_state or initial_states – the initial state(s) in which the machine starts. Either specify a single one with initial_state or a list of them with initial_states. If both are given, initial_state will be appended to initial_states. If neither is specified, the initial states of the finite state machine are taken.



So if I understand correctly, by passing initial_state='q1' to the DFA.language() method, like in the code above, the automaton should output words, beginning from state 'q1', ignoring the previously set initial state 'q0' from its initializer.

This doesn't work however. The above code will always yield output beginning at 'q0'.
I did a bit of investigation and I think the reason for this is, that **kwargs from Automaton.language() is not passed correctly to the FSMProcessIterator, as it's mentioned in the docs. I am not good enough with the sage codebase or python to debug this however.

Did I do something wrong? If not, it'd be very kind if someone could confirm the issue.

Lucca Jimenez-Könings

unread,
Nov 24, 2022, 3:41:45 PM11/24/22
to sage-devel
I can also trigger an exception with a different automaton defintion:
stateTransitions = {'q0':[('q1', '0')],'q1':[('q1', '1')]}
DFA = Automaton(stateTransitions)
DFA.state('q1').is_final=True
list(DFA.process(['1'],initial_state='q1'))


a.png
It's slightly hard to read, but the automaton has two states, q0 and q1, where q1 is the accepting state.
The transitions are:
q0 -> q1 : 0
q1 -> q1 : 1

The second transition is not in the graph above.

When running the above code, the following trace is thrown:
AttributeError: 'str' object has no attribute '_in_epsilon_cycle_' 

The datatype doesn't seem to make a difference, wether it's str or not.

dmo...@deductivepress.ca

unread,
Nov 30, 2022, 12:16:02 AM11/30/22
to sage-devel
Thanks for the bug report. I think you are right that the keyword arguments are being ignored, so I opened trac ticket #34810.  Further discussion should be posted there.

However, your second problem is not a bug.  The initial state needs to be a state, not a string, so it should work if you change ''q1" to DFA.state("q1") in the final line.  Perhaps we should clarify the documentation (or allow the parameter to be a string).
Reply all
Reply to author
Forward
0 new messages