Hello! I have this function:
Clear[chernC];
chernC[0] = 1;
chernC[1] = Subscript[ch, 1];
chernC[k_Integer /; k > 0] :=
chernC[k] =
Simplify[(1/k)*
Total[Table[(-1)^(j + 1)*Factorial[j]*Subscript[ch, j]*
chernC[k - j], {j, 1, k}]]];
which when called
chernC[2]
gives an output like this: $ \frac{1}{2}(ch_1^2-2ch_2) $, where $ ch $ is the variable of the polynomials. I am trying to write it in a nice way (factor out the common terms, write all the number in prime factorization form etc.) the way I do here for another function: http://community.wolfram.com/groups/-/m/t/1305165
My code that tries to do this is this:
primeFactorForm[n_] :=
If[Length@# == 1, First@#, CenterDot @@ #] &[
Superscript @@@ FactorInteger[n]]
string = With[{order = "Lexicographic"},
StringJoin[
Riffle[Table[
poly = MonomialList[chernC[i],
Table[Subscript[ch, k], {k, 1, 9}], order];
gcd = GCD @@ poly /. Rational[n_, d_]*c_ :> d;
ToString[
Inactive[Set][Subscript[ch, i],
DisplayForm@
RowBox[{1/primeFactorForm[gcd], "(",
RowBox[(List @@
Distribute[gcd*poly]) /. {Times[Rational[n_, d_],
e__] :>
RowBox[{If[n/d > 0, "+", "-"],
primeFactorForm[Abs@n]/primeFactorForm[Abs@d], e}],
Times[n_Integer, e__] :>
RowBox[{If[n > 0, "+", "-"], primeFactorForm[Abs@n],
e}]}], ")"}]], TeXForm], {i, 0, 9}], "\\\\"]]]
CopyToClipboard[string]
For the previous function it works great, but now it just gives weird output, for example the gcd function appears in the output explicitly, without actually computing the numerical gcd value. Can someone tell me how to fix this? Thank you!