• Keine Ergebnisse gefunden

Lecture 4: OCL Semantics

N/A
N/A
Protected

Academic year: 2022

Aktie "Lecture 4: OCL Semantics"

Copied!
26
0
0

Wird geladen.... (Jetzt Volltext ansehen)

Volltext

(1)

2015-11-03main

Software Design, Modelling and Analysis in UML

Lecture 4: OCL Semantics

2015-11-03

Prof. Dr. Andreas Podelski, Dr. Bernd Westphal

Albert-Ludwigs-Universit¨at Freiburg, Germany

(2)

Contents & Goals

1-03Sprelim

Last Lecture:

• OCL Syntax

This Lecture:

• Educational Objectives: Capabilities for these tasks/questions:

• Please un-abbreviate all abbreviations in this OCL expression.

• Please explain this OCL constraint.

• Please formalise this constraint in OCL.

• Does this OCL constraint hold in this system state?

• Give a system state satisfying this constraint?

• In what sense is OCL a three-valued logic? For what purpose?

• How are D(C) and TC related?

• Content:

• OCL Semantics

(3)

Recall

2015-11-03Sthetask

OCL Syntax 1/4: Expressions

032014-10-29Soclsyn

6/35

expr::=

w :τ(w)

|expr1=τexpr2 :τ×τBool

|oclIsUndefinedτ(expr1) :τBool

|{expr1,. . .,exprn} :τ× · · · ×τSet(τ)

|isEmpty(expr1) :Set(τ)Bool

|size(expr1) :Set(τ)Int

|allInstancesC :Set(τC)

|v(expr1) :τCτ(v)

|r1(expr1) :τCτD

|r2(expr1) :τCSet(τD)

Where, givenS = (T,C, V,atr),

W⊇ {selfC:τC|CC} is a set of typedlogical variables, whas typeτ(w)

τis any type fromT TBTC

∪ {Set(τ0)|τ0T TBTC}

TBis a set of(OCL) basic types, in the following we use TB={Bool,Int,String}

TC=C|CC}is the set ofobject types,

Set(τ0)denotes theset-of-τ0

type forτ0TBTC

(sufficient because of

“flattening” (cf. standard))

v:T(v)atr(C),T(v)T,

r1:D0,1atr(C),

r2:Datr(C),

C, DC.

OCL Syntax 2/4: Constants & Arithmetics

032014-10-29Soclsyn

9/35

For example:

expr::= . . .

|true,false :Bool

|expr1{and,or,implies}expr2 :Bool×BoolBool

|notexpr1 :BoolBool

|0,−1,1,−2,2, . . . :Int

|OclUndefinedτ :τ

|expr1{+,−, . . .}expr2 :Int×IntInt

|expr1{<,, . . .}expr2 :Int×IntBool

Generalised notation:

expr::= ω(expr1, . . . ,exprn) :τ1× · · · ×τnτ withω∈ {+,−, . . .}

OCL Syntax 3/4: Iterate

032014-10-29Soclsyn

11 expr::=· · · |expr1->iterate(w1:τ1;w2:τ2=expr2|expr3) or, with a little renaming,

expr::=· · · |expr1->iterate(iter :τ1;result:τ2=expr2|expr3)

where

expr1is of acollection type(here: a setSet(τ0)for someτ0),

iterW is callediterator, gets typeτ1 (ifτ1is omitted,τ0is assumed as type ofiter)

resultWis calledresult variable, gets typeτ2,

expr2in an expression of typeτ2giving theinitial valueforresult, (OclUndefinedτ2, if omitted)

expr3is an expression of typeτ2

in which in particulariterandresultmay appear.

OCL Syntax 4/4: Context

032014-10-29Soclsyn

14 context::=contextw1:τ1, . . .,wn:τninv:expr

wherewiWandτiTC for all1in,n0.

contextw1:C1, . . . , wn:Cninv:expr is anabbreviationfor

allInstancesC1->forAll(w1:τC1| . . .

allInstancesCn->forAll(wn:τCn| expr

) . . . )

(4)

OCL Semantics: The Task

1-03Sthetask

• Given an OCL expression expr (over signature S), e.g.

expr1 = context DD inv : wen implies win > 0

• and a system state σ ∈ ΣDS , e.g.

σ1 = {7VM 7→ {dd 7→ {1DD},cp 7→ {3DD,5DD}}, 1DD 7→ {win 7→ 13,wen 7→ true}, 3CP 7→ {wen 7→ true}, 5CP 7→ {wen 7→ false}}

• and a valuation of logical variables β : W → I(T ∪ TB ∪ TC),

• define the interpretation of expr in σ under β

IJ·K(·, ·) : OCLExpressions(S) × ΣDS × (W → I(T ∪ TB ∪ TC)) → I(Bool) i.e.

(5)

OCL Semantics OMG (2006)

2015-11-03main

(6)

Basically business as usual...

1-03Soclsem

(i) Equip each OCL (!) type with a reasonable domain, i.e. define function I with dom(I) = T ∪ TB ∪ TC

(ii) Equip each set type Set(τ0) with reasonable domain, i.e. define function I with dom(I) = {Set(τ0) | τ0 ∈ T ∪ TB ∪ TC}

(iii) Equip each arithmetical operation with a reasonable interpretation (that is, with a function operating on the corresponding domains).

I with dom(I) = {+,−,≤, . . .}, e.g., I(+) ∈ I(Int) × I(Int) → I(Int) (iv) Set operations similar: I with dom(I) = {isEmpty, . . .}

(v) Equip each expression with a reasonable interpretation, i.e. define function I : Expr × ΣDS × (W → I(T ∪ TB ∪ TC)) → I(Bool)

(7)

Basically business as usual...

2015-11-03Soclsem

(i) Equip each OCL (!) type with a reasonable domain, i.e. define function I with dom(I) = T ∪ TB ∪ TC

(ii) Equip each set type Set(τ0) with reasonable domain, i.e. define function I with dom(I) = {Set(τ0) | τ0 ∈ T ∪ TB ∪ TC}

(iii) Equip each arithmetical operation with a reasonable interpretation (that is, with a function operating on the corresponding domains).

I with dom(I) = {+,−,≤, . . .}, e.g., I(+) ∈ I(Int) × I(Int) → I(Int) (iv) Set operations similar: I with dom(I) = {isEmpty, . . .}

(v) Equip each expression with a reasonable interpretation, i.e. define function I : Expr × ΣDS × (W → I(T ∪ TB ∪ TC)) → I(Bool)

...except for OCL being a three-valued logic, and the “iterate” expression.

(8)

(i) Domains of OCL and (!) Model Basic Types

1-03Soclsem

Recall: OCL basic types

TB = {Bool,Int,String}

We set:

• I(Bool) := {true,false,⊥Bool}

• I(Int) := Z ∪ {⊥Int}

• I(String) := . . . ∪ {⊥String}

We may omit index τ of ⊥τ if it is clear from context.

Given signature S with model basic types T and domain D, set I(T) := D(T) ∪ {⊥T}

for each model basic type T ∈ T .

(9)

OCL and Model Types?! An Example.

2015-11-03Soclsem

S = ({Bool, Nat},{VM,CP,DD},

{cp : CP,dd : DD0,1,wen : Bool,win : Nat},

{VM 7→ {cp,dd},CP 7→ {wen},DD 7→ {win, wen})

(10)

(i) Domains of Object and (ii) Set Types

1-03Soclsem

• Let τC be an (OCL) object type for a class C ∈ C.

• We set

I(τC) := D(C) ˙∪ {⊥τC}

• Let τ be a type from T ∪ TB ∪ TC.

• We set

I(Set(τ)) := 2I(τ) ∪ {⊥˙ Set(τ)} Note: in the OCL standard, only finite subsets of I(τ).

But infinity doesn’t scare us, so we simply allow it.

(11)

(iii) Interpretation of Arithmetic Operations

2015-11-03Soclsem

• Literals map to fixed values:

I(true) := true, I(false) := false, I(0) := 0, I(1) := 1, . . . I(OclUndefinedτ) := τ

(12)

(iii) Interpretation of Arithmetic Operations

1-03Soclsem

• Literals map to fixed values:

I(true) := true, I(false) := false, I(0) := 0, I(1) := 1, . . . I(OclUndefinedτ) := τ

• Boolean operations (defined point-wise for x1, x2 ∈ I(τ)):

I(=τ)(x1, x2) :=

true , if x1 6= τ 6= x2 and x1 = x2 false , if x1 6= τ 6= x2 and x1 6= x2

Bool , otherwise

• Integer operations (defined point-wise for x1, x2 ∈ I(Int)):

I(+)(x1, x2) :=

(x1 + x2 , if x1 6= ⊥ 6= x2

, otherwise

Note: There is a common principle.

(13)

(iii) Interpretation of OclIsUndefined

2015-11-03Soclsem

• The is-undefined predicate (defined point-wise for x ∈ I(τ)):

I(oclIsUndefinedτ)(x) :=

(true , if x = τ false , otherwise

Note: I(oclIsUndefinedτ) is definite, i.e., it never yields .

(14)

(iv) Interpretation of Set Operations

1-03Soclsem

Basically the same principle as with arithmetic operations...

Let τ ∈ T ∪ TB ∪ TC.

• Set comprehension (x1, . . . , xn ∈ I(τ)):

I({}τn)(x1, . . . , xn) := {x1, . . . , xn}

for all n ∈ N0

• Empty-ness check (x ∈ I(Set(τ))):

I(isEmptyτ)(x) :=

true , if x =

Bool , if x = Set(τ) false , otherwise

• Counting (x ∈ I(Set(τ))):

I(sizeτ)(x) :=

(

|x| , if x 6= Set)

(15)

(v) Putting It All Together

2015-11-03Soclsem

OCL Syntax 1/4: Expressions

032014-10-29Soclsyn

6/35

expr::=

w :τ(w)

|expr1=τexpr2 :τ×τBool

|oclIsUndefinedτ(expr1) :τBool

|{expr1,. . .,exprn} :τ× · · · ×τSet(τ)

|isEmpty(expr1) :Set(τ)Bool

|size(expr1) :Set(τ)Int

|allInstancesC :Set(τC)

|v(expr1) :τCτ(v)

|r1(expr1) :τCτD

|r2(expr1) :τCSet(τD)

Where, givenS = (T,C, V,atr),

W⊇ {selfC:τC|CC} is a set of typedlogical variables, whas typeτ(w)

τis any type fromT TBTC

∪ {Set(τ0)|τ0T TBTC}

TBis a set of(OCL) basic types, in the following we use TB={Bool,Int,String}

TC=C|CC}is the set ofobject types,

Set(τ0)denotes theset-of-τ0

type forτ0TBTC

(sufficient because of

“flattening” (cf. standard))

v:T(v)atr(C),T(v)T,

r1:D0,1atr(C),

r2:Datr(C),

C, DC.

OCL Syntax 2/4: Constants & Arithmetics

032014-10-29Soclsyn

9/35

For example:

expr::= . . .

|true,false :Bool

|expr1{and,or,implies}expr2 :Bool×BoolBool

|notexpr1 :BoolBool

|0,−1,1,−2,2, . . . :Int

|OclUndefinedτ :τ

|expr1{+,−, . . .}expr2 :Int×IntInt

|expr1{<,, . . .}expr2 :Int×IntBool

Generalised notation:

expr::= ω(expr1, . . . ,exprn) :τ1× · · · ×τnτ withω∈ {+,−, . . .}

OCL Syntax 3/4: Iterate

032014-10-29Soclsyn

11 expr::=· · · |expr1->iterate(w1:τ1;w2:τ2=expr2|expr3) or, with a little renaming,

expr::=· · · |expr1->iterate(iter :τ1;result:τ2=expr2|expr3)

where

expr1is of acollection type(here: a setSet(τ0)for someτ0),

iterW is callediterator, gets typeτ1 (ifτ1is omitted,τ0is assumed as type ofiter)

resultWis calledresult variable, gets typeτ2,

expr2in an expression of typeτ2giving theinitial valueforresult, (OclUndefinedτ2, if omitted)

expr3is an expression of typeτ2

in which in particulariterandresultmay appear.

OCL Syntax 4/4: Context

032014-10-29Soclsyn

14 context::=contextw1:τ1, . . .,wn:τninv:expr

wherewiWandτiTC for all1in,n0.

contextw1:C1, . . . , wn:Cninv:expr is anabbreviationfor

allInstancesC1->forAll(w1:τC1| . . .

allInstancesCn->forAll(wn:τCn| expr

) . . . )

(16)

Valuations of Logical Variables

1-03Soclsem

• Recall: we have typed logical variables (w ∈) W, τ(w) is the type of w.

• By β, we denote a valuation of the logical variables, i.e. for each w ∈ W, β(w) ∈ I(τ(w)).

(17)

(v) Putting It All Together...

2015-11-03Soclsem

expr ::= w | ω(expr1, . . . ,exprn) | allInstancesC | v(expr1) | r1(expr1)

| r2(expr1) | expr1->iterate(v1 : τ1 ; v2 : τ2 = expr2 | expr3)

• IJwK(σ, β) := β(w)

• IJω(expr1, . . . , exprn)K(σ, β) := I(ω)(IJexpr1K(σ, β), . . . IJexprnK(σ, β))

• IJallInstancesCK(σ, β) := dom(σ) ∩ D(C)

Note: in the OCL standard, dom(σ) is assumed to be finite.

Again: doesn’t scare us.

(18)

Example

1-03Soclsem

S = ({Bool, Nat},{VM,CP,DD},

{cp : CP,dd : DD0,1,wen : Bool,win : Nat},

{VM 7→ {cp,dd},CP 7→ {wen},DD 7→ {win, wen})

σ1 = {7VM 7→ {dd 7→ {1DD},cp 7→ {3DD,5DD}}, 1DD 7→ {win 7→ 13,wen 7→ true}, 3CP 7→ {wen 7→ true}, 5CP 7→ {wen 7→ false}}

IJwK(σ, β) := β(w) IJallInstancesCK(σ, β) := dom(σ) D(C)

IJω(expr1, . . . ,exprn)K(σ, β) := I(ω)(IJexpr1K(σ, β), . . . IJexprnK(σ, β))

(19)

(v) Putting It All Together...

2015-11-03Soclsem

expr ::= w | ω(expr1, . . . ,exprn) | allInstancesC | v(expr1) | r1(expr1)

| r2(expr1) | expr1->iterate(v1 : τ1 ; v2 : τ2 = expr2 | expr3)

Assume expr1 : τC for some C ∈ C. Set u1 := IJexpr1K(σ, β) ∈ D(τC).

• IJv(expr1)K(σ, β) :=

(σ(u1)(v) , if u1 ∈ dom(σ)

⊥ , otherwise

(20)

Example

1-03Soclsem

S = ({Bool,Nat},{VM,CP,DD},

{cp : CP,dd : DD0,1,wen : Bool,win : Nat},

{VM 7→ {cp,dd},CP 7→ {wen},DD 7→ {win,wen})

σ1 = {7VM 7→ {dd 7→ {1DD},cp 7→ {3DD,5DD}}, 1DD 7→ {win 7→ 13,wen 7→ true}, 3CP 7→ {wen 7→ true}, 5CP 7→ {wen 7→ false}}

Assume expr1 : τC for some C C. Set u1 := IJexpr1K(σ, β) DC).

IJv(expr1)K(σ, β) :=

(σ(u1)(v) , if u1 dom(σ)

, otherwise

(21)

(v) Putting It All Together...

2015-11-03Soclsem

expr ::= w | ω(expr1, . . . ,exprn) | allInstancesC | v(expr1) | r1(expr1)

| r2(expr1) | expr1->iterate(v1 : τ1 ; v2 : τ2 = expr2 | expr3)

Assume expr1 : τC for some C ∈ C. Set u1 := IJexpr1K(σ, β) ∈ D(τC).

• IJv(expr1)K(σ, β) :=

(σ(u1)(v) , if u1 ∈ dom(σ)

⊥ , otherwise

• IJr1(expr1)K(σ, β) :=

(u , if u1 ∈ dom(σ) and σ(u1)(r1) = {u}

⊥ , otherwise

• IJr2(expr1)K(σ, β) :=

(σ(u1)(r2) , if u1 ∈ dom(σ)

⊥ , otherwise

Recall: σ evaluates r2 of type C to a set.

(22)

(v) Putting It All Together...

1-03Soclsem

expr ::= w | ω(expr1, . . . ,exprn) | allInstancesC | v(expr1) | r1(expr1)

| r2(expr1) | expr1->iterate(v1 : τ1 ; v2 : τ2 = expr2 | expr3)

IJexpr1->iterate(v1 : τ1 ; v2 : τ2 = expr2 | expr3)K(σ, β)

:=

(IJexpr2K(σ, β) , if IJexpr1K(σ, β) = iterate(hlp, v1, v2,expr3, σ, β) , otherwise

where β = β[hlp 7→ IJexpr1K(σ, β), v2 7→ IJexpr2K(σ, β)] and

iterate(hlp, v1, v2,expr3, σ, β) :=

(IJexpr3K(σ, β[v1 7→ x]) , if β(hlp) = {x}

IJexpr3K(σ, β′′) , if β(hlp) = X ∪ {˙ x} and X 6= where β′′ = β[v1 7→ x, v2 7→ iterate(hlp, v1, v2,expr3, σ, β[hlp 7→ X])]

(23)

Example

2015-11-03Soclsem

S = ({Bool,Nat},{VM,CP,DD},

{cp : CP,dd : DD0,1,wen : Bool,win : Nat},

{VM 7→ {cp,dd},CP 7→ {wen},DD 7→ {win,wen})

σ1 = {7VM 7→ {dd 7→ {1DD},cp 7→ {3DD,5DD}}, 1DD 7→ {win 7→ 13,wen 7→ true}, 3CP 7→ {wen 7→ true}, 5CP 7→ {wen 7→ false}}

context DD inv : wen implies win > 0

(24)

Another Example

1-03Soclsem

S = ({Bool,Nat},{VM,CP,DD},

{cp : CP,dd : DD0,1,wen : Bool,win : Nat},

{VM 7→ {cp,dd},CP 7→ {wen},DD 7→ {win,wen})

σ1 = {7VM 7→ {dd 7→ {1DD},cp 7→ {3DD,5DD}}, 1DD 7→ {win 7→ 13,wen 7→ true}, 3CP 7→ {wen 7→ true}, 5CP 7→ {wen 7→ false}}

(25)

References

2015-11-03main

(26)

References

1-03main

Cabot, J. and Claris´o, R. (2008). UML-OCL verification in practice. In Chaudron, M. R. V., editor, MoDELS Workshops, volume 5421 of Lecture Notes in Computer Science. Springer.

Cengarle, M. V. and Knapp, A. (2001). On the expressive power of pure OCL. Technical Report 0101, Institut f¨ur Informatik, Ludwig-Maximilians-Universit¨at M¨unchen.

Cengarle, M. V. and Knapp, A. (2002). Towards OCL/RT. In Eriksson, L.-H. and Lindsay, P. A., editors, FME, volume 2391 of Lecture Notes in Computer Science, pages 390–409.

Springer-Verlag.

Flake, S. and M¨uller, W. (2003). Formal semantics of static and temporal state-oriented OCL constraints. Software and Systems Modeling, 2(3):164–186.

Jackson, D. (2002). Alloy: A lightweight object modelling notation. ACM Transactions on Software Engineering and Methodology, 11(2):256–290.

OMG (2006). Object Constraint Language, version 2.0. Technical Report formal/06-05-01.

OMG (2007a). Unified modeling language: Infrastructure, version 2.1.2. Technical Report formal/07-11-04.

OMG (2007b). Unified modeling language: Superstructure, version 2.1.2. Technical Report

Referenzen

ÄHNLICHE DOKUMENTE

6.4.2 Dual norm of the nuclear norm and its triangle property 74 6.4.3 An oracle result for trace regression with least squares loss 76 6.4.4 Robust matrix

My original plan was to completely rewrite it for publication; in particular I wanted to make it more readable for the non—expert. Finally I chose to rather publish it like it is

THE SCHR ¨ ODINGER EQUATION Even though the potential vanishes in the box (and classically a particle at rest with energy E = 0 is allowed) this is not the case for the quantum

In what follows we consider three cases: time independent non-degenerate perturbation theory, time independent degenerate perturbation theory and time dependent perturbation theory.

The progressive tax system and progressive taxation in general relates to a situation in which the proportion of income earned through taxation (tax rate) increases with

This exercise sheet aims to assess your progress and to explicitly work out more details of some of the results proposed in the previous lectures. The solutions to this assignment

This exercise sheet aims to assess your progress and to explicitly work out more details of some of the results proposed in the

This exercise sheet aims to assess your progress and to explicitly work out more details of some of the results proposed in the