Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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:open
  • Created a year ago
  • Comments:15 (15 by maintainers)

github_iconTop GitHub Comments

caleb531commented, Oct 24, 2022

@eliotwrobson @Tagl But it will be important that __contains__ makes a direct call to accepts_input rather than enumerating the iterator of words in the accepted language (because the latter could be substantially slower).

Taglcommented, Oct 24, 2022

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Enumeration and generation with a string automata ...
Section 5 briefly describes the implementation of a generator and methods for parallelizing the counting of regular languages. Using a table of pre-calculated ......
Read more >
WojciechMula/pyahocorasick: Python module (C ... - GitHub
Python module (C extension and plain python) implementing Aho-Corasick algorithm ... The Automaton.iter() method return the results as two-tuples of the end ...
Read more >
Enumerating regular expressions and their languages Contents
We would like to enumerate both (i) valid regular expressions and (ii) the distinct languages they represent. Observe that these are two different...
Read more >
Aspects of Enumeration and Generation with a String Automata ...
In Section 4, we briefly describe the implementation of ... of distinct languages accepted by finite automata with n states over an alphabet...
Read more >
Automata THeory - CMU School of Computer Science
F Q is the set of accept states. A finite automaton is a 5-tuple M = (Q, Σ, , q0, F). L(M) =...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Post

No results found

github_iconTop Related Hashnode Post

No results found