src/HOL/Set.thy
changeset 21333 eb291029d6cd
parent 21316 4d913b8bccf1
child 21384 2b58b308300c
equal deleted inserted replaced
21332:2605e1ccd9f2 21333:eb291029d6cd
     4 *)
     4 *)
     5 
     5 
     6 header {* Set theory for higher-order logic *}
     6 header {* Set theory for higher-order logic *}
     7 
     7 
     8 theory Set
     8 theory Set
     9 imports LOrder
     9 imports Lattices
    10 begin
    10 begin
    11 
    11 
    12 text {* A set in HOL is simply a predicate. *}
    12 text {* A set in HOL is simply a predicate. *}
    13 
    13 
    14 
    14 
    41   "op :"  ("op :")
    41   "op :"  ("op :")
    42   "op :"  ("(_/ : _)" [50, 51] 50)
    42   "op :"  ("(_/ : _)" [50, 51] 50)
    43 
    43 
    44 local
    44 local
    45 
    45 
    46 instance set :: (type) "{ord, minus}" ..
       
    47 
       
    48 
    46 
    49 subsection {* Additional concrete syntax *}
    47 subsection {* Additional concrete syntax *}
    50 
    48 
    51 abbreviation
    49 abbreviation
    52   range :: "('a => 'b) => 'b set"             -- "of function"
    50   range :: "('a => 'b) => 'b set"             -- "of function"
    74   "op Un"  (infixl "\<union>" 65)
    72   "op Un"  (infixl "\<union>" 65)
    75   "op :"  ("op \<in>")
    73   "op :"  ("op \<in>")
    76   "op :"  ("(_/ \<in> _)" [50, 51] 50)
    74   "op :"  ("(_/ \<in> _)" [50, 51] 50)
    77   not_mem  ("op \<notin>")
    75   not_mem  ("op \<notin>")
    78   not_mem  ("(_/ \<notin> _)" [50, 51] 50)
    76   not_mem  ("(_/ \<notin> _)" [50, 51] 50)
    79 
       
    80 abbreviation
       
    81   subset :: "'a set \<Rightarrow> 'a set \<Rightarrow> bool"
       
    82   "subset == less"
       
    83   subset_eq :: "'a set \<Rightarrow> 'a set \<Rightarrow> bool"
       
    84   "subset_eq == less_eq"
       
    85 
       
    86 notation (output)
       
    87   subset  ("op <")
       
    88   subset  ("(_/ < _)" [50, 51] 50)
       
    89   subset_eq  ("op <=")
       
    90   subset_eq  ("(_/ <= _)" [50, 51] 50)
       
    91 
       
    92 notation (xsymbols)
       
    93   subset  ("op \<subset>")
       
    94   subset  ("(_/ \<subset> _)" [50, 51] 50)
       
    95   subset_eq  ("op \<subseteq>")
       
    96   subset_eq  ("(_/ \<subseteq> _)" [50, 51] 50)
       
    97 
       
    98 notation (HTML output)
       
    99   subset  ("op \<subset>")
       
   100   subset  ("(_/ \<subset> _)" [50, 51] 50)
       
   101   subset_eq  ("op \<subseteq>")
       
   102   subset_eq  ("(_/ \<subseteq> _)" [50, 51] 50)
       
   103 
       
   104 abbreviation (input)
       
   105   supset :: "'a set \<Rightarrow> 'a set \<Rightarrow> bool"    (infixl "\<supset>" 50)
       
   106   "supset == greater"
       
   107   supset_eq :: "'a set \<Rightarrow> 'a set \<Rightarrow> bool"  (infixl "\<supseteq>" 50)
       
   108   "supset_eq == greater_eq"
       
   109 
    77 
   110 syntax
    78 syntax
   111   "@Finset"     :: "args => 'a set"                       ("{(_)}")
    79   "@Finset"     :: "args => 'a set"                       ("{(_)}")
   112   "@Coll"       :: "pttrn => bool => 'a set"              ("(1{_./ _})")
    80   "@Coll"       :: "pttrn => bool => 'a set"              ("(1{_./ _})")
   113   "@SetCompr"   :: "'a => idts => bool => 'a set"         ("(1{_ |/_./ _})")
    81   "@SetCompr"   :: "'a => idts => bool => 'a set"         ("(1{_ |/_./ _})")
   174   and their \LaTeX\ rendition: @{term"\<Union>a\<^isub>1\<in>A\<^isub>1. B"}. The
   142   and their \LaTeX\ rendition: @{term"\<Union>a\<^isub>1\<in>A\<^isub>1. B"}. The
   175   former does not make the index expression a subscript of the
   143   former does not make the index expression a subscript of the
   176   union/intersection symbol because this leads to problems with nested
   144   union/intersection symbol because this leads to problems with nested
   177   subscripts in Proof General. *}
   145   subscripts in Proof General. *}
   178 
   146 
       
   147 instance set :: (type) ord
       
   148   subset_def:   "A <= B         == \<forall>x\<in>A. x \<in> B"
       
   149   psubset_def:  "A < B          == (A::'a set) <= B & ~ A=B" ..
       
   150 
       
   151 abbreviation
       
   152   subset :: "'a set \<Rightarrow> 'a set \<Rightarrow> bool"
       
   153   "subset == less"
       
   154   subset_eq :: "'a set \<Rightarrow> 'a set \<Rightarrow> bool"
       
   155   "subset_eq == less_eq"
       
   156 
       
   157 notation (output)
       
   158   subset  ("op <")
       
   159   subset  ("(_/ < _)" [50, 51] 50)
       
   160   subset_eq  ("op <=")
       
   161   subset_eq  ("(_/ <= _)" [50, 51] 50)
       
   162 
       
   163 notation (xsymbols)
       
   164   subset  ("op \<subset>")
       
   165   subset  ("(_/ \<subset> _)" [50, 51] 50)
       
   166   subset_eq  ("op \<subseteq>")
       
   167   subset_eq  ("(_/ \<subseteq> _)" [50, 51] 50)
       
   168 
       
   169 notation (HTML output)
       
   170   subset  ("op \<subset>")
       
   171   subset  ("(_/ \<subset> _)" [50, 51] 50)
       
   172   subset_eq  ("op \<subseteq>")
       
   173   subset_eq  ("(_/ \<subseteq> _)" [50, 51] 50)
       
   174 
       
   175 abbreviation (input)
       
   176   supset :: "'a set \<Rightarrow> 'a set \<Rightarrow> bool"    (infixl "\<supset>" 50)
       
   177   "supset == greater"
       
   178   supset_eq :: "'a set \<Rightarrow> 'a set \<Rightarrow> bool"  (infixl "\<supseteq>" 50)
       
   179   "supset_eq == greater_eq"
       
   180 
   179 
   181 
   180 subsubsection "Bounded quantifiers"
   182 subsubsection "Bounded quantifiers"
   181 
   183 
   182 syntax (output)
   184 syntax (output)
   183   "_setlessAll" :: "[idt, 'a, bool] => bool"  ("(3ALL _<_./ _)"  [0, 0, 10] 10)
   185   "_setlessAll" :: "[idt, 'a, bool] => bool"  ("(3ALL _<_./ _)"  [0, 0, 10] 10)
   327 defs
   329 defs
   328   Ball_def:     "Ball A P       == ALL x. x:A --> P(x)"
   330   Ball_def:     "Ball A P       == ALL x. x:A --> P(x)"
   329   Bex_def:      "Bex A P        == EX x. x:A & P(x)"
   331   Bex_def:      "Bex A P        == EX x. x:A & P(x)"
   330   Bex1_def:     "Bex1 A P       == EX! x. x:A & P(x)"
   332   Bex1_def:     "Bex1 A P       == EX! x. x:A & P(x)"
   331 
   333 
   332 defs (overloaded)
   334 instance set :: (type) minus
   333   subset_def:   "A <= B         == ALL x:A. x:B"
       
   334   psubset_def:  "A < B          == (A::'a set) <= B & ~ A=B"
       
   335   Compl_def:    "- A            == {x. ~x:A}"
   335   Compl_def:    "- A            == {x. ~x:A}"
   336   set_diff_def: "A - B          == {x. x:A & ~x:B}"
   336   set_diff_def: "A - B          == {x. x:A & ~x:B}" ..
   337 
   337 
   338 defs
   338 defs
   339   Un_def:       "A Un B         == {x. x:A | x:B}"
   339   Un_def:       "A Un B         == {x. x:A | x:B}"
   340   Int_def:      "A Int B        == {x. x:A & x:B}"
   340   Int_def:      "A Int B        == {x. x:A & x:B}"
   341   INTER_def:    "INTER A B      == {y. ALL x:A. y: B(x)}"
   341   INTER_def:    "INTER A B      == {y. ALL x:A. y: B(x)}"
  2221   assume r: "!!x y. x < y ==> f x < f y"
  2221   assume r: "!!x y. x < y ==> f x < f y"
  2222   assume "a = f b"
  2222   assume "a = f b"
  2223   also assume "b < c" hence "f b < f c" by (rule r)
  2223   also assume "b < c" hence "f b < f c" by (rule r)
  2224   finally (ord_eq_less_trans) show ?thesis .
  2224   finally (ord_eq_less_trans) show ?thesis .
  2225 qed
  2225 qed
       
  2226 
       
  2227 instance set :: (type) order
       
  2228   by (intro_classes,
       
  2229       (assumption | rule subset_refl subset_trans subset_antisym psubset_eq)+)
  2226 
  2230 
  2227 text {*
  2231 text {*
  2228   Note that this list of rules is in reverse order of priorities.
  2232   Note that this list of rules is in reverse order of priorities.
  2229 *}
  2233 *}
  2230 
  2234