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$
  • 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$ – Sjoerd Smit Feb 8 at 10:24
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, privacy policy and cookie policy

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