Dear SymPy list.

I'm playing around with polynomials in the context of spline curves.

I want to use a cubic polynomial with yet unknown coefficients like this:

>>> import sympy as sp
>>> t, a0, a1, a2, a3 = sp.symbols('t, a:4', real=True)
>>> a3 * t**3 + a2 * t**2 + a1 * t + a0
a0 + a1*t + a2*t**2 + a3*t**3

The problem here is that the displayed order of terms is reversed,
normally the highest power of t should come first.
I guess this is because SymPy doesn't know that the coefficients a0
etc. are constants and shouldn't be treated like variables.
So in fact this polynomial isn't sorted by powers of t but instead by
the coefficients.

Is there a way to get around this?

At some later point, I have expressions like this (without t):

a1 + 2*a2 + 3*a3

It would make sense in my case to also display them reversed like this:

3*a3 + 2*a2 + a1

Is it possible to create a new type of symbol with non-default ordering?
Is it possible to define that this order is "ascending": a3, a2, a1, a0?
It doesn't have to be a generic solution, I'm OK with having those 4
special symbols.

Or is there an entirely different and much better way to do this?

I know that I could just use a, b, c, d instead of a3, a2, a1, a0 and
it would work, but I would really like to see the connection between a
coefficient and its power of t.

For the record, I also quickly tried to use IndexedBase to get a3, a2,
a1 and a0, and it turns out that although the LaTeX display of the
symbols looks the same (in text mode it's different), they are sorted
differently.

>>> b = sp.IndexedBase('b')
>>> b[3] * t**3 + b[2] * t**2 + b[1] * t + b[0]
t**3*b[3] + t**2*b[2] + t*b[1] + b[0]

They are sorted after the powers of t, which isn't what I want, either.

cheers,
Matthias

-- 
You received this message because you are subscribed to the Google Groups 
"sympy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sympy+unsubscr...@googlegroups.com.
To post to this group, send email to sympy@googlegroups.com.
Visit this group at https://groups.google.com/group/sympy.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sympy/CAFesC-fMMxYqirZD1wmAX32Wsxz-NOQHiryCWp%2ByDDiUN6agng%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to