src/HOL/Library/Cset.thy
author haftmann
Sat, 27 Aug 2011 09:44:45 +0200
changeset 44558 cc878a312673
parent 44555 da75ffe3d988
child 44563 01b2732cf4ad
permissions -rw-r--r--
Cset, Dlist_Cset, List_Cset: restructured
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
31807
039893a9a77d added List_Set and Code_Set theories
haftmann
parents:
diff changeset
     1
039893a9a77d added List_Set and Code_Set theories
haftmann
parents:
diff changeset
     2
(* Author: Florian Haftmann, TU Muenchen *)
039893a9a77d added List_Set and Code_Set theories
haftmann
parents:
diff changeset
     3
40672
abd4e7358847 replaced misleading Fset/fset name -- these do not stand for finite sets
haftmann
parents: 40604
diff changeset
     4
header {* A dedicated set type which is executable on its finite part *}
31807
039893a9a77d added List_Set and Code_Set theories
haftmann
parents:
diff changeset
     5
40672
abd4e7358847 replaced misleading Fset/fset name -- these do not stand for finite sets
haftmann
parents: 40604
diff changeset
     6
theory Cset
37024
e938a0b5286e renamed List_Set to the now more appropriate More_Set
haftmann
parents: 37023
diff changeset
     7
imports More_Set More_List
31807
039893a9a77d added List_Set and Code_Set theories
haftmann
parents:
diff changeset
     8
begin
039893a9a77d added List_Set and Code_Set theories
haftmann
parents:
diff changeset
     9
039893a9a77d added List_Set and Code_Set theories
haftmann
parents:
diff changeset
    10
subsection {* Lifting *}
039893a9a77d added List_Set and Code_Set theories
haftmann
parents:
diff changeset
    11
40672
abd4e7358847 replaced misleading Fset/fset name -- these do not stand for finite sets
haftmann
parents: 40604
diff changeset
    12
typedef (open) 'a set = "UNIV :: 'a set set"
44555
da75ffe3d988 separating predicates and sets syntactically
haftmann
parents: 43971
diff changeset
    13
  morphisms set_of Set by rule+
40672
abd4e7358847 replaced misleading Fset/fset name -- these do not stand for finite sets
haftmann
parents: 40604
diff changeset
    14
hide_type (open) set
31807
039893a9a77d added List_Set and Code_Set theories
haftmann
parents:
diff changeset
    15
44555
da75ffe3d988 separating predicates and sets syntactically
haftmann
parents: 43971
diff changeset
    16
lemma set_of_Set [simp]:
da75ffe3d988 separating predicates and sets syntactically
haftmann
parents: 43971
diff changeset
    17
  "set_of (Set A) = A"
da75ffe3d988 separating predicates and sets syntactically
haftmann
parents: 43971
diff changeset
    18
  by (rule Set_inverse) rule
da75ffe3d988 separating predicates and sets syntactically
haftmann
parents: 43971
diff changeset
    19
da75ffe3d988 separating predicates and sets syntactically
haftmann
parents: 43971
diff changeset
    20
lemma Set_set_of [simp]:
da75ffe3d988 separating predicates and sets syntactically
haftmann
parents: 43971
diff changeset
    21
  "Set (set_of A) = A"
da75ffe3d988 separating predicates and sets syntactically
haftmann
parents: 43971
diff changeset
    22
  by (fact set_of_inverse)
da75ffe3d988 separating predicates and sets syntactically
haftmann
parents: 43971
diff changeset
    23
da75ffe3d988 separating predicates and sets syntactically
haftmann
parents: 43971
diff changeset
    24
definition member :: "'a Cset.set \<Rightarrow> 'a \<Rightarrow> bool" where
da75ffe3d988 separating predicates and sets syntactically
haftmann
parents: 43971
diff changeset
    25
  "member A x \<longleftrightarrow> x \<in> set_of A"
da75ffe3d988 separating predicates and sets syntactically
haftmann
parents: 43971
diff changeset
    26
da75ffe3d988 separating predicates and sets syntactically
haftmann
parents: 43971
diff changeset
    27
lemma member_set_of:
da75ffe3d988 separating predicates and sets syntactically
haftmann
parents: 43971
diff changeset
    28
  "set_of = member"
da75ffe3d988 separating predicates and sets syntactically
haftmann
parents: 43971
diff changeset
    29
  by (rule ext)+ (simp add: member_def mem_def)
da75ffe3d988 separating predicates and sets syntactically
haftmann
parents: 43971
diff changeset
    30
40672
abd4e7358847 replaced misleading Fset/fset name -- these do not stand for finite sets
haftmann
parents: 40604
diff changeset
    31
lemma member_Set [simp]:
44555
da75ffe3d988 separating predicates and sets syntactically
haftmann
parents: 43971
diff changeset
    32
  "member (Set A) x \<longleftrightarrow> x \<in> A"
da75ffe3d988 separating predicates and sets syntactically
haftmann
parents: 43971
diff changeset
    33
  by (simp add: member_def)
37468
a2a3b62fc819 quickcheck for fsets
haftmann
parents: 37024
diff changeset
    34
40672
abd4e7358847 replaced misleading Fset/fset name -- these do not stand for finite sets
haftmann
parents: 40604
diff changeset
    35
lemma Set_inject [simp]:
abd4e7358847 replaced misleading Fset/fset name -- these do not stand for finite sets
haftmann
parents: 40604
diff changeset
    36
  "Set A = Set B \<longleftrightarrow> A = B"
abd4e7358847 replaced misleading Fset/fset name -- these do not stand for finite sets
haftmann
parents: 40604
diff changeset
    37
  by (simp add: Set_inject)
37468
a2a3b62fc819 quickcheck for fsets
haftmann
parents: 37024
diff changeset
    38
40672
abd4e7358847 replaced misleading Fset/fset name -- these do not stand for finite sets
haftmann
parents: 40604
diff changeset
    39
lemma set_eq_iff:
39380
5a2662c1e44a established emerging canonical names *_eqI and *_eq_iff
haftmann
parents: 39302
diff changeset
    40
  "A = B \<longleftrightarrow> member A = member B"
44555
da75ffe3d988 separating predicates and sets syntactically
haftmann
parents: 43971
diff changeset
    41
  by (auto simp add: fun_eq_iff set_of_inject [symmetric] member_def mem_def)
40672
abd4e7358847 replaced misleading Fset/fset name -- these do not stand for finite sets
haftmann
parents: 40604
diff changeset
    42
hide_fact (open) set_eq_iff
39380
5a2662c1e44a established emerging canonical names *_eqI and *_eq_iff
haftmann
parents: 39302
diff changeset
    43
40672
abd4e7358847 replaced misleading Fset/fset name -- these do not stand for finite sets
haftmann
parents: 40604
diff changeset
    44
lemma set_eqI:
37473
013f78aed840 extensionality rule fset_eqI
haftmann
parents: 37468
diff changeset
    45
  "member A = member B \<Longrightarrow> A = B"
40672
abd4e7358847 replaced misleading Fset/fset name -- these do not stand for finite sets
haftmann
parents: 40604
diff changeset
    46
  by (simp add: Cset.set_eq_iff)
abd4e7358847 replaced misleading Fset/fset name -- these do not stand for finite sets
haftmann
parents: 40604
diff changeset
    47
hide_fact (open) set_eqI
37473
013f78aed840 extensionality rule fset_eqI
haftmann
parents: 37468
diff changeset
    48
34048
369509057220 using existing lattice classes
haftmann
parents: 33939
diff changeset
    49
subsection {* Lattice instantiation *}
369509057220 using existing lattice classes
haftmann
parents: 33939
diff changeset
    50
40672
abd4e7358847 replaced misleading Fset/fset name -- these do not stand for finite sets
haftmann
parents: 40604
diff changeset
    51
instantiation Cset.set :: (type) boolean_algebra
34048
369509057220 using existing lattice classes
haftmann
parents: 33939
diff changeset
    52
begin
369509057220 using existing lattice classes
haftmann
parents: 33939
diff changeset
    53
40672
abd4e7358847 replaced misleading Fset/fset name -- these do not stand for finite sets
haftmann
parents: 40604
diff changeset
    54
definition less_eq_set :: "'a Cset.set \<Rightarrow> 'a Cset.set \<Rightarrow> bool" where
44555
da75ffe3d988 separating predicates and sets syntactically
haftmann
parents: 43971
diff changeset
    55
  [simp]: "A \<le> B \<longleftrightarrow> set_of A \<subseteq> set_of B"
34048
369509057220 using existing lattice classes
haftmann
parents: 33939
diff changeset
    56
40672
abd4e7358847 replaced misleading Fset/fset name -- these do not stand for finite sets
haftmann
parents: 40604
diff changeset
    57
definition less_set :: "'a Cset.set \<Rightarrow> 'a Cset.set \<Rightarrow> bool" where
44555
da75ffe3d988 separating predicates and sets syntactically
haftmann
parents: 43971
diff changeset
    58
  [simp]: "A < B \<longleftrightarrow> set_of A \<subset> set_of B"
34048
369509057220 using existing lattice classes
haftmann
parents: 33939
diff changeset
    59
40672
abd4e7358847 replaced misleading Fset/fset name -- these do not stand for finite sets
haftmann
parents: 40604
diff changeset
    60
definition inf_set :: "'a Cset.set \<Rightarrow> 'a Cset.set \<Rightarrow> 'a Cset.set" where
44555
da75ffe3d988 separating predicates and sets syntactically
haftmann
parents: 43971
diff changeset
    61
  [simp]: "inf A B = Set (set_of A \<inter> set_of B)"
34048
369509057220 using existing lattice classes
haftmann
parents: 33939
diff changeset
    62
40672
abd4e7358847 replaced misleading Fset/fset name -- these do not stand for finite sets
haftmann
parents: 40604
diff changeset
    63
definition sup_set :: "'a Cset.set \<Rightarrow> 'a Cset.set \<Rightarrow> 'a Cset.set" where
44555
da75ffe3d988 separating predicates and sets syntactically
haftmann
parents: 43971
diff changeset
    64
  [simp]: "sup A B = Set (set_of A \<union> set_of B)"
34048
369509057220 using existing lattice classes
haftmann
parents: 33939
diff changeset
    65
40672
abd4e7358847 replaced misleading Fset/fset name -- these do not stand for finite sets
haftmann
parents: 40604
diff changeset
    66
definition bot_set :: "'a Cset.set" where
abd4e7358847 replaced misleading Fset/fset name -- these do not stand for finite sets
haftmann
parents: 40604
diff changeset
    67
  [simp]: "bot = Set {}"
34048
369509057220 using existing lattice classes
haftmann
parents: 33939
diff changeset
    68
40672
abd4e7358847 replaced misleading Fset/fset name -- these do not stand for finite sets
haftmann
parents: 40604
diff changeset
    69
definition top_set :: "'a Cset.set" where
abd4e7358847 replaced misleading Fset/fset name -- these do not stand for finite sets
haftmann
parents: 40604
diff changeset
    70
  [simp]: "top = Set UNIV"
34048
369509057220 using existing lattice classes
haftmann
parents: 33939
diff changeset
    71
40672
abd4e7358847 replaced misleading Fset/fset name -- these do not stand for finite sets
haftmann
parents: 40604
diff changeset
    72
definition uminus_set :: "'a Cset.set \<Rightarrow> 'a Cset.set" where
44555
da75ffe3d988 separating predicates and sets syntactically
haftmann
parents: 43971
diff changeset
    73
  [simp]: "- A = Set (- (set_of A))"
34048
369509057220 using existing lattice classes
haftmann
parents: 33939
diff changeset
    74
40672
abd4e7358847 replaced misleading Fset/fset name -- these do not stand for finite sets
haftmann
parents: 40604
diff changeset
    75
definition minus_set :: "'a Cset.set \<Rightarrow> 'a Cset.set \<Rightarrow> 'a Cset.set" where
44555
da75ffe3d988 separating predicates and sets syntactically
haftmann
parents: 43971
diff changeset
    76
  [simp]: "A - B = Set (set_of A - set_of B)"
34048
369509057220 using existing lattice classes
haftmann
parents: 33939
diff changeset
    77
369509057220 using existing lattice classes
haftmann
parents: 33939
diff changeset
    78
instance proof
44555
da75ffe3d988 separating predicates and sets syntactically
haftmann
parents: 43971
diff changeset
    79
qed (auto intro!: Cset.set_eqI simp add: member_def mem_def)
34048
369509057220 using existing lattice classes
haftmann
parents: 33939
diff changeset
    80
369509057220 using existing lattice classes
haftmann
parents: 33939
diff changeset
    81
end
369509057220 using existing lattice classes
haftmann
parents: 33939
diff changeset
    82
40672
abd4e7358847 replaced misleading Fset/fset name -- these do not stand for finite sets
haftmann
parents: 40604
diff changeset
    83
instantiation Cset.set :: (type) complete_lattice
34048
369509057220 using existing lattice classes
haftmann
parents: 33939
diff changeset
    84
begin
369509057220 using existing lattice classes
haftmann
parents: 33939
diff changeset
    85
40672
abd4e7358847 replaced misleading Fset/fset name -- these do not stand for finite sets
haftmann
parents: 40604
diff changeset
    86
definition Inf_set :: "'a Cset.set set \<Rightarrow> 'a Cset.set" where
44555
da75ffe3d988 separating predicates and sets syntactically
haftmann
parents: 43971
diff changeset
    87
  [simp]: "Inf_set As = Set (Inf (image set_of As))"
34048
369509057220 using existing lattice classes
haftmann
parents: 33939
diff changeset
    88
40672
abd4e7358847 replaced misleading Fset/fset name -- these do not stand for finite sets
haftmann
parents: 40604
diff changeset
    89
definition Sup_set :: "'a Cset.set set \<Rightarrow> 'a Cset.set" where
44555
da75ffe3d988 separating predicates and sets syntactically
haftmann
parents: 43971
diff changeset
    90
  [simp]: "Sup_set As = Set (Sup (image set_of As))"
34048
369509057220 using existing lattice classes
haftmann
parents: 33939
diff changeset
    91
369509057220 using existing lattice classes
haftmann
parents: 33939
diff changeset
    92
instance proof
44555
da75ffe3d988 separating predicates and sets syntactically
haftmann
parents: 43971
diff changeset
    93
qed (auto simp add: le_fun_def)
34048
369509057220 using existing lattice classes
haftmann
parents: 33939
diff changeset
    94
369509057220 using existing lattice classes
haftmann
parents: 33939
diff changeset
    95
end
369509057220 using existing lattice classes
haftmann
parents: 33939
diff changeset
    96
44555
da75ffe3d988 separating predicates and sets syntactically
haftmann
parents: 43971
diff changeset
    97
instance Cset.set :: (type) complete_boolean_algebra proof
da75ffe3d988 separating predicates and sets syntactically
haftmann
parents: 43971
diff changeset
    98
qed (unfold INF_def SUP_def, auto)
da75ffe3d988 separating predicates and sets syntactically
haftmann
parents: 43971
diff changeset
    99
37023
efc202e1677e added theory More_List
haftmann
parents: 36176
diff changeset
   100
31807
039893a9a77d added List_Set and Code_Set theories
haftmann
parents:
diff changeset
   101
subsection {* Basic operations *}
039893a9a77d added List_Set and Code_Set theories
haftmann
parents:
diff changeset
   102
43971
892030194015 added operations to Cset with code equations in backing implementations
Andreas Lochbihler
parents: 43241
diff changeset
   103
abbreviation empty :: "'a Cset.set" where "empty \<equiv> bot"
892030194015 added operations to Cset with code equations in backing implementations
Andreas Lochbihler
parents: 43241
diff changeset
   104
hide_const (open) empty
892030194015 added operations to Cset with code equations in backing implementations
Andreas Lochbihler
parents: 43241
diff changeset
   105
892030194015 added operations to Cset with code equations in backing implementations
Andreas Lochbihler
parents: 43241
diff changeset
   106
abbreviation UNIV :: "'a Cset.set" where "UNIV \<equiv> top"
892030194015 added operations to Cset with code equations in backing implementations
Andreas Lochbihler
parents: 43241
diff changeset
   107
hide_const (open) UNIV
892030194015 added operations to Cset with code equations in backing implementations
Andreas Lochbihler
parents: 43241
diff changeset
   108
40672
abd4e7358847 replaced misleading Fset/fset name -- these do not stand for finite sets
haftmann
parents: 40604
diff changeset
   109
definition is_empty :: "'a Cset.set \<Rightarrow> bool" where
44555
da75ffe3d988 separating predicates and sets syntactically
haftmann
parents: 43971
diff changeset
   110
  [simp]: "is_empty A \<longleftrightarrow> More_Set.is_empty (set_of A)"
31807
039893a9a77d added List_Set and Code_Set theories
haftmann
parents:
diff changeset
   111
40672
abd4e7358847 replaced misleading Fset/fset name -- these do not stand for finite sets
haftmann
parents: 40604
diff changeset
   112
definition insert :: "'a \<Rightarrow> 'a Cset.set \<Rightarrow> 'a Cset.set" where
44555
da75ffe3d988 separating predicates and sets syntactically
haftmann
parents: 43971
diff changeset
   113
  [simp]: "insert x A = Set (Set.insert x (set_of A))"
31807
039893a9a77d added List_Set and Code_Set theories
haftmann
parents:
diff changeset
   114
40672
abd4e7358847 replaced misleading Fset/fset name -- these do not stand for finite sets
haftmann
parents: 40604
diff changeset
   115
definition remove :: "'a \<Rightarrow> 'a Cset.set \<Rightarrow> 'a Cset.set" where
44555
da75ffe3d988 separating predicates and sets syntactically
haftmann
parents: 43971
diff changeset
   116
  [simp]: "remove x A = Set (More_Set.remove x (set_of A))"
31807
039893a9a77d added List_Set and Code_Set theories
haftmann
parents:
diff changeset
   117
40672
abd4e7358847 replaced misleading Fset/fset name -- these do not stand for finite sets
haftmann
parents: 40604
diff changeset
   118
definition map :: "('a \<Rightarrow> 'b) \<Rightarrow> 'a Cset.set \<Rightarrow> 'b Cset.set" where
44555
da75ffe3d988 separating predicates and sets syntactically
haftmann
parents: 43971
diff changeset
   119
  [simp]: "map f A = Set (image f (set_of A))"
31807
039893a9a77d added List_Set and Code_Set theories
haftmann
parents:
diff changeset
   120
41505
6d19301074cf "enriched_type" replaces less specific "type_lifting"
haftmann
parents: 41372
diff changeset
   121
enriched_type map: map
41372
551eb49a6e91 tuned type_lifting declarations
haftmann
parents: 40968
diff changeset
   122
  by (simp_all add: fun_eq_iff image_compose)
40604
c0770657c8de mapper for fset type
haftmann
parents: 39929
diff changeset
   123
40672
abd4e7358847 replaced misleading Fset/fset name -- these do not stand for finite sets
haftmann
parents: 40604
diff changeset
   124
definition filter :: "('a \<Rightarrow> bool) \<Rightarrow> 'a Cset.set \<Rightarrow> 'a Cset.set" where
44555
da75ffe3d988 separating predicates and sets syntactically
haftmann
parents: 43971
diff changeset
   125
  [simp]: "filter P A = Set (More_Set.project P (set_of A))"
31807
039893a9a77d added List_Set and Code_Set theories
haftmann
parents:
diff changeset
   126
40672
abd4e7358847 replaced misleading Fset/fset name -- these do not stand for finite sets
haftmann
parents: 40604
diff changeset
   127
definition forall :: "('a \<Rightarrow> bool) \<Rightarrow> 'a Cset.set \<Rightarrow> bool" where
44555
da75ffe3d988 separating predicates and sets syntactically
haftmann
parents: 43971
diff changeset
   128
  [simp]: "forall P A \<longleftrightarrow> Ball (set_of A) P"
31807
039893a9a77d added List_Set and Code_Set theories
haftmann
parents:
diff changeset
   129
40672
abd4e7358847 replaced misleading Fset/fset name -- these do not stand for finite sets
haftmann
parents: 40604
diff changeset
   130
definition exists :: "('a \<Rightarrow> bool) \<Rightarrow> 'a Cset.set \<Rightarrow> bool" where
44555
da75ffe3d988 separating predicates and sets syntactically
haftmann
parents: 43971
diff changeset
   131
  [simp]: "exists P A \<longleftrightarrow> Bex (set_of A) P"
31807
039893a9a77d added List_Set and Code_Set theories
haftmann
parents:
diff changeset
   132
40672
abd4e7358847 replaced misleading Fset/fset name -- these do not stand for finite sets
haftmann
parents: 40604
diff changeset
   133
definition card :: "'a Cset.set \<Rightarrow> nat" where
44555
da75ffe3d988 separating predicates and sets syntactically
haftmann
parents: 43971
diff changeset
   134
  [simp]: "card A = Finite_Set.card (set_of A)"
43241
93b1183e43e5 splitting Cset into Cset and List_Cset
bulwahn
parents: 41505
diff changeset
   135
  
34048
369509057220 using existing lattice classes
haftmann
parents: 33939
diff changeset
   136
context complete_lattice
369509057220 using existing lattice classes
haftmann
parents: 33939
diff changeset
   137
begin
31807
039893a9a77d added List_Set and Code_Set theories
haftmann
parents:
diff changeset
   138
40672
abd4e7358847 replaced misleading Fset/fset name -- these do not stand for finite sets
haftmann
parents: 40604
diff changeset
   139
definition Infimum :: "'a Cset.set \<Rightarrow> 'a" where
44555
da75ffe3d988 separating predicates and sets syntactically
haftmann
parents: 43971
diff changeset
   140
  [simp]: "Infimum A = Inf (set_of A)"
31807
039893a9a77d added List_Set and Code_Set theories
haftmann
parents:
diff changeset
   141
40672
abd4e7358847 replaced misleading Fset/fset name -- these do not stand for finite sets
haftmann
parents: 40604
diff changeset
   142
definition Supremum :: "'a Cset.set \<Rightarrow> 'a" where
44555
da75ffe3d988 separating predicates and sets syntactically
haftmann
parents: 43971
diff changeset
   143
  [simp]: "Supremum A = Sup (set_of A)"
34048
369509057220 using existing lattice classes
haftmann
parents: 33939
diff changeset
   144
369509057220 using existing lattice classes
haftmann
parents: 33939
diff changeset
   145
end
31807
039893a9a77d added List_Set and Code_Set theories
haftmann
parents:
diff changeset
   146
43971
892030194015 added operations to Cset with code equations in backing implementations
Andreas Lochbihler
parents: 43241
diff changeset
   147
subsection {* More operations *}
892030194015 added operations to Cset with code equations in backing implementations
Andreas Lochbihler
parents: 43241
diff changeset
   148
892030194015 added operations to Cset with code equations in backing implementations
Andreas Lochbihler
parents: 43241
diff changeset
   149
text {* conversion from @{typ "'a list"} *}
892030194015 added operations to Cset with code equations in backing implementations
Andreas Lochbihler
parents: 43241
diff changeset
   150
892030194015 added operations to Cset with code equations in backing implementations
Andreas Lochbihler
parents: 43241
diff changeset
   151
definition set :: "'a list \<Rightarrow> 'a Cset.set" where
892030194015 added operations to Cset with code equations in backing implementations
Andreas Lochbihler
parents: 43241
diff changeset
   152
  "set xs = Set (List.set xs)"
892030194015 added operations to Cset with code equations in backing implementations
Andreas Lochbihler
parents: 43241
diff changeset
   153
hide_const (open) set
892030194015 added operations to Cset with code equations in backing implementations
Andreas Lochbihler
parents: 43241
diff changeset
   154
44558
cc878a312673 Cset, Dlist_Cset, List_Cset: restructured
haftmann
parents: 44555
diff changeset
   155
definition coset :: "'a list \<Rightarrow> 'a Cset.set" where
cc878a312673 Cset, Dlist_Cset, List_Cset: restructured
haftmann
parents: 44555
diff changeset
   156
  "coset xs = Set (- List.set xs)"
cc878a312673 Cset, Dlist_Cset, List_Cset: restructured
haftmann
parents: 44555
diff changeset
   157
hide_const (open) coset
cc878a312673 Cset, Dlist_Cset, List_Cset: restructured
haftmann
parents: 44555
diff changeset
   158
43971
892030194015 added operations to Cset with code equations in backing implementations
Andreas Lochbihler
parents: 43241
diff changeset
   159
text {* conversion from @{typ "'a Predicate.pred"} *}
892030194015 added operations to Cset with code equations in backing implementations
Andreas Lochbihler
parents: 43241
diff changeset
   160
44555
da75ffe3d988 separating predicates and sets syntactically
haftmann
parents: 43971
diff changeset
   161
definition pred_of_cset :: "'a Cset.set \<Rightarrow> 'a Predicate.pred" where
da75ffe3d988 separating predicates and sets syntactically
haftmann
parents: 43971
diff changeset
   162
  [code del]: "pred_of_cset = Predicate.Pred \<circ> Cset.member"
43971
892030194015 added operations to Cset with code equations in backing implementations
Andreas Lochbihler
parents: 43241
diff changeset
   163
44555
da75ffe3d988 separating predicates and sets syntactically
haftmann
parents: 43971
diff changeset
   164
definition of_pred :: "'a Predicate.pred \<Rightarrow> 'a Cset.set" where
da75ffe3d988 separating predicates and sets syntactically
haftmann
parents: 43971
diff changeset
   165
  "of_pred = Cset.Set \<circ> Collect \<circ> Predicate.eval"
43971
892030194015 added operations to Cset with code equations in backing implementations
Andreas Lochbihler
parents: 43241
diff changeset
   166
44555
da75ffe3d988 separating predicates and sets syntactically
haftmann
parents: 43971
diff changeset
   167
definition of_seq :: "'a Predicate.seq \<Rightarrow> 'a Cset.set" where 
da75ffe3d988 separating predicates and sets syntactically
haftmann
parents: 43971
diff changeset
   168
  "of_seq = of_pred \<circ> Predicate.pred_of_seq"
43971
892030194015 added operations to Cset with code equations in backing implementations
Andreas Lochbihler
parents: 43241
diff changeset
   169
892030194015 added operations to Cset with code equations in backing implementations
Andreas Lochbihler
parents: 43241
diff changeset
   170
text {* monad operations *}
892030194015 added operations to Cset with code equations in backing implementations
Andreas Lochbihler
parents: 43241
diff changeset
   171
892030194015 added operations to Cset with code equations in backing implementations
Andreas Lochbihler
parents: 43241
diff changeset
   172
definition single :: "'a \<Rightarrow> 'a Cset.set" where
892030194015 added operations to Cset with code equations in backing implementations
Andreas Lochbihler
parents: 43241
diff changeset
   173
  "single a = Set {a}"
892030194015 added operations to Cset with code equations in backing implementations
Andreas Lochbihler
parents: 43241
diff changeset
   174
44555
da75ffe3d988 separating predicates and sets syntactically
haftmann
parents: 43971
diff changeset
   175
definition bind :: "'a Cset.set \<Rightarrow> ('a \<Rightarrow> 'b Cset.set) \<Rightarrow> 'b Cset.set" (infixl "\<guillemotright>=" 70) where
da75ffe3d988 separating predicates and sets syntactically
haftmann
parents: 43971
diff changeset
   176
  "A \<guillemotright>= f = (SUP x : set_of A. f x)"
da75ffe3d988 separating predicates and sets syntactically
haftmann
parents: 43971
diff changeset
   177
31807
039893a9a77d added List_Set and Code_Set theories
haftmann
parents:
diff changeset
   178
31846
89c37daebfdd added Inter, Union
haftmann
parents: 31807
diff changeset
   179
subsection {* Simplified simprules *}
89c37daebfdd added Inter, Union
haftmann
parents: 31807
diff changeset
   180
44555
da75ffe3d988 separating predicates and sets syntactically
haftmann
parents: 43971
diff changeset
   181
lemma empty_simp [simp]: "member Cset.empty = bot"
da75ffe3d988 separating predicates and sets syntactically
haftmann
parents: 43971
diff changeset
   182
  by (simp add: fun_eq_iff bot_apply)
43971
892030194015 added operations to Cset with code equations in backing implementations
Andreas Lochbihler
parents: 43241
diff changeset
   183
44555
da75ffe3d988 separating predicates and sets syntactically
haftmann
parents: 43971
diff changeset
   184
lemma UNIV_simp [simp]: "member Cset.UNIV = top"
da75ffe3d988 separating predicates and sets syntactically
haftmann
parents: 43971
diff changeset
   185
  by (simp add: fun_eq_iff top_apply)
43971
892030194015 added operations to Cset with code equations in backing implementations
Andreas Lochbihler
parents: 43241
diff changeset
   186
31846
89c37daebfdd added Inter, Union
haftmann
parents: 31807
diff changeset
   187
lemma is_empty_simp [simp]:
44555
da75ffe3d988 separating predicates and sets syntactically
haftmann
parents: 43971
diff changeset
   188
  "is_empty A \<longleftrightarrow> set_of A = {}"
37024
e938a0b5286e renamed List_Set to the now more appropriate More_Set
haftmann
parents: 37023
diff changeset
   189
  by (simp add: More_Set.is_empty_def)
31846
89c37daebfdd added Inter, Union
haftmann
parents: 31807
diff changeset
   190
declare is_empty_def [simp del]
89c37daebfdd added Inter, Union
haftmann
parents: 31807
diff changeset
   191
89c37daebfdd added Inter, Union
haftmann
parents: 31807
diff changeset
   192
lemma remove_simp [simp]:
44555
da75ffe3d988 separating predicates and sets syntactically
haftmann
parents: 43971
diff changeset
   193
  "remove x A = Set (set_of A - {x})"
37024
e938a0b5286e renamed List_Set to the now more appropriate More_Set
haftmann
parents: 37023
diff changeset
   194
  by (simp add: More_Set.remove_def)
31846
89c37daebfdd added Inter, Union
haftmann
parents: 31807
diff changeset
   195
declare remove_def [simp del]
89c37daebfdd added Inter, Union
haftmann
parents: 31807
diff changeset
   196
31847
7de0e20ca24d Executable_Set now based on Code_Set
haftmann
parents: 31846
diff changeset
   197
lemma filter_simp [simp]:
44555
da75ffe3d988 separating predicates and sets syntactically
haftmann
parents: 43971
diff changeset
   198
  "filter P A = Set {x \<in> set_of A. P x}"
37024
e938a0b5286e renamed List_Set to the now more appropriate More_Set
haftmann
parents: 37023
diff changeset
   199
  by (simp add: More_Set.project_def)
31847
7de0e20ca24d Executable_Set now based on Code_Set
haftmann
parents: 31846
diff changeset
   200
declare filter_def [simp del]
31846
89c37daebfdd added Inter, Union
haftmann
parents: 31807
diff changeset
   201
44555
da75ffe3d988 separating predicates and sets syntactically
haftmann
parents: 43971
diff changeset
   202
lemma set_of_set [simp]:
da75ffe3d988 separating predicates and sets syntactically
haftmann
parents: 43971
diff changeset
   203
  "set_of (Cset.set xs) = set xs"
43971
892030194015 added operations to Cset with code equations in backing implementations
Andreas Lochbihler
parents: 43241
diff changeset
   204
  by (simp add: set_def)
44555
da75ffe3d988 separating predicates and sets syntactically
haftmann
parents: 43971
diff changeset
   205
hide_fact (open) set_def
43971
892030194015 added operations to Cset with code equations in backing implementations
Andreas Lochbihler
parents: 43241
diff changeset
   206
44558
cc878a312673 Cset, Dlist_Cset, List_Cset: restructured
haftmann
parents: 44555
diff changeset
   207
lemma member_set [simp]:
cc878a312673 Cset, Dlist_Cset, List_Cset: restructured
haftmann
parents: 44555
diff changeset
   208
  "member (Cset.set xs) = (\<lambda>x. x \<in> set xs)"
cc878a312673 Cset, Dlist_Cset, List_Cset: restructured
haftmann
parents: 44555
diff changeset
   209
  by (simp add: fun_eq_iff member_def)
cc878a312673 Cset, Dlist_Cset, List_Cset: restructured
haftmann
parents: 44555
diff changeset
   210
hide_fact (open) member_set
cc878a312673 Cset, Dlist_Cset, List_Cset: restructured
haftmann
parents: 44555
diff changeset
   211
cc878a312673 Cset, Dlist_Cset, List_Cset: restructured
haftmann
parents: 44555
diff changeset
   212
lemma set_of_coset [simp]:
cc878a312673 Cset, Dlist_Cset, List_Cset: restructured
haftmann
parents: 44555
diff changeset
   213
  "set_of (Cset.coset xs) = - set xs"
cc878a312673 Cset, Dlist_Cset, List_Cset: restructured
haftmann
parents: 44555
diff changeset
   214
  by (simp add: coset_def)
cc878a312673 Cset, Dlist_Cset, List_Cset: restructured
haftmann
parents: 44555
diff changeset
   215
hide_fact (open) coset_def
cc878a312673 Cset, Dlist_Cset, List_Cset: restructured
haftmann
parents: 44555
diff changeset
   216
cc878a312673 Cset, Dlist_Cset, List_Cset: restructured
haftmann
parents: 44555
diff changeset
   217
lemma member_coset [simp]:
cc878a312673 Cset, Dlist_Cset, List_Cset: restructured
haftmann
parents: 44555
diff changeset
   218
  "member (Cset.coset xs) = (\<lambda>x. x \<in> - set xs)"
cc878a312673 Cset, Dlist_Cset, List_Cset: restructured
haftmann
parents: 44555
diff changeset
   219
  by (simp add: fun_eq_iff member_def)
cc878a312673 Cset, Dlist_Cset, List_Cset: restructured
haftmann
parents: 44555
diff changeset
   220
hide_fact (open) member_coset
cc878a312673 Cset, Dlist_Cset, List_Cset: restructured
haftmann
parents: 44555
diff changeset
   221
43971
892030194015 added operations to Cset with code equations in backing implementations
Andreas Lochbihler
parents: 43241
diff changeset
   222
lemma set_simps [simp]:
892030194015 added operations to Cset with code equations in backing implementations
Andreas Lochbihler
parents: 43241
diff changeset
   223
  "Cset.set [] = Cset.empty"
892030194015 added operations to Cset with code equations in backing implementations
Andreas Lochbihler
parents: 43241
diff changeset
   224
  "Cset.set (x # xs) = insert x (Cset.set xs)"
892030194015 added operations to Cset with code equations in backing implementations
Andreas Lochbihler
parents: 43241
diff changeset
   225
by(simp_all add: Cset.set_def)
892030194015 added operations to Cset with code equations in backing implementations
Andreas Lochbihler
parents: 43241
diff changeset
   226
44555
da75ffe3d988 separating predicates and sets syntactically
haftmann
parents: 43971
diff changeset
   227
lemma member_SUP [simp]:
43971
892030194015 added operations to Cset with code equations in backing implementations
Andreas Lochbihler
parents: 43241
diff changeset
   228
  "member (SUPR A f) = SUPR A (member \<circ> f)"
44555
da75ffe3d988 separating predicates and sets syntactically
haftmann
parents: 43971
diff changeset
   229
  by (auto simp add: fun_eq_iff SUP_apply member_def, unfold SUP_def, auto)
43971
892030194015 added operations to Cset with code equations in backing implementations
Andreas Lochbihler
parents: 43241
diff changeset
   230
892030194015 added operations to Cset with code equations in backing implementations
Andreas Lochbihler
parents: 43241
diff changeset
   231
lemma member_bind [simp]:
44555
da75ffe3d988 separating predicates and sets syntactically
haftmann
parents: 43971
diff changeset
   232
  "member (P \<guillemotright>= f) = SUPR (set_of P) (member \<circ> f)"
da75ffe3d988 separating predicates and sets syntactically
haftmann
parents: 43971
diff changeset
   233
  by (simp add: bind_def Cset.set_eq_iff)
43971
892030194015 added operations to Cset with code equations in backing implementations
Andreas Lochbihler
parents: 43241
diff changeset
   234
892030194015 added operations to Cset with code equations in backing implementations
Andreas Lochbihler
parents: 43241
diff changeset
   235
lemma member_single [simp]:
44555
da75ffe3d988 separating predicates and sets syntactically
haftmann
parents: 43971
diff changeset
   236
  "member (single a) = (\<lambda>x. x \<in> {a})"
da75ffe3d988 separating predicates and sets syntactically
haftmann
parents: 43971
diff changeset
   237
  by (simp add: single_def fun_eq_iff)
43971
892030194015 added operations to Cset with code equations in backing implementations
Andreas Lochbihler
parents: 43241
diff changeset
   238
892030194015 added operations to Cset with code equations in backing implementations
Andreas Lochbihler
parents: 43241
diff changeset
   239
lemma single_sup_simps [simp]:
892030194015 added operations to Cset with code equations in backing implementations
Andreas Lochbihler
parents: 43241
diff changeset
   240
  shows single_sup: "sup (single a) A = insert a A"
892030194015 added operations to Cset with code equations in backing implementations
Andreas Lochbihler
parents: 43241
diff changeset
   241
  and sup_single: "sup A (single a) = insert a A"
44555
da75ffe3d988 separating predicates and sets syntactically
haftmann
parents: 43971
diff changeset
   242
  by (auto simp add: Cset.set_eq_iff single_def)
43971
892030194015 added operations to Cset with code equations in backing implementations
Andreas Lochbihler
parents: 43241
diff changeset
   243
892030194015 added operations to Cset with code equations in backing implementations
Andreas Lochbihler
parents: 43241
diff changeset
   244
lemma single_bind [simp]:
892030194015 added operations to Cset with code equations in backing implementations
Andreas Lochbihler
parents: 43241
diff changeset
   245
  "single a \<guillemotright>= B = B a"
44555
da75ffe3d988 separating predicates and sets syntactically
haftmann
parents: 43971
diff changeset
   246
  by (simp add: Cset.set_eq_iff SUP_insert single_def)
43971
892030194015 added operations to Cset with code equations in backing implementations
Andreas Lochbihler
parents: 43241
diff changeset
   247
892030194015 added operations to Cset with code equations in backing implementations
Andreas Lochbihler
parents: 43241
diff changeset
   248
lemma bind_bind:
892030194015 added operations to Cset with code equations in backing implementations
Andreas Lochbihler
parents: 43241
diff changeset
   249
  "(A \<guillemotright>= B) \<guillemotright>= C = A \<guillemotright>= (\<lambda>x. B x \<guillemotright>= C)"
44555
da75ffe3d988 separating predicates and sets syntactically
haftmann
parents: 43971
diff changeset
   250
  by (simp add: bind_def, simp only: SUP_def image_image, simp)
da75ffe3d988 separating predicates and sets syntactically
haftmann
parents: 43971
diff changeset
   251
 
43971
892030194015 added operations to Cset with code equations in backing implementations
Andreas Lochbihler
parents: 43241
diff changeset
   252
lemma bind_single [simp]:
892030194015 added operations to Cset with code equations in backing implementations
Andreas Lochbihler
parents: 43241
diff changeset
   253
  "A \<guillemotright>= single = A"
44555
da75ffe3d988 separating predicates and sets syntactically
haftmann
parents: 43971
diff changeset
   254
  by (simp add: Cset.set_eq_iff SUP_apply fun_eq_iff single_def member_def)
43971
892030194015 added operations to Cset with code equations in backing implementations
Andreas Lochbihler
parents: 43241
diff changeset
   255
892030194015 added operations to Cset with code equations in backing implementations
Andreas Lochbihler
parents: 43241
diff changeset
   256
lemma bind_const: "A \<guillemotright>= (\<lambda>_. B) = (if Cset.is_empty A then Cset.empty else B)"
44555
da75ffe3d988 separating predicates and sets syntactically
haftmann
parents: 43971
diff changeset
   257
  by (auto simp add: Cset.set_eq_iff fun_eq_iff)
43971
892030194015 added operations to Cset with code equations in backing implementations
Andreas Lochbihler
parents: 43241
diff changeset
   258
892030194015 added operations to Cset with code equations in backing implementations
Andreas Lochbihler
parents: 43241
diff changeset
   259
lemma empty_bind [simp]:
892030194015 added operations to Cset with code equations in backing implementations
Andreas Lochbihler
parents: 43241
diff changeset
   260
  "Cset.empty \<guillemotright>= f = Cset.empty"
44555
da75ffe3d988 separating predicates and sets syntactically
haftmann
parents: 43971
diff changeset
   261
  by (simp add: Cset.set_eq_iff fun_eq_iff bot_apply)
43971
892030194015 added operations to Cset with code equations in backing implementations
Andreas Lochbihler
parents: 43241
diff changeset
   262
892030194015 added operations to Cset with code equations in backing implementations
Andreas Lochbihler
parents: 43241
diff changeset
   263
lemma member_of_pred [simp]:
44555
da75ffe3d988 separating predicates and sets syntactically
haftmann
parents: 43971
diff changeset
   264
  "member (of_pred P) = (\<lambda>x. x \<in> {x. Predicate.eval P x})"
da75ffe3d988 separating predicates and sets syntactically
haftmann
parents: 43971
diff changeset
   265
  by (simp add: of_pred_def fun_eq_iff)
43971
892030194015 added operations to Cset with code equations in backing implementations
Andreas Lochbihler
parents: 43241
diff changeset
   266
892030194015 added operations to Cset with code equations in backing implementations
Andreas Lochbihler
parents: 43241
diff changeset
   267
lemma member_of_seq [simp]:
44555
da75ffe3d988 separating predicates and sets syntactically
haftmann
parents: 43971
diff changeset
   268
  "member (of_seq xq) = (\<lambda>x. x \<in> {x. Predicate.member xq x})"
da75ffe3d988 separating predicates and sets syntactically
haftmann
parents: 43971
diff changeset
   269
  by (simp add: of_seq_def eval_member)
43971
892030194015 added operations to Cset with code equations in backing implementations
Andreas Lochbihler
parents: 43241
diff changeset
   270
892030194015 added operations to Cset with code equations in backing implementations
Andreas Lochbihler
parents: 43241
diff changeset
   271
lemma eval_pred_of_cset [simp]: 
892030194015 added operations to Cset with code equations in backing implementations
Andreas Lochbihler
parents: 43241
diff changeset
   272
  "Predicate.eval (pred_of_cset A) = Cset.member A"
44555
da75ffe3d988 separating predicates and sets syntactically
haftmann
parents: 43971
diff changeset
   273
  by (simp add: pred_of_cset_def)
43971
892030194015 added operations to Cset with code equations in backing implementations
Andreas Lochbihler
parents: 43241
diff changeset
   274
892030194015 added operations to Cset with code equations in backing implementations
Andreas Lochbihler
parents: 43241
diff changeset
   275
subsection {* Default implementations *}
892030194015 added operations to Cset with code equations in backing implementations
Andreas Lochbihler
parents: 43241
diff changeset
   276
892030194015 added operations to Cset with code equations in backing implementations
Andreas Lochbihler
parents: 43241
diff changeset
   277
lemma set_code [code]:
44555
da75ffe3d988 separating predicates and sets syntactically
haftmann
parents: 43971
diff changeset
   278
  "Cset.set = (\<lambda>xs. fold insert xs Cset.empty)"
da75ffe3d988 separating predicates and sets syntactically
haftmann
parents: 43971
diff changeset
   279
proof (rule ext, rule Cset.set_eqI)
da75ffe3d988 separating predicates and sets syntactically
haftmann
parents: 43971
diff changeset
   280
  fix xs :: "'a list"
da75ffe3d988 separating predicates and sets syntactically
haftmann
parents: 43971
diff changeset
   281
  show "member (Cset.set xs) = member (fold insert xs Cset.empty)"
da75ffe3d988 separating predicates and sets syntactically
haftmann
parents: 43971
diff changeset
   282
    by (simp add: fold_commute_apply [symmetric, where ?h = Set and ?g = Set.insert]
da75ffe3d988 separating predicates and sets syntactically
haftmann
parents: 43971
diff changeset
   283
      fun_eq_iff Cset.set_def union_set [symmetric])
43971
892030194015 added operations to Cset with code equations in backing implementations
Andreas Lochbihler
parents: 43241
diff changeset
   284
qed
892030194015 added operations to Cset with code equations in backing implementations
Andreas Lochbihler
parents: 43241
diff changeset
   285
892030194015 added operations to Cset with code equations in backing implementations
Andreas Lochbihler
parents: 43241
diff changeset
   286
lemma single_code [code]:
892030194015 added operations to Cset with code equations in backing implementations
Andreas Lochbihler
parents: 43241
diff changeset
   287
  "single a = insert a Cset.empty"
44555
da75ffe3d988 separating predicates and sets syntactically
haftmann
parents: 43971
diff changeset
   288
  by (simp add: Cset.single_def)
43971
892030194015 added operations to Cset with code equations in backing implementations
Andreas Lochbihler
parents: 43241
diff changeset
   289
44558
cc878a312673 Cset, Dlist_Cset, List_Cset: restructured
haftmann
parents: 44555
diff changeset
   290
lemma compl_set [simp]:
cc878a312673 Cset, Dlist_Cset, List_Cset: restructured
haftmann
parents: 44555
diff changeset
   291
  "- Cset.set xs = Cset.coset xs"
cc878a312673 Cset, Dlist_Cset, List_Cset: restructured
haftmann
parents: 44555
diff changeset
   292
  by (simp add: Cset.set_def Cset.coset_def)
cc878a312673 Cset, Dlist_Cset, List_Cset: restructured
haftmann
parents: 44555
diff changeset
   293
cc878a312673 Cset, Dlist_Cset, List_Cset: restructured
haftmann
parents: 44555
diff changeset
   294
lemma compl_coset [simp]:
cc878a312673 Cset, Dlist_Cset, List_Cset: restructured
haftmann
parents: 44555
diff changeset
   295
  "- Cset.coset xs = Cset.set xs"
cc878a312673 Cset, Dlist_Cset, List_Cset: restructured
haftmann
parents: 44555
diff changeset
   296
  by (simp add: Cset.set_def Cset.coset_def)
cc878a312673 Cset, Dlist_Cset, List_Cset: restructured
haftmann
parents: 44555
diff changeset
   297
cc878a312673 Cset, Dlist_Cset, List_Cset: restructured
haftmann
parents: 44555
diff changeset
   298
lemma member_cset_of:
cc878a312673 Cset, Dlist_Cset, List_Cset: restructured
haftmann
parents: 44555
diff changeset
   299
  "member = set_of"
cc878a312673 Cset, Dlist_Cset, List_Cset: restructured
haftmann
parents: 44555
diff changeset
   300
  by (rule ext)+ (simp add: member_def mem_def)
cc878a312673 Cset, Dlist_Cset, List_Cset: restructured
haftmann
parents: 44555
diff changeset
   301
cc878a312673 Cset, Dlist_Cset, List_Cset: restructured
haftmann
parents: 44555
diff changeset
   302
lemma inter_project:
cc878a312673 Cset, Dlist_Cset, List_Cset: restructured
haftmann
parents: 44555
diff changeset
   303
  "inf A (Cset.set xs) = Cset.set (List.filter (Cset.member A) xs)"
cc878a312673 Cset, Dlist_Cset, List_Cset: restructured
haftmann
parents: 44555
diff changeset
   304
  "inf A (Cset.coset xs) = foldr Cset.remove xs A"
cc878a312673 Cset, Dlist_Cset, List_Cset: restructured
haftmann
parents: 44555
diff changeset
   305
proof -
cc878a312673 Cset, Dlist_Cset, List_Cset: restructured
haftmann
parents: 44555
diff changeset
   306
  show "inf A (Cset.set xs) = Cset.set (List.filter (member A) xs)"
cc878a312673 Cset, Dlist_Cset, List_Cset: restructured
haftmann
parents: 44555
diff changeset
   307
    by (simp add: inter project_def Cset.set_def member_def)
cc878a312673 Cset, Dlist_Cset, List_Cset: restructured
haftmann
parents: 44555
diff changeset
   308
  have *: "\<And>x::'a. Cset.remove = (\<lambda>x. Set \<circ> More_Set.remove x \<circ> member)"
cc878a312673 Cset, Dlist_Cset, List_Cset: restructured
haftmann
parents: 44555
diff changeset
   309
    by (simp add: fun_eq_iff More_Set.remove_def member_cset_of)
cc878a312673 Cset, Dlist_Cset, List_Cset: restructured
haftmann
parents: 44555
diff changeset
   310
  have "member \<circ> fold (\<lambda>x. Set \<circ> More_Set.remove x \<circ> member) xs =
cc878a312673 Cset, Dlist_Cset, List_Cset: restructured
haftmann
parents: 44555
diff changeset
   311
    fold More_Set.remove xs \<circ> member"
cc878a312673 Cset, Dlist_Cset, List_Cset: restructured
haftmann
parents: 44555
diff changeset
   312
    by (rule fold_commute) (simp add: fun_eq_iff mem_def)
cc878a312673 Cset, Dlist_Cset, List_Cset: restructured
haftmann
parents: 44555
diff changeset
   313
  then have "fold More_Set.remove xs (member A) = 
cc878a312673 Cset, Dlist_Cset, List_Cset: restructured
haftmann
parents: 44555
diff changeset
   314
    member (fold (\<lambda>x. Set \<circ> More_Set.remove x \<circ> member) xs A)"
cc878a312673 Cset, Dlist_Cset, List_Cset: restructured
haftmann
parents: 44555
diff changeset
   315
    by (simp add: fun_eq_iff)
cc878a312673 Cset, Dlist_Cset, List_Cset: restructured
haftmann
parents: 44555
diff changeset
   316
  then have "inf A (Cset.coset xs) = fold Cset.remove xs A"
cc878a312673 Cset, Dlist_Cset, List_Cset: restructured
haftmann
parents: 44555
diff changeset
   317
    by (simp add: Diff_eq [symmetric] minus_set * member_cset_of)
cc878a312673 Cset, Dlist_Cset, List_Cset: restructured
haftmann
parents: 44555
diff changeset
   318
  moreover have "\<And>x y :: 'a. Cset.remove y \<circ> Cset.remove x = Cset.remove x \<circ> Cset.remove y"
cc878a312673 Cset, Dlist_Cset, List_Cset: restructured
haftmann
parents: 44555
diff changeset
   319
    by (auto simp add: More_Set.remove_def * member_cset_of)
cc878a312673 Cset, Dlist_Cset, List_Cset: restructured
haftmann
parents: 44555
diff changeset
   320
  ultimately show "inf A (Cset.coset xs) = foldr Cset.remove xs A"
cc878a312673 Cset, Dlist_Cset, List_Cset: restructured
haftmann
parents: 44555
diff changeset
   321
    by (simp add: foldr_fold)
cc878a312673 Cset, Dlist_Cset, List_Cset: restructured
haftmann
parents: 44555
diff changeset
   322
qed
cc878a312673 Cset, Dlist_Cset, List_Cset: restructured
haftmann
parents: 44555
diff changeset
   323
cc878a312673 Cset, Dlist_Cset, List_Cset: restructured
haftmann
parents: 44555
diff changeset
   324
lemma subtract_remove:
cc878a312673 Cset, Dlist_Cset, List_Cset: restructured
haftmann
parents: 44555
diff changeset
   325
  "A - Cset.set xs = foldr Cset.remove xs A"
cc878a312673 Cset, Dlist_Cset, List_Cset: restructured
haftmann
parents: 44555
diff changeset
   326
  "A - Cset.coset xs = Cset.set (List.filter (member A) xs)"
cc878a312673 Cset, Dlist_Cset, List_Cset: restructured
haftmann
parents: 44555
diff changeset
   327
  by (simp_all only: diff_eq compl_set compl_coset inter_project)
cc878a312673 Cset, Dlist_Cset, List_Cset: restructured
haftmann
parents: 44555
diff changeset
   328
cc878a312673 Cset, Dlist_Cset, List_Cset: restructured
haftmann
parents: 44555
diff changeset
   329
lemma union_insert:
cc878a312673 Cset, Dlist_Cset, List_Cset: restructured
haftmann
parents: 44555
diff changeset
   330
  "sup (Cset.set xs) A = foldr Cset.insert xs A"
cc878a312673 Cset, Dlist_Cset, List_Cset: restructured
haftmann
parents: 44555
diff changeset
   331
  "sup (Cset.coset xs) A = Cset.coset (List.filter (Not \<circ> member A) xs)"
cc878a312673 Cset, Dlist_Cset, List_Cset: restructured
haftmann
parents: 44555
diff changeset
   332
proof -
cc878a312673 Cset, Dlist_Cset, List_Cset: restructured
haftmann
parents: 44555
diff changeset
   333
  have *: "\<And>x::'a. Cset.insert = (\<lambda>x. Set \<circ> Set.insert x \<circ> member)"
cc878a312673 Cset, Dlist_Cset, List_Cset: restructured
haftmann
parents: 44555
diff changeset
   334
    by (simp add: fun_eq_iff member_cset_of)
cc878a312673 Cset, Dlist_Cset, List_Cset: restructured
haftmann
parents: 44555
diff changeset
   335
  have "member \<circ> fold (\<lambda>x. Set \<circ> Set.insert x \<circ> member) xs =
cc878a312673 Cset, Dlist_Cset, List_Cset: restructured
haftmann
parents: 44555
diff changeset
   336
    fold Set.insert xs \<circ> member"
cc878a312673 Cset, Dlist_Cset, List_Cset: restructured
haftmann
parents: 44555
diff changeset
   337
    by (rule fold_commute) (simp add: fun_eq_iff mem_def)
cc878a312673 Cset, Dlist_Cset, List_Cset: restructured
haftmann
parents: 44555
diff changeset
   338
  then have "fold Set.insert xs (member A) =
cc878a312673 Cset, Dlist_Cset, List_Cset: restructured
haftmann
parents: 44555
diff changeset
   339
    member (fold (\<lambda>x. Set \<circ> Set.insert x \<circ> member) xs A)"
cc878a312673 Cset, Dlist_Cset, List_Cset: restructured
haftmann
parents: 44555
diff changeset
   340
    by (simp add: fun_eq_iff)
cc878a312673 Cset, Dlist_Cset, List_Cset: restructured
haftmann
parents: 44555
diff changeset
   341
  then have "sup (Cset.set xs) A = fold Cset.insert xs A"
cc878a312673 Cset, Dlist_Cset, List_Cset: restructured
haftmann
parents: 44555
diff changeset
   342
    by (simp add: union_set * member_cset_of)
cc878a312673 Cset, Dlist_Cset, List_Cset: restructured
haftmann
parents: 44555
diff changeset
   343
  moreover have "\<And>x y :: 'a. Cset.insert y \<circ> Cset.insert x = Cset.insert x \<circ> Cset.insert y"
cc878a312673 Cset, Dlist_Cset, List_Cset: restructured
haftmann
parents: 44555
diff changeset
   344
    by (auto simp add: * member_cset_of)
cc878a312673 Cset, Dlist_Cset, List_Cset: restructured
haftmann
parents: 44555
diff changeset
   345
  ultimately show "sup (Cset.set xs) A = foldr Cset.insert xs A"
cc878a312673 Cset, Dlist_Cset, List_Cset: restructured
haftmann
parents: 44555
diff changeset
   346
    by (simp add: foldr_fold)
cc878a312673 Cset, Dlist_Cset, List_Cset: restructured
haftmann
parents: 44555
diff changeset
   347
  show "sup (Cset.coset xs) A = Cset.coset (List.filter (Not \<circ> member A) xs)"
cc878a312673 Cset, Dlist_Cset, List_Cset: restructured
haftmann
parents: 44555
diff changeset
   348
    by (auto simp add: Cset.coset_def member_cset_of mem_def)
cc878a312673 Cset, Dlist_Cset, List_Cset: restructured
haftmann
parents: 44555
diff changeset
   349
qed
cc878a312673 Cset, Dlist_Cset, List_Cset: restructured
haftmann
parents: 44555
diff changeset
   350
cc878a312673 Cset, Dlist_Cset, List_Cset: restructured
haftmann
parents: 44555
diff changeset
   351
context complete_lattice
cc878a312673 Cset, Dlist_Cset, List_Cset: restructured
haftmann
parents: 44555
diff changeset
   352
begin
cc878a312673 Cset, Dlist_Cset, List_Cset: restructured
haftmann
parents: 44555
diff changeset
   353
cc878a312673 Cset, Dlist_Cset, List_Cset: restructured
haftmann
parents: 44555
diff changeset
   354
lemma Infimum_inf:
cc878a312673 Cset, Dlist_Cset, List_Cset: restructured
haftmann
parents: 44555
diff changeset
   355
  "Infimum (Cset.set As) = foldr inf As top"
cc878a312673 Cset, Dlist_Cset, List_Cset: restructured
haftmann
parents: 44555
diff changeset
   356
  "Infimum (Cset.coset []) = bot"
cc878a312673 Cset, Dlist_Cset, List_Cset: restructured
haftmann
parents: 44555
diff changeset
   357
  by (simp_all add: Inf_set_foldr)
cc878a312673 Cset, Dlist_Cset, List_Cset: restructured
haftmann
parents: 44555
diff changeset
   358
cc878a312673 Cset, Dlist_Cset, List_Cset: restructured
haftmann
parents: 44555
diff changeset
   359
lemma Supremum_sup:
cc878a312673 Cset, Dlist_Cset, List_Cset: restructured
haftmann
parents: 44555
diff changeset
   360
  "Supremum (Cset.set As) = foldr sup As bot"
cc878a312673 Cset, Dlist_Cset, List_Cset: restructured
haftmann
parents: 44555
diff changeset
   361
  "Supremum (Cset.coset []) = top"
cc878a312673 Cset, Dlist_Cset, List_Cset: restructured
haftmann
parents: 44555
diff changeset
   362
  by (simp_all add: Sup_set_foldr)
cc878a312673 Cset, Dlist_Cset, List_Cset: restructured
haftmann
parents: 44555
diff changeset
   363
cc878a312673 Cset, Dlist_Cset, List_Cset: restructured
haftmann
parents: 44555
diff changeset
   364
end
cc878a312673 Cset, Dlist_Cset, List_Cset: restructured
haftmann
parents: 44555
diff changeset
   365
43971
892030194015 added operations to Cset with code equations in backing implementations
Andreas Lochbihler
parents: 43241
diff changeset
   366
lemma of_pred_code [code]:
892030194015 added operations to Cset with code equations in backing implementations
Andreas Lochbihler
parents: 43241
diff changeset
   367
  "of_pred (Predicate.Seq f) = (case f () of
892030194015 added operations to Cset with code equations in backing implementations
Andreas Lochbihler
parents: 43241
diff changeset
   368
     Predicate.Empty \<Rightarrow> Cset.empty
892030194015 added operations to Cset with code equations in backing implementations
Andreas Lochbihler
parents: 43241
diff changeset
   369
   | Predicate.Insert x P \<Rightarrow> Cset.insert x (of_pred P)
892030194015 added operations to Cset with code equations in backing implementations
Andreas Lochbihler
parents: 43241
diff changeset
   370
   | Predicate.Join P xq \<Rightarrow> sup (of_pred P) (of_seq xq))"
44555
da75ffe3d988 separating predicates and sets syntactically
haftmann
parents: 43971
diff changeset
   371
  apply (auto split: seq.split simp add: Predicate.Seq_def of_pred_def Cset.set_eq_iff sup_apply eval_member [symmetric] member_def [symmetric] Collect_def mem_def member_set_of)
da75ffe3d988 separating predicates and sets syntactically
haftmann
parents: 43971
diff changeset
   372
  apply (unfold Set.insert_def Collect_def sup_apply member_set_of)
da75ffe3d988 separating predicates and sets syntactically
haftmann
parents: 43971
diff changeset
   373
  apply simp_all
da75ffe3d988 separating predicates and sets syntactically
haftmann
parents: 43971
diff changeset
   374
  done
43971
892030194015 added operations to Cset with code equations in backing implementations
Andreas Lochbihler
parents: 43241
diff changeset
   375
892030194015 added operations to Cset with code equations in backing implementations
Andreas Lochbihler
parents: 43241
diff changeset
   376
lemma of_seq_code [code]:
892030194015 added operations to Cset with code equations in backing implementations
Andreas Lochbihler
parents: 43241
diff changeset
   377
  "of_seq Predicate.Empty = Cset.empty"
892030194015 added operations to Cset with code equations in backing implementations
Andreas Lochbihler
parents: 43241
diff changeset
   378
  "of_seq (Predicate.Insert x P) = Cset.insert x (of_pred P)"
892030194015 added operations to Cset with code equations in backing implementations
Andreas Lochbihler
parents: 43241
diff changeset
   379
  "of_seq (Predicate.Join P xq) = sup (of_pred P) (of_seq xq)"
44555
da75ffe3d988 separating predicates and sets syntactically
haftmann
parents: 43971
diff changeset
   380
  apply (auto simp add: of_seq_def of_pred_def Cset.set_eq_iff mem_def Collect_def)
da75ffe3d988 separating predicates and sets syntactically
haftmann
parents: 43971
diff changeset
   381
  apply (unfold Set.insert_def Collect_def sup_apply member_set_of)
da75ffe3d988 separating predicates and sets syntactically
haftmann
parents: 43971
diff changeset
   382
  apply simp_all
da75ffe3d988 separating predicates and sets syntactically
haftmann
parents: 43971
diff changeset
   383
  done
31846
89c37daebfdd added Inter, Union
haftmann
parents: 31807
diff changeset
   384
44558
cc878a312673 Cset, Dlist_Cset, List_Cset: restructured
haftmann
parents: 44555
diff changeset
   385
lemma bind_set:
cc878a312673 Cset, Dlist_Cset, List_Cset: restructured
haftmann
parents: 44555
diff changeset
   386
  "Cset.bind (Cset.set xs) f = fold (sup \<circ> f) xs (Cset.set [])"
cc878a312673 Cset, Dlist_Cset, List_Cset: restructured
haftmann
parents: 44555
diff changeset
   387
  by (simp add: Cset.bind_def SUPR_set_fold)
cc878a312673 Cset, Dlist_Cset, List_Cset: restructured
haftmann
parents: 44555
diff changeset
   388
hide_fact (open) bind_set
cc878a312673 Cset, Dlist_Cset, List_Cset: restructured
haftmann
parents: 44555
diff changeset
   389
cc878a312673 Cset, Dlist_Cset, List_Cset: restructured
haftmann
parents: 44555
diff changeset
   390
lemma pred_of_cset_set:
cc878a312673 Cset, Dlist_Cset, List_Cset: restructured
haftmann
parents: 44555
diff changeset
   391
  "pred_of_cset (Cset.set xs) = foldr sup (List.map Predicate.single xs) bot"
cc878a312673 Cset, Dlist_Cset, List_Cset: restructured
haftmann
parents: 44555
diff changeset
   392
proof -
cc878a312673 Cset, Dlist_Cset, List_Cset: restructured
haftmann
parents: 44555
diff changeset
   393
  have "pred_of_cset (Cset.set xs) = Predicate.Pred (\<lambda>x. x \<in> set xs)"
cc878a312673 Cset, Dlist_Cset, List_Cset: restructured
haftmann
parents: 44555
diff changeset
   394
    by (simp add: Cset.pred_of_cset_def member_set)
cc878a312673 Cset, Dlist_Cset, List_Cset: restructured
haftmann
parents: 44555
diff changeset
   395
  moreover have "foldr sup (List.map Predicate.single xs) bot = \<dots>"
cc878a312673 Cset, Dlist_Cset, List_Cset: restructured
haftmann
parents: 44555
diff changeset
   396
    by (induct xs) (auto simp add: bot_pred_def intro: pred_eqI, simp add: mem_def)
cc878a312673 Cset, Dlist_Cset, List_Cset: restructured
haftmann
parents: 44555
diff changeset
   397
  ultimately show ?thesis by simp
cc878a312673 Cset, Dlist_Cset, List_Cset: restructured
haftmann
parents: 44555
diff changeset
   398
qed
cc878a312673 Cset, Dlist_Cset, List_Cset: restructured
haftmann
parents: 44555
diff changeset
   399
hide_fact (open) pred_of_cset_set
cc878a312673 Cset, Dlist_Cset, List_Cset: restructured
haftmann
parents: 44555
diff changeset
   400
43971
892030194015 added operations to Cset with code equations in backing implementations
Andreas Lochbihler
parents: 43241
diff changeset
   401
no_notation bind (infixl "\<guillemotright>=" 70)
31849
431d8588bcad renamed theory Code_Set to Fset
haftmann
parents: 31847
diff changeset
   402
43241
93b1183e43e5 splitting Cset into Cset and List_Cset
bulwahn
parents: 41505
diff changeset
   403
hide_const (open) is_empty insert remove map filter forall exists card
43971
892030194015 added operations to Cset with code equations in backing implementations
Andreas Lochbihler
parents: 43241
diff changeset
   404
  Inter Union bind single of_pred of_seq
892030194015 added operations to Cset with code equations in backing implementations
Andreas Lochbihler
parents: 43241
diff changeset
   405
892030194015 added operations to Cset with code equations in backing implementations
Andreas Lochbihler
parents: 43241
diff changeset
   406
hide_fact (open) set_def pred_of_cset_def of_pred_def of_seq_def single_def 
44555
da75ffe3d988 separating predicates and sets syntactically
haftmann
parents: 43971
diff changeset
   407
  bind_def empty_simp UNIV_simp set_simps member_bind 
43971
892030194015 added operations to Cset with code equations in backing implementations
Andreas Lochbihler
parents: 43241
diff changeset
   408
  member_single single_sup_simps single_sup sup_single single_bind
892030194015 added operations to Cset with code equations in backing implementations
Andreas Lochbihler
parents: 43241
diff changeset
   409
  bind_bind bind_single bind_const empty_bind member_of_pred member_of_seq
892030194015 added operations to Cset with code equations in backing implementations
Andreas Lochbihler
parents: 43241
diff changeset
   410
  eval_pred_of_cset set_code single_code of_pred_code of_seq_code
31849
431d8588bcad renamed theory Code_Set to Fset
haftmann
parents: 31847
diff changeset
   411
31807
039893a9a77d added List_Set and Code_Set theories
haftmann
parents:
diff changeset
   412
end