From 8d1604863cfc33c9538a18b85496db4d605493ec Mon Sep 17 00:00:00 2001 From: kalmar Date: Thu, 27 Jul 2017 22:09:48 +0200 Subject: [PATCH] RG(::Vector{GroupElem}) method for constructing GroupRingElems --- src/GroupRings.jl | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/GroupRings.jl b/src/GroupRings.jl index d2cf331..7a4ad4e 100644 --- a/src/GroupRings.jl +++ b/src/GroupRings.jl @@ -136,7 +136,7 @@ function (RG::GroupRing)(g::GroupElem, T::Type=Int) return result end -function (RG::GroupRing)(x::AbstractVector) +function (RG::GroupRing){T<:Number}(x::AbstractVector{T}) isdefined(RG, :basis) || throw("Can not coerce without basis of GroupRing") length(x) == length(RG.basis) || throw("Can not coerce to $RG: lengths differ") result = RG(eltype(x)) @@ -144,6 +144,16 @@ function (RG::GroupRing)(x::AbstractVector) return result end +function (RG::GroupRing{Gr,T}){Gr<:Nemo.Group, T<:Nemo.GroupElem}(V::Vector{T}, + S::Type=Rational{Int}; alt=false) + res = RG(S) + for g in V + c = (alt ? sign(g)*one(S) : one(S)) + res[g] += c/length(V) + end + return res +end + function (RG::GroupRing)(X::GroupRingElem) RG == parent(X) || throw("Can not coerce!") return RG(X.coeffs)