Skip to content

Commit

Permalink
Printing for MPolyAnyMap (#2790)
Browse files Browse the repository at this point in the history
* printing for MPolyAnyMap

* fix doctests
  • Loading branch information
simonbrandhorst committed Sep 14, 2023
1 parent 3f9b859 commit ebee98c
Show file tree
Hide file tree
Showing 10 changed files with 162 additions and 136 deletions.
99 changes: 50 additions & 49 deletions docs/src/CommutativeAlgebra/affine_algebras.md
Original file line number Diff line number Diff line change
Expand Up @@ -357,13 +357,14 @@ julia> C1, (s,t) = graded_polynomial_ring(QQ, ["s", "t"]);
julia> V1 = [s^3, s^2*t, s*t^2, t^3];
julia> para = hom(D1, C1, V1)
Map with following data
Domain:
=======
Graded multivariate polynomial ring in 4 variables over QQ
Codomain:
=========
Graded multivariate polynomial ring in 2 variables over QQ
Ring homomorphism
from graded multivariate polynomial ring in 4 variables over QQ
to graded multivariate polynomial ring in 2 variables over QQ
defined by
w -> s^3
x -> s^2*t
y -> s*t^2
z -> t^3
julia> twistedCubic = kernel(para)
ideal(-x*z + y^2, -w*z + x*y, -w*y + x^2)
Expand All @@ -375,13 +376,13 @@ julia> D2, (a, b, c) = graded_polynomial_ring(QQ, ["a", "b", "c"]);
julia> V2 = [p2(w-y), p2(x), p2(z)];
julia> proj = hom(D2, C2, V2)
Map with following data
Domain:
=======
Graded multivariate polynomial ring in 3 variables over QQ
Codomain:
=========
Quotient of multivariate polynomial ring by ideal with 3 generators
Ring homomorphism
from graded multivariate polynomial ring in 3 variables over QQ
to quotient of multivariate polynomial ring by ideal with 3 generators
defined by
a -> w - y
b -> x
c -> z
julia> nodalCubic = kernel(proj)
ideal(-a^2*c + b^3 - 2*b^2*c + b*c^2)
Expand All @@ -396,13 +397,13 @@ julia> C3, x = polynomial_ring(QQ, "x" => 1:3);
julia> V3 = [x[1]*x[2], x[1]*x[3], x[2]*x[3]];
julia> F3 = hom(D3, C3, V3)
Map with following data
Domain:
=======
Multivariate polynomial ring in 3 variables over QQ
Codomain:
=========
Multivariate polynomial ring in 3 variables over QQ
Ring homomorphism
from multivariate polynomial ring in 3 variables over QQ
to multivariate polynomial ring in 3 variables over QQ
defined by
y[1] -> x[1]*x[2]
y[2] -> x[1]*x[3]
y[3] -> x[2]*x[3]
julia> sphere = ideal(C3, [x[1]^3 + x[2]^3 + x[3]^3 - 1])
ideal(x[1]^3 + x[2]^3 + x[3]^3 - 1)
Expand Down Expand Up @@ -434,13 +435,13 @@ julia> C, p = quo(S, ideal(S, [c-b^3]));
julia> V = [p(2*a + b^6), p(7*b - a^2), p(c^2)];
julia> F = hom(D, C, V)
Map with following data
Domain:
=======
Multivariate polynomial ring in 3 variables over QQ
Codomain:
=========
Quotient of multivariate polynomial ring by ideal with 1 generator
Ring homomorphism
from multivariate polynomial ring in 3 variables over QQ
to quotient of multivariate polynomial ring by ideal with 1 generator
defined by
x -> 2*a + c^2
y -> -a^2 + 7*b
z -> c^2
julia> is_surjective(F)
true
Expand All @@ -462,13 +463,13 @@ julia> C, (s, t) = polynomial_ring(QQ, ["s", "t"]);
julia> V = [s*t, t, s^2];
julia> paraWhitneyUmbrella = hom(R, C, V)
Map with following data
Domain:
=======
Multivariate polynomial ring in 3 variables over QQ
Codomain:
=========
Multivariate polynomial ring in 2 variables over QQ
Ring homomorphism
from multivariate polynomial ring in 3 variables over QQ
to multivariate polynomial ring in 2 variables over QQ
defined by
x -> s*t
y -> t
z -> s^2
julia> D, _ = quo(R, kernel(paraWhitneyUmbrella));
Expand Down Expand Up @@ -517,22 +518,22 @@ julia> L[1]
-5*y + z
julia> L[2]
Map with following data
Domain:
=======
Quotient of multivariate polynomial ring by ideal with 2 generators
Codomain:
=========
Quotient of multivariate polynomial ring by ideal with 2 generators
Ring homomorphism
from quotient of multivariate polynomial ring by ideal with 2 generators
to quotient of multivariate polynomial ring by ideal with 2 generators
defined by
x -> x
y -> 2*x + y
z -> 10*x + 5*y + z
julia> L[3]
Map with following data
Domain:
=======
Quotient of multivariate polynomial ring by ideal with 2 generators
Codomain:
=========
Quotient of multivariate polynomial ring by ideal with 2 generators
Ring homomorphism
from quotient of multivariate polynomial ring by ideal with 2 generators
to quotient of multivariate polynomial ring by ideal with 2 generators
defined by
x -> x
y -> -2*x + y
z -> -5*y + z
```
## Normalization
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,13 +135,13 @@ Spectrum
by ideal(x1)
julia> pullback(inclusion_morphism(X, Y))
Map with following data
Domain:
=======
Multivariate polynomial ring in 3 variables over QQ
Codomain:
=========
Quotient of multivariate polynomial ring by ideal with 1 generator
Ring homomorphism
from multivariate polynomial ring in 3 variables over QQ
to quotient of multivariate polynomial ring by ideal with 1 generator
defined by
x1 -> 0
x2 -> x2
x3 -> x3
```
"""
pullback(f::AbsSpecMor) = pullback(underlying_morphism(f))
Expand Down
8 changes: 1 addition & 7 deletions src/InvariantTheory/affine_algebra.jl
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,7 @@ with generators
AbstractAlgebra.Generic.MatSpaceElem{nf_elem}[[0 0 1; 1 0 0; 0 1 0], [1 0 0; 0 a 0; 0 0 -a-1]]
julia> affine_algebra(IR)
(Quotient of multivariate polynomial ring by ideal with 1 generator, Map with following data
Domain:
=======
Quotient of multivariate polynomial ring by ideal with 1 generator
Codomain:
=========
Graded multivariate polynomial ring in 3 variables over cyclotomic field of order 3)
(Quotient of multivariate polynomial ring by ideal with 1 generator, Hom: quotient of multivariate polynomial ring -> graded multivariate polynomial ring)
```
"""
function affine_algebra(IR::InvRing; algo_gens::Symbol = :default, algo_rels::Symbol = :groebner_basis)
Expand Down
12 changes: 5 additions & 7 deletions src/Rings/MPolyMap/AffineAlgebras.jl
Original file line number Diff line number Diff line change
Expand Up @@ -155,13 +155,11 @@ julia> is_bijective(F)
true
julia> G = inverse(F)
Map with following data
Domain:
=======
Multivariate polynomial ring in 1 variable over QQ
Codomain:
=========
D
Ring homomorphism
from multivariate polynomial ring in 1 variable over QQ
to quotient of multivariate polynomial ring by ideal with 2 generators
defined by
t -> x
julia> G(t)
x
Expand Down
35 changes: 32 additions & 3 deletions src/Rings/MPolyMap/MPolyAnyMap.jl
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,39 @@ _images(f::MPolyAnyMap) = f.img_gens
# String I/O
#
################################################################################
function Base.show(io::IO, ::MIME"text/plain", f::MPolyAnyMap)
io = pretty(io)
println(io, "Ring homomorphism") # at least one new line is needed
println(io, Indent(), "from ", Lowercase(), domain(f))
println(io, "to ", Lowercase(), codomain(f))
println(io, Dedent(), "defined by", Indent())
R = domain(f)
g = gens(R)
for i in 1:(ngens(R)-1)
println(io, g[i], " -> ", f(g[i]))
end
print(io, g[end], " -> ", f(g[end]), Dedent())
# the last print statement must not add a new line
phi = coefficient_map(f)
if !(phi isa Nothing)
println(io)
println(io, "with map on coefficients")
print(io, Indent(), phi, Dedent())
end
end

# There is some default printing for maps.
# We might want to hijack this if we want to indicate whether there is
# a non-trivial coefficient ring map.
function Base.show(io::IO, f::MPolyAnyMap)
io = pretty(io)
if get(io, :supercompact, false)
# no nested printing
print(io, "Ring homomorphism")
else
# nested printing allowed, preferably supercompact
print(io, "Hom: ")
print(IOContext(io, :supercompact => true), Lowercase(), domain(f), " -> ")
print(IOContext(io, :supercompact => true), Lowercase(), codomain(f))
end
end

################################################################################
#
Expand Down
14 changes: 7 additions & 7 deletions src/Rings/MPolyMap/MPolyQuo.jl
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,13 @@ julia> A, _ = quo(R, ideal(R, [y-x^2, z-x^3]));
julia> S, (s, t) = polynomial_ring(QQ, ["s", "t"]);
julia> F = hom(A, S, [s, s^2, s^3])
Map with following data
Domain:
=======
A
Codomain:
=========
Multivariate polynomial ring in 2 variables over QQ
Ring homomorphism
from quotient of multivariate polynomial ring by ideal with 2 generators
to multivariate polynomial ring in 2 variables over QQ
defined by
x -> s
y -> s^2
z -> s^3
```
"""
function hom(R::MPolyQuoRing, S::NCRing, coeff_map, images::Vector; check::Bool = true)
Expand Down
49 changes: 28 additions & 21 deletions src/Rings/MPolyMap/MPolyRing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,14 @@ julia> K, a = FiniteField(2, 2, "a");
julia> R, (x, y) = polynomial_ring(K, ["x", "y"]);
julia> F = hom(R, R, z -> z^2, [y, x])
Map with following data
Domain:
=======
Multivariate polynomial ring in 2 variables over GF(2^2)
Codomain:
=========
Multivariate polynomial ring in 2 variables over GF(2^2)
Ring homomorphism
from multivariate polynomial ring in 2 variables over GF(2^2)
to multivariate polynomial ring in 2 variables over GF(2^2)
defined by
x -> y
y -> x
with map on coefficients
#1
julia> F(a * y)
(a + 1)*x
Expand All @@ -69,13 +70,20 @@ julia> Qi, i = quadratic_field(-1)
julia> S, (x, y) = polynomial_ring(Qi, ["x", "y"]);
julia> G = hom(S, S, hom(Qi, Qi, -i), [x^2, y^2])
Map with following data
Domain:
=======
Multivariate polynomial ring in 2 variables over imaginary quadratic field defined by x^2 + 1
Codomain:
=========
Multivariate polynomial ring in 2 variables over imaginary quadratic field defined by x^2 + 1
Ring homomorphism
from multivariate polynomial ring in 2 variables over imaginary quadratic field defined by x^2 + 1
to multivariate polynomial ring in 2 variables over imaginary quadratic field defined by x^2 + 1
defined by
x -> x^2
y -> y^2
with map on coefficients
Map with following data
Domain:
=======
Qi
Codomain:
=========
Qi
julia> G(x+i*y)
x^2 - sqrt(-1)*y^2
Expand All @@ -87,13 +95,12 @@ julia> f = 3*x^2+2*x+1;
julia> S, (x, y) = polynomial_ring(GF(2), ["x", "y"]);
julia> H = hom(R, S, gens(S))
Map with following data
Domain:
=======
Multivariate polynomial ring in 2 variables over ZZ
Codomain:
=========
Multivariate polynomial ring in 2 variables over GF(2)
Ring homomorphism
from multivariate polynomial ring in 2 variables over ZZ
to multivariate polynomial ring in 2 variables over GF(2)
defined by
x -> x
y -> y
julia> H(f)
x^2 + 1
Expand Down
14 changes: 7 additions & 7 deletions src/Rings/localization_interface.jl
Original file line number Diff line number Diff line change
Expand Up @@ -173,13 +173,13 @@ Localization
at complement of prime ideal(x)
julia> iota
Map with following data
Domain:
=======
Multivariate polynomial ring in 3 variables over QQ
Codomain:
=========
Localization of multivariate polynomial ring in 3 variables over QQ at complement of prime ideal
Ring homomorphism
from multivariate polynomial ring in 3 variables over QQ
to localization of multivariate polynomial ring in 3 variables over QQ at complement of prime ideal
defined by
x -> x
y -> y
z -> z
```
"""
function Localization(S::AbsMultSet)
Expand Down
13 changes: 6 additions & 7 deletions src/Rings/mpoly-affine-algebras.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1267,13 +1267,12 @@ Quotient
by ideal(-T(1)*y + x, -T(1)*x + y^2, T(1)^2 - y, -x^2 + y^3)
julia> LL[1][2]
Map with following data
Domain:
=======
A
Codomain:
=========
Quotient of multivariate polynomial ring by ideal with 4 generators
Ring homomorphism
from quotient of multivariate polynomial ring by ideal with 1 generator
to quotient of multivariate polynomial ring by ideal with 4 generators
defined by
x -> x
y -> y
julia> LL[1][3]
(y, ideal(x, y))
Expand Down
Loading

0 comments on commit ebee98c

Please sign in to comment.