Implement Automaton __iter__ for enumerating accepted language?
See original GitHub issue@eliotwrobson So with all the recent discussion around automata ultimately being representations of finite languages, it got me thinking:
What if we implemented an __iter__
method that produced each string in that automaton’s accepted language? My thought it we could generate one string at a time via yield
, and leave it up to the user if they want to convert the automaton to a list
or set
. Ideally, we could start with DFAs/NFAs, and then explore if a similar algorithm is possible with PDAs and TMs.
How difficult do you think this would be to implement from an algorithmic perspective? Initially, my thought is generating all permutations of the machine’s input symbols, then filter that set down to only those accepted via accepts_input
.
Although the number of iterations could be enormous, so maybe we could filter that set further by analyzing transition symbols from the initial state (first character) and final states (possible last characters). But I’m curious if there is an approach that isn’t so brute-force.
Issue Analytics
- State:
- Created a year ago
- Comments:15 (15 by maintainers)
Top GitHub Comments
@eliotwrobson @Tagl But it will be important that
__contains__
makes a direct call toaccepts_input
rather than enumerating the iterator of words in the accepted language (because the latter could be substantially slower).Yes, converting to doing it iteratively is no problem at all since the transitions if the DP are simple. It was one of the optimizations I had in mind.