Move parametrising GroupAlgebraElements by the Vector-type
This commit is contained in:
parent
8d1fbf0f62
commit
0d5a2c0bc5
|
@ -6,13 +6,14 @@ import Base: size, length, norm
|
||||||
|
|
||||||
export GroupAlgebraElement
|
export GroupAlgebraElement
|
||||||
|
|
||||||
|
typealias CoordinateVector{T<:Number} AbstractVector{T}
|
||||||
|
|
||||||
immutable GroupAlgebraElement{T<:Number}
|
immutable GroupAlgebraElement{T<:CoordinateVector}
|
||||||
coordinates::Vector{T}
|
coordinates::T
|
||||||
product_matrix::Array{Int,2}
|
product_matrix::Array{Int,2}
|
||||||
# basis::Array{Any,1}
|
# basis::Array{Any,1}
|
||||||
|
|
||||||
function GroupAlgebraElement(coordinates::Vector{T},
|
function GroupAlgebraElement(coordinates::T,
|
||||||
product_matrix::Array{Int,2})
|
product_matrix::Array{Int,2})
|
||||||
|
|
||||||
size(product_matrix, 1) == size(product_matrix, 2) ||
|
size(product_matrix, 1) == size(product_matrix, 2) ||
|
||||||
|
@ -22,13 +23,13 @@ immutable GroupAlgebraElement{T<:Number}
|
||||||
end
|
end
|
||||||
|
|
||||||
# GroupAlgebraElement(c,pm,b) = GroupAlgebraElement(c,pm)
|
# GroupAlgebraElement(c,pm,b) = GroupAlgebraElement(c,pm)
|
||||||
GroupAlgebraElement{T}(c::Vector{T},pm) = GroupAlgebraElement{T}(c,pm)
|
GroupAlgebraElement{T}(c::T,pm) = GroupAlgebraElement{T}(c,pm)
|
||||||
|
|
||||||
convert{T<:Number}(::Type{T}, X::GroupAlgebraElement) =
|
convert{T<:Number}(::Type{T}, X::GroupAlgebraElement) =
|
||||||
GroupAlgebraElement(convert(Vector{T}, X.coordinates), X.product_matrix)
|
GroupAlgebraElement(convert(CoordinateVector{T}, X.coordinates), X.product_matrix)
|
||||||
|
|
||||||
show{T}(io::IO, X::GroupAlgebraElement{T}) = print(io,
|
show{T}(io::IO, X::GroupAlgebraElement{T}) = print(io,
|
||||||
"Element of Group Algebra over ", T, "of length $(length(X)):\n", X.coordinates)
|
"Element of Group Algebra over $(typeofelt(X)), of length $(length(X)):\n", X.coordinates)
|
||||||
|
|
||||||
|
|
||||||
function isequal{T, S}(X::GroupAlgebraElement{T}, Y::GroupAlgebraElement{S})
|
function isequal{T, S}(X::GroupAlgebraElement{T}, Y::GroupAlgebraElement{S})
|
||||||
|
@ -42,13 +43,13 @@ end
|
||||||
|
|
||||||
(==)(X::GroupAlgebraElement, Y::GroupAlgebraElement) = isequal(X,Y)
|
(==)(X::GroupAlgebraElement, Y::GroupAlgebraElement) = isequal(X,Y)
|
||||||
|
|
||||||
function add{T<:Number}(X::GroupAlgebraElement{T}, Y::GroupAlgebraElement{T})
|
function add{T<:CoordinateVector}(X::GroupAlgebraElement{T}, Y::GroupAlgebraElement{T})
|
||||||
X.product_matrix == Y.product_matrix || throw(ArgumentError(
|
X.product_matrix == Y.product_matrix || throw(ArgumentError(
|
||||||
"Elements don't seem to belong to the same Group Algebra!"))
|
"Elements don't seem to belong to the same Group Algebra!"))
|
||||||
return GroupAlgebraElement(X.coordinates+Y.coordinates, X.product_matrix)
|
return GroupAlgebraElement(X.coordinates+Y.coordinates, X.product_matrix)
|
||||||
end
|
end
|
||||||
|
|
||||||
function add{T<:Number, S<:Number}(X::GroupAlgebraElement{T},
|
function add{T<:CoordinateVector, S<:CoordinateVector}(X::GroupAlgebraElement{T},
|
||||||
Y::GroupAlgebraElement{S})
|
Y::GroupAlgebraElement{S})
|
||||||
warn("Adding elements with different base rings!")
|
warn("Adding elements with different base rings!")
|
||||||
return GroupAlgebraElement(+(promote(X.coordinates, Y.coordinates)...),
|
return GroupAlgebraElement(+(promote(X.coordinates, Y.coordinates)...),
|
||||||
|
@ -59,7 +60,7 @@ end
|
||||||
(-)(X::GroupAlgebraElement) = GroupAlgebraElement(-X.coordinates, X.product_matrix)
|
(-)(X::GroupAlgebraElement) = GroupAlgebraElement(-X.coordinates, X.product_matrix)
|
||||||
(-)(X::GroupAlgebraElement, Y::GroupAlgebraElement) = add(X,-Y)
|
(-)(X::GroupAlgebraElement, Y::GroupAlgebraElement) = add(X,-Y)
|
||||||
|
|
||||||
function group_star_multiplication{T<:Number}(X::GroupAlgebraElement{T},
|
function group_star_multiplication{T<:CoordinateVector}(X::GroupAlgebraElement{T},
|
||||||
Y::GroupAlgebraElement{T})
|
Y::GroupAlgebraElement{T})
|
||||||
X.product_matrix == Y.product_matrix || ArgumentError(
|
X.product_matrix == Y.product_matrix || ArgumentError(
|
||||||
"Elements don't seem to belong to the same Group Algebra!")
|
"Elements don't seem to belong to the same Group Algebra!")
|
||||||
|
@ -81,33 +82,37 @@ function group_star_multiplication{T<:Number}(X::GroupAlgebraElement{T},
|
||||||
return GroupAlgebraElement(result, X.product_matrix)
|
return GroupAlgebraElement(result, X.product_matrix)
|
||||||
end
|
end
|
||||||
|
|
||||||
function group_star_multiplication{T<:Number, S<:Number}(
|
function group_star_multiplication{T<:CoordinateVector, S<:CoordinateVector}(
|
||||||
X::GroupAlgebraElement{T},
|
X::GroupAlgebraElement{T},
|
||||||
Y::GroupAlgebraElement{S})
|
Y::GroupAlgebraElement{S})
|
||||||
S == T || warn("Multiplying elements with different base rings!")
|
S == T || warn("Multiplying elements with different base rings!")
|
||||||
return group_star_multiplication(promote(X,Y)...)
|
return group_star_multiplication(promote(X,Y)...)
|
||||||
end
|
end
|
||||||
|
|
||||||
(*){T<:Number, S<:Number}(X::GroupAlgebraElement{T},
|
(*){T<:CoordinateVector, S<:CoordinateVector}(X::GroupAlgebraElement{T},
|
||||||
Y::GroupAlgebraElement{S}) = group_star_multiplication(X,Y);
|
Y::GroupAlgebraElement{S}) = group_star_multiplication(X,Y);
|
||||||
|
|
||||||
(*){T<:Number}(a::T, X::GroupAlgebraElement{T}) = GroupAlgebraElement(
|
typeofelt{T<:Number}(X::AbstractVector{T}) = T
|
||||||
a*X.coordinates, X.product_matrix)
|
typeofelt{S<:CoordinateVector}(X::GroupAlgebraElement{S}) = typeofelt(X.coordinates)
|
||||||
|
|
||||||
function scalar_multiplication{T<:Number, S<:Number}(a::T,
|
function (*){T<:Number, S<:CoordinateVector}(a::T, X::GroupAlgebraElement{S})
|
||||||
X::GroupAlgebraElement{S})
|
W = typeofelt(X)
|
||||||
if T!=S
|
promote_type(T,W) == W || warn("Scalar and coordinates are in different rings! Promoting result to $(promote_type(T,W))")
|
||||||
warn("Scalars and coefficients ring are not the same! Trying to promote...")
|
|
||||||
end
|
|
||||||
return GroupAlgebraElement(a*X.coordinates, X.product_matrix)
|
return GroupAlgebraElement(a*X.coordinates, X.product_matrix)
|
||||||
end
|
end
|
||||||
(*){T<:Number}(a::T,X::GroupAlgebraElement) = scalar_multiplication(a, X)
|
|
||||||
|
|
||||||
//{T<:Rational, S<:Rational}(X::GroupAlgebraElement{T}, a::S) =
|
(*){T<:Number, S<:CoordinateVector}(X::GroupAlgebraElement{S}, a::T) = (*)(a, X)
|
||||||
GroupAlgebraElement(X.coordinates//a, X.product_matrix)
|
|
||||||
|
|
||||||
//{T<:Rational, S<:Integer}(X::GroupAlgebraElement{T}, a::S) =
|
function rational_division{T<:CoordinateVector, S<:Rational}(X::GroupAlgebraElement{T}, a::S)
|
||||||
X//convert(T,a)
|
if typeofelt(X) <: Rational
|
||||||
|
return GroupAlgebraElement(X.coordinates//a, X.product_matrix)
|
||||||
|
else
|
||||||
|
throw(ArgumentError("Rational division attempt on a GroupAlgebraElement of non-rational coefficients!"))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
(//)(X,a) = rational_division(X,a)
|
||||||
|
(//){S<:Integer}(X::GroupAlgebraElement, a::S) = //(X, Rational{S}(a))
|
||||||
|
|
||||||
length(X::GroupAlgebraElement) = length(X.coordinates)
|
length(X::GroupAlgebraElement) = length(X.coordinates)
|
||||||
size(X::GroupAlgebraElement) = size(X.coordinates)
|
size(X::GroupAlgebraElement) = size(X.coordinates)
|
||||||
|
|
|
@ -87,7 +87,7 @@ function create_SDP_problem(matrix_constraints,
|
||||||
return m
|
return m
|
||||||
end
|
end
|
||||||
|
|
||||||
function resulting_SOS{T<:Number}(sqrt_matrix::Array{T,2}, elt::GroupAlgebraElement{T})
|
function resulting_SOS{T<:Number}(sqrt_matrix::Array{T,2}, elt::GroupAlgebraElement)
|
||||||
result = zeros(elt.coordinates)
|
result = zeros(elt.coordinates)
|
||||||
zzz = zeros(elt.coordinates)
|
zzz = zeros(elt.coordinates)
|
||||||
L = size(sqrt_matrix,2)
|
L = size(sqrt_matrix,2)
|
||||||
|
@ -96,7 +96,7 @@ function resulting_SOS{T<:Number}(sqrt_matrix::Array{T,2}, elt::GroupAlgebraElem
|
||||||
new_base = GroupAlgebraElement(zzz, elt.product_matrix)
|
new_base = GroupAlgebraElement(zzz, elt.product_matrix)
|
||||||
result += (new_base*new_base).coordinates
|
result += (new_base*new_base).coordinates
|
||||||
end
|
end
|
||||||
return GroupAlgebraElement{T}(result, elt.product_matrix)
|
return GroupAlgebraElement(result, elt.product_matrix)
|
||||||
end
|
end
|
||||||
|
|
||||||
function correct_to_augmentation_ideal{T<:Rational}(sqrt_matrix::Array{T,2})
|
function correct_to_augmentation_ideal{T<:Rational}(sqrt_matrix::Array{T,2})
|
||||||
|
|
Loading…
Reference in New Issue