From 9261df96ecc3c646e1d7c318b7c97301c80ad8b7 Mon Sep 17 00:00:00 2001 From: kalmarek Date: Tue, 4 Jun 2019 20:10:04 +0200 Subject: [PATCH] move Group Ring specific functions (norm, aug, supp, star) to misc.jl --- src/GroupRings.jl | 31 ------------------------------- src/misc.jl | 23 +++++++++++++++++++++++ 2 files changed, 23 insertions(+), 31 deletions(-) diff --git a/src/GroupRings.jl b/src/GroupRings.jl index 1db09a2..f93fee8 100644 --- a/src/GroupRings.jl +++ b/src/GroupRings.jl @@ -81,37 +81,6 @@ function (==)(A::GroupRing, B::GroupRing) end -############################################################################### -# -# *-involution -# -############################################################################### - -function star(X::GroupRingElem{T}) where T - RG = parent(X) - isdefined(RG, :basis) || throw("*-involution without basis is not possible") - result = RG(T) - for (i,c) in enumerate(X.coeffs) - if c != zero(T) - g = inv(RG.basis[i]) - result[g] = c - end - end - return result -end - -############################################################################### -# -# Misc -# -############################################################################### - -LinearAlgebra.norm(X::GroupRingElem, p::Int=2) = norm(X.coeffs, p) - -aug(X::GroupRingElem) = sum(X.coeffs) - -supp(X::GroupRingElem) = parent(X).basis[findall(!iszero, X.coeffs)] - function reverse_dict(::Type{I}, iter) where I<:Integer length(iter) > typemax(I) && error("Can not produce reverse dict: $(length(iter)) is too large for $T") return Dict{eltype(iter), I}(x => i for (i,x) in enumerate(iter)) diff --git a/src/misc.jl b/src/misc.jl index bdcceda..97adaa4 100644 --- a/src/misc.jl +++ b/src/misc.jl @@ -53,3 +53,26 @@ Base.@propagate_inbounds function Base.setindex!(X::GroupRingElem, val, g::Grou return X.coeffs[RG[g]] = val end +############################################################################### +# +# GroupRing specifics: augmentation, support, *-involution +# +############################################################################### + +aug(X::GroupRingElem) = sum(X.coeffs) + +function supp(X::GroupRingElem) + @assert hasbasis(parent(X)) + dropzeros!(X.coeffs) + return parent(X).basis[X.coeffs.nzind] +end + +function star(X::GroupRingElem{T}) where T + RG = parent(X) + hasbasis(RG) || throw(ArgumentError("*-involution without basis is not possible")) + nzind = [RG.basis_dict[inv(RG.basis[i])] for i in X.coeffs.nzind] + return GroupRingElem(sparsevec(nzind, X.coeffs.nzval, X.coeffs.n), RG) +end + +LinearAlgebra.norm(X::GroupRingElem, p::Int=2) = norm(X.coeffs, p) +