
clasohm@923: (*  Title:      HOL/Set.thy
clasohm@923:     ID:         $Id$
wenzelm@12257:     Author:     Tobias Nipkow, Lawrence C Paulson and Markus Wenzel
wenzelm@12020:     License:    GPL (GNU GENERAL PUBLIC LICENSE)
clasohm@923: *)
clasohm@923: 
wenzelm@11979: header {* Set theory for higher-order logic *}
wenzelm@11979: 
wenzelm@12897: theory Set = HOL:
wenzelm@11979: 
wenzelm@11979: text {* A set in HOL is simply a predicate. *}
clasohm@923: 
wenzelm@2261: 
wenzelm@11979: subsection {* Basic syntax *}
wenzelm@2261: 
wenzelm@3947: global
wenzelm@3947: 
wenzelm@11979: typedecl 'a set
wenzelm@12338: arities set :: (type) type
wenzelm@3820: 
clasohm@923: consts
wenzelm@11979:   "{}"          :: "'a set"                             ("{}")
wenzelm@11979:   UNIV          :: "'a set"
wenzelm@11979:   insert        :: "'a => 'a set => 'a set"
wenzelm@11979:   Collect       :: "('a => bool) => 'a set"              -- "comprehension"
wenzelm@11979:   Int           :: "'a set => 'a set => 'a set"          (infixl 70)
wenzelm@11979:   Un            :: "'a set => 'a set => 'a set"          (infixl 65)
wenzelm@11979:   UNION         :: "'a set => ('a => 'b set) => 'b set"  -- "general union"
wenzelm@11979:   INTER         :: "'a set => ('a => 'b set) => 'b set"  -- "general intersection"
wenzelm@11979:   Union         :: "'a set set => 'a set"                -- "union of a set"
wenzelm@11979:   Inter         :: "'a set set => 'a set"                -- "intersection of a set"
wenzelm@11979:   Pow           :: "'a set => 'a set set"                -- "powerset"
wenzelm@11979:   Ball          :: "'a set => ('a => bool) => bool"      -- "bounded universal quantifiers"
wenzelm@11979:   Bex           :: "'a set => ('a => bool) => bool"      -- "bounded existential quantifiers"
wenzelm@11979:   image         :: "('a => 'b) => 'a set => 'b set"      (infixr "`" 90)
wenzelm@11979: 
wenzelm@11979: syntax
wenzelm@11979:   "op :"        :: "'a => 'a set => bool"                ("op :")
wenzelm@11979: consts
wenzelm@11979:   "op :"        :: "'a => 'a set => bool"                ("(_/ : _)" [50, 51] 50)  -- "membership"
wenzelm@11979: 
wenzelm@11979: local
wenzelm@11979: 
wenzelm@12338: instance set :: (type) ord ..
wenzelm@12338: instance set :: (type) minus ..
clasohm@923: 
clasohm@923: 
wenzelm@11979: subsection {* Additional concrete syntax *}
wenzelm@2261: 
clasohm@923: syntax
wenzelm@11979:   range         :: "('a => 'b) => 'b set"             -- "of function"
clasohm@923: 
wenzelm@11979:   "op ~:"       :: "'a => 'a set => bool"                 ("op ~:")  -- "non-membership"
wenzelm@11979:   "op ~:"       :: "'a => 'a set => bool"                 ("(_/ ~: _)" [50, 51] 50)
wenzelm@7238: 
wenzelm@11979:   "@Finset"     :: "args => 'a set"                       ("{(_)}")
wenzelm@11979:   "@Coll"       :: "pttrn => bool => 'a set"              ("(1{_./ _})")
wenzelm@11979:   "@SetCompr"   :: "'a => idts => bool => 'a set"         ("(1{_ |/_./ _})")
clasohm@923: 
wenzelm@11979:   "@INTER1"     :: "pttrns => 'b set => 'b set"           ("(3INT _./ _)" 10)
wenzelm@11979:   "@UNION1"     :: "pttrns => 'b set => 'b set"           ("(3UN _./ _)" 10)
wenzelm@11979:   "@INTER"      :: "pttrn => 'a set => 'b set => 'b set"  ("(3INT _:_./ _)" 10)
wenzelm@11979:   "@UNION"      :: "pttrn => 'a set => 'b set => 'b set"  ("(3UN _:_./ _)" 10)
clasohm@923: 
wenzelm@11979:   "_Ball"       :: "pttrn => 'a set => bool => bool"      ("(3ALL _:_./ _)" [0, 0, 10] 10)
wenzelm@11979:   "_Bex"        :: "pttrn => 'a set => bool => bool"      ("(3EX _:_./ _)" [0, 0, 10] 10)
clasohm@923: 
wenzelm@7238: syntax (HOL)
wenzelm@11979:   "_Ball"       :: "pttrn => 'a set => bool => bool"      ("(3! _:_./ _)" [0, 0, 10] 10)
wenzelm@11979:   "_Bex"        :: "pttrn => 'a set => bool => bool"      ("(3? _:_./ _)" [0, 0, 10] 10)
clasohm@923: 
clasohm@923: translations
nipkow@10832:   "range f"     == "f`UNIV"
clasohm@923:   "x ~: y"      == "~ (x : y)"
clasohm@923:   "{x, xs}"     == "insert x {xs}"
clasohm@923:   "{x}"         == "insert x {}"
nipkow@13764:   "{x. P}"      == "Collect (%x. P)"
paulson@4159:   "UN x y. B"   == "UN x. UN y. B"
paulson@4159:   "UN x. B"     == "UNION UNIV (%x. B)"
nipkow@13858:   "UN x. B"     == "UN x:UNIV. B"
wenzelm@7238:   "INT x y. B"  == "INT x. INT y. B"
paulson@4159:   "INT x. B"    == "INTER UNIV (%x. B)"
nipkow@13858:   "INT x. B"    == "INT x:UNIV. B"
nipkow@13764:   "UN x:A. B"   == "UNION A (%x. B)"
nipkow@13764:   "INT x:A. B"  == "INTER A (%x. B)"
nipkow@13764:   "ALL x:A. P"  == "Ball A (%x. P)"
nipkow@13764:   "EX x:A. P"   == "Bex A (%x. P)"
clasohm@923: 
wenzelm@12633: syntax (output)
wenzelm@11979:   "_setle"      :: "'a set => 'a set => bool"             ("op <=")
wenzelm@11979:   "_setle"      :: "'a set => 'a set => bool"             ("(_/ <= _)" [50, 51] 50)
wenzelm@11979:   "_setless"    :: "'a set => 'a set => bool"             ("op <")
wenzelm@11979:   "_setless"    :: "'a set => 'a set => bool"             ("(_/ < _)" [50, 51] 50)
clasohm@923: 
wenzelm@12114: syntax (xsymbols)
wenzelm@11979:   "_setle"      :: "'a set => 'a set => bool"             ("op \<subseteq>")
wenzelm@11979:   "_setle"      :: "'a set => 'a set => bool"             ("(_/ \<subseteq> _)" [50, 51] 50)
wenzelm@11979:   "_setless"    :: "'a set => 'a set => bool"             ("op \<subset>")
wenzelm@11979:   "_setless"    :: "'a set => 'a set => bool"             ("(_/ \<subset> _)" [50, 51] 50)
wenzelm@11979:   "op Int"      :: "'a set => 'a set => 'a set"           (infixl "\<inter>" 70)
wenzelm@11979:   "op Un"       :: "'a set => 'a set => 'a set"           (infixl "\<union>" 65)
wenzelm@11979:   "op :"        :: "'a => 'a set => bool"                 ("op \<in>")
wenzelm@11979:   "op :"        :: "'a => 'a set => bool"                 ("(_/ \<in> _)" [50, 51] 50)
wenzelm@11979:   "op ~:"       :: "'a => 'a set => bool"                 ("op \<notin>")
wenzelm@11979:   "op ~:"       :: "'a => 'a set => bool"                 ("(_/ \<notin> _)" [50, 51] 50)
wenzelm@11979:   "@UNION1"     :: "pttrns => 'b set => 'b set"           ("(3\<Union>_./ _)" 10)
wenzelm@11979:   "@INTER1"     :: "pttrns => 'b set => 'b set"           ("(3\<Inter>_./ _)" 10)
wenzelm@11979:   "@UNION"      :: "pttrn => 'a set => 'b set => 'b set"  ("(3\<Union>_\<in>_./ _)" 10)
wenzelm@11979:   "@INTER"      :: "pttrn => 'a set => 'b set => 'b set"  ("(3\<Inter>_\<in>_./ _)" 10)
wenzelm@11979:   Union         :: "'a set set => 'a set"                 ("\<Union>_" [90] 90)
wenzelm@11979:   Inter         :: "'a set set => 'a set"                 ("\<Inter>_" [90] 90)
wenzelm@11979:   "_Ball"       :: "pttrn => 'a set => bool => bool"      ("(3\<forall>_\<in>_./ _)" [0, 0, 10] 10)
wenzelm@11979:   "_Bex"        :: "pttrn => 'a set => bool => bool"      ("(3\<exists>_\<in>_./ _)" [0, 0, 10] 10)
wenzelm@2261: 
wenzelm@2412: translations
wenzelm@11979:   "op \<subseteq>" => "op <= :: _ set => _ set => bool"
wenzelm@11979:   "op \<subset>" => "op <  :: _ set => _ set => bool"
wenzelm@2261: 
wenzelm@2261: 
wenzelm@11979: typed_print_translation {*
wenzelm@11979:   let
wenzelm@11979:     fun le_tr' _ (Type ("fun", (Type ("set", _) :: _))) ts =
wenzelm@11979:           list_comb (Syntax.const "_setle", ts)
wenzelm@11979:       | le_tr' _ _ _ = raise Match;
wenzelm@11979: 
wenzelm@11979:     fun less_tr' _ (Type ("fun", (Type ("set", _) :: _))) ts =
wenzelm@11979:           list_comb (Syntax.const "_setless", ts)
wenzelm@11979:       | less_tr' _ _ _ = raise Match;
wenzelm@11979:   in [("op <=", le_tr'), ("op <", less_tr')] end
wenzelm@11979: *}
wenzelm@2261: 
wenzelm@11979: text {*
wenzelm@11979:   \medskip Translate between @{text "{e | x1...xn. P}"} and @{text
wenzelm@11979:   "{u. EX x1..xn. u = e & P}"}; @{text "{y. EX x1..xn. y = e & P}"} is
wenzelm@11979:   only translated if @{text "[0..n] subset bvs(e)"}.
wenzelm@11979: *}
wenzelm@11979: 
wenzelm@11979: parse_translation {*
wenzelm@11979:   let
wenzelm@11979:     val ex_tr = snd (mk_binder_tr ("EX ", "Ex"));
wenzelm@3947: 
wenzelm@11979:     fun nvars (Const ("_idts", _) $ _ $ idts) = nvars idts + 1
wenzelm@11979:       | nvars _ = 1;
wenzelm@11979: 
wenzelm@11979:     fun setcompr_tr [e, idts, b] =
wenzelm@11979:       let
wenzelm@11979:         val eq = Syntax.const "op =" $ Bound (nvars idts) $ e;
wenzelm@11979:         val P = Syntax.const "op &" $ eq $ b;
wenzelm@11979:         val exP = ex_tr [idts, P];
wenzelm@11979:       in Syntax.const "Collect" $ Abs ("", dummyT, exP) end;
wenzelm@11979: 
wenzelm@11979:   in [("@SetCompr", setcompr_tr)] end;
wenzelm@11979: *}
clasohm@923: 
nipkow@13763: (* To avoid eta-contraction of body: *)
wenzelm@11979: print_translation {*
nipkow@13763: let
nipkow@13763:   fun btr' syn [A,Abs abs] =
nipkow@13763:     let val (x,t) = atomic_abs_tr' abs
nipkow@13763:     in Syntax.const syn $ x $ A $ t end
nipkow@13763: in
nipkow@13858: [("Ball", btr' "_Ball"),("Bex", btr' "_Bex"),
nipkow@13858:  ("UNION", btr' "@UNION"),("INTER", btr' "@INTER")]
nipkow@13763: end
nipkow@13763: *}
nipkow@13763: 
nipkow@13763: print_translation {*
nipkow@13763: let
nipkow@13763:   val ex_tr' = snd (mk_binder_tr' ("Ex", "DUMMY"));
nipkow@13763: 
nipkow@13763:   fun setcompr_tr' [Abs (abs as (_, _, P))] =
nipkow@13763:     let
nipkow@13763:       fun check (Const ("Ex", _) $ Abs (_, _, P), n) = check (P, n + 1)
nipkow@13763:         | check (Const ("op &", _) $ (Const ("op =", _) $ Bound m $ e) $ P, n) =
nipkow@13763:             n > 0 andalso m = n andalso not (loose_bvar1 (P, n)) andalso
nipkow@13763:             ((0 upto (n - 1)) subset add_loose_bnos (e, 0, []))
nipkow@13764:         | check _ = false
clasohm@923: 
wenzelm@11979:         fun tr' (_ $ abs) =
wenzelm@11979:           let val _ $ idts $ (_ $ (_ $ _ $ e) $ Q) = ex_tr' [abs]
wenzelm@11979:           in Syntax.const "@SetCompr" $ e $ idts $ Q end;
nipkow@13763:     in if check (P, 0) then tr' P
nipkow@13763:        else let val (x,t) = atomic_abs_tr' abs
nipkow@13763:             in Syntax.const "@Coll" $ x $ t end
nipkow@13763:     end;
wenzelm@11979:   in [("Collect", setcompr_tr')] end;
wenzelm@11979: *}
wenzelm@11979: 
wenzelm@11979: 
wenzelm@11979: subsection {* Rules and definitions *}
wenzelm@11979: 
wenzelm@11979: text {* Isomorphisms between predicates and sets. *}
clasohm@923: 
wenzelm@11979: axioms
wenzelm@11979:   mem_Collect_eq [iff]: "(a : {x. P(x)}) = P(a)"
wenzelm@11979:   Collect_mem_eq [simp]: "{x. x:A} = A"
wenzelm@11979: 
wenzelm@11979: defs
wenzelm@11979:   Ball_def:     "Ball A P       == ALL x. x:A --> P(x)"
wenzelm@11979:   Bex_def:      "Bex A P        == EX x. x:A & P(x)"
wenzelm@11979: 
wenzelm@11979: defs (overloaded)
wenzelm@11979:   subset_def:   "A <= B         == ALL x:A. x:B"
wenzelm@11979:   psubset_def:  "A < B          == (A::'a set) <= B & ~ A=B"
wenzelm@11979:   Compl_def:    "- A            == {x. ~x:A}"
wenzelm@12257:   set_diff_def: "A - B          == {x. x:A & ~x:B}"
clasohm@923: 
clasohm@923: defs
wenzelm@11979:   Un_def:       "A Un B         == {x. x:A | x:B}"
wenzelm@11979:   Int_def:      "A Int B        == {x. x:A & x:B}"
wenzelm@11979:   INTER_def:    "INTER A B      == {y. ALL x:A. y: B(x)}"
wenzelm@11979:   UNION_def:    "UNION A B      == {y. EX x:A. y: B(x)}"
wenzelm@11979:   Inter_def:    "Inter S        == (INT x:S. x)"
wenzelm@11979:   Union_def:    "Union S        == (UN x:S. x)"
wenzelm@11979:   Pow_def:      "Pow A          == {B. B <= A}"
wenzelm@11979:   empty_def:    "{}             == {x. False}"
wenzelm@11979:   UNIV_def:     "UNIV           == {x. True}"
wenzelm@11979:   insert_def:   "insert a B     == {x. x=a} Un B"
wenzelm@11979:   image_def:    "f`A            == {y. EX x:A. y = f(x)}"
wenzelm@11979: 
wenzelm@11979: 
wenzelm@11979: subsection {* Lemmas and proof tool setup *}
wenzelm@11979: 
wenzelm@11979: subsubsection {* Relating predicates and sets *}
wenzelm@11979: 
wenzelm@12257: lemma CollectI: "P(a) ==> a : {x. P(x)}"
wenzelm@11979:   by simp
wenzelm@11979: 
wenzelm@11979: lemma CollectD: "a : {x. P(x)} ==> P(a)"
wenzelm@11979:   by simp
wenzelm@11979: 
wenzelm@12937: lemma set_ext: assumes prem: "(!!x. (x:A) = (x:B))" shows "A = B"
wenzelm@12257:   apply (rule prem [THEN ext, THEN arg_cong, THEN box_equals])
wenzelm@12257:    apply (rule Collect_mem_eq)
wenzelm@12257:   apply (rule Collect_mem_eq)
wenzelm@12257:   done
wenzelm@11979: 
wenzelm@11979: lemma Collect_cong: "(!!x. P x = Q x) ==> {x. P(x)} = {x. Q(x)}"
wenzelm@11979:   by simp
wenzelm@11979: 
wenzelm@12257: lemmas CollectE = CollectD [elim_format]
wenzelm@11979: 
wenzelm@11979: 
wenzelm@11979: subsubsection {* Bounded quantifiers *}
wenzelm@11979: 
wenzelm@11979: lemma ballI [intro!]: "(!!x. x:A ==> P x) ==> ALL x:A. P x"
wenzelm@11979:   by (simp add: Ball_def)
wenzelm@11979: 
wenzelm@11979: lemmas strip = impI allI ballI
wenzelm@11979: 
wenzelm@11979: lemma bspec [dest?]: "ALL x:A. P x ==> x:A ==> P x"
wenzelm@11979:   by (simp add: Ball_def)
wenzelm@11979: 
wenzelm@11979: lemma ballE [elim]: "ALL x:A. P x ==> (P x ==> Q) ==> (x ~: A ==> Q) ==> Q"
wenzelm@11979:   by (unfold Ball_def) blast
wenzelm@11979: 
wenzelm@11979: text {*
wenzelm@11979:   \medskip This tactic takes assumptions @{prop "ALL x:A. P x"} and
wenzelm@11979:   @{prop "a:A"}; creates assumption @{prop "P a"}.
wenzelm@11979: *}
wenzelm@11979: 
wenzelm@11979: ML {*
wenzelm@11979:   local val ballE = thm "ballE"
wenzelm@11979:   in fun ball_tac i = etac ballE i THEN contr_tac (i + 1) end;
wenzelm@11979: *}
wenzelm@11979: 
wenzelm@11979: text {*
wenzelm@11979:   Gives better instantiation for bound:
wenzelm@11979: *}
wenzelm@11979: 
wenzelm@11979: ML_setup {*
wenzelm@11979:   claset_ref() := claset() addbefore ("bspec", datac (thm "bspec") 1);
wenzelm@11979: *}
wenzelm@11979: 
wenzelm@11979: lemma bexI [intro]: "P x ==> x:A ==> EX x:A. P x"
wenzelm@11979:   -- {* Normally the best argument order: @{prop "P x"} constrains the
wenzelm@11979:     choice of @{prop "x:A"}. *}
wenzelm@11979:   by (unfold Bex_def) blast
wenzelm@11979: 
wenzelm@13113: lemma rev_bexI [intro?]: "x:A ==> P x ==> EX x:A. P x"
wenzelm@11979:   -- {* The best argument order when there is only one @{prop "x:A"}. *}
wenzelm@11979:   by (unfold Bex_def) blast
wenzelm@11979: 
wenzelm@11979: lemma bexCI: "(ALL x:A. ~P x ==> P a) ==> a:A ==> EX x:A. P x"
wenzelm@11979:   by (unfold Bex_def) blast
wenzelm@11979: 
wenzelm@11979: lemma bexE [elim!]: "EX x:A. P x ==> (!!x. x:A ==> P x ==> Q) ==> Q"
wenzelm@11979:   by (unfold Bex_def) blast
wenzelm@11979: 
wenzelm@11979: lemma ball_triv [simp]: "(ALL x:A. P) = ((EX x. x:A) --> P)"
wenzelm@11979:   -- {* Trival rewrite rule. *}
wenzelm@11979:   by (simp add: Ball_def)
wenzelm@11979: 
wenzelm@11979: lemma bex_triv [simp]: "(EX x:A. P) = ((EX x. x:A) & P)"
wenzelm@11979:   -- {* Dual form for existentials. *}
wenzelm@11979:   by (simp add: Bex_def)
wenzelm@11979: 
wenzelm@11979: lemma bex_triv_one_point1 [simp]: "(EX x:A. x = a) = (a:A)"
wenzelm@11979:   by blast
wenzelm@11979: 
wenzelm@11979: lemma bex_triv_one_point2 [simp]: "(EX x:A. a = x) = (a:A)"
wenzelm@11979:   by blast
wenzelm@11979: 
wenzelm@11979: lemma bex_one_point1 [simp]: "(EX x:A. x = a & P x) = (a:A & P a)"
wenzelm@11979:   by blast
wenzelm@11979: 
wenzelm@11979: lemma bex_one_point2 [simp]: "(EX x:A. a = x & P x) = (a:A & P a)"
wenzelm@11979:   by blast
wenzelm@11979: 
wenzelm@11979: lemma ball_one_point1 [simp]: "(ALL x:A. x = a --> P x) = (a:A --> P a)"
wenzelm@11979:   by blast
wenzelm@11979: 
wenzelm@11979: lemma ball_one_point2 [simp]: "(ALL x:A. a = x --> P x) = (a:A --> P a)"
wenzelm@11979:   by blast
wenzelm@11979: 
wenzelm@11979: ML_setup {*
wenzelm@13462:   local
wenzelm@11979:     val Ball_def = thm "Ball_def";
wenzelm@11979:     val Bex_def = thm "Bex_def";
wenzelm@11979: 
wenzelm@11979:     val prove_bex_tac =
wenzelm@11979:       rewrite_goals_tac [Bex_def] THEN Quantifier1.prove_one_point_ex_tac;
wenzelm@11979:     val rearrange_bex = Quantifier1.rearrange_bex prove_bex_tac;
wenzelm@11979: 
wenzelm@11979:     val prove_ball_tac =
wenzelm@11979:       rewrite_goals_tac [Ball_def] THEN Quantifier1.prove_one_point_all_tac;
wenzelm@11979:     val rearrange_ball = Quantifier1.rearrange_ball prove_ball_tac;
wenzelm@11979:   in
wenzelm@13462:     val defBEX_regroup = Simplifier.simproc (Theory.sign_of (the_context ()))
wenzelm@13462:       "defined BEX" ["EX x:A. P x & Q x"] rearrange_bex;
wenzelm@13462:     val defBALL_regroup = Simplifier.simproc (Theory.sign_of (the_context ()))
wenzelm@13462:       "defined BALL" ["ALL x:A. P x --> Q x"] rearrange_ball;
wenzelm@11979:   end;
wenzelm@13462: 
wenzelm@13462:   Addsimprocs [defBALL_regroup, defBEX_regroup];
wenzelm@11979: *}
wenzelm@11979: 
wenzelm@11979: 
wenzelm@11979: subsubsection {* Congruence rules *}
wenzelm@11979: 
wenzelm@11979: lemma ball_cong [cong]:
wenzelm@11979:   "A = B ==> (!!x. x:B ==> P x = Q x) ==>
wenzelm@11979:     (ALL x:A. P x) = (ALL x:B. Q x)"
wenzelm@11979:   by (simp add: Ball_def)
wenzelm@11979: 
wenzelm@11979: lemma bex_cong [cong]:
wenzelm@11979:   "A = B ==> (!!x. x:B ==> P x = Q x) ==>
wenzelm@11979:     (EX x:A. P x) = (EX x:B. Q x)"
wenzelm@11979:   by (simp add: Bex_def cong: conj_cong)
regensbu@1273: 
wenzelm@7238: 
wenzelm@11979: subsubsection {* Subsets *}
wenzelm@11979: 
wenzelm@12897: lemma subsetI [intro!]: "(!!x. x:A ==> x:B) ==> A \<subseteq> B"
wenzelm@11979:   by (simp add: subset_def)
wenzelm@11979: 
wenzelm@11979: text {*
wenzelm@11979:   \medskip Map the type @{text "'a set => anything"} to just @{typ
wenzelm@11979:   'a}; for overloading constants whose first argument has type @{typ
wenzelm@11979:   "'a set"}.
wenzelm@11979: *}
wenzelm@11979: 
wenzelm@12897: lemma subsetD [elim]: "A \<subseteq> B ==> c \<in> A ==> c \<in> B"
wenzelm@11979:   -- {* Rule in Modus Ponens style. *}
wenzelm@11979:   by (unfold subset_def) blast
wenzelm@11979: 
wenzelm@11979: declare subsetD [intro?] -- FIXME
wenzelm@11979: 
wenzelm@12897: lemma rev_subsetD: "c \<in> A ==> A \<subseteq> B ==> c \<in> B"
wenzelm@11979:   -- {* The same, with reversed premises for use with @{text erule} --
wenzelm@11979:       cf @{text rev_mp}. *}
wenzelm@11979:   by (rule subsetD)
wenzelm@11979: 
wenzelm@11979: declare rev_subsetD [intro?] -- FIXME
wenzelm@11979: 
wenzelm@11979: text {*
wenzelm@12897:   \medskip Converts @{prop "A \<subseteq> B"} to @{prop "x \<in> A ==> x \<in> B"}.
wenzelm@11979: *}
wenzelm@11979: 
wenzelm@11979: ML {*
wenzelm@11979:   local val rev_subsetD = thm "rev_subsetD"
wenzelm@11979:   in fun impOfSubs th = th RSN (2, rev_subsetD) end;
wenzelm@11979: *}
wenzelm@11979: 
wenzelm@12897: lemma subsetCE [elim]: "A \<subseteq>  B ==> (c \<notin> A ==> P) ==> (c \<in> B ==> P) ==> P"
wenzelm@11979:   -- {* Classical elimination rule. *}
wenzelm@11979:   by (unfold subset_def) blast
wenzelm@11979: 
wenzelm@11979: text {*
wenzelm@12897:   \medskip Takes assumptions @{prop "A \<subseteq> B"}; @{prop "c \<in> A"} and
wenzelm@12897:   creates the assumption @{prop "c \<in> B"}.
wenzelm@11979: *}
wenzelm@11979: 
wenzelm@11979: ML {*
wenzelm@11979:   local val subsetCE = thm "subsetCE"
wenzelm@11979:   in fun set_mp_tac i = etac subsetCE i THEN mp_tac i end;
wenzelm@11979: *}
wenzelm@11979: 
wenzelm@12897: lemma contra_subsetD: "A \<subseteq> B ==> c \<notin> B ==> c \<notin> A"
wenzelm@11979:   by blast
wenzelm@11979: 
wenzelm@12897: lemma subset_refl: "A \<subseteq> A"
wenzelm@11979:   by fast
wenzelm@11979: 
wenzelm@12897: lemma subset_trans: "A \<subseteq> B ==> B \<subseteq> C ==> A \<subseteq> C"
wenzelm@11979:   by blast
clasohm@923: 
wenzelm@2261: 
wenzelm@11979: subsubsection {* Equality *}
wenzelm@11979: 
wenzelm@12897: lemma subset_antisym [intro!]: "A \<subseteq> B ==> B \<subseteq> A ==> A = B"
wenzelm@11979:   -- {* Anti-symmetry of the subset relation. *}
wenzelm@12897:   by (rules intro: set_ext subsetD)
wenzelm@12897: 
wenzelm@12897: lemmas equalityI [intro!] = subset_antisym
wenzelm@11979: 
wenzelm@11979: text {*
wenzelm@11979:   \medskip Equality rules from ZF set theory -- are they appropriate
wenzelm@11979:   here?
wenzelm@11979: *}
wenzelm@11979: 
wenzelm@12897: lemma equalityD1: "A = B ==> A \<subseteq> B"
wenzelm@11979:   by (simp add: subset_refl)
wenzelm@11979: 
wenzelm@12897: lemma equalityD2: "A = B ==> B \<subseteq> A"
wenzelm@11979:   by (simp add: subset_refl)
wenzelm@11979: 
wenzelm@11979: text {*
wenzelm@11979:   \medskip Be careful when adding this to the claset as @{text
wenzelm@11979:   subset_empty} is in the simpset: @{prop "A = {}"} goes to @{prop "{}
wenzelm@12897:   \<subseteq> A"} and @{prop "A \<subseteq> {}"} and then back to @{prop "A = {}"}!
wenzelm@11979: *}
wenzelm@11979: 
wenzelm@12897: lemma equalityE: "A = B ==> (A \<subseteq> B ==> B \<subseteq> A ==> P) ==> P"
wenzelm@11979:   by (simp add: subset_refl)
clasohm@923: 
wenzelm@11979: lemma equalityCE [elim]:
wenzelm@12897:     "A = B ==> (c \<in> A ==> c \<in> B ==> P) ==> (c \<notin> A ==> c \<notin> B ==> P) ==> P"
wenzelm@11979:   by blast
wenzelm@11979: 
wenzelm@11979: text {*
wenzelm@11979:   \medskip Lemma for creating induction formulae -- for "pattern
wenzelm@11979:   matching" on @{text p}.  To make the induction hypotheses usable,
wenzelm@11979:   apply @{text spec} or @{text bspec} to put universal quantifiers over the free
wenzelm@11979:   variables in @{text p}.
wenzelm@11979: *}
wenzelm@11979: 
wenzelm@11979: lemma setup_induction: "p:A ==> (!!z. z:A ==> p = z --> R) ==> R"
wenzelm@11979:   by simp
clasohm@923: 
wenzelm@11979: lemma eqset_imp_iff: "A = B ==> (x : A) = (x : B)"
wenzelm@11979:   by simp
wenzelm@11979: 
wenzelm@11979: 
wenzelm@11979: subsubsection {* The universal set -- UNIV *}
wenzelm@11979: 
wenzelm@11979: lemma UNIV_I [simp]: "x : UNIV"
wenzelm@11979:   by (simp add: UNIV_def)
wenzelm@11979: 
wenzelm@11979: declare UNIV_I [intro]  -- {* unsafe makes it less likely to cause problems *}
wenzelm@11979: 
wenzelm@11979: lemma UNIV_witness [intro?]: "EX x. x : UNIV"
wenzelm@11979:   by simp
wenzelm@11979: 
wenzelm@12897: lemma subset_UNIV: "A \<subseteq> UNIV"
wenzelm@11979:   by (rule subsetI) (rule UNIV_I)
wenzelm@2388: 
wenzelm@11979: text {*
wenzelm@11979:   \medskip Eta-contracting these two rules (to remove @{text P})
wenzelm@11979:   causes them to be ignored because of their interaction with
wenzelm@11979:   congruence rules.
wenzelm@11979: *}
wenzelm@11979: 
wenzelm@11979: lemma ball_UNIV [simp]: "Ball UNIV P = All P"
wenzelm@11979:   by (simp add: Ball_def)
wenzelm@11979: 
wenzelm@11979: lemma bex_UNIV [simp]: "Bex UNIV P = Ex P"
wenzelm@11979:   by (simp add: Bex_def)
wenzelm@11979: 
wenzelm@11979: 
wenzelm@11979: subsubsection {* The empty set *}
wenzelm@11979: 
wenzelm@11979: lemma empty_iff [simp]: "(c : {}) = False"
wenzelm@11979:   by (simp add: empty_def)
wenzelm@11979: 
wenzelm@11979: lemma emptyE [elim!]: "a : {} ==> P"
wenzelm@11979:   by simp
wenzelm@11979: 
wenzelm@12897: lemma empty_subsetI [iff]: "{} \<subseteq> A"
wenzelm@11979:     -- {* One effect is to delete the ASSUMPTION @{prop "{} <= A"} *}
wenzelm@11979:   by blast
wenzelm@11979: 
wenzelm@12897: lemma equals0I: "(!!y. y \<in> A ==> False) ==> A = {}"
wenzelm@11979:   by blast
wenzelm@2388: 
wenzelm@12897: lemma equals0D: "A = {} ==> a \<notin> A"
wenzelm@11979:     -- {* Use for reasoning about disjointness: @{prop "A Int B = {}"} *}
wenzelm@11979:   by blast
wenzelm@11979: 
wenzelm@11979: lemma ball_empty [simp]: "Ball {} P = True"
wenzelm@11979:   by (simp add: Ball_def)
wenzelm@11979: 
wenzelm@11979: lemma bex_empty [simp]: "Bex {} P = False"
wenzelm@11979:   by (simp add: Bex_def)
wenzelm@11979: 
wenzelm@11979: lemma UNIV_not_empty [iff]: "UNIV ~= {}"
wenzelm@11979:   by (blast elim: equalityE)
wenzelm@11979: 
wenzelm@11979: 
wenzelm@12023: subsubsection {* The Powerset operator -- Pow *}
wenzelm@11979: 
wenzelm@12897: lemma Pow_iff [iff]: "(A \<in> Pow B) = (A \<subseteq> B)"
wenzelm@11979:   by (simp add: Pow_def)
wenzelm@11979: 
wenzelm@12897: lemma PowI: "A \<subseteq> B ==> A \<in> Pow B"
wenzelm@11979:   by (simp add: Pow_def)
wenzelm@11979: 
wenzelm@12897: lemma PowD: "A \<in> Pow B ==> A \<subseteq> B"
wenzelm@11979:   by (simp add: Pow_def)
wenzelm@11979: 
wenzelm@12897: lemma Pow_bottom: "{} \<in> Pow B"
wenzelm@11979:   by simp
wenzelm@11979: 
wenzelm@12897: lemma Pow_top: "A \<in> Pow A"
wenzelm@11979:   by (simp add: subset_refl)
wenzelm@2684: 
wenzelm@2388: 
wenzelm@11979: subsubsection {* Set complement *}
wenzelm@11979: 
wenzelm@12897: lemma Compl_iff [simp]: "(c \<in> -A) = (c \<notin> A)"
wenzelm@11979:   by (unfold Compl_def) blast
wenzelm@11979: 
wenzelm@12897: lemma ComplI [intro!]: "(c \<in> A ==> False) ==> c \<in> -A"
wenzelm@11979:   by (unfold Compl_def) blast
wenzelm@11979: 
wenzelm@11979: text {*
wenzelm@11979:   \medskip This form, with negated conclusion, works well with the
wenzelm@11979:   Classical prover.  Negated assumptions behave like formulae on the
wenzelm@11979:   right side of the notional turnstile ... *}
wenzelm@11979: 
wenzelm@11979: lemma ComplD: "c : -A ==> c~:A"
wenzelm@11979:   by (unfold Compl_def) blast
wenzelm@11979: 
wenzelm@11979: lemmas ComplE [elim!] = ComplD [elim_format]
wenzelm@11979: 
wenzelm@11979: 
wenzelm@11979: subsubsection {* Binary union -- Un *}
clasohm@923: 
wenzelm@11979: lemma Un_iff [simp]: "(c : A Un B) = (c:A | c:B)"
wenzelm@11979:   by (unfold Un_def) blast
wenzelm@11979: 
wenzelm@11979: lemma UnI1 [elim?]: "c:A ==> c : A Un B"
wenzelm@11979:   by simp
wenzelm@11979: 
wenzelm@11979: lemma UnI2 [elim?]: "c:B ==> c : A Un B"
wenzelm@11979:   by simp
clasohm@923: 
wenzelm@11979: text {*
wenzelm@11979:   \medskip Classical introduction rule: no commitment to @{prop A} vs
wenzelm@11979:   @{prop B}.
wenzelm@11979: *}
wenzelm@11979: 
wenzelm@11979: lemma UnCI [intro!]: "(c~:B ==> c:A) ==> c : A Un B"
wenzelm@11979:   by auto
wenzelm@11979: 
wenzelm@11979: lemma UnE [elim!]: "c : A Un B ==> (c:A ==> P) ==> (c:B ==> P) ==> P"
wenzelm@11979:   by (unfold Un_def) blast
wenzelm@11979: 
wenzelm@11979: 
wenzelm@12023: subsubsection {* Binary intersection -- Int *}
clasohm@923: 
wenzelm@11979: lemma Int_iff [simp]: "(c : A Int B) = (c:A & c:B)"
wenzelm@11979:   by (unfold Int_def) blast
wenzelm@11979: 
wenzelm@11979: lemma IntI [intro!]: "c:A ==> c:B ==> c : A Int B"
wenzelm@11979:   by simp
wenzelm@11979: 
wenzelm@11979: lemma IntD1: "c : A Int B ==> c:A"
wenzelm@11979:   by simp
wenzelm@11979: 
wenzelm@11979: lemma IntD2: "c : A Int B ==> c:B"
wenzelm@11979:   by simp
wenzelm@11979: 
wenzelm@11979: lemma IntE [elim!]: "c : A Int B ==> (c:A ==> c:B ==> P) ==> P"
wenzelm@11979:   by simp
wenzelm@11979: 
wenzelm@11979: 
wenzelm@12023: subsubsection {* Set difference *}
wenzelm@11979: 
wenzelm@11979: lemma Diff_iff [simp]: "(c : A - B) = (c:A & c~:B)"
wenzelm@11979:   by (unfold set_diff_def) blast
clasohm@923: 
wenzelm@11979: lemma DiffI [intro!]: "c : A ==> c ~: B ==> c : A - B"
wenzelm@11979:   by simp
wenzelm@11979: 
wenzelm@11979: lemma DiffD1: "c : A - B ==> c : A"
wenzelm@11979:   by simp
wenzelm@11979: 
wenzelm@11979: lemma DiffD2: "c : A - B ==> c : B ==> P"
wenzelm@11979:   by simp
wenzelm@11979: 
wenzelm@11979: lemma DiffE [elim!]: "c : A - B ==> (c:A ==> c~:B ==> P) ==> P"
wenzelm@11979:   by simp
wenzelm@11979: 
wenzelm@11979: 
wenzelm@11979: subsubsection {* Augmenting a set -- insert *}
wenzelm@11979: 
wenzelm@11979: lemma insert_iff [simp]: "(a : insert b A) = (a = b | a:A)"
wenzelm@11979:   by (unfold insert_def) blast
wenzelm@11979: 
wenzelm@11979: lemma insertI1: "a : insert a B"
wenzelm@11979:   by simp
wenzelm@11979: 
wenzelm@11979: lemma insertI2: "a : B ==> a : insert b B"
wenzelm@11979:   by simp
clasohm@923: 
wenzelm@11979: lemma insertE [elim!]: "a : insert b A ==> (a = b ==> P) ==> (a:A ==> P) ==> P"
wenzelm@11979:   by (unfold insert_def) blast
wenzelm@11979: 
wenzelm@11979: lemma insertCI [intro!]: "(a~:B ==> a = b) ==> a: insert b B"
wenzelm@11979:   -- {* Classical introduction rule. *}
wenzelm@11979:   by auto
wenzelm@11979: 
wenzelm@12897: lemma subset_insert_iff: "(A \<subseteq> insert x B) = (if x:A then A - {x} \<subseteq> B else A \<subseteq> B)"
wenzelm@11979:   by auto
wenzelm@11979: 
wenzelm@11979: 
wenzelm@11979: subsubsection {* Singletons, using insert *}
wenzelm@11979: 
wenzelm@11979: lemma singletonI [intro!]: "a : {a}"
wenzelm@11979:     -- {* Redundant? But unlike @{text insertCI}, it proves the subgoal immediately! *}
wenzelm@11979:   by (rule insertI1)
wenzelm@11979: 
wenzelm@11979: lemma singletonD: "b : {a} ==> b = a"
wenzelm@11979:   by blast
wenzelm@11979: 
wenzelm@11979: lemmas singletonE [elim!] = singletonD [elim_format]
wenzelm@11979: 
wenzelm@11979: lemma singleton_iff: "(b : {a}) = (b = a)"
wenzelm@11979:   by blast
wenzelm@11979: 
wenzelm@11979: lemma singleton_inject [dest!]: "{a} = {b} ==> a = b"
wenzelm@11979:   by blast
wenzelm@11979: 
wenzelm@12897: lemma singleton_insert_inj_eq [iff]: "({b} = insert a A) = (a = b & A \<subseteq> {b})"
wenzelm@11979:   by blast
wenzelm@11979: 
wenzelm@12897: lemma singleton_insert_inj_eq' [iff]: "(insert a A = {b}) = (a = b & A \<subseteq> {b})"
wenzelm@11979:   by blast
wenzelm@11979: 
wenzelm@12897: lemma subset_singletonD: "A \<subseteq> {x} ==> A = {} | A = {x}"
wenzelm@11979:   by fast
wenzelm@11979: 
wenzelm@11979: lemma singleton_conv [simp]: "{x. x = a} = {a}"
wenzelm@11979:   by blast
wenzelm@11979: 
wenzelm@11979: lemma singleton_conv2 [simp]: "{x. a = x} = {a}"
wenzelm@11979:   by blast
clasohm@923: 
wenzelm@12897: lemma diff_single_insert: "A - {x} \<subseteq> B ==> x \<in> A ==> A \<subseteq> insert x B"
wenzelm@11979:   by blast
wenzelm@11979: 
wenzelm@11979: 
wenzelm@11979: subsubsection {* Unions of families *}
wenzelm@11979: 
wenzelm@11979: text {*
wenzelm@11979:   @{term [source] "UN x:A. B x"} is @{term "Union (B`A)"}.
wenzelm@11979: *}
wenzelm@11979: 
wenzelm@11979: lemma UN_iff [simp]: "(b: (UN x:A. B x)) = (EX x:A. b: B x)"
wenzelm@11979:   by (unfold UNION_def) blast
wenzelm@11979: 
wenzelm@11979: lemma UN_I [intro]: "a:A ==> b: B a ==> b: (UN x:A. B x)"
wenzelm@11979:   -- {* The order of the premises presupposes that @{term A} is rigid;
wenzelm@11979:     @{term b} may be flexible. *}
wenzelm@11979:   by auto
wenzelm@11979: 
wenzelm@11979: lemma UN_E [elim!]: "b : (UN x:A. B x) ==> (!!x. x:A ==> b: B x ==> R) ==> R"
wenzelm@11979:   by (unfold UNION_def) blast
clasohm@923: 
wenzelm@11979: lemma UN_cong [cong]:
wenzelm@11979:     "A = B ==> (!!x. x:B ==> C x = D x) ==> (UN x:A. C x) = (UN x:B. D x)"
wenzelm@11979:   by (simp add: UNION_def)
wenzelm@11979: 
wenzelm@11979: 
wenzelm@11979: subsubsection {* Intersections of families *}
wenzelm@11979: 
wenzelm@11979: text {* @{term [source] "INT x:A. B x"} is @{term "Inter (B`A)"}. *}
wenzelm@11979: 
wenzelm@11979: lemma INT_iff [simp]: "(b: (INT x:A. B x)) = (ALL x:A. b: B x)"
wenzelm@11979:   by (unfold INTER_def) blast
clasohm@923: 
wenzelm@11979: lemma INT_I [intro!]: "(!!x. x:A ==> b: B x) ==> b : (INT x:A. B x)"
wenzelm@11979:   by (unfold INTER_def) blast
wenzelm@11979: 
wenzelm@11979: lemma INT_D [elim]: "b : (INT x:A. B x) ==> a:A ==> b: B a"
wenzelm@11979:   by auto
wenzelm@11979: 
wenzelm@11979: lemma INT_E [elim]: "b : (INT x:A. B x) ==> (b: B a ==> R) ==> (a~:A ==> R) ==> R"
wenzelm@11979:   -- {* "Classical" elimination -- by the Excluded Middle on @{prop "a:A"}. *}
wenzelm@11979:   by (unfold INTER_def) blast
wenzelm@11979: 
wenzelm@11979: lemma INT_cong [cong]:
wenzelm@11979:     "A = B ==> (!!x. x:B ==> C x = D x) ==> (INT x:A. C x) = (INT x:B. D x)"
wenzelm@11979:   by (simp add: INTER_def)
wenzelm@7238: 
clasohm@923: 
wenzelm@11979: subsubsection {* Union *}
wenzelm@11979: 
wenzelm@11979: lemma Union_iff [simp]: "(A : Union C) = (EX X:C. A:X)"
wenzelm@11979:   by (unfold Union_def) blast
wenzelm@11979: 
wenzelm@11979: lemma UnionI [intro]: "X:C ==> A:X ==> A : Union C"
wenzelm@11979:   -- {* The order of the premises presupposes that @{term C} is rigid;
wenzelm@11979:     @{term A} may be flexible. *}
wenzelm@11979:   by auto
wenzelm@11979: 
wenzelm@11979: lemma UnionE [elim!]: "A : Union C ==> (!!X. A:X ==> X:C ==> R) ==> R"
wenzelm@11979:   by (unfold Union_def) blast
wenzelm@11979: 
wenzelm@11979: 
wenzelm@11979: subsubsection {* Inter *}
wenzelm@11979: 
wenzelm@11979: lemma Inter_iff [simp]: "(A : Inter C) = (ALL X:C. A:X)"
wenzelm@11979:   by (unfold Inter_def) blast
wenzelm@11979: 
wenzelm@11979: lemma InterI [intro!]: "(!!X. X:C ==> A:X) ==> A : Inter C"
wenzelm@11979:   by (simp add: Inter_def)
wenzelm@11979: 
wenzelm@11979: text {*
wenzelm@11979:   \medskip A ``destruct'' rule -- every @{term X} in @{term C}
wenzelm@11979:   contains @{term A} as an element, but @{prop "A:X"} can hold when
wenzelm@11979:   @{prop "X:C"} does not!  This rule is analogous to @{text spec}.
wenzelm@11979: *}
wenzelm@11979: 
wenzelm@11979: lemma InterD [elim]: "A : Inter C ==> X:C ==> A:X"
wenzelm@11979:   by auto
wenzelm@11979: 
wenzelm@11979: lemma InterE [elim]: "A : Inter C ==> (X~:C ==> R) ==> (A:X ==> R) ==> R"
wenzelm@11979:   -- {* ``Classical'' elimination rule -- does not require proving
wenzelm@11979:     @{prop "X:C"}. *}
wenzelm@11979:   by (unfold Inter_def) blast
wenzelm@11979: 
wenzelm@11979: text {*
wenzelm@11979:   \medskip Image of a set under a function.  Frequently @{term b} does
wenzelm@11979:   not have the syntactic form of @{term "f x"}.
wenzelm@11979: *}
wenzelm@11979: 
wenzelm@11979: lemma image_eqI [simp, intro]: "b = f x ==> x:A ==> b : f`A"
wenzelm@11979:   by (unfold image_def) blast
wenzelm@11979: 
wenzelm@11979: lemma imageI: "x : A ==> f x : f ` A"
wenzelm@11979:   by (rule image_eqI) (rule refl)
wenzelm@11979: 
wenzelm@11979: lemma rev_image_eqI: "x:A ==> b = f x ==> b : f`A"
wenzelm@11979:   -- {* This version's more effective when we already have the
wenzelm@11979:     required @{term x}. *}
wenzelm@11979:   by (unfold image_def) blast
wenzelm@11979: 
wenzelm@11979: lemma imageE [elim!]:
wenzelm@11979:   "b : (%x. f x)`A ==> (!!x. b = f x ==> x:A ==> P) ==> P"
wenzelm@11979:   -- {* The eta-expansion gives variable-name preservation. *}
wenzelm@11979:   by (unfold image_def) blast
wenzelm@11979: 
wenzelm@11979: lemma image_Un: "f`(A Un B) = f`A Un f`B"
wenzelm@11979:   by blast
wenzelm@11979: 
wenzelm@11979: lemma image_iff: "(z : f`A) = (EX x:A. z = f x)"
wenzelm@11979:   by blast
wenzelm@11979: 
wenzelm@12897: lemma image_subset_iff: "(f`A \<subseteq> B) = (\<forall>x\<in>A. f x \<in> B)"
wenzelm@11979:   -- {* This rewrite rule would confuse users if made default. *}
wenzelm@11979:   by blast
wenzelm@11979: 
wenzelm@12897: lemma subset_image_iff: "(B \<subseteq> f`A) = (EX AA. AA \<subseteq> A & B = f`AA)"
wenzelm@11979:   apply safe
wenzelm@11979:    prefer 2 apply fast
wenzelm@11979:   apply (rule_tac x = "{a. a : A & f a : B}" in exI)
wenzelm@11979:   apply fast
wenzelm@11979:   done
wenzelm@11979: 
wenzelm@12897: lemma image_subsetI: "(!!x. x \<in> A ==> f x \<in> B) ==> f`A \<subseteq> B"
wenzelm@11979:   -- {* Replaces the three steps @{text subsetI}, @{text imageE},
wenzelm@11979:     @{text hypsubst}, but breaks too many existing proofs. *}
wenzelm@11979:   by blast
wenzelm@11979: 
wenzelm@11979: text {*
wenzelm@11979:   \medskip Range of a function -- just a translation for image!
wenzelm@11979: *}
wenzelm@11979: 
wenzelm@12897: lemma range_eqI: "b = f x ==> b \<in> range f"
wenzelm@11979:   by simp
wenzelm@11979: 
wenzelm@12897: lemma rangeI: "f x \<in> range f"
wenzelm@11979:   by simp
wenzelm@11979: 
wenzelm@12897: lemma rangeE [elim?]: "b \<in> range (\<lambda>x. f x) ==> (!!x. b = f x ==> P) ==> P"
wenzelm@11979:   by blast
wenzelm@11979: 
wenzelm@11979: 
wenzelm@11979: subsubsection {* Set reasoning tools *}
wenzelm@11979: 
wenzelm@11979: text {*
wenzelm@11979:   Rewrite rules for boolean case-splitting: faster than @{text
wenzelm@11979:   "split_if [split]"}.
wenzelm@11979: *}
wenzelm@11979: 
wenzelm@11979: lemma split_if_eq1: "((if Q then x else y) = b) = ((Q --> x = b) & (~ Q --> y = b))"
wenzelm@11979:   by (rule split_if)
wenzelm@11979: 
wenzelm@11979: lemma split_if_eq2: "(a = (if Q then x else y)) = ((Q --> a = x) & (~ Q --> a = y))"
wenzelm@11979:   by (rule split_if)
wenzelm@11979: 
wenzelm@11979: text {*
wenzelm@11979:   Split ifs on either side of the membership relation.  Not for @{text
wenzelm@11979:   "[simp]"} -- can cause goals to blow up!
wenzelm@11979: *}
wenzelm@11979: 
wenzelm@11979: lemma split_if_mem1: "((if Q then x else y) : b) = ((Q --> x : b) & (~ Q --> y : b))"
wenzelm@11979:   by (rule split_if)
wenzelm@11979: 
wenzelm@11979: lemma split_if_mem2: "(a : (if Q then x else y)) = ((Q --> a : x) & (~ Q --> a : y))"
wenzelm@11979:   by (rule split_if)
wenzelm@11979: 
wenzelm@11979: lemmas split_ifs = if_bool_eq_conj split_if_eq1 split_if_eq2 split_if_mem1 split_if_mem2
wenzelm@11979: 
wenzelm@11979: lemmas mem_simps =
wenzelm@11979:   insert_iff empty_iff Un_iff Int_iff Compl_iff Diff_iff
wenzelm@11979:   mem_Collect_eq UN_iff Union_iff INT_iff Inter_iff
wenzelm@11979:   -- {* Each of these has ALREADY been added @{text "[simp]"} above. *}
wenzelm@11979: 
wenzelm@11979: (*Would like to add these, but the existing code only searches for the
wenzelm@11979:   outer-level constant, which in this case is just "op :"; we instead need
wenzelm@11979:   to use term-nets to associate patterns with rules.  Also, if a rule fails to
wenzelm@11979:   apply, then the formula should be kept.
wenzelm@11979:   [("uminus", Compl_iff RS iffD1), ("op -", [Diff_iff RS iffD1]),
wenzelm@11979:    ("op Int", [IntD1,IntD2]),
wenzelm@11979:    ("Collect", [CollectD]), ("Inter", [InterD]), ("INTER", [INT_D])]
wenzelm@11979:  *)
wenzelm@11979: 
wenzelm@11979: ML_setup {*
wenzelm@11979:   val mksimps_pairs = [("Ball", [thm "bspec"])] @ mksimps_pairs;
wenzelm@11979:   simpset_ref() := simpset() setmksimps (mksimps mksimps_pairs);
wenzelm@11979: *}
wenzelm@11979: 
wenzelm@11979: declare subset_UNIV [simp] subset_refl [simp]
wenzelm@11979: 
wenzelm@11979: 
wenzelm@11979: subsubsection {* The ``proper subset'' relation *}
wenzelm@11979: 
wenzelm@12897: lemma psubsetI [intro!]: "A \<subseteq> B ==> A \<noteq> B ==> A \<subset> B"
wenzelm@11979:   by (unfold psubset_def) blast
wenzelm@11979: 
paulson@13624: lemma psubsetE [elim!]: 
paulson@13624:     "[|A \<subset> B;  [|A \<subseteq> B; ~ (B\<subseteq>A)|] ==> R|] ==> R"
paulson@13624:   by (unfold psubset_def) blast
paulson@13624: 
wenzelm@11979: lemma psubset_insert_iff:
wenzelm@12897:   "(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)"
wenzelm@12897:   by (auto simp add: psubset_def subset_insert_iff)
wenzelm@12897: 
wenzelm@12897: lemma psubset_eq: "(A \<subset> B) = (A \<subseteq> B & A \<noteq> B)"
wenzelm@11979:   by (simp only: psubset_def)
wenzelm@11979: 
wenzelm@12897: lemma psubset_imp_subset: "A \<subset> B ==> A \<subseteq> B"
wenzelm@11979:   by (simp add: psubset_eq)
wenzelm@11979: 
wenzelm@12897: lemma psubset_subset_trans: "A \<subset> B ==> B \<subseteq> C ==> A \<subset> C"
wenzelm@11979:   by (auto simp add: psubset_eq)
wenzelm@11979: 
wenzelm@12897: lemma subset_psubset_trans: "A \<subseteq> B ==> B \<subset> C ==> A \<subset> C"
wenzelm@11979:   by (auto simp add: psubset_eq)
wenzelm@11979: 
wenzelm@12897: lemma psubset_imp_ex_mem: "A \<subset> B ==> \<exists>b. b \<in> (B - A)"
wenzelm@11979:   by (unfold psubset_def) blast
wenzelm@11979: 
wenzelm@11979: lemma atomize_ball:
wenzelm@12897:     "(!!x. x \<in> A ==> P x) == Trueprop (\<forall>x\<in>A. P x)"
wenzelm@11979:   by (simp only: Ball_def atomize_all atomize_imp)
wenzelm@11979: 
wenzelm@11979: declare atomize_ball [symmetric, rulify]
wenzelm@11979: 
wenzelm@11979: 
wenzelm@11979: subsection {* Further set-theory lemmas *}
wenzelm@11979: 
wenzelm@12897: subsubsection {* Derived rules involving subsets. *}
wenzelm@12897: 
wenzelm@12897: text {* @{text insert}. *}
wenzelm@12897: 
wenzelm@12897: lemma subset_insertI: "B \<subseteq> insert a B"
wenzelm@12897:   apply (rule subsetI)
wenzelm@12897:   apply (erule insertI2)
wenzelm@12897:   done
wenzelm@12897: 
wenzelm@12897: lemma subset_insert: "x \<notin> A ==> (A \<subseteq> insert x B) = (A \<subseteq> B)"
wenzelm@12897:   by blast
wenzelm@12897: 
wenzelm@12897: 
wenzelm@12897: text {* \medskip Big Union -- least upper bound of a set. *}
wenzelm@12897: 
wenzelm@12897: lemma Union_upper: "B \<in> A ==> B \<subseteq> Union A"
wenzelm@12897:   by (rules intro: subsetI UnionI)
wenzelm@12897: 
wenzelm@12897: lemma Union_least: "(!!X. X \<in> A ==> X \<subseteq> C) ==> Union A \<subseteq> C"
wenzelm@12897:   by (rules intro: subsetI elim: UnionE dest: subsetD)
wenzelm@12897: 
wenzelm@12897: 
wenzelm@12897: text {* \medskip General union. *}
wenzelm@12897: 
wenzelm@12897: lemma UN_upper: "a \<in> A ==> B a \<subseteq> (\<Union>x\<in>A. B x)"
wenzelm@12897:   by blast
wenzelm@12897: 
wenzelm@12897: lemma UN_least: "(!!x. x \<in> A ==> B x \<subseteq> C) ==> (\<Union>x\<in>A. B x) \<subseteq> C"
wenzelm@12897:   by (rules intro: subsetI elim: UN_E dest: subsetD)
wenzelm@12897: 
wenzelm@12897: 
wenzelm@12897: text {* \medskip Big Intersection -- greatest lower bound of a set. *}
wenzelm@12897: 
wenzelm@12897: lemma Inter_lower: "B \<in> A ==> Inter A \<subseteq> B"
wenzelm@12897:   by blast
wenzelm@12897: 
wenzelm@12897: lemma Inter_greatest: "(!!X. X \<in> A ==> C \<subseteq> X) ==> C \<subseteq> Inter A"
wenzelm@12897:   by (rules intro: InterI subsetI dest: subsetD)
wenzelm@12897: 
wenzelm@12897: lemma INT_lower: "a \<in> A ==> (\<Inter>x\<in>A. B x) \<subseteq> B a"
wenzelm@12897:   by blast
wenzelm@12897: 
wenzelm@12897: lemma INT_greatest: "(!!x. x \<in> A ==> C \<subseteq> B x) ==> C \<subseteq> (\<Inter>x\<in>A. B x)"
wenzelm@12897:   by (rules intro: INT_I subsetI dest: subsetD)
wenzelm@12897: 
wenzelm@12897: 
wenzelm@12897: text {* \medskip Finite Union -- the least upper bound of two sets. *}
wenzelm@12897: 
wenzelm@12897: lemma Un_upper1: "A \<subseteq> A \<union> B"
wenzelm@12897:   by blast
wenzelm@12897: 
wenzelm@12897: lemma Un_upper2: "B \<subseteq> A \<union> B"
wenzelm@12897:   by blast
wenzelm@12897: 
wenzelm@12897: lemma Un_least: "A \<subseteq> C ==> B \<subseteq> C ==> A \<union> B \<subseteq> C"
wenzelm@12897:   by blast
wenzelm@12897: 
wenzelm@12897: 
wenzelm@12897: text {* \medskip Finite Intersection -- the greatest lower bound of two sets. *}
wenzelm@12897: 
wenzelm@12897: lemma Int_lower1: "A \<inter> B \<subseteq> A"
wenzelm@12897:   by blast
wenzelm@12897: 
wenzelm@12897: lemma Int_lower2: "A \<inter> B \<subseteq> B"
wenzelm@12897:   by blast
wenzelm@12897: 
wenzelm@12897: lemma Int_greatest: "C \<subseteq> A ==> C \<subseteq> B ==> C \<subseteq> A \<inter> B"
wenzelm@12897:   by blast
wenzelm@12897: 
wenzelm@12897: 
wenzelm@12897: text {* \medskip Set difference. *}
wenzelm@12897: 
wenzelm@12897: lemma Diff_subset: "A - B \<subseteq> A"
wenzelm@12897:   by blast
wenzelm@12897: 
wenzelm@12897: 
wenzelm@12897: text {* \medskip Monotonicity. *}
wenzelm@12897: 
wenzelm@13421: lemma mono_Un: includes mono shows "f A \<union> f B \<subseteq> f (A \<union> B)"
wenzelm@12897:   apply (rule Un_least)
wenzelm@13421:    apply (rule Un_upper1 [THEN mono])
wenzelm@13421:   apply (rule Un_upper2 [THEN mono])
wenzelm@12897:   done
wenzelm@12897: 
wenzelm@13421: lemma mono_Int: includes mono shows "f (A \<inter> B) \<subseteq> f A \<inter> f B"
wenzelm@12897:   apply (rule Int_greatest)
wenzelm@13421:    apply (rule Int_lower1 [THEN mono])
wenzelm@13421:   apply (rule Int_lower2 [THEN mono])
wenzelm@12897:   done
wenzelm@12897: 
wenzelm@12897: 
wenzelm@12897: subsubsection {* Equalities involving union, intersection, inclusion, etc. *}
wenzelm@12897: 
wenzelm@12897: text {* @{text "{}"}. *}
wenzelm@12897: 
wenzelm@12897: lemma Collect_const [simp]: "{s. P} = (if P then UNIV else {})"
wenzelm@12897:   -- {* supersedes @{text "Collect_False_empty"} *}
wenzelm@12897:   by auto
wenzelm@12897: 
wenzelm@12897: lemma subset_empty [simp]: "(A \<subseteq> {}) = (A = {})"
wenzelm@12897:   by blast
wenzelm@12897: 
wenzelm@12897: lemma not_psubset_empty [iff]: "\<not> (A < {})"
wenzelm@12897:   by (unfold psubset_def) blast
wenzelm@12897: 
wenzelm@12897: lemma Collect_empty_eq [simp]: "(Collect P = {}) = (\<forall>x. \<not> P x)"
wenzelm@12897:   by auto
wenzelm@12897: 
wenzelm@12897: lemma Collect_neg_eq: "{x. \<not> P x} = - {x. P x}"
wenzelm@12897:   by blast
wenzelm@12897: 
wenzelm@12897: lemma Collect_disj_eq: "{x. P x | Q x} = {x. P x} \<union> {x. Q x}"
wenzelm@12897:   by blast
wenzelm@12897: 
wenzelm@12897: lemma Collect_conj_eq: "{x. P x & Q x} = {x. P x} \<inter> {x. Q x}"
wenzelm@12897:   by blast
wenzelm@12897: 
wenzelm@12897: lemma Collect_all_eq: "{x. \<forall>y. P x y} = (\<Inter>y. {x. P x y})"
wenzelm@12897:   by blast
wenzelm@12897: 
wenzelm@12897: lemma Collect_ball_eq: "{x. \<forall>y\<in>A. P x y} = (\<Inter>y\<in>A. {x. P x y})"
wenzelm@12897:   by blast
wenzelm@12897: 
wenzelm@12897: lemma Collect_ex_eq: "{x. \<exists>y. P x y} = (\<Union>y. {x. P x y})"
wenzelm@12897:   by blast
wenzelm@12897: 
wenzelm@12897: lemma Collect_bex_eq: "{x. \<exists>y\<in>A. P x y} = (\<Union>y\<in>A. {x. P x y})"
wenzelm@12897:   by blast
wenzelm@12897: 
wenzelm@12897: 
wenzelm@12897: text {* \medskip @{text insert}. *}
wenzelm@12897: 
wenzelm@12897: lemma insert_is_Un: "insert a A = {a} Un A"
wenzelm@12897:   -- {* NOT SUITABLE FOR REWRITING since @{text "{a} == insert a {}"} *}
wenzelm@12897:   by blast
wenzelm@12897: 
wenzelm@12897: lemma insert_not_empty [simp]: "insert a A \<noteq> {}"
wenzelm@12897:   by blast
wenzelm@12897: 
wenzelm@12897: lemmas empty_not_insert [simp] = insert_not_empty [symmetric, standard]
wenzelm@12897: 
wenzelm@12897: lemma insert_absorb: "a \<in> A ==> insert a A = A"
wenzelm@12897:   -- {* @{text "[simp]"} causes recursive calls when there are nested inserts *}
wenzelm@12897:   -- {* with \emph{quadratic} running time *}
wenzelm@12897:   by blast
wenzelm@12897: 
wenzelm@12897: lemma insert_absorb2 [simp]: "insert x (insert x A) = insert x A"
wenzelm@12897:   by blast
wenzelm@12897: 
wenzelm@12897: lemma insert_commute: "insert x (insert y A) = insert y (insert x A)"
wenzelm@12897:   by blast
wenzelm@12897: 
wenzelm@12897: lemma insert_subset [simp]: "(insert x A \<subseteq> B) = (x \<in> B & A \<subseteq> B)"
wenzelm@12897:   by blast
wenzelm@12897: 
wenzelm@12897: lemma mk_disjoint_insert: "a \<in> A ==> \<exists>B. A = insert a B & a \<notin> B"
wenzelm@12897:   -- {* use new @{text B} rather than @{text "A - {a}"} to avoid infinite unfolding *}
wenzelm@12897:   apply (rule_tac x = "A - {a}" in exI)
wenzelm@12897:   apply blast
wenzelm@12897:   done
wenzelm@12897: 
wenzelm@12897: lemma insert_Collect: "insert a (Collect P) = {u. u \<noteq> a --> P u}"
wenzelm@12897:   by auto
wenzelm@12897: 
wenzelm@12897: lemma UN_insert_distrib: "u \<in> A ==> (\<Union>x\<in>A. insert a (B x)) = insert a (\<Union>x\<in>A. B x)"
wenzelm@12897:   by blast
wenzelm@12897: 
nipkow@13103: lemma insert_disjoint[simp]:
nipkow@13103:  "(insert a A \<inter> B = {}) = (a \<notin> B \<and> A \<inter> B = {})"
nipkow@13103: by blast
nipkow@13103: 
nipkow@13103: lemma disjoint_insert[simp]:
nipkow@13103:  "(B \<inter> insert a A = {}) = (a \<notin> B \<and> B \<inter> A = {})"
nipkow@13103: by blast
wenzelm@12897: 
wenzelm@12897: text {* \medskip @{text image}. *}
wenzelm@12897: 
wenzelm@12897: lemma image_empty [simp]: "f`{} = {}"
wenzelm@12897:   by blast
wenzelm@12897: 
wenzelm@12897: lemma image_insert [simp]: "f ` insert a B = insert (f a) (f`B)"
wenzelm@12897:   by blast
wenzelm@12897: 
wenzelm@12897: lemma image_constant: "x \<in> A ==> (\<lambda>x. c) ` A = {c}"
wenzelm@12897:   by blast
wenzelm@12897: 
wenzelm@12897: lemma image_image: "f ` (g ` A) = (\<lambda>x. f (g x)) ` A"
wenzelm@12897:   by blast
wenzelm@12897: 
wenzelm@12897: lemma insert_image [simp]: "x \<in> A ==> insert (f x) (f`A) = f`A"
wenzelm@12897:   by blast
wenzelm@12897: 
wenzelm@12897: lemma image_is_empty [iff]: "(f`A = {}) = (A = {})"
wenzelm@12897:   by blast
wenzelm@12897: 
wenzelm@12897: lemma image_Collect: "f ` {x. P x} = {f x | x. P x}"
wenzelm@12897:   -- {* NOT suitable as a default simprule: the RHS isn't simpler than the LHS, *}
wenzelm@12897:   -- {* with its implicit quantifier and conjunction.  Also image enjoys better *}
wenzelm@12897:   -- {* equational properties than does the RHS. *}
wenzelm@12897:   by blast
wenzelm@12897: 
wenzelm@12897: lemma if_image_distrib [simp]:
wenzelm@12897:   "(\<lambda>x. if P x then f x else g x) ` S
wenzelm@12897:     = (f ` (S \<inter> {x. P x})) \<union> (g ` (S \<inter> {x. \<not> P x}))"
wenzelm@12897:   by (auto simp add: image_def)
wenzelm@12897: 
wenzelm@12897: lemma image_cong: "M = N ==> (!!x. x \<in> N ==> f x = g x) ==> f`M = g`N"
wenzelm@12897:   by (simp add: image_def)
wenzelm@12897: 
wenzelm@12897: 
wenzelm@12897: text {* \medskip @{text range}. *}
wenzelm@12897: 
wenzelm@12897: lemma full_SetCompr_eq: "{u. \<exists>x. u = f x} = range f"
wenzelm@12897:   by auto
wenzelm@12897: 
wenzelm@12897: lemma range_composition [simp]: "range (\<lambda>x. f (g x)) = f`range g"
wenzelm@12897:   apply (subst image_image)
wenzelm@12897:   apply simp
wenzelm@12897:   done
wenzelm@12897: 
wenzelm@12897: 
wenzelm@12897: text {* \medskip @{text Int} *}
wenzelm@12897: 
wenzelm@12897: lemma Int_absorb [simp]: "A \<inter> A = A"
wenzelm@12897:   by blast
wenzelm@12897: 
wenzelm@12897: lemma Int_left_absorb: "A \<inter> (A \<inter> B) = A \<inter> B"
wenzelm@12897:   by blast
wenzelm@12897: 
wenzelm@12897: lemma Int_commute: "A \<inter> B = B \<inter> A"
wenzelm@12897:   by blast
wenzelm@12897: 
wenzelm@12897: lemma Int_left_commute: "A \<inter> (B \<inter> C) = B \<inter> (A \<inter> C)"
wenzelm@12897:   by blast
wenzelm@12897: 
wenzelm@12897: lemma Int_assoc: "(A \<inter> B) \<inter> C = A \<inter> (B \<inter> C)"
wenzelm@12897:   by blast
wenzelm@12897: 
wenzelm@12897: lemmas Int_ac = Int_assoc Int_left_absorb Int_commute Int_left_commute
wenzelm@12897:   -- {* Intersection is an AC-operator *}
wenzelm@12897: 
wenzelm@12897: lemma Int_absorb1: "B \<subseteq> A ==> A \<inter> B = B"
wenzelm@12897:   by blast
wenzelm@12897: 
wenzelm@12897: lemma Int_absorb2: "A \<subseteq> B ==> A \<inter> B = A"
wenzelm@12897:   by blast
wenzelm@12897: 
wenzelm@12897: lemma Int_empty_left [simp]: "{} \<inter> B = {}"
wenzelm@12897:   by blast
wenzelm@12897: 
wenzelm@12897: lemma Int_empty_right [simp]: "A \<inter> {} = {}"
wenzelm@12897:   by blast
wenzelm@12897: 
wenzelm@12897: lemma disjoint_eq_subset_Compl: "(A \<inter> B = {}) = (A \<subseteq> -B)"
wenzelm@12897:   by blast
wenzelm@12897: 
wenzelm@12897: lemma disjoint_iff_not_equal: "(A \<inter> B = {}) = (\<forall>x\<in>A. \<forall>y\<in>B. x \<noteq> y)"
wenzelm@12897:   by blast
wenzelm@12897: 
wenzelm@12897: lemma Int_UNIV_left [simp]: "UNIV \<inter> B = B"
wenzelm@12897:   by blast
wenzelm@12897: 
wenzelm@12897: lemma Int_UNIV_right [simp]: "A \<inter> UNIV = A"
wenzelm@12897:   by blast
wenzelm@12897: 
wenzelm@12897: lemma Int_eq_Inter: "A \<inter> B = \<Inter>{A, B}"
wenzelm@12897:   by blast
wenzelm@12897: 
wenzelm@12897: lemma Int_Un_distrib: "A \<inter> (B \<union> C) = (A \<inter> B) \<union> (A \<inter> C)"
wenzelm@12897:   by blast
wenzelm@12897: 
wenzelm@12897: lemma Int_Un_distrib2: "(B \<union> C) \<inter> A = (B \<inter> A) \<union> (C \<inter> A)"
wenzelm@12897:   by blast
wenzelm@12897: 
wenzelm@12897: lemma Int_UNIV [simp]: "(A \<inter> B = UNIV) = (A = UNIV & B = UNIV)"
wenzelm@12897:   by blast
wenzelm@12897: 
wenzelm@12897: lemma Int_subset_iff: "(C \<subseteq> A \<inter> B) = (C \<subseteq> A & C \<subseteq> B)"
wenzelm@12897:   by blast
wenzelm@12897: 
wenzelm@12897: lemma Int_Collect: "(x \<in> A \<inter> {x. P x}) = (x \<in> A & P x)"
wenzelm@12897:   by blast
wenzelm@12897: 
wenzelm@12897: 
wenzelm@12897: text {* \medskip @{text Un}. *}
wenzelm@12897: 
wenzelm@12897: lemma Un_absorb [simp]: "A \<union> A = A"
wenzelm@12897:   by blast
wenzelm@12897: 
wenzelm@12897: lemma Un_left_absorb: "A \<union> (A \<union> B) = A \<union> B"
wenzelm@12897:   by blast
wenzelm@12897: 
wenzelm@12897: lemma Un_commute: "A \<union> B = B \<union> A"
wenzelm@12897:   by blast
wenzelm@12897: 
wenzelm@12897: lemma Un_left_commute: "A \<union> (B \<union> C) = B \<union> (A \<union> C)"
wenzelm@12897:   by blast
wenzelm@12897: 
wenzelm@12897: lemma Un_assoc: "(A \<union> B) \<union> C = A \<union> (B \<union> C)"
wenzelm@12897:   by blast
wenzelm@12897: 
wenzelm@12897: lemmas Un_ac = Un_assoc Un_left_absorb Un_commute Un_left_commute
wenzelm@12897:   -- {* Union is an AC-operator *}
wenzelm@12897: 
wenzelm@12897: lemma Un_absorb1: "A \<subseteq> B ==> A \<union> B = B"
wenzelm@12897:   by blast
wenzelm@12897: 
wenzelm@12897: lemma Un_absorb2: "B \<subseteq> A ==> A \<union> B = A"
wenzelm@12897:   by blast
wenzelm@12897: 
wenzelm@12897: lemma Un_empty_left [simp]: "{} \<union> B = B"
wenzelm@12897:   by blast
wenzelm@12897: 
wenzelm@12897: lemma Un_empty_right [simp]: "A \<union> {} = A"
wenzelm@12897:   by blast
wenzelm@12897: 
wenzelm@12897: lemma Un_UNIV_left [simp]: "UNIV \<union> B = UNIV"
wenzelm@12897:   by blast
wenzelm@12897: 
wenzelm@12897: lemma Un_UNIV_right [simp]: "A \<union> UNIV = UNIV"
wenzelm@12897:   by blast
wenzelm@12897: 
wenzelm@12897: lemma Un_eq_Union: "A \<union> B = \<Union>{A, B}"
wenzelm@12897:   by blast
wenzelm@12897: 
wenzelm@12897: lemma Un_insert_left [simp]: "(insert a B) \<union> C = insert a (B \<union> C)"
wenzelm@12897:   by blast
wenzelm@12897: 
wenzelm@12897: lemma Un_insert_right [simp]: "A \<union> (insert a B) = insert a (A \<union> B)"
wenzelm@12897:   by blast
wenzelm@12897: 
wenzelm@12897: lemma Int_insert_left:
wenzelm@12897:     "(insert a B) Int C = (if a \<in> C then insert a (B \<inter> C) else B \<inter> C)"
wenzelm@12897:   by auto
wenzelm@12897: 
wenzelm@12897: lemma Int_insert_right:
wenzelm@12897:     "A \<inter> (insert a B) = (if a \<in> A then insert a (A \<inter> B) else A \<inter> B)"
wenzelm@12897:   by auto
wenzelm@12897: 
wenzelm@12897: lemma Un_Int_distrib: "A \<union> (B \<inter> C) = (A \<union> B) \<inter> (A \<union> C)"
wenzelm@12897:   by blast
wenzelm@12897: 
wenzelm@12897: lemma Un_Int_distrib2: "(B \<inter> C) \<union> A = (B \<union> A) \<inter> (C \<union> A)"
wenzelm@12897:   by blast
wenzelm@12897: 
wenzelm@12897: lemma Un_Int_crazy:
wenzelm@12897:     "(A \<inter> B) \<union> (B \<inter> C) \<union> (C \<inter> A) = (A \<union> B) \<inter> (B \<union> C) \<inter> (C \<union> A)"
wenzelm@12897:   by blast
wenzelm@12897: 
wenzelm@12897: lemma subset_Un_eq: "(A \<subseteq> B) = (A \<union> B = B)"
wenzelm@12897:   by blast
wenzelm@12897: 
wenzelm@12897: lemma Un_empty [iff]: "(A \<union> B = {}) = (A = {} & B = {})"
wenzelm@12897:   by blast
wenzelm@12897: 
wenzelm@12897: lemma Un_subset_iff: "(A \<union> B \<subseteq> C) = (A \<subseteq> C & B \<subseteq> C)"
wenzelm@12897:   by blast
wenzelm@12897: 
wenzelm@12897: lemma Un_Diff_Int: "(A - B) \<union> (A \<inter> B) = A"
wenzelm@12897:   by blast
wenzelm@12897: 
wenzelm@12897: 
wenzelm@12897: text {* \medskip Set complement *}
wenzelm@12897: 
wenzelm@12897: lemma Compl_disjoint [simp]: "A \<inter> -A = {}"
wenzelm@12897:   by blast
wenzelm@12897: 
wenzelm@12897: lemma Compl_disjoint2 [simp]: "-A \<inter> A = {}"
wenzelm@12897:   by blast
wenzelm@12897: 
paulson@13818: lemma Compl_partition: "A \<union> -A = UNIV"
paulson@13818:   by blast
paulson@13818: 
paulson@13818: lemma Compl_partition2: "-A \<union> A = UNIV"
wenzelm@12897:   by blast
wenzelm@12897: 
wenzelm@12897: lemma double_complement [simp]: "- (-A) = (A::'a set)"
wenzelm@12897:   by blast
wenzelm@12897: 
wenzelm@12897: lemma Compl_Un [simp]: "-(A \<union> B) = (-A) \<inter> (-B)"
wenzelm@12897:   by blast
wenzelm@12897: 
wenzelm@12897: lemma Compl_Int [simp]: "-(A \<inter> B) = (-A) \<union> (-B)"
wenzelm@12897:   by blast
wenzelm@12897: 
wenzelm@12897: lemma Compl_UN [simp]: "-(\<Union>x\<in>A. B x) = (\<Inter>x\<in>A. -B x)"
wenzelm@12897:   by blast
wenzelm@12897: 
wenzelm@12897: lemma Compl_INT [simp]: "-(\<Inter>x\<in>A. B x) = (\<Union>x\<in>A. -B x)"
wenzelm@12897:   by blast
wenzelm@12897: 
wenzelm@12897: lemma subset_Compl_self_eq: "(A \<subseteq> -A) = (A = {})"
wenzelm@12897:   by blast
wenzelm@12897: 
wenzelm@12897: lemma Un_Int_assoc_eq: "((A \<inter> B) \<union> C = A \<inter> (B \<union> C)) = (C \<subseteq> A)"
wenzelm@12897:   -- {* Halmos, Naive Set Theory, page 16. *}
wenzelm@12897:   by blast
wenzelm@12897: 
wenzelm@12897: lemma Compl_UNIV_eq [simp]: "-UNIV = {}"
wenzelm@12897:   by blast
wenzelm@12897: 
wenzelm@12897: lemma Compl_empty_eq [simp]: "-{} = UNIV"
wenzelm@12897:   by blast
wenzelm@12897: 
wenzelm@12897: lemma Compl_subset_Compl_iff [iff]: "(-A \<subseteq> -B) = (B \<subseteq> A)"
wenzelm@12897:   by blast
wenzelm@12897: 
wenzelm@12897: lemma Compl_eq_Compl_iff [iff]: "(-A = -B) = (A = (B::'a set))"
wenzelm@12897:   by blast
wenzelm@12897: 
wenzelm@12897: 
wenzelm@12897: text {* \medskip @{text Union}. *}
wenzelm@12897: 
wenzelm@12897: lemma Union_empty [simp]: "Union({}) = {}"
wenzelm@12897:   by blast
wenzelm@12897: 
wenzelm@12897: lemma Union_UNIV [simp]: "Union UNIV = UNIV"
wenzelm@12897:   by blast
wenzelm@12897: 
wenzelm@12897: lemma Union_insert [simp]: "Union (insert a B) = a \<union> \<Union>B"
wenzelm@12897:   by blast
wenzelm@12897: 
wenzelm@12897: lemma Union_Un_distrib [simp]: "\<Union>(A Un B) = \<Union>A \<union> \<Union>B"
wenzelm@12897:   by blast
wenzelm@12897: 
wenzelm@12897: lemma Union_Int_subset: "\<Union>(A \<inter> B) \<subseteq> \<Union>A \<inter> \<Union>B"
wenzelm@12897:   by blast
wenzelm@12897: 
wenzelm@12897: lemma Union_empty_conv [iff]: "(\<Union>A = {}) = (\<forall>x\<in>A. x = {})"
nipkow@13653:   by blast
nipkow@13653: 
nipkow@13653: lemma empty_Union_conv [iff]: "({} = \<Union>A) = (\<forall>x\<in>A. x = {})"
nipkow@13653:   by blast
wenzelm@12897: 
wenzelm@12897: lemma Union_disjoint: "(\<Union>C \<inter> A = {}) = (\<forall>B\<in>C. B \<inter> A = {})"
wenzelm@12897:   by blast
wenzelm@12897: 
wenzelm@12897: 
wenzelm@12897: text {* \medskip @{text Inter}. *}
wenzelm@12897: 
wenzelm@12897: lemma Inter_empty [simp]: "\<Inter>{} = UNIV"
wenzelm@12897:   by blast
wenzelm@12897: 
wenzelm@12897: lemma Inter_UNIV [simp]: "\<Inter>UNIV = {}"
wenzelm@12897:   by blast
wenzelm@12897: 
wenzelm@12897: lemma Inter_insert [simp]: "\<Inter>(insert a B) = a \<inter> \<Inter>B"
wenzelm@12897:   by blast
wenzelm@12897: 
wenzelm@12897: lemma Inter_Un_subset: "\<Inter>A \<union> \<Inter>B \<subseteq> \<Inter>(A \<inter> B)"
wenzelm@12897:   by blast
wenzelm@12897: 
wenzelm@12897: lemma Inter_Un_distrib: "\<Inter>(A \<union> B) = \<Inter>A \<inter> \<Inter>B"
wenzelm@12897:   by blast
wenzelm@12897: 
nipkow@13653: lemma Inter_UNIV_conv [iff]:
nipkow@13653:   "(\<Inter>A = UNIV) = (\<forall>x\<in>A. x = UNIV)"
nipkow@13653:   "(UNIV = \<Inter>A) = (\<forall>x\<in>A. x = UNIV)"
nipkow@13653:   by(blast)+
nipkow@13653: 
wenzelm@12897: 
wenzelm@12897: text {*
wenzelm@12897:   \medskip @{text UN} and @{text INT}.
wenzelm@12897: 
wenzelm@12897:   Basic identities: *}
wenzelm@12897: 
wenzelm@12897: lemma UN_empty [simp]: "(\<Union>x\<in>{}. B x) = {}"
wenzelm@12897:   by blast
wenzelm@12897: 
wenzelm@12897: lemma UN_empty2 [simp]: "(\<Union>x\<in>A. {}) = {}"
wenzelm@12897:   by blast
wenzelm@12897: 
wenzelm@12897: lemma UN_singleton [simp]: "(\<Union>x\<in>A. {x}) = A"
wenzelm@12897:   by blast
wenzelm@12897: 
wenzelm@12897: lemma UN_absorb: "k \<in> I ==> A k \<union> (\<Union>i\<in>I. A i) = (\<Union>i\<in>I. A i)"
wenzelm@12897:   by blast
wenzelm@12897: 
wenzelm@12897: lemma INT_empty [simp]: "(\<Inter>x\<in>{}. B x) = UNIV"
wenzelm@12897:   by blast
wenzelm@12897: 
wenzelm@12897: lemma INT_absorb: "k \<in> I ==> A k \<inter> (\<Inter>i\<in>I. A i) = (\<Inter>i\<in>I. A i)"
wenzelm@12897:   by blast
wenzelm@12897: 
wenzelm@12897: lemma UN_insert [simp]: "(\<Union>x\<in>insert a A. B x) = B a \<union> UNION A B"
wenzelm@12897:   by blast
wenzelm@12897: 
wenzelm@12897: lemma UN_Un: "(\<Union>i \<in> A \<union> B. M i) = (\<Union>i\<in>A. M i) \<union> (\<Union>i\<in>B. M i)"
wenzelm@12897:   by blast
wenzelm@12897: 
wenzelm@12897: 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)"
wenzelm@12897:   by blast
wenzelm@12897: 
wenzelm@12897: lemma UN_subset_iff: "((\<Union>i\<in>I. A i) \<subseteq> B) = (\<forall>i\<in>I. A i \<subseteq> B)"
wenzelm@12897:   by blast
wenzelm@12897: 
wenzelm@12897: lemma INT_subset_iff: "(B \<subseteq> (\<Inter>i\<in>I. A i)) = (\<forall>i\<in>I. B \<subseteq> A i)"
wenzelm@12897:   by blast
wenzelm@12897: 
wenzelm@12897: lemma INT_insert [simp]: "(\<Inter>x \<in> insert a A. B x) = B a \<inter> INTER A B"
wenzelm@12897:   by blast
wenzelm@12897: 
wenzelm@12897: lemma INT_Un: "(\<Inter>i \<in> A \<union> B. M i) = (\<Inter>i \<in> A. M i) \<inter> (\<Inter>i\<in>B. M i)"
wenzelm@12897:   by blast
wenzelm@12897: 
wenzelm@12897: lemma INT_insert_distrib:
wenzelm@12897:     "u \<in> A ==> (\<Inter>x\<in>A. insert a (B x)) = insert a (\<Inter>x\<in>A. B x)"
wenzelm@12897:   by blast
wenzelm@12897: 
wenzelm@12897: lemma Union_image_eq [simp]: "\<Union>(B`A) = (\<Union>x\<in>A. B x)"
wenzelm@12897:   by blast
wenzelm@12897: 
wenzelm@12897: lemma image_Union: "f ` \<Union>S = (\<Union>x\<in>S. f ` x)"
wenzelm@12897:   by blast
wenzelm@12897: 
wenzelm@12897: lemma Inter_image_eq [simp]: "\<Inter>(B`A) = (\<Inter>x\<in>A. B x)"
wenzelm@12897:   by blast
wenzelm@12897: 
wenzelm@12897: lemma UN_constant [simp]: "(\<Union>y\<in>A. c) = (if A = {} then {} else c)"
wenzelm@12897:   by auto
wenzelm@12897: 
wenzelm@12897: lemma INT_constant [simp]: "(\<Inter>y\<in>A. c) = (if A = {} then UNIV else c)"
wenzelm@12897:   by auto
wenzelm@12897: 
wenzelm@12897: lemma UN_eq: "(\<Union>x\<in>A. B x) = \<Union>({Y. \<exists>x\<in>A. Y = B x})"
wenzelm@12897:   by blast
wenzelm@12897: 
wenzelm@12897: lemma INT_eq: "(\<Inter>x\<in>A. B x) = \<Inter>({Y. \<exists>x\<in>A. Y = B x})"
wenzelm@12897:   -- {* Look: it has an \emph{existential} quantifier *}
wenzelm@12897:   by blast
wenzelm@12897: 
nipkow@13653: lemma UNION_empty_conv[iff]:
nipkow@13653:   "({} = (UN x:A. B x)) = (\<forall>x\<in>A. B x = {})"
nipkow@13653:   "((UN x:A. B x) = {}) = (\<forall>x\<in>A. B x = {})"
nipkow@13653: by blast+
nipkow@13653: 
nipkow@13653: lemma INTER_UNIV_conv[iff]:
nipkow@13653:  "(UNIV = (INT x:A. B x)) = (\<forall>x\<in>A. B x = UNIV)"
nipkow@13653:  "((INT x:A. B x) = UNIV) = (\<forall>x\<in>A. B x = UNIV)"
nipkow@13653: by blast+
wenzelm@12897: 
wenzelm@12897: 
wenzelm@12897: text {* \medskip Distributive laws: *}
wenzelm@12897: 
wenzelm@12897: lemma Int_Union: "A \<inter> \<Union>B = (\<Union>C\<in>B. A \<inter> C)"
wenzelm@12897:   by blast
wenzelm@12897: 
wenzelm@12897: lemma Int_Union2: "\<Union>B \<inter> A = (\<Union>C\<in>B. C \<inter> A)"
wenzelm@12897:   by blast
wenzelm@12897: 
wenzelm@12897: lemma Un_Union_image: "(\<Union>x\<in>C. A x \<union> B x) = \<Union>(A`C) \<union> \<Union>(B`C)"
wenzelm@12897:   -- {* Devlin, Fundamentals of Contemporary Set Theory, page 12, exercise 5: *}
wenzelm@12897:   -- {* Union of a family of unions *}
wenzelm@12897:   by blast
wenzelm@12897: 
wenzelm@12897: 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)"
wenzelm@12897:   -- {* Equivalent version *}
wenzelm@12897:   by blast
wenzelm@12897: 
wenzelm@12897: lemma Un_Inter: "A \<union> \<Inter>B = (\<Inter>C\<in>B. A \<union> C)"
wenzelm@12897:   by blast
wenzelm@12897: 
wenzelm@12897: lemma Int_Inter_image: "(\<Inter>x\<in>C. A x \<inter> B x) = \<Inter>(A`C) \<inter> \<Inter>(B`C)"
wenzelm@12897:   by blast
wenzelm@12897: 
wenzelm@12897: 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)"
wenzelm@12897:   -- {* Equivalent version *}
wenzelm@12897:   by blast
wenzelm@12897: 
wenzelm@12897: lemma Int_UN_distrib: "B \<inter> (\<Union>i\<in>I. A i) = (\<Union>i\<in>I. B \<inter> A i)"
wenzelm@12897:   -- {* Halmos, Naive Set Theory, page 35. *}
wenzelm@12897:   by blast
wenzelm@12897: 
wenzelm@12897: lemma Un_INT_distrib: "B \<union> (\<Inter>i\<in>I. A i) = (\<Inter>i\<in>I. B \<union> A i)"
wenzelm@12897:   by blast
wenzelm@12897: 
wenzelm@12897: 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)"
wenzelm@12897:   by blast
wenzelm@12897: 
wenzelm@12897: 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)"
wenzelm@12897:   by blast
wenzelm@12897: 
wenzelm@12897: 
wenzelm@12897: text {* \medskip Bounded quantifiers.
wenzelm@12897: 
wenzelm@12897:   The following are not added to the default simpset because
wenzelm@12897:   (a) they duplicate the body and (b) there are no similar rules for @{text Int}. *}
wenzelm@12897: 
wenzelm@12897: lemma ball_Un: "(\<forall>x \<in> A \<union> B. P x) = ((\<forall>x\<in>A. P x) & (\<forall>x\<in>B. P x))"
wenzelm@12897:   by blast
wenzelm@12897: 
wenzelm@12897: lemma bex_Un: "(\<exists>x \<in> A \<union> B. P x) = ((\<exists>x\<in>A. P x) | (\<exists>x\<in>B. P x))"
wenzelm@12897:   by blast
wenzelm@12897: 
wenzelm@12897: lemma ball_UN: "(\<forall>z \<in> UNION A B. P z) = (\<forall>x\<in>A. \<forall>z \<in> B x. P z)"
wenzelm@12897:   by blast
wenzelm@12897: 
wenzelm@12897: lemma bex_UN: "(\<exists>z \<in> UNION A B. P z) = (\<exists>x\<in>A. \<exists>z\<in>B x. P z)"
wenzelm@12897:   by blast
wenzelm@12897: 
wenzelm@12897: 
wenzelm@12897: text {* \medskip Set difference. *}
wenzelm@12897: 
wenzelm@12897: lemma Diff_eq: "A - B = A \<inter> (-B)"
wenzelm@12897:   by blast
wenzelm@12897: 
wenzelm@12897: lemma Diff_eq_empty_iff [simp]: "(A - B = {}) = (A \<subseteq> B)"
wenzelm@12897:   by blast
wenzelm@12897: 
wenzelm@12897: lemma Diff_cancel [simp]: "A - A = {}"
wenzelm@12897:   by blast
wenzelm@12897: 
wenzelm@12897: lemma Diff_triv: "A \<inter> B = {} ==> A - B = A"
wenzelm@12897:   by (blast elim: equalityE)
wenzelm@12897: 
wenzelm@12897: lemma empty_Diff [simp]: "{} - A = {}"
wenzelm@12897:   by blast
wenzelm@12897: 
wenzelm@12897: lemma Diff_empty [simp]: "A - {} = A"
wenzelm@12897:   by blast
wenzelm@12897: 
wenzelm@12897: lemma Diff_UNIV [simp]: "A - UNIV = {}"
wenzelm@12897:   by blast
wenzelm@12897: 
wenzelm@12897: lemma Diff_insert0 [simp]: "x \<notin> A ==> A - insert x B = A - B"
wenzelm@12897:   by blast
wenzelm@12897: 
wenzelm@12897: lemma Diff_insert: "A - insert a B = A - B - {a}"
wenzelm@12897:   -- {* NOT SUITABLE FOR REWRITING since @{text "{a} == insert a 0"} *}
wenzelm@12897:   by blast
wenzelm@12897: 
wenzelm@12897: lemma Diff_insert2: "A - insert a B = A - {a} - B"
wenzelm@12897:   -- {* NOT SUITABLE FOR REWRITING since @{text "{a} == insert a 0"} *}
wenzelm@12897:   by blast
wenzelm@12897: 
wenzelm@12897: lemma insert_Diff_if: "insert x A - B = (if x \<in> B then A - B else insert x (A - B))"
wenzelm@12897:   by auto
wenzelm@12897: 
wenzelm@12897: lemma insert_Diff1 [simp]: "x \<in> B ==> insert x A - B = A - B"
wenzelm@12897:   by blast
wenzelm@12897: 
wenzelm@12897: lemma insert_Diff: "a \<in> A ==> insert a (A - {a}) = A"
wenzelm@12897:   by blast
wenzelm@12897: 
wenzelm@12897: lemma Diff_insert_absorb: "x \<notin> A ==> (insert x A) - {x} = A"
wenzelm@12897:   by auto
wenzelm@12897: 
wenzelm@12897: lemma Diff_disjoint [simp]: "A \<inter> (B - A) = {}"
wenzelm@12897:   by blast
wenzelm@12897: 
wenzelm@12897: lemma Diff_partition: "A \<subseteq> B ==> A \<union> (B - A) = B"
wenzelm@12897:   by blast
wenzelm@12897: 
wenzelm@12897: lemma double_diff: "A \<subseteq> B ==> B \<subseteq> C ==> B - (C - A) = A"
wenzelm@12897:   by blast
wenzelm@12897: 
wenzelm@12897: lemma Un_Diff_cancel [simp]: "A \<union> (B - A) = A \<union> B"
wenzelm@12897:   by blast
wenzelm@12897: 
wenzelm@12897: lemma Un_Diff_cancel2 [simp]: "(B - A) \<union> A = B \<union> A"
wenzelm@12897:   by blast
wenzelm@12897: 
wenzelm@12897: lemma Diff_Un: "A - (B \<union> C) = (A - B) \<inter> (A - C)"
wenzelm@12897:   by blast
wenzelm@12897: 
wenzelm@12897: lemma Diff_Int: "A - (B \<inter> C) = (A - B) \<union> (A - C)"
wenzelm@12897:   by blast
wenzelm@12897: 
wenzelm@12897: lemma Un_Diff: "(A \<union> B) - C = (A - C) \<union> (B - C)"
wenzelm@12897:   by blast
wenzelm@12897: 
wenzelm@12897: lemma Int_Diff: "(A \<inter> B) - C = A \<inter> (B - C)"
wenzelm@12897:   by blast
wenzelm@12897: 
wenzelm@12897: lemma Diff_Int_distrib: "C \<inter> (A - B) = (C \<inter> A) - (C \<inter> B)"
wenzelm@12897:   by blast
wenzelm@12897: 
wenzelm@12897: lemma Diff_Int_distrib2: "(A - B) \<inter> C = (A \<inter> C) - (B \<inter> C)"
wenzelm@12897:   by blast
wenzelm@12897: 
wenzelm@12897: lemma Diff_Compl [simp]: "A - (- B) = A \<inter> B"
wenzelm@12897:   by auto
wenzelm@12897: 
wenzelm@12897: lemma Compl_Diff_eq [simp]: "- (A - B) = -A \<union> B"
wenzelm@12897:   by blast
wenzelm@12897: 
wenzelm@12897: 
wenzelm@12897: text {* \medskip Quantification over type @{typ bool}. *}
wenzelm@12897: 
wenzelm@12897: lemma all_bool_eq: "(\<forall>b::bool. P b) = (P True & P False)"
wenzelm@12897:   apply auto
wenzelm@12897:   apply (tactic {* case_tac "b" 1 *})
wenzelm@12897:    apply auto
wenzelm@12897:   done
wenzelm@12897: 
wenzelm@12897: lemma bool_induct: "P True \<Longrightarrow> P False \<Longrightarrow> P x"
wenzelm@12897:   by (rule conjI [THEN all_bool_eq [THEN iffD2], THEN spec])
wenzelm@12897: 
wenzelm@12897: lemma ex_bool_eq: "(\<exists>b::bool. P b) = (P True | P False)"
wenzelm@12897:   apply auto
wenzelm@12897:   apply (tactic {* case_tac "b" 1 *})
wenzelm@12897:    apply auto
wenzelm@12897:   done
wenzelm@12897: 
wenzelm@12897: lemma Un_eq_UN: "A \<union> B = (\<Union>b. if b then A else B)"
wenzelm@12897:   by (auto simp add: split_if_mem2)
wenzelm@12897: 
wenzelm@12897: lemma UN_bool_eq: "(\<Union>b::bool. A b) = (A True \<union> A False)"
wenzelm@12897:   apply auto
wenzelm@12897:   apply (tactic {* case_tac "b" 1 *})
wenzelm@12897:    apply auto
wenzelm@12897:   done
wenzelm@12897: 
wenzelm@12897: lemma INT_bool_eq: "(\<Inter>b::bool. A b) = (A True \<inter> A False)"
wenzelm@12897:   apply auto
wenzelm@12897:   apply (tactic {* case_tac "b" 1 *})
wenzelm@12897:   apply auto
wenzelm@12897:   done
wenzelm@12897: 
wenzelm@12897: 
wenzelm@12897: text {* \medskip @{text Pow} *}
wenzelm@12897: 
wenzelm@12897: lemma Pow_empty [simp]: "Pow {} = {{}}"
wenzelm@12897:   by (auto simp add: Pow_def)
wenzelm@12897: 
wenzelm@12897: lemma Pow_insert: "Pow (insert a A) = Pow A \<union> (insert a ` Pow A)"
wenzelm@12897:   by (blast intro: image_eqI [where ?x = "u - {a}", standard])
wenzelm@12897: 
wenzelm@12897: lemma Pow_Compl: "Pow (- A) = {-B | B. A \<in> Pow B}"
wenzelm@12897:   by (blast intro: exI [where ?x = "- u", standard])
wenzelm@12897: 
wenzelm@12897: lemma Pow_UNIV [simp]: "Pow UNIV = UNIV"
wenzelm@12897:   by blast
wenzelm@12897: 
wenzelm@12897: lemma Un_Pow_subset: "Pow A \<union> Pow B \<subseteq> Pow (A \<union> B)"
wenzelm@12897:   by blast
wenzelm@12897: 
wenzelm@12897: lemma UN_Pow_subset: "(\<Union>x\<in>A. Pow (B x)) \<subseteq> Pow (\<Union>x\<in>A. B x)"
wenzelm@12897:   by blast
wenzelm@12897: 
wenzelm@12897: lemma subset_Pow_Union: "A \<subseteq> Pow (\<Union>A)"
wenzelm@12897:   by blast
wenzelm@12897: 
wenzelm@12897: lemma Union_Pow_eq [simp]: "\<Union>(Pow A) = A"
wenzelm@12897:   by blast
wenzelm@12897: 
wenzelm@12897: lemma Pow_Int_eq [simp]: "Pow (A \<inter> B) = Pow A \<inter> Pow B"
wenzelm@12897:   by blast
wenzelm@12897: 
wenzelm@12897: lemma Pow_INT_eq: "Pow (\<Inter>x\<in>A. B x) = (\<Inter>x\<in>A. Pow (B x))"
wenzelm@12897:   by blast
wenzelm@12897: 
wenzelm@12897: 
wenzelm@12897: text {* \medskip Miscellany. *}
wenzelm@12897: 
wenzelm@12897: lemma set_eq_subset: "(A = B) = (A \<subseteq> B & B \<subseteq> A)"
wenzelm@12897:   by blast
wenzelm@12897: 
wenzelm@12897: lemma subset_iff: "(A \<subseteq> B) = (\<forall>t. t \<in> A --> t \<in> B)"
wenzelm@12897:   by blast
wenzelm@12897: 
wenzelm@12897: lemma subset_iff_psubset_eq: "(A \<subseteq> B) = ((A \<subset> B) | (A = B))"
wenzelm@12897:   by (unfold psubset_def) blast
wenzelm@12897: 
wenzelm@12897: lemma all_not_in_conv [iff]: "(\<forall>x. x \<notin> A) = (A = {})"
wenzelm@12897:   by blast
wenzelm@12897: 
paulson@13831: lemma ex_in_conv: "(\<exists>x. x \<in> A) = (A \<noteq> {})"
paulson@13831:   by blast
paulson@13831: 
wenzelm@12897: lemma distinct_lemma: "f x \<noteq> f y ==> x \<noteq> y"
wenzelm@12897:   by rules
wenzelm@12897: 
wenzelm@12897: 
paulson@13860: text {* \medskip Miniscoping: pushing in quantifiers and big Unions
paulson@13860:            and Intersections. *}
wenzelm@12897: 
wenzelm@12897: lemma UN_simps [simp]:
wenzelm@12897:   "!!a B C. (UN x:C. insert a (B x)) = (if C={} then {} else insert a (UN x:C. B x))"
wenzelm@12897:   "!!A B C. (UN x:C. A x Un B)   = ((if C={} then {} else (UN x:C. A x) Un B))"
wenzelm@12897:   "!!A B C. (UN x:C. A Un B x)   = ((if C={} then {} else A Un (UN x:C. B x)))"
wenzelm@12897:   "!!A B C. (UN x:C. A x Int B)  = ((UN x:C. A x) Int B)"
wenzelm@12897:   "!!A B C. (UN x:C. A Int B x)  = (A Int (UN x:C. B x))"
wenzelm@12897:   "!!A B C. (UN x:C. A x - B)    = ((UN x:C. A x) - B)"
wenzelm@12897:   "!!A B C. (UN x:C. A - B x)    = (A - (INT x:C. B x))"
wenzelm@12897:   "!!A B. (UN x: Union A. B x) = (UN y:A. UN x:y. B x)"
wenzelm@12897:   "!!A B C. (UN z: UNION A B. C z) = (UN  x:A. UN z: B(x). C z)"
wenzelm@12897:   "!!A B f. (UN x:f`A. B x)     = (UN a:A. B (f a))"
wenzelm@12897:   by auto
wenzelm@12897: 
wenzelm@12897: lemma INT_simps [simp]:
wenzelm@12897:   "!!A B C. (INT x:C. A x Int B) = (if C={} then UNIV else (INT x:C. A x) Int B)"
wenzelm@12897:   "!!A B C. (INT x:C. A Int B x) = (if C={} then UNIV else A Int (INT x:C. B x))"
wenzelm@12897:   "!!A B C. (INT x:C. A x - B)   = (if C={} then UNIV else (INT x:C. A x) - B)"
wenzelm@12897:   "!!A B C. (INT x:C. A - B x)   = (if C={} then UNIV else A - (UN x:C. B x))"
wenzelm@12897:   "!!a B C. (INT x:C. insert a (B x)) = insert a (INT x:C. B x)"
wenzelm@12897:   "!!A B C. (INT x:C. A x Un B)  = ((INT x:C. A x) Un B)"
wenzelm@12897:   "!!A B C. (INT x:C. A Un B x)  = (A Un (INT x:C. B x))"
wenzelm@12897:   "!!A B. (INT x: Union A. B x) = (INT y:A. INT x:y. B x)"
wenzelm@12897:   "!!A B C. (INT z: UNION A B. C z) = (INT x:A. INT z: B(x). C z)"
wenzelm@12897:   "!!A B f. (INT x:f`A. B x)    = (INT a:A. B (f a))"
wenzelm@12897:   by auto
wenzelm@12897: 
wenzelm@12897: lemma ball_simps [simp]:
wenzelm@12897:   "!!A P Q. (ALL x:A. P x | Q) = ((ALL x:A. P x) | Q)"
wenzelm@12897:   "!!A P Q. (ALL x:A. P | Q x) = (P | (ALL x:A. Q x))"
wenzelm@12897:   "!!A P Q. (ALL x:A. P --> Q x) = (P --> (ALL x:A. Q x))"
wenzelm@12897:   "!!A P Q. (ALL x:A. P x --> Q) = ((EX x:A. P x) --> Q)"
wenzelm@12897:   "!!P. (ALL x:{}. P x) = True"
wenzelm@12897:   "!!P. (ALL x:UNIV. P x) = (ALL x. P x)"
wenzelm@12897:   "!!a B P. (ALL x:insert a B. P x) = (P a & (ALL x:B. P x))"
wenzelm@12897:   "!!A P. (ALL x:Union A. P x) = (ALL y:A. ALL x:y. P x)"
wenzelm@12897:   "!!A B P. (ALL x: UNION A B. P x) = (ALL a:A. ALL x: B a. P x)"
wenzelm@12897:   "!!P Q. (ALL x:Collect Q. P x) = (ALL x. Q x --> P x)"
wenzelm@12897:   "!!A P f. (ALL x:f`A. P x) = (ALL x:A. P (f x))"
wenzelm@12897:   "!!A P. (~(ALL x:A. P x)) = (EX x:A. ~P x)"
wenzelm@12897:   by auto
wenzelm@12897: 
wenzelm@12897: lemma bex_simps [simp]:
wenzelm@12897:   "!!A P Q. (EX x:A. P x & Q) = ((EX x:A. P x) & Q)"
wenzelm@12897:   "!!A P Q. (EX x:A. P & Q x) = (P & (EX x:A. Q x))"
wenzelm@12897:   "!!P. (EX x:{}. P x) = False"
wenzelm@12897:   "!!P. (EX x:UNIV. P x) = (EX x. P x)"
wenzelm@12897:   "!!a B P. (EX x:insert a B. P x) = (P(a) | (EX x:B. P x))"
wenzelm@12897:   "!!A P. (EX x:Union A. P x) = (EX y:A. EX x:y. P x)"
wenzelm@12897:   "!!A B P. (EX x: UNION A B. P x) = (EX a:A. EX x:B a. P x)"
wenzelm@12897:   "!!P Q. (EX x:Collect Q. P x) = (EX x. Q x & P x)"
wenzelm@12897:   "!!A P f. (EX x:f`A. P x) = (EX x:A. P (f x))"
wenzelm@12897:   "!!A P. (~(EX x:A. P x)) = (ALL x:A. ~P x)"
wenzelm@12897:   by auto
wenzelm@12897: 
wenzelm@12897: lemma ball_conj_distrib:
wenzelm@12897:   "(ALL x:A. P x & Q x) = ((ALL x:A. P x) & (ALL x:A. Q x))"
wenzelm@12897:   by blast
wenzelm@12897: 
wenzelm@12897: lemma bex_disj_distrib:
wenzelm@12897:   "(EX x:A. P x | Q x) = ((EX x:A. P x) | (EX x:A. Q x))"
wenzelm@12897:   by blast
wenzelm@12897: 
wenzelm@12897: 
paulson@13860: text {* \medskip Maxiscoping: pulling out big Unions and Intersections. *}
paulson@13860: 
paulson@13860: lemma UN_extend_simps:
paulson@13860:   "!!a B C. insert a (UN x:C. B x) = (if C={} then {a} else (UN x:C. insert a (B x)))"
paulson@13860:   "!!A B C. (UN x:C. A x) Un B    = (if C={} then B else (UN x:C. A x Un B))"
paulson@13860:   "!!A B C. A Un (UN x:C. B x)   = (if C={} then A else (UN x:C. A Un B x))"
paulson@13860:   "!!A B C. ((UN x:C. A x) Int B) = (UN x:C. A x Int B)"
paulson@13860:   "!!A B C. (A Int (UN x:C. B x)) = (UN x:C. A Int B x)"
paulson@13860:   "!!A B C. ((UN x:C. A x) - B) = (UN x:C. A x - B)"
paulson@13860:   "!!A B C. (A - (INT x:C. B x)) = (UN x:C. A - B x)"
paulson@13860:   "!!A B. (UN y:A. UN x:y. B x) = (UN x: Union A. B x)"
paulson@13860:   "!!A B C. (UN  x:A. UN z: B(x). C z) = (UN z: UNION A B. C z)"
paulson@13860:   "!!A B f. (UN a:A. B (f a)) = (UN x:f`A. B x)"
paulson@13860:   by auto
paulson@13860: 
paulson@13860: lemma INT_extend_simps:
paulson@13860:   "!!A B C. (INT x:C. A x) Int B = (if C={} then B else (INT x:C. A x Int B))"
paulson@13860:   "!!A B C. A Int (INT x:C. B x) = (if C={} then A else (INT x:C. A Int B x))"
paulson@13860:   "!!A B C. (INT x:C. A x) - B   = (if C={} then UNIV-B else (INT x:C. A x - B))"
paulson@13860:   "!!A B C. A - (UN x:C. B x)   = (if C={} then A else (INT x:C. A - B x))"
paulson@13860:   "!!a B C. insert a (INT x:C. B x) = (INT x:C. insert a (B x))"
paulson@13860:   "!!A B C. ((INT x:C. A x) Un B)  = (INT x:C. A x Un B)"
paulson@13860:   "!!A B C. A Un (INT x:C. B x)  = (INT x:C. A Un B x)"
paulson@13860:   "!!A B. (INT y:A. INT x:y. B x) = (INT x: Union A. B x)"
paulson@13860:   "!!A B C. (INT x:A. INT z: B(x). C z) = (INT z: UNION A B. C z)"
paulson@13860:   "!!A B f. (INT a:A. B (f a))    = (INT x:f`A. B x)"
paulson@13860:   by auto
paulson@13860: 
paulson@13860: 
wenzelm@12897: subsubsection {* Monotonicity of various operations *}
wenzelm@12897: 
wenzelm@12897: lemma image_mono: "A \<subseteq> B ==> f`A \<subseteq> f`B"
wenzelm@12897:   by blast
wenzelm@12897: 
wenzelm@12897: lemma Pow_mono: "A \<subseteq> B ==> Pow A \<subseteq> Pow B"
wenzelm@12897:   by blast
wenzelm@12897: 
wenzelm@12897: lemma Union_mono: "A \<subseteq> B ==> \<Union>A \<subseteq> \<Union>B"
wenzelm@12897:   by blast
wenzelm@12897: 
wenzelm@12897: lemma Inter_anti_mono: "B \<subseteq> A ==> \<Inter>A \<subseteq> \<Inter>B"
wenzelm@12897:   by blast
wenzelm@12897: 
wenzelm@12897: lemma UN_mono:
wenzelm@12897:   "A \<subseteq> B ==> (!!x. x \<in> A ==> f x \<subseteq> g x) ==>
wenzelm@12897:     (\<Union>x\<in>A. f x) \<subseteq> (\<Union>x\<in>B. g x)"
wenzelm@12897:   by (blast dest: subsetD)
wenzelm@12897: 
wenzelm@12897: lemma INT_anti_mono:
wenzelm@12897:   "B \<subseteq> A ==> (!!x. x \<in> A ==> f x \<subseteq> g x) ==>
wenzelm@12897:     (\<Inter>x\<in>A. f x) \<subseteq> (\<Inter>x\<in>A. g x)"
wenzelm@12897:   -- {* The last inclusion is POSITIVE! *}
wenzelm@12897:   by (blast dest: subsetD)
wenzelm@12897: 
wenzelm@12897: lemma insert_mono: "C \<subseteq> D ==> insert a C \<subseteq> insert a D"
wenzelm@12897:   by blast
wenzelm@12897: 
wenzelm@12897: lemma Un_mono: "A \<subseteq> C ==> B \<subseteq> D ==> A \<union> B \<subseteq> C \<union> D"
wenzelm@12897:   by blast
wenzelm@12897: 
wenzelm@12897: lemma Int_mono: "A \<subseteq> C ==> B \<subseteq> D ==> A \<inter> B \<subseteq> C \<inter> D"
wenzelm@12897:   by blast
wenzelm@12897: 
wenzelm@12897: lemma Diff_mono: "A \<subseteq> C ==> D \<subseteq> B ==> A - B \<subseteq> C - D"
wenzelm@12897:   by blast
wenzelm@12897: 
wenzelm@12897: lemma Compl_anti_mono: "A \<subseteq> B ==> -B \<subseteq> -A"
wenzelm@12897:   by blast
wenzelm@12897: 
wenzelm@12897: text {* \medskip Monotonicity of implications. *}
wenzelm@12897: 
wenzelm@12897: lemma in_mono: "A \<subseteq> B ==> x \<in> A --> x \<in> B"
wenzelm@12897:   apply (rule impI)
wenzelm@12897:   apply (erule subsetD)
wenzelm@12897:   apply assumption
wenzelm@12897:   done
wenzelm@12897: 
wenzelm@12897: lemma conj_mono: "P1 --> Q1 ==> P2 --> Q2 ==> (P1 & P2) --> (Q1 & Q2)"
wenzelm@12897:   by rules
wenzelm@12897: 
wenzelm@12897: lemma disj_mono: "P1 --> Q1 ==> P2 --> Q2 ==> (P1 | P2) --> (Q1 | Q2)"
wenzelm@12897:   by rules
wenzelm@12897: 
wenzelm@12897: lemma imp_mono: "Q1 --> P1 ==> P2 --> Q2 ==> (P1 --> P2) --> (Q1 --> Q2)"
wenzelm@12897:   by rules
wenzelm@12897: 
wenzelm@12897: lemma imp_refl: "P --> P" ..
wenzelm@12897: 
wenzelm@12897: lemma ex_mono: "(!!x. P x --> Q x) ==> (EX x. P x) --> (EX x. Q x)"
wenzelm@12897:   by rules
wenzelm@12897: 
wenzelm@12897: lemma all_mono: "(!!x. P x --> Q x) ==> (ALL x. P x) --> (ALL x. Q x)"
wenzelm@12897:   by rules
wenzelm@12897: 
wenzelm@12897: lemma Collect_mono: "(!!x. P x --> Q x) ==> Collect P \<subseteq> Collect Q"
wenzelm@12897:   by blast
wenzelm@12897: 
wenzelm@12897: lemma Int_Collect_mono:
wenzelm@12897:     "A \<subseteq> B ==> (!!x. x \<in> A ==> P x --> Q x) ==> A \<inter> Collect P \<subseteq> B \<inter> Collect Q"
wenzelm@12897:   by blast
wenzelm@12897: 
wenzelm@12897: lemmas basic_monos =
wenzelm@12897:   subset_refl imp_refl disj_mono conj_mono
wenzelm@12897:   ex_mono Collect_mono in_mono
wenzelm@12897: 
wenzelm@12897: lemma eq_to_mono: "a = b ==> c = d ==> b --> d ==> a --> c"
wenzelm@12897:   by rules
wenzelm@12897: 
wenzelm@12897: lemma eq_to_mono2: "a = b ==> c = d ==> ~ b --> ~ d ==> ~ a --> ~ c"
wenzelm@12897:   by rules
wenzelm@11979: 
wenzelm@11982: lemma Least_mono:
wenzelm@11982:   "mono (f::'a::order => 'b::order) ==> EX x:S. ALL y:S. x <= y
wenzelm@11982:     ==> (LEAST y. y : f ` S) = f (LEAST x. x : S)"
wenzelm@11982:     -- {* Courtesy of Stephan Merz *}
wenzelm@11982:   apply clarify
wenzelm@11982:   apply (erule_tac P = "%x. x : S" in LeastI2)
wenzelm@11982:    apply fast
wenzelm@11982:   apply (rule LeastI2)
wenzelm@11982:   apply (auto elim: monoD intro!: order_antisym)
wenzelm@11982:   done
wenzelm@11982: 
wenzelm@12020: 
wenzelm@12257: subsection {* Inverse image of a function *}
wenzelm@12257: 
wenzelm@12257: constdefs
wenzelm@12257:   vimage :: "('a => 'b) => 'b set => 'a set"    (infixr "-`" 90)
wenzelm@12257:   "f -` B == {x. f x : B}"
wenzelm@12257: 
wenzelm@12257: 
wenzelm@12257: subsubsection {* Basic rules *}
wenzelm@12257: 
wenzelm@12257: lemma vimage_eq [simp]: "(a : f -` B) = (f a : B)"
wenzelm@12257:   by (unfold vimage_def) blast
wenzelm@12257: 
wenzelm@12257: lemma vimage_singleton_eq: "(a : f -` {b}) = (f a = b)"
wenzelm@12257:   by simp
wenzelm@12257: 
wenzelm@12257: lemma vimageI [intro]: "f a = b ==> b:B ==> a : f -` B"
wenzelm@12257:   by (unfold vimage_def) blast
wenzelm@12257: 
wenzelm@12257: lemma vimageI2: "f a : A ==> a : f -` A"
wenzelm@12257:   by (unfold vimage_def) fast
wenzelm@12257: 
wenzelm@12257: lemma vimageE [elim!]: "a: f -` B ==> (!!x. f a = x ==> x:B ==> P) ==> P"
wenzelm@12257:   by (unfold vimage_def) blast
wenzelm@12257: 
wenzelm@12257: lemma vimageD: "a : f -` A ==> f a : A"
wenzelm@12257:   by (unfold vimage_def) fast
wenzelm@12257: 
wenzelm@12257: 
wenzelm@12257: subsubsection {* Equations *}
wenzelm@12257: 
wenzelm@12257: lemma vimage_empty [simp]: "f -` {} = {}"
wenzelm@12257:   by blast
wenzelm@12257: 
wenzelm@12257: lemma vimage_Compl: "f -` (-A) = -(f -` A)"
wenzelm@12257:   by blast
wenzelm@12257: 
wenzelm@12257: lemma vimage_Un [simp]: "f -` (A Un B) = (f -` A) Un (f -` B)"
wenzelm@12257:   by blast
wenzelm@12257: 
wenzelm@12257: lemma vimage_Int [simp]: "f -` (A Int B) = (f -` A) Int (f -` B)"
wenzelm@12257:   by fast
wenzelm@12257: 
wenzelm@12257: lemma vimage_Union: "f -` (Union A) = (UN X:A. f -` X)"
wenzelm@12257:   by blast
wenzelm@12257: 
wenzelm@12257: lemma vimage_UN: "f-`(UN x:A. B x) = (UN x:A. f -` B x)"
wenzelm@12257:   by blast
wenzelm@12257: 
wenzelm@12257: lemma vimage_INT: "f-`(INT x:A. B x) = (INT x:A. f -` B x)"
wenzelm@12257:   by blast
wenzelm@12257: 
wenzelm@12257: lemma vimage_Collect_eq [simp]: "f -` Collect P = {y. P (f y)}"
wenzelm@12257:   by blast
wenzelm@12257: 
wenzelm@12257: lemma vimage_Collect: "(!!x. P (f x) = Q x) ==> f -` (Collect P) = Collect Q"
wenzelm@12257:   by blast
wenzelm@12257: 
wenzelm@12257: lemma vimage_insert: "f-`(insert a B) = (f-`{a}) Un (f-`B)"
wenzelm@12257:   -- {* NOT suitable for rewriting because of the recurrence of @{term "{a}"}. *}
wenzelm@12257:   by blast
wenzelm@12257: 
wenzelm@12257: lemma vimage_Diff: "f -` (A - B) = (f -` A) - (f -` B)"
wenzelm@12257:   by blast
wenzelm@12257: 
wenzelm@12257: lemma vimage_UNIV [simp]: "f -` UNIV = UNIV"
wenzelm@12257:   by blast
wenzelm@12257: 
wenzelm@12257: lemma vimage_eq_UN: "f-`B = (UN y: B. f-`{y})"
wenzelm@12257:   -- {* NOT suitable for rewriting *}
wenzelm@12257:   by blast
wenzelm@12257: 
wenzelm@12897: lemma vimage_mono: "A \<subseteq> B ==> f -` A \<subseteq> f -` B"
wenzelm@12257:   -- {* monotonicity *}
wenzelm@12257:   by blast
wenzelm@12257: 
wenzelm@12257: 
wenzelm@12023: subsection {* Transitivity rules for calculational reasoning *}
wenzelm@12020: 
wenzelm@12020: lemma forw_subst: "a = b ==> P b ==> P a"
wenzelm@12020:   by (rule ssubst)
wenzelm@12020: 
wenzelm@12020: lemma back_subst: "P a ==> a = b ==> P b"
wenzelm@12020:   by (rule subst)
wenzelm@12020: 
wenzelm@12897: lemma set_rev_mp: "x:A ==> A \<subseteq> B ==> x:B"
wenzelm@12020:   by (rule subsetD)
wenzelm@12020: 
wenzelm@12897: lemma set_mp: "A \<subseteq> B ==> x:A ==> x:B"
wenzelm@12020:   by (rule subsetD)
wenzelm@12020: 
wenzelm@12020: lemma order_neq_le_trans: "a ~= b ==> (a::'a::order) <= b ==> a < b"
wenzelm@12020:   by (simp add: order_less_le)
wenzelm@12020: 
wenzelm@12020: lemma order_le_neq_trans: "(a::'a::order) <= b ==> a ~= b ==> a < b"
wenzelm@12020:   by (simp add: order_less_le)
wenzelm@12020: 
wenzelm@12020: lemma order_less_asym': "(a::'a::order) < b ==> b < a ==> P"
wenzelm@12020:   by (rule order_less_asym)
wenzelm@12020: 
wenzelm@12020: lemma ord_le_eq_trans: "a <= b ==> b = c ==> a <= c"
wenzelm@12020:   by (rule subst)
wenzelm@12020: 
wenzelm@12020: lemma ord_eq_le_trans: "a = b ==> b <= c ==> a <= c"
wenzelm@12020:   by (rule ssubst)
wenzelm@12020: 
wenzelm@12020: lemma ord_less_eq_trans: "a < b ==> b = c ==> a < c"
wenzelm@12020:   by (rule subst)
wenzelm@12020: 
wenzelm@12020: lemma ord_eq_less_trans: "a = b ==> b < c ==> a < c"
wenzelm@12020:   by (rule ssubst)
wenzelm@12020: 
wenzelm@12020: lemma order_less_subst2: "(a::'a::order) < b ==> f b < (c::'c::order) ==>
wenzelm@12020:   (!!x y. x < y ==> f x < f y) ==> f a < c"
wenzelm@12020: proof -
wenzelm@12020:   assume r: "!!x y. x < y ==> f x < f y"
wenzelm@12020:   assume "a < b" hence "f a < f b" by (rule r)
wenzelm@12020:   also assume "f b < c"
wenzelm@12020:   finally (order_less_trans) show ?thesis .
wenzelm@12020: qed
wenzelm@12020: 
wenzelm@12020: lemma order_less_subst1: "(a::'a::order) < f b ==> (b::'b::order) < c ==>
wenzelm@12020:   (!!x y. x < y ==> f x < f y) ==> a < f c"
wenzelm@12020: proof -
wenzelm@12020:   assume r: "!!x y. x < y ==> f x < f y"
wenzelm@12020:   assume "a < f b"
wenzelm@12020:   also assume "b < c" hence "f b < f c" by (rule r)
wenzelm@12020:   finally (order_less_trans) show ?thesis .
wenzelm@12020: qed
wenzelm@12020: 
wenzelm@12020: lemma order_le_less_subst2: "(a::'a::order) <= b ==> f b < (c::'c::order) ==>
wenzelm@12020:   (!!x y. x <= y ==> f x <= f y) ==> f a < c"
wenzelm@12020: proof -
wenzelm@12020:   assume r: "!!x y. x <= y ==> f x <= f y"
wenzelm@12020:   assume "a <= b" hence "f a <= f b" by (rule r)
wenzelm@12020:   also assume "f b < c"
wenzelm@12020:   finally (order_le_less_trans) show ?thesis .
wenzelm@12020: qed
wenzelm@12020: 
wenzelm@12020: lemma order_le_less_subst1: "(a::'a::order) <= f b ==> (b::'b::order) < c ==>
wenzelm@12020:   (!!x y. x < y ==> f x < f y) ==> a < f c"
wenzelm@12020: proof -
wenzelm@12020:   assume r: "!!x y. x < y ==> f x < f y"
wenzelm@12020:   assume "a <= f b"
wenzelm@12020:   also assume "b < c" hence "f b < f c" by (rule r)
wenzelm@12020:   finally (order_le_less_trans) show ?thesis .
wenzelm@12020: qed
wenzelm@12020: 
wenzelm@12020: lemma order_less_le_subst2: "(a::'a::order) < b ==> f b <= (c::'c::order) ==>
wenzelm@12020:   (!!x y. x < y ==> f x < f y) ==> f a < c"
wenzelm@12020: proof -
wenzelm@12020:   assume r: "!!x y. x < y ==> f x < f y"
wenzelm@12020:   assume "a < b" hence "f a < f b" by (rule r)
wenzelm@12020:   also assume "f b <= c"
wenzelm@12020:   finally (order_less_le_trans) show ?thesis .
wenzelm@12020: qed
wenzelm@12020: 
wenzelm@12020: lemma order_less_le_subst1: "(a::'a::order) < f b ==> (b::'b::order) <= c ==>
wenzelm@12020:   (!!x y. x <= y ==> f x <= f y) ==> a < f c"
wenzelm@12020: proof -
wenzelm@12020:   assume r: "!!x y. x <= y ==> f x <= f y"
wenzelm@12020:   assume "a < f b"
wenzelm@12020:   also assume "b <= c" hence "f b <= f c" by (rule r)
wenzelm@12020:   finally (order_less_le_trans) show ?thesis .
wenzelm@12020: qed
wenzelm@12020: 
wenzelm@12020: lemma order_subst1: "(a::'a::order) <= f b ==> (b::'b::order) <= c ==>
wenzelm@12020:   (!!x y. x <= y ==> f x <= f y) ==> a <= f c"
wenzelm@12020: proof -
wenzelm@12020:   assume r: "!!x y. x <= y ==> f x <= f y"
wenzelm@12020:   assume "a <= f b"
wenzelm@12020:   also assume "b <= c" hence "f b <= f c" by (rule r)
wenzelm@12020:   finally (order_trans) show ?thesis .
wenzelm@12020: qed
wenzelm@12020: 
wenzelm@12020: lemma order_subst2: "(a::'a::order) <= b ==> f b <= (c::'c::order) ==>
wenzelm@12020:   (!!x y. x <= y ==> f x <= f y) ==> f a <= c"
wenzelm@12020: proof -
wenzelm@12020:   assume r: "!!x y. x <= y ==> f x <= f y"
wenzelm@12020:   assume "a <= b" hence "f a <= f b" by (rule r)
wenzelm@12020:   also assume "f b <= c"
wenzelm@12020:   finally (order_trans) show ?thesis .
wenzelm@12020: qed
wenzelm@12020: 
wenzelm@12020: lemma ord_le_eq_subst: "a <= b ==> f b = c ==>
wenzelm@12020:   (!!x y. x <= y ==> f x <= f y) ==> f a <= c"
wenzelm@12020: proof -
wenzelm@12020:   assume r: "!!x y. x <= y ==> f x <= f y"
wenzelm@12020:   assume "a <= b" hence "f a <= f b" by (rule r)
wenzelm@12020:   also assume "f b = c"
wenzelm@12020:   finally (ord_le_eq_trans) show ?thesis .
wenzelm@12020: qed
wenzelm@12020: 
wenzelm@12020: lemma ord_eq_le_subst: "a = f b ==> b <= c ==>
wenzelm@12020:   (!!x y. x <= y ==> f x <= f y) ==> a <= f c"
wenzelm@12020: proof -
wenzelm@12020:   assume r: "!!x y. x <= y ==> f x <= f y"
wenzelm@12020:   assume "a = f b"
wenzelm@12020:   also assume "b <= c" hence "f b <= f c" by (rule r)
wenzelm@12020:   finally (ord_eq_le_trans) show ?thesis .
wenzelm@12020: qed
wenzelm@12020: 
wenzelm@12020: lemma ord_less_eq_subst: "a < b ==> f b = c ==>
wenzelm@12020:   (!!x y. x < y ==> f x < f y) ==> f a < c"
wenzelm@12020: proof -
wenzelm@12020:   assume r: "!!x y. x < y ==> f x < f y"
wenzelm@12020:   assume "a < b" hence "f a < f b" by (rule r)
wenzelm@12020:   also assume "f b = c"
wenzelm@12020:   finally (ord_less_eq_trans) show ?thesis .
wenzelm@12020: qed
wenzelm@12020: 
wenzelm@12020: lemma ord_eq_less_subst: "a = f b ==> b < c ==>
wenzelm@12020:   (!!x y. x < y ==> f x < f y) ==> a < f c"
wenzelm@12020: proof -
wenzelm@12020:   assume r: "!!x y. x < y ==> f x < f y"
wenzelm@12020:   assume "a = f b"
wenzelm@12020:   also assume "b < c" hence "f b < f c" by (rule r)
wenzelm@12020:   finally (ord_eq_less_trans) show ?thesis .
wenzelm@12020: qed
wenzelm@12020: 
wenzelm@12020: text {*
wenzelm@12020:   Note that this list of rules is in reverse order of priorities.
wenzelm@12020: *}
wenzelm@12020: 
wenzelm@12020: lemmas basic_trans_rules [trans] =
wenzelm@12020:   order_less_subst2
wenzelm@12020:   order_less_subst1
wenzelm@12020:   order_le_less_subst2
wenzelm@12020:   order_le_less_subst1
wenzelm@12020:   order_less_le_subst2
wenzelm@12020:   order_less_le_subst1
wenzelm@12020:   order_subst2
wenzelm@12020:   order_subst1
wenzelm@12020:   ord_le_eq_subst
wenzelm@12020:   ord_eq_le_subst
wenzelm@12020:   ord_less_eq_subst
wenzelm@12020:   ord_eq_less_subst
wenzelm@12020:   forw_subst
wenzelm@12020:   back_subst
wenzelm@12020:   rev_mp
wenzelm@12020:   mp
wenzelm@12020:   set_rev_mp
wenzelm@12020:   set_mp
wenzelm@12020:   order_neq_le_trans
wenzelm@12020:   order_le_neq_trans
wenzelm@12020:   order_less_trans
wenzelm@12020:   order_less_asym'
wenzelm@12020:   order_le_less_trans
wenzelm@12020:   order_less_le_trans
wenzelm@12020:   order_trans
wenzelm@12020:   order_antisym
wenzelm@12020:   ord_le_eq_trans
wenzelm@12020:   ord_eq_le_trans
wenzelm@12020:   ord_less_eq_trans
wenzelm@12020:   ord_eq_less_trans
wenzelm@12020:   trans
wenzelm@12020: 
wenzelm@11979: end




