# Function input syntax [closed]

My functions are

W[L_, r_] := 1 + 3 L + 2 L^2 - 6 r*L - 6 L (r*L) + 6 (r*L)^2;
T[L_, r_, d_, koff_, u_, W_] := ((u/d^2)* W[L, r]+6 u (L - 1)) + koff (u/d^2) W[L, r]


How to write correctly T function: is W an input or not? What is the difference between T[L_, r_, d_, koff_, u_, W_] and T[L_, r_, d_, koff_, u_]?

How doest Mathematica understand W and T in both cases?

It seems that sometimes there is no difference but if I create the third function K=f(T,W) it will affect. And Mathematica gives different colors of W[L,r] in different cases.

• Have you already worked your way through the following tutorials? Defining functions; Functions and Programs; How To - Work with Variables and Functions – MarcoB Nov 10 '15 at 16:22
• You don't need the W in the definition of T. Just write T[L_, r_, d_, koff_, u_] := ... – eldo Nov 10 '15 at 16:28
• @eldo I understood that, I am just wondering why and how Mathematica interpret if I include W in the definition of T. – Maria Nov 10 '15 at 16:41
• @MarcoB didn't find the answer in these tutorials. – Maria Nov 10 '15 at 16:42
• @MarcoB Why the question has been put on hold? It does not arise from syntax mistake, it's not possible find in documentation.I was trying to understand how Mathematica works and why it interprets my syntax incorrectly. (I understand rules but I didn't understand what happens internally in it when I didn't follow the rule) Sorry, if my question is confusing. – Maria Nov 12 '15 at 23:17

I think you are getting confused due to the naming convention you are using. For T you can use any symbol to represent the function W in T. It is perhaps best not to use the symbol W in T's definition because it is confusing you. Try using f instead.

ClearAll[T, W];
W[L_, r_] := 1 + 3 L + 2 L^2 - 6 r*L - 6 L (r*L) + 6 (r*L)^2
T[L_, r_, d_, koff_, u_, f_] := ((u/d^2)*f[L, r] + 6 u (L - 1)) + koff (u/d^2) f[L, r]


There I have used f the symbol that takes the function. Now, when I call the function with W all works as expected and it is clear what W is and what f is.

T[L, r, d, koff, u, W]
(* 6*(-1 + L)*u + ((1 + 3*L + 2*L^2 - 6*L*r - 6*L^2*r + 6*L^2*r^2)*u)/d^2 +
(koff*(1 + 3*L + 2*L^2 - 6*L*r - 6*L^2*r + 6*L^2*r^2)*u)/d^2 *)


$$\frac{\text{koff} u \left(6 L^2 r^2-6 L^2 r+2 L^2-6 L r+3 L+1\right)}{d^2}+\frac{u \left(6 L^2 r^2-6 L^2 r+2 L^2-6 L r+3 L+1\right)}{d^2}+6 (L-1) u$$

Also, a point to note is that you should not create symbols that start with capital letters in your notebooks. These may clash with current or future symbols that Wolfram adds to the language. For example, consider N or E.

Hope this helps.

Consider this simple case.

w[x_, y_] := 1 + x y
t[x_, y_, z_] := w[x, y]/z


Then

t[2, 3, 5]


gives

7/5

which shows Mathematica recognized and evaluated the reference to w[x, y] in the definition of t, substituted the correct values of x and y, and got the correct result for t[2, 3, 5]. It will do the same for your definitions.

• I do understand that it works.My question is not about that. How does Mathematica recognize W? For me it was interesting,because I did obtain correct results with W-input, and only once occasionally got list of lists as a result of T-output. I am interested why? – Maria Nov 10 '15 at 21:37
• @Maria. Sorry that I misunderstood your question. Not sure I understand the question in your comment either. However, if you are seeking to learn how Mathematica evaluates a general expression, I recommend reading Chapter 7 of David Wagner's classic book. You can download a free copy by going to this question. Wagner's discussion of how Mathematica works internally is the best I know. – m_goldberg Nov 11 '15 at 13:41
• Why then a question has been put on hold? It does not arise from syntax mistake, it's not possible find in documentation.I was trying to understand how Mathematica works and why it interprets my syntax incorrectly. (I understand rules but I didn't understand what happens internally in it when I didn't follow the rule) Sorry, if my question is confusing and thanks for the book. – Maria Nov 12 '15 at 23:14
• @Maria. I voted to close because I misunderstood what you were asking until you clarified your intent in a comment. Others might have done the same. I will not vote to reopen it as it stands because it still reads as a simple misunderstanding of function evaluation as covered in the documentation. Should you edit it, it will automatically come up for reopen consideration, but unless you clarify it so reads as a non-trivial question about evaluation, it is not likely to get enough votes to be reopened. – m_goldberg Nov 13 '15 at 2:28