Docsity

Equational Simplification Modulo Axioms in Maude - Prof. Jose Meseguer, Study notes of Computer Science

Partial preview of the text

Download Equational Simplification Modulo Axioms in Maude - Prof. Jose Meseguer and more Study notes Computer Science in PDF only on Docsity!

Program Verification:

Lecture 6 Jos´e Meseguer

Computer Science DepartmentUniversity of Illinois at Urbana-Champaign

Subsignatures We have already seen an example of a signature extendinganother, namely

Σ(X)^ extends^

Σ. It is natural to call

Σ^ a

subsignature^ of

Σ(X). The general notion is as follows.

A signature^ Σ^ is a

subsignature^ of a signature

′ Σ, denoted

′ Σ ⊆ Σ, iff: • the poset of sorts

(S,^ ≤)^ of^ Σ^ is contained in the poset

′′of sorts (S,^ ≤)

′ of Σ, that is,^

′^ S ⊆ Sand^ ≤ ⊆ ≤

′, and

-^ the constants and operations of

Σ^ are a subset of those

′of Σ, that is, for each

s^ ∈^ S^ and^ w^ ∈^

∗^ Swe have

′ Σ⊆ Σ.w,s w,s

Constructor Subsignatures

Let^ T^ = (Σ, E)^ be an equational theory with equations

E

that are ground confluent and terminating. Then asubsignature^ Ω^

⊆^ Σ^ is called the

constructor subsignature

for

T^ = (Σ, E)^ iff: 1.^ Ω^ ⊆^ Σ^ 2.^ Ω^ has the same poset of sorts

(S,^ ≤)^ as^ Σ, and

3.^ Ω^ is the smallest signature satisfying (1) and (2) aboveand such that its terms contain all canonical forms:

Can|⊆^ T.Σ,E^ Ω^ Ω

We call^ Ω^ a subsignature of

free constructors

if we actually

have an equality

Can|=^ T.Σ,E^ Ω^ Ω

Constructor Subsignatures (II) In Maude, we have the option of indicating the constructorsubsignature for a given Maude module by declaring the ctor attribute for the constants and operators in theconstructor subsignature. For example, we can declare, fmod NAT-MIXFIX issort Natural .op 0 : -> Natural [ctor] .op s_ : Natural -> Natural [ctor] .op + : Natural Natural -> Natural .vars N M : Natural .eq N + 0 = N .eq N + s M = s(N + M) .endfm to indicate the, in this case^ free

, constructor subsignature.

Constructor Subsignatures (VI) Note that a given subsort overloaded operator may be aconstructor, while another subsort overloaded version of thesame operator^ may not be. For example, the module fmod INTEGER issorts Zero Natural NzNatural Negative NzNegative Integer .subsorts Zero NzNatural < Natural < Integer .subsorts Zero NzNegative < Negative < Integer .op 0 : -> Zero [ctor] .op s_ : Natural -> NzNatural [ctor] .op s_ : Integer -> Integer .op p_ : Negative -> NzNegative [ctor] .op p_ : Integer -> Integer .var I : Integer .eq p s I = I .eq s p I = I .endfm defines a free^ constructor subsignature for the integers.

Equational Simplification Modulo Axioms In OBJ and Maude, we allow certain equations, namely associativity,^ commutativity

, and^ identity^ to be declared as attributes^ of operators by means of the

assoc,^ comm, and

id:

attribute declarations in modules and theories. Mathematically

, this means that our theory is of the form

T^ = (Σ, E^ ∪^ A), with

E^ the equations

explicitly given

in the

module, and with

A^ the equations

implicitly declared

by

attributes such as

assoc,^ comm, and

id:, of operators.

Operationally, what this means is that we can apply theequations in^ E^

modulo^ the axioms

A. For example, the

equation^ N + 0 = N

applies to the term

s(0)+(0+s(0))

modulo^ associativity of

+^ ; and to the term

0+s(0)^ modulo

commutativity of

+^.

Examples of Equational Simplification Modulo

A^ (II)

Lists modulo associativity, with membership. More patternsneed to be considered without the identity attribute. fmod LIST-A isprotecting NAT.

sort List.^ subsort Nat < List .op nil : -> List .op ; : List List -> List [assoc] .op in : Nat List -> Bool .var N : Nat. vars L L’ : List .eq nil ; L = L .eq L ; nil = L .eq N in N = true .eq N in N ; L = true .eq N in L ; N = true .eq N in L ; N ; L’ = true .eq N in L = false [owise]. endfm

reduce in LIST-A : 7 in 3 ; 4 ; 9 .result Bool: false==========================================reduce in LIST-A : 7 in 4 ; 3 ; 7 .result Bool: true

Examples of Equational Simplification Modulo

A^ (IV)

Multisets modulo associativity and commutativity. fmod MSET-AC isprotecting NAT .sort MSet .subsort Nat < MSet .op nil : -> MSet .op ; : MSet MSet -> MSet [assoc comm] .op in : Nat MSet -> Bool .var N : Nat.^ var S : MSet .eq N in N = true .eq N in N ; S = true .eq N in S = false [owise] .endfmreduce in MSET-AC : 7 in 3 ; 4 ; 9 .result Bool: false==========================================reduce in MSET-AC : 7 in 4 ; 3 ; 7 .result Bool: true

Equational Simplification Modulo

A

The above examples and

red^ commands illustrate

equational simplification modulo

A, for^ A^ any combination

of associativity, commutativity, and identity axioms.Let^ T^ = (Σ, E^ ∪

A)^ be a theory whose equations

E^ are

admissible as equational simplification rules. Then, we candefine a binary relation on terms in

T, denoted^ −→Σ

, andE/A

called one-step equational simplification modulo

A, by

means of our two previously defined relations

−→, andE^

≡, as follows:A^ t^ −→

′^ t⇔^ t^ ≡E/A A

′u −→v ≡t. E A

Another Example of Equational Simplification Modulo

A

The following Maude module defines sets of naturalnumbers by simplifying multisets of natural numbers modulo^ associativity and commutativity, using identity andidempotency equations. fmod NAT-SET is protecting NATURAL .sort NatSet .subsort Natural < NatSet .op empty : -> NatSet [ctor] .op _ _ : NatSet NatSet -> NatSet [ctor assoc comm]. *** set unionvar X : NatSet .eq empty X = X.

*** identity

eq X X = X.^

*** idempotency

endfm

16

Caveats on Equational Simplification Modulo

A

Equational simplification

modulo identity

is trickier. For example, the innocent-looking idempotency equation in fmod NAT-SET’ is protecting NAT .sort NatSet .subsort Natural < NatSet .op empty : -> NatSet [ctor] .op _ _ : NatSet NatSet -> NatSet [ctor assoc comm id: empty] .var X : NatSet .eq X X = X .endfm is nonterminating, since, denoting by

≡the congruenceACI^

modulo associativity, commutativity, and identity, we have, empty^ ≡empty emptyACI^

−→empty^ ≡E^ ACI

empty empty^ −→

.. .E 17

All Generalizes Modulo

A

Under reasonable assumptions on

A, all the concepts on

equational simplification generalize in a natural way toequational simplification modulo

A. We of course define the

∗relation −→E/A^

as the reflexive and transitive closure of

−→.E/A The definitions of

confluence^ and

termination^ are the same,

replacing^ −→E^

by^ −→, and we again haveE/A

soundness,

and for confluent equations

completeness, of equational simplification modulo

A^ as an equational proof method.

All Generalizes Modulo

A^ (II)

The concepts of

canonical term algebra

and of^ constructor subsignature^ also generalize, except that now canonicalforms are^ equivalence classes modulo

A, (Notation:

Can) and ifΣ,E/A

Ω^ are the constructors we have,^ Can|ΩΣ,E/A

⊆^ T. Ω/A

We call the constructors

free^ modulo^ A

if we in fact have,

Can|=^ TΣ,E/AΩ^ Ω

./A

For example, the constructors in

NAT-SET^ are^ not

free

modulo associativity and commutativity; for instance, themultiset^ 0 0 0^

is^ not^ in canonical form.