I have an expression that I want to use in a function definition. For concreteness let's take
Gamma[k + 4]/k!. I know this can be simplified to
(1 + k) (2 + k) (3 + k), but I don't want to have to copy-paste the simplified expression into my function definion like this
copypaste[k_] := (1 + k) (2 + k) (3 + k)
so instead I write
slow[k_] := FullSimplify[Gamma[k + 4]/k!]
This second function is not only slow, but Mathematica will redo the simplification each time I want to evaluate this function.
Solution so far
A way to solve this is to use
evaluated[k_] = FullSimplify[Gamma[k + 4]/k!] simplerandfaster[k_] := evaluated[k]
This works, but it feels like a not-so-neat workaround to me. If I have to do this trick several times for different functions in one notebook I'll have a bunch of function names like
evaluated which I will only ever use once. Is there a better way? I guess I could add
ClearAll@evaluated at the end or put everything inside a
Module block, but I'm hoping there's a better way.