Conversion from DFA to NFA does not properly handle state names of mixed data types
See original GitHub issueI found the following bug: nfa._add_new_state introduces integers into the set of states.
Current code is:
def _add_new_state(state_set, start=0):
"""Adds new state to the state set and returns it"""
new_state = start
while new_state in state_set:
new_state += 1
state_set.add(new_state)
return new_state
which could be fixed, for example, in this way:
def _add_new_state(state_set, start=0):
"""Adds new state to the state set and returns it"""
new_state = start
while str(new_state) in state_set:
new_state += 1
state_set.add(str(new_state))
return str(new_state)
EDIT: this bugfix actually runs into other problems later - this is just an idea
This can lead to logic problems later. For example the following code fails:
from automata.fa.dfa import DFA
from automata.fa.nfa import NFA
A = NFA(
states={'0', '1'},
input_symbols={'0'},
transitions={'0': {'0': {'1'}}, '1': {'0': {'1'}}},
initial_state='0',
final_states={'1'}
)
print(A.reverse().states)
B = DFA.from_nfa(A.reverse())
assert(A.accepts_input('00')==B.accepts_input('00'))
Issue Analytics
- State:
- Created a year ago
- Comments:10 (10 by maintainers)
Top Results From Across the Web
Issues · caleb531/automata - GitHub
Issues list ; Regex parsing efficiency enhancement. #61 opened ; Conversion from DFA to NFA does not properly handle state names of mixed...
Read more >Can every DFA be converted into an NFA? - Quora
The simple answer is Yes. Every DFA is an NFA i.e every DFA can be converted into NFA but not vice versa. But...
Read more >Converting Non-Deterministic Finite Automata to ... - YouTube
By adding ambiguities to a finite automaton based on a regular expression, we show how to convert a non -deterministic finite automaton (...
Read more >"Simple" Conversions (DFA to NFA to PDA, RG to CFG)
Here we cover all of the "simple" conversions commonly taught in the theory of computation class: deterministic finite automaton ( DFA ) to ......
Read more >Efficient algorithm for converting a character set into a nfa/dfa
If I use large character sets, like the any operator '.' or the unicode property {L}, the nfa (and also the dfa) contains...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@caleb531 It looks like the test you wrote checks for the fact that the
_add_new_state
now has better support for integer string state names, but there are still issues when manually constructing an NFA.The following (somewhat contrived) assertion fails:
@colette-b Good news! I was actually able to refactor
_add_new_state
to correctly handle non-string states, thus fixing your original example. All other automated tests are passing too, so there should be no regressions from this refactor.In case you’re curious, here is the new implementation: