-
Notifications
You must be signed in to change notification settings - Fork 17
Improve product of TaylorModelNs
#31
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -208,28 +208,66 @@ end | |
| # Multiplication | ||
| function *(a::TaylorModelN, b::TaylorModelN) | ||
| @assert a.x0 == b.x0 && a.I == b.I | ||
|
|
||
| # Polynomial product with extended order | ||
| order = max(get_order(a), get_order(b)) | ||
| @assert 2*order ≤ get_order() | ||
| aext = TaylorN(copy(a.pol.coeffs), 2*order) | ||
| bext = TaylorN(copy(b.pol.coeffs), 2*order) | ||
| res = aext * bext | ||
|
|
||
| # Returned polynomial | ||
| bext = TaylorN( copy(res.coeffs[1:order+1]) ) | ||
|
|
||
| # Bound for the neglected part of the product of polynomials | ||
| res[0:order] .= zero(eltype(res)) | ||
| aux = a.I - a.x0 | ||
| Δnegl = res(aux) | ||
|
|
||
| # Remainder of the product | ||
| Δa = a.pol(aux) | ||
| Δb = b.pol(aux) | ||
| Δ = Δnegl + Δb * a.rem + Δa * b.rem + a.rem * b.rem | ||
| # Some definitions related to the order of some polynomials | ||
| orderTS = get_order() # maximum order, fixed by `TaylorSeries._params_TaylorN_` | ||
| order_a = get_order(a) | ||
| order_b = get_order(b) | ||
| order_prod = 2 * max(order_a, order_b) | ||
|
|
||
| # The returned polynomial has no terms beyond `orderTS` | ||
| if order_prod ≤ orderTS | ||
| apol = TaylorN(a.pol.coeffs, order_prod) | ||
| bpol = TaylorN(b.pol.coeffs, order_prod) | ||
| res = apol * bpol | ||
| Δa = a.pol(aux) | ||
| Δb = b.pol(aux) | ||
| Δ = Δb * a.rem + Δa * b.rem + a.rem * b.rem | ||
| return TaylorModelN(res, Δ, a.x0, a.I) | ||
| end | ||
|
|
||
| # The resulting product has a part whose order is larger than `orderTS`; | ||
| # a bound for this polynomial has to be included | ||
| apol = TaylorN(a.pol.coeffs, orderTS) | ||
| bpol = TaylorN(b.pol.coeffs, orderTS) | ||
| res = apol * bpol # Trunctated polynomial to order `orderTS` | ||
| Δa = apol(aux) | ||
| Δb = bpol(aux) | ||
| Δ = Δb * a.rem + Δa * b.rem + a.rem * b.rem | ||
| N = get_numvars() | ||
|
|
||
| # We evaluate *explicitely* each term of the product of coefficients at `aux` | ||
| Δnegl = zero(Δ) | ||
| for order = orderTS+1:order_prod | ||
| orderini = order - orderTS | ||
| for inda = orderini:order_a | ||
| indb = order - inda | ||
| # Δnegl += evaluate(apol[inda], aux) * evaluate(bpol[indb], aux) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You could try evaluating all of these bounds once before the loop (and storing them in new arrays), and then just indexing into the arrays inside the What I had done previously was store these bounds in the |
||
|
|
||
| # Coefficient tables of corresponding `HomogeneousPolynomial`s | ||
| @inbounds cta = TaylorSeries.coeff_table[inda+1] | ||
| @inbounds ctb = TaylorSeries.coeff_table[indb+1] | ||
|
|
||
| for i in eachindex(cta) | ||
| @inbounds a_coeff = apol.coeffs[inda+1][i] | ||
| iszero(a_coeff) && continue | ||
| for j in eachindex(ctb) | ||
| @inbounds b_coeff = bpol.coeffs[indb+1][j] | ||
| iszero(b_coeff) && continue | ||
|
|
||
| # Evaluation of monomials | ||
| tmp = one(Δ) | ||
| for n in 1:N | ||
| @inbounds tmp *= aux[n]^(cta[i][n]+ctb[j][n]) | ||
| end | ||
| Δnegl += a_coeff * b_coeff * tmp | ||
| end | ||
| end | ||
| end | ||
| end | ||
|
|
||
| return TaylorModelN(bext, Δ, a.x0, a.I) | ||
| return TaylorModelN(res, Δ+Δnegl, a.x0, a.I) | ||
| end | ||
|
|
||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.