Skip to content

Commit

Permalink
Add some finite ring/field coercion (#729)
Browse files Browse the repository at this point in the history
Matches functions currently in Oscar
  • Loading branch information
fingolfin authored Nov 5, 2023
1 parent 37ab9a6 commit c3f8b0d
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/number/n_Zp.jl
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,27 @@ promote_rule(C::Type{n_Zp}, ::Type{n_Z}) = n_Zp
# take ownership of the pointer - not for general users
(R::N_ZpField)(n::libSingular.number_ptr) = n_Zp(R, n)

function (F::N_ZpField)(a::Nemo.fpFieldElem)
characteristic(F) == characteristic(parent(a)) || error("characteristic does not match")
return F(lift(a))
end

function (F::N_ZpField)(a::Nemo.zzModRingElem)
characteristic(F) == characteristic(parent(a)) || error("characteristic does not match")
return F(lift(a))
end

function (F::Nemo.fpField)(a::n_Zp)
characteristic(F) == characteristic(parent(a)) || error("characteristic does not match")
return F(Int(a))
end

function (F::Nemo.zzModRing)(a::n_Zp)
characteristic(F) == characteristic(parent(a)) || error("characteristic does not match")
return F(Int(a))
end


###############################################################################
#
# Fp constructor
Expand Down
24 changes: 24 additions & 0 deletions test/libsingular/nemo-test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,30 @@ end
@test string(p) == "0"
@test length(p) == 0
@test is_zero(p)

R = residue_ring(Nemo.ZZ, 7)
F = Fp(7)
for i in -10:10
@test R(one(F)*i) == one(R)*i
@test F(one(R)*i) == one(F)*i
end

S = Nemo.GF(5)
@test_throws ErrorException S(one(F))
@test_throws ErrorException F(one(S))
end

@testset "Nemo.fpFieldElem" begin
R = Nemo.GF(7)
F = Fp(7)
for i in -10:10
@test R(one(F)*i) == one(R)*i
@test F(one(R)*i) == one(F)*i
end

S = Nemo.GF(5)
@test_throws ErrorException S(one(F))
@test_throws ErrorException F(one(S))
end

@testset "Nemo.ZZModRingElem" begin
Expand Down

0 comments on commit c3f8b0d

Please sign in to comment.