Skip to content

Commit 39d8217

Browse files
committed
Change behavior of base_ring for Laurent polynomials
1 parent 93cfa8c commit 39d8217

7 files changed

Lines changed: 45 additions & 48 deletions

File tree

src/LaurentMPoly.jl

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@
1010
#
1111
###############################################################################
1212

13-
characteristic(R::LaurentMPolyRing) = characteristic(base_ring(R))
14-
is_known(::typeof(characteristic), R::LaurentMPolyRing) = is_known(characteristic, base_ring(R))
13+
characteristic(R::LaurentMPolyRing) = characteristic(coefficient_ring(R))
14+
is_known(::typeof(characteristic), R::LaurentMPolyRing) = is_known(characteristic, coefficient_ring(R))
1515

16-
is_finite(R::LaurentMPolyRing) = is_trivial(base_ring(R)) || (nvars(R) == 0 && is_finite(base_ring(R)))
16+
is_finite(R::LaurentMPolyRing) = is_trivial(coefficient_ring(R)) || (nvars(R) == 0 && is_finite(coefficient_ring(R)))
1717
is_known(::typeof(is_finite), R::LaurentMPolyRing) =
18-
is_known(is_trivial, base_ring(R)) &&
19-
(is_trivial(base_ring(R)) || nvars(R) > 0 || is_known(is_finite, base_ring(R)))
18+
is_known(is_trivial, coefficient_ring(R)) &&
19+
(is_trivial(coefficient_ring(R)) || nvars(R) > 0 || is_known(is_finite, coefficient_ring(R)))
2020

2121
###############################################################################
2222
#
@@ -62,7 +62,7 @@ function show(io::IO, mime::MIME"text/plain", p::LaurentMPolyRing)
6262
println(io)
6363
end
6464
io = pretty(io)
65-
print(io, Indent(), "over ", Lowercase(), base_ring(p))
65+
print(io, Indent(), "over ", Lowercase(), coefficient_ring(p))
6666
print(io, Dedent())
6767
end
6868

@@ -74,7 +74,7 @@ function show(io::IO, p::LaurentMPolyRing)
7474
else
7575
io = pretty(io)
7676
print(io, "Multivariate Laurent polynomial ring in ", ItemQuantity(nvars(p), "variable"))
77-
print(terse(io), " over ", Lowercase(), base_ring(p))
77+
print(terse(io), " over ", Lowercase(), coefficient_ring(p))
7878
end
7979
end
8080

@@ -113,7 +113,7 @@ function RandomExtensions.make(S::LaurentMPolyRing,
113113
term_range::AbstractUnitRange{Int},
114114
exp_bound::AbstractUnitRange{Int},
115115
vs...)
116-
R = base_ring(S)
116+
R = coefficient_ring(S)
117117
if length(vs) == 1 && elem_type(R) == Random.gentype(vs[1])
118118
Make(S, term_range, exp_bound, vs[1])
119119
else
@@ -129,7 +129,7 @@ function rand(rng::AbstractRNG,
129129
S, term_range, exp_bound, v = sp[][1:end]
130130
f = zero(S)
131131
g = gens(S)
132-
R = base_ring(S)
132+
R = coefficient_ring(S)
133133
for i = 1:rand(rng, term_range)
134134
term = one(S)
135135
for j = 1:length(g)

src/LaurentPoly.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
#
1111
###############################################################################
1212

13-
characteristic(R::LaurentPolyRing) = characteristic(base_ring(R))
14-
is_known(::typeof(characteristic), R::LaurentPolyRing) = is_known(characteristic, base_ring(R))
13+
characteristic(R::LaurentPolyRing) = characteristic(coefficient_ring(R))
14+
is_known(::typeof(characteristic), R::LaurentPolyRing) = is_known(characteristic, coefficient_ring(R))
1515

1616
is_finite(R::LaurentPolyRing) = is_trivial(R)
1717
is_known(::typeof(is_finite), R::LaurentPolyRing) = is_known(is_trivial, R)

src/algorithms/LaurentPoly.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,12 +103,12 @@ end
103103

104104
function leading_coefficient(p::LaurentPolyRingElem)
105105
dr = degrees_range(p)
106-
isempty(dr) ? zero(base_ring(p)) : coeff(p, last(dr))
106+
isempty(dr) ? zero(coefficient_ring(p)) : coeff(p, last(dr))
107107
end
108108

109109
function trailing_coefficient(p::LaurentPolyRingElem)
110110
dr = degrees_range(p)
111-
isempty(dr) ? zero(base_ring(p)) : coeff(p, first(dr))
111+
isempty(dr) ? zero(coefficient_ring(p)) : coeff(p, first(dr))
112112
end
113113

114114
gens(R::LaurentPolyRing) = [gen(R)]
@@ -218,7 +218,7 @@ function show(io::IO, mime::MIME"text/plain", p::LaurentPolyRing)
218218
print(io, "Univariate Laurent polynomial ring in ", var(p))
219219
println(io)
220220
io = pretty(io)
221-
print(io, Indent(), "over ", Lowercase(), base_ring(p))
221+
print(io, Indent(), "over ", Lowercase(), coefficient_ring(p))
222222
print(io, Dedent())
223223
end
224224

@@ -230,7 +230,7 @@ function show(io::IO, p::LaurentPolyRing)
230230
else
231231
io = pretty(io)
232232
print(io, "Univariate Laurent polynomial ring in ", var(p), " over ")
233-
print(terse(io), Lowercase(), base_ring(p))
233+
print(terse(io), Lowercase(), coefficient_ring(p))
234234
end
235235
end
236236

src/generic/LaurentMPoly.jl

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,16 @@ elem_type(::Type{LaurentMPolyWrapRing{T, PR}}) where {T, PR} =
1717

1818
parent(p::LaurentMPolyWrap) = p.parent
1919

20-
base_ring_type(::Type{<:LaurentMPolyWrapRing{T}}) where {T} = parent_type(T)
21-
base_ring(R::LaurentMPolyWrapRing) = base_ring(R.mpolyring)::base_ring_type(R)
20+
base_ring_type(::Type{<:LaurentMPolyWrapRing{T}}) where {T} = mpoly_ring_type(T)
21+
base_ring(R::LaurentMPolyWrapRing) = R.mpolyring::base_ring_type(R)
2222

2323
coefficient_ring_type(::Type{LaurentMPolyWrapRing{T, PR}}) where {T, PR} = coefficient_ring_type(PR)
24-
coefficient_ring(R::LaurentMPolyWrapRing) = coefficient_ring(R.mpolyring)
24+
coefficient_ring(R::LaurentMPolyWrapRing) = coefficient_ring(base_ring(R))
2525

26-
symbols(R::LaurentMPolyWrapRing) = symbols(R.mpolyring)
26+
symbols(R::LaurentMPolyWrapRing) = symbols(base_ring(R))
2727

28-
number_of_variables(R::LaurentMPolyWrapRing) = number_of_variables(R.mpolyring)
29-
number_of_generators(R::LaurentMPolyWrapRing) = number_of_variables(R.mpolyring)
28+
number_of_variables(R::LaurentMPolyWrapRing) = number_of_variables(base_ring(R))
29+
number_of_generators(R::LaurentMPolyWrapRing) = number_of_variables(base_ring(R))
3030

3131
###############################################################################
3232
#
@@ -51,15 +51,15 @@ function length(a::LaurentMPolyWrap)
5151
end
5252

5353
function zero(R::LaurentMPolyWrapRing)
54-
return LaurentMPolyWrap(R, zero(R.mpolyring))
54+
return LaurentMPolyWrap(R, zero(base_ring(R)))
5555
end
5656

5757
function one(R::LaurentMPolyWrapRing)
58-
return LaurentMPolyWrap(R, one(R.mpolyring))
58+
return LaurentMPolyWrap(R, one(base_ring(R)))
5959
end
6060

6161
function gen(R::LaurentMPolyWrapRing, i::Int)
62-
return LaurentMPolyWrap(R, gen(R.mpolyring, i))
62+
return LaurentMPolyWrap(R, gen(base_ring(R), i))
6363
end
6464

6565
function iszero(a::LaurentMPolyWrap)
@@ -585,11 +585,11 @@ function (a::LaurentMPolyWrapRing{T})() where T <: RingElement
585585
end
586586

587587
function (a::LaurentMPolyWrapRing{T})(b::RingElement) where T <: RingElement
588-
return LaurentMPolyWrap(a, a.mpolyring(b))
588+
return LaurentMPolyWrap(a, base_ring(a)(b))
589589
end
590590

591591
function (a::LaurentMPolyWrapRing{T})(b::MPolyRingElem{T}) where T <: RingElement
592-
parent(b) == a.mpolyring || error("Unable to coerce polynomial")
592+
parent(b) == base_ring(a) || error("Unable to coerce polynomial")
593593
return LaurentMPolyWrap(a, b)
594594
end
595595

@@ -608,7 +608,7 @@ function (a::LaurentMPolyWrapRing{T})(b::Vector{T}, e::Vector{Vector{Int}}) wher
608608
length(e[i]) == n || error("Exponent vector $i has length $(length(m[i])) (expected $(n))")
609609
min_broadcast!(m, m, e[i])
610610
end
611-
return LaurentMPolyWrap(a, a.mpolyring(b, map(x -> x - m, e)), m)
611+
return LaurentMPolyWrap(a, base_ring(a)(b, map(x -> x - m, e)), m)
612612
end
613613

614614
###############################################################################
@@ -630,7 +630,7 @@ end
630630
################################################################################
631631

632632
function AbstractAlgebra._map(g::T, p::LaurentMPolyWrap, R::LaurentMPolyWrapRing) where T
633-
return LaurentMPolyWrap(R, AbstractAlgebra._map(g, p.mpoly, R.mpolyring),
633+
return LaurentMPolyWrap(R, AbstractAlgebra._map(g, p.mpoly, base_ring(R)),
634634
p.mindegs)
635635
end
636636

src/generic/LaurentPoly.jl

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,15 @@ elem_type(::Type{LaurentPolyWrapRing{T, PR}}) where {T, PR} =
1717

1818
parent(p::LaurentPolyWrap) = p.parent
1919

20-
base_ring_type(::Type{<:LaurentPolyWrapRing{T}}) where {T} = parent_type(T)
21-
base_ring(R::LaurentPolyWrapRing) = base_ring(R.polyring)::base_ring_type(R)
20+
base_ring_type(::Type{<:LaurentPolyWrapRing{T}}) where {T} = poly_ring_type(T)
21+
base_ring(R::LaurentPolyWrapRing) = R.polyring::base_ring_type(R)
2222

2323
coefficient_ring_type(::Type{LaurentPolyWrapRing{T, PR}}) where {T, PR} = coefficient_ring_type(PR)
24-
coefficient_ring(R::LaurentPolyWrapRing) = coefficient_ring(R.polyring)
24+
coefficient_ring(R::LaurentPolyWrapRing) = coefficient_ring(base_ring(R))
2525

26-
var(R::LaurentPolyWrapRing) = var(R.polyring)
26+
var(R::LaurentPolyWrapRing) = var(base_ring(R))
2727

28-
symbols(R::LaurentPolyWrapRing) = symbols(R.polyring)
28+
symbols(R::LaurentPolyWrapRing) = symbols(base_ring(R))
2929

3030
number_of_variables(R::LaurentPolyWrapRing) = 1
3131
number_of_generators(R::LaurentPolyWrapRing) = number_of_variables(R)
@@ -59,7 +59,7 @@ The result is undefined when `p` is null.
5959
lead_degree(p::LaurentPolyWrap) = p.mindeg + degree(p.poly)
6060

6161
coeff(p::LaurentPolyWrap, i::Int) =
62-
i < p.mindeg ? zero(base_ring(p)) : coeff(p.poly, i - p.mindeg)
62+
i < p.mindeg ? zero(coefficient_ring(p)) : coeff(p.poly, i - p.mindeg)
6363

6464
function _enable_deg!(p::LaurentPolyWrap, i::Int)
6565
diff = p.mindeg - i
@@ -81,10 +81,10 @@ iszero(p::LaurentPolyWrap) = iszero(p.poly)
8181

8282
isone(p::LaurentPolyWrap) = is_monomial(p, 0)
8383

84-
zero(R::LaurentPolyWrapRing) = LaurentPolyWrap(R, zero(R.polyring))
85-
one(R::LaurentPolyWrapRing) = LaurentPolyWrap(R, one(R.polyring))
84+
zero(R::LaurentPolyWrapRing) = LaurentPolyWrap(R, zero(base_ring(R)))
85+
one(R::LaurentPolyWrapRing) = LaurentPolyWrap(R, one(base_ring(R)))
8686

87-
gen(R::LaurentPolyWrapRing) = LaurentPolyWrap(R, gen(R.polyring))
87+
gen(R::LaurentPolyWrapRing) = LaurentPolyWrap(R, gen(base_ring(R)))
8888

8989
is_gen(p::LaurentPolyWrap) = is_monomial(p, 1)
9090

@@ -413,7 +413,7 @@ end
413413
RandomExtensions.maketype(S::LaurentPolyWrapRing, _, _) = elem_type(S)
414414

415415
function RandomExtensions.make(S::LaurentPolyWrapRing, v1, vs...)
416-
R = S.polyring
416+
R = base_ring(S)
417417
if length(vs) == 1 && vs[1] isa Integer && elem_type(R) == Random.gentype(v1)
418418
Make(S, v1, vs[1]) # forward to default Make constructor
419419
else
@@ -474,7 +474,7 @@ end
474474

475475
function AbstractAlgebra._map(g::T, p::LaurentPolyWrap, Rx::LaurentPolyWrapRing) where T
476476
return LaurentPolyWrap(Rx,
477-
AbstractAlgebra._map(g, p.poly, Rx.polyring), p.mindeg)
477+
AbstractAlgebra._map(g, p.poly, base_ring(Rx)), p.mindeg)
478478
end
479479

480480
function change_base_ring(R::Ring, p::LaurentPolyWrap; cached::Bool = true,
@@ -496,14 +496,14 @@ end
496496
#
497497
###############################################################################
498498

499-
(R::LaurentPolyWrapRing)(b::RingElement) = LaurentPolyWrap(R, R.polyring(b))
499+
(R::LaurentPolyWrapRing)(b::RingElement) = LaurentPolyWrap(R, base_ring(R)(b))
500500

501-
(R::LaurentPolyWrapRing)(b::RingElement, d::Int) = LaurentPolyWrap(R, R.polyring(b), d)
501+
(R::LaurentPolyWrapRing)(b::RingElement, d::Int) = LaurentPolyWrap(R, base_ring(R)(b), d)
502502

503-
(R::LaurentPolyWrapRing)() = LaurentPolyWrap(R, R.polyring())
503+
(R::LaurentPolyWrapRing)() = LaurentPolyWrap(R, base_ring(R)())
504504

505505
function (R::LaurentPolyWrapRing)(p::LaurentPolyWrap)
506-
parent(p) == R ? p : LaurentPolyWrap(R, R.polyring(p.poly), p.mindeg)
506+
parent(p) == R ? p : LaurentPolyWrap(R, base_ring(R)(p.poly), p.mindeg)
507507
end
508508

509509
###############################################################################

test/generic/LaurentMPoly-test.jl

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,8 @@ end
1212
@test L != laurent_polynomial_ring(GF(5), 2, 'x', cached = false)[1]
1313
@test L == laurent_polynomial_ring(GF(5), 2, :x, cached = true)[1]
1414

15-
@test base_ring(L) == GF(5)
1615
@test coefficient_ring(L) == GF(5)
1716
@test coefficient_ring_type(L) === typeof(GF(5))
18-
@test base_ring(x) == GF(5)
1917
@test coefficient_ring(x) == GF(5)
2018
@test coefficient_ring_type(x) === typeof(GF(5))
2119

test/generic/LaurentPoly-test.jl

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,8 @@ using AbstractAlgebra.Generic: Integers, LaurentPolyWrapRing, LaurentPolyWrap,
3535

3636
@test parent(y) == L
3737

38-
@test base_ring(L) == R
39-
@test base_ring(L) == base_ring(P)
4038
@test coefficient_ring(L) == R
39+
@test coefficient_ring(L) == coefficient_ring(P)
4140
@test coefficient_ring_type(L) === typeof(R)
4241

4342
@test var(L) == :y
@@ -122,7 +121,7 @@ using AbstractAlgebra.Generic: Integers, LaurentPolyWrapRing, LaurentPolyWrap,
122121
@test is_unit(y^e)
123122
end
124123

125-
if base_ring(L) isa AbstractAlgebra.Field
124+
if coefficient_ring(L) isa AbstractAlgebra.Field
126125
for e = -5:5
127126
@test is_unit(2*y^e)
128127
@test is_unit(3*y^(2e))

0 commit comments

Comments
 (0)