• Aucun résultat trouvé

Collection Type Sequence: Operations

Dans le document FEATHERWEIGHT OCL (Page 109-115)

1.18.1. Basic Properties of the Sequence Type

Every element in a dened sequence is valid.

lemma Sequence-inv-lemma:τ |= (δX) =⇒ ∀x∈set ppRep-Sequencebase(X τ)qq.x 6=bot hproofi

1.18.2. Denition: Strict Equality

After the part of foundational operations on sets, we detail here equality on sets. Strong equality is inherited from the OCL core, but we have to consider the case of the strict equality. We decide to overload strict equality in the same way we do for other value's in OCL:

defs(overloaded) StrictRefEqS eq : ((x::(0A,0α::null)Sequence) .

=y) ≡(λ τ .if (υ x)τ =true τ ∧(υ y)τ =true τ then (x ,y)τ

else invalid τ)

One might object here that for the case of objects, this is an empty denition. The answer is no,

we will restrain later on states and objects such that any object has its oid stored inside the object (so the ref, under which an object can be referenced in the store will represented in the object itself). For such well-formed stores that satisfy this invariant (the WFF-invariant), the referential equality and the strong equalityand therefore the strict equality on sequences in the sense abovecoincides.

Property proof in terms of prole-binS tr ong E q-v-v

interpretation StrictRefEqS eq :prole-binS tr ong E q-v-v λx y.(x::(0A,0α::null)Sequence) .

=y hproofi

1.18.3. Constants: mtSequence

denition mtSequence ::(0A,0α::null)Sequence (Sequence{}) where Sequence{} ≡(λ τ . Abs-Sequencebase xx[]::0αlistyy)

lemma mtSequence-dened[simp,code-unfold]:δ(Sequence{}) =true hproofi

lemma mtSequence-valid[simp,code-unfold]:υ(Sequence{}) =true hproofi

lemma mtSequence-rep-set:ppRep-Sequencebase(Sequence{}τ)qq= []

hproofilemma[simp,code-unfold]:const Sequence{}

hproofi

Note that the collection types in OCL allow for null to be included; however, there is the null-collection into which inclusion yields invalid.

1.18.4. Denition: Prepend

denition OclPrepend :: [(0A,0α::null)Sequence,(0A,0α)val]⇒(0A,0α)Sequence where OclPrepend x y= (λ τ .if (δx)τ =true τ ∧ (υ y)τ =true τ

then Abs-Sequencebasexx(yτ)#ppRep-Sequencebase (x τ)qq yy else invalid τ )

notation OclPrepend (-−>prependS eq0(-0))

interpretation OclPrepend:prole-bind-v OclPrepend λx y.Abs-Sequencebasexxy#ppRep-Sequencebase xqqyy hproofi

syntax

-OclFinsequence ::args =>(0A,0a::null)Sequence (Sequence{(-)}) translations

Sequence{x,xs}==CONST OclPrepend (Sequence{xs})x Sequence{x} ==CONST OclPrepend (Sequence{}) x

1.18.5. Denition: Including

denition OclIncluding :: [(0A,0α::null) Sequence,(0A,0α) val]⇒(0A,0α) Sequence where OclIncluding x y = (λ τ .if (δ x)τ =true τ ∧(υ y)τ =true τ

then Abs-Sequencebasexx ppRep-Sequencebase(x τ)qq @ [y τ]yy else invalid τ )

notation OclIncluding (-−>includingS eq0

(-0)) interpretation OclIncluding :

prole-bind-v OclIncluding λx y.Abs-SequencebasexxppRep-Sequencebase xqq@ [y]yy hproofi

lemma[simp,code-unfold] : (Sequence{}−>includingS eq(a)) = (Sequence{}−>prependS eq(a)) hproofi

lemma [simp,code-unfold] : ((S−>prependS eq(a))−>includingS eq(b)) = ((S−>includingS eq(b))−>prependS eq(a))

hproofi

1.18.6. Denition: Excluding

denition OclExcluding :: [(0A,0α::null) Sequence,(0A,0α)val]⇒(0A,0α)Sequence where OclExcluding x y = (λ τ .if (δ x)τ =true τ ∧(υ y) τ =true τ

then Abs-Sequencebase xxlter (λx.x =y τ) ppRep-Sequencebase (x τ)qqyy else invalid τ )

notation OclExcluding (-−>excludingS eq0

(-0)) interpretation OclExcluding:prole-bind-v OclExcluding

λx y.Abs-Sequencebase xxlter (λx.x =y)ppRep-Sequencebase(x)qqyy hproofi

1.18.7. Denition: Append

Identical to OclIncluding.

denition OclAppend :: [(0A,0α::null)Sequence,(0A,0α)val]⇒(0A,0α)Sequence where OclAppend =OclIncluding

notation OclAppend (-−>appendS eq0

(-0)) interpretation OclAppend :

prole-bind-vOclAppend λx y.Abs-SequencebasexxppRep-Sequencebasexqq@ [y]yy hproofi

1.18.8. Denition: Union

denition OclUnion :: [(0A,0α::null)Sequence,(0A,0α) Sequence]⇒(0A,0α)Sequence where OclUnion x y = (λ τ .if (δx) τ =true τ ∧(δ y)τ =true τ

then Abs-Sequencebasexx ppRep-Sequencebase (x τ)qq@ ppRep-Sequencebase(yτ)qqyy else invalid τ )

notation OclUnion (-−>unionS eq0

(-0)) interpretation OclUnion :

prole-bind-dOclUnion λx y.Abs-SequencebasexxppRep-Sequencebase xqq@ppRep-Sequencebaseyqqyy hproofi

1.18.9. Denition: At

denition OclAt :: [(0A,0α::null) Sequence,(0A)Integer]⇒(0A,0α)val where OclAt x y = (λ τ . if (δ x)τ =true τ ∧(δy)τ =true τ

then if 1 ≤ppy τqq∧ ppy τqq≤lengthppRep-Sequencebase (x τ)qq thenppRep-Sequencebase(x τ)qq! (nat ppy τqq−1)

else invalid τ else invalid τ ) notation OclAt (-−>atS eq0(-0))

1.18.10. Denition: First

denition OclFirst :: [(0A,0α::null) Sequence]⇒(0A,0α)val

where OclFirst x = (λ τ . if (δ x)τ =true τ then

case ppRep-Sequencebase(x τ)qqof []⇒invalid τ

|x #-⇒x else invalid τ )

notation OclFirst (-−>rstS eq0(-0))

1.18.11. Denition: Last

denition OclLast :: [(0A,0α::null)Sequence]⇒(0A,0α)val where OclLast x = (λ τ . if (δ x)τ =true τ then

if ppRep-Sequencebase (x τ)qq= [] then invalid τ

elselast ppRep-Sequencebase(x τ)qq else invalid τ )

notation OclLast (-−>lastS eq0(-0))

1.18.12. Denition: Iterate

denition OclIterate :: [(0A,0α::null)Sequence,(0A,0β::null)val, (0A,0α)val⇒(0A,0β)val⇒(0A,0β)val]⇒(0A,0β)val where OclIterate S A F = (λ τ .if (δ S)τ =true τ ∧(υ A)τ =true τ

then (foldr (F) (map (λa τ .a) ppRep-Sequencebase (S τ)qq))(A)τ else ⊥)

syntax

-OclIterateSeq :: [(0A,0α::null)Sequence,idt,idt, 0α, 0β] =>(0A,0γ)val (-−>iterateS eq0

(-;-=-|-0) ) translations

X−>iterateS eq(a;x =A|P) ==CONST OclIterate X A(%a.(%x.P))

1.18.13. Denition: Forall

denition OclForall :: [(0A,0α::null) Sequence,(0A,0α)val⇒(0A)Boolean]⇒ 0ABoolean where OclForall S P = (S−>iterateS eq(b;x =true |x and (P b)))

syntax

-OclForallSeq :: [(0A,0α::null)Sequence,id,(0A)Boolean]⇒ 0ABoolean ((-)−>forAllS eq0(-|-0)) translations

X−>forAllS eq(x |P) ==CONST UML-Sequence.OclForall X (%x.P)

1.18.14. Denition: Exists

denition OclExists :: [(0A,0α::null) Sequence,(0A,0α)val⇒(0A)Boolean]⇒ 0ABoolean where OclExists S P = (S−>iterateS eq(b;x =false|x or (P b)))

syntax

-OclExistSeq :: [(0A,0α::null)Sequence,id,(0A)Boolean]⇒ 0ABoolean ((-)−>existsS eq0

(-|-0)) translations

X−>existsS eq(x |P) ==CONST OclExists X (%x.P)

1.18.15. Denition: Collect

denition OclCollect :: [(0A,0α::null)Sequence,(0A,0α)val⇒(0A,0β)val]⇒(0A,0β::null)Sequence where OclCollect S P = (S−>iterateS eq(b;x =Sequence{} |x−>prependS eq(P b))) syntax

-OclCollectSeq :: [(0A,0α::null)Sequence,id,(0A)Boolean]⇒ 0ABoolean ((-)−>collectS eq0(-|-0)) translations

X−>collectS eq(x |P) ==CONST OclCollect X (%x.P)

1.18.16. Denition: Select

denition OclSelect :: [(0A,0α::null)Sequence,(0A,0α)val⇒(0A)Boolean]⇒(0A,0α::null)Sequence where OclSelect S P =

(S−>iterateS eq(b;x =Sequence{} |if P b then x−>prependS eq(b)else x endif)) syntax

-OclSelectSeq :: [(0A,0α::null) Sequence,id,(0A)Boolean]⇒ 0ABoolean ((-)−>selectS eq0(-|-0)) translations

X−>selectS eq(x |P) ==CONST UML-Sequence.OclSelect X (%x.P)

1.18.17. Denition: Size

denition OclSize :: [(0A,0α::null)Sequence]⇒(0A)Integer ((-)−>sizeS eq0

(0)) where OclSize S = (S−>iterateS eq(b;x =0|x +int 1))

1.18.18. Denition: IsEmpty

denition OclIsEmpty :: (0A,0α::null)Sequence ⇒ 0ABoolean where OclIsEmpty x = ((υ x and not(δx))or ((OclSize x) .

=0)) notation OclIsEmpty (-−>isEmptyS eq0

(0) )

1.18.19. Denition: NotEmpty

denition OclNotEmpty :: (0A,0α::null)Sequence ⇒ 0ABoolean where OclNotEmpty x = not(OclIsEmpty x)

notation OclNotEmpty (-−>notEmptyS eq0

(0) )

1.18.20. Denition: Any

denition OclANY x = (λ τ . if x τ =invalid τ then

⊥ else

case drop(drop (Rep-Sequencebase(x τ)))of []⇒ ⊥

|l ⇒hd l) notation OclANY (-−>anyS eq0

(0))

1.18.21. Denition (future operators)

consts

OclCount :: [(0A,0α::null)Sequence,(0A,0α)Sequence]⇒ 0AInteger

OclSum :: (0A,0α::null) Sequence ⇒ 0AInteger notation OclCount (-−>countS eq0(-0) )

notation OclSum (-−>sumS eq0

(0) )

1.18.22. Logical Properties

1.18.23. Execution Laws with Invalid or Null as Argument

OclIterate

lemma OclIterate-invalid[simp,code-unfold]:invalid−>iterateS eq(a;x =A |P a x) =invalid hproofi

lemma OclIterate-null[simp,code-unfold]:null−>iterateS eq(a;x =A|P a x) =invalid hproofi

lemma OclIterate-invalid-args[simp,code-unfold]:S−>iterateS eq(a;x =invalid |P a x) =invalid hproofi

Context Passing lemma cp-OclIncluding:

(X−>includingS eq(x))τ = ((λ-.X τ)−>includingS eq(λ-.x τ))τ hproofi

lemma cp-OclIterate:

(X−>iterateS eq(a;x =A|P a x))τ =

((λ-.X τ)−>iterateS eq(a;x =A|P a x))τ hproofi

lemmas cp-intro00S eq[intro!,simp,code-unfold] =

cp-OclIncluding [THEN allI[THEN allI[THEN allI[THEN cpI2]],of OclIncluding]]

Const

1.18.24. General Algebraic Execution Rules

Execution Rules on Iterate

lemma OclIterate-empty[simp,code-unfold]:Sequence{}−>iterateS eq(a;x =A |P a x) =A hproofi

In particular, this does hold for A = null.

lemma OclIterate-including[simp,code-unfold]:

assumes strict1 :VX.P invalid X =invalid and P-valid-arg:V

τ .(υ A)τ = (υ (P a A))τ and P-cp :Vx y τ . P x y τ =P (λ-.x τ)y τ and P-cp0 :Vx y τ . P x y τ =P x (λ-.y τ) τ

shows (S−>includingS eq(a))−>iterateS eq(b;x =A|P b x) =S−>iterateS eq(b;x =P a A|P b x) hproofi

lemma OclIterate-prepend[simp,code-unfold]:

assumes strict1 :VX.P invalid X =invalid and strict2 :VX.P X invalid =invalid

and P-cp :Vx y τ . P x y τ =P (λ-.x τ)y τ and P-cp0 :Vx y τ . P x y τ =P x (λ-.y τ) τ

shows (S−>prependS eq(a))−>iterateS eq(b;x =A|P b x) =P a (S−>iterateS eq(b;x =A|P b x)) hproofi

1.18.25. Test Statements

instantiation Sequencebase :: (equal)equal begin

denition HOL.equal k l ←→ (k::(0a::equal)Sequencebase) = l instance hproofi

end

lemma equal-Sequencebase-code [code]:

HOL.equal k (l::(0a::{equal,null})Sequencebase) ←→Rep-Sequencebasek =Rep-Sequencebasel hproofi

Assert τ |= (Sequence{} .

=Sequence{})

Assert τ |= (Sequence{1,2}, Sequence{}−>prependS eq(2)−>prependS eq(1)) Assert τ |= (Sequence{1,invalid,2},invalid)

Assert τ |= (Sequence{1,2}−>prependS eq(null), Sequence{null,1,2}) Assert τ |= (Sequence{1,2}−>includingS eq(null),Sequence{1,2,null})

end

theory UML-Library imports

basic-types/UML-Boolean basic-types/UML-Void basic-types/UML-Integer basic-types/UML-Real basic-types/UML-String

collection-types/UML-Pair collection-types/UML-Bag collection-types/UML-Set collection-types/UML-Sequence begin

Dans le document FEATHERWEIGHT OCL (Page 109-115)