src/HOL/Set.thy
 author nipkow Sat May 16 11:28:02 2009 +0200 (2009-05-16) changeset 31166 a90fe83f58ea parent 30814 10dc9bc264b7 child 31197 c1c163ec6c44 permissions -rw-r--r--
"{x. P x & x=t & Q x}" is now rewritten to "if P t & Q t then {t} else {}"
by the new simproc defColl_regroup. More precisely, the simproc pulls an
equation x=t (or t=x) out of a nest of conjunctions to the front where the
simp rule singleton_conj_conv(2) converts to "if".
 clasohm@923  1 (* Title: HOL/Set.thy  wenzelm@12257  2  Author: Tobias Nipkow, Lawrence C Paulson and Markus Wenzel  clasohm@923  3 *)  clasohm@923  4 wenzelm@11979  5 header {* Set theory for higher-order logic *}  wenzelm@11979  6 nipkow@15131  7 theory Set  haftmann@30304  8 imports Lattices  nipkow@15131  9 begin  wenzelm@11979  10 wenzelm@11979  11 text {* A set in HOL is simply a predicate. *}  clasohm@923  12 haftmann@30531  13 haftmann@30531  14 subsection {* Basic syntax *}  haftmann@30531  15 wenzelm@3947  16 global  wenzelm@3947  17 berghofe@26800  18 types 'a set = "'a => bool"  wenzelm@3820  19 clasohm@923  20 consts  haftmann@30531  21  Collect :: "('a => bool) => 'a set" -- "comprehension"  haftmann@30531  22  "op :" :: "'a => 'a set => bool" -- "membership"  haftmann@30531  23  insert :: "'a => 'a set => 'a set"  haftmann@30531  24  Ball :: "'a set => ('a => bool) => bool" -- "bounded universal quantifiers"  haftmann@30531  25  Bex :: "'a set => ('a => bool) => bool" -- "bounded existential quantifiers"  haftmann@30531  26  Bex1 :: "'a set => ('a => bool) => bool" -- "bounded unique existential quantifiers"  haftmann@30531  27  Pow :: "'a set => 'a set set" -- "powerset"  haftmann@30531  28  image :: "('a => 'b) => 'a set => 'b set" (infixr "" 90)  haftmann@30304  29 haftmann@30304  30 local  wenzelm@19656  31 wenzelm@21210  32 notation  wenzelm@21404  33  "op :" ("op :") and  wenzelm@19656  34  "op :" ("(_/ : _)" [50, 51] 50)  wenzelm@11979  35 wenzelm@19656  36 abbreviation  wenzelm@21404  37  "not_mem x A == ~ (x : A)" -- "non-membership"  wenzelm@19656  38 wenzelm@21210  39 notation  wenzelm@21404  40  not_mem ("op ~:") and  wenzelm@19656  41  not_mem ("(_/ ~: _)" [50, 51] 50)  wenzelm@19656  42 wenzelm@21210  43 notation (xsymbols)  wenzelm@21404  44  "op :" ("op \") and  wenzelm@21404  45  "op :" ("(_/ \ _)" [50, 51] 50) and  wenzelm@21404  46  not_mem ("op \") and  haftmann@30304  47  not_mem ("(_/ \ _)" [50, 51] 50)  wenzelm@19656  48 wenzelm@21210  49 notation (HTML output)  wenzelm@21404  50  "op :" ("op \") and  wenzelm@21404  51  "op :" ("(_/ \ _)" [50, 51] 50) and  wenzelm@21404  52  not_mem ("op \") and  wenzelm@19656  53  not_mem ("(_/ \ _)" [50, 51] 50)  wenzelm@19656  54 haftmann@30531  55 syntax  haftmann@30531  56  "@Coll" :: "pttrn => bool => 'a set" ("(1{_./ _})")  haftmann@30531  57 haftmann@30531  58 translations  haftmann@30531  59  "{x. P}" == "Collect (%x. P)"  haftmann@30531  60 haftmann@30531  61 definition empty :: "'a set" ("{}") where  haftmann@30531  62  "empty \ {x. False}"  haftmann@30531  63 haftmann@30531  64 definition UNIV :: "'a set" where  haftmann@30531  65  "UNIV \ {x. True}"  haftmann@30531  66 haftmann@30531  67 syntax  haftmann@30531  68  "@Finset" :: "args => 'a set" ("{(_)}")  haftmann@30531  69 haftmann@30531  70 translations  haftmann@30531  71  "{x, xs}" == "insert x {xs}"  haftmann@30531  72  "{x}" == "insert x {}"  haftmann@30531  73 haftmann@30531  74 definition Int :: "'a set \ 'a set \ 'a set" (infixl "Int" 70) where  haftmann@30531  75  "A Int B \ {x. x \ A \ x \ B}"  haftmann@30531  76 haftmann@30531  77 definition Un :: "'a set \ 'a set \ 'a set" (infixl "Un" 65) where  haftmann@30531  78  "A Un B \ {x. x \ A \ x \ B}"  haftmann@30531  79 haftmann@30531  80 notation (xsymbols)  haftmann@30531  81  "Int" (infixl "\" 70) and  haftmann@30531  82  "Un" (infixl "\" 65)  haftmann@30531  83 haftmann@30531  84 notation (HTML output)  haftmann@30531  85  "Int" (infixl "\" 70) and  haftmann@30531  86  "Un" (infixl "\" 65)  haftmann@30531  87 haftmann@30531  88 syntax  haftmann@30531  89  "_Ball" :: "pttrn => 'a set => bool => bool" ("(3ALL _:_./ _)" [0, 0, 10] 10)  haftmann@30531  90  "_Bex" :: "pttrn => 'a set => bool => bool" ("(3EX _:_./ _)" [0, 0, 10] 10)  haftmann@30531  91  "_Bex1" :: "pttrn => 'a set => bool => bool" ("(3EX! _:_./ _)" [0, 0, 10] 10)  haftmann@30531  92  "_Bleast" :: "id => 'a set => bool => 'a" ("(3LEAST _:_./ _)" [0, 0, 10] 10)  haftmann@30531  93 haftmann@30531  94 syntax (HOL)  haftmann@30531  95  "_Ball" :: "pttrn => 'a set => bool => bool" ("(3! _:_./ _)" [0, 0, 10] 10)  haftmann@30531  96  "_Bex" :: "pttrn => 'a set => bool => bool" ("(3? _:_./ _)" [0, 0, 10] 10)  haftmann@30531  97  "_Bex1" :: "pttrn => 'a set => bool => bool" ("(3?! _:_./ _)" [0, 0, 10] 10)  haftmann@30531  98 haftmann@30531  99 syntax (xsymbols)  haftmann@30531  100  "_Ball" :: "pttrn => 'a set => bool => bool" ("(3\_\_./ _)" [0, 0, 10] 10)  haftmann@30531  101  "_Bex" :: "pttrn => 'a set => bool => bool" ("(3\_\_./ _)" [0, 0, 10] 10)  haftmann@30531  102  "_Bex1" :: "pttrn => 'a set => bool => bool" ("(3\!_\_./ _)" [0, 0, 10] 10)  haftmann@30531  103  "_Bleast" :: "id => 'a set => bool => 'a" ("(3LEAST_\_./ _)" [0, 0, 10] 10)  haftmann@30531  104 haftmann@30531  105 syntax (HTML output)  haftmann@30531  106  "_Ball" :: "pttrn => 'a set => bool => bool" ("(3\_\_./ _)" [0, 0, 10] 10)  haftmann@30531  107  "_Bex" :: "pttrn => 'a set => bool => bool" ("(3\_\_./ _)" [0, 0, 10] 10)  haftmann@30531  108  "_Bex1" :: "pttrn => 'a set => bool => bool" ("(3\!_\_./ _)" [0, 0, 10] 10)  haftmann@30531  109 haftmann@30531  110 translations  haftmann@30531  111  "ALL x:A. P" == "Ball A (%x. P)"  haftmann@30531  112  "EX x:A. P" == "Bex A (%x. P)"  haftmann@30531  113  "EX! x:A. P" == "Bex1 A (%x. P)"  haftmann@30531  114  "LEAST x:A. P" => "LEAST x. x:A & P"  haftmann@30531  115 haftmann@30531  116 definition INTER :: "'a set \ ('a \ 'b set) \ 'b set" where  haftmann@30531  117  "INTER A B \ {y. \x\A. y \ B x}"  haftmann@30531  118 haftmann@30531  119 definition UNION :: "'a set \ ('a \ 'b set) \ 'b set" where  haftmann@30531  120  "UNION A B \ {y. \x\A. y \ B x}"  haftmann@30531  121 haftmann@30531  122 definition Inter :: "'a set set \ 'a set" where  haftmann@30531  123  "Inter S \ INTER S (\x. x)"  haftmann@30531  124 haftmann@30531  125 definition Union :: "'a set set \ 'a set" where  haftmann@30531  126  "Union S \ UNION S (\x. x)"  haftmann@30531  127 haftmann@30531  128 notation (xsymbols)  haftmann@30531  129  Inter ("\_" [90] 90) and  haftmann@30531  130  Union ("\_" [90] 90)  haftmann@30531  131 haftmann@30531  132 haftmann@30531  133 subsection {* Additional concrete syntax *}  haftmann@30531  134 haftmann@30531  135 syntax  haftmann@30531  136  "@SetCompr" :: "'a => idts => bool => 'a set" ("(1{_ |/_./ _})")  haftmann@30531  137  "@Collect" :: "idt => 'a set => bool => 'a set" ("(1{_ :/ _./ _})")  haftmann@30531  138  "@INTER1" :: "pttrns => 'b set => 'b set" ("(3INT _./ _)" [0, 10] 10)  haftmann@30531  139  "@UNION1" :: "pttrns => 'b set => 'b set" ("(3UN _./ _)" [0, 10] 10)  haftmann@30531  140  "@INTER" :: "pttrn => 'a set => 'b set => 'b set" ("(3INT _:_./ _)" [0, 10] 10)  haftmann@30531  141  "@UNION" :: "pttrn => 'a set => 'b set => 'b set" ("(3UN _:_./ _)" [0, 10] 10)  haftmann@30531  142 haftmann@30531  143 syntax (xsymbols)  haftmann@30531  144  "@Collect" :: "idt => 'a set => bool => 'a set" ("(1{_ \/ _./ _})")  haftmann@30531  145  "@INTER1" :: "pttrns => 'b set => 'b set" ("(3\_./ _)" [0, 10] 10)  haftmann@30531  146  "@UNION1" :: "pttrns => 'b set => 'b set" ("(3\_./ _)" [0, 10] 10)  haftmann@30531  147  "@INTER" :: "pttrn => 'a set => 'b set => 'b set" ("(3\_\_./ _)" [0, 10] 10)  haftmann@30531  148  "@UNION" :: "pttrn => 'a set => 'b set => 'b set" ("(3\_\_./ _)" [0, 10] 10)  haftmann@30531  149 haftmann@30531  150 syntax (latex output)  haftmann@30531  151  "@INTER1" :: "pttrns => 'b set => 'b set" ("(3\(00\<^bsub>_\<^esub>)/ _)" [0, 10] 10)  haftmann@30531  152  "@UNION1" :: "pttrns => 'b set => 'b set" ("(3\(00\<^bsub>_\<^esub>)/ _)" [0, 10] 10)  haftmann@30531  153  "@INTER" :: "pttrn => 'a set => 'b set => 'b set" ("(3\(00\<^bsub>_\_\<^esub>)/ _)" [0, 10] 10)  haftmann@30531  154  "@UNION" :: "pttrn => 'a set => 'b set => 'b set" ("(3\(00\<^bsub>_\_\<^esub>)/ _)" [0, 10] 10)  haftmann@30531  155 haftmann@30531  156 translations  haftmann@30531  157  "{x:A. P}" => "{x. x:A & P}"  haftmann@30531  158  "INT x y. B" == "INT x. INT y. B"  haftmann@30531  159  "INT x. B" == "CONST INTER CONST UNIV (%x. B)"  haftmann@30531  160  "INT x. B" == "INT x:CONST UNIV. B"  haftmann@30531  161  "INT x:A. B" == "CONST INTER A (%x. B)"  haftmann@30531  162  "UN x y. B" == "UN x. UN y. B"  haftmann@30531  163  "UN x. B" == "CONST UNION CONST UNIV (%x. B)"  haftmann@30531  164  "UN x. B" == "UN x:CONST UNIV. B"  haftmann@30531  165  "UN x:A. B" == "CONST UNION A (%x. B)"  haftmann@30531  166 haftmann@30531  167 text {*  haftmann@30531  168  Note the difference between ordinary xsymbol syntax of indexed  haftmann@30531  169  unions and intersections (e.g.\ @{text"\a\<^isub>1\A\<^isub>1. B"})  haftmann@30531  170  and their \LaTeX\ rendition: @{term"\a\<^isub>1\A\<^isub>1. B"}. The  haftmann@30531  171  former does not make the index expression a subscript of the  haftmann@30531  172  union/intersection symbol because this leads to problems with nested  haftmann@30531  173  subscripts in Proof General.  haftmann@30531  174 *}  wenzelm@2261  175 haftmann@21333  176 abbreviation  wenzelm@21404  177  subset :: "'a set \ 'a set \ bool" where  haftmann@21819  178  "subset \ less"  wenzelm@21404  179 wenzelm@21404  180 abbreviation  wenzelm@21404  181  subset_eq :: "'a set \ 'a set \ bool" where  haftmann@21819  182  "subset_eq \ less_eq"  haftmann@21333  183 haftmann@21333  184 notation (output)  wenzelm@21404  185  subset ("op <") and  wenzelm@21404  186  subset ("(_/ < _)" [50, 51] 50) and  wenzelm@21404  187  subset_eq ("op <=") and  haftmann@21333  188  subset_eq ("(_/ <= _)" [50, 51] 50)  haftmann@21333  189 haftmann@21333  190 notation (xsymbols)  wenzelm@21404  191  subset ("op \") and  wenzelm@21404  192  subset ("(_/ \ _)" [50, 51] 50) and  wenzelm@21404  193  subset_eq ("op \") and  haftmann@21333  194  subset_eq ("(_/ \ _)" [50, 51] 50)  haftmann@21333  195 haftmann@21333  196 notation (HTML output)  wenzelm@21404  197  subset ("op \") and  wenzelm@21404  198  subset ("(_/ \ _)" [50, 51] 50) and  wenzelm@21404  199  subset_eq ("op \") and  haftmann@21333  200  subset_eq ("(_/ \ _)" [50, 51] 50)  haftmann@21333  201 haftmann@21333  202 abbreviation (input)  haftmann@21819  203  supset :: "'a set \ 'a set \ bool" where  haftmann@21819  204  "supset \ greater"  wenzelm@21404  205 wenzelm@21404  206 abbreviation (input)  haftmann@21819  207  supset_eq :: "'a set \ 'a set \ bool" where  haftmann@21819  208  "supset_eq \ greater_eq"  haftmann@21819  209 haftmann@21819  210 notation (xsymbols)  haftmann@21819  211  supset ("op \") and  haftmann@21819  212  supset ("(_/ \ _)" [50, 51] 50) and  haftmann@21819  213  supset_eq ("op \") and  haftmann@21819  214  supset_eq ("(_/ \ _)" [50, 51] 50)  haftmann@21333  215 haftmann@30531  216 abbreviation  haftmann@30531  217  range :: "('a => 'b) => 'b set" where -- "of function"  haftmann@30531  218  "range f == f  UNIV"  haftmann@30531  219 haftmann@30531  220 haftmann@30531  221 subsubsection "Bounded quantifiers"  nipkow@14804  222 wenzelm@19656  223 syntax (output)  nipkow@14804  224  "_setlessAll" :: "[idt, 'a, bool] => bool" ("(3ALL _<_./ _)" [0, 0, 10] 10)  nipkow@14804  225  "_setlessEx" :: "[idt, 'a, bool] => bool" ("(3EX _<_./ _)" [0, 0, 10] 10)  nipkow@14804  226  "_setleAll" :: "[idt, 'a, bool] => bool" ("(3ALL _<=_./ _)" [0, 0, 10] 10)  nipkow@14804  227  "_setleEx" :: "[idt, 'a, bool] => bool" ("(3EX _<=_./ _)" [0, 0, 10] 10)  webertj@20217  228  "_setleEx1" :: "[idt, 'a, bool] => bool" ("(3EX! _<=_./ _)" [0, 0, 10] 10)  nipkow@14804  229 nipkow@14804  230 syntax (xsymbols)  nipkow@14804  231  "_setlessAll" :: "[idt, 'a, bool] => bool" ("(3\_\_./ _)" [0, 0, 10] 10)  nipkow@14804  232  "_setlessEx" :: "[idt, 'a, bool] => bool" ("(3\_\_./ _)" [0, 0, 10] 10)  nipkow@14804  233  "_setleAll" :: "[idt, 'a, bool] => bool" ("(3\_\_./ _)" [0, 0, 10] 10)  nipkow@14804  234  "_setleEx" :: "[idt, 'a, bool] => bool" ("(3\_\_./ _)" [0, 0, 10] 10)  webertj@20217  235  "_setleEx1" :: "[idt, 'a, bool] => bool" ("(3\!_\_./ _)" [0, 0, 10] 10)  nipkow@14804  236 wenzelm@19656  237 syntax (HOL output)  nipkow@14804  238  "_setlessAll" :: "[idt, 'a, bool] => bool" ("(3! _<_./ _)" [0, 0, 10] 10)  nipkow@14804  239  "_setlessEx" :: "[idt, 'a, bool] => bool" ("(3? _<_./ _)" [0, 0, 10] 10)  nipkow@14804  240  "_setleAll" :: "[idt, 'a, bool] => bool" ("(3! _<=_./ _)" [0, 0, 10] 10)  nipkow@14804  241  "_setleEx" :: "[idt, 'a, bool] => bool" ("(3? _<=_./ _)" [0, 0, 10] 10)  webertj@20217  242  "_setleEx1" :: "[idt, 'a, bool] => bool" ("(3?! _<=_./ _)" [0, 0, 10] 10)  nipkow@14804  243 nipkow@14804  244 syntax (HTML output)  nipkow@14804  245  "_setlessAll" :: "[idt, 'a, bool] => bool" ("(3\_\_./ _)" [0, 0, 10] 10)  nipkow@14804  246  "_setlessEx" :: "[idt, 'a, bool] => bool" ("(3\_\_./ _)" [0, 0, 10] 10)  nipkow@14804  247  "_setleAll" :: "[idt, 'a, bool] => bool" ("(3\_\_./ _)" [0, 0, 10] 10)  nipkow@14804  248  "_setleEx" :: "[idt, 'a, bool] => bool" ("(3\_\_./ _)" [0, 0, 10] 10)  webertj@20217  249  "_setleEx1" :: "[idt, 'a, bool] => bool" ("(3\!_\_./ _)" [0, 0, 10] 10)  nipkow@14804  250 nipkow@14804  251 translations  haftmann@30531  252  "\A\B. P" => "ALL A. A \ B --> P"  haftmann@30531  253  "\A\B. P" => "EX A. A \ B & P"  haftmann@30531  254  "\A\B. P" => "ALL A. A \ B --> P"  haftmann@30531  255  "\A\B. P" => "EX A. A \ B & P"  haftmann@30531  256  "\!A\B. P" => "EX! A. A \ B & P"  nipkow@14804  257 nipkow@14804  258 print_translation {*  nipkow@14804  259 let  wenzelm@22377  260  val Type (set_type, _) = @{typ "'a set"};  wenzelm@22377  261  val All_binder = Syntax.binder_name @{const_syntax "All"};  wenzelm@22377  262  val Ex_binder = Syntax.binder_name @{const_syntax "Ex"};  wenzelm@22377  263  val impl = @{const_syntax "op -->"};  wenzelm@22377  264  val conj = @{const_syntax "op &"};  wenzelm@22377  265  val sbset = @{const_syntax "subset"};  wenzelm@22377  266  val sbset_eq = @{const_syntax "subset_eq"};  haftmann@21819  267 haftmann@21819  268  val trans =  haftmann@21819  269  [((All_binder, impl, sbset), "_setlessAll"),  haftmann@21819  270  ((All_binder, impl, sbset_eq), "_setleAll"),  haftmann@21819  271  ((Ex_binder, conj, sbset), "_setlessEx"),  haftmann@21819  272  ((Ex_binder, conj, sbset_eq), "_setleEx")];  haftmann@21819  273 haftmann@21819  274  fun mk v v' c n P =  haftmann@21819  275  if v = v' andalso not (Term.exists_subterm (fn Free (x, _) => x = v | _ => false) n)  haftmann@21819  276  then Syntax.const c $Syntax.mark_bound v'$ n $P else raise Match;  haftmann@21819  277 haftmann@21819  278  fun tr' q = (q,  haftmann@21819  279  fn [Const ("_bound", _)$ Free (v, Type (T, _)), Const (c, _) $(Const (d, _)$ (Const ("_bound", _) $Free (v', _))$ n) $P] =>  haftmann@21819  280  if T = (set_type) then case AList.lookup (op =) trans (q, c, d)  haftmann@21819  281  of NONE => raise Match  haftmann@21819  282  | SOME l => mk v v' l n P  haftmann@21819  283  else raise Match  haftmann@21819  284  | _ => raise Match);  nipkow@14804  285 in  haftmann@21819  286  [tr' All_binder, tr' Ex_binder]  nipkow@14804  287 end  nipkow@14804  288 *}  nipkow@14804  289 haftmann@30531  290 wenzelm@11979  291 text {*  wenzelm@11979  292  \medskip Translate between @{text "{e | x1...xn. P}"} and @{text  wenzelm@11979  293  "{u. EX x1..xn. u = e & P}"}; @{text "{y. EX x1..xn. y = e & P}"} is  wenzelm@11979  294  only translated if @{text "[0..n] subset bvs(e)"}.  wenzelm@11979  295 *}  wenzelm@11979  296 wenzelm@11979  297 parse_translation {*  wenzelm@11979  298  let  wenzelm@11979  299  val ex_tr = snd (mk_binder_tr ("EX ", "Ex"));  wenzelm@3947  300 wenzelm@11979  301  fun nvars (Const ("_idts", _)$ _ $idts) = nvars idts + 1  wenzelm@11979  302  | nvars _ = 1;  wenzelm@11979  303 wenzelm@11979  304  fun setcompr_tr [e, idts, b] =  wenzelm@11979  305  let  wenzelm@11979  306  val eq = Syntax.const "op ="$ Bound (nvars idts) $e;  wenzelm@11979  307  val P = Syntax.const "op &"$ eq $b;  wenzelm@11979  308  val exP = ex_tr [idts, P];  wenzelm@17784  309  in Syntax.const "Collect"$ Term.absdummy (dummyT, exP) end;  wenzelm@11979  310 wenzelm@11979  311  in [("@SetCompr", setcompr_tr)] end;  wenzelm@11979  312 *}  clasohm@923  313 haftmann@30531  314 (* To avoid eta-contraction of body: *)  haftmann@30531  315 print_translation {*  haftmann@30531  316 let  haftmann@30531  317  fun btr' syn [A, Abs abs] =  haftmann@30531  318  let val (x, t) = atomic_abs_tr' abs  haftmann@30531  319  in Syntax.const syn $x$ A $t end  haftmann@30531  320 in  haftmann@30531  321 [(@{const_syntax Ball}, btr' "_Ball"), (@{const_syntax Bex}, btr' "_Bex"),  haftmann@30531  322  (@{const_syntax UNION}, btr' "@UNION"),(@{const_syntax INTER}, btr' "@INTER")]  haftmann@30531  323 end  haftmann@30531  324 *}  haftmann@30531  325 nipkow@13763  326 print_translation {*  nipkow@13763  327 let  nipkow@13763  328  val ex_tr' = snd (mk_binder_tr' ("Ex", "DUMMY"));  nipkow@13763  329 nipkow@13763  330  fun setcompr_tr' [Abs (abs as (_, _, P))] =  nipkow@13763  331  let  nipkow@13763  332  fun check (Const ("Ex", _)$ Abs (_, _, P), n) = check (P, n + 1)  nipkow@13763  333  | check (Const ("op &", _) $(Const ("op =", _)$ Bound m $e)$ P, n) =  nipkow@13763  334  n > 0 andalso m = n andalso not (loose_bvar1 (P, n)) andalso  nipkow@13763  335  ((0 upto (n - 1)) subset add_loose_bnos (e, 0, []))  nipkow@13764  336  | check _ = false  clasohm@923  337 wenzelm@11979  338  fun tr' (_ $abs) =  wenzelm@11979  339  let val _$ idts $(_$ (_ $_$ e) $Q) = ex_tr' [abs]  wenzelm@11979  340  in Syntax.const "@SetCompr"$ e $idts$ Q end;  nipkow@13763  341  in if check (P, 0) then tr' P  nipkow@15535  342  else let val (x as _ $Free(xN,_), t) = atomic_abs_tr' abs  nipkow@15535  343  val M = Syntax.const "@Coll"$ x $t  nipkow@15535  344  in case t of  nipkow@15535  345  Const("op &",_)  nipkow@15535  346 $ (Const("op :",_) $(Const("_bound",_)$ Free(yN,_)) $A)  nipkow@15535  347 $ P =>  nipkow@15535  348  if xN=yN then Syntax.const "@Collect" $x$ A $P else M  nipkow@15535  349  | _ => M  nipkow@15535  350  end  nipkow@13763  351  end;  wenzelm@11979  352  in [("Collect", setcompr_tr')] end;  wenzelm@11979  353 *}  wenzelm@11979  354 haftmann@30531  355 haftmann@30531  356 subsection {* Rules and definitions *}  haftmann@30531  357 haftmann@30531  358 text {* Isomorphisms between predicates and sets. *}  haftmann@30531  359 haftmann@30531  360 defs  haftmann@30531  361  mem_def [code]: "x : S == S x"  haftmann@30531  362  Collect_def [code]: "Collect P == P"  haftmann@30531  363 haftmann@30531  364 defs  haftmann@30531  365  Ball_def: "Ball A P == ALL x. x:A --> P(x)"  haftmann@30531  366  Bex_def: "Bex A P == EX x. x:A & P(x)"  haftmann@30531  367  Bex1_def: "Bex1 A P == EX! x. x:A & P(x)"  haftmann@30531  368 haftmann@30531  369 instantiation "fun" :: (type, minus) minus  haftmann@30531  370 begin  haftmann@30531  371 haftmann@30531  372 definition  haftmann@30531  373  fun_diff_def: "A - B = (%x. A x - B x)"  haftmann@30531  374 haftmann@30531  375 instance ..  haftmann@30531  376 haftmann@30531  377 end  haftmann@30531  378 haftmann@30531  379 instantiation bool :: minus  haftmann@30531  380 begin  haftmann@30531  381 haftmann@30531  382 definition  haftmann@30531  383  bool_diff_def: "A - B = (A & ~ B)"  haftmann@30531  384 haftmann@30531  385 instance ..  haftmann@30531  386 haftmann@30531  387 end  haftmann@30531  388 haftmann@30531  389 instantiation "fun" :: (type, uminus) uminus  haftmann@30531  390 begin  haftmann@30531  391 haftmann@30531  392 definition  haftmann@30531  393  fun_Compl_def: "- A = (%x. - A x)"  haftmann@30531  394 haftmann@30531  395 instance ..  haftmann@30531  396 haftmann@30531  397 end  haftmann@30531  398 haftmann@30531  399 instantiation bool :: uminus  haftmann@30531  400 begin  haftmann@30531  401 haftmann@30531  402 definition  haftmann@30531  403  bool_Compl_def: "- A = (~ A)"  haftmann@30531  404 haftmann@30531  405 instance ..  haftmann@30531  406 haftmann@30531  407 end  haftmann@30531  408 haftmann@30531  409 defs  haftmann@30531  410  Pow_def: "Pow A == {B. B <= A}"  haftmann@30531  411  insert_def: "insert a B == {x. x=a} Un B"  haftmann@30531  412  image_def: "fA == {y. EX x:A. y = f(x)}"  haftmann@30531  413 haftmann@30531  414 haftmann@30531  415 subsection {* Lemmas and proof tool setup *}  haftmann@30531  416 haftmann@30531  417 subsubsection {* Relating predicates and sets *}  haftmann@30531  418 haftmann@30531  419 lemma mem_Collect_eq [iff]: "(a : {x. P(x)}) = P(a)"  haftmann@30531  420  by (simp add: Collect_def mem_def)  haftmann@30531  421 haftmann@30531  422 lemma Collect_mem_eq [simp]: "{x. x:A} = A"  haftmann@30531  423  by (simp add: Collect_def mem_def)  haftmann@30531  424 haftmann@30531  425 lemma CollectI: "P(a) ==> a : {x. P(x)}"  haftmann@30531  426  by simp  haftmann@30531  427 haftmann@30531  428 lemma CollectD: "a : {x. P(x)} ==> P(a)"  haftmann@30531  429  by simp  haftmann@30531  430 haftmann@30531  431 lemma Collect_cong: "(!!x. P x = Q x) ==> {x. P(x)} = {x. Q(x)}"  haftmann@30531  432  by simp  haftmann@30531  433 haftmann@30531  434 lemmas CollectE = CollectD [elim_format]  haftmann@30531  435 haftmann@30531  436 haftmann@30531  437 subsubsection {* Bounded quantifiers *}  haftmann@30531  438 wenzelm@11979  439 lemma ballI [intro!]: "(!!x. x:A ==> P x) ==> ALL x:A. P x"  wenzelm@11979  440  by (simp add: Ball_def)  wenzelm@11979  441 wenzelm@11979  442 lemmas strip = impI allI ballI  wenzelm@11979  443 wenzelm@11979  444 lemma bspec [dest?]: "ALL x:A. P x ==> x:A ==> P x"  wenzelm@11979  445  by (simp add: Ball_def)  wenzelm@11979  446 wenzelm@11979  447 lemma ballE [elim]: "ALL x:A. P x ==> (P x ==> Q) ==> (x ~: A ==> Q) ==> Q"  wenzelm@11979  448  by (unfold Ball_def) blast  wenzelm@22139  449 wenzelm@22139  450 ML {* bind_thm ("rev_ballE", permute_prems 1 1 @{thm ballE}) *}  wenzelm@11979  451 wenzelm@11979  452 text {*  wenzelm@11979  453  \medskip This tactic takes assumptions @{prop "ALL x:A. P x"} and  wenzelm@11979  454  @{prop "a:A"}; creates assumption @{prop "P a"}.  wenzelm@11979  455 *}  wenzelm@11979  456 wenzelm@11979  457 ML {*  wenzelm@22139  458  fun ball_tac i = etac @{thm ballE} i THEN contr_tac (i + 1)  wenzelm@11979  459 *}  wenzelm@11979  460 wenzelm@11979  461 text {*  wenzelm@11979  462  Gives better instantiation for bound:  wenzelm@11979  463 *}  wenzelm@11979  464 wenzelm@26339  465 declaration {* fn _ =>  wenzelm@26339  466  Classical.map_cs (fn cs => cs addbefore ("bspec", datac @{thm bspec} 1))  wenzelm@11979  467 *}  wenzelm@11979  468 wenzelm@11979  469 lemma bexI [intro]: "P x ==> x:A ==> EX x:A. P x"  wenzelm@11979  470  -- {* Normally the best argument order: @{prop "P x"} constrains the  wenzelm@11979  471  choice of @{prop "x:A"}. *}  wenzelm@11979  472  by (unfold Bex_def) blast  wenzelm@11979  473 wenzelm@13113  474 lemma rev_bexI [intro?]: "x:A ==> P x ==> EX x:A. P x"  wenzelm@11979  475  -- {* The best argument order when there is only one @{prop "x:A"}. *}  wenzelm@11979  476  by (unfold Bex_def) blast  wenzelm@11979  477 wenzelm@11979  478 lemma bexCI: "(ALL x:A. ~P x ==> P a) ==> a:A ==> EX x:A. P x"  wenzelm@11979  479  by (unfold Bex_def) blast  wenzelm@11979  480 wenzelm@11979  481 lemma bexE [elim!]: "EX x:A. P x ==> (!!x. x:A ==> P x ==> Q) ==> Q"  wenzelm@11979  482  by (unfold Bex_def) blast  wenzelm@11979  483 wenzelm@11979  484 lemma ball_triv [simp]: "(ALL x:A. P) = ((EX x. x:A) --> P)"  wenzelm@11979  485  -- {* Trival rewrite rule. *}  wenzelm@11979  486  by (simp add: Ball_def)  wenzelm@11979  487 wenzelm@11979  488 lemma bex_triv [simp]: "(EX x:A. P) = ((EX x. x:A) & P)"  wenzelm@11979  489  -- {* Dual form for existentials. *}  wenzelm@11979  490  by (simp add: Bex_def)  wenzelm@11979  491 wenzelm@11979  492 lemma bex_triv_one_point1 [simp]: "(EX x:A. x = a) = (a:A)"  wenzelm@11979  493  by blast  wenzelm@11979  494 wenzelm@11979  495 lemma bex_triv_one_point2 [simp]: "(EX x:A. a = x) = (a:A)"  wenzelm@11979  496  by blast  wenzelm@11979  497 wenzelm@11979  498 lemma bex_one_point1 [simp]: "(EX x:A. x = a & P x) = (a:A & P a)"  wenzelm@11979  499  by blast  wenzelm@11979  500 wenzelm@11979  501 lemma bex_one_point2 [simp]: "(EX x:A. a = x & P x) = (a:A & P a)"  wenzelm@11979  502  by blast  wenzelm@11979  503 wenzelm@11979  504 lemma ball_one_point1 [simp]: "(ALL x:A. x = a --> P x) = (a:A --> P a)"  wenzelm@11979  505  by blast  wenzelm@11979  506 wenzelm@11979  507 lemma ball_one_point2 [simp]: "(ALL x:A. a = x --> P x) = (a:A --> P a)"  wenzelm@11979  508  by blast  wenzelm@11979  509 wenzelm@26480  510 ML {*  wenzelm@13462  511  local  wenzelm@22139  512  val unfold_bex_tac = unfold_tac @{thms "Bex_def"};  wenzelm@18328  513  fun prove_bex_tac ss = unfold_bex_tac ss THEN Quantifier1.prove_one_point_ex_tac;  wenzelm@11979  514  val rearrange_bex = Quantifier1.rearrange_bex prove_bex_tac;  wenzelm@11979  515 wenzelm@22139  516  val unfold_ball_tac = unfold_tac @{thms "Ball_def"};  wenzelm@18328  517  fun prove_ball_tac ss = unfold_ball_tac ss THEN Quantifier1.prove_one_point_all_tac;  wenzelm@11979  518  val rearrange_ball = Quantifier1.rearrange_ball prove_ball_tac;  wenzelm@11979  519  in  wenzelm@18328  520  val defBEX_regroup = Simplifier.simproc (the_context ())  wenzelm@13462  521  "defined BEX" ["EX x:A. P x & Q x"] rearrange_bex;  wenzelm@18328  522  val defBALL_regroup = Simplifier.simproc (the_context ())  wenzelm@13462  523  "defined BALL" ["ALL x:A. P x --> Q x"] rearrange_ball;  wenzelm@11979  524  end;  wenzelm@13462  525 wenzelm@13462  526  Addsimprocs [defBALL_regroup, defBEX_regroup];  wenzelm@11979  527 *}  wenzelm@11979  528 haftmann@30531  529 haftmann@30531  530 subsubsection {* Congruence rules *}  wenzelm@11979  531 berghofe@16636  532 lemma ball_cong:  wenzelm@11979  533  "A = B ==> (!!x. x:B ==> P x = Q x) ==>  wenzelm@11979  534  (ALL x:A. P x) = (ALL x:B. Q x)"  wenzelm@11979  535  by (simp add: Ball_def)  wenzelm@11979  536 berghofe@16636  537 lemma strong_ball_cong [cong]:  berghofe@16636  538  "A = B ==> (!!x. x:B =simp=> P x = Q x) ==>  berghofe@16636  539  (ALL x:A. P x) = (ALL x:B. Q x)"  berghofe@16636  540  by (simp add: simp_implies_def Ball_def)  berghofe@16636  541 berghofe@16636  542 lemma bex_cong:  wenzelm@11979  543  "A = B ==> (!!x. x:B ==> P x = Q x) ==>  wenzelm@11979  544  (EX x:A. P x) = (EX x:B. Q x)"  wenzelm@11979  545  by (simp add: Bex_def cong: conj_cong)  regensbu@1273  546 berghofe@16636  547 lemma strong_bex_cong [cong]:  berghofe@16636  548  "A = B ==> (!!x. x:B =simp=> P x = Q x) ==>  berghofe@16636  549  (EX x:A. P x) = (EX x:B. Q x)"  berghofe@16636  550  by (simp add: simp_implies_def Bex_def cong: conj_cong)  berghofe@16636  551 haftmann@30531  552 haftmann@30531  553 subsubsection {* Subsets *}  haftmann@30531  554 haftmann@30531  555 lemma subsetI [atp,intro!]: "(!!x. x:A ==> x:B) ==> A \ B"  haftmann@30531  556  by (auto simp add: mem_def intro: predicate1I)  haftmann@30352  557 wenzelm@11979  558 text {*  haftmann@30531  559  \medskip Map the type @{text "'a set => anything"} to just @{typ  haftmann@30531  560  'a}; for overloading constants whose first argument has type @{typ  haftmann@30531  561  "'a set"}.  wenzelm@11979  562 *}  wenzelm@11979  563 haftmann@30596  564 lemma subsetD [elim, intro?]: "A \ B ==> c \ A ==> c \ B"  haftmann@30531  565  -- {* Rule in Modus Ponens style. *}  haftmann@30531  566  by (unfold mem_def) blast  haftmann@30531  567 haftmann@30596  568 lemma rev_subsetD [intro?]: "c \ A ==> A \ B ==> c \ B"  haftmann@30531  569  -- {* The same, with reversed premises for use with @{text erule} --  haftmann@30531  570  cf @{text rev_mp}. *}  haftmann@30531  571  by (rule subsetD)  haftmann@30531  572 wenzelm@11979  573 text {*  haftmann@30531  574  \medskip Converts @{prop "A \ B"} to @{prop "x \ A ==> x \ B"}.  haftmann@30531  575 *}  haftmann@30531  576 haftmann@30531  577 ML {*  haftmann@30531  578  fun impOfSubs th = th RSN (2, @{thm rev_subsetD})  wenzelm@11979  579 *}  wenzelm@11979  580 haftmann@30531  581 lemma subsetCE [elim]: "A \ B ==> (c \ A ==> P) ==> (c \ B ==> P) ==> P"  haftmann@30531  582  -- {* Classical elimination rule. *}  haftmann@30531  583  by (unfold mem_def) blast  haftmann@30531  584 haftmann@30531  585 lemma subset_eq: "A \ B = (\x\A. x \ B)" by blast  wenzelm@2388  586 wenzelm@11979  587 text {*  haftmann@30531  588  \medskip Takes assumptions @{prop "A \ B"}; @{prop "c \ A"} and  haftmann@30531  589  creates the assumption @{prop "c \ B"}.  haftmann@30352  590 *}  haftmann@30352  591 haftmann@30352  592 ML {*  haftmann@30531  593  fun set_mp_tac i = etac @{thm subsetCE} i THEN mp_tac i  wenzelm@11979  594 *}  wenzelm@11979  595 haftmann@30531  596 lemma contra_subsetD: "A \ B ==> c \ B ==> c \ A"  haftmann@30531  597  by blast  haftmann@30531  598 haftmann@30531  599 lemma subset_refl [simp,atp]: "A \ A"  haftmann@30531  600  by fast  haftmann@30531  601 haftmann@30531  602 lemma subset_trans: "A \ B ==> B \ C ==> A \ C"  haftmann@30531  603  by blast  haftmann@30531  604 haftmann@30531  605 haftmann@30531  606 subsubsection {* Equality *}  haftmann@30531  607 haftmann@30531  608 lemma set_ext: assumes prem: "(!!x. (x:A) = (x:B))" shows "A = B"  haftmann@30531  609  apply (rule prem [THEN ext, THEN arg_cong, THEN box_equals])  haftmann@30531  610  apply (rule Collect_mem_eq)  haftmann@30531  611  apply (rule Collect_mem_eq)  haftmann@30531  612  done  haftmann@30531  613 haftmann@30531  614 (* Due to Brian Huffman *)  haftmann@30531  615 lemma expand_set_eq: "(A = B) = (ALL x. (x:A) = (x:B))"  haftmann@30531  616 by(auto intro:set_ext)  haftmann@30531  617 haftmann@30531  618 lemma subset_antisym [intro!]: "A \ B ==> B \ A ==> A = B"  haftmann@30531  619  -- {* Anti-symmetry of the subset relation. *}  haftmann@30531  620  by (iprover intro: set_ext subsetD)  haftmann@30531  621 haftmann@30531  622 text {*  haftmann@30531  623  \medskip Equality rules from ZF set theory -- are they appropriate  haftmann@30531  624  here?  haftmann@30531  625 *}  haftmann@30531  626 haftmann@30531  627 lemma equalityD1: "A = B ==> A \ B"  haftmann@30531  628  by (simp add: subset_refl)  haftmann@30531  629 haftmann@30531  630 lemma equalityD2: "A = B ==> B \ A"  haftmann@30531  631  by (simp add: subset_refl)  haftmann@30531  632 haftmann@30531  633 text {*  haftmann@30531  634  \medskip Be careful when adding this to the claset as @{text  haftmann@30531  635  subset_empty} is in the simpset: @{prop "A = {}"} goes to @{prop "{}  haftmann@30531  636  \ A"} and @{prop "A \ {}"} and then back to @{prop "A = {}"}!  haftmann@30352  637 *}  haftmann@30352  638 haftmann@30531  639 lemma equalityE: "A = B ==> (A \ B ==> B \ A ==> P) ==> P"  haftmann@30531  640  by (simp add: subset_refl)  haftmann@30531  641 haftmann@30531  642 lemma equalityCE [elim]:  haftmann@30531  643  "A = B ==> (c \ A ==> c \ B ==> P) ==> (c \ A ==> c \ B ==> P) ==> P"  haftmann@30531  644  by blast  haftmann@30531  645 haftmann@30531  646 lemma eqset_imp_iff: "A = B ==> (x : A) = (x : B)"  haftmann@30531  647  by simp  haftmann@30531  648 haftmann@30531  649 lemma eqelem_imp_iff: "x = y ==> (x : A) = (y : A)"  haftmann@30531  650  by simp  haftmann@30531  651 haftmann@30531  652 haftmann@30531  653 subsubsection {* The universal set -- UNIV *}  haftmann@30531  654 haftmann@30531  655 lemma UNIV_I [simp]: "x : UNIV"  haftmann@30531  656  by (simp add: UNIV_def)  haftmann@30531  657 haftmann@30531  658 declare UNIV_I [intro] -- {* unsafe makes it less likely to cause problems *}  haftmann@30531  659 haftmann@30531  660 lemma UNIV_witness [intro?]: "EX x. x : UNIV"  haftmann@30531  661  by simp  haftmann@30531  662 haftmann@30531  663 lemma subset_UNIV [simp]: "A \ UNIV"  haftmann@30531  664  by (rule subsetI) (rule UNIV_I)  haftmann@30531  665 haftmann@30531  666 text {*  haftmann@30531  667  \medskip Eta-contracting these two rules (to remove @{text P})  haftmann@30531  668  causes them to be ignored because of their interaction with  haftmann@30531  669  congruence rules.  haftmann@30531  670 *}  haftmann@30531  671 haftmann@30531  672 lemma ball_UNIV [simp]: "Ball UNIV P = All P"  haftmann@30531  673  by (simp add: Ball_def)  haftmann@30531  674 haftmann@30531  675 lemma bex_UNIV [simp]: "Bex UNIV P = Ex P"  haftmann@30531  676  by (simp add: Bex_def)  haftmann@30531  677 haftmann@30531  678 lemma UNIV_eq_I: "(\x. x \ A) \ UNIV = A"  haftmann@30531  679  by auto  haftmann@30531  680 haftmann@30531  681 haftmann@30531  682 subsubsection {* The empty set *}  haftmann@30531  683 haftmann@30531  684 lemma empty_iff [simp]: "(c : {}) = False"  haftmann@30531  685  by (simp add: empty_def)  haftmann@30531  686 haftmann@30531  687 lemma emptyE [elim!]: "a : {} ==> P"  haftmann@30531  688  by simp  haftmann@30531  689 haftmann@30531  690 lemma empty_subsetI [iff]: "{} \ A"  haftmann@30531  691  -- {* One effect is to delete the ASSUMPTION @{prop "{} <= A"} *}  haftmann@30531  692  by blast  haftmann@30531  693 haftmann@30531  694 lemma equals0I: "(!!y. y \ A ==> False) ==> A = {}"  haftmann@30531  695  by blast  haftmann@30531  696 haftmann@30531  697 lemma equals0D: "A = {} ==> a \ A"  haftmann@30531  698  -- {* Use for reasoning about disjointness: @{prop "A Int B = {}"} *}  haftmann@30531  699  by blast  haftmann@30531  700 haftmann@30531  701 lemma ball_empty [simp]: "Ball {} P = True"  haftmann@30531  702  by (simp add: Ball_def)  haftmann@30531  703 haftmann@30531  704 lemma bex_empty [simp]: "Bex {} P = False"  haftmann@30531  705  by (simp add: Bex_def)  haftmann@30531  706 haftmann@30531  707 lemma UNIV_not_empty [iff]: "UNIV ~= {}"  haftmann@30531  708  by (blast elim: equalityE)  haftmann@30531  709 haftmann@30531  710 haftmann@30531  711 subsubsection {* The Powerset operator -- Pow *}  haftmann@30531  712 haftmann@30531  713 lemma Pow_iff [iff]: "(A \ Pow B) = (A \ B)"  haftmann@30531  714  by (simp add: Pow_def)  haftmann@30531  715 haftmann@30531  716 lemma PowI: "A \ B ==> A \ Pow B"  haftmann@30531  717  by (simp add: Pow_def)  haftmann@30531  718 haftmann@30531  719 lemma PowD: "A \ Pow B ==> A \ B"  haftmann@30531  720  by (simp add: Pow_def)  haftmann@30531  721 haftmann@30531  722 lemma Pow_bottom: "{} \ Pow B"  haftmann@30531  723  by simp  haftmann@30531  724 haftmann@30531  725 lemma Pow_top: "A \ Pow A"  haftmann@30531  726  by (simp add: subset_refl)  haftmann@30531  727 haftmann@30531  728 haftmann@30531  729 subsubsection {* Set complement *}  haftmann@30531  730 haftmann@30531  731 lemma Compl_iff [simp]: "(c \ -A) = (c \ A)"  haftmann@30531  732  by (simp add: mem_def fun_Compl_def bool_Compl_def)  haftmann@30531  733 haftmann@30531  734 lemma ComplI [intro!]: "(c \ A ==> False) ==> c \ -A"  haftmann@30531  735  by (unfold mem_def fun_Compl_def bool_Compl_def) blast  clasohm@923  736 wenzelm@11979  737 text {*  haftmann@30531  738  \medskip This form, with negated conclusion, works well with the  haftmann@30531  739  Classical prover. Negated assumptions behave like formulae on the  haftmann@30531  740  right side of the notional turnstile ... *}  haftmann@30531  741 haftmann@30531  742 lemma ComplD [dest!]: "c : -A ==> c~:A"  haftmann@30531  743  by (simp add: mem_def fun_Compl_def bool_Compl_def)  haftmann@30531  744 haftmann@30531  745 lemmas ComplE = ComplD [elim_format]  haftmann@30531  746 haftmann@30531  747 lemma Compl_eq: "- A = {x. ~ x : A}" by blast  haftmann@30531  748 haftmann@30531  749 haftmann@30531  750 subsubsection {* Binary union -- Un *}  haftmann@30531  751 haftmann@30531  752 lemma Un_iff [simp]: "(c : A Un B) = (c:A | c:B)"  haftmann@30531  753  by (unfold Un_def) blast  haftmann@30531  754 haftmann@30531  755 lemma UnI1 [elim?]: "c:A ==> c : A Un B"  haftmann@30531  756  by simp  haftmann@30531  757 haftmann@30531  758 lemma UnI2 [elim?]: "c:B ==> c : A Un B"  haftmann@30531  759  by simp  haftmann@30531  760 haftmann@30531  761 text {*  haftmann@30531  762  \medskip Classical introduction rule: no commitment to @{prop A} vs  haftmann@30531  763  @{prop B}.  wenzelm@11979  764 *}  wenzelm@11979  765 haftmann@30531  766 lemma UnCI [intro!]: "(c~:B ==> c:A) ==> c : A Un B"  haftmann@30531  767  by auto  haftmann@30531  768 haftmann@30531  769 lemma UnE [elim!]: "c : A Un B ==> (c:A ==> P) ==> (c:B ==> P) ==> P"  haftmann@30531  770  by (unfold Un_def) blast  haftmann@30531  771 haftmann@30531  772 haftmann@30531  773 subsubsection {* Binary intersection -- Int *}  haftmann@30531  774 haftmann@30531  775 lemma Int_iff [simp]: "(c : A Int B) = (c:A & c:B)"  haftmann@30531  776  by (unfold Int_def) blast  haftmann@30531  777 haftmann@30531  778 lemma IntI [intro!]: "c:A ==> c:B ==> c : A Int B"  haftmann@30531  779  by simp  haftmann@30531  780 haftmann@30531  781 lemma IntD1: "c : A Int B ==> c:A"  haftmann@30531  782  by simp  haftmann@30531  783 haftmann@30531  784 lemma IntD2: "c : A Int B ==> c:B"  haftmann@30531  785  by simp  haftmann@30531  786 haftmann@30531  787 lemma IntE [elim!]: "c : A Int B ==> (c:A ==> c:B ==> P) ==> P"  haftmann@30531  788  by simp  haftmann@30531  789 haftmann@30531  790 haftmann@30531  791 subsubsection {* Set difference *}  haftmann@30531  792 haftmann@30531  793 lemma Diff_iff [simp]: "(c : A - B) = (c:A & c~:B)"  haftmann@30531  794  by (simp add: mem_def fun_diff_def bool_diff_def)  haftmann@30531  795 haftmann@30531  796 lemma DiffI [intro!]: "c : A ==> c ~: B ==> c : A - B"  haftmann@30531  797  by simp  haftmann@30531  798 haftmann@30531  799 lemma DiffD1: "c : A - B ==> c : A"  haftmann@30531  800  by simp  haftmann@30531  801 haftmann@30531  802 lemma DiffD2: "c : A - B ==> c : B ==> P"  haftmann@30531  803  by simp  haftmann@30531  804 haftmann@30531  805 lemma DiffE [elim!]: "c : A - B ==> (c:A ==> c~:B ==> P) ==> P"  haftmann@30531  806  by simp  haftmann@30531  807 haftmann@30531  808 lemma set_diff_eq: "A - B = {x. x : A & ~ x : B}" by blast  haftmann@30531  809 haftmann@30531  810 lemma Compl_eq_Diff_UNIV: "-A = (UNIV - A)"  haftmann@30531  811 by blast  haftmann@30531  812 haftmann@30531  813 haftmann@30531  814 subsubsection {* Augmenting a set -- insert *}  haftmann@30531  815 haftmann@30531  816 lemma insert_iff [simp]: "(a : insert b A) = (a = b | a:A)"  haftmann@30531  817  by (unfold insert_def) blast  haftmann@30531  818 haftmann@30531  819 lemma insertI1: "a : insert a B"  haftmann@30531  820  by simp  haftmann@30531  821 haftmann@30531  822 lemma insertI2: "a : B ==> a : insert b B"  haftmann@30531  823  by simp  haftmann@30531  824 haftmann@30531  825 lemma insertE [elim!]: "a : insert b A ==> (a = b ==> P) ==> (a:A ==> P) ==> P"  haftmann@30531  826  by (unfold insert_def) blast  haftmann@30531  827 haftmann@30531  828 lemma insertCI [intro!]: "(a~:B ==> a = b) ==> a: insert b B"  haftmann@30531  829  -- {* Classical introduction rule. *}  haftmann@30531  830  by auto  haftmann@30531  831 haftmann@30531  832 lemma subset_insert_iff: "(A \ insert x B) = (if x:A then A - {x} \ B else A \ B)"  haftmann@30531  833  by auto  haftmann@30531  834 haftmann@30531  835 lemma set_insert:  haftmann@30531  836  assumes "x \ A"  haftmann@30531  837  obtains B where "A = insert x B" and "x \ B"  haftmann@30531  838 proof  haftmann@30531  839  from assms show "A = insert x (A - {x})" by blast  haftmann@30531  840 next  haftmann@30531  841  show "x \ A - {x}" by blast  haftmann@30531  842 qed  haftmann@30531  843 haftmann@30531  844 lemma insert_ident: "x ~: A ==> x ~: B ==> (insert x A = insert x B) = (A = B)"  haftmann@30531  845 by auto  haftmann@30531  846 haftmann@30531  847 subsubsection {* Singletons, using insert *}  haftmann@30531  848 haftmann@30531  849 lemma singletonI [intro!,noatp]: "a : {a}"  haftmann@30531  850  -- {* Redundant? But unlike @{text insertCI}, it proves the subgoal immediately! *}  haftmann@30531  851  by (rule insertI1)  haftmann@30531  852 haftmann@30531  853 lemma singletonD [dest!,noatp]: "b : {a} ==> b = a"  haftmann@30531  854  by blast  haftmann@30531  855 haftmann@30531  856 lemmas singletonE = singletonD [elim_format]  haftmann@30531  857 haftmann@30531  858 lemma singleton_iff: "(b : {a}) = (b = a)"  haftmann@30531  859  by blast  haftmann@30531  860 haftmann@30531  861 lemma singleton_inject [dest!]: "{a} = {b} ==> a = b"  haftmann@30531  862  by blast  haftmann@30531  863 haftmann@30531  864 lemma singleton_insert_inj_eq [iff,noatp]:  haftmann@30531  865  "({b} = insert a A) = (a = b & A \ {b})"  haftmann@30531  866  by blast  haftmann@30531  867 haftmann@30531  868 lemma singleton_insert_inj_eq' [iff,noatp]:  haftmann@30531  869  "(insert a A = {b}) = (a = b & A \ {b})"  haftmann@30531  870  by blast  haftmann@30531  871 haftmann@30531  872 lemma subset_singletonD: "A \ {x} ==> A = {} | A = {x}"  haftmann@30531  873  by fast  haftmann@30531  874 haftmann@30531  875 lemma singleton_conv [simp]: "{x. x = a} = {a}"  haftmann@30531  876  by blast  haftmann@30531  877 haftmann@30531  878 lemma singleton_conv2 [simp]: "{x. a = x} = {a}"  haftmann@30531  879  by blast  haftmann@30531  880 haftmann@30531  881 lemma diff_single_insert: "A - {x} \ B ==> x \ A ==> A \ insert x B"  haftmann@30531  882  by blast  haftmann@30531  883 haftmann@30531  884 lemma doubleton_eq_iff: "({a,b} = {c,d}) = (a=c & b=d | a=d & b=c)"  haftmann@30531  885  by (blast elim: equalityE)  haftmann@30531  886 wenzelm@11979  887 wenzelm@11979  888 subsubsection {* Unions of families *}  wenzelm@11979  889 wenzelm@11979  890 text {*  wenzelm@11979  891  @{term [source] "UN x:A. B x"} is @{term "Union (BA)"}.  wenzelm@11979  892 *}  wenzelm@11979  893 paulson@24286  894 declare UNION_def [noatp]  paulson@24286  895 wenzelm@11979  896 lemma UN_iff [simp]: "(b: (UN x:A. B x)) = (EX x:A. b: B x)"  wenzelm@11979  897  by (unfold UNION_def) blast  wenzelm@11979  898 wenzelm@11979  899 lemma UN_I [intro]: "a:A ==> b: B a ==> b: (UN x:A. B x)"  wenzelm@11979  900  -- {* The order of the premises presupposes that @{term A} is rigid;  wenzelm@11979  901  @{term b} may be flexible. *}  wenzelm@11979  902  by auto  wenzelm@11979  903 wenzelm@11979  904 lemma UN_E [elim!]: "b : (UN x:A. B x) ==> (!!x. x:A ==> b: B x ==> R) ==> R"  wenzelm@11979  905  by (unfold UNION_def) blast  clasohm@923  906 wenzelm@11979  907 lemma UN_cong [cong]:  wenzelm@11979  908  "A = B ==> (!!x. x:B ==> C x = D x) ==> (UN x:A. C x) = (UN x:B. D x)"  wenzelm@11979  909  by (simp add: UNION_def)  wenzelm@11979  910 berghofe@29691  911 lemma strong_UN_cong:  berghofe@29691  912  "A = B ==> (!!x. x:B =simp=> C x = D x) ==> (UN x:A. C x) = (UN x:B. D x)"  berghofe@29691  913  by (simp add: UNION_def simp_implies_def)  berghofe@29691  914 wenzelm@11979  915 wenzelm@11979  916 subsubsection {* Intersections of families *}  wenzelm@11979  917 wenzelm@11979  918 text {* @{term [source] "INT x:A. B x"} is @{term "Inter (BA)"}. *}  wenzelm@11979  919 wenzelm@11979  920 lemma INT_iff [simp]: "(b: (INT x:A. B x)) = (ALL x:A. b: B x)"  wenzelm@11979  921  by (unfold INTER_def) blast  clasohm@923  922 wenzelm@11979  923 lemma INT_I [intro!]: "(!!x. x:A ==> b: B x) ==> b : (INT x:A. B x)"  wenzelm@11979  924  by (unfold INTER_def) blast  wenzelm@11979  925 wenzelm@11979  926 lemma INT_D [elim]: "b : (INT x:A. B x) ==> a:A ==> b: B a"  wenzelm@11979  927  by auto  wenzelm@11979  928 wenzelm@11979  929 lemma INT_E [elim]: "b : (INT x:A. B x) ==> (b: B a ==> R) ==> (a~:A ==> R) ==> R"  wenzelm@11979  930  -- {* "Classical" elimination -- by the Excluded Middle on @{prop "a:A"}. *}  wenzelm@11979  931  by (unfold INTER_def) blast  wenzelm@11979  932 wenzelm@11979  933 lemma INT_cong [cong]:  wenzelm@11979  934  "A = B ==> (!!x. x:B ==> C x = D x) ==> (INT x:A. C x) = (INT x:B. D x)"  wenzelm@11979  935  by (simp add: INTER_def)  wenzelm@7238  936 clasohm@923  937 wenzelm@11979  938 subsubsection {* Union *}  wenzelm@11979  939 paulson@24286  940 lemma Union_iff [simp,noatp]: "(A : Union C) = (EX X:C. A:X)"  wenzelm@11979  941  by (unfold Union_def) blast  wenzelm@11979  942 wenzelm@11979  943 lemma UnionI [intro]: "X:C ==> A:X ==> A : Union C"  wenzelm@11979  944  -- {* The order of the premises presupposes that @{term C} is rigid;  wenzelm@11979  945  @{term A} may be flexible. *}  wenzelm@11979  946  by auto  wenzelm@11979  947 wenzelm@11979  948 lemma UnionE [elim!]: "A : Union C ==> (!!X. A:X ==> X:C ==> R) ==> R"  wenzelm@11979  949  by (unfold Union_def) blast  wenzelm@11979  950 wenzelm@11979  951 wenzelm@11979  952 subsubsection {* Inter *}  wenzelm@11979  953 paulson@24286  954 lemma Inter_iff [simp,noatp]: "(A : Inter C) = (ALL X:C. A:X)"  wenzelm@11979  955  by (unfold Inter_def) blast  wenzelm@11979  956 wenzelm@11979  957 lemma InterI [intro!]: "(!!X. X:C ==> A:X) ==> A : Inter C"  wenzelm@11979  958  by (simp add: Inter_def)  wenzelm@11979  959 wenzelm@11979  960 text {*  wenzelm@11979  961  \medskip A destruct'' rule -- every @{term X} in @{term C}  wenzelm@11979  962  contains @{term A} as an element, but @{prop "A:X"} can hold when  wenzelm@11979  963  @{prop "X:C"} does not! This rule is analogous to @{text spec}.  wenzelm@11979  964 *}  wenzelm@11979  965 wenzelm@11979  966 lemma InterD [elim]: "A : Inter C ==> X:C ==> A:X"  wenzelm@11979  967  by auto  wenzelm@11979  968 wenzelm@11979  969 lemma InterE [elim]: "A : Inter C ==> (X~:C ==> R) ==> (A:X ==> R) ==> R"  wenzelm@11979  970  -- {* Classical'' elimination rule -- does not require proving  wenzelm@11979  971  @{prop "X:C"}. *}  wenzelm@11979  972  by (unfold Inter_def) blast  wenzelm@11979  973 haftmann@30531  974 text {*  haftmann@30531  975  \medskip Image of a set under a function. Frequently @{term b} does  haftmann@30531  976  not have the syntactic form of @{term "f x"}.  haftmann@30531  977 *}  haftmann@30531  978 haftmann@30531  979 declare image_def [noatp]  haftmann@30531  980 haftmann@30531  981 lemma image_eqI [simp, intro]: "b = f x ==> x:A ==> b : fA"  haftmann@30531  982  by (unfold image_def) blast  haftmann@30531  983 haftmann@30531  984 lemma imageI: "x : A ==> f x : f  A"  haftmann@30531  985  by (rule image_eqI) (rule refl)  haftmann@30531  986 haftmann@30531  987 lemma rev_image_eqI: "x:A ==> b = f x ==> b : fA"  haftmann@30531  988  -- {* This version's more effective when we already have the  haftmann@30531  989  required @{term x}. *}  haftmann@30531  990  by (unfold image_def) blast  haftmann@30531  991 haftmann@30531  992 lemma imageE [elim!]:  haftmann@30531  993  "b : (%x. f x)A ==> (!!x. b = f x ==> x:A ==> P) ==> P"  haftmann@30531  994  -- {* The eta-expansion gives variable-name preservation. *}  haftmann@30531  995  by (unfold image_def) blast  haftmann@30531  996 haftmann@30531  997 lemma image_Un: "f(A Un B) = fA Un fB"  haftmann@30531  998  by blast  haftmann@30531  999 haftmann@30531  1000 lemma image_eq_UN: "fA = (UN x:A. {f x})"  haftmann@30531  1001  by blast  haftmann@30531  1002 haftmann@30531  1003 lemma image_iff: "(z : fA) = (EX x:A. z = f x)"  haftmann@30531  1004  by blast  haftmann@30531  1005 haftmann@30531  1006 lemma image_subset_iff: "(fA \ B) = (\x\A. f x \ B)"  haftmann@30531  1007  -- {* This rewrite rule would confuse users if made default. *}  haftmann@30531  1008  by blast  haftmann@30531  1009 haftmann@30531  1010 lemma subset_image_iff: "(B \ fA) = (EX AA. AA \ A & B = fAA)"  haftmann@30531  1011  apply safe  haftmann@30531  1012  prefer 2 apply fast  haftmann@30531  1013  apply (rule_tac x = "{a. a : A & f a : B}" in exI, fast)  haftmann@30531  1014  done  haftmann@30531  1015 haftmann@30531  1016 lemma image_subsetI: "(!!x. x \ A ==> f x \ B) ==> fA \ B"  haftmann@30531  1017  -- {* Replaces the three steps @{text subsetI}, @{text imageE},  haftmann@30531  1018  @{text hypsubst}, but breaks too many existing proofs. *}  haftmann@30531  1019  by blast  haftmann@30531  1020 haftmann@30531  1021 text {*  haftmann@30531  1022  \medskip Range of a function -- just a translation for image!  haftmann@30531  1023 *}  haftmann@30531  1024 haftmann@30531  1025 lemma range_eqI: "b = f x ==> b \ range f"  haftmann@30531  1026  by simp  haftmann@30531  1027 haftmann@30531  1028 lemma rangeI: "f x \ range f"  haftmann@30531  1029  by simp  haftmann@30531  1030 haftmann@30531  1031 lemma rangeE [elim?]: "b \ range (\x. f x) ==> (!!x. b = f x ==> P) ==> P"  haftmann@30531  1032  by blast  haftmann@30531  1033 haftmann@30531  1034 haftmann@30531  1035 subsubsection {* Set reasoning tools *}  haftmann@30531  1036 nipkow@31166  1037 text{* Elimination of @{text"{x. \ & x=t & \}"}. *}  nipkow@31166  1038 nipkow@31166  1039 lemma singleton_conj_conv[simp]: "{x. x=a & P x} = (if P a then {a} else {})"  nipkow@31166  1040 by auto  nipkow@31166  1041 nipkow@31166  1042 lemma singleton_conj_conv2[simp]: "{x. a=x & P x} = (if P a then {a} else {})"  nipkow@31166  1043 by auto  nipkow@31166  1044 nipkow@31166  1045 ML{*  nipkow@31166  1046  local  nipkow@31166  1047  val Coll_perm_tac = rtac @{thm Collect_cong} 1 THEN rtac @{thm iffI} 1 THEN  nipkow@31166  1048  ALLGOALS(EVERY'[REPEAT_DETERM o (etac @{thm conjE}),  nipkow@31166  1049  DEPTH_SOLVE_1 o (ares_tac [@{thm conjI}])])  nipkow@31166  1050  in  nipkow@31166  1051  val defColl_regroup = Simplifier.simproc (the_context ())  nipkow@31166  1052  "defined Collect" ["{x. P x & Q x}"]  nipkow@31166  1053  (Quantifier1.rearrange_Coll Coll_perm_tac)  nipkow@31166  1054  end;  nipkow@31166  1055 nipkow@31166  1056  Addsimprocs [defColl_regroup];  nipkow@31166  1057 nipkow@31166  1058 *}  nipkow@31166  1059 haftmann@30531  1060 text {*  haftmann@30531  1061  Rewrite rules for boolean case-splitting: faster than @{text  haftmann@30531  1062  "split_if [split]"}.  haftmann@30531  1063 *}  haftmann@30531  1064 haftmann@30531  1065 lemma split_if_eq1: "((if Q then x else y) = b) = ((Q --> x = b) & (~ Q --> y = b))"  haftmann@30531  1066  by (rule split_if)  haftmann@30531  1067 haftmann@30531  1068 lemma split_if_eq2: "(a = (if Q then x else y)) = ((Q --> a = x) & (~ Q --> a = y))"  haftmann@30531  1069  by (rule split_if)  haftmann@30531  1070 haftmann@30531  1071 text {*  haftmann@30531  1072  Split ifs on either side of the membership relation. Not for @{text  haftmann@30531  1073  "[simp]"} -- can cause goals to blow up!  haftmann@30531  1074 *}  haftmann@30531  1075 haftmann@30531  1076 lemma split_if_mem1: "((if Q then x else y) : b) = ((Q --> x : b) & (~ Q --> y : b))"  haftmann@30531  1077  by (rule split_if)  haftmann@30531  1078 haftmann@30531  1079 lemma split_if_mem2: "(a : (if Q then x else y)) = ((Q --> a : x) & (~ Q --> a : y))"  haftmann@30531  1080  by (rule split_if [where P="%S. a : S"])  haftmann@30531  1081 haftmann@30531  1082 lemmas split_ifs = if_bool_eq_conj split_if_eq1 split_if_eq2 split_if_mem1 split_if_mem2  haftmann@30531  1083 haftmann@30531  1084 (*Would like to add these, but the existing code only searches for the  haftmann@30531  1085  outer-level constant, which in this case is just "op :"; we instead need  haftmann@30531  1086  to use term-nets to associate patterns with rules. Also, if a rule fails to  haftmann@30531  1087  apply, then the formula should be kept.  haftmann@30531  1088  [("HOL.uminus", Compl_iff RS iffD1), ("HOL.minus", [Diff_iff RS iffD1]),  haftmann@30531  1089  ("Int", [IntD1,IntD2]),  haftmann@30531  1090  ("Collect", [CollectD]), ("Inter", [InterD]), ("INTER", [INT_D])]  haftmann@30531  1091  *)  haftmann@30531  1092 haftmann@30531  1093 ML {*  haftmann@30531  1094  val mksimps_pairs = [(@{const_name Ball}, @{thms bspec})] @ mksimps_pairs;  haftmann@30531  1095 *}  haftmann@30531  1096 declaration {* fn _ =>  haftmann@30531  1097  Simplifier.map_ss (fn ss => ss setmksimps (mksimps mksimps_pairs))  haftmann@30531  1098 *}  haftmann@30531  1099 haftmann@30531  1100 haftmann@30531  1101 subsubsection {* The proper subset'' relation *}  haftmann@30531  1102 haftmann@30531  1103 lemma psubsetI [intro!,noatp]: "A \ B ==> A \ B ==> A \ B"  haftmann@30531  1104  by (unfold less_le) blast  haftmann@30531  1105 haftmann@30531  1106 lemma psubsetE [elim!,noatp]:  haftmann@30531  1107  "[|A \ B; [|A \ B; ~ (B\A)|] ==> R|] ==> R"  haftmann@30531  1108  by (unfold less_le) blast  haftmann@30531  1109 haftmann@30531  1110 lemma psubset_insert_iff:  haftmann@30531  1111  "(A \ insert x B) = (if x \ B then A \ B else if x \ A then A - {x} \ B else A \ B)"  haftmann@30531  1112  by (auto simp add: less_le subset_insert_iff)  haftmann@30531  1113 haftmann@30531  1114 lemma psubset_eq: "(A \ B) = (A \ B & A \ B)"  haftmann@30531  1115  by (simp only: less_le)  haftmann@30531  1116 haftmann@30531  1117 lemma psubset_imp_subset: "A \ B ==> A \ B"  haftmann@30531  1118  by (simp add: psubset_eq)  haftmann@30531  1119 haftmann@30531  1120 lemma psubset_trans: "[| A \ B; B \ C |] ==> A \ C"  haftmann@30531  1121 apply (unfold less_le)  haftmann@30531  1122 apply (auto dest: subset_antisym)  haftmann@30531  1123 done  haftmann@30531  1124 haftmann@30531  1125 lemma psubsetD: "[| A \ B; c \ A |] ==> c \ B"  haftmann@30531  1126 apply (unfold less_le)  haftmann@30531  1127 apply (auto dest: subsetD)  haftmann@30531  1128 done  haftmann@30531  1129 haftmann@30531  1130 lemma psubset_subset_trans: "A \ B ==> B \ C ==> A \ C"  haftmann@30531  1131  by (auto simp add: psubset_eq)  haftmann@30531  1132 haftmann@30531  1133 lemma subset_psubset_trans: "A \ B ==> B \ C ==> A \ C"  haftmann@30531  1134  by (auto simp add: psubset_eq)  haftmann@30531  1135 haftmann@30531  1136 lemma psubset_imp_ex_mem: "A \ B ==> \b. b \ (B - A)"  haftmann@30531  1137  by (unfold less_le) blast  haftmann@30531  1138 haftmann@30531  1139 lemma atomize_ball:  haftmann@30531  1140  "(!!x. x \ A ==> P x) == Trueprop (\x\A. P x)"  haftmann@30531  1141  by (simp only: Ball_def atomize_all atomize_imp)  haftmann@30531  1142 haftmann@30531  1143 lemmas [symmetric, rulify] = atomize_ball  haftmann@30531  1144  and [symmetric, defn] = atomize_ball  haftmann@30531  1145 haftmann@30531  1146 haftmann@30531  1147 subsection {* Further set-theory lemmas *}  haftmann@30531  1148 haftmann@30531  1149 subsubsection {* Derived rules involving subsets. *}  haftmann@30531  1150 haftmann@30531  1151 text {* @{text insert}. *}  haftmann@30531  1152 haftmann@30531  1153 lemma subset_insertI: "B \ insert a B"  haftmann@30531  1154  by (rule subsetI) (erule insertI2)  haftmann@30531  1155 haftmann@30531  1156 lemma subset_insertI2: "A \ B \ A \ insert b B"  haftmann@30531  1157  by blast  haftmann@30531  1158 haftmann@30531  1159 lemma subset_insert: "x \ A ==> (A \ insert x B) = (A \ B)"  haftmann@30531  1160  by blast  wenzelm@12897  1161 wenzelm@12897  1162 wenzelm@12897  1163 text {* \medskip Big Union -- least upper bound of a set. *}  wenzelm@12897  1164 wenzelm@12897  1165 lemma Union_upper: "B \ A ==> B \ Union A"  nipkow@17589  1166  by (iprover intro: subsetI UnionI)  wenzelm@12897  1167 wenzelm@12897  1168 lemma Union_least: "(!!X. X \ A ==> X \ C) ==> Union A \ C"  nipkow@17589  1169  by (iprover intro: subsetI elim: UnionE dest: subsetD)  wenzelm@12897  1170 wenzelm@12897  1171 wenzelm@12897  1172 text {* \medskip General union. *}  wenzelm@12897  1173 wenzelm@12897  1174 lemma UN_upper: "a \ A ==> B a \ (\x\A. B x)"  wenzelm@12897  1175  by blast  wenzelm@12897  1176 wenzelm@12897  1177 lemma UN_least: "(!!x. x \ A ==> B x \ C) ==> (\x\A. B x) \ C"  nipkow@17589  1178  by (iprover intro: subsetI elim: UN_E dest: subsetD)  wenzelm@12897  1179 wenzelm@12897  1180 wenzelm@12897  1181 text {* \medskip Big Intersection -- greatest lower bound of a set. *}  wenzelm@12897  1182 wenzelm@12897  1183 lemma Inter_lower: "B \ A ==> Inter A \ B"  wenzelm@12897  1184  by blast  wenzelm@12897  1185 ballarin@14551  1186 lemma Inter_subset:  ballarin@14551  1187  "[| !!X. X \ A ==> X \ B; A ~= {} |] ==> \A \ B"  ballarin@14551  1188  by blast  ballarin@14551  1189 wenzelm@12897  1190 lemma Inter_greatest: "(!!X. X \ A ==> C \ X) ==> C \ Inter A"  nipkow@17589  1191  by (iprover intro: InterI subsetI dest: subsetD)  wenzelm@12897  1192 wenzelm@12897  1193 lemma INT_lower: "a \ A ==> (\x\A. B x) \ B a"  wenzelm@12897  1194  by blast  wenzelm@12897  1195 wenzelm@12897  1196 lemma INT_greatest: "(!!x. x \ A ==> C \ B x) ==> C \ (\x\A. B x)"  nipkow@17589  1197  by (iprover intro: INT_I subsetI dest: subsetD)  wenzelm@12897  1198 haftmann@30531  1199 haftmann@30531  1200 text {* \medskip Finite Union -- the least upper bound of two sets. *}  haftmann@30531  1201 haftmann@30531  1202 lemma Un_upper1: "A \ A \ B"  haftmann@30531  1203  by blast  haftmann@30531  1204 haftmann@30531  1205 lemma Un_upper2: "B \ A \ B"  haftmann@30531  1206  by blast  haftmann@30531  1207 haftmann@30531  1208 lemma Un_least: "A \ C ==> B \ C ==> A \ B \ C"  haftmann@30531  1209  by blast  haftmann@30531  1210 haftmann@30531  1211 haftmann@30531  1212 text {* \medskip Finite Intersection -- the greatest lower bound of two sets. *}  haftmann@30531  1213 haftmann@30531  1214 lemma Int_lower1: "A \ B \ A"  haftmann@30531  1215  by blast  haftmann@30531  1216 haftmann@30531  1217 lemma Int_lower2: "A \ B \ B"  haftmann@30531  1218  by blast  haftmann@30531  1219 haftmann@30531  1220 lemma Int_greatest: "C \ A ==> C \ B ==> C \ A \ B"  haftmann@30531  1221  by blast  haftmann@30531  1222 haftmann@30531  1223 haftmann@30531  1224 text {* \medskip Set difference. *}  haftmann@30531  1225 haftmann@30531  1226 lemma Diff_subset: "A - B \ A"  haftmann@30531  1227  by blast  haftmann@30531  1228 haftmann@30531  1229 lemma Diff_subset_conv: "(A - B \ C) = (A \ B \ C)"  haftmann@30531  1230 by blast  haftmann@30531  1231 haftmann@30531  1232 haftmann@30531  1233 subsubsection {* Equalities involving union, intersection, inclusion, etc. *}  haftmann@30531  1234 haftmann@30531  1235 text {* @{text "{}"}. *}  haftmann@30531  1236 haftmann@30531  1237 lemma Collect_const [simp]: "{s. P} = (if P then UNIV else {})"  haftmann@30531  1238  -- {* supersedes @{text "Collect_False_empty"} *}  haftmann@30531  1239  by auto  haftmann@30531  1240 haftmann@30531  1241 lemma subset_empty [simp]: "(A \ {}) = (A = {})"  haftmann@30531  1242  by blast  haftmann@30531  1243 haftmann@30531  1244 lemma not_psubset_empty [iff]: "\ (A < {})"  haftmann@30531  1245  by (unfold less_le) blast  haftmann@30531  1246 haftmann@30531  1247 lemma Collect_empty_eq [simp]: "(Collect P = {}) = (\x. \ P x)"  haftmann@30531  1248 by blast  haftmann@30531  1249 haftmann@30531  1250 lemma empty_Collect_eq [simp]: "({} = Collect P) = (\x. \ P x)"  haftmann@30531  1251 by blast  haftmann@30531  1252 haftmann@30531  1253 lemma Collect_neg_eq: "{x. \ P x} = - {x. P x}"  haftmann@30531  1254  by blast  haftmann@30531  1255 haftmann@30531  1256 lemma Collect_disj_eq: "{x. P x | Q x} = {x. P x} \ {x. Q x}"  haftmann@30531  1257  by blast  haftmann@30531  1258 haftmann@30531  1259 lemma Collect_imp_eq: "{x. P x --> Q x} = -{x. P x} \ {x. Q x}"  haftmann@30531  1260  by blast  haftmann@30531  1261 haftmann@30531  1262 lemma Collect_conj_eq: "{x. P x & Q x} = {x. P x} \ {x. Q x}"  wenzelm@12897  1263  by blast  wenzelm@12897  1264 wenzelm@12897  1265 lemma Collect_all_eq: "{x. \y. P x y} = (\y. {x. P x y})"  wenzelm@12897  1266  by blast  wenzelm@12897  1267 wenzelm@12897  1268 lemma Collect_ball_eq: "{x. \y\A. P x y} = (\y\A. {x. P x y})"  wenzelm@12897  1269  by blast  wenzelm@12897  1270 paulson@24286  1271 lemma Collect_ex_eq [noatp]: "{x. \y. P x y} = (\y. {x. P x y})"  wenzelm@12897  1272  by blast  wenzelm@12897  1273 paulson@24286  1274 lemma Collect_bex_eq [noatp]: "{x. \y\A. P x y} = (\y\A. {x. P x y})"  wenzelm@12897  1275  by blast  wenzelm@12897  1276 wenzelm@12897  1277 haftmann@30531  1278 text {* \medskip @{text insert}. *}  haftmann@30531  1279 haftmann@30531  1280 lemma insert_is_Un: "insert a A = {a} Un A"  haftmann@30531  1281  -- {* NOT SUITABLE FOR REWRITING since @{text "{a} == insert a {}"} *}  haftmann@30531  1282  by blast  haftmann@30531  1283 haftmann@30531  1284 lemma insert_not_empty [simp]: "insert a A \ {}"  haftmann@30531  1285  by blast  haftmann@30531  1286 haftmann@30531  1287 lemmas empty_not_insert = insert_not_empty [symmetric, standard]  haftmann@30531  1288 declare empty_not_insert [simp]  haftmann@30531  1289 haftmann@30531  1290 lemma insert_absorb: "a \ A ==> insert a A = A"  haftmann@30531  1291  -- {* @{text "[simp]"} causes recursive calls when there are nested inserts *}  haftmann@30531  1292  -- {* with \emph{quadratic} running time *}  haftmann@30531  1293  by blast  haftmann@30531  1294 haftmann@30531  1295 lemma insert_absorb2 [simp]: "insert x (insert x A) = insert x A"  haftmann@30531  1296  by blast  haftmann@30531  1297 haftmann@30531  1298 lemma insert_commute: "insert x (insert y A) = insert y (insert x A)"  haftmann@30531  1299  by blast  haftmann@30531  1300 haftmann@30531  1301 lemma insert_subset [simp]: "(insert x A \ B) = (x \ B & A \ B)"  haftmann@30531  1302  by blast  haftmann@30531  1303 haftmann@30531  1304 lemma mk_disjoint_insert: "a \ A ==> \B. A = insert a B & a \ B"  haftmann@30531  1305  -- {* use new @{text B} rather than @{text "A - {a}"} to avoid infinite unfolding *}  haftmann@30531  1306  apply (rule_tac x = "A - {a}" in exI, blast)  haftmann@30531  1307  done  haftmann@30531  1308 haftmann@30531  1309 lemma insert_Collect: "insert a (Collect P) = {u. u \ a --> P u}"  haftmann@30531  1310  by auto  haftmann@30531  1311 haftmann@30531  1312 lemma UN_insert_distrib: "u \ A ==> (\x\A. insert a (B x)) = insert a (\x\A. B x)"  haftmann@30531  1313  by blast  haftmann@30531  1314 haftmann@30531  1315 lemma insert_inter_insert[simp]: "insert a A \ insert a B = insert a (A \ B)"  mehta@14742  1316  by blast  nipkow@14302  1317 haftmann@30531  1318 lemma insert_disjoint [simp,noatp]:  haftmann@30531  1319  "(insert a A \ B = {}) = (a \ B \ A \ B = {})"  haftmann@30531  1320  "({} = insert a A \ B) = (a \ B \ {} = A \ B)"  haftmann@30531  1321  by auto  haftmann@30531  1322 haftmann@30531  1323 lemma disjoint_insert [simp,noatp]:  haftmann@30531  1324  "(B \ insert a A = {}) = (a \ B \ B \ A = {})"  haftmann@30531  1325  "({} = A \ insert b B) = (b \ A \ {} = A \ B)"  haftmann@30531  1326  by auto  haftmann@30531  1327 haftmann@30531  1328 text {* \medskip @{text image}. *}  haftmann@30531  1329 haftmann@30531  1330 lemma image_empty [simp]: "f{} = {}"  haftmann@30531  1331  by blast  haftmann@30531  1332 haftmann@30531  1333 lemma image_insert [simp]: "f  insert a B = insert (f a) (fB)"  haftmann@30531  1334  by blast  haftmann@30531  1335 haftmann@30531  1336 lemma image_constant: "x \ A ==> (\x. c)  A = {c}"  haftmann@30531  1337  by auto  haftmann@30531  1338 haftmann@30531  1339 lemma image_constant_conv: "(%x. c)  A = (if A = {} then {} else {c})"  haftmann@30531  1340 by auto  haftmann@30531  1341 haftmann@30531  1342 lemma image_image: "f  (g  A) = (\x. f (g x))  A"  haftmann@30531  1343  by blast  haftmann@30531  1344 haftmann@30531  1345 lemma insert_image [simp]: "x \ A ==> insert (f x) (fA) = fA"  haftmann@30531  1346  by blast  haftmann@30531  1347 haftmann@30531  1348 lemma image_is_empty [iff]: "(fA = {}) = (A = {})"  haftmann@30531  1349  by blast  haftmann@30531  1350 haftmann@30531  1351 haftmann@30531  1352 lemma image_Collect [noatp]: "f  {x. P x} = {f x | x. P x}"  haftmann@30531  1353  -- {* NOT suitable as a default simprule: the RHS isn't simpler than the LHS,  haftmann@30531  1354  with its implicit quantifier and conjunction. Also image enjoys better  haftmann@30531  1355  equational properties than does the RHS. *}  haftmann@30531  1356  by blast  haftmann@30531  1357 haftmann@30531  1358 lemma if_image_distrib [simp]:  haftmann@30531  1359  "(\x. if P x then f x else g x)  S  haftmann@30531  1360  = (f  (S \ {x. P x})) \ (g  (S \ {x. \ P x}))"  haftmann@30531  1361  by (auto simp add: image_def)  haftmann@30531  1362 haftmann@30531  1363 lemma image_cong: "M = N ==> (!!x. x \ N ==> f x = g x) ==> fM = gN"  haftmann@30531  1364  by (simp add: image_def)  haftmann@30531  1365 haftmann@30531  1366 haftmann@30531  1367 text {* \medskip @{text range}. *}  haftmann@30531  1368 paulson@24286  1369 lemma full_SetCompr_eq [noatp]: "{u. \x. u = f x} = range f"  wenzelm@12897  1370  by auto  wenzelm@12897  1371 huffman@27418  1372 lemma range_composition: "range (\x. f (g x)) = frange g"  paulson@14208  1373 by (subst image_image, simp)  wenzelm@12897  1374 wenzelm@12897  1375 wenzelm@12897  1376 text {* \medskip @{text Int} *}  wenzelm@12897  1377 wenzelm@12897  1378 lemma Int_absorb [simp]: "A \ A = A"  wenzelm@12897  1379  by blast  wenzelm@12897  1380 wenzelm@12897  1381 lemma Int_left_absorb: "A \ (A \ B) = A \ B"  wenzelm@12897  1382  by blast  wenzelm@12897  1383 wenzelm@12897  1384 lemma Int_commute: "A \ B = B \ A"  wenzelm@12897  1385  by blast  wenzelm@12897  1386 wenzelm@12897  1387 lemma Int_left_commute: "A \ (B \ C) = B \ (A \ C)"  wenzelm@12897  1388  by blast  wenzelm@12897  1389 wenzelm@12897  1390 lemma Int_assoc: "(A \ B) \ C = A \ (B \ C)"  wenzelm@12897  1391  by blast  wenzelm@12897  1392 wenzelm@12897  1393 lemmas Int_ac = Int_assoc Int_left_absorb Int_commute Int_left_commute  wenzelm@12897  1394  -- {* Intersection is an AC-operator *}  wenzelm@12897  1395 wenzelm@12897  1396 lemma Int_absorb1: "B \ A ==> A \ B = B"  wenzelm@12897  1397  by blast  wenzelm@12897  1398 wenzelm@12897  1399 lemma Int_absorb2: "A \ B ==> A \ B = A"  wenzelm@12897  1400  by blast  wenzelm@12897  1401 wenzelm@12897  1402 lemma Int_empty_left [simp]: "{} \ B = {}"  wenzelm@12897  1403  by blast  wenzelm@12897  1404 wenzelm@12897  1405 lemma Int_empty_right [simp]: "A \ {} = {}"  wenzelm@12897  1406  by blast  wenzelm@12897  1407 wenzelm@12897  1408 lemma disjoint_eq_subset_Compl: "(A \ B = {}) = (A \ -B)"  wenzelm@12897  1409  by blast  wenzelm@12897  1410 wenzelm@12897  1411 lemma disjoint_iff_not_equal: "(A \ B = {}) = (\x\A. \y\B. x \ y)"  wenzelm@12897  1412  by blast  wenzelm@12897  1413 wenzelm@12897  1414 lemma Int_UNIV_left [simp]: "UNIV \ B = B"  wenzelm@12897  1415  by blast  wenzelm@12897  1416 wenzelm@12897  1417 lemma Int_UNIV_right [simp]: "A \ UNIV = A"  wenzelm@12897  1418  by blast  wenzelm@12897  1419 wenzelm@12897  1420 lemma Int_eq_Inter: "A \ B = \{A, B}"  wenzelm@12897  1421  by blast  wenzelm@12897  1422 wenzelm@12897  1423 lemma Int_Un_distrib: "A \ (B \ C) = (A \ B) \ (A \ C)"  wenzelm@12897  1424  by blast  wenzelm@12897  1425 wenzelm@12897  1426 lemma Int_Un_distrib2: "(B \ C) \ A = (B \ A) \ (C \ A)"  wenzelm@12897  1427  by blast  wenzelm@12897  1428 paulson@24286  1429 lemma Int_UNIV [simp,noatp]: "(A \ B = UNIV) = (A = UNIV & B = UNIV)"  wenzelm@12897  1430  by blast  wenzelm@12897  1431 paulson@15102  1432 lemma Int_subset_iff [simp]: "(C \ A \ B) = (C \ A & C \ B)"  wenzelm@12897  1433  by blast  wenzelm@12897  1434 wenzelm@12897  1435 lemma Int_Collect: "(x \ A \ {x. P x}) = (x \ A & P x)"  wenzelm@12897  1436  by blast  wenzelm@12897  1437 wenzelm@12897  1438 wenzelm@12897  1439 text {* \medskip @{text Un}. *}  wenzelm@12897  1440 wenzelm@12897  1441 lemma Un_absorb [simp]: "A \ A = A"  wenzelm@12897  1442  by blast  wenzelm@12897  1443 wenzelm@12897  1444 lemma Un_left_absorb: "A \ (A \ B) = A \ B"  wenzelm@12897  1445  by blast  wenzelm@12897  1446 wenzelm@12897  1447 lemma Un_commute: "A \ B = B \ A"  wenzelm@12897  1448  by blast  wenzelm@12897  1449 wenzelm@12897  1450 lemma Un_left_commute: "A \ (B \ C) = B \ (A \ C)"  wenzelm@12897  1451  by blast  wenzelm@12897  1452 wenzelm@12897  1453 lemma Un_assoc: "(A \ B) \ C = A \ (B \ C)"  wenzelm@12897  1454  by blast  wenzelm@12897  1455 wenzelm@12897  1456 lemmas Un_ac = Un_assoc Un_left_absorb Un_commute Un_left_commute  wenzelm@12897  1457  -- {* Union is an AC-operator *}  wenzelm@12897  1458 wenzelm@12897  1459 lemma Un_absorb1: "A \ B ==> A \ B = B"  wenzelm@12897  1460  by blast  wenzelm@12897  1461 wenzelm@12897  1462 lemma Un_absorb2: "B \ A ==> A \ B = A"  wenzelm@12897  1463  by blast  wenzelm@12897  1464 wenzelm@12897  1465 lemma Un_empty_left [simp]: "{} \ B = B"  wenzelm@12897  1466  by blast  wenzelm@12897  1467 wenzelm@12897  1468 lemma Un_empty_right [simp]: "A \ {} = A"  wenzelm@12897  1469  by blast  wenzelm@12897  1470 wenzelm@12897  1471 lemma Un_UNIV_left [simp]: "UNIV \ B = UNIV"  wenzelm@12897  1472  by blast  wenzelm@12897  1473 wenzelm@12897  1474 lemma Un_UNIV_right [simp]: "A \ UNIV = UNIV"  wenzelm@12897  1475  by blast  wenzelm@12897  1476 wenzelm@12897  1477 lemma Un_eq_Union: "A \ B = \{A, B}"  wenzelm@12897  1478  by blast  wenzelm@12897  1479 wenzelm@12897  1480 lemma Un_insert_left [simp]: "(insert a B) \ C = insert a (B \ C)"  wenzelm@12897  1481  by blast  wenzelm@12897  1482 wenzelm@12897  1483 lemma Un_insert_right [simp]: "A \ (insert a B) = insert a (A \ B)"  wenzelm@12897  1484  by blast  wenzelm@12897  1485 wenzelm@12897  1486 lemma Int_insert_left:  wenzelm@12897  1487  "(insert a B) Int C = (if a \ C then insert a (B \ C) else B \ C)"  wenzelm@12897  1488  by auto  wenzelm@12897  1489 wenzelm@12897  1490 lemma Int_insert_right:  wenzelm@12897  1491  "A \ (insert a B) = (if a \ A then insert a (A \ B) else A \ B)"  wenzelm@12897  1492  by auto  wenzelm@12897  1493 wenzelm@12897  1494 lemma Un_Int_distrib: "A \ (B \ C) = (A \ B) \ (A \ C)"  wenzelm@12897  1495  by blast  wenzelm@12897  1496 wenzelm@12897  1497 lemma Un_Int_distrib2: "(B \ C) \ A = (B \ A) \ (C \ A)"  wenzelm@12897  1498  by blast  wenzelm@12897  1499 wenzelm@12897  1500 lemma Un_Int_crazy:  wenzelm@12897  1501  "(A \ B) \ (B \ C) \ (C \ A) = (A \ B) \ (B \ C) \ (C \ A)"  wenzelm@12897  1502  by blast  wenzelm@12897  1503 wenzelm@12897  1504 lemma subset_Un_eq: "(A \ B) = (A \ B = B)"  wenzelm@12897  1505  by blast  wenzelm@12897  1506 wenzelm@12897  1507 lemma Un_empty [iff]: "(A \ B = {}) = (A = {} & B = {})"  wenzelm@12897  1508  by blast  paulson@15102  1509 paulson@15102  1510 lemma Un_subset_iff [simp]: "(A \ B \ C) = (A \ C & B \ C)"  wenzelm@12897  1511  by blast  wenzelm@12897  1512 wenzelm@12897  1513 lemma Un_Diff_Int: "(A - B) \ (A \ B) = A"  wenzelm@12897  1514  by blast  wenzelm@12897  1515 paulson@22172  1516 lemma Diff_Int2: "A \ C - B \ C = A \ C - B"  paulson@22172  1517  by blast  paulson@22172  1518 wenzelm@12897  1519 wenzelm@12897  1520 text {* \medskip Set complement *}  wenzelm@12897  1521 wenzelm@12897  1522 lemma Compl_disjoint [simp]: "A \ -A = {}"  wenzelm@12897  1523  by blast  wenzelm@12897  1524 wenzelm@12897  1525 lemma Compl_disjoint2 [simp]: "-A \ A = {}"  wenzelm@12897  1526  by blast  wenzelm@12897  1527 paulson@13818  1528 lemma Compl_partition: "A \ -A = UNIV"  paulson@13818  1529  by blast  paulson@13818  1530 paulson@13818  1531 lemma Compl_partition2: "-A \ A = UNIV"  wenzelm@12897  1532  by blast  wenzelm@12897  1533 wenzelm@12897  1534 lemma double_complement [simp]: "- (-A) = (A::'a set)"  wenzelm@12897  1535  by blast  wenzelm@12897  1536 wenzelm@12897  1537 lemma Compl_Un [simp]: "-(A \ B) = (-A) \ (-B)"  wenzelm@12897  1538  by blast  wenzelm@12897  1539 wenzelm@12897  1540 lemma Compl_Int [simp]: "-(A \ B) = (-A) \ (-B)"  wenzelm@12897  1541  by blast  wenzelm@12897  1542 wenzelm@12897  1543 lemma Compl_UN [simp]: "-(\x\A. B x) = (\x\A. -B x)"  wenzelm@12897  1544  by blast  wenzelm@12897  1545 wenzelm@12897  1546 lemma Compl_INT [simp]: "-(\x\A. B x) = (\x\A. -B x)"  wenzelm@12897  1547  by blast  wenzelm@12897  1548 wenzelm@12897  1549 lemma subset_Compl_self_eq: "(A \ -A) = (A = {})"  wenzelm@12897  1550  by blast  wenzelm@12897  1551 wenzelm@12897  1552 lemma Un_Int_assoc_eq: "((A \ B) \ C = A \ (B \ C)) = (C \ A)"  wenzelm@12897  1553  -- {* Halmos, Naive Set Theory, page 16. *}  wenzelm@12897  1554  by blast  wenzelm@12897  1555 wenzelm@12897  1556 lemma Compl_UNIV_eq [simp]: "-UNIV = {}"  wenzelm@12897  1557  by blast  wenzelm@12897  1558 wenzelm@12897  1559 lemma Compl_empty_eq [simp]: "-{} = UNIV"  wenzelm@12897  1560  by blast  wenzelm@12897  1561 wenzelm@12897  1562 lemma Compl_subset_Compl_iff [iff]: "(-A \ -B) = (B \ A)"  wenzelm@12897  1563  by blast  wenzelm@12897  1564 wenzelm@12897  1565 lemma Compl_eq_Compl_iff [iff]: "(-A = -B) = (A = (B::'a set))"  wenzelm@12897  1566  by blast  wenzelm@12897  1567 wenzelm@12897  1568 wenzelm@12897  1569 text {* \medskip @{text Union}. *}  wenzelm@12897  1570 wenzelm@12897  1571 lemma Union_empty [simp]: "Union({}) = {}"  wenzelm@12897  1572  by blast  wenzelm@12897  1573 wenzelm@12897  1574 lemma Union_UNIV [simp]: "Union UNIV = UNIV"  wenzelm@12897  1575  by blast  wenzelm@12897  1576 wenzelm@12897  1577 lemma Union_insert [simp]: "Union (insert a B) = a \ \B"  wenzelm@12897  1578  by blast  wenzelm@12897  1579 wenzelm@12897  1580 lemma Union_Un_distrib [simp]: "\(A Un B) = \A \ \B"  wenzelm@12897  1581  by blast  wenzelm@12897  1582 wenzelm@12897  1583 lemma Union_Int_subset: "\(A \ B) \ \A \ \B"  wenzelm@12897  1584  by blast  wenzelm@12897  1585 paulson@24286  1586 lemma Union_empty_conv [simp,noatp]: "(\A = {}) = (\x\A. x = {})"  nipkow@13653  1587  by blast  nipkow@13653  1588 paulson@24286  1589 lemma empty_Union_conv [simp,noatp]: "({} = \A) = (\x\A. x = {})"  nipkow@13653  1590  by blast  wenzelm@12897  1591 wenzelm@12897  1592 lemma Union_disjoint: "(\C \ A = {}) = (\B\C. B \ A = {})"  wenzelm@12897  1593  by blast  wenzelm@12897  1594 wenzelm@12897  1595 wenzelm@12897  1596 text {* \medskip @{text Inter}. *}  wenzelm@12897  1597 wenzelm@12897  1598 lemma Inter_empty [simp]: "\{} = UNIV"  wenzelm@12897  1599  by blast  wenzelm@12897  1600 wenzelm@12897  1601 lemma Inter_UNIV [simp]: "\UNIV = {}"  wenzelm@12897  1602  by blast  wenzelm@12897  1603 wenzelm@12897  1604 lemma Inter_insert [simp]: "\(insert a B) = a \ \B"  wenzelm@12897  1605  by blast  wenzelm@12897  1606 wenzelm@12897  1607 lemma Inter_Un_subset: "\A \ \B \ \(A \ B)"  wenzelm@12897  1608  by blast  wenzelm@12897  1609 wenzelm@12897  1610 lemma Inter_Un_distrib: "\(A \ B) = \A \ \B"  wenzelm@12897  1611  by blast  wenzelm@12897  1612 paulson@24286  1613 lemma Inter_UNIV_conv [simp,noatp]:  nipkow@13653  1614  "(\A = UNIV) = (\x\A. x = UNIV)"  nipkow@13653  1615  "(UNIV = \A) = (\x\A. x = UNIV)"  paulson@14208  1616  by blast+  nipkow@13653  1617 wenzelm@12897  1618 wenzelm@12897  1619 text {*  wenzelm@12897  1620  \medskip @{text UN} and @{text INT}.  wenzelm@12897  1621 wenzelm@12897  1622  Basic identities: *}  wenzelm@12897  1623 paulson@24286  1624 lemma UN_empty [simp,noatp]: "(\x\{}. B x) = {}"  wenzelm@12897  1625  by blast  wenzelm@12897  1626 wenzelm@12897  1627 lemma UN_empty2 [simp]: "(\x\A. {}) = {}"  wenzelm@12897  1628  by blast  wenzelm@12897  1629 wenzelm@12897  1630 lemma UN_singleton [simp]: "(\x\A. {x}) = A"  wenzelm@12897  1631  by blast  wenzelm@12897  1632 wenzelm@12897  1633 lemma UN_absorb: "k \ I ==> A k \ (\i\I. A i) = (\i\I. A i)"  paulson@15102  1634  by auto  wenzelm@12897  1635 wenzelm@12897  1636 lemma INT_empty [simp]: "(\x\{}. B x) = UNIV"  wenzelm@12897  1637  by blast  wenzelm@12897  1638 wenzelm@12897  1639 lemma INT_absorb: "k \ I ==> A k \ (\i\I. A i) = (\i\I. A i)"  wenzelm@12897  1640  by blast  wenzelm@12897  1641 wenzelm@12897  1642 lemma UN_insert [simp]: "(\x\insert a A. B x) = B a \ UNION A B"  wenzelm@12897  1643  by blast  wenzelm@12897  1644 nipkow@24331  1645 lemma UN_Un[simp]: "(\i \ A \ B. M i) = (\i\A. M i) \ (\i\B. M i)"  wenzelm@12897  1646  by blast  wenzelm@12897  1647 wenzelm@12897  1648 lemma UN_UN_flatten: "(\x \ (\y\A. B y). C x) = (\y\A. \x\B y. C x)"  wenzelm@12897  1649  by blast  wenzelm@12897  1650 wenzelm@12897  1651 lemma UN_subset_iff: "((\i\I. A i) \ B) = (\i\I. A i \ B)"  wenzelm@12897  1652  by blast  wenzelm@12897  1653 wenzelm@12897  1654 lemma INT_subset_iff: "(B \ (\i\I. A i)) = (\i\I. B \ A i)"  wenzelm@12897  1655  by blast  wenzelm@12897  1656 wenzelm@12897  1657 lemma INT_insert [simp]: "(\x \ insert a A. B x) = B a \ INTER A B"  wenzelm@12897  1658  by blast  wenzelm@12897  1659 wenzelm@12897  1660 lemma INT_Un: "(\i \ A \ B. M i) = (\i \ A. M i) \ (\i\B. M i)"  wenzelm@12897  1661  by blast  wenzelm@12897  1662 wenzelm@12897  1663 lemma INT_insert_distrib:  wenzelm@12897  1664  "u \ A ==> (\x\A. insert a (B x)) = insert a (\x\A. B x)"  wenzelm@12897  1665  by blast  wenzelm@12897  1666 wenzelm@12897  1667 lemma Union_image_eq [simp]: "\(BA) = (\x\A. B x)"  wenzelm@12897  1668  by blast  wenzelm@12897  1669 wenzelm@12897  1670 lemma image_Union: "f  \S = (\x\S. f  x)"  wenzelm@12897  1671  by blast  wenzelm@12897  1672 wenzelm@12897  1673 lemma Inter_image_eq [simp]: "\(BA) = (\x\A. B x)"  wenzelm@12897  1674  by blast  wenzelm@12897  1675 wenzelm@12897  1676 lemma UN_constant [simp]: "(\y\A. c) = (if A = {} then {} else c)"  wenzelm@12897  1677  by auto  wenzelm@12897  1678 wenzelm@12897  1679 lemma INT_constant [simp]: "(\y\A. c) = (if A = {} then UNIV else c)"  wenzelm@12897  1680  by auto  wenzelm@12897  1681 wenzelm@12897  1682 lemma UN_eq: "(\x\A. B x) = \({Y. \x\A. Y = B x})"  wenzelm@12897  1683  by blast  wenzelm@12897  1684 wenzelm@12897  1685 lemma INT_eq: "(\x\A. B x) = \({Y. \x\A. Y = B x})"  wenzelm@12897  1686  -- {* Look: it has an \emph{existential} quantifier *}  wenzelm@12897  1687  by blast  wenzelm@12897  1688 paulson@18447  1689 lemma UNION_empty_conv[simp]:  nipkow@13653  1690  "({} = (UN x:A. B x)) = (\x\A. B x = {})"  nipkow@13653  1691  "((UN x:A. B x) = {}) = (\x\A. B x = {})"  nipkow@13653  1692 by blast+  nipkow@13653  1693 paulson@18447  1694 lemma INTER_UNIV_conv[simp]:  nipkow@13653  1695  "(UNIV = (INT x:A. B x)) = (\x\A. B x = UNIV)"  nipkow@13653  1696  "((INT x:A. B x) = UNIV) = (\x\A. B x = UNIV)"  nipkow@13653  1697 by blast+  wenzelm@12897  1698 wenzelm@12897  1699 wenzelm@12897  1700 text {* \medskip Distributive laws: *}  wenzelm@12897  1701 wenzelm@12897  1702 lemma Int_Union: "A \ \B = (\C\B. A \ C)"  wenzelm@12897  1703  by blast  wenzelm@12897  1704 wenzelm@12897  1705 lemma Int_Union2: "\B \ A = (\C\B. C \ A)"  wenzelm@12897  1706  by blast  wenzelm@12897  1707 wenzelm@12897  1708 lemma Un_Union_image: "(\x\C. A x \ B x) = \(AC) \ \(BC)"  wenzelm@12897  1709  -- {* Devlin, Fundamentals of Contemporary Set Theory, page 12, exercise 5: *}  wenzelm@12897  1710  -- {* Union of a family of unions *}  wenzelm@12897  1711  by blast  wenzelm@12897  1712 wenzelm@12897  1713 lemma UN_Un_distrib: "(\i\I. A i \ B i) = (\i\I. A i) \ (\i\I. B i)"  wenzelm@12897  1714  -- {* Equivalent version *}  wenzelm@12897  1715  by blast  wenzelm@12897  1716 wenzelm@12897  1717 lemma Un_Inter: "A \ \B = (\C\B. A \ C)"  wenzelm@12897  1718  by blast  wenzelm@12897  1719 wenzelm@12897  1720 lemma Int_Inter_image: "(\x\C. A x \ B x) = \(AC) \ \(BC)"  wenzelm@12897  1721  by blast  wenzelm@12897  1722 wenzelm@12897  1723 lemma INT_Int_distrib: "(\i\I. A i \ B i) = (\i\I. A i) \ (\i\I. B i)"  wenzelm@12897  1724  -- {* Equivalent version *}  wenzelm@12897  1725  by blast  wenzelm@12897  1726 wenzelm@12897  1727 lemma Int_UN_distrib: "B \ (\i\I. A i) = (\i\I. B \ A i)"  wenzelm@12897  1728  -- {* Halmos, Naive Set Theory, page 35. *}  wenzelm@12897  1729  by blast  wenzelm@12897  1730 wenzelm@12897  1731 lemma Un_INT_distrib: "B \ (\i\I. A i) = (\i\I. B \ A i)"  wenzelm@12897  1732  by blast  wenzelm@12897  1733 wenzelm@12897  1734 lemma Int_UN_distrib2: "(\i\I. A i) \ (\j\J. B j) = (\i\I. \j\J. A i \ B j)"  wenzelm@12897  1735  by blast  wenzelm@12897  1736 wenzelm@12897  1737 lemma Un_INT_distrib2: "(\i\I. A i) \ (\j\J. B j) = (\i\I. \j\J. A i \ B j)"  wenzelm@12897  1738  by blast  wenzelm@12897  1739 wenzelm@12897  1740 wenzelm@12897  1741 text {* \medskip Bounded quantifiers.  wenzelm@12897  1742 wenzelm@12897  1743  The following are not added to the default simpset because  wenzelm@12897  1744  (a) they duplicate the body and (b) there are no similar rules for @{text Int}. *}  wenzelm@12897  1745 wenzelm@12897  1746 lemma ball_Un: "(\x \ A \ B. P x) = ((\x\A. P x) & (\x\B. P x))"  wenzelm@12897  1747  by blast  wenzelm@12897  1748 wenzelm@12897  1749 lemma bex_Un: "(\x \ A \ B. P x) = ((\x\A. P x) | (\x\B. P x))"  wenzelm@12897  1750  by blast  wenzelm@12897  1751 wenzelm@12897  1752 lemma ball_UN: "(\z \ UNION A B. P z) = (\x\A. \z \ B x. P z)"  wenzelm@12897  1753  by blast  wenzelm@12897  1754 wenzelm@12897  1755 lemma bex_UN: "(\z \ UNION A B. P z) = (\x\A. \z\B x. P z)"  wenzelm@12897  1756  by blast  wenzelm@12897  1757 wenzelm@12897  1758 wenzelm@12897  1759 text {* \medskip Set difference. *}  wenzelm@12897  1760 wenzelm@12897  1761 lemma Diff_eq: "A - B = A \ (-B)"  wenzelm@12897  1762  by blast  wenzelm@12897  1763 paulson@24286  1764 lemma Diff_eq_empty_iff [simp,noatp]: "(A - B = {}) = (A \ B)"  wenzelm@12897  1765  by blast  wenzelm@12897  1766 wenzelm@12897  1767 lemma Diff_cancel [simp]: "A - A = {}"  wenzelm@12897  1768  by blast  wenzelm@12897  1769 nipkow@14302  1770 lemma Diff_idemp [simp]: "(A - B) - B = A - (B::'a set)"  nipkow@14302  1771 by blast  nipkow@14302  1772 wenzelm@12897  1773 lemma Diff_triv: "A \ B = {} ==> A - B = A"  wenzelm@12897  1774  by (blast elim: equalityE)  wenzelm@12897  1775 wenzelm@12897  1776 lemma empty_Diff [simp]: "{} - A = {}"  wenzelm@12897  1777  by blast  wenzelm@12897  1778 wenzelm@12897  1779 lemma Diff_empty [simp]: "A - {} = A"  wenzelm@12897  1780  by blast  wenzelm@12897  1781 wenzelm@12897  1782 lemma Diff_UNIV [simp]: "A - UNIV = {}"  wenzelm@12897  1783  by blast  wenzelm@12897  1784 paulson@24286  1785 lemma Diff_insert0 [simp,noatp]: "x \ A ==> A - insert x B = A - B"  wenzelm@12897  1786  by blast  wenzelm@12897  1787 wenzelm@12897  1788 lemma Diff_insert: "A - insert a B = A - B - {a}"  wenzelm@12897  1789  -- {* NOT SUITABLE FOR REWRITING since @{text "{a} == insert a 0"} *}  wenzelm@12897  1790  by blast  wenzelm@12897  1791 wenzelm@12897  1792 lemma Diff_insert2: "A - insert a B = A - {a} - B"  wenzelm@12897  1793  -- {* NOT SUITABLE FOR REWRITING since @{text "{a} == insert a 0"} *}  wenzelm@12897  1794  by blast  wenzelm@12897  1795 wenzelm@12897  1796 lemma insert_Diff_if: "insert x A - B = (if x \ B then A - B else insert x (A - B))"  wenzelm@12897  1797  by auto  wenzelm@12897  1798 wenzelm@12897  1799 lemma insert_Diff1 [simp]: "x \ B ==> insert x A - B = A - B"  wenzelm@12897  1800  by blast  wenzelm@12897  1801 nipkow@14302  1802 lemma insert_Diff_single[simp]: "insert a (A - {a}) = insert a A"  nipkow@14302  1803 by blast  nipkow@14302  1804 wenzelm@12897  1805 lemma insert_Diff: "a \ A ==> insert a (A - {a}) = A"  wenzelm@12897  1806  by blast  wenzelm@12897  1807 wenzelm@12897  1808 lemma Diff_insert_absorb: "x \ A ==> (insert x A) - {x} = A"  wenzelm@12897  1809  by auto  wenzelm@12897  1810 wenzelm@12897  1811 lemma Diff_disjoint [simp]: "A \ (B - A) = {}"  wenzelm@12897  1812  by blast  wenzelm@12897  1813 wenzelm@12897  1814 lemma Diff_partition: "A \ B ==> A \ (B - A) = B"  wenzelm@12897  1815  by blast  wenzelm@12897  1816 wenzelm@12897  1817 lemma double_diff: "A \ B ==> B \ C ==> B - (C - A) = A"  wenzelm@12897  1818  by blast  wenzelm@12897  1819 wenzelm@12897  1820 lemma Un_Diff_cancel [simp]: "A \ (B - A) = A \ B"  wenzelm@12897  1821  by blast  wenzelm@12897  1822 wenzelm@12897  1823 lemma Un_Diff_cancel2 [simp]: "(B - A) \ A = B \ A"  wenzelm@12897  1824  by blast  wenzelm@12897  1825 wenzelm@12897  1826 lemma Diff_Un: "A - (B \ C) = (A - B) \ (A - C)"  wenzelm@12897  1827  by blast  wenzelm@12897  1828 wenzelm@12897  1829 lemma Diff_Int: "A - (B \ C) = (A - B) \ (A - C)"  wenzelm@12897  1830  by blast  wenzelm@12897  1831 wenzelm@12897  1832 lemma Un_Diff: "(A \ B) - C = (A - C) \ (B - C)"  wenzelm@12897  1833  by blast  wenzelm@12897  1834 wenzelm@12897  1835 lemma Int_Diff: "(A \ B) - C = A \ (B - C)"  wenzelm@12897  1836  by blast  wenzelm@12897  1837 wenzelm@12897  1838 lemma Diff_Int_distrib: "C \ (A - B) = (C \ A) - (C \ B)"  wenzelm@12897  1839  by blast  wenzelm@12897  1840 wenzelm@12897  1841 lemma Diff_Int_distrib2: "(A - B) \ C = (A \ C) - (B \ C)"  wenzelm@12897  1842  by blast  wenzelm@12897  1843 wenzelm@12897  1844 lemma Diff_Compl [simp]: "A - (- B) = A \ B"  wenzelm@12897  1845  by auto  wenzelm@12897  1846 wenzelm@12897  1847 lemma Compl_Diff_eq [simp]: "- (A - B) = -A \ B"  wenzelm@12897  1848  by blast  wenzelm@12897  1849 wenzelm@12897  1850 wenzelm@12897  1851 text {* \medskip Quantification over type @{typ bool}. *}  wenzelm@12897  1852 wenzelm@12897  1853 lemma bool_induct: "P True \ P False \ P x"  haftmann@21549  1854  by (cases x) auto  haftmann@21549  1855 haftmann@21549  1856 lemma all_bool_eq: "(\b. P b) \ P True \ P False"  haftmann@21549  1857  by (auto intro: bool_induct)  haftmann@21549  1858 haftmann@21549  1859 lemma bool_contrapos: "P x \ \ P False \ P True"  haftmann@21549  1860  by (cases x) auto  haftmann@21549  1861 haftmann@21549  1862 lemma ex_bool_eq: "(\b. P b) \ P True \ P False"  haftmann@21549  1863  by (auto intro: bool_contrapos)  wenzelm@12897  1864 wenzelm@12897  1865 lemma Un_eq_UN: "A \ B = (\b. if b then A else B)"  wenzelm@12897  1866  by (auto simp add: split_if_mem2)  wenzelm@12897  1867 wenzelm@12897  1868 lemma UN_bool_eq: "(\b::bool. A b) = (A True \ A False)"  haftmann@21549  1869  by (auto intro: bool_contrapos)  wenzelm@12897  1870 wenzelm@12897  1871 lemma INT_bool_eq: "(\b::bool. A b) = (A True \ A False)"  haftmann@21549  1872  by (auto intro: bool_induct)  wenzelm@12897  1873 wenzelm@12897  1874 text {* \medskip @{text Pow} *}  wenzelm@12897  1875 wenzelm@12897  1876 lemma Pow_empty [simp]: "Pow {} = {{}}"  wenzelm@12897  1877  by (auto simp add: Pow_def)  wenzelm@12897  1878 wenzelm@12897  1879 lemma Pow_insert: "Pow (insert a A) = Pow A \ (insert a  Pow A)"  wenzelm@12897  1880  by (blast intro: image_eqI [where ?x = "u - {a}", standard])  wenzelm@12897  1881 wenzelm@12897  1882 lemma Pow_Compl: "Pow (- A) = {-B | B. A \ Pow B}"  wenzelm@12897  1883  by (blast intro: exI [where ?x = "- u", standard])  wenzelm@12897  1884 wenzelm@12897  1885 lemma Pow_UNIV [simp]: "Pow UNIV = UNIV"  wenzelm@12897  1886  by blast  wenzelm@12897  1887 wenzelm@12897  1888 lemma Un_Pow_subset: "Pow A \ Pow B \ Pow (A \ B)"  wenzelm@12897  1889  by blast  wenzelm@12897  1890 wenzelm@12897  1891 lemma UN_Pow_subset: "(\x\A. Pow (B x)) \ Pow (\x\A. B x)"  wenzelm@12897  1892  by blast  wenzelm@12897  1893 wenzelm@12897  1894 lemma subset_Pow_Union: "A \ Pow (\A)"  wenzelm@12897  1895  by blast  wenzelm@12897  1896 wenzelm@12897  1897 lemma Union_Pow_eq [simp]: "\(Pow A) = A"  wenzelm@12897  1898  by blast  wenzelm@12897  1899 wenzelm@12897  1900 lemma Pow_Int_eq [simp]: "Pow (A \ B) = Pow A \ Pow B"  wenzelm@12897  1901  by blast  wenzelm@12897  1902 wenzelm@12897  1903 lemma Pow_INT_eq: "Pow (\x\A. B x) = (\x\A. Pow (B x))"  wenzelm@12897  1904  by blast  wenzelm@12897  1905 wenzelm@12897  1906 wenzelm@12897  1907 text {* \medskip Miscellany. *}  wenzelm@12897  1908 wenzelm@12897  1909 lemma set_eq_subset: "(A = B) = (A \ B & B \ A)"  wenzelm@12897  1910  by blast  wenzelm@12897  1911 wenzelm@12897  1912 lemma subset_iff: "(A \ B) = (\t. t \ A --> t \ B)"  wenzelm@12897  1913  by blast  wenzelm@12897  1914 wenzelm@12897  1915 lemma subset_iff_psubset_eq: "(A \ B) = ((A \ B) | (A = B))"  berghofe@26800  1916  by (unfold less_le) blast  wenzelm@12897  1917 paulson@18447  1918 lemma all_not_in_conv [simp]: "(\x. x \ A) = (A = {})"  wenzelm@12897  1919  by blast  wenzelm@12897  1920 paulson@13831  1921 lemma ex_in_conv: "(\x. x \ A) = (A \ {})"  paulson@13831  1922  by blast  paulson@13831  1923 wenzelm@12897  1924 lemma distinct_lemma: "f x \ f y ==> x \ y"  nipkow@17589  1925  by iprover  wenzelm@12897  1926 wenzelm@12897  1927 paulson@13860  1928 text {* \medskip Miniscoping: pushing in quantifiers and big Unions  paulson@13860  1929  and Intersections. *}  wenzelm@12897  1930 wenzelm@12897  1931 lemma UN_simps [simp]:  wenzelm@12897  1932  "!!a B C. (UN x:C. insert a (B x)) = (if C={} then {} else insert a (UN x:C. B x))"  wenzelm@12897  1933  "!!A B C. (UN x:C. A x Un B) = ((if C={} then {} else (UN x:C. A x) Un B))"  wenzelm@12897  1934  "!!A B C. (UN x:C. A Un B x) = ((if C={} then {} else A Un (UN x:C. B x)))"  wenzelm@12897  1935  "!!A B C. (UN x:C. A x Int B) = ((UN x:C. A x) Int B)"  wenzelm@12897  1936  "!!A B C. (UN x:C. A Int B x) = (A Int (UN x:C. B x))"  wenzelm@12897  1937  "!!A B C. (UN x:C. A x - B) = ((UN x:C. A x) - B)"  wenzelm@12897  1938  "!!A B C. (UN x:C. A - B x) = (A - (INT x:C. B x))"  wenzelm@12897  1939  "!!A B. (UN x: Union A. B x) = (UN y:A. UN x:y. B x)"  wenzelm@12897  1940  "!!A B C. (UN z: UNION A B. C z) = (UN x:A. UN z: B(x). C z)"  wenzelm@12897  1941  "!!A B f. (UN x:fA. B x) = (UN a:A. B (f a))"  wenzelm@12897  1942  by auto  wenzelm@12897  1943 wenzelm@12897  1944 lemma INT_simps [simp]:  wenzelm@12897  1945  "!!A B C. (INT x:C. A x Int B) = (if C={} then UNIV else (INT x:C. A x) Int B)"  wenzelm@12897  1946  "!!A B C. (INT x:C. A Int B x) = (if C={} then UNIV else A Int (INT x:C. B x))"  wenzelm@12897  1947  "!!A B C. (INT x:C. A x - B) = (if C={} then UNIV else (INT x:C. A x) - B)"  wenzelm@12897  1948  "!!A B C. (INT x:C. A - B x) = (if C={} then UNIV else A - (UN x:C. B x))"  wenzelm@12897  1949  "!!a B C. (INT x:C. insert a (B x)) = insert a (INT x:C. B x)"  wenzelm@12897  1950  "!!A B C. (INT x:C. A x Un B) = ((INT x:C. A x) Un B)"  wenzelm@12897  1951  "!!A B C. (INT x:C. A Un B x) = (A Un (INT x:C. B x))"  wenzelm@12897  1952  "!!A B. (INT x: Union A. B x) = (INT y:A. INT x:y. B x)"  wenzelm@12897  1953  "!!A B C. (INT z: UNION A B. C z) = (INT x:A. INT z: B(x). C z)"  wenzelm@12897  1954  "!!A B f. (INT x:fA. B x) = (INT a:A. B (f a))"  wenzelm@12897  1955  by auto  wenzelm@12897  1956 paulson@24286  1957 lemma ball_simps [simp,noatp]:  wenzelm@12897  1958  "!!A P Q. (ALL x:A. P x | Q) = ((ALL x:A. P x) | Q)"  wenzelm@12897  1959  "!!A P Q. (ALL x:A. P | Q x) = (P | (ALL x:A. Q x))"  wenzelm@12897  1960  "!!A P Q. (ALL x:A. P --> Q x) = (P --> (ALL x:A. Q x))"  wenzelm@12897  1961  "!!A P Q. (ALL x:A. P x --> Q) = ((EX x:A. P x) --> Q)"  wenzelm@12897  1962  "!!P. (ALL x:{}. P x) = True"  wenzelm@12897  1963  "!!P. (ALL x:UNIV. P x) = (ALL x. P x)"  wenzelm@12897  1964  "!!a B P. (ALL x:insert a B. P x) = (P a & (ALL x:B. P x))"  wenzelm@12897  1965  "!!A P. (ALL x:Union A. P x) = (ALL y:A. ALL x:y. P x)"  wenzelm@12897  1966  "!!A B P. (ALL x: UNION A B. P x) = (ALL a:A. ALL x: B a. P x)"  wenzelm@12897  1967  "!!P Q. (ALL x:Collect Q. P x) = (ALL x. Q x --> P x)"  wenzelm@12897  1968  "!!A P f. (ALL x:fA. P x) = (ALL x:A. P (f x))"  wenzelm@12897  1969  "!!A P. (~(ALL x:A. P x)) = (EX x:A. ~P x)"  wenzelm@12897  1970  by auto  wenzelm@12897  1971 paulson@24286  1972 lemma bex_simps [simp,noatp]:  wenzelm@12897  1973  "!!A P Q. (EX x:A. P x & Q) = ((EX x:A. P x) & Q)"  wenzelm@12897  1974  "!!A P Q. (EX x:A. P & Q x) = (P & (EX x:A. Q x))"  wenzelm@12897  1975  "!!P. (EX x:{}. P x) = False"  wenzelm@12897  1976  "!!P. (EX x:UNIV. P x) = (EX x. P x)"  wenzelm@12897  1977  "!!a B P. (EX x:insert a B. P x) = (P(a) | (EX x:B. P x))"  wenzelm@12897  1978  "!!A P. (EX x:Union A. P x) = (EX y:A. EX x:y. P x)"  wenzelm@12897  1979  "!!A B P. (EX x: UNION A B. P x) = (EX a:A. EX x:B a. P x)"  wenzelm@12897  1980  "!!P Q. (EX x:Collect Q. P x) = (EX x. Q x & P x)"  wenzelm@12897  1981  "!!A P f. (EX x:fA. P x) = (EX x:A. P (f x))"  wenzelm@12897  1982  "!!A P. (~(EX x:A. P x)) = (ALL x:A. ~P x)"  wenzelm@12897  1983  by auto  wenzelm@12897  1984 wenzelm@12897  1985 lemma ball_conj_distrib:  wenzelm@12897  1986  "(ALL x:A. P x & Q x) = ((ALL x:A. P x) & (ALL x:A. Q x))"  wenzelm@12897  1987  by blast  wenzelm@12897  1988 wenzelm@12897  1989 lemma bex_disj_distrib:  wenzelm@12897  1990  "(EX x:A. P x | Q x) = ((EX x:A. P x) | (EX x:A. Q x))"  wenzelm@12897  1991  by blast  wenzelm@12897  1992 wenzelm@12897  1993 paulson@13860  1994 text {* \medskip Maxiscoping: pulling out big Unions and Intersections. *}  paulson@13860  1995 paulson@13860  1996 lemma UN_extend_simps:  paulson@13860  1997  "!!a B C. insert a (UN x:C. B x) = (if C={} then {a} else (UN x:C. insert a (B x)))"  paulson@13860  1998  "!!A B C. (UN x:C. A x) Un B = (if C={} then B else (UN x:C. A x Un B))"  paulson@13860  1999  "!!A B C. A Un (UN x:C. B x) = (if C={} then A else (UN x:C. A Un B x))"  paulson@13860  2000  "!!A B C. ((UN x:C. A x) Int B) = (UN x:C. A x Int B)"  paulson@13860  2001  "!!A B C. (A Int (UN x:C. B x)) = (UN x:C. A Int B x)"  paulson@13860  2002  "!!A B C. ((UN x:C. A x) - B) = (UN x:C. A x - B)"  paulson@13860  2003  "!!A B C. (A - (INT x:C. B x)) = (UN x:C. A - B x)"  paulson@13860  2004  "!!A B. (UN y:A. UN x:y. B x) = (UN x: Union A. B x)"  paulson@13860  2005  "!!A B C. (UN x:A. UN z: B(x). C z) = (UN z: UNION A B. C z)"  paulson@13860  2006  "!!A B f. (UN a:A. B (f a)) = (UN x:fA. B x)"  paulson@13860  2007  by auto  paulson@13860  2008 paulson@13860  2009 lemma INT_extend_simps:  paulson@13860  2010  "!!A B C. (INT x:C. A x) Int B = (if C={} then B else (INT x:C. A x Int B))"  paulson@13860  2011  "!!A B C. A Int (INT x:C. B x) = (if C={} then A else (INT x:C. A Int B x))"  paulson@13860  2012  "!!A B C. (INT x:C. A x) - B = (if C={} then UNIV-B else (INT x:C. A x - B))"  paulson@13860  2013  "!!A B C. A - (UN x:C. B x) = (if C={} then A else (INT x:C. A - B x))"  paulson@13860  2014  "!!a B C. insert a (INT x:C. B x) = (INT x:C. insert a (B x))"  paulson@13860  2015  "!!A B C. ((INT x:C. A x) Un B) = (INT x:C. A x Un B)"  paulson@13860  2016  "!!A B C. A Un (INT x:C. B x) = (INT x:C. A Un B x)"  paulson@13860  2017  "!!A B. (INT y:A. INT x:y. B x) = (INT x: Union A. B x)"  paulson@13860  2018  "!!A B C. (INT x:A. INT z: B(x). C z) = (INT z: UNION A B. C z)"  paulson@13860  2019  "!!A B f. (INT a:A. B (f a)) = (INT x:fA. B x)"  paulson@13860  2020  by auto  paulson@13860  2021 paulson@13860  2022 wenzelm@12897  2023 subsubsection {* Monotonicity of various operations *}  wenzelm@12897  2024 wenzelm@12897  2025 lemma image_mono: "A \ B ==> fA \ fB"  wenzelm@12897  2026  by blast  wenzelm@12897  2027 wenzelm@12897  2028 lemma Pow_mono: "A \ B ==> Pow A \ Pow B"  wenzelm@12897  2029  by blast  wenzelm@12897  2030 wenzelm@12897  2031 lemma Union_mono: "A \ B ==> \A \ \B"  wenzelm@12897  2032  by blast  wenzelm@12897  2033 wenzelm@12897  2034 lemma Inter_anti_mono: "B \ A ==> \A \ \B"  wenzelm@12897  2035  by blast  wenzelm@12897  2036 wenzelm@12897  2037 lemma UN_mono:  wenzelm@12897  2038  "A \ B ==> (!!x. x \ A ==> f x \ g x) ==>  wenzelm@12897  2039  (\x\A. f x) \ (\x\B. g x)"  wenzelm@12897  2040  by (blast dest: subsetD)  wenzelm@12897  2041 wenzelm@12897  2042 lemma INT_anti_mono:  wenzelm@12897  2043  "B \ A ==> (!!x. x \ A ==> f x \ g x) ==>  wenzelm@12897  2044  (\x\A. f x) \ (\x\A. g x)"  wenzelm@12897  2045  -- {* The last inclusion is POSITIVE! *}  wenzelm@12897  2046  by (blast dest: subsetD)  wenzelm@12897  2047 wenzelm@12897  2048 lemma insert_mono: "C \ D ==> insert a C \ insert a D"  wenzelm@12897  2049  by blast  wenzelm@12897  2050 wenzelm@12897  2051 lemma Un_mono: "A \ C ==> B \ D ==> A \ B \ C \ D"  wenzelm@12897  2052  by blast  wenzelm@12897  2053 wenzelm@12897  2054 lemma Int_mono: "A \ C ==> B \ D ==> A \ B \ C \ D"  wenzelm@12897  2055  by blast  wenzelm@12897  2056 wenzelm@12897  2057 lemma Diff_mono: "A \ C ==> D \ B ==> A - B \ C - D"  wenzelm@12897  2058  by blast  wenzelm@12897  2059 wenzelm@12897  2060 lemma Compl_anti_mono: "A \ B ==> -B \ -A"  wenzelm@12897  2061  by blast  wenzelm@12897  2062 wenzelm@12897  2063 text {* \medskip Monotonicity of implications. *}  wenzelm@12897  2064 wenzelm@12897  2065 lemma in_mono: "A \ B ==> x \ A --> x \ B"  wenzelm@12897  2066  apply (rule impI)  paulson@14208  2067  apply (erule subsetD, assumption)  wenzelm@12897  2068  done  wenzelm@12897  2069 wenzelm@12897  2070 lemma conj_mono: "P1 --> Q1 ==> P2 --> Q2 ==> (P1 & P2) --> (Q1 & Q2)"  nipkow@17589  2071  by iprover  wenzelm@12897  2072 wenzelm@12897  2073 lemma disj_mono: "P1 --> Q1 ==> P2 --> Q2 ==> (P1 | P2) --> (Q1 | Q2)"  nipkow@17589  2074  by iprover  wenzelm@12897  2075 wenzelm@12897  2076 lemma imp_mono: "Q1 --> P1 ==> P2 --> Q2 ==> (P1 --> P2) --> (Q1 --> Q2)"  nipkow@17589  2077  by iprover  wenzelm@12897  2078 wenzelm@12897  2079 lemma imp_refl: "P --> P" ..  wenzelm@12897  2080 wenzelm@12897  2081 lemma ex_mono: "(!!x. P x --> Q x) ==> (EX x. P x) --> (EX x. Q x)"  nipkow@17589  2082  by iprover  wenzelm@12897  2083 wenzelm@12897  2084 lemma all_mono: "(!!x. P x --> Q x) ==> (ALL x. P x) --> (ALL x. Q x)"  nipkow@17589  2085  by iprover  wenzelm@12897  2086 wenzelm@12897  2087 lemma Collect_mono: "(!!x. P x --> Q x) ==> Collect P \ Collect Q"  wenzelm@12897  2088  by blast  wenzelm@12897  2089 wenzelm@12897  2090 lemma Int_Collect_mono:  wenzelm@12897  2091  "A \ B ==> (!!x. x \ A ==> P x --> Q x) ==> A \ Collect P \ B \ Collect Q"  wenzelm@12897  2092  by blast  wenzelm@12897  2093 wenzelm@12897  2094 lemmas basic_monos =  wenzelm@12897  2095  subset_refl imp_refl disj_mono conj_mono  wenzelm@12897  2096  ex_mono Collect_mono in_mono  wenzelm@12897  2097 wenzelm@12897  2098 lemma eq_to_mono: "a = b ==> c = d ==> b --> d ==> a --> c"  nipkow@17589  2099  by iprover  wenzelm@12897  2100 wenzelm@12897  2101 lemma eq_to_mono2: "a = b ==> c = d ==> ~ b --> ~ d ==> ~ a --> ~ c"  nipkow@17589  2102  by iprover  wenzelm@11979  2103 wenzelm@12020  2104 haftmann@30531  2105 subsection {* Inverse image of a function *}  wenzelm@12257  2106 wenzelm@12257  2107 constdefs  wenzelm@12257  2108  vimage :: "('a => 'b) => 'b set => 'a set" (infixr "-" 90)  haftmann@28562  2109  [code del]: "f - B == {x. f x : B}"  wenzelm@12257  2110 haftmann@30531  2111 haftmann@30531  2112 subsubsection {* Basic rules *}  haftmann@30531  2113 wenzelm@12257  2114 lemma vimage_eq [simp]: "(a : f - B) = (f a : B)"  wenzelm@12257  2115  by (unfold vimage_def) blast  wenzelm@12257  2116 wenzelm@12257  2117 lemma vimage_singleton_eq: "(a : f - {b}) = (f a = b)"  wenzelm@12257  2118  by simp  wenzelm@12257  2119 wenzelm@12257  2120 lemma vimageI [intro]: "f a = b ==> b:B ==> a : f - B"  wenzelm@12257  2121  by (unfold vimage_def) blast  wenzelm@12257  2122 wenzelm@12257  2123 lemma vimageI2: "f a : A ==> a : f - A"  wenzelm@12257  2124  by (unfold vimage_def) fast  wenzelm@12257  2125 wenzelm@12257  2126 lemma vimageE [elim!]: "a: f - B ==> (!!x. f a = x ==> x:B ==> P) ==> P"  wenzelm@12257  2127  by (unfold vimage_def) blast  wenzelm@12257  2128 wenzelm@12257  2129 lemma vimageD: "a : f - A ==> f a : A"  wenzelm@12257  2130  by (unfold vimage_def) fast  wenzelm@12257  2131 haftmann@30531  2132 haftmann@30531  2133 subsubsection {* Equations *}  haftmann@30531  2134 wenzelm@12257  2135 lemma vimage_empty [simp]: "f - {} = {}"  wenzelm@12257  2136  by blast  wenzelm@12257  2137 wenzelm@12257  2138 lemma vimage_Compl: "f - (-A) = -(f - A)"  wenzelm@12257  2139  by blast  wenzelm@12257  2140 wenzelm@12257  2141 lemma vimage_Un [simp]: "f - (A Un B) = (f - A) Un (f - B)"  wenzelm@12257  2142  by blast  wenzelm@12257  2143 wenzelm@12257  2144 lemma vimage_Int [simp]: "f - (A Int B) = (f - A) Int (f - B)"  wenzelm@12257  2145  by fast  wenzelm@12257  2146 wenzelm@12257  2147 lemma vimage_Union: "f - (Union A) = (UN X:A. f - X)"  wenzelm@12257  2148  by blast  wenzelm@12257  2149 wenzelm@12257  2150 lemma vimage_UN: "f-(UN x:A. B x) = (UN x:A. f - B x)"  wenzelm@12257  2151  by blast  wenzelm@12257  2152 wenzelm@12257  2153 lemma vimage_INT: "f-(INT x:A. B x) = (INT x:A. f - B x)"  wenzelm@12257  2154  by blast  wenzelm@12257  2155 wenzelm@12257  2156 lemma vimage_Collect_eq [simp]: "f - Collect P = {y. P (f y)}"  wenzelm@12257  2157  by blast  wenzelm@12257  2158 wenzelm@12257  2159 lemma vimage_Collect: "(!!x. P (f x) = Q x) ==> f - (Collect P) = Collect Q"  wenzelm@12257  2160  by blast  wenzelm@12257  2161 wenzelm@12257  2162 lemma vimage_insert: "f-(insert a B) = (f-{a}) Un (f-B)"  wenzelm@12257  2163  -- {* NOT suitable for rewriting because of the recurrence of @{term "{a}"}. *}  wenzelm@12257  2164  by blast  wenzelm@12257  2165 wenzelm@12257  2166 lemma vimage_Diff: "f - (A - B) = (f - A) - (f - B)"  wenzelm@12257  2167  by blast  wenzelm@12257  2168 wenzelm@12257  2169 lemma vimage_UNIV [simp]: "f - UNIV = UNIV"  wenzelm@12257  2170  by blast  wenzelm@12257  2171 wenzelm@12257  2172 lemma vimage_eq_UN: "f-B = (UN y: B. f-{y})"  wenzelm@12257  2173  -- {* NOT suitable for rewriting *}  wenzelm@12257  2174  by blast  wenzelm@12257  2175 wenzelm@12897  2176 lemma vimage_mono: "A \ B ==> f - A \ f - B"  wenzelm@12257  2177  -- {* monotonicity *}  wenzelm@12257  2178  by blast  wenzelm@12257  2179 haftmann@26150  2180 lemma vimage_image_eq [noatp]: "f - (f  A) = {y. EX x:A. f x = f y}"  haftmann@26150  2181 by (blast intro: sym)  haftmann@26150  2182 haftmann@26150  2183 lemma image_vimage_subset: "f  (f - A) <= A"  haftmann@26150  2184 by blast  haftmann@26150  2185 haftmann@26150  2186 lemma image_vimage_eq [simp]: "f  (f - A) = A Int range f"  haftmann@26150  2187 by blast  haftmann@26150  2188 haftmann@26150  2189 lemma image_Int_subset: "f(A Int B) <= fA Int fB"  haftmann@26150  2190 by blast  haftmann@26150  2191 haftmann@26150  2192 lemma image_diff_subset: "fA - fB <= f(A - B)"  haftmann@26150  2193 by blast  haftmann@26150  2194 haftmann@26150  2195 lemma image_UN: "(f  (UNION A B)) = (UN x:A.(f  (B x)))"  haftmann@26150  2196 by blast  haftmann@26150  2197 wenzelm@12257  2198 haftmann@30531  2199 subsection {* Getting the Contents of a Singleton Set *}  haftmann@30531  2200 haftmann@30531  2201 definition contents :: "'a set \ 'a" where  haftmann@30531  2202  [code del]: "contents X = (THE x. X = {x})"  haftmann@30531  2203 haftmann@30531  2204 lemma contents_eq [simp]: "contents {x} = x"  haftmann@30531  2205  by (simp add: contents_def)  haftmann@30531  2206 haftmann@30531  2207 haftmann@30531  2208 subsection {* Transitivity rules for calculational reasoning *}  haftmann@30531  2209 haftmann@30531  2210 lemma set_rev_mp: "x:A ==> A \ B ==> x:B"  haftmann@30531  2211  by (rule subsetD)  haftmann@30531  2212 haftmann@30531  2213 lemma set_mp: "A \ B ==> x:A ==> x:B"  haftmann@30531  2214  by (rule subsetD)  haftmann@30531  2215 haftmann@30531  2216 lemmas basic_trans_rules [trans] =  haftmann@30531  2217  order_trans_rules set_rev_mp set_mp  haftmann@30531  2218 haftmann@30531  2219 haftmann@30531  2220 subsection {* Least value operator *}  berghofe@26800  2221 berghofe@26800  2222 lemma Least_mono:  berghofe@26800  2223  "mono (f::'a::order => 'b::order) ==> EX x:S. ALL y:S. x <= y  berghofe@26800  2224  ==> (LEAST y. y : f  S) = f (LEAST x. x : S)"  berghofe@26800  2225  -- {* Courtesy of Stephan Merz *}  berghofe@26800  2226  apply clarify  berghofe@26800  2227  apply (erule_tac P = "%x. x : S" in LeastI2_order, fast)  berghofe@26800  2228  apply (rule LeastI2_order)  berghofe@26800  2229  apply (auto elim: monoD intro!: order_antisym)  berghofe@26800  2230  done  berghofe@26800  2231 haftmann@24420  2232 haftmann@30531  2233 subsection {* Rudimentary code generation *}  haftmann@27824  2234 haftmann@28562  2235 lemma empty_code [code]: "{} x \ False"  haftmann@27824  2236  unfolding empty_def Collect_def ..  haftmann@27824  2237 haftmann@28562  2238 lemma UNIV_code [code]: "UNIV x \ True"  haftmann@27824  2239  unfolding UNIV_def Collect_def ..  haftmann@27824  2240 haftmann@28562  2241 lemma insert_code [code]: "insert y A x \ y = x \ A x"  haftmann@27824  2242  unfolding insert_def Collect_def mem_def Un_def by auto  haftmann@27824  2243 haftmann@28562  2244 lemma inter_code [code]: "(A \ B) x \ A x \ B x"  haftmann@27824  2245  unfolding Int_def Collect_def mem_def ..  haftmann@27824  2246 haftmann@28562  2247 lemma union_code [code]: "(A \ B) x \ A x \ B x"  haftmann@27824  2248  unfolding Un_def Collect_def mem_def ..  haftmann@27824  2249 haftmann@28562  2250 lemma vimage_code [code]: "(f - A) x = A (f x)"  haftmann@27824  2251  unfolding vimage_def Collect_def mem_def ..  haftmann@27824  2252 haftmann@27824  2253 haftmann@30531  2254 subsection {* Complete lattices *}  haftmann@30531  2255 haftmann@30531  2256 notation  haftmann@30531  2257  less_eq (infix "\" 50) and  haftmann@30531  2258  less (infix "\" 50) and  haftmann@30531  2259  inf (infixl "\" 70) and  haftmann@30531  2260  sup (infixl "\" 65)  haftmann@30531  2261 haftmann@30531  2262 class complete_lattice = lattice + bot + top +  haftmann@30531  2263  fixes Inf :: "'a set \ 'a" ("\_" [900] 900)  haftmann@30531  2264  and Sup :: "'a set \ 'a" ("\_" [900] 900)  haftmann@30531  2265  assumes Inf_lower: "x \ A \ \A \ x"  haftmann@30531  2266  and Inf_greatest: "(\x. x \ A \ z \ x) \ z \ \A"  haftmann@30531  2267  assumes Sup_upper: "x \ A \ x \ \A"  haftmann@30531  2268  and Sup_least: "(\x. x \ A \ x \ z) \ \A \ z"  haftmann@30531  2269 begin  haftmann@30531  2270 haftmann@30531  2271 lemma Inf_Sup: "\A = \{b. \a \ A. b \ a}"  haftmann@30531  2272  by (auto intro: antisym Inf_lower Inf_greatest Sup_upper Sup_least)  haftmann@30531  2273 haftmann@30531  2274 lemma Sup_Inf: "\A = \{b. \a \ A. a \ b}"  haftmann@30531  2275  by (auto intro: antisym Inf_lower Inf_greatest Sup_upper Sup_least)  haftmann@30531  2276 haftmann@30531  2277 lemma Inf_Univ: "\UNIV = \{}"  haftmann@30531  2278  unfolding Sup_Inf by auto  haftmann@30531  2279 haftmann@30531  2280 lemma Sup_Univ: "\UNIV = \{}"  haftmann@30531  2281  unfolding Inf_Sup by auto  haftmann@30531  2282 haftmann@30531  2283 lemma Inf_insert: "\insert a A = a \ \A"  haftmann@30531  2284  by (auto intro: antisym Inf_greatest Inf_lower)  haftmann@30531  2285 haftmann@30531  2286 lemma Sup_insert: "\insert a A = a \ \A"  haftmann@30531  2287  by (auto intro: antisym Sup_least Sup_upper)  haftmann@30531  2288 haftmann@30531  2289 lemma Inf_singleton [simp]:  haftmann@30531  2290  "\{a} = a"  haftmann@30531  2291  by (auto intro: antisym Inf_lower Inf_greatest)  haftmann@30531  2292 haftmann@30531  2293 lemma Sup_singleton [simp]:  haftmann@30531  2294  "\{a} = a"  haftmann@30531  2295  by (auto intro: antisym Sup_upper Sup_least)  haftmann@30531  2296 haftmann@30531  2297 lemma Inf_insert_simp:  haftmann@30531  2298  "\insert a A = (if A = {} then a else a \ \A)"  haftmann@30531  2299  by (cases "A = {}") (simp_all, simp add: Inf_insert)  haftmann@30531  2300 haftmann@30531  2301 lemma Sup_insert_simp:  haftmann@30531  2302  "\insert a A = (if A = {} then a else a \ \A)"  haftmann@30531  2303  by (cases "A = {}") (simp_all, simp add: Sup_insert)  haftmann@30531  2304 haftmann@30531  2305 lemma Inf_binary:  haftmann@30531  2306  "\{a, b} = a \ b"  haftmann@30531  2307  by (simp add: Inf_insert_simp)  haftmann@30531  2308 haftmann@30531  2309 lemma Sup_binary:  haftmann@30531  2310  "\{a, b} = a \ b"  haftmann@30531  2311  by (simp add: Sup_insert_simp)  haftmann@30531  2312 haftmann@30531  2313 lemma bot_def:  haftmann@30531  2314  "bot = \{}"  haftmann@30531  2315  by (auto intro: antisym Sup_least)  haftmann@30531  2316 haftmann@30531  2317 lemma top_def:  haftmann@30531  2318  "top = \{}"  haftmann@30531  2319  by (auto intro: antisym Inf_greatest)  haftmann@30531  2320 haftmann@30531  2321 lemma sup_bot [simp]:  haftmann@30531  2322  "x \ bot = x"  haftmann@30531  2323  using bot_least [of x] by (simp add: le_iff_sup sup_commute)  haftmann@30531  2324 haftmann@30531  2325 lemma inf_top [simp]:  haftmann@30531  2326  "x \ top = x"  haftmann@30531  2327  using top_greatest [of x] by (simp add: le_iff_inf inf_commute)  haftmann@30531  2328 haftmann@30531  2329 definition SUPR :: "'b set \ ('b \ 'a) \ 'a" where  haftmann@30531  2330  "SUPR A f == \ (f  A)"  haftmann@30531  2331 haftmann@30531  2332 definition INFI :: "'b set \ ('b \ 'a) \ 'a" where  haftmann@30531  2333  "INFI A f == \ (f  A)"  haftmann@30531  2334 haftmann@30531  2335 end  haftmann@30531  2336 haftmann@30531  2337 syntax  haftmann@30531  2338  "_SUP1" :: "pttrns => 'b => 'b" ("(3SUP _./ _)" [0, 10] 10)  haftmann@30531  2339  "_SUP" :: "pttrn => 'a set => 'b => 'b" ("(3SUP _:_./ _)" [0, 10] 10)  haftmann@30531  2340  "_INF1" :: "pttrns => 'b => 'b" ("(3INF _./ _)" [0, 10] 10)  haftmann@30531  2341  "_INF" :: "pttrn => 'a set => 'b => 'b" ("(3INF _:_./ _)" [0, 10] 10)  haftmann@30531  2342 haftmann@30531  2343 translations  haftmann@30531  2344  "SUP x y. B" == "SUP x. SUP y. B"  haftmann@30531  2345  "SUP x. B" == "CONST SUPR CONST UNIV (%x. B)"  haftmann@30531  2346  "SUP x. B" == "SUP x:CONST UNIV. B"  haftmann@30531  2347  "SUP x:A. B" == "CONST SUPR A (%x. B)"  haftmann@30531  2348  "INF x y. B" == "INF x. INF y. B"  haftmann@30531  2349  "INF x. B" == "CONST INFI CONST UNIV (%x. B)"  haftmann@30531  2350  "INF x. B" == "INF x:CONST UNIV. B"  haftmann@30531  2351  "INF x:A. B" == "CONST INFI A (%x. B)"  haftmann@30531  2352 haftmann@30531  2353 (* To avoid eta-contraction of body: *)  haftmann@30531  2354 print_translation {*  haftmann@30531  2355 let  haftmann@30531  2356  fun btr' syn (A :: Abs abs :: ts) =  haftmann@30531  2357  let val (x,t) = atomic_abs_tr' abs  haftmann@30531  2358  in list_comb (Syntax.const syn$ x $A$ t, ts) end  haftmann@30531  2359  val const_syntax_name = Sign.const_syntax_name @{theory} o fst o dest_Const  haftmann@30531  2360 in  haftmann@30531  2361 [(const_syntax_name @{term SUPR}, btr' "_SUP"),(const_syntax_name @{term "INFI"}, btr' "_INF")]  haftmann@30531  2362 end  haftmann@30531  2363 *}  haftmann@30531  2364 haftmann@30531  2365 context complete_lattice  haftmann@30531  2366 begin  haftmann@30531  2367 haftmann@30531  2368 lemma le_SUPI: "i : A \ M i \ (SUP i:A. M i)"  haftmann@30531  2369  by (auto simp add: SUPR_def intro: Sup_upper)  haftmann@30531  2370 haftmann@30531  2371 lemma SUP_leI: "(\i. i : A \ M i \ u) \ (SUP i:A. M i) \ u"  haftmann@30531  2372  by (auto simp add: SUPR_def intro: Sup_least)  haftmann@30531  2373 haftmann@30531  2374 lemma INF_leI: "i : A \ (INF i:A. M i) \ M i"  haftmann@30531  2375  by (auto simp add: INFI_def intro: Inf_lower)  haftmann@30531  2376 haftmann@30531  2377 lemma le_INFI: "(\i. i : A \ u \ M i) \ u \ (INF i:A. M i)"  haftmann@30531  2378  by (auto simp add: INFI_def intro: Inf_greatest)  haftmann@30531  2379 haftmann@30531  2380 lemma SUP_const[simp]: "A \ {} \ (SUP i:A. M) = M"  haftmann@30531  2381  by (auto intro: antisym SUP_leI le_SUPI)  haftmann@30531  2382 haftmann@30531  2383 lemma INF_const[simp]: "A \ {} \ (INF i:A. M) = M"  haftmann@30531  2384  by (auto intro: antisym INF_leI le_INFI)  haftmann@30531  2385 haftmann@30531  2386 end  haftmann@30531  2387 haftmann@30531  2388 haftmann@30531  2389 subsection {* Bool as complete lattice *}  haftmann@30531  2390 haftmann@30531  2391 instantiation bool :: complete_lattice  haftmann@30531  2392 begin  haftmann@30531  2393 haftmann@30531  2394 definition  haftmann@30531  2395  Inf_bool_def: "\A \ (\x\A. x)"  haftmann@30531  2396 haftmann@30531  2397 definition  haftmann@30531  2398  Sup_bool_def: "\A \ (\x\A. x)"  haftmann@30531  2399 haftmann@30531  2400 instance  haftmann@30531  2401  by intro_classes (auto simp add: Inf_bool_def Sup_bool_def le_bool_def)  haftmann@30531  2402 haftmann@30531  2403 end  haftmann@30531  2404 haftmann@30531  2405 lemma Inf_empty_bool [simp]:  haftmann@30531  2406  "\{}"  haftmann@30531  2407  unfolding Inf_bool_def by auto  haftmann@30531  2408 haftmann@30531  2409 lemma not_Sup_empty_bool [simp]:  wenzelm@30814  2410  "\ \{}"  haftmann@30531  2411  unfolding Sup_bool_def by auto  haftmann@30531  2412 haftmann@30531  2413 haftmann@30531  2414 subsection {* Fun as complete lattice *}  haftmann@30531  2415 haftmann@30531  2416 instantiation "fun" :: (type, complete_lattice) complete_lattice  haftmann@30531  2417 begin  haftmann@30531  2418 haftmann@30531  2419 definition  haftmann@30531  2420  Inf_fun_def [code del]: "\A = (\x. \{y. \f\A. y = f x})"  haftmann@30531  2421 haftmann@30531  2422 definition  haftmann@30531  2423  Sup_fun_def [code del]: "\A = (\x. \{y. \f\A. y = f x})"  haftmann@30531  2424 haftmann@30531  2425 instance  haftmann@30531  2426  by intro_classes  haftmann@30531  2427  (auto simp add: Inf_fun_def Sup_fun_def le_fun_def  haftmann@30531  2428  intro: Inf_lower Sup_upper Inf_greatest Sup_least)  haftmann@30531  2429 haftmann@30531  2430 end  haftmann@30531  2431 haftmann@30531  2432 lemma Inf_empty_fun:  haftmann@30531  2433  "\{} = (\_. \{})"  haftmann@30531  2434  by rule (auto simp add: Inf_fun_def)  haftmann@30531  2435 haftmann@30531  2436 lemma Sup_empty_fun:  haftmann@30531  2437  "\{} = (\_. \{})"  haftmann@30531  2438  by rule (auto simp add: Sup_fun_def)  haftmann@30531  2439 haftmann@30531  2440 haftmann@30531  2441 subsection {* Set as lattice *}  haftmann@30531  2442 haftmann@30531  2443 lemma inf_set_eq: "A \ B = A \ B"  haftmann@30531  2444  apply (rule subset_antisym)  haftmann@30531  2445  apply (rule Int_greatest)  haftmann@30531  2446  apply (rule inf_le1)  haftmann@30531  2447  apply (rule inf_le2)  haftmann@30531  2448  apply (rule inf_greatest)  haftmann@30531  2449  apply (rule Int_lower1)  haftmann@30531  2450  apply (rule Int_lower2)  haftmann@30531  2451  done  haftmann@30531  2452 haftmann@30531  2453 lemma sup_set_eq: "A \ B = A \ B"  haftmann@30531  2454  apply (rule subset_antisym)  haftmann@30531  2455  apply (rule sup_least)  haftmann@30531  2456  apply (rule Un_upper1)  haftmann@30531  2457  apply (rule Un_upper2)  haftmann@30531  2458  apply (rule Un_least)  haftmann@30531  2459  apply (rule sup_ge1)  haftmann@30531  2460  apply (rule sup_ge2)  haftmann@30531  2461  done  haftmann@30531  2462` haftmann@30531