From 52a68e84294ebccf0a63feeb47d4602ee9689883 Mon Sep 17 00:00:00 2001 From: kalmar Date: Tue, 14 Mar 2017 23:34:47 +0100 Subject: [PATCH] tidy ValidatedNumerics and move functions --- src/checksolution.jl | 36 ++++++++++++++++++++++-------------- 1 file changed, 22 insertions(+), 14 deletions(-) diff --git a/src/checksolution.jl b/src/checksolution.jl index c034851..ce9ecc5 100644 --- a/src/checksolution.jl +++ b/src/checksolution.jl @@ -1,7 +1,10 @@ using ProgressMeter -using ValidatedNumerics import Base: rationalize +using ValidatedNumerics +setrounding(Interval, :narrow) +setdisplay(:standard) + function EOI{T<:Number}(Δ::GroupAlgebraElement{T}, κ::T) return Δ*Δ - κ*Δ end @@ -41,6 +44,22 @@ function correct_to_augmentation_ideal{T<:Rational}(sqrt_matrix::Array{T,2}) return sqrt_corrected end +import ValidatedNumerics.± + +function (±){T<:Number}(X::AbstractArray{T}, tol::Real) + r{T}(x::T) = (x == zero(T)? @biginterval(0) : x ± tol) + return r.(X) +end + +(±)(X::GroupAlgebraElement, tol::Real) = GroupAlgebraElement(X.coefficients ± tol, X.product_matrix) + +function Base.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 + +ℚ(x, tol::Real) = rationalize(BigInt, x, tol=tol) function check_solution{T<:Number}(κ::T, sqrt_matrix::Array{T,2}, Δ::GroupAlgebraElement{T}; verbose=true, augmented=false) result = compute_SOS(sqrt_matrix, Δ) if augmented @@ -67,21 +86,10 @@ function check_solution{T<:Number}(κ::T, sqrt_matrix::Array{T,2}, Δ::GroupAlge return distance_to_cone end -import ValidatedNumerics.± -function (±)(X::AbstractArray, tol::Real) - r{T}(x::T) = ( x==zero(T) ? @interval(x) : x ± tol) - return r.(X) + + end -(±)(X::GroupAlgebraElement, tol::Real) = GroupAlgebraElement(X.coefficients ± tol, X.product_matrix) - -function Base.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 - -ℚ(x, tol::Real) = rationalize(BigInt, x, tol=tol) function ℚ_distance_to_positive_cone(Δ::GroupAlgebraElement, κ, A; tol=1e-7, verbose=true, rational=false)