# I just don't see the difference

I checked it by hand and i am sure that the first code does what i want it to do. But i just don't get even by calculating by hand why the 2nd code is wrong. The only difference in the two codes is that once i use j= and the other time j:= . By integrating by hand for me the 1st code is correct. 1)

 g[f_, n_, b_, l_, m_, y_] :=
Assuming[n \[Element] Integers && n > 0, Integrate[2 f, {s, f, y}]]
j[f_, n_, b_, l_, m_] = Integrate[g[f, n, b, l, m, y], {y, f, b}]
k[l_, m_, n_] := l/(2 mn + 2 mn^2)
j[k[l, m, n], n, b, l, m]


2)

  g[f_, n_, b_, l_, m_, y_] :=
Assuming[n \[Element] Integers && n > 0, Integrate[2 f, {s, f, y}]]
j[f_, n_, b_, l_, m_] := Integrate[g[f, n, b, l, m, y], {y, f, b}]
k[l_, m_, n_] := l/(2 mn + 2 mn^2)
j[k[l, m, n], n, b, l, m]


Can you explain why the 2nd code confuses sth.?

• It would help if you formatted your code block to make it visually clear which definitions are separate, and if you pointed out all differences between 1) and 2), since they're so hard to see. E.g. when you use = and when you use :=. – Szabolcs Nov 11 '16 at 11:49
• in (1) your j is define by =, in (2) you use the correct delayed definition := – Mauricio Fernández Nov 11 '16 at 11:49
• I updated my text to make sure that the differences in the code are clear. @MauricioLobos Yeah (2) seems more correct in the mathematica sense, but either i can't integrate by hand or (2) is wrong. Integrating by hand gives me the result from the first code. – Paul Nov 11 '16 at 12:59
• You did not explain, what's wrong with the second code. Does it return any answer at all? Or it returns one, which is different from the right answer? Besides, it would be helpful, if you give the definition of the functions you use, such as f. Last, mn is understood by Mma, as a new variable. For a product you should write n m or n*m . – Alexei Boulbitch Nov 11 '16 at 13:23

I've redefined your two "j" functions to be j1 and j2 so that we can look at both of them at once. I've also added FullSimplify. Now you can see that the two are identical.

g[f_, n_, b_, l_, m_, y_] :=
Assuming[n \[Element] Integers && n > 0, Integrate[2 f, {s, f, y}]]
j1[f_, n_, b_, l_, m_] = Integrate[g[f, n, b, l, m, y], {y, f, b}];
k[l_, m_, n_] := l/(2 mn + 2 mn^2)
j1[k[l, m, n], n, b, l, m] // FullSimplify
j2[f_, n_, b_, l_, m_] := Integrate[g[f, n, b, l, m, y], {y, f, b}];
j2[k[l, m, n], n, b, l, m] // FullSimplify

FullSimplify[j1[k[l, m, n], n, b, l, m]]==FullSimplify[j2[k[l, m, n], n, b, l, m]]

True
`

Since the order of the calculations is different, the answers appear to be different, but when simplified, they are the same.

• Thank you very much. I substracted them from each other and i was just given 0 under special conditions, don#t know what there happened. At least i now know that they are equal. – Paul Nov 11 '16 at 14:01