2

Are the following two OCL statements equivalent for some function context?

post: if a > 0 then b < c

post: b < c implies a > 0

a_fan
  • 383
  • 2
  • 22

1 Answers1

2

No.

In OCL, the construct is if ... then ... else ... endif so your first example can only be 'equivalent' to a different syntax error.

The logical operations are rewritable using if constructs, but considerable care is necessary to ensure that the possibilities with null or invalid inputs do not crash the if condition term which must be a 2-valued Boolean.

Christophe
  • 68,716
  • 7
  • 72
  • 138
Ed Willink
  • 1,205
  • 7
  • 8
  • Subsidiary question: if the syntax was correct, and looking at the implication [truth table](https://en.wikipedia.org/wiki/Material_conditional), wouldn't `post: if a > 0 then b < c else true endif` be equivalent to `post: a > 0 implies b < c` or `post: a <= 0 implies b >= c` ? and not `post: b < c implies a > 0`? – Christophe Sep 24 '21 at 17:35
  • Looks plausible. Arguably the use of multiple invaraints (pre/postconditions) is just an editorial choice that improves readbility. Once an implmenetation starts considering avoiding redundancy via Common Subexepression Elimination, it is clear that an efficient evaluation will prioritize and merge the multiples in a single constraint that shares wherever possible. – Ed Willink Apr 28 '22 at 17:26