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.
AllTrue[DeleteDuplicates[Flatten[toSort]], (Positive[#] && IntegerQ[#] &)]
is faster than usingUnion
. And if you need it sorted,Sort@DeleteDuplicates[Flatten[toSort]]
is faster thanUnion
, too, on the exampletoSort
. $\endgroup$