Type Theory and Formal Proof 读书笔记

军训太闲了决定开个新坑?
(话说这种东西真的能叫军训嘛)

Untyped Lambda Calculus

Construction principles:

  • Abstraction \(\lambda x.M\): abstraction of a variable \(x\) over an expression \(M\).
  • Application \(M\ N\): application of an expression \(M\) to an expression \(N\).

\(\beta\)-reduction: \((\lambda x.M)\ N = M[x:=N]\).
application: a first step of the procedure of applying \(M\) to \(N\)

\(\lambda\)-terms: expressions of the untyped lambda calculus.
Let \(V\) be the set of variables. then the set of \(\lambda\)-terms (\(\Lambda\)) is defined as follows:

  • variable: \(x\in V\to x\in\Lambda\)
  • application: \(M,N\in\Lambda\to (M\ N)\in\Lambda\)
  • abstraction: \(x\in V, M\in\Lambda\to (\lambda x.M)\in\Lambda\)
    Using grammar: \(\Lambda = V|(\Lambda \Lambda)|(\lambda V.\Lambda)\)

Syntactical identity \(\equiv\)

Multiset of subterms:

  • \(Sub(x)=\{x\}\)

  • \(Sub((M\ N))=Sub(M)\cup Sub(N)\cup \{(MN)\}\)

  • \(Sub((\lambda x.M))=Sub(M)\cup\{(\lambda x.M)\}\).
    The relation \(Sub\) has reflexivity and transitivity.
    Proper subterm: \(L\in Sub(M), L\not\equiv M\).

  • application is left-associative: \(M\ N\ L=((M\ N)\ L)\)

  • application takes precedence over abstraction: \(\lambda x.M\ N=(\lambda x.(M\ N))\)

  • Success of abstraction: \(\lambda xy.M=\lambda x.(\lambda y.M)\)

Free variables

Variables can be divided into free, bound and binding occurrences.
binding: occurrences immediately after a \(\lambda\)
\(FV(L)\): set of free variables in \(L\).

  • \(FV(x)=\{x\}\)
  • \(FV(M\ N)=FV(M)\cup FV(N)\)
  • \(FV(\lambda x.M)=FV(M) \backslash \{x\}\)
    Closed \(\lambda\)-term: \(FV(M)=\emptyset\), also called a combinator. The set of it is denoted by \(\Lambda^0\).

Alpha conversion

\(M^{x\to y}\): replace all free occurrences of \(x\) in \(M\) with \(y\).
\(\lambda x.M=_\alpha \lambda y.M^{x\to y}\), where \(y\not\in FV(M)\) and \(y\) is not a binding occurrence in \(M\).
Compatibility: If \(M=_\alpha N\), then \(ML=_\alpha NL, LM=_\alpha LN\) and for any \(z\), \(\lambda z.M=_\alpha \lambda z.N\).
It's an equivalence relation.
\(\alpha\)-variant: \(M\) and \(N\) are \(\alpha\)-variants if \(M=_\alpha N\).

Substitution

  • \(x[x:=N]\equiv N\)
  • \(y[x:=N]\equiv y\), if \(y\not\equiv x\)
  • \((PQ)[x:=N]\equiv(P[x:=N])(Q[x:=N])\)
  • \((\lambda y.P)[x:=N]\equiv \lambda z.(P^{y\to z}[x:=N])\), if \(\lambda z.P^{y\to z}\) is \(\alpha\)-variant of \(\lambda y.P\) and \(z\not\in FV(N)\).

Substitution is not commutative. \(x[y:=x][x:=y]\equiv y\) but \(x[x:=y][y:=x]\equiv x\).
Let \(x\equiv y\) and \(x\notin FV(L)\), then \(M[x:=N][y:=L]=M[y:=L][x:=N[y:=L]]\)

Lambda-terms modulo \(\alpha\)-equivalence

If \(M_1=_\alpha N_1\) and \(M_2=_\alpha N_2\), then also:

  • \(M_1N_1=_\alpha M_2N_2\)
  • \(\lambda x.M_1=_\alpha \lambda x.M_2\)
  • \(M_1[x:=N_1]=_\alpha M_2[x:=N_2]\)
    We can consider a full class of \(\alpha\)-equivalent \(\lambda\)-terms as one abstract \(\lambda\)-term.
    Barendregt convention: We choose the names for the binding variables in a λ-term in such a manner that they are all different, and such that each of them differs from all free variables occurring in the term.

Beta reduction

One-step \(\beta\)-reduction(\(\to_\beta\)):

  • \((\lambda x.M)N\to_\beta M[x:=N]\). Term \((\lambda x.M)N\to_\beta\) is called a redex(reducible expression) and term \(M[x:=N]\) is called the contractum(of the redex).
  • If \(M\to_\beta N\), then \(ML\to_\beta NL\) and \(LM\to_\beta LN\) and \(\lambda x.M\to_\beta \lambda x.N\).

\(\beta\)-reduction(zero-or-more-step), \(\twoheadrightarrow_\beta\): \(M\twoheadrightarrow_\beta N\) if there are terms \(M_0\) to \(M_n\) such that \(M_0\equiv M\), \(M_n\equiv N\) and forall \(0\leq i<n\), \(M_i\to_\beta M_{i+1}\).

  • \(\twoheadrightarrow\) is reflexive and transitive.

\(\beta\)-conversion(\(=_\beta\)): \(M=_\beta N\) if there are terms \(M_0\) to \(M_n\) such that \(M_0\equiv M\), \(M_n\equiv N\) and forall \(0\leq i<n\), either \(M_i\to_\beta M_{i+1}\) or \(M_{i+1}\to_\beta M_i\).

  • \(=_\beta\) is an equivalence relation.

Normal forms and confluence

\(\beta\)-normal form:

  • \(M\) is in \(\beta\)-normal form if \(M\) does not contain any redex.
  • \(M\) has a \(\beta\)-normal form if there is a term \(N\) such that \(M=_\beta N\) and \(N\) is in \(\beta\)-normal form.

When \(M\) is in \(\beta\)-nf, then \(M\twoheadrightarrow_\beta N\) implies \(M\equiv N\). (The converse is not true.)

Some example:

  • Let \(\Omega = (\lambda x.x x)(\lambda x.xx)\). \(\Omega\) only \(\beta\)-reduces to itself, so it is not a \(\beta\)-nf and does not reduce to a \(\beta\)-nf.
  • Let \(\Delta = \lambda x.xxx\). Then \(\Delta\Delta\to_\beta\Delta\Delta\Delta\to_\beta\Delta\Delta\Delta\Delta\to_\beta\cdots\), so \(\Delta\Delta\) also does not reduce to a \(\beta\)-nf.
  • \((\lambda u.v)\Delta\) contains two redexes. Reduce the first redex gives \(v\), which is in \(\beta\)-nf, so \((\lambda u.v)\Delta\) has a \(\beta\)-nf.

Reduction path:

  • a finite reduction path from \(M\) is a finite sequence of terms \(N_0,\cdots,N_n\) such that \(N_0\equiv M\) and \(N_i\to_\beta N_{i+1}\) for all \(0\leq i<n\).
  • an infinite reduction path from \(M\) is an infinite sequence of terms \(N_0,N_1,\cdots\) such that \(N_0\equiv M\) and \(N_i\to_\beta N_{i+1}\) for all \(i\geq 0\).

Weak normalisation: \(M\) is weakly normalising if there is an \(N\) in \(\beta\)-normal form such that \(M\twoheadrightarrow_\beta N\).
Strong normalisation: \(M\) is strongly normalising if there is no infinite reduction path from \(M\).

Church-Rosser theorem: Suppose that for a given \(\lambda\)-term \(M\), we have \(M\twoheadrightarrow_\beta N_1\) and \(M\twoheadrightarrow_\beta N_2\). Then there is a \(\lambda\)-term \(N_3\) such that \(N_1\twoheadrightarrow_\beta N_3\) and \(N_2\twoheadrightarrow_\beta N_3\).

  • implies that the outcome of a calculation (if exists) is independent of the order in which the calculations are performed.
  • Corollary: If \(M=_\beta N\), then there is \(L\) such that \(M\twoheadrightarrow_\beta L\) and \(N\twoheadrightarrow_\beta L\).

Corollaries:

  • If \(M\) has \(N\) as a \(\beta\)-nf, then \(M\twoheadrightarrow_\beta N\).
  • A \(\lambda\)-term has at most one \(\beta\)-nf.

Fixed point theorem

Forall \(L\in\Lambda\), there is a term \(M\) such that \(LM=_\beta M\).

  • Proof: Let \(M:=(\lambda x.L (xx))(\lambda x.L (xx))\).

Fixed point combinator: \(Y\equiv \lambda y.(\lambda x.y (xx))(\lambda x.y (xx))\).

  • Froall \(L\), \(Y L=_\beta L (Y L)\).

剩下的可以看这里

posted @ 2023-06-27 10:33  EncodeTalker  阅读(25)  评论(0编辑  收藏  举报