1

I have the following Formula in First Order Logic.

forAll a:A | forAll b :B | if a.r1=b then a.r2=b

simply, for all objects of type A, and for all objects of type B, if they are related by r1 then they are related by r2 as well.

Here is the Class diagram:

enter image description here

Can somebody provide the OCL representation of the above formula please.

qartal
  • 2,024
  • 19
  • 31

2 Answers2

1

I don't have a convenient way to test this, but I think the syntax is r1->forall(i | r2->exists(i)).

Possibly more simply, if you just want to say that r1 is a subset of r2, you can just declare that.

Jim L.
  • 6,177
  • 3
  • 21
  • 47
  • r1 is a reference not a class. It can not be used as a set in OCL (to the best of my knowledge) as you wrote it here (that is, 'r1->forall' is not an acceptable syntax) – qartal Aug 13 '15 at 18:47
  • 1
    Just write it like `context A: inv: self.r1->forAll(i | self.r2->exists(i))` that solves the syntax issue. – mike Dec 15 '17 at 09:49
0

The question in answered here.

I repeat the answer to follow the stack overflow rule:

A.allInstances()->forAll(a | B.allInstances()->forAll(b | a.r1=b implies 
a.r2=b))

This seems very bulky to me! but it seems what it is!

qartal
  • 2,024
  • 19
  • 31
  • The use of `allInstances()` is strongly discouraged, since it has bad performance (remember: OCL can also be executed). Rather use `context A: inv:` and within that use `self`. – mike Dec 15 '17 at 09:52