Algebra over fields
An algebra over a field is a vector space over that field, in which a bilinear operator (often called the "multiplication") between vectors is defined.
With the help of the structure constants of the algebra, the result of the bilinear operation between any arbitrary two vectors can be expressed by a sum of individual ones. Therefore, in principle, an algebra can be represented by the complete basis set of its corresponding vector space and a rank-3 tensor encapsulating its structure constants. It is noted that the "bilinear operation" is not restricted to the usual multiplication only. For example, it is the commutator, which is a composition of the usual multiplication and subtraction (for any A and B, the commutator [A, B] is defined as [A, B]≝AB-BA) that serves as the bilinear operator for Lie algebras. In this module, for scalars in the field and elements in the algebra, we only provide the interfaces of the scalar multiplication (including the scalar division) between a scalar and an element, the addition (including the subtraction) and the usual multiplication between two elements. Other complicated operations should be composed from these basic ones.
SimpleID and ID
SimpleID
is the building block of the id system of an algebra over a field, while ID
defines the specific identifier of an element in that algebra.
Generally, the usual multiplication between two elements of an algebra is not commutable, and the rank of the multiplication is just the add-up before the simplification with the help of the algebra structure. We thus use a simple id to denote a single basis of the corresponding vector space, and an id to denote the identifier of an element. With the help of the direct product (⊗
) of two ids, an over complete id system designed for the whole algebra is constructed. This id system is redundant because it does not reflects the structure constants of the algebra, which reduces independent basis elements. Extra mechanisms should be provided to kill this redundancy, which goes beyond the current module. Users should define them themselves.
Element and Elements
Element
defines a single element of an algebra while Elements
defines an expression composed of several elements from an algebra.
An Element
must have two predefined contents:
value::Number
: the coefficient of the elementid::ID
: the id of the element
Arithmetic operations (+
, -
, *
, /
) between a scalar, an Element
or an Elements
is defined. See Manual for details.
Manual
Core.Number
— MethodNumber(m::Element) -> valtype(m)
Get the value of an element.
QuantumLattices.Mathematics.AlgebraOverFields.Element
— TypeElement{V, I<:ID{SimpleID}}
An element of an algebra over a field.
Basically, a concrete subtype should contain two attributes:
value::V
: the coefficient of the elementid::I
: the id of the element
QuantumLattices.Mathematics.AlgebraOverFields.Elements
— TypeElements{I<:ID{SimpleID}, M<:Element} <: AbstractDict{I, M}
An set of elements of an algebra over a field.
Type alias for Dict{I<:ID{SimpleID}, M<:Element}
. Similar iterms are automatically merged thanks to the id system.
QuantumLattices.Mathematics.AlgebraOverFields.Elements
— MethodElements(ms)
Elements(ms::Pair{I, M}...) where {I<:ID{SimpleID}, M<:Element}
Elements(ms::Element...)
Get the set of elements with similar items merged.
QuantumLattices.Mathematics.AlgebraOverFields.ID
— TypeID{I<:SimpleID, N}
The (composite) id system of an algebra over a field.
Type alias for NTuple{N, I} where {N, I<:SimpleID}
.
QuantumLattices.Mathematics.AlgebraOverFields.ID
— MethodID(ids::SimpleID...)
ID(ids::NTuple{N, SimpleID}) where N
Get the composite id from simple ids.
QuantumLattices.Mathematics.AlgebraOverFields.ID
— MethodID(::Type{SID}, attrs::Vararg{NTuple{N}, M}) where {SID<:SimpleID, N, M}
Get the composite id from the components of simple ids.
QuantumLattices.Mathematics.AlgebraOverFields.Scalar
— TypeScalar{V}
Scalar element.
QuantumLattices.Mathematics.AlgebraOverFields.SimpleID
— TypeSimpleID <: NamedVector
A simple id is the building block of the id system of an algebra over a field.
Base.:*
— Method*(m::Element, ::Nothing) -> Nothing
*(::Nothing, m::Element) -> Nothing
*(factor::Number, m::Element) -> Element
*(m::Element, factor::Number) -> Element
*(m1::Element, m2::Element) -> Element
*(ms::Elements, ::Nothing) -> Nothing
*(::Nothing, ms::Elements) -> Nothing
*(factor::Number, ms::Elements) -> Elements
*(ms::Elements, factor::Number) -> Elements
*(m::Element, ms::Elements) -> Elements
*(ms::Elements, m::Element) -> Elements
*(ms1::Elements, ms2::Elements) -> Elements
Overloaded *
operator for element-scalar multiplications and element-element multiplications of an algebra over a field.
Base.:*
— Method*(sid1::SimpleID, sid2::SimpleID) -> ID{SimpleID}
*(sid::SimpleID, cid::ID{SimpleID}) -> ID{SimpleID}
*(cid::ID{SimpleID}, sid::SimpleID) -> ID{SimpleID}
*(cid1::ID{SimpleID}, cid2::ID{SimpleID}) -> ID{SimpleID}
Get the product of the id system.
Base.:+
— Method+(m::Element) -> typeof(m)
+(m::Element, ::Nothing) -> typeof(m)
+(::Nothing, m::Element) -> typeof(m)
+(m::Element, factor::Number) -> Elements
+(factor::Number, m::Element) -> Elements
+(m1::Element, m2::Element) -> Elements
+(ms::Elements) -> typeof(ms)
+(ms::Elements, ::Nothing) -> typeof(ms)
+(::Nothing, ms::Elements) -> typeof(ms)
+(ms::Elements, factor::Number) -> Elements
+(factor::Number, ms::Elements) -> Elements
+(ms::Elements, m::Element) -> Elements
+(m::Element, ms::Elements) -> Elements
+(ms1::Elements, ms2::Elements) -> Elements
Overloaded +
operator between elements of an algebra over a field.
Base.:-
— Method-(m::Element) -> typeof(m)
-(m::Element, ::Nothing) -> typeof(m)
-(::Nothing, m::Element) -> typeof(m)
-(m::Element, factor::Number) -> Elements
-(factor::Number, m::Element) -> Elements
-(m1::Element, m2::Element) -> Elements
-(ms::Elements) -> typeof(ms)
-(ms::Elements, ::Nothing) -> typeof(ms)
-(::Nothing, ms::Elements) -> typeof(ms)
-(ms::Elements, factor::Number) -> Elements
-(factor::Number, ms::Elements) -> Elements
-(m::Element, ms::Elements) -> Elements
-(ms::Elements, m::Element) -> Elements
-(ms1::Elements, ms2::Elements) -> Elements
Overloaded -
operator between elements of an algebra over a field.
Base.:/
— Method/(m::Element, factor::Number) -> Element
/(m::Element, factor::Scalar) -> Element
/(ms::Elements, factor::Number) -> Elements
/(ms::Elements, factor::Scalar) -> Elements
Overloaded /
operator for element-scalar division of an algebra over a field.
Base.://
— Method//(m::Element, factor::Integer) -> Element
//(m::Element, factor::Scalar) -> Element
//(ms::Elements, factor::Integer) -> Elements
//(ms::Elements, factor::Scalar) -> Elements
Overloaded //
operator for element-scalar division of an algebra over a field.
Base.:==
— Method==(ms::Elements, ::Nothing) -> Bool
==(::Nothing, ms::Elements) -> Bool
Judge whether a set of elements is identically empty.
Base.:==
— Method==(m1::Element, m2::Element) -> Bool
Compare two elements and judge whether they are equal to each other.
Base.:^
— Method^(m::Element, n::Integer) -> Element
^(ms::Elements, n::Integer) -> Elements
Overloaded ^
operator for element-integer power of an algebra over a field.
Base.convert
— Methodconvert(::Type{M}, m::Scalar) where M<:Scalar
convert(::Type{M}, m::Number) where M<:Scalar
convert(::Type{M}, m::Element) where M<:Element
- Convert a scalar element from one type to another;
- Convert a scalar to a scalar element;
- Convert an element from one type to another.
Base.getindex
— Methodgetindex(m::Element, i) -> Element
Overloaded []
operator.
Base.getproperty
— Methodgetproperty(cid::ID{SimpleID}, name::Symbol)
Get the property of a composite id.
Base.isapprox
— Methodisapprox(m1::Element, m2::Element; atol::Real=atol, rtol::Real=rtol) -> Bool
Compare two elements and judge whether they are inexactly equivalent to each other.
Base.isequal
— Methodisequal(ms::Elements, ::Nothing) -> Bool
isequal(::Nothing, ms::Elements) -> Bool
Judge whether a set of elements is identically empty.
Base.isequal
— Methodisequal(m1::Element, m2::Element) -> Bool
Compare two elements and judge whether they are equal to each other.
Base.isless
— Methodisless(::Type{<:SimpleID}, cid1::ID{SimpleID}, cid2::ID{SimpleID}) -> Bool
Compare two ids and judge whether the first is less than the second.
The comparison rule are as follows:
- ids with smaller ranks are always less than those with higher ranks;
- if two ids are of the same rank, the comparison goes just like that between tuples.
Base.length
— Methodlength(m::Element) -> Int
Get the length of an element.
Base.one
— Methodone(::Type{M}) where M<:Element
one(m::Element)
Get the identity operator.
Base.permute!
— Methodpermute!(result::Elements, m::Element, table) -> Elements
permute!(result::Elements, ms::Elements, table) -> Elements
Permute the ids of an-element/a-set-of-elements to the descending order according to a table, and store the permuted elements in result.
To use this function, the user must implement a method of permute
, which computes the result of the permutation of a rank-2 element and takes the following interface:
permute(::Type{M}, id1::SimpleID, id2::SimpleID) -> Union{M, Elements}
Here, M
is the type of the input element m
in permute!
, id1
and id2
are two arbitary simple ids contained in id(m)
.
Base.promote_rule
— Methodpromote_rule(::Type{M1}, ::Type{M2}) where {M1<:Element, M2<:Element}
Define the promote rule for Element types.
Base.promote_type
— Methodpromote_type(::Type{Tuple{}}, I::Type{<:ID{SimpleID, N}}) where N
promote_type(I::Type{<:ID{SimpleID, N}}, ::Type{Tuple{}}) where N
Define the promote rule for ID types.
Base.promote_type
— Methodpromote_type(::Type{M}, ::Type{V}, ::Val{:*}) where {M<:Element, V<:Number}
promote_type(::Type{V}, ::Type{M}, ::Val{:*}) where {M<:Element, V<:Number}
Define the promote rule for the multiplication between an Element and a scalar.
Base.propertynames
— Methodpropertynames(::Type{I}) where I<:ID{SimpleID} -> Tuple{Vararg{Symbol}}
Get the property names of a composite id.
Base.replace
— Methodreplace(m::Element, v::Number) -> Element
Replace the value of an element.
Base.replace
— Methodreplace(m::Element, pairs::Pair{<:SimpleID, <:Union{Element, Elements}}...) -> Element/Elements
replace(ms::Elements, pairs::Pair{<:SimpleID, <:Union{Element, Elements}}...) -> Elements
Replace the rank-1 components of an element with new element/elements.
Base.replace
— Methodreplace(m::Element; kwargs...) -> typeof(m)
Return a copy of a concrete Element
with some of the field values replaced by the keyword arguments.
Base.repr
— Methodrepr(ms::Elements) -> String
Get the repr representation of a set of elements.
Base.show
— Methodshow(io::IO, ms::Elements)
Show a set of elements.
Base.show
— Methodshow(io::IO, cid::Tuple{SimpleID, Vararg{SimpleID}})
Show a composite id.
Base.split
— Methodsplit(m::Element) -> Tuple{Any, Vararg{Element}}
Split an element into the coefficient and a sequence of rank-1 elements.
Base.valtype
— Methodvaltype(m::Element)
valtype(::Type{T}) where {T<:Element}
Get the type of the value of an element.
The result is also the type of the field over which the algebra is defined.
Base.zero
— Methodzero(ms::Elements) -> Nothing
zero(::Type{<:Elements}) -> Nothing
Get a zero set of elements.
A zero set of elements is defined to be the one with no elements.
QuantumLattices.Interfaces.:⊗
— Method⊗(m::Element, ms::Elements) -> Elements
⊗(ms::Elements, m::Element) -> Elements
⊗(ms1::Elements, ms2::Elements) -> Elements
Overloaded ⊗
operator for element-element multiplications of an algebra over a field.
QuantumLattices.Interfaces.:⋅
— Method⋅(m::Element, ms::Elements) -> Elements
⋅(ms::Elements, m::Element) -> Elements
⋅(ms1::Elements, ms2::Elements) -> Elements
Overloaded ⋅
operator for element-element multiplications of an algebra over a field.
QuantumLattices.Interfaces.add!
— Methodadd!(ms::Elements) -> typeof(ms)
add!(ms::Elements, ::Nothing) -> typeof(ms)
add!(ms::Elements, m::Number) -> typeof(ms)
add!(ms::Elements, m::Element) -> typeof(ms)
add!(ms::Elements, mms::Elements) -> typeof(ms)
Get the inplace addition of elements to a set.
QuantumLattices.Interfaces.div!
— Methoddiv!(ms::Elements, factor::Scalar) -> Elements
div!(ms::Elements, factor::Number) -> Elements
Get the inplace division of element with a scalar.
QuantumLattices.Interfaces.id
— Methodid(m::Element) -> idtype(m)
Get the id of an element.
QuantumLattices.Interfaces.mul!
— Methodmul!(ms::Elements, factor::Scalar) -> Elements
mul!(ms::Elements, factor::Number) -> Elements
Get the inplace multiplication of elements with a scalar.
QuantumLattices.Interfaces.permute
— Methodpermute(m::Element, table) -> Elements
permute(ms::Elements, table) -> Elements
Permute the ids of an-element/a-set-of-elements to the descending order according to a table.
QuantumLattices.Interfaces.permute
— Methodpermute(::Type{T}, id1::SimpleID, id2::SimpleID) where {T<:Element} -> Tuple{Vararg{Element}}
Permutation rule of two ids of type T
.
QuantumLattices.Interfaces.rank
— Methodrank(m::Element) -> Int
rank(::Type{M}) where M<:Element -> Int
Get the rank of an element.
QuantumLattices.Interfaces.rank
— Methodrank(id::ID{SimpleID}) -> Int
rank(::Type{<:ID{SimpleID}}) -> Any
rank(::Type{<:ID{SimpleID, N}}) where N -> Int
Get the rank of a composite id.
QuantumLattices.Interfaces.sub!
— Methodsub!(ms::Elements) -> typeof(ms)
sub!(ms::Elements, ::Nothing) -> typeof(ms)
add!(ms::Elements, m::Number) -> typeof(ms)
sub!(ms::Elements, m::Element) -> typeof(ms)
sub!(ms::Elements, mms::Elements) -> typeof(ms)
Get the inplace subtraction of elements from a set.
QuantumLattices.Mathematics.AlgebraOverFields.idtype
— Methodidtype(m::Element)
idtype(::Type{T}) where {T<:Element}
The type of the id of an element.
QuantumLattices.Mathematics.AlgebraOverFields.sequence
— Methodsequence(m::Element, table) -> NTuple{rank(m), Int}
Get the sequence of the ids of an element according to a table.