From 2eecee3b7c44c7e38cb20ca316b56b964f1b704e Mon Sep 17 00:00:00 2001 From: Johannes Schmitt Date: Tue, 20 Aug 2024 15:18:21 +0200 Subject: [PATCH] Fix a power series bug (#1840) Fix a bug --- src/flint/fmpz_mod_abs_series.jl | 20 ++------------------ src/flint/fmpz_mod_rel_series.jl | 20 ++------------------ src/flint/fq_abs_series.jl | 20 ++------------------ src/flint/fq_default_abs_series.jl | 20 ++------------------ src/flint/fq_default_rel_series.jl | 22 ++-------------------- src/flint/fq_rel_series.jl | 22 ++-------------------- src/flint/nmod_rel_series.jl | 20 ++------------------ test/flint/fmpz_mod_abs_series-test.jl | 7 +++++++ test/flint/fmpz_mod_rel_series-test.jl | 7 +++++++ test/flint/fq_abs_series-test.jl | 5 +++++ test/flint/fq_default_abs_series-test.jl | 5 +++++ test/flint/fq_default_rel_series-test.jl | 5 +++++ test/flint/fq_rel_series-test.jl | 5 +++++ test/flint/nmod_abs_series-test.jl | 5 +++++ test/flint/nmod_rel_series-test.jl | 5 +++++ 15 files changed, 58 insertions(+), 130 deletions(-) diff --git a/src/flint/fmpz_mod_abs_series.jl b/src/flint/fmpz_mod_abs_series.jl index 12c47c0f4..28027b868 100644 --- a/src/flint/fmpz_mod_abs_series.jl +++ b/src/flint/fmpz_mod_abs_series.jl @@ -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)) diff --git a/src/flint/fmpz_mod_rel_series.jl b/src/flint/fmpz_mod_rel_series.jl index 02f13499e..91aaa55b6 100644 --- a/src/flint/fmpz_mod_rel_series.jl +++ b/src/flint/fmpz_mod_rel_series.jl @@ -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)) diff --git a/src/flint/fq_abs_series.jl b/src/flint/fq_abs_series.jl index 6b815b737..bd46c2229 100644 --- a/src/flint/fq_abs_series.jl +++ b/src/flint/fq_abs_series.jl @@ -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)) diff --git a/src/flint/fq_default_abs_series.jl b/src/flint/fq_default_abs_series.jl index a614e5186..d1eddfe3d 100644 --- a/src/flint/fq_default_abs_series.jl +++ b/src/flint/fq_default_abs_series.jl @@ -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) diff --git a/src/flint/fq_default_rel_series.jl b/src/flint/fq_default_rel_series.jl index f33bf2141..81823e98f 100644 --- a/src/flint/fq_default_rel_series.jl +++ b/src/flint/fq_default_rel_series.jl @@ -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) diff --git a/src/flint/fq_rel_series.jl b/src/flint/fq_rel_series.jl index cff4341c3..1936b97b4 100644 --- a/src/flint/fq_rel_series.jl +++ b/src/flint/fq_rel_series.jl @@ -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)) diff --git a/src/flint/nmod_rel_series.jl b/src/flint/nmod_rel_series.jl index b8eaf1163..5e9a0300d 100644 --- a/src/flint/nmod_rel_series.jl +++ b/src/flint/nmod_rel_series.jl @@ -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)) diff --git a/test/flint/fmpz_mod_abs_series-test.jl b/test/flint/fmpz_mod_abs_series-test.jl index 31db0197a..1311cf7dc 100644 --- a/test/flint/fmpz_mod_abs_series-test.jl +++ b/test/flint/fmpz_mod_abs_series-test.jl @@ -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 diff --git a/test/flint/fmpz_mod_rel_series-test.jl b/test/flint/fmpz_mod_rel_series-test.jl index fffae6fd2..b0ad84a4d 100644 --- a/test/flint/fmpz_mod_rel_series-test.jl +++ b/test/flint/fmpz_mod_rel_series-test.jl @@ -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 diff --git a/test/flint/fq_abs_series-test.jl b/test/flint/fq_abs_series-test.jl index 31d6a4dbe..9e789191d 100644 --- a/test/flint/fq_abs_series-test.jl +++ b/test/flint/fq_abs_series-test.jl @@ -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 diff --git a/test/flint/fq_default_abs_series-test.jl b/test/flint/fq_default_abs_series-test.jl index 03e7fe082..79d2ccca2 100644 --- a/test/flint/fq_default_abs_series-test.jl +++ b/test/flint/fq_default_abs_series-test.jl @@ -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 diff --git a/test/flint/fq_default_rel_series-test.jl b/test/flint/fq_default_rel_series-test.jl index 8cba43ee8..fe9fc6a5c 100644 --- a/test/flint/fq_default_rel_series-test.jl +++ b/test/flint/fq_default_rel_series-test.jl @@ -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 diff --git a/test/flint/fq_rel_series-test.jl b/test/flint/fq_rel_series-test.jl index f35ceee5d..bdb4e7f8f 100644 --- a/test/flint/fq_rel_series-test.jl +++ b/test/flint/fq_rel_series-test.jl @@ -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 diff --git a/test/flint/nmod_abs_series-test.jl b/test/flint/nmod_abs_series-test.jl index 98e6b0201..7b19061e3 100644 --- a/test/flint/nmod_abs_series-test.jl +++ b/test/flint/nmod_abs_series-test.jl @@ -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 diff --git a/test/flint/nmod_rel_series-test.jl b/test/flint/nmod_rel_series-test.jl index 16539c29f..f44926307 100644 --- a/test/flint/nmod_rel_series-test.jl +++ b/test/flint/nmod_rel_series-test.jl @@ -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