src/CCL/Set.thy
changeset 58977 9576b510f6a2
parent 58889 5b7a9633cfa8
child 60770 240563fbf41d
equal deleted inserted replaced
58976:b38a54bbfbd6 58977:9576b510f6a2
     8 
     8 
     9 typedecl 'a set
     9 typedecl 'a set
    10 instance set :: ("term") "term" ..
    10 instance set :: ("term") "term" ..
    11 
    11 
    12 consts
    12 consts
    13   Collect       :: "['a => o] => 'a set"                    (*comprehension*)
    13   Collect       :: "['a \<Rightarrow> o] \<Rightarrow> 'a set"                    (*comprehension*)
    14   Compl         :: "('a set) => 'a set"                     (*complement*)
    14   Compl         :: "('a set) \<Rightarrow> 'a set"                     (*complement*)
    15   Int           :: "['a set, 'a set] => 'a set"         (infixl "Int" 70)
    15   Int           :: "['a set, 'a set] \<Rightarrow> 'a set"         (infixl "Int" 70)
    16   Un            :: "['a set, 'a set] => 'a set"         (infixl "Un" 65)
    16   Un            :: "['a set, 'a set] \<Rightarrow> 'a set"         (infixl "Un" 65)
    17   Union         :: "(('a set)set) => 'a set"                (*...of a set*)
    17   Union         :: "(('a set)set) \<Rightarrow> 'a set"                (*...of a set*)
    18   Inter         :: "(('a set)set) => 'a set"                (*...of a set*)
    18   Inter         :: "(('a set)set) \<Rightarrow> 'a set"                (*...of a set*)
    19   UNION         :: "['a set, 'a => 'b set] => 'b set"       (*general*)
    19   UNION         :: "['a set, 'a \<Rightarrow> 'b set] \<Rightarrow> 'b set"       (*general*)
    20   INTER         :: "['a set, 'a => 'b set] => 'b set"       (*general*)
    20   INTER         :: "['a set, 'a \<Rightarrow> 'b set] \<Rightarrow> 'b set"       (*general*)
    21   Ball          :: "['a set, 'a => o] => o"                 (*bounded quants*)
    21   Ball          :: "['a set, 'a \<Rightarrow> o] \<Rightarrow> o"                 (*bounded quants*)
    22   Bex           :: "['a set, 'a => o] => o"                 (*bounded quants*)
    22   Bex           :: "['a set, 'a \<Rightarrow> o] \<Rightarrow> o"                 (*bounded quants*)
    23   mono          :: "['a set => 'b set] => o"                (*monotonicity*)
    23   mono          :: "['a set \<Rightarrow> 'b set] \<Rightarrow> o"                (*monotonicity*)
    24   mem           :: "['a, 'a set] => o"                  (infixl ":" 50) (*membership*)
    24   mem           :: "['a, 'a set] \<Rightarrow> o"                  (infixl ":" 50) (*membership*)
    25   subset        :: "['a set, 'a set] => o"              (infixl "<=" 50)
    25   subset        :: "['a set, 'a set] \<Rightarrow> o"              (infixl "<=" 50)
    26   singleton     :: "'a => 'a set"                       ("{_}")
    26   singleton     :: "'a \<Rightarrow> 'a set"                       ("{_}")
    27   empty         :: "'a set"                             ("{}")
    27   empty         :: "'a set"                             ("{}")
    28 
    28 
    29 syntax
    29 syntax
    30   "_Coll"       :: "[idt, o] => 'a set"                 ("(1{_./ _})") (*collection*)
    30   "_Coll"       :: "[idt, o] \<Rightarrow> 'a set"                 ("(1{_./ _})") (*collection*)
    31 
    31 
    32   (* Big Intersection / Union *)
    32   (* Big Intersection / Union *)
    33 
    33 
    34   "_INTER"      :: "[idt, 'a set, 'b set] => 'b set"    ("(INT _:_./ _)" [0, 0, 0] 10)
    34   "_INTER"      :: "[idt, 'a set, 'b set] \<Rightarrow> 'b set"    ("(INT _:_./ _)" [0, 0, 0] 10)
    35   "_UNION"      :: "[idt, 'a set, 'b set] => 'b set"    ("(UN _:_./ _)" [0, 0, 0] 10)
    35   "_UNION"      :: "[idt, 'a set, 'b set] \<Rightarrow> 'b set"    ("(UN _:_./ _)" [0, 0, 0] 10)
    36 
    36 
    37   (* Bounded Quantifiers *)
    37   (* Bounded Quantifiers *)
    38 
    38 
    39   "_Ball"       :: "[idt, 'a set, o] => o"              ("(ALL _:_./ _)" [0, 0, 0] 10)
    39   "_Ball"       :: "[idt, 'a set, o] \<Rightarrow> o"              ("(ALL _:_./ _)" [0, 0, 0] 10)
    40   "_Bex"        :: "[idt, 'a set, o] => o"              ("(EX _:_./ _)" [0, 0, 0] 10)
    40   "_Bex"        :: "[idt, 'a set, o] \<Rightarrow> o"              ("(EX _:_./ _)" [0, 0, 0] 10)
    41 
    41 
    42 translations
    42 translations
    43   "{x. P}"      == "CONST Collect(%x. P)"
    43   "{x. P}"      == "CONST Collect(\<lambda>x. P)"
    44   "INT x:A. B"  == "CONST INTER(A, %x. B)"
    44   "INT x:A. B"  == "CONST INTER(A, \<lambda>x. B)"
    45   "UN x:A. B"   == "CONST UNION(A, %x. B)"
    45   "UN x:A. B"   == "CONST UNION(A, \<lambda>x. B)"
    46   "ALL x:A. P"  == "CONST Ball(A, %x. P)"
    46   "ALL x:A. P"  == "CONST Ball(A, \<lambda>x. P)"
    47   "EX x:A. P"   == "CONST Bex(A, %x. P)"
    47   "EX x:A. P"   == "CONST Bex(A, \<lambda>x. P)"
    48 
    48 
    49 axiomatization where
    49 axiomatization where
    50   mem_Collect_iff: "(a : {x. P(x)}) <-> P(a)" and
    50   mem_Collect_iff: "(a : {x. P(x)}) \<longleftrightarrow> P(a)" and
    51   set_extension: "A = B <-> (ALL x. x:A <-> x:B)"
    51   set_extension: "A = B \<longleftrightarrow> (ALL x. x:A \<longleftrightarrow> x:B)"
    52 
    52 
    53 defs
    53 defs
    54   Ball_def:      "Ball(A, P)  == ALL x. x:A --> P(x)"
    54   Ball_def:      "Ball(A, P)  == ALL x. x:A \<longrightarrow> P(x)"
    55   Bex_def:       "Bex(A, P)   == EX x. x:A & P(x)"
    55   Bex_def:       "Bex(A, P)   == EX x. x:A \<and> P(x)"
    56   mono_def:      "mono(f)     == (ALL A B. A <= B --> f(A) <= f(B))"
    56   mono_def:      "mono(f)     == (ALL A B. A <= B \<longrightarrow> f(A) <= f(B))"
    57   subset_def:    "A <= B      == ALL x:A. x:B"
    57   subset_def:    "A <= B      == ALL x:A. x:B"
    58   singleton_def: "{a}         == {x. x=a}"
    58   singleton_def: "{a}         == {x. x=a}"
    59   empty_def:     "{}          == {x. False}"
    59   empty_def:     "{}          == {x. False}"
    60   Un_def:        "A Un B      == {x. x:A | x:B}"
    60   Un_def:        "A Un B      == {x. x:A | x:B}"
    61   Int_def:       "A Int B     == {x. x:A & x:B}"
    61   Int_def:       "A Int B     == {x. x:A \<and> x:B}"
    62   Compl_def:     "Compl(A)    == {x. ~x:A}"
    62   Compl_def:     "Compl(A)    == {x. \<not>x:A}"
    63   INTER_def:     "INTER(A, B) == {y. ALL x:A. y: B(x)}"
    63   INTER_def:     "INTER(A, B) == {y. ALL x:A. y: B(x)}"
    64   UNION_def:     "UNION(A, B) == {y. EX x:A. y: B(x)}"
    64   UNION_def:     "UNION(A, B) == {y. EX x:A. y: B(x)}"
    65   Inter_def:     "Inter(S)    == (INT x:S. x)"
    65   Inter_def:     "Inter(S)    == (INT x:S. x)"
    66   Union_def:     "Union(S)    == (UN x:S. x)"
    66   Union_def:     "Union(S)    == (UN x:S. x)"
    67 
    67 
    68 
    68 
    69 lemma CollectI: "[| P(a) |] ==> a : {x. P(x)}"
    69 lemma CollectI: "P(a) \<Longrightarrow> a : {x. P(x)}"
    70   apply (rule mem_Collect_iff [THEN iffD2])
    70   apply (rule mem_Collect_iff [THEN iffD2])
    71   apply assumption
    71   apply assumption
    72   done
    72   done
    73 
    73 
    74 lemma CollectD: "[| a : {x. P(x)} |] ==> P(a)"
    74 lemma CollectD: "a : {x. P(x)} \<Longrightarrow> P(a)"
    75   apply (erule mem_Collect_iff [THEN iffD1])
    75   apply (erule mem_Collect_iff [THEN iffD1])
    76   done
    76   done
    77 
    77 
    78 lemmas CollectE = CollectD [elim_format]
    78 lemmas CollectE = CollectD [elim_format]
    79 
    79 
    80 lemma set_ext: "[| !!x. x:A <-> x:B |] ==> A = B"
    80 lemma set_ext: "(\<And>x. x:A \<longleftrightarrow> x:B) \<Longrightarrow> A = B"
    81   apply (rule set_extension [THEN iffD2])
    81   apply (rule set_extension [THEN iffD2])
    82   apply simp
    82   apply simp
    83   done
    83   done
    84 
    84 
    85 
    85 
    86 subsection {* Bounded quantifiers *}
    86 subsection {* Bounded quantifiers *}
    87 
    87 
    88 lemma ballI: "[| !!x. x:A ==> P(x) |] ==> ALL x:A. P(x)"
    88 lemma ballI: "(\<And>x. x:A \<Longrightarrow> P(x)) \<Longrightarrow> ALL x:A. P(x)"
    89   by (simp add: Ball_def)
    89   by (simp add: Ball_def)
    90 
    90 
    91 lemma bspec: "[| ALL x:A. P(x);  x:A |] ==> P(x)"
    91 lemma bspec: "\<lbrakk>ALL x:A. P(x); x:A\<rbrakk> \<Longrightarrow> P(x)"
    92   by (simp add: Ball_def)
    92   by (simp add: Ball_def)
    93 
    93 
    94 lemma ballE: "[| ALL x:A. P(x);  P(x) ==> Q;  ~ x:A ==> Q |] ==> Q"
    94 lemma ballE: "\<lbrakk>ALL x:A. P(x); P(x) \<Longrightarrow> Q; \<not> x:A \<Longrightarrow> Q\<rbrakk> \<Longrightarrow> Q"
    95   unfolding Ball_def by blast
    95   unfolding Ball_def by blast
    96 
    96 
    97 lemma bexI: "[| P(x);  x:A |] ==> EX x:A. P(x)"
    97 lemma bexI: "\<lbrakk>P(x); x:A\<rbrakk> \<Longrightarrow> EX x:A. P(x)"
    98   unfolding Bex_def by blast
    98   unfolding Bex_def by blast
    99 
    99 
   100 lemma bexCI: "[| EX x:A. ~P(x) ==> P(a);  a:A |] ==> EX x:A. P(x)"
   100 lemma bexCI: "\<lbrakk>EX x:A. \<not>P(x) \<Longrightarrow> P(a); a:A\<rbrakk> \<Longrightarrow> EX x:A. P(x)"
   101   unfolding Bex_def by blast
   101   unfolding Bex_def by blast
   102 
   102 
   103 lemma bexE: "[| EX x:A. P(x);  !!x. [| x:A; P(x) |] ==> Q  |] ==> Q"
   103 lemma bexE: "\<lbrakk>EX x:A. P(x); \<And>x. \<lbrakk>x:A; P(x)\<rbrakk> \<Longrightarrow> Q\<rbrakk> \<Longrightarrow> Q"
   104   unfolding Bex_def by blast
   104   unfolding Bex_def by blast
   105 
   105 
   106 (*Trival rewrite rule;   (! x:A.P)=P holds only if A is nonempty!*)
   106 (*Trival rewrite rule;   (! x:A.P)=P holds only if A is nonempty!*)
   107 lemma ball_rew: "(ALL x:A. True) <-> True"
   107 lemma ball_rew: "(ALL x:A. True) \<longleftrightarrow> True"
   108   by (blast intro: ballI)
   108   by (blast intro: ballI)
   109 
   109 
   110 
   110 
   111 subsection {* Congruence rules *}
   111 subsection {* Congruence rules *}
   112 
   112 
   113 lemma ball_cong:
   113 lemma ball_cong:
   114   "[| A=A';  !!x. x:A' ==> P(x) <-> P'(x) |] ==>
   114   "\<lbrakk>A = A'; \<And>x. x:A' \<Longrightarrow> P(x) \<longleftrightarrow> P'(x)\<rbrakk> \<Longrightarrow>
   115     (ALL x:A. P(x)) <-> (ALL x:A'. P'(x))"
   115     (ALL x:A. P(x)) \<longleftrightarrow> (ALL x:A'. P'(x))"
   116   by (blast intro: ballI elim: ballE)
   116   by (blast intro: ballI elim: ballE)
   117 
   117 
   118 lemma bex_cong:
   118 lemma bex_cong:
   119   "[| A=A';  !!x. x:A' ==> P(x) <-> P'(x) |] ==>
   119   "\<lbrakk>A = A'; \<And>x. x:A' \<Longrightarrow> P(x) \<longleftrightarrow> P'(x)\<rbrakk> \<Longrightarrow>
   120     (EX x:A. P(x)) <-> (EX x:A'. P'(x))"
   120     (EX x:A. P(x)) \<longleftrightarrow> (EX x:A'. P'(x))"
   121   by (blast intro: bexI elim: bexE)
   121   by (blast intro: bexI elim: bexE)
   122 
   122 
   123 
   123 
   124 subsection {* Rules for subsets *}
   124 subsection {* Rules for subsets *}
   125 
   125 
   126 lemma subsetI: "(!!x. x:A ==> x:B) ==> A <= B"
   126 lemma subsetI: "(\<And>x. x:A \<Longrightarrow> x:B) \<Longrightarrow> A <= B"
   127   unfolding subset_def by (blast intro: ballI)
   127   unfolding subset_def by (blast intro: ballI)
   128 
   128 
   129 (*Rule in Modus Ponens style*)
   129 (*Rule in Modus Ponens style*)
   130 lemma subsetD: "[| A <= B;  c:A |] ==> c:B"
   130 lemma subsetD: "\<lbrakk>A <= B; c:A\<rbrakk> \<Longrightarrow> c:B"
   131   unfolding subset_def by (blast elim: ballE)
   131   unfolding subset_def by (blast elim: ballE)
   132 
   132 
   133 (*Classical elimination rule*)
   133 (*Classical elimination rule*)
   134 lemma subsetCE: "[| A <= B;  ~(c:A) ==> P;  c:B ==> P |] ==> P"
   134 lemma subsetCE: "\<lbrakk>A <= B; \<not>(c:A) \<Longrightarrow> P; c:B \<Longrightarrow> P\<rbrakk> \<Longrightarrow> P"
   135   by (blast dest: subsetD)
   135   by (blast dest: subsetD)
   136 
   136 
   137 lemma subset_refl: "A <= A"
   137 lemma subset_refl: "A <= A"
   138   by (blast intro: subsetI)
   138   by (blast intro: subsetI)
   139 
   139 
   140 lemma subset_trans: "[| A<=B;  B<=C |] ==> A<=C"
   140 lemma subset_trans: "\<lbrakk>A <= B; B <= C\<rbrakk> \<Longrightarrow> A <= C"
   141   by (blast intro: subsetI dest: subsetD)
   141   by (blast intro: subsetI dest: subsetD)
   142 
   142 
   143 
   143 
   144 subsection {* Rules for equality *}
   144 subsection {* Rules for equality *}
   145 
   145 
   146 (*Anti-symmetry of the subset relation*)
   146 (*Anti-symmetry of the subset relation*)
   147 lemma subset_antisym: "[| A <= B;  B <= A |] ==> A = B"
   147 lemma subset_antisym: "\<lbrakk>A <= B; B <= A\<rbrakk> \<Longrightarrow> A = B"
   148   by (blast intro: set_ext dest: subsetD)
   148   by (blast intro: set_ext dest: subsetD)
   149 
   149 
   150 lemmas equalityI = subset_antisym
   150 lemmas equalityI = subset_antisym
   151 
   151 
   152 (* Equality rules from ZF set theory -- are they appropriate here? *)
   152 (* Equality rules from ZF set theory -- are they appropriate here? *)
   153 lemma equalityD1: "A = B ==> A<=B"
   153 lemma equalityD1: "A = B \<Longrightarrow> A<=B"
   154   and equalityD2: "A = B ==> B<=A"
   154   and equalityD2: "A = B \<Longrightarrow> B<=A"
   155   by (simp_all add: subset_refl)
   155   by (simp_all add: subset_refl)
   156 
   156 
   157 lemma equalityE: "[| A = B;  [| A<=B; B<=A |] ==> P |]  ==>  P"
   157 lemma equalityE: "\<lbrakk>A = B; \<lbrakk>A <= B; B <= A\<rbrakk> \<Longrightarrow> P\<rbrakk> \<Longrightarrow> P"
   158   by (simp add: subset_refl)
   158   by (simp add: subset_refl)
   159 
   159 
   160 lemma equalityCE:
   160 lemma equalityCE: "\<lbrakk>A = B; \<lbrakk>c:A; c:B\<rbrakk> \<Longrightarrow> P; \<lbrakk>\<not> c:A; \<not> c:B\<rbrakk> \<Longrightarrow> P\<rbrakk> \<Longrightarrow> P"
   161     "[| A = B;  [| c:A; c:B |] ==> P;  [| ~ c:A; ~ c:B |] ==> P |]  ==>  P"
       
   162   by (blast elim: equalityE subsetCE)
   161   by (blast elim: equalityE subsetCE)
   163 
   162 
   164 lemma trivial_set: "{x. x:A} = A"
   163 lemma trivial_set: "{x. x:A} = A"
   165   by (blast intro: equalityI subsetI CollectI dest: CollectD)
   164   by (blast intro: equalityI subsetI CollectI dest: CollectD)
   166 
   165 
   167 
   166 
   168 subsection {* Rules for binary union *}
   167 subsection {* Rules for binary union *}
   169 
   168 
   170 lemma UnI1: "c:A ==> c : A Un B"
   169 lemma UnI1: "c:A \<Longrightarrow> c : A Un B"
   171   and UnI2: "c:B ==> c : A Un B"
   170   and UnI2: "c:B \<Longrightarrow> c : A Un B"
   172   unfolding Un_def by (blast intro: CollectI)+
   171   unfolding Un_def by (blast intro: CollectI)+
   173 
   172 
   174 (*Classical introduction rule: no commitment to A vs B*)
   173 (*Classical introduction rule: no commitment to A vs B*)
   175 lemma UnCI: "(~c:B ==> c:A) ==> c : A Un B"
   174 lemma UnCI: "(\<not>c:B \<Longrightarrow> c:A) \<Longrightarrow> c : A Un B"
   176   by (blast intro: UnI1 UnI2)
   175   by (blast intro: UnI1 UnI2)
   177 
   176 
   178 lemma UnE: "[| c : A Un B;  c:A ==> P;  c:B ==> P |] ==> P"
   177 lemma UnE: "\<lbrakk>c : A Un B; c:A \<Longrightarrow> P; c:B \<Longrightarrow> P\<rbrakk> \<Longrightarrow> P"
   179   unfolding Un_def by (blast dest: CollectD)
   178   unfolding Un_def by (blast dest: CollectD)
   180 
   179 
   181 
   180 
   182 subsection {* Rules for small intersection *}
   181 subsection {* Rules for small intersection *}
   183 
   182 
   184 lemma IntI: "[| c:A;  c:B |] ==> c : A Int B"
   183 lemma IntI: "\<lbrakk>c:A; c:B\<rbrakk> \<Longrightarrow> c : A Int B"
   185   unfolding Int_def by (blast intro: CollectI)
   184   unfolding Int_def by (blast intro: CollectI)
   186 
   185 
   187 lemma IntD1: "c : A Int B ==> c:A"
   186 lemma IntD1: "c : A Int B \<Longrightarrow> c:A"
   188   and IntD2: "c : A Int B ==> c:B"
   187   and IntD2: "c : A Int B \<Longrightarrow> c:B"
   189   unfolding Int_def by (blast dest: CollectD)+
   188   unfolding Int_def by (blast dest: CollectD)+
   190 
   189 
   191 lemma IntE: "[| c : A Int B;  [| c:A; c:B |] ==> P |] ==> P"
   190 lemma IntE: "\<lbrakk>c : A Int B; \<lbrakk>c:A; c:B\<rbrakk> \<Longrightarrow> P\<rbrakk> \<Longrightarrow> P"
   192   by (blast dest: IntD1 IntD2)
   191   by (blast dest: IntD1 IntD2)
   193 
   192 
   194 
   193 
   195 subsection {* Rules for set complement *}
   194 subsection {* Rules for set complement *}
   196 
   195 
   197 lemma ComplI: "[| c:A ==> False |] ==> c : Compl(A)"
   196 lemma ComplI: "(c:A \<Longrightarrow> False) \<Longrightarrow> c : Compl(A)"
   198   unfolding Compl_def by (blast intro: CollectI)
   197   unfolding Compl_def by (blast intro: CollectI)
   199 
   198 
   200 (*This form, with negated conclusion, works well with the Classical prover.
   199 (*This form, with negated conclusion, works well with the Classical prover.
   201   Negated assumptions behave like formulae on the right side of the notional
   200   Negated assumptions behave like formulae on the right side of the notional
   202   turnstile...*)
   201   turnstile...*)
   203 lemma ComplD: "[| c : Compl(A) |] ==> ~c:A"
   202 lemma ComplD: "c : Compl(A) \<Longrightarrow> \<not>c:A"
   204   unfolding Compl_def by (blast dest: CollectD)
   203   unfolding Compl_def by (blast dest: CollectD)
   205 
   204 
   206 lemmas ComplE = ComplD [elim_format]
   205 lemmas ComplE = ComplD [elim_format]
   207 
   206 
   208 
   207 
   209 subsection {* Empty sets *}
   208 subsection {* Empty sets *}
   210 
   209 
   211 lemma empty_eq: "{x. False} = {}"
   210 lemma empty_eq: "{x. False} = {}"
   212   by (simp add: empty_def)
   211   by (simp add: empty_def)
   213 
   212 
   214 lemma emptyD: "a : {} ==> P"
   213 lemma emptyD: "a : {} \<Longrightarrow> P"
   215   unfolding empty_def by (blast dest: CollectD)
   214   unfolding empty_def by (blast dest: CollectD)
   216 
   215 
   217 lemmas emptyE = emptyD [elim_format]
   216 lemmas emptyE = emptyD [elim_format]
   218 
   217 
   219 lemma not_emptyD:
   218 lemma not_emptyD:
   220   assumes "~ A={}"
   219   assumes "\<not> A={}"
   221   shows "EX x. x:A"
   220   shows "EX x. x:A"
   222 proof -
   221 proof -
   223   have "\<not> (EX x. x:A) \<Longrightarrow> A = {}"
   222   have "\<not> (EX x. x:A) \<Longrightarrow> A = {}"
   224     by (rule equalityI) (blast intro!: subsetI elim!: emptyD)+
   223     by (rule equalityI) (blast intro!: subsetI elim!: emptyD)+
   225   with assms show ?thesis by blast
   224   with assms show ?thesis by blast
   229 subsection {* Singleton sets *}
   228 subsection {* Singleton sets *}
   230 
   229 
   231 lemma singletonI: "a : {a}"
   230 lemma singletonI: "a : {a}"
   232   unfolding singleton_def by (blast intro: CollectI)
   231   unfolding singleton_def by (blast intro: CollectI)
   233 
   232 
   234 lemma singletonD: "b : {a} ==> b=a"
   233 lemma singletonD: "b : {a} \<Longrightarrow> b=a"
   235   unfolding singleton_def by (blast dest: CollectD)
   234   unfolding singleton_def by (blast dest: CollectD)
   236 
   235 
   237 lemmas singletonE = singletonD [elim_format]
   236 lemmas singletonE = singletonD [elim_format]
   238 
   237 
   239 
   238 
   240 subsection {* Unions of families *}
   239 subsection {* Unions of families *}
   241 
   240 
   242 (*The order of the premises presupposes that A is rigid; b may be flexible*)
   241 (*The order of the premises presupposes that A is rigid; b may be flexible*)
   243 lemma UN_I: "[| a:A;  b: B(a) |] ==> b: (UN x:A. B(x))"
   242 lemma UN_I: "\<lbrakk>a:A; b: B(a)\<rbrakk> \<Longrightarrow> b: (UN x:A. B(x))"
   244   unfolding UNION_def by (blast intro: bexI CollectI)
   243   unfolding UNION_def by (blast intro: bexI CollectI)
   245 
   244 
   246 lemma UN_E: "[| b : (UN x:A. B(x));  !!x.[| x:A;  b: B(x) |] ==> R |] ==> R"
   245 lemma UN_E: "\<lbrakk>b : (UN x:A. B(x)); \<And>x. \<lbrakk>x:A; b: B(x)\<rbrakk> \<Longrightarrow> R\<rbrakk> \<Longrightarrow> R"
   247   unfolding UNION_def by (blast dest: CollectD elim: bexE)
   246   unfolding UNION_def by (blast dest: CollectD elim: bexE)
   248 
   247 
   249 lemma UN_cong:
   248 lemma UN_cong: "\<lbrakk>A = B; \<And>x. x:B \<Longrightarrow> C(x) = D(x)\<rbrakk> \<Longrightarrow> (UN x:A. C(x)) = (UN x:B. D(x))"
   250   "[| A=B;  !!x. x:B ==> C(x) = D(x) |] ==>
       
   251     (UN x:A. C(x)) = (UN x:B. D(x))"
       
   252   by (simp add: UNION_def cong: bex_cong)
   249   by (simp add: UNION_def cong: bex_cong)
   253 
   250 
   254 
   251 
   255 subsection {* Intersections of families *}
   252 subsection {* Intersections of families *}
   256 
   253 
   257 lemma INT_I: "(!!x. x:A ==> b: B(x)) ==> b : (INT x:A. B(x))"
   254 lemma INT_I: "(\<And>x. x:A \<Longrightarrow> b: B(x)) \<Longrightarrow> b : (INT x:A. B(x))"
   258   unfolding INTER_def by (blast intro: CollectI ballI)
   255   unfolding INTER_def by (blast intro: CollectI ballI)
   259 
   256 
   260 lemma INT_D: "[| b : (INT x:A. B(x));  a:A |] ==> b: B(a)"
   257 lemma INT_D: "\<lbrakk>b : (INT x:A. B(x)); a:A\<rbrakk> \<Longrightarrow> b: B(a)"
   261   unfolding INTER_def by (blast dest: CollectD bspec)
   258   unfolding INTER_def by (blast dest: CollectD bspec)
   262 
   259 
   263 (*"Classical" elimination rule -- does not require proving X:C *)
   260 (*"Classical" elimination rule -- does not require proving X:C *)
   264 lemma INT_E: "[| b : (INT x:A. B(x));  b: B(a) ==> R;  ~ a:A ==> R |] ==> R"
   261 lemma INT_E: "\<lbrakk>b : (INT x:A. B(x)); b: B(a) \<Longrightarrow> R; \<not> a:A \<Longrightarrow> R\<rbrakk> \<Longrightarrow> R"
   265   unfolding INTER_def by (blast dest: CollectD bspec)
   262   unfolding INTER_def by (blast dest: CollectD bspec)
   266 
   263 
   267 lemma INT_cong:
   264 lemma INT_cong: "\<lbrakk>A = B; \<And>x. x:B \<Longrightarrow> C(x) = D(x)\<rbrakk> \<Longrightarrow> (INT x:A. C(x)) = (INT x:B. D(x))"
   268   "[| A=B;  !!x. x:B ==> C(x) = D(x) |] ==>
       
   269     (INT x:A. C(x)) = (INT x:B. D(x))"
       
   270   by (simp add: INTER_def cong: ball_cong)
   265   by (simp add: INTER_def cong: ball_cong)
   271 
   266 
   272 
   267 
   273 subsection {* Rules for Unions *}
   268 subsection {* Rules for Unions *}
   274 
   269 
   275 (*The order of the premises presupposes that C is rigid; A may be flexible*)
   270 (*The order of the premises presupposes that C is rigid; A may be flexible*)
   276 lemma UnionI: "[| X:C;  A:X |] ==> A : Union(C)"
   271 lemma UnionI: "\<lbrakk>X:C; A:X\<rbrakk> \<Longrightarrow> A : Union(C)"
   277   unfolding Union_def by (blast intro: UN_I)
   272   unfolding Union_def by (blast intro: UN_I)
   278 
   273 
   279 lemma UnionE: "[| A : Union(C);  !!X.[| A:X;  X:C |] ==> R |] ==> R"
   274 lemma UnionE: "\<lbrakk>A : Union(C); \<And>X. \<lbrakk> A:X; X:C\<rbrakk> \<Longrightarrow> R\<rbrakk> \<Longrightarrow> R"
   280   unfolding Union_def by (blast elim: UN_E)
   275   unfolding Union_def by (blast elim: UN_E)
   281 
   276 
   282 
   277 
   283 subsection {* Rules for Inter *}
   278 subsection {* Rules for Inter *}
   284 
   279 
   285 lemma InterI: "[| !!X. X:C ==> A:X |] ==> A : Inter(C)"
   280 lemma InterI: "(\<And>X. X:C \<Longrightarrow> A:X) \<Longrightarrow> A : Inter(C)"
   286   unfolding Inter_def by (blast intro: INT_I)
   281   unfolding Inter_def by (blast intro: INT_I)
   287 
   282 
   288 (*A "destruct" rule -- every X in C contains A as an element, but
   283 (*A "destruct" rule -- every X in C contains A as an element, but
   289   A:X can hold when X:C does not!  This rule is analogous to "spec". *)
   284   A:X can hold when X:C does not!  This rule is analogous to "spec". *)
   290 lemma InterD: "[| A : Inter(C);  X:C |] ==> A:X"
   285 lemma InterD: "\<lbrakk>A : Inter(C);  X:C\<rbrakk> \<Longrightarrow> A:X"
   291   unfolding Inter_def by (blast dest: INT_D)
   286   unfolding Inter_def by (blast dest: INT_D)
   292 
   287 
   293 (*"Classical" elimination rule -- does not require proving X:C *)
   288 (*"Classical" elimination rule -- does not require proving X:C *)
   294 lemma InterE: "[| A : Inter(C);  A:X ==> R;  ~ X:C ==> R |] ==> R"
   289 lemma InterE: "\<lbrakk>A : Inter(C); A:X \<Longrightarrow> R; \<not> X:C \<Longrightarrow> R\<rbrakk> \<Longrightarrow> R"
   295   unfolding Inter_def by (blast elim: INT_E)
   290   unfolding Inter_def by (blast elim: INT_E)
   296 
   291 
   297 
   292 
   298 section {* Derived rules involving subsets; Union and Intersection as lattice operations *}
   293 section {* Derived rules involving subsets; Union and Intersection as lattice operations *}
   299 
   294 
   300 subsection {* Big Union -- least upper bound of a set *}
   295 subsection {* Big Union -- least upper bound of a set *}
   301 
   296 
   302 lemma Union_upper: "B:A ==> B <= Union(A)"
   297 lemma Union_upper: "B:A \<Longrightarrow> B <= Union(A)"
   303   by (blast intro: subsetI UnionI)
   298   by (blast intro: subsetI UnionI)
   304 
   299 
   305 lemma Union_least: "[| !!X. X:A ==> X<=C |] ==> Union(A) <= C"
   300 lemma Union_least: "(\<And>X. X:A \<Longrightarrow> X<=C) \<Longrightarrow> Union(A) <= C"
   306   by (blast intro: subsetI dest: subsetD elim: UnionE)
   301   by (blast intro: subsetI dest: subsetD elim: UnionE)
   307 
   302 
   308 
   303 
   309 subsection {* Big Intersection -- greatest lower bound of a set *}
   304 subsection {* Big Intersection -- greatest lower bound of a set *}
   310 
   305 
   311 lemma Inter_lower: "B:A ==> Inter(A) <= B"
   306 lemma Inter_lower: "B:A \<Longrightarrow> Inter(A) <= B"
   312   by (blast intro: subsetI dest: InterD)
   307   by (blast intro: subsetI dest: InterD)
   313 
   308 
   314 lemma Inter_greatest: "[| !!X. X:A ==> C<=X |] ==> C <= Inter(A)"
   309 lemma Inter_greatest: "(\<And>X. X:A \<Longrightarrow> C<=X) \<Longrightarrow> C <= Inter(A)"
   315   by (blast intro: subsetI InterI dest: subsetD)
   310   by (blast intro: subsetI InterI dest: subsetD)
   316 
   311 
   317 
   312 
   318 subsection {* Finite Union -- the least upper bound of 2 sets *}
   313 subsection {* Finite Union -- the least upper bound of 2 sets *}
   319 
   314 
   321   by (blast intro: subsetI UnI1)
   316   by (blast intro: subsetI UnI1)
   322 
   317 
   323 lemma Un_upper2: "B <= A Un B"
   318 lemma Un_upper2: "B <= A Un B"
   324   by (blast intro: subsetI UnI2)
   319   by (blast intro: subsetI UnI2)
   325 
   320 
   326 lemma Un_least: "[| A<=C;  B<=C |] ==> A Un B <= C"
   321 lemma Un_least: "\<lbrakk>A<=C; B<=C\<rbrakk> \<Longrightarrow> A Un B <= C"
   327   by (blast intro: subsetI elim: UnE dest: subsetD)
   322   by (blast intro: subsetI elim: UnE dest: subsetD)
   328 
   323 
   329 
   324 
   330 subsection {* Finite Intersection -- the greatest lower bound of 2 sets *}
   325 subsection {* Finite Intersection -- the greatest lower bound of 2 sets *}
   331 
   326 
   333   by (blast intro: subsetI elim: IntE)
   328   by (blast intro: subsetI elim: IntE)
   334 
   329 
   335 lemma Int_lower2: "A Int B <= B"
   330 lemma Int_lower2: "A Int B <= B"
   336   by (blast intro: subsetI elim: IntE)
   331   by (blast intro: subsetI elim: IntE)
   337 
   332 
   338 lemma Int_greatest: "[| C<=A;  C<=B |] ==> C <= A Int B"
   333 lemma Int_greatest: "\<lbrakk>C<=A; C<=B\<rbrakk> \<Longrightarrow> C <= A Int B"
   339   by (blast intro: subsetI IntI dest: subsetD)
   334   by (blast intro: subsetI IntI dest: subsetD)
   340 
   335 
   341 
   336 
   342 subsection {* Monotonicity *}
   337 subsection {* Monotonicity *}
   343 
   338 
   344 lemma monoI: "[| !!A B. A <= B ==> f(A) <= f(B) |] ==> mono(f)"
   339 lemma monoI: "(\<And>A B. A <= B \<Longrightarrow> f(A) <= f(B)) \<Longrightarrow> mono(f)"
   345   unfolding mono_def by blast
   340   unfolding mono_def by blast
   346 
   341 
   347 lemma monoD: "[| mono(f);  A <= B |] ==> f(A) <= f(B)"
   342 lemma monoD: "\<lbrakk>mono(f); A <= B\<rbrakk> \<Longrightarrow> f(A) <= f(B)"
   348   unfolding mono_def by blast
   343   unfolding mono_def by blast
   349 
   344 
   350 lemma mono_Un: "mono(f) ==> f(A) Un f(B) <= f(A Un B)"
   345 lemma mono_Un: "mono(f) \<Longrightarrow> f(A) Un f(B) <= f(A Un B)"
   351   by (blast intro: Un_least dest: monoD intro: Un_upper1 Un_upper2)
   346   by (blast intro: Un_least dest: monoD intro: Un_upper1 Un_upper2)
   352 
   347 
   353 lemma mono_Int: "mono(f) ==> f(A Int B) <= f(A) Int f(B)"
   348 lemma mono_Int: "mono(f) \<Longrightarrow> f(A Int B) <= f(A) Int f(B)"
   354   by (blast intro: Int_greatest dest: monoD intro: Int_lower1 Int_lower2)
   349   by (blast intro: Int_greatest dest: monoD intro: Int_lower1 Int_lower2)
   355 
   350 
   356 
   351 
   357 subsection {* Automated reasoning setup *}
   352 subsection {* Automated reasoning setup *}
   358 
   353 
   360   and [intro] = bexI UnionI UN_I
   355   and [intro] = bexI UnionI UN_I
   361   and [elim!] = bexE UnionE UN_E CollectE ComplE IntE UnE emptyE singletonE
   356   and [elim!] = bexE UnionE UN_E CollectE ComplE IntE UnE emptyE singletonE
   362   and [elim] = ballE InterD InterE INT_D INT_E subsetD subsetCE
   357   and [elim] = ballE InterD InterE INT_D INT_E subsetD subsetCE
   363 
   358 
   364 lemma mem_rews:
   359 lemma mem_rews:
   365   "(a : A Un B)   <->  (a:A | a:B)"
   360   "(a : A Un B)   \<longleftrightarrow>  (a:A | a:B)"
   366   "(a : A Int B)  <->  (a:A & a:B)"
   361   "(a : A Int B)  \<longleftrightarrow>  (a:A \<and> a:B)"
   367   "(a : Compl(B)) <->  (~a:B)"
   362   "(a : Compl(B)) \<longleftrightarrow>  (\<not>a:B)"
   368   "(a : {b})      <->  (a=b)"
   363   "(a : {b})      \<longleftrightarrow>  (a=b)"
   369   "(a : {})       <->   False"
   364   "(a : {})       \<longleftrightarrow>   False"
   370   "(a : {x. P(x)}) <->  P(a)"
   365   "(a : {x. P(x)}) \<longleftrightarrow>  P(a)"
   371   by blast+
   366   by blast+
   372 
   367 
   373 lemmas [simp] = trivial_set empty_eq mem_rews
   368 lemmas [simp] = trivial_set empty_eq mem_rews
   374   and [cong] = ball_cong bex_cong INT_cong UN_cong
   369   and [cong] = ball_cong bex_cong INT_cong UN_cong
   375 
   370 
   388   by (blast intro: equalityI)
   383   by (blast intro: equalityI)
   389 
   384 
   390 lemma Int_Un_distrib: "(A Un B) Int C  =  (A Int C) Un (B Int C)"
   385 lemma Int_Un_distrib: "(A Un B) Int C  =  (A Int C) Un (B Int C)"
   391   by (blast intro: equalityI)
   386   by (blast intro: equalityI)
   392 
   387 
   393 lemma subset_Int_eq: "(A<=B) <-> (A Int B = A)"
   388 lemma subset_Int_eq: "(A<=B) \<longleftrightarrow> (A Int B = A)"
   394   by (blast intro: equalityI elim: equalityE)
   389   by (blast intro: equalityI elim: equalityE)
   395 
   390 
   396 
   391 
   397 subsection {* Binary Union *}
   392 subsection {* Binary Union *}
   398 
   393 
   410 
   405 
   411 lemma Un_Int_crazy:
   406 lemma Un_Int_crazy:
   412     "(A Int B) Un (B Int C) Un (C Int A) = (A Un B) Int (B Un C) Int (C Un A)"
   407     "(A Int B) Un (B Int C) Un (C Int A) = (A Un B) Int (B Un C) Int (C Un A)"
   413   by (blast intro: equalityI)
   408   by (blast intro: equalityI)
   414 
   409 
   415 lemma subset_Un_eq: "(A<=B) <-> (A Un B = B)"
   410 lemma subset_Un_eq: "(A<=B) \<longleftrightarrow> (A Un B = B)"
   416   by (blast intro: equalityI elim: equalityE)
   411   by (blast intro: equalityI elim: equalityE)
   417 
   412 
   418 
   413 
   419 subsection {* Simple properties of @{text "Compl"} -- complement of a set *}
   414 subsection {* Simple properties of @{text "Compl"} -- complement of a set *}
   420 
   415 
   438 
   433 
   439 lemma Compl_INT: "Compl(INT x:A. B(x)) = (UN x:A. Compl(B(x)))"
   434 lemma Compl_INT: "Compl(INT x:A. B(x)) = (UN x:A. Compl(B(x)))"
   440   by (blast intro: equalityI)
   435   by (blast intro: equalityI)
   441 
   436 
   442 (*Halmos, Naive Set Theory, page 16.*)
   437 (*Halmos, Naive Set Theory, page 16.*)
   443 lemma Un_Int_assoc_eq: "((A Int B) Un C = A Int (B Un C)) <-> (C<=A)"
   438 lemma Un_Int_assoc_eq: "((A Int B) Un C = A Int (B Un C)) \<longleftrightarrow> (C<=A)"
   444   by (blast intro: equalityI elim: equalityE)
   439   by (blast intro: equalityI elim: equalityE)
   445 
   440 
   446 
   441 
   447 subsection {* Big Union and Intersection *}
   442 subsection {* Big Union and Intersection *}
   448 
   443 
   449 lemma Union_Un_distrib: "Union(A Un B) = Union(A) Un Union(B)"
   444 lemma Union_Un_distrib: "Union(A Un B) = Union(A) Un Union(B)"
   450   by (blast intro: equalityI)
   445   by (blast intro: equalityI)
   451 
   446 
   452 lemma Union_disjoint:
   447 lemma Union_disjoint:
   453     "(Union(C) Int A = {x. False}) <-> (ALL B:C. B Int A = {x. False})"
   448     "(Union(C) Int A = {x. False}) \<longleftrightarrow> (ALL B:C. B Int A = {x. False})"
   454   by (blast intro: equalityI elim: equalityE)
   449   by (blast intro: equalityI elim: equalityE)
   455 
   450 
   456 lemma Inter_Un_distrib: "Inter(A Un B) = Inter(A) Int Inter(B)"
   451 lemma Inter_Un_distrib: "Inter(A Un B) = Inter(A) Int Inter(B)"
   457   by (blast intro: equalityI)
   452   by (blast intro: equalityI)
   458 
   453 
   473   by (blast intro: equalityI)
   468   by (blast intro: equalityI)
   474 
   469 
   475 
   470 
   476 section {* Monotonicity of various operations *}
   471 section {* Monotonicity of various operations *}
   477 
   472 
   478 lemma Union_mono: "A<=B ==> Union(A) <= Union(B)"
   473 lemma Union_mono: "A<=B \<Longrightarrow> Union(A) <= Union(B)"
   479   by blast
   474   by blast
   480 
   475 
   481 lemma Inter_anti_mono: "[| B<=A |] ==> Inter(A) <= Inter(B)"
   476 lemma Inter_anti_mono: "B <= A \<Longrightarrow> Inter(A) <= Inter(B)"
   482   by blast
   477   by blast
   483 
   478 
   484 lemma UN_mono:
   479 lemma UN_mono: "\<lbrakk>A <= B; \<And>x. x:A \<Longrightarrow> f(x)<=g(x)\<rbrakk> \<Longrightarrow> (UN x:A. f(x)) <= (UN x:B. g(x))"
   485   "[| A<=B;  !!x. x:A ==> f(x)<=g(x) |] ==>  
   480   by blast
   486     (UN x:A. f(x)) <= (UN x:B. g(x))"
   481 
   487   by blast
   482 lemma INT_anti_mono: "\<lbrakk>B <= A; \<And>x. x:A \<Longrightarrow> f(x) <= g(x)\<rbrakk> \<Longrightarrow> (INT x:A. f(x)) <= (INT x:A. g(x))"
   488 
   483   by blast
   489 lemma INT_anti_mono:
   484 
   490   "[| B<=A;  !!x. x:A ==> f(x)<=g(x) |] ==>  
   485 lemma Un_mono: "\<lbrakk>A <= C; B <= D\<rbrakk> \<Longrightarrow> A Un B <= C Un D"
   491     (INT x:A. f(x)) <= (INT x:A. g(x))"
   486   by blast
   492   by blast
   487 
   493 
   488 lemma Int_mono: "\<lbrakk>A <= C; B <= D\<rbrakk> \<Longrightarrow> A Int B <= C Int D"
   494 lemma Un_mono: "[| A<=C;  B<=D |] ==> A Un B <= C Un D"
   489   by blast
   495   by blast
   490 
   496 
   491 lemma Compl_anti_mono: "A <= B \<Longrightarrow> Compl(B) <= Compl(A)"
   497 lemma Int_mono: "[| A<=C;  B<=D |] ==> A Int B <= C Int D"
       
   498   by blast
       
   499 
       
   500 lemma Compl_anti_mono: "[| A<=B |] ==> Compl(B) <= Compl(A)"
       
   501   by blast
   492   by blast
   502 
   493 
   503 end
   494 end