note gjb <p>NP-completeness is a property of an algorithm. It implies that no algorithm is known to solve the problem in polynomial time.<br/> This means that if you increase the length of the input for the problem, the execution time will increase exponentially. (Of course there are input cases which are polynomial, but many of interest are not). Essentially, it means that brute force is the only known method to tackle the problem exactly.</p> <p>The question is on the relation between the behavior of an algorithm to decide on a language and the class to which this language belongs. For regular languages and context free languages polynomial time algorithms are known, but does this necessarily mean that since regular expressions with backreferences are proven to be NP-complete that the language they describe are a superset of regular and context free languages?</p> <p>It certainly means it is hard to decide whether or not a certain string is an element of the language described by a regular expression with backreferences. But what does it tell us about the expressive power?</p> <p>The expression <code>/^(.*)\1\$/</code> defines the language <code>{ww | w in sigma*}</code>, known neither to be regular, nor context free. On the other hand, regular expressions with backreference <em>can't</em> describe <code>{a^n b^n | n >= 0}</code> which is definitely context free.</p> <p>So on the one hand, regular expressions with backreference describe languages that are not context free, but can't describe all context free languages either! This example illustrates that one has to be very careful when judging expressive power from algorithmic complexity. A high complexity is a sign that the expressive power must be high in some cases, but doesn't guarantee that everything can be done.</p> <p>Incidently, the code below shows two Perl regular expressions that describe non-regular languages: <code> { a^n b^n | n >= 0} /^ (a*) (??{sprintf("b{%d}", (length(\$1)))}) \$/x </code> which is context free as mentioned above and <code> { a^n b^n c^n | n >= 0 } /^ (a*) (??{sprintf("b{%d}", (length(\$1)))}) (??{sprintf("c{%d}", (length(\$1)))}) \$/x </code> which is context sensitive.</p> <p>Just my 2 cents, -gjb-</p> 224537 224853