6
$\begingroup$

Bug introduced in 11.3 or earlier and persisting through 12.0 or later

[CASE:4352435] and [CASE:4354378]


In Mathematica 11.3 and 12.0,

ReplaceList[{2,2},{u_,Except[u_|1]}:>True]

incorrectly returns

{True}

In earlier versions (10.1, 10.3, 11.0, 11.1) executing the above code causes the kernel to hang, requiring it to be quit, so this appears never to have worked correctly. See also the Answer below.

In addition, in the earlier versions, the following also hangs:

ReplaceList[{2, 3}, {u_, Except[1 | u_] ..} :> True]

Using Replace instead of ReplaceList is fine; SequenceCases behaves incorrectly like ReplaceList.

The issue is also seen with orderless matches (which presumably are represented by alternatives internally); for example,

 ReplaceList[{2 x, 2 x}, {2 u_, Except[2 u_]} :> True]

incorrectly returns

{True}

in 11.3 and 12.0.

-- The above has been revised as a result of feedback and further testing.

$\endgroup$
  • $\begingroup$ ReplaceList and SequenceCases work for me in version 12. $\endgroup$ – C. E. Nov 9 '19 at 11:36
  • $\begingroup$ I suggest you check these examples with a new kernel. Also report your operating system, in case this is significant. $\endgroup$ – mikado Nov 9 '19 at 11:41
  • $\begingroup$ @C.E. -- Thanks for checking; sounds like I should upgrade. $\endgroup$ – David Bevan Nov 9 '19 at 12:06
  • $\begingroup$ Kernel hang confirmed in v10.1.0 under Windows x64. $\endgroup$ – Mr.Wizard Nov 9 '19 at 13:37
  • $\begingroup$ ReplaceList[{2, 3}, {u_, Except[1 | u_] ..} :> True] evaluated instantly and returned {True} in V11.3.0 running on MacOS 10.13.4 $\endgroup$ – m_goldberg Nov 9 '19 at 14:19
5
$\begingroup$

Update. The bug is confirmed by the tech support: [CASE:4352435].


For

ReplaceList[{2, 3}, {u_, Except[1 | u_] ..} :> True]

Mathematica 8.0.4 prints error:

Except::named: Named pattern variables are not allowed in the first argument of Except[1|u_].

and returns {}, but versions 11.3 and 12.0 both return {True} without any messages.

What seems to be a real bug in the latest versions is that each of the following two lines also returns {True}:

ReplaceList[{2, 2}, {u_, Except[u_ | 1]} :> True]    
SequenceCases[{2, 2}, {u_, Except[u_ | 1]} :> True]

while the pattern doen't match:

MatchQ[{2, 2}, {u_, Except[u_ | 1]}]
False

Replace works as expected though:

Replace[{2, 2}, {u_, Except[u_ | 1]} :> True]
Replace[{2, 3}, {u_, Except[u_ | 1]} :> True]
{2, 2}

True
|improve this answer|||||
$\endgroup$

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.