Domains VIII Sobolev Institute of Mathematics Novosibirsk Akademgorodok 11 - 15 September, 2007
A domain-theoretic characterisation of strong normalisation in the λ-R-calculus
Ulrich Berger Swansea University
1 / 52
A domain-theoretic characterisation of strong normalisation in the - - PowerPoint PPT Presentation
Domains VIII Sobolev Institute of Mathematics Novosibirsk Akademgorodok 11 - 15 September, 2007 A domain-theoretic characterisation of strong normalisation in the - R -calculus Ulrich Berger Swansea University 1 / 52 Introduction
Domains VIII Sobolev Institute of Mathematics Novosibirsk Akademgorodok 11 - 15 September, 2007
Ulrich Berger Swansea University
1 / 52
2 / 52
Introduction
Given a higher type rewrite system - typically an extension of G¨
prove strong normalisation?
3 / 52
Introduction
We define a domain model with totality such that for any rewrite system: if all constants are total, then all terms are strongly normalising. Advantages
G¨
constant separately.
4 / 52
Introduction
β-conversion, (λx.M)N → M[N/x], plus R A G 0 → A R A G (n + 1) → G n (R A G n) Suppressing arguments that are not changed in the recursive call of R this simplifies to R 0 → A R (n + 1) → G n (R n) In the following examples we use this simplified notation.
5 / 52
Introduction
BR(α, n) → if Y α < n then G(α, n) else H α n (λx.BR(αx
n, n + 1))
where x < 0 → F 0 < (y + 1) → T (x + 1) < (y + 1) → x < y and αx
n := λm.if m = n then x else α m
Think of (α, n) as coding the finite sequence [α 0, . . . , α (n − 1)]. Hence (αx
n, n + 1) codes the sequence [α 0, . . . , α (n − 1), x].
6 / 52
Introduction
OR α → Y α (λn, x, β.if x ≺ α n then OR (αx,β
n ) else 0 )
where αx,β
n
= λm.if m ≤ n then αx
n m else β m .
Think of α as ranging over infinite sequences ordered lexicographically by ≺. Hence αx,β
n , with x ≺ α n, ranges over all infinite sequences
lexicographically below α.
7 / 52
Introduction
The rewrite rules we have seen are all meaningful w.r.t. a domain semantics, since they can be viewed as recursive definition. That is, the denotational semantics of a constant is the least fixed point of the effectively continuous function explicitely defined by the rules.
8 / 52
Introduction
x | | y → x x | | y → y
◮ Used by Kristiansen (CiE 2006) to characterise the
nondeterministic polynomial hierarchy in terms of fragments
◮ What is its denotational semantics? ◮ Can destroy termination: extending G¨
f 0 1 x → f x x x still terminates, but adding further | | yields f 0 1 (0 | | 1) → f (0 | | 1) (0 | | 1) (0 | | 1) →2 f 0 1 (0 | | 1) (Toyama)
9 / 52
Introduction
We interpret terms as nondeterministic values, i.e. as finite sequences of deterministic values. The choice operator | | is interpreted as the concatenation
10 / 52
Introduction
We characterise strong normalisation by the denotational property
[ [M] ] total ⇒ [ [M] ] = ⊥ ⇔ M strongly normalising
11 / 52
Introduction
◮ Adequacy for PCF (Plotkin): If a closed PCF-term of base
type denotes a numeral in the domain model, then it weak head reduces to that numeral.
◮ Characterisation of strongly normalising (pure) λ-terms by
intersection types (Pottinger).
◮ Intersection types as a filter model of λ-terms (Barendregt,
Coppo, Dezani, van Bakel). The connection with intersection types was pointed out by Thomas Ehrhard.
12 / 52
Introduction
◮ “[
[M] ] = ⊥ ⇒ SN(M)” for deterministic rewrite systems, assuming SN for the underlying type theory (B 05).
◮ “[
[M] ] = ⊥ ⇒ SN(M)” for deterministic rewrite systems, unconditionally, using the “intersection types as filter models” idea (Coquand, Spiwack 06). New in this talk:
◮ Nondeterminism. ◮ Completeness: “[
[M] ] = ⊥ ⇔ SN(M)”.
◮ Abstract domain theory instead of formal typing rules.
13 / 52
The λ-R-calculus
Λ ∋ M, N ::= x variable | c constructor (always includes T, F) | f constant | (M, N) pair | λx.M abstraction | M N application | if(M, N) definition by cases Notation: if K then M else N := if(M, N) K.
14 / 52
The λ-R-calculus
For every constant f we assume a list Rf of rules of the form f P → M where
◮
P is a list of patterns, i.e. terms built from constructors, variables and pairing, such that in P no variable occurs more than once;
◮ M is a term with FV(M) ⊆ FV(
P);
◮ the length of the pattern list
P is fixed for each f (this fixed length is called the arity of f );
◮ only finitely many left hand sides are allowed to be unifiable.
15 / 52
The λ-R-calculus
R A G 0 → A R A G (S, n) → G n (R A G n) R constant of arity 3 0, S constructors A, G, n variables
16 / 52
The λ-R-calculus
Contracting a subterm of K which is not in a branch of an if-term, where contracts to (λx.M) N M[N/x] if(M, N) T M if(M, N) F N f Pθ M θ (f P → M a rule, θ a substitutition)
17 / 52
The λ-R-calculus
A term M is strongly normalising, SN(M), if there is no infinite reduction sequence M → M′ → M′′ → . . .
18 / 52
The λ-R-calculus
A term is safe if (1) every constant f occurs only in contexts of the form f M1 . . . Mk where k is the arity of f , (2) no constructor or pair occurs as the left hand side of an application, (3) (inductively) all reducts are safe. Safety is usually guaranteed by typability.
19 / 52
Domain-theoretic semantics
D = C⊥ ⊕ (D∗ ⊗ D∗) ⊕ (D∗
!
→ D∗) C⊥ flat domain of constructors D∗ strict finite lists (non-deterministic values) ⊗ strict (or smash) product ⊕ strict (or coalesced) sum
!
→ strict function space The elements of D+ := D \ ⊥: c (c a constructor) (d, e) (d, e ∈ D∗
+)
fun(f ) (f : D∗ → D∗, continuous, strict, = ⊥)
20 / 52
Domain-theoretic semantics
app(fun(f ), d) := f (d) app(d, d) := ⊥, if d is a pair or a constructor d • e := [app(d, e) | d ← d] T ⊲ d := d F ⊲ d := [] matchP : D∗ → (FV(P) → D∗)∗ matchx(d) = [[x → d]] matchc(d) = (c ∈ d) ⊲ [∅] match(P,Q)(d) = [η ∪ η′ | (e, e′) ← d, η ← matchP(e), η′ ← matchQ(e′)]
21 / 52
Domain-theoretic semantics
[ [x] ]η = η(x) [ [c] ] = [c] [ [(M, N)] ]η = [([ [M] ]η, [ [N] ]η)] [ [MN] ]η = [ [M] ]η • [ [N] ]η [ [λx.M] ]η = [fun(λd ∈ D∗.[ [M] ]η[x := d])] [ [if(M, N)] ]η = [fun(λd ∈ D∗.(T ∈ d ⊲ [ [M] ]η) + + (F ∈ d ⊲ [ [N] ]η))] [ [f ] ] = [funk(λ d ∈ (D∗)k. concat[ [ [M] ]η | ( P → M) ← Rf , η ← match
P(
d) ] )] where η: FV(M) → D∗ and k = arity(f ).
22 / 52
Domain-theoretic semantics
The relation U ⊑ [ [M] ]η, where U ranges over non-deterministic defined compacts, can be defined inductively, similar to typing judgements in the intersection type calculus (η ⊢ M : U). This has been carried out (without non-determinism) by Coquand and Spiwack. Hence, “[ [M] ]η = ⊥”, which is equivalent to “∃U (U ⊑ [ [M] ]η)”, can be read as “M is typeable”.
23 / 52
Characterising strong normalisation
Set [ [M] ] := [ [M] ]η0 where η0(x) := [] for all variables x. For every safe term M, [ [M] ] = ⊥ ⇔ M is strongly normalising We sketch the proof of “⇒” (which doesn’t need the safety assumption).
24 / 52
Characterising strong normalisation
A term is simple if it has neither of the following forms: c N, (M1, M2) N, λx.M, if then M else N , f N1 . . . Nk where k < arity(f ). A reducibility candidate is a set X of terms such that RC1 X ⊆ SN. RC2 If M ∈ X and M → M′, then M′ ∈ X. RC3 If M is simple and ∀M′ (M → M′ ⇒ M′ ∈ X), then M ∈ X. X → Y := {M | ∀N (N ∈ X ⇒ MN ∈ Y )}. X × Y := {(M, N) | M ∈ X, N ∈ Y } (⊆ Λ). RC3(X) := the closure of X under the rule RC3 above.
25 / 52
Characterising strong normalisation
D = limn Dn, with canonical embeddings ǫn : Dn → D, where D0 = {⊥} Dn+1 = C⊥ ⊕ (D∗
n ⊗ D∗ n) ⊕ (D∗ n !
→ D∗
n)
For compacts U ∈ D \ ⊥ and U ∈ D∗ \ ⊥ we set rk(U) := min{n | n ∈ ǫn(Dn)} rk(U) := sup{rk(U) | U ∈ U} (the stage where U resp. U is constructed)
26 / 52
Characterising strong normalisation
◮ rk(Ui) < rk((U1, U2)). ◮ If F(d) = ⊥, then
27 / 52
Characterising strong normalisation
Λ(c) = RC3(c) Λ((U, V)) = RC3(Λ(U) × Λ(V)) Λ(fun(F)) = {Λ(U) → Λ(F(U)) | U ∈ dom(F), rk(U)<rk(fun(F))} = {Λ(U) → Λ(F(U)) | U ∈ dom(F)} Λ(U) = RC3({Λ(U) | U ∈ U})
28 / 52
Characterising strong normalisation
◮ If U ⊆ V, then Λ(U) ⊆ Λ(V) ◮ If U ⊑ V, then Λ(U) ⊇ Λ(V) ◮ If M ∈ Λ(U) and N ∈ Λ(V), then M N ∈ Λ(U • V) ◮ If M[N/x] ∈ Λ(F(U)) for all U ∈ dom(F) and all N ∈ Λ(U),
then λx.M ∈ Λ(fun(F))
◮ If Pθ ∈ Λ(U), then θ ∈ Λ(η) for some η ∈ matchP(U)
29 / 52
Characterising strong normalisation
If U ⊑ [ [M] ]nη and θ ∈ Λ(η), then Mθ ∈ Λ(U). Proof by “Scott induction”, i.e. induction on n.
30 / 52
Characterising strong normalisation
Main Claim: If M is strongly normalising, then
[M] ] = ⊥,
[M] ]) there exists a substitution θ with dom(θ) = FV(P) such that M →∗ Pθ and η = [ [θ] ], i.e. η(x) = [ [θ] ](x), Proof by induction on the strong normalisability of M.
31 / 52
Types and totality
Polymorphic types
A typed system is given by a rewrite system and typing axioms f : ρ → σ where f is a function constant and ρ, σ are types.
32 / 52
Types and totality
Γ ⊢ T : o Γ ⊢ F : o Γ ⊢ 0 : ι Γ ⊢ M : ι Γ ⊢ (S, M) : ι Γ, x : ρ ⊢ x : ρ Γ, x : ρ ⊢ M : σ Γ ⊢ λx.M : ρ → σ Γ ⊢ M : ρ → σ Γ ⊢ N : ρ Γ ⊢ MN : σ Γ ⊢ M : ρ Γ ⊢ M : ∀p .ρ (p not free in Γ) Γ ⊢ M : ∀p .ρ Γ ⊢ M : ρ[σ/p] Γ ⊢ Mi : ρi (i = 1, . . . , k) Γ ⊢ f M1 . . . Mk : σ (f : ρ1, . . . , ρk → σ axiom) Γ ⊢ M : ρ Γ ⊢ N : ρ Γ ⊢ if then M else N : o → ρ
33 / 52
Types and totality
[ [ρ] ]t ⊆ D+ (ρ type, t : type variables → powerset of D) [ [p] ]t = t(p). [ [o] ]t = {T, F}. [ [ι] ]t = the least subset of D+ containing 0 and with d1, . . . , dn also ([S], [d1, . . . , dn]). [ [ρ → σ] ]t = {fun(f ) | f ([ [ρ] ]t∗) ⊆ [ [σ] ]t∗}. [ [∀p .ρ] ]t =
A⊆D+[
[ρ] ]t[p:=A]. [ [ρ] ] := [ [ρ] ]t∅ where t∅(p) := ∅ for all type variables p.
34 / 52
Types and totality
A typed system is total if [ [f ] ] ∈ [ [ ρ → σ] ]∗
t for every axiom
f : ρ → σ and every assignment t. Semantic typing Γ | = M : ρ :⇔ ∀η, t(η ∈ [ [Γ] ]∗
t ⇒ [
[M] ]η ∈ [ [ρ] ]∗
t )
Semantic soundness theorem for total typed systems Γ ⊢ M : ρ ⇒ Γ | = M : ρ Corollary Every total typed system is strongly normalising.
35 / 52
Types and totality
A type correct system is a typed system such that
P → M and context Γ, if Γ ⊢ Pi : ρi for all i = 1, . . . , k, then Γ ⊢ M : σ. Lemma Type correct systems are safe, i.e. every typeable term is safe. Corollary In a type correct system a typeable term is strongly normalising if and only if it does not denote ⊥.
36 / 52
Applications
R : ρ, (ι → ρ → ρ), ι → ρ BR : τG, τH, τY , (ι → ρ), ι → σ where τG = (ι → ρ) → ι → σ τH = (ι → ρ) → ι → (ρ → σ) → σ τY = (ι → ρ) → o OR : τY , (ι → ρ), ι where τY = (ι → ρ) → (ι → ρ → (ι → ρ) → ι) → ι | | ρ, ρ → ρ
37 / 52
Applications
Theorem The typed system comprising system T, barrecursion, open recursion and non-deterministic choice is strongly normalising. Proof It suffices to show that all constants are total. For example, [ [ | | ] ] • d • e = d+ +e. Hence, clearly [ [ | | ] ] ∈ [ [ρ → ρ → ρ] ].
38 / 52
Applications
[ [R] ] • d1 • d2 • d3 = ((0 ∈ d3)⊲d1) + + concat [d2•e•([ [R] ]•d1•d2•e) | ([S], e) ← d3] One easily shows [ [R] ] • d1 • d2 • d3 ∈ [ [ρ] ]∗ for all (d1, d2, d3) ∈ [ [ρ] ]∗ × [ [ι → ρ → ρ] ]∗ × [ [ι] ]∗, by induction on the number of occurrences of the constructor S in d3 ∈ [ [ι] ]∗.
39 / 52
Applications
Γ ⊢ Mi : ρi Γ ⊢ (i, M) : ρ0 + ρ1 (i = 0, 1) Casek : (ρ0 → σ′), (ρ1 → σ′), (ρ0 + ρ1), σ1, . . . , σk → σ, where σ′ := σ1 → . . . → σk → σ. Case0 x0 x1 (i, y) → xi y (i = 0, 1) Casek+1 x0 x1 (i, y) z → xi y z (i = 0, 1)
40 / 52
Applications
Casek+1 x0 x1 u z → Casek (λy0.x0 y0 z) (λy1.x1 y1 z) u. Recall: Casek : (ρ0 → σ′), (ρ1 → σ′), (ρ0 + ρ1), σ1, . . . , σk → σ, where σ′ := σ1 → . . . → σk → σ. Theorem The system comprising the previously considered extensions of G¨
normalising. Proof : Show that [ [Casek] ] is total, by induction on k.
41 / 52
Applications
Γ ⊢ M0 : ρ Γ ⊢ M1 : ρ Γ ⊢ M2 : ρ . . . Γ ⊢< Mi >i∈N: ι → ρ < Mi >i∈N 0 → M0 < Mi >i∈N (S, K) → < Mi+1 >i∈N K Reduction inside < Mi >i∈N is not allowed.
42 / 52
Applications
Theorem The system comprising the previous system plus ω-rule is strongly normalising. Proof : The ω-rule can be simulated by constants f⌈
x,<Mi>i∈N⌉, for
every infinite sequence of terms M0, M1, M2, . . . with free variable included in x, and the rewrite rules f⌈
x,<Mi>i∈N⌉
x 0 → M0 f⌈
x,<Mi>i∈N⌉
x (S, K) → f⌈
x,<Mi+1>i∈N⌉
x K It is easy to prove that each f⌈
x,<Mi>i∈N⌉ is total.
43 / 52
Conclusion
◮ We introduced a flexible, powerful and easy to use method for
proving strong normalisation for λ-calculi with rewriting.
◮ In typed systems additional constants only need to be shown
total.
◮ Can cope with non-determinism and infinitary terms (ω-rule). ◮ Restricted to “definitional rules”. Hence rules like
(x + y) + z → x + (y + z) are excluded.
◮ Can our semantic method be combined with more syntax
with rules like the above?
44 / 52
Conclusion
◮ Although easy to use, our method is too heavy handed, from
a foundational point of view:
the usual definition of Tait’s strong computability predicates).
[ρ → σ] ] requires quantification over domain elements (i.e. second-order objects).
third-order quantification.
◮ Due to recent results by Abel (HOR’97) it is likely that the
characterisation theorem can be proven elementarily (see also Valentini’s elementary proof of the corresponding theorem for intersection types).
45 / 52
References
¨ Uber eine bisher noch nicht ben¨ utzte Erweiterung des finiten
Provably recursive functionals of analysis: a consistency proof
Theory: Proc. Sympos. in Pure Math., 5, 1–27. AMS, 1962
Outline of a mathematical theory of computation. In 4th Annual Princeton Conference on Information Sciences and Systems, pages 169–176, 1970.
46 / 52
References
W.W. Tait. Normal form theorem for barrecursive functions of finite type. In J.E. Fenstad, ed, Proceedings of the Second Scandinavian Logic Symp., 353–367. North–Holland, 1971.
Ein starker Normalisationssatz f¨ ur die barrekursiven
Yuri L. Ershov. Model C of partial continuous functionals. Logic Colloquium
Amsterdam 455–467, 1977.
LCF considered as a programming language. Theoretical Computer Science, 5:223–255, 1977.
47 / 52
References
A type assignment for the strongly normalisable terms. In J.P. Seldin and J.R. Hindley, editors, To H.B. Curry: Essays on Combinatory Logic, Lambda Calculus and Formalism, pages 561–577. Academic Press, 1980.
A filter lambda model and the completeness of type
Strong normalization of barrecursive terms without using infinite terms. Arch. Math. Logic, 25:175–181, 1985.
Counterexample to termination for the direct sum of term rewriting systems. Information Processing Letters, 25:141–143, 1987.
48 / 52
References
Complete restrictions of the intersection type discipline. Theoretical Computer Science, 102:135–163, 1992.
Strict functionals for termination proofs. In
Calculi and Applications, volume 902 of LNCS, pages 350–364. Springer Verlag, Berlin, Heidelberg, New York, 1995.
Termination for direct sums of left-linear complete term rewriting systems. Journal of the Association for Computing Machinery, 42(6):1275–1304, 1995.
49 / 52
References
Relational Properties of Domains. Information and Computation, 127(2):66–90, 1996.
On the computational content of the axiom of choice. Journal
The calculus of algebraic constructions. In P. Narendran and
in LNCS, pages 301–316. Springer Verlag, Berlin, Heidelberg, New York, 1999.
50 / 52
References
An elementary proof of strong normalisation for intersection
B. A computational interpretation of open induction. Lics 2004. B. Strong normalization for applied lambda calculi. Logical Methods in Computer Science, 1(2):1–14, 2005.
51 / 52
References
Proof of strong normalisation using domain theory. Lics 2006.
Syntactical normalization for intersection types with term rewriting rules. In Fourth International Workshop on Higher-Order Rewriting, HOR’07, Paris, France, 25 June 2007, 2007. B. A domain model characterising strong normalisation. To appear in Annals of Pure and Applied Logic.
52 / 52