 
  
  
   
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:
 .
The state variable, t, maps to a set of integers.
 .
The state variable, t, maps to a set of integers. .
The set of initial states is the set of states that
map t to a singleton set.  Notice that there are an infinite number
of initial states.
 .
The set of initial states is the set of states that
map t to a singleton set.  Notice that there are an infinite number
of initial states. union(u: set[int])/ok(), card()/ok(int)
  union(u: set[int])/ok(), card()/ok(int)   
  =
  =
1
unionĒ(u: set[int])/ok() pre

post

card()/ok(int)
pre true
post

Suppose I want to show the property that the size of the FatSet t is always greater than or equal to 1:
  
 
Here's an informal proof:
 (i.e., the invariant holds in the pre-state), and
   (i.e., the invariant holds in the pre-state), and (i.e., the post-condition holds in the pre- and post-states)
  (i.e., the post-condition holds in the pre- and post-states)
 .  This is true since
taking the union of two non-empty sets (t and u) is a non-empty
set,
whose size is
 .  This is true since
taking the union of two non-empty sets (t and u) is a non-empty
set,
whose size is   .
 . (i.e., the invariant holds in the pre-state), and
  (i.e., the invariant holds in the pre-state), and (i.e., the post-condition holds in the pre- and post-states)
  (i.e., the post-condition holds in the pre- and post-states)
 .  This is true since
t' = t and t's size is
 .  This is true since
t' = t and t's size is   .
 .
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

post

 (where i is the argument to delete)
then the size of t' would be 0.
 
(where i is the argument to delete)
then the size of t' would be 0.
 
  
 