简体   繁体   English

“ {a,b}上的字符串的偶数奇数语言”的正则表达式

[英]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

  1. Regular Expression For Even no of b's (a*a*a*bb)* b的Regular Expression (a*a*a*bb)*

  2. 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吗?

  • How to merge above two Regular Expressions into one if both are correct?? 如果两个正则表达式都正确,如何将两个正则表达式合并为一个?
  • How to Convert 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.

相关问题 带有偶数个 b 后跟字母 c 后跟奇数个 a 的字符串的正则表达式 - Regular Expression for Strings with even number of b's followed by the letter c followed by an odd number of a's 查找包含字母{a,b}上的子字符串aba的字符串的正则表达式? (形式语言理论) - find a regular expression for strings containing the substring aba over the alphabet {a, b}? (formal language theory) 语言{ab}的正则表达式,包含奇数长度的字符串,并且必须至少包含一个'b' - Regular Expression of Language {a b} which contains string of Odd Length and must contain atleast one 'b' in it 包含a和偶数b的字符串的正则表达式 - Regular expression for strings that cointains a and an even number of b's 将奇数甚至正则表达式与常规语法相结合? - Combing odd and even regular expression to regular grammar? 查找包含偶数个a和偶数个b的所有a和b字符串的正则表达式? - Regular expression to find all strings of a's and b's that contain an even number of a's and an even number of b's? 使用正则表达式确定字符串是偶数还是奇数长度 - Determine if string is even or odd length with regular expression 正则表达式只匹配奇数或偶数 - Regular Expression to match only odd or even number 在E = {a,b}上找到该语言的正则表达式 - Find the regular expression for the language on E={a,b} 在{a,b}上未生成正则表达式是什么? - what is regular expression not generated over {a,b}?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM