diff --git a/src/Rings/AbelianClosure.jl b/src/Rings/AbelianClosure.jl index 9bd00fe7294c..d48394f3d6aa 100644 --- a/src/Rings/AbelianClosure.jl +++ b/src/Rings/AbelianClosure.jl @@ -42,16 +42,16 @@ import Hecke: conductor, data ################################################################################ @attributes mutable struct QQAbField{T} <: Nemo.Field # union of cyclotomic fields - s::String fields::Dict{Int, T} # Cache for the cyclotomic fields + s::String - function QQAbField{T}(s::String, fields::Dict{Int, T}) where T - return new(s, fields) + function QQAbField{T}(fields::Dict{Int, T}) where T + return new(fields) end end -const _QQAb = QQAbField{AnticNumberField}("ζ", Dict{Int, AnticNumberField}()) -const _QQAb_sparse = QQAbField{NfAbsNS}("ζ", Dict{Int, NfAbsNS}()) +const _QQAb = QQAbField{AnticNumberField}(Dict{Int, AnticNumberField}()) +const _QQAb_sparse = QQAbField{NfAbsNS}(Dict{Int, NfAbsNS}()) mutable struct QQAbElem{T} <: Nemo.FieldElem data::T # Element in cyclotomic field @@ -150,14 +150,25 @@ parent(::QQAbElem{NfAbsNSElem}) = _QQAb_sparse # ################################################################################ -_variable(K::QQAbField) = K.s +function _variable(K::QQAbField) + if isdefined(K, :s) + return K.s + else + if Oscar.is_unicode_allowed() + return "ζ" + else + return "z" + end + end +end + _variable(b::QQAbElem{nf_elem}) = Expr(:call, Symbol(_variable(_QQAb)), b.c) function _variable(b::QQAbElem{NfAbsNSElem}) k = parent(b.data) lc = get_attribute(k, :decom) n = get_attribute(k, :cyclo) - return [Expr(:call, Symbol(_variable(_QQAb)), n, divexact(n, i)) for i = lc] + return [Expr(:call, Symbol(_variable(parent(b))), n, divexact(n, i)) for i = lc] end function Hecke.cyclotomic_field(K::QQAbField{AnticNumberField}, c::Int) @@ -165,7 +176,7 @@ function Hecke.cyclotomic_field(K::QQAbField{AnticNumberField}, c::Int) k = K.fields[c] return k, gen(k) else - k, z = CyclotomicField(c, string(K.s, "(", c, ")"), cached = false) + k, z = CyclotomicField(c, string("\$", "(", c, ")"), cached = false) K.fields[c] = k return k, z end @@ -186,7 +197,7 @@ function Hecke.cyclotomic_field(K::QQAbField{NfAbsNS}, c::Int) k = K.fields[c] return k, ns_gen(k) else - k, _ = cyclotomic_field(NonSimpleNumField, c, string(K.s)) + k, _ = cyclotomic_field(NonSimpleNumField, c, "\$") K.fields[c] = k return k, ns_gen(k) end @@ -311,6 +322,7 @@ end function Base.show(io::IO, a::QQAbField{NfAbsNS}) print(io, "(Sparse) abelian closure of Q") end + function Base.show(io::IO, a::QQAbField{AnticNumberField}) print(io, "Abelian closure of Q") end @@ -330,7 +342,7 @@ Change the printing of the primitive n-th root of the abelian closure of the rationals to `s(n)`, where `s` is the supplied string. """ function set_variable!(K::QQAbField, s::String) - ss = K.s + ss = _variable(K) K.s = s return ss end diff --git a/test/Rings/AbelianClosure.jl b/test/Rings/AbelianClosure.jl index 5a438405db51..e4e3b799dc7f 100644 --- a/test/Rings/AbelianClosure.jl +++ b/test/Rings/AbelianClosure.jl @@ -60,18 +60,28 @@ end @testset "Printing" begin K, z = abelian_closure(QQ) @test sprint(show, "text/plain", K) == "Abelian closure of Q" - @test get_variable(K) == "ζ" + + @test get_variable(K) == "z" s = sprint(show, "text/plain", z) a = z(1) sprint(show, "text/plain", a) == "1" a = z(4) - sprint(show, "text/plain", a) == "ζ(4)" - - t = set_variable!(K, "z") - @test t == "ζ" - @test get_variable(K) == "z" sprint(show, "text/plain", a) == "z(4)" + Oscar.with_unicode() do + @test get_variable(K) == "ζ" + s = sprint(show, "text/plain", z) + + a = z(1) + sprint(show, "text/plain", a) == "1" + a = z(4) + sprint(show, "text/plain", a) == "ζ(4)" + end + + t = set_variable!(K, "zz") + @test t == "z" + @test get_variable(K) == "zz" + sprint(show, "text/plain", a) == "zz(4)" zz = gen(K, "ω") @test get_variable(K) == "ω" @@ -81,7 +91,7 @@ end @test isone(a^4) && !isone(a) && !isone(a^2) # reset variable for any subsequent (doc-)tests - set_variable!(K, "ζ") + @test set_variable!(K, "z") == "ω" end @testset "Coercion" begin