Skip to content

Commit

Permalink
Use new is_terse and terse functions (#3690)
Browse files Browse the repository at this point in the history
  • Loading branch information
fingolfin committed May 7, 2024
1 parent 498afce commit 7d7bb9b
Show file tree
Hide file tree
Showing 63 changed files with 178 additions and 184 deletions.
44 changes: 22 additions & 22 deletions docs/src/DeveloperDocumentation/printing_details.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ found in the [Developer Style Guide](@ref).

## Implementing `show` functions

Here is the translation between `:detail`, `one line` and `:supercompact`,
Here is the translation between `:detail`, `one line` and `terse`,
where `io` is an `IO` object (such as `stdout` or an `IOBuffer`):

```
show(io, MIME"text/plain"(), x) # detailed printing
print(io, x) # one line printing
print(IOContext(io, :supercompact => true), x) # supercompact printing
print(terse(io), x) # terse printing
```

For reference, string interpolation `"$(x)"` uses one line printing via `print(io, x)`,
Expand Down Expand Up @@ -49,16 +49,16 @@ function Base.show(io::IO, ::MIME"text/plain", R::NewRing)
end
```

The following is a template for `one line` and `:supercompact` printing.
The following is a template for `one line` and `terse` printing.
```julia
function Base.show(io::IO, R::NewRing)
if get(io, :supercompact, false)
if is_terse(io)
# no nested printing
print(io, "supercompact printing of newring ")
print(io, "terse printing of newring ")
else
# nested printing allowed, preferably supercompact
# nested printing allowed, preferably terse
print(io, "one line printing of newring with ")
print(IOContext(io, :supercompact => true), "supercompact ", base_ring(R))
print(terse(io), "terse ", base_ring(R))
end
end
```
Expand All @@ -71,8 +71,8 @@ QQ

julia> [R,R]
2-element Vector{NewRing}:
one line printing of newring with supercompact QQ
one line printing of newring with supercompact QQ
one line printing of newring with terse QQ
one line printing of newring with terse QQ

```

Expand All @@ -81,7 +81,7 @@ julia> [R,R]
This version needs to be used in case the detailed
printing does not contain newlines.
Then detailed and one line printing agree.
The `if` clause takes care of supercompact printing as well.
The `if` clause takes care of terse printing as well.

```julia
struct NewRing2
Expand All @@ -91,13 +91,13 @@ end
base_ring(R::NewRing2) = R.base_ring

function Base.show(io::IO, R::NewRing2)
if get(io, :supercompact, false)
if is_terse(io)
# no nested printing
print(io, "supercompact printing of newring")
print(io, "terse printing of newring")
else
# nested printing allowed, preferably supercompact
# nested printing allowed, preferably terse
print(io, "I am a new ring and always print in one line " )
print(IOContext(io, :supercompact => true), base_ring(R))
print(terse(io), base_ring(R))
end
end
```
Expand All @@ -111,11 +111,11 @@ julia> [R,R]
I am a new ring and always print in one line Rational Field
I am a new ring and always print in one line Rational Field

julia> print(IOContext(Base.stdout, :supercompact => true) ,R)
supercompact printing of newring
julia> print(terse(Base.stdout) ,R)
terse printing of newring
```

The `supercompact` printing uses an `IOContext` (see [IOContext](https://docs.julialang.org/en/v1/base/io-network/#Base.IOContext) from
The `terse` printing uses an `IOContext` (see [IOContext](https://docs.julialang.org/en/v1/base/io-network/#Base.IOContext) from
the Julia documentation) to pass information to other `show` methods invoked
recursively (for example in nested printings). The same mechanism can be used to
pass other context data. For instance, this is used by the `Scheme` code in
Expand All @@ -140,11 +140,11 @@ It will be used for `print(io, R::NewRing)` though.

```julia
function Base.show(io::IO, R::NewRing)
if get(io, :supercompact, false)
print(io, "supercompact printing of newring")
if is_terse(io)
print(io, "terse printing of newring")
else # this is what we call one line
print(io, "one line printing of newring with ")
print(IOContext(io, :supercompact => true), "supercompact ", R.base_ring)
print(terse(io), "terse ", R.base_ring)
end
end
```
Expand All @@ -161,7 +161,7 @@ julia> [R,R] # one line printing is ignored
I am a new ring with a detailed printing of one line

julia> print(Base.stdout, R)
one line printing of newring with supercompact QQ
one line printing of newring with terse QQ
```

## Advanced printing functionality
Expand Down Expand Up @@ -306,7 +306,7 @@ Here is an example with and without output using Unicode:
- All `show` methods for parent objects such as rings or modules should use the `@show_name`
macro. This macro ensures that if the object has a name (including one derived from
the name of a Julia REPL variable to which the object is currently assigned) then in
a `compact` or `supercompact` io context it is printed using that name.
a `compact` or `terse` io context it is printed using that name.
Here is an example illustrating this:
```
julia> vector_space(GF(2), 2)
Expand Down
12 changes: 6 additions & 6 deletions docs/src/DeveloperDocumentation/styleguide.md
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ matrix `A`, write `Oscar.parent(A)`.

### The 2 + 1 print modes of Oscar
Oscar has two user print modes `detailed` and `one line` and one internal
print mode `:supercompact`. The latter is for use during recursion,
print mode `terse`. The latter is for use during recursion,
e.g. to print the `base_ring(X)` when in `one line` mode.
It exists to make sure that `one line` stays compact and human readable.

Expand All @@ -302,7 +302,7 @@ General linear group of degree 24
# one line
General linear group of degree 24 over GF(29^7)
# supercompact
# terse
General linear group
```

Expand All @@ -317,17 +317,17 @@ The print modes are specified as follows
- should make sense as a standalone without context
- variable names/generators/relations should not be printed only their number.
- Only the first word is capitalized e.g. `Polynomial ring`
- one should use `:supercompact` for nested printing in compact
- one should use `terse` for nested printing in compact
- nested calls to `one line` (if you think them really necessary) should be at the end,
so that one can read sequentially. Calls to `:supercompact` can be anywhere.
so that one can read sequentially. Calls to `terse` can be anywhere.
- commas must be enclosed in brackets so that printing tuples stays unambiguous
#### Super compact printing
#### Terse printing
- a user readable version of the main (mathematical) type.
- a single term or a symbol/letter mimicking mathematical notation
- should usually only depend on the type and not of the type parameters or of
the concrete instance - exceptions of this rule are possible e.g. for `GF(2)`
- no nested printing. In particular variable names and `base_ring` must not be displayed.
This ensures that `one line` and `:supercompact` stay compact even for complicated things.
This ensures that `one line` and `terse` stay compact even for complicated things.
If you want nested printing use `one line` or `detailed`.

For further information and examples we refer you to our section [Details on
Expand Down
4 changes: 2 additions & 2 deletions experimental/BasisLieHighestWeight/src/MonomialBasis.jl
Original file line number Diff line number Diff line change
Expand Up @@ -92,14 +92,14 @@ function Base.show(io::IO, ::MIME"text/plain", basis::MonomialBasis)
end

function Base.show(io::IO, basis::MonomialBasis)
if get(io, :supercompact, false)
if is_terse(io)
print(io, "Monomial basis of a highest weight module")
else
io = pretty(io)
print(
io,
"Monomial basis of a highest weight module with highest weight $(highest_weight(basis)) over ",
)
print(IOContext(io, :supercompact => true), Lowercase(), base_lie_algebra(basis))
print(terse(io), Lowercase(), base_lie_algebra(basis))
end
end
5 changes: 3 additions & 2 deletions experimental/GModule/GaloisCohomology.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import Oscar.GrpCoh: CoChain, MultGrpElem, MultGrp, GModule, is_consistent,
Group
import Base: parent
import Oscar: direct_sum
import Oscar: pretty, Lowercase, Indent, Dedent
import Oscar: pretty, Lowercase, Indent, Dedent, terse

export is_coboundary, idel_class_gmodule, relative_brauer_group
export local_invariants, global_fundamental_class, shrink
Expand Down Expand Up @@ -1390,7 +1390,8 @@ end
function Base.show(io::IO, m::MIME"text/plain", a::RelativeBrauerGroupElem)
io = pretty(io)
print(io, "Element of relative Brauer group of ", Lowercase(), parent(a).k)
io = IOContext(io, :supercompact => true, :compact => true)
io = terse(io)
io = IOContext(io, :compact => true) # FIXME: for now also enable compact printing
print(io, Indent())
data = sort(collect(a.data); by =(x -> first(x) isa AbsSimpleNumFieldEmbedding ? Inf : minimum(first(x))))
for (p,v) in data
Expand Down
2 changes: 1 addition & 1 deletion experimental/InvariantTheory/src/InvariantTheory.jl
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ function Base.show(io::IO, G::LinearlyReductiveGroup)
io = pretty(io)
if G.group[1] == :SL
println(io, "Reductive group ", G.group[1], G.group[2])
print(IOContext(io, :supercompact => true), Indent(), "over ", Lowercase(), field(G))
print(terse(io), Indent(), "over ", Lowercase(), field(G))
print(io, Dedent())
end
end
Expand Down
4 changes: 2 additions & 2 deletions experimental/InvariantTheory/src/TorusInvariantsFast.jl
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ field(G::TorusGroup) = G.field
function Base.show(io::IO, G::TorusGroup)
io = pretty(io)
println(io, "Torus of rank ", rank(G))
print(IOContext(io, :supercompact => true), Indent(), "over ", Lowercase(), field(G))
print(terse(io), Indent(), "over ", Lowercase(), field(G))
print(io, Dedent())
end

Expand Down Expand Up @@ -152,7 +152,7 @@ group(R::RepresentationTorusGroup) = R.group
function Base.show(io::IO, R::RepresentationTorusGroup)
io = pretty(io)
println(io, "Representation of torus of rank ", rank(group(R)))
println(IOContext(io, :supercompact => true), Indent(), "over ", Lowercase(), field(group(R)), " and weights ")
println(terse(io), Indent(), "over ", Lowercase(), field(group(R)), " and weights ")
print(io, R.weights)
print(io, Dedent())
end
Expand Down
4 changes: 2 additions & 2 deletions experimental/LieAlgebras/src/AbstractLieAlgebra.jl
Original file line number Diff line number Diff line change
Expand Up @@ -120,12 +120,12 @@ function Base.show(io::IO, ::MIME"text/plain", L::AbstractLieAlgebra)
end

function Base.show(io::IO, L::AbstractLieAlgebra)
if get(io, :supercompact, false)
if is_terse(io)
print(io, "Abstract Lie algebra")
else
io = pretty(io)
print(io, "Abstract Lie algebra over ", Lowercase())
print(IOContext(io, :supercompact => true), coefficient_ring(L))
print(terse(io), coefficient_ring(L))
end
end

Expand Down
4 changes: 2 additions & 2 deletions experimental/LieAlgebras/src/LieAlgebraHom.jl
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ end

function Base.show(io::IO, ::MIME"text/plain", h::LieAlgebraHom)
io = pretty(io)
println(IOContext(io, :supercompact => true), h)
println(terse(io), h)
print(io, Indent())
println(io, "from ", Lowercase(), domain(h))
print(io, "to ", Lowercase(), codomain(h))
Expand All @@ -80,7 +80,7 @@ end

function Base.show(io::IO, h::LieAlgebraHom)
io = pretty(io)
if get(io, :supercompact, false)
if is_terse(io)
print(io, LowercaseOff(), "Lie algebra morphism")
else
print(io, LowercaseOff(), "Lie algebra morphism: ")
Expand Down
4 changes: 2 additions & 2 deletions experimental/LieAlgebras/src/LieAlgebraIdeal.jl
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,11 @@ end

function Base.show(io::IO, I::LieAlgebraIdeal)
io = pretty(io)
if get(io, :supercompact, false)
if is_terse(io)
print(io, LowercaseOff(), "Lie algebra ideal")
else
print(io, LowercaseOff(), "Lie algebra ideal of dimension $(dim(I)) over ", Lowercase())
print(IOContext(io, :supercompact => true), base_lie_algebra(I))
print(terse(io), base_lie_algebra(I))
end
end

Expand Down
4 changes: 2 additions & 2 deletions experimental/LieAlgebras/src/LieAlgebraModule.jl
Original file line number Diff line number Diff line change
Expand Up @@ -211,12 +211,12 @@ function _show_inner(io::IO, V::LieAlgebraModule)
end

function Base.show(io::IO, V::LieAlgebraModule)
if get(io, :supercompact, false)
if is_terse(io)
print(io, _module_type_to_string(V))
else
io = pretty(io)
print(io, _module_type_to_string(V), " of dimension $(dim(V)) over ", Lowercase())
print(IOContext(io, :supercompact => true), base_lie_algebra(V))
print(terse(io), base_lie_algebra(V))
end
end

Expand Down
4 changes: 2 additions & 2 deletions experimental/LieAlgebras/src/LieAlgebraModuleHom.jl
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ end

function Base.show(io::IO, ::MIME"text/plain", h::LieAlgebraModuleHom)
io = pretty(io)
println(IOContext(io, :supercompact => true), h)
println(terse(io), h)
print(io, Indent())
println(io, "from ", Lowercase(), domain(h))
print(io, "to ", Lowercase(), codomain(h))
Expand All @@ -87,7 +87,7 @@ end

function Base.show(io::IO, h::LieAlgebraModuleHom)
io = pretty(io)
if get(io, :supercompact, false)
if is_terse(io)
print(io, LowercaseOff(), "Lie algebra module morphism")
else
print(io, LowercaseOff(), "Lie algebra module morphism: ")
Expand Down
4 changes: 2 additions & 2 deletions experimental/LieAlgebras/src/LieSubalgebra.jl
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,11 @@ end

function Base.show(io::IO, S::LieSubalgebra)
io = pretty(io)
if get(io, :supercompact, false)
if is_terse(io)
print(io, LowercaseOff(), "Lie subalgebra")
else
print(io, LowercaseOff(), "Lie subalgebra of dimension $(dim(S)) of ", Lowercase())
print(IOContext(io, :supercompact => true), base_lie_algebra(S))
print(terse(io), base_lie_algebra(S))
end
end

Expand Down
4 changes: 2 additions & 2 deletions experimental/LieAlgebras/src/LinearLieAlgebra.jl
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ function Base.show(io::IO, ::MIME"text/plain", L::LinearLieAlgebra)
end

function Base.show(io::IO, L::LinearLieAlgebra)
if get(io, :supercompact, false)
if is_terse(io)
print(io, _lie_algebra_type_to_compact_string(get_attribute(L, :type, :unknown), L.n))
else
io = pretty(io)
Expand All @@ -101,7 +101,7 @@ function Base.show(io::IO, L::LinearLieAlgebra)
" over ",
Lowercase(),
)
print(IOContext(io, :supercompact => true), coefficient_ring(L))
print(terse(io), coefficient_ring(L))
end
end

Expand Down
2 changes: 1 addition & 1 deletion experimental/LieAlgebras/src/RootSystem.jl
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ function Base.show(io::IO, ::MIME"text/plain", R::RootSystem)
end

function Base.show(io::IO, R::RootSystem)
if get(io, :supercompact, false)
if is_terse(io)
print(io, "Root system")
else
print(io, "Root system defined by Cartan matrix $(cartan_matrix(R))")
Expand Down
4 changes: 2 additions & 2 deletions experimental/QuadFormAndIsom/src/printings.jl
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ function Base.show(io::IO, ::MIME"text/plain", Lf::ZZLatWithIsom)
end

function Base.show(io::IO, Lf::ZZLatWithIsom)
if get(io, :supercompact, false)
if is_terse(io)
print(io, "Integer lattice with isometry")
else
n = order_of_isometry(Lf)
Expand Down Expand Up @@ -54,7 +54,7 @@ function Base.show(io::IO, ::MIME"text/plain", Vf::QuadSpaceWithIsom)
end

function Base.show(io::IO, Vf::QuadSpaceWithIsom)
if get(io, :supercompact, false)
if is_terse(io)
print(io, "Quadratic space with isometry")
else
n = order_of_isometry(Vf)
Expand Down
2 changes: 1 addition & 1 deletion experimental/Schemes/AlgebraicCycles.jl
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ function Base.show(io::IO, D::AlgebraicCycle)
end
if has_name(D)
print(io, name(D))
elseif get(io, :supercompact, false)
elseif is_terse(io)
print(io, "Algebraic cycle")
elseif length(components(D)) == 0
print(io, "Zero algebraic cycle on ", Lowercase(), scheme(D))
Expand Down
2 changes: 1 addition & 1 deletion experimental/Schemes/BlowupMorphism.jl
Original file line number Diff line number Diff line change
Expand Up @@ -686,7 +686,7 @@ end
##############################################################################
function Base.show(io::IO, Bl::AbsSimpleBlowdownMorphism)
io = pretty(io)
if get(io, :supercompact, false)
if is_terse(io)
print(io, "Blowup morphism")
else
print(io, "Blow-down: ", Lowercase(), domain(Bl))
Expand Down

0 comments on commit 7d7bb9b

Please sign in to comment.