Bug introduced in 10.1 and fixed in 11.1

Thank you for taking the time to send in this report. It does appear that pattern-variable renaming misses symbols within Except when using With. I will forward an incident report to our developers regarding this issue, and include the discussion in the stack exchange article.

With[{u = {f}},
 HoldPattern[G[f_, Except[f_]]] :> u


HoldPattern[G[f$_, Except[f_]]] :> {f}

I would expect

HoldPattern[G[f$_, Except[f$_]]] :> {f}


  • $\begingroup$ I agree that this is a bug, adding the tag. $\endgroup$
    – Szabolcs
    Sep 1 '16 at 12:31
  • $\begingroup$ Can you please confirm that you have (or will) report the problem? $\endgroup$
    – Szabolcs
    Sep 1 '16 at 12:41
  • $\begingroup$ I'd expect neither. I don't understand why is f touched at all. Curiously, if you try With[{u = {f}}, HoldPattern[G[f_, Except[f_]]]] you get HoldPattern[G[f_, Except[f_]]]. $\endgroup$
    – rcollyer
    Sep 1 '16 at 12:50
  • $\begingroup$ maybe related: 101903 $\endgroup$
    – Kuba
    Sep 1 '16 at 12:57
  • $\begingroup$ @rcollyer That's because :> is a scoping construct and could potentially have f on the RHS as well (in addition to the LHS as a pattern name). In that case the uniqueness (localization) of f must be guaranteed. Mathematica is a bit overeager in doing this. $\endgroup$
    – Szabolcs
    Sep 1 '16 at 13:17

I agree that this is a bug. However, I want to point out that this usage of Except does not seem to be allowed in older versions.

In version 9.0:

enter image description here

We don't get the expected True answer. An error message is issued. The error message is also triggered by your example.

In version 10.0:

enter image description here

The error is not triggered by your example in version 10.0.2. (It is triggered by other similar examples such as the MatchQ above.)

In version 10.3.1 everything works fine:

enter image description here

It seems that this usage of Except is new in 10.1, 10.2 or 10.3 and that the renaming rules were not yet updated to be compatible with it. With this context, it seems like a bug.

The change is not mentioned on the documentation page of Except, which is annoying.

  • 4
    $\begingroup$ Narrowed down the window, it's between 10.0 and 10.2. $\endgroup$
    – rcollyer
    Sep 1 '16 at 14:04
  • $\begingroup$ @rcollyer The True result is given in 10.1.0. $\endgroup$
    – Mr.Wizard
    Apr 24 '17 at 18:41
  • $\begingroup$ @Mr.Wizard I could have figured that out, eventually. But, it would have required unpacking 10.1.0, etc., and it couldn't exceed the threshold of my laziness. :) $\endgroup$
    – rcollyer
    Apr 24 '17 at 19:55

I think the problem is when you provide a pattern as the first argument of Except. Although, given as a second argument the pattern is preserved, the context now changes:

With[{u = {f}},
HoldPattern[G[f_, Except[_, f_]]] :> u

(* HoldPattern[G[f$_, Except[_, f$_]]] :> {f} *)

Pattern provided as either a first or a second in Except will yield different contexts e.g.

Cases[{1, 2, b, 3, 4, a, 5}, Except[_Integer]]
(* {b,a} *)

Cases[{1, 2, b, 3, 4, a, 5}, Except[# &, _Integer]]
(* {1, 2, 3, 4, 5} *)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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