src/HOL/Library/FuncSet.thy
author wenzelm
Tue May 02 20:42:32 2006 +0200 (2006-05-02)
changeset 19536 1a3a3cf8b4fa
parent 17781 32bb237158a5
child 19656 09be06943252
permissions -rw-r--r--
replaced syntax/translations by abbreviation;
     1 (*  Title:      HOL/Library/FuncSet.thy
     2     ID:         $Id$
     3     Author:     Florian Kammueller and Lawrence C Paulson
     4 *)
     5 
     6 header {* Pi and Function Sets *}
     7 
     8 theory FuncSet
     9 imports Main
    10 begin
    11 
    12 constdefs
    13   Pi :: "['a set, 'a => 'b set] => ('a => 'b) set"
    14   "Pi A B == {f. \<forall>x. x \<in> A --> f x \<in> B x}"
    15 
    16   extensional :: "'a set => ('a => 'b) set"
    17   "extensional A == {f. \<forall>x. x~:A --> f x = arbitrary}"
    18 
    19   "restrict" :: "['a => 'b, 'a set] => ('a => 'b)"
    20   "restrict f A == (%x. if x \<in> A then f x else arbitrary)"
    21 
    22 abbreviation
    23   funcset :: "['a set, 'b set] => ('a => 'b) set"      (infixr "->" 60)
    24   "A -> B == Pi A (%_. B)"
    25 
    26 abbreviation (xsymbols)
    27   funcset1  (infixr "\<rightarrow>" 60)
    28   "funcset1 == funcset"
    29 
    30 syntax
    31   "@Pi"  :: "[pttrn, 'a set, 'b set] => ('a => 'b) set"  ("(3PI _:_./ _)" 10)
    32   "@lam" :: "[pttrn, 'a set, 'a => 'b] => ('a=>'b)"  ("(3%_:_./ _)" [0,0,3] 3)
    33 
    34 syntax (xsymbols)
    35   "@Pi" :: "[pttrn, 'a set, 'b set] => ('a => 'b) set"  ("(3\<Pi> _\<in>_./ _)"   10)
    36   "@lam" :: "[pttrn, 'a set, 'a => 'b] => ('a=>'b)"  ("(3\<lambda>_\<in>_./ _)" [0,0,3] 3)
    37 
    38 syntax (HTML output)
    39   "@Pi" :: "[pttrn, 'a set, 'b set] => ('a => 'b) set"  ("(3\<Pi> _\<in>_./ _)"   10)
    40   "@lam" :: "[pttrn, 'a set, 'a => 'b] => ('a=>'b)"  ("(3\<lambda>_\<in>_./ _)" [0,0,3] 3)
    41 
    42 translations
    43   "PI x:A. B" == "Pi A (%x. B)"
    44   "%x:A. f" == "restrict (%x. f) A"
    45 
    46 constdefs
    47   "compose" :: "['a set, 'b => 'c, 'a => 'b] => ('a => 'c)"
    48   "compose A g f == \<lambda>x\<in>A. g (f x)"
    49 
    50 
    51 subsection{*Basic Properties of @{term Pi}*}
    52 
    53 lemma Pi_I: "(!!x. x \<in> A ==> f x \<in> B x) ==> f \<in> Pi A B"
    54   by (simp add: Pi_def)
    55 
    56 lemma funcsetI: "(!!x. x \<in> A ==> f x \<in> B) ==> f \<in> A -> B"
    57   by (simp add: Pi_def)
    58 
    59 lemma Pi_mem: "[|f: Pi A B; x \<in> A|] ==> f x \<in> B x"
    60   by (simp add: Pi_def)
    61 
    62 lemma funcset_mem: "[|f \<in> A -> B; x \<in> A|] ==> f x \<in> B"
    63   by (simp add: Pi_def)
    64 
    65 lemma funcset_image: "f \<in> A\<rightarrow>B ==> f ` A \<subseteq> B"
    66 by (auto simp add: Pi_def)
    67 
    68 lemma Pi_eq_empty: "((PI x: A. B x) = {}) = (\<exists>x\<in>A. B(x) = {})"
    69 apply (simp add: Pi_def, auto)
    70 txt{*Converse direction requires Axiom of Choice to exhibit a function
    71 picking an element from each non-empty @{term "B x"}*}
    72 apply (drule_tac x = "%u. SOME y. y \<in> B u" in spec, auto)
    73 apply (cut_tac P= "%y. y \<in> B x" in some_eq_ex, auto)
    74 done
    75 
    76 lemma Pi_empty [simp]: "Pi {} B = UNIV"
    77   by (simp add: Pi_def)
    78 
    79 lemma Pi_UNIV [simp]: "A -> UNIV = UNIV"
    80   by (simp add: Pi_def)
    81 
    82 text{*Covariance of Pi-sets in their second argument*}
    83 lemma Pi_mono: "(!!x. x \<in> A ==> B x <= C x) ==> Pi A B <= Pi A C"
    84   by (simp add: Pi_def, blast)
    85 
    86 text{*Contravariance of Pi-sets in their first argument*}
    87 lemma Pi_anti_mono: "A' <= A ==> Pi A B <= Pi A' B"
    88   by (simp add: Pi_def, blast)
    89 
    90 
    91 subsection{*Composition With a Restricted Domain: @{term compose}*}
    92 
    93 lemma funcset_compose:
    94     "[| f \<in> A -> B; g \<in> B -> C |]==> compose A g f \<in> A -> C"
    95   by (simp add: Pi_def compose_def restrict_def)
    96 
    97 lemma compose_assoc:
    98     "[| f \<in> A -> B; g \<in> B -> C; h \<in> C -> D |]
    99       ==> compose A h (compose A g f) = compose A (compose B h g) f"
   100   by (simp add: expand_fun_eq Pi_def compose_def restrict_def)
   101 
   102 lemma compose_eq: "x \<in> A ==> compose A g f x = g(f(x))"
   103   by (simp add: compose_def restrict_def)
   104 
   105 lemma surj_compose: "[| f ` A = B; g ` B = C |] ==> compose A g f ` A = C"
   106   by (auto simp add: image_def compose_eq)
   107 
   108 
   109 subsection{*Bounded Abstraction: @{term restrict}*}
   110 
   111 lemma restrict_in_funcset: "(!!x. x \<in> A ==> f x \<in> B) ==> (\<lambda>x\<in>A. f x) \<in> A -> B"
   112   by (simp add: Pi_def restrict_def)
   113 
   114 lemma restrictI: "(!!x. x \<in> A ==> f x \<in> B x) ==> (\<lambda>x\<in>A. f x) \<in> Pi A B"
   115   by (simp add: Pi_def restrict_def)
   116 
   117 lemma restrict_apply [simp]:
   118     "(\<lambda>y\<in>A. f y) x = (if x \<in> A then f x else arbitrary)"
   119   by (simp add: restrict_def)
   120 
   121 lemma restrict_ext:
   122     "(!!x. x \<in> A ==> f x = g x) ==> (\<lambda>x\<in>A. f x) = (\<lambda>x\<in>A. g x)"
   123   by (simp add: expand_fun_eq Pi_def Pi_def restrict_def)
   124 
   125 lemma inj_on_restrict_eq [simp]: "inj_on (restrict f A) A = inj_on f A"
   126   by (simp add: inj_on_def restrict_def)
   127 
   128 lemma Id_compose:
   129     "[|f \<in> A -> B;  f \<in> extensional A|] ==> compose A (\<lambda>y\<in>B. y) f = f"
   130   by (auto simp add: expand_fun_eq compose_def extensional_def Pi_def)
   131 
   132 lemma compose_Id:
   133     "[|g \<in> A -> B;  g \<in> extensional A|] ==> compose A g (\<lambda>x\<in>A. x) = g"
   134   by (auto simp add: expand_fun_eq compose_def extensional_def Pi_def)
   135 
   136 lemma image_restrict_eq [simp]: "(restrict f A) ` A = f ` A"
   137   by (auto simp add: restrict_def) 
   138 
   139 
   140 subsection{*Bijections Between Sets*}
   141 
   142 text{*The basic definition could be moved to @{text "Fun.thy"}, but most of
   143 the theorems belong here, or need at least @{term Hilbert_Choice}.*}
   144 
   145 constdefs
   146   bij_betw :: "['a => 'b, 'a set, 'b set] => bool"         (*bijective*)
   147     "bij_betw f A B == inj_on f A & f ` A = B"
   148 
   149 lemma bij_betw_imp_inj_on: "bij_betw f A B \<Longrightarrow> inj_on f A"
   150 by (simp add: bij_betw_def)
   151 
   152 lemma bij_betw_imp_funcset: "bij_betw f A B \<Longrightarrow> f \<in> A \<rightarrow> B"
   153 by (auto simp add: bij_betw_def inj_on_Inv Pi_def)
   154 
   155 lemma bij_betw_Inv: "bij_betw f A B \<Longrightarrow> bij_betw (Inv A f) B A"
   156 apply (auto simp add: bij_betw_def inj_on_Inv Inv_mem) 
   157 apply (simp add: image_compose [symmetric] o_def) 
   158 apply (simp add: image_def Inv_f_f) 
   159 done
   160 
   161 lemma inj_on_compose:
   162     "[| bij_betw f A B; inj_on g B |] ==> inj_on (compose A g f) A"
   163   by (auto simp add: bij_betw_def inj_on_def compose_eq)
   164 
   165 lemma bij_betw_compose:
   166     "[| bij_betw f A B; bij_betw g B C |] ==> bij_betw (compose A g f) A C"
   167 apply (simp add: bij_betw_def compose_eq inj_on_compose)
   168 apply (auto simp add: compose_def image_def)
   169 done
   170 
   171 lemma bij_betw_restrict_eq [simp]:
   172      "bij_betw (restrict f A) A B = bij_betw f A B"
   173   by (simp add: bij_betw_def)
   174 
   175 
   176 subsection{*Extensionality*}
   177 
   178 lemma extensional_arb: "[|f \<in> extensional A; x\<notin> A|] ==> f x = arbitrary"
   179   by (simp add: extensional_def)
   180 
   181 lemma restrict_extensional [simp]: "restrict f A \<in> extensional A"
   182   by (simp add: restrict_def extensional_def)
   183 
   184 lemma compose_extensional [simp]: "compose A f g \<in> extensional A"
   185   by (simp add: compose_def)
   186 
   187 lemma extensionalityI:
   188     "[| f \<in> extensional A; g \<in> extensional A;
   189       !!x. x\<in>A ==> f x = g x |] ==> f = g"
   190   by (force simp add: expand_fun_eq extensional_def)
   191 
   192 lemma Inv_funcset: "f ` A = B ==> (\<lambda>x\<in>B. Inv A f x) : B -> A"
   193   by (unfold Inv_def) (fast intro: restrict_in_funcset someI2)
   194 
   195 lemma compose_Inv_id:
   196     "bij_betw f A B ==> compose A (\<lambda>y\<in>B. Inv A f y) f = (\<lambda>x\<in>A. x)"
   197   apply (simp add: bij_betw_def compose_def)
   198   apply (rule restrict_ext, auto)
   199   apply (erule subst)
   200   apply (simp add: Inv_f_f)
   201   done
   202 
   203 lemma compose_id_Inv:
   204     "f ` A = B ==> compose B f (\<lambda>y\<in>B. Inv A f y) = (\<lambda>x\<in>B. x)"
   205   apply (simp add: compose_def)
   206   apply (rule restrict_ext)
   207   apply (simp add: f_Inv_f)
   208   done
   209 
   210 
   211 subsection{*Cardinality*}
   212 
   213 lemma card_inj: "[|f \<in> A\<rightarrow>B; inj_on f A; finite B|] ==> card(A) \<le> card(B)"
   214 apply (rule card_inj_on_le)
   215 apply (auto simp add: Pi_def)
   216 done
   217 
   218 lemma card_bij:
   219      "[|f \<in> A\<rightarrow>B; inj_on f A;
   220         g \<in> B\<rightarrow>A; inj_on g B; finite A; finite B|] ==> card(A) = card(B)"
   221 by (blast intro: card_inj order_antisym)
   222 
   223 end