src/HOL/Library/Executable_Set.thy
author huffman
Wed, 18 Feb 2009 20:14:45 -0800
changeset 29987 391dcbd7e4dd
parent 29110 476c46e99ada
child 30304 d8e4cd2ac2a1
permissions -rw-r--r--
move Polynomial.thy to Library
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
23854
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
     1
(*  Title:      HOL/Library/Executable_Set.thy
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
     2
    ID:         $Id$
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
     3
    Author:     Stefan Berghofer, TU Muenchen
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
     4
*)
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
     5
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
     6
header {* Implementation of finite sets by lists *}
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
     7
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
     8
theory Executable_Set
27487
c8a6ce181805 absolute imports of HOL/*.thy theories
haftmann
parents: 27368
diff changeset
     9
imports Plain "~~/src/HOL/List"
23854
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
    10
begin
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
    11
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
    12
subsection {* Definitional rewrites *}
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
    13
28522
eacb54d9e78d only one theorem table for both code generators
haftmann
parents: 27487
diff changeset
    14
definition subset :: "'a set \<Rightarrow> 'a set \<Rightarrow> bool" where
eacb54d9e78d only one theorem table for both code generators
haftmann
parents: 27487
diff changeset
    15
  "subset = op \<le>"
eacb54d9e78d only one theorem table for both code generators
haftmann
parents: 27487
diff changeset
    16
eacb54d9e78d only one theorem table for both code generators
haftmann
parents: 27487
diff changeset
    17
declare subset_def [symmetric, code unfold]
eacb54d9e78d only one theorem table for both code generators
haftmann
parents: 27487
diff changeset
    18
28939
08004ce1b167 added code equation for subset
haftmann
parents: 28522
diff changeset
    19
lemma [code]: "subset A B \<longleftrightarrow> (\<forall>x\<in>A. x \<in> B)"
28522
eacb54d9e78d only one theorem table for both code generators
haftmann
parents: 27487
diff changeset
    20
  unfolding subset_def subset_eq ..
23854
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
    21
28522
eacb54d9e78d only one theorem table for both code generators
haftmann
parents: 27487
diff changeset
    22
definition is_empty :: "'a set \<Rightarrow> bool" where
eacb54d9e78d only one theorem table for both code generators
haftmann
parents: 27487
diff changeset
    23
  "is_empty A \<longleftrightarrow> A = {}"
eacb54d9e78d only one theorem table for both code generators
haftmann
parents: 27487
diff changeset
    24
eacb54d9e78d only one theorem table for both code generators
haftmann
parents: 27487
diff changeset
    25
definition eq_set :: "'a set \<Rightarrow> 'a set \<Rightarrow> bool" where
eacb54d9e78d only one theorem table for both code generators
haftmann
parents: 27487
diff changeset
    26
  [code del]: "eq_set = op ="
eacb54d9e78d only one theorem table for both code generators
haftmann
parents: 27487
diff changeset
    27
eacb54d9e78d only one theorem table for both code generators
haftmann
parents: 27487
diff changeset
    28
lemma [code]: "eq_set A B \<longleftrightarrow> A \<subseteq> B \<and> B \<subseteq> A"
eacb54d9e78d only one theorem table for both code generators
haftmann
parents: 27487
diff changeset
    29
  unfolding eq_set_def by auto
26816
e82229ee8f43 - Declared subset_eq as code lemma
berghofe
parents: 26312
diff changeset
    30
29107
e70b9c2bee14 code for {x:A. P(x)} and for fold
nipkow
parents: 28939
diff changeset
    31
(* FIXME allow for Stefan's code generator:
e70b9c2bee14 code for {x:A. P(x)} and for fold
nipkow
parents: 28939
diff changeset
    32
declare set_eq_subset[code unfold]
e70b9c2bee14 code for {x:A. P(x)} and for fold
nipkow
parents: 28939
diff changeset
    33
*)
e70b9c2bee14 code for {x:A. P(x)} and for fold
nipkow
parents: 28939
diff changeset
    34
23854
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
    35
lemma [code]:
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
    36
  "a \<in> A \<longleftrightarrow> (\<exists>x\<in>A. x = a)"
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
    37
  unfolding bex_triv_one_point1 ..
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
    38
28939
08004ce1b167 added code equation for subset
haftmann
parents: 28522
diff changeset
    39
definition filter_set :: "('a \<Rightarrow> bool) \<Rightarrow> 'a set \<Rightarrow> 'a set" where
23854
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
    40
  "filter_set P xs = {x\<in>xs. P x}"
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
    41
29107
e70b9c2bee14 code for {x:A. P(x)} and for fold
nipkow
parents: 28939
diff changeset
    42
declare filter_set_def[symmetric, code unfold] 
e70b9c2bee14 code for {x:A. P(x)} and for fold
nipkow
parents: 28939
diff changeset
    43
23854
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
    44
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
    45
subsection {* Operations on lists *}
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
    46
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
    47
subsubsection {* Basic definitions *}
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
    48
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
    49
definition
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
    50
  flip :: "('a \<Rightarrow> 'b \<Rightarrow> 'c) \<Rightarrow> 'b \<Rightarrow> 'a \<Rightarrow> 'c" where
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
    51
  "flip f a b = f b a"
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
    52
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
    53
definition
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
    54
  member :: "'a list \<Rightarrow> 'a \<Rightarrow> bool" where
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
    55
  "member xs x \<longleftrightarrow> x \<in> set xs"
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
    56
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
    57
definition
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
    58
  insertl :: "'a \<Rightarrow> 'a list \<Rightarrow> 'a list" where
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
    59
  "insertl x xs = (if member xs x then xs else x#xs)"
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
    60
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
    61
lemma [code target: List]: "member [] y \<longleftrightarrow> False"
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
    62
  and [code target: List]: "member (x#xs) y \<longleftrightarrow> y = x \<or> member xs y"
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
    63
  unfolding member_def by (induct xs) simp_all
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
    64
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
    65
fun
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
    66
  drop_first :: "('a \<Rightarrow> bool) \<Rightarrow> 'a list \<Rightarrow> 'a list" where
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
    67
  "drop_first f [] = []"
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
    68
| "drop_first f (x#xs) = (if f x then xs else x # drop_first f xs)"
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
    69
declare drop_first.simps [code del]
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
    70
declare drop_first.simps [code target: List]
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
    71
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
    72
declare remove1.simps [code del]
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
    73
lemma [code target: List]:
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
    74
  "remove1 x xs = (if member xs x then drop_first (\<lambda>y. y = x) xs else xs)"
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
    75
proof (cases "member xs x")
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
    76
  case False thus ?thesis unfolding member_def by (induct xs) auto
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
    77
next
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
    78
  case True
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
    79
  have "remove1 x xs = drop_first (\<lambda>y. y = x) xs" by (induct xs) simp_all
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
    80
  with True show ?thesis by simp
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
    81
qed
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
    82
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
    83
lemma member_nil [simp]:
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
    84
  "member [] = (\<lambda>x. False)"
26816
e82229ee8f43 - Declared subset_eq as code lemma
berghofe
parents: 26312
diff changeset
    85
proof (rule ext)
23854
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
    86
  fix x
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
    87
  show "member [] x = False" unfolding member_def by simp
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
    88
qed
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
    89
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
    90
lemma member_insertl [simp]:
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
    91
  "x \<in> set (insertl x xs)"
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
    92
  unfolding insertl_def member_def mem_iff by simp
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
    93
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
    94
lemma insertl_member [simp]:
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
    95
  fixes xs x
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
    96
  assumes member: "member xs x"
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
    97
  shows "insertl x xs = xs"
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
    98
  using member unfolding insertl_def by simp
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
    99
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
   100
lemma insertl_not_member [simp]:
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
   101
  fixes xs x
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
   102
  assumes member: "\<not> (member xs x)"
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
   103
  shows "insertl x xs = x # xs"
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
   104
  using member unfolding insertl_def by simp
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
   105
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
   106
lemma foldr_remove1_empty [simp]:
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
   107
  "foldr remove1 xs [] = []"
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
   108
  by (induct xs) simp_all
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
   109
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
   110
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
   111
subsubsection {* Derived definitions *}
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
   112
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
   113
function unionl :: "'a list \<Rightarrow> 'a list \<Rightarrow> 'a list"
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
   114
where
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
   115
  "unionl [] ys = ys"
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
   116
| "unionl xs ys = foldr insertl xs ys"
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
   117
by pat_completeness auto
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
   118
termination by lexicographic_order
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
   119
26312
e9a65675e5e8 avoid rebinding of existing facts;
wenzelm
parents: 25885
diff changeset
   120
lemmas unionl_eq = unionl.simps(2)
23854
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
   121
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
   122
function intersect :: "'a list \<Rightarrow> 'a list \<Rightarrow> 'a list"
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
   123
where
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
   124
  "intersect [] ys = []"
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
   125
| "intersect xs [] = []"
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
   126
| "intersect xs ys = filter (member xs) ys"
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
   127
by pat_completeness auto
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
   128
termination by lexicographic_order
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
   129
26312
e9a65675e5e8 avoid rebinding of existing facts;
wenzelm
parents: 25885
diff changeset
   130
lemmas intersect_eq = intersect.simps(3)
23854
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
   131
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
   132
function subtract :: "'a list \<Rightarrow> 'a list \<Rightarrow> 'a list"
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
   133
where
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
   134
  "subtract [] ys = ys"
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
   135
| "subtract xs [] = []"
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
   136
| "subtract xs ys = foldr remove1 xs ys"
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
   137
by pat_completeness auto
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
   138
termination by lexicographic_order
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
   139
26312
e9a65675e5e8 avoid rebinding of existing facts;
wenzelm
parents: 25885
diff changeset
   140
lemmas subtract_eq = subtract.simps(3)
23854
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
   141
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
   142
function map_distinct :: "('a \<Rightarrow> 'b) \<Rightarrow> 'a list \<Rightarrow> 'b list"
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
   143
where
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
   144
  "map_distinct f [] = []"
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
   145
| "map_distinct f xs = foldr (insertl o f) xs []"
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
   146
by pat_completeness auto
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
   147
termination by lexicographic_order
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
   148
26312
e9a65675e5e8 avoid rebinding of existing facts;
wenzelm
parents: 25885
diff changeset
   149
lemmas map_distinct_eq = map_distinct.simps(2)
23854
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
   150
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
   151
function unions :: "'a list list \<Rightarrow> 'a list"
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
   152
where
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
   153
  "unions [] = []"
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
   154
| "unions xs = foldr unionl xs []"
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
   155
by pat_completeness auto
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
   156
termination by lexicographic_order
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
   157
26312
e9a65675e5e8 avoid rebinding of existing facts;
wenzelm
parents: 25885
diff changeset
   158
lemmas unions_eq = unions.simps(2)
23854
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
   159
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
   160
consts intersects :: "'a list list \<Rightarrow> 'a list"
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
   161
primrec
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
   162
  "intersects (x#xs) = foldr intersect xs x"
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
   163
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
   164
definition
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
   165
  map_union :: "'a list \<Rightarrow> ('a \<Rightarrow> 'b list) \<Rightarrow> 'b list" where
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
   166
  "map_union xs f = unions (map f xs)"
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
   167
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
   168
definition
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
   169
  map_inter :: "'a list \<Rightarrow> ('a \<Rightarrow> 'b list) \<Rightarrow> 'b list" where
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
   170
  "map_inter xs f = intersects (map f xs)"
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
   171
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
   172
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
   173
subsection {* Isomorphism proofs *}
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
   174
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
   175
lemma iso_member:
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
   176
  "member xs x \<longleftrightarrow> x \<in> set xs"
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
   177
  unfolding member_def mem_iff ..
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
   178
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
   179
lemma iso_insert:
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
   180
  "set (insertl x xs) = insert x (set xs)"
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
   181
  unfolding insertl_def iso_member by (simp add: Set.insert_absorb)
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
   182
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
   183
lemma iso_remove1:
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
   184
  assumes distnct: "distinct xs"
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
   185
  shows "set (remove1 x xs) = set xs - {x}"
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
   186
  using distnct set_remove1_eq by auto
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
   187
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
   188
lemma iso_union:
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
   189
  "set (unionl xs ys) = set xs \<union> set ys"
26312
e9a65675e5e8 avoid rebinding of existing facts;
wenzelm
parents: 25885
diff changeset
   190
  unfolding unionl_eq
23854
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
   191
  by (induct xs arbitrary: ys) (simp_all add: iso_insert)
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
   192
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
   193
lemma iso_intersect:
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
   194
  "set (intersect xs ys) = set xs \<inter> set ys"
26312
e9a65675e5e8 avoid rebinding of existing facts;
wenzelm
parents: 25885
diff changeset
   195
  unfolding intersect_eq Int_def by (simp add: Int_def iso_member) auto
23854
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
   196
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
   197
definition
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
   198
  subtract' :: "'a list \<Rightarrow> 'a list \<Rightarrow> 'a list" where
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
   199
  "subtract' = flip subtract"
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
   200
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
   201
lemma iso_subtract:
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
   202
  fixes ys
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
   203
  assumes distnct: "distinct ys"
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
   204
  shows "set (subtract' ys xs) = set ys - set xs"
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
   205
    and "distinct (subtract' ys xs)"
26312
e9a65675e5e8 avoid rebinding of existing facts;
wenzelm
parents: 25885
diff changeset
   206
  unfolding subtract'_def flip_def subtract_eq
23854
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
   207
  using distnct by (induct xs arbitrary: ys) auto
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
   208
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
   209
lemma iso_map_distinct:
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
   210
  "set (map_distinct f xs) = image f (set xs)"
26312
e9a65675e5e8 avoid rebinding of existing facts;
wenzelm
parents: 25885
diff changeset
   211
  unfolding map_distinct_eq by (induct xs) (simp_all add: iso_insert)
23854
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
   212
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
   213
lemma iso_unions:
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
   214
  "set (unions xss) = \<Union> set (map set xss)"
26312
e9a65675e5e8 avoid rebinding of existing facts;
wenzelm
parents: 25885
diff changeset
   215
  unfolding unions_eq
23854
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
   216
proof (induct xss)
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
   217
  case Nil show ?case by simp
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
   218
next
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
   219
  case (Cons xs xss) thus ?case by (induct xs) (simp_all add: iso_insert)
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
   220
qed
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
   221
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
   222
lemma iso_intersects:
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
   223
  "set (intersects (xs#xss)) = \<Inter> set (map set (xs#xss))"
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
   224
  by (induct xss) (simp_all add: Int_def iso_member, auto)
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
   225
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
   226
lemma iso_UNION:
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
   227
  "set (map_union xs f) = UNION (set xs) (set o f)"
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
   228
  unfolding map_union_def iso_unions by simp
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
   229
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
   230
lemma iso_INTER:
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
   231
  "set (map_inter (x#xs) f) = INTER (set (x#xs)) (set o f)"
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
   232
  unfolding map_inter_def iso_intersects by (induct xs) (simp_all add: iso_member, auto)
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
   233
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
   234
definition
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
   235
  Blall :: "'a list \<Rightarrow> ('a \<Rightarrow> bool) \<Rightarrow> bool" where
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
   236
  "Blall = flip list_all"
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
   237
definition
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
   238
  Blex :: "'a list \<Rightarrow> ('a \<Rightarrow> bool) \<Rightarrow> bool" where
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
   239
  "Blex = flip list_ex"
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
   240
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
   241
lemma iso_Ball:
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
   242
  "Blall xs f = Ball (set xs) f"
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
   243
  unfolding Blall_def flip_def by (induct xs) simp_all
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
   244
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
   245
lemma iso_Bex:
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
   246
  "Blex xs f = Bex (set xs) f"
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
   247
  unfolding Blex_def flip_def by (induct xs) simp_all
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
   248
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
   249
lemma iso_filter:
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
   250
  "set (filter P xs) = filter_set P (set xs)"
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
   251
  unfolding filter_set_def by (induct xs) auto
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
   252
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
   253
subsection {* code generator setup *}
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
   254
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
   255
ML {*
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
   256
nonfix inter;
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
   257
nonfix union;
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
   258
nonfix subset;
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
   259
*}
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
   260
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
   261
subsubsection {* const serializations *}
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
   262
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
   263
consts_code
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
   264
  "{}" ("{*[]*}")
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
   265
  insert ("{*insertl*}")
28522
eacb54d9e78d only one theorem table for both code generators
haftmann
parents: 27487
diff changeset
   266
  is_empty ("{*null*}")
23854
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
   267
  "op \<union>" ("{*unionl*}")
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
   268
  "op \<inter>" ("{*intersect*}")
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
   269
  "op - \<Colon> 'a set \<Rightarrow> 'a set \<Rightarrow> 'a set" ("{* flip subtract *}")
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
   270
  image ("{*map_distinct*}")
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
   271
  Union ("{*unions*}")
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
   272
  Inter ("{*intersects*}")
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
   273
  UNION ("{*map_union*}")
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
   274
  INTER ("{*map_inter*}")
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
   275
  Ball ("{*Blall*}")
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
   276
  Bex ("{*Blex*}")
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
   277
  filter_set ("{*filter*}")
29110
476c46e99ada flipped fold implementation
nipkow
parents: 29107
diff changeset
   278
  fold ("{* foldl o flip *}")
23854
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
   279
688a8a7bcd4e uniform naming conventions for CG theories
haftmann
parents:
diff changeset
   280
end