Docsity

Program Verification: Lecture 8 - ITP Inference Rules and Tree Induction - Prof. Jose Mese, Study notes of Computer Science

Partial preview of the text

Download Program Verification: Lecture 8 - ITP Inference Rules and Tree Induction - Prof. Jose Mese and more Study notes Computer Science in PDF only on Docsity!

Program Verification:

Lecture 8

Jos´ e Meseguer Computer Science Department University of Illinois at Urbana-Champaign

The ITP Inference Rules Notice that in the ITP we reason backwards , replacing the main goal

G

we want to prove by subgoals ,

G

1

,... , G

n , such that if we prove each of the subgoals, then we have provedthe main goal.For such an inference to be sound , the implication G 1

G

n

G

should always be satisfied , that is, should be semantically valid in the initial model

T

Σ ,E on which we are doing the inductive reasoning.

Linearity of the Number Ordering Consider the following module defining the order onnumbers, which we would like to prove is linear. (fmod NATURAL-ORD is sort Natural .op 0 : -> Natural [ctor] .op s : Natural -> Natural [ctor] .op < : Natural Natural -> Bool .op =< : Natural Natural -> Bool .vars N M : Natural .eq N < 0 = false .eq 0 < s(N) = true .eq s(N) < s(M) = N < M .ceq N =< M = true if N < M .ceq N =< M = true if not(M < N) .ceq N =< M = false if M < N. endfm)

The cns Inference Rule After entering the goal stating that the order on thenaturals is linear, one of the possible ITP inference rules wecan invoke is the lemma of constants , which converts universally quantified variables in a goal into constants. Maude> (goal linear : NATURAL-ORD |- {N:Natural ; M:Natural} (((N:Natural =< M:Natural) or (M:Natural =< N:Natural)) = true) .) =================================linear$0=================================|-{N:Natural ; M:Natural}(N:Natural =< M:Natural or M:Natural =< N:Natural = true) +++++++++++++++++++++++++++++++++

The cns Inference Rule (II) The fact that this is a semantically valid inference is basedon the Constants Lemma , which states the equivalence between satisfiability of a quantified equation, and of thesame equation with the variables transformed into generic constants

,^ E

Σ

X

t

t ′^

E

Σ( X )

t

t

Thanks to the completeness of equational reasoning, this is expressed in the ITP as the cns rule, E

Σ

X

t

t ′ E

Σ( X )

t

t ′

Justification of the cns Rule We can justify the validity of the Constants Lemma not only for unconditional equations, but also for conditionalones as follows. Given a conditional equation

X

ϕ

X

t

t ′^

u 1

v 1

u n

v n

we have

E

Σ

X

ϕ iff, by definition, (

A, a

Alg Σ( X )

A

Σ

E

A, a

Σ( X )

ϕ, which is equivalent, by Ex 6.2, to (

A, a

Alg Σ( X )

A, a

Σ( X )

E

A, a

Σ( X )

ϕ, which, by definition of satisfaction, is precisely E

Σ( X )

ϕ , as desired.

Reasoning by Cases: The split Rule (II) In our example we can give the split command, Maude> (split linear$0 on (NNatural < MNatural). )=================================linear$1.0=================================|- NNatural =< MNatural or MNatural =< NNatural = true=================================linear$2.0=================================|- NNatural =< MNatural or MNatural =< NNatural = true

Reasoning by Cases: The split Rule (III) The goals remain the same, but the split hypotheses foreach case have been added to each case’s module. Usingthese hypotheses we can now discharge each of thesubgoals with the auto tactic. Maude> (auto linear$1.0 .)=================================linear$2.0=================================|- NNatural =< MNatural or MNatural =< NNatural = true+++++++++++++++++++++++++++++++++Maude> (auto linear$2.0 .)q.e.d

Applications of split Must Protect

BOOL

Regardless of the current ITP restrictions in the applicationof split , there is a fundamental way in which the application of split would be unsound, namely, if we have messed up the Booleans by adding junk and perhaps confusion to them, so that we do not have anymore two different canonical forms, true , and false , but may have other nonstandard Boolean elements as well.This can happen because, when defining new predicateswith operators of sort Bool , we do not give enough equations , thus adding “junk” to Bool , or we give the wrong equations , adding “confusion” and possibly also “junk” to Bool

. Therefore, sound application of split require that the BOOL submodule is protected .

Protecting Module Importations In general, if we have a theory

, E

having a subtheory (Σ ′

, E

′

with,

′^

and

E

′^

E,

and the module fmod

, E

endfm imports the submodule fmod

′

, E

′

endfm in protecting mode, we require that the unique

′ -homomorphism eval E ′ T Σ ,E | Σ ′^

T

Σ ′^ /E ′^

T

Σ ,E

Σ ′ is an isomorphism .

Justification of the split Rule (II) Therefore, given any Boolean valued

-term p

T

Σ

X

Bool , and given any assignment a

X

T

Σ /E , we have, (

T

Σ /E , a

p

true

p

false

That is, for any such assignment a , the above proposition is equivalent to the identically false proposition,

, which is never satisfied:

T

Σ /E , a

p

true

p

false

T

Σ /E , a

Now, since for any proposition

A

we always have the Boolean equivalence,

A

A

, we also have an equivalence

X

A

X

A

. Therefore, given an equation

X

t

t ′ , we have, 16

Justification of the split Rule (III) T Σ /E

X

t

t ′^

T

Σ /E

X

t

t

or, equivalently, T Σ /E

X

t

t ′^

T

Σ /E

X

t

t ′

p

true

p

false

which, using distributivity of disjunction over conjunction,plus the fact that

A

B

A

B

, is equivalent to, T Σ /E

X

t

t ′^

T

Σ /E

X

p

true

t

t

p

false

t

which, modulo the distribution of

over

, is our desired justification for split as a sound inductive reasoning rule. 17

Induction on Other Data Structures: Tree Induction (II) Consider the following module defining binary trees whosenodes are quoted identifiers (constants in the predefinedmodule

QID

), and a reverse function on binary trees. (fmod TREE isprotecting QID .sort Tree .subsort Qid < Tree .op # : Tree Tree -> Tree [ctor] .op rev : Tree -> Tree .var I : Qid .vars T T’ : Tree .eq rev(I) = I .eq rev(T # T’) = rev(T’) # rev(T) .endfm)

Induction on Other Data Structures: Tree Induction (III) We can apply binary tree induction to prove that for alltrees

T

the equation rev(rev(T)) = T holds. We can do so by entering the

TREE

module in the ITP and the goal: Maude> (goal rev : TREE |- {T:Tree}((rev(rev(T:Tree))) = (T:Tree)) .)=================================rev$0=================================|-{T:Tree}(rev(rev(T:Tree))= T:Tree)