src/HOL/IMP/Collecting_Examples.thy
author haftmann
Fri, 24 Aug 2018 20:22:14 +0000
changeset 68802 3974935e0252
parent 68778 4566bac4517d
permissions -rw-r--r--
some modernization of notation
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
68778
4566bac4517d improved sectioning
nipkow
parents: 67437
diff changeset
     1
subsection "Collecting Semantics Examples"
4566bac4517d improved sectioning
nipkow
parents: 67437
diff changeset
     2
48765
fb1ed5230abc special code with lists no longer necessary, use sets
nipkow
parents:
diff changeset
     3
theory Collecting_Examples
51566
8e97017538ba improved pretty printing for state set acom
nipkow
parents: 51391
diff changeset
     4
imports Collecting Vars
48765
fb1ed5230abc special code with lists no longer necessary, use sets
nipkow
parents:
diff changeset
     5
begin
fb1ed5230abc special code with lists no longer necessary, use sets
nipkow
parents:
diff changeset
     6
68778
4566bac4517d improved sectioning
nipkow
parents: 67437
diff changeset
     7
subsubsection "Pretty printing state sets"
51566
8e97017538ba improved pretty printing for state set acom
nipkow
parents: 51391
diff changeset
     8
67406
23307fd33906 isabelle update_cartouches -c;
wenzelm
parents: 52019
diff changeset
     9
text\<open>Tweak code generation to work with sets of non-equality types:\<close>
48765
fb1ed5230abc special code with lists no longer necessary, use sets
nipkow
parents:
diff changeset
    10
declare insert_code[code del] union_coset_filter[code del]
fb1ed5230abc special code with lists no longer necessary, use sets
nipkow
parents:
diff changeset
    11
lemma insert_code [code]:  "insert x (set xs) = set (x#xs)"
fb1ed5230abc special code with lists no longer necessary, use sets
nipkow
parents:
diff changeset
    12
by simp
fb1ed5230abc special code with lists no longer necessary, use sets
nipkow
parents:
diff changeset
    13
67406
23307fd33906 isabelle update_cartouches -c;
wenzelm
parents: 52019
diff changeset
    14
text\<open>Compensate for the fact that sets may now have duplicates:\<close>
51566
8e97017538ba improved pretty printing for state set acom
nipkow
parents: 51391
diff changeset
    15
definition compact :: "'a set \<Rightarrow> 'a set" where
8e97017538ba improved pretty printing for state set acom
nipkow
parents: 51391
diff changeset
    16
"compact X = X"
8e97017538ba improved pretty printing for state set acom
nipkow
parents: 51391
diff changeset
    17
8e97017538ba improved pretty printing for state set acom
nipkow
parents: 51391
diff changeset
    18
lemma [code]: "compact(set xs) = set(remdups xs)"
8e97017538ba improved pretty printing for state set acom
nipkow
parents: 51391
diff changeset
    19
by(simp add: compact_def)
8e97017538ba improved pretty printing for state set acom
nipkow
parents: 51391
diff changeset
    20
51698
c0af8bbc5825 reduced duplication
nipkow
parents: 51566
diff changeset
    21
definition "vars_acom = compact o vars o strip"
51566
8e97017538ba improved pretty printing for state set acom
nipkow
parents: 51391
diff changeset
    22
67406
23307fd33906 isabelle update_cartouches -c;
wenzelm
parents: 52019
diff changeset
    23
text\<open>In order to display commands annotated with state sets, states must be
51566
8e97017538ba improved pretty printing for state set acom
nipkow
parents: 51391
diff changeset
    24
translated into a printable format as sets of variable-state pairs, for the
67406
23307fd33906 isabelle update_cartouches -c;
wenzelm
parents: 52019
diff changeset
    25
variables in the command:\<close>
51040
faf7f0d4f9eb tuned state display
nipkow
parents: 50986
diff changeset
    26
52019
a4cbca8f7342 finally: acom with pointwise access and update of annotations
nipkow
parents: 51698
diff changeset
    27
definition show_acom :: "state set acom \<Rightarrow> (vname*val)set set acom" where
a4cbca8f7342 finally: acom with pointwise access and update of annotations
nipkow
parents: 51698
diff changeset
    28
"show_acom C =
a4cbca8f7342 finally: acom with pointwise access and update of annotations
nipkow
parents: 51698
diff changeset
    29
   annotate (\<lambda>p. (\<lambda>s. (\<lambda>x. (x, s x)) ` (vars_acom C)) ` anno C p) (strip C)"
51040
faf7f0d4f9eb tuned state display
nipkow
parents: 50986
diff changeset
    30
faf7f0d4f9eb tuned state display
nipkow
parents: 50986
diff changeset
    31
68778
4566bac4517d improved sectioning
nipkow
parents: 67437
diff changeset
    32
subsubsection "Examples"
51566
8e97017538ba improved pretty printing for state set acom
nipkow
parents: 51391
diff changeset
    33
8e97017538ba improved pretty printing for state set acom
nipkow
parents: 51391
diff changeset
    34
definition "c0 = WHILE Less (V ''x'') (N 3)
48765
fb1ed5230abc special code with lists no longer necessary, use sets
nipkow
parents:
diff changeset
    35
                DO ''x'' ::= Plus (V ''x'') (N 2)"
67437
nipkow
parents: 67406
diff changeset
    36
nipkow
parents: 67406
diff changeset
    37
definition C0 :: "state set acom" where "C0 = annotate (\<lambda>p. {}) c0"
48765
fb1ed5230abc special code with lists no longer necessary, use sets
nipkow
parents:
diff changeset
    38
67406
23307fd33906 isabelle update_cartouches -c;
wenzelm
parents: 52019
diff changeset
    39
text\<open>Collecting semantics:\<close>
50821
nipkow
parents: 50766
diff changeset
    40
67437
nipkow
parents: 67406
diff changeset
    41
value "show_acom (((step {<>}) ^^ 0) C0)"
51566
8e97017538ba improved pretty printing for state set acom
nipkow
parents: 51391
diff changeset
    42
value "show_acom (((step {<>}) ^^ 1) C0)"
8e97017538ba improved pretty printing for state set acom
nipkow
parents: 51391
diff changeset
    43
value "show_acom (((step {<>}) ^^ 2) C0)"
8e97017538ba improved pretty printing for state set acom
nipkow
parents: 51391
diff changeset
    44
value "show_acom (((step {<>}) ^^ 3) C0)"
8e97017538ba improved pretty printing for state set acom
nipkow
parents: 51391
diff changeset
    45
value "show_acom (((step {<>}) ^^ 4) C0)"
8e97017538ba improved pretty printing for state set acom
nipkow
parents: 51391
diff changeset
    46
value "show_acom (((step {<>}) ^^ 5) C0)"
8e97017538ba improved pretty printing for state set acom
nipkow
parents: 51391
diff changeset
    47
value "show_acom (((step {<>}) ^^ 6) C0)"
8e97017538ba improved pretty printing for state set acom
nipkow
parents: 51391
diff changeset
    48
value "show_acom (((step {<>}) ^^ 7) C0)"
8e97017538ba improved pretty printing for state set acom
nipkow
parents: 51391
diff changeset
    49
value "show_acom (((step {<>}) ^^ 8) C0)"
48765
fb1ed5230abc special code with lists no longer necessary, use sets
nipkow
parents:
diff changeset
    50
67406
23307fd33906 isabelle update_cartouches -c;
wenzelm
parents: 52019
diff changeset
    51
text\<open>Small-step semantics:\<close>
51566
8e97017538ba improved pretty printing for state set acom
nipkow
parents: 51391
diff changeset
    52
value "show_acom (((step {}) ^^ 0) (step {<>} C0))"
8e97017538ba improved pretty printing for state set acom
nipkow
parents: 51391
diff changeset
    53
value "show_acom (((step {}) ^^ 1) (step {<>} C0))"
8e97017538ba improved pretty printing for state set acom
nipkow
parents: 51391
diff changeset
    54
value "show_acom (((step {}) ^^ 2) (step {<>} C0))"
8e97017538ba improved pretty printing for state set acom
nipkow
parents: 51391
diff changeset
    55
value "show_acom (((step {}) ^^ 3) (step {<>} C0))"
8e97017538ba improved pretty printing for state set acom
nipkow
parents: 51391
diff changeset
    56
value "show_acom (((step {}) ^^ 4) (step {<>} C0))"
8e97017538ba improved pretty printing for state set acom
nipkow
parents: 51391
diff changeset
    57
value "show_acom (((step {}) ^^ 5) (step {<>} C0))"
8e97017538ba improved pretty printing for state set acom
nipkow
parents: 51391
diff changeset
    58
value "show_acom (((step {}) ^^ 6) (step {<>} C0))"
8e97017538ba improved pretty printing for state set acom
nipkow
parents: 51391
diff changeset
    59
value "show_acom (((step {}) ^^ 7) (step {<>} C0))"
8e97017538ba improved pretty printing for state set acom
nipkow
parents: 51391
diff changeset
    60
value "show_acom (((step {}) ^^ 8) (step {<>} C0))"
48765
fb1ed5230abc special code with lists no longer necessary, use sets
nipkow
parents:
diff changeset
    61
fb1ed5230abc special code with lists no longer necessary, use sets
nipkow
parents:
diff changeset
    62
end