1
|
6302 Views
|
15 Replies
|
6 Total Likes
View groups...
Share
GROUPS:

Problem with printing many solutions V10

Posted 10 years ago
 Hi everyone Since I moved up to V10 I am finding the amount of work I can do is diminishing due to the way V10 seems to work, this is the major problem that seems to cause the most headache. If as a result of a computation there are many solutions and I wish to print them on screen, (many as in more than a thousand) Mathematica doesn't start printing until all solutions have been found, then it prints them out, you can see it is printing as the scroll bar on the right of the window starts to move but the screen remains empty until it has finished. To me this is not acceptable as many times I set something going not knowing there are going to be many solutions, the screen then goes blank, I don't know where it is in the computation so I can fine tune it because its not printing anything. using abort etc is useless as it has already sent many solutions to the print cue and until that has finished you might as well forget it. It is now time to re-boot as the only way to stop it. So is anyone else finding the same? Here is a small example where because there are over 5000 solutions the screen remains blank until all have been found. a = Range[2000]; b = Subsets[a, {2}]^3; list = Reap[Do[Sow[{b[[q]], Total[b[[q]]]}], {q, 1, Length[b]}]]; list = list[[2]]; list = Partition[Flatten[list], 3]; list = SortBy[list, #[[3]] &]; Do[If[list[[q, 3]] == list[[q + 1, 3]], Print[TextCell[ Row[{ExpressionCell[Power[list[[q, 1]], (3)^-1]]^3, "+", ExpressionCell[Power[list[[q, 2]], (3)^-1]]^3, " = ", ExpressionCell[Power[list[[q + 1, 1]], (3)^-1]]^3, "+", ExpressionCell[Power[list[[q + 1, 2]], (3)^-1]]^3, " = ", ExpressionCell[list[[q, 3]]]}]]]], {q, 1, Length[list] - 1}] // Timing  Paul.
15 Replies
Sort By:
Posted 10 years ago
 I think you're not seeing any solutions until the calculation is done because you're using Reap and Sow.
Posted 10 years ago
 HI FrankI could have also used AppendTo[list, ], but in the end I still have a list. I then look through the list with the Do loop and when it finds a solution I ask it to print, If there were only a few in the list no matter how big that list was it would print them on the screen as it gets to them, but when there are many it doesn't. I have just amended that program to print when it finds 2 numbers that are separated quite far in the list and sure enough as it gets to them they print out, if you change this bit Do[If[list[[q, 3]] == list[[q + 1, 3]] to list[[q, 3]] == 1171143792 || list[[q, 3]] == 8901458055you will see what I mean.Paul.
Posted 10 years ago
 Why don't you use Table instead of Reap and Sow?
Posted 10 years ago
 The program has completed all calculations before the Print[] statement unless you want to call the Do[] a calculation.To slow down the output stream so you have a chance to kill the print stream insert a Pause[]. a = Range[2000]; b = Subsets[a, {2}]^3; list = Reap[Do[Sow[{b[[q]], Total[b[[q]]]}], {q, 1, Length[b]}]]; list = list[[2]]; list = Partition[Flatten[list], 3]; list = SortBy[list, #[[3]] &]; Do[If[list[[q, 3]] == list[[q + 1, 3]], Pause[0.1]; Print[TextCell[ Row[{ExpressionCell[Power[list[[q, 1]], (3)^-1]]^3, "+", ExpressionCell[Power[list[[q, 2]], (3)^-1]]^3, " = ", ExpressionCell[Power[list[[q + 1, 1]], (3)^-1]]^3, "+", ExpressionCell[Power[list[[q + 1, 2]], (3)^-1]]^3, " = ", ExpressionCell[list[[q, 3]]]}]]]], {q, 1, Length[list] - 1}] // Timing 
Posted 10 years ago
 Ok I have made the list using Table, the section of program that looks through the list and finds solutions still waits till it has found all solutions first before it prints them out. list = Table[{i^3, j^3, i^3 + j^3}, {i, 1, 1000}, {j, i + 1, 1000}]; list = Partition[Flatten[list], 3]; list = SortBy[list, #[[3]] &]; Do[If[list[[q, 3]] == list[[q + 1, 3]], Print[TextCell[ Row[{ExpressionCell[list[[q, 1]]]^3, "+", ExpressionCell[list[[q, 2]]]^3, " = ", ExpressionCell[list[[q + 1, 1]]]^3, "+", ExpressionCell[list[[q + 1, 2]]]^3, " = ", ExpressionCell[list[[q, 3]]]}]]]], {q, 1, Length[list] - 1}] // Timing That is smaller than the previous program but still shows the effect. just do this simple program and see if it delay prints. Do[Print[n, " ", n^2], {n, 1, 1000}] even that waits till its finished all 1000 before it prints the first. That's my concern if i was to say print 1 to 1000000 it wouldn't print anything till all had been done in memory first.Paul
Posted 10 years ago
 Hi DouglasThat might be a solution, however, I never had this problem with V9, it would happily print as soon as it got a solution no matter how many were still to be printed. Its the printing on screen as it encounters a solution is my concern, it just doesn't print anything.Paul.
Posted 10 years ago
 There is no delay in printing Do[Print[n, " ", n^2], {n, 1, 10000}] for me in Version 10 on OSX.By the way you might be better off be using CellPrint rather than Print when printing a formatted Cell though this has nothing to do with the other issues you are observing on your system. For me, your code, list = Table[{i^3, j^3, i^3 + j^3}, {i, 1, 1000}, {j, i + 1, 1000}]; list = Partition[Flatten[list], 3]; list = SortBy[list, #[[3]] &]; Do[If[list[[q, 3]] == list[[q + 1, 3]], Print[TextCell[ Row[{ExpressionCell[list[[q, 1]]]^3, "+", ExpressionCell[list[[q, 2]]]^3, " = ", ExpressionCell[list[[q + 1, 1]]]^3, "+", ExpressionCell[list[[q + 1, 2]]]^3, " = ", ExpressionCell[list[[q, 3]]]}]]]], {q, 1, Length[list] - 1}] also startes to print out results almost immediately upon execution...
Posted 10 years ago
 Hi Paul,The code is a solution to your problem of too much output too fast. I guess M10 is more efficient than M9. An alternative solution is to make the program self-regulating, i.e. count the solutions before printing anything. If there are too many, Abort[].Douglas
Posted 10 years ago
 I found that CellPrint does not group the output as Print does. The result is that to delete many many cells it's easier to copy the code and delete the entire notebook.
Posted 10 years ago
 Here is an approach which will put your output results into a new notebook, saving you the need to do select and delete in your original notebook:  nb = CreateWindow[]; list = Table[{i^3, j^3, i^3 + j^3}, {i, 1, 100}, {j, i + 1, 100}]; list = Partition[Flatten[list], 3]; list = SortBy[list, #[[3]] &]; Do[If[list[[q, 3]] == list[[q + 1, 3]], SelectionMove[nb, After, Notebook]; NotebookWrite[nb, ToBoxes[TextCell[ Row[{ExpressionCell[list[[q, 1]]]^3, "+", ExpressionCell[list[[q, 2]]]^3, " = ", ExpressionCell[list[[q + 1, 1]]]^3, "+", ExpressionCell[list[[q + 1, 2]]]^3, " = ", ExpressionCell[list[[q, 3]]]}], "Text"]]]], {q, 1, Length[list] - 1}] 
Posted 10 years ago
 Pause of 0.05 seems to be usable, any smaller and it runs away again causing the mouse to disappear when inside the notebook, until it has finished.
Posted 10 years ago
 Very nice. MakeBoxes has a small problem. Gets a message "An improperly formatted directive with head Cell was encountered."
Posted 10 years ago
 Sorry about that... it was a copy/paste error from a test cell. I updated/edited it out in the code above now. ;-)
Posted 10 years ago
 Yes very nice, your revised version works ok now, I will definitely look at that in more depth.
Posted 10 years ago
 Just noticed a slight error in the code, here is a revised version, it needed a cube root inserting. nb = CreateWindow[]; list = Table[{i^3, j^3, i^3 + j^3}, {i, 1, 100}, {j, i + 1, 100}]; list = Partition[Flatten[list], 3]; list = SortBy[list, #[[3]] &]; Do[If[list[[q, 3]] == list[[q + 1, 3]], SelectionMove[nb, After, Notebook]; NotebookWrite[nb, ToBoxes[TextCell[ Row[{ExpressionCell[Power[list[[q, 1]], (3)^-1]]^3, "+", ExpressionCell[Power[list[[q, 2]], (3)^-1]]^3, " = ", ExpressionCell[Power[list[[q + 1, 1]], (3)^-1]]^3, "+", ExpressionCell[Power[list[[q + 1, 2]], (3)^-1]]^3, " = ", ExpressionCell[list[[q, 3]]]}], "Text"]]]], {q, 1, Length[list] - 1}] Paul.