2
$\begingroup$

I want to check if a given polynomial contains a certain monomial while ignoring ordering of the variables. For example: $$P(a,b,c)=abc + bca$$ And then I want to check if $P$ contains $bac$ (should be true). I tried FreeQ and MemberQ but both return false.

$\endgroup$
6
  • $\begingroup$ Isn’t FreeQ[] —> False just the result you want? (I guess you realize that $P$ is just $2 abc$, though.) $\endgroup$
    – Michael E2
    Apr 3 at 4:48
  • $\begingroup$ Not exactly, for example FreeQ[abc, a*b]=False also $\endgroup$
    – David
    Apr 3 at 4:59
  • $\begingroup$ Have you seen MonomialList? $\endgroup$
    – Michael E2
    Apr 3 at 5:02
  • $\begingroup$ I guess I could do something like: MemberQ[MonomialList[abc], acb] but that wont work if there is a coefficient other than 1. $\endgroup$
    – David
    Apr 3 at 5:06
  • 1
    $\begingroup$ Perhaps MemberQ[MonomialList[2 a b c], Optional[_?NumericQ] a c b]? $\endgroup$
    – Michael E2
    Apr 3 at 5:44
2
$\begingroup$

This seems to work:

MemberQ[MonomialList[2 a b c], Optional[_?NumericQ] a c b]
(*  True  *)

Also this, which is a more algebraic approach.

With[{vars = {a, b, c, d}}, 
 KeyExistsQ[CoefficientRules[a b + 2 a b c + a b c d, vars], 
  First@Keys@CoefficientRules[a c b, vars]]
 ]
(*  True  *)

It's important that the variables be the same in the same order in both calls to CoefficientRules. (I tend to prefer algebraic approaches in dealing with polynomials.)

Another algebraic approach:

With[{vars = {a, b, c, d}},
   With[{monomial = CoefficientArrays[a b c, vars]},
    CoefficientArrays[a b + 2 a b c + a b c d, 
       vars][[Length@monomial]] * Last@monomial
    ]]@"NonzeroPositions" =!= {}
(*  True  *)

With[{vars = {a, b, c, d}},
   With[{monomial = CoefficientArrays[a d c, vars]},
    CoefficientArrays[a b + 2 a b c + a b c d, 
       vars][[Length@monomial]] * Last@monomial
    ]]@"NonzeroPositions" =!= {}
(*  False  *)
$\endgroup$
0
$\begingroup$
PolynomialQ[a b c + 2 b c a, {b, a, c}]

a, b, c do not need to be symbols: PolynomialQ

or use

Decompose

or use

FactorList

for more flexibility.

Best seems up to the exactness of the question:

SubsetQ[List @@ (a b c + b c a), List @@ (b a c)]

(* True *)

That is because You do not primarily intent to differentiate between permutations. The basic idea stems from PolynomialOrderings. The Apply of List remove the built-ins from the FullForm and that is for polynomials Plus and Times. It then uses lexicographics ordering.

The question is basically for multivariate polynomials in order without the meaning of the order. That is confusing. As seems there is used the set of variate names abc, bac and bca so the induced intent of multivariation is forgotten in the name strings.

MemberQ[List @@ (abc + bca), List @@ (bac)]

(* False *)

based on the different names. The built-in Characters is then the link between both approaches.

SubsetQ[Characters[ToString[(List @@ (abc + bca))]], 
 Characters[ToString[List @@ (bac)]]]

(* True *)

$\endgroup$
1
  • $\begingroup$ These work on those examples but for example SubsetQ[List @@ (a b c + b c a), List @@ (b a)] returns true also when I want that to be false. I want the monomial to appear in the polynomial exactly up to permutation. $\endgroup$
    – David
    Apr 3 at 15:35

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.