src/ZF/func.thy
author paulson
Sun Jul 14 15:11:21 2002 +0200 (2002-07-14)
changeset 13355 d19cdbd8b559
parent 13269 3ba9be497c33
child 13357 6f54e992777e
permissions -rw-r--r--
merged Update with func
paulson@13163
     1
(*  Title:      ZF/func.thy
paulson@13163
     2
    ID:         $Id$
paulson@13163
     3
    Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
paulson@13163
     4
    Copyright   1991  University of Cambridge
paulson@13163
     5
paulson@13163
     6
*)
paulson@13163
     7
paulson@13355
     8
header{*Functions, Function Spaces, Lambda-Abstraction*}
paulson@13355
     9
paulson@13168
    10
theory func = equalities:
paulson@13163
    11
paulson@13355
    12
subsection{*The Pi Operator: Dependent Function Space*}
paulson@13355
    13
paulson@13248
    14
lemma subset_Sigma_imp_relation: "r <= Sigma(A,B) ==> relation(r)"
paulson@13248
    15
by (simp add: relation_def, blast)
paulson@13248
    16
paulson@13221
    17
lemma relation_converse_converse [simp]:
paulson@13221
    18
     "relation(r) ==> converse(converse(r)) = r"
paulson@13221
    19
by (simp add: relation_def, blast) 
paulson@13221
    20
paulson@13221
    21
lemma relation_restrict [simp]:  "relation(restrict(r,A))"
paulson@13221
    22
by (simp add: restrict_def relation_def, blast) 
paulson@13221
    23
paulson@13163
    24
lemma Pi_iff:
paulson@13163
    25
    "f: Pi(A,B) <-> function(f) & f<=Sigma(A,B) & A<=domain(f)"
paulson@13163
    26
by (unfold Pi_def, blast)
paulson@13163
    27
paulson@13163
    28
(*For upward compatibility with the former definition*)
paulson@13163
    29
lemma Pi_iff_old:
paulson@13163
    30
    "f: Pi(A,B) <-> f<=Sigma(A,B) & (ALL x:A. EX! y. <x,y>: f)"
paulson@13163
    31
by (unfold Pi_def function_def, blast)
paulson@13163
    32
paulson@13163
    33
lemma fun_is_function: "f: Pi(A,B) ==> function(f)"
paulson@13163
    34
by (simp only: Pi_iff)
paulson@13163
    35
paulson@13219
    36
lemma function_imp_Pi:
paulson@13219
    37
     "[|function(f); relation(f)|] ==> f \<in> domain(f) -> range(f)"
paulson@13219
    38
by (simp add: Pi_iff relation_def, blast) 
paulson@13219
    39
paulson@13172
    40
lemma functionI: 
paulson@13172
    41
     "[| !!x y y'. [| <x,y>:r; <x,y'>:r |] ==> y=y' |] ==> function(r)"
paulson@13172
    42
by (simp add: function_def, blast) 
paulson@13172
    43
paulson@13163
    44
(*Functions are relations*)
paulson@13163
    45
lemma fun_is_rel: "f: Pi(A,B) ==> f <= Sigma(A,B)"
paulson@13163
    46
by (unfold Pi_def, blast)
paulson@13163
    47
paulson@13163
    48
lemma Pi_cong:
paulson@13163
    49
    "[| A=A';  !!x. x:A' ==> B(x)=B'(x) |] ==> Pi(A,B) = Pi(A',B')"
paulson@13163
    50
by (simp add: Pi_def cong add: Sigma_cong)
paulson@13163
    51
paulson@13163
    52
(*Sigma_cong, Pi_cong NOT given to Addcongs: they cause
paulson@13163
    53
  flex-flex pairs and the "Check your prover" error.  Most
paulson@13163
    54
  Sigmas and Pis are abbreviated as * or -> *)
paulson@13163
    55
paulson@13163
    56
(*Weakening one function type to another; see also Pi_type*)
paulson@13163
    57
lemma fun_weaken_type: "[| f: A->B;  B<=D |] ==> f: A->D"
paulson@13163
    58
by (unfold Pi_def, best)
paulson@13163
    59
paulson@13355
    60
subsection{*Function Application*}
paulson@13163
    61
paulson@13163
    62
lemma apply_equality2: "[| <a,b>: f;  <a,c>: f;  f: Pi(A,B) |] ==> b=c"
paulson@13163
    63
by (unfold Pi_def function_def, blast)
paulson@13163
    64
paulson@13163
    65
lemma function_apply_equality: "[| <a,b>: f;  function(f) |] ==> f`a = b"
paulson@13163
    66
by (unfold apply_def function_def, blast)
paulson@13163
    67
paulson@13163
    68
lemma apply_equality: "[| <a,b>: f;  f: Pi(A,B) |] ==> f`a = b"
paulson@13163
    69
apply (unfold Pi_def)
paulson@13163
    70
apply (blast intro: function_apply_equality)
paulson@13163
    71
done
paulson@13163
    72
paulson@13163
    73
(*Applying a function outside its domain yields 0*)
paulson@13163
    74
lemma apply_0: "a ~: domain(f) ==> f`a = 0"
paulson@13176
    75
by (unfold apply_def, blast)
paulson@13163
    76
paulson@13163
    77
lemma Pi_memberD: "[| f: Pi(A,B);  c: f |] ==> EX x:A.  c = <x,f`x>"
paulson@13163
    78
apply (frule fun_is_rel)
paulson@13163
    79
apply (blast dest: apply_equality)
paulson@13163
    80
done
paulson@13163
    81
paulson@13163
    82
lemma function_apply_Pair: "[| function(f);  a : domain(f)|] ==> <a,f`a>: f"
paulson@13176
    83
apply (simp add: function_def, clarify) 
paulson@13176
    84
apply (subgoal_tac "f`a = y", blast) 
paulson@13176
    85
apply (simp add: apply_def, blast) 
paulson@13163
    86
done
paulson@13163
    87
paulson@13163
    88
lemma apply_Pair: "[| f: Pi(A,B);  a:A |] ==> <a,f`a>: f"
paulson@13163
    89
apply (simp add: Pi_iff)
paulson@13163
    90
apply (blast intro: function_apply_Pair)
paulson@13163
    91
done
paulson@13163
    92
paulson@13163
    93
(*Conclusion is flexible -- use res_inst_tac or else apply_funtype below!*)
paulson@13163
    94
lemma apply_type [TC]: "[| f: Pi(A,B);  a:A |] ==> f`a : B(a)"
paulson@13163
    95
by (blast intro: apply_Pair dest: fun_is_rel)
paulson@13163
    96
paulson@13163
    97
(*This version is acceptable to the simplifier*)
paulson@13163
    98
lemma apply_funtype: "[| f: A->B;  a:A |] ==> f`a : B"
paulson@13163
    99
by (blast dest: apply_type)
paulson@13163
   100
paulson@13163
   101
lemma apply_iff: "f: Pi(A,B) ==> <a,b>: f <-> a:A & f`a = b"
paulson@13163
   102
apply (frule fun_is_rel)
paulson@13163
   103
apply (blast intro!: apply_Pair apply_equality)
paulson@13163
   104
done
paulson@13163
   105
paulson@13163
   106
(*Refining one Pi type to another*)
paulson@13163
   107
lemma Pi_type: "[| f: Pi(A,C);  !!x. x:A ==> f`x : B(x) |] ==> f : Pi(A,B)"
paulson@13163
   108
apply (simp only: Pi_iff)
paulson@13163
   109
apply (blast dest: function_apply_equality)
paulson@13163
   110
done
paulson@13163
   111
paulson@13163
   112
(*Such functions arise in non-standard datatypes, ZF/ex/Ntree for instance*)
paulson@13163
   113
lemma Pi_Collect_iff:
paulson@13163
   114
     "(f : Pi(A, %x. {y:B(x). P(x,y)}))
paulson@13163
   115
      <->  f : Pi(A,B) & (ALL x: A. P(x, f`x))"
paulson@13163
   116
by (blast intro: Pi_type dest: apply_type)
paulson@13163
   117
paulson@13163
   118
lemma Pi_weaken_type:
paulson@13163
   119
        "[| f : Pi(A,B);  !!x. x:A ==> B(x)<=C(x) |] ==> f : Pi(A,C)"
paulson@13163
   120
by (blast intro: Pi_type dest: apply_type)
paulson@13163
   121
paulson@13163
   122
paulson@13163
   123
(** Elimination of membership in a function **)
paulson@13163
   124
paulson@13163
   125
lemma domain_type: "[| <a,b> : f;  f: Pi(A,B) |] ==> a : A"
paulson@13163
   126
by (blast dest: fun_is_rel)
paulson@13163
   127
paulson@13163
   128
lemma range_type: "[| <a,b> : f;  f: Pi(A,B) |] ==> b : B(a)"
paulson@13163
   129
by (blast dest: fun_is_rel)
paulson@13163
   130
paulson@13163
   131
lemma Pair_mem_PiD: "[| <a,b>: f;  f: Pi(A,B) |] ==> a:A & b:B(a) & f`a = b"
paulson@13163
   132
by (blast intro: domain_type range_type apply_equality)
paulson@13163
   133
paulson@13355
   134
subsection{*Lambda Abstraction*}
paulson@13163
   135
paulson@13163
   136
lemma lamI: "a:A ==> <a,b(a)> : (lam x:A. b(x))"
paulson@13163
   137
apply (unfold lam_def)
paulson@13163
   138
apply (erule RepFunI)
paulson@13163
   139
done
paulson@13163
   140
paulson@13163
   141
lemma lamE:
paulson@13163
   142
    "[| p: (lam x:A. b(x));  !!x.[| x:A; p=<x,b(x)> |] ==> P
paulson@13163
   143
     |] ==>  P"
paulson@13163
   144
by (simp add: lam_def, blast)
paulson@13163
   145
paulson@13163
   146
lemma lamD: "[| <a,c>: (lam x:A. b(x)) |] ==> c = b(a)"
paulson@13163
   147
by (simp add: lam_def)
paulson@13163
   148
paulson@13163
   149
lemma lam_type [TC]:
paulson@13163
   150
    "[| !!x. x:A ==> b(x): B(x) |] ==> (lam x:A. b(x)) : Pi(A,B)"
paulson@13163
   151
by (simp add: lam_def Pi_def function_def, blast)
paulson@13163
   152
paulson@13163
   153
lemma lam_funtype: "(lam x:A. b(x)) : A -> {b(x). x:A}"
paulson@13176
   154
by (blast intro: lam_type)
paulson@13163
   155
paulson@13172
   156
lemma function_lam: "function (lam x:A. b(x))"
paulson@13172
   157
by (simp add: function_def lam_def) 
paulson@13172
   158
paulson@13172
   159
lemma relation_lam: "relation (lam x:A. b(x))"  
paulson@13172
   160
by (simp add: relation_def lam_def) 
paulson@13172
   161
paulson@13175
   162
lemma beta_if [simp]: "(lam x:A. b(x)) ` a = (if a : A then b(a) else 0)"
paulson@13176
   163
by (simp add: apply_def lam_def, blast)
paulson@13175
   164
paulson@13175
   165
lemma beta: "a : A ==> (lam x:A. b(x)) ` a = b(a)"
paulson@13176
   166
by (simp add: apply_def lam_def, blast)
paulson@13163
   167
paulson@13163
   168
lemma lam_empty [simp]: "(lam x:0. b(x)) = 0"
paulson@13163
   169
by (simp add: lam_def)
paulson@13163
   170
paulson@13163
   171
lemma domain_lam [simp]: "domain(Lambda(A,b)) = A"
paulson@13163
   172
by (simp add: lam_def, blast)
paulson@13163
   173
paulson@13163
   174
(*congruence rule for lambda abstraction*)
paulson@13163
   175
lemma lam_cong [cong]:
paulson@13163
   176
    "[| A=A';  !!x. x:A' ==> b(x)=b'(x) |] ==> Lambda(A,b) = Lambda(A',b')"
paulson@13163
   177
by (simp only: lam_def cong add: RepFun_cong)
paulson@13163
   178
paulson@13163
   179
lemma lam_theI:
paulson@13163
   180
    "(!!x. x:A ==> EX! y. Q(x,y)) ==> EX f. ALL x:A. Q(x, f`x)"
paulson@13175
   181
apply (rule_tac x = "lam x: A. THE y. Q (x,y)" in exI)
paulson@13176
   182
apply simp 
paulson@13163
   183
apply (blast intro: theI)
paulson@13163
   184
done
paulson@13163
   185
paulson@13163
   186
lemma lam_eqE: "[| (lam x:A. f(x)) = (lam x:A. g(x));  a:A |] ==> f(a)=g(a)"
paulson@13163
   187
by (fast intro!: lamI elim: equalityE lamE)
paulson@13163
   188
paulson@13163
   189
paulson@13163
   190
(*Empty function spaces*)
paulson@13163
   191
lemma Pi_empty1 [simp]: "Pi(0,A) = {0}"
paulson@13163
   192
by (unfold Pi_def function_def, blast)
paulson@13163
   193
paulson@13163
   194
(*The singleton function*)
paulson@13163
   195
lemma singleton_fun [simp]: "{<a,b>} : {a} -> {b}"
paulson@13163
   196
by (unfold Pi_def function_def, blast)
paulson@13163
   197
paulson@13163
   198
lemma Pi_empty2 [simp]: "(A->0) = (if A=0 then {0} else 0)"
paulson@13163
   199
by (unfold Pi_def function_def, force)
paulson@13163
   200
paulson@13163
   201
lemma  fun_space_empty_iff [iff]: "(A->X)=0 \<longleftrightarrow> X=0 & (A \<noteq> 0)"
paulson@13163
   202
apply auto
paulson@13163
   203
apply (fast intro!: equals0I intro: lam_type)
paulson@13163
   204
done
paulson@13163
   205
paulson@13163
   206
paulson@13355
   207
subsection{*Extensionality*}
paulson@13163
   208
paulson@13163
   209
(*Semi-extensionality!*)
paulson@13163
   210
paulson@13163
   211
lemma fun_subset:
paulson@13163
   212
    "[| f : Pi(A,B);  g: Pi(C,D);  A<=C;
paulson@13163
   213
        !!x. x:A ==> f`x = g`x       |] ==> f<=g"
paulson@13163
   214
by (force dest: Pi_memberD intro: apply_Pair)
paulson@13163
   215
paulson@13163
   216
lemma fun_extension:
paulson@13163
   217
    "[| f : Pi(A,B);  g: Pi(A,D);
paulson@13163
   218
        !!x. x:A ==> f`x = g`x       |] ==> f=g"
paulson@13163
   219
by (blast del: subsetI intro: subset_refl sym fun_subset)
paulson@13163
   220
paulson@13163
   221
lemma eta [simp]: "f : Pi(A,B) ==> (lam x:A. f`x) = f"
paulson@13163
   222
apply (rule fun_extension)
paulson@13163
   223
apply (auto simp add: lam_type apply_type beta)
paulson@13163
   224
done
paulson@13163
   225
paulson@13163
   226
lemma fun_extension_iff:
paulson@13163
   227
     "[| f:Pi(A,B); g:Pi(A,C) |] ==> (ALL a:A. f`a = g`a) <-> f=g"
paulson@13163
   228
by (blast intro: fun_extension)
paulson@13163
   229
paulson@13163
   230
(*thm by Mark Staples, proof by lcp*)
paulson@13163
   231
lemma fun_subset_eq: "[| f:Pi(A,B); g:Pi(A,C) |] ==> f <= g <-> (f = g)"
paulson@13163
   232
by (blast dest: apply_Pair
paulson@13163
   233
	  intro: fun_extension apply_equality [symmetric])
paulson@13163
   234
paulson@13163
   235
paulson@13163
   236
(*Every element of Pi(A,B) may be expressed as a lambda abstraction!*)
paulson@13163
   237
lemma Pi_lamE:
paulson@13163
   238
  assumes major: "f: Pi(A,B)"
paulson@13163
   239
      and minor: "!!b. [| ALL x:A. b(x):B(x);  f = (lam x:A. b(x)) |] ==> P"
paulson@13163
   240
  shows "P"
paulson@13163
   241
apply (rule minor)
paulson@13163
   242
apply (rule_tac [2] eta [symmetric])
paulson@13163
   243
apply (blast intro: major apply_type)+
paulson@13163
   244
done
paulson@13163
   245
paulson@13163
   246
paulson@13355
   247
subsection{*Images of Functions*}
paulson@13163
   248
paulson@13163
   249
lemma image_lam: "C <= A ==> (lam x:A. b(x)) `` C = {b(x). x:C}"
paulson@13163
   250
by (unfold lam_def, blast)
paulson@13163
   251
paulson@13179
   252
lemma Repfun_function_if:
paulson@13179
   253
     "function(f) 
paulson@13179
   254
      ==> {f`x. x:C} = (if C <= domain(f) then f``C else cons(0,f``C))";
paulson@13179
   255
apply simp
paulson@13179
   256
apply (intro conjI impI)  
paulson@13179
   257
 apply (blast dest: function_apply_equality intro: function_apply_Pair) 
paulson@13179
   258
apply (rule equalityI)
paulson@13179
   259
 apply (blast intro!: function_apply_Pair apply_0) 
paulson@13179
   260
apply (blast dest: function_apply_equality intro: apply_0 [symmetric]) 
paulson@13179
   261
done
paulson@13179
   262
paulson@13179
   263
(*For this lemma and the next, the right-hand side could equivalently 
paulson@13179
   264
  be written UN x:C. {f`x} *)
paulson@13174
   265
lemma image_function:
paulson@13174
   266
     "[| function(f);  C <= domain(f) |] ==> f``C = {f`x. x:C}";
paulson@13179
   267
by (simp add: Repfun_function_if) 
paulson@13174
   268
paulson@13163
   269
lemma image_fun: "[| f : Pi(A,B);  C <= A |] ==> f``C = {f`x. x:C}"
paulson@13174
   270
apply (simp add: Pi_iff) 
paulson@13174
   271
apply (blast intro: image_function) 
paulson@13163
   272
done
paulson@13163
   273
paulson@13163
   274
lemma Pi_image_cons:
paulson@13163
   275
     "[| f: Pi(A,B);  x: A |] ==> f `` cons(x,y) = cons(f`x, f``y)"
paulson@13163
   276
by (blast dest: apply_equality apply_Pair)
paulson@13163
   277
clasohm@124
   278
paulson@13355
   279
subsection{*Properties of @{term "restrict(f,A)"}*}
paulson@13163
   280
paulson@13179
   281
lemma restrict_subset: "restrict(f,A) <= f"
paulson@13179
   282
by (unfold restrict_def, blast)
paulson@13163
   283
paulson@13163
   284
lemma function_restrictI:
paulson@13163
   285
    "function(f) ==> function(restrict(f,A))"
paulson@13163
   286
by (unfold restrict_def function_def, blast)
paulson@13163
   287
paulson@13163
   288
lemma restrict_type2: "[| f: Pi(C,B);  A<=C |] ==> restrict(f,A) : Pi(A,B)"
paulson@13163
   289
by (simp add: Pi_iff function_def restrict_def, blast)
paulson@13163
   290
paulson@13179
   291
lemma restrict: "restrict(f,A) ` a = (if a : A then f`a else 0)"
paulson@13176
   292
by (simp add: apply_def restrict_def, blast)
paulson@13163
   293
paulson@13163
   294
lemma restrict_empty [simp]: "restrict(f,0) = 0"
paulson@13179
   295
by (unfold restrict_def, simp)
paulson@13163
   296
paulson@13172
   297
lemma restrict_iff: "z \<in> restrict(r,A) \<longleftrightarrow> z \<in> r & (\<exists>x\<in>A. \<exists>y. z = \<langle>x, y\<rangle>)"
paulson@13172
   298
by (simp add: restrict_def) 
paulson@13172
   299
paulson@13163
   300
lemma restrict_restrict [simp]:
paulson@13163
   301
     "restrict(restrict(r,A),B) = restrict(r, A Int B)"
paulson@13163
   302
by (unfold restrict_def, blast)
paulson@13163
   303
paulson@13163
   304
lemma domain_restrict [simp]: "domain(restrict(f,C)) = domain(f) Int C"
paulson@13163
   305
apply (unfold restrict_def)
paulson@13163
   306
apply (auto simp add: domain_def)
paulson@13163
   307
done
paulson@13163
   308
paulson@13248
   309
lemma restrict_idem: "f <= Sigma(A,B) ==> restrict(f,A) = f"
paulson@13163
   310
by (simp add: restrict_def, blast)
paulson@13163
   311
paulson@13248
   312
paulson@13248
   313
(*converse probably holds too*)
paulson@13248
   314
lemma domain_restrict_idem:
paulson@13248
   315
     "[| domain(r) <= A; relation(r) |] ==> restrict(r,A) = r"
paulson@13248
   316
by (simp add: restrict_def relation_def, blast)
paulson@13248
   317
paulson@13248
   318
lemma domain_restrict_lam [simp]: "domain(restrict(Lambda(A,f),C)) = A Int C"
paulson@13248
   319
apply (unfold restrict_def lam_def)
paulson@13248
   320
apply (rule equalityI)
paulson@13248
   321
apply (auto simp add: domain_iff)
paulson@13248
   322
done
paulson@13248
   323
paulson@13163
   324
lemma restrict_if [simp]: "restrict(f,A) ` a = (if a : A then f`a else 0)"
paulson@13163
   325
by (simp add: restrict apply_0)
paulson@13163
   326
paulson@13163
   327
lemma restrict_lam_eq:
paulson@13163
   328
    "A<=C ==> restrict(lam x:C. b(x), A) = (lam x:A. b(x))"
paulson@13163
   329
by (unfold restrict_def lam_def, auto)
paulson@13163
   330
paulson@13163
   331
lemma fun_cons_restrict_eq:
paulson@13163
   332
     "f : cons(a, b) -> B ==> f = cons(<a, f ` a>, restrict(f, b))"
paulson@13163
   333
apply (rule equalityI)
paulson@13248
   334
 prefer 2 apply (blast intro: apply_Pair restrict_subset [THEN subsetD])
paulson@13163
   335
apply (auto dest!: Pi_memberD simp add: restrict_def lam_def)
paulson@13163
   336
done
paulson@13163
   337
paulson@13163
   338
paulson@13355
   339
subsection{*Unions of Functions*}
paulson@13163
   340
paulson@13163
   341
(** The Union of a set of COMPATIBLE functions is a function **)
paulson@13163
   342
paulson@13163
   343
lemma function_Union:
paulson@13163
   344
    "[| ALL x:S. function(x);
paulson@13163
   345
        ALL x:S. ALL y:S. x<=y | y<=x  |]
paulson@13163
   346
     ==> function(Union(S))"
paulson@13163
   347
by (unfold function_def, blast) 
paulson@13163
   348
paulson@13163
   349
lemma fun_Union:
paulson@13163
   350
    "[| ALL f:S. EX C D. f:C->D;
paulson@13163
   351
             ALL f:S. ALL y:S. f<=y | y<=f  |] ==>
paulson@13163
   352
          Union(S) : domain(Union(S)) -> range(Union(S))"
paulson@13163
   353
apply (unfold Pi_def)
paulson@13163
   354
apply (blast intro!: rel_Union function_Union)
paulson@13163
   355
done
paulson@13163
   356
paulson@13174
   357
lemma gen_relation_Union [rule_format]:
paulson@13174
   358
     "\<forall>f\<in>F. relation(f) \<Longrightarrow> relation(Union(F))"
paulson@13174
   359
by (simp add: relation_def) 
paulson@13174
   360
paulson@13163
   361
paulson@13163
   362
(** The Union of 2 disjoint functions is a function **)
paulson@13163
   363
paulson@13163
   364
lemmas Un_rls = Un_subset_iff SUM_Un_distrib1 prod_Un_distrib2
paulson@13163
   365
                subset_trans [OF _ Un_upper1]
paulson@13163
   366
                subset_trans [OF _ Un_upper2]
paulson@13163
   367
paulson@13163
   368
lemma fun_disjoint_Un:
paulson@13163
   369
     "[| f: A->B;  g: C->D;  A Int C = 0  |]
paulson@13163
   370
      ==> (f Un g) : (A Un C) -> (B Un D)"
paulson@13163
   371
(*Prove the product and domain subgoals using distributive laws*)
paulson@13163
   372
apply (simp add: Pi_iff extension Un_rls)
paulson@13163
   373
apply (unfold function_def, blast)
paulson@13163
   374
done
paulson@13163
   375
paulson@13179
   376
lemma fun_disjoint_apply1: "a \<notin> domain(g) ==> (f Un g)`a = f`a"
paulson@13179
   377
by (simp add: apply_def, blast) 
paulson@13163
   378
paulson@13179
   379
lemma fun_disjoint_apply2: "c \<notin> domain(f) ==> (f Un g)`c = g`c"
paulson@13179
   380
by (simp add: apply_def, blast) 
paulson@13163
   381
paulson@13355
   382
subsection{*Domain and Range of a Function or Relation*}
paulson@13163
   383
paulson@13163
   384
lemma domain_of_fun: "f : Pi(A,B) ==> domain(f)=A"
paulson@13163
   385
by (unfold Pi_def, blast)
paulson@13163
   386
paulson@13163
   387
lemma apply_rangeI: "[| f : Pi(A,B);  a: A |] ==> f`a : range(f)"
paulson@13163
   388
by (erule apply_Pair [THEN rangeI], assumption)
paulson@13163
   389
paulson@13163
   390
lemma range_of_fun: "f : Pi(A,B) ==> f : A->range(f)"
paulson@13163
   391
by (blast intro: Pi_type apply_rangeI)
paulson@13163
   392
paulson@13355
   393
subsection{*Extensions of Functions*}
paulson@13163
   394
paulson@13163
   395
lemma fun_extend:
paulson@13163
   396
     "[| f: A->B;  c~:A |] ==> cons(<c,b>,f) : cons(c,A) -> cons(b,B)"
paulson@13163
   397
apply (frule singleton_fun [THEN fun_disjoint_Un], blast)
paulson@13163
   398
apply (simp add: cons_eq) 
paulson@13163
   399
done
paulson@13163
   400
paulson@13163
   401
lemma fun_extend3:
paulson@13163
   402
     "[| f: A->B;  c~:A;  b: B |] ==> cons(<c,b>,f) : cons(c,A) -> B"
paulson@13163
   403
by (blast intro: fun_extend [THEN fun_weaken_type])
paulson@13163
   404
paulson@13176
   405
lemma extend_apply:
paulson@13176
   406
     "c ~: domain(f) ==> cons(<c,b>,f)`a = (if a=c then b else f`a)"
paulson@13176
   407
by (auto simp add: apply_def) 
paulson@13163
   408
paulson@13176
   409
lemma fun_extend_apply [simp]:
paulson@13176
   410
     "[| f: A->B;  c~:A |] ==> cons(<c,b>,f)`a = (if a=c then b else f`a)" 
paulson@13176
   411
apply (rule extend_apply) 
paulson@13176
   412
apply (simp add: Pi_def, blast) 
paulson@13163
   413
done
paulson@13163
   414
paulson@13163
   415
lemmas singleton_apply = apply_equality [OF singletonI singleton_fun, simp]
paulson@13163
   416
paulson@13163
   417
(*For Finite.ML.  Inclusion of right into left is easy*)
paulson@13163
   418
lemma cons_fun_eq:
paulson@13269
   419
     "c ~: A ==> cons(c,A) -> B = (\<Union>f \<in> A->B. \<Union>b\<in>B. {cons(<c,b>, f)})"
paulson@13163
   420
apply (rule equalityI)
paulson@13163
   421
apply (safe elim!: fun_extend3)
paulson@13163
   422
(*Inclusion of left into right*)
paulson@13163
   423
apply (subgoal_tac "restrict (x, A) : A -> B")
paulson@13163
   424
 prefer 2 apply (blast intro: restrict_type2)
paulson@13163
   425
apply (rule UN_I, assumption)
paulson@13163
   426
apply (rule apply_funtype [THEN UN_I]) 
paulson@13163
   427
  apply assumption
paulson@13163
   428
 apply (rule consI1) 
paulson@13163
   429
apply (simp (no_asm))
paulson@13163
   430
apply (rule fun_extension) 
paulson@13163
   431
  apply assumption
paulson@13163
   432
 apply (blast intro: fun_extend) 
paulson@13176
   433
apply (erule consE, simp_all)
paulson@13163
   434
done
paulson@13163
   435
paulson@13269
   436
lemma succ_fun_eq: "succ(n) -> B = (\<Union>f \<in> n->B. \<Union>b\<in>B. {cons(<n,b>, f)})"
paulson@13269
   437
by (simp add: succ_def mem_not_refl cons_fun_eq)
paulson@13269
   438
paulson@13355
   439
paulson@13355
   440
subsection{*Function Updates*}
paulson@13355
   441
paulson@13355
   442
constdefs
paulson@13355
   443
  update  :: "[i,i,i] => i"
paulson@13355
   444
   "update(f,a,b) == lam x: cons(a, domain(f)). if(x=a, b, f`x)"
paulson@13355
   445
paulson@13355
   446
nonterminals
paulson@13355
   447
  updbinds  updbind
paulson@13355
   448
paulson@13355
   449
syntax
paulson@13355
   450
paulson@13355
   451
  (* Let expressions *)
paulson@13355
   452
paulson@13355
   453
  "_updbind"    :: "[i, i] => updbind"               ("(2_ :=/ _)")
paulson@13355
   454
  ""            :: "updbind => updbinds"             ("_")
paulson@13355
   455
  "_updbinds"   :: "[updbind, updbinds] => updbinds" ("_,/ _")
paulson@13355
   456
  "_Update"     :: "[i, updbinds] => i"              ("_/'((_)')" [900,0] 900)
paulson@13355
   457
paulson@13355
   458
translations
paulson@13355
   459
  "_Update (f, _updbinds(b,bs))"  == "_Update (_Update(f,b), bs)"
paulson@13355
   460
  "f(x:=y)"                       == "update(f,x,y)"
paulson@13355
   461
paulson@13355
   462
paulson@13355
   463
lemma update_apply [simp]: "f(x:=y) ` z = (if z=x then y else f`z)"
paulson@13355
   464
apply (simp add: update_def)
paulson@13355
   465
apply (rule_tac P="z \<in> domain(f)" in case_split_thm)   
paulson@13355
   466
apply (simp_all add: apply_0)
paulson@13355
   467
done
paulson@13355
   468
paulson@13355
   469
lemma update_idem: "[| f`x = y;  f: Pi(A,B);  x: A |] ==> f(x:=y) = f"
paulson@13355
   470
apply (unfold update_def)
paulson@13355
   471
apply (simp add: domain_of_fun cons_absorb)
paulson@13355
   472
apply (rule fun_extension)
paulson@13355
   473
apply (best intro: apply_type if_type lam_type, assumption, simp)
paulson@13355
   474
done
paulson@13355
   475
paulson@13355
   476
paulson@13355
   477
(* [| f: Pi(A, B); x:A |] ==> f(x := f`x) = f *)
paulson@13355
   478
declare refl [THEN update_idem, simp]
paulson@13355
   479
paulson@13355
   480
lemma domain_update [simp]: "domain(f(x:=y)) = cons(x, domain(f))"
paulson@13355
   481
by (unfold update_def, simp)
paulson@13355
   482
paulson@13355
   483
lemma update_type: "[| f: A -> B;  x : A;  y: B |] ==> f(x:=y) : A -> B"
paulson@13355
   484
apply (unfold update_def)
paulson@13355
   485
apply (simp add: domain_of_fun cons_absorb apply_funtype lam_type)
paulson@13355
   486
done
paulson@13355
   487
paulson@13355
   488
paulson@13163
   489
ML
paulson@13163
   490
{*
paulson@13163
   491
val Pi_iff = thm "Pi_iff";
paulson@13163
   492
val Pi_iff_old = thm "Pi_iff_old";
paulson@13163
   493
val fun_is_function = thm "fun_is_function";
paulson@13163
   494
val fun_is_rel = thm "fun_is_rel";
paulson@13163
   495
val Pi_cong = thm "Pi_cong";
paulson@13163
   496
val fun_weaken_type = thm "fun_weaken_type";
paulson@13163
   497
val apply_equality2 = thm "apply_equality2";
paulson@13163
   498
val function_apply_equality = thm "function_apply_equality";
paulson@13163
   499
val apply_equality = thm "apply_equality";
paulson@13163
   500
val apply_0 = thm "apply_0";
paulson@13163
   501
val Pi_memberD = thm "Pi_memberD";
paulson@13163
   502
val function_apply_Pair = thm "function_apply_Pair";
paulson@13163
   503
val apply_Pair = thm "apply_Pair";
paulson@13163
   504
val apply_type = thm "apply_type";
paulson@13163
   505
val apply_funtype = thm "apply_funtype";
paulson@13163
   506
val apply_iff = thm "apply_iff";
paulson@13163
   507
val Pi_type = thm "Pi_type";
paulson@13163
   508
val Pi_Collect_iff = thm "Pi_Collect_iff";
paulson@13163
   509
val Pi_weaken_type = thm "Pi_weaken_type";
paulson@13163
   510
val domain_type = thm "domain_type";
paulson@13163
   511
val range_type = thm "range_type";
paulson@13163
   512
val Pair_mem_PiD = thm "Pair_mem_PiD";
paulson@13163
   513
val lamI = thm "lamI";
paulson@13163
   514
val lamE = thm "lamE";
paulson@13163
   515
val lamD = thm "lamD";
paulson@13163
   516
val lam_type = thm "lam_type";
paulson@13163
   517
val lam_funtype = thm "lam_funtype";
paulson@13163
   518
val beta = thm "beta";
paulson@13163
   519
val lam_empty = thm "lam_empty";
paulson@13163
   520
val domain_lam = thm "domain_lam";
paulson@13163
   521
val lam_cong = thm "lam_cong";
paulson@13163
   522
val lam_theI = thm "lam_theI";
paulson@13163
   523
val lam_eqE = thm "lam_eqE";
paulson@13163
   524
val Pi_empty1 = thm "Pi_empty1";
paulson@13163
   525
val singleton_fun = thm "singleton_fun";
paulson@13163
   526
val Pi_empty2 = thm "Pi_empty2";
paulson@13163
   527
val fun_space_empty_iff = thm "fun_space_empty_iff";
paulson@13163
   528
val fun_subset = thm "fun_subset";
paulson@13163
   529
val fun_extension = thm "fun_extension";
paulson@13163
   530
val eta = thm "eta";
paulson@13163
   531
val fun_extension_iff = thm "fun_extension_iff";
paulson@13163
   532
val fun_subset_eq = thm "fun_subset_eq";
paulson@13163
   533
val Pi_lamE = thm "Pi_lamE";
paulson@13163
   534
val image_lam = thm "image_lam";
paulson@13163
   535
val image_fun = thm "image_fun";
paulson@13163
   536
val Pi_image_cons = thm "Pi_image_cons";
paulson@13163
   537
val restrict_subset = thm "restrict_subset";
paulson@13163
   538
val function_restrictI = thm "function_restrictI";
paulson@13163
   539
val restrict_type2 = thm "restrict_type2";
paulson@13163
   540
val restrict = thm "restrict";
paulson@13163
   541
val restrict_empty = thm "restrict_empty";
paulson@13163
   542
val domain_restrict_lam = thm "domain_restrict_lam";
paulson@13163
   543
val restrict_restrict = thm "restrict_restrict";
paulson@13163
   544
val domain_restrict = thm "domain_restrict";
paulson@13163
   545
val restrict_idem = thm "restrict_idem";
paulson@13163
   546
val restrict_if = thm "restrict_if";
paulson@13163
   547
val restrict_lam_eq = thm "restrict_lam_eq";
paulson@13163
   548
val fun_cons_restrict_eq = thm "fun_cons_restrict_eq";
paulson@13163
   549
val function_Union = thm "function_Union";
paulson@13163
   550
val fun_Union = thm "fun_Union";
paulson@13163
   551
val fun_disjoint_Un = thm "fun_disjoint_Un";
paulson@13163
   552
val fun_disjoint_apply1 = thm "fun_disjoint_apply1";
paulson@13163
   553
val fun_disjoint_apply2 = thm "fun_disjoint_apply2";
paulson@13163
   554
val domain_of_fun = thm "domain_of_fun";
paulson@13163
   555
val apply_rangeI = thm "apply_rangeI";
paulson@13163
   556
val range_of_fun = thm "range_of_fun";
paulson@13163
   557
val fun_extend = thm "fun_extend";
paulson@13163
   558
val fun_extend3 = thm "fun_extend3";
paulson@13176
   559
val fun_extend_apply = thm "fun_extend_apply";
paulson@13163
   560
val singleton_apply = thm "singleton_apply";
paulson@13163
   561
val cons_fun_eq = thm "cons_fun_eq";
paulson@13355
   562
paulson@13355
   563
val update_def = thm "update_def";
paulson@13355
   564
val update_apply = thm "update_apply";
paulson@13355
   565
val update_idem = thm "update_idem";
paulson@13355
   566
val domain_update = thm "domain_update";
paulson@13355
   567
val update_type = thm "update_type";
paulson@13163
   568
*}
paulson@13163
   569
paulson@13163
   570
end