# Pattern matcher behavior change in 11.3

When trying to switch from version 10.3 to 11.3 I noticed that some of my code do not work properly. After some investigation I found that the problem is with pattern matcher. Here is the example:

toSort = Subsets[Range[13]][[2 ;;]];
gaIndexSort[ind : {{__Integer?Positive} ..},
ord_String: "InvDeg[Lex]"] := "matched"

gaIndexSort[toSort, "Lex"]
(* not evaluated *)


Evaluation in 10.3 and 11.0 works as expected, however in 11.3 message "General::maxrec: Recursion limit exceeded; positive match might be missed." is issued and the function is not evaluated. Of course, I can change the pattern to, for example,

gaIndexSort1[ind : {_List ..}, ord_String: "InvDeg[Lex]"] :=
"matched1" /;
AllTrue[Union[Flatten[ind]], (Positive[#] && IntegerQ[#] &)];

gaIndexSort1[toSort, "Lex"]
(*"matched1"*)


Which works as expected. The questions, however, remains 1) is the change intentional and 2) how to effectively match large recursive pattern in most effective way.

• What do you mean by "recursive" pattern? I don't see any recursion, or am I missing something? As for the issue itself: Seems buggy to me, as removing the default value from the second parameter fixes the issue – Lukas Lang Jul 22 '19 at 11:27
• @LukasLang I just name it after message name General::maxrec: which claims that Mma thinks it is recursion somewhere. At least this message is not issued for, say, toSort = Subsets[Range[10]][[2 ;;]]; or smaller lists. – user18792 Jul 22 '19 at 11:55
• The change was intentional, to address crashes from deep recursion in pattern matching. As noted in post, one can address this using more specific patterns that give rise to less need for dynamic backtracking in the pattern matching code. – Daniel Lichtblau Jul 30 '19 at 16:21
• @DanielLichtblau Can your post this information as an answer? – user18792 Jul 31 '19 at 13:47
• Side note: AllTrue[DeleteDuplicates[Flatten[toSort]], (Positive[#] && IntegerQ[#] &)] is faster than using Union. And if you need it sorted, Sort@DeleteDuplicates[Flatten[toSort]] is faster than Union, too, on the example toSort. – Michael E2 Jul 31 '19 at 16:13