Hi again. I still have some doubts... I tried to elaborate a new code (...but maybe has a better way using some increment in counting the digits that I do not know to do...). Also have doubts in the commands Parallelize and Compile, which in some cases did not work as I wanted... Below are the versions of the codes that I did compare:
This is my old code that had the problem of the big numbers (creating a big number to then count the digits), just to be able to compare (absolute timing) with my new code (using 7 terms in all comparisons below):
z = 7;
g = Compile[{{x, _Integer}}, Range[10^x - 1]]
EvaluationData[
Parallelize[
h[x1_] := (DigitCount[
ToExpression[
StringDelete[ToString[g[x1]], {"{", "}", " ", ","}]]])];
b = Flatten[
Table[N[Take[h[i], {10}]/Take[h[i], {2}], 11], {i, Range[z]}]];
{ListLinePlot[b,
PlotRange -> {{1, Automatic}, {Automatic, Automatic}},
LabelingFunction -> (#1 &), ImageSize -> Large], b}]
This (below) is the new code I developed, it makes the sum of the digits without have to generate a large number before it (again, I don't know if it was the best way to do this..). The memory problem has apparently been solved but it has shown slower than the old code when evaluate(?!). And Parallelize wasn't very efficient either, I still don't know why (?!). Doing two variations of this code, one with and one without the Parallelize command did not change almost nothing in absolute timming ..of course if I did that correctly... (at least it does not crash the PC with lack of memory due to premature big numbers). My new code:
n = 7;
z = Compile[{{k, _Integer}}, 10^k - 1]
EvaluationData[
Parallelize[b = Table[Sum[DigitCount[x], {x, 1, z[i]}], {i, 1, n}]];
c = Table[
N[FromDigits[
Take[FromDigits[Take[b, {v}]], {10}]/
Take[FromDigits[Take[b, {v}]], {2}]], 11], {v, 1, n}];
{ListLinePlot[c,
PlotRange -> {{1, Automatic}, {Automatic, Automatic}},
LabelingFunction -> (#1 &), ImageSize -> Large], c}]
This version below of the code proved to be better, also does not have the problem of the large numbers that my old version had and is faster, but is not in a form as automatic as the version containing Table (above)... But Parallelize seems to work in this case (the absolute timing was almost 1/2 from the time of my old code and went to almost 1/6 of the absolute timing of the new version with Table)! I do not know why Parallelize worked with several “manual” lines and practically did not work in the version of this code with Table (?!).
z = Compile[{{k, _Integer}}, 10^k - 1]
EvaluationData[Parallelize[b1 = Sum[DigitCount[x], {x, 1, z[1]}];
b2 = Sum[DigitCount[x], {x, 1, z[2]}];
b3 = Sum[DigitCount[x], {x, 1, z[3]}];
b4 = Sum[DigitCount[x], {x, 1, z[4]}];
b5 = Sum[DigitCount[x], {x, 1, z[5]}];
b6 = Sum[DigitCount[x], {x, 1, z[6]}];
b7 = Sum[DigitCount[x], {x, 1, z[7]}];
c1 = N[FromDigits[Take[b1, {10}]/Take[b1, {2}]], 11];
c2 = N[FromDigits[Take[b2, {10}]/Take[b2, {2}]], 11];
c3 = N[FromDigits[Take[b3, {10}]/Take[b3, {2}]], 11];
c4 = N[FromDigits[Take[b4, {10}]/Take[b4, {2}]], 11];
c5 = N[FromDigits[Take[b5, {10}]/Take[b5, {2}]], 11];
c6 = N[FromDigits[Take[b6, {10}]/Take[b6, {2}]], 11];
c7 = N[FromDigits[Take[b7, {10}]/Take[b7, {2}]], 11]];
d = {c1, c2, c3, c4, c5, c6, c7};
{ListLinePlot[d,
PlotRange -> {{1, Automatic}, {Automatic, Automatic}},
LabelingFunction -> (#1 &), ImageSize -> Large], d}]
This below is the same code as the above but without using Compile... with the Compile command I didn't know how to took advantage in none of the tested cases so far, because it hasn't changed anything when I made variations of the codes with or without it. How do I use Compile to help solve my problem? Or in this type of problem it has not much use? Same code as the previous one without Compile:
z[k_] := (10^k - 1)
EvaluationData[Parallelize[b1 = Sum[DigitCount[x], {x, 1, z[1]}];
b2 = Sum[DigitCount[x], {x, 1, z[2]}];
b3 = Sum[DigitCount[x], {x, 1, z[3]}];
b4 = Sum[DigitCount[x], {x, 1, z[4]}];
b5 = Sum[DigitCount[x], {x, 1, z[5]}];
b6 = Sum[DigitCount[x], {x, 1, z[6]}];
b7 = Sum[DigitCount[x], {x, 1, z[7]}];
c1 = N[FromDigits[Take[b1, {10}]/Take[b1, {2}]], 11];
c2 = N[FromDigits[Take[b2, {10}]/Take[b2, {2}]], 11];
c3 = N[FromDigits[Take[b3, {10}]/Take[b3, {2}]], 11];
c4 = N[FromDigits[Take[b4, {10}]/Take[b4, {2}]], 11];
c5 = N[FromDigits[Take[b5, {10}]/Take[b5, {2}]], 11];
c6 = N[FromDigits[Take[b6, {10}]/Take[b6, {2}]], 11];
c7 = N[FromDigits[Take[b7, {10}]/Take[b7, {2}]], 11]];
d = {c1, c2, c3, c4, c5, c6, c7};
{ListLinePlot[d,
PlotRange -> {{1, Automatic}, {Automatic, Automatic}},
LabelingFunction -> (#1 &), ImageSize -> Large], d}]
I know I need to learn a lot about these functions (Parallelize, Compile, etc) but if anyone can give a feedback of what I'm doing wrong or some hint of how I can do better I would be very grateful..!
Thank you very much!