object oriented rules and inheritance

70
Object Oriented Rules and Inheritance Fabrício Teles & Marcos Aurélio, August 2006

Upload: tracey

Post on 30-Jan-2016

47 views

Category:

Documents


0 download

DESCRIPTION

Object Oriented Rules and Inheritance. Fabrício Teles & Marcos Aurélio, August 2006. Outline. Purely Relational Rule Languages x Purely Object Oriented Languages Hybrid Object Oriented Rule Languages Inheritance Taxonomy Yang’s Inheritance Postulates - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Object Oriented Rules and Inheritance

Object Oriented Rules and Inheritance

Fabrício Teles & Marcos Aurélio, August 2006

Page 2: Object Oriented Rules and Inheritance

Outline

• Purely Relational Rule Languages x Purely Object Oriented Languages

• Hybrid Object Oriented Rule Languages

• Inheritance Taxonomy

• Yang’s Inheritance Postulates

• CHORD: Extending CHR with High-Order Object Oriented Constraints

• Case Study: Triangram

Page 3: Object Oriented Rules and Inheritance

Knowledge Representation and Rule Based Languages

• Strong points– provides built-in FOL deduction with negation as failure

• the most powerful and versatile inference mechanism

• with formal semantics• provides bases for implementation

of other mechanisms like abduction, induction, planning, non-monotonic reasoning

– uses rules that:• are intuitive and modular• preserve the truth (detachment)• can be acquired by machine

learning

• Weak points– non-intuitive codification of the

terminological and procedural knowledge

– poor facility to structure complex entities

– limitations of the tools and methodologies of distributed development on a large scale

– poor standardization– few non-AI computational services,

libraries available for reuse – limited interoperability with other

languages

Page 4: Object Oriented Rules and Inheritance

Knowledge Representation and Rule Based Languages

• Rules often represent expert knowledge in a natural way (If...Then)

• Rules represent modular knowledge

X Y = ( X) Y =

Y = ( X) Y = X

Page 5: Object Oriented Rules and Inheritance

Knowledge Representation and Object Oriented Languages

• Strong points– intuitive codification of the

terminological and procedural knowledge

– facilities to structure complex entities – tools and methodologies of

distributed development on a large scale consolidated and very spread out

– API for the most varied computational services and languages

– emphasis in the standardization, interoperability and reuse

• Weak points– no built-in general purpose inference

machine– any mechanism of inference beyond

inheritance must be implemented from scratch

– codifies behaviors procedurally – no techniques to learn objects from

data – neither complete nor standard

declarative formal semantics

Page 6: Object Oriented Rules and Inheritance

Hybrid Object OrientedRule Languages

Reasoning Requirements:Reasoning Requirements:• Declarative Language• Predicates with logical variables• Automatic deduction • Formal semantics • Computational completeness

OO Requirements:OO Requirements:• Object identity• Complex Objects• Classes • Encapsulation• Inheritance • Overriding and Overloading

Hybrid Rules + ObjectsHybrid Rules + Objects

Page 7: Object Oriented Rules and Inheritance

Rules and objects: how

integrate?

Rule Based Systems

Rules Base

f1(...,X,...)...fn(...,X,...) f0(...,X,...)

Fact Base

f1(...,a,...) fn(...,a,...) f0(...,a,...)f1(...,b,...) fn(...,c,...) f0(...,d,...)

Object Oriented Systems

Classes Hierarchy

Cn

Ani: Cnq

Mnj:

{while ... do ... if ... then ... else ... }

Cp

Api: Cpk

Mpj:

{while ... do ... if ... then ... else ... }

Cm

Ami: Cmr

Mmj:

{while ... do ... if ... then ... else ... }

Object Base

Opi

Api: Opk

Omj

Ami: Omr

Opmk

Ami: Omr

Page 8: Object Oriented Rules and Inheritance

Integrating rules with objects:syntactic alternatives

• Hybrid system = object oriented system in which :

– procedural methods of the classes are substituted by encapsulated rules bases, or

• Hybrid system = rule based system in which

– instances of logical terms in the facts base are substituted by:• objects instances of a hierarchy of classes

– logical terms in the premises and conclusions of the rules are substituted by:

• object patterns with logical variables in the place of:– object names and attribute values– possibly also name of classes and attributes

Page 9: Object Oriented Rules and Inheritance

Substitute procedural methodsby encapsulated rule bases

Classes Hierarchy

Cn

Ani: Cnq

Mnj:

Cp

Api: Cpk

Mpj:

Cm

Ami: Cmr

Mmj:

fpj1(...,X,...)...fpjn(...,X,...) fpn0(...,X,...)

fnj1(...,X,...)...fnjn(...,X,...) fnn0(...,X,...)

fmj1(...,X,...)...fmjn(...,X,...) fmn0(...,X,...)

Object Base

Opi

Api: Opk

Omj

Ami: Omr

Opmk

Ami: Omr

Page 10: Object Oriented Rules and Inheritance

Substitutefact base byobject base

Rules Base

f1(...,X,...)...fn(...,X,...) f0(...,X,...)

Classes Hierarchy

Cn

Ani: Cnq

Mnj:

{while ... do ... if ... then ... else ... }

Cp

Api: Cpk

Mpj:

{while ... do ... if ... then ... else ... }

Cm

Ami: Cmr

Mmj:

{while ... do ... if ... then ... else ... }

Object Base

Opi

Api: Opk

Omj

Ami: Omr

Opmk

Ami: Omr

Page 11: Object Oriented Rules and Inheritance

F-Logic

• Frame Logic is a deductive object oriented database language

• Syntactical integration between Object Oriented Paradigm and Rules

• Combines rules’ expressivity and declarative semantics with object oriented concepts.

• Implements Structural and Behavioral Inheritance with support for Single-source Multiple Inheritance

• Flora is an implementation for F-logic over XSB Prolog

Page 12: Object Oriented Rules and Inheritance

Flora Metamodel

FLP

HLPGLP

DLP

STLP

STFLPFrame Logic Programming

General Logic Programming

Hilog Logic Programming

Definite Logic Programming

Sequential Transaction Frame Logic Programming

Sequential Transaction Logic Programming

Page 13: Object Oriented Rules and Inheritance

HiLog Metamodel

closure(R)(X,Y) :- R(X,Y).closure(R)(X,Y) :- R(X,Z), closure(R)(Z,Y).

Page 14: Object Oriented Rules and Inheritance

F-Logic Metamodel

john : person, john[age -> 31], john[children ->> {bob,mary}]

john : person[age -> 31, children ->> {bob,mary}]

Page 15: Object Oriented Rules and Inheritance

F-Logic Metamodel

john.age = 31, john..children = bob, john..children = mary

Page 16: Object Oriented Rules and Inheritance

F-Logic Metamodel

dog1 : dog.cat1 : cat.

InstanceFAtom

Page 17: Object Oriented Rules and Inheritance

F-Logic Metamodel

dog :: mammal.mammal :: animal.

SubCIassFAtom

Page 18: Object Oriented Rules and Inheritance

F-Logic Metamodel

dog[name => string].cat[name *=> string].dog[children =>> dog].cat[children *=>> cat].

AttributeSignatureSpecification

Page 19: Object Oriented Rules and Inheritance

F-Logic Metamodel

dog[name -> “jerry”].cat[name *-> “tom”].dog[children ->> d1].cat[children *->> c1].

AttributeValueSpecification

Page 20: Object Oriented Rules and Inheritance

F-Logic Metamodel

dog[getName()=> string].cat[getName()*=> string].dog[getChildren() =>> dog].cat[getChildren() *=>> cat].

MethodSignatureSpecification

Page 21: Object Oriented Rules and Inheritance

F-Logic Metamodel

dog[getName()-> “tom”].cat[getName()*-> “jerry”].dog[getChildren()->> d1].cat[getChildren()*->> c1].

MethodValueSpecification

Page 22: Object Oriented Rules and Inheritance

F-Logic OO Concepts

F-Logic

X::Y

X:Y

C[M->V]

C[M->>V]

C[M=>V]

C[M=>>V]

C[M*->V]

C[M*->>V]

C[M*=>V]

C[M*=>>V]

Taxonomic F-Atom

SignatureSpecification

ValueSpecification

Multiplicity: multi

Multiplicity: single

Inheritable

Non-Inheritable

Page 23: Object Oriented Rules and Inheritance

F-Logic Program Example with Rules

X:irregularPolygon :- X:triangle[side->>{S1,S2}] and

tnot(S1 = S2) and S1.length =\= S2.length.

X[hypotenuse->Hypotenuse] :- X:triangle and X..triangleSide[position->base, side->Base] and X..triangleSide[position->left, side->Left] and X..triangleSide[position->right, side->Right] and

if (Base.length > Left.length and Base.length > Right.length) then Hypotenuse = Base else if Left.length > Right.length then Hypotenuse = Left else Hypotenuse = Right.

Triangram: Rule – Segment Adjacency

S[adjacent->>X] :- X:segmentLine, X[adjacent->>S].

Triangram: Rules - Poligon Regularity

Page 24: Object Oriented Rules and Inheritance

Inheritance Taxonomy (1/4)

Structural

Inheritance

Behavioral

Signatures Values Code

*Non-monotonic reasoning in FLORA-2, Kifer, 2005

flower[petalColorcolor] mary : flowermary[petalColorcolor]

engineer[salary(2009)*5000] john:engineerjohn[salary(2009)5000]

code engineer[salary(X)*V]:-V=X*2 john:engineer john[salary(X)V]:-V=X*2

Page 25: Object Oriented Rules and Inheritance

Code Inheritance Example• RulesR1 @ softDept[bonus()*->B] :- softDept[total*->T], B = T * 100.R2 @ code softDept[bonus1()*->B] :- softDept[total*->T], B = T * 100.

• Factsjohn : softDeptsoftDept[total*->10].john[total->30].

?- john[bonus()->B].B = 1000.

?- john[bonus1()->B].B = 3000.

john[bonus()->1000]

john:softDept softDept[bonus()*->1000]

softDept[total*->10] R1

john[bonus()->3000]

john[total->30] john[bonus1()->B] :- john[total->T], B=T*100.

john : softDept R2

Page 26: Object Oriented Rules and Inheritance

Inheritance Taxonomy (2/4)

Inheritance

Monotonic Non-monotonic

class1[att1*color] class2[att1*tree] class2::class1 obj:class2[att1value]value : color value : tree

class1[att1*color] class2[att1*integer] class2::class1 obj:class2obj[att1integer]

Page 27: Object Oriented Rules and Inheritance

Inheritance Taxonomy (3/4)

Inheritance

Simple Multiple

Single Source Multiple Source

Source Based Value Based

flower[petalColorcolor] mary : flowermary[petalColorcolor]

quaker[policy*pacifist] republican[policy*hawk] nixon : quaker nixon : republican nixon.policy = unknown

quaker[policy*pacifist] republican[policy*pacifist] nixon : quaker nixon : republican nixon[policy*->pacifist]

human[legs*2] police[hasGun*true] shaft:police shaft:humanshaft[legs2] shaft[hasGuntrue]

Page 28: Object Oriented Rules and Inheritance

Inheritance Taxonomy (4/4)

Inheritance

w/Overriding

wo/Overriding

elephant[color*gray] royalElephant[color*white] royalElephant :: elephant clyde : royalElephantclyde[colorwhite]

elephant[color*gray] royalElephant[color*white] royalElephant :: elephant clyde : royalElephant false

elephant[color*gray] royalElephant[color*white] royalElephant :: elephant clyde : royalElephantclyde[colorwhite] clyde[colorgray] white = gray

Page 29: Object Oriented Rules and Inheritance

Source x Value Based Multiple Inheritance

• Source-based: c2..m and c3..m cancel each other regardless of the set of values

• Value-based: c2..m and c3..m do not cancel each other when they return the same set of values (since there is no real conflict)

c2

+m[0..*] = {x0,x1,...}

c3

+m[0..*] = {y0,y1,...}

c1

Page 30: Object Oriented Rules and Inheritance

Inheritance and Negation

• Non-Monotonic Inheritance (NMI) is a form of default reasoning,

• Thus, in order to provide semantics and implement inheritance we can reuse another form of default reasoning: Negation As Failure (NAF)

• F-Logic programs inheritance semantics reuses General Logic Programs' Well-Founded Semantics for NAF

• Flora implements F-logic inheritance by reusing SLG resolution of XSB Prolog

Page 31: Object Oriented Rules and Inheritance

Yang’s Postulates

• Embodies the common intuition behind non-monotonic multiple inheritance

• An object model for some F-logic program is an interpretation for every F-atom under a three-valued semantics

Page 32: Object Oriented Rules and Inheritance

Main Concepts

• Inheritance Contextsc[m] is an inheritance context for o if o is a member of class c

and mv is locally defined at c for some value v

• Local contexts[m] is a local context if is a fact or if it is derived through some rule

• Overridingthe inheritance context s[m] overrides c[m] for o if c≠s and s::c

• Inheritance Candidatesc[m] is an inheritance candidate for o if it is an inheritance context

which is not overriden by any other inheritance context

• Inheritance ConflictAn inheritance conflict occurs when there is more than one

inheritance candidate for inheriting some field m to o

Page 33: Object Oriented Rules and Inheritance

Main Concepts

• Each concept previously defined can be:– Strong

Some concept is “strong” if all of its preconditions are true.

– WeakSome concept is “weak” if some of its preconditions

is undefined.

Page 34: Object Oriented Rules and Inheritance

Example

quaker[policy*pacifist] republican[policy*hawk] party[policy*->pacifist]

quaker :: party republican :: partynixon : quaker nixon : republican

________________________________________________________

Inheritance Contexts:

• party[policy]-quaker• party[policy]-republican• party[policy]-nixon• quaker[policy]-nixon• republican[policy]-nixon

Local Contexts:

• party[policy]• quaker[policy]• republican[policy]

Overriding:

• quaker[policy] overrides party[policy]• republican[policy] overrides party[policy]

Inheritance Candidates:

• quaker[policy]-nixon• republican[policy]-nixon

Inheritance Conflict:

• quaker[policy]-nixon and republican[policy]-nixon

Page 35: Object Oriented Rules and Inheritance

Translation Schema

• Transforms every FLP F into a GLP G such that:– WFS(G) OptimisticObjectModel (F)

• Two parts:– Transformation rules, each one rewriting an

FLP fragment into a corresponding GLP fragment

– Trailer GLP rules, concatenated at the end of the transformation result

Page 36: Object Oriented Rules and Inheritance

Translation Schema

Page 37: Object Oriented Rules and Inheritance

Translation Schema – Trailer Rules

Page 38: Object Oriented Rules and Inheritance

X:irregularPolygon :- X:triangle[side->>S1[length->L1], side->>S2[length->L12]], S1=\=S2, L1 =\= L2.

isa(X,irregularPolygon) :- isa(X,triangle), mvd(X,side,S1), mvd(X,side,S2), fd(S1,length, L1), fd(S2, length, L2), S1=\=S2, L1=\=L2.

Page 39: Object Oriented Rules and Inheritance

CHORD:Extending CHR with High-Order

Object Oriented Constraints

Page 40: Object Oriented Rules and Inheritance

CHORD Metamodel

Page 41: Object Oriented Rules and Inheritance

Reusing Yang’s Approach on CHORD

• Translate the initial set of CHORD rules into a set of CHR rules, transforming each F-atom in some special CHR predicate

• Attach some trailer rules implementing OO semantics

Page 42: Object Oriented Rules and Inheritance

Current Implementation

• Current implementation supports only:– F-Atoms and conjunctive F-molecules – F-Atoms are only allowed as rule defined

constraints

Page 43: Object Oriented Rules and Inheritance

Trailer Rules

• Alter normal CHR execution:– insert inheritance steps between constraint

simplification stepsNormalCHR

ConstraintSimplification!

Page 44: Object Oriented Rules and Inheritance

CHORD Runtime State Machine

Constraint Simplification

PropagateClass

Structure

PropagateInheritanceCandidates

ProcessOverriding

BlockMultiple-source

Inheritance

InheritCandidates

RemoveCandidates

Page 45: Object Oriented Rules and Inheritance

Example

GOAL: quaker[policy*pacifist], republican[policy*hawk, count*7],

party[policy*->pacifist], quaker :: party, republican :: party, nixon : quaker, nixon : republican

Page 46: Object Oriented Rules and Inheritance

CHORD Runtime State Machine

Constraint Simplification

PropagateClass

Structure

PropagateInheritanceCandidates

ProcessOverriding

BlockMultiple-source

Inheritance

InheritCandidates

RemoveCandidates

Applies user rules, as in CHR

There are no rules to fire

CONSTRAINT STORE

quaker[policy*pacifist], republican[policy*hawk], republican[count*7], party[policy*->pacifist], quaker :: party, republican :: party, nixon : quaker, nixon : republican

Page 47: Object Oriented Rules and Inheritance

CHORD Runtime State Machine

Constraint Simplification

PropagateClass

Structure

PropagateInheritanceCandidates

ProcessOverriding

BlockMultiple-source

Inheritance

InheritCandidates

RemoveCandidates

Propagates class structures, i.e.:

a::b, b::c a::c

CONSTRAINT STORE

quaker[policy*pacifist], republican[policy*hawk], republican[count*7], party[policy*->pacifist], quaker :: party, republican :: party, nixon : quaker, nixon : republican nixon : party

Page 48: Object Oriented Rules and Inheritance

CHORD Runtime State Machine

Constraint Simplification

PropagateClass

Structure

PropagateInheritanceCandidates

ProcessOverriding

BlockMultiple-source

Inheritance

InheritCandidates

RemoveCandidates

Calculate exhaustive list of

inheritance candidates,

without taking overriding into

consideration

CONSTRAINT STORE

quaker[policy*pacifist], republican[policy*hawk], republican[count*7], party[policy*->pacifist], quaker :: party, republican :: party, nixon : quaker, nixon : republican nixon : party candidate_ifd(nixon,republican,count) candidate_ifd(nixon,quaker,policy) candidate_ifd(nixon,republican,policy) candidate_ifd(nixon,party,policy) candidate_ifd(republican,party,policy) candidate_ifd(quaker,party,policy)

Page 49: Object Oriented Rules and Inheritance

CHORD Runtime State Machine

Constraint Simplification

PropagateClass

Structure

PropagateInheritanceCandidates

ProcessOverriding

BlockMultiple-source

Inheritance

InheritCandidates

RemoveCandidates

Removes overriden

inheritance

candidates CONSTRAINT STORE

quaker[policy*pacifist], republican[policy*hawk], republican[count*7], party[policy*->pacifist],quaker :: party, republican :: party, nixon : quaker, nixon : republican nixon : partycandidate_ifd(nixon,republican,count)candidate_ifd(nixon,quaker,policy)candidate_ifd(nixon,republican,policy)candidate_ifd(nixon,party,policy)candidate_ifd(republican,party,policy)candidate_ifd(quaker,party,policy)

Page 50: Object Oriented Rules and Inheritance

CHORD Runtime State Machine

Constraint Simplification

PropagateClass

Structure

PropagateInheritanceCandidates

ProcessOverriding

BlockMultiple-source

Inheritance

InheritCandidates

RemoveCandidates

Removes inheritance Candidates causing multiple inheritance conflicts

CONSTRAINT STORE

quaker[policy*pacifist], republican[policy*hawk], republican[count*7], party[policy*->pacifist],quaker :: party, republican :: party, nixon : quaker, nixon : republican nixon : partycandidate_ifd(nixon,republican,count)candidate_ifd(nixon,quaker,policy)candidate_ifd(nixon,republican,policy)

Page 51: Object Oriented Rules and Inheritance

CHORD Runtime State Machine

Constraint Simplification

PropagateClass

Structure

PropagateInheritanceCandidates

ProcessOverriding

BlockMultiple-source

Inheritance

InheritCandidates

RemoveCandidates

Define remaining candidates as localDefinitions

CONSTRAINT STORE

quaker[policy*pacifist], republican[policy*hawk], republican[count*7], party[policy*->pacifist],quaker :: party, republican :: party, nixon : quaker, nixon : republican nixon : partynixon[count7]

Page 52: Object Oriented Rules and Inheritance

CHORD Runtime State Machine

Constraint Simplification

PropagateClass

Structure

PropagateInheritanceCandidates

ProcessOverriding

BlockMultiple-source

Inheritance

InheritCandidates

RemoveCandidates

Remove remaining intermediate helperconstraints

CONSTRAINT STORE

quaker[policy*pacifist], republican[policy*hawk], republican[count*7], party[policy*->pacifist],quaker :: party, republican :: party, nixon : quaker, nixon : republican nixon : partynixon[count7]

Page 53: Object Oriented Rules and Inheritance

CHORD Runtime State Machine

• Each state is associated to a sub-rule base associated with a part of the trailer

• Constraint Simplification state is associated to user rules and goal

• Since we can not control the order of the execution of the rules, we need some special strategy in order to implement state machines in CHR

Page 54: Object Oriented Rules and Inheritance

Implementing State Machines in CHRD

1) Associate each state to an unique constraint name

Deduction run_program(X)

PropagateClass

Structureclass_structure()

PropagateInheritanceCandidates

propagate_candidates()

ProcessOverriding

overriding()

BlockMultiple-source

Inheritance

multiple_inheritance_blocking()

InheritCandidates

inherit_candidates()

RemoveCandidates

clean_mvd_candidates()

Page 55: Object Oriented Rules and Inheritance

Implementing State Machines in CHRD

2) Attach to each rule head of each state rule base the constraint associated to the state

X::Z, Z::Y ==> X Y | X::Y.

S::C, O:S ==> O:C.

O:C, C[M*=>R] ==> O[M=>R].

PropagateClass

Structure

X::Z, Z::Y, class_structure() ==> X Y | X::Y.

S::C, O:S, class_structure() ==> O:C.

O:C, C[M*=>R], class_structure() ==> O[M=>R].

Page 56: Object Oriented Rules and Inheritance

Implementing State Machines in CHRD

3) For each state rule base, add an simplification rule to simulate state transitions(this rule should be the last one in state rule base)

class_structure() <=> propagate_candidates().

Page 57: Object Oriented Rules and Inheritance

Implementing State Machines in CHRD

X::Z, Z::Y, class_structure() ==> X Y | X::Y.

S::C, O:S, class_structure() ==> O:C.

O:C, C[M*=>R], class_structure() ==> O[M=>R].

class_structure() <=> propagate_candidates().

Page 58: Object Oriented Rules and Inheritance

Case Study: Triangram

Page 59: Object Oriented Rules and Inheritance

Case Study - Triangram

• Simplification of the known Chinese game, the Tangram

• Tangram– form complex figures using only 7 geometric 2D

figures, without having overlapping between them – It considers only the following types of different parts:

• 5 isosceles triangles (2 small ones, 1 medium and 2 great ones)

• 1 square• 1 parallelogram

Page 60: Object Oriented Rules and Inheritance

Case Study - Triangram

• Exemplo: Tangram

Page 61: Object Oriented Rules and Inheritance

Case Study - Triangram

• Triangram– Basic parts are only of a type: triangles– Uses three types of triangles

Page 62: Object Oriented Rules and Inheritance

Case Study - Triangram

• Triangram– The objective is to form geometric figures

from the basic types of triangles– It's only allowed to form a restricted number of

types of figures: the straight hexagons, pentagons and the quadrilaterals

Page 63: Object Oriented Rules and Inheritance

Case Study - Triangram

• UML/OCL– Representation of the world: convex polygons

Page 64: Object Oriented Rules and Inheritance

Case Study - Triangram

• UML/OCL– Representation of the world: triangle

Page 65: Object Oriented Rules and Inheritance

Case Study - Triangram

• Implementation– 28 CHORD rules

• The largest one has 19 contraints on its head

– About 125 constraints on goal – Average instances of the problem last about

1h to run

Page 66: Object Oriented Rules and Inheritance

Case Study - Triangram

• Implementation– Goal

• Scenary being tested• Class hierarchy• Classes signatures

– Rules• Invariants• Methods

– Query propagation rules with the F-Atom of the method in the body of the rule and pre-conditions in the head

– Transactional simpagation rules with pre-conditions in the head, removals in simplificateHead and pos-conditions in the body

Page 67: Object Oriented Rules and Inheritance

Case Study - Triangram

scaleneTriangle::triangle, isoscelesTriangle::triangle, equilateralTriangle::isoscelesTriangle, ...

CHORD Implementation - Goal

main() <=> true | ...

Class Hierarchy

tri1 : equilateralTriangle [side ->> s11 [ adjacent ->> s12,

adjacent ->> s13, length -> 3 ],

... ],

...

Scenary being tested

triangle[side *=>> segmentLine, triangleSide *=>> triangleSide, hypotenuse *=> segmentLine], ...

Class signatures

Page 68: Object Oriented Rules and Inheritance

Case Study - Triangram

...

X:segmentLine[adjacent->>S] ==> true | S:segmentLine[adjacent->>X].

X:triangle, X[side->>S1], X[side->>S2], S1[length->L1], S2[length->L2] ==> ne(S1,S2), L1 = L2 | X:regularPolygon.

...

Invariants

Page 69: Object Oriented Rules and Inheritance

Case Study - Triangram

Query Methods

...

Pol1 : rectangle [ side ->> SidePol1[ length -> L, adjacent ->> A1[ length -> LA1 ] ],

parts ->> P1,parts ->> P2 ],

Pol2 : isoscelesTriangle [ triangleSide ->> TS1[ side -> SidePol2 [ length -> L,

adjacent ->> A2 [length -> LA1 ] ], position -> base ] ]

==> ne(P1,Pol2), ne(P2,Pol2) |Pol1[isCompatible(Pol2, SidePol1, SidePol2)->void].

...

Page 70: Object Oriented Rules and Inheritance

Case Study - Triangram

Transactional Methods

...Pol11:triangle[isCompatible(Pol2, SidePol1, SidePol2)->void], Pol2 : triangle, ... \

A11[adjacent ->> SidePol1], A12[adjacent ->> SidePol1],A21[adjacent ->> SidePol2], A22[adjacent ->> SidePol2]

==> A11 != A12, A21 != A22

|A11[adjacent ->> A22], A12[adjacent ->> A21],A21[adjacent ->> A12], A22[adjacent ->> A11],

Pol3 : rectangle[side ->> {A11,A12,A21,A22}, parts ->> {Pol1,Pol2}],

...