This question already has an answer here:
I have many delayed-defined functions of many variables, and all the functions share a term containing some of these variables. Thus, I would like to just call the term
x and for each function to immediately read
x as that term. What would be the easiest/best/cleanest way to do this?
As a very simplified example, the code
x = a1 + a2; f[a1_, a2_, a3_] := x + a3 f[b1, b2, b3]
gives the output
a1 + a2 + b3
but the output I want is
b1 + b2 + b3
Given my problem, the following concerns and conditions are understandable.
I want to avoid defining
xexplicitly as a function (i.e.
x[...]) because it depends on many variables, it would be called many times, and
x[...]would end up being almost as large as the term it is supposed to be a shortcut for.
I want to avoid calling
Blockor using replacement rules in each function because I would have to do this for many functions and they are complicated enough as it is. This is why I would like the definition for
xto be global.
It seems like there should be a straightforward way for Mathematica to just immediately read a symbol
x in each delayed-defined function as a term containing some of the functions' arguments.