Ask Your Question
3

Defining a symmetric function

asked 2016-09-18 13:38:17 -0500

Mafra gravatar image

updated 2016-11-01 15:44:14 -0500

I am new to Sage (about a week) and I would like to define a symbolic function called s that doesn't evaluate to anything, but it has to be symmetric.

So if I type s(3,2) the output must be s(2,3), or typing s(1,4,3,2) the output must be s(1,2,3,4) etc.

Is it possible to have such a definition? I am searching the documentation to try to implement this, but so far no luck.

I tried using the function sort_subscript()* that I found in the tensor.pdf documentation, but the attempt below obviously fails in an infinite loop:

def s(*m):
    a=sort_subscript(m);
    return s(a[1]);

How can I implement this? My motivation is that s(i,j) are the symmetric Mandelstam invariants in a scattering amplitude context.

Edit:

Today I tried this:

class s(BuiltinFunction):
    def __init__(self, x1, x2):
        if x2 >= x1:
            self.x = x1
            self.y = x2
            BuiltinFunction.__init__(self,'s(%s,%s)' % (x1,x2))
         else:
             self.x = x2
             self.y = x1
             BuiltinFunction.__init__(self,'s(%s,%s)' % (x2,x1))

And it works in the sense that

   sage: s(4,2) 
   s(2,4)

However, this is not complete since

sage: 2*s(4,2)
...
TypeError: unsupported operand parent(s) for '*': 'Integer Ring' and '<class '__main__.s'>'

where I would expect the answer 2*s(2,4). So it is not so simple and I couldn't get a working definition for the __mul__ method and it just looked like the wrong approach anyway.

So is it possible to define a symmetric function that behaves like this inside the user interface?

Alternatively, it would be nice if there was an argument to the built-in function() to specify the symmetry,

s = function('s', nargs=2, sym='symmetric')
edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
4

answered 2016-10-31 21:15:08 -0500

MikeZabrocki gravatar image

updated 2016-11-02 20:54:13 -0500

Ok, it sounds like you want to work in the ring of symmetric functions (however you didn't mention that there might be a + or * or take linear combinations, but these features don't seem to interfere with what you are asking for). Are you allowed repeated entries?

If I am not mistaken, even if this is not precisely what you are looking for, it seems like this algebra should be your model.

You seem to be asking for a vector space whose coefficients are integers and whose index set is a sorted list of non-negative integers (I'm adding the non-negative integer condition for convenience). If this is the case, then lets call them 'partitions.' I hope you don't mind that they will display in weakly decreasing order rather than increasing order, but I don't see that option built in so it will take slightly more than a couple of lines of programming.

sage: Sym = SymmetricFunctions(ZZ)
sage: h = Sym.complete()
sage: h._prefix='s'
sage: def s(lst):
....:     return h.mul(h([a]) for a in lst)
....: 
sage: s([2,1,2,3])
s[3, 2, 2, 1]
sage: 2*s([2,4])+s([1,2,3])
s[3, 2, 1] + 2*s[4, 2]

Is this what you were looking for or am I mis-interpreting what you were asking?

P.S. calling the complete basis 's' kind of goes against my nature, because we use that for Schur functions normally. But the line "s._prefix='s'" makes sure that the result is displayed with an 's' instead of the default 'h' just to follow closely the notation you were looking for.

edit flag offensive delete link more

Comments

Thank you for your answer, but this is not really what I am looking for. The name of the function in the input must be the same as the output; ie I want to type A = s(3,2)*s(1,2) + 2*s(4,2)*s(1,3) and obtain A = s(2,3)*s(1,2) + 2*s(2,4)*s(1,3). If I am allowed to use a different name in the input I already know a solution (just replace def s(*m) by def ss(*m) in my original question and type A = ss(3,2)*ss(1,2) + ... instead).

Mafra gravatar imageMafra ( 2016-11-01 13:00:30 -0500 )edit

So ideally one would have the choice of defining a symmetric function via an argument to the function() method, for example function('f', nargs=2, sym=symmetric) would define a function 'f' that takes two arguments and is symmetric in the sense that f(3,1) = f(1,3)

Mafra gravatar imageMafra ( 2016-11-01 13:03:39 -0500 )edit
2

It is possible to muck with the names so that the name in the input and output are the same, so that is not the real problem with this algebra (I will edit the answer so that it reflects this). I don't think that you've stated all the rules that your algebra satisfies. You didn't mention if you are allowed repeated parts entries or not. That is, does s(1,1) make sense? Now you are mentioning that there is a product on this algebra. Is the algebra commutative? Are there other relations? Does s(2,3)s(1,2) = s(1,2)s(2,3) or not?

MikeZabrocki gravatar imageMikeZabrocki ( 2016-11-02 20:52:39 -0500 )edit

Right, s(1,1) makes sense but it is zero. So in general one can restrict the labels to be distinct. Furthermore, s(i,j) is commutative. In Mathematica terms I am looking for the equivalent of using something like SetAttributes[s, Orderless] and nothing more.

Mafra gravatar imageMafra ( 2016-11-03 15:20:46 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2016-09-18 13:38:17 -0500

Seen: 147 times

Last updated: Nov 02 '16