For example, for a built-in function in Mathematica, f, originally f[1] gives {1,2,3}, but I want to let Mathematica gives only {1,3}. A simple method for rewritting f is desired. I don't want to define a new function or totally rewrite f or just dealing with original f's outputs. I want to rewite f.
Thanks. :)
I prefer a method which is functional and reminds me of decorators in Python. http://wiki.python.org/moin/PythonDecorators
First we create the decorator:
It can then be used as a prefix:
A variation of Searke's method that I prefer is:
This automatically removes results that are not odd, and it is applied to the function itself, which I find more convenient.
Examples:
You can use the Villegas-Gayley trick for this.
For the
Sin
function:Could apply a rule of the form
Daniel Lichtblau