Program Analysis Seminar The Dependency Pair Technique Proving Termination of Term Rewrite Systems Hannes Saffrich University of Freiburg Department of Computer Science June 30, 2015 Hannes Saffrich The Dependency Pair Technique Program Analysis Seminar 1 / 23
Introduction ◮ Term Rewrite Systems (TRSs) are a turing complete formalism for modeling both programs and programming languages ◮ Proving the termination of a TRS corresponds either ◮ to proving termination of a particular program, or ◮ to proving termination of all programs in a programming language ◮ Unfortunately, proving termination of arbitrary TRSs is undecidable (Halting Problem) ◮ The Dependency Pair Technique describes an algorithm which for a given TRS either ◮ constructs a proof of termination, or ◮ constructs a proof of non-termination, or ◮ gives up ◮ It can be extended to incorporate other termination analyses. Hannes Saffrich The Dependency Pair Technique Program Analysis Seminar 2 / 23
Overview ◮ Part I: Term Rewrite Systems ◮ Formal definition ◮ Termination property ◮ Example ◮ Part II: The Dependency Pair Technique ◮ Alternative Termination Property ◮ Proving this property automatically ◮ Covering Section 1 and 2 of the original paper. ◮ Part III: Summary Hannes Saffrich The Dependency Pair Technique Program Analysis Seminar 3 / 23
Part I Term Rewrite Systems Hannes Saffrich The Dependency Pair Technique Program Analysis Seminar 4 / 23
Term Rewrite Systems Introduction ◮ Term Rewrite System (TRS) T consists of ◮ a set of terms T ◮ a binary relation between terms − →⊆ T × T ◮ t 1 − → t 2 iff t 1 is rewritten to t 2 by 1 computation step, i.e. 1 + (2 + 3) − → 1 + 5 1 + 5 − → 6 → ∗ t 2 iff t 1 is rewritten to t 2 by n computation steps, i.e. ◮ t 1 − → ∗ 6 → ∗ 6 1 + (2 + 3) − 6 − ◮ T is non-terminating for t 1 iff t 1 can be rewritten infinitely often → ∗ t 2 = ∀ t 2 . ( t 1 − ⇒ ∃ t 3 . t 2 − → t 3 ) ◮ T is terminating iff it contains no non-terminating term. Hannes Saffrich The Dependency Pair Technique Program Analysis Seminar 5 / 23
Term Rewrite Systems Terms ◮ The terms T of a TRS are trees build from ◮ a set of function symbols F ◮ a set of variables V ◮ Example: Arithmetic on Natural Numbers ◮ F = + 2 , · 2 , s 1 , 0 0 � � + ◮ V = { x , y , z , . . . } s · ◮ Arity fixes number of sub-terms (function arguments) 0 x 0 ◮ String notation: +(s(0) , · ( x , 0)) Hannes Saffrich The Dependency Pair Technique Program Analysis Seminar 6 / 23
Term Rewrite Systems Substitution ◮ A substitution σ : V → T maps variables to terms ◮ We write { x �→ t } for the substitution � t if x = y { x �→ t } ( y ) = otherwise y ◮ We write σ [ t ] for substituting all variables in term t by σ ◮ i.e. for σ = { x �→ 0 , y �→ · ( x , z ) } it holds that + + y = · x 0 σ x z Hannes Saffrich The Dependency Pair Technique Program Analysis Seminar 7 / 23
Term Rewrite Systems Semantics ◮ Rewrite relation − →⊆ T × T R ◮ Derived from a set of rewrite rules t 1 − → t 2 ∈ T × T ◮ Example: Arithmetic on Natural Numbers R R − → y − → s(+( x , y )) +(0 , y ) +(s( x ) , y ) ( Base +) ( Rec +) R R · (0 , y ) − → 0 · (s( x ) , y ) − → +( · ( x , y ) , y ) ( Base · ) ( Rec · ) ◮ Closed under substitutions ◮ if t 1 − → t 2 then ∀ σ. σ [ t 1 ] − → σ [ t 2 ], i.e. ◮ if +(0 , y ) − → y then +(0 , · (0 , 0)) − → · (0 , 0) ◮ Closed under contexts ◮ if t 1 − → t 2 then { x �→ t 1 } [ t ] − → { x �→ t 2 } [ t ], i.e. ◮ if + (0 , y ) − → y then s( + (0 , y )) − → s( y ) Hannes Saffrich The Dependency Pair Technique Program Analysis Seminar 8 / 23
Term Rewrite Systems Symbol Classification ◮ The outermost symbol of a term is called its root symbol . ◮ Root symbols of a rewrite rule’s left side are called defined . ◮ In our example those are Def R = { + , ·} ◮ Defined symbols represent functions, because terms having them as root symbol may be reduced by the rewriting relation. ◮ Symbols which are not defined, are called constructors . ◮ Constructors represent values of recursive datatypes. ◮ In our example those are Cons R = { 0 , s } and we use them to build terms representing arbitrary natural numbers, i.e. s(s(0)) for 2. ◮ The rewrite rules define the functions of the defined function symbols by pattern matching on constructors. R R +(0 , y ) − → y +(s( x ) , y ) − → s(+( x , y )) ( Base +) ( Rec +) R R · (0 , y ) − → 0 · (s( x ) , y ) − → +( · ( x , y ) , y ) ( Base · ) ( Rec · ) Hannes Saffrich The Dependency Pair Technique Program Analysis Seminar 9 / 23
Part II The Dependency Pair Technique Hannes Saffrich The Dependency Pair Technique Program Analysis Seminar 10 / 23
Dependency Pair Technique Termination revisited ◮ A term is barely non-terminating iff it is non-terminating, but all its subterms are terminating ◮ A non-terminating term t has a barely non-terminating subterm u ◮ start with u := t ◮ either all subterms of u are terminating ◮ or we can choose a non-terminating subterm as new u R ◮ When rewriting u , eventually a rule l − → r rewrites the whole term → ∗ u = f ( u 1 , . . . , u n ) − s f ( v 1 , . . . , v n ) = σ [ l ] − → σ [ r ] ◮ σ [ r ] is reached in a finite amount of steps, hence ◮ σ [ r ] is non-terminating and we can repeat this infinitely often Hannes Saffrich The Dependency Pair Technique Program Analysis Seminar 11 / 23
Dependency Pair Technique Dependency Pairs & Chains → ∗ t ⊒ f ( u 1 , . . . , u n ) − s f ( v 1 , . . . , v n ) = σ [ l ] − → σ [ r ] ⊒ f ′ ( u ′ 1 , . . . , u ′ n ) − → ∗ s . . . R ◮ A dependency pair combines the top-level rule l − → r with the subsequent choice of the barely non-terminating subterm of σ [ r ]. ◮ The dependency pairs of a TRS T are � DP → r ′ � R � → r ∈ T , r ⊒ r ′ , root ( r ′ ) ∈ Def R DP( T ) = − − l � l � DP DP ◮ A chain is a sequence of dependency pairs l 1 − → r 1 , l 2 − → r 2 , . . . , such that ∀ i . ∃ σ. σ [ r i ] − → ∗ s σ [ l i +1 ]. ◮ A TRS terminates if it has no infinite chains. Hannes Saffrich The Dependency Pair Technique Program Analysis Seminar 12 / 23
Dependency Pair Technique Dependency Pairs & Chains ◮ Example: Arithmetic on Natural Numbers R R +(0 , y ) − → y ( Base +) +(s( x ) , y ) − → s(+( x , y )) ( Rec +) R R · (0 , y ) − → 0 · (s( x ) , y ) − → +( · ( x , y ) , y ) ( Base · ) ( Rec · ) ◮ The dependency pairs for this TRS are DP DP DP +(s( x ) , y ) − → +( x , y ) · (s( x ) , y ) − → · ( x , y ) · (s( x ) , y ) − → +( · ( x , y ) , y ) ◮ Repeating the first rule 2 times is a finite chain DP DP +(s( x ) , y ) − → + ( x , y ) , +(s( x ) , y ) − → +( x , y ) because for σ 1 = { x �→ s(0) , y �→ 0 } and σ 2 = { x �→ 0 , y �→ 0 } +(s(s(0)) , 0) − → + (s(0) , 0) − → ∗ +(s(0) , 0) − → +(0 , 0) s Hannes Saffrich The Dependency Pair Technique Program Analysis Seminar 13 / 23
Dependency Pair Technique Dependency Problems ◮ A dependency problem P = �T , D � consists of ◮ a TRS T ◮ a set of dependency pairs D ◮ P is solved by proving the absence or existence of infinite chains of D in T . ◮ Solving �T , DP( T ) � answers whether T is terminating ◮ Basic idea of the dependency pair technique ◮ split dependency problems into smaller dependency problems ◮ such that solving the smaller problems solves the original problem Hannes Saffrich The Dependency Pair Technique Program Analysis Seminar 14 / 23
Dependency Pair Technique Overview TRS T ◮ Given TRS T ◮ Calculate DP( T ) Dependency Pairs DP( T ) ◮ Start with problem �T , DP( T ) � Dependency Problem �T , DP( T ) � ◮ Split with dependency processors ◮ Repeat until solved or timeout �T , DP 1 � �T , DP 2 � �T , DP 3 � ◮ DP i = ∅ → no chains → terminates �T , ∅� no �T , DP 4 � ◮ Dependency processors as extension . yes . mechanism . Hannes Saffrich The Dependency Pair Technique Program Analysis Seminar 15 / 23
Dependency Pair Technique Dependency Graph Processor ◮ Input: dependency problem �T , DP � ◮ Approximates a dependency graph G ◮ Nodes are dependency pairs DP ◮ Edge from p 1 to p 2 iff p 1 , p 2 is a chain of DP in T ◮ Output: {T } × SCCs( G ) ◮ Solving output problems solves input problem ◮ DP finite, but infinite chains are infinite ◮ Dependency pairs have to repeat ◮ G captures potential repeating by edges ◮ Any infinite chain has at least one infinite sub-chain containing only the dependency pairs of a single SCC of G ◮ Focusing on that SCC, still allows to find this infinite sub-chain ◮ Covering all SCCs covers all infinite chains Hannes Saffrich The Dependency Pair Technique Program Analysis Seminar 16 / 23
Recommend
More recommend