Nominal/FSet.thy
author Cezary Kaliszyk <kaliszyk@in.tum.de>
Mon, 12 Apr 2010 17:05:19 +0200
changeset 1813 69fff336dd18
parent 1682 ae54ce4cde54
child 1817 f20096761790
permissions -rw-r--r--
Porting lemmas from Quotient package FSet to new 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
1813
69fff336dd18 Porting lemmas from Quotient package FSet to new FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1682
diff changeset
   118
lemma fcard_raw_0:
69fff336dd18 Porting lemmas from Quotient package FSet to new FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1682
diff changeset
   119
  fixes a :: "'a list"
69fff336dd18 Porting lemmas from Quotient package FSet to new FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1682
diff changeset
   120
  shows "(fcard_raw a = 0) = (a \<approx> [])"
69fff336dd18 Porting lemmas from Quotient package FSet to new FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1682
diff changeset
   121
  apply (induct a)
69fff336dd18 Porting lemmas from Quotient package FSet to new FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1682
diff changeset
   122
  apply auto
69fff336dd18 Porting lemmas from Quotient package FSet to new FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1682
diff changeset
   123
  apply (drule memb_absorb)
69fff336dd18 Porting lemmas from Quotient package FSet to new FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1682
diff changeset
   124
  apply (auto simp add: nil_not_cons)
69fff336dd18 Porting lemmas from Quotient package FSet to new FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1682
diff changeset
   125
  done
69fff336dd18 Porting lemmas from Quotient package FSet to new FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1682
diff changeset
   126
1518
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   127
lemma fcard_raw_gt_0:
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   128
  assumes a: "x \<in> set xs"
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   129
  shows "0 < fcard_raw xs"
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   130
  using a
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   131
  by (induct xs) (auto simp add: memb_def)
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   132
1813
69fff336dd18 Porting lemmas from Quotient package FSet to new FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1682
diff changeset
   133
lemma fcard_raw_not_memb:
69fff336dd18 Porting lemmas from Quotient package FSet to new FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1682
diff changeset
   134
  fixes x :: "'a"
69fff336dd18 Porting lemmas from Quotient package FSet to new FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1682
diff changeset
   135
  fixes xs :: "'a list"
69fff336dd18 Porting lemmas from Quotient package FSet to new FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1682
diff changeset
   136
  shows "(~(memb x xs)) = (fcard_raw (x # xs) = Suc (fcard_raw xs))"
69fff336dd18 Porting lemmas from Quotient package FSet to new FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1682
diff changeset
   137
  by auto
69fff336dd18 Porting lemmas from Quotient package FSet to new FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1682
diff changeset
   138
69fff336dd18 Porting lemmas from Quotient package FSet to new FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1682
diff changeset
   139
lemma fcard_raw_suc:
69fff336dd18 Porting lemmas from Quotient package FSet to new FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1682
diff changeset
   140
  fixes xs :: "'a list"
69fff336dd18 Porting lemmas from Quotient package FSet to new FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1682
diff changeset
   141
  fixes n :: "nat"
69fff336dd18 Porting lemmas from Quotient package FSet to new FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1682
diff changeset
   142
  assumes c: "fcard_raw xs = Suc n"
69fff336dd18 Porting lemmas from Quotient package FSet to new FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1682
diff changeset
   143
  shows "\<exists>a ys. ~(memb a ys) \<and> xs \<approx> (a # ys)"
69fff336dd18 Porting lemmas from Quotient package FSet to new FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1682
diff changeset
   144
  using c
69fff336dd18 Porting lemmas from Quotient package FSet to new FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1682
diff changeset
   145
  apply(induct xs)
69fff336dd18 Porting lemmas from Quotient package FSet to new FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1682
diff changeset
   146
  apply simp
69fff336dd18 Porting lemmas from Quotient package FSet to new FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1682
diff changeset
   147
  apply (auto)
69fff336dd18 Porting lemmas from Quotient package FSet to new FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1682
diff changeset
   148
  apply (metis memb_def)
69fff336dd18 Porting lemmas from Quotient package FSet to new FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1682
diff changeset
   149
  done
69fff336dd18 Porting lemmas from Quotient package FSet to new FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1682
diff changeset
   150
1518
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   151
lemma fcard_raw_delete_one:
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   152
  "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
   153
  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
   154
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   155
lemma fcard_raw_rsp_aux:
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   156
  assumes a: "a \<approx> b"
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   157
  shows "fcard_raw a = fcard_raw b"
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   158
  using a
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   159
  apply(induct a arbitrary: b)
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   160
  apply(auto simp add: memb_def)
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   161
  apply(metis)
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   162
  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
   163
  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
   164
  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
   165
  done
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 fcard_raw_rsp[quot_respect]:
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   168
  "(op \<approx> ===> op =) fcard_raw fcard_raw"
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   169
  by (simp add: fcard_raw_rsp_aux)
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
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   172
section {* fmap and fset comprehension *}
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   173
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   174
quotient_definition
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   175
  "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
   176
is
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   177
 "map"
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   178
1813
69fff336dd18 Porting lemmas from Quotient package FSet to new FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1682
diff changeset
   179
lemma map_append:
69fff336dd18 Porting lemmas from Quotient package FSet to new FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1682
diff changeset
   180
  "(map f (a @ b)) \<approx> (map f a) @ (map f b)"
69fff336dd18 Porting lemmas from Quotient package FSet to new FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1682
diff changeset
   181
  by simp
69fff336dd18 Porting lemmas from Quotient package FSet to new FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1682
diff changeset
   182
1518
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   183
text {* raw section *}
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   184
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   185
lemma map_rsp_aux:
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   186
  assumes a: "a \<approx> b"
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   187
  shows "map f a \<approx> map f b"
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   188
  using a
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   189
  apply(induct a arbitrary: b)
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   190
  apply(auto)
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   191
  apply(metis rev_image_eqI)
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   192
  done
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   193
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   194
lemma map_rsp[quot_respect]:
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   195
  shows "(op = ===> op \<approx> ===> op \<approx>) map map"
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   196
  by (auto simp add: map_rsp_aux)
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
lemma cons_left_comm:
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   199
  "x # y # A \<approx> y # x # A"
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   200
  by (auto simp add: id_simps)
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 cons_left_idem:
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   203
  "x # x # A \<approx> x # A"
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   204
  by (auto simp add: id_simps)
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 none_mem_nil:
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   207
  "(\<forall>a. a \<notin> set A) = (A \<approx> [])"
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   208
  by simp
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 finite_set_raw_strong_cases:
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   211
  "(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
   212
  apply (induct X)
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   213
  apply (simp)
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   214
  apply (rule disjI2)
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   215
  apply (erule disjE)
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   216
  apply (rule_tac x="a" in exI)
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   217
  apply (rule_tac x="[]" in exI)
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   218
  apply (simp)
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   219
  apply (erule exE)+
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   220
  apply (case_tac "a = aa")
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   221
  apply (rule_tac x="a" in exI)
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   222
  apply (rule_tac x="Y" in exI)
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   223
  apply (simp)
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   224
  apply (rule_tac x="aa" in exI)
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   225
  apply (rule_tac x="a # Y" in exI)
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   226
  apply (auto)
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   227
  done
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
fun
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   230
  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
   231
where
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   232
  "delete_raw [] x = []"
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   233
| "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
   234
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   235
lemma mem_delete_raw:
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   236
  "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
   237
  by (induct A arbitrary: x a) (auto)
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   238
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   239
lemma mem_delete_raw_ident:
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   240
  "\<not>(a \<in> set (delete_raw A a))"
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   241
  by (induct A) (auto)
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   242
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   243
lemma not_mem_delete_raw_ident:
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   244
  "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
   245
  by (induct A) (auto)
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   246
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   247
lemma finite_set_raw_delete_raw_cases:
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   248
  "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
   249
  by (induct X) (auto)
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   250
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   251
lemma list2set_thm:
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   252
  shows "set [] = {}"
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   253
  and "set (h # t) = insert h (set t)"
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
lemma list2set_rsp[quot_respect]:
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   257
  "(op \<approx> ===> op =) set set"
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   258
  by auto
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   259
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   260
definition
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   261
  rsp_fold
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   262
where
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   263
  "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
   264
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   265
primrec
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   266
  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
   267
where
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   268
  "fold_raw f z [] = z"
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   269
| "fold_raw f z (a # A) =
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   270
     (if (rsp_fold f) then
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   271
       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
   272
       else f a (fold_raw f z A)
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   273
     else z)"
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
section {* Constants on the Quotient Type *} 
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
quotient_definition
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   278
  "fdelete :: 'a fset \<Rightarrow> 'a \<Rightarrow> 'a fset" 
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   279
  is "delete_raw"
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   280
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   281
quotient_definition
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   282
  "fset_to_set :: 'a fset \<Rightarrow> 'a set" 
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   283
  is "set"
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   284
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   285
lemma funion_sym_pre:
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   286
  "a @ b \<approx> b @ a"
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   287
  by auto
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 append_rsp[quot_respect]:
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   290
  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
   291
  by (auto)
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   292
1533
5f5e99a11f66 A few more theorems in FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1518
diff changeset
   293
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
   294
  apply rule
5f5e99a11f66 A few more theorems in FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1518
diff changeset
   295
  apply simp_all
5f5e99a11f66 A few more theorems in FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1518
diff changeset
   296
  apply (induct x y rule: list_induct2')
5f5e99a11f66 A few more theorems in FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1518
diff changeset
   297
  apply simp_all
5f5e99a11f66 A few more theorems in FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1518
diff changeset
   298
  apply auto
5f5e99a11f66 A few more theorems in FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1518
diff changeset
   299
  done
5f5e99a11f66 A few more theorems in FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1518
diff changeset
   300
5f5e99a11f66 A few more theorems in FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1518
diff changeset
   301
lemma inj_map_eq_iff:
5f5e99a11f66 A few more theorems in FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1518
diff changeset
   302
  "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
   303
  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
   304
1813
69fff336dd18 Porting lemmas from Quotient package FSet to new FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1682
diff changeset
   305
quotient_definition
69fff336dd18 Porting lemmas from Quotient package FSet to new FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1682
diff changeset
   306
  "fconcat :: ('a fset) fset \<Rightarrow> 'a fset"
69fff336dd18 Porting lemmas from Quotient package FSet to new FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1682
diff changeset
   307
is
69fff336dd18 Porting lemmas from Quotient package FSet to new FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1682
diff changeset
   308
  "concat"
1533
5f5e99a11f66 A few more theorems in FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1518
diff changeset
   309
1813
69fff336dd18 Porting lemmas from Quotient package FSet to new FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1682
diff changeset
   310
lemma list_equiv_rsp[quot_respect]:
69fff336dd18 Porting lemmas from Quotient package FSet to new FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1682
diff changeset
   311
  shows "(op \<approx> ===> op \<approx> ===> op =) op \<approx> op \<approx>"
69fff336dd18 Porting lemmas from Quotient package FSet to new FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1682
diff changeset
   312
  by auto
1518
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   313
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   314
section {* lifted part *}
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
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   317
lemma fin_finsert_iff[simp]:
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   318
  "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
   319
  by (lifting memb_cons_iff)
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
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   322
  shows finsertI1: "x |\<in>| finsert x S"
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   323
  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
   324
  by (lifting memb_consI1, lifting memb_consI2)
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   325
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   326
lemma finsert_absorb[simp]:
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   327
  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
   328
  by (lifting memb_absorb)
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 fempty_not_finsert[simp]:
1533
5f5e99a11f66 A few more theorems in FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1518
diff changeset
   331
  "{||} \<noteq> finsert x S"
5f5e99a11f66 A few more theorems in FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1518
diff changeset
   332
  "finsert x S \<noteq> {||}"
1518
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   333
  by (lifting nil_not_cons)
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 finsert_left_comm:
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   336
  "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
   337
  by (lifting cons_left_comm)
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 finsert_left_idem:
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   340
  "finsert a (finsert a S) = finsert a S"
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   341
  by (lifting cons_left_idem)
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   342
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   343
lemma fsingleton_eq[simp]:
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   344
  shows "{|x|} = {|y|} \<longleftrightarrow> x = y"
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   345
  by (lifting singleton_list_eq)
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   346
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   347
text {* fset_to_set *}
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   348
1533
5f5e99a11f66 A few more theorems in FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1518
diff changeset
   349
lemma fset_to_set_simps[simp]:
1518
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   350
  "fset_to_set {||} = {}"
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   351
  "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
   352
  by (lifting list2set_thm)
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   353
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   354
lemma in_fset_to_set:
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   355
  "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
   356
  by (lifting memb_def[symmetric])
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   357
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   358
lemma none_in_fempty:
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   359
  "(\<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
   360
  by (lifting none_mem_nil)
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   361
1533
5f5e99a11f66 A few more theorems in FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1518
diff changeset
   362
lemma fset_cong:
5f5e99a11f66 A few more theorems in FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1518
diff changeset
   363
  "(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
   364
  by (lifting set_cong)
5f5e99a11f66 A few more theorems in FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1518
diff changeset
   365
1518
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   366
text {* fcard *}
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   367
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   368
lemma fcard_fempty [simp]:
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   369
  shows "fcard {||} = 0"
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   370
  by (lifting fcard_raw_nil)
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   371
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   372
lemma fcard_finsert_if [simp]:
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   373
  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
   374
  by (lifting fcard_raw_cons)
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   375
1813
69fff336dd18 Porting lemmas from Quotient package FSet to new FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1682
diff changeset
   376
lemma fcard_0: "(fcard a = 0) = (a = {||})"
69fff336dd18 Porting lemmas from Quotient package FSet to new FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1682
diff changeset
   377
  by (lifting fcard_raw_0)
69fff336dd18 Porting lemmas from Quotient package FSet to new FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1682
diff changeset
   378
1518
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   379
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
   380
  by (lifting fcard_raw_gt_0)
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   381
1813
69fff336dd18 Porting lemmas from Quotient package FSet to new FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1682
diff changeset
   382
lemma fcard_not_memb: "(x |\<notin>| xs) = (fcard (finsert x xs) = Suc (fcard xs))"
69fff336dd18 Porting lemmas from Quotient package FSet to new FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1682
diff changeset
   383
  by (lifting fcard_raw_not_memb)
69fff336dd18 Porting lemmas from Quotient package FSet to new FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1682
diff changeset
   384
69fff336dd18 Porting lemmas from Quotient package FSet to new FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1682
diff changeset
   385
lemma fcard_suc: "fcard xs = Suc n \<Longrightarrow> \<exists>a ys. a |\<notin>| ys \<and> xs = finsert a ys"
69fff336dd18 Porting lemmas from Quotient package FSet to new FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1682
diff changeset
   386
  by (lifting fcard_raw_suc)
69fff336dd18 Porting lemmas from Quotient package FSet to new FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1682
diff changeset
   387
1518
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   388
text {* funion *}
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   389
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   390
lemma funion_simps[simp]:
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   391
  "{||} |\<union>| ys = ys"
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   392
  "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
   393
  by (lifting append.simps)
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   394
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   395
lemma funion_sym:
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   396
  "a |\<union>| b = b |\<union>| a"
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   397
  by (lifting funion_sym_pre)
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   398
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   399
lemma funion_assoc:
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   400
 "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
   401
  by (lifting append_assoc)
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   402
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   403
section {* Induction and Cases rules for finite sets *}
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   404
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   405
lemma fset_strong_cases:
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   406
  "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
   407
  by (lifting finite_set_raw_strong_cases)
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   408
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   409
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
   410
  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
   411
  by (lifting list.exhaust)
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   412
1533
5f5e99a11f66 A few more theorems in FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1518
diff changeset
   413
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
   414
  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
   415
  by (lifting list.induct)
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   416
1533
5f5e99a11f66 A few more theorems in FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1518
diff changeset
   417
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
   418
  assumes prem1: "P {||}" 
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   419
  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
   420
  shows "P S"
1533
5f5e99a11f66 A few more theorems in FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1518
diff changeset
   421
proof(induct S rule: fset_induct_weak)
1518
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   422
  case fempty
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   423
  show "P {||}" by (rule prem1)
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   424
next
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   425
  case (finsert x S)
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   426
  have asm: "P S" by fact
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   427
  show "P (finsert x S)"
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   428
  proof(cases "x |\<in>| S")
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   429
    case True
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   430
    have "x |\<in>| S" by fact
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   431
    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
   432
  next
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   433
    case False
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   434
    have "x |\<notin>| S" by fact
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   435
    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
   436
  qed
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   437
qed
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   438
1533
5f5e99a11f66 A few more theorems in FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1518
diff changeset
   439
lemma fset_induct2:
5f5e99a11f66 A few more theorems in FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1518
diff changeset
   440
  "P {||} {||} \<Longrightarrow>
5f5e99a11f66 A few more theorems in FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1518
diff changeset
   441
  (\<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
   442
  (\<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
   443
  (\<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
   444
  P xsa ysa"
5f5e99a11f66 A few more theorems in FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1518
diff changeset
   445
  apply (induct xsa arbitrary: ysa)
5f5e99a11f66 A few more theorems in FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1518
diff changeset
   446
  apply (induct_tac x rule: fset_induct)
5f5e99a11f66 A few more theorems in FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1518
diff changeset
   447
  apply simp_all
5f5e99a11f66 A few more theorems in FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1518
diff changeset
   448
  apply (induct_tac xa rule: fset_induct)
5f5e99a11f66 A few more theorems in FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1518
diff changeset
   449
  apply simp_all
5f5e99a11f66 A few more theorems in FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1518
diff changeset
   450
  done
1518
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   451
1533
5f5e99a11f66 A few more theorems in FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1518
diff changeset
   452
(* fmap *)
5f5e99a11f66 A few more theorems in FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1518
diff changeset
   453
lemma fmap_simps[simp]:
5f5e99a11f66 A few more theorems in FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1518
diff changeset
   454
  "fmap (f :: 'a \<Rightarrow> 'b) {||} = {||}"
5f5e99a11f66 A few more theorems in FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1518
diff changeset
   455
  "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
   456
  by (lifting map.simps)
5f5e99a11f66 A few more theorems in FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1518
diff changeset
   457
5f5e99a11f66 A few more theorems in FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1518
diff changeset
   458
lemma fmap_set_image:
5f5e99a11f66 A few more theorems in FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1518
diff changeset
   459
  "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
   460
  apply (induct fs)
5f5e99a11f66 A few more theorems in FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1518
diff changeset
   461
  apply (simp_all)
5f5e99a11f66 A few more theorems in FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1518
diff changeset
   462
done
5f5e99a11f66 A few more theorems in FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1518
diff changeset
   463
5f5e99a11f66 A few more theorems in FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1518
diff changeset
   464
lemma inj_fmap_eq_iff:
5f5e99a11f66 A few more theorems in FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1518
diff changeset
   465
  "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
   466
  by (lifting inj_map_eq_iff)
5f5e99a11f66 A few more theorems in FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1518
diff changeset
   467
1813
69fff336dd18 Porting lemmas from Quotient package FSet to new FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1682
diff changeset
   468
lemma fmap_funion: "fmap f (a |\<union>| b) = fmap f a |\<union>| fmap f b"
69fff336dd18 Porting lemmas from Quotient package FSet to new FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1682
diff changeset
   469
  by (lifting map_append)
69fff336dd18 Porting lemmas from Quotient package FSet to new FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1682
diff changeset
   470
1533
5f5e99a11f66 A few more theorems in FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1518
diff changeset
   471
ML {*
5f5e99a11f66 A few more theorems in FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1518
diff changeset
   472
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
   473
  | 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
   474
*}
1518
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   475
1682
ae54ce4cde54 Remove list_eq notation.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1533
diff changeset
   476
no_notation
ae54ce4cde54 Remove list_eq notation.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1533
diff changeset
   477
  list_eq (infix "\<approx>" 50)
ae54ce4cde54 Remove list_eq notation.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 1533
diff changeset
   478
1518
212629c90971 Added a cleaned version of FSet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   479
end