0

In other words, is it possible to create a PCRE "regular" expression which takes Ackermann(m,m) time for an m length string?

chx
  • 373

1 Answers1

2

First, we have to assume a particular PCRE implementation to make "time taken" a well-defined function. We also need to demand that this implementation is "sane", e.g., doesn't deliberately take much longer than necessary (say, exactly Ackermann(m, m) steps).

Then, note that even the most naive backtracking takes exponential time in the length of the string. The Ackermann function grows faster than any exponential function, and exponential functions are primitive recursive.

However, this only establishes that there isn't a regular expression taking Ackermann(m, m) time. It's conceivable that the exact time taken by one particular PCRE implementation happens to be weird enough to not be primitive recursive even though it's bounded above by an exponential. After all, functions don't need to grow very fast to be non-(primitive-)recursive. As an example, consider f(n) = the number of halting programs that can be written down with n bits (which is not even recursive, but bounded above by 2^n).

However, this is not a particular interesting question since

  1. I suspect it's not actually the case
  2. It probably depends on encoding details
  3. It probably doesn't tell you anything about the computation, just about the particular PCRE implementation

The more sensible question is whether there is some primitive recursive function for each regex. This isn't very sensitive to encoding details since it's usually easy to translate from one sensible encoding to another. So I suspect the answer is yes, though I have no proof.