Question: [This question](https://mathematica.stackexchange.com/questions/2440/effective-matrix-power-like-algorithm) mentions "`x := x =` trickery".

What does defining a function as `f[x_] := f[x] = ...` do and what is it good for?

Answer: 
It is a simple way to implement [Memoization](https://en.wikipedia.org/wiki/Memoization). The trick is that if you define a function as

```
f[x_]:=f[x]=ExpensiveFunctionOf[x]

```

then when you for the first time call e.g. `f[3]`, it will evaluate as

```
f[3]=ExpensiveFunctionOf[3]

```

which will evalulate the expensive function, and *assign the result to `f[3]`* (in addition to giving it back, of course). So if e.g. `ExpensiveFunctionOf[3]` evaluates to 7, it will assign `f[3]=7`.

The next time you call `f[3]`, it will find that newly created definition of `f[3]` and use that in preference to the general rule. This means it will return the value 7 *without* calculating `ExpensiveFunctionOf[3]` a second time.
It also has another practical side. If you have a **random** function, which

* you only want to evaluate once, **but**
* you don't know *where* exactly it will be evaluated **or**
* you want to declare it *before* the parameters it depends on are defined, **and**
* you want it to be the same after the first evaluation, for any subsequent call,

you can use the memoization trick:

```
initPopulation := initPopulation = InitializeRandomPopulation[args..];

(* lots of computation *)
(* the above *args* (on which the function depends!) are defined only now *)
(* and finally we got to the part where we compute the initial population *)

pop1 = initPopulation

(* use the very same initial population again and again... *)

pop2 = initPopulation 

...

```