Docsity

Equational Theory and Program Verification: Lecture 4 - Prof. Jose Meseguer, Study notes of Computer Science

Partial preview of the text

Download Equational Theory and Program Verification: Lecture 4 - Prof. Jose Meseguer and more Study notes Computer Science in PDF only on Docsity!

Program Verification:

Lecture 4

Jos´

e Meseguer

Computer Science Department

University of Illinois at Urbana-Champaign

Theories

An

equational theory

is a pair

T

, E

with

a signature

and

E

a set of universally quantified equations, each of

which may be conditional or unconditional. We have alreadyseen examples of such theories:

for

consisting of one sort, a constant

, and a binary

operation

, the set

E

consisting of the associativity

and identity axioms gives us the theory of

monoids

;

adding to such a

a unary operation

−

1

, and to the

above

E

the identity axioms gives us the theory of

groups

;

adding to the theory of monoids the conditionalequation

x, y

x

y

x

z

y

z

, yields the theory

of

cancellative monoids

.

Examples, Argot, and Notation

For example, monoids are of course the models of thetheory of monoids, groups the models of the theory ofgroups, and rings the models of the theory of rings.In the argot of algebraic specifications we are giving to theequational theory

T

a

loose semantics

, in that we allow

any

model satisfying the theory, and not just the standard orinitial model, that we will see it always has. Notation:

in (Full) Maude, theories with loose semantics

are specificed with the keywords

fth...endfth

. In general,

such loose theories are not assumed to be executable.

The (Semantic) Consequence Relation

Given a theory

T

, E

what other equations are satisfied

by any model of

T

? That is, what other equations are

theorems

of

T

? For example, the equations

−

1

and

x

y

−

1

y

−

1

x

−

1

are satisfied by any group and are

therefore theorems in group theory.We express this relation by the (semantic)

consequence

relation

E

e

, holding between a set of (possibly

conditional) universally quantified

-equations

E

and

another universally quantified

-equation

e

iff for any

-algebra

A

, we have

A

E

A

e

Similarly, we define

T

e

iff

E

e

. Notice that now we can

have either algebras or equations on the left of

.

Equational Deduction (II)

Symmetry

.

X

t

t

′

X

t

′

t

Transitivity

.

X

t

t

′

X

t

′

t

′′

X

t

t

′′

Congruence

. For

f

s

1

... s

n

s

,

f

s

′ 1

... s

′ n

s

′

in

with

s

1

... s

n

s

≤

s

′ 1

... s

′ n

s

′

, and for

t

i

T

Σ

X

s

i

,

t

′ i

T

Σ

X

s

′ i

i

n

,

X

t

1

t

′ 1

X

t

n

t

′ n

X

f

t

1

,... , t

n

f

t

′ 1

,... , t

′ n

Equational Deduction (III)

Modus ponens

. For families of variables

X, Y

, a

substitution

θ

X

T

Σ

Y

, and a conditional equation

in

E

X

t

t

′

u

1

v

1

u

n

v

n

Y

θ

u

1

θ

v

1

Y

θ

u

n

θ

v

n

Y

θ

t

θ

t

′

We call

the

provability relation

, and define

T

X

t

t

′

iff

E

X

t

t

′

.

Soundness of the Provability Relation

Are the above inference rules

correct

? That is, are they a

sound

method for deriving theorems for the given theory

T

?

They will be correct if all the equations they derive are truein all models of

T

, that is, if the following theorem, stating

that the provability relation implies the semanticcosequence relation, holds: Soundness Theorem

. For

T

, E

an equational theory,

T

X

t

t

′

T

X

t

t

′

10

Proof of the Soundness Theorem

First of all, note that being able to derive an equation E

X

t

t

′

means exactly the same as being able to

build a

proof tree

, with that equation obtained by an

inference step at its root, and with one of the above rulesof inference applied at any other node in the tree. We cantherefore prove soundness by induction on the depth of theproof tree.Note also that in the above rules of inference we haveimplicitly treated unconditional equations in

E

as

conditional equations with an

empty

set of equations in

their condition, so that the

Modus ponens

rule applies to

unconditional equations in

E

with no premisses

.

Proof of the Soundness Theorem (III)

We now have to show that if

A

E

then

A

Y

θ

t

θ

t

′

. Let

a

Y

A

be any assignment. We

have to show that

a

θ

t

a

θ

t

′

.

By hypothesis

A

E

and in particular

A

X

t

t

′

. In

particular, for the assignment

θ

a

X

A

(see picture) we

must have,

θ

a

t

θ

a

t

′

.

The key observation is that, by the freeness of

T

Σ

X

, we

have

η

X

θ

a

η

X

θ

a

θ

a.

And therefore by uniqueness

we must have

θ

a

θ

a

(see the diagram).

Therefore the identity

a

θ

t

a

θ

t

′

coincides with the

already proved identity

θ

a

t

θ

a

t

′

, as desired.

Proof that

θ

a

θ

a

X

Y

T

Σ

Y

T

Σ

X

A

Q

Q

Q

Q

Q

Q

Q

Q

Q

Q

Qs

Q

Q

Q

Q

Q

Q

Q

Q

Q

Q

Qs

a

θ

a

a

θ

θ

η

X

θ

η

Y

14

Proof of the Soundness Theorem (V)

Let

A

E

. By the induction hypothesis, for any assignment

a

X

A

we then have,

a

t

i

a

t

′ i

,

i

n

, and then by

the definition of

-algebra, according to which

subsort-overloaded operators must agree on commonarguments, and by

a

a

-homomorphism we must have,

a

f

t

1

,... , t

n

A

w,sf

a

t

1

a

t

n

A

w,sf

a

t

′ 1

a

t

′ n

A

w

′

,s

′

f

a

t

′ 1

a

t

′ n

a

f

t

′ 1

,... , t

′ n

, as desired.

The only remaining possibility for a proof of depth

n

is

the application of

Modus ponens

to a

conditional

equation

X

t

t

′

u

1

v

1

u

n

v

n

in

E

using a substitution

θ

X

T

Σ

Y

.

16

Proof of the Soundness Theorem (VI)

Let

A

E

. We must show that for any assignment

a

Y

A

we have

a

θ

t

a

θ

t

′

.

By the induction hypothesis we know that A

Y

θ

u

i

θ

v

i

,

i

n

. In particular, for the

assignment

a

Y

A

we must have,

a

θ

u

i

a

θ

v

i

,

i

n

.

But as pointed out in the depth 0 case, the freeness of T

Σ

X

gives us the equality

θ

a

θ

a.

Therefore,

A

satisfies

the condition of the equation under the assignment θ

a

X

A

. Therefore, since

A

satisfies the given

conditional equation, we must have,

θ

a

t

θ

a

t

′

, which,

again by

θ

a

θ

a

, proves

a

θ

t

a

θ

t

′

. q.e.d.

Construction of the Initial Algebra

T

Σ

/E

We have already shown the initiality of

T

Σ

for the class of

all

-algebras, that we shall denote by

Alg

Σ

. What we are

really interested in is the more general construction of aninitial algebra in the class of all models of a givenequational theory

T

, E

. That is, of an algebra that is

initial in the class,

Alg

(Σ

,E

)

A

Alg

Σ

A

E

We shall construct such an algebra, denoted

T

Σ

/E

, and

show that it is indeed initial in

Alg

(Σ

,E

)

.

Remark:

OBJ, specifications of the form

obj

, E

endo

,

and Maude specifications of the form

fmod

, E

endfm

, have

an

initial algebra semantics

, given by

T

Σ

/E

.

Construction of

T

Σ

/E

(II)

We can construct

T

Σ

/E

out of the provability relation

. First

of all, note that, for terms without variables

t, t

′

T

Σ

that

have sorts related by

≤

, our general notation for quantified

equations specializes to the notation

t

t

′

, where

denotes the empty family of variables (that is, for each s

S

the set of variables is empty). Note that we have,

, and therefore

T

Σ

T

Σ

.

Then, for each conected component

C

in the poset of sorts

S,

consider the set

T

Σ

,C

s

∈

C

T

Σ

,s

. We can define an

equivalence relation

E

on any such

T

Σ

,C

as follows:

t

E

t

′

E

t

t

′