Allow DFA transition function to be partial
See original GitHub issueWhen I studied Automata Theory (and in the literature), the transition function for a DFA could be partial, this is, that there could be some states which do not have an associated transition for a symbol in the alphabet. In my particular case, I was trying to get this automata:
But, as I said, some states do not have an associated transition for a symbol (take for example state b). This, in principle, accomplishes the DFA restrictions since there is no state such that for a symbol in the alphabet there is more than one associated transition. When trying to obtain the above DFA using the transition function:
{
'': {'a': 'a', 'b': 'b'},
'a': {'b': 'ab', 'a': 'aa'},
'b': {'b': 'bb'},
'aa': {'a': 'aa', 'b': 'ab'},
'bb': {'a': 'ba'},
'ab': {'b': 'bb'},
'ba': {'a': 'aa'}
}
I get an exception:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/guillermh/.local/lib/python3.9/site-packages/automata/fa/dfa.py", line 23, in __init__
self.validate()
File "/home/guillermh/.local/lib/python3.9/site-packages/automata/fa/dfa.py", line 67, in validate
self._validate_transitions(start_state, paths)
File "/home/guillermh/.local/lib/python3.9/site-packages/automata/fa/dfa.py", line 59, in _validate_transitions
self._validate_transition_missing_symbols(start_state, paths)
File "/home/guillermh/.local/lib/python3.9/site-packages/automata/fa/dfa.py", line 29, in _validate_transition_missing_symbols
raise exceptions.MissingSymbolError(
automata.base.exceptions.MissingSymbolError: state b is missing transitions for symbol a
I think there is a method _validate_transition_missing_symbols
in automata.fa.dfa
which is the culprit of this thing.
I would make a pull request but right now I haven’t got the time to learn how to implement and run tests and testing code coverage (I’m pretty novice in contributing tasks).
But I opened this issue in order to notify about the possible misconception about the formalities of DFA.
Thank you beforehand!
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (3 by maintainers)
Top GitHub Comments
@alkkem Alright, I’ve released Automata v5 with the
allow_partial
parameter! Hope you enjoy, and let me know if you run into any issues:https://github.com/caleb531/automata/releases/tag/v5.0.0
@caleb531 Hehe, you have cited the same page that I found when I was trying to figure out what the problem was.
Thank you for taking this in consideration 😄