Menu

#3893 display2d and long numbers

None
closed
nobody
5
2022-02-08
2021-11-30
Kirill
No

Dear Maxima community
It looks like the linel option stops working if the display2d flag is set to false and large numbers are used.
I’m ready to accept that the break is happening in the wrong place, but I really miss the line break character (backslash), since its absence makes it difficult to parse the maxima output.

(%i1) linel;
(%o1)                                 79
(%i2) display2d;
(%o2)                                true
(%i3) (x + 1) / (x^2 + 2^300);
                2
(%o3) (x + 1)/(x  + 2037035976334486086268445688409378161051468393665936250636\
140449354381299763336706183397376)
(%i4) linel: 40;
(%o4)              40
(%i5) (x + 1) / (x^2 + 2^300);
                2
(%o5) (x + 1)/(x  + 2037035976334486086\
268445688409378161051468393665936250636\
140449354381299763336706183397376)
(%i6) linel: 79;
(%o6)                                 79
(%i7) display2d: false;

(%o7) false
(%i8) (x + 1) / (x^2 + 2^300);

(%o8) (x+1)/(x^2+2037035976334486086268445688409378161051468393665936250636140449354381299763336706183397376)
(%i9) linel: 40;

(%o9) 40
(%i10) (x + 1) / (x^2 + 2^300);

(%o10) (x+1)/(x^2+2037035976334486086268445688409378161051468393665936250636140449354381299763336706183397376)
(%i11) linel: 10;

(%o11) 10
(%i12) (x + 1) / (x^2 + 2^300);

(%o12) (x+1)
 /(x^2
  +2037035976334486086268445688409378161051468393665936250636140449354381299763336706183397376)
Maxima version: "5.43.2"
Maxima build date: "2020-02-21 05:22:38"
Host type: "x86_64-pc-linux-gnu"
Lisp implementation type: "GNU Common Lisp (GCL)"
Lisp implementation version: "GCL 2.6.12"
User dir: "/home/kikke/.maxima"
Temp dir: "/tmp"
Object dir: "/home/kikke/.maxima/binary/5_43_2/gcl/GCL_2_6_12"
Frontend: false

Thanks in advance.

Discussion

  • Stavros Macrakis

    As far as I can tell, with display2d:false, the printer never inserts a newline in the middle of a token (symbol, number, or string), so I don't see how a break can "happen[] in the wrong place" -- but linel continues to force line breaks between tokens.

    Since the printer starts each new line with a space, you can just concatenate all the output to parse it. I'm not sure what the value of a backslash character would be since one is essentially implicit at the end of every line.

    Is this a bug? The documentation isn't explicit enough to say....

     
    • Kirill

      Kirill - 2021-11-30

      Thanks for your reply.
      It would be nice if a comment about the lack of a line break in the middle of the token would be added to the documentation to the description of the display2d: false option. Then it will definitely not be a bug =)
      I think the ticket can be closed

       
  • Gunter Königsmann

    wxMaxima can be configured to add line breaks to long numbers. If that is the case a right-click on such a number will allow to select any of the other options.

     
  • Stavros Macrakis

    • labels: linel, display2d --> linel, display2d, Documentation
     
  • Robert Dodier

    Robert Dodier - 2021-11-30

    It seems kind of inconsistent that linel is applied to atoms when display2d is enabled and not otherwise ... it seems like disabling display2d is more likely a situation in which one would like a fixed line width. What does anyone think about that? Kirill, what were you trying to do when you bumped into linel?

     
    • Kirill

      Kirill - 2022-02-06

      I have a C++ program that sometimes has coefficients (fractions with polynomials), which need to be simplified. It uses fork and execl to start simplifier programs to which it sends the coefficients to stdin and reads stdout. And I'm trying to use Maxima to do this. From the documentation I realized that I need to use the flags ratsimpexpons:true; display2d:false; stardisp:true; nolabels:true; and the ratsimp function. Now I'm running Maxima with the --very-quiet flag so that labels are not displayed in stdout, but two problems appear:
      1) Due to the interactive mode, Maxima writes not only simplified coefficient to stdout, but also the original one.
      2) Even if the problem 1) is resolved, it is still difficult to understand at what point the simplified coefficient ends. Adding the prefix I set to all the results of ratsimp would solve this problem. And with using linel I tried to solve 2) the problem.
      Are there any ways to solve my problems with Maxima?
      Thanks in advance.

       
      • Robert Dodier

        Robert Dodier - 2022-02-08

        Kirill, I don't understand the problems (1) and (2) you mentioned. Here is an example input,

        display2d: false $
        linel: 1000000 $
        expand ((x - y - z)^10);
        

        Let's say that's in a file named /tmp/foo.mac. Then when I say

        $ cat /tmp/foo.mac | maxima --very-quiet
        

        then the output is just the one long line,

        z^10+10*y*z^9-10*x*z^9+45*y^2*z^8-90*x*y*z^8+45*x^2*z^8+120*y^3*z^7-360*x*y^2*z^7+360*x^2*y*z^7-120*x^3*z^7+210*y^4*z^6-840*x*y^3*z^6+1260*x^2*y^2*z^6-840*x^3*y*z^6+210*x^4*z^6+252*y^5*z^5-1260*x*y^4*z^5+2520*x^2*y^3*z^5-2520*x^3*y^2*z^5+1260*x^4*y*z^5-252*x^5*z^5+210*y^6*z^4-1260*x*y^5*z^4+3150*x^2*y^4*z^4-4200*x^3*y^3*z^4+3150*x^4*y^2*z^4-1260*x^5*y*z^4+210*x^6*z^4+120*y^7*z^3-840*x*y^6*z^3+2520*x^2*y^5*z^3-4200*x^3*y^4*z^3+4200*x^4*y^3*z^3-2520*x^5*y^2*z^3+840*x^6*y*z^3-120*x^7*z^3+45*y^8*z^2-360*x*y^7*z^2+1260*x^2*y^6*z^2-2520*x^3*y^5*z^2+3150*x^4*y^4*z^2-2520*x^5*y^3*z^2+1260*x^6*y^2*z^2-360*x^7*y*z^2+45*x^8*z^2+10*y^9*z-90*x*y^8*z+360*x^2*y^7*z-840*x^3*y^6*z+1260*x^4*y^5*z-1260*x^5*y^4*z+840*x^6*y^3*z-360*x^7*y^2*z+90*x^8*y*z-10*x^9*z+y^10-10*x*y^9+45*x^2*y^8-120*x^3*y^7+210*x^4*y^6-252*x^5*y^5+210*x^6*y^4-120*x^7*y^3+45*x^8*y^2-10*x^9*y+x^10
        

        I don't see the input being echoed.

        About (2), I don't understand what you mean about not knowing where the coefficient ends. Can you make linel very large and then just read the output from one line?

        My advice at this point is to open a new bug report and paste in an example input and output to illustrate what you are seeing. Please create a new bug report, since that will help us focus on the new issues.

         
  • Stavros Macrakis

    I don't think it matters. It's not as though anyone is using TTY33's where excess characters pile up on the right margin.

    Not breaking has the advantage that any process that consumes the output doesn't need to know what convention Maxima follows for continuation lines.

    Let's just document the behavior (as the OP suggests) and move on.

     
  • Robert Dodier

    Robert Dodier - 2021-12-03
    • status: open --> closed
     
  • Robert Dodier

    Robert Dodier - 2021-12-03

    Fixed by commit 758816, closing this report.

    As discussed here, I updated the description of display2d to say how it interacts with linel. The behavior is actually not entirely consistent, but as we were saying, let it stand for now. I put in the following paragraphs, which are shown by ? display2d:

    +When @code{display2d} is @code{true},
    +Maxima attempts to honor the global variable for line length, @code{linel}.
    +When an atom (symbol, number, or string) would otherwise cause a line to exceed @code{linel},
    +the atom may be printed in pieces on successive lines,
    +with a continuation character (backslash, @code{\}) at the end of the leading piece;
    +however, in some cases, such atoms are printed without a line break,
    +and the length of the line is greater than @code{linel}.
    
    +When @code{display2d} is @code{false},
    +Maxima attempts to honor @code{linel},
    +but atoms are not broken across lines,
    +and the actual length of an output line may exceed @code{linel}.
    
     
  • Robert Dodier

    Robert Dodier - 2021-12-03

    Kirill, if you want to ensure that lines are exactly a certain length, the only way which I have found to ensure that is by setting display2d: true and then saying string(expr);. E.g.,

    (%i1) linel: 40 $
    (%i2) display2d;
    (%o2)             true
    (%i3) string ((x + 1) / (x^2 + 2^300));
    (%o3) (x+1)/(x^2+2037035976334486086268\
    445688409378161051468393665936250636140\
    449354381299763336706183397376)
    

    If you want to save stuff in a file, you could try something like with_stdout("foo.out", print(string(expr)));

    I found that whenexpr is very large, then the above procedure is surprisingly slow. I didn't figure out where is the bottleneck -- in string, print, with_stdout ? I don't know.

     

Log in to post a comment.