The Dependency Pair Technique Proving Termination of Term Rewrite - - PowerPoint PPT Presentation

the dependency pair technique
SMART_READER_LITE
LIVE PREVIEW

The Dependency Pair Technique Proving Termination of Term Rewrite - - PowerPoint PPT Presentation

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


slide-1
SLIDE 1

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

slide-2
SLIDE 2

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

slide-3
SLIDE 3

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

slide-4
SLIDE 4

Part I

Term Rewrite Systems

Hannes Saffrich The Dependency Pair Technique Program Analysis Seminar 4 / 23

slide-5
SLIDE 5

Term Rewrite Systems

Introduction

◮ Term Rewrite System (TRS) T consists of

◮ a set of terms T ◮ a binary relation between terms −

→⊆ T × T

◮ t1 −

→ t2 iff t1 is rewritten to t2 by 1 computation step, i.e. 1 + (2 + 3) − → 1 + 5 1 + 5 − → 6

◮ t1 −

→∗ t2 iff t1 is rewritten to t2 by n computation steps, i.e. 1 + (2 + 3) − →∗ 6 6 − →∗ 6

◮ T is non-terminating for t1 iff t1 can be rewritten infinitely often

∀t2. (t1 − →∗ t2 = ⇒ ∃t3. t2 − → t3)

◮ T is terminating iff it contains no non-terminating term.

Hannes Saffrich The Dependency Pair Technique Program Analysis Seminar 5 / 23

slide-6
SLIDE 6

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, s1, 00

◮ V = {x, y, z, . . .} ◮ Arity fixes number of sub-terms

(function arguments)

◮ String notation: +(s(0), ·(x, 0))

+ s · x

Hannes Saffrich The Dependency Pair Technique Program Analysis Seminar 6 / 23

slide-7
SLIDE 7

Term Rewrite Systems

Substitution

◮ A substitution σ : V → T maps variables to terms ◮ We write {x → t} for the substitution

{x → t} (y) =

  • t

if x = y y

  • therwise

◮ We write σ [t] for substituting all variables in term t by σ ◮ i.e. for σ = {x → 0, y → ·(x, z)} it holds that

σ

     

+ x y

     

=

+ · x z

Hannes Saffrich The Dependency Pair Technique Program Analysis Seminar 7 / 23

slide-8
SLIDE 8

Term Rewrite Systems

Semantics

◮ Rewrite relation −

→⊆ T × T

◮ Derived from a set of rewrite rules t1 R

− → t2 ∈ T × T

◮ Example: Arithmetic on Natural Numbers

+(0, y)

R

− → y

(Base+)

·(0, y)

R

− → 0

(Base·)

+(s(x), y)

R

− → s(+(x, y))

(Rec+)

·(s(x), y)

R

− → +(·(x, y), y)

(Rec·) ◮ Closed under substitutions

◮ if t1 −

→ t2 then ∀σ. σ [t1] − → σ [t2], i.e.

◮ if +(0, y) −

→ y then +(0, · (0, 0)) − → · (0, 0)

◮ Closed under contexts

◮ if t1 −

→ t2 then {x → t1} [t] − → {x → t2} [t], i.e.

◮ if + (0, y) −

→ y then s( + (0, y)) − → s(y)

Hannes Saffrich The Dependency Pair Technique Program Analysis Seminar 8 / 23

slide-9
SLIDE 9

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 DefR = {+, ·} ◮ 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 ConsR = {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. +(0, y)

R

− → y

(Base+)

·(0, y)

R

− → 0

(Base·)

+(s(x), y)

R

− → s(+(x, y))

(Rec+)

·(s(x), y)

R

− → +(·(x, y), y)

(Rec·)

Hannes Saffrich The Dependency Pair Technique Program Analysis Seminar 9 / 23

slide-10
SLIDE 10

Part II

The Dependency Pair Technique

Hannes Saffrich The Dependency Pair Technique Program Analysis Seminar 10 / 23

slide-11
SLIDE 11

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

◮ When rewriting u, eventually a rule l R

− → r rewrites the whole term u = f (u1, . . . , un) − →∗

s f (v1, . . . , vn) = σ [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

slide-12
SLIDE 12

Dependency Pair Technique

Dependency Pairs & Chains

t ⊒ f (u1, . . . , un) − →∗

s f (v1, . . . , vn) = σ [l] −

→ σ [r] ⊒ f ′(u′1, . . . , u′n) − →∗

s . . . ◮ A dependency pair combines the top-level rule l R

− → r with the subsequent choice of the barely non-terminating subterm of σ [r].

◮ The dependency pairs of a TRS T are

DP(T ) =

  • l

DP

− → r ′

  • l

R

− → r ∈ T , r ⊒ r ′, root(r ′) ∈ DefR

  • ◮ A chain is a sequence of dependency pairs l1

DP

− → r1, l2

DP

− → r2, . . ., such that ∀i. ∃σ. σ [ri] − →∗

s σ [li+1]. ◮ A TRS terminates if it has no infinite chains.

Hannes Saffrich The Dependency Pair Technique Program Analysis Seminar 12 / 23

slide-13
SLIDE 13

Dependency Pair Technique

Dependency Pairs & Chains

◮ Example: Arithmetic on Natural Numbers

+(0, y)

R

− → y

(Base+)

·(0, y)

R

− → 0

(Base·)

+(s(x), y)

R

− → s(+(x, y))

(Rec+)

·(s(x), y)

R

− → +(·(x, y), y)

(Rec·) ◮ The dependency pairs for this TRS are

+(s(x), y)

DP

− → +(x, y) ·(s(x), y)

DP

− → ·(x, y) ·(s(x), y)

DP

− → +(·(x, y), y)

◮ Repeating the first rule 2 times is a finite chain

+(s(x), y)

DP

− → + (x, y) , +(s(x), y)

DP

− → +(x, y)

because for σ1 = {x → s(0), y → 0} and σ2 = {x → 0, y → 0}

+(s(s(0)), 0) − → + (s(0), 0) − →∗

s

+(s(0), 0) − → +(0, 0)

Hannes Saffrich The Dependency Pair Technique Program Analysis Seminar 13 / 23

slide-14
SLIDE 14

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

slide-15
SLIDE 15

Dependency Pair Technique

Overview TRS T Dependency Pairs DP(T ) Dependency Problem T , DP(T ) T , DP1 T , DP2 T , DP3 T , ∅ yes no T , DP4 . . .

◮ Given TRS T ◮ Calculate DP(T ) ◮ Start with problem T , DP(T ) ◮ Split with dependency processors ◮ Repeat until solved or timeout ◮ DPi = ∅ → no chains → terminates ◮ Dependency processors as extension

mechanism

Hannes Saffrich The Dependency Pair Technique Program Analysis Seminar 15 / 23

slide-16
SLIDE 16

Dependency Pair Technique

Dependency Graph Processor

◮ Input: dependency problem T , DP ◮ Approximates a dependency graph G

◮ Nodes are dependency pairs DP ◮ Edge from p1 to p2 iff p1, p2 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

slide-17
SLIDE 17

Dependency Pair Technique

Dependency Graph Processor

◮ Dependency pairs in T , DP(T ) for our example

+(s(x), y)

DP

− → +(x, y) ·(s(x), y)

DP

− → ·(x, y) ·(s(x), y)

DP

− → +(·(x, y), y)

◮ Dependency graph for our example

·(s(x), y) DP − → ·(x, y) ·(s(x), y) DP − → +(·(x, y), y) +(s(x), y) DP − → +(x, y)

◮ 2 output problems

  • T ,
  • ·(s(x), y) DP

− → ·(x, y)

  • T ,
  • +(s(x), y) DP

− → +(x, y)

  • Hannes Saffrich

The Dependency Pair Technique Program Analysis Seminar 17 / 23

slide-18
SLIDE 18

Dependency Pair Technique

Reduction Pair Processor

◮ Idea: well-founded order ≻ on terms implies termination ◮ Forall t1 exist only finitely many t2 with t1 ≻ t2 ◮ If for any rule l R

− → r it holds that l ≻ r and ≻ is closed under substitution and contexts, then all terms are terminating

◮ If each rewriting makes the term smaller and there are only a finite

amount of smaller terms, we can only finitely often rewrite.

Hannes Saffrich The Dependency Pair Technique Program Analysis Seminar 18 / 23

slide-19
SLIDE 19

Dependency Pair Technique

Reduction Pair Processor

◮ We can do better! ◮ We want to show that there is no infinite chain for a DP problem

◮ no infinite sequence l1

DP

− → r1, l2

DP

− → r2, . . . with ∀i. ∃σ. σ [ri] − →∗

s σ [li+1].

◮ Only the dependency pairs have to make the terms smaller wrt. ≻ ◮ For TRS rules it suffices to not make the terms bigger, as

σ [ri] − →∗

s σ [li+1] terminates anyway. ◮ Hence, for the absence of infinite chains, it suffices to show

◮ l ≻ r for all dependency pairs l

DP

− → r

◮ l r for all TRS rules l

R

− → r

Hannes Saffrich The Dependency Pair Technique Program Analysis Seminar 19 / 23

slide-20
SLIDE 20

Dependency Pair Technique

Reduction Pair Processor

◮ In our example we have two dependency problems left

  • T ,
  • ·(s(x), y) DP

− → ·(x, y)

  • T ,
  • +(s(x), y) DP

− → +(x, y)

  • ◮ We have to find an order ≻i each, satisfying the following constraints

+(s(x), y) ≻1 +(x, y) +(0, y) i y ·(0, y) i 0 ·(s(x), y) ≻2 ·(x, y) +(s(x), y) i s(+(x, y)) ·(s(x), y) i +(·(x, y), y)

◮ The lexicographic order with 0 < s < + < ·

◮ is well-founded ◮ satisfies the constraints for i ∈ {1, 2} Hannes Saffrich The Dependency Pair Technique Program Analysis Seminar 20 / 23

slide-21
SLIDE 21

Part III

Summary

Hannes Saffrich The Dependency Pair Technique Program Analysis Seminar 21 / 23

slide-22
SLIDE 22

Summary

◮ Proving termination is undecidable ◮ The dependency pair technique can decide some instances ◮ This is achieved by identifying infinite chains ◮ Dependency problems restrict the scope in which to identify those

chains

◮ Dependency problems are split by dependency processors ◮ This allows for integrating other termination analyses ◮ Further information in the original paper

Giesl, Thiemann, Falke. Mechanizing and Improving Dependency Pairs. Journal of Automated Reasoning, Vol 37, 2006

Hannes Saffrich The Dependency Pair Technique Program Analysis Seminar 22 / 23

slide-23
SLIDE 23

The End

Thanks for your attention! Questions? Giesl, Thiemann, Falke. Mechanizing and Improving Dependency Pairs. Journal of Automated Reasoning, Vol 37, 2006

Hannes Saffrich The Dependency Pair Technique Program Analysis Seminar 23 / 23