Making orthogonal polynomials more symbolic

33 views
Skip to first unread message

rl

unread,
Jul 13, 2012, 8:25:50 AM7/13/12
to sy...@googlegroups.com
There is an old open PR:

http://github.com/sympy/sympy/pull/1026

which tries to make orthogonal polynomials work
for symbolic order 'n'. An open question is
when to apply "simplifications" like:

    L_n(-x)  --->  (-1)**n * L_n(x)
    L_{-n}(x)  --->  L_{n-1}(x)

Do we want to have this:

a) at construction time
b) only when calling expand_func

Both approaches have their obvious advantages.

Please see the commits:
a) a958cb78c2bfd6d6e94dd05123f43195f2cdbe83
and
b) 659afc3474b146814279d39840c61f4c6589071c
to get an implementation of both approaches.

krastano...@gmail.com

unread,
Jul 13, 2012, 11:20:25 AM7/13/12
to sy...@googlegroups.com
> a) at construction time
> b) only when calling expand_func

Would option b) provide for this:

simplify(Integral(L(n, x)*L(n+1, x), blah blah))

If yes I may vote for b).

rl

unread,
Jul 13, 2012, 2:05:48 PM7/13/12
to sy...@googlegroups.com
No, at the moment both options do not allow to
compute the orthogonality integrals :-/

@asmeurer: I remember we once tried
computing that:

In [2]: n = Symbol("n")
In [3]: m = Symbol("m")
In [4]: x = Symbol("x")

In [5]: dln = diff(legendre(n,x),x)
In [6]: dln
Out[6]: n*(x*legendre(n, x) - legendre(n - 1, x))/(x**2 - 1)

In [7]: dlm = diff(legendre(m,x),x)
In [8]: dlm
Out[8]: m*(x*legendre(m, x) - legendre(m - 1, x))/(x**2 - 1)

In [9]: integrate(dlm*dln, (x, -1,1))

Probably we used one of your integration branches?

Aaron Meurer

unread,
Jul 13, 2012, 5:18:27 PM7/13/12
to sy...@googlegroups.com
I personally would vote for option a as it would be consistent with functions like sin and cos. 

Some things to consider though:

- What if either argument is something like x - y or y - x?  Would those both be canonicalized to the same thing (with either choice)?

- If there ever could be a case where someone would not want it changed, go with option b, because, as with all automatic simplifications, option a makes it impossible to not have it applied. 

- Don't worry too much about algorithms being easier if you choose option a because the form will always be canonical. It's not hard to add a function call at the top to put it into canonical form if you choose b. 

Aaron Meurer
--
You received this message because you are subscribed to the Google Groups "sympy" group.
To view this discussion on the web visit https://groups.google.com/d/msg/sympy/-/eDJFpg7fz5cJ.
To post to this group, send email to sy...@googlegroups.com.
To unsubscribe from this group, send email to sympy+un...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/sympy?hl=en.

rl

unread,
Jul 13, 2012, 5:35:04 PM7/13/12
to sy...@googlegroups.com
> What if either argument is something like x - y or y - x?  Would those both be canonicalized to the same thing (with either choice)?

No.

a) We pull out some factors and get legendre objects of same argument:

In [6]: legendre(n, y-x)
Out[6]: (-1)**n*legendre(n, x - y)

In [7]: legendre(n, x-y)
Out[7]: legendre(n, x - y)

b) Nothing happens beside what sympy does with the "Add"

In [6]: legendre(n, x-y)
Out[6]: legendre(n, x - y)

In [7]: legendre(n, y-x)
Out[7]: legendre(n, -x + y)

- If there ever could be a case where someone would not want it changed, go with option b, because, as with all automatic simplifications, option a makes it impossible to not have it applied. 

At the moment I see no reason to do so.
But this does absolutely not mean that there never will be a reason.

 
> I personally would vote for option a as it would be consistent with functions like sin and cos.

Me too. Most objects do some simpler transformation at this point. Option b) is probably an overkill
in turning off automatic simplification features, compared to the rest of sympy.

Aaron Meurer

unread,
Jul 13, 2012, 5:49:21 PM7/13/12
to sy...@googlegroups.com
On Jul 13, 2012, at 3:35 PM, rl <some...@bluewin.ch> wrote:

> What if either argument is something like x - y or y - x?  Would those both be canonicalized to the same thing (with either choice)?

I meant using expand_func with option b. 

Aaron Meurer


No.

a) We pull out some factors and get legendre objects of same argument:

In [6]: legendre(n, y-x)
Out[6]: (-1)**n*legendre(n, x - y)

In [7]: legendre(n, x-y)
Out[7]: legendre(n, x - y)

b) Nothing happens beside what sympy does with the "Add"

In [6]: legendre(n, x-y)
Out[6]: legendre(n, x - y)

In [7]: legendre(n, y-x)
Out[7]: legendre(n, -x + y)

- If there ever could be a case where someone would not want it changed, go with option b, because, as with all automatic simplifications, option a makes it impossible to not have it applied. 

At the moment I see no reason to do so.
But this does absolutely not mean that there never will be a reason.
 
> I personally would vote for option a as it would be consistent with functions like sin and cos.

Me too. Most objects do some simpler transformation at this point. Option b) is probably an overkill
in turning off automatic simplification features, compared to the rest of sympy.

--
You received this message because you are subscribed to the Google Groups "sympy" group.
To view this discussion on the web visit https://groups.google.com/d/msg/sympy/-/jUEDJo-rQpAJ.

rl

unread,
Jul 13, 2012, 5:57:17 PM7/13/12
to sy...@googlegroups.com
> What if either argument is something like x - y or y - x?  Would those both be canonicalized to the same thing (with either choice)?

I meant using expand_func with option b. 

Of course, my fault.

In [8]: legendre(n, y-x)
Out[8]: legendre(n, -x + y)

In [9]: expand_func(_)
Out[9]: (-1)**n*legendre(n, x - y)

The results is the same, but this is obvious, we use the very same expansion code,
just at different locations in the class.

krastano...@gmail.com

unread,
Jul 13, 2012, 6:10:02 PM7/13/12
to sy...@googlegroups.com
>> I personally would vote for option a as it would be consistent with
>> functions like sin and cos.
>
> Me too. Most objects do some simpler transformation at this point. Option b)
> is probably an overkill
> in turning off automatic simplification features, compared to the rest of
> sympy.

If it matters, I find this particular argument very convincing.
Reply all
Reply to author
Forward
0 new messages