symmetric function

74 views
Skip to first unread message

danabe

unread,
Nov 14, 2017, 5:35:07 AM11/14/17
to sympy
Hi all,
Is it possible to define a general symmetric function of two variables, let's say F(x,y) such that F(x,y)-F(y,x) would evaluate to zero?
Thanks

Francesco Bonazzi

unread,
Nov 14, 2017, 10:13:36 AM11/14/17
to sympy
Not in the functions, but there is a symmetry canonicalization algorithm in the tensor module:

http://docs.sympy.org/latest/modules/tensor/tensor.html

Unfortunately it's unrelated.

Aaron Meurer

unread,
Nov 14, 2017, 2:55:51 PM11/14/17
to sy...@googlegroups.com
The easiest way is to define a Function subclass that sorts the arguments.

class F(Function):
@classmethod
def eval(cls, x, y):
if default_sort_key(x) > default_sort_key(y):
return cls(y, x)

For more than two variables, I would use the algorithm described by Francesco.

Aaron Meurer
> --
> 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+un...@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/c472fbde-1640-4bc8-a0b6-563d37c2077f%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages