TITLE: Problem with a basic lemma in Lambda Calculus
QUESTION [6 upvotes]: I have some serious problems with Lambda Calculus. In an introduction by Barendregt and Barendsen at page 11 there is the following lemma, whose proof I do not completely get.

$\mathbf{\lambda} \vdash ( \lambda x_1 \dots x_n . M) X_1\dots X_n = M [ x_1 := X_1] \dots [x_n := X_n]$.

Even if I find the result intuitive, the proof, which should be obvious by induction and $\beta$-reduction, is not clear. In particular, I really don't get why the order is preserved in the manipulation, that is, from LHS we get on the RHS that  $x_1 := X_1$,
$x_2 := X_2$, etc (and I think here the order has to be important). I have the feeling that this is the symptom of a deep misunderstanding of how lambda calculus works in general.
Any feedback is greatly appreciated.

REPLY [4 votes]: There is an implicit but fundamental hypothesis in the lemma you cited: the variables $x_1, \dots, x_n$ are not free in $X_1, \dots, X_n$. This is the reason why the order of the substitutions in $M[x_1:=X_1]\dots[x_n :=X_n]$ actually does not matter.
This hypothesis is implicit in the definition of $\beta$-conversion, because you always assume the variable convention 2.6 (p. 10):

If $M_1, \dots, M_n$ occur in a certain mathematical context (e.g.
  definition, proof), then in these terms all bound variables
  are chosen to be different from the free  variables. 

Note that this variable convention is also crucial in the definition of substitution for abstractions (p. 10). Indeed, setting
$$(\lambda y.M)[x := N] \equiv \lambda y. M[x := N]$$
is correct only in the case $y$ is not a free variable in $N$; this condition can always be fulfilled by renaming bound variables ($\lambda$-terms are considered up to $\alpha$-conversion, i.e. up to renaming of bound variables).
If the variable convention were not fulfilled you would have for instance 
$$(\lambda y. x)[x := y] \equiv \lambda y.y\,,$$
which is clearly wrong, instead of the correct
$$(\lambda y. x)[x := y] \equiv \lambda z.y\,.$$