# Defining a symmetric function

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')
```