JuliaIntervals / TaylorModels.jl

Rigorous function approximation using Taylor models in Julia
Other
63 stars 14 forks source link

Behaviour of the evaluate function #140

Open orkolorko opened 1 year ago

orkolorko commented 1 year ago

Dear all, I have a question on the behavior of the evaluate function, or to be more precise, on the behavior of the iscontained function.

At the moment it is defined as

iscontained(a, tm::TaylorModelN) = a ∈ domain(tm)-tm.x0

this leads to, in my opinion, unexpected behavior: as an example if tm is a Taylor model centered at 5, with domain [4,6], then tm(5) fails the iscontained assertion, i.e., the evaluation fails on the expansion point.

Minimum failing code:

julia> tm = TaylorModel1(10, 5, Interval(4, 6))
 5 + 1 t + [0, 0]

julia> tm(5)
ERROR: AssertionError: iscontained(a, tm)

If this is a design choice of the package I think this should be documented.

lbenet commented 1 year ago

Thanks @orkolorko for bringing this up and open the discussion. I agree that it may be counterintuitive and it requires documentation... as always, lack of time is the reason.

Let me argue why this is designed the way it is. The polynomial part is a truncated Taylor series, which has terms of the form $(x-x_0)^k$, where $x\in D$ is the actual value we are interested, $D$ is the domain, and $x_0\in D$ is the expansion point. The Taylor approximation makes sense if $h = x-x_0$ is "small enough"; $h$ is the quantity actually used in evaluate (defined in TaylorSeries.jl). So, in order to check that $h$ makes sense, we have to check that $x = x_0 + h \in D$, which is what iscontained does.

Does this explanation makes sense?

orkolorko commented 1 year ago

Dear @lbenet , thank you, for the explanation.

I think it makes sense and I think it is a good interpretation of the mathematical idea, i.e., the fact that TaylorModel1(6, 5, Interval(4,6)) is not a point, but a function with an associated domain and expansion point.

I think what confused me the most is the tube plot in the documentation and the associated recipe: Tube plot

tm6 = TaylorModel1(6, interval(x0), a)
ftm6 = f(tm6)
plot(ftm6, label="6th order")

plots a "tube" around the original function, but ftm6(x) is computing the value of

$$ \sum_{i=0}^6 a_i x^i+\Delta $$

In Mioara's thesis Def. 2.1.3, and in the documentation of the package a Taylor model is defined as a polynomial such that

$$ P(x)-f(x)\in \Delta, \forall x \in [a,b] $$

but what is exposed by the interface is ftm6(x) = P(x+x_0), i.e., ftm6 is translated.

I think both the approaches work equally well but this needs clarifying; if you want I can try to write down a small note on this in the documentation and submit it as a pull request.

lbenet commented 1 year ago

Yes, please, help us with the documentation or whatever other improvement it is worth adding to the package!