[英]Regular expression for "even odd language of strings over {a, b}
I want to make regular expression having even number of b's and odd number of a's also DFA AND NFA of it for this i made below DFA
我想为此做我在
DFA
以下制作的正则表达式,其中b的偶数和a的奇数也为DFA和NFA
I got these two Regular Expression
我得到了这两个
Regular Expression
Regular Expression
For Even no of b's (a*a*a*bb)*
b的
Regular Expression
(a*a*a*bb)*
Regular Expression
For Odd no of a's (ab*b*)(ab*b*a)*
Regular Expression
a的奇数(ab*b*)(ab*b*a)*
QUESTION: Did I make the right DFA ? 问题:我制定了正确的DFA吗?
DFA
into NFA
? DFA
转换成NFA
? Edits: I got DFA From Grijesh Chauhan
Answer still unable to make regular expression which will allow only even number of b's and odd nubmer of a's . 编辑:我从
Grijesh Chauhan
Answer那里获得了DFA, Grijesh Chauhan
仍然无法进行正则表达式,这将仅允许b的偶数和a的奇数个小数。 I also tried this Regular Expression 我也尝试过这个正则表达式
(a(bb)*(aa)*)*
Note: From above RE only those strings are generated which start from a but i want that RE which generate string of even number of b's and odd number of a's regardles of starting from a or b 注意:从RE上方仅生成从a开头的那些字符串,但我希望RE生成从a或b开头的偶数个b和奇数个a的字符串
The regexes are incorrect. 正则表达式不正确。 They should be
他们应该是
a*(ba*ba*)*
for an even number of b a*(ba*ba*)*
b的偶数 b*ab*(ab*ab*)*
for an odd number of a b*ab*(ab*ab*)*
表示a的奇数 There is a systematic way to perform a merge of these two, because every regular expression can be represented by a state machine and vice versa and there is definitely a way to merge state machines such that the resulting state machine accepts if either of the two state machines accept, but I cannot remember how this is done directly on regular expressions. 有一种执行这两种合并的系统方法,因为每个正则表达式都可以由状态机表示,反之亦然,并且肯定有一种合并状态机的方法,以使结果状态机接受两个状态中的任何一个机器接受,但我不记得如何直接在正则表达式上完成此操作。
Your DFA is incorrect. 您的DFA不正确。 One can see this because you have cycles of odd length.
可以看到这一点,因为您有奇数个周期。 Following those cycles changes the even/odd parity.
在这些周期之后,将更改偶数/奇数奇偶校验。 So I can start with "babb" which your DFA accepts, having odd number of b's and odd number of a's.
因此,我可以从DFA接受的“ babb”开始,它具有b的奇数和a的奇数。 q0->q1->q2 is a cycle of 3 a's so adding 3 a's when I am in one of those states does not change wether the automata accepts, so your automata accepts "aaababb" despite neither having an odd number of a's or an even number of b's.
q0-> q1-> q2是一个3 a的周期,因此当我处于这些状态之一时,加3 a不会改变自动机接受的程度,因此即使自动机也没有奇数个a或一个,您的自动机也接受“ aaababb” b的偶数。 (Also your machine fails for "bab", despite this having both odd number of a's and even number of b's)
(即使您的计算机同时具有奇数个a和偶数个b,但它的“ bab”故障)
Your DFA should at minimum keep track of the parity of the number of a's and b's. 您的DFA至少应跟踪a和b数量的奇偶性。 So you should start with 4 states.
因此,您应该从4种状态开始。 Q_{even,even},Q_{even,odd},Q_{odd,even} and Q_{odd,odd}.
Q_ {even,even},Q_ {even,odd},Q_ {odd,even}和Q_ {odd,odd}。 Having labeled the states in this way it should be straightforward to set up the transitions and selecting what should be the intial and accepting states.
以这种方式标记状态后,应该可以直接设置转换并选择初始状态和接受状态。
Your regular expressions also has some issues. 您的正则表达式也有一些问题。 I would note that
a*
means 0 or more a's, so a*a*
means 0 or more a's followed by 0 or more a's. 我会注意到
a*
表示0或多个a,因此a*a*
表示0或多个a,后跟0或多个a。 This means that a*a*
= a*
. 这意味着
a*a*
= a*
。 Other than that see Georg's answer. 除此之外,请参见乔治的答案。
Conventional definitions are such that every DFA is also a NFA. 常规定义是每个DFA也是NFA。 Converting can be a problem when going from NFA to DFA.
从NFA转换为DFA时,转换可能会成为问题。
See Need Regular Expression for Finite Automata: Even number of 1s and Even number of 0s for a discussion on what algebra can be done on regular expressions. 有关有限度自动机的需要正则表达式:1的偶数和0的偶数,请参见在正则表达式上可以完成的代数讨论。
use this DFA....may be help you....i made in paint so,not looking pretty... 使用这个DFA。...可能对您有帮助。...我用油漆做成,看起来不太漂亮...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.