From 53dec056e06495503477691990f810cfcd7a518e Mon Sep 17 00:00:00 2001 From: kalmar Date: Mon, 9 Jan 2017 00:59:40 +0100 Subject: [PATCH] Rationalizing properly done --- GroupAlgebras.jl | 8 +++++++- property(T).jl | 7 +++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/GroupAlgebras.jl b/GroupAlgebras.jl index 494fc9d..cc2d4a6 100644 --- a/GroupAlgebras.jl +++ b/GroupAlgebras.jl @@ -2,7 +2,7 @@ module GroupAlgebras import Base: convert, show, isequal, == import Base: +, -, *, // -import Base: size, length, norm +import Base: size, length, norm, rationalize export GroupAlgebraElement @@ -112,4 +112,10 @@ length(X::GroupAlgebraElement) = length(X.coefficients) size(X::GroupAlgebraElement) = size(X.coefficients) norm(X::GroupAlgebraElement, p=2) = norm(X.coefficients, p) +rationalize{T<:Integer, S<:Number}(::Type{T}, X::GroupAlgebraElement{S}; + tol=eps(S)) = + GroupAlgebraElement( + rationalize(T, X.coefficients, tol=tol), X.product_matrix) + + end diff --git a/property(T).jl b/property(T).jl index 0100e86..a3fe9f7 100644 --- a/property(T).jl +++ b/property(T).jl @@ -1,4 +1,5 @@ using JuMP +import Base: rationalize function products{T<:Real}(S1::Array{Array{T,2},1}, S2::Array{Array{T,2},1}) result = [0*similar(S1[1])] @@ -109,3 +110,9 @@ function correct_to_augmentation_ideal{T<:Rational}(sqrt_matrix::Array{T,2}) end return sqrt_corrected end +function rationalize{T<:Integer, S<:Real}(::Type{T}, + X::AbstractArray{S}; tol::Real=eps(eltype(X))) + + r(x) = rationalize(T, x, tol=tol) + return r.(X) +end