This web page discusses syntactical aspects of substitution in first-order logic. In particular, the tricky definition of substitution itself is given and we will see when that substitution is valid. All these details are technical. They behave exactly as one would naïvely hope (though the details are more awkward to write down than one might expect), and in particular all these notions are computable, i.e. computable on a computer, or representable in a formal system like a Post system. Readers who can take such details on trust need not read further. Only those who want to see the gory details need read on.
We want to define and investigate the effect of substituting terms ${t}_{1},\dots ,{t}_{k}$ for variables ${v}_{1},\dots ,{v}_{k}$ in a term or formula. The work here will be entirely syntactical (i.e. manipulations of strings of symbols without meaning attached) but looking ahead to further work we will take care to ensure that our substitutions are potentially meaningful (i.e. can at a later stage be given meaning).
We fix a first order language $L$ with variables from ${\mathrm{VAR}}_{L}=\left\{u\right\},v,w,\dots $ and terms ${\mathrm{TERM}}_{L}$.
In its simplest form a substitution is a function $s:V\to {\mathrm{TERM}}_{L}$ where $V=dom\left(s\right)$ is a finite set of variables. The idea is that we should substitute each $v\in V$ with the term $s\left(v\right)$. This is turn gives more complex substitition functions $s\left(t\right)$ and $s\left(\varphi \right)$ where $t$ is a term and $\varphi $ is a formula of $L$. Most of the inductive definition of this extension to terms and formulas is given recursively by the following.
This is an inductive definition on terms and formulas, and as such relies on the Unique Readability Theorem for terms and formulas.
The only clauses missing from the above are those for $s\left(v\right)=v$ if $v\in dom\left(s\right)$ and for the quantifiers $\forall $ and $$. But these cause difficulties: some substitutions are invalid i.e. they result in unacceptable introduction of new variables in the scope of an existing quantifier. To resolve this problem we must specify when substitutions are valid, and this involves a slightly more sophisticated idea of substitution.
From now on, we say that a substitution $s$ is a function $s:V\to {\mathrm{TERM}}_{L}$ with domain $V=dom\left(s\right)$ and a finite set of forbidden variables, $\left(s\right)$. Variables in $\left(s\right)$ are not allowed in the substituted output, though they can be present in unsubstituted output.
The remaining clauses of the definition of substitution will now be given, starting with the substitution of a variable for a term.
Finally, we can give the rules for substitution of formulas involving quantifiers. There are two cases. In the following, $Q$ is either $\forall $ or $$.
The point is here that a quantified variable must never be substituted, since it already has an intended meaning (ranging over all or some elements of a $L$-structure). That is why in the first case the domain of the substitution is altered to remove the variable $v$. Furthermore, in the scope of the quantifier terms should not be introduced by substitution if they involve the variable being quantified over. That is why the forbidden variable set is made bigger.
In the sequel, when defining a substitution $s$ we shall normally just give the domain of $s$ and the value $s\left(v\right)$ for each variable $v\in dom\left(s\right)$. If $\left(s\right)$ is not specified it will be assumed to be empty.