1.3 Second Order Logic AF2
1.3.1 Definition of the System
Formulas are generated as follows:
A, B, C::=X~t|A→B| ∀xA| ∀XA
where x(X) is first-order (second-order) variable and inX~t, the arity ofX
is equal to the length of~t. The term system is a static one generated by
r, s, t::=x|f~t
wheref belongs to a given set of function symbols.
The setsF V(t) andF V(A) of free variables oftandAare defined as usual. Observe that in this caseF V(t) consists of all variables occurring int.
On Substitution
Definition 1.23 Given a termt, variables~x and terms~swe define the simul- taneous substitution of~xwith~sint denotedt[~x:=~s] as follows:
x[~x:=~s] = si If x≡xi x If x /∈~x (f~t)[~x:=~s] =f(~t[~x:=~s])
Definition 1.24 Given a formula A, variables ~x and terms ~s we define the substitution of~xwith~sinA, denoted A[~x:=~s] as follows:
1.3. SECOND ORDER LOGICAF2 25
(A→B)[~x:=~s] =A[~x:=~s]→B[~x:=~s]
(∀xA)[~x:=~s] =∀x.A[~x:=~s], always assumingx /∈~x∪F V(~s).
(∀XA)[~x:=~s] =∀X.A[~x:=~s]
The following concept provides an important tool to define sets in second- order logic.
Definition 1.25 A comprehension predicate is an expression of the form λ~yF
where ~y are first-order variables and F is a formula. With calligraphic letters
F,G,H, . . . ,we denote the comprehension predicates generated by the formulas F, G, H, . . . , respectively. The arity ofλ~yF is the length of~y.
Intuitively λ~yF represents the set {~t | F[~y := ~t ]}, therefore (λ~y.F)~tshould be understood as F[~y := ~t]. The set of free variables of λ~yF is defined as F V(λ~yF) :=F V(F)\ {~y}.
A predicate is either a second-order variable or a comprehension predicate.
Definition 1.26 Given a formula A, variables X~ and predicates F~ we define the substitution of X~ with F~ in A, denotedA[X~ :=F~]as follows:
(X~t)[X~ :=F~] = Fi~t IfX ≡Xi X~t IfX /∈X~ (A→B)[X~ :=F~] =A[X~ :=F~]→B[X~ :=F~]
(∀xA)[X~ :=F~] =∀x.A[X~ :=F~], always assuming x /∈F V(F~).
(∀XA)[X~ :=F~] =∀X.A[X~ :=F~], always assuming X /∈X~ ∪F V(F~).
Lemma 1.22 (Substitution Properties) The following properties hold:
◦ If~x /∈~y∪F V(~s)then
t[~x:=~r][~y:=~s] =t[~y:=~s][~x:=~r[~y:=~s]] (SwP1) ◦ Ifβ /~∈~γ∪F V(~ζ)then
A[β~:=~χ][~γ :=~ζ] ≡ A[~γ:=~ζ][~β:=χ~[~γ :=~ζ]] (SwP2)
where ~β, ~γ can be first or second order variables and χ, ~~ ζ are terms or comprehension predicates respectively, so that every substitution makes sense.
Proof. Induction on tandArespectively. a The particular feature of AF2is the use of equations between terms s =t
defined in the next section. The judgments of the logic are of the form Γ` t:A
where
◦ Ais a formula.
◦ Γ is a given context of formulas of the form{x1:A1, . . . , xn:An}. ◦
is a given context of equations of the form {s1=t1, . . . , sk=tk}. ◦ t is a lambda-term encoding the derivation ofA. Such terms are called
proof-terms.
The relation Γ` t:A, read as “the formulaAis derivable from the assumptions Γ,
and the termtis a code for such derivation”, is inductively defined from Γ, x:A` x:A (V ar) s=t∈ Γ` s=t (start) as follows: Γ, x:A` r:B Γ` λxr:A→B (→I) Γ` r:A→B Γ` s:A Γ` rs:B (→E) Γ` t:A Γ` t:∀xA(∀I) Γ` t:∀xA Γ` t:A[x:=s] (∀E) Γ` t:A Γ` t:∀XA (∀ 2I) Γ` t:∀XA Γ` t:A[X :=F] (∀ 2E) Γ` r:A[x:=s] Γ` s=t Γ` r:A[x:=t] (Eq) Important remarks are:
◦ In the rule (∀I),x /∈F V(Γ,
).
◦ In the rule (∀2I),X /∈F V(Γ) (Observe thatX /∈F V(
) always holds). ◦ In the rule (Eq), Γ` s=tmeans nothing but a derivation with the rules
being defined with the difference that we get rid of the proof-terms. Indeed we could isolate the context of equalities and perform only derivations of the form
`s=tbut in extensions of the system needed later this is not possible anymore, therefore we prefer this general formulation.
1.3. SECOND ORDER LOGICAF2 27
◦ Although we make no syntactic distinction between object and proof-term variables we consider both sets as disjunct.
◦ From now on we will make explicit the context
only if neccesary, but usually we will only write`instead of` .
◦ Rules like (Eq) and the four rules for ∀,∀2 whose application is not re- flected in the proof-term system are callednon-traceable., in other case a rule is calledtraceable.
The proof reduction is given by the followingβ-reduction rule between proof- terms:
(λxr)s 7→β r[x:=s]
To see the expressive power ofAF2we define natural numbers and streams. Natural Numbers inAF2
Given a constant symbol 0 and a unary function symbols, we define the unary predicate of natural numbers as:
:=λz.∀X.X0→(∀x.Xx→Xsx)→Xz
It is easy to see that`e0 :
0 and`se: ∀x.
x →
sx. wheree0 :=λxλf.x
andse:λnλxλf.f(nxf). Streams in AF2
Given unary function symbolshead,tail, we define the unary predicate of streams of elements of the predicateAas:
SA:= λu.∀Z.
∀X.(∀x.Xx→ Aheadx)→(∀x.Xx→Xtailx)→ ∀x.Xx→Zx→Zu
We can see that`headg :∀x.SAx→ Aheadxand`tailf :∀x.SAx→ SAtailx,
where headg :=λs.s(λhλtλx.hx) andtailf :=λs.s(λhλtλxλf.f ht(tx)). On Leibniz’ Equality
The particular feature of AF2 is the use of Leibniz’ equality, which is defined for given terms s, tas:
s=t:=∀X.Xs→Xt
A formula of the forms=twill be called equation.
Γ` t=t (ref l) Γ` s=t Γ` t=s (symm) Γ` r=s Γ` s=t Γ` r=t (trans) Γ` si=ti, 1≤i≤k Γ` f~s=f~t (comp)
Proposition 1.13 The above rules for equational reasoning can be derived in
AF2.
Proof. We derive each rule
◦ (ref l). Clearly Γ` ∀X.Xx→Xx. ◦ (trans). It suffices to show
Γ,∀X.Xr→Xs,∀X.Xs→Xt` ∀X.Xr→Xt,
which is clear.
◦ (symm). It suffices to show Γ` s=t→t=s. The goal is then Γ,∀X.Xs→Xt` t=s.
We have by (∀E)
Γ,∀X.Xs→Xt` (Xs→Xt)[X :=λz.z=s],
i.e.,
Γ,∀X.Xs→Xt` s=s→t=s
Finally using (ref l) we can eliminate the implication getting Γ,∀X.Xs→Xt` t=s
which was the goal.
◦ (comp). Assume Γ ` si = ti for 1 ≤ i ≤ k. In particular we have Γ ` s1 = t1, which implies Γ` (Xs1 → Xt1)[X := λz.Xf zs2. . . sk], that is Γ` Xf~s→Xf t1s2. . . sk, which can be rewritten as
Γ` (Xf~s→Xf t1z2. . . zk)[z2:=s2]. . .[zk :=sk]
Therefore as the ~z are fresh variables then after applying the rule (Eq) with Γ` sj=tj for 2≤j≤kand permuting some substitutions we get
Γ` (Xf~s→Xf t1z2. . . zk)[z2:=t2]. . .[zk :=tk] i.e.,
Γ` Xf~s→Xf t1t2. . . tk
Finally by (∀2I) asX /∈ F V(Γ), we get Γ ` ∀X.Xf~s → Xf~t, which is the
1.3. SECOND ORDER LOGICAF2 29
Subject Reduction
This important property was proved in [Kri93].