有没有办法否定一个普通的前pression? [英] Is there a way to negate a regular expression?

查看:123
本文介绍了有没有办法否定一个普通的前pression?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于常规EX pression的研究的,描述了一个普通的语言(没有华丽的反向引用)。是否有一个算法的方式来构造一个常规的前pression的 R * 的描述的所有文字语言的除外的研究的说明?它应该是尽可能维基的表示:

Given a regular expression R that describes a regular language (no fancy backreferences). Is there an algorithmic way to construct a regular expression R* that describes the language of all words except those described by R? It should be possible as Wikipedia says:

常规语言的各种操作下关闭,即,如果该语言的 K 的和的大号的是常规的,所以是下列运算的结果:[...补体的¬L

The regular languages are closed under the various operations, that is, if the languages K and L are regular, so is the result of the following operations: […] the complement ¬L

例如,给定字母表的 {A,B,C} 的,语言的(ABC *)+ 的的倒数的(A |(AC | B | C)*)

For example, given the alphabet {a,b,c}, the inverse of the language (abc*)+ is (a|(ac|b|c).*)?

正如DPenner已经指出的意见,有规律的前presion的逆可以成倍比原来的前pression大。这使得反演经常EX pressions不宜实行负部分EX pression语法搜索的目的。是否有一个算法,preserves中的 O(N * M)的运行特征(其中的 N 的是正则表达式的大小和 M 的是输入的常规前pression匹配的长度),并允许否定SUBEX pressions?

As DPenner has already pointed out in the comments, the inverse of a regular expresion can be exponentially larger than the original expression. This makes inversing regular expressions unsuitable to implement negative partial expression syntax for searching purposes. Is there an algorithm that preserves the O(n*m) runtime characteristic (where n is the size of the regex and m is the length of the input) of regular expression matching and allows for negated subexpressions?

推荐答案

不幸的是,nhahdtdh在评论中给出的答案是一样好,我们可以做(到目前为止)。无论是给定的正前pression产生的所有字符串是PSPACE完全的。由于NP的所有问题都在PSPACE完全的,有效的解决方案来的普遍性问题,将意味着P = NP。

Unfortunately, the answer given by nhahdtdh in the comments is as good as we can do (so far). Whether a given regular expression generates all strings is PSPACE-complete. Since all problems in NP are in PSPACE-complete, an efficient solution to the universality problem would imply that P=NP.

如果有一个有效的解决问题的方法,你会能够解决的普遍性问题?当然你会的。

If there were an efficient solution to your problem, would you be able to resolve the universality problem? Sure you would.

  1. 使用您有效的算法来产生一个有规律的前pression的否定;
  2. 确定是否将导致经常EX pression产生空集。

请注意,这个问题给予定期EX pression,它产生的空集是非常简单的:

Note that the problem "given a regular expression, does it generate the empty set" is fairly straightforward:

  1. 在常规的前pression {} 生成空集。
  2. (R + S)生成空集IFF两个研究取值生成空集。
  3. (RS)生成空集IFF无论是研究取值生成空集。
  4. 闲来无事产生空集。
  1. The regular expression {} generates the empty set.
  2. (r + s) generates the empty set iff both r and s generate the empty set.
  3. (rs) generates the empty set iff either r or s generates the empty set.
  4. Nothing else generates the empty set.

基本上,它是pretty的容易分辨是否正规EX pression产生空集:刚开始评估正规EX pression

Basically, it's pretty easy to tell whether a regular expression generates the empty set: just start evaluating the regular expression.

(注意,虽然上面的程序是有效的,在输出长度方面,它可能不是有效的输入长度方面,如果输出长度大于多项式比输入长度更快。然而,如果这是的情况下,我们有同样的结果,无论如何,也就是说,你的算法是不是真的有效,因为它会采取指数许多措施来从给定的输入输出指数更长)。

(Note that while the above procedure is efficient in terms of the output length, it might not be efficient in terms of the input length, if the output length is more than polynomially faster than the input length. However, if that were the case, we'd have the same result anyway, i.e., that your algorithm isn't really efficient, since it would take exponentially many steps to generate an exponentially longer output from a given input).

这篇关于有没有办法否定一个普通的前pression?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆