| 
48765
 | 
     1  | 
theory Collecting_Examples
  | 
| 
 | 
     2  | 
imports Collecting
  | 
| 
 | 
     3  | 
begin
  | 
| 
 | 
     4  | 
  | 
| 
 | 
     5  | 
text{* Tweak code generation to work with sets of non-equality types: *}
 | 
| 
 | 
     6  | 
declare insert_code[code del] union_coset_filter[code del]
  | 
| 
 | 
     7  | 
lemma insert_code [code]:  "insert x (set xs) = set (x#xs)"
  | 
| 
 | 
     8  | 
by simp
  | 
| 
 | 
     9  | 
  | 
| 
51040
 | 
    10  | 
text{* In order to display commands annotated with state sets,
 | 
| 
 | 
    11  | 
states must be translated into a printable format as lists of pairs,
  | 
| 
 | 
    12  | 
for a given set of variable names. This is what @{text show_acom} does: *}
 | 
| 
 | 
    13  | 
  | 
| 
 | 
    14  | 
definition show_acom ::
  | 
| 
 | 
    15  | 
  "vname list \<Rightarrow> state set acom \<Rightarrow> (vname*val)list set acom" where
  | 
| 
 | 
    16  | 
"show_acom xs = map_acom (\<lambda>S. (\<lambda>s. map (\<lambda>x. (x, s x)) xs) ` S)"
  | 
| 
 | 
    17  | 
  | 
| 
 | 
    18  | 
  | 
| 
48765
 | 
    19  | 
text{* The example: *}
 | 
| 
 | 
    20  | 
definition "c = WHILE Less (V ''x'') (N 3)
  | 
| 
 | 
    21  | 
                DO ''x'' ::= Plus (V ''x'') (N 2)"
  | 
| 
50766
 | 
    22  | 
definition C0 :: "state set acom" where "C0 = anno {} c"
 | 
| 
48765
 | 
    23  | 
  | 
| 
 | 
    24  | 
text{* Collecting semantics: *}
 | 
| 
50821
 | 
    25  | 
  | 
| 
 | 
    26  | 
value "show_acom [''x''] (((step {<>}) ^^ 1) C0)"
 | 
| 
 | 
    27  | 
value "show_acom [''x''] (((step {<>}) ^^ 2) C0)"
 | 
| 
 | 
    28  | 
value "show_acom [''x''] (((step {<>}) ^^ 3) C0)"
 | 
| 
 | 
    29  | 
value "show_acom [''x''] (((step {<>}) ^^ 4) C0)"
 | 
| 
 | 
    30  | 
value "show_acom [''x''] (((step {<>}) ^^ 5) C0)"
 | 
| 
 | 
    31  | 
value "show_acom [''x''] (((step {<>}) ^^ 6) C0)"
 | 
| 
 | 
    32  | 
value "show_acom [''x''] (((step {<>}) ^^ 7) C0)"
 | 
| 
 | 
    33  | 
value "show_acom [''x''] (((step {<>}) ^^ 8) C0)"
 | 
| 
48765
 | 
    34  | 
  | 
| 
 | 
    35  | 
text{* Small-step semantics: *}
 | 
| 
50821
 | 
    36  | 
value "show_acom [''x''] (((step {}) ^^ 0) (step {<>} C0))"
 | 
| 
 | 
    37  | 
value "show_acom [''x''] (((step {}) ^^ 1) (step {<>} C0))"
 | 
| 
 | 
    38  | 
value "show_acom [''x''] (((step {}) ^^ 2) (step {<>} C0))"
 | 
| 
 | 
    39  | 
value "show_acom [''x''] (((step {}) ^^ 3) (step {<>} C0))"
 | 
| 
 | 
    40  | 
value "show_acom [''x''] (((step {}) ^^ 4) (step {<>} C0))"
 | 
| 
 | 
    41  | 
value "show_acom [''x''] (((step {}) ^^ 5) (step {<>} C0))"
 | 
| 
 | 
    42  | 
value "show_acom [''x''] (((step {}) ^^ 6) (step {<>} C0))"
 | 
| 
 | 
    43  | 
value "show_acom [''x''] (((step {}) ^^ 7) (step {<>} C0))"
 | 
| 
 | 
    44  | 
value "show_acom [''x''] (((step {}) ^^ 8) (step {<>} C0))"
 | 
| 
48765
 | 
    45  | 
  | 
| 
 | 
    46  | 
end
  |