1
0
mirror of https://github.com/kalmarek/GroupRings.jl.git synced 2024-12-29 11:00:28 +01:00

indentation and other trivial changes

This commit is contained in:
kalmarek 2019-06-06 17:01:50 +02:00
parent c6b557080d
commit 65d2df3a40
No known key found for this signature in database
GPG Key ID: 8BF1A3855328FC15
2 changed files with 74 additions and 75 deletions

View File

@ -27,8 +27,6 @@ function mul!(result::GroupRingElem, X::GroupRingElem, Y::GroupRingElem)
result = zero!(_dealias(result, X, Y)) result = zero!(_dealias(result, X, Y))
X_nzeros_idx = findall(!iszero, X.coeffs) X_nzeros_idx = findall(!iszero, X.coeffs)
Y_nzeros_idx = findall(!iszero, Y.coeffs) Y_nzeros_idx = findall(!iszero, Y.coeffs)
# X_nzeros_idx = [i for i in eachindex(X.coeffs) if X[i] != zero(eltype(X))]
# Y_nzeros_idx = [i for i in eachindex(Y.coeffs) if Y[i] != zero(eltype(Y))]
RG = parent(X) RG = parent(X)

View File

@ -7,7 +7,7 @@
AbstractAlgebra.parent_type(::Type{GroupRingElem{T, GR}}) where {T, GR} = GR AbstractAlgebra.parent_type(::Type{GroupRingElem{T, GR}}) where {T, GR} = GR
function AbstractAlgebra.elem_type(::Type{<:GroupRing{R,G,El}}) where {R,G,El} function AbstractAlgebra.elem_type(::Type{<:GroupRing{R,G,El}}) where {R,G,El}
return GroupRingElem{elem_type(R), GroupRing{R,G,El}} return GroupRingElem{elem_type(R), GroupRing{R,G,El}}
end end
AbstractAlgebra.base_ring(RG::GroupRing) = RG.base_ring AbstractAlgebra.base_ring(RG::GroupRing) = RG.base_ring
@ -18,11 +18,11 @@ AbstractAlgebra.isexact_type(::Type{<:GroupRingElem{T}}) where T = isexact_type(
# hash(GroupRingElem) = 0x839279ac6f12f62a # hash(GroupRingElem) = 0x839279ac6f12f62a
function Base.hash(X::GroupRingElem, h::UInt) function Base.hash(X::GroupRingElem, h::UInt)
return (hash(X.coeffs, h), hash(parent(X), h), 0x839279ac6f12f62a) return (hash(X.coeffs, h), hash(parent(X), h), 0x839279ac6f12f62a)
end end
function Base.deepcopy_internal(X::GroupRingElem, dict::IdDict) function Base.deepcopy_internal(X::GroupRingElem, dict::IdDict)
return parent(X)(deepcopy(X.coeffs)) return parent(X)(deepcopy(X.coeffs))
end end
Base.zero(RG::GroupRing) = RG(0) Base.zero(RG::GroupRing) = RG(0)
@ -30,7 +30,7 @@ Base.one(RG::GroupRing) = RG(1)
Base.iszero(X::GroupRingElem{T}) where T = all(x == zero(T) for x in X.coeffs.nzval) Base.iszero(X::GroupRingElem{T}) where T = all(x == zero(T) for x in X.coeffs.nzval)
function Base.isone(X::GroupRingElem{T}) where T function Base.isone(X::GroupRingElem{T}) where T
idx = _identity_idx(parent(X)) idx = _identity_idx(parent(X))
X[idx] == one(T) || return false X[idx] == one(T) || return false
all(X[i] == zero(T) for i in eachindex(X.coeffs) if i != idx) || return false all(X[i] == zero(T) for i in eachindex(X.coeffs) if i != idx) || return false
return true return true
@ -43,33 +43,33 @@ end
############################################################################### ###############################################################################
Base.show(io::IO, RG::GroupRing) = Base.show(io::IO, RG::GroupRing) =
print(io, "Group ring of $(RG.group) with coefficients in $(base_ring(RG))") print(io, "Group ring of $(RG.group) with coefficients in $(base_ring(RG))")
function Base.show(io::IO, X::GroupRingElem{T}) where T function Base.show(io::IO, X::GroupRingElem{T}) where T
RG = parent(X) RG = parent(X)
if iszero(X) if iszero(X)
print(io, "$(zero(T))*$(multiplicative_id(RG.group))") print(io, "$(zero(T))*$(multiplicative_id(RG.group))")
elseif hasbasis(RG) elseif hasbasis(RG)
suppX = supp(X) suppX = supp(X)
elts = String[] elts = String[]
elts = String[] elts = String[]
sgn = "" sgn = ""
for g in suppX for g in suppX
coeff = X[g] coeff = X[g]
if X[g] < 0 if X[g] < 0
sgn = " - " sgn = " - "
coeff = -coeff coeff = -coeff
end end
push!(elts, sgn*string(coeff)*string(g)) push!(elts, sgn*string(coeff)*string(g))
sgn = " + " sgn = " + "
end end
str = join(elts, "") str = join(elts, "")
print(io, str) print(io, str)
else else
@warn("Basis of the parent group ring is not defined, showing coeffs") @warn("Basis of the parent group ring is not defined, showing coeffs")
show(io, MIME("text/plain"), X.coeffs) show(io, MIME("text/plain"), X.coeffs)
end end
end end
AbstractAlgebra.needs_parentheses(X::GroupRingElem) = true AbstractAlgebra.needs_parentheses(X::GroupRingElem) = true
@ -83,42 +83,42 @@ AbstractAlgebra.show_minus_one(::Type{<:GroupRingElem}) = true
############################################################################### ###############################################################################
function ==(X::GroupRingElem{T}, Y::GroupRingElem{S}) where {T,S} function ==(X::GroupRingElem{T}, Y::GroupRingElem{S}) where {T,S}
if promote_type(T,S) T || promote_type(T,S) S if promote_type(T,S) T || promote_type(T,S) S
@warn "Comparing elements with incompatible coeffs Rings: $T and $S can be only compared as $(promote_type(T,S))" @warn "Comparing elements with incompatible coeffs Rings: $T and $S can be only compared as $(promote_type(T,S))"
end end
length(X.coeffs) == length(Y.coeffs) || return false length(X.coeffs) == length(Y.coeffs) || return false
parent(X).group == parent(Y).group || return false parent(X).group == parent(Y).group || return false
return all(x == y for (x,y) in zip(X.coeffs, Y.coeffs)) return all(x == y for (x,y) in zip(X.coeffs, Y.coeffs))
end end
Base.isequal(X::GroupRingElem, Y::GroupRingElem) = X == Y Base.isequal(X::GroupRingElem, Y::GroupRingElem) = X == Y
_equalorzero(x,y) = x == y || x == 0 || y == 0 _equalorzero(x,y) = x == 0 || y == 0 || x == y
function ==(A::GroupRing, B::GroupRing) function ==(A::GroupRing, B::GroupRing)
A.group == B.group || return false A.group == B.group || return false
# base_ring(A) == base_ring(B) || return false # base_ring(A) == base_ring(B) || return false
bases = hasbasis(A) && hasbasis(B) bases = hasbasis(A) && hasbasis(B)
caches = cachesmultiplication(A) && cachesmultiplication(B) caches = cachesmultiplication(A) && cachesmultiplication(B)
if bases && caches if bases && caches
length(A) == length(B) || return false length(A) == length(B) || return false
size(A.pm) == size(B.pm) || return false size(A.pm) == size(B.pm) || return false
all(A.basis[i] == B.basis[i] for i in eachindex(A.basis)) || return false all(A.basis[i] == B.basis[i] for i = eachindex(A.basis)) || return false
all(_equalorzero(A.pm[i], B.pm[i]) for i in eachindex(A.pm)) || return false all(_equalorzero(A.pm[i], B.pm[i]) for i=eachindex(A.pm)) || return false
return true return true
elseif bases # && !caches elseif bases # && !caches
length(A) == length(B) || return false length(A) == length(B) || return false
all(A.basis[i] == B.basis[i] for i in eachindex(A.basis)) || return false all(A.basis[i] == B.basis[i] for i in eachindex(A.basis)) || return false
return true return true
elseif caches # && !bases elseif caches # && !bases
size(A.pm) == size(B.pm) || return false size(A.pm) == size(B.pm) || return false
all(A.pm[i] == B.pm[i] for i in eachindex(A.pm)) || return false all(A.pm[i] == B.pm[i] for i in eachindex(A.pm)) || return false
return true return true
else else
return false return false
end end
end end
############################################################################### ###############################################################################
@ -128,13 +128,13 @@ end
############################################################################### ###############################################################################
function AbstractAlgebra.divexact_left(X::GroupRingElem, Y::GroupRingElem) function AbstractAlgebra.divexact_left(X::GroupRingElem, Y::GroupRingElem)
isunit(Y) || throw(DivideError()) isunit(Y) || throw(DivideError())
return inv(Y)*X return inv(Y)*X
end end
function AbstractAlgebra.divexact_right(X::GroupRingElem, Y::GroupRingElem) function AbstractAlgebra.divexact_right(X::GroupRingElem, Y::GroupRingElem)
isunit(Y) || throw(DivideError()) isunit(Y) || throw(DivideError())
return X*inv(Y) return X*inv(Y)
end end
############################################################################### ###############################################################################
@ -161,24 +161,25 @@ function AbstractAlgebra.promote_rule(u::Type{U}, x::Type{GREl}) where {T, GREl<
return AbstractAlgebra.promote_rule(x, u) return AbstractAlgebra.promote_rule(x, u)
end end
function Base.rand(RG::GroupRing, density=0.05, args...) function Base.rand(RG::GroupRing, density=0.05, args...)
l = length(RG) l = length(RG)
if cachesmultiplication(RG) if cachesmultiplication(RG)
nzind = rand(1:size(RG.pm, 1), floor(Int, density*l)) nzind = rand(1:size(RG.pm, 1), floor(Int, density*l))
else else
nzind = rand(1:l, floor(Int, density*l)) nzind = rand(1:l, floor(Int, density*l))
end end
nzval = [rand(base_ring(RG), args...) for _ in nzind] nzval = [rand(base_ring(RG), args...) for _ in nzind]
return GroupRingElem(sparsevec(nzind, nzval, l), RG) return GroupRingElem(sparsevec(nzind, nzval, l), RG)
end end
function Base.isapprox(X::GroupRingElem{T}, Y::GroupRingElem{S}; function Base.isapprox(X::GroupRingElem{T}, Y::GroupRingElem{S};
atol::Real=sqrt(eps())) where {T,S} atol::Real=sqrt(eps())) where {T,S}
parent(X) == parent(Y) || return false parent(X) == parent(Y) || return false
return isapprox(X.coeffs, Y.coeffs, atol=atol) return isapprox(X.coeffs, Y.coeffs, atol=atol)
end end
Base.isapprox(X::GroupRingElem{T}, a::T; atol::Real=sqrt(eps())) where T = isapprox(X, RG(a)) Base.isapprox(X::GroupRingElem{T}, a::T; atol::Real=sqrt(eps())) where T = isapprox(X, RG(a))
@ -192,6 +193,6 @@ Base.isapprox(a::T, X::GroupRingElem{T}; atol::Real=sqrt(eps())) where T = isapp
############################################################################### ###############################################################################
function AbstractAlgebra.isunit(X::GroupRingElem) function AbstractAlgebra.isunit(X::GroupRingElem)
count(!iszero, X.coeffs) == 1 || return false count(!iszero, X.coeffs) == 1 || return false
return isunit(X[supp(X)[1]]) return isunit(X[supp(X)[1]])
end end