Try โ€‚โ€‰HackMD

Abstract Reduction Systems 3: Termination

Proving termination is of practicial significance to the programmer. Windows was known for crashing so often that serious programmers or computer scientists would not touch it. One of the reasons was that device drivers would go into an infinite loop. This problem has been sorted out thanks to formal methods that could automatically detect such problems.

Think of a while loop? How do you know that it terminates? Or maybe it doesnt? โ€ฆ The technique that we learn now in order to show termination of ARSs will also apply to showing termination of loops in general.

The basic idea to prove termination of an ARS

(A,โ†’) is:

Find a measure function

ฯ•:Aโ†’N such that
aโ†’b
implies
ฯ•(a)>ฯ•(b)
.

Why does this prove termination?

Recall our examples, listed for convenience again below.

Examples:

  • A is the set of integers
    >1
    and
    mโ†’n
    is defined to hold if
    m>n
    and
    n
    divides
    m
    .

  • A is the set of finite lists (aka words) over

    {a,b},
    wbavโ†’wabv

    • maybe first sth easier:

    • what if we have only one rule allowing to rewrite

      abbโ†’aa in every word?[1]

    • or what if have only one rule allowing to rewrite

      aโ†’b in every word?[2]

    • or what if you have both rules above?[3]

    • what now about the first question where we have one rule allowint to rewrite

      baโ†’ab? [4]

  • A is the set of multisets over

    {a,b},
    aaโ†’a
    ,
    bbโ†’a
    ,
    abโ†’b
    ,
    baโ†’b

  • Langton's Ant is an example of an interesting ARS that is not termintating. But it nevertheless reaches some kind of stability that, even though not a normal form in the technical sense, has some resemblance with it. A point worth thinking about.

Def: Let

(A,โ†’) be an ARS. The function
ฯ•:Aโ†’N
is called a measure function if
aโ†’b
implies
ฯ•(a)>ฯ•(b)
.

Fact: If an ARS has a measure function, then it is terminating.

We have seen examples of how to use measure functions to prove termination.

What about the converse? Can we always find a measure function if the ARS is terminating?

Let us look at the following example. Working out some reductions (eg write down all reductions starting from

(4,3)) leads us to the firm belief that it is termintatin. But what is the measure function?

Example: Let

A=Nร—N and
(i,j+1)โ†’(i,j)
and
(i+1,j)โ†’(i,i)
. Does it terminate? What is the measure function? [5]

References:

  • Baader, Nipkow. Term Rewriting and All That. 1999

    โ€‹โ€‹โ€‹โ€‹โ€‹โ€‹  Chapter 
    โ€‹โ€‹  	2.3 termination
    

  1. Count the number of letters. More formally, you can implement a function

    length and then define
    ฯ•1(w)=length(w)
    . โ†ฉ๏ธŽ

  2. Count the number of "a"s. More formally, you can implement a function

    number and then define
    ฯ•2(w)=number(a,w)
    โ†ฉ๏ธŽ

  3. Add the two measure functions above. More formally, define

    ฯ•(w)=ฯ•1(w)+ฯ•2(w). โ†ฉ๏ธŽ

  4. Leaving this as an exercise for now, will see a simpler solution later when we learned about lexicographic orderings. โ†ฉ๏ธŽ

  5. Answer:

    ฯ•(i,j)=i2+j. โ†ฉ๏ธŽ