|
Sorting Machine TemplateConcept Sorting_Machine_Template (type entry; max)capacity: integer; ordering £ ); uses integer, boolean, ordering theory;
Family entry_keeper Í cartesian product entry_count: (entry ® N); dispensing: B; exemplar K; definition Total_Entry_Ct (k:entry_keeper): N = ( constraint Total_Entry_Ct £ max_capacity; initialization ensures k.dispensing = false and Total_Entry_Ct = 0;
definition Is_Only_Addition (x: entry; k1, k2: entry_keeper): B = k2.entry_count(x) = k1.entry_keeper(x) + 1 and " y ¹ x, k2.entry_count(y) = k1.entry_count(y); operation add_entry (var x: entry; var k: entry_keeper); requires Total_Entry_Ct < max_capacity and k.dispensing = false; ensures Is_Only_Addition(x,@k,k) and k.dispensing = false;
operation prepare_to_dispense (var k: entry_keeper); requires k.dispensing = false; ensures k.dispensing - true and k.entry_count = @k.entry_count; operation get_a_smallest (var s: entry; var k: entry_keeper); requires k.dispensing = true and Total_Entry_Ct > 0; ensures k.dispensing = true and Is_Only_Addition(s, k, @k) and " x, if x < s, @k.entry_count = 0; operation Total_Entry_Count (k: entry_keeper): integer; ensures Total_Entry_Count = Total_Entry_Ct(k); operation is_dispensing (k: entry_keeper): boolean; ensures is_dispensing = k.dispensing; operation clear(var k: entry_keeper); ensures k.dispensing = false and Total_Entry_Ct = 0; end; |
Last modified: Tuesday, 18-Feb-2003 14:31:20 EST