Nominal/FSet.thy
author Cezary Kaliszyk <kaliszyk@in.tum.de>
Fri, 19 Mar 2010 06:55:17 +0100
changeset 1533 5f5e99a11f66
parent 1518 212629c90971
child 1682 ae54ce4cde54
permissions -rw-r--r--
A few more theorems in FSet.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1518
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
     1
theory FSet
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
     2
imports Quotient Quotient_List List
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
     3
begin
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
     4
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
     5
fun
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
     6
  list_eq :: "'a list \<Rightarrow> 'a list \<Rightarrow> bool" (infix "\<approx>" 50)
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
     7
where
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
     8
  "list_eq xs ys = (\<forall>x. x \<in> set xs \<longleftrightarrow> x \<in> set ys)"
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
     9
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    10
lemma list_eq_equivp:
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    11
  shows "equivp list_eq"
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    12
unfolding equivp_reflp_symp_transp reflp_def symp_def transp_def
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    13
by auto
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    14
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    15
quotient_type
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    16
  'a fset = "'a list" / "list_eq"
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    17
by (rule list_eq_equivp)
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    18
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    19
section {* empty fset, finsert and membership *}
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    20
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    21
quotient_definition
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    22
  fempty  ("{||}")
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    23
where
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    24
  "fempty :: 'a fset"
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    25
is "[]::'a list"
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    26
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    27
quotient_definition
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    28
  "finsert :: 'a \<Rightarrow> 'a fset \<Rightarrow> 'a fset" 
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    29
is "op #"
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    30
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    31
syntax
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    32
  "@Finset"     :: "args => 'a fset"  ("{|(_)|}")
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    33
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    34
translations
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    35
  "{|x, xs|}" == "CONST finsert x {|xs|}"
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    36
  "{|x|}"     == "CONST finsert x {||}"
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    37
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    38
definition
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    39
  memb :: "'a \<Rightarrow> 'a list \<Rightarrow> bool"
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    40
where
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    41
  "memb x xs \<equiv> x \<in> set xs"
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    42
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    43
quotient_definition
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    44
  fin ("_ |\<in>| _" [50, 51] 50)
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    45
where
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    46
  "fin :: 'a \<Rightarrow> 'a fset \<Rightarrow> bool"
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    47
is "memb"
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    48
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    49
abbreviation
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    50
  fnotin :: "'a \<Rightarrow> 'a fset \<Rightarrow> bool" ("_ |\<notin>| _" [50, 51] 50)
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    51
where
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    52
  "a |\<notin>| S \<equiv> \<not>(a |\<in>| S)"
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    53
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    54
lemma memb_rsp[quot_respect]:
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    55
  shows "(op = ===> op \<approx> ===> op =) memb memb"
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    56
by (auto simp add: memb_def)
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    57
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    58
lemma nil_rsp[quot_respect]:
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    59
  shows "[] \<approx> []"
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    60
by simp
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    61
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    62
lemma cons_rsp[quot_respect]:
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    63
  shows "(op = ===> op \<approx> ===> op \<approx>) op # op #"
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    64
by simp
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    65
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    66
section {* Augmenting a set -- @{const finsert} *}
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    67
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    68
lemma nil_not_cons:
1533
5f5e99a11f66 A few more theorems in FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1518
diff changeset
    69
  shows
5f5e99a11f66 A few more theorems in FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1518
diff changeset
    70
  "\<not>[] \<approx> x # xs"
5f5e99a11f66 A few more theorems in FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1518
diff changeset
    71
  "\<not>x # xs \<approx> []"
1518
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    72
  by auto
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    73
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    74
lemma memb_cons_iff:
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    75
  shows "memb x (y # xs) = (x = y \<or> memb x xs)"
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    76
  by (induct xs) (auto simp add: memb_def)
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    77
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    78
lemma memb_consI1:
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    79
  shows "memb x (x # xs)"
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    80
  by (simp add: memb_def)
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    81
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    82
lemma memb_consI2:
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    83
  shows "memb x xs \<Longrightarrow> memb x (y # xs)"
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    84
  by (simp add: memb_def)
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    85
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    86
lemma memb_absorb:
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    87
  shows "memb x xs \<Longrightarrow> x # xs \<approx> xs"
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    88
  by (induct xs) (auto simp add: memb_def id_simps)
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    89
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    90
section {* Singletons *}
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    91
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    92
lemma singleton_list_eq:
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    93
  shows "[x] \<approx> [y] \<longleftrightarrow> x = y"
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    94
  by (simp add: id_simps) auto
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    95
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    96
section {* Union *}
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    97
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    98
quotient_definition
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    99
  funion  (infixl "|\<union>|" 65)
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   100
where
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   101
  "funion :: 'a fset \<Rightarrow> 'a fset \<Rightarrow> 'a fset"
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   102
is
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   103
  "op @"
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   104
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   105
section {* Cardinality of finite sets *}
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   106
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   107
fun
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   108
  fcard_raw :: "'a list \<Rightarrow> nat"
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   109
where
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   110
  fcard_raw_nil:  "fcard_raw [] = 0"
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   111
| fcard_raw_cons: "fcard_raw (x # xs) = (if memb x xs then fcard_raw xs else Suc (fcard_raw xs))"
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   112
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   113
quotient_definition
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   114
  "fcard :: 'a fset \<Rightarrow> nat" 
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   115
is
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   116
  "fcard_raw"
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   117
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   118
lemma fcard_raw_gt_0:
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   119
  assumes a: "x \<in> set xs"
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   120
  shows "0 < fcard_raw xs"
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   121
  using a
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   122
  by (induct xs) (auto simp add: memb_def)
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   123
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   124
lemma fcard_raw_delete_one:
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   125
  "fcard_raw ([x \<leftarrow> xs. x \<noteq> y]) = (if memb y xs then fcard_raw xs - 1 else fcard_raw xs)"
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   126
  by (induct xs) (auto dest: fcard_raw_gt_0 simp add: memb_def)
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   127
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   128
lemma fcard_raw_rsp_aux:
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   129
  assumes a: "a \<approx> b"
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   130
  shows "fcard_raw a = fcard_raw b"
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   131
  using a
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   132
  apply(induct a arbitrary: b)
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   133
  apply(auto simp add: memb_def)
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   134
  apply(metis)
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   135
  apply(drule_tac x="[x \<leftarrow> b. x \<noteq> a1]" in meta_spec)
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   136
  apply(simp add: fcard_raw_delete_one)
1533
5f5e99a11f66 A few more theorems in FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1518
diff changeset
   137
  apply(metis Suc_pred'[OF fcard_raw_gt_0] fcard_raw_delete_one memb_def)
1518
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   138
  done
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   139
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   140
lemma fcard_raw_rsp[quot_respect]:
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   141
  "(op \<approx> ===> op =) fcard_raw fcard_raw"
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   142
  by (simp add: fcard_raw_rsp_aux)
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   143
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   144
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   145
section {* fmap and fset comprehension *}
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   146
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   147
quotient_definition
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   148
  "fmap :: ('a \<Rightarrow> 'b) \<Rightarrow> 'a fset \<Rightarrow> 'b fset"
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   149
is
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   150
 "map"
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   151
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   152
text {* raw section *}
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   153
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   154
lemma map_rsp_aux:
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   155
  assumes a: "a \<approx> b"
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   156
  shows "map f a \<approx> map f b"
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   157
  using a
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   158
  apply(induct a arbitrary: b)
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   159
  apply(auto)
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   160
  apply(metis rev_image_eqI)
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   161
  done
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   162
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   163
lemma map_rsp[quot_respect]:
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   164
  shows "(op = ===> op \<approx> ===> op \<approx>) map map"
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   165
  by (auto simp add: map_rsp_aux)
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   166
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   167
lemma cons_left_comm:
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   168
  "x # y # A \<approx> y # x # A"
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   169
  by (auto simp add: id_simps)
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   170
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   171
lemma cons_left_idem:
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   172
  "x # x # A \<approx> x # A"
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   173
  by (auto simp add: id_simps)
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   174
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   175
lemma none_mem_nil:
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   176
  "(\<forall>a. a \<notin> set A) = (A \<approx> [])"
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   177
  by simp
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   178
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   179
lemma finite_set_raw_strong_cases:
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   180
  "(X = []) \<or> (\<exists>a Y. ((a \<notin> set Y) \<and> (X \<approx> a # Y)))"
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   181
  apply (induct X)
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   182
  apply (simp)
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   183
  apply (rule disjI2)
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   184
  apply (erule disjE)
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   185
  apply (rule_tac x="a" in exI)
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   186
  apply (rule_tac x="[]" in exI)
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   187
  apply (simp)
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   188
  apply (erule exE)+
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   189
  apply (case_tac "a = aa")
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   190
  apply (rule_tac x="a" in exI)
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   191
  apply (rule_tac x="Y" in exI)
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   192
  apply (simp)
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   193
  apply (rule_tac x="aa" in exI)
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   194
  apply (rule_tac x="a # Y" in exI)
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   195
  apply (auto)
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   196
  done
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   197
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   198
fun
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   199
  delete_raw :: "'a list \<Rightarrow> 'a \<Rightarrow> 'a list"
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   200
where
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   201
  "delete_raw [] x = []"
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   202
| "delete_raw (a # A) x = (if (a = x) then delete_raw A x else a # (delete_raw A x))"
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   203
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   204
lemma mem_delete_raw:
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   205
  "x \<in> set (delete_raw A a) = (x \<in> set A \<and> \<not>(x = a))"
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   206
  by (induct A arbitrary: x a) (auto)
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   207
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   208
lemma mem_delete_raw_ident:
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   209
  "\<not>(a \<in> set (delete_raw A a))"
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   210
  by (induct A) (auto)
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   211
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   212
lemma not_mem_delete_raw_ident:
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   213
  "b \<notin> set A \<Longrightarrow> (delete_raw A b = A)"
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   214
  by (induct A) (auto)
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   215
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   216
lemma finite_set_raw_delete_raw_cases:
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   217
  "X = [] \<or> (\<exists>a. a mem X \<and> X \<approx> a # delete_raw X a)"
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   218
  by (induct X) (auto)
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   219
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   220
lemma list2set_thm:
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   221
  shows "set [] = {}"
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   222
  and "set (h # t) = insert h (set t)"
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   223
  by (auto)
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   224
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   225
lemma list2set_rsp[quot_respect]:
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   226
  "(op \<approx> ===> op =) set set"
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   227
  by auto
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   228
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   229
definition
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   230
  rsp_fold
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   231
where
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   232
  "rsp_fold f = (\<forall>u v w. (f u (f v w) = f v (f u w)))"
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   233
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   234
primrec
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   235
  fold_raw :: "('a \<Rightarrow> 'b \<Rightarrow> 'b) \<Rightarrow> 'b \<Rightarrow> 'a list \<Rightarrow> 'b"
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   236
where
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   237
  "fold_raw f z [] = z"
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   238
| "fold_raw f z (a # A) =
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   239
     (if (rsp_fold f) then
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   240
       if a mem A then fold_raw f z A
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   241
       else f a (fold_raw f z A)
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   242
     else z)"
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   243
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   244
section {* Constants on the Quotient Type *} 
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   245
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   246
quotient_definition
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   247
  "fdelete :: 'a fset \<Rightarrow> 'a \<Rightarrow> 'a fset" 
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   248
  is "delete_raw"
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   249
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   250
quotient_definition
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   251
  "fset_to_set :: 'a fset \<Rightarrow> 'a set" 
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   252
  is "set"
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   253
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   254
lemma funion_sym_pre:
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   255
  "a @ b \<approx> b @ a"
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   256
  by auto
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   257
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   258
lemma append_rsp[quot_respect]:
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   259
  shows "(op \<approx> ===> op \<approx> ===> op \<approx>) op @ op @"
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   260
  by (auto)
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   261
1533
5f5e99a11f66 A few more theorems in FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1518
diff changeset
   262
lemma set_cong: "(set x = set y) = (x \<approx> y)"
5f5e99a11f66 A few more theorems in FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1518
diff changeset
   263
  apply rule
5f5e99a11f66 A few more theorems in FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1518
diff changeset
   264
  apply simp_all
5f5e99a11f66 A few more theorems in FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1518
diff changeset
   265
  apply (induct x y rule: list_induct2')
5f5e99a11f66 A few more theorems in FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1518
diff changeset
   266
  apply simp_all
5f5e99a11f66 A few more theorems in FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1518
diff changeset
   267
  apply auto
5f5e99a11f66 A few more theorems in FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1518
diff changeset
   268
  done
5f5e99a11f66 A few more theorems in FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1518
diff changeset
   269
5f5e99a11f66 A few more theorems in FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1518
diff changeset
   270
lemma inj_map_eq_iff:
5f5e99a11f66 A few more theorems in FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1518
diff changeset
   271
  "inj f \<Longrightarrow> (map f l \<approx> map f m) = (l \<approx> m)"
5f5e99a11f66 A few more theorems in FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1518
diff changeset
   272
  by (simp add: expand_set_eq[symmetric] inj_image_eq_iff)
5f5e99a11f66 A few more theorems in FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1518
diff changeset
   273
5f5e99a11f66 A few more theorems in FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1518
diff changeset
   274
1518
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   275
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   276
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   277
section {* lifted part *}
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   278
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   279
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   280
lemma fin_finsert_iff[simp]:
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   281
  "x |\<in>| finsert y S = (x = y \<or> x |\<in>| S)"
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   282
  by (lifting memb_cons_iff)
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   283
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   284
lemma
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   285
  shows finsertI1: "x |\<in>| finsert x S"
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   286
  and   finsertI2: "x |\<in>| S \<Longrightarrow> x |\<in>| finsert y S"
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   287
  by (lifting memb_consI1, lifting memb_consI2)
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   288
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   289
lemma finsert_absorb[simp]:
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   290
  shows "x |\<in>| S \<Longrightarrow> finsert x S = S"
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   291
  by (lifting memb_absorb)
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   292
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   293
lemma fempty_not_finsert[simp]:
1533
5f5e99a11f66 A few more theorems in FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1518
diff changeset
   294
  "{||} \<noteq> finsert x S"
5f5e99a11f66 A few more theorems in FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1518
diff changeset
   295
  "finsert x S \<noteq> {||}"
1518
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   296
  by (lifting nil_not_cons)
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   297
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   298
lemma finsert_left_comm:
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   299
  "finsert a (finsert b S) = finsert b (finsert a S)"
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   300
  by (lifting cons_left_comm)
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   301
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   302
lemma finsert_left_idem:
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   303
  "finsert a (finsert a S) = finsert a S"
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   304
  by (lifting cons_left_idem)
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   305
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   306
lemma fsingleton_eq[simp]:
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   307
  shows "{|x|} = {|y|} \<longleftrightarrow> x = y"
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   308
  by (lifting singleton_list_eq)
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   309
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   310
text {* fset_to_set *}
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   311
1533
5f5e99a11f66 A few more theorems in FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1518
diff changeset
   312
lemma fset_to_set_simps[simp]:
1518
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   313
  "fset_to_set {||} = {}"
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   314
  "fset_to_set (finsert (h :: 'b) t) = insert h (fset_to_set t)"
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   315
  by (lifting list2set_thm)
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   316
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   317
lemma in_fset_to_set:
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   318
  "x \<in> fset_to_set xs \<equiv> x |\<in>| xs"
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   319
  by (lifting memb_def[symmetric])
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   320
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   321
lemma none_in_fempty:
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   322
  "(\<forall>a. a \<notin> fset_to_set A) = (A = {||})"
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   323
  by (lifting none_mem_nil)
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   324
1533
5f5e99a11f66 A few more theorems in FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1518
diff changeset
   325
lemma fset_cong:
5f5e99a11f66 A few more theorems in FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1518
diff changeset
   326
  "(fset_to_set x = fset_to_set y) = (x = y)"
5f5e99a11f66 A few more theorems in FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1518
diff changeset
   327
  by (lifting set_cong)
5f5e99a11f66 A few more theorems in FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1518
diff changeset
   328
1518
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   329
text {* fcard *}
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   330
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   331
lemma fcard_fempty [simp]:
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   332
  shows "fcard {||} = 0"
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   333
  by (lifting fcard_raw_nil)
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   334
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   335
lemma fcard_finsert_if [simp]:
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   336
  shows "fcard (finsert x S) = (if x |\<in>| S then fcard S else Suc (fcard S))"
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   337
  by (lifting fcard_raw_cons)
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   338
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   339
lemma fcard_gt_0: "x \<in> fset_to_set xs \<Longrightarrow> 0 < fcard xs"
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   340
  by (lifting fcard_raw_gt_0)
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   341
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   342
text {* funion *}
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   343
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   344
lemma funion_simps[simp]:
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   345
  "{||} |\<union>| ys = ys"
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   346
  "finsert x xs |\<union>| ys = finsert x (xs |\<union>| ys)"
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   347
  by (lifting append.simps)
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   348
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   349
lemma funion_sym:
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   350
  "a |\<union>| b = b |\<union>| a"
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   351
  by (lifting funion_sym_pre)
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   352
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   353
lemma funion_assoc:
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   354
 "x |\<union>| xa |\<union>| xb = x |\<union>| (xa |\<union>| xb)"
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   355
  by (lifting append_assoc)
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   356
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   357
section {* Induction and Cases rules for finite sets *}
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   358
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   359
lemma fset_strong_cases:
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   360
  "X = {||} \<or> (\<exists>a Y. a \<notin> fset_to_set Y \<and> X = finsert a Y)"
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   361
  by (lifting finite_set_raw_strong_cases)
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   362
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   363
lemma fset_exhaust[case_names fempty finsert, cases type: fset]:
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   364
  shows "\<lbrakk>S = {||} \<Longrightarrow> P; \<And>x S'. S = finsert x S' \<Longrightarrow> P\<rbrakk> \<Longrightarrow> P"
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   365
  by (lifting list.exhaust)
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   366
1533
5f5e99a11f66 A few more theorems in FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1518
diff changeset
   367
lemma fset_induct_weak[case_names fempty finsert]:
1518
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   368
  shows "\<lbrakk>P {||}; \<And>x S. P S \<Longrightarrow> P (finsert x S)\<rbrakk> \<Longrightarrow> P S"
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   369
  by (lifting list.induct)
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   370
1533
5f5e99a11f66 A few more theorems in FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1518
diff changeset
   371
lemma fset_induct[case_names fempty finsert, induct type: fset]:
1518
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   372
  assumes prem1: "P {||}" 
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   373
  and     prem2: "\<And>x S. \<lbrakk>x |\<notin>| S; P S\<rbrakk> \<Longrightarrow> P (finsert x S)"
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   374
  shows "P S"
1533
5f5e99a11f66 A few more theorems in FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1518
diff changeset
   375
proof(induct S rule: fset_induct_weak)
1518
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   376
  case fempty
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   377
  show "P {||}" by (rule prem1)
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   378
next
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   379
  case (finsert x S)
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   380
  have asm: "P S" by fact
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   381
  show "P (finsert x S)"
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   382
  proof(cases "x |\<in>| S")
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   383
    case True
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   384
    have "x |\<in>| S" by fact
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   385
    then show "P (finsert x S)" using asm by simp
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   386
  next
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   387
    case False
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   388
    have "x |\<notin>| S" by fact
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   389
    then show "P (finsert x S)" using prem2 asm by simp
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   390
  qed
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   391
qed
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   392
1533
5f5e99a11f66 A few more theorems in FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1518
diff changeset
   393
lemma fset_induct2:
5f5e99a11f66 A few more theorems in FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1518
diff changeset
   394
  "P {||} {||} \<Longrightarrow>
5f5e99a11f66 A few more theorems in FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1518
diff changeset
   395
  (\<And>x xs. x |\<notin>| xs \<Longrightarrow> P (finsert x xs) {||}) \<Longrightarrow>
5f5e99a11f66 A few more theorems in FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1518
diff changeset
   396
  (\<And>y ys. y |\<notin>| ys \<Longrightarrow> P {||} (finsert y ys)) \<Longrightarrow>
5f5e99a11f66 A few more theorems in FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1518
diff changeset
   397
  (\<And>x xs y ys. \<lbrakk>P xs ys; x |\<notin>| xs; y |\<notin>| ys\<rbrakk> \<Longrightarrow> P (finsert x xs) (finsert y ys)) \<Longrightarrow>
5f5e99a11f66 A few more theorems in FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1518
diff changeset
   398
  P xsa ysa"
5f5e99a11f66 A few more theorems in FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1518
diff changeset
   399
  apply (induct xsa arbitrary: ysa)
5f5e99a11f66 A few more theorems in FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1518
diff changeset
   400
  apply (induct_tac x rule: fset_induct)
5f5e99a11f66 A few more theorems in FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1518
diff changeset
   401
  apply simp_all
5f5e99a11f66 A few more theorems in FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1518
diff changeset
   402
  apply (induct_tac xa rule: fset_induct)
5f5e99a11f66 A few more theorems in FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1518
diff changeset
   403
  apply simp_all
5f5e99a11f66 A few more theorems in FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1518
diff changeset
   404
  done
1518
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   405
1533
5f5e99a11f66 A few more theorems in FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1518
diff changeset
   406
(* fmap *)
5f5e99a11f66 A few more theorems in FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1518
diff changeset
   407
lemma fmap_simps[simp]:
5f5e99a11f66 A few more theorems in FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1518
diff changeset
   408
  "fmap (f :: 'a \<Rightarrow> 'b) {||} = {||}"
5f5e99a11f66 A few more theorems in FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1518
diff changeset
   409
  "fmap f (finsert x xs) = finsert (f x) (fmap f xs)"
5f5e99a11f66 A few more theorems in FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1518
diff changeset
   410
  by (lifting map.simps)
5f5e99a11f66 A few more theorems in FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1518
diff changeset
   411
5f5e99a11f66 A few more theorems in FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1518
diff changeset
   412
lemma fmap_set_image:
5f5e99a11f66 A few more theorems in FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1518
diff changeset
   413
  "fset_to_set (fmap f fs) = f ` (fset_to_set fs)"
5f5e99a11f66 A few more theorems in FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1518
diff changeset
   414
  apply (induct fs)
5f5e99a11f66 A few more theorems in FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1518
diff changeset
   415
  apply (simp_all)
5f5e99a11f66 A few more theorems in FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1518
diff changeset
   416
done
5f5e99a11f66 A few more theorems in FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1518
diff changeset
   417
5f5e99a11f66 A few more theorems in FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1518
diff changeset
   418
lemma inj_fmap_eq_iff:
5f5e99a11f66 A few more theorems in FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1518
diff changeset
   419
  "inj f \<Longrightarrow> (fmap f l = fmap f m) = (l = m)"
5f5e99a11f66 A few more theorems in FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1518
diff changeset
   420
  by (lifting inj_map_eq_iff)
5f5e99a11f66 A few more theorems in FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1518
diff changeset
   421
5f5e99a11f66 A few more theorems in FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1518
diff changeset
   422
ML {*
5f5e99a11f66 A few more theorems in FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1518
diff changeset
   423
fun dest_fsetT (Type ("FSet.fset", [T])) = T
5f5e99a11f66 A few more theorems in FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1518
diff changeset
   424
  | dest_fsetT T = raise TYPE ("dest_fsetT: fset type expected", [T], []);
5f5e99a11f66 A few more theorems in FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1518
diff changeset
   425
*}
1518
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   426
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   427
end