I am trying to separate/split an expression (consisting of polynomials) to a list. However I want to keep the exponents intact. Here is an example:
k1=((x+y)^(2+e) (a+b)^(-1-e) (k - z) )//Expand
k2=k1 /. Times | Plus | Power -> List
output:
(a + b)^(-1 - e) k (x + y)^(2 + e) - (a + b)^(-1 - e) (x + y)^(2 + e) z
{{{{a, b}, {-1, {-1, e}}}, k, {{x, y}, {2, e}}}, {-1, {{a, b}, {-1, {-1, e}}}, {{x, y}, {2, e}}, z}}
The problem in this approach is it makes list in which it is not apparant to distinguish -e
and -1+e
.
-e /. Times | Plus | Power -> List
-1+e /. Times | Plus | Power -> List
leads to same {-1, e}
. For each -
sign it creates a list which is unwanted.
In this example,
How do I prevent applying Plus -> List
to the exponent?
The reason is I want to finally get back to the following form from each term of the list at the end, i.e.
k2[[1]], k2[[2]] etc.
where
k2[[1]][[1]] = (a + b)^(-1 - e)
k2[[1]][[2]] = (x + y)^(2 + e)
k2[[1]][[3]] = k
k2[[2]][[1]] = (a + b)^(-1 - e)
k2[[2]][[2]] = (x + y)^(2 + e)
k2[[2]][[3]] = -z
EDIT::
The expected final output
k2={
{{(a + b),(-1 - e)},{ k },{(x + y),(2 + e)}},
{{(a + b),(-1 - e)},{-z},{(x + y),(2 + e)}}
}
or
k2={
{{{a , b},{-1, - e}},{ k },{{x , y},{2 , e}}},
{{{a , b},{-1, - e}},{-z},{{x , y},{2 , e}}}
}
Such that finally I get each of the two terms ( which are separated by +/-
)
(1.) (a + b)^(-1 - e) k (x + y)^(2 + e)
(2.) - (a + b)^(-1 - e) (x + y)^(2 + e) z
Also from (1.)
and (2.)
I will get each terms which are multiplied i.e.
(1.) (a + b)^(-1 - e), k, (x + y)^(2 + e)
(2.) (a + b)^(-1 - e), -z, (x + y)^(2 + e)
I find the difficult part is to handle this -
ve sign.
k1 /. {Power[a_, b_] :> Power[a /. Plus | Times -> List, b] , Plus | Times -> List}
give what you need? $\endgroup$+-
and then for each of them I want to find out the terms which are multiplied. Like in this example firstk2 = k2[[1]] + k2[[2]]
. Then for eachk2[[i]]
I want to take out each term which is multipled. Like from k2[[1]] I want(a + b)^(-1 - e)
,(x + y)^(2 + e)
,k
. $\endgroup$k2
? and for-e /. rule1
and-1+e /. rule2
? $\endgroup$k2[[1]][[1]] /. {{x_^y_, a_^b_} -> (x+a)^y}
. $\endgroup$-
ve sign in a general case. In your scond listk2[[2]]
, it contains-1
as one of the list element, which I like to keep with any of the terms. I can probably do a workaround. Basically the top level lists will have sameLength
. $\endgroup$