I am looking for an alternative to f
@Sander's example is very clear. This type of definition returns an up value of the symbol Plus.
Hi Robert, you can make it work; but not for all input:
So it would work for a+1 (where a is a symbol). If a is a number, then it will first compute the sum, and then call the function; the function does not match the pattern then.
What's wrong with f[n_]:=(n-1)^2?
f[n_ + 1] := n^2 is a valid definition but doesn't mean what you expect here. To understand why, you can read an introduction to pattern matching here.
f[n_ + 1] := n^2