From a following program (part of a longer program) I will get a recurrence in an elegant format.
sold =
{624, -1490, 1244, -430, 52, 0, 0, 0, 0, 0, 0, -6648, 13539, -9945,
3117, -351, 0, 0, 0, 0, 0, 0, 12384, -22716, 15216, -4416, 468, 0,
0, 0, 0, 0, 0, 3456, -8672, 6752, -2032, 208, 0, 0, 0, 0, 0, 0,
53760, -86912, 47552, -10624, 832, 0, 0, 0, 0, 0, 0};
maxdenom = 624; maxdeg = 10; j = 4;
strecur = ""; ikoef = 0;
Do[sign = 0; dejmin = 0; numpol = Factor[Sum[ikoef++;
If[sold[[ikoef]] != 0, sign = Sign[sold[[ikoef]]]];
sold[[ikoef]]*n^i, {i, 0, maxdeg}]];
If[ord == 0, signan = sign;
If[signan < 0, numpol = -numpol; sign = 1;]];
If[ord > 0 && signan > 0, If[sign == 1, dejmin = 1,
If[sign != 0, numpol = Factor[-numpol]; sign = 1];];];
If[ord > 0 && signan < 0,
If[sign == -1, dejmin = 1; numpol = Factor[-numpol]; sign = 1];];
strpol = ToString[TraditionalForm[numpol*a[n - ord]]];
If[sign == 1, If[ord < 2, znam = "", znam = "+"],
If[ord > 1, znam = "+", znam = ""]];
If[dejmin == 1, znam = "-"];
If[sign != 0 && strpol != "0", strecur = strecur <> znam <> strpol];
If[ord == 0, strecur = strecur <> "="];, {ord, 0, j}];
Print[strecur]
How to replace spaces with *
in the TraditionalForm output ?
I can export this (manually) as "plain text"
2 (n-1) (2 n-3) (13 n^2-75 n+104) a(n)=3 (117 n^4-1039 n^3+3315 n^2-4513 n+2216) a(n-1)-12 (39 n^4-368 n^3+1268 n^2-1893 n+1032) a(n-2)-16 (n-4) (13 n^3-75 n^2+122 n-54) a(n-3)-64 (n-5) (n-4) (13 n^2-49 n+42) a(n-4)
and replace all spaces with *
manually in an external editor. But I want to do this in Mathematica and print it (with *
) inside the program. I need a string
"2*(n-1)*(2*n-3)*(13*n^2-75*n+104)*a(n)=3*(117*n^4-1039*n^3+3315*n^2-4513*n+2216)*a(n-1)-12*(39*n^4-368*n^3+1268*n^2-1893*n+1032)*a(n-2)-16*(n-4)*(13*n^3-75*n^2+122*n-54)*a(n-3)-64*(n-5)*(n-4)*(13*n^2-49*n+42)*a(n-4)"
After
ToString[strecur]
I get an absolutelly unusable output with exponents on separate lines.
So, my question is: How to convert it from a traditional format to a string (without changing the order of terms) ? Then it's easy to do StringReplace["string", " " -> "*"]