1
0
mirror of https://github.com/kalmarek/PropertyT.jl.git synced 2024-11-14 14:15:28 +01:00

Revert "Move parametrising GroupAlgebraElements by the Vector-type"

This reverts commit 0d5a2c0bc5.
This commit is contained in:
kalmar 2016-12-22 22:12:52 +01:00
parent 0d5a2c0bc5
commit 2476101af3
2 changed files with 25 additions and 30 deletions

View File

@ -6,14 +6,13 @@ import Base: size, length, norm
export GroupAlgebraElement
typealias CoordinateVector{T<:Number} AbstractVector{T}
immutable GroupAlgebraElement{T<:CoordinateVector}
coordinates::T
immutable GroupAlgebraElement{T<:Number}
coordinates::Vector{T}
product_matrix::Array{Int,2}
# basis::Array{Any,1}
function GroupAlgebraElement(coordinates::T,
function GroupAlgebraElement(coordinates::Vector{T},
product_matrix::Array{Int,2})
size(product_matrix, 1) == size(product_matrix, 2) ||
@ -23,13 +22,13 @@ immutable GroupAlgebraElement{T<:CoordinateVector}
end
# GroupAlgebraElement(c,pm,b) = GroupAlgebraElement(c,pm)
GroupAlgebraElement{T}(c::T,pm) = GroupAlgebraElement{T}(c,pm)
GroupAlgebraElement{T}(c::Vector{T},pm) = GroupAlgebraElement{T}(c,pm)
convert{T<:Number}(::Type{T}, X::GroupAlgebraElement) =
GroupAlgebraElement(convert(CoordinateVector{T}, X.coordinates), X.product_matrix)
GroupAlgebraElement(convert(Vector{T}, X.coordinates), X.product_matrix)
show{T}(io::IO, X::GroupAlgebraElement{T}) = print(io,
"Element of Group Algebra over $(typeofelt(X)), of length $(length(X)):\n", X.coordinates)
"Element of Group Algebra over ", T, "of length $(length(X)):\n", X.coordinates)
function isequal{T, S}(X::GroupAlgebraElement{T}, Y::GroupAlgebraElement{S})
@ -43,13 +42,13 @@ end
(==)(X::GroupAlgebraElement, Y::GroupAlgebraElement) = isequal(X,Y)
function add{T<:CoordinateVector}(X::GroupAlgebraElement{T}, Y::GroupAlgebraElement{T})
function add{T<:Number}(X::GroupAlgebraElement{T}, Y::GroupAlgebraElement{T})
X.product_matrix == Y.product_matrix || throw(ArgumentError(
"Elements don't seem to belong to the same Group Algebra!"))
return GroupAlgebraElement(X.coordinates+Y.coordinates, X.product_matrix)
end
function add{T<:CoordinateVector, S<:CoordinateVector}(X::GroupAlgebraElement{T},
function add{T<:Number, S<:Number}(X::GroupAlgebraElement{T},
Y::GroupAlgebraElement{S})
warn("Adding elements with different base rings!")
return GroupAlgebraElement(+(promote(X.coordinates, Y.coordinates)...),
@ -60,7 +59,7 @@ end
(-)(X::GroupAlgebraElement) = GroupAlgebraElement(-X.coordinates, X.product_matrix)
(-)(X::GroupAlgebraElement, Y::GroupAlgebraElement) = add(X,-Y)
function group_star_multiplication{T<:CoordinateVector}(X::GroupAlgebraElement{T},
function group_star_multiplication{T<:Number}(X::GroupAlgebraElement{T},
Y::GroupAlgebraElement{T})
X.product_matrix == Y.product_matrix || ArgumentError(
"Elements don't seem to belong to the same Group Algebra!")
@ -82,37 +81,33 @@ function group_star_multiplication{T<:CoordinateVector}(X::GroupAlgebraElement{T
return GroupAlgebraElement(result, X.product_matrix)
end
function group_star_multiplication{T<:CoordinateVector, S<:CoordinateVector}(
function group_star_multiplication{T<:Number, S<:Number}(
X::GroupAlgebraElement{T},
Y::GroupAlgebraElement{S})
S == T || warn("Multiplying elements with different base rings!")
return group_star_multiplication(promote(X,Y)...)
end
(*){T<:CoordinateVector, S<:CoordinateVector}(X::GroupAlgebraElement{T},
(*){T<:Number, S<:Number}(X::GroupAlgebraElement{T},
Y::GroupAlgebraElement{S}) = group_star_multiplication(X,Y);
typeofelt{T<:Number}(X::AbstractVector{T}) = T
typeofelt{S<:CoordinateVector}(X::GroupAlgebraElement{S}) = typeofelt(X.coordinates)
(*){T<:Number}(a::T, X::GroupAlgebraElement{T}) = GroupAlgebraElement(
a*X.coordinates, X.product_matrix)
function (*){T<:Number, S<:CoordinateVector}(a::T, X::GroupAlgebraElement{S})
W = typeofelt(X)
promote_type(T,W) == W || warn("Scalar and coordinates are in different rings! Promoting result to $(promote_type(T,W))")
function scalar_multiplication{T<:Number, S<:Number}(a::T,
X::GroupAlgebraElement{S})
if T!=S
warn("Scalars and coefficients ring are not the same! Trying to promote...")
end
return GroupAlgebraElement(a*X.coordinates, X.product_matrix)
end
(*){T<:Number}(a::T,X::GroupAlgebraElement) = scalar_multiplication(a, X)
(*){T<:Number, S<:CoordinateVector}(X::GroupAlgebraElement{S}, a::T) = (*)(a, X)
//{T<:Rational, S<:Rational}(X::GroupAlgebraElement{T}, a::S) =
GroupAlgebraElement(X.coordinates//a, X.product_matrix)
function rational_division{T<:CoordinateVector, S<:Rational}(X::GroupAlgebraElement{T}, a::S)
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))
//{T<:Rational, S<:Integer}(X::GroupAlgebraElement{T}, a::S) =
X//convert(T,a)
length(X::GroupAlgebraElement) = length(X.coordinates)
size(X::GroupAlgebraElement) = size(X.coordinates)

View File

@ -87,7 +87,7 @@ function create_SDP_problem(matrix_constraints,
return m
end
function resulting_SOS{T<:Number}(sqrt_matrix::Array{T,2}, elt::GroupAlgebraElement)
function resulting_SOS{T<:Number}(sqrt_matrix::Array{T,2}, elt::GroupAlgebraElement{T})
result = zeros(elt.coordinates)
zzz = zeros(elt.coordinates)
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)
result += (new_base*new_base).coordinates
end
return GroupAlgebraElement(result, elt.product_matrix)
return GroupAlgebraElement{T}(result, elt.product_matrix)
end
function correct_to_augmentation_ideal{T<:Rational}(sqrt_matrix::Array{T,2})