Docsity

Termination and Conditional Termination in Program Verification - Prof. Jose Meseguer, Study notes of Computer Science

Partial preview of the text

Download Termination and Conditional Termination in Program Verification - Prof. Jose Meseguer and more Study notes Computer Science in PDF only on Docsity!

Program Verification:

Lecture 12 Jos´e Meseguer

Computer Science DepartmentUniversity of Illinois at Urbana-Champaign

Termination We need methods to check termination. In the Maudeenvironment, the^ Termination Checker

developed by

Francisco Dur´an assists the user in this task, and supportssome useful methods to prove termination. This tool, withexamples and documentation can be directly downloadedfrom the Maude web page.Again, we can only give a flavor for the basic ideas, andillustrate one of the possible termination proof methods.More details about the termination tool, its use, itsprinciples, and examples can be found in,F. Dur´an, “Termination Checker and Knuth-BendixCompletion Tools for Maude Equational Specifications,”July 2000,^ http://maude.csl.sri.com

Reduction Orderings To show (♣) we need to consider an,^

infinite^ number of

′rewrites t −→t. We would like to reduce this problem toE checking (♣) only for the equations

in^ E. We need:

Definition: A Noetherian ordering

>^ on^ ∪T(V^ )^ is calleds∈S^ Σ

a^ reduction ordering

iff it satisfies the following two

conditions:^ •^ strict^ Σ-monotonicity

: for each^ f^ ∈^ Σ, whenever

f^ (t,... , t), f^ (t,... , t^1 n^1

′, t, t,... , t)^ ∈^ i− 1 i+1n i

T(V^ )^ withΣ

′ t> t, we have,i i^ f^ (t,... , t)^1 n

′> f (t,... , t, t, t 1 i− 1 i+1 i

,... , t)n

-^ closure under substitutuion

′: if t > t, then, for any

substitution^ θ^ :^ V^ −→

T(V^ )^ we have,^ θ(tΣ

′) > θ(t).^4

Reduction Orderings (II)Theorem: Let (Σ, E)^ be an (unconditional) equationaltheory. Then, E is terminating iff there exists a reductionorder > such that for each equation

u^ =^ v^ in^ E^ we have,

u > v. Proof: The^ (⇒)^ part follows from the observation that, if

E

is terminating, the transitive closure

+ −→of the relationE^

−→is a reduction order satisfying this requirement.E^ To see^ (⇐), it is enough to show that a reduction orderwith the above property satisfies the implication

(♣). Let

′^ t −→tthis means that there is a positionE

π^ in^ t, an

equation^ u^ =^ v^ in^ E

, and a substitution

θ^ such that

t^ =^ t[π^ ←^ θ(u)], and^

′^ t=^ t[π^ ←^ θ(v)]. But by closure under

substitution we have,

θ(u)^ >^ θ(v)^ and by repeated application

of strict^ Σ-monotonicity we then have,

′ t > t. q.e.d.^5

The Recursive Path OrderingDefinition: Given a finite signature

Σ^ an an ordering^ >

of its symbols, then the

lexicographic path ordering

>onlpo^

∪T(V^ )^ is defined recursively as follows:s∈S^ Σ^ •^ if^ x^ ∈^ vars(t)^ and

x^6 =^ t, then^ t >x.lpo^ ′′ • f (t,... , t) >g(t,... , t)^ if either: 1 nlpo 1 m ′′ ◦ for some i, t>g(t,... , t), ori lpo^1 m ′ ◦ f > g and f (t,... , t)^ >t, for all 1 nlpo^ j^

j, or

◦^ f^ =^ g,^ f^ (t,... , t)^1 n

′ >t, for all^ j, and there exist anlpo j^ ′ i such that, t= t, 1 ≤ j < i, and^ t>j i^ j

′t.lpo i^7

A Caveat on Rewriting Modulo Commutativity Since when rewriting modulo commutativity we arerewriting^ equivalence classes

, some orderings may not be appropriate, because they may give different results ondifferent^ representatives

of the equivalence class. For example, the lexicograhic path order may lead to suchconflicts, because of the strict left-to-right order used onthe list of subterms, violated by commutativity.What we need is an order

compatible^ with the

commutativity equations, so that it defines also an order onthe set,^ ∪T(Vs∈S^ Σ/C^

). Such orders do exist, for example

orders treating the subterms as a

multiset, instead than as a list.

Conditional Termination (II) The problem is that, when trying to simplify

a^ the

interpreter will try to apply the equation

a^ =^ b^ if^ a^ =^ c

but to do so it will have to first check the condition

a^ =^ c.

It will do so by trying to simplify both sides to canonicalform and then check syntactic equality of such canonicalforms. The constant

c^ is indeed in canonical form. But

what about^ a? Well, we need to see if any equation applies,namely our only conditional equation, but we must firstcheck the condition (the same condition again!) and we aredown a silly infinite loop, in which the same condition ischecked recursively^

ad infinitum.

Conditional Termination (III) What can we then do to prove the

actual termination in practice of conditional theories? We need to do threethings:1.^ to give a^ general notion of conditional termination

that captures the actual termination in practice of animplementation; and2. to develop adequate

methods^ to prove that a conditional theory terminates in this sense;3. use (or develop) adequate

tools^ supporting those methods.There is a substantial literature on conditional termination,but some of the notions are wrong.

Conditional Termination (VI)^ ...b^ →^1 a^ →b^

∗^ c ∗ a →c 1 a →b

1 where →denotes exactly one simplification step, and

denotes 0, one, or more simplification steps.Intuitively, operational termination means that

there are no infinite proof trees when we build them from left to right

That is, an implementation will build such proof treesincrementally, solving

one goal at a time

. For example, if the condition is a conjunction, it will solve the first conjunctfirst, then the second, and so on (complete details in Lucas,March´e and Meseguer).

13

Conditional Termination (VII) What methods^ can we now use to prove operationaltermination? There are basically two kinds of methods: (i) direct methods; and (ii)^ transformational

methods. In a direct method, we work directly with the conditionalequations as given. A good example of a direct method isthe following. Given a conditional equational theory

(Σ, E)

find a reduction ordering

>, such that, for each conditional

equation^ (∀X)^ t

′^ = t⇐^ u=^ v∧^...^ ∧^1

u=^ vn^ n

′ in E we have, t > t

, and^ t > u,^ t > v, forii

1 ≤^ i^ ≤^ n. If such

an ordering can be found, we call

(Σ, E)^ reductive.

Conditional Termination (IX) An alternative proof termination technique that does workin full generality and allows extra variables in conditions isto use a transformational^ method, in which a Maudefunctional module^ (Σ, E)^ is transformed into an unsorted••and unconditional theory^ (Σ, E)^

  • •so that if (Σ, E) terminates in the standard sense (that is, if

+•^ −→isE

Noetherian), then^ (Σ

, E)^ is operationally terminating.

The above transformation

  • • (Σ, E) 7 → (Σ, E)^ is carried out in

two steps: first^ (Σ, E

)^ is transformed into an

unsorted

conditional^ theory^ (Σ

◦◦◦, E); and then^ (Σ

◦, E)^ is transformed

into an^ unsorted unconditional

  • • theory (Σ, E). There are several very good tools to prove termination of unsortedunconditional theories. A prototype tool performs thesetransformations and then invokes any of those tools.

Termination is Undecidable All the termination tools try to prove that a set ofequations E, conditional or unconditional, is terminating byapplying different proof methods; for example by trying tosee if particular orderings can be used to prove theequations terminating.But these termination proof methods

are not decision procedures: in general termination of a set of equations(even if they are unconditional) is

undecidable^. However,

termination^ is^ decidable for finite sets of unconditionalequations^ E^ such that both the lefthand and the righthandsides are^ ground^ terms, or even if just the righthand sidesare ground terms (see Chapter 5 in Baader and Nipkow,“Term Rewriting and All That”, Cambridge U.P.).

Where to Go from Here (II) On conditional termination, a very good general reference isE. Ohlebusch, “Advanced Topics in Term RewritingSystems,” Springer Verlag, 2002.and for the work on operational termination and its toolsupport:S. Lucas, C. March´e and J. Meseguer, “OperationalTermination of Conditional Term Rewriting Systems,”Technical Report, Univ. Polit´ecnica de Valencia, 2005.F. Dur´an, S. Lucas, C. March´e, J. Meseguer, and X.Urbain, “Proving Termination of Membership EquationalPrograms,” in Proc. of ACM Symp. on Partial Evaluationand Program Manipulation, ACM, 147–158, 2004.

Verification of Functional Modules We are now ready to consider a

general methodology

for verifying^ declarative programs

. We will present the ideas in the context of verifying Maude

functional modules

, which are based on equational logic. The first key observation isthat there are^ three viewpoints

involved:

-^ the^ customer’s viewpoint

, expressed in the form of

requirements^ that the desired software should satisfy; • the^ implementor’s viewpoint

, whose job is to write a

program meeting the customer’s requirements; and • the^ verifier’s viewpoint

, whose responsibility is to verify that the implementation does indeed meet thecustomer’s requirements.