• Aucun résultat trouvé

Collection Type Sequence: Operations

2. Formalization II: OCL Terms and Library Operations 47

2.10. Collection Type Sequence: Operations

2.10.1. Basic Properties of the Sequence Type

Every element in a defined sequence is valid.

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

2.10.2. Definition: 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:

overloading

StrictRefEqStrictRefEq :: [(0A,0α::null)Sequence,(0A,0α::null)Sequence]⇒(0A)Boolean begin

definitionStrictRefEqS eq : ((x::(0A,0α::null)Sequence) .

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

else invalid τ) end

One might object here that for the case of objects, this is an empty definition. 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 equality—and therefore the strict equality on sequences in the sense above—coincides.

Property proof in terms ofprofile-binS tr ong E q-v-v

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

=y hproofi

2.10.3. Constants: mtSequence

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

lemmamtSequence-defined[simp,code-unfold]:δ(Sequence{}) =true hproofi

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

lemmamtSequence-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.

2.10.4. Definition: Prepend

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

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

notation OclPrepend (-−>prependS eq0

(-0))

interpretationOclPrepend:profile-bind-vOclPrepend λ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

2.10.5. Definition: Including

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

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

notation OclIncluding (-−>includingS eq0

(-0)) interpretationOclIncluding :

profile-bind-v OclIncluding λx y.Abs-SequencebasexxppRep-Sequencebasexqq@ [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

2.10.6. Definition: Excluding

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

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

notation OclExcluding (-−>excludingS eq0

(-0)) interpretationOclExcluding:profile-bind-v OclExcluding

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

2.10.7. Definition: Append

Identical to OclIncluding.

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

notation OclAppend (-−>appendS eq0

(-0)) interpretationOclAppend :

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

2.10.8. Definition: Union

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

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

notation OclUnion (-−>unionS eq0

(-0)) interpretationOclUnion:

profile-bind-dOclUnion λx y.Abs-SequencebasexxppRep-Sequencebasexqq@ppRep-Sequencebaseyqqyy hproofi

2.10.9. Definition: At

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

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

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

(-0))

2.10.10. Definition: First

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

where OclFirst x = (λ τ . ifx)τ =true τ then

caseppRep-Sequencebase(x τ)qqof []⇒invalid τ

|x #-x else invalid τ )

notation OclFirst (-−>firstS eq0

(-0))

2.10.11. Definition: Last

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

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

else

lastppRep-Sequencebase (x τ)qq else invalid τ )

notation OclLast (-−>lastS eq0

(-0))

2.10.12. Definition: Iterate

definitionOclIterate :: [(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 = (λ τ . ifS) τ =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))

2.10.13. Definition: Forall

definitionOclForall :: [(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)

2.10.14. Definition: Exists

definitionOclExists :: [(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)

2.10.15. Definition: Collect

definitionOclCollect :: [(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)

2.10.16. Definition: Select

definitionOclSelect :: [(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)

2.10.17. Definition: Size

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

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

2.10.18. Definition: IsEmpty

definitionOclIsEmpty :: (0A,0α::null)Sequence0ABoolean where OclIsEmpty x= ((υ x and notx))or ((OclSize x) .

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

(0) )

2.10.19. Definition: NotEmpty

definitionOclNotEmpty :: (0A,0α::null)Sequence0ABoolean where OclNotEmpty x= not(OclIsEmpty x)

notation OclNotEmpty (-−>notEmptyS eq0

(0) )

2.10.20. Definition: Any

definitionOclANY x = (λ τ . if x τ =invalid τ then

else

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

|lhd l) notation OclANY (-−>anyS eq0

(0))

2.10.21. Definition (future operators)

consts

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

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

(-0) ) notation OclSum (-−>sumS eq0

(0) )

2.10.22. Logical Properties

2.10.23. Execution Laws with Invalid or Null as Argument

OclIterate

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

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

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

Context Passing lemmacp-OclIncluding:

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

lemmacp-OclIterate:

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

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

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

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

Const

2.10.24. General Algebraic Execution Rules

Execution Rules on Iterate

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

In particular, this does hold for A = null.

lemmaOclIterate-including[simp,code-unfold]:

assumesstrict1 :V

X.P invalid X =invalid and P-valid-arg:V

τ .(υ A)τ = (υ (P a A))τ and P-cp :V

x yτ . P x y τ =P-.x τ)yτ and P-cp0 :V

x 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

lemmaOclIterate-prepend[simp,code-unfold]:

assumesstrict1 :V

X.P invalid X =invalid and strict2 :V

X.P X invalid=invalid and P-cp :V

x yτ . P x y τ =P-.x τ)yτ and P-cp0 :V

x 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

2.10.25. Test Statements

instantiationSequencebase :: (equal)equal begin

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

end

lemmaequal-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