I am working on the solution of an ordinary differential equation. Among others related to a given Ansatz I get a long set of sums I want to sort and order in dependency of terms like
Unfortunately there are 4 summands, which do not behave like this. They show exponents of order 19/4, 15/4 and 7/4
Obviously I have to tune the Collect code line.
My question to the experts:
Would you please give me a hint to tune my Collect code line to avoid the above mentioned exponents.
Additionally I added an nb-File to reproduce the problem and because of the large number of summands a PDF of my output showing the problem summands marked with a red box.
My suggestion is to use the pattern matching to isolate terms of x^n/(x-1)^m. To do this you can pattern match the various forms of the term and replace it with another variable (in this case “g”).
nq = (q/. (* match the term raised to a power *)
(x/(x-1))^(w_)-> g^w ) /.
(* match the the numerator and denominator raised to the same power w is negative *)
Times[Power[Plus[-1,x],w_],Power[x,v_]]/; Abs[w]==Abs[v]->g^v /.
(* match the the denominator raised to a higher power *)
Times[Power[Plus[-1,x],w_],Power[x,v_]]/; Abs[w]>Abs[v]->g^v *(x-1)^(w+v)/.
(* match the the numerator raised to a higher power *)
Times[Power[Plus[-1,x],w_],Power[x,v_]]/; Abs[w]<Abs[v]->g^Abs[w ]*x^(w+v) /.
(* match the term raised to no power *)
x/(x-1)->g /.
(* match the term raised to no power *)
x/(x-1)^2->g /(x-1)
The result is a long expression in g. Now you can Collect in g. My first posting had a typo in the rules – you should verify that they are mathematically correct)
thank you very much for this qualified reply. It was near to this I needed. To solve the ODE one has to break down the problem into one or more convenient ODEs. The way I want to go a way to eliminate the factors (x/(-1+x))^(1/4), (x/(-1+x))^(1/2) and (x/(-1+x))^(3/4) by collecting the terms related to these factors and to solve the resulting 4 differential equations. In a first step I want to see the set of terms collected under the above mentioned factors to get an impression of the Ansatz I have to select to solve the ODEs in a second step.
Your code snippet was really helpful. I took the code and modified it like this:
nq = (q /. (x^(19/4))/((-1 + x)^(11/
4)) -> ((x^4)/((-1 + x)^2)) (x/(-1 + x))^(3/4) /. (x^(15/
4))/((-1 + x)^(7/4)) -> ((x^3)/((-1 + x))) (x/(-1 + x))^(3/4))
"and do the Collect once again"
"now all summands are well collected to each of the factors \
(x/(-1+x))^(1/4) or (x/(-1+x))^(1/2) or (x/(-1+x))^(3/4) and the \
rest"
s = Collect[
nq, {((x/(-1 + x))^(1/4)), ((x/(-1 + x))^(1/2)), ((x/(-1 + x))^(3/
4))}]