Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

Bug introduced in 10.0.0 and fixed in 10.0.1


Just to report.

IgnoringInactiveshould work with Cases. In agreement with the things written at the Documentation Center this:

 Cases[{Cos[a], Inactive[Cos][b]}, IgnoringInactive[Cos[x_]]]

works correctly yielding

(*   {Cos[a], Inactive[Cos][b]}   *)

exactly as expected.

However, this

Cases[{Cos[a], Inactive[Cos][b], Tan[c]}, IgnoringInactive[Cos[x_]]]

works (as I think) incorrectly returning

(*  {Cos[a], Inactive[Cos][b], Tan[c]}  *)

while I would expect again {Cos[a], Inactive[Cos][b]}.

share|improve this question
    
I agree: that doesn't seem right. It seems IgnoringInactive[Inactive[Cos][x_]] does work however, not that that makes this OK. –  Mr.Wizard Jul 21 at 14:06
4  
On a related note, MatchQ[1, IgnoringInactive[0]] and MatchQ["a", IgnoringInactive["b"]] both return True instead of False (reported to WRI). –  WReach Jul 21 at 17:55

1 Answer 1

Since IgnoringInactive is presently bugged we may wish to have a workaround for this operation.
Here is my first attempt at implementing this. Please test it and give me feedback.

patternHead = 
  Pattern | Blank | Repeated | HoldPattern | Verbatim | Inactive | _Alternatives;

ignInac[pat_] := 
 Replace[pat, (h : Except[patternHead])[x___] :> (h | Inactive[h])[x], {0, -1}]

Test for an example from the documentation:

diff[ignInac[int[f_, x_]], x_] := f

diff[int[Sin[x], x], x]
diff[Inactive[int][Sin[x], x], x]
Sin[x]

Sin[x]

And demonstrating correct function with the examples from the question and comments:

Cases[{Cos[a], Inactive[Cos][b], Tan[c]}, ignInac @ Cos[x_]]
{Cos[a], Inactive[Cos][b]}
MatchQ[1, ignInac[0]]
MatchQ["a", ignInac["b"]]
False
False

Notes:

  • The function ignInac directly transforms patterns so definitions do not look as clean as with the built-in, however for the cases I've tried it appears equivalent.

  • I did not attempt to handle the case of HoldPattern outside of IgnoringInactive (or ignInac) but I do not see an example of that in the documentation.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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