size based termination semantics and generalizations
play

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:


  1. 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 app Γ ⊢ size t u : U Γ , x : T ∞ ⊢ size t : U Γ ⊢ size λ x : | T | . t : T → U abs Γ ⊢ size t : T T ≤ U sub Γ ⊢ size t : U

  2. Algebraic semantics Size-based termination Semantic Labelling The Model Construction Proving Termination The criterion then requires (among other things) that each rule f l 1 . . . l n → r if Γ ⊢ size l i : B a i then Γ ⊢ � a size r : T where ⊢ � a size constrains recursive calls on f to smaller arguments.

  3. 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.

  4. Algebraic semantics Size-based termination Semantic Labelling The Model Construction Proving Termination Our approach: Rewrite System Algebraic Semantics Translated System Generic Termination Proof

  5. 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

  6. 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].

  7. Algebraic semantics Size-based termination Semantic Labelling The Model Construction Proving Termination The idea: • Select a model M R of the rewrite system R , with interpretation ( | _ | ) M . • In each rule l → r ∈ R , we replace each f ( t 1 , . . . , t n ) ∈ l , r with f (( )) ( t 1 , . . . , t n ) | t 1 | ) ,..., ( | t n | recursively. • Show that normalization of the new system is equivalent to that of the original system.

  8. 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.

  9. 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!

  10. 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 • λ x : T . t x φ = f ( φ , . . . , t n φ ) • f ( t 1 , . . . , t n ) ) φ ( t 1 | � t | 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.

  11. Algebraic semantics Size-based termination Semantic Labelling The Model Construction Proving Termination In the curried framework: f ( t 1 , t 2 , . . . , t n ) is represented by ( . . . (( f t 1 ) t 2 ) . . . t n ) The labelling of this last term is φ . . . t n φ f () t 1 There is no meaningful label for f as it takes no arguments!

  12. Algebraic semantics Size-based termination Semantic Labelling The Model Construction Proving Termination Our solution: non structural labelling: φ = f ( φ . . . t n φ f t 1 . . . t n ) φ t 1 | � t | f may be applied to less than n arguments. φ = f (( φ )) � f t 1 . . . t k t ) φ ,..., ( ) , ( | ? | | t 1 | | t k |

  13. 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 (( φ ) φ ′ ) � f t 1 . . . t k t ) φ ′ ,..., ( ) φ ′ , ( ) φ ′ ,..., ( | t 1 | | t k | | x 1 | | x n − k | with φ ′ = φ x 1 ... x n − k x 1 ... x n − k

  14. 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: φ → R t ′ φ t → R t ′ ⇔ ∀ φ, t if we are working with a model and φ → R∪ Decr ∗ t ′ φ t → R t ′ ⇔ ∀ φ, t if we are working with a premodel, with Decr = { f l → f l ′ | l ≥ M ∗ l ′ }

  15. 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.

  16. 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 ) t �→ β f ( ) t | x ⊢ x | | 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 ) �→ β λ x : U . f ( ) t | t | | x ⊢ t |

  17. 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 = { f l → f l ′ | l > inst , decr l ′ }

  18. Algebraic semantics Size-based termination Semantic Labelling The Model Construction Proving Termination With the structural rules, we can “save” the result: Theorem: φ → R∪ β ∪ Decr ∗ t ′ φ t → R∪ β t ′ ⇔ t ∗ ∪ Struct

  19. 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 ( ) > inst ( ) > weak ( ) | x ⊢ t | | t | | x ⊢ t | We can however express a relative termination result: Corollary: φ is R β -normalizing t is R ∪ β -normalizing ⇔ t relative to Decr ∪ Struct

  20. 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

  21. 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.

  22. 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 t 1 . . . t n | ) φ = ( c , ( ) φ , . . . , ( ) φ ) | t 1 | | t n | • elements of arrow types by functions ( | λ x : T . t | ) φ = v �→ ( ) φ x | t | v We need to find interpretations for base types.

  23. 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: � � ] | ∃ t , t � f ] [ [ A ] [ [ A → B ] ] = f ∈ [ [ B ] with t � f ⇔ ∀ u � x , t u � f ( x )

  24. 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 , t 1 , . . . , t n )) = max ( size ( t 1 ) , . . . , size ( t n )) + 1 • size ( f ) = sup x f ( x )

  25. Algebraic semantics Size-based termination Semantic Labelling The Model Construction Proving Termination The size types correspond to sizes in the model: Γ ⊢ size t : B a ⇒ θ | = µ ⇒ size (( | t | ) θ ) ≤ ( | a | ) µ By well-founded induction on the sizes we can interpret defined functions f Alg ( x 1 ) . . . ( x n ) = ( | r | ) θ for f � � ) θ = � l → r ∈ R and ( | l | x . We use the orthogonality restriction here.

  26. Algebraic semantics Size-based termination Semantic Labelling The Model Construction Proving Termination Using this construction we build a model Alg of the rewrite system. ] → . . . → [ Alg T (Γ) = [ [Γ → T ] ] = [ [ T 1 ] [ T n ] ] → [ [ T ] ] subst ( f , x 1 , . . . , x n ) = v �→ f ( x 1 ( v )) . . . ( x n ( v )) etc. Theorem: Alg constitutes a R ∪ β -model.

  27. 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

  28. 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].

  29. 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 .

  30. Algebraic semantics Size-based termination Semantic Labelling The Model Construction Proving Termination Compatibility states: if f t 1 . . . t n → S g u 1 . . . u m then u is an S -permutation of � • � t : ∀ i ∃ j , t j → S u i • 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

  31. Algebraic semantics Size-based termination Semantic Labelling The Model Construction Proving Termination Define > decr on labels to be l > Alg l ′ f l > decr f l ′ ⇔ with x > Alg y ⇔ size ( x ) > size ( y ) To show termination of the size-based system we take f > prec g ⇔ f > Struct ◦ > decr g It is easy to show compatibility.

  32. Algebraic semantics Size-based termination Semantic Labelling The Model Construction Proving Termination Well-foundedness is more difficult: we may have Γ 1 Γ 2 Γ 3 ⊇ ⊆ x 1 > prec x 2 > prec x 3 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].

  33. 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:

  34. 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 → D � ����������� �� ����������� � n and f ( l 1 , . . . , l n ) → r f curry ( l 1 ) . . . curry ( l n ) → curry ( r ) �→ • β -reduction Is strongly normalizing on typed terms.

  35. 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.

  36. 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.

  37. 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.

  38. 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

  39. 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.

  40. 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 ∈ T rm ≔ 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.

  41. 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 − app Γ ⊢ t u : U Γ ⊢ t : ∀ α. T Γ ⊢ t p : T { α �→ p } p − app symb Γ ⊢ f : τ f

  42. 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 ( ⊤ )

  43. 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 • p 1 ≪ q 1 ∧ p 2 ≪ q 2 ⇒ node ( p 1 , p 2 ) ≪ node ( q 1 , q 2 ) This leads to the following subtyping: • p ≪ q ⇒ B ( p ) ≤ B ( q ) • T 2 ≤ T 1 ∧ U 1 ≤ U 2 ⇒ T 1 → U 1 ≤ T 2 → U 2 • T ≤ U ⇒ ∀ α. T ≤ ∀ α. U Γ ⊢ t : T T ≤ U sub Γ ⊢ t : U

  44. 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 : T ′ Γ ⊢ t : T → U sub − app Γ ⊢ t u : U This rule replaces application and subtyping.

  45. 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.

  46. 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

  47. 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 ) → T f • the α i appear positively in T f . • In each rule l → r , each symbol g ∈ r is fully applied to its type arguments.

  48. 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 l i : B ( p i ) • g q 1 . . . q n appears in r We build the dependency pair f ♯ ( p 1 , . . . , p n ) → g ♯ ( q 1 , . . . , q m )

  49. 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 ♯ ( p 1 , . . . , p n ) ⊲⊳ f ♯ ( q 1 , . . . , q n ) if p 1 ⊲⊳ q 1 ∧ . . . ∧ p n ⊲⊳ q n

  50. 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 ′ ♯

  51. 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 )

  52. 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

  53. The Type System Dependency Graph The Termination Criterion The Termination Semantics Perspectives To show termination we observe the dependency graph: i ♯ ( node ( α, β )) → ⊲ i ♯ ( α ) f ♯ ( node ( α, β )) → � g ♯ ( node ( α, β )) g ♯ ( node ( α, β )) → ⊲ f ♯ ( α ) i ♯ ( node ( α, β )) → ⊲ i ♯ ( β ) f ♯ ( node ( α, β )) → � i ♯ ( node ( α, β )) g ♯ ( node ( α, β )) → � i ♯ ( node ( α, β )) g ♯ ( leaf ) → f ♯ ( ⊥ ) g ♯ ( leaf ) → h ♯ ( leaf ) h ♯ ( node ( α, β )) → ⊲ h ♯ ( α )

  54. 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

  55. 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

  56. 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.

  57. The Type System Dependency Graph The Termination Criterion The Termination Semantics Perspectives The intuition: [ [ B ( p )] ] θ = { t | t matches 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.

  58. 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 θ }

  59. 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.

  60. 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 l 1 l 2 ) σ , then every normal form of t is of the shape Node v 1 v 2 with v 1 and v 2 normal forms of l 1 σ and l 2 σ .

  61. The Type System Dependency Graph The Termination Criterion The Termination Semantics Perspectives From this we get • if t = ( Node l 1 l 2 ) σ • if for every θ t ∈ [ [ B ( node ( α, β ))] ] θ ⇒ u ∈ [ [ B ( α )] ] θ Then every normal form of u is smaller than some normal form of t .

  62. The Type System Dependency Graph The Termination Criterion The Termination Semantics Perspectives Infinite sequences of calls: t 1 → t 2 → . . . therefore give rise to sequences of normal forms u 1 v 1 . . . u 2 v 2 u 3 v 3 And we may conclude by König’s lemma.

  63. 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

  64. 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.

  65. 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.

  66. 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 ( p 1 ) ∪ . . . ∪ B ( p n ) 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).

  67. The Type System Dependency Graph The Termination Criterion The Termination Semantics Perspectives Thank you!

Recommend


More recommend