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