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
|
2020-11-10 17:03:10 +01:00
|
|
|
return i <= abs(s.pow) ? (change_pow(s, sign(s.pow)), i+1) : nothing
|
2020-03-25 04:05:28 +01:00
|
|
|
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
|
2020-03-25 05:00:16 +01:00
|
|
|
|
|
|
|
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
|