src/HOL/Set.thy
 author paulson Tue Aug 03 13:48:00 2004 +0200 (2004-08-03) changeset 15102 04b0e943fcc9 parent 14981 e73f8140af78 child 15120 f0359f75682e permissions -rw-r--r--
new simprules Int_subset_iff and Un_subset_iff
     1 (*  Title:      HOL/Set.thy

     2     ID:         $Id$

     3     Author:     Tobias Nipkow, Lawrence C Paulson and Markus Wenzel

     4 *)

     5

     6 header {* Set theory for higher-order logic *}

     7

     8 theory Set = HOL:

     9

    10 text {* A set in HOL is simply a predicate. *}

    11

    12

    13 subsection {* Basic syntax *}

    14

    15 global

    16

    17 typedecl 'a set

    18 arities set :: (type) type

    19

    20 consts

    21   "{}"          :: "'a set"                             ("{}")

    22   UNIV          :: "'a set"

    23   insert        :: "'a => 'a set => 'a set"

    24   Collect       :: "('a => bool) => 'a set"              -- "comprehension"

    25   Int           :: "'a set => 'a set => 'a set"          (infixl 70)

    26   Un            :: "'a set => 'a set => 'a set"          (infixl 65)

    27   UNION         :: "'a set => ('a => 'b set) => 'b set"  -- "general union"

    28   INTER         :: "'a set => ('a => 'b set) => 'b set"  -- "general intersection"

    29   Union         :: "'a set set => 'a set"                -- "union of a set"

    30   Inter         :: "'a set set => 'a set"                -- "intersection of a set"

    31   Pow           :: "'a set => 'a set set"                -- "powerset"

    32   Ball          :: "'a set => ('a => bool) => bool"      -- "bounded universal quantifiers"

    33   Bex           :: "'a set => ('a => bool) => bool"      -- "bounded existential quantifiers"

    34   image         :: "('a => 'b) => 'a set => 'b set"      (infixr "" 90)

    35

    36 syntax

    37   "op :"        :: "'a => 'a set => bool"                ("op :")

    38 consts

    39   "op :"        :: "'a => 'a set => bool"                ("(_/ : _)" [50, 51] 50)  -- "membership"

    40

    41 local

    42

    43 instance set :: (type) "{ord, minus}" ..

    44

    45

    46 subsection {* Additional concrete syntax *}

    47

    48 syntax

    49   range         :: "('a => 'b) => 'b set"             -- "of function"

    50

    51   "op ~:"       :: "'a => 'a set => bool"                 ("op ~:")  -- "non-membership"

    52   "op ~:"       :: "'a => 'a set => bool"                 ("(_/ ~: _)" [50, 51] 50)

    53

    54   "@Finset"     :: "args => 'a set"                       ("{(_)}")

    55   "@Coll"       :: "pttrn => bool => 'a set"              ("(1{_./ _})")

    56   "@SetCompr"   :: "'a => idts => bool => 'a set"         ("(1{_ |/_./ _})")

    57

    58   "@INTER1"     :: "pttrns => 'b set => 'b set"           ("(3INT _./ _)" 10)

    59   "@UNION1"     :: "pttrns => 'b set => 'b set"           ("(3UN _./ _)" 10)

    60   "@INTER"      :: "pttrn => 'a set => 'b set => 'b set"  ("(3INT _:_./ _)" 10)

    61   "@UNION"      :: "pttrn => 'a set => 'b set => 'b set"  ("(3UN _:_./ _)" 10)

    62

    63   "_Ball"       :: "pttrn => 'a set => bool => bool"      ("(3ALL _:_./ _)" [0, 0, 10] 10)

    64   "_Bex"        :: "pttrn => 'a set => bool => bool"      ("(3EX _:_./ _)" [0, 0, 10] 10)

    65

    66 syntax (HOL)

    67   "_Ball"       :: "pttrn => 'a set => bool => bool"      ("(3! _:_./ _)" [0, 0, 10] 10)

    68   "_Bex"        :: "pttrn => 'a set => bool => bool"      ("(3? _:_./ _)" [0, 0, 10] 10)

    69

    70 translations

    71   "range f"     == "fUNIV"

    72   "x ~: y"      == "~ (x : y)"

    73   "{x, xs}"     == "insert x {xs}"

    74   "{x}"         == "insert x {}"

    75   "{x. P}"      == "Collect (%x. P)"

    76   "UN x y. B"   == "UN x. UN y. B"

    77   "UN x. B"     == "UNION UNIV (%x. B)"

    78   "UN x. B"     == "UN x:UNIV. B"

    79   "INT x y. B"  == "INT x. INT y. B"

    80   "INT x. B"    == "INTER UNIV (%x. B)"

    81   "INT x. B"    == "INT x:UNIV. B"

    82   "UN x:A. B"   == "UNION A (%x. B)"

    83   "INT x:A. B"  == "INTER A (%x. B)"

    84   "ALL x:A. P"  == "Ball A (%x. P)"

    85   "EX x:A. P"   == "Bex A (%x. P)"

    86

    87 syntax (output)

    88   "_setle"      :: "'a set => 'a set => bool"             ("op <=")

    89   "_setle"      :: "'a set => 'a set => bool"             ("(_/ <= _)" [50, 51] 50)

    90   "_setless"    :: "'a set => 'a set => bool"             ("op <")

    91   "_setless"    :: "'a set => 'a set => bool"             ("(_/ < _)" [50, 51] 50)

    92

    93 syntax (xsymbols)

    94   "_setle"      :: "'a set => 'a set => bool"             ("op \<subseteq>")

    95   "_setle"      :: "'a set => 'a set => bool"             ("(_/ \<subseteq> _)" [50, 51] 50)

    96   "_setless"    :: "'a set => 'a set => bool"             ("op \<subset>")

    97   "_setless"    :: "'a set => 'a set => bool"             ("(_/ \<subset> _)" [50, 51] 50)

    98   "op Int"      :: "'a set => 'a set => 'a set"           (infixl "\<inter>" 70)

    99   "op Un"       :: "'a set => 'a set => 'a set"           (infixl "\<union>" 65)

   100   "op :"        :: "'a => 'a set => bool"                 ("op \<in>")

   101   "op :"        :: "'a => 'a set => bool"                 ("(_/ \<in> _)" [50, 51] 50)

   102   "op ~:"       :: "'a => 'a set => bool"                 ("op \<notin>")

   103   "op ~:"       :: "'a => 'a set => bool"                 ("(_/ \<notin> _)" [50, 51] 50)

   104   Union         :: "'a set set => 'a set"                 ("\<Union>_" [90] 90)

   105   Inter         :: "'a set set => 'a set"                 ("\<Inter>_" [90] 90)

   106   "_Ball"       :: "pttrn => 'a set => bool => bool"      ("(3\<forall>_\<in>_./ _)" [0, 0, 10] 10)

   107   "_Bex"        :: "pttrn => 'a set => bool => bool"      ("(3\<exists>_\<in>_./ _)" [0, 0, 10] 10)

   108

   109 syntax (HTML output)

   110   "_setle"      :: "'a set => 'a set => bool"             ("op \<subseteq>")

   111   "_setle"      :: "'a set => 'a set => bool"             ("(_/ \<subseteq> _)" [50, 51] 50)

   112   "_setless"    :: "'a set => 'a set => bool"             ("op \<subset>")

   113   "_setless"    :: "'a set => 'a set => bool"             ("(_/ \<subset> _)" [50, 51] 50)

   114   "op Int"      :: "'a set => 'a set => 'a set"           (infixl "\<inter>" 70)

   115   "op Un"       :: "'a set => 'a set => 'a set"           (infixl "\<union>" 65)

   116   "op :"        :: "'a => 'a set => bool"                 ("op \<in>")

   117   "op :"        :: "'a => 'a set => bool"                 ("(_/ \<in> _)" [50, 51] 50)

   118   "op ~:"       :: "'a => 'a set => bool"                 ("op \<notin>")

   119   "op ~:"       :: "'a => 'a set => bool"                 ("(_/ \<notin> _)" [50, 51] 50)

   120   "_Ball"       :: "pttrn => 'a set => bool => bool"      ("(3\<forall>_\<in>_./ _)" [0, 0, 10] 10)

   121   "_Bex"        :: "pttrn => 'a set => bool => bool"      ("(3\<exists>_\<in>_./ _)" [0, 0, 10] 10)

   122

   123 syntax (input)

   124   "@UNION1"     :: "pttrns => 'b set => 'b set"           ("(3\<Union>_./ _)" 10)

   125   "@INTER1"     :: "pttrns => 'b set => 'b set"           ("(3\<Inter>_./ _)" 10)

   126   "@UNION"      :: "pttrn => 'a set => 'b set => 'b set"  ("(3\<Union>_\<in>_./ _)" 10)

   127   "@INTER"      :: "pttrn => 'a set => 'b set => 'b set"  ("(3\<Inter>_\<in>_./ _)" 10)

   128

   129 syntax (xsymbols)

   130   "@UNION1"     :: "pttrns => 'b set => 'b set"           ("(3\<Union>(00\<^bsub>_\<^esub>)/ _)" 10)

   131   "@INTER1"     :: "pttrns => 'b set => 'b set"           ("(3\<Inter>(00\<^bsub>_\<^esub>)/ _)" 10)

   132   "@UNION"      :: "pttrn => 'a set => 'b set => 'b set"  ("(3\<Union>(00\<^bsub>_\<in>_\<^esub>)/ _)" 10)

   133   "@INTER"      :: "pttrn => 'a set => 'b set => 'b set"  ("(3\<Inter>(00\<^bsub>_\<in>_\<^esub>)/ _)" 10)

   134

   135

   136 translations

   137   "op \<subseteq>" => "op <= :: _ set => _ set => bool"

   138   "op \<subset>" => "op <  :: _ set => _ set => bool"

   139

   140 typed_print_translation {*

   141   let

   142     fun le_tr' _ (Type ("fun", (Type ("set", _) :: _))) ts =

   143           list_comb (Syntax.const "_setle", ts)

   144       | le_tr' _ _ _ = raise Match;

   145

   146     fun less_tr' _ (Type ("fun", (Type ("set", _) :: _))) ts =

   147           list_comb (Syntax.const "_setless", ts)

   148       | less_tr' _ _ _ = raise Match;

   149   in [("op <=", le_tr'), ("op <", less_tr')] end

   150 *}

   151

   152

   153 subsubsection "Bounded quantifiers"

   154

   155 syntax

   156   "_setlessAll" :: "[idt, 'a, bool] => bool"  ("(3ALL _<_./ _)"  [0, 0, 10] 10)

   157   "_setlessEx"  :: "[idt, 'a, bool] => bool"  ("(3EX _<_./ _)"  [0, 0, 10] 10)

   158   "_setleAll"   :: "[idt, 'a, bool] => bool"  ("(3ALL _<=_./ _)" [0, 0, 10] 10)

   159   "_setleEx"    :: "[idt, 'a, bool] => bool"  ("(3EX _<=_./ _)" [0, 0, 10] 10)

   160

   161 syntax (xsymbols)

   162   "_setlessAll" :: "[idt, 'a, bool] => bool"   ("(3\<forall>_\<subset>_./ _)"  [0, 0, 10] 10)

   163   "_setlessEx"  :: "[idt, 'a, bool] => bool"   ("(3\<exists>_\<subset>_./ _)"  [0, 0, 10] 10)

   164   "_setleAll"   :: "[idt, 'a, bool] => bool"   ("(3\<forall>_\<subseteq>_./ _)" [0, 0, 10] 10)

   165   "_setleEx"    :: "[idt, 'a, bool] => bool"   ("(3\<exists>_\<subseteq>_./ _)" [0, 0, 10] 10)

   166

   167 syntax (HOL)

   168   "_setlessAll" :: "[idt, 'a, bool] => bool"   ("(3! _<_./ _)"  [0, 0, 10] 10)

   169   "_setlessEx"  :: "[idt, 'a, bool] => bool"   ("(3? _<_./ _)"  [0, 0, 10] 10)

   170   "_setleAll"   :: "[idt, 'a, bool] => bool"   ("(3! _<=_./ _)" [0, 0, 10] 10)

   171   "_setleEx"    :: "[idt, 'a, bool] => bool"   ("(3? _<=_./ _)" [0, 0, 10] 10)

   172

   173 syntax (HTML output)

   174   "_setlessAll" :: "[idt, 'a, bool] => bool"   ("(3\<forall>_\<subset>_./ _)"  [0, 0, 10] 10)

   175   "_setlessEx"  :: "[idt, 'a, bool] => bool"   ("(3\<exists>_\<subset>_./ _)"  [0, 0, 10] 10)

   176   "_setleAll"   :: "[idt, 'a, bool] => bool"   ("(3\<forall>_\<subseteq>_./ _)" [0, 0, 10] 10)

   177   "_setleEx"    :: "[idt, 'a, bool] => bool"   ("(3\<exists>_\<subseteq>_./ _)" [0, 0, 10] 10)

   178

   179 translations

   180  "\<forall>A\<subset>B. P"   =>  "ALL A. A \<subset> B --> P"

   181  "\<exists>A\<subset>B. P"    =>  "EX A. A \<subset> B & P"

   182  "\<forall>A\<subseteq>B. P"  =>  "ALL A. A \<subseteq> B --> P"

   183  "\<exists>A\<subseteq>B. P"   =>  "EX A. A \<subseteq> B & P"

   184

   185 print_translation {*

   186 let

   187   fun

   188     all_tr' [Const ("_bound",_) $Free (v,Type(T,_)),   189 Const("op -->",_)$ (Const ("op <",_) $(Const ("_bound",_)$ Free (v',_)) $n )$ P] =

   190   (if v=v' andalso T="set"

   191    then Syntax.const "_setlessAll" $Syntax.mark_bound v'$ n $P   192 else raise Match)   193   194 | all_tr' [Const ("_bound",_)$ Free (v,Type(T,_)),

   195              Const("op -->",_) $(Const ("op <=",_)$ (Const ("_bound",_) $Free (v',_))$ n ) $P] =   196 (if v=v' andalso T="set"   197 then Syntax.const "_setleAll"$ Syntax.mark_bound v' $n$ P

   198    else raise Match);

   199

   200   fun

   201     ex_tr' [Const ("_bound",_) $Free (v,Type(T,_)),   202 Const("op &",_)$ (Const ("op <",_) $(Const ("_bound",_)$ Free (v',_)) $n )$ P] =

   203   (if v=v' andalso T="set"

   204    then Syntax.const "_setlessEx" $Syntax.mark_bound v'$ n $P   205 else raise Match)   206   207 | ex_tr' [Const ("_bound",_)$ Free (v,Type(T,_)),

   208             Const("op &",_) $(Const ("op <=",_)$ (Const ("_bound",_) $Free (v',_))$ n ) $P] =   209 (if v=v' andalso T="set"   210 then Syntax.const "_setleEx"$ Syntax.mark_bound v' $n$ P

   211    else raise Match)

   212 in

   213 [("ALL ", all_tr'), ("EX ", ex_tr')]

   214 end

   215 *}

   216

   217

   218

   219 text {*

   220   \medskip Translate between @{text "{e | x1...xn. P}"} and @{text

   221   "{u. EX x1..xn. u = e & P}"}; @{text "{y. EX x1..xn. y = e & P}"} is

   222   only translated if @{text "[0..n] subset bvs(e)"}.

   223 *}

   224

   225 parse_translation {*

   226   let

   227     val ex_tr = snd (mk_binder_tr ("EX ", "Ex"));

   228

   229     fun nvars (Const ("_idts", _) $_$ idts) = nvars idts + 1

   230       | nvars _ = 1;

   231

   232     fun setcompr_tr [e, idts, b] =

   233       let

   234         val eq = Syntax.const "op =" $Bound (nvars idts)$ e;

   235         val P = Syntax.const "op &" $eq$ b;

   236         val exP = ex_tr [idts, P];

   237       in Syntax.const "Collect" $Abs ("", dummyT, exP) end;   238   239 in [("@SetCompr", setcompr_tr)] end;   240 *}   241   242 (* To avoid eta-contraction of body: *)   243 print_translation {*   244 let   245 fun btr' syn [A,Abs abs] =   246 let val (x,t) = atomic_abs_tr' abs   247 in Syntax.const syn$ x $A$ t end

   248 in

   249 [("Ball", btr' "_Ball"),("Bex", btr' "_Bex"),

   250  ("UNION", btr' "@UNION"),("INTER", btr' "@INTER")]

   251 end

   252 *}

   253

   254 print_translation {*

   255 let

   256   val ex_tr' = snd (mk_binder_tr' ("Ex", "DUMMY"));

   257

   258   fun setcompr_tr' [Abs (abs as (_, _, P))] =

   259     let

   260       fun check (Const ("Ex", _) $Abs (_, _, P), n) = check (P, n + 1)   261 | check (Const ("op &", _)$ (Const ("op =", _) $Bound m$ e) $P, n) =   262 n > 0 andalso m = n andalso not (loose_bvar1 (P, n)) andalso   263 ((0 upto (n - 1)) subset add_loose_bnos (e, 0, []))   264 | check _ = false   265   266 fun tr' (_$ abs) =

   267           let val _ $idts$ (_ $(_$ _ $e)$ Q) = ex_tr' [abs]

   268           in Syntax.const "@SetCompr" $e$ idts $Q end;   269 in if check (P, 0) then tr' P   270 else let val (x,t) = atomic_abs_tr' abs   271 in Syntax.const "@Coll"$ x \$ t end

   272     end;

   273   in [("Collect", setcompr_tr')] end;

   274 *}

   275

   276

   277 subsection {* Rules and definitions *}

   278

   279 text {* Isomorphisms between predicates and sets. *}

   280

   281 axioms

   282   mem_Collect_eq [iff]: "(a : {x. P(x)}) = P(a)"

   283   Collect_mem_eq [simp]: "{x. x:A} = A"

   284

   285 defs

   286   Ball_def:     "Ball A P       == ALL x. x:A --> P(x)"

   287   Bex_def:      "Bex A P        == EX x. x:A & P(x)"

   288

   289 defs (overloaded)

   290   subset_def:   "A <= B         == ALL x:A. x:B"

   291   psubset_def:  "A < B          == (A::'a set) <= B & ~ A=B"

   292   Compl_def:    "- A            == {x. ~x:A}"

   293   set_diff_def: "A - B          == {x. x:A & ~x:B}"

   294

   295 defs

   296   Un_def:       "A Un B         == {x. x:A | x:B}"

   297   Int_def:      "A Int B        == {x. x:A & x:B}"

   298   INTER_def:    "INTER A B      == {y. ALL x:A. y: B(x)}"

   299   UNION_def:    "UNION A B      == {y. EX x:A. y: B(x)}"

   300   Inter_def:    "Inter S        == (INT x:S. x)"

   301   Union_def:    "Union S        == (UN x:S. x)"

   302   Pow_def:      "Pow A          == {B. B <= A}"

   303   empty_def:    "{}             == {x. False}"

   304   UNIV_def:     "UNIV           == {x. True}"

   305   insert_def:   "insert a B     == {x. x=a} Un B"

   306   image_def:    "fA            == {y. EX x:A. y = f(x)}"

   307

   308

   309 subsection {* Lemmas and proof tool setup *}

   310

   311 subsubsection {* Relating predicates and sets *}

   312

   313 lemma CollectI: "P(a) ==> a : {x. P(x)}"

   314   by simp

   315

   316 lemma CollectD: "a : {x. P(x)} ==> P(a)"

   317   by simp

   318

   319 lemma Collect_cong: "(!!x. P x = Q x) ==> {x. P(x)} = {x. Q(x)}"

   320   by simp

   321

   322 lemmas CollectE = CollectD [elim_format]

   323

   324

   325 subsubsection {* Bounded quantifiers *}

   326

   327 lemma ballI [intro!]: "(!!x. x:A ==> P x) ==> ALL x:A. P x"

   328   by (simp add: Ball_def)

   329

   330 lemmas strip = impI allI ballI

   331

   332 lemma bspec [dest?]: "ALL x:A. P x ==> x:A ==> P x"

   333   by (simp add: Ball_def)

   334

   335 lemma ballE [elim]: "ALL x:A. P x ==> (P x ==> Q) ==> (x ~: A ==> Q) ==> Q"

   336   by (unfold Ball_def) blast

   337 ML {* bind_thm("rev_ballE",permute_prems 1 1 (thm "ballE")) *}

   338

   339 text {*

   340   \medskip This tactic takes assumptions @{prop "ALL x:A. P x"} and

   341   @{prop "a:A"}; creates assumption @{prop "P a"}.

   342 *}

   343

   344 ML {*

   345   local val ballE = thm "ballE"

   346   in fun ball_tac i = etac ballE i THEN contr_tac (i + 1) end;

   347 *}

   348

   349 text {*

   350   Gives better instantiation for bound:

   351 *}

   352

   353 ML_setup {*

   354   claset_ref() := claset() addbefore ("bspec", datac (thm "bspec") 1);

   355 *}

   356

   357 lemma bexI [intro]: "P x ==> x:A ==> EX x:A. P x"

   358   -- {* Normally the best argument order: @{prop "P x"} constrains the

   359     choice of @{prop "x:A"}. *}

   360   by (unfold Bex_def) blast

   361

   362 lemma rev_bexI [intro?]: "x:A ==> P x ==> EX x:A. P x"

   363   -- {* The best argument order when there is only one @{prop "x:A"}. *}

   364   by (unfold Bex_def) blast

   365

   366 lemma bexCI: "(ALL x:A. ~P x ==> P a) ==> a:A ==> EX x:A. P x"

   367   by (unfold Bex_def) blast

   368

   369 lemma bexE [elim!]: "EX x:A. P x ==> (!!x. x:A ==> P x ==> Q) ==> Q"

   370   by (unfold Bex_def) blast

   371

   372 lemma ball_triv [simp]: "(ALL x:A. P) = ((EX x. x:A) --> P)"

   373   -- {* Trival rewrite rule. *}

   374   by (simp add: Ball_def)

   375

   376 lemma bex_triv [simp]: "(EX x:A. P) = ((EX x. x:A) & P)"

   377   -- {* Dual form for existentials. *}

   378   by (simp add: Bex_def)

   379

   380 lemma bex_triv_one_point1 [simp]: "(EX x:A. x = a) = (a:A)"

   381   by blast

   382

   383 lemma bex_triv_one_point2 [simp]: "(EX x:A. a = x) = (a:A)"

   384   by blast

   385

   386 lemma bex_one_point1 [simp]: "(EX x:A. x = a & P x) = (a:A & P a)"

   387   by blast

   388

   389 lemma bex_one_point2 [simp]: "(EX x:A. a = x & P x) = (a:A & P a)"

   390   by blast

   391

   392 lemma ball_one_point1 [simp]: "(ALL x:A. x = a --> P x) = (a:A --> P a)"

   393   by blast

   394

   395 lemma ball_one_point2 [simp]: "(ALL x:A. a = x --> P x) = (a:A --> P a)"

   396   by blast

   397

   398 ML_setup {*

   399   local

   400     val Ball_def = thm "Ball_def";

   401     val Bex_def = thm "Bex_def";

   402

   403     val prove_bex_tac =

   404       rewrite_goals_tac [Bex_def] THEN Quantifier1.prove_one_point_ex_tac;

   405     val rearrange_bex = Quantifier1.rearrange_bex prove_bex_tac;

   406

   407     val prove_ball_tac =

   408       rewrite_goals_tac [Ball_def] THEN Quantifier1.prove_one_point_all_tac;

   409     val rearrange_ball = Quantifier1.rearrange_ball prove_ball_tac;

   410   in

   411     val defBEX_regroup = Simplifier.simproc (Theory.sign_of (the_context ()))

   412       "defined BEX" ["EX x:A. P x & Q x"] rearrange_bex;

   413     val defBALL_regroup = Simplifier.simproc (Theory.sign_of (the_context ()))

   414       "defined BALL" ["ALL x:A. P x --> Q x"] rearrange_ball;

   415   end;

   416

   417   Addsimprocs [defBALL_regroup, defBEX_regroup];

   418 *}

   419

   420

   421 subsubsection {* Congruence rules *}

   422

   423 lemma ball_cong [cong]:

   424   "A = B ==> (!!x. x:B ==> P x = Q x) ==>

   425     (ALL x:A. P x) = (ALL x:B. Q x)"

   426   by (simp add: Ball_def)

   427

   428 lemma bex_cong [cong]:

   429   "A = B ==> (!!x. x:B ==> P x = Q x) ==>

   430     (EX x:A. P x) = (EX x:B. Q x)"

   431   by (simp add: Bex_def cong: conj_cong)

   432

   433

   434 subsubsection {* Subsets *}

   435

   436 lemma subsetI [intro!]: "(!!x. x:A ==> x:B) ==> A \<subseteq> B"

   437   by (simp add: subset_def)

   438

   439 text {*

   440   \medskip Map the type @{text "'a set => anything"} to just @{typ

   441   'a}; for overloading constants whose first argument has type @{typ

   442   "'a set"}.

   443 *}

   444

   445 lemma subsetD [elim]: "A \<subseteq> B ==> c \<in> A ==> c \<in> B"

   446   -- {* Rule in Modus Ponens style. *}

   447   by (unfold subset_def) blast

   448

   449 declare subsetD [intro?] -- FIXME

   450

   451 lemma rev_subsetD: "c \<in> A ==> A \<subseteq> B ==> c \<in> B"

   452   -- {* The same, with reversed premises for use with @{text erule} --

   453       cf @{text rev_mp}. *}

   454   by (rule subsetD)

   455

   456 declare rev_subsetD [intro?] -- FIXME

   457

   458 text {*

   459   \medskip Converts @{prop "A \<subseteq> B"} to @{prop "x \<in> A ==> x \<in> B"}.

   460 *}

   461

   462 ML {*

   463   local val rev_subsetD = thm "rev_subsetD"

   464   in fun impOfSubs th = th RSN (2, rev_subsetD) end;

   465 *}

   466

   467 lemma subsetCE [elim]: "A \<subseteq>  B ==> (c \<notin> A ==> P) ==> (c \<in> B ==> P) ==> P"

   468   -- {* Classical elimination rule. *}

   469   by (unfold subset_def) blast

   470

   471 text {*

   472   \medskip Takes assumptions @{prop "A \<subseteq> B"}; @{prop "c \<in> A"} and

   473   creates the assumption @{prop "c \<in> B"}.

   474 *}

   475

   476 ML {*

   477   local val subsetCE = thm "subsetCE"

   478   in fun set_mp_tac i = etac subsetCE i THEN mp_tac i end;

   479 *}

   480

   481 lemma contra_subsetD: "A \<subseteq> B ==> c \<notin> B ==> c \<notin> A"

   482   by blast

   483

   484 lemma subset_refl: "A \<subseteq> A"

   485   by fast

   486

   487 lemma subset_trans: "A \<subseteq> B ==> B \<subseteq> C ==> A \<subseteq> C"

   488   by blast

   489

   490

   491 subsubsection {* Equality *}

   492

   493 lemma set_ext: assumes prem: "(!!x. (x:A) = (x:B))" shows "A = B"

   494   apply (rule prem [THEN ext, THEN arg_cong, THEN box_equals])

   495    apply (rule Collect_mem_eq)

   496   apply (rule Collect_mem_eq)

   497   done

   498

   499 lemma subset_antisym [intro!]: "A \<subseteq> B ==> B \<subseteq> A ==> A = B"

   500   -- {* Anti-symmetry of the subset relation. *}

   501   by (rules intro: set_ext subsetD)

   502

   503 lemmas equalityI [intro!] = subset_antisym

   504

   505 text {*

   506   \medskip Equality rules from ZF set theory -- are they appropriate

   507   here?

   508 *}

   509

   510 lemma equalityD1: "A = B ==> A \<subseteq> B"

   511   by (simp add: subset_refl)

   512

   513 lemma equalityD2: "A = B ==> B \<subseteq> A"

   514   by (simp add: subset_refl)

   515

   516 text {*

   517   \medskip Be careful when adding this to the claset as @{text

   518   subset_empty} is in the simpset: @{prop "A = {}"} goes to @{prop "{}

   519   \<subseteq> A"} and @{prop "A \<subseteq> {}"} and then back to @{prop "A = {}"}!

   520 *}

   521

   522 lemma equalityE: "A = B ==> (A \<subseteq> B ==> B \<subseteq> A ==> P) ==> P"

   523   by (simp add: subset_refl)

   524

   525 lemma equalityCE [elim]:

   526     "A = B ==> (c \<in> A ==> c \<in> B ==> P) ==> (c \<notin> A ==> c \<notin> B ==> P) ==> P"

   527   by blast

   528

   529 text {*

   530   \medskip Lemma for creating induction formulae -- for "pattern

   531   matching" on @{text p}.  To make the induction hypotheses usable,

   532   apply @{text spec} or @{text bspec} to put universal quantifiers over the free

   533   variables in @{text p}.

   534 *}

   535

   536 lemma setup_induction: "p:A ==> (!!z. z:A ==> p = z --> R) ==> R"

   537   by simp

   538

   539 lemma eqset_imp_iff: "A = B ==> (x : A) = (x : B)"

   540   by simp

   541

   542 lemma eqelem_imp_iff: "x = y ==> (x : A) = (y : A)"

   543   by simp

   544

   545

   546 subsubsection {* The universal set -- UNIV *}

   547

   548 lemma UNIV_I [simp]: "x : UNIV"

   549   by (simp add: UNIV_def)

   550

   551 declare UNIV_I [intro]  -- {* unsafe makes it less likely to cause problems *}

   552

   553 lemma UNIV_witness [intro?]: "EX x. x : UNIV"

   554   by simp

   555

   556 lemma subset_UNIV: "A \<subseteq> UNIV"

   557   by (rule subsetI) (rule UNIV_I)

   558

   559 text {*

   560   \medskip Eta-contracting these two rules (to remove @{text P})

   561   causes them to be ignored because of their interaction with

   562   congruence rules.

   563 *}

   564

   565 lemma ball_UNIV [simp]: "Ball UNIV P = All P"

   566   by (simp add: Ball_def)

   567

   568 lemma bex_UNIV [simp]: "Bex UNIV P = Ex P"

   569   by (simp add: Bex_def)

   570

   571

   572 subsubsection {* The empty set *}

   573

   574 lemma empty_iff [simp]: "(c : {}) = False"

   575   by (simp add: empty_def)

   576

   577 lemma emptyE [elim!]: "a : {} ==> P"

   578   by simp

   579

   580 lemma empty_subsetI [iff]: "{} \<subseteq> A"

   581     -- {* One effect is to delete the ASSUMPTION @{prop "{} <= A"} *}

   582   by blast

   583

   584 lemma equals0I: "(!!y. y \<in> A ==> False) ==> A = {}"

   585   by blast

   586

   587 lemma equals0D: "A = {} ==> a \<notin> A"

   588     -- {* Use for reasoning about disjointness: @{prop "A Int B = {}"} *}

   589   by blast

   590

   591 lemma ball_empty [simp]: "Ball {} P = True"

   592   by (simp add: Ball_def)

   593

   594 lemma bex_empty [simp]: "Bex {} P = False"

   595   by (simp add: Bex_def)

   596

   597 lemma UNIV_not_empty [iff]: "UNIV ~= {}"

   598   by (blast elim: equalityE)

   599

   600

   601 subsubsection {* The Powerset operator -- Pow *}

   602

   603 lemma Pow_iff [iff]: "(A \<in> Pow B) = (A \<subseteq> B)"

   604   by (simp add: Pow_def)

   605

   606 lemma PowI: "A \<subseteq> B ==> A \<in> Pow B"

   607   by (simp add: Pow_def)

   608

   609 lemma PowD: "A \<in> Pow B ==> A \<subseteq> B"

   610   by (simp add: Pow_def)

   611

   612 lemma Pow_bottom: "{} \<in> Pow B"

   613   by simp

   614

   615 lemma Pow_top: "A \<in> Pow A"

   616   by (simp add: subset_refl)

   617

   618

   619 subsubsection {* Set complement *}

   620

   621 lemma Compl_iff [simp]: "(c \<in> -A) = (c \<notin> A)"

   622   by (unfold Compl_def) blast

   623

   624 lemma ComplI [intro!]: "(c \<in> A ==> False) ==> c \<in> -A"

   625   by (unfold Compl_def) blast

   626

   627 text {*

   628   \medskip This form, with negated conclusion, works well with the

   629   Classical prover.  Negated assumptions behave like formulae on the

   630   right side of the notional turnstile ... *}

   631

   632 lemma ComplD: "c : -A ==> c~:A"

   633   by (unfold Compl_def) blast

   634

   635 lemmas ComplE [elim!] = ComplD [elim_format]

   636

   637

   638 subsubsection {* Binary union -- Un *}

   639

   640 lemma Un_iff [simp]: "(c : A Un B) = (c:A | c:B)"

   641   by (unfold Un_def) blast

   642

   643 lemma UnI1 [elim?]: "c:A ==> c : A Un B"

   644   by simp

   645

   646 lemma UnI2 [elim?]: "c:B ==> c : A Un B"

   647   by simp

   648

   649 text {*

   650   \medskip Classical introduction rule: no commitment to @{prop A} vs

   651   @{prop B}.

   652 *}

   653

   654 lemma UnCI [intro!]: "(c~:B ==> c:A) ==> c : A Un B"

   655   by auto

   656

   657 lemma UnE [elim!]: "c : A Un B ==> (c:A ==> P) ==> (c:B ==> P) ==> P"

   658   by (unfold Un_def) blast

   659

   660

   661 subsubsection {* Binary intersection -- Int *}

   662

   663 lemma Int_iff [simp]: "(c : A Int B) = (c:A & c:B)"

   664   by (unfold Int_def) blast

   665

   666 lemma IntI [intro!]: "c:A ==> c:B ==> c : A Int B"

   667   by simp

   668

   669 lemma IntD1: "c : A Int B ==> c:A"

   670   by simp

   671

   672 lemma IntD2: "c : A Int B ==> c:B"

   673   by simp

   674

   675 lemma IntE [elim!]: "c : A Int B ==> (c:A ==> c:B ==> P) ==> P"

   676   by simp

   677

   678

   679 subsubsection {* Set difference *}

   680

   681 lemma Diff_iff [simp]: "(c : A - B) = (c:A & c~:B)"

   682   by (unfold set_diff_def) blast

   683

   684 lemma DiffI [intro!]: "c : A ==> c ~: B ==> c : A - B"

   685   by simp

   686

   687 lemma DiffD1: "c : A - B ==> c : A"

   688   by simp

   689

   690 lemma DiffD2: "c : A - B ==> c : B ==> P"

   691   by simp

   692

   693 lemma DiffE [elim!]: "c : A - B ==> (c:A ==> c~:B ==> P) ==> P"

   694   by simp

   695

   696

   697 subsubsection {* Augmenting a set -- insert *}

   698

   699 lemma insert_iff [simp]: "(a : insert b A) = (a = b | a:A)"

   700   by (unfold insert_def) blast

   701

   702 lemma insertI1: "a : insert a B"

   703   by simp

   704

   705 lemma insertI2: "a : B ==> a : insert b B"

   706   by simp

   707

   708 lemma insertE [elim!]: "a : insert b A ==> (a = b ==> P) ==> (a:A ==> P) ==> P"

   709   by (unfold insert_def) blast

   710

   711 lemma insertCI [intro!]: "(a~:B ==> a = b) ==> a: insert b B"

   712   -- {* Classical introduction rule. *}

   713   by auto

   714

   715 lemma subset_insert_iff: "(A \<subseteq> insert x B) = (if x:A then A - {x} \<subseteq> B else A \<subseteq> B)"

   716   by auto

   717

   718

   719 subsubsection {* Singletons, using insert *}

   720

   721 lemma singletonI [intro!]: "a : {a}"

   722     -- {* Redundant? But unlike @{text insertCI}, it proves the subgoal immediately! *}

   723   by (rule insertI1)

   724

   725 lemma singletonD: "b : {a} ==> b = a"

   726   by blast

   727

   728 lemmas singletonE [elim!] = singletonD [elim_format]

   729

   730 lemma singleton_iff: "(b : {a}) = (b = a)"

   731   by blast

   732

   733 lemma singleton_inject [dest!]: "{a} = {b} ==> a = b"

   734   by blast

   735

   736 lemma singleton_insert_inj_eq [iff]: "({b} = insert a A) = (a = b & A \<subseteq> {b})"

   737   by blast

   738

   739 lemma singleton_insert_inj_eq' [iff]: "(insert a A = {b}) = (a = b & A \<subseteq> {b})"

   740   by blast

   741

   742 lemma subset_singletonD: "A \<subseteq> {x} ==> A = {} | A = {x}"

   743   by fast

   744

   745 lemma singleton_conv [simp]: "{x. x = a} = {a}"

   746   by blast

   747

   748 lemma singleton_conv2 [simp]: "{x. a = x} = {a}"

   749   by blast

   750

   751 lemma diff_single_insert: "A - {x} \<subseteq> B ==> x \<in> A ==> A \<subseteq> insert x B"

   752   by blast

   753

   754

   755 subsubsection {* Unions of families *}

   756

   757 text {*

   758   @{term [source] "UN x:A. B x"} is @{term "Union (BA)"}.

   759 *}

   760

   761 lemma UN_iff [simp]: "(b: (UN x:A. B x)) = (EX x:A. b: B x)"

   762   by (unfold UNION_def) blast

   763

   764 lemma UN_I [intro]: "a:A ==> b: B a ==> b: (UN x:A. B x)"

   765   -- {* The order of the premises presupposes that @{term A} is rigid;

   766     @{term b} may be flexible. *}

   767   by auto

   768

   769 lemma UN_E [elim!]: "b : (UN x:A. B x) ==> (!!x. x:A ==> b: B x ==> R) ==> R"

   770   by (unfold UNION_def) blast

   771

   772 lemma UN_cong [cong]:

   773     "A = B ==> (!!x. x:B ==> C x = D x) ==> (UN x:A. C x) = (UN x:B. D x)"

   774   by (simp add: UNION_def)

   775

   776

   777 subsubsection {* Intersections of families *}

   778

   779 text {* @{term [source] "INT x:A. B x"} is @{term "Inter (BA)"}. *}

   780

   781 lemma INT_iff [simp]: "(b: (INT x:A. B x)) = (ALL x:A. b: B x)"

   782   by (unfold INTER_def) blast

   783

   784 lemma INT_I [intro!]: "(!!x. x:A ==> b: B x) ==> b : (INT x:A. B x)"

   785   by (unfold INTER_def) blast

   786

   787 lemma INT_D [elim]: "b : (INT x:A. B x) ==> a:A ==> b: B a"

   788   by auto

   789

   790 lemma INT_E [elim]: "b : (INT x:A. B x) ==> (b: B a ==> R) ==> (a~:A ==> R) ==> R"

   791   -- {* "Classical" elimination -- by the Excluded Middle on @{prop "a:A"}. *}

   792   by (unfold INTER_def) blast

   793

   794 lemma INT_cong [cong]:

   795     "A = B ==> (!!x. x:B ==> C x = D x) ==> (INT x:A. C x) = (INT x:B. D x)"

   796   by (simp add: INTER_def)

   797

   798

   799 subsubsection {* Union *}

   800

   801 lemma Union_iff [simp]: "(A : Union C) = (EX X:C. A:X)"

   802   by (unfold Union_def) blast

   803

   804 lemma UnionI [intro]: "X:C ==> A:X ==> A : Union C"

   805   -- {* The order of the premises presupposes that @{term C} is rigid;

   806     @{term A} may be flexible. *}

   807   by auto

   808

   809 lemma UnionE [elim!]: "A : Union C ==> (!!X. A:X ==> X:C ==> R) ==> R"

   810   by (unfold Union_def) blast

   811

   812

   813 subsubsection {* Inter *}

   814

   815 lemma Inter_iff [simp]: "(A : Inter C) = (ALL X:C. A:X)"

   816   by (unfold Inter_def) blast

   817

   818 lemma InterI [intro!]: "(!!X. X:C ==> A:X) ==> A : Inter C"

   819   by (simp add: Inter_def)

   820

   821 text {*

   822   \medskip A destruct'' rule -- every @{term X} in @{term C}

   823   contains @{term A} as an element, but @{prop "A:X"} can hold when

   824   @{prop "X:C"} does not!  This rule is analogous to @{text spec}.

   825 *}

   826

   827 lemma InterD [elim]: "A : Inter C ==> X:C ==> A:X"

   828   by auto

   829

   830 lemma InterE [elim]: "A : Inter C ==> (X~:C ==> R) ==> (A:X ==> R) ==> R"

   831   -- {* Classical'' elimination rule -- does not require proving

   832     @{prop "X:C"}. *}

   833   by (unfold Inter_def) blast

   834

   835 text {*

   836   \medskip Image of a set under a function.  Frequently @{term b} does

   837   not have the syntactic form of @{term "f x"}.

   838 *}

   839

   840 lemma image_eqI [simp, intro]: "b = f x ==> x:A ==> b : fA"

   841   by (unfold image_def) blast

   842

   843 lemma imageI: "x : A ==> f x : f  A"

   844   by (rule image_eqI) (rule refl)

   845

   846 lemma rev_image_eqI: "x:A ==> b = f x ==> b : fA"

   847   -- {* This version's more effective when we already have the

   848     required @{term x}. *}

   849   by (unfold image_def) blast

   850

   851 lemma imageE [elim!]:

   852   "b : (%x. f x)A ==> (!!x. b = f x ==> x:A ==> P) ==> P"

   853   -- {* The eta-expansion gives variable-name preservation. *}

   854   by (unfold image_def) blast

   855

   856 lemma image_Un: "f(A Un B) = fA Un fB"

   857   by blast

   858

   859 lemma image_iff: "(z : fA) = (EX x:A. z = f x)"

   860   by blast

   861

   862 lemma image_subset_iff: "(fA \<subseteq> B) = (\<forall>x\<in>A. f x \<in> B)"

   863   -- {* This rewrite rule would confuse users if made default. *}

   864   by blast

   865

   866 lemma subset_image_iff: "(B \<subseteq> fA) = (EX AA. AA \<subseteq> A & B = fAA)"

   867   apply safe

   868    prefer 2 apply fast

   869   apply (rule_tac x = "{a. a : A & f a : B}" in exI, fast)

   870   done

   871

   872 lemma image_subsetI: "(!!x. x \<in> A ==> f x \<in> B) ==> fA \<subseteq> B"

   873   -- {* Replaces the three steps @{text subsetI}, @{text imageE},

   874     @{text hypsubst}, but breaks too many existing proofs. *}

   875   by blast

   876

   877 text {*

   878   \medskip Range of a function -- just a translation for image!

   879 *}

   880

   881 lemma range_eqI: "b = f x ==> b \<in> range f"

   882   by simp

   883

   884 lemma rangeI: "f x \<in> range f"

   885   by simp

   886

   887 lemma rangeE [elim?]: "b \<in> range (\<lambda>x. f x) ==> (!!x. b = f x ==> P) ==> P"

   888   by blast

   889

   890

   891 subsubsection {* Set reasoning tools *}

   892

   893 text {*

   894   Rewrite rules for boolean case-splitting: faster than @{text

   895   "split_if [split]"}.

   896 *}

   897

   898 lemma split_if_eq1: "((if Q then x else y) = b) = ((Q --> x = b) & (~ Q --> y = b))"

   899   by (rule split_if)

   900

   901 lemma split_if_eq2: "(a = (if Q then x else y)) = ((Q --> a = x) & (~ Q --> a = y))"

   902   by (rule split_if)

   903

   904 text {*

   905   Split ifs on either side of the membership relation.  Not for @{text

   906   "[simp]"} -- can cause goals to blow up!

   907 *}

   908

   909 lemma split_if_mem1: "((if Q then x else y) : b) = ((Q --> x : b) & (~ Q --> y : b))"

   910   by (rule split_if)

   911

   912 lemma split_if_mem2: "(a : (if Q then x else y)) = ((Q --> a : x) & (~ Q --> a : y))"

   913   by (rule split_if)

   914

   915 lemmas split_ifs = if_bool_eq_conj split_if_eq1 split_if_eq2 split_if_mem1 split_if_mem2

   916

   917 lemmas mem_simps =

   918   insert_iff empty_iff Un_iff Int_iff Compl_iff Diff_iff

   919   mem_Collect_eq UN_iff Union_iff INT_iff Inter_iff

   920   -- {* Each of these has ALREADY been added @{text "[simp]"} above. *}

   921

   922 (*Would like to add these, but the existing code only searches for the

   923   outer-level constant, which in this case is just "op :"; we instead need

   924   to use term-nets to associate patterns with rules.  Also, if a rule fails to

   925   apply, then the formula should be kept.

   926   [("uminus", Compl_iff RS iffD1), ("op -", [Diff_iff RS iffD1]),

   927    ("op Int", [IntD1,IntD2]),

   928    ("Collect", [CollectD]), ("Inter", [InterD]), ("INTER", [INT_D])]

   929  *)

   930

   931 ML_setup {*

   932   val mksimps_pairs = [("Ball", [thm "bspec"])] @ mksimps_pairs;

   933   simpset_ref() := simpset() setmksimps (mksimps mksimps_pairs);

   934 *}

   935

   936 declare subset_UNIV [simp] subset_refl [simp]

   937

   938

   939 subsubsection {* The proper subset'' relation *}

   940

   941 lemma psubsetI [intro!]: "A \<subseteq> B ==> A \<noteq> B ==> A \<subset> B"

   942   by (unfold psubset_def) blast

   943

   944 lemma psubsetE [elim!]:

   945     "[|A \<subset> B;  [|A \<subseteq> B; ~ (B\<subseteq>A)|] ==> R|] ==> R"

   946   by (unfold psubset_def) blast

   947

   948 lemma psubset_insert_iff:

   949   "(A \<subset> insert x B) = (if x \<in> B then A \<subset> B else if x \<in> A then A - {x} \<subset> B else A \<subseteq> B)"

   950   by (auto simp add: psubset_def subset_insert_iff)

   951

   952 lemma psubset_eq: "(A \<subset> B) = (A \<subseteq> B & A \<noteq> B)"

   953   by (simp only: psubset_def)

   954

   955 lemma psubset_imp_subset: "A \<subset> B ==> A \<subseteq> B"

   956   by (simp add: psubset_eq)

   957

   958 lemma psubset_trans: "[| A \<subset> B; B \<subset> C |] ==> A \<subset> C"

   959 apply (unfold psubset_def)

   960 apply (auto dest: subset_antisym)

   961 done

   962

   963 lemma psubsetD: "[| A \<subset> B; c \<in> A |] ==> c \<in> B"

   964 apply (unfold psubset_def)

   965 apply (auto dest: subsetD)

   966 done

   967

   968 lemma psubset_subset_trans: "A \<subset> B ==> B \<subseteq> C ==> A \<subset> C"

   969   by (auto simp add: psubset_eq)

   970

   971 lemma subset_psubset_trans: "A \<subseteq> B ==> B \<subset> C ==> A \<subset> C"

   972   by (auto simp add: psubset_eq)

   973

   974 lemma psubset_imp_ex_mem: "A \<subset> B ==> \<exists>b. b \<in> (B - A)"

   975   by (unfold psubset_def) blast

   976

   977 lemma atomize_ball:

   978     "(!!x. x \<in> A ==> P x) == Trueprop (\<forall>x\<in>A. P x)"

   979   by (simp only: Ball_def atomize_all atomize_imp)

   980

   981 declare atomize_ball [symmetric, rulify]

   982

   983

   984 subsection {* Further set-theory lemmas *}

   985

   986 subsubsection {* Derived rules involving subsets. *}

   987

   988 text {* @{text insert}. *}

   989

   990 lemma subset_insertI: "B \<subseteq> insert a B"

   991   apply (rule subsetI)

   992   apply (erule insertI2)

   993   done

   994

   995 lemma subset_insertI2: "A \<subseteq> B \<Longrightarrow> A \<subseteq> insert b B"

   996 by blast

   997

   998 lemma subset_insert: "x \<notin> A ==> (A \<subseteq> insert x B) = (A \<subseteq> B)"

   999   by blast

  1000

  1001

  1002 text {* \medskip Big Union -- least upper bound of a set. *}

  1003

  1004 lemma Union_upper: "B \<in> A ==> B \<subseteq> Union A"

  1005   by (rules intro: subsetI UnionI)

  1006

  1007 lemma Union_least: "(!!X. X \<in> A ==> X \<subseteq> C) ==> Union A \<subseteq> C"

  1008   by (rules intro: subsetI elim: UnionE dest: subsetD)

  1009

  1010

  1011 text {* \medskip General union. *}

  1012

  1013 lemma UN_upper: "a \<in> A ==> B a \<subseteq> (\<Union>x\<in>A. B x)"

  1014   by blast

  1015

  1016 lemma UN_least: "(!!x. x \<in> A ==> B x \<subseteq> C) ==> (\<Union>x\<in>A. B x) \<subseteq> C"

  1017   by (rules intro: subsetI elim: UN_E dest: subsetD)

  1018

  1019

  1020 text {* \medskip Big Intersection -- greatest lower bound of a set. *}

  1021

  1022 lemma Inter_lower: "B \<in> A ==> Inter A \<subseteq> B"

  1023   by blast

  1024

  1025 lemma Inter_subset:

  1026   "[| !!X. X \<in> A ==> X \<subseteq> B; A ~= {} |] ==> \<Inter>A \<subseteq> B"

  1027   by blast

  1028

  1029 lemma Inter_greatest: "(!!X. X \<in> A ==> C \<subseteq> X) ==> C \<subseteq> Inter A"

  1030   by (rules intro: InterI subsetI dest: subsetD)

  1031

  1032 lemma INT_lower: "a \<in> A ==> (\<Inter>x\<in>A. B x) \<subseteq> B a"

  1033   by blast

  1034

  1035 lemma INT_greatest: "(!!x. x \<in> A ==> C \<subseteq> B x) ==> C \<subseteq> (\<Inter>x\<in>A. B x)"

  1036   by (rules intro: INT_I subsetI dest: subsetD)

  1037

  1038

  1039 text {* \medskip Finite Union -- the least upper bound of two sets. *}

  1040

  1041 lemma Un_upper1: "A \<subseteq> A \<union> B"

  1042   by blast

  1043

  1044 lemma Un_upper2: "B \<subseteq> A \<union> B"

  1045   by blast

  1046

  1047 lemma Un_least: "A \<subseteq> C ==> B \<subseteq> C ==> A \<union> B \<subseteq> C"

  1048   by blast

  1049

  1050

  1051 text {* \medskip Finite Intersection -- the greatest lower bound of two sets. *}

  1052

  1053 lemma Int_lower1: "A \<inter> B \<subseteq> A"

  1054   by blast

  1055

  1056 lemma Int_lower2: "A \<inter> B \<subseteq> B"

  1057   by blast

  1058

  1059 lemma Int_greatest: "C \<subseteq> A ==> C \<subseteq> B ==> C \<subseteq> A \<inter> B"

  1060   by blast

  1061

  1062

  1063 text {* \medskip Set difference. *}

  1064

  1065 lemma Diff_subset: "A - B \<subseteq> A"

  1066   by blast

  1067

  1068 lemma Diff_subset_conv: "(A - B \<subseteq> C) = (A \<subseteq> B \<union> C)"

  1069 by blast

  1070

  1071

  1072 text {* \medskip Monotonicity. *}

  1073

  1074 lemma mono_Un: includes mono shows "f A \<union> f B \<subseteq> f (A \<union> B)"

  1075   apply (rule Un_least)

  1076    apply (rule Un_upper1 [THEN mono])

  1077   apply (rule Un_upper2 [THEN mono])

  1078   done

  1079

  1080 lemma mono_Int: includes mono shows "f (A \<inter> B) \<subseteq> f A \<inter> f B"

  1081   apply (rule Int_greatest)

  1082    apply (rule Int_lower1 [THEN mono])

  1083   apply (rule Int_lower2 [THEN mono])

  1084   done

  1085

  1086

  1087 subsubsection {* Equalities involving union, intersection, inclusion, etc. *}

  1088

  1089 text {* @{text "{}"}. *}

  1090

  1091 lemma Collect_const [simp]: "{s. P} = (if P then UNIV else {})"

  1092   -- {* supersedes @{text "Collect_False_empty"} *}

  1093   by auto

  1094

  1095 lemma subset_empty [simp]: "(A \<subseteq> {}) = (A = {})"

  1096   by blast

  1097

  1098 lemma not_psubset_empty [iff]: "\<not> (A < {})"

  1099   by (unfold psubset_def) blast

  1100

  1101 lemma Collect_empty_eq [simp]: "(Collect P = {}) = (\<forall>x. \<not> P x)"

  1102   by auto

  1103

  1104 lemma Collect_neg_eq: "{x. \<not> P x} = - {x. P x}"

  1105   by blast

  1106

  1107 lemma Collect_disj_eq: "{x. P x | Q x} = {x. P x} \<union> {x. Q x}"

  1108   by blast

  1109

  1110 lemma Collect_imp_eq: "{x. P x --> Q x} = -{x. P x} \<union> {x. Q x}"

  1111   by blast

  1112

  1113 lemma Collect_conj_eq: "{x. P x & Q x} = {x. P x} \<inter> {x. Q x}"

  1114   by blast

  1115

  1116 lemma Collect_all_eq: "{x. \<forall>y. P x y} = (\<Inter>y. {x. P x y})"

  1117   by blast

  1118

  1119 lemma Collect_ball_eq: "{x. \<forall>y\<in>A. P x y} = (\<Inter>y\<in>A. {x. P x y})"

  1120   by blast

  1121

  1122 lemma Collect_ex_eq: "{x. \<exists>y. P x y} = (\<Union>y. {x. P x y})"

  1123   by blast

  1124

  1125 lemma Collect_bex_eq: "{x. \<exists>y\<in>A. P x y} = (\<Union>y\<in>A. {x. P x y})"

  1126   by blast

  1127

  1128

  1129 text {* \medskip @{text insert}. *}

  1130

  1131 lemma insert_is_Un: "insert a A = {a} Un A"

  1132   -- {* NOT SUITABLE FOR REWRITING since @{text "{a} == insert a {}"} *}

  1133   by blast

  1134

  1135 lemma insert_not_empty [simp]: "insert a A \<noteq> {}"

  1136   by blast

  1137

  1138 lemmas empty_not_insert [simp] = insert_not_empty [symmetric, standard]

  1139

  1140 lemma insert_absorb: "a \<in> A ==> insert a A = A"

  1141   -- {* @{text "[simp]"} causes recursive calls when there are nested inserts *}

  1142   -- {* with \emph{quadratic} running time *}

  1143   by blast

  1144

  1145 lemma insert_absorb2 [simp]: "insert x (insert x A) = insert x A"

  1146   by blast

  1147

  1148 lemma insert_commute: "insert x (insert y A) = insert y (insert x A)"

  1149   by blast

  1150

  1151 lemma insert_subset [simp]: "(insert x A \<subseteq> B) = (x \<in> B & A \<subseteq> B)"

  1152   by blast

  1153

  1154 lemma mk_disjoint_insert: "a \<in> A ==> \<exists>B. A = insert a B & a \<notin> B"

  1155   -- {* use new @{text B} rather than @{text "A - {a}"} to avoid infinite unfolding *}

  1156   apply (rule_tac x = "A - {a}" in exI, blast)

  1157   done

  1158

  1159 lemma insert_Collect: "insert a (Collect P) = {u. u \<noteq> a --> P u}"

  1160   by auto

  1161

  1162 lemma UN_insert_distrib: "u \<in> A ==> (\<Union>x\<in>A. insert a (B x)) = insert a (\<Union>x\<in>A. B x)"

  1163   by blast

  1164

  1165 lemma insert_inter_insert[simp]: "insert a A \<inter> insert a B = insert a (A \<inter> B)"

  1166   by blast

  1167

  1168 lemma insert_disjoint[simp]:

  1169  "(insert a A \<inter> B = {}) = (a \<notin> B \<and> A \<inter> B = {})"

  1170  "({} = insert a A \<inter> B) = (a \<notin> B \<and> {} = A \<inter> B)"

  1171 by auto

  1172

  1173 lemma disjoint_insert[simp]:

  1174  "(B \<inter> insert a A = {}) = (a \<notin> B \<and> B \<inter> A = {})"

  1175  "({} = A \<inter> insert b B) = (b \<notin> A \<and> {} = A \<inter> B)"

  1176 by auto

  1177

  1178 text {* \medskip @{text image}. *}

  1179

  1180 lemma image_empty [simp]: "f{} = {}"

  1181   by blast

  1182

  1183 lemma image_insert [simp]: "f  insert a B = insert (f a) (fB)"

  1184   by blast

  1185

  1186 lemma image_constant: "x \<in> A ==> (\<lambda>x. c)  A = {c}"

  1187   by blast

  1188

  1189 lemma image_image: "f  (g  A) = (\<lambda>x. f (g x))  A"

  1190   by blast

  1191

  1192 lemma insert_image [simp]: "x \<in> A ==> insert (f x) (fA) = fA"

  1193   by blast

  1194

  1195 lemma image_is_empty [iff]: "(fA = {}) = (A = {})"

  1196   by blast

  1197

  1198 lemma image_Collect: "f  {x. P x} = {f x | x. P x}"

  1199   -- {* NOT suitable as a default simprule: the RHS isn't simpler than the LHS, *}

  1200   -- {* with its implicit quantifier and conjunction.  Also image enjoys better *}

  1201   -- {* equational properties than does the RHS. *}

  1202   by blast

  1203

  1204 lemma if_image_distrib [simp]:

  1205   "(\<lambda>x. if P x then f x else g x)  S

  1206     = (f  (S \<inter> {x. P x})) \<union> (g  (S \<inter> {x. \<not> P x}))"

  1207   by (auto simp add: image_def)

  1208

  1209 lemma image_cong: "M = N ==> (!!x. x \<in> N ==> f x = g x) ==> fM = gN"

  1210   by (simp add: image_def)

  1211

  1212

  1213 text {* \medskip @{text range}. *}

  1214

  1215 lemma full_SetCompr_eq: "{u. \<exists>x. u = f x} = range f"

  1216   by auto

  1217

  1218 lemma range_composition [simp]: "range (\<lambda>x. f (g x)) = frange g"

  1219 by (subst image_image, simp)

  1220

  1221

  1222 text {* \medskip @{text Int} *}

  1223

  1224 lemma Int_absorb [simp]: "A \<inter> A = A"

  1225   by blast

  1226

  1227 lemma Int_left_absorb: "A \<inter> (A \<inter> B) = A \<inter> B"

  1228   by blast

  1229

  1230 lemma Int_commute: "A \<inter> B = B \<inter> A"

  1231   by blast

  1232

  1233 lemma Int_left_commute: "A \<inter> (B \<inter> C) = B \<inter> (A \<inter> C)"

  1234   by blast

  1235

  1236 lemma Int_assoc: "(A \<inter> B) \<inter> C = A \<inter> (B \<inter> C)"

  1237   by blast

  1238

  1239 lemmas Int_ac = Int_assoc Int_left_absorb Int_commute Int_left_commute

  1240   -- {* Intersection is an AC-operator *}

  1241

  1242 lemma Int_absorb1: "B \<subseteq> A ==> A \<inter> B = B"

  1243   by blast

  1244

  1245 lemma Int_absorb2: "A \<subseteq> B ==> A \<inter> B = A"

  1246   by blast

  1247

  1248 lemma Int_empty_left [simp]: "{} \<inter> B = {}"

  1249   by blast

  1250

  1251 lemma Int_empty_right [simp]: "A \<inter> {} = {}"

  1252   by blast

  1253

  1254 lemma disjoint_eq_subset_Compl: "(A \<inter> B = {}) = (A \<subseteq> -B)"

  1255   by blast

  1256

  1257 lemma disjoint_iff_not_equal: "(A \<inter> B = {}) = (\<forall>x\<in>A. \<forall>y\<in>B. x \<noteq> y)"

  1258   by blast

  1259

  1260 lemma Int_UNIV_left [simp]: "UNIV \<inter> B = B"

  1261   by blast

  1262

  1263 lemma Int_UNIV_right [simp]: "A \<inter> UNIV = A"

  1264   by blast

  1265

  1266 lemma Int_eq_Inter: "A \<inter> B = \<Inter>{A, B}"

  1267   by blast

  1268

  1269 lemma Int_Un_distrib: "A \<inter> (B \<union> C) = (A \<inter> B) \<union> (A \<inter> C)"

  1270   by blast

  1271

  1272 lemma Int_Un_distrib2: "(B \<union> C) \<inter> A = (B \<inter> A) \<union> (C \<inter> A)"

  1273   by blast

  1274

  1275 lemma Int_UNIV [simp]: "(A \<inter> B = UNIV) = (A = UNIV & B = UNIV)"

  1276   by blast

  1277

  1278 lemma Int_subset_iff [simp]: "(C \<subseteq> A \<inter> B) = (C \<subseteq> A & C \<subseteq> B)"

  1279   by blast

  1280

  1281 lemma Int_Collect: "(x \<in> A \<inter> {x. P x}) = (x \<in> A & P x)"

  1282   by blast

  1283

  1284

  1285 text {* \medskip @{text Un}. *}

  1286

  1287 lemma Un_absorb [simp]: "A \<union> A = A"

  1288   by blast

  1289

  1290 lemma Un_left_absorb: "A \<union> (A \<union> B) = A \<union> B"

  1291   by blast

  1292

  1293 lemma Un_commute: "A \<union> B = B \<union> A"

  1294   by blast

  1295

  1296 lemma Un_left_commute: "A \<union> (B \<union> C) = B \<union> (A \<union> C)"

  1297   by blast

  1298

  1299 lemma Un_assoc: "(A \<union> B) \<union> C = A \<union> (B \<union> C)"

  1300   by blast

  1301

  1302 lemmas Un_ac = Un_assoc Un_left_absorb Un_commute Un_left_commute

  1303   -- {* Union is an AC-operator *}

  1304

  1305 lemma Un_absorb1: "A \<subseteq> B ==> A \<union> B = B"

  1306   by blast

  1307

  1308 lemma Un_absorb2: "B \<subseteq> A ==> A \<union> B = A"

  1309   by blast

  1310

  1311 lemma Un_empty_left [simp]: "{} \<union> B = B"

  1312   by blast

  1313

  1314 lemma Un_empty_right [simp]: "A \<union> {} = A"

  1315   by blast

  1316

  1317 lemma Un_UNIV_left [simp]: "UNIV \<union> B = UNIV"

  1318   by blast

  1319

  1320 lemma Un_UNIV_right [simp]: "A \<union> UNIV = UNIV"

  1321   by blast

  1322

  1323 lemma Un_eq_Union: "A \<union> B = \<Union>{A, B}"

  1324   by blast

  1325

  1326 lemma Un_insert_left [simp]: "(insert a B) \<union> C = insert a (B \<union> C)"

  1327   by blast

  1328

  1329 lemma Un_insert_right [simp]: "A \<union> (insert a B) = insert a (A \<union> B)"

  1330   by blast

  1331

  1332 lemma Int_insert_left:

  1333     "(insert a B) Int C = (if a \<in> C then insert a (B \<inter> C) else B \<inter> C)"

  1334   by auto

  1335

  1336 lemma Int_insert_right:

  1337     "A \<inter> (insert a B) = (if a \<in> A then insert a (A \<inter> B) else A \<inter> B)"

  1338   by auto

  1339

  1340 lemma Un_Int_distrib: "A \<union> (B \<inter> C) = (A \<union> B) \<inter> (A \<union> C)"

  1341   by blast

  1342

  1343 lemma Un_Int_distrib2: "(B \<inter> C) \<union> A = (B \<union> A) \<inter> (C \<union> A)"

  1344   by blast

  1345

  1346 lemma Un_Int_crazy:

  1347     "(A \<inter> B) \<union> (B \<inter> C) \<union> (C \<inter> A) = (A \<union> B) \<inter> (B \<union> C) \<inter> (C \<union> A)"

  1348   by blast

  1349

  1350 lemma subset_Un_eq: "(A \<subseteq> B) = (A \<union> B = B)"

  1351   by blast

  1352

  1353 lemma Un_empty [iff]: "(A \<union> B = {}) = (A = {} & B = {})"

  1354   by blast

  1355

  1356 lemma Un_subset_iff [simp]: "(A \<union> B \<subseteq> C) = (A \<subseteq> C & B \<subseteq> C)"

  1357   by blast

  1358

  1359 lemma Un_Diff_Int: "(A - B) \<union> (A \<inter> B) = A"

  1360   by blast

  1361

  1362

  1363 text {* \medskip Set complement *}

  1364

  1365 lemma Compl_disjoint [simp]: "A \<inter> -A = {}"

  1366   by blast

  1367

  1368 lemma Compl_disjoint2 [simp]: "-A \<inter> A = {}"

  1369   by blast

  1370

  1371 lemma Compl_partition: "A \<union> -A = UNIV"

  1372   by blast

  1373

  1374 lemma Compl_partition2: "-A \<union> A = UNIV"

  1375   by blast

  1376

  1377 lemma double_complement [simp]: "- (-A) = (A::'a set)"

  1378   by blast

  1379

  1380 lemma Compl_Un [simp]: "-(A \<union> B) = (-A) \<inter> (-B)"

  1381   by blast

  1382

  1383 lemma Compl_Int [simp]: "-(A \<inter> B) = (-A) \<union> (-B)"

  1384   by blast

  1385

  1386 lemma Compl_UN [simp]: "-(\<Union>x\<in>A. B x) = (\<Inter>x\<in>A. -B x)"

  1387   by blast

  1388

  1389 lemma Compl_INT [simp]: "-(\<Inter>x\<in>A. B x) = (\<Union>x\<in>A. -B x)"

  1390   by blast

  1391

  1392 lemma subset_Compl_self_eq: "(A \<subseteq> -A) = (A = {})"

  1393   by blast

  1394

  1395 lemma Un_Int_assoc_eq: "((A \<inter> B) \<union> C = A \<inter> (B \<union> C)) = (C \<subseteq> A)"

  1396   -- {* Halmos, Naive Set Theory, page 16. *}

  1397   by blast

  1398

  1399 lemma Compl_UNIV_eq [simp]: "-UNIV = {}"

  1400   by blast

  1401

  1402 lemma Compl_empty_eq [simp]: "-{} = UNIV"

  1403   by blast

  1404

  1405 lemma Compl_subset_Compl_iff [iff]: "(-A \<subseteq> -B) = (B \<subseteq> A)"

  1406   by blast

  1407

  1408 lemma Compl_eq_Compl_iff [iff]: "(-A = -B) = (A = (B::'a set))"

  1409   by blast

  1410

  1411

  1412 text {* \medskip @{text Union}. *}

  1413

  1414 lemma Union_empty [simp]: "Union({}) = {}"

  1415   by blast

  1416

  1417 lemma Union_UNIV [simp]: "Union UNIV = UNIV"

  1418   by blast

  1419

  1420 lemma Union_insert [simp]: "Union (insert a B) = a \<union> \<Union>B"

  1421   by blast

  1422

  1423 lemma Union_Un_distrib [simp]: "\<Union>(A Un B) = \<Union>A \<union> \<Union>B"

  1424   by blast

  1425

  1426 lemma Union_Int_subset: "\<Union>(A \<inter> B) \<subseteq> \<Union>A \<inter> \<Union>B"

  1427   by blast

  1428

  1429 lemma Union_empty_conv [iff]: "(\<Union>A = {}) = (\<forall>x\<in>A. x = {})"

  1430   by blast

  1431

  1432 lemma empty_Union_conv [iff]: "({} = \<Union>A) = (\<forall>x\<in>A. x = {})"

  1433   by blast

  1434

  1435 lemma Union_disjoint: "(\<Union>C \<inter> A = {}) = (\<forall>B\<in>C. B \<inter> A = {})"

  1436   by blast

  1437

  1438

  1439 text {* \medskip @{text Inter}. *}

  1440

  1441 lemma Inter_empty [simp]: "\<Inter>{} = UNIV"

  1442   by blast

  1443

  1444 lemma Inter_UNIV [simp]: "\<Inter>UNIV = {}"

  1445   by blast

  1446

  1447 lemma Inter_insert [simp]: "\<Inter>(insert a B) = a \<inter> \<Inter>B"

  1448   by blast

  1449

  1450 lemma Inter_Un_subset: "\<Inter>A \<union> \<Inter>B \<subseteq> \<Inter>(A \<inter> B)"

  1451   by blast

  1452

  1453 lemma Inter_Un_distrib: "\<Inter>(A \<union> B) = \<Inter>A \<inter> \<Inter>B"

  1454   by blast

  1455

  1456 lemma Inter_UNIV_conv [iff]:

  1457   "(\<Inter>A = UNIV) = (\<forall>x\<in>A. x = UNIV)"

  1458   "(UNIV = \<Inter>A) = (\<forall>x\<in>A. x = UNIV)"

  1459   by blast+

  1460

  1461

  1462 text {*

  1463   \medskip @{text UN} and @{text INT}.

  1464

  1465   Basic identities: *}

  1466

  1467 lemma UN_empty [simp]: "(\<Union>x\<in>{}. B x) = {}"

  1468   by blast

  1469

  1470 lemma UN_empty2 [simp]: "(\<Union>x\<in>A. {}) = {}"

  1471   by blast

  1472

  1473 lemma UN_singleton [simp]: "(\<Union>x\<in>A. {x}) = A"

  1474   by blast

  1475

  1476 lemma UN_absorb: "k \<in> I ==> A k \<union> (\<Union>i\<in>I. A i) = (\<Union>i\<in>I. A i)"

  1477   by auto

  1478

  1479 lemma INT_empty [simp]: "(\<Inter>x\<in>{}. B x) = UNIV"

  1480   by blast

  1481

  1482 lemma INT_absorb: "k \<in> I ==> A k \<inter> (\<Inter>i\<in>I. A i) = (\<Inter>i\<in>I. A i)"

  1483   by blast

  1484

  1485 lemma UN_insert [simp]: "(\<Union>x\<in>insert a A. B x) = B a \<union> UNION A B"

  1486   by blast

  1487

  1488 lemma UN_Un: "(\<Union>i \<in> A \<union> B. M i) = (\<Union>i\<in>A. M i) \<union> (\<Union>i\<in>B. M i)"

  1489   by blast

  1490

  1491 lemma UN_UN_flatten: "(\<Union>x \<in> (\<Union>y\<in>A. B y). C x) = (\<Union>y\<in>A. \<Union>x\<in>B y. C x)"

  1492   by blast

  1493

  1494 lemma UN_subset_iff: "((\<Union>i\<in>I. A i) \<subseteq> B) = (\<forall>i\<in>I. A i \<subseteq> B)"

  1495   by blast

  1496

  1497 lemma INT_subset_iff: "(B \<subseteq> (\<Inter>i\<in>I. A i)) = (\<forall>i\<in>I. B \<subseteq> A i)"

  1498   by blast

  1499

  1500 lemma INT_insert [simp]: "(\<Inter>x \<in> insert a A. B x) = B a \<inter> INTER A B"

  1501   by blast

  1502

  1503 lemma INT_Un: "(\<Inter>i \<in> A \<union> B. M i) = (\<Inter>i \<in> A. M i) \<inter> (\<Inter>i\<in>B. M i)"

  1504   by blast

  1505

  1506 lemma INT_insert_distrib:

  1507     "u \<in> A ==> (\<Inter>x\<in>A. insert a (B x)) = insert a (\<Inter>x\<in>A. B x)"

  1508   by blast

  1509

  1510 lemma Union_image_eq [simp]: "\<Union>(BA) = (\<Union>x\<in>A. B x)"

  1511   by blast

  1512

  1513 lemma image_Union: "f  \<Union>S = (\<Union>x\<in>S. f  x)"

  1514   by blast

  1515

  1516 lemma Inter_image_eq [simp]: "\<Inter>(BA) = (\<Inter>x\<in>A. B x)"

  1517   by blast

  1518

  1519 lemma UN_constant [simp]: "(\<Union>y\<in>A. c) = (if A = {} then {} else c)"

  1520   by auto

  1521

  1522 lemma INT_constant [simp]: "(\<Inter>y\<in>A. c) = (if A = {} then UNIV else c)"

  1523   by auto

  1524

  1525 lemma UN_eq: "(\<Union>x\<in>A. B x) = \<Union>({Y. \<exists>x\<in>A. Y = B x})"

  1526   by blast

  1527

  1528 lemma INT_eq: "(\<Inter>x\<in>A. B x) = \<Inter>({Y. \<exists>x\<in>A. Y = B x})"

  1529   -- {* Look: it has an \emph{existential} quantifier *}

  1530   by blast

  1531

  1532 lemma UNION_empty_conv[iff]:

  1533   "({} = (UN x:A. B x)) = (\<forall>x\<in>A. B x = {})"

  1534   "((UN x:A. B x) = {}) = (\<forall>x\<in>A. B x = {})"

  1535 by blast+

  1536

  1537 lemma INTER_UNIV_conv[iff]:

  1538  "(UNIV = (INT x:A. B x)) = (\<forall>x\<in>A. B x = UNIV)"

  1539  "((INT x:A. B x) = UNIV) = (\<forall>x\<in>A. B x = UNIV)"

  1540 by blast+

  1541

  1542

  1543 text {* \medskip Distributive laws: *}

  1544

  1545 lemma Int_Union: "A \<inter> \<Union>B = (\<Union>C\<in>B. A \<inter> C)"

  1546   by blast

  1547

  1548 lemma Int_Union2: "\<Union>B \<inter> A = (\<Union>C\<in>B. C \<inter> A)"

  1549   by blast

  1550

  1551 lemma Un_Union_image: "(\<Union>x\<in>C. A x \<union> B x) = \<Union>(AC) \<union> \<Union>(BC)"

  1552   -- {* Devlin, Fundamentals of Contemporary Set Theory, page 12, exercise 5: *}

  1553   -- {* Union of a family of unions *}

  1554   by blast

  1555

  1556 lemma UN_Un_distrib: "(\<Union>i\<in>I. A i \<union> B i) = (\<Union>i\<in>I. A i) \<union> (\<Union>i\<in>I. B i)"

  1557   -- {* Equivalent version *}

  1558   by blast

  1559

  1560 lemma Un_Inter: "A \<union> \<Inter>B = (\<Inter>C\<in>B. A \<union> C)"

  1561   by blast

  1562

  1563 lemma Int_Inter_image: "(\<Inter>x\<in>C. A x \<inter> B x) = \<Inter>(AC) \<inter> \<Inter>(BC)"

  1564   by blast

  1565

  1566 lemma INT_Int_distrib: "(\<Inter>i\<in>I. A i \<inter> B i) = (\<Inter>i\<in>I. A i) \<inter> (\<Inter>i\<in>I. B i)"

  1567   -- {* Equivalent version *}

  1568   by blast

  1569

  1570 lemma Int_UN_distrib: "B \<inter> (\<Union>i\<in>I. A i) = (\<Union>i\<in>I. B \<inter> A i)"

  1571   -- {* Halmos, Naive Set Theory, page 35. *}

  1572   by blast

  1573

  1574 lemma Un_INT_distrib: "B \<union> (\<Inter>i\<in>I. A i) = (\<Inter>i\<in>I. B \<union> A i)"

  1575   by blast

  1576

  1577 lemma Int_UN_distrib2: "(\<Union>i\<in>I. A i) \<inter> (\<Union>j\<in>J. B j) = (\<Union>i\<in>I. \<Union>j\<in>J. A i \<inter> B j)"

  1578   by blast

  1579

  1580 lemma Un_INT_distrib2: "(\<Inter>i\<in>I. A i) \<union> (\<Inter>j\<in>J. B j) = (\<Inter>i\<in>I. \<Inter>j\<in>J. A i \<union> B j)"

  1581   by blast

  1582

  1583

  1584 text {* \medskip Bounded quantifiers.

  1585

  1586   The following are not added to the default simpset because

  1587   (a) they duplicate the body and (b) there are no similar rules for @{text Int}. *}

  1588

  1589 lemma ball_Un: "(\<forall>x \<in> A \<union> B. P x) = ((\<forall>x\<in>A. P x) & (\<forall>x\<in>B. P x))"

  1590   by blast

  1591

  1592 lemma bex_Un: "(\<exists>x \<in> A \<union> B. P x) = ((\<exists>x\<in>A. P x) | (\<exists>x\<in>B. P x))"

  1593   by blast

  1594

  1595 lemma ball_UN: "(\<forall>z \<in> UNION A B. P z) = (\<forall>x\<in>A. \<forall>z \<in> B x. P z)"

  1596   by blast

  1597

  1598 lemma bex_UN: "(\<exists>z \<in> UNION A B. P z) = (\<exists>x\<in>A. \<exists>z\<in>B x. P z)"

  1599   by blast

  1600

  1601

  1602 text {* \medskip Set difference. *}

  1603

  1604 lemma Diff_eq: "A - B = A \<inter> (-B)"

  1605   by blast

  1606

  1607 lemma Diff_eq_empty_iff [simp]: "(A - B = {}) = (A \<subseteq> B)"

  1608   by blast

  1609

  1610 lemma Diff_cancel [simp]: "A - A = {}"

  1611   by blast

  1612

  1613 lemma Diff_idemp [simp]: "(A - B) - B = A - (B::'a set)"

  1614 by blast

  1615

  1616 lemma Diff_triv: "A \<inter> B = {} ==> A - B = A"

  1617   by (blast elim: equalityE)

  1618

  1619 lemma empty_Diff [simp]: "{} - A = {}"

  1620   by blast

  1621

  1622 lemma Diff_empty [simp]: "A - {} = A"

  1623   by blast

  1624

  1625 lemma Diff_UNIV [simp]: "A - UNIV = {}"

  1626   by blast

  1627

  1628 lemma Diff_insert0 [simp]: "x \<notin> A ==> A - insert x B = A - B"

  1629   by blast

  1630

  1631 lemma Diff_insert: "A - insert a B = A - B - {a}"

  1632   -- {* NOT SUITABLE FOR REWRITING since @{text "{a} == insert a 0"} *}

  1633   by blast

  1634

  1635 lemma Diff_insert2: "A - insert a B = A - {a} - B"

  1636   -- {* NOT SUITABLE FOR REWRITING since @{text "{a} == insert a 0"} *}

  1637   by blast

  1638

  1639 lemma insert_Diff_if: "insert x A - B = (if x \<in> B then A - B else insert x (A - B))"

  1640   by auto

  1641

  1642 lemma insert_Diff1 [simp]: "x \<in> B ==> insert x A - B = A - B"

  1643   by blast

  1644

  1645 lemma insert_Diff_single[simp]: "insert a (A - {a}) = insert a A"

  1646 by blast

  1647

  1648 lemma insert_Diff: "a \<in> A ==> insert a (A - {a}) = A"

  1649   by blast

  1650

  1651 lemma Diff_insert_absorb: "x \<notin> A ==> (insert x A) - {x} = A"

  1652   by auto

  1653

  1654 lemma Diff_disjoint [simp]: "A \<inter> (B - A) = {}"

  1655   by blast

  1656

  1657 lemma Diff_partition: "A \<subseteq> B ==> A \<union> (B - A) = B"

  1658   by blast

  1659

  1660 lemma double_diff: "A \<subseteq> B ==> B \<subseteq> C ==> B - (C - A) = A"

  1661   by blast

  1662

  1663 lemma Un_Diff_cancel [simp]: "A \<union> (B - A) = A \<union> B"

  1664   by blast

  1665

  1666 lemma Un_Diff_cancel2 [simp]: "(B - A) \<union> A = B \<union> A"

  1667   by blast

  1668

  1669 lemma Diff_Un: "A - (B \<union> C) = (A - B) \<inter> (A - C)"

  1670   by blast

  1671

  1672 lemma Diff_Int: "A - (B \<inter> C) = (A - B) \<union> (A - C)"

  1673   by blast

  1674

  1675 lemma Un_Diff: "(A \<union> B) - C = (A - C) \<union> (B - C)"

  1676   by blast

  1677

  1678 lemma Int_Diff: "(A \<inter> B) - C = A \<inter> (B - C)"

  1679   by blast

  1680

  1681 lemma Diff_Int_distrib: "C \<inter> (A - B) = (C \<inter> A) - (C \<inter> B)"

  1682   by blast

  1683

  1684 lemma Diff_Int_distrib2: "(A - B) \<inter> C = (A \<inter> C) - (B \<inter> C)"

  1685   by blast

  1686

  1687 lemma Diff_Compl [simp]: "A - (- B) = A \<inter> B"

  1688   by auto

  1689

  1690 lemma Compl_Diff_eq [simp]: "- (A - B) = -A \<union> B"

  1691   by blast

  1692

  1693

  1694 text {* \medskip Quantification over type @{typ bool}. *}

  1695

  1696 lemma all_bool_eq: "(\<forall>b::bool. P b) = (P True & P False)"

  1697   apply auto

  1698   apply (tactic {* case_tac "b" 1 *}, auto)

  1699   done

  1700

  1701 lemma bool_induct: "P True \<Longrightarrow> P False \<Longrightarrow> P x"

  1702   by (rule conjI [THEN all_bool_eq [THEN iffD2], THEN spec])

  1703

  1704 lemma ex_bool_eq: "(\<exists>b::bool. P b) = (P True | P False)"

  1705   apply auto

  1706   apply (tactic {* case_tac "b" 1 *}, auto)

  1707   done

  1708

  1709 lemma Un_eq_UN: "A \<union> B = (\<Union>b. if b then A else B)"

  1710   by (auto simp add: split_if_mem2)

  1711

  1712 lemma UN_bool_eq: "(\<Union>b::bool. A b) = (A True \<union> A False)"

  1713   apply auto

  1714   apply (tactic {* case_tac "b" 1 *}, auto)

  1715   done

  1716

  1717 lemma INT_bool_eq: "(\<Inter>b::bool. A b) = (A True \<inter> A False)"

  1718   apply auto

  1719   apply (tactic {* case_tac "b" 1 *}, auto)

  1720   done

  1721

  1722

  1723 text {* \medskip @{text Pow} *}

  1724

  1725 lemma Pow_empty [simp]: "Pow {} = {{}}"

  1726   by (auto simp add: Pow_def)

  1727

  1728 lemma Pow_insert: "Pow (insert a A) = Pow A \<union> (insert a  Pow A)"

  1729   by (blast intro: image_eqI [where ?x = "u - {a}", standard])

  1730

  1731 lemma Pow_Compl: "Pow (- A) = {-B | B. A \<in> Pow B}"

  1732   by (blast intro: exI [where ?x = "- u", standard])

  1733

  1734 lemma Pow_UNIV [simp]: "Pow UNIV = UNIV"

  1735   by blast

  1736

  1737 lemma Un_Pow_subset: "Pow A \<union> Pow B \<subseteq> Pow (A \<union> B)"

  1738   by blast

  1739

  1740 lemma UN_Pow_subset: "(\<Union>x\<in>A. Pow (B x)) \<subseteq> Pow (\<Union>x\<in>A. B x)"

  1741   by blast

  1742

  1743 lemma subset_Pow_Union: "A \<subseteq> Pow (\<Union>A)"

  1744   by blast

  1745

  1746 lemma Union_Pow_eq [simp]: "\<Union>(Pow A) = A"

  1747   by blast

  1748

  1749 lemma Pow_Int_eq [simp]: "Pow (A \<inter> B) = Pow A \<inter> Pow B"

  1750   by blast

  1751

  1752 lemma Pow_INT_eq: "Pow (\<Inter>x\<in>A. B x) = (\<Inter>x\<in>A. Pow (B x))"

  1753   by blast

  1754

  1755

  1756 text {* \medskip Miscellany. *}

  1757

  1758 lemma set_eq_subset: "(A = B) = (A \<subseteq> B & B \<subseteq> A)"

  1759   by blast

  1760

  1761 lemma subset_iff: "(A \<subseteq> B) = (\<forall>t. t \<in> A --> t \<in> B)"

  1762   by blast

  1763

  1764 lemma subset_iff_psubset_eq: "(A \<subseteq> B) = ((A \<subset> B) | (A = B))"

  1765   by (unfold psubset_def) blast

  1766

  1767 lemma all_not_in_conv [iff]: "(\<forall>x. x \<notin> A) = (A = {})"

  1768   by blast

  1769

  1770 lemma ex_in_conv: "(\<exists>x. x \<in> A) = (A \<noteq> {})"

  1771   by blast

  1772

  1773 lemma distinct_lemma: "f x \<noteq> f y ==> x \<noteq> y"

  1774   by rules

  1775

  1776

  1777 text {* \medskip Miniscoping: pushing in quantifiers and big Unions

  1778            and Intersections. *}

  1779

  1780 lemma UN_simps [simp]:

  1781   "!!a B C. (UN x:C. insert a (B x)) = (if C={} then {} else insert a (UN x:C. B x))"

  1782   "!!A B C. (UN x:C. A x Un B)   = ((if C={} then {} else (UN x:C. A x) Un B))"

  1783   "!!A B C. (UN x:C. A Un B x)   = ((if C={} then {} else A Un (UN x:C. B x)))"

  1784   "!!A B C. (UN x:C. A x Int B)  = ((UN x:C. A x) Int B)"

  1785   "!!A B C. (UN x:C. A Int B x)  = (A Int (UN x:C. B x))"

  1786   "!!A B C. (UN x:C. A x - B)    = ((UN x:C. A x) - B)"

  1787   "!!A B C. (UN x:C. A - B x)    = (A - (INT x:C. B x))"

  1788   "!!A B. (UN x: Union A. B x) = (UN y:A. UN x:y. B x)"

  1789   "!!A B C. (UN z: UNION A B. C z) = (UN  x:A. UN z: B(x). C z)"

  1790   "!!A B f. (UN x:fA. B x)     = (UN a:A. B (f a))"

  1791   by auto

  1792

  1793 lemma INT_simps [simp]:

  1794   "!!A B C. (INT x:C. A x Int B) = (if C={} then UNIV else (INT x:C. A x) Int B)"

  1795   "!!A B C. (INT x:C. A Int B x) = (if C={} then UNIV else A Int (INT x:C. B x))"

  1796   "!!A B C. (INT x:C. A x - B)   = (if C={} then UNIV else (INT x:C. A x) - B)"

  1797   "!!A B C. (INT x:C. A - B x)   = (if C={} then UNIV else A - (UN x:C. B x))"

  1798   "!!a B C. (INT x:C. insert a (B x)) = insert a (INT x:C. B x)"

  1799   "!!A B C. (INT x:C. A x Un B)  = ((INT x:C. A x) Un B)"

  1800   "!!A B C. (INT x:C. A Un B x)  = (A Un (INT x:C. B x))"

  1801   "!!A B. (INT x: Union A. B x) = (INT y:A. INT x:y. B x)"

  1802   "!!A B C. (INT z: UNION A B. C z) = (INT x:A. INT z: B(x). C z)"

  1803   "!!A B f. (INT x:fA. B x)    = (INT a:A. B (f a))"

  1804   by auto

  1805

  1806 lemma ball_simps [simp]:

  1807   "!!A P Q. (ALL x:A. P x | Q) = ((ALL x:A. P x) | Q)"

  1808   "!!A P Q. (ALL x:A. P | Q x) = (P | (ALL x:A. Q x))"

  1809   "!!A P Q. (ALL x:A. P --> Q x) = (P --> (ALL x:A. Q x))"

  1810   "!!A P Q. (ALL x:A. P x --> Q) = ((EX x:A. P x) --> Q)"

  1811   "!!P. (ALL x:{}. P x) = True"

  1812   "!!P. (ALL x:UNIV. P x) = (ALL x. P x)"

  1813   "!!a B P. (ALL x:insert a B. P x) = (P a & (ALL x:B. P x))"

  1814   "!!A P. (ALL x:Union A. P x) = (ALL y:A. ALL x:y. P x)"

  1815   "!!A B P. (ALL x: UNION A B. P x) = (ALL a:A. ALL x: B a. P x)"

  1816   "!!P Q. (ALL x:Collect Q. P x) = (ALL x. Q x --> P x)"

  1817   "!!A P f. (ALL x:fA. P x) = (ALL x:A. P (f x))"

  1818   "!!A P. (~(ALL x:A. P x)) = (EX x:A. ~P x)"

  1819   by auto

  1820

  1821 lemma bex_simps [simp]:

  1822   "!!A P Q. (EX x:A. P x & Q) = ((EX x:A. P x) & Q)"

  1823   "!!A P Q. (EX x:A. P & Q x) = (P & (EX x:A. Q x))"

  1824   "!!P. (EX x:{}. P x) = False"

  1825   "!!P. (EX x:UNIV. P x) = (EX x. P x)"

  1826   "!!a B P. (EX x:insert a B. P x) = (P(a) | (EX x:B. P x))"

  1827   "!!A P. (EX x:Union A. P x) = (EX y:A. EX x:y. P x)"

  1828   "!!A B P. (EX x: UNION A B. P x) = (EX a:A. EX x:B a. P x)"

  1829   "!!P Q. (EX x:Collect Q. P x) = (EX x. Q x & P x)"

  1830   "!!A P f. (EX x:fA. P x) = (EX x:A. P (f x))"

  1831   "!!A P. (~(EX x:A. P x)) = (ALL x:A. ~P x)"

  1832   by auto

  1833

  1834 lemma ball_conj_distrib:

  1835   "(ALL x:A. P x & Q x) = ((ALL x:A. P x) & (ALL x:A. Q x))"

  1836   by blast

  1837

  1838 lemma bex_disj_distrib:

  1839   "(EX x:A. P x | Q x) = ((EX x:A. P x) | (EX x:A. Q x))"

  1840   by blast

  1841

  1842

  1843 text {* \medskip Maxiscoping: pulling out big Unions and Intersections. *}

  1844

  1845 lemma UN_extend_simps:

  1846   "!!a B C. insert a (UN x:C. B x) = (if C={} then {a} else (UN x:C. insert a (B x)))"

  1847   "!!A B C. (UN x:C. A x) Un B    = (if C={} then B else (UN x:C. A x Un B))"

  1848   "!!A B C. A Un (UN x:C. B x)   = (if C={} then A else (UN x:C. A Un B x))"

  1849   "!!A B C. ((UN x:C. A x) Int B) = (UN x:C. A x Int B)"

  1850   "!!A B C. (A Int (UN x:C. B x)) = (UN x:C. A Int B x)"

  1851   "!!A B C. ((UN x:C. A x) - B) = (UN x:C. A x - B)"

  1852   "!!A B C. (A - (INT x:C. B x)) = (UN x:C. A - B x)"

  1853   "!!A B. (UN y:A. UN x:y. B x) = (UN x: Union A. B x)"

  1854   "!!A B C. (UN  x:A. UN z: B(x). C z) = (UN z: UNION A B. C z)"

  1855   "!!A B f. (UN a:A. B (f a)) = (UN x:fA. B x)"

  1856   by auto

  1857

  1858 lemma INT_extend_simps:

  1859   "!!A B C. (INT x:C. A x) Int B = (if C={} then B else (INT x:C. A x Int B))"

  1860   "!!A B C. A Int (INT x:C. B x) = (if C={} then A else (INT x:C. A Int B x))"

  1861   "!!A B C. (INT x:C. A x) - B   = (if C={} then UNIV-B else (INT x:C. A x - B))"

  1862   "!!A B C. A - (UN x:C. B x)   = (if C={} then A else (INT x:C. A - B x))"

  1863   "!!a B C. insert a (INT x:C. B x) = (INT x:C. insert a (B x))"

  1864   "!!A B C. ((INT x:C. A x) Un B)  = (INT x:C. A x Un B)"

  1865   "!!A B C. A Un (INT x:C. B x)  = (INT x:C. A Un B x)"

  1866   "!!A B. (INT y:A. INT x:y. B x) = (INT x: Union A. B x)"

  1867   "!!A B C. (INT x:A. INT z: B(x). C z) = (INT z: UNION A B. C z)"

  1868   "!!A B f. (INT a:A. B (f a))    = (INT x:fA. B x)"

  1869   by auto

  1870

  1871

  1872 subsubsection {* Monotonicity of various operations *}

  1873

  1874 lemma image_mono: "A \<subseteq> B ==> fA \<subseteq> fB"

  1875   by blast

  1876

  1877 lemma Pow_mono: "A \<subseteq> B ==> Pow A \<subseteq> Pow B"

  1878   by blast

  1879

  1880 lemma Union_mono: "A \<subseteq> B ==> \<Union>A \<subseteq> \<Union>B"

  1881   by blast

  1882

  1883 lemma Inter_anti_mono: "B \<subseteq> A ==> \<Inter>A \<subseteq> \<Inter>B"

  1884   by blast

  1885

  1886 lemma UN_mono:

  1887   "A \<subseteq> B ==> (!!x. x \<in> A ==> f x \<subseteq> g x) ==>

  1888     (\<Union>x\<in>A. f x) \<subseteq> (\<Union>x\<in>B. g x)"

  1889   by (blast dest: subsetD)

  1890

  1891 lemma INT_anti_mono:

  1892   "B \<subseteq> A ==> (!!x. x \<in> A ==> f x \<subseteq> g x) ==>

  1893     (\<Inter>x\<in>A. f x) \<subseteq> (\<Inter>x\<in>A. g x)"

  1894   -- {* The last inclusion is POSITIVE! *}

  1895   by (blast dest: subsetD)

  1896

  1897 lemma insert_mono: "C \<subseteq> D ==> insert a C \<subseteq> insert a D"

  1898   by blast

  1899

  1900 lemma Un_mono: "A \<subseteq> C ==> B \<subseteq> D ==> A \<union> B \<subseteq> C \<union> D"

  1901   by blast

  1902

  1903 lemma Int_mono: "A \<subseteq> C ==> B \<subseteq> D ==> A \<inter> B \<subseteq> C \<inter> D"

  1904   by blast

  1905

  1906 lemma Diff_mono: "A \<subseteq> C ==> D \<subseteq> B ==> A - B \<subseteq> C - D"

  1907   by blast

  1908

  1909 lemma Compl_anti_mono: "A \<subseteq> B ==> -B \<subseteq> -A"

  1910   by blast

  1911

  1912 text {* \medskip Monotonicity of implications. *}

  1913

  1914 lemma in_mono: "A \<subseteq> B ==> x \<in> A --> x \<in> B"

  1915   apply (rule impI)

  1916   apply (erule subsetD, assumption)

  1917   done

  1918

  1919 lemma conj_mono: "P1 --> Q1 ==> P2 --> Q2 ==> (P1 & P2) --> (Q1 & Q2)"

  1920   by rules

  1921

  1922 lemma disj_mono: "P1 --> Q1 ==> P2 --> Q2 ==> (P1 | P2) --> (Q1 | Q2)"

  1923   by rules

  1924

  1925 lemma imp_mono: "Q1 --> P1 ==> P2 --> Q2 ==> (P1 --> P2) --> (Q1 --> Q2)"

  1926   by rules

  1927

  1928 lemma imp_refl: "P --> P" ..

  1929

  1930 lemma ex_mono: "(!!x. P x --> Q x) ==> (EX x. P x) --> (EX x. Q x)"

  1931   by rules

  1932

  1933 lemma all_mono: "(!!x. P x --> Q x) ==> (ALL x. P x) --> (ALL x. Q x)"

  1934   by rules

  1935

  1936 lemma Collect_mono: "(!!x. P x --> Q x) ==> Collect P \<subseteq> Collect Q"

  1937   by blast

  1938

  1939 lemma Int_Collect_mono:

  1940     "A \<subseteq> B ==> (!!x. x \<in> A ==> P x --> Q x) ==> A \<inter> Collect P \<subseteq> B \<inter> Collect Q"

  1941   by blast

  1942

  1943 lemmas basic_monos =

  1944   subset_refl imp_refl disj_mono conj_mono

  1945   ex_mono Collect_mono in_mono

  1946

  1947 lemma eq_to_mono: "a = b ==> c = d ==> b --> d ==> a --> c"

  1948   by rules

  1949

  1950 lemma eq_to_mono2: "a = b ==> c = d ==> ~ b --> ~ d ==> ~ a --> ~ c"

  1951   by rules

  1952

  1953 lemma Least_mono:

  1954   "mono (f::'a::order => 'b::order) ==> EX x:S. ALL y:S. x <= y

  1955     ==> (LEAST y. y : f  S) = f (LEAST x. x : S)"

  1956     -- {* Courtesy of Stephan Merz *}

  1957   apply clarify

  1958   apply (erule_tac P = "%x. x : S" in LeastI2, fast)

  1959   apply (rule LeastI2)

  1960   apply (auto elim: monoD intro!: order_antisym)

  1961   done

  1962

  1963

  1964 subsection {* Inverse image of a function *}

  1965

  1966 constdefs

  1967   vimage :: "('a => 'b) => 'b set => 'a set"    (infixr "-" 90)

  1968   "f - B == {x. f x : B}"

  1969

  1970

  1971 subsubsection {* Basic rules *}

  1972

  1973 lemma vimage_eq [simp]: "(a : f - B) = (f a : B)"

  1974   by (unfold vimage_def) blast

  1975

  1976 lemma vimage_singleton_eq: "(a : f - {b}) = (f a = b)"

  1977   by simp

  1978

  1979 lemma vimageI [intro]: "f a = b ==> b:B ==> a : f - B"

  1980   by (unfold vimage_def) blast

  1981

  1982 lemma vimageI2: "f a : A ==> a : f - A"

  1983   by (unfold vimage_def) fast

  1984

  1985 lemma vimageE [elim!]: "a: f - B ==> (!!x. f a = x ==> x:B ==> P) ==> P"

  1986   by (unfold vimage_def) blast

  1987

  1988 lemma vimageD: "a : f - A ==> f a : A"

  1989   by (unfold vimage_def) fast

  1990

  1991

  1992 subsubsection {* Equations *}

  1993

  1994 lemma vimage_empty [simp]: "f - {} = {}"

  1995   by blast

  1996

  1997 lemma vimage_Compl: "f - (-A) = -(f - A)"

  1998   by blast

  1999

  2000 lemma vimage_Un [simp]: "f - (A Un B) = (f - A) Un (f - B)"

  2001   by blast

  2002

  2003 lemma vimage_Int [simp]: "f - (A Int B) = (f - A) Int (f - B)"

  2004   by fast

  2005

  2006 lemma vimage_Union: "f - (Union A) = (UN X:A. f - X)"

  2007   by blast

  2008

  2009 lemma vimage_UN: "f-(UN x:A. B x) = (UN x:A. f - B x)"

  2010   by blast

  2011

  2012 lemma vimage_INT: "f-(INT x:A. B x) = (INT x:A. f - B x)"

  2013   by blast

  2014

  2015 lemma vimage_Collect_eq [simp]: "f - Collect P = {y. P (f y)}"

  2016   by blast

  2017

  2018 lemma vimage_Collect: "(!!x. P (f x) = Q x) ==> f - (Collect P) = Collect Q"

  2019   by blast

  2020

  2021 lemma vimage_insert: "f-(insert a B) = (f-{a}) Un (f-B)"

  2022   -- {* NOT suitable for rewriting because of the recurrence of @{term "{a}"}. *}

  2023   by blast

  2024

  2025 lemma vimage_Diff: "f - (A - B) = (f - A) - (f - B)"

  2026   by blast

  2027

  2028 lemma vimage_UNIV [simp]: "f - UNIV = UNIV"

  2029   by blast

  2030

  2031 lemma vimage_eq_UN: "f-B = (UN y: B. f-{y})"

  2032   -- {* NOT suitable for rewriting *}

  2033   by blast

  2034

  2035 lemma vimage_mono: "A \<subseteq> B ==> f - A \<subseteq> f - B"

  2036   -- {* monotonicity *}

  2037   by blast

  2038

  2039

  2040 subsection {* Getting the Contents of a Singleton Set *}

  2041

  2042 constdefs

  2043   contents :: "'a set => 'a"

  2044    "contents X == THE x. X = {x}"

  2045

  2046 lemma contents_eq [simp]: "contents {x} = x"

  2047 by (simp add: contents_def)

  2048

  2049

  2050 subsection {* Transitivity rules for calculational reasoning *}

  2051

  2052 lemma forw_subst: "a = b ==> P b ==> P a"

  2053   by (rule ssubst)

  2054

  2055 lemma back_subst: "P a ==> a = b ==> P b"

  2056   by (rule subst)

  2057

  2058 lemma set_rev_mp: "x:A ==> A \<subseteq> B ==> x:B"

  2059   by (rule subsetD)

  2060

  2061 lemma set_mp: "A \<subseteq> B ==> x:A ==> x:B"

  2062   by (rule subsetD)

  2063

  2064 lemma ord_le_eq_trans: "a <= b ==> b = c ==> a <= c"

  2065   by (rule subst)

  2066

  2067 lemma ord_eq_le_trans: "a = b ==> b <= c ==> a <= c"

  2068   by (rule ssubst)

  2069

  2070 lemma ord_less_eq_trans: "a < b ==> b = c ==> a < c"

  2071   by (rule subst)

  2072

  2073 lemma ord_eq_less_trans: "a = b ==> b < c ==> a < c"

  2074   by (rule ssubst)

  2075

  2076 lemma order_less_subst2: "(a::'a::order) < b ==> f b < (c::'c::order) ==>

  2077   (!!x y. x < y ==> f x < f y) ==> f a < c"

  2078 proof -

  2079   assume r: "!!x y. x < y ==> f x < f y"

  2080   assume "a < b" hence "f a < f b" by (rule r)

  2081   also assume "f b < c"

  2082   finally (order_less_trans) show ?thesis .

  2083 qed

  2084

  2085 lemma order_less_subst1: "(a::'a::order) < f b ==> (b::'b::order) < c ==>

  2086   (!!x y. x < y ==> f x < f y) ==> a < f c"

  2087 proof -

  2088   assume r: "!!x y. x < y ==> f x < f y"

  2089   assume "a < f b"

  2090   also assume "b < c" hence "f b < f c" by (rule r)

  2091   finally (order_less_trans) show ?thesis .

  2092 qed

  2093

  2094 lemma order_le_less_subst2: "(a::'a::order) <= b ==> f b < (c::'c::order) ==>

  2095   (!!x y. x <= y ==> f x <= f y) ==> f a < c"

  2096 proof -

  2097   assume r: "!!x y. x <= y ==> f x <= f y"

  2098   assume "a <= b" hence "f a <= f b" by (rule r)

  2099   also assume "f b < c"

  2100   finally (order_le_less_trans) show ?thesis .

  2101 qed

  2102

  2103 lemma order_le_less_subst1: "(a::'a::order) <= f b ==> (b::'b::order) < c ==>

  2104   (!!x y. x < y ==> f x < f y) ==> a < f c"

  2105 proof -

  2106   assume r: "!!x y. x < y ==> f x < f y"

  2107   assume "a <= f b"

  2108   also assume "b < c" hence "f b < f c" by (rule r)

  2109   finally (order_le_less_trans) show ?thesis .

  2110 qed

  2111

  2112 lemma order_less_le_subst2: "(a::'a::order) < b ==> f b <= (c::'c::order) ==>

  2113   (!!x y. x < y ==> f x < f y) ==> f a < c"

  2114 proof -

  2115   assume r: "!!x y. x < y ==> f x < f y"

  2116   assume "a < b" hence "f a < f b" by (rule r)

  2117   also assume "f b <= c"

  2118   finally (order_less_le_trans) show ?thesis .

  2119 qed

  2120

  2121 lemma order_less_le_subst1: "(a::'a::order) < f b ==> (b::'b::order) <= c ==>

  2122   (!!x y. x <= y ==> f x <= f y) ==> a < f c"

  2123 proof -

  2124   assume r: "!!x y. x <= y ==> f x <= f y"

  2125   assume "a < f b"

  2126   also assume "b <= c" hence "f b <= f c" by (rule r)

  2127   finally (order_less_le_trans) show ?thesis .

  2128 qed

  2129

  2130 lemma order_subst1: "(a::'a::order) <= f b ==> (b::'b::order) <= c ==>

  2131   (!!x y. x <= y ==> f x <= f y) ==> a <= f c"

  2132 proof -

  2133   assume r: "!!x y. x <= y ==> f x <= f y"

  2134   assume "a <= f b"

  2135   also assume "b <= c" hence "f b <= f c" by (rule r)

  2136   finally (order_trans) show ?thesis .

  2137 qed

  2138

  2139 lemma order_subst2: "(a::'a::order) <= b ==> f b <= (c::'c::order) ==>

  2140   (!!x y. x <= y ==> f x <= f y) ==> f a <= c"

  2141 proof -

  2142   assume r: "!!x y. x <= y ==> f x <= f y"

  2143   assume "a <= b" hence "f a <= f b" by (rule r)

  2144   also assume "f b <= c"

  2145   finally (order_trans) show ?thesis .

  2146 qed

  2147

  2148 lemma ord_le_eq_subst: "a <= b ==> f b = c ==>

  2149   (!!x y. x <= y ==> f x <= f y) ==> f a <= c"

  2150 proof -

  2151   assume r: "!!x y. x <= y ==> f x <= f y"

  2152   assume "a <= b" hence "f a <= f b" by (rule r)

  2153   also assume "f b = c"

  2154   finally (ord_le_eq_trans) show ?thesis .

  2155 qed

  2156

  2157 lemma ord_eq_le_subst: "a = f b ==> b <= c ==>

  2158   (!!x y. x <= y ==> f x <= f y) ==> a <= f c"

  2159 proof -

  2160   assume r: "!!x y. x <= y ==> f x <= f y"

  2161   assume "a = f b"

  2162   also assume "b <= c" hence "f b <= f c" by (rule r)

  2163   finally (ord_eq_le_trans) show ?thesis .

  2164 qed

  2165

  2166 lemma ord_less_eq_subst: "a < b ==> f b = c ==>

  2167   (!!x y. x < y ==> f x < f y) ==> f a < c"

  2168 proof -

  2169   assume r: "!!x y. x < y ==> f x < f y"

  2170   assume "a < b" hence "f a < f b" by (rule r)

  2171   also assume "f b = c"

  2172   finally (ord_less_eq_trans) show ?thesis .

  2173 qed

  2174

  2175 lemma ord_eq_less_subst: "a = f b ==> b < c ==>

  2176   (!!x y. x < y ==> f x < f y) ==> a < f c"

  2177 proof -

  2178   assume r: "!!x y. x < y ==> f x < f y"

  2179   assume "a = f b"

  2180   also assume "b < c" hence "f b < f c" by (rule r)

  2181   finally (ord_eq_less_trans) show ?thesis .

  2182 qed

  2183

  2184 text {*

  2185   Note that this list of rules is in reverse order of priorities.

  2186 *}

  2187

  2188 lemmas basic_trans_rules [trans] =

  2189   order_less_subst2

  2190   order_less_subst1

  2191   order_le_less_subst2

  2192   order_le_less_subst1

  2193   order_less_le_subst2

  2194   order_less_le_subst1

  2195   order_subst2

  2196   order_subst1

  2197   ord_le_eq_subst

  2198   ord_eq_le_subst

  2199   ord_less_eq_subst

  2200   ord_eq_less_subst

  2201   forw_subst

  2202   back_subst

  2203   rev_mp

  2204   mp

  2205   set_rev_mp

  2206   set_mp

  2207   order_neq_le_trans

  2208   order_le_neq_trans

  2209   order_less_trans

  2210   order_less_asym'

  2211   order_le_less_trans

  2212   order_less_le_trans

  2213   order_trans

  2214   order_antisym

  2215   ord_le_eq_trans

  2216   ord_eq_le_trans

  2217   ord_less_eq_trans

  2218   ord_eq_less_trans

  2219   trans

  2220

  2221 end