next up previous
Next: Diverging Counter Up: Invariants Previous: OddCounter

Fat Sets

This example has two purposes. One is to give another example of an invariant. The other is to hint at how state machines are appropriate models of abstract data types, as you might implement in your favorite object-oriented language.

Here is a description of a FatSet abstract data type modeled as a state machine:

Suppose I want to show the property that the size of the FatSet t is always greater than or equal to 1:

tex2html_wrap_inline502

Here's an informal proof:

  1. It's true of all initial states since the size of all singleton sets is 1.
  2. We need to show the invariant is preserved for each of union and card.
    1. (union). Assume
      • u is nonempty (i.e., the pre-condition holds in the pre-state),
      • t's size is tex2html_wrap_inline508 (i.e., the invariant holds in the pre-state), and
      • tex2html_wrap_inline494 (i.e., the post-condition holds in the pre- and post-states)
      Then I need to show that the size of t' is tex2html_wrap_inline508 . This is true since taking the union of two non-empty sets (t and u) is a non-empty set, whose size is tex2html_wrap_inline508 .
    2. (card). Assume
      • t's size is tex2html_wrap_inline508 (i.e., the invariant holds in the pre-state), and
      • tex2html_wrap_inline498 (i.e., the post-condition holds in the pre- and post-states)
      Then I need to show that the size of t' is tex2html_wrap_inline508 . This is true since t' = t and t's size is tex2html_wrap_inline508 .

Notice how awful it would be if I had to write out these proof steps in gory detail!

Two points about this example:

Now, suppose I added a delete action to my FatSet example. Let delete have the following behavior:

1

 deleteĒ(i:int)/ok()

pre tex2html_wrap_inline542

post tex2html_wrap_inline544

Then my invariant would no longer hold because if delete were called in any state where tex2html_wrap_inline546 (where i is the argument to delete) then the size of t' would be 0.


next up previous
Next: Diverging Counter Up: Invariants Previous: OddCounter

Norman Papernick
Mon Mar 18 14:28:12 EST 1996