Size-Based Termination: Semantics and Generalizations Cody Roux - - PowerPoint PPT Presentation

size based termination semantics and generalizations
SMART_READER_LITE
LIVE PREVIEW

Size-Based Termination: Semantics and Generalizations Cody Roux - - PowerPoint PPT Presentation

Introduction Size-Based Termination: Semantics and Generalizations Cody Roux INRIA-Lorraine Pareo June 7, 2011 Introduction Outline Introduction Introduction High-level computation is about recognizing shapes: And modifying them:


slide-1
SLIDE 1

Introduction

Size-Based Termination: Semantics and Generalizations

Cody Roux

INRIA-Lorraine Pareo

June 7, 2011

slide-2
SLIDE 2

Introduction

Outline

Introduction

slide-3
SLIDE 3

Introduction

High-level computation is about recognizing shapes: And modifying them:

slide-4
SLIDE 4

Introduction

We are particularly interested in tree structures and their transformations. Trees can be represented using algebraic data-types: the tree f g a a Is represented by the term: f(g(a), a)

slide-5
SLIDE 5

Introduction

We can also represent families of trees using terms with variables: The family of trees: f g is represented by the term f(g(x), y)

slide-6
SLIDE 6

Introduction

We can then represent transformations using pairs of terms: The transformation: f g g Is represented by the rule: f(g(x), y) → g(y) Applying the transformation is called rewriting.

slide-7
SLIDE 7

Introduction

Example: the snowflakes can be represented by terms of the shape

  • Line
  • Peak(x, y, z, w)

x y z w For example if a = Peak(Line, Line, Line, Line) then Peak(a, Line, Line, a) represents:

slide-8
SLIDE 8

Introduction

We can transform such a shape by the rule: Line → Peak(Line, Line, Line, Line) This is non-deterministic: applied to Peak(Line, Line, Line, Line) it can give

  • r

Rewriting can therefore encode decisions.

slide-9
SLIDE 9

Introduction

More formally:

  • A term is either a variable x, y, . . . or a function symbol f, g, . . .

applied to a number of terms, depending on its arity.

  • A rewrite rule is a pair l → r of terms such that all variables of r

are present in l.

  • A substitution θ is a (partial) mapping from variables to terms.

We write tθ for the term t in which every variable x is replaced with θ(x).

  • A term t rewrites to a term u if there is a rule l → r, a subterm t′

and a substitution θ such that t′ = lθ and u is equal to t with the

  • ccurrence of t′ replaced with rθ.
slide-10
SLIDE 10

Introduction

A few remarks:

  • Pure rewriting has a very rich and profound theory

[Bezem et al., 2003, Jouannaud, 1993, Dershowitz and Jouannaud, 1990, Baader and Nipkow, 1998].

  • Rewriting is very expressive: it is Turing-complete, and most

problems are undecidable: Termination, Confluence, Reachability... And can serve as a model for computation, security protocols, etc.

  • Rewriting can be seen as a semantics for equality: a rewrite rule

can be seen as a directed equation.

slide-11
SLIDE 11

Introduction

Given a family of terms, for example: f There is a fundamental transformation: f This is the substitution operation. We wish to reify this transformation.

slide-12
SLIDE 12

Introduction

This transformation becomes the term

λx.f(x, x)

Called the abstraction of f(x, x). This term can be applied:

(λx.f(x, x))t

rewrites to f(t, t) This reduction is called β-reduction.

slide-13
SLIDE 13

Introduction

The combination of β-reduction and rewriting is very expressive: it may form the basis of a real programming language! (e.g. Ocaml/SML [Cousineau et al., 1985, Milner et al., 1997], Haskell [Hudak et al., 1992], Elan [Borovanský et al., 1998], Maude [Clavel et al., 1996]...) Our approach is founded on [Jouannaud and Okada, 1991].

slide-14
SLIDE 14

Introduction

In fact a bit too expressive!

We add types:

  • Allows simple algebraic semantics
  • Makes β-reduction alone terminating

How can we use this additional structure to give guarantees?

slide-15
SLIDE 15

Algebraic semantics Size-based termination Semantic Labelling The Model Construction Proving Termination

Outline

Algebraic semantics Size-based termination Semantic Labelling The Model Construction Proving Termination

slide-16
SLIDE 16

Algebraic semantics Size-based termination Semantic Labelling The Model Construction Proving Termination

We adopt the algebraic semantics for higher-order systems described by Plotkin, Fiore and Turi [Fiore et al., 1999] and extended to rewriting by Hamana [Hamana, 2003].

slide-17
SLIDE 17

Algebraic semantics Size-based termination Semantic Labelling The Model Construction Proving Termination

What is an algebraic structure?

The categorical view:

An algebraic structure is a functor which encodes information which can refer to its argument: Nat(X) = Unit + X An element of Nat(X) is either a “special element” i or a box containing an e ∈ X. Given a functor F, an F-algebra A is an interpretation of F(A) into A: eval : F(A) → A

slide-18
SLIDE 18

Algebraic semantics Size-based termination Semantic Labelling The Model Construction Proving Termination

For Nat(X) over sets: An algebra is a set A with

  • An element z ∈ A, the image of i by eval
  • A function s : A → A which sends the boxed element e to s(e).
  • Nat-algebras form a category
  • The initial Nat-algebra is the set of closed terms

0, S(0), S(S(0)), . . . Or, equivalently, N. How do we encode information about variable binding?

slide-19
SLIDE 19

Algebraic semantics Size-based termination Semantic Labelling The Model Construction Proving Termination

Idea: replace sets with variable indexed sets, called presheafs: For each set V = {x1, . . . , xn} of variables A(V) are the elements

  • f A that depend on x1, . . . , xn.

Motivating example:

Term(V) = {t | free variables of t ⊆ V}

slide-20
SLIDE 20

Algebraic semantics Size-based termination Semantic Labelling The Model Construction Proving Termination

Abstraction then becomes a morphism of presheafs: absV : A(V ∪ {x}) → A(V) for x V. We define the presheaf Ax(V) = A(V∪{x}) for x V. This gives abs : Ax → A

slide-21
SLIDE 21

Algebraic semantics Size-based termination Semantic Labelling The Model Construction Proving Termination

In the typed framework:

Γ, x : T, ∆ ⊢ x : T var Γ ⊢ f : τf

sig

Γ ⊢ t : T → U Γ ⊢ u: T Γ ⊢ t u: U

app

Γ, x : T ⊢ t : U Γ ⊢ λx : T.t : T → U abs

slide-22
SLIDE 22

Algebraic semantics Size-based termination Semantic Labelling The Model Construction Proving Termination

The typed algebras: presheafs over contexts instead of sets of variables and indexed by types.

The term presheaf

TermT(Γ) = {t | Γ ⊢ t : T}

slide-23
SLIDE 23

Algebraic semantics Size-based termination Semantic Labelling The Model Construction Proving Termination

We can give the signature for the that defines term algebra functor:

Σλ(F) = V + S + F × F + Fx : _

slide-24
SLIDE 24

Algebraic semantics Size-based termination Semantic Labelling The Model Construction Proving Termination

We can give the signature for the that defines term algebra functor:

Σλ(F) =

V

  • var

+

S

  • sig

+ F × F

  • app

+ Fx : _

  • abs
slide-25
SLIDE 25

Algebraic semantics Size-based termination Semantic Labelling The Model Construction Proving Termination

We can give the signature for the that defines term algebra functor:

Σλ(F) =

V

  • var

+

S

  • sig

+ F × F

  • app

+ Fx : _

  • abs

Note: the actual product and abstraction are slightly more complex.

slide-26
SLIDE 26

Algebraic semantics Size-based termination Semantic Labelling The Model Construction Proving Termination

We define the operator • on presheafs:

(A • B)T(Γ)

is the set of tuples

(a, b1, . . . , bn)

such that a ∈ AT(x1 : T1, . . . , xn : Tn) ⇒ bi ∈ BTi(Γ) modulo renaming. This can be seen as the unapplied substitution a{x1 → b1, . . . , xn → bn}

slide-27
SLIDE 27

Algebraic semantics Size-based termination Semantic Labelling The Model Construction Proving Termination

The operator • defines a monoidal product for term algebras. We define a substitution to be an arrow subst : A • A → A which turns A into a •-monoid. We furthermore require the structure to be compatible with the algebra structure; we call this a •-algebra.

slide-28
SLIDE 28

Algebraic semantics Size-based termination Semantic Labelling The Model Construction Proving Termination

Theorem (Fiore, Plotkin & Turi)

Term is the initial •-algebra. This gives us an interpretation morphism

( |_| ): Term → A

for every •-algebra A.

We write: ( |Γ ⊢ t : A| ) ∈ AT(Γ)

slide-29
SLIDE 29

Algebraic semantics Size-based termination Semantic Labelling The Model Construction Proving Termination

Finally, we want this structure to be compatible with the rewrite rules: A is an ordered presheaf such that t →∗

R∪β u

⇒ ( |t| ) ≥ ( |u| )

We call such a structure a premodel, or model if there is equality.

slide-30
SLIDE 30

Algebraic semantics Size-based termination Semantic Labelling The Model Construction Proving Termination

Question

How can we use models to simplify termination problems?

slide-31
SLIDE 31

Algebraic semantics Size-based termination Semantic Labelling The Model Construction Proving Termination

Outline

Algebraic semantics Size-based termination Semantic Labelling The Model Construction Proving Termination

slide-32
SLIDE 32

Algebraic semantics Size-based termination Semantic Labelling The Model Construction Proving Termination

Size-based termination uses type annotations to deduce size-information about terms.

We have a judgment for base types: Γ ⊢size t : Ba

Which denotes: t is of size a.

slide-33
SLIDE 33

Algebraic semantics Size-based termination Semantic Labelling The Model Construction Proving Termination

We consider strictly positive inductive types: if c is a constructor of the type B, for example c : A → B → (A → B) → B then we annotate with size information to give c : A → Bα → (A → Bβ) → Bmax(α,β)+1 The size of a term intuitively corresponds to the size of the normal form as a tree.

slide-34
SLIDE 34

Algebraic semantics Size-based termination Semantic Labelling The Model Construction Proving Termination

The size-type system is given by the following rules [Blanqui and Roux, 2009, Blanqui, 2004, Barthe et al., 2004]:

Γ, x : T, ∆ ⊢size x : T ax φ subst Γ ⊢size f : τfφsymb Γ ⊢size t : T → U Γ ⊢size u: T Γ ⊢size t u: U

app

Γ, x : T∞ ⊢size t : U Γ ⊢size λx : |T|.t : T → U abs Γ ⊢size t : T

T ≤ U

Γ ⊢size t : U

sub

slide-35
SLIDE 35

Algebraic semantics Size-based termination Semantic Labelling The Model Construction Proving Termination

The criterion then requires (among other things) that each rule f l1 . . . ln → r if Γ ⊢size li : Bai then

Γ ⊢

a size r : T

where ⊢

a size constrains recursive calls on f to smaller arguments.

slide-36
SLIDE 36

Algebraic semantics Size-based termination Semantic Labelling The Model Construction Proving Termination

The traditional proof of correctness involves a modification of the classic Tait normalization proof. We desire

  • A more conceptually simple proof.
  • A more modular proof.
slide-37
SLIDE 37

Algebraic semantics Size-based termination Semantic Labelling The Model Construction Proving Termination

Our approach: Rewrite System Translated System Algebraic Semantics Generic Termination Proof

slide-38
SLIDE 38

Algebraic semantics Size-based termination Semantic Labelling The Model Construction Proving Termination

Outline

Algebraic semantics Size-based termination Semantic Labelling Currying Stability by Reduction The Model Construction Proving Termination

slide-39
SLIDE 39

Algebraic semantics Size-based termination Semantic Labelling The Model Construction Proving Termination

Our transformation method needs to use semantic information in the terms. We select semantic labelling [Zantema, 1995].

slide-40
SLIDE 40

Algebraic semantics Size-based termination Semantic Labelling The Model Construction Proving Termination

The idea:

  • Select a model MR of the rewrite system R, with interpretation

( |_| )M.

  • In each rule l → r ∈ R, we replace each f(t1, . . . , tn) ∈ l, r with

f((

|t1| ),...,( |tn| ))(t1, . . . , tn)

recursively.

  • Show that normalization of the new system is equivalent to that
  • f the original system.
slide-41
SLIDE 41

Algebraic semantics Size-based termination Semantic Labelling The Model Construction Proving Termination

Hamana [Hamana, 2007] describes such a framework for the higher-order case and shows correctness.

slide-42
SLIDE 42

Algebraic semantics Size-based termination Semantic Labelling The Model Construction Proving Termination

However his approach has several drawbacks:

  • Application may not be curried.
  • The reduction associated to β-reduction is not β-reduction!
slide-43
SLIDE 43

Algebraic semantics Size-based termination Semantic Labelling The Model Construction Proving Termination

The definition of labelling:

Without currying φ is a valuation and

  • xφ = x
  • t u

φ = t φ uφ

  • λx : T.t

φ = λx : T.t φx

x

  • f(t1, . . . , tn)

φ = f( | t| )φ(t1 φ, . . . , tn φ)

Where φx

x weakens the context for φ and extends it to send x to x.

The labelling of a term only depends on the semantics of subtypes.

slide-44
SLIDE 44

Algebraic semantics Size-based termination Semantic Labelling The Model Construction Proving Termination

In the curried framework: f(t1, t2, . . . , tn) is represented by (. . . ((f t1) t2) . . . tn) The labelling of this last term is f() t1

φ . . . tn φ

There is no meaningful label for f as it takes no arguments!

slide-45
SLIDE 45

Algebraic semantics Size-based termination Semantic Labelling The Model Construction Proving Termination

Our solution: non structural labelling: f t1 . . . tn

φ = f( | t| )φ t1 φ . . . tn φ

f may be applied to less than n arguments. f t1 . . . tk

φ = f(( |t1| )φ,...,( |tk| ),( |?| ))

t

φ

slide-46
SLIDE 46

Algebraic semantics Size-based termination Semantic Labelling The Model Construction Proving Termination

We solve this by weakening the context for f-labels in this case: f t1 . . . tk

φ = f(( |t1| )φ′,...,( |tk| )φ′,( |x1| )φ′,...,( |xn−k| )φ′)

t

φ

with φ′ = φx1...xn−k

x1...xn−k

slide-47
SLIDE 47

Algebraic semantics Size-based termination Semantic Labelling The Model Construction Proving Termination

Now the fundamental property of labelling in the first-order case is expressed by: t→Rt′ ⇔ ∀φ, t

φ→Rt′φ

if we are working with a model and t→Rt′ ⇔ ∀φ, t

φ→R∪Decr

∗t′φ

if we are working with a premodel, with Decr = {fl → fl′ | l ≥M∗ l′}

slide-48
SLIDE 48

Algebraic semantics Size-based termination Semantic Labelling The Model Construction Proving Termination

In the higher-order framework we would like to have t→R∪βt′ ⇔ t

φ→R∪βt′φ

to be able to apply some generic termination argument to the labelled system. However this property fails in Hamana’s framework.

slide-49
SLIDE 49

Algebraic semantics Size-based termination Semantic Labelling The Model Construction Proving Termination

It fails in 2 different ways:

instantiation of variables in a context (λx : T.f x) t →β f t

labelling gives

(λx : T.f(

|x⊢x| ) x) t →β f( |t| ) t

And symmetrically:

substitution of a term into a context (λy : T.λx : U.y) (f t) →β λx : U.f t

labelling gives

(λy : T.λx : U.y) (f(

|t| ) t) →β λx : U.f( |x⊢t| ) t

slide-50
SLIDE 50

Algebraic semantics Size-based termination Semantic Labelling The Model Construction Proving Termination

To solve this failure we introduce two orders on labels:

( |x ⊢ t| ) >inst ( |t| )x→v

Which allows instantiation of free variables in labels and

( |t| ) >weak ( |x ⊢ t| )

which allows us to weaken the context of the labels. And allow decrease of the labels in rewriting: Struct = {fl → fl′ | l >inst,decr l′}

slide-51
SLIDE 51

Algebraic semantics Size-based termination Semantic Labelling The Model Construction Proving Termination

With the structural rules, we can “save” the result:

Theorem:

t→R∪βt′

t

φ→R∪β∪Decr

∗∪Struct ∗t′φ

slide-52
SLIDE 52

Algebraic semantics Size-based termination Semantic Labelling The Model Construction Proving Termination

However we loose termination, as Struct is non-terminating: If x is free in t, then

( |x ⊢ t| ) >inst ( |t| ) >weak ( |x ⊢ t| )

We can however express a relative termination result:

Corollary:

t is R ∪ β-normalizing

t

φ is Rβ-normalizing

relative to Decr ∪ Struct

slide-53
SLIDE 53

Algebraic semantics Size-based termination Semantic Labelling The Model Construction Proving Termination

Outline

Algebraic semantics Size-based termination Semantic Labelling The Model Construction Proving Termination

slide-54
SLIDE 54

Algebraic semantics Size-based termination Semantic Labelling The Model Construction Proving Termination

We want to build a set-theoretical model in which:

  • Abstractions are interpreted by functions.
  • There is a natural notion of size.
slide-55
SLIDE 55

Algebraic semantics Size-based termination Semantic Labelling The Model Construction Proving Termination

We proceed by cumulativity.

We mutually define:

  • elements of inductive types by tuples

( |c t1 . . . tn| )φ = (c, ( |t1| )φ, . . . , ( |tn| )φ)

  • elements of arrow types by functions

( |λx : T.t| )φ = v → ( |t| )φx

v

We need to find interpretations for base types.

slide-56
SLIDE 56

Algebraic semantics Size-based termination Semantic Labelling The Model Construction Proving Termination

Pure set theoretic extensions lead to very large sets!

Solution

Use realizable function spaces. We consider the interpretation:

[ [A → B] ] =

  • f ∈ [

[B] ][

[A] ] | ∃t, t f

  • with

t f ⇔ ∀u x, t u f(x)

slide-57
SLIDE 57

Algebraic semantics Size-based termination Semantic Labelling The Model Construction Proving Termination

Using this definition and the Tarski fixed-point theorem we can interpret types. There is a natural notion of size:

  • size((c, t1, . . . , tn)) = max(size(t1), . . . , size(tn)) + 1
  • size(f) = supx f(x)
slide-58
SLIDE 58

Algebraic semantics Size-based termination Semantic Labelling The Model Construction Proving Termination

The size types correspond to sizes in the model:

Γ ⊢size t : Ba ⇒ θ |= µ ⇒ size(( |t| )θ) ≤ ( |a| )µ

By well-founded induction on the sizes we can interpret defined functions fAlg(x1) . . . (xn) = (

|r| )θ

for f l → r ∈ R and (

|

  • l|

)θ =

  • x. We use the orthogonality restriction

here.

slide-59
SLIDE 59

Algebraic semantics Size-based termination Semantic Labelling The Model Construction Proving Termination

Using this construction we build a model Alg of the rewrite system. AlgT(Γ) = [

[Γ → T] ] = [ [T1] ] → . . . → [ [Tn] ] → [ [T] ]

subst(f, x1, . . . , xn) = v → f(x1(v)) . . . (xn(v)) etc.

Theorem:

Alg constitutes a R ∪ β-model.

slide-60
SLIDE 60

Algebraic semantics Size-based termination Semantic Labelling The Model Construction Proving Termination

Outline

Algebraic semantics Size-based termination Semantic Labelling The Model Construction Proving Termination

slide-61
SLIDE 61

Algebraic semantics Size-based termination Semantic Labelling The Model Construction Proving Termination

For the termination proof, we need a relative precedence termination criterion. We proceed in a similar manner to [Blanqui, 2003].

slide-62
SLIDE 62

Algebraic semantics Size-based termination Semantic Labelling The Model Construction Proving Termination

We consider a typed left-algebraic higher-order rewrite system R and a typed algebraic rewrite system S. The Criterion We suppose that

  • The positivity conditions are satisfied.
  • There is a well-founded precedence >prec on the function

symbols.

  • The rules in R respect the precedence:

∀f

l → r ∈ R, g ∈ r ⇒ f >prec g

  • The precedence is compatible with S.
slide-63
SLIDE 63

Algebraic semantics Size-based termination Semantic Labelling The Model Construction Proving Termination

Compatibility states: if f t1 . . . tn →S g u1 . . . um then

u is an S-permutation of t:

∀i∃j, tj →S ui

  • g is weaker for >prec than f:

∀h, g >prec h ⇒ f >prec h Theorem:

If R and S satisfy the criterion then

Γ ⊢ t : T ⇒

t ∈ SN

slide-64
SLIDE 64

Algebraic semantics Size-based termination Semantic Labelling The Model Construction Proving Termination

Define >decr on labels to be fl >decr fl′

l>Algl′ with x>Algy

size(x) > size(y) To show termination of the size-based system we take f >prec g

f>Struct ◦ >decrg It is easy to show compatibility.

slide-65
SLIDE 65

Algebraic semantics Size-based termination Semantic Labelling The Model Construction Proving Termination

Well-foundedness is more difficult: we may have

Γ1 ⊇ Γ2 ⊆ Γ3

x1

>prec

x2

>prec

x3 In particular lexicographic ordering on sizes and the size of contexts is insufficient. We use a lemma from Doornbos and Von Karger [Doornbos and Karger, 1998].

slide-66
SLIDE 66

Algebraic semantics Size-based termination Semantic Labelling The Model Construction Proving Termination

This method is generic: it can be used to prove different termination results, for example:

slide-67
SLIDE 67

Algebraic semantics Size-based termination Semantic Labelling The Model Construction Proving Termination

Theorem (Breazu-Tannen, Gallier & Okada)[Breazu-Tannen and Gallier, 1990, Okada, 1989]:

Let R be a first-order (uni-sorted) rewrite system that is SN. Then the system consisting of

  • A single base type D.
  • Curried typed rewrite rules: if f is of arity n then

f : D → . . . → D

  • n

→ D

and f(l1, . . . , ln) → r

f curry(l1) . . . curry(ln) → curry(r)

  • β-reduction

Is strongly normalizing on typed terms.

slide-68
SLIDE 68

The Type System Dependency Graph The Termination Criterion The Termination Semantics Perspectives

However this approach fails on certain simple rewrite systems. There is no model for which f (S x) → (λy : T.f y) x can be shown to be terminating in the labelling framework. We need to be capable of analyzing control flow.

slide-69
SLIDE 69

The Type System Dependency Graph The Termination Criterion The Termination Semantics Perspectives

To do this we go back to the types. We need a system capable of analyzing potential calls. In first-order rewriting, this is achieved using dependency pairs.

slide-70
SLIDE 70

The Type System Dependency Graph The Termination Criterion The Termination Semantics Perspectives

We wish to capture part of the analysis on the dependency graph using refinement types We restrict ourselves to the type of unlabeled binary trees.

The idea:

The refinement B(p) of the type B of trees is B(p) = {t ∈ B | t is of shape p} We perform analysis on the shapes.

slide-71
SLIDE 71

The Type System Dependency Graph The Termination Criterion The Termination Semantics Perspectives

Outline

The Type System Dependency Graph The Termination Criterion The Termination Semantics Perspectives

slide-72
SLIDE 72

The Type System Dependency Graph The Termination Criterion The Termination Semantics Perspectives

We give the following shapes or patterns:

  • The top pattern ⊤, which denotes any possible tree.
  • The leaf pattern which denotes leaves.
  • The node(p, q) pattern which denotes trees which are nodes

with left subtree of shape p and right subtree of shape q.

  • The bottom pattern ⊥ which denotes no possible tree.
  • Variables α which allow us to quantify over all patterns.
slide-73
SLIDE 73

The Type System Dependency Graph The Termination Criterion The Termination Semantics Perspectives

We can then describe our system. types: T, U ∈ T ≔ B(p) | ∀α.T | T → U terms: t, u ∈ Trm ≔ x | f | λx : T.t | λα.t | t u | t p | Leaf | Node Note that abstraction and application of patterns is explicit. Contrary to the previous approach, we only treat matching on non-defined terms, but with no orthogonality restriction.

slide-74
SLIDE 74

The Type System Dependency Graph The Termination Criterion The Termination Semantics Perspectives

We define a type system to assign types with patterns to terms.

Γ, x : T, Γ′ ⊢ x : T ax Γ, x : T ⊢ t : U Γ ⊢ λx : T.t : T → U t − lam Γ ⊢ Leaf: B(leaf)leaf − intro Γ ⊢ Node: ∀αβ.B(α) → B(β) → B(node(α, β))node − intro Γ ⊢ t : T Γ ⊢ λα.t : ∀α.T p − lam

with α free in Γ.

Γ ⊢ t : T → U Γ ⊢ u: T Γ ⊢ t u: U

t − app

Γ ⊢ t : ∀α.T Γ ⊢ t p : T{α → p}p − app Γ ⊢ f : τf

symb

slide-75
SLIDE 75

The Type System Dependency Graph The Termination Criterion The Termination Semantics Perspectives

This is insufficient in general to type interesting rewrite systems: rev Leaf

Leaf rev (Node x y)

Node (rev y) (rev x) The type of rev can only be ∀α.B(α) → B(⊤) and we need subtyping to derive Leaf: B(⊤) and Node (rev y) (rev x): B(⊤)

slide-76
SLIDE 76

The Type System Dependency Graph The Termination Criterion The Termination Semantics Perspectives

We introduce subtyping rules We define the sub-pattern relation ≪ by:

  • p ≪ p
  • p ≪ ⊤
  • ⊥ ≪ p
  • p1 ≪ q1 ∧ p2 ≪ q2 ⇒ node(p1, p2) ≪ node(q1, q2)

This leads to the following subtyping:

  • p≪q ⇒ B(p)≤B(q)
  • T2 ≤ T1 ∧ U1 ≤ U2 ⇒ T1 → U1 ≤ T2 → U2
  • T ≤ U ⇒ ∀α.T ≤ ∀α.U

Γ ⊢ t : T

T ≤ U

Γ ⊢ t : U

sub

slide-77
SLIDE 77

The Type System Dependency Graph The Termination Criterion The Termination Semantics Perspectives

Thanks to explicit annotations of pattern abstraction and application, all of our rules are syntax directed, except for the subtyping rules.

An alternate application rule: Γ ⊢ t : T → U Γ ⊢ u: T′

T′ ≤ T

Γ ⊢ t u: U

sub − app This rule replaces application and subtyping.

slide-78
SLIDE 78

The Type System Dependency Graph The Termination Criterion The Termination Semantics Perspectives

Using transitivity of subtyping we show that the new rules are equivalent to the old ones.

Theorem:

Type inference is decidable.

slide-79
SLIDE 79

The Type System Dependency Graph The Termination Criterion The Termination Semantics Perspectives

Outline

The Type System Dependency Graph The Termination Criterion The Termination Semantics Perspectives

slide-80
SLIDE 80

The Type System Dependency Graph The Termination Criterion The Termination Semantics Perspectives

We suppose that every rule can be well-typed in the framework and that:

  • Each symbol f has a number of recursive arguments of type B.
  • The type of f is of the form

f : ∀α1 . . . αn.B(α1) → . . . → B(αn) → Tf

  • the αi appear positively in Tf.
  • In each rule l → r, each symbol g ∈ r is fully applied to its type

arguments.

slide-81
SLIDE 81

The Type System Dependency Graph The Termination Criterion The Termination Semantics Perspectives

We wish to analyze the types involved in typing to build a type based dependency graph.

The dependency pairs:

For each rule f

α

l → r and each g ∈ r such that

  • Γ ⊢min li : B(pi)
  • g q1 . . . qn appears in r

We build the dependency pair f♯(p1, . . . , pn) → g♯(q1, . . . , qm)

slide-82
SLIDE 82

The Type System Dependency Graph The Termination Criterion The Termination Semantics Perspectives

We need to check possible successive calls by examination of the

  • pairs. To do this we define pattern unification ⊲⊳.
  • A variable α pattern-unifies with everything.
  • ⊤ pattern-unifies with everything.
  • ⊥ may unify with a variable, with ⊤ or itself
  • Similarly leaf unifies with a variable, ⊤ or leaf.
  • Same for node(p, q) which unifies with a variable, ⊤, or

node(p′, q′) iff p⊲⊳p′

q⊲⊳q′

We write:

f♯(p1, . . . , pn)⊲⊳f♯(q1, . . . , qn) if p1⊲⊳q1 ∧ . . . ∧ pn⊲⊳qn

slide-83
SLIDE 83

The Type System Dependency Graph The Termination Criterion The Termination Semantics Perspectives

The dependency graph has

  • as nodes the dependency pairs
  • an edge between l♯ → r♯ and l′♯ → r′♯ if

r♯ ⊲⊳ l′♯

slide-84
SLIDE 84

The Type System Dependency Graph The Termination Criterion The Termination Semantics Perspectives

We can also define a decrease ⊲ on patterns: The closure by context of node p, q⊲p and node p, q⊲q We carry this to dependency pairs: f(node(p, q)) →⊲ g(p)

slide-85
SLIDE 85

The Type System Dependency Graph The Termination Criterion The Termination Semantics Perspectives

Outline

The Type System Dependency Graph The Termination Criterion The Termination Semantics Perspectives

slide-86
SLIDE 86

The Type System Dependency Graph The Termination Criterion The Termination Semantics Perspectives

To show termination we observe the dependency graph:

i♯(node(α, β)) →⊲ i♯(α) i♯(node(α, β)) →⊲ i♯(β) f♯(node(α, β)) → g♯(node(α, β)) f♯(node(α, β)) → i♯(node(α, β)) g♯(node(α, β)) →⊲ f♯(α) g♯(node(α, β)) → i♯(node(α, β)) g♯(leaf) → f♯(⊥) g♯(leaf) → h♯(leaf) h♯(node(α, β)) →⊲ h♯(α)

slide-87
SLIDE 87

The Type System Dependency Graph The Termination Criterion The Termination Semantics Perspectives

We need to verify that each cycle contains only weak decreases (marked with ) and at least one strict decrease (marked with ⊲).

Theorem [Roux, 2011]:

If the above condition is satisfied, every well-typed term is strongly normalizing

slide-88
SLIDE 88

The Type System Dependency Graph The Termination Criterion The Termination Semantics Perspectives

Outline

The Type System Dependency Graph The Termination Criterion The Termination Semantics Perspectives

slide-89
SLIDE 89

The Type System Dependency Graph The Termination Criterion The Termination Semantics Perspectives

To prove termination, we modify the classic proof by candidates: we need to find an interpretation of the base types. In particular we need to instantiated pattern variables. We instantiate them with closed patterns.

slide-90
SLIDE 90

The Type System Dependency Graph The Termination Criterion The Termination Semantics Perspectives

The intuition:

[ [B(p)] ]θ = {t | tmatches p} Problem

If a non-confluent term Node (Node x y) z ← t → Node Leaf Leaf is in B(node(α, β)), then we would necessarily have α → ⊤. This is not sufficiently precise. We interpret pattern variables by sets of closed patterns.

slide-91
SLIDE 91

The Type System Dependency Graph The Termination Criterion The Termination Semantics Perspectives

If t is a term in SN and P is a set of closed patterns, we write t ↓≺

≺ P if

For each normal form u of t, there is some p ∈ P such that u matches p. We take θ to send variables to sets of closed patterns. We define

[ [B(p)] ]θ = {t ∈ SN | t ↓≺ ≺ pθ}

slide-92
SLIDE 92

The Type System Dependency Graph The Termination Criterion The Termination Semantics Perspectives

Then we carry out the classic construction

  • [

[A → B] ]θ = {t | ∀u ∈ [ [A] ]θ, t u ∈ [ [B] ]θ}

  • [

[∀α.A] ]θ = {t | ∀P, t ∈ [ [T] ]θα

P}

It works.

slide-93
SLIDE 93

The Type System Dependency Graph The Termination Criterion The Termination Semantics Perspectives

To show decrease in terms we need additional information.

Lemma:

If t = (Node l1 l2)σ, then every normal form of t is of the shape Node v1 v2 with v1 and v2 normal forms of l1σ and l2σ.

slide-94
SLIDE 94

The Type System Dependency Graph The Termination Criterion The Termination Semantics Perspectives

From this we get

  • if t = (Node l1 l2)σ
  • if for every θ

t ∈ [

[B(node(α, β))] ]θ ⇒

u ∈ [

[B(α)] ]θ

Then every normal form of u is smaller than some normal form of t.

slide-95
SLIDE 95

The Type System Dependency Graph The Termination Criterion The Termination Semantics Perspectives

Infinite sequences of calls: t1 → t2 → . . . therefore give rise to sequences of normal forms u1 u2 u3 v1 v2 v3

. . .

And we may conclude by König’s lemma.

slide-96
SLIDE 96

The Type System Dependency Graph The Termination Criterion The Termination Semantics Perspectives

Outline

The Type System Dependency Graph The Termination Criterion The Termination Semantics Perspectives

slide-97
SLIDE 97

The Type System Dependency Graph The Termination Criterion The Termination Semantics Perspectives

We have described two distinct extensions to the size-types approach to termination of higher-order rewrite systems. We would like a combination which

  • Has the power of the algebraic semantics.
  • Can capture the notions of control flow.

The Objective

Prove completeness of such a framework.

slide-98
SLIDE 98

The Type System Dependency Graph The Termination Criterion The Termination Semantics Perspectives

In addition, for both these frameworks, we can go up:

  • More expressive type theories.
  • Weaker conditions: relax orthogonality, matching on defined

constructors, higher-order inductive types.

slide-99
SLIDE 99

The Type System Dependency Graph The Termination Criterion The Termination Semantics Perspectives

A natural extension of the type-based dependency framework is to allow unions of base types: B(p1) ∪ . . . ∪ B(pn) and explore the possible lattices of types that can be authorized. We can also look at conversion at the type level: f : ∀α.B(α) → B(˜ f(α)),

˜

f(leaf)≃p,

˜

f(node(γ, δ))≃q and study the type annotations as a first order rewrite system. Look for type-level analogues of first-order techniques (interpretations, simplification orderings).

slide-100
SLIDE 100

The Type System Dependency Graph The Termination Criterion The Termination Semantics Perspectives

Thank you!

slide-101
SLIDE 101

The Type System Dependency Graph The Termination Criterion The Termination Semantics Perspectives

Baader, F. and Nipkow, T. (1998).

Term Rewriting and All That.

Cambridge University Press. Barthe, G., Frade, M. J., Giménez, E., Pinto, L. and Uustalu, T. (2004). Type-based termination of recursive definitions.

Mathematical Structures in Computer Science 14, 97–141.

Bezem, M., Klop, J. W. and de Vrijer, R., eds (2003).

Term Rewriting Systems.

Cambridge Tracts in Theoretical Computer Science, Cambridge University Press. Blanqui, F. (2003). Rewriting Modulo in Deduction Modulo. In RTA, (Nieuwenhuis, R., ed.), vol. 2706, of Lecture Notes in

Computer Science pp. 395–409, Springer.

Blanqui, F. (2004).

slide-102
SLIDE 102

The Type System Dependency Graph The Termination Criterion The Termination Semantics Perspectives

A type-based termination criterion for dependently-typed higher-order rewrite systems. In Proceedings of RTA’04, (van Oostrom, V., ed.), vol. 3091, pp. 24–39,. Blanqui, F. and Roux, C. (2009). On the Relation between Sized-Types Based Termination and Semantic Labelling. In CSL, (Grädel, E. and Kahle, R., eds), vol. 5771, of Lecture

Notes in Computer Science pp. 147–162, Springer.

Borovanský, P ., Kirchner, C., Kirchner, H., Moreau, P .-E. and Ringeissen, C. (1998). An Overview of ELAN. In Proc. of WRLA vol. 15, Electronic Notes in Theoretical Computer Science. Breazu-Tannen, V. and Gallier, J. (1990). Polymorphic rewriting conserves algebraic strong normalisation.

slide-103
SLIDE 103

The Type System Dependency Graph The Termination Criterion The Termination Semantics Perspectives

Theoretical Computer Science 83, 3–28.

Clavel, M., Eker, S., Lincoln, P . and Meseguer, J. (1996). Principles of Maude. In Proc. of WRLA vol. 4, Electronic Notes in Theoretical Computer Science. Cousineau, G., Curien, P .-L. and Mauny, M. (1985). The Categorical Abstract Machine. In FPCA pp. 50–64,. Dershowitz, N. and Jouannaud, J.-P . (1990). Rewrite Systems. In Handbook of Theoretical Computer Science, (Leeuwen, J. v., ed.), vol. B: Formal Models and Semantics, chapter 6, pp. 243–320. Doornbos, H. and Karger, B. V. (1998). On the Union of Well-Founded Relations. Fiore, M. P ., Plotkin, G. D. and Turi, D. (1999).

slide-104
SLIDE 104

The Type System Dependency Graph The Termination Criterion The Termination Semantics Perspectives

Abstract Syntax and Variable Binding. In LICS pp. 193–202,. Hamana, M. (2003). Term rewriting with variable binding: an initial algebra approach. In PPDP pp. 148–159, ACM. Hamana, M. (2007). Higher-Order Semantic Labelling for Inductive Datatype Systems. In Proceedings of the 9th ACM SIGPLAN International

Conference on Principles and Practice of Declarative Programming.

Hudak, P ., Peyton Jones, S., Wadler, P ., Arvind, B., Fairbairn,

  • B. J., Fasel, J., Guzmán, M., Hammond, K., Hughes, J.,

Johnsson, T., Kieburtz, R., Nikhil, R., Partain, W. and Peterson, J. (1992).

slide-105
SLIDE 105

The Type System Dependency Graph The Termination Criterion The Termination Semantics Perspectives

Report on the functional programming language Haskell, version 1.2.

Special Issue of SIGPLAN Notices 27.

Jouannaud, J.-P . (1993). Introduction to Rewriting. In Term rewriting, (Comon, H. and Jouannaud, J.-P ., eds), vol. 909, pp. 1–15,. Jouannaud, J.-P . and Okada, M. (1991). Executable higher-order algebraic specification languages. In Proceedings of LICS’91 pp. 350–361, IEEE Computer Society Press. Milner, R., Tofte, M., Harper, R. and MacQueen, D. (1997).

The Definition of Standard ML (Revised).

The MIT Press. Okada, M. (1989). Strong normalizability for the combined system of the typed

λ-calculus and an arbitrary convergent term rewrite system.

slide-106
SLIDE 106

The Type System Dependency Graph The Termination Criterion The Termination Semantics Perspectives

In Proc. of ISSAC pp. 357–363, ACM Press. Roux, C. (2011). Refinement Types as Higher-Order Dependency Pairs. In 22nd International Conference on Rewriting Techniques and

Applications (RTA’11), (Schmidt-Schau¨

s, M., ed.), vol. 10, of

Leibniz International Proceedings in Informatics (LIPIcs) pp.

299–312, Schloss Dagstuhl–Leibniz-Zentrum fuer Informatik, Dagstuhl, Germany. Zantema, H. (1995). Termination of Term Rewriting by Semantic Labelling.

Fundamenta Informaticae 24, 89–105.