VeriFIT / mata

A fast and simple automata library
MIT License
14 stars 11 forks source link

Lazy evaluation of operations to get some accepted word #415

Open jurajsic opened 1 week ago

jurajsic commented 1 week ago

For Z3-Noodler, I need to get a word from application of operations on automata while not constructing the resulting automaton (as it can blow-up). More specifically I need:

The first problem could be solved by doing determinization and stopping when some macrostate does not contain any final state. The second is harder, I do not know how to do it.

vhavlena commented 1 week ago

The second one is language difference, no? It should be similar to the first case, the only difference is that a macrostate looks like (q,S) not just S.

jurajsic commented 1 week ago

Yes, it's language difference. And yes, the macrostate would be (q,S), but I think implementation-wise it will be harder (for the first case, we can just reuse the determinization implementation).

Adda0 commented 4 days ago

For the implementation of get_word_from_complement(Nfa nfa_to_complement), we could modify the existing determinization algorithm. We could add an optional callback function, similarly to how we handle callback functions in Tarjan's algorithm, for example, where the callback would be an event handler for encountering a new macrostate. If the callback is defined and returns true, the determinization continues, otherwise the determinization stops. In this case, the callback would check the final states in the macrostate and return false if there is none (the macrostate is a final state in the complement). The determinization then returns the DFA created so far.

For the language difference, this callback could be maybe utilized, too. However, you would have to take into account the transition symbols leading to this macrostate. Or possibly the outgoing transition symbols.

Does this sound reasonable?

vhavlena commented 4 days ago

It could work. It is quite useful to add the language difference operation and then this kind of callback extension should be easy.

Adda0 commented 2 days ago

I have implemented nfa::Nfa::get_word_from_complement(). The PR will be created once the PRs the implementation depends on get merged.