Closed simon-king-jena closed 16 years ago
As i mentioned, pmat
(in Singular's inout.lib
) may help. However, up to now, this function did only display a matrix on screen (it had no return value!), and if a polynomial was truncated, the user hasn't been notified.
I just changed pmat
in Singular's cvs repository. Now, it returns a string, truncations are made visible, and the column separator now is ", " (before, it was sometimes " " and sometimes ",").
I don't know if the rest of the Singular team accepts this change (after all, a change from "no return" to "return a string" is non-trivial). If this is the case, i think using pmat
in the method __str__
(and perhaps __repr__
) for SingularElement
s of type matrix
, choosing the parameter so that the matrix fits on screen, may help to close this ticket.
Examples using the new pmat:
sage: singular.LIB("inout.lib")
sage: R=singular.ring(0,'(x,y,z)','dp')
sage: I=singular.ideal('x','z+3y','x+y','z')
sage: M=(I^2).matrix(3,3)
sage: M
x^2, 3*x*y+x*z, x^2+x*y,
x*z, 9*y^2+6*y*z+z^2,3*x*y+3*y^2+x*z+y*z,
3*y*z+z^2,x^2+2*x*y+y^2, x*z+y*z
sage: M.pmat()
x^2, 3*x*y+x*z, x^2+x*y,
x*z, 9*y^2+6*y*z+z^2, 3*x*y+3*y^2+x*z+y*z,
3*y*z+z^2, x^2+2*x*y+y^2, x*z+y*z
# note the additional blanc space; i find it nicer this way.
sage: M.pmat(7)
x^2, 3*x*y.., x^2+x*y,
x*z, 9*y^2.., 3*x*y..,
3*y*z.., x^2+2.., x*z+y*z
# Now it is clear which polynomials are truncated and which are not!
Is the change in the newest Singular upstream? If so, we can make use of it. If not, we should wait for it to hit the official Singular release.
Replying to @malb:
Is the change in the newest Singular upstream? If so, we can make use of it. If not, we should wait for it to hit the official Singular release.
I realize that we still didn't finish to work on it.
Yes, it is in the official release, and the above example
sage: M.pmat(7)
x^2, 3*x*y.., x^2+x*y,
x*z, 9*y^2.., 3*x*y..,
3*y*z.., x^2+2.., x*z+y*z
is now the standard behaviour.
Attachment: SingularMatrix.patch.gz
Try to avoid autogenerated names when printing pexpect objects
Printing Singular matrices relies on some __repr__
method from expect.py
. I changed it as follows:
SingularElement
of type matrix then try pmat
Hence, my patch changes the usual behaviour only if either the object has a custom name, or it happens to be a singular matrix, in which case the polynomials will be cut by default after 20 characters.
Hence, the example is like this, which i think is an improvement:
sage: R=singular.ring(7,'(x(1..2))','dp')
sage: M=singular.matrix(1,3,'x(1)^7*x(2)-x(1)*x(2)^7,x(1)^12-2*x(1)^9*x(2)^3-x(1)^6*x(2)^6+2*x(1)^3*x(2)^9+x(2)^12,x(1)^18+2*x(1)^15*x(2)^3+3*x(1)^12*x(2)^6+3*x(1)^6*x(2)^12-2*x(1)^3*x(2)^15+x(2)^18')
sage: M
x(1)^7*x(2)-x(1)*x.., x(1)^12-2*x(1)^9*x.., x(1)^18+2*x(1)^15*..
sage: M.rename('T')
sage: M
x(1)^7*x(2)-x(1)*x(2)^7,T[1,2],T[1,3]
Certainly the "cut point" (now 20 characters) could be customized. Any suggestions how this should be done?
fixes issues found in review
Attachment: trac_1300_fixup.patch.gz
Review
expect.py
is not the right place for Singular specific interface issue, thus it should be moved code to singular.py
(done in attached patch).I'll give Simon's patch a positive review if my patch is applied afterwards. So my patch needs a review.
Replying to @malb:
Review
- no doctest was added to demonstrate the new behavior (added in attached patch)
expect.py
is not the right place for Singular specific interface issue, thus it should be moved code tosingular.py
(done in attached patch).I'll give Simon's patch a positive review if my patch is applied afterwards. So my patch needs a review.
I agree with you that the __repr__
method in expect.py
should be overwritten with a method in singular.py
. The doc test shows one the new feature for Singular matrices. Also, doc tests pass.
So, up to here, i give Martin's patch a positive review.
However, one new feature for the __repr__
method (custom names) is not in the doc tests. Therefore i'll create another patch, with an additional doc test.
Attachment: SingularMatrixMoreTest.patch.gz
slight layout fixups
I edited Simon's patch to match Sage's undocumented docstring style. Positive review.
Merged SingularMatrix.patch, trac_1300_fixup.patch and SingularMatrixMoreTest.patch in Sage 3.1.2.alpha0
When Singular prints a matrix M then it tries to keep the row-column structure of M visible on screen. If this is impossible (for large polynomials), the entries are abbreviated:
The Singular developers have good reasons for it and wouldn't like to change it.
Unfortunate consequence for Sage: Creating this matrix via the Singular interface, it is assigned an automatically generated name; printing it, Singular uses that name, that the user probably is not aware of:
I believe it is confusing for the user to be confronted with variable names that he/she has not defined him/herself. Therefore i think the printing of Singular-matrices in Sage should be customized.
Remarks
SingularElement.__str__
.sage1
in the example above) by the user-defined name (M
in the example above). In that way, one has an output that preserves the shape of the matrix but reduces confusion of the user by cryptic variable names.In the following, i show several ways to continue the Singular-example above, which may provide a nicer printing.
The first shows everything without abbreviation, even though this destroys the visible matrix shape. The latter shows at most the leading 15 letters of each column, which is another form of abbreviation. However, for the last two polynomials, it is impossible to guess whether they are abbreviated or not!
I think this is a solution that could almost be adopted by Sage. However, IMHO, the user
__must__
be alerted about the presence of an abbreviation, e.g., by appending '...
' if there has been an abbreviation. So, the following output would be clearer:This is not good, since this doesn't show the shape of the matrix and, called via the interface, would again show the automatically generated variable name.
This shows a definition of the matrix, but the shape is invisible
Sorry for such long description of a minor problem.
CC: @malb
Component: commutative algebra
Keywords: Singular matrix
Issue created by migration from https://trac.sagemath.org/ticket/1300