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