简体   繁体   English

将DFA排除为正则表达式

[英]State Elimination DFA to Regular Expression

I have a few questions regarding state elimination and the terminology. 关于状态消除和术语,我有几个问题。

在此处输入图片说明

In the example above is a DFA with a accepting state where you must start with symbol 0 and end with 1. 在上面的示例中,DFA处于接受状态,您必须以符号0开头并以1结尾。

If I were to convert it to regular expression, the upper would be 如果我将其转换为正则表达式,则上限为 在此处输入图片说明

and the bottom would be 而底部将是 在此处输入图片说明

Here is my problem, I have no idea how to add the top part and the bottom part into on single expression. 这是我的问题,我不知道如何在单个表达式上添加顶部和底部。 I am also not totally sure how to eliminate q2 symbol 1 further. 我也不完全确定如何进一步消除q2符号1。

Would it be 0(0*(0+1))1* ? 会是0(0 *(0 + 1))1 *吗?

Thank you to anyone who could help! 感谢任何可以帮助您的人!

There is a much more well known and comprehensible algorithm available to accomplish this task. 有一种更广为人知且可理解的算法可以完成此任务。

To convert a DFA G into a Regular expression we first convert G into a 'GNFA'. 要将DFA G转换为正则表达式,我们首先将G转换为“ GNFA”。 Let for example G be the following DFA (q is the start state): 假设G是以下DFA(q是开始状态):

在此处输入图片说明

The process of converting a DFA to a GNFA is as follows: 将DFA转换为GNFA的过程如下:

  1. Add new start state with an epsilon transition to the original start state. 将带有epsilon过渡的新启动状态添加到原始启动状态。
  2. Add new accept state, add epsilon transitions from every original accept state to the newly added accept state, then make all the original accept states into normal states. 添加新的接受状态,添加从每个原始接受状态到新添加的接受状态的epsilon转换,然后使所有原始接受状态变为正常状态。

This is the resulting GNFA: 这是生成的GNFA:

在此处输入图片说明

Then we remove each state in-between the new start state and the new accept state one at a time, adjusting the graph to maintain correctness. 然后,我们一次删除介于新的开始状态和新的接受状态之间的每个状态,并调整图表以保持正确性。 The process works as follows: Let x, y, and z be states in our DFA. 该过程的工作方式如下:令x,y和z为DFA中的状态。 Additionally, the transitions are as follows x->y on input a, y->y on input b and y->z on input c. 另外,转换如下:输入a上的x-> y,输入b上的y-> y和输入c上的y-> z。 Say we want to remove y. 假设我们要删除y。 For every transition from some node n to y and for every transition from y to m, we must add a new transition n->m. 对于从某个节点n到y的每个过渡以及从y到m的每个过渡,我们必须添加一个新的过渡n-> m。 The transition from n to m would be the content of the transition from n to y, followed by the content of transition y->y with a kleene star followed by the content of the transition from y->m. 从n到m的过渡将是从n到y的过渡的内容,然后是带有kleene星的过渡y-> y的内容,然后是从y-> m的过渡的内容。 In this case x->y on a, y->y on b and y->z on c, after removing state y, there would be a transition from x->z on a(b*)c . 在这种情况下,a上的x-> y,b上的y-> y和c上的y-> z,在删除状态y之后, a(b*)ca(b*)c x-> z会发生转变。


Consider our DFA in the images. 在图像中考虑我们的DFA。 After removing state q we get: 删除状态q后,我们得到: 在此处输入图片说明

After removing state r, we get: 删除状态r后,我们得到: 在此处输入图片说明

Finally, after removing state s we are left with: 最后,在删除状态s之后,我们得到: 在此处输入图片说明

This is our complete regular expression. 这是我们完整的正则表达式。 Using this process completely avoids any of the problems you are facing. 使用此过程可以完全避免您面临的任何问题。 However, I will also provide you with a direct answer to your question. 但是,我也会为您提供直接答案。 For starters, the upper part would not be what you suggested. 对于初学者来说,上面的部分不是您建议的。 Instead, it would become: 相反,它将变为: 在此处输入图片说明 This simplifies into: 简化为: 在此处输入图片说明 This is our final regex, since the bottom part has no accept state and is thus irrelevant. 这是我们最终的正则表达式,因为底部没有接受状态,因此无关紧要。

you start from (q0) state if u input (0) then you can reach to the final ; 您从(q0)状态开始,如果u输入(0),则可以到达最终状态; instead if u input (1) you couldnt reach final . 相反,如果u输入(1),则无法到达final。 so consider only states (q0) (q1) (q2) and apply elimination rule on these states 因此,仅考虑状态(q0)(q1)(q2),并对这些状态应用消除规则

after elimination RE would be as follow 消除后,RE将如下

0(0)*1 . (1+0(0)*1)*

start from 0 and ending on 1 从0开始到1结束

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM