This question already has an answer here:
- Turn expression into function 4 answers
How can I automatically define a function inside my Mathematica code using a result (expression) that preceded the point of definition.
tt = x + y x + y f[x_, y_] := 2*tt f[1, 1] 2 (x + y)
doesn't give $f$ as 2($x+y$) with $x$ and $y$ being variables here. So, instead of giving
f[1,1]=2(1+1)=4 it gave
2(x+y) not recognizing that $x$ and $y$ are meant to be variables.
How can I define $f$ here so that it picks up its definition from the expression of $tt$ automatically, with $x$ and $y$ as variables?
The reason I need this is that it would save me manually copying and pasting the expression
x+y into the function defintion, and would make my code run automatically even when
tt gives different expressions.