Polynomials: missed opportunity to simplify?

25 views
Skip to first unread message

Matthias Geier

unread,
Jun 26, 2018, 8:31:32 AM6/26/18
to sy...@googlegroups.com
Dear list.

Sorry for the strange title, I couldn't come up with anything more
meaningful ...

I'm working with non-uniform cubic splines and I created a simple
polynomial where the input t in the range [t0, t1] is mapped to the
range [0, 1]:

>>> import sympy as sp
>>> t, t0, t1 = sp.symbols('t t:2')
>>> coefficients = sp.Matrix(sp.symbols('a:4')[::-1])
>>> p = sp.Matrix([t**3, t**2, t, 1]).dot(coefficients).subs(t, (t - t0) / (t1 - t0))
>>> p
a0 + a1*(t - t0)/(-t0 + t1) + a2*(t - t0)**2/(-t0 + t1)**2 + a3*(t -
t0)**3/(-t0 + t1)**3

So far so good.
The problem occurs when I'm getting the derivative:

>>> p.diff(t)
a1/(-t0 + t1) + a2*(2*t - 2*t0)/(-t0 + t1)**2 + 3*a3*(t - t0)**2/(-t0 + t1)**3

I'm talking about the numerator of the second term:

a2*(2*t - 2*t0)

I would expect that to be:

2*a2*(t - t0)

... and in fact that's how it is done in the third term!

It gets worse when I substitute t1 for t:

>>> p.diff(t).subs(t, t1)
a1/(-t0 + t1) + a2*(-2*t0 + 2*t1)/(-t0 + t1)**2 + 3*a3/(-t0 + t1)

Now the second term contains some parts that should cancel each other
out. The second term should be:

2*a2*/(-t0 + t1)

Again, the third term already has this form.

Is there a way I can tell SymPy to show the terms as I like it?

BTW, I'm using SymPy version 1.1.1.

cheers,
Matthias

nisha prasad

unread,
Jun 26, 2018, 8:33:35 AM6/26/18
to sy...@googlegroups.com
Can anybody help to do how to implement Finite field in sympy

Nisha T M



--
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+unsubscribe@googlegroups.com.
To post to this group, send email to sy...@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-eTWCiQuWuc11jiuonrny%2BjfNdT2mC0CfGm_2V72KBqDw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages