2

I need a function that, given 2 patterns, determines if the first pattern is more general than the second (i.e. that any expression successfully matched by the second, will be successfully matched by the first as well). I suppose this problem is undecidable in general, so I am okay with the function returning false negatives in some cases, but it should never return false positives (i.e. should not declare a pattern more general when this is not actually the case).

Now, the problem as I stated it admits a trivial solution that always returns False. Of course, I am looking for something more practical, at least as smart as the one implemented in Mathematica itself and mentioned in the help topic The Ordering of Definitions:

When you make a sequence of definitions in Mathematica, some may be more general than others. Mathematica follows the principle of trying to put more general definitions after more specific ones. This means that special cases of rules are typically tried before more general cases.


Although in many practical cases, Mathematica can recognize when one rule is more general than another, you should realize that this is not always possible. For example, if two rules both contain complicated conditions, it may not be possible to work out which is more general, and, in fact, there may not be a definite ordering. Whenever the appropriate ordering is not clear, Mathematica stores rules in the order you give them.

Or, if it's possible, I would rather invoke the built-in algorithm for recognizing more general patterns mentioned in this help topic.

Լ.Ƭ.
  • 333
  • 2
  • 5

0 Answers0