0
$\begingroup$

I have this code:

K[Q_, n_Integer] := 
 Module[{z, x}, 
  SymmetricReduction[
     SeriesCoefficient[
      Product[ComposeSeries[Series[Q[z], {z, 0, n}], 
        Series[x[i] z, {z, 0, n}]], {i, 1, n}], n], 
     Table[x[i], {i, 1, n}], Table[Subscript[c, i], {i, 1, n}]][[1]] //
    FactorTerms]

   poly = K[Sqrt[#]/Tanh[Sqrt[#]] &, 8] /. c -> p;
   primeFactorForm[n_] := 
   If[Length@# == 1, First@#, CenterDot @@ #] &[Superscript @@@ FactorInteger[n]];

   For[i = 0, i < 5, i++, 
   poly = K[Sqrt[#]/Tanh[Sqrt[#]] &, i] /. c -> p;  
   Print[Subscript[L, i], " = ", 
   Plus @@ List @@ Expand[poly] /. 
   Times[Rational[n_, d_], e__] :> 
   primeFactorForm[n]/ primeFactorForm[d]*e]] 

Which outputs some polynomials of the form:

$L_2 = \frac{p_1^2-1^1}{ 5^1 \cdot 3^2}+\frac{7^1 p_2}{5^1\cdot 3^2 }$

How can I put the variable out of the fraction? I want to obtain something like: $L_2 = \frac{-1^1}{ 5^1 \cdot 3^2}p_1^2+\frac{7^1 }{5^1\cdot 3^2 }p_2$ Thank you!

$\endgroup$
  • $\begingroup$ You can use collect command. $\endgroup$ – Gopal Verma Mar 6 '18 at 11:56
  • $\begingroup$ @GopalVerma Where exactly should I add that? I see that Collect requires a variable but my polynomial has many (it is not just a polynomial in x) $\endgroup$ – Silviu Mar 6 '18 at 12:16
  • $\begingroup$ Can you provide your polynomial? $\endgroup$ – Gopal Verma Mar 6 '18 at 12:22
  • $\begingroup$ I gave an example of one of them in my post. They look more or less the same for higher terms, just with more parameters not just p1 and p2 and also crossed terms i.e. p1*p3 $\endgroup$ – Silviu Mar 6 '18 at 12:25
  • $\begingroup$ Did you try Expand[poly]? $\endgroup$ – Gopal Verma Mar 6 '18 at 14:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.