special code with lists no longer necessary, use sets
authornipkow
Sat, 11 Aug 2012 11:31:05 +0200
changeset 48765 fb1ed5230abc
parent 48764 4fe0920d5049
child 48766 553ad5f99968
special code with lists no longer necessary, use sets
src/HOL/IMP/Collecting_Examples.thy
src/HOL/IMP/Collecting_list.thy
src/HOL/ROOT
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/HOL/IMP/Collecting_Examples.thy	Sat Aug 11 11:31:05 2012 +0200
@@ -0,0 +1,40 @@
+theory Collecting_Examples
+imports Collecting
+begin
+
+text{* Tweak code generation to work with sets of non-equality types: *}
+declare insert_code[code del] union_coset_filter[code del]
+lemma insert_code [code]:  "insert x (set xs) = set (x#xs)"
+by simp
+
+text{* Make assignment rule executable: *}
+declare step.simps(2)[code del]
+lemma [code]: "step S (x ::= e {P}) = (x ::= e {(%s. s(x := aval e s)) ` S})"
+by auto
+declare step.simps(1,3-)[code]
+
+text{* The example: *}
+definition "c = WHILE Less (V ''x'') (N 3)
+                DO ''x'' ::= Plus (V ''x'') (N 2)"
+definition c0 :: "state set acom" where "c0 = anno {} c"
+
+definition "show_acom xs = map_acom (\<lambda>S. show_state xs ` S)"
+
+text{* Collecting semantics: *}
+value "show_acom [''x''] (((step {%x. 0}) ^^ 1) c0)"
+value "show_acom [''x''] (((step {%x. 0}) ^^ 2) c0)"
+value "show_acom [''x''] (((step {%x. 0}) ^^ 3) c0)"
+value "show_acom [''x''] (((step {%x. 0}) ^^ 4) c0)"
+value "show_acom [''x''] (((step {%x. 0}) ^^ 5) c0)"
+value "show_acom [''x''] (((step {%x. 0}) ^^ 6) c0)"
+
+text{* Small-step semantics: *}
+value "show_acom [''x''] (((step {}) ^^ 0) (step {%x. 0} c0))"
+value "show_acom [''x''] (((step {}) ^^ 1) (step {%x. 0} c0))"
+value "show_acom [''x''] (((step {}) ^^ 2) (step {%x. 0} c0))"
+value "show_acom [''x''] (((step {}) ^^ 3) (step {%x. 0} c0))"
+value "show_acom [''x''] (((step {}) ^^ 4) (step {%x. 0} c0))"
+value "show_acom [''x''] (((step {}) ^^ 5) (step {%x. 0} c0))"
+
+
+end
--- a/src/HOL/IMP/Collecting_list.thy	Fri Aug 10 22:25:45 2012 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,37 +0,0 @@
-theory Collecting_list
-imports ACom
-begin
-
-subsection "Executable Collecting Semantics on lists"
-
-fun step :: "state list \<Rightarrow> state list acom \<Rightarrow> state list acom" where
-"step S (SKIP {P}) = (SKIP {S})" |
-"step S (x ::= e {P}) =
-  (x ::= e {[s(x := aval e s). s \<leftarrow> S]})" |
-"step S (c1; c2) = step S c1; step (post c1) c2" |
-"step S (IF b THEN c1 ELSE c2 {P}) =
-   IF b THEN step [s \<leftarrow> S. bval b s] c1 ELSE step [s\<leftarrow>S. \<not> bval b s] c2
-   {post c1 @ post c2}" |
-"step S ({Inv} WHILE b DO c {P}) =
-  {S @ post c} WHILE b DO (step [s\<leftarrow>Inv. bval b s] c) {[s\<leftarrow>Inv. \<not> bval b s]}"
-
-
-text{* Examples: *}
-
-definition "c = WHILE Less (V ''x'') (N 3)
-                DO ''x'' ::= Plus (V ''x'') (N 2)"
-definition "c0 = anno [] c"
-
-definition "show_acom xs = map_acom (map (show_state xs))"
-
-
-text{* Collecting semantics: *}
-
-value "show_acom [''x''] (((step [<>]) ^^ 6) c0)"
-
-
-text{* Small step semantics: *}
-
-value "show_acom [''x''] (((step []) ^^ 5) (step [<>] c0))"
-
-end
--- a/src/HOL/ROOT	Fri Aug 10 22:25:45 2012 +0200
+++ b/src/HOL/ROOT	Sat Aug 11 11:31:05 2012 +0200
@@ -92,7 +92,7 @@
     VC
     HoareT
     Collecting1
-    Collecting_list
+    Collecting_Examples
     Abs_Int_Tests
     Abs_Int1_parity
     Abs_Int1_const