Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "TaylorModels"
uuid = "314ce334-5f6e-57ae-acf6-00b6e903104a"
version = "0.13.0"
version = "0.13.1"
repo = "https://github.com/JuliaIntervals/TaylorModels.jl.git"

[deps]
Expand Down Expand Up @@ -31,8 +31,8 @@ Random = "1"
RecipesBase = "1"
Reexport = "1"
StaticArrays = "1.9"
TaylorIntegration = "0.18.18"
TaylorSeries = "0.23"
TaylorIntegration = "0.18.19"
TaylorSeries = "0.23.1"
Test = "1"
julia = "1.10"

Expand Down
48 changes: 3 additions & 45 deletions src/valid_integ/integ_utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -302,48 +302,6 @@ function _update_output!(xTM1v::AbstractVector{<:TaylorModel1}, x1N)
end


# The following is used to get an exact, floating number representation,
# of the step size δt and of the accumulated time
# Knuth's TwoSum: s + e == a + b exactly
@inline function _two_sum(a::T, b::T) where {T<:AbstractFloat}
s = a + b
bb = s - a
e = (a - (s - bb)) + (b - bb)
return s, e
end

"""
_exact_step(t0, δt, tmax, sign_tstep) -> δt′

Step with `t0 + δt′` exact in floating point and `|δt′| ≤ |δt|`, except that
a step reaching `tmax` lands exactly on it. `sign_tstep = ±1` (forward/backward).
"""
function _exact_step(t0::T, δt::T, tmax::T, sign_tstep::Int) where {T<:AbstractFloat}
t1 = t0 + δt
sign_tstep*t1 >= sign_tstep*tmax && (t1 = tmax)
for _ in 1:8
δt1 = t1 - t0
s, e = _two_sum(t0, δt1)
if s == t1 && iszero(e) # t0 + δt1 == t1 exactly
if iszero(δt1) # request < ½ ulp(t0): one ulp
t1 = sign_tstep > 0 ? nextfloat(t0) : prevfloat(t0)
return t1 - t0
end
(t1 == tmax || sign_tstep*δt1 <= sign_tstep*δt) && return δt1
t1 = sign_tstep > 0 ? prevfloat(t1) : nextfloat(t1) # ½-ulp overshoot
else
# t1 - t0 not representable (t1 not within a factor 2 of t0): take an
# exact shorter step; later steps reach tmax exactly (Sterbenz).
if sign_tstep*t0 > 0 # away from 0: at most doubling
δt = sign_tstep * min(abs(δt1), abs(t0))
elseif sign_tstep*tmax >= 0 && abs(t0) <= abs(δt) # 0 lies on the way
δt = -t0 # stop exactly at 0
else # toward 0, tmax before 0
δt = sign_tstep * min(abs(δt1), abs(t0)) / 2
end
t1 = t0 + δt
end
end
error("_exact_step: no exact step found (t0 = $t0, δt = $δt)")
end
_exact_step(t0::Real, δt::Real, tmax::Real, ::Int) = δt # exact types (e.g. Rational)
# Smallest nonzero exact advance, for callers that must make progress
_ulp_step(t0::T, sg::Int) where {T<:AbstractFloat} =
(sg > 0 ? nextfloat(t0) : prevfloat(t0)) - t0
8 changes: 5 additions & 3 deletions src/valid_integ/validated_integ3.jl
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,8 @@ function validated_step3!(vB::Val{B}, f!,
δt = min(δt, sign_tstep*(tmax-t0))
δt = sign_tstep * δt
# Representable step: t0 + δt exact in floating point
δt = _exact_step(t0, δt, tmax, sign_tstep)
δt = TI._exact_step(t0, δt, tmax, sign_tstep)
iszero(δt) && (δt = _ulp_step(t0, sign_tstep))
return δt
end

Expand Down Expand Up @@ -462,7 +463,8 @@ function _validation3!(f!,
if bool_red
reduced_abstol = reduced_abstol/10
δt = δt / 2
δt = _exact_step(t[0], δt, tmax, sign_tstep)
δt = TI._exact_step(t[0], δt, tmax, sign_tstep)
iszero(δt) && (δt = _ulp_step(t0, sign_tstep))
continue
end
@warn("Minimum absolute tolerance reached: ",
Expand Down Expand Up @@ -499,7 +501,7 @@ function _validation3!(f!,
# issatisfied = check_property(t[0]+δt, xvv)
# if !issatisfied
# # δt = δt/2
# # δt = _exact_step(t[0], δt, tmax, sign_tstep)
# # δt = TI._exact_step(t[0], δt, tmax, sign_tstep)
# bool_red = reduced_abstol > minabstol
# @info("issatisfied: ", bool_red, δt)
# if bool_red
Expand Down
62 changes: 5 additions & 57 deletions test/validated_integ3.jl
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
# Tests for validated_integ3 and its building blocks.
#
# 1. _exact_step representable time steps
# 2. picard_lindelof no aliasing, exact Picard iterates, argument order
# 3. cache the Picard time of the first step is t0
# 4. monotonicity_bounder range enclosure (soundness, tightness)
# 5. qrprecondition! (⋆) and v ∈ L∘ρ, exact in BigFloat, T ∈ {Float64, Interval}
# 6. integration completion, pointwise containment x(t;x0) ∈ Φ_k(τ, σ_k(ξ))
# 1. picard_lindelof no aliasing, exact Picard iterates, argument order
# 2. cache the Picard time of the first step is t0
# 3. monotonicity_bounder range enclosure (soundness, tightness)
# 4. qrprecondition! (⋆) and v ∈ L∘ρ, exact in BigFloat, T ∈ {Float64, Interval}
# 5. integration completion, pointwise containment x(t;x0) ∈ Φ_k(τ, σ_k(ξ))
# with exact times, tdrift == 0, tightness
#
# The arithmetic of TaylorModel1{TaylorModelN} (products, squares, numbers, integration) is
Expand Down Expand Up @@ -256,31 +255,6 @@ function check_tightness_1d(name, sol, fex, X0; maxratio, printinfo=false)
@test tp.maxratio <= maxratio
end

# --- exact step ---------------------------------------------------------------
function check_step(t0, δt, tmax, sgn)
δt1 = VI._exact_step(t0, δt, tmax, sgn)
t1 = t0 + δt1
s, e = VI._two_sum(t0, δt1)
@test s == t1 && iszero(e) # exact
@test t1 == tmax || abs(δt1) <= abs(δt) || # conservative, except landing on
t1 == (sgn > 0 ? nextfloat(t0) : prevfloat(t0)) # tmax or a sub-ulp request
@test sign(δt1) == sgn # direction
@test sgn * t1 <= sgn * tmax # no overshoot
return δt1
end

# Repeated steps with the same requested δt until tmax is reached exactly;
# returns the number of steps (every step checked with check_step).
function reach_tmax(t0, δt, tmax, sgn; maxsteps = 64)
t, n = t0, 0
while t != tmax
t += check_step(t, δt, tmax, sgn)
n += 1
n < maxsteps || error("reach_tmax: tmax not reached")
end
return n
end

# --- QR preconditioning ------------------------------------------------------
# Random v = c + Aξ + h(ξ) + Δ on B (interval coefficients widened by `wid`)
function random_vTMN(rng, X, A, ::Type{T}; nl = 0.05, remr = 1e-6, wid = 1e-9) where {T}
Expand Down Expand Up @@ -346,32 +320,6 @@ rotation(θ) = [cos(θ) -sin(θ); sin(θ) cos(θ)]
setprecision(BigFloat, 256)
local printinfo = false

@testset "_exact_step" begin
s, e = VI._two_sum(1.0, 1e-17)
@test big(s) + big(e) == big(1.0) + big(1e-17)
@test check_step(0.0, 0.1, 10.0, 1) == 0.1 # t0 = 0
check_step(4.0, 0.8802595366450658, 10.0, 1) # |t0| ≥ |δt|
check_step(10.0, -0.3, 0.0, -1)
check_step(1e-3, 0.7, 10.0, 1) # 0 < |t0| < |δt|
check_step(-1e-3, -0.7, -10.0, -1)
@test check_step(7565.0, 8e-14, 8000.0, 1) == eps(7565.0) # request < ½ ulp(t0)
# requested step larger than what is left (TI's estimate is often larger):
# the step is clipped and tmax is reached exactly, possibly in a few steps
# when tmax - t0 is not representable (tmax not within a factor 2 of t0)
@test reach_tmax(0.0, 0.5, 0.7, 1) == 2 # 0.5, then 0.2 → 0.7
@test reach_tmax(4.0, 9.0, 7.3, 1) == 1 # Sterbenz: one step
@test reach_tmax(5.0, -9.0, 0.1, -1) <= 8 # 0.1 - 5 not representable
@test reach_tmax(5.0, -20.0, -3.0, -1) <= 8 # across 0
@test reach_tmax(1e-3, 10.0, 7.3, 1) <= 16 # 0 < |t0| ≪ |δt|
rng = MersenneTwister(2026)
for _ in 1:2_000
sgn = rand(rng, (-1, 1))
t0 = sgn * 10 * rand(rng) * rand(rng, (0.0, 1e-6, 1.0, 1e3))
δt = sgn * rand(rng) * rand(rng, (1e-8, 1e-2, 1.0))
check_step(t0, δt, t0 + sgn * 100, sgn)
end
end

@testset "picard_lindelof" begin
function fb!(dx, x, p, t) # autonomous
dx[1] = x[2]
Expand Down
Loading