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