Upload
zoe-jones
View
212
Download
0
Tags:
Embed Size (px)
Citation preview
Three “Styles” of Explaining Semantics of • “Formal Class Diagrams with Diagram Predicates”
• SOSYM Journal (12 pages)• Full Clafer• Abstract
• “(Standard?) Set Theory and FOL”• Behavioral Clafer submission• Core Clafer + Behavior (2.5 pages)• Abstract
• “Semantics by Example”• A working document + emails• Model instances and evaluations of expressions• Concrete
Formal Class Diagrams with Diagram Predicates
Clafer explained using Formal Class Diagrams
Semantics by Translation to Class Diagrams
Inheritance
Clafer explained using Set Theory and FOL
Improving the Understanding with the
Help of Examples
For a model snippet:- write down an instance as sets and relations- evaluate expressions
Main Idea
Show how the abstract rules are applied to concrete cases
Main Goal
Conventions
```clafer<code here>```
```semantics_S = { S$1, S$2, … }_T = { T$1, T$2, … }T = { (S$1, T$1) , (S$2, T$2) , … }```
```typesSet <op> Relation -> Set
_T = { }T = { (_S, _T) }```
Six Predefined Sets Accessible by Keywords• `root` - the container (parent) of instances of top-level concrete
clafers (`Sing` and its instance `*` in SOSYM)• `clafer` - the (derived) set of all instances of all clafers• `this` - a singleton set containing an instance of the context clafer of a
constraint• `integer` - the set of all integers• `real` - the set of all reals• `string` - the set of all strings
Example 1 - Sets
```claferAlice 1..1Bob 0..1Carol 1..2```
```semanticsroot = { root$0 }_Alice = { Alice$0 }_Bob = { }_Carol = { Carol$0, Carol$1 }clafer = { root$0, Alice$0, Carol$0, Carol$1 }integer = { ..., -1, 0, 1, ... }string = { <all strings> }real = { <all reals> }```
```semanticsroot = { root$0 }_Alice = { Alice$0 }_Bob = { Bob$0 }_Carol = { Carol$0 }clafer = { root$0, Alice$0, Bob$0, Carol$0 }integer = { ..., -1, 0, 1, ... }string = { <all strings> }real = { <all reals> }```
Example 2 – The keyword `this`
• a singleton set containing an instance of the context clafer of a constraint
```claferPerson * [ Phi(this) ] ```
```semantics_Person = { Person$0, Person$1, Person$2 }```
```clafer (incorrect)Person *[ all this : Person |Phi(this) ] ```
```claferPerson *[ all p : Person |Phi(p) ] ```
Relations
• Every clafer defines a set of its instances and a relation from parent to these instances• Top-level concrete clafers are relations from the root
Example 3 – Top-Level Concrete Clafer
```claferPerson *```
```semanticsroot = { root$0 }_ Person = { Person$0, Person$1, Person$2 }
Person = { (root$0, Person$0) , (root$0, Person$1) , (root$0, Person$2) }```
Example 4 – The Operator Join `.`
• `.` performs a relational join and projects out the left column
```claferPerson *[ some (root.Person) ]```
```semanticsroot . Person--------------------------------------------------{ root$0 } . { (root$0, P$0) = { P$0 , (root$0, P$1) , P$1 , (root$0, P$2) } , P$2 }```
```typesSet `.` Relation -> Set```
```semanticsroot = { root$0 }_ Person = { P$0, P$1, P$2 }Person = { (root$0, P$0) , (root$0, P$1) , (root$0, P$2) }```
Example 4’ – The Quantifier `some`
• `some` asserts a non-empty set; the default quantifier
```claferPerson *[ some (root.Person) ]```
```semanticssome ( root . Person )------------------------------------------------------------------------------------some ({ root$0 } . { (root$0, P$0) = some ( { P$0 = True , (root$0, P$1) , P$1 , (root$0, P$2) } ) , P$2 } )```
```types`some` Set -> Boolean```
Example 5 – Nested Concrete Clafers• Nested clafers define relations from their parent instead of `root`
```claferAlice 1..1 Head 1..1```
```semanticsroot = { root$0 }_Alice = {Alice$0 }Alice = { (root$0, Alice$0) }_Head = { Head$0 }Head = { (Alice$0, Head$0) }```
```semantics (incorrect)root = { root$0 }_Alice = { Alice$0 }Alice = { (Head$0, Alice$0) }_Head = { Head$0 }Head = { (root$0, Head$0) }```
Example 5’ – Navigation using `.`
• Nested clafers define relations from their parent instead of `root`
```claferAlice 1..1 Head 1..1[ some (root.Alice.Head) ]```
```semantics( root . Alice ) . Head------------------------------------------------------------({ root$0 } . { (root$0, Alice$0) }) . { (Alice$0, Head$0) } = { Alice$0 } . { (Alice$0, Head$0) } = { Head$0 }```
```typesSet `.` Relation -> Set```
Example 6 – Top-level Abstract Clafers• Derived unions of sets and relations of the extending concrete clafers
```claferabstract PersonAlice : Person 1Team 1 Bob : Person 1 ```
```semanticsTeam = { (root$0, Team$0) }Alice = { (root$0, Alice$0) }Bob = { (Team$0, Bob$0) } _Person = _Alice + _Bob = { Alice$0, Bob$0 }Person = Alice + Bob = { (root$0, Alice$0) , (Team$0, Bob$0) }```
Example 6’ – Instances of an Abstract Clafer
```claferabstract PersonAlice : Person 1Team 1 Bob : Person 1[ some clafer.Person ] ```
```semanticsclafer . Person------------------------------------------------------{ root$0 . { (root$0, Alice$0) = { Alice$0, Alice$0 , (Team$0, Bob$0) } , Bob$0 }, Bob$0, Team$0 } ```
Example 7 – The Operator Domain Restriction `<:`• Removes tuples whose left elements do not belong to the given set
```claferabstract PersonAlice : Person 1Team 1 Bob : Person 1[ some root <: Person ]```
```semanticsroot <: Person----------------------------------------------------------------------------------{ root$0 } <: { (root$0, Alice$0) = { (root$0, Alice$0) } = Alice , (Team$0, Bob$0) }```
```typesSet `<:` Relation -> Relation```
Example 7’ – The Operator Domain Restriction `<:`• Removes tuples whose left elements do not belong to the given set
```claferabstract PersonAlice : Person 1Team 1 Bob : Person 1[ some root.Team <: Person ]```
```typesSet `<:` Relation -> Relation``` ```semantics
(root . Team ) <: Person-----------------------------------------------------------------------------------({ root$0 } . { (root$0, Team$0)}) <: { (root$0, Alice$0) = , (Team$0, Bob$0) } { Team$0 } <: { (root$0, Alice$0) = , (Team$0, Bob$0) } { (Team$0, Bob$0) } = Bob```
Example 8 – Reference Clafers `->`• Each introduces a predefined relation `dref`
```claferabstract PersonAlice : Person 1 age -> integer 1 name -> string 1
boss -> Person 1```
```semantics_age = { age$0 }age = { (Alice$0, age$0) }_name = { name$0 }name = { (Alice$0, name$0) }_boss = { boss$0 }boss = { (root$0, boss$0) }
age_dref = { (age$0, 20) }name_dref = { (name$0, "Alice") }boss_dref = { (boss$0, Alice$0) }```
Example 9 – Asserting Values of References• The operator equality `=`
```claferabstract PersonAlice : Person 1 age -> integer 1 [ this = 20 ] name -> string 1[ root.Alice.name = "Alice" ]```
```typesSet `=` Set -> BooleanRelation `=` Relation -> Boolean```
```semanticsthis . age_dref = 20------------------------------------------{ age$0 } . { (age$0, 20) } = { 20 }```
Example 10 – Inheritance
• A clafer can participate in all relations of all of its superclafers
```claferabstract Person 0..* age -> integer 1
Alice : Person 1 [ this.age = 20 ]Bob : Person 1 [ this.age = 21 ]```
```semantics (context of Alice)this . age . age_dref = {20}---------------------------------------------------------------{Alice$0} . {(Alice$0, age$0) . {(age$0, 20) = {20} , (Bob$0, age$1)} ,(age$1, 21)}```
```semanticsAlice = { (root$0, Alice$0)}Bob = { (root$0, Bob$0) }Person = { (root$0, Alice$0) , (root$0, Bob$0)}
age = { (Alice$0, age$0) , (Bob$0, age$1) }age_dref = { (age$0, 20) , (age$1, 21) }```
```semantics (context of Bob)this . age . age_dref = {21}--------------------------------------------------------------{Bob$0} . {(Alice$0, age$0) . {(age$0, 20) = {21} , (Bob$0, age$1)} , (age$1, 21)} ```
Example 11 – Inheritance from Nested Clafers• Inheritance from a nested clafer must preserve the nesting
```claferabstract Person 0..* Hand 2
Alice : Person 1 left : Hand 1 right : Hand 1```
```semanticsAlice = { (root$0, Alice$0) }left = { (Alice$0, left$0) }right = { (Alice$0, right$0) }```
```clafer (incorrect)abstract Person 0..* Hand 2
severedHand : Hand 1```
```typesPerson = { (root, _Person) }Hand = { (_Person, _Hand) }left = { (_Alice, _left) }```
```semantics (incorrect)severedHand = { (root$0, severedHand$0) }```
Example 11 – Redefinition• Restricting group and clafer cardinality, reference type, and bag to set
```claferabstract A link ->> A *
B : A link : link -> B 1
C : A 2```
```semanticsB = { (root$0, B$0) }Blink = { (B$0, Blink$0) }link_dref = { (Blink$0, B$0) }```
```types_A = { }A = { (root, _A) }_Alink = { }Alink = { (_A, _Alink) }
_B { }B = { (root, _B) }_Blink = { }Blink = { (_B, _Blink) }```
```semantics (incorrect)B = { (root$0, B$0) }Blink = { (B$0, Blink$0) }link_dref = { (Blink$0, C$0) , (Blink$0, C$1) }```
Conclusions
The three ways are complementary
• “Formal Class Diagrams with Diagram Predicates”• Excels in showing structure• Very declarative, instantiation via CDs/ODs
• “Set Theory and FOL”• Excels in showing the abstract rules concisely (descriptive)• Closer to implementation, direct instantiation
• “Semantics by Example”• Excels in case by case analysis of language constructs and corner cases• Conceptually simple, direct instantiation• Lightweight, text-based syntax for day-to-day email communication
Experience
• “Formal Class Diagrams with Diagram Predicates”• Seems complex because
• rich conceptual framework• fully explicit and full scope
• “Set Theory and FOL”• Seems concise but very hard to build mental picture and validate
• “Semantics by Example”• Applied in relational Clafer (Peiyuan) and Clafer in MPS (Eldar, Markus) efforts• Does not require strong formal background but it’s not standalone• Extremely effective