I am using the following two lines of code relatively frequently
f/:Plus[f[x_], f[y_], z___]:=f[x+y]+z
f/:Times[c_, f[x_]]:=f[c x]
and I was wondering if it is possible to automate the process.
What I have in mind, is to supply a list of heads to a function and the function will make definitions similar to those presented above, for every head in the list.
The idea is to have a package that defines a bunch of heads that behave like f
above and exports them to the user without having to show the user how the behavior is implemented.
I'm interested in avoiding possible side-effects from the automation process, if there are any.
So, to sum up, is it possible to automate the two TagSetDelayed
definitions presented above, in a package that safely exports the heads exhibiting the same behaviour as f
, without major side-effects?