In my Mathematica 11.3.

MatchQ[-3*i[1], -x_*i[1]]

returns False. But

MatchQ[-3*i[1], x_*i[1]]

returns True. I don't understand the reason. Does the minus "-" do something bad?

  • $\begingroup$ Yes, the Minus is the issue: Head[-3] is Integer, not Minus. But Head[-x] is Minus, so also MatchQ[-3, -x_] returns False. $\endgroup$ – Henrik Schumacher May 1 '18 at 13:30
  • 3
    $\begingroup$ In a situation like this the first thing to do is check the FullForm of the expression. $\endgroup$ – Daniel Lichtblau May 1 '18 at 13:43
  • $\begingroup$ fyi, if you want to match negative coefficients you may try MatchQ[-3*i[1], x_*i[1] /; x < 0] (returns true) $\endgroup$ – egwene sedai May 1 '18 at 16:25

Your Answer

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

Browse other questions tagged or ask your own question.