# Purpose of seemingly repeated definition [duplicate]

This is related to the answer (link) of my previous question. The code works great. I just don't know what is the purpose of the additional part 'psi[n]' and 'psi[n]' in the definition. Thanks in advance!

Clear[psi, phi]
psi[0] = Pi;
phi[0] = 0.1;

psi[n_] :=psi[n] = If[L < Mod[psi[n - 1] + 2*phi[n - 1], 2 Pi] < 2 Pi - L,psi[n - 1] + 2*phi[n - 1],psi2[psi[n - 1], phi[n - 1]]]
phi[n_] :=phi[n] = If[L < Mod[psi[n - 1] + 2*phi[n -1], 2 Pi] < 2 Pi - L,phi[n - 1], phi2[psi[n - 1], phi[n- 1]]]

• It's called "memoization" and basically memorizes already calculated values, essentially using memory instead of computation. – bill s Nov 18 '20 at 1:42
• – Bob Hanlon Nov 18 '20 at 2:32
• Thanks a lot for the explanation and the reference! – Pengfei Nov 18 '20 at 2:48