-
Notifications
You must be signed in to change notification settings - Fork 53
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
Evaluate for TaylorN fails with ModelingToolkit #242
Comments
Fun |
I do reproduce the problem. No idea where to look for the solution... |
Yet, it does work with julia> x[1]([xx, yy])
0 + 1.0 * (xx ^ 1 * yy ^ 0) So the problem may be related to the Horner implementation. |
I don't think Horner is used for multivariate polynomials? sum(h([x, y]) for h in t)` to evaluate a |
Ah you mean that's too naive and there's some complicated extension of Horner for multivariate polynomials. |
The way we do it is not really Horner, you are right, but some sort of generalization. If I recall correctly, evaluate separately the homogeneous polynomials of given order, sort them, and then add them. Sorting them is to avoid the usual cancellations. In any case, the observation holds: it seems evaluation works for |
I think I found what the problem and it has nothing to do with the way we compute the evaluation
julia> using ModelingToolkit
julia> using TaylorSeries
julia> x, y = set_variables("x", numvars=2);
julia> @variables xx, yy;
julia> @which evaluate(x, [xx, yy])
evaluate(a::TaylorN, vals) in TaylorSeries at /Users/benet/.julia/dev/TaylorSeries/src/evaluate.jl:237
julia> @which evaluate(x, (xx, yy))
evaluate(a::TaylorN, vals) in TaylorSeries at /Users/benet/.julia/dev/TaylorSeries/src/evaluate.jl:237 Ideally, julia> TaylorSeries.NumberNotSeries
Union{Real, Complex} The question is: how can we update (dynamically) |
Great catch! I believe there should not be a
and
Julia will take care of choosing the correct one by dispatch. |
Using #247 partially solves this issue: julia> using TaylorSeries, ModelingToolkit
julia> x, y = set_variables("x", numvars=2);
julia> @variables xx, yy;
julia> @which evaluate(x, [xx, yy])
evaluate(a::TaylorN, vals) in TaylorSeries at /Users/benet/.julia/dev/TaylorSeries/src/evaluate.jl:235
julia> @which evaluate(x, (xx, yy))
evaluate(a::TaylorN{T}, vals::Tuple{Vararg{T,N}} where T where N) where T<:Number in TaylorSeries at /Users/benet/.julia/dev/TaylorSeries/src/evaluate.jl:223 Note that the different methods are properly recognized. Yet, the evaluation doesn't quite work: julia> evaluate(x, [xx, yy])
ERROR: MethodError: no method matching isless(::Operation, ::Operation)
... The problem is that evaluating on @dpsanders What do you think? |
The following is a proof-of-concept of what I would get using the keyword variable with the example you outlined above (it uses the last commit in #247): julia> evaluate(t, [xx, yy], sorting=false)
(((((0 + (0 + 1.0 * (xx ^ 0 * yy ^ 1))) + (0 + 1.0 * (xx ^ 2 * yy ^ 0))) + 0) + 0) + 0) + 0 |
That looks great, thanks! |
What is |
I think it was introduced there to add the different contributions of the monomials reordered from the smallest to the largest (according to |
Reopening, as a reminder... |
The text was updated successfully, but these errors were encountered: