1
$\begingroup$

I understand that Attributes of Times make a bit non intuitive the Pattern Matching of its arguments. However I do not understand why this gives False:

MatchQ[Times[a, b, c], Times[___, b, ___]] 
False

Can you explain it to me?

$\endgroup$
2
  • 1
    $\begingroup$ You need the pattern HoldPattern[Times[___, b, ___]] instead. If you look at the FullForm of Times[___, b, ___] you'll see that the attributes of Times mucked up the pattern. $\endgroup$ Feb 8, 2019 at 10:24
  • $\begingroup$ Related: (156282) $\endgroup$
    – Michael E2
    May 27, 2019 at 14:46

1 Answer 1

2
$\begingroup$
Times[___,b,___] // FullForm

Times[b,Power[BlankNullSequence[],2]]

MatchQ[Times[a, b, c], HoldPattern[Times[___, b, ___]]]

True

or

MatchQ[Times[a, b, c], Unevaluated[Times[___, b, ___]]]

True

$\endgroup$

Your Answer

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

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