How to find the intersection of two NFA

和自甴很熟 提交于 2019-12-01 04:26:24

问题


In DFA we can do the intersection of two automata by doing the cross product of the states of the two automata and accepting those states that are accepting in both the initial automata. Union is performed similarly. How ever although i can do union in NFA easily using epsilon transition how do i do their intersection?


回答1:


You can use the cross-product construction on NFAs just as you would DFAs. The only changes are how you'd handle ε-transitions. Specifically, for each state (qi, rj) in the cross-product automaton, you add an ε-transition from that state to each pair of states (qk, rj) where there's an ε-transition in the first machine from qi to qk and to each pair of states (qi, rk) where there's an ε-transition in the second machine from rj to rk.

Alternatively, you can always convert the NFAs into DFAs and then compute the cross product of those DFAs.

Hope this helps!




回答2:


there is a huge mistake in the templatetypedef 's answer .

the product automaton of L1 and L2 which are NFAs :

new states Q = product of the states of L1 and L2 .

now the transition function :

a is a symbol in the union of both automatons alphabets

delta( (q_1,q_2) , a) = delta_L1(q_1 , a) X delta_L2(q_2 , a)

which means you should multiply the set that is the resualt of delta_L1(q_1 , a) with the set that results from delta_L2(q_1 , a).

the problem in the templatetypedef's answer is that the product result (qk ,rk) is not mentioned .




回答3:


We can also use De Morgan's Laws: A intersection B = (A' U B')'

Taking the union of the compliments of the two NFA's is comparatively simpler, especially if you are used to the epsilon method of union.




回答4:


Probabaly a late answer, but since I had the similair problem today I felt like sharing it. Realise the meaning of intersection first. Here, it means that given the string e, e should be accepted by both automata.

Consider the folowing automata:

  1. m1 accepting the language {w | w contains '11' as a substring}
  2. m2 accepting the language {w | w contains '00' as a substring}

Intiuitivly m = m1m2 is the automaton accepting the strings containing both '11' and '00' as a substring. The idea is to simulate both automata simultaneously.

Let's now formally define the intersection.

m = (Q, Σ, Δ, q0, F)

  • Let's start by defining the states for m this is, as mentioned above the carthesian product of the states in m1 and m2. So, if we have a1, a2 as labels for the states in m1, and b1, b2 the states in m2, Q will consist out of following states: a1b1, a2b1, a1b2, a2b2. The meaning behind this is to keep track of where where are in both m1 and m2.

  • Σ most likely remains the same, however in some cases they differ and we just take the union of alphabets in m1 and m2.

  • q0 is now the state in Q containing both the start state of m1 and the start state of m2. (a1b1, to give an example.)

  • F contains state s IF and only IF both states mentioned in s are accept states of m1, m2 respectively.

  • Last, but not least Δ; we define delta again in terms of the carthesian product, as follows: Δ(a1b1, E) = Δ(m1)(a1, E) x Δ(m2)(b1, E) as also mentoined in one of the answers above if I am not mistaken. The intuitive idea behind this is to just tear a1b1 apart, and consider the states a1 and b1 in their original automaton. Now we 'iterate' each possible edge, lets pick E for example, and see where it brings us in the original automata. After that we glue these results together using the carthesian product. If (a1, E) is present in m1, but not Δ(b1, E) in m2 the edge will not exist in m, otherwise we'll have some kind of a union construction.




回答5:


An alternative to constructing the product automaton is allowing more complicated acceptance criteria. Ordinarily, an NFA accepts an input string when it has reached any one of a set of accepting final states. That can be extended to boolean combinations of states. Specifically, you construct the automaton for the intersection like you do for the union, but consider the resulting automaton to accept an input string only when it is in (what corresponds to) accepting final states in both automata.



来源:https://stackoverflow.com/questions/21662041/how-to-find-the-intersection-of-two-nfa

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!