Oscar.jl icon indicating copy to clipboard operation
Oscar.jl copied to clipboard

More compact printing

Open joschmitt opened this issue 2 years ago • 9 comments

I'm supposed to give a short talk in the "OSCAR case studies" at the SFB meeting next week and used this opportunity to clean up some of the printing methods. I'm aware that all the doc-tests need to be changed now, but before I do this, I would like to agree on what we want to have. I changed the show methods for the types InvRing, MPolyQuo, MPolyRing_dec and MPolyIdeal. For the latter one I removed this expressify functionality - mostly because I could not get what I want with it. Is there documentation for this somewhere? I'm of course happy to change things to conform with other aesthetic requirements. Here are some impressions of the differences

# master
julia> K, a = CyclotomicField(3);

julia> r = matrix(K, [a 0 0 0; 0 a^-1 0 0; 0 0 a^-1 0; 0 0 0 a]);

julia> s = matrix(K, [ 0 1 0 0; 1 0 0 0; 0 0 0 1; 0 0 1 0 ]);

julia> G = matrix_group(r, s);

julia> RG = invariant_ring(G)
Invariant ring of
Matrix group of degree 4 over K
with generators
AbstractAlgebra.Generic.MatSpaceElem{nf_elem}[[z_3 0 0 0; 0 -z_3-1 0 0; 0 0 -z_3-1 0; 0 0 0 z_3], [0 1 0 0; 1 0 0 0; 0 0 0 1; 0 0 1 0]]

julia> polynomial_ring(RG)
Multivariate Polynomial Ring in x[1], x[2], x[3], x[4] over K graded by 
  x[1] -> [1]
  x[2] -> [1]
  x[3] -> [1]
  x[4] -> [1]

julia> affine_algebra(RG)
(Quotient of Multivariate Polynomial Ring in 7 variables y[1], y[2], y[3], y[4], ..., y[7] over K graded by 
  y[1] -> [2]
  y[2] -> [2]
  y[3] -> [2]
  y[4] -> [3]
  y[5] -> [3]
  y[6] -> [3]
  y[7] -> [3] by ideal(y[1]*y[7] - y[2]*y[6] + y[3]*y[5], y[1]*y[6] - y[2]*y[5] + y[3]*y[4], y[1]*y[4]*y[7] - y[1]*y[5]*y[6] - y[2]*y[4]*y[6] + y[2]*y[5]^2, -4*y[1]*y[3]^2 + y[2]^2*y[3] - y[5]*y[7] + y[6]^2, -4*y[1]*y[2]*y[3] + y[2]^3 - y[4]*y[7] + y[5]*y[6], -4*y[1]^2*y[3] + y[1]*y[2]^2 - y[4]*y[6] + y[5]^2, 4*y[1]^3*y[5]*y[7] - 4*y[1]^3*y[6]^2 - y[1]^2*y[2]*y[4]*y[7] + y[1]^2*y[2]*y[5]*y[6] + y[4]^2*y[6]^2 - 2*y[4]*y[5]^2*y[6] + y[5]^4, -y[1]^3*y[4]*y[6]*y[7] + 4*y[1]^3*y[5]^2*y[7] - 3*y[1]^3*y[5]*y[6]^2 - y[1]^2*y[2]*y[4]*y[5]*y[7] + y[1]^2*y[2]*y[4]*y[6]^2 + y[4]^2*y[5]*y[6]^2 - 2*y[4]*y[5]^3*y[6] + y[5]^5, 5*y[1]^3*y[4]*y[5]*y[6]*y[7] - 4*y[1]^3*y[4]*y[6]^3 - 4*y[1]^3*y[5]^3*y[7] + 3*y[1]^3*y[5]^2*y[6]^2 - y[1]^2*y[2]*y[4]^2*y[6]*y[7] + y[1]^2*y[2]*y[4]*y[5]^2*y[7] + y[4]^3*y[6]^3 - 3*y[4]^2*y[5]^2*y[6]^2 + 3*y[4]*y[5]^4*y[6] - y[5]^6), Map with following data
Domain:
=======
Quotient of Multivariate Polynomial Ring in 7 variables y[1], y[2], y[3], y[4], ..., y[7] over K graded by 
  y[1] -> [2]
  y[2] -> [2]
  y[3] -> [2]
  y[4] -> [3]
  y[5] -> [3]
  y[6] -> [3]
  y[7] -> [3] by ideal(y[1]*y[7] - y[2]*y[6] + y[3]*y[5], y[1]*y[6] - y[2]*y[5] + y[3]*y[4], y[1]*y[4]*y[7] - y[1]*y[5]*y[6] - y[2]*y[4]*y[6] + y[2]*y[5]^2, -4*y[1]*y[3]^2 + y[2]^2*y[3] - y[5]*y[7] + y[6]^2, -4*y[1]*y[2]*y[3] + y[2]^3 - y[4]*y[7] + y[5]*y[6], -4*y[1]^2*y[3] + y[1]*y[2]^2 - y[4]*y[6] + y[5]^2, 4*y[1]^3*y[5]*y[7] - 4*y[1]^3*y[6]^2 - y[1]^2*y[2]*y[4]*y[7] + y[1]^2*y[2]*y[5]*y[6] + y[4]^2*y[6]^2 - 2*y[4]*y[5]^2*y[6] + y[5]^4, -y[1]^3*y[4]*y[6]*y[7] + 4*y[1]^3*y[5]^2*y[7] - 3*y[1]^3*y[5]*y[6]^2 - y[1]^2*y[2]*y[4]*y[5]*y[7] + y[1]^2*y[2]*y[4]*y[6]^2 + y[4]^2*y[5]*y[6]^2 - 2*y[4]*y[5]^3*y[6] + y[5]^5, 5*y[1]^3*y[4]*y[5]*y[6]*y[7] - 4*y[1]^3*y[4]*y[6]^3 - 4*y[1]^3*y[5]^3*y[7] + 3*y[1]^3*y[5]^2*y[6]^2 - y[1]^2*y[2]*y[4]^2*y[6]*y[7] + y[1]^2*y[2]*y[4]*y[5]^2*y[7] + y[4]^3*y[6]^3 - 3*y[4]^2*y[5]^2*y[6]^2 + 3*y[4]*y[5]^4*y[6] - y[5]^6)
Codomain:
=========
Multivariate Polynomial Ring in x[1], x[2], x[3], x[4] over K graded by 
  x[1] -> [1]
  x[2] -> [1]
  x[3] -> [1]
  x[4] -> [1])
# this branch
julia> K, a = CyclotomicField(3);

julia> r = matrix(K, [a 0 0 0; 0 a^-1 0 0; 0 0 a^-1 0; 0 0 0 a]);

julia> s = matrix(K, [ 0 1 0 0; 1 0 0 0; 0 0 0 1; 0 0 1 0 ]);

julia> G = matrix_group(r, s);

julia> RG = invariant_ring(G)
Invariant ring of
G
with coefficient ring
K

julia> polynomial_ring(RG)
Multivariate Polynomial Ring in x[1], x[2], x[3], x[4] over K
graded by 
Abelian group with structure: Z
via
x[1] -> [1], x[2] -> [1], x[3] -> [1], x[4] -> [1]

julia> affine_algebra(RG)
(Quotient of
===========
Multivariate Polynomial Ring in 7 variables y[1], y[2], y[3], y[4], ..., y[7] over K
graded by 
Abelian group with structure: Z
via
y[1] -> [2], y[2] -> [2], y[3] -> [2], y[4] -> [3], ..., y[7] -> [3]

by the ideal
============
Ideal with 9 generators, Map with following data
Domain:
=======
Quotient of
===========
Multivariate Polynomial Ring in 7 variables y[1], y[2], y[3], y[4], ..., y[7] over K
graded by 
Abelian group with structure: Z
via
y[1] -> [2], y[2] -> [2], y[3] -> [2], y[4] -> [3], ..., y[7] -> [3]

by the ideal
============
Ideal with 9 generators
Codomain:
=========
Multivariate Polynomial Ring in x[1], x[2], x[3], x[4] over K
graded by 
Abelian group with structure: Z
via
x[1] -> [1], x[2] -> [1], x[3] -> [1], x[4] -> [1])

joschmitt avatar Sep 13 '22 14:09 joschmitt

I was just playing around with abbreviations, and was wondering: can @thofma can get this :sizelimit into the global stdout?

julia> R,(x,y,z) = QQ["x","y","z"]
(Multivariate Polynomial Ring in x, y, z over Rational Field, fmpq_mpoly[x, y, z])

julia> i = ideal([x, y, z])
ideal(x, y, z)

julia> show(stdout, i^6)
ideal(x^6, x^5*y, x^5*z, x^4*y^2, x^4*y*z, x^4*z^2, x^3*y^3, x^3*y^2*z, x^3*y*z^2, x^3*z^3, x^2*y^4, x^2*y^3*z, x^2*y^2*z^2, x^2*y*z^3, x^2*z^4, x*y^5, x*y^4*z, x*y^3*z^2, x*y^2*z^3, x*y*z^4, x*z^5, y^6, y^5*z, y^4*z^2, y^3*z^3, y^2*z^4, y*z^5, z^6)

julia> show(IOContext(stdout, :size_limit=>10), i^6)
ideal(x^6, ..., y*z^5, z^6)

tthsqe12 avatar Sep 13 '22 15:09 tthsqe12

@tthsqe12 No, thankfully no one can do this.

I don't understand why we would want to hide generators of ideals by default. Was there some discussion I missed?

thofma avatar Sep 13 '22 15:09 thofma

Okay, so what I have here is probably not what we want (at least for the MPolyIdeals). But I think it would be good if there were a more compact printing of the ideals when they come as "substructures", so as a modulus of a quotient ring for example.

joschmitt avatar Sep 13 '22 16:09 joschmitt

I understand that affine_algebra(RG) looks really awkward. In particular since the return value is a tuple. One option is to make the quotient algebras print compactly in one line (same for the map) when it appears in a Tuple. So we would do something like the following:

julia> A = [1 2; 3 4]
2×2 Matrix{Int64}:
 1  2
 3  4

julia> (A, A)
([1 2; 3 4], [1 2; 3 4])

For example we can make it behave as follows:

julia> A, m = affine_algebra(QG)
(Quotient ring of Z-graded multivariate polynomial ring in 7 variables, Map)

(not sure if we can get the Z and maybe Map is a bit too compact). And then

julia> A
[...]

would give you what we have now.

What do you think?

thofma avatar Sep 13 '22 17:09 thofma

Yes, I think this would be much better. I still find the way MPolyIdeals are printed, i.e. ideal(x, y), quite awkward. I would prefer something like Ideal generated by x, y. Or do we also want to include the base ring?

joschmitt avatar Sep 13 '22 17:09 joschmitt

I am very much in favour of compact writing. In particular, words like AbstractAlgebrsa Hecke etc should disappear. In the example above, -- (Quotient ring of Z-graded multivariate polynomial ring in 7 variables, Map),-- one should see the general picture: what do you write if the grading is given by a more general abelian group? So, should we omit the Z-??? Also, I would write projection map instead of Map.

In general, it would be great if we could switch to compact printing everywhere ...

wdecker avatar Sep 13 '22 18:09 wdecker

A general remark: I am extremely unhappy with the idea of moving to this:

julia> G = matrix_group(r, s);

julia> RG = invariant_ring(G)
Invariant ring of
G
with coefficient ring
K

and in general greatly dislike the whole functionality where we "guess" names of objects based on variables defined in the REPL. It may look "cool" in demos, and may seem useful in strictly localized use. But in larger session it just is source of confusion when variables get overwritten later on and object reassigned etc.

So personally I'd prefer to see use this feature less, not more, and I've argued in this vein just today with regards to printing of chain complexes.

fingolfin avatar Sep 13 '22 21:09 fingolfin

Just to record the state of this pull request: should NOT be merged. Once we reached a consensus regarding the discussion in #1540 , I'm happy to implement that solution for the show functions I wanted to change here.

joschmitt avatar Sep 15 '22 06:09 joschmitt

@tthsqe12 No, thankfully no one can do this.

I don't understand why we would want to hide generators of ideals by default. Was there some discussion I missed?

For the same reason that I do not want a 1000 x 1000 matrix fully printed. It is not human readable. The same is true for most ideals in commutative algebra.

simonbrandhorst avatar Oct 05 '22 14:10 simonbrandhorst

I close this now since it's probably easier to start fresh for the new printing guidelines #2148 , see #2166 .

joschmitt avatar Mar 30 '23 21:03 joschmitt