Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix casing in show(::PBWAlgebra) and friends #4315

Merged
merged 4 commits into from
Nov 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions docs/src/NoncommutativeAlgebra/PBWAlgebras/ideals.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@ If `I` is an ideal of a PBW-algebra `A`, then

```jldoctest
julia> D, (x, y, dx, dy) = weyl_algebra(QQ, ["x", "y"])
(Weyl-algebra over Rational field in variables (x, y), PBWAlgElem{QQFieldElem, Singular.n_Q}[x, y, dx, dy])
(Weyl-algebra over rational field in variables (x, y), PBWAlgElem{QQFieldElem, Singular.n_Q}[x, y, dx, dy])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Orthogonal to this PR (and not a change request for it): it really also should be Weyl algebra and PBW algebra (without the -)


julia> I = left_ideal(D, [x, dx])
left_ideal(x, dx)

julia> base_ring(I)
Weyl-algebra over Rational field in variables (x, y)
Weyl-algebra over rational field in variables (x, y)

julia> gens(I)
2-element Vector{PBWAlgElem{QQFieldElem, Singular.n_Q}}:
Expand Down
2 changes: 1 addition & 1 deletion docs/src/NoncommutativeAlgebra/PBWAlgebras/quotients.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ julia> I = two_sided_ideal(A, [x^2, y^2, z^2]);
julia> Q, q = quo(A, I);

julia> base_ring(Q)
PBW-algebra over Rational field in x, y, z with relations y*x = -x*y, z*x = -x*z, z*y = -y*z
PBW-algebra over rational field in x, y, z with relations y*x = -x*y, z*x = -x*z, z*y = -y*z

julia> modulus(Q)
two_sided_ideal(x^2, y^2, z^2)
Expand Down
15 changes: 13 additions & 2 deletions experimental/ExteriorAlgebra/src/ExteriorAlgebra.jl
Original file line number Diff line number Diff line change
Expand Up @@ -84,15 +84,26 @@ function exterior_algebra(K::Ring, varnames::Vector{Symbol})
ExtAlg_singular = Singular.create_ring_from_singular_ring(SINGULAR_PTR)
# Create Quotient ring with special implementation:
ExtAlg, _ = quo(PBW, I; special_impl=ExtAlg_singular) # 2nd result is a QuoMap, apparently not needed
return ExtAlg, gens(ExtAlg)
generators = gens(ExtAlg)
else
ExtAlg, QuoMap = quo(PBW, I)
return ExtAlg, QuoMap.(PBW_indets)
generators = QuoMap.(PBW_indets)
end
set_attribute!(ExtAlg, :show, show_exterior_algebra)
return ExtAlg, generators
end

AbstractAlgebra.@varnames_interface exterior_algebra(K::Ring, varnames) macros = :no

function show_exterior_algebra(io::IO, E::PBWAlgQuo)
x = symbols(E)
io = pretty(io)
print(io, "Exterior algebra over ", Lowercase(), coefficient_ring(E))
print(io, " in (")
join(io, x, ", ")
print(io, ")")
end

# # BUGS/DEFICIENCIES (2023-02-13):
# # (1) Computations with elements DO NOT AUTOMATICALLY REDUCE
# # modulo the squares of the generators.
Expand Down
69 changes: 35 additions & 34 deletions src/Rings/PBWAlgebra.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# Use attribute :is_weyl_algebra to permit better printing (see expressify, below)
@attributes mutable struct PBWAlgRing{T, S} <: NCRing
sring::Singular.PluralRing{S}
relations::Singular.smatrix{Singular.spoly{S}}
Expand Down Expand Up @@ -85,28 +84,31 @@ end

@enable_all_show_via_expressify PBWAlgElem

function expressify(a::PBWAlgRing; context = nothing)
function show(io::IO, a::PBWAlgRing)
@show_name(io, a)
@show_special(io, a)
x = symbols(a)
n = length(x)
# Next if stmt handles special printing for Weyl algebras
if get_attribute(a, :is_weyl_algebra) === :true
return Expr(:sequence, Expr(:text, "Weyl-algebra over "),
expressify(coefficient_ring(a); context=context),
Expr(:text, " in variables ("),
Expr(:series, first(x,div(n,2))...),
Expr(:text, ")"))
end
rel = [Expr(:call, :(==), Expr(:call, :*, x[j], x[i]), expressify(a.relations[i,j]))
io = pretty(io)
rel = [AbstractAlgebra.PrettyPrinting.canonicalize(Expr(:call, :(==), Expr(:call, :*, x[j], x[i]), expressify(a.relations[i,j])))
for i in 1:n-1 for j in i+1:n]
return Expr(:sequence, Expr(:text, "PBW-algebra over "),
expressify(coefficient_ring(a); context=context),
Expr(:text, " in "),
Expr(:series, x...),
Expr(:text, " with relations "),
Expr(:series, rel...))
print(io, LowercaseOff(), "PBW-algebra over ", Lowercase(), coefficient_ring(a))
print(io, " in ")
join(io, x, ", ")
print(io, " with relations ")
AbstractAlgebra.show_obj(io, MIME("text/plain"), Expr(:series, rel...))
end

@enable_all_show_via_expressify PBWAlgRing
# handles special printing for Weyl algebras
function show_weyl_algebra(io::IO, a::PBWAlgRing)
x = symbols(a)
n = length(x)
io = pretty(io)
print(io, LowercaseOff(), "Weyl-algebra over ", Lowercase(), coefficient_ring(a))
print(io, " in variables (")
join(io, first(x, div(n, 2)), ", ")
print(io, ")")
end

#### AA prefix here because these all use the ordering in the parent

Expand Down Expand Up @@ -428,7 +430,7 @@ julia> L = [x*y, x*z, y*z + 1];
julia> REL = strictly_upper_triangular_matrix(L);

julia> A, (x, y, z) = pbw_algebra(R, REL, deglex(gens(R)))
(PBW-algebra over Rational field in x, y, z with relations y*x = x*y, z*x = x*z, z*y = y*z + 1, PBWAlgElem{QQFieldElem, Singular.n_Q}[x, y, z])
(PBW-algebra over rational field in x, y, z with relations y*x = x*y, z*x = x*z, z*y = y*z + 1, PBWAlgElem{QQFieldElem, Singular.n_Q}[x, y, z])
```
"""
function pbw_algebra(r::MPolyRing{T}, rel, ord::MonomialOrdering; check::Bool = true) where T
Expand Down Expand Up @@ -482,7 +484,8 @@ function weyl_algebra(K::Ring, xs::Vector{Symbol}, dxs::Vector{Symbol})
r, v = polynomial_ring(K, vcat(xs, dxs); cached = false)
rel = elem_type(r)[v[i]*v[j] + (j == i + n) for i in 1:2*n-1 for j in i+1:2*n]
R,vars = pbw_algebra(r, strictly_upper_triangular_matrix(rel), default_ordering(r); check = false)
set_attribute!(R, :is_weyl_algebra, :true) # to activate special printing for Weyl algebras
set_attribute!(R, :is_weyl_algebra, :true)
set_attribute!(R, :show, show_weyl_algebra) # to activate special printing for Weyl algebras
return (R,vars)
end

Expand All @@ -504,7 +507,7 @@ The generators of the returned algebra print according to the entries of `xs`. S
# Examples
```jldoctest
julia> D, (x, y, dx, dy) = weyl_algebra(QQ, [:x, :y])
(Weyl-algebra over Rational field in variables (x, y), PBWAlgElem{QQFieldElem, Singular.n_Q}[x, y, dx, dy])
(Weyl-algebra over rational field in variables (x, y), PBWAlgElem{QQFieldElem, Singular.n_Q}[x, y, dx, dy])

julia> dx*x
x*dx + 1
Expand All @@ -519,13 +522,11 @@ end

####

function expressify(a::PBWAlgOppositeMap; context = nothing)
return Expr(:sequence, Expr(:text, "Map to opposite of "),
expressify(a.source; context=context))
function Base.show(io::IO, a::PBWAlgOppositeMap)
io = pretty(io)
print(io, "Map to opposite of ", Lowercase(), a.source)
end

@enable_all_show_via_expressify PBWAlgOppositeMap

function _opposite(a::PBWAlgRing{T, S}) where {T, S}
if !isdefined(a, :opposite)
ptr = Singular.libSingular.rOpposite(a.sring.ptr)
Expand Down Expand Up @@ -553,15 +554,15 @@ Return the opposite algebra of `A`.
# Examples
```jldoctest
julia> D, (x, y, dx, dy) = weyl_algebra(QQ, [:x, :y])
(Weyl-algebra over Rational field in variables (x, y), PBWAlgElem{QQFieldElem, Singular.n_Q}[x, y, dx, dy])
(Weyl-algebra over rational field in variables (x, y), PBWAlgElem{QQFieldElem, Singular.n_Q}[x, y, dx, dy])

julia> Dop, opp = opposite_algebra(D);

julia> Dop
PBW-algebra over Rational field in dy, dx, y, x with relations dx*dy = dy*dx, y*dy = dy*y + 1, x*dy = dy*x, y*dx = dx*y, x*dx = dx*x + 1, x*y = y*x
PBW-algebra over rational field in dy, dx, y, x with relations dx*dy = dy*dx, y*dy = dy*y + 1, x*dy = dy*x, y*dx = dx*y, x*dx = dx*x + 1, x*y = y*x

julia> opp
Map to opposite of Weyl-algebra over Rational field in variables (x, y)
Map to opposite of Weyl-algebra over rational field in variables (x, y)

julia> opp(dx*x)
dx*x + 1
Expand Down Expand Up @@ -644,7 +645,7 @@ julia> L = [x*y, x*z, y*z + 1];
julia> REL = strictly_upper_triangular_matrix(L);

julia> A, (x, y, z) = pbw_algebra(R, REL, deglex(gens(R)))
(PBW-algebra over Rational field in x, y, z with relations y*x = x*y, z*x = x*z, z*y = y*z + 1, PBWAlgElem{QQFieldElem, Singular.n_Q}[x, y, z])
(PBW-algebra over rational field in x, y, z with relations y*x = x*y, z*x = x*z, z*y = y*z + 1, PBWAlgElem{QQFieldElem, Singular.n_Q}[x, y, z])

julia> I = left_ideal(A, [x^2*y^2, x*z+y*z])
left_ideal(x^2*y^2, x*z + y*z)
Expand Down Expand Up @@ -748,7 +749,7 @@ Return `true` if `I` is the zero ideal, `false` otherwise.
# Examples
```jldoctest
julia> D, (x, y, dx, dy) = weyl_algebra(QQ, [:x, :y])
(Weyl-algebra over Rational field in variables (x, y), PBWAlgElem{QQFieldElem, Singular.n_Q}[x, y, dx, dy])
(Weyl-algebra over rational field in variables (x, y), PBWAlgElem{QQFieldElem, Singular.n_Q}[x, y, dx, dy])

julia> I = left_ideal(D, [x, dx])
left_ideal(x, dx)
Expand Down Expand Up @@ -778,7 +779,7 @@ Return `true` if `I` is generated by `1`, `false` otherwise.
# Examples
```jldoctest
julia> D, (x, y, dx, dy) = weyl_algebra(QQ, [:x, :y])
(Weyl-algebra over Rational field in variables (x, y), PBWAlgElem{QQFieldElem, Singular.n_Q}[x, y, dx, dy])
(Weyl-algebra over rational field in variables (x, y), PBWAlgElem{QQFieldElem, Singular.n_Q}[x, y, dx, dy])

julia> I = left_ideal(D, [x, dx])
left_ideal(x, dx)
Expand Down Expand Up @@ -1275,7 +1276,7 @@ julia> L = [x*y-z, x*z+2*x, x*a, y*z-2*y, y*a, z*a];
julia> REL = strictly_upper_triangular_matrix(L);

julia> A, (x, y, z, a) = pbw_algebra(R, REL, deglex(gens(R)))
(PBW-algebra over Rational field in x, y, z, a with relations y*x = x*y - z, z*x = x*z + 2*x, a*x = x*a, z*y = y*z - 2*y, a*y = y*a, a*z = z*a, PBWAlgElem{QQFieldElem, Singular.n_Q}[x, y, z, a])
(PBW-algebra over rational field in x, y, z, a with relations y*x = x*y - z, z*x = x*z + 2*x, a*x = x*a, z*y = y*z - 2*y, a*y = y*a, a*z = z*a, PBWAlgElem{QQFieldElem, Singular.n_Q}[x, y, z, a])

julia> f = 4*x*y+z^2-2*z-a;

Expand All @@ -1300,7 +1301,7 @@ julia> L = [p*q+q^2];
julia> REL = strictly_upper_triangular_matrix(L);

julia> A, (p, q) = pbw_algebra(R, REL, lex(gens(R)))
(PBW-algebra over Rational field in p, q with relations q*p = p*q + q^2, PBWAlgElem{QQFieldElem, Singular.n_Q}[p, q])
(PBW-algebra over rational field in p, q with relations q*p = p*q + q^2, PBWAlgElem{QQFieldElem, Singular.n_Q}[p, q])

julia> I = left_ideal(A, [p, q])
left_ideal(p, q)
Expand Down
39 changes: 14 additions & 25 deletions src/Rings/PBWAlgebraQuo.jl
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,20 @@ export PBWAlgQuo, PBWAlgQuoElem


###### @attributes ### DID NOT WORK -- alternative solution found (via has_special_impl, see ExteriorAlgebra.jl)
mutable struct PBWAlgQuo{T, S} <: NCRing
@attributes mutable struct PBWAlgQuo{T, S} <: NCRing
I::PBWAlgIdeal{0, T, S}
sring::Singular.PluralRing{S} # For ExtAlg this is the Singular impl; o/w same as I.basering.sring

function PBWAlgQuo(I::PBWAlgIdeal{0, T, S}, sring::Singular.PluralRing{S}) where {T, S}
return new{T, S}(I, sring)
end
end


# For backward compatibility: ctor with 1 arg:
# uses "default" arith impl -- namely that from basering!
function PBWAlgQuo(I::PBWAlgIdeal{0, T, S}) where {T, S}
return PBWAlgQuo{T, S}(I, I.basering.sring)
return PBWAlgQuo(I, I.basering.sring)
end


Expand Down Expand Up @@ -93,27 +97,12 @@ end

@enable_all_show_via_expressify PBWAlgQuoElem

function expressify(Q::PBWAlgQuo; context = nothing) # what about new sring data-field ???
## special printing if Q is an exterior algebra
###### if get_attribute(Q, :is_exterior_algebra) === :true
if has_special_impl(Q)
a = Q.I.basering
x = symbols(a)
n = length(x)
return Expr(:sequence, Expr(:text, "Exterior algebra over "),
expressify(coefficient_ring(a); context=context),
Expr(:text, " in ("),
Expr(:series, x...),
Expr(:text, ")"))

end
# General case (not exterior algebra)
return Expr(:call, :/, expressify(Q.I.basering; context = nothing),
expressify(Q.I; context = nothing))
function Base.show(io::IO, Q::PBWAlgQuo)
@show_name(io, Q)
@show_special(io, Q)
print(io, "(", base_ring(Q), ")/", modulus(Q))
end

@enable_all_show_via_expressify PBWAlgQuo

####

function number_of_generators(Q::PBWAlgQuo)
Expand Down Expand Up @@ -216,20 +205,20 @@ julia> L = [-x*y, -x*z, -y*z];
julia> REL = strictly_upper_triangular_matrix(L);

julia> A, (x, y, z) = pbw_algebra(R, REL, deglex(gens(R)))
(PBW-algebra over Rational field in x, y, z with relations y*x = -x*y, z*x = -x*z, z*y = -y*z, PBWAlgElem{QQFieldElem, Singular.n_Q}[x, y, z])
(PBW-algebra over rational field in x, y, z with relations y*x = -x*y, z*x = -x*z, z*y = -y*z, PBWAlgElem{QQFieldElem, Singular.n_Q}[x, y, z])

julia> I = two_sided_ideal(A, [x^2, y^2, z^2])
two_sided_ideal(x^2, y^2, z^2)

julia> Q, q = quo(A, I);

julia> Q
(PBW-algebra over Rational field in x, y, z with relations y*x = -x*y, z*x = -x*z, z*y = -y*z)/two_sided_ideal(x^2, y^2, z^2)
(PBW-algebra over rational field in x, y, z with relations y*x = -x*y, z*x = -x*z, z*y = -y*z)/two_sided_ideal(x^2, y^2, z^2)

julia> q
Map defined by a julia-function with inverse
from pBW-algebra over Rational field in x, y, z with relations y*x = -x*y, z*x = -x*z, z*y = -y*z
to (PBW-algebra over Rational field in x, y, z with relations y*x = -x*y, z*x = -x*z, z*y = -y*z)/two_sided_ideal(x^2, y^2, z^2)
from PBW-algebra over rational field in x, y, z with relations y*x = -x*y, z*x = -x*z, z*y = -y*z
to (PBW-algebra over rational field in x, y, z with relations y*x = -x*y, z*x = -x*z, z*y = -y*z)/two_sided_ideal(x^2, y^2, z^2)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these two lines show all fixes to the casing in one place

```

!!! note
Expand Down
Loading