1
$\begingroup$

I have the following expression

expr = x1^d1 * x2^d2 * x3^d3;

where d1,d2,d3 can contain negative values/expression i.e. in general these d1,d2,d3 may not be numerical values. Say

d1 = 4 d;
d2 = -5 e;
d3 =  -6 d;
with assumption d, e are positive.

Question : Is there any way to make two lists one containing positive exponent and other with negative exponent?

My current try is to use Exponent for each one of these terms and test them for positive and negative.

$\endgroup$
3
$\begingroup$
$Version

(* "12.1.1 for Mac OS X x86 (64-bit) (June 19, 2020)" *)

Clear["Global`*"]

expr = x1^d1*x2^d2*x3^d3;

exponents = 
 Cases[expr, x_^p_. :> p, 1] /. {d1 -> 4 d, d2 -> -5 e, d3 -> -6 d}

(* {4 d, -5 e, -6 d} *)

pos = Assuming[{d > 0, e > 0}, Select[exponents, Simplify[# > 0] &]]

(* {4 d} *)

neg = Assuming[{d > 0, e > 0}, Select[exponents, Simplify[# < 0] &]]

(* {-5 e, -6 d} *)
$\endgroup$
1
$\begingroup$

You can also use Internal`SyntacticNegativeQ with GeneralUtilities`SelectDiscard, GroupBy, Cases, DeleteCases, Select or Pick as follows:

expr = x1^d1*x2^d2*x3^d3
x1^(4 d) x2^(-5 e) x3^(-6 d)
exponents = Exponent[expr, {x1, x2, x3}]
{4 d, -5 e, -6 d}
{neg, pos} = GeneralUtilities`SelectDiscard[Internal`SyntacticNegativeQ] @ exponents

{neg, pos} = GroupBy[exponents, Internal`SyntacticNegativeQ] /@ {True, False}

{neg, pos} = Cases[#@_?Internal`SyntacticNegativeQ]@exponents & /@ 
   {Identity, Except}

{neg, pos} = DeleteCases[#@_?Internal`SyntacticNegativeQ] @ exponents & /@ 
   {Except, Identity}

{neg, pos} = Select[#@*Internal`SyntacticNegativeQ]@exponents & /@ 
   {Identity, Not}

{neg, pos} = Pick[exponents, 
    Internal`SyntacticNegativeQ /@ exponents, #] & /@ {True, False}

all give

 {{-5 e, -6 d}, {4 d}}
$\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.