16

Note that this question is not a duplicate of that one. It is specifically about the pattern-matching engine, and explicitly excluding those patterns which call back into the full evaluation (i.e. PatternTest and Condition; if there are others like those, consider them excluded as well).

To state the problem more specifically: Given a problem with a yes/no answer which can be decided in finite time by an appropriate Turing machine, does there always exist a Mathematica pattern involving neither PatternTest nor Condition together with an appropriate encoding for the input data which matches iff the Turing machine would give "yes" for the input data?

To make more clear what I mean, I give an example of a problem solvable both with a Turing machine and with the pattern matcher:

Given a natural number, determine whether that number is even or odd. It is obvious that a Turing machine can solve this problem in finite time. Here's how pattern matching can solve that problem: Encode the natural number into a list of as many 1, so that 0 is {}, 1 is {1}, 2 is {1,1} etc. Then the pattern implementing the test is simply {PatternSequence[1,1]...}.

celtschk
  • 19,133
  • 1
  • 51
  • 106

1 Answers1

6

I cannot offer a rigorous answer to this question, but I will offer some thoughts...

This question asks whether the set of functions computable using basic patterns and MatchQ is isomorphic to the subset of Turing-computable functions whose results can be expressed in a single bit. The one-bit subset restriction is important since MatchQ is clearly not fully Turing-complete since it cannot handle functions outside of that subset.

Basic pattern-matching would seem to be a very close approximation of boolean circuits. With suitable input encoding, we can implement the basic operations thus:

    a OR b    -->    a | b
    NOT a     -->    Except[a]
    a AND b   -->    Except[Except[a], b]

For bounded input sizes, boolean circuits are known to be able to compute any boolean function (see, for example, Theorem 1.8.1 on page 32 of Clote and Kranakis: Boolean Functions and Computation Models). The emphasis here is on bounded. Boolean circuits are known not to be Turing-equivalent due to non-uniformity. That is, a fixed-size Turing program can handle any input size while a boolean circuit must grow (exponentially!) in size as input size increases.

What is not clear to me is whether the other pattern-matching features add capability that will let us will evade this conclusion. Perhaps some creative use of BlankSequence, Repeated, Longest, Shortest, PatternSequence, etc. takes us outside of the realm of boolean circuits and toward (one bit) Turing-equivalence.

WReach
  • 68,832
  • 4
  • 164
  • 269
  • Interesting. I think a AND b is not quite right though. Maybe should be Except[Except[a] | Except[b]] ? Regardless, once you have Or and Not, you have the full set of possibilities. – Daniel Lichtblau Sep 03 '12 at 19:55
  • @DanielLichtblau That is an alternate representation of AND. I chose the shorter one that exploits the second argument to Except. – WReach Sep 03 '12 at 20:12