Understanding Taylor models
(by Sean Cowan)
Analogously to the arithmetic operators of gduals, the interface with Taylor models in pyaudi is similar, if not identical.
Importing stuff
[7]:
from pyaudi import gdual_double as gdual, taylor_model, int_d
Defining function
We will try to approximate a function — shown below, as one could also do with gduals, and show how Taylor models differ from gduals.
Now, to approximate a function using Taylor expansions, we need to define the expansion order and expansion point:
Taylor polynomial (with gduals)
[25]:
order = 4
exp_points = {"x": 2.0}
x = gdual(exp_points["x"], "x", order)
fx = 1 / x + x
print(fx)
2.5+0.125*dx**2+0.03125*dx**4+0.75*dx-0.0625*dx**3
Taylor model
The result is the expected fourth order Taylor polynomial of function \(f(x)\). If however, we would like to do the same computation with Taylor models by encompassing the higher order terms into a remainder interval, we also need to define the domain of validity and initial remainder bound. The same steps are performed, yet now there is a non-zero remainder bound.
[27]:
rem_bound = int_d(0.0, 0.0)
domain = {"x": int_d(1.9, 2.1)}
x = gdual(exp_points["x"], "x", order)
tm_x = taylor_model(x, rem_bound, exp_points, domain)
tm_fx = 1 / tm_x + tm_x
tm_fx
[27]:
Taylor Polynomial:
2.5+0.125*dx**2+0.03125*dx**4+0.75*dx-0.0625*dx**3
Remainder Bound: [-2.12558e-07, 2.12558e-07]
Expansion Point: {x: 2}
Domain: {x:[1.9, 2.1]}
This remainder bound means that, given a Taylor polynomial valid within the domain of \([1.9, 2.1]\), one would need to add the lower and upper bound as a constant to that Taylor polynomial to ensure that, whatever \(x\) value is chosen, the function value of \(f(x)\) will be within that range. This differs fundamentally from the information that the gdual provides, since it will provide no mathematical guarantee on the distance from the actual function.