From b648e49225773b322a97f90cc96b5178dd8efda5 Mon Sep 17 00:00:00 2001 From: "David P. Sanders" Date: Tue, 10 Mar 2020 00:01:28 -0400 Subject: [PATCH] Intervalize contents of Aff --- src/aff.jl | 76 ++++----------------------------------------------- src/affine.jl | 4 +-- 2 files changed, 8 insertions(+), 72 deletions(-) diff --git a/src/aff.jl b/src/aff.jl index 6442c90..303a697 100644 --- a/src/aff.jl +++ b/src/aff.jl @@ -11,10 +11,10 @@ Affine form with center `c`, affine components `γ` and error `Δ`. Variant where Δ is an interval """ -struct Aff{N,T<:AbstractFloat} +struct Aff{N,T<:Interval} c::T # mid-point γ::SVector{N,T} # affine terms - Δ::Interval{T} # error term + Δ::T # error term end @@ -27,11 +27,11 @@ end """ Make an `Aff` based on an interval, which is number `i` of `n` total variables. """ -function Aff(X::Interval{T}, n, i) where {T} - c = mid(X) - r = radius(X) +function Aff(X::Interval{T}, n::Int, i) where {T} + c = interval(mid(X)) + r = interval(radius(X)) - γ = SVector(ntuple(j->i==j ? r : zero(r), n)) + γ = SVector(ntuple(j -> i==j ? r : zero(r), n)) return Aff(c, γ, Interval{T}(0)) end @@ -97,70 +97,6 @@ end Base.literal_pow(::typeof(^), x::Aff, ::Val{p}) where {T,p} = x^p -x = Aff{2,Float64}(0.0, SVector(1.0, 0.0), 0..0) -y = Aff{2,Float64}(0.0, SVector(0.0, 1.0), 0..0) - - -x = Aff(3..5, 2, 1) -y = Aff(2..4, 2, 2) -# -# 3-x -# interval(3-x) -# -# x + y -# -# -# interval(x+y) -# -# x * y -# interval(x * y) -# -# interval(x * y) -# interval(x) * interval(y) -# -# z = Aff(-1..1, 1, 1) -# z^2 -# interval(z^2) -# -# using Polynomials -# -# p = Poly([-3, 1]) -# p2 = p^8 -# -# x = 4 ± 1e-4 -# y = Aff(x, 1, 1) -# -# interval(y) -# interval(p2(x)) -# interval(p2(y)) -# -# @time interval(p2(y)) -# -# -# f( (x, y) ) = [x^3 + y, (x - y)^2] -# -# X = IntervalBox(-1..1, -1..1) -# -# f(X) -# -# xx = Aff(X[1], 2, 1) -# yy = Aff(X[2], 2, 2) -# -# interval.(f((xx, yy))) -# -# f(X) -# -# -# -# -# x = Aff(4..6, 1, 1) # example from Messine -# f(x) = x * (10 - x) -# -# f(x) -# interval(f(x)) -# -# interval(10*x - x^2) - "General formula for affine approximation of nonlinear functions" function affine_approx(x::Aff, α, ζ, δ) diff --git a/src/affine.jl b/src/affine.jl index b858531..eb94135 100644 --- a/src/affine.jl +++ b/src/affine.jl @@ -11,9 +11,9 @@ Affine form with center `c`, affine components `γ` and error `Δ`. Variant where Δ is an interval """ -struct Affine{N,T<:AbstractFloat} +struct Affine{N,T<:Interval} affine::Aff{N,T} - range::Interval{T} + range::T end interval(x::Affine) = x.range