Group Abstract Group Abstract

Message Boards Message Boards

1
|
7.2K Views
|
15 Replies
|
6 Total Likes
View groups...
Share
Share this post:

Problem with printing many solutions V10

Posted 12 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.

POSTED BY: Paul Cleary
15 Replies

Sorry about that... it was a copy/paste error from a test cell. I updated/edited it out in the code above now. ;-)

POSTED BY: David Reiss
Posted 12 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 BY: Douglas Kubler

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 BY: David Reiss
Posted 12 years ago
POSTED BY: Paul Cleary
Posted 12 years ago
POSTED BY: Paul Cleary
Posted 12 years ago
POSTED BY: Paul Cleary
Posted 12 years ago

Yes very nice, your revised version works ok now, I will definitely look at that in more depth.

POSTED BY: Paul Cleary
Posted 12 years ago

Very nice. MakeBoxes has a small problem. Gets a message "An improperly formatted directive with head Cell was encountered."

POSTED BY: Douglas Kubler
Posted 12 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 BY: Paul Cleary

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 BY: David Reiss
Posted 12 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 BY: Douglas Kubler
Posted 12 years ago

Hi Douglas

That 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 BY: Paul Cleary
Posted 12 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 BY: Douglas Kubler

Why don't you use Table instead of Reap and Sow?

POSTED BY: Frank Kampas

I think you're not seeing any solutions until the calculation is done because you're using Reap and Sow.

POSTED BY: Frank Kampas
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard