Rules in Pure/Untyped lambda calculus :
[ x → s ] x = s [x\to s]x = s [ x → s ] x = s [ x → s ] y = y if x ≠ y [x\to s ]y = y\ \text{if}\ x \neq y [ x → s ] y = y if x = y [ x → s ] λ y . t = { λ y . [ x → s ] t if y ≠ x ∧ y ∉ F V ( s ) λ y . t if y = x [x\to s]\lambda y.\ t = \begin{cases} \lambda y.\ [x\to s]t & \text{if}\ y \neq x \land y \notin FV(s) \\ \lambda y.\ t & \text{if}\ y = x \end{cases} [ x → s ] λ y . t = { λ y . [ x → s ] t λ y . t if y = x ∧ y ∈ / F V ( s ) if y = x
[ x → s ] ( t 1 t 2 ) = [ x → s ] t 1 [ x → s ] t 2 [x \to s](t_1\ t_2) = [x \to s]t_1\ [x \to s]t_2 [ x → s ] ( t 1 t 2 ) = [ x → s ] t 1 [ x → s ] t 2
Practical foundations for programming languages 's notation
A substitution [ b / x ] [b / x] [ b / x ] is a Partial function on the set of Abstract syntax tree (AST) s A \mathcal{A} A . Given the set of variables X \mathcal{X} X and an AST a ∈ A a \in \mathcal{A} a ∈ A :
If a = x ∈ X a = x \in \mathcal{X} a = x ∈ X then [ b / x ] a = b [b/x]a = b [ b / x ] a = b . If a = y ∈ X a = y \in \mathcal{X} a = y ∈ X and y ≠ x y \neq x y = x then [ b / x ] y = y [b/x]y = y [ b / x ] y = y . [ b / x ] o ( x ⃗ 1 . a 1 ; … ; x ⃗ n . a n ) = o ( x ⃗ 1 . a 1 ′ ; … ; x ⃗ n . a n ′ ) [b/x]o(\vec{x}_1.a_1; \ldots; \vec{x}_n.a_n) = o(\vec{x}_1.a'_1; \ldots; \vec{x}_n.a'_n) [ b / x ] o ( x 1 . a 1 ; … ; x n . a n ) = o ( x 1 . a 1 ′ ; … ; x n . a n ′ ) , where for each 1 ≤ i ≤ n 1 \leq i \leq n 1 ≤ i ≤ n , we require that x ⃗ i ∉ b \vec{x}_i \notin b x i ∈ / b , and we set a i ′ = [ b / x ] a i a'_i = [b/x]a_i a i ′ = [ b / x ] a i if x ∉ x ⃗ i x \notin \vec{x}_i x ∈ / x i , and a i ′ = a i a'_i = a_i a i ′ = a i otherwise.