Hello! I would really appreciate any help with this as I have tried looking for an answer for more than 2 weeks. So this is my 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]]]
primeFactorForm[n_] :=
If[Length@# == 1, First@#, CenterDot @@ #] &[
Superscript @@@ FactorInteger[n]];
string = StringJoin[
Riffle[Table[poly = K[Sqrt[#]/Tanh[Sqrt[#]] &, i] /. c -> p;
gcd = GCD @@ List @@ poly /. Rational[n_, d_]*c_ :> d;
ToString[
Inactive[Set][Subscript[L, i],
1/primeFactorForm[gcd]*Plus @@ List @@ Distribute[gcd*poly] /.
Times[Rational[n_, d_], e__] :>
primeFactorForm[n]/primeFactorForm[d]*e], TeXForm], {i, 0,
7}], "\\\\"]]
CopyToClipboard[string]
And this is the output (I have to do this many times with mad=ny different polynomials but the output is similar in all the cases):
$L_0=\frac{1}{1^1}\\L_1=\frac{\gcd \left(\frac{1}{3},p_1\right)+p_1+\frac{1}{3}}{\frac{1}{3}^{p_1}}\\L_2=\frac{7 p_2-p_1^2}{3^2\cdot 5^1}\\L_3=\frac{2 p_1^3-13 p_2 p_1+62 p_3}{3^3\cdot 5^1\cdot 7^1}\\L_4=\frac{\frac{p_2 p_1^2 2^1\cdot 11^1}{3^1}+\frac{p_3 p_1 -1^1\cdot 71^1}{3^1}+\frac{p_2^2 -1^1\cdot 19^1}{3^1}-p_1^4+127 p_4}{3^3\cdot 5^2\cdot 7^1}\\L_5=\frac{\frac{p_1^5 2^1}{3^1\cdot 7^1}+\frac{p_2 p_1^3 -1^1\cdot 83^1}{3^1\cdot 5^1\cdot 7^1}+\frac{p_3 p_1^2 79^1}{5^1\cdot 7^1}+\frac{p_4 p_1 -1^1\cdot 919^1}{3^1\cdot 5^1\cdot 7^1}+\frac{p_2^2 p_1 127^1}{3^1\cdot 5^1\cdot 7^1}+\frac{p_5 2^1\cdot 73^1}{3^1}+\frac{p_2 p_3 -1^1\cdot 2^4}{5^1}}{3^4\cdot 5^1\cdot 11^1}\\L_6=\frac{\frac{p_4 p_1^2 40841^1}{5^1}+\frac{p_1^6 -1^1\cdot 2^1\cdot 691^1}{3^1\cdot 5^1}+\frac{p_2 p_1^4 2^1\cdot 6421^1}{3^1\cdot 5^1}+\frac{p_3 p_1^3 -1^1\cdot 33863^1}{3^1\cdot 5^1}+\frac{p_2^2 p_1^2 -1^1\cdot 5527^1}{3^1}+\frac{p_2 p_3 p_1 83^1\cdot 349^1}{5^1}+\frac{p_5 p_1 -1^1\cdot 2^5\cdot 29^1\cdot 181^1}{5^1}+\frac{p_3^2 -1^1\cdot 167^1\cdot 241^1}{3^1\cdot 5^1}+\frac{p_2 p_4 -1^1\cdot 159287^1}{3^1\cdot 5^1}+\frac{p_6 2^1\cdot 23^1\cdot 89^1\cdot 691^1}{3^1\cdot 5^1}+\frac{p_2^3 2^1\cdot 1453^1}{5^1}}{3^5\cdot 5^2\cdot 7^2\cdot 11^1\cdot 13^1}\\L_7=\frac{\frac{p_1^7 2^2}{3^4\cdot 5^1\cdot 11^1}+\frac{p_2 p_1^5 -1^1\cdot 2^1\cdot 2161^1}{3^5\cdot 5^2\cdot 7^1\cdot 11^1}+\frac{p_3 p_1^4 2^2}{5^2\cdot 7^1}+\frac{p_4 p_1^3 -1^1\cdot 2^1\cdot 113^1}{3^4\cdot 5^1\cdot 7^1}+\frac{p_2^2 p_1^3 2^3}{3^2\cdot 5^1\cdot 7^1}+\frac{p_2 p_3 p_1^2 -1^1\cdot 39341^1}{3^5\cdot 5^2\cdot 7^1\cdot 11^1}+\frac{p_5 p_1^2 2^4\cdot 277^1}{3^4\cdot 5^2\cdot 7^1}+\frac{p_2^3 p_1 -1^1\cdot 2^1\cdot 3989^1}{3^5\cdot 5^2\cdot 7^1\cdot 11^1}+\frac{p_6 p_1 -1^1\cdot 2^1\cdot 305633^1}{3^5\cdot 5^2\cdot 7^1\cdot 11^1}+\frac{p_2 p_4 p_1 1399^1}{3^3\cdot 5^2\cdot 11^1}+\frac{p_3^2 p_1 22027^1}{3^5\cdot 5^2\cdot 7^1\cdot 11^1}+\frac{p_2^2 p_3 2^3\cdot 2087^1}{3^5\cdot 5^2\cdot 7^1\cdot 11^1}+\frac{p_3 p_4 -1^1\cdot 2^1\cdot 97^1\cdot 107^1}{3^4\cdot 5^2\cdot 7^1\cdot 11^1}+\frac{p_2 p_5 -1^1\cdot 2^1\cdot 23^2}{3^5\cdot 11^1}+\frac{p_7 2^2\cdot 8191^1}{3^4\cdot 5^1\cdot 11^1}}{3^2\cdot 5^1\cdot 7^1\cdot 13^1}$
Now here are the things I was struggling with. I need to use these results in a paper so I was requested to have a certain format. I need the variables out of the fraction and I need the common denominator to be in front of everything, instead of having a fraction over a fraction i.e. instead of let's say $\frac{\frac{7p_ 2}{2} -p_ 1^2}{3^2\cdot 5^1}$ I need $\frac{1}{3^2\cdot 5^1}(\frac{7}{2} p_ 2-p_ 1^2)$. Also, in the example I gave $L_1$ is weird and this happens sometimes in other polynomials. Why is this? (but this is less important). So, can anyone tell me how to fix this formating problem as I tried so so many functions and stuff, but nothing works, and doing it by hand in Latex, not only it is time consuming, but it is seriously prone to error... Thank you!