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.

  • 1
    $\begingroup$ 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. $\endgroup$
    – Carl Woll
    Aug 18, 2018 at 8:20
  • $\begingroup$ 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. $\endgroup$
    – halirutan
    Aug 18, 2018 at 8:22
  • $\begingroup$ @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? $\endgroup$
    – halirutan
    Aug 18, 2018 at 8:25
  • $\begingroup$ Yes, that's right. $\endgroup$
    – Carl Woll
    Aug 18, 2018 at 8:25
  • $\begingroup$ @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. $\endgroup$
    – halirutan
    Aug 18, 2018 at 8:27

1 Answer 1


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.

  • 2
    $\begingroup$ +1. The original behaviour and changes are discussed in (108636), (4937) and on SE in (6401255). $\endgroup$
    – WReach
    Aug 18, 2018 at 12:29
  • $\begingroup$ @WReach I wonder how you found all these references. I certainly wouldn't. $\endgroup$ Aug 18, 2018 at 17:08
  • $\begingroup$ @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. $\endgroup$
    – WReach
    Aug 18, 2018 at 18:19
  • $\begingroup$ @WReach I see. That explains it. $\endgroup$ Aug 18, 2018 at 19:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.