-
Notifications
You must be signed in to change notification settings - Fork 30
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
Possible future internal improvements #31
Comments
I am impressed, good work ! This might have a big impact in the performance of PolyJuMP and SumOfSquares :)
couldn't you just do:
I haven't yet checked the details of the implementation but it seems to me that we could keep several implementations. They would share common functions thanks to abstract types like We would could have
that creates a variable
then it would default to |
I think you maybe mean StaticPolynomials (aside: these names are not great. I'm open to more clear names)? For TypedPolynomials, the monomial instance holds the exponents, so we need to keep the instance as a member of the Term. For StaticPolynomials you're totally right: in fact, what you suggested is actually what's in the code; I just put the wrong thing in the issue above.
Wow, that's true. I hadn't thought of that, but I think you're right. These two implementations can probably share a lot of code. OK, I'll see if it's possible. |
This looks very impressive, @rdeits. Two quick questions/comments:
|
Yes, that's right. I'm still working the implementation out, though, so it might turn out to be cleaner than my current version.
Absolutely. I'm doing some reworking of TypedPolynomials now to try to generalize as much as possible, then I'll try to wire up StaticPolynomials through the same general functions so that we can get a fair test. |
Yes, indeed, I meant I also like the fact that with One other concern I have with In fact it seems to me that In short, I think we need to choose between
About the naming, if we remove the current implementation we might rename |
@blegat thanks for all the comments 😄 . I agree with all of your concerns about StaticPolynomials. One more weirdness of StaticPolynomials is that if you want to create a concretely typed vector containing [1, x, x^2], then the type of that vector has to be:
which is crazy. Essentially, StaticPolynomials only ever makes sense if you always store tuples, not vectors. However, I think the good news is that it's not much more work to get StaticPolynomials functioning alongside TypedPolynomials. Providing both implementations would be neat. I think my plan is:
And yes, I think |
I like the plan, thanks for the hard work ! Let me know if you need any help. |
I was thinking about something. Since TypedPolynomials and StaticPolynomials use |
I'm not sure I know what you mean. v0.6 brought in some tighter restrictions on what can be done inside the body of a |
I was talking about static compilation, see here. |
Ah, understood. Yes, then that would be a reasonable thing to do. I'll keep trying to move as much behavior as possible to the abstract types. |
Good news! I've managed to eliminate all of the Of course, StaticPolynomials is a whole other story. Doing that without |
First of all, thank you for your great work, the development of this package will probably carry our (admittedly very MultiPoly-dependent) code into the future! I am starting to migrate our code to MultivariatePolynomials in the course of migrating to julia v0.6, however, I would like to circumvent the performance gap (ideally gain performance) which appears (#3) to exist without the improvements made in TypedPolynomials. Is there a branch in MultivariatePolynomials which integrates TypedPolynomials at this time? |
Sorry, not yet. It's definitely still on my radar, but real life has a habit of intruding. The primary missing features are basic calculus (pretty easy) and non-commutative variables (possibly not so easy). |
Finally \o/ ! |
Continuing the discussion from over at #28 ...
I've spent some time working on two different possible alternative designs for multivariate polynomials:
They're both still extremely rough (only addition and multiplication are tested). Both are using some new type system features from Julia 0.6, so they're both 0.6-only.
A consequence of both of these designs is that a variable's name is its identity. That is, any two variables with the name
:x
are the same variable. Otherwise code like:would have to compile new methods for each loop iteration and would be type-unstable. That's a big change from MultivariatePolynomials, where every variable has a unique ID. It's similar, however, to the way MultiPoly.jl works, and I think I'm OK with it.
TypedPolynomials
In this design, we have, roughly:
StaticPolynomials
This design has:
Those two designs have led to some different design choices. In TypedPolynomials, I've kept the standard Vector of Terms in each polynomial. That's necessary because when adding two polynomials, we can't infer at compile time how many terms the result will have. In StaticPolynomials, however, we can infer the number of terms, but each term is a different type, so the terms are stored in a heterogeneous tuple of Terms.
Advantages of both packages:
The advantage of this syntax is that it doesn't require allocating a vector of variables and a vector of values. In fact, complete substitution of all variables in a polynomial now allocates no memory at all.
Notable differences:
3x + 2y + 1 + x + z^3
inefficient. Some macro magic similar to what JuMP uses could help here.x^n
depends on the value ofn
. This is less of an issue in julia 0.6 wherex^n
is lowered tox^Val{n}
, but it still means code like[x^i for i in 0:3]
is inherently type-unstable.differentiate(3x, x)
isInt
, while TypedPolynomials could not.Performance
As an example, constructing the polynomial
x^2 + y + x * x + 3 * x * y + x * y
on my laptop with Julia 0.6 takes:MultivariatePolynomials:
TypedPolynomials
StaticPolynomials
And substitution takes:
MultivariatePolynomials:
TypedPolynomials
StaticPolynomials
Summary
I'm currently leaning towards TypedPolynomials. It's easier to understand and develop, and I think its performance is good enough for what we're doing. But I'm interested in getting your opinion on both of these designs. I have a demo of TypedPolynomials here: https://github.com/rdeits/TypedPolynomials.jl/blob/master/demo.ipynb which shows off some of the basic features.
The text was updated successfully, but these errors were encountered: