Nominal/FSet.thy
author Christian Urban <urbanc@in.tum.de>
Thu, 18 Mar 2010 23:38:01 +0100
changeset 1527 e1c74b864b1b
parent 1518 212629c90971
child 1533 5f5e99a11f66
permissions -rw-r--r--
added item about size functions
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:
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    69
  shows "\<not>[] \<approx> x # xs"
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    70
  by auto
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    71
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    72
lemma memb_cons_iff:
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    73
  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
    74
  by (induct xs) (auto simp add: memb_def)
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    75
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    76
lemma memb_consI1:
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    77
  shows "memb x (x # xs)"
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    78
  by (simp add: memb_def)
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    79
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    80
lemma memb_consI2:
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    81
  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
    82
  by (simp add: memb_def)
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    83
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    84
lemma memb_absorb:
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    85
  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
    86
  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
    87
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    88
section {* Singletons *}
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
lemma singleton_list_eq:
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    91
  shows "[x] \<approx> [y] \<longleftrightarrow> x = y"
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    92
  by (simp add: id_simps) auto
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    93
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    94
section {* Union *}
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
quotient_definition
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    97
  funion  (infixl "|\<union>|" 65)
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    98
where
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    99
  "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
   100
is
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   101
  "op @"
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   102
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   103
section {* Cardinality of finite sets *}
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
fun
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   106
  fcard_raw :: "'a list \<Rightarrow> nat"
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   107
where
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   108
  fcard_raw_nil:  "fcard_raw [] = 0"
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   109
| 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
   110
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   111
quotient_definition
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   112
  "fcard :: 'a fset \<Rightarrow> nat" 
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   113
is
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   114
  "fcard_raw"
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   115
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   116
lemma fcard_raw_gt_0:
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   117
  assumes a: "x \<in> set xs"
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   118
  shows "0 < fcard_raw xs"
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   119
  using a
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   120
  by (induct xs) (auto simp add: memb_def)
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   121
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   122
lemma fcard_raw_delete_one:
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   123
  "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
   124
  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
   125
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   126
lemma fcard_raw_rsp_aux:
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   127
  assumes a: "a \<approx> b"
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   128
  shows "fcard_raw a = fcard_raw b"
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   129
  using a
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   130
  apply(induct a arbitrary: b)
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   131
  apply(auto simp add: memb_def)
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   132
  apply(metis)
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   133
  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
   134
  apply(simp add: fcard_raw_delete_one)
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   135
  apply(metis Suc_pred' fcard_raw_gt_0 fcard_raw_delete_one memb_def)
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   136
  done
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   137
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   138
lemma fcard_raw_rsp[quot_respect]:
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   139
  "(op \<approx> ===> op =) fcard_raw fcard_raw"
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   140
  by (simp add: fcard_raw_rsp_aux)
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   141
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   142
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   143
section {* fmap and fset comprehension *}
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
quotient_definition
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   146
  "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
   147
is
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   148
 "map"
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   149
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   150
text {* raw section *}
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
lemma map_rsp_aux:
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   153
  assumes a: "a \<approx> b"
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   154
  shows "map f a \<approx> map f b"
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   155
  using a
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   156
  apply(induct a arbitrary: b)
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   157
  apply(auto)
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   158
  apply(metis rev_image_eqI)
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   159
  done
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   160
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   161
lemma map_rsp[quot_respect]:
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   162
  shows "(op = ===> op \<approx> ===> op \<approx>) map map"
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   163
  by (auto simp add: map_rsp_aux)
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   164
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   165
lemma cons_left_comm:
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   166
  "x # y # A \<approx> y # x # A"
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   167
  by (auto simp add: id_simps)
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   168
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   169
lemma cons_left_idem:
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   170
  "x # x # A \<approx> x # A"
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   171
  by (auto simp add: id_simps)
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   172
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   173
lemma none_mem_nil:
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   174
  "(\<forall>a. a \<notin> set A) = (A \<approx> [])"
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   175
  by simp
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   176
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   177
lemma finite_set_raw_strong_cases:
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   178
  "(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
   179
  apply (induct X)
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   180
  apply (simp)
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   181
  apply (rule disjI2)
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   182
  apply (erule disjE)
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   183
  apply (rule_tac x="a" in exI)
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   184
  apply (rule_tac x="[]" in exI)
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   185
  apply (simp)
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   186
  apply (erule exE)+
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   187
  apply (case_tac "a = aa")
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   188
  apply (rule_tac x="a" in exI)
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   189
  apply (rule_tac x="Y" in exI)
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   190
  apply (simp)
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   191
  apply (rule_tac x="aa" in exI)
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   192
  apply (rule_tac x="a # Y" in exI)
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   193
  apply (auto)
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   194
  done
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   195
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   196
fun
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   197
  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
   198
where
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   199
  "delete_raw [] x = []"
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   200
| "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
   201
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   202
lemma mem_delete_raw:
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   203
  "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
   204
  by (induct A arbitrary: x a) (auto)
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   205
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   206
lemma mem_delete_raw_ident:
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   207
  "\<not>(a \<in> set (delete_raw A a))"
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   208
  by (induct A) (auto)
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   209
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   210
lemma not_mem_delete_raw_ident:
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   211
  "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
   212
  by (induct A) (auto)
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   213
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   214
lemma finite_set_raw_delete_raw_cases:
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   215
  "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
   216
  by (induct X) (auto)
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   217
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   218
lemma list2set_thm:
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   219
  shows "set [] = {}"
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   220
  and "set (h # t) = insert h (set t)"
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   221
  by (auto)
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   222
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   223
lemma list2set_rsp[quot_respect]:
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   224
  "(op \<approx> ===> op =) set set"
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   225
  by auto
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   226
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   227
definition
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   228
  rsp_fold
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   229
where
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   230
  "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
   231
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   232
primrec
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   233
  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
   234
where
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   235
  "fold_raw f z [] = z"
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   236
| "fold_raw f z (a # A) =
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   237
     (if (rsp_fold f) then
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   238
       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
   239
       else f a (fold_raw f z A)
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   240
     else z)"
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   241
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   242
section {* Constants on the Quotient Type *} 
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
quotient_definition
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   245
  "fdelete :: 'a fset \<Rightarrow> 'a \<Rightarrow> 'a fset" 
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   246
  is "delete_raw"
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   247
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   248
quotient_definition
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   249
  "fset_to_set :: 'a fset \<Rightarrow> 'a set" 
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   250
  is "set"
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   251
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   252
lemma funion_sym_pre:
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   253
  "a @ b \<approx> b @ a"
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   254
  by auto
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   255
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   256
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   257
lemma append_rsp[quot_respect]:
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   258
  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
   259
  by (auto)
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   260
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   261
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   262
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   263
section {* lifted part *}
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   264
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   265
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   266
lemma fin_finsert_iff[simp]:
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   267
  "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
   268
  by (lifting memb_cons_iff)
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   269
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   270
lemma
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   271
  shows finsertI1: "x |\<in>| finsert x S"
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   272
  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
   273
  by (lifting memb_consI1, lifting memb_consI2)
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   274
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   275
lemma finsert_absorb[simp]:
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   276
  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
   277
  by (lifting memb_absorb)
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
lemma fempty_not_finsert[simp]:
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   280
  shows "{||} \<noteq> finsert x S"
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   281
  by (lifting nil_not_cons)
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   282
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   283
lemma finsert_left_comm:
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   284
  "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
   285
  by (lifting cons_left_comm)
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   286
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   287
lemma finsert_left_idem:
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   288
  "finsert a (finsert a S) = finsert a S"
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   289
  by (lifting cons_left_idem)
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   290
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   291
lemma fsingleton_eq[simp]:
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   292
  shows "{|x|} = {|y|} \<longleftrightarrow> x = y"
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   293
  by (lifting singleton_list_eq)
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   294
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   295
text {* fset_to_set *}
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   296
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   297
lemma fset_to_set_simps:
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   298
  "fset_to_set {||} = {}"
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   299
  "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
   300
  by (lifting list2set_thm)
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 in_fset_to_set:
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   303
  "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
   304
  by (lifting memb_def[symmetric])
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 none_in_fempty:
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   307
  "(\<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
   308
  by (lifting none_mem_nil)
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 {* fcard *}
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   311
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   312
lemma fcard_fempty [simp]:
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   313
  shows "fcard {||} = 0"
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   314
  by (lifting fcard_raw_nil)
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   315
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   316
lemma fcard_finsert_if [simp]:
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   317
  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
   318
  by (lifting fcard_raw_cons)
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   319
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   320
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
   321
  by (lifting fcard_raw_gt_0)
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   322
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   323
text {* funion *}
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   324
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   325
lemma funion_simps[simp]:
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   326
  "{||} |\<union>| ys = ys"
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   327
  "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
   328
  by (lifting append.simps)
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   329
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   330
lemma funion_sym:
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   331
  "a |\<union>| b = b |\<union>| a"
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   332
  by (lifting funion_sym_pre)
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   333
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   334
lemma funion_assoc:
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   335
 "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
   336
  by (lifting append_assoc)
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   337
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   338
section {* Induction and Cases rules for finite sets *}
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   339
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   340
lemma fset_strong_cases:
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   341
  "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
   342
  by (lifting finite_set_raw_strong_cases)
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 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
   345
  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
   346
  by (lifting list.exhaust)
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   347
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   348
lemma fset_induct[case_names fempty finsert]:
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   349
  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
   350
  by (lifting list.induct)
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   351
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   352
lemma fset_induct2[case_names fempty finsert, induct type: fset]:
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   353
  assumes prem1: "P {||}" 
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   354
  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
   355
  shows "P S"
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   356
proof(induct S rule: fset_induct)
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   357
  case fempty
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   358
  show "P {||}" by (rule prem1)
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   359
next
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   360
  case (finsert x S)
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   361
  have asm: "P S" by fact
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   362
  show "P (finsert x S)"
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   363
  proof(cases "x |\<in>| S")
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   364
    case True
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   365
    have "x |\<in>| S" by fact
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   366
    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
   367
  next
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   368
    case False
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   369
    have "x |\<notin>| S" by fact
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   370
    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
   371
  qed
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   372
qed
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   373
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   374
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   375
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   376
end