Skip to content

Commit

Permalink
Fix a power series bug (#1840)
Browse files Browse the repository at this point in the history
Fix a bug
  • Loading branch information
joschmitt authored Aug 20, 2024
1 parent de0808a commit 2eecee3
Show file tree
Hide file tree
Showing 15 changed files with 58 additions and 130 deletions.
20 changes: 2 additions & 18 deletions src/flint/fmpz_mod_abs_series.jl
Original file line number Diff line number Diff line change
Expand Up @@ -671,27 +671,11 @@ for (etype, rtype, ctype, mtype, brtype, flint_fn) in (
end

function (a::($rtype))(b::Integer)
m = base_ring(a)
if b == 0
z = ($etype)(m)
z.prec = a.prec_max
else
z = ($etype)(m, [ZZRingElem(b)], 1, a.prec_max)
end
z.parent = a
return z
return a(base_ring(a)(b))
end

function (a::($rtype))(b::ZZRingElem)
m = base_ring(a)
if iszero(b)
z = ($etype)(m)
z.prec = a.prec_max
else
z = ($etype)(m, [b], 1, a.prec_max)
end
z.parent = a
return z
return a(base_ring(a)(b))
end

function (a::($rtype))(b::$(mtype))
Expand Down
20 changes: 2 additions & 18 deletions src/flint/fmpz_mod_rel_series.jl
Original file line number Diff line number Diff line change
Expand Up @@ -878,27 +878,11 @@ for (etype, rtype, ctype, mtype, brtype, flint_fn) in (
end

function (a::($rtype))(b::Integer)
if b == 0
z = ($etype)(base_ring(a))
z.prec = a.prec_max
z.val = a.prec_max
else
z = ($etype)(base_ring(a), [ZZRingElem(b)], 1, a.prec_max, 0)
end
z.parent = a
return z
return a(base_ring(a)(b))
end

function (a::($rtype))(b::ZZRingElem)
if iszero(b)
z = ($etype)(base_ring(a))
z.prec = a.prec_max
z.val = a.prec_max
else
z = ($etype)(base_ring(a), [b], 1, a.prec_max, 0)
end
z.parent = a
return z
return a(base_ring(a)(b))
end

function (a::($rtype))(b::($mtype))
Expand Down
20 changes: 2 additions & 18 deletions src/flint/fq_abs_series.jl
Original file line number Diff line number Diff line change
Expand Up @@ -679,27 +679,11 @@ for (etype, rtype, ctype, btype, flint_fn, flint_tail) in (
end

function (a::($rtype))(b::Integer)
ctx = base_ring(a)
if b == 0
z = ($etype)(ctx)
z.prec = a.prec_max
else
z = ($etype)(ctx, [base_ring(a)(b)], 1, a.prec_max)
end
z.parent = a
return z
return a(base_ring(a)(b))
end

function (a::($rtype))(b::ZZRingElem)
ctx = base_ring(a)
if iszero(b)
z = ($etype)(ctx)
z.prec = a.prec_max
else
z = ($etype)(ctx, [base_ring(a)(b)], 1, a.prec_max)
end
z.parent = a
return z
return a(base_ring(a)(b))
end

function (a::($rtype))(b::($btype))
Expand Down
20 changes: 2 additions & 18 deletions src/flint/fq_default_abs_series.jl
Original file line number Diff line number Diff line change
Expand Up @@ -671,27 +671,11 @@ function (a::FqAbsPowerSeriesRing)()
end

function (a::FqAbsPowerSeriesRing)(b::Integer)
ctx = base_ring(a)
if b == 0
z = FqAbsPowerSeriesRingElem(ctx)
z.prec = a.prec_max
else
z = FqAbsPowerSeriesRingElem(ctx, [base_ring(a)(b)], 1, a.prec_max)
end
z.parent = a
return z
return a(base_ring(a)(b))
end

function (a::FqAbsPowerSeriesRing)(b::ZZRingElem)
ctx = base_ring(a)
if iszero(b)
z = FqAbsPowerSeriesRingElem(ctx)
z.prec = a.prec_max
else
z = FqAbsPowerSeriesRingElem(ctx, [base_ring(a)(b)], 1, a.prec_max)
end
z.parent = a
return z
return a(base_ring(a)(b))
end

function (a::FqAbsPowerSeriesRing)(b::FqFieldElem)
Expand Down
22 changes: 2 additions & 20 deletions src/flint/fq_default_rel_series.jl
Original file line number Diff line number Diff line change
Expand Up @@ -806,29 +806,11 @@ function (a::FqRelPowerSeriesRing)()
end

function (a::FqRelPowerSeriesRing)(b::Integer)
ctx = base_ring(a)
if b == 0
z = FqRelPowerSeriesRingElem(ctx)
z.prec = a.prec_max
z.val = a.prec_max
else
z = FqRelPowerSeriesRingElem(ctx, [ctx(b)], 1, a.prec_max, 0)
end
z.parent = a
return z
return a(base_ring(a)(b))
end

function (a::FqRelPowerSeriesRing)(b::ZZRingElem)
ctx = base_ring(a)
if iszero(b)
z = FqRelPowerSeriesRingElem(ctx)
z.prec = a.prec_max
z.val = a.prec_max
else
z = FqRelPowerSeriesRingElem(ctx, [ctx(b)], 1, a.prec_max, 0)
end
z.parent = a
return z
return a(base_ring(a)(b))
end

function (a::FqRelPowerSeriesRing)(b::FqFieldElem)
Expand Down
22 changes: 2 additions & 20 deletions src/flint/fq_rel_series.jl
Original file line number Diff line number Diff line change
Expand Up @@ -820,29 +820,11 @@ for (etype, rtype, ctype, btype, flint_fn, flint_tail) in (
end

function (a::($rtype))(b::Integer)
ctx = base_ring(a)
if b == 0
z = ($etype)(ctx)
z.prec = a.prec_max
z.val = a.prec_max
else
z = ($etype)(ctx, [ctx(b)], 1, a.prec_max, 0)
end
z.parent = a
return z
return a(base_ring(a)(b))
end

function (a::($rtype))(b::ZZRingElem)
ctx = base_ring(a)
if iszero(b)
z = ($etype)(ctx)
z.prec = a.prec_max
z.val = a.prec_max
else
z = ($etype)(ctx, [ctx(b)], 1, a.prec_max, 0)
end
z.parent = a
return z
return a(base_ring(a)(b))
end

function (a::($rtype))(b::($btype))
Expand Down
20 changes: 2 additions & 18 deletions src/flint/nmod_rel_series.jl
Original file line number Diff line number Diff line change
Expand Up @@ -870,27 +870,11 @@ for (etype, rtype, mtype, brtype, flint_fn) in (
end

function (a::($rtype))(b::Integer)
if b == 0
z = ($etype)(modulus(a))
z.prec = a.prec_max
z.val = a.prec_max
else
z = ($etype)(modulus(a), [ZZRingElem(b)], 1, a.prec_max, 0)
end
z.parent = a
return z
return a(base_ring(a)(b))
end

function (a::($rtype))(b::ZZRingElem)
if iszero(b)
z = ($etype)(modulus(a))
z.prec = a.prec_max
z.val = a.prec_max
else
z = ($etype)(modulus(a), [b], 1, a.prec_max, 0)
end
z.parent = a
return z
return a(base_ring(a)(b))
end

function (a::($rtype))(b::($mtype))
Expand Down
7 changes: 7 additions & 0 deletions test/flint/fmpz_mod_abs_series-test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,13 @@ end
@test isa(R(ZZ(2)), SeriesElem)

@test isa(R(), SeriesElem)

R, = residue_ring(ZZ, ZZ(12))
S, x = power_series_ring(R, 30, "x", model = :capped_absolute)
@test is_zero(S(12))
@test valuation(S(12)) == max_precision(S)
@test is_zero(S(ZZ(12)))
@test valuation(S(ZZ(12))) == max_precision(S)
end

@testset "ZZModAbsPowerSeriesRingElem.printing" begin
Expand Down
7 changes: 7 additions & 0 deletions test/flint/fmpz_mod_rel_series-test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,13 @@ end
@test isa(S(0), SeriesElem)
@test isa(S(R(0)), SeriesElem)
@test isa(S(ZZRingElem(0)), SeriesElem)

R, = residue_ring(ZZ, ZZ(12))
S, x = power_series_ring(R, 30, "x")
@test is_zero(S(12))
@test valuation(S(12)) == max_precision(S)
@test is_zero(S(ZZ(12)))
@test valuation(S(ZZ(12))) == max_precision(S)
end

@testset "ZZModRelPowerSeriesRingElem.printing" begin
Expand Down
5 changes: 5 additions & 0 deletions test/flint/fq_abs_series-test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ end
@test isa(R(ZZ(2)), SeriesElem)

@test isa(R(), SeriesElem)

@test is_zero(R(23))
@test valuation(R(23)) == max_precision(R)
@test is_zero(R(ZZ(23)))
@test valuation(R(ZZ(23))) == max_precision(R)
end

@testset "FqPolyRepAbsPowerSeriesRingElem.printing" begin
Expand Down
5 changes: 5 additions & 0 deletions test/flint/fq_default_abs_series-test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ end
@test isa(R(ZZ(2)), SeriesElem)

@test isa(R(), SeriesElem)

@test is_zero(R(23))
@test valuation(R(23)) == max_precision(R)
@test is_zero(R(ZZ(23)))
@test valuation(R(ZZ(23))) == max_precision(R)
end

@testset "FqAbsPowerSeriesRingElem.printing" begin
Expand Down
5 changes: 5 additions & 0 deletions test/flint/fq_default_rel_series-test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ end
l = S(t)

@test isa(l, SeriesElem)

@test is_zero(S(23))
@test valuation(S(23)) == max_precision(S)
@test is_zero(S(ZZ(23)))
@test valuation(S(ZZ(23))) == max_precision(S)
end

@testset "FqRelPowerSeriesRingElem.printing" begin
Expand Down
5 changes: 5 additions & 0 deletions test/flint/fq_rel_series-test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ end
l = S(t)

@test isa(l, SeriesElem)

@test is_zero(S(23))
@test valuation(S(23)) == max_precision(S)
@test is_zero(S(ZZ(23)))
@test valuation(S(ZZ(23))) == max_precision(S)
end

@testset "FqPolyRepRelPowerSeriesRingElem.printing" begin
Expand Down
5 changes: 5 additions & 0 deletions test/flint/nmod_abs_series-test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ end
@test isa(R(ZZ(2)), SeriesElem)

@test isa(R(), SeriesElem)

@test is_zero(R(23))
@test valuation(R(23)) == max_precision(R)
@test is_zero(R(ZZ(23)))
@test valuation(R(ZZ(23))) == max_precision(R)
end

@testset "zzModAbsPowerSeriesRingElem.printing" begin
Expand Down
5 changes: 5 additions & 0 deletions test/flint/nmod_rel_series-test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ end
l = S(R(4))

@test isa(l, SeriesElem)

@test is_zero(S(17))
@test valuation(S(17)) == max_precision(S)
@test is_zero(S(ZZ(17)))
@test valuation(S(ZZ(17))) == max_precision(S)
end

@testset "zzModRelPowerSeriesRingElem.printing" begin
Expand Down

0 comments on commit 2eecee3

Please sign in to comment.