1.3 Higher-Order Calculi ( HOC )
1.3.3 Meta-level & conventions about variable binding
the terminology of sorts by that of syntactic categories (of the meta-level). As in multi-sorted first-order logic, expressions are based on notational constants taking n arguments (n≥0), each being of some syntactic category.
As in multi-sorted first-order logic, the meta-level has no higher-order syntac- tic category; however some first-order notations intend some variable binding:
• to denote a binder of the object level,
• to denote a construction in which some variable name does not matter, as for the (implicit) substitution ©N
x
ª
M that we define in this section. Both kinds of bindings introduce the problem of variable capture and liberation. We might want to write for instance
• a rule like η-reduction in λ-calculus: λx.M x →M, or the propagation of an explicit substitution through an abstraction in the λx-calculus [BR95]: hP/yiλx.M →λx.hP/yiM (all bindings from the object-level)
• the substitution lemma ©P y ª©N x ª M = n{Py}N x o©P y ª M (all bindings from the meta-level)
• the case of the abstraction for the definition of (implicit) substitution:©
P y ª (x.M) = x.©P y ª
M (interaction between object-level binding and meta-level binding)
The side-conditions avoiding variable capture and liberation are x 6∈FV(M) for η-reduction, andx6∈FV(P)and x6=yfor the rule ofλx, the substitution lemma, and the definition of implicit substitution. In all cases we want a safe way to drop these side-conditions, because they can be mechanically recovered just by looking at the above expressions, and this is the main point of this section. But in order to define this mechanical process, information about the intended variable bindings must be available, so we slightly enrich the sorting of multi-sorted first-order logic so that it bears this information.
The grammar for syntactic categories of the meta-level must cover every kind of notation used in this dissertation. First-order notations are standard to deal with, but expressions of the meta-level might intend not only unary bindings (as in the example of the substitution) but also n-ary bindings, i.e. bindings of several variables in one construct. For example in Chapter 5 we use lists. Lists can be used as binders in a notation of λ-calculus like λΠ.M that stands for λx1. . . . .λxn.M if Π is the list x1, . . . , xn. In this case writing
©N x ª (λΠ.M) = λΠ.©N x ª
M should generate the side-conditions Dom(Π) ∩ FV(N) = ∅ and x 6∈ Dom(Π), which are more complex than the side-conditions of the previous examples.
Definition 35 (Syntactic categories of the meta-level)
The meta-level uses the basic syntactic categories of the object-level but new ones can also be used, given in a setSCM. Syntactic categories of the meta-level are given by the following grammar:
where P ranges over thesyntactic categories of super-bound expressions and B ranges over the syntactic categories of binders, given as follows:
P ::= T|B×P
T ::= T ∈ SC |VC×T
B ::= VC |ListsC |MultisetsC |SetsC | . . .
The syntactic categories ranged over byTaresyntactic categories of term-expressions, those expressions denoting terms. Expressions of a syntactic category P, called
super-bound expressions are those involving the complex binders mentioned ear- lier such as lists of variables.
Expressions in B × P will be pairs, with the first component representing some binders of the object-level and the second component representing their scope. We must be able to apply the support extractor Support to expressions representing binders to produce the set of variables that they bind.
Hence, these expressions can be in VC,ListsC,MultisetsC,SetsC, i.e. respec-
tively the syntactic categories of variables, lists of variables, multi-sets and sets of variables of some syntactic category C of the object-level (with variables).
In fact in this dissertation the only categories of binders we use are variables, and lists of variables in Chapter 5. But we could imagine having other categories of binders whose expressions can be the argument of Support, for instance terms themselves if we needed to express pattern matching.
Now we give an encoding†of syntactic category of the object-level as syntactic
categories of term-expressions, ranged over by T. The idea is that a term of a syntactic category C will be represented by an expression of C†:
Definition 36 (Encoding of object-level syntactic categories)
T† := T if T ∈ SC
(C1 ,→ C2)† := VC1 × C2 †
Note that is encoding is bijective: expressions of T will denote a term of some C with C†=T.
Definition 37 (Meta-grammar of HOC) The grammar of the meta-language to describe HOC is given by the following sets, for each syntactic category S:
• a denumerable set of elements called meta-variables such asM, N . . ., and ranged over by M,N. . . As at the object-level, we also write M ... S to indicate the category.
IfM ...T (T category of term-expressions) we say thatMis a meta-variable for terms, and if M ... VC we say it is a meta-variable for variables, but
• a set of elements called constructions, denoted liked, that can takenargu- ments (n ≥ 0). Its signature is a tuple of syntactic categories (S1, . . . ,Sn)
which describes the expected categories of the arguments. We also write c ...S1 *· · ·*Sn *S.
Definition 38 (Expressions of HOC)
• In such an HOC, the expressions, also called meta-terms, of a syntactic category are given by the following five rules:
For each meta-variable M ...S, M ... S
For all construction d ... S1 *· · ·*Sn *S,
(Ei ...Si)1≤i≤n
d(E1, . . . ,En) ... S
For each meta-variable X ...VC1,→···,→Cn,→T (T ∈ SC),
(Ei ...Ci†)1≤i≤n X(E1, . . . ,En) ...T
For each term constructor co C1 ,→ · · ·,→ Cn,→ T (T ∈ SC),
(Ei ... Ci†)1≤i≤n
c(E1, . . . ,En)... T E ... B E0 ... P
E.E0 ... B×P
• As at the object-level, definitions and theorems about the meta-language are sometimes done by induction on expressions, i.e. on their sizes as trees. • This inductive definition provides a notion of sub-expression.
Example 5 (Constructions)
• In the meta-language we often use notions from set theory, for instance we have the constructions FVC ... T * SetsC for each T. We also have
constructions ∅ ... SetsC and ∪,∩ ... SetsC * SetsC * SetsC that we use as
usual as an infix notation, as well as set difference denoted \.
• We have also used Support ... VC * SetsC and Support ... ListsC *SetsC and
the swapping (_ _)_... VC *VC *T*T.
Generalised swapping can apply to expressions of other syntactic categories: we general say that an expressionEcan be subject to the swapping operator
if it makes sense to write (X Y)E.
• Note that the notation _._ can itself be considered a construction of B * T * (B × T) with a particular binding behaviour. On the con- trary, the notation [_]._ for syntactic terms, that has no intrinsic notion of binding, can be seen as a construction of VC * STC0 * STC,→C0 if STC
is the syntactic category in SCM of the expressions representing syntactic terms of C. No side-condition avoiding variable capture and liberation will then be produced, since the represented objects are syntactic terms and not equivalence classes of them.
• For each syntactic categoryC of the object level and each syntactic category
P, we have an construction called substitution in
(VC×P)*C† *P.
The construction of substitution, when applied to two arguments X.E and E0, is denoted ©E0
X ª
E.
• We have mentioned that we sometimes use lists, such as in Π.M, and we sometimes write x1. . . . .xn for Π = (xi)1≤i≤n.
We now describe how we defineHOCinBNF-format, noting that a connection between BNF-definitions and ERShas been studied in [Kha90].
Definition 39 (BNF-definitions) We shall often give the grammar of anHOC
in BNF-format, by giving for each syntactic category T a structure like the fol- lowing one: MT,NT, . . . ::= XT( −−→ X1C1.M1T1, . . . , −−−→ XmCm.MmTm)| . . . | cT( −−→ X0 1C0 1.M 0 1T0 1, . . . , −−→ X0 nC0 n.M 0 nT0 n)| . . . where
• XT(
−−→
X1C1.M1T1, . . . ,
−−−→
XmCm.MmTm)| . . .is a scheme describing the constructs
with the meta-variables XT ... VC00
1,→···,→C00m,→T (with, for all 1 ≤ i ≤ m,
C00
i =Ci,1 ,→ · · ·,→ Ci,pi ,→ Ti, and
−−→
XiCi.representing a series of bindings on
(Xi,j ...VCi,j)1≤j≤pi, and MiTi being a meta-variable of Ti),
• cT( −−→ X0 1C0 1.M 0 1T0 1, . . . , −−→ X0 nC0 n.M 0 nT0
n)| . . . is a scheme describing the constructs
with the term constructors cT o C100 ,→ · · · ,→ Cn00 ,→ T (with, for all
1 ≤ i ≤ n, C00
i = Ci,10 ,→ · · · ,→ Ci,pi0 ,→ Ti0, and
−−→ X0 iC0 i. representing a se- ries of bindings on (X0 i,j ... VC0
i,j)1≤j≤pi, and M 0 iT0
i being a meta-variable of
T0 i).
Either of the last two schemes can be absent when the sets of such variables or term constructors are empty (e.g. variable-free syntactic categories).
All isomorphic notations are acceptable in the definition of HOC, as long as the binders and their scopes are specified. Traditional notations will thus be allowed. For instance we can write a term construct ashN/xiM instead ofexpsub(x.M, N)
for explicit substitutions such as those ofλx[BR95]. More generally, when a term constructor corresponds, in some sense, to a construction, we tend to use angled brackets for the term constructor and braces for the construction (as in the case of explicit and implicit substitutions).
Example 6 (BNF-definition of λ-calculus) We re-express inBNF-format the definition of the syntax ofλ-calculus from Example 3:
M, N ::=x|λx.M |M N
But we can also define the notation λΠ.M if Π is a list of variables, where λx1, . . . , xn.M abbreviates λx1. . . . .λxn.M.
Note that for a variable category T of order 0, the meta-variables for terms inT are abusively taken to be the same as meta-variables for variables inVT. In
BNF-definitions we thus often omit lines such as M::=X
and we useXeverywhere instead ofM, as we illustrate with the following example.
Example 7 (BNF-definition of λx) We can express in BNF-format the defi- nition of the syntax of the calculus with explicit substitutions λx by [BR95].16 Instead of
U, V ::=x
M, N ::=var(U)|λx.M |M N | hN/xiM 16As discussed in Chapter 4, this presentation ofλxis one among others.
we can more simply write
M, N ::=var(x)|λx.M |M N | hN/xiM
We also abusively write
M, N ::=x|λx.M |M N | hN/xiM
if it is clear from context that variables form a syntactic category of their own.
As mentioned in the introduction of this chapter, we now develop the ideas of Barendregt’s convention by giving a mechanical way to recover, just from the expressions we write to denote terms, the side-conditions that are needed to avoid variable capture and liberation. We shall then be able to safely drop those side-conditions throughout the rest of this dissertation.
Nominal logic [Pit03] might be a way of implementing the reasonings that use such conventions in first-order logic.
The idea is very close to the notion of parameter path of SERS [BKR00] (a particular notion of ERS): given a finite set of expressions (Ei)1≤i≤n with
occurrences of a particular meta-variable for terms M, [BKR00] forbids M to be instantiated with a term that contains a variable that is bound by the parameter path of one occurrence and not by that of another occurrence.
Here we bypass the notion of instance but instead produce the side-conditions, directly expressed in the meta-language, that avoid variable capture and liber- ation. For this we define a set-theoretic expression of the meta-language that represents the set of variables that are allowed to occur freely in the term rep- resented by M but that are bound outside by abstractions having M in their scopes.
We first need to define what the meta-variables of an expression are. For that we use set theoretic notions (at the meta-meta-level), which we need to distinguish from the set-theoretic constructions of the meta-level. Hence we write 6[],t,u,E,[. . .] for the former and ∅,∪,∩,∈,{. . .} for the latter. For instance, if F is the set [E1, . . . ,En] of expressions denoting sets, then
S
F stands for the expressionE1∪. . .∪En(for any particular order) while
F
F does not make sense (the (Ei)1≤i≤n are not sets but expressions).
Definition 40 (Meta-variables of an expression) We define the meta- variables for terms & variables MV(E)of an expression E by induction on E:
MV(M) := [M] if M ...T MV(M) := 6[] if not MV(E0.E) := MV(E) MV(X(E1, . . . ,En)) := [X]t F 1≤i≤nMV(Ei) MV(c(E1, . . . ,En)) := F 1≤i≤nMV(Ei) MV(d(E1, . . . ,En)) := F 1≤i≤nMV(Ei)
where X, cand d are respectively a meta-variable of some VC, a term constructor and a construction
Definition 41 (Allowed variables)
• Theexpression of allowed variables in a meta-variable MEMV(E), denoted
AVeM(E), is an expression defined by induction onE:
AVeM(M) := ∅
AVeM(E0.E) := AVeM(E)∪Support(E0) AVeM(M(E1, . . . ,En)) := ∅ AVeM(X(E1, . . . ,En)) := T [AVeM(Ei)|M∈MV(Ei)] if X6=M AVeM(c(E1, . . . ,En)) := T [AVeM(Ei)|M∈MV(Ei)] AVeM(d(E1, . . . ,En)) := T [AVeM(Ei)|M∈MV(Ei)]
whereX, c and d respectively stand for a meta-variable of some VC, a term constructor and a construction
• Suppose every constructE1.E2in an expressionEare such thatE1 =X...VC.
The set of allowed meta-variables in a meta-variable ME MV(E), denoted
AVsM(E), is the set of meta-variables defined by induction on Eas follows:
AVsM(M) :=6[]
AVsM(X.E) := AVsM(E)t[X] AVsM(M(E1, . . . ,En)) := 6[] AVsM(X(E1, . . . ,En)) := d [AVsM(Ei)|M∈MV(Ei)] if X6=M AVsM(c(E1, . . . ,En)) := d [AVsM(Ei)|M∈MV(Ei)] AVsM(d(E1, . . . ,En)) := d [AVsM(Ei)|M∈MV(Ei)]
whereX, c and d respectively stand for a meta-variable of some VC, a term constructor and a construction
Definition 42 (Generation of side-conditions) We define the side- conditions against capture and liberation of a finite set of expressions[E1, . . . ,En].
These are expressed directly in the meta-language and defined by use of a similar notion for a single expressionE:
• For E=M, there is no side-condition.
• For E=E00.E0, the side-conditions are those of E0 and those of E00, plus
Support(E00)∩AVe
M(E0) =∅
for each meta-variable M∈MV(E0).
• For E = c(E1, . . . ,En) or E = d(E1, . . . ,En) (where c and d respectively
stand for a term constructor and an construction), the side-conditions are those of {E1, . . . ,En}.
• For E = X(E1, . . . ,En) (where X ... VC for some C), the side-conditions are
those of [E1, . . . ,En], plus
[
[AVeX(Ei)|X∈MV(Ei)] =∅
• The side-conditions of [E1, . . . ,En] are:
for each meta-variable M∈F1≤i≤nMV(Ei),
³³[
F´\³\F´´∩FV(M) = ∅
writing F for the set of expressions [AVeM(Ei)|M∈MV(Ei)],
as well as the side-conditions produced by each Ei.
Remark 39 Note that the meta-variables that appear in the side-conditions produced by the process above can all be subject to the swapping operator.
Example 8 (Side-conditions against variable capture and liberation)
• AVeM(c(x.y.M,Π.M))is the expression
(((∅ ∪Support(y))∪Support(x))∩Support(Π))
and because the meta-level uses first-order logic with set theory, this is therein equal to {x, y} ∩Support(Π).
The side-conditions are equal, after a similar set-theoretic simplification at the meta-level, to(({y, x}∪Support(Π))\({y, x}∩Support(Π)))∩FV(M) = ∅ and x6=y.
IfSupport(Π) ={y, z}thenAVeM(c(x.y.M,Π.M)) ={y}and the first side-
condition becomes {x, z} ∩FV(M) =∅, i.e. x6∈FV(M) and z 6∈FV(M). • Note that the expression λx.λx.M of λ-calculus, although we are allowed
to write it, produces the unsatisfiable side-condition x 6= x. To denote the α-equivalence class of λ[x].λ[x].M, we can use λy.λx.M with the side- condition y6∈FV(M).
We shall use the above automated generation of the side-conditions whenever we write a term and when we write several terms at the same level, e.g. on the left-hand side and right-hand side of an equation, of a reduction relation,etc. For instance, we show how this process of producing side-conditions applies by giving the definition of substitution, directly at the meta-level:
Definition 43 (Substitution) For each syntactic categoryC1 ,→ C2we define a
construction calledsubstitution, a.k.a. implicit substitution ormeta-substitution, taking two terms x.M o C1 ,→ C2 and N o C1 and constructing a term
©N
x
ª
M o C2.
For that we define, for each tuple of syntactic categories(Ci)1≤i≤nand each ba-
sic syntactic category T, an auxiliary construction that takes a term M o C1 ,→ · · ·,→ Cn,→ T and n terms (Ni o Ci)1≤i≤n and constructs a term
app(M, N1, . . . , Nn)o T.
The definition is by mutual induction on C1 ,→ · · · ,→ Cn ,→ T for the
auxiliary construct and onC1 for the substitution. Then for eachC1 the definition
of ©N x
ª
M is by induction on the size of M.17
©N x ª x(M1, . . . , Mn) := app(N, ©N x ª M1, . . . , ©N x ª Mn) ©N x ª y(M1, . . . , Mn) := y( ©N x ª M1, . . . , ©N x ª Mn) ©N x ª c(M1, . . . , Mn) := c( ©N x ª M1, . . . , ©N x ª Mn) ©N x ª (y.M) := y.©N x ª M app(M) := M app(x.M, M1, . . . , Mn) := app( ©M 1 x ª M, M2, . . . , Mn) if n ≥1
The process described in Definition 42 directly gives the conditions: • x6=y in the second line,
• x6=y and y6∈FV(N) in the last one.
Note that the auxiliary construct is only useful when there are higher-order variables. It also allows the abbreviation of app(x1. . . . .xn.M, N1, . . . , Nn) as
©N
1,...,Nn x1,...,xn
ª
M, whenx1, . . . , xnis a list of variables of someC andN1, . . . , Nn
is a list of terms ofC.
Lemma 40 (Substitution lemma) ©P y ª©N x ª M = n {P y}N x o©P y ª M
(Note that we implicitly have the side-conditions x6=y and x6∈FV(P).)
Proof: Straightforward induction following that of Definition 43, together with the statement ©N x ª app(M, M1, . . . , Mn) = app( ©N x ª M,©N x ª M1, . . . , ©N x ª Mn) 2
Remark 41 We have{y
x}M = (x y)M if y6∈FV(M).
Hence, λx.M =λy.{y