3
$\begingroup$

I have several very long, factorised polynomials in several variables, e.g.

x1^4 x2^3 x3 x4^3 x5 x6 x7^2 x8 (1 + x2 + x2 x3 + x5 + x1 x5)

I want an easy way to check whether such a polynomial is 'subtraction free' in the sense of having no relative minus sign between terms anywhere. So

-x1(1+x2+x2*x3) 

or

x1*x2+1+x3+x4*x5)

are both fine, but

x1*x2(1+x1*x3-x2)

is not.

Is there any easy way to implement this?

$\endgroup$
4
  • $\begingroup$ What answer would you seek if the polynomial had the form -((-x - y) z)? I ask since you specified a "factorised polynomial", and I wasn't sure if that meant it shouldn't be multiplied out. $\endgroup$
    – Michael E2
    Commented Sep 5, 2023 at 13:15
  • 1
    $\begingroup$ Maybe "relative minus sign" means no nonzero monomials in a factor with opposite signs? $\endgroup$
    – Michael E2
    Commented Sep 5, 2023 at 13:34
  • 1
    $\begingroup$ Are the coefficients always integers (with head Integer)? $\endgroup$
    – Michael E2
    Commented Sep 5, 2023 at 13:45
  • $\begingroup$ -(-x-y)z would count as subtraction-free, yes. Rather than 'factorised polynomial' one could just expand out the whole thing and seek no relative minus signs between terms. The coefficients in my application would all be integer. $\endgroup$
    – Facieod
    Commented Sep 6, 2023 at 14:02

2 Answers 2

3
$\begingroup$

The expressions:

t1 = x1x2 (1 + x1x3 - x2);
t2 = -x1 (1 + x2 + x2x3);

should be bad/good. For this look at the FullForm of t1/t2:

t1//FullForm
t2//FullForm

enter image description here

enter image description here

Note the position of "-1":

Position[t1, -1]

Position[t2, -1]

{{2, 3, 1}}
{{1}}

If -1 is on level 1 it is good like in t2. In t1 -1 is deeper nested. We may exploit this lik3 e.g.:

check[ex_] := Length[Position[ex, -1][[1]]] <= 1

With this:

check[t1]
check[t2]

False
True
$\endgroup$
0
3
$\begingroup$

Perhaps something like:

f1 = FreeQ[Factor @ #, Plus[_?Internal`SyntacticNegativeQ, __]] &;

f2 = FreeQ[Factor @ #, Times[_?Internal`SyntacticNegativeQ, __], {1, ∞}] & ;

Examples:

expr1 = x1^4 x2^3 x3 x4^3 x5 x6 x7^2 x8 (1 + x2 + x2 x3 + x5 + x1 x5);

expr2 = - x1^4 x2^3 x3 x4^3 x5 x6 x7^2 x8 (1 + x2 + x2 x3 + x5 + x1 x5);

expr3 = x1^4 x2^3 x3 x4^3 x5 x6 x7^2 x8 (1 + x2 + x2 x3 - x5 +  x1 x5);


f1 /@ {expr1, expr2, expr3}
{True, True, False}
f2 /@ {expr1, expr2, expr3}
{True, True, False}
$\endgroup$
5
  • $\begingroup$ expr2 seems to have a negative sign? $\endgroup$
    – Syed
    Commented Sep 5, 2023 at 13:24
  • $\begingroup$ @Syed, yes. "So -x1(1+x2+x2x3) and x1*x2+1+x3+x4*x5) are both fine" $\endgroup$
    – kglr
    Commented Sep 5, 2023 at 13:26
  • $\begingroup$ I need to put glasses back on. $\endgroup$
    – Syed
    Commented Sep 5, 2023 at 13:28
  • 1
    $\begingroup$ I wonder if the output of f2[x1*x2 (1 + x1*x3 - 2 x2)] is correct? I'd expect coefficients other than -1, 0, +1 could occur, even though they are missing from the OP. $\endgroup$
    – Michael E2
    Commented Sep 5, 2023 at 13:42
  • 1
    $\begingroup$ Thank you @MichaelE2; updated with a fix. $\endgroup$
    – kglr
    Commented Sep 5, 2023 at 13:45

Your Answer

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

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