1 | initial version |

Here is how you can define an additive function:

```
sage: import operator
sage: def f_eval(self, arg):
....: try:
....: op = arg.operator()
....: except AttributeError:
....: return None
....: if op is operator.add:
....: return sum(map(self,arg.operands()))
....:
sage: f = function('f',eval_func=f_eval)
sage: var('x,y')
(x, y)
sage: f(x+y)
f(x) + f(y)
sage: f(x*y)
f(x*y)
```

The documentation you get from

```
sage: function?
```

doesn't isn't very helpful, but this has some examples:

```
sage: sage.symbolic.function_factory.function?
```

2 | No.2 Revision |

Here is how you can define an additive function:

```
sage: import operator
sage: def f_eval(self, arg):
....: try:
....: op = arg.operator()
....: except AttributeError:
....: return None
....: if op is operator.add:
....: return
```~~sum(map(self,arg.operands()))
~~sum(map(self, arg.operands()))
....:
sage: f = function('f',eval_func=f_eval)
sage: var('x,y')
(x, y)
sage: f(x+y)
f(x) + f(y)
sage: f(x*y)
f(x*y)

The documentation you get from

```
sage: function?
```

~~doesn't ~~isn't very helpful, but this has some examples:

```
sage: sage.symbolic.function_factory.function?
```

Copyright Sage, 2010. Some rights reserved under creative commons license. Content on this site is licensed under a Creative Commons Attribution Share Alike 3.0 license.