# Optional pattern behaves differently in version 8, 9, and 10+

We recently ran into an issue when testing Rubi on older versions. It boils down to this simple example which I didn't dare to simplify further as I cannot test it in versions < 10

Test[XXX[expr_, x_], n_Integer : Infinity, OptionsPattern[]] := True /;
Head[x] === Symbol && n > 0;
Test[___] := False;
XXX[blub, x] // Test


The important part is n in the pattern and it should say

• n is an integer
• n is optional an Infinity per default
• n must be greater zero

Above code gives False in versions 8 and 9, but True in version 10 and 11. I'm not looking for a workaround, but I'd like to understand why it returns False in the older versions.

Maybe someone who still has access can give me some insight.

• In M9 and earlier, the issue is that Infinity does not have the head Integer. I believe they relaxed the pattern matcher in M10 to allow such patterns. – Carl Woll Aug 18 at 8:20
• I also had this idea, but I was under the impression that the default parameter does not have to have the head from the pattern. E.g. f[x_Integer: "Error"] := x; f[] returns "Error" although it also has not the Integer head. – halirutan Aug 18 at 8:22
• @CarlWoll Ah, OK. Now I understand your comment. You mean in earlier versions the head of the default must match if there is a restriction on the pattern, right? – halirutan Aug 18 at 8:25
• Yes, that's right. – Carl Woll Aug 18 at 8:25
• @CarlWoll That is a completely reasonable explanation. If you post it as answer and someone with 8 or 9 can test it, I'm happy to accept it. – halirutan Aug 18 at 8:27

In M9 and earlier, the default value must match any pattern restrictions. In your example, the head of the default is not Integer, and so the default value could never be triggered. In either 10.2 or 10.3 the pattern matcher was relaxed so that the default value no longer needed to match pattern restrictions.
• @Leonid I remembered that one of these questions existed because it had appeared around the time I had sent feedback to WRI about subtle interactions between facilities with implicit pattern expansion (Flat, OneIdentity, Optional, etc.). Once I found the first question, the others were linked. – WReach Aug 18 at 18:19