1
0
mirror of https://github.com/kalmarek/Groups.jl.git synced 2024-11-19 14:35:28 +01:00
Groups.jl/src/symbols.jl

23 lines
750 B
Julia
Raw Normal View History

2020-03-25 04:05:28 +01:00
change_pow(s::S, n::Integer) where S<:GSymbol = S(s.id, n)
function Base.iterate(s::GS, i=1) where GS<:GSymbol
return i <= abs(s.pow) ? (GS(s.id, sign(s.pow)), i+1) : nothing
end
2020-04-20 02:02:57 +02:00
Base.size(s::GSymbol) = (abs(s.pow), )
Base.length(s::GSymbol) = first(size(s))
2020-03-25 04:05:28 +01:00
Base.eltype(s::GS) where GS<:GSymbol = GS
Base.isone(s::GSymbol) = iszero(s.pow)
Base.inv(s::GSymbol) = change_pow(s, -s.pow)
Base.hash(s::S, h::UInt) where S<:GSymbol = hash(s.id, hash(s.pow, hash(S, h)))
function (==)(s::GSymbol, t::GSymbol)
isone(s) && isone(t) && return true
s.pow == t.pow && s.id == t.id && return true
return false
end
Base.convert(::Type{GS}, s::GSymbol) where GS<:GSymbol = GS(s.id, s.pow)
2020-03-25 05:21:57 +01:00
Base.convert(::Type{GS}, s::GS) where GS<:GSymbol = s