toString

12 views
Skip to first unread message

Doug

unread,
Aug 14, 2025, 12:20:55 PMAug 14
to Macaulay2
When I'm running examples to decide how to automate computations, I find myself having to type a semi-colon followed by toString on just about every line to defeat M2's desire to print exponents on a separate line, when I want something I can cut and paste into a new input line instead. Is there any way to get Macaulay 2 to default print strings to the screen?

Doug Leonard

Doug Torrance

unread,
Aug 14, 2025, 3:17:38 PMAug 14
to Macaulay2
One way to accomplish this would be to redefine the "net" method (which is called when printing) for the given ring to just be "toString".  For example:

i1 : R = QQ[x,y,z]

o1 = R

o1 : PolynomialRing

i2 : net R := toString

o2 = toString

o2 : MethodFunctionSingle

i3 : random(2, R)

o3 = 8*x^2+(6/5)*x*y+(2/7)*y^2+3*x*z+(9/2)*y*z+(4/7)*z^2

o3 : R

Douglas Leonard

unread,
Aug 14, 2025, 3:53:32 PMAug 14
to maca...@googlegroups.com
That's great. 

But I'm dealing with a nested string of maybe 20 or so rings. Can I set this once at the beginning of a session so that it applies to any ring I define?

Doug Leonard

From: maca...@googlegroups.com <maca...@googlegroups.com> on behalf of Doug Torrance <douglas.a...@gmail.com>
Sent: Thursday, August 14, 2025 2:17 PM
To: Macaulay2 <maca...@googlegroups.com>
Subject: [Macaulay2] Re: toString
 
--
You received this message because you are subscribed to the Google Groups "Macaulay2" group.
To unsubscribe from this group and stop receiving emails from it, send an email to macaulay2+...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/macaulay2/f3c3f1a3-fe9d-4f9b-b8dc-e0fedb67bb58n%40googlegroups.com.

Doug Torrance

unread,
Aug 14, 2025, 3:59:44 PMAug 14
to Macaulay2
One way to do that would be to override "net" for various subclasses of Expression.  I think Power (to fix exponents), Product (so we get * after coefficients) and Divide (for rational coefficients) should be sufficient.  So something like:

i1 : net Power := net Product := net Divide := toString

o1 = toString

o1 : MethodFunctionSingle

i2 : R = QQ[x,y]; S = QQ[z,w];

i4 : random(2, R)

o4 = (12/7)*x^2 + (3/10)*x*y + (23/6)*y^2

o4 : R

i5 : random(2, S)

o5 = (79/9)*z^2 + (22/3)*z*w + (39/4)*w^2

o5 : S


Douglas Leonard

unread,
Aug 14, 2025, 5:36:50 PMAug 14
to maca...@googlegroups.com
That seems to work.
I had to do Subscript as well;
but I don't know how to supress the rows of of hyphens
Produced when a list is longer than one line. 

Doug Leonard

Sent: Thursday, August 14, 2025 2:59 PM
To: Macaulay2 <maca...@googlegroups.com>
Subject: Re: [Macaulay2] Re: toString
 

Doug Torrance

unread,
Sep 1, 2025, 11:33:08 AMSep 1
to Macaulay2
The "printWidth" variable controls when we wrap the output.  If it's set to 0, then we don't wrap at all.  For example:

i1 : R = ZZ/2[x_0..x_50];

i2 : random(1, R)

o2 = x  + x  + x  + x  + x   + x   + x   + x   + x   + x   + x   + x   + x   +
      1    2    5    6    10    11    13    14    16    18    20    21    23  
     --------------------------------------------------------------------------
     x   + x   + x   + x   + x   + x   + x   + x   + x   + x   + x   + x   +
      25    27    29    30    31    35    36    41    42    43    44    45  
     --------------------------------------------------------------------------
     x   + x
      47    50

o2 : R

i3 : printWidth = 0

o3 = 0

i4 : random(1, R)

o4 = x  + x  + x  + x   + x   + x   + x   + x   + x   + x   + x   + x   + x   + x   + x   + x   + x   + x   + x   + x   + x   + x   + x   + x   + x   + x   + x   + x
      0    5    7    11    13    14    15    17    19    21    22    25    26    27    28    29    31    33    35    38    39    40    42    43    46    47    49    50

o4 : R
Reply all
Reply to author
Forward
0 new messages