简体   繁体   English

找到正则表达式 (a|b)*ab(a|b)* 的补码

[英]Finding the complement of a regular expression (a|b)*ab(a|b)*

There's a question on my exercise sheet to find the complement of r = (a|b)*ab(a|b)*我的练习单上有一个问题是求r = (a|b)*ab(a|b)*的补码

I've come up with a solution, but I'm not sure if it's correct.我想出了一个解决方案,但我不确定它是否正确。 Please help me to check, and correct my errors.请帮我检查,并纠正我的错误。

I'm assuming that a and b are the only allowed symbols.我假设ab是唯一允许的符号。

Your original expression matches any string that contains ab .您的原始表达式匹配任何包含ab字符串。 The complement is any string that does not contain ab .补码是任何不包含ab字符串。 In other words if there is an a the next character must be another a or the end of the string.换句话说,如果有一个a下一个字符必须是另一个a或字符串的结尾。 If a b occurs it must be before all a s.如果 a b出现,它必须在所有a s 之前。

So that gives the result:所以这给出了结果:

b*a*

I think your expression is equivalent to this.我认为你的表达相当于这个。

The given RE states the language having substring ab at least once The complement of the same would be ..language accepting no substring ab给定的 RE 声明至少一次具有子字符串 ab 的语言相同的补充将是 ..language 不接受子字符串 ab

Hence b*a* is the correct answer因此 b*a* 是正确答案

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

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