src/ZF/OrderArith.thy
author paulson
Wed Aug 28 13:08:50 2002 +0200 (2002-08-28)
changeset 13544 895994073bdf
parent 13512 80edb859fd24
child 13634 99a593b49b04
permissions -rw-r--r--
various new lemmas for Constructible
clasohm@1478
     1
(*  Title:      ZF/OrderArith.thy
lcp@437
     2
    ID:         $Id$
clasohm@1478
     3
    Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
lcp@437
     4
    Copyright   1994  University of Cambridge
lcp@437
     5
lcp@437
     6
*)
lcp@437
     7
paulson@13356
     8
header{*Combining Orderings: Foundations of Ordinal Arithmetic*}
paulson@13356
     9
paulson@13140
    10
theory OrderArith = Order + Sum + Ordinal:
paulson@13140
    11
constdefs
lcp@437
    12
lcp@437
    13
  (*disjoint sum of two relations; underlies ordinal addition*)
paulson@13140
    14
  radd    :: "[i,i,i,i]=>i"
paulson@13140
    15
    "radd(A,r,B,s) == 
clasohm@1155
    16
                {z: (A+B) * (A+B).  
clasohm@1478
    17
                    (EX x y. z = <Inl(x), Inr(y)>)   |   
clasohm@1478
    18
                    (EX x' x. z = <Inl(x'), Inl(x)> & <x',x>:r)   |      
clasohm@1155
    19
                    (EX y' y. z = <Inr(y'), Inr(y)> & <y',y>:s)}"
lcp@437
    20
lcp@437
    21
  (*lexicographic product of two relations; underlies ordinal multiplication*)
paulson@13140
    22
  rmult   :: "[i,i,i,i]=>i"
paulson@13140
    23
    "rmult(A,r,B,s) == 
clasohm@1155
    24
                {z: (A*B) * (A*B).  
clasohm@1478
    25
                    EX x' y' x y. z = <<x',y'>, <x,y>> &         
clasohm@1155
    26
                       (<x',x>: r | (x'=x & <y',y>: s))}"
lcp@437
    27
lcp@437
    28
  (*inverse image of a relation*)
paulson@13140
    29
  rvimage :: "[i,i,i]=>i"
paulson@13140
    30
    "rvimage(A,f,r) == {z: A*A. EX x y. z = <x,y> & <f`x,f`y>: r}"
paulson@13140
    31
paulson@13140
    32
  measure :: "[i, i\<Rightarrow>i] \<Rightarrow> i"
paulson@13140
    33
    "measure(A,f) == {<x,y>: A*A. f(x) < f(y)}"
paulson@13140
    34
paulson@13140
    35
paulson@13356
    36
subsection{*Addition of Relations -- Disjoint Sum*}
paulson@13140
    37
paulson@13512
    38
subsubsection{*Rewrite rules.  Can be used to obtain introduction rules*}
paulson@13140
    39
paulson@13140
    40
lemma radd_Inl_Inr_iff [iff]: 
paulson@13140
    41
    "<Inl(a), Inr(b)> : radd(A,r,B,s)  <->  a:A & b:B"
paulson@13356
    42
by (unfold radd_def, blast)
paulson@13140
    43
paulson@13140
    44
lemma radd_Inl_iff [iff]: 
paulson@13140
    45
    "<Inl(a'), Inl(a)> : radd(A,r,B,s)  <->  a':A & a:A & <a',a>:r"
paulson@13356
    46
by (unfold radd_def, blast)
paulson@13140
    47
paulson@13140
    48
lemma radd_Inr_iff [iff]: 
paulson@13140
    49
    "<Inr(b'), Inr(b)> : radd(A,r,B,s) <->  b':B & b:B & <b',b>:s"
paulson@13356
    50
by (unfold radd_def, blast)
paulson@13140
    51
paulson@13140
    52
lemma radd_Inr_Inl_iff [iff]: 
paulson@13140
    53
    "<Inr(b), Inl(a)> : radd(A,r,B,s) <->  False"
paulson@13356
    54
by (unfold radd_def, blast)
paulson@13140
    55
paulson@13512
    56
subsubsection{*Elimination Rule*}
paulson@13140
    57
paulson@13140
    58
lemma raddE:
paulson@13140
    59
    "[| <p',p> : radd(A,r,B,s);                  
paulson@13140
    60
        !!x y. [| p'=Inl(x); x:A; p=Inr(y); y:B |] ==> Q;        
paulson@13140
    61
        !!x' x. [| p'=Inl(x'); p=Inl(x); <x',x>: r; x':A; x:A |] ==> Q;  
paulson@13140
    62
        !!y' y. [| p'=Inr(y'); p=Inr(y); <y',y>: s; y':B; y:B |] ==> Q   
paulson@13140
    63
     |] ==> Q"
paulson@13356
    64
by (unfold radd_def, blast) 
paulson@13140
    65
paulson@13512
    66
subsubsection{*Type checking*}
paulson@13140
    67
paulson@13140
    68
lemma radd_type: "radd(A,r,B,s) <= (A+B) * (A+B)"
paulson@13140
    69
apply (unfold radd_def)
paulson@13140
    70
apply (rule Collect_subset)
paulson@13140
    71
done
paulson@13140
    72
paulson@13140
    73
lemmas field_radd = radd_type [THEN field_rel_subset]
paulson@13140
    74
paulson@13512
    75
subsubsection{*Linearity*}
paulson@13140
    76
paulson@13140
    77
lemma linear_radd: 
paulson@13140
    78
    "[| linear(A,r);  linear(B,s) |] ==> linear(A+B,radd(A,r,B,s))"
paulson@13356
    79
by (unfold linear_def, blast) 
paulson@13140
    80
paulson@13140
    81
paulson@13512
    82
subsubsection{*Well-foundedness*}
paulson@13140
    83
paulson@13140
    84
lemma wf_on_radd: "[| wf[A](r);  wf[B](s) |] ==> wf[A+B](radd(A,r,B,s))"
paulson@13140
    85
apply (rule wf_onI2)
paulson@13140
    86
apply (subgoal_tac "ALL x:A. Inl (x) : Ba")
paulson@13512
    87
 --{*Proving the lemma, which is needed twice!*}
paulson@13140
    88
 prefer 2
paulson@13140
    89
 apply (erule_tac V = "y : A + B" in thin_rl)
paulson@13140
    90
 apply (rule_tac ballI)
paulson@13140
    91
 apply (erule_tac r = "r" and a = "x" in wf_on_induct, assumption)
paulson@13269
    92
 apply blast 
paulson@13512
    93
txt{*Returning to main part of proof*}
paulson@13140
    94
apply safe
paulson@13140
    95
apply blast
paulson@13269
    96
apply (erule_tac r = "s" and a = "ya" in wf_on_induct, assumption, blast) 
paulson@13140
    97
done
paulson@13140
    98
paulson@13140
    99
lemma wf_radd: "[| wf(r);  wf(s) |] ==> wf(radd(field(r),r,field(s),s))"
paulson@13140
   100
apply (simp add: wf_iff_wf_on_field)
paulson@13140
   101
apply (rule wf_on_subset_A [OF _ field_radd])
paulson@13140
   102
apply (blast intro: wf_on_radd) 
paulson@13140
   103
done
paulson@13140
   104
paulson@13140
   105
lemma well_ord_radd:
paulson@13140
   106
     "[| well_ord(A,r);  well_ord(B,s) |] ==> well_ord(A+B, radd(A,r,B,s))"
paulson@13140
   107
apply (rule well_ordI)
paulson@13140
   108
apply (simp add: well_ord_def wf_on_radd)
paulson@13140
   109
apply (simp add: well_ord_def tot_ord_def linear_radd)
paulson@13140
   110
done
paulson@13140
   111
paulson@13512
   112
subsubsection{*An @{term ord_iso} congruence law*}
lcp@437
   113
paulson@13140
   114
lemma sum_bij:
paulson@13140
   115
     "[| f: bij(A,C);  g: bij(B,D) |]
paulson@13140
   116
      ==> (lam z:A+B. case(%x. Inl(f`x), %y. Inr(g`y), z)) : bij(A+B, C+D)"
paulson@13356
   117
apply (rule_tac d = "case (%x. Inl (converse(f)`x), %y. Inr(converse(g)`y))" 
paulson@13356
   118
       in lam_bijective)
paulson@13140
   119
apply (typecheck add: bij_is_inj inj_is_fun) 
paulson@13140
   120
apply (auto simp add: left_inverse_bij right_inverse_bij) 
paulson@13140
   121
done
paulson@13140
   122
paulson@13140
   123
lemma sum_ord_iso_cong: 
paulson@13140
   124
    "[| f: ord_iso(A,r,A',r');  g: ord_iso(B,s,B',s') |] ==>      
paulson@13140
   125
            (lam z:A+B. case(%x. Inl(f`x), %y. Inr(g`y), z))             
paulson@13140
   126
            : ord_iso(A+B, radd(A,r,B,s), A'+B', radd(A',r',B',s'))"
paulson@13140
   127
apply (unfold ord_iso_def)
paulson@13140
   128
apply (safe intro!: sum_bij)
paulson@13140
   129
(*Do the beta-reductions now*)
paulson@13140
   130
apply (auto cong add: conj_cong simp add: bij_is_fun [THEN apply_type])
paulson@13140
   131
done
paulson@13140
   132
paulson@13140
   133
(*Could we prove an ord_iso result?  Perhaps 
paulson@13140
   134
     ord_iso(A+B, radd(A,r,B,s), A Un B, r Un s) *)
paulson@13140
   135
lemma sum_disjoint_bij: "A Int B = 0 ==>      
paulson@13140
   136
            (lam z:A+B. case(%x. x, %y. y, z)) : bij(A+B, A Un B)"
paulson@13140
   137
apply (rule_tac d = "%z. if z:A then Inl (z) else Inr (z) " in lam_bijective)
paulson@13140
   138
apply auto
paulson@13140
   139
done
paulson@13140
   140
paulson@13512
   141
subsubsection{*Associativity*}
paulson@13140
   142
paulson@13140
   143
lemma sum_assoc_bij:
paulson@13140
   144
     "(lam z:(A+B)+C. case(case(Inl, %y. Inr(Inl(y))), %y. Inr(Inr(y)), z))  
paulson@13140
   145
      : bij((A+B)+C, A+(B+C))"
paulson@13140
   146
apply (rule_tac d = "case (%x. Inl (Inl (x)), case (%x. Inl (Inr (x)), Inr))" 
paulson@13140
   147
       in lam_bijective)
paulson@13140
   148
apply auto
paulson@13140
   149
done
paulson@13140
   150
paulson@13140
   151
lemma sum_assoc_ord_iso:
paulson@13140
   152
     "(lam z:(A+B)+C. case(case(Inl, %y. Inr(Inl(y))), %y. Inr(Inr(y)), z))  
paulson@13140
   153
      : ord_iso((A+B)+C, radd(A+B, radd(A,r,B,s), C, t),     
paulson@13140
   154
                A+(B+C), radd(A, r, B+C, radd(B,s,C,t)))"
paulson@13356
   155
by (rule sum_assoc_bij [THEN ord_isoI], auto)
paulson@13140
   156
paulson@13140
   157
paulson@13356
   158
subsection{*Multiplication of Relations -- Lexicographic Product*}
paulson@13140
   159
paulson@13512
   160
subsubsection{*Rewrite rule.  Can be used to obtain introduction rules*}
paulson@13140
   161
paulson@13140
   162
lemma  rmult_iff [iff]: 
paulson@13140
   163
    "<<a',b'>, <a,b>> : rmult(A,r,B,s) <->        
paulson@13140
   164
            (<a',a>: r  & a':A & a:A & b': B & b: B) |   
paulson@13140
   165
            (<b',b>: s  & a'=a & a:A & b': B & b: B)"
paulson@13140
   166
paulson@13356
   167
by (unfold rmult_def, blast)
paulson@13140
   168
paulson@13140
   169
lemma rmultE: 
paulson@13140
   170
    "[| <<a',b'>, <a,b>> : rmult(A,r,B,s);               
paulson@13140
   171
        [| <a',a>: r;  a':A;  a:A;  b':B;  b:B |] ==> Q;         
paulson@13140
   172
        [| <b',b>: s;  a:A;  a'=a;  b':B;  b:B |] ==> Q  
paulson@13140
   173
     |] ==> Q"
paulson@13356
   174
by blast 
paulson@13140
   175
paulson@13512
   176
subsubsection{*Type checking*}
paulson@13140
   177
paulson@13140
   178
lemma rmult_type: "rmult(A,r,B,s) <= (A*B) * (A*B)"
paulson@13356
   179
by (unfold rmult_def, rule Collect_subset)
paulson@13140
   180
paulson@13140
   181
lemmas field_rmult = rmult_type [THEN field_rel_subset]
paulson@13140
   182
paulson@13512
   183
subsubsection{*Linearity*}
paulson@13140
   184
paulson@13140
   185
lemma linear_rmult:
paulson@13140
   186
    "[| linear(A,r);  linear(B,s) |] ==> linear(A*B,rmult(A,r,B,s))"
paulson@13356
   187
by (simp add: linear_def, blast) 
paulson@13140
   188
paulson@13512
   189
subsubsection{*Well-foundedness*}
paulson@13140
   190
paulson@13140
   191
lemma wf_on_rmult: "[| wf[A](r);  wf[B](s) |] ==> wf[A*B](rmult(A,r,B,s))"
paulson@13140
   192
apply (rule wf_onI2)
paulson@13140
   193
apply (erule SigmaE)
paulson@13140
   194
apply (erule ssubst)
paulson@13269
   195
apply (subgoal_tac "ALL b:B. <x,b>: Ba", blast)
paulson@13269
   196
apply (erule_tac a = "x" in wf_on_induct, assumption)
paulson@13140
   197
apply (rule ballI)
paulson@13269
   198
apply (erule_tac a = "b" in wf_on_induct, assumption)
paulson@13140
   199
apply (best elim!: rmultE bspec [THEN mp])
paulson@13140
   200
done
paulson@13140
   201
paulson@13140
   202
paulson@13140
   203
lemma wf_rmult: "[| wf(r);  wf(s) |] ==> wf(rmult(field(r),r,field(s),s))"
paulson@13140
   204
apply (simp add: wf_iff_wf_on_field)
paulson@13140
   205
apply (rule wf_on_subset_A [OF _ field_rmult])
paulson@13140
   206
apply (blast intro: wf_on_rmult) 
paulson@13140
   207
done
paulson@13140
   208
paulson@13140
   209
lemma well_ord_rmult:
paulson@13140
   210
     "[| well_ord(A,r);  well_ord(B,s) |] ==> well_ord(A*B, rmult(A,r,B,s))"
paulson@13140
   211
apply (rule well_ordI)
paulson@13140
   212
apply (simp add: well_ord_def wf_on_rmult)
paulson@13140
   213
apply (simp add: well_ord_def tot_ord_def linear_rmult)
paulson@13140
   214
done
paulson@9883
   215
paulson@9883
   216
paulson@13512
   217
subsubsection{*An @{term ord_iso} congruence law*}
paulson@13140
   218
paulson@13140
   219
lemma prod_bij:
paulson@13140
   220
     "[| f: bij(A,C);  g: bij(B,D) |] 
paulson@13140
   221
      ==> (lam <x,y>:A*B. <f`x, g`y>) : bij(A*B, C*D)"
paulson@13140
   222
apply (rule_tac d = "%<x,y>. <converse (f) `x, converse (g) `y>" 
paulson@13140
   223
       in lam_bijective)
paulson@13140
   224
apply (typecheck add: bij_is_inj inj_is_fun) 
paulson@13140
   225
apply (auto simp add: left_inverse_bij right_inverse_bij) 
paulson@13140
   226
done
paulson@13140
   227
paulson@13140
   228
lemma prod_ord_iso_cong: 
paulson@13140
   229
    "[| f: ord_iso(A,r,A',r');  g: ord_iso(B,s,B',s') |]      
paulson@13140
   230
     ==> (lam <x,y>:A*B. <f`x, g`y>)                                  
paulson@13140
   231
         : ord_iso(A*B, rmult(A,r,B,s), A'*B', rmult(A',r',B',s'))"
paulson@13140
   232
apply (unfold ord_iso_def)
paulson@13140
   233
apply (safe intro!: prod_bij)
paulson@13140
   234
apply (simp_all add: bij_is_fun [THEN apply_type])
paulson@13140
   235
apply (blast intro: bij_is_inj [THEN inj_apply_equality])
paulson@13140
   236
done
paulson@13140
   237
paulson@13140
   238
lemma singleton_prod_bij: "(lam z:A. <x,z>) : bij(A, {x}*A)"
paulson@13269
   239
by (rule_tac d = "snd" in lam_bijective, auto)
paulson@13140
   240
paulson@13140
   241
(*Used??*)
paulson@13140
   242
lemma singleton_prod_ord_iso:
paulson@13140
   243
     "well_ord({x},xr) ==>   
paulson@13140
   244
          (lam z:A. <x,z>) : ord_iso(A, r, {x}*A, rmult({x}, xr, A, r))"
paulson@13140
   245
apply (rule singleton_prod_bij [THEN ord_isoI])
paulson@13140
   246
apply (simp (no_asm_simp))
paulson@13140
   247
apply (blast dest: well_ord_is_wf [THEN wf_on_not_refl])
paulson@13140
   248
done
paulson@13140
   249
paulson@13140
   250
(*Here we build a complicated function term, then simplify it using
paulson@13140
   251
  case_cong, id_conv, comp_lam, case_case.*)
paulson@13140
   252
lemma prod_sum_singleton_bij:
paulson@13140
   253
     "a~:C ==>  
paulson@13140
   254
       (lam x:C*B + D. case(%x. x, %y.<a,y>, x))  
paulson@13140
   255
       : bij(C*B + D, C*B Un {a}*D)"
paulson@13140
   256
apply (rule subst_elem)
paulson@13140
   257
apply (rule id_bij [THEN sum_bij, THEN comp_bij])
paulson@13140
   258
apply (rule singleton_prod_bij)
paulson@13269
   259
apply (rule sum_disjoint_bij, blast)
paulson@13140
   260
apply (simp (no_asm_simp) cong add: case_cong)
paulson@13140
   261
apply (rule comp_lam [THEN trans, symmetric])
paulson@13140
   262
apply (fast elim!: case_type)
paulson@13140
   263
apply (simp (no_asm_simp) add: case_case)
paulson@13140
   264
done
paulson@13140
   265
paulson@13140
   266
lemma prod_sum_singleton_ord_iso:
paulson@13140
   267
 "[| a:A;  well_ord(A,r) |] ==>  
paulson@13140
   268
    (lam x:pred(A,a,r)*B + pred(B,b,s). case(%x. x, %y.<a,y>, x))  
paulson@13140
   269
    : ord_iso(pred(A,a,r)*B + pred(B,b,s),               
paulson@13140
   270
                  radd(A*B, rmult(A,r,B,s), B, s),       
paulson@13140
   271
              pred(A,a,r)*B Un {a}*pred(B,b,s), rmult(A,r,B,s))"
paulson@13140
   272
apply (rule prod_sum_singleton_bij [THEN ord_isoI])
paulson@13140
   273
apply (simp (no_asm_simp) add: pred_iff well_ord_is_wf [THEN wf_on_not_refl])
paulson@13140
   274
apply (auto elim!: well_ord_is_wf [THEN wf_on_asym] predE)
paulson@13140
   275
done
paulson@13140
   276
paulson@13512
   277
subsubsection{*Distributive law*}
paulson@13140
   278
paulson@13140
   279
lemma sum_prod_distrib_bij:
paulson@13140
   280
     "(lam <x,z>:(A+B)*C. case(%y. Inl(<y,z>), %y. Inr(<y,z>), x))  
paulson@13140
   281
      : bij((A+B)*C, (A*C)+(B*C))"
paulson@13356
   282
by (rule_tac d = "case (%<x,y>.<Inl (x),y>, %<x,y>.<Inr (x),y>) " 
paulson@13356
   283
    in lam_bijective, auto)
paulson@13140
   284
paulson@13140
   285
lemma sum_prod_distrib_ord_iso:
paulson@13140
   286
 "(lam <x,z>:(A+B)*C. case(%y. Inl(<y,z>), %y. Inr(<y,z>), x))  
paulson@13140
   287
  : ord_iso((A+B)*C, rmult(A+B, radd(A,r,B,s), C, t),  
paulson@13140
   288
            (A*C)+(B*C), radd(A*C, rmult(A,r,C,t), B*C, rmult(B,s,C,t)))"
paulson@13356
   289
by (rule sum_prod_distrib_bij [THEN ord_isoI], auto)
paulson@13140
   290
paulson@13512
   291
subsubsection{*Associativity*}
paulson@13140
   292
paulson@13140
   293
lemma prod_assoc_bij:
paulson@13140
   294
     "(lam <<x,y>, z>:(A*B)*C. <x,<y,z>>) : bij((A*B)*C, A*(B*C))"
paulson@13356
   295
by (rule_tac d = "%<x, <y,z>>. <<x,y>, z>" in lam_bijective, auto)
paulson@13140
   296
paulson@13140
   297
lemma prod_assoc_ord_iso:
paulson@13140
   298
 "(lam <<x,y>, z>:(A*B)*C. <x,<y,z>>)                    
paulson@13140
   299
  : ord_iso((A*B)*C, rmult(A*B, rmult(A,r,B,s), C, t),   
paulson@13140
   300
            A*(B*C), rmult(A, r, B*C, rmult(B,s,C,t)))"
paulson@13356
   301
by (rule prod_assoc_bij [THEN ord_isoI], auto)
paulson@13140
   302
paulson@13356
   303
subsection{*Inverse Image of a Relation*}
paulson@13140
   304
paulson@13512
   305
subsubsection{*Rewrite rule*}
paulson@13140
   306
paulson@13140
   307
lemma rvimage_iff: "<a,b> : rvimage(A,f,r)  <->  <f`a,f`b>: r & a:A & b:A"
paulson@13269
   308
by (unfold rvimage_def, blast)
paulson@13140
   309
paulson@13512
   310
subsubsection{*Type checking*}
paulson@13140
   311
paulson@13140
   312
lemma rvimage_type: "rvimage(A,f,r) <= A*A"
paulson@13356
   313
apply (unfold rvimage_def, rule Collect_subset)
paulson@13140
   314
done
paulson@13140
   315
paulson@13140
   316
lemmas field_rvimage = rvimage_type [THEN field_rel_subset]
paulson@13140
   317
paulson@13140
   318
lemma rvimage_converse: "rvimage(A,f, converse(r)) = converse(rvimage(A,f,r))"
paulson@13269
   319
by (unfold rvimage_def, blast)
paulson@13140
   320
paulson@13140
   321
paulson@13512
   322
subsubsection{*Partial Ordering Properties*}
paulson@13140
   323
paulson@13140
   324
lemma irrefl_rvimage: 
paulson@13140
   325
    "[| f: inj(A,B);  irrefl(B,r) |] ==> irrefl(A, rvimage(A,f,r))"
paulson@13140
   326
apply (unfold irrefl_def rvimage_def)
paulson@13140
   327
apply (blast intro: inj_is_fun [THEN apply_type])
paulson@13140
   328
done
paulson@13140
   329
paulson@13140
   330
lemma trans_on_rvimage: 
paulson@13140
   331
    "[| f: inj(A,B);  trans[B](r) |] ==> trans[A](rvimage(A,f,r))"
paulson@13140
   332
apply (unfold trans_on_def rvimage_def)
paulson@13140
   333
apply (blast intro: inj_is_fun [THEN apply_type])
paulson@13140
   334
done
paulson@13140
   335
paulson@13140
   336
lemma part_ord_rvimage: 
paulson@13140
   337
    "[| f: inj(A,B);  part_ord(B,r) |] ==> part_ord(A, rvimage(A,f,r))"
paulson@13140
   338
apply (unfold part_ord_def)
paulson@13140
   339
apply (blast intro!: irrefl_rvimage trans_on_rvimage)
paulson@13140
   340
done
paulson@13140
   341
paulson@13512
   342
subsubsection{*Linearity*}
paulson@13140
   343
paulson@13140
   344
lemma linear_rvimage:
paulson@13140
   345
    "[| f: inj(A,B);  linear(B,r) |] ==> linear(A,rvimage(A,f,r))"
paulson@13140
   346
apply (simp add: inj_def linear_def rvimage_iff) 
paulson@13269
   347
apply (blast intro: apply_funtype) 
paulson@13140
   348
done
paulson@13140
   349
paulson@13140
   350
lemma tot_ord_rvimage: 
paulson@13140
   351
    "[| f: inj(A,B);  tot_ord(B,r) |] ==> tot_ord(A, rvimage(A,f,r))"
paulson@13140
   352
apply (unfold tot_ord_def)
paulson@13140
   353
apply (blast intro!: part_ord_rvimage linear_rvimage)
paulson@13140
   354
done
paulson@13140
   355
paulson@13140
   356
paulson@13512
   357
subsubsection{*Well-foundedness*}
paulson@13140
   358
paulson@13140
   359
lemma wf_rvimage [intro!]: "wf(r) ==> wf(rvimage(A,f,r))"
paulson@13140
   360
apply (simp (no_asm_use) add: rvimage_def wf_eq_minimal)
paulson@13140
   361
apply clarify
paulson@13140
   362
apply (subgoal_tac "EX w. w : {w: {f`x. x:Q}. EX x. x: Q & (f`x = w) }")
paulson@13140
   363
 apply (erule allE)
paulson@13140
   364
 apply (erule impE)
paulson@13269
   365
 apply assumption
paulson@13140
   366
 apply blast
paulson@13269
   367
apply blast 
paulson@13140
   368
done
paulson@13140
   369
paulson@13544
   370
text{*But note that the combination of @{text wf_imp_wf_on} and
paulson@13544
   371
 @{text wf_rvimage} gives @{term "wf(r) ==> wf[C](rvimage(A,f,r))"}*}
paulson@13140
   372
lemma wf_on_rvimage: "[| f: A->B;  wf[B](r) |] ==> wf[A](rvimage(A,f,r))"
paulson@13140
   373
apply (rule wf_onI2)
paulson@13140
   374
apply (subgoal_tac "ALL z:A. f`z=f`y --> z: Ba")
paulson@13140
   375
 apply blast
paulson@13140
   376
apply (erule_tac a = "f`y" in wf_on_induct)
paulson@13140
   377
 apply (blast intro!: apply_funtype)
paulson@13140
   378
apply (blast intro!: apply_funtype dest!: rvimage_iff [THEN iffD1])
paulson@13140
   379
done
paulson@13140
   380
paulson@13140
   381
(*Note that we need only wf[A](...) and linear(A,...) to get the result!*)
paulson@13140
   382
lemma well_ord_rvimage:
paulson@13140
   383
     "[| f: inj(A,B);  well_ord(B,r) |] ==> well_ord(A, rvimage(A,f,r))"
paulson@13140
   384
apply (rule well_ordI)
paulson@13140
   385
apply (unfold well_ord_def tot_ord_def)
paulson@13140
   386
apply (blast intro!: wf_on_rvimage inj_is_fun)
paulson@13140
   387
apply (blast intro!: linear_rvimage)
paulson@13140
   388
done
paulson@13140
   389
paulson@13140
   390
lemma ord_iso_rvimage: 
paulson@13140
   391
    "f: bij(A,B) ==> f: ord_iso(A, rvimage(A,f,s), B, s)"
paulson@13140
   392
apply (unfold ord_iso_def)
paulson@13140
   393
apply (simp add: rvimage_iff)
paulson@13140
   394
done
paulson@13140
   395
paulson@13140
   396
lemma ord_iso_rvimage_eq: 
paulson@13140
   397
    "f: ord_iso(A,r, B,s) ==> rvimage(A,f,s) = r Int A*A"
paulson@13356
   398
by (unfold ord_iso_def rvimage_def, blast)
paulson@13140
   399
paulson@13140
   400
paulson@13544
   401
subsection{*Other Results*}
paulson@13544
   402
paulson@13544
   403
lemma wf_times: "A Int B = 0 ==> wf(A*B)"
paulson@13544
   404
by (simp add: wf_def, blast)
paulson@13544
   405
paulson@13544
   406
text{*Could also be used to prove @{text wf_radd}*}
paulson@13544
   407
lemma wf_Un:
paulson@13544
   408
     "[| range(r) Int domain(s) = 0; wf(r);  wf(s) |] ==> wf(r Un s)"
paulson@13544
   409
apply (simp add: wf_def, clarify) 
paulson@13544
   410
apply (rule equalityI) 
paulson@13544
   411
 prefer 2 apply blast 
paulson@13544
   412
apply clarify 
paulson@13544
   413
apply (drule_tac x=Z in spec)
paulson@13544
   414
apply (drule_tac x="Z Int domain(s)" in spec)
paulson@13544
   415
apply simp 
paulson@13544
   416
apply (blast intro: elim: equalityE) 
paulson@13544
   417
done
paulson@13544
   418
paulson@13544
   419
subsubsection{*The Empty Relation*}
paulson@13544
   420
paulson@13544
   421
lemma wf0: "wf(0)"
paulson@13544
   422
by (simp add: wf_def, blast)
paulson@13544
   423
paulson@13544
   424
lemma linear0: "linear(0,0)"
paulson@13544
   425
by (simp add: linear_def)
paulson@13544
   426
paulson@13544
   427
lemma well_ord0: "well_ord(0,0)"
paulson@13544
   428
by (blast intro: wf_imp_wf_on well_ordI wf0 linear0)
paulson@13512
   429
paulson@13512
   430
subsubsection{*The "measure" relation is useful with wfrec*}
paulson@13140
   431
paulson@13140
   432
lemma measure_eq_rvimage_Memrel:
paulson@13140
   433
     "measure(A,f) = rvimage(A,Lambda(A,f),Memrel(Collect(RepFun(A,f),Ord)))"
paulson@13140
   434
apply (simp (no_asm) add: measure_def rvimage_def Memrel_iff)
paulson@13269
   435
apply (rule equalityI, auto)
paulson@13140
   436
apply (auto intro: Ord_in_Ord simp add: lt_def)
paulson@13140
   437
done
paulson@13140
   438
paulson@13140
   439
lemma wf_measure [iff]: "wf(measure(A,f))"
paulson@13356
   440
by (simp (no_asm) add: measure_eq_rvimage_Memrel wf_Memrel wf_rvimage)
paulson@13140
   441
paulson@13140
   442
lemma measure_iff [iff]: "<x,y> : measure(A,f) <-> x:A & y:A & f(x)<f(y)"
paulson@13356
   443
by (simp (no_asm) add: measure_def)
paulson@13140
   444
paulson@13544
   445
lemma linear_measure: 
paulson@13544
   446
 assumes Ordf: "!!x. x \<in> A ==> Ord(f(x))"
paulson@13544
   447
     and inj:  "!!x y. [|x \<in> A; y \<in> A; f(x) = f(y) |] ==> x=y"
paulson@13544
   448
 shows "linear(A, measure(A,f))"
paulson@13544
   449
apply (auto simp add: linear_def) 
paulson@13544
   450
apply (rule_tac i="f(x)" and j="f(y)" in Ord_linear_lt) 
paulson@13544
   451
    apply (simp_all add: Ordf) 
paulson@13544
   452
apply (blast intro: inj) 
paulson@13544
   453
done
paulson@13544
   454
paulson@13544
   455
lemma wf_on_measure: "wf[B](measure(A,f))"
paulson@13544
   456
by (rule wf_imp_wf_on [OF wf_measure])
paulson@13544
   457
paulson@13544
   458
lemma well_ord_measure: 
paulson@13544
   459
 assumes Ordf: "!!x. x \<in> A ==> Ord(f(x))"
paulson@13544
   460
     and inj:  "!!x y. [|x \<in> A; y \<in> A; f(x) = f(y) |] ==> x=y"
paulson@13544
   461
 shows "well_ord(A, measure(A,f))"
paulson@13544
   462
apply (rule well_ordI)
paulson@13544
   463
apply (rule wf_on_measure) 
paulson@13544
   464
apply (blast intro: linear_measure Ordf inj) 
paulson@13544
   465
done
paulson@13544
   466
paulson@13544
   467
lemma measure_type: "measure(A,f) <= A*A"
paulson@13544
   468
by (auto simp add: measure_def)
paulson@13544
   469
paulson@13512
   470
subsubsection{*Well-foundedness of Unions*}
paulson@13512
   471
paulson@13512
   472
lemma wf_on_Union:
paulson@13512
   473
 assumes wfA: "wf[A](r)"
paulson@13512
   474
     and wfB: "!!a. a\<in>A ==> wf[B(a)](s)"
paulson@13512
   475
     and ok: "!!a u v. [|<u,v> \<in> s; v \<in> B(a); a \<in> A|] 
paulson@13512
   476
                       ==> (\<exists>a'\<in>A. <a',a> \<in> r & u \<in> B(a')) | u \<in> B(a)"
paulson@13512
   477
 shows "wf[\<Union>a\<in>A. B(a)](s)"
paulson@13512
   478
apply (rule wf_onI2)
paulson@13512
   479
apply (erule UN_E)
paulson@13512
   480
apply (subgoal_tac "\<forall>z \<in> B(a). z \<in> Ba", blast)
paulson@13512
   481
apply (rule_tac a = a in wf_on_induct [OF wfA], assumption)
paulson@13512
   482
apply (rule ballI)
paulson@13512
   483
apply (rule_tac a = z in wf_on_induct [OF wfB], assumption, assumption)
paulson@13512
   484
apply (rename_tac u) 
paulson@13512
   485
apply (drule_tac x=u in bspec, blast) 
paulson@13512
   486
apply (erule mp, clarify)
paulson@13512
   487
apply (frule ok, assumption+); 
paulson@13512
   488
apply blast 
paulson@13512
   489
done
paulson@13512
   490
paulson@13512
   491
paulson@13140
   492
ML {*
paulson@13140
   493
val measure_def = thm "measure_def";
paulson@13140
   494
val radd_Inl_Inr_iff = thm "radd_Inl_Inr_iff";
paulson@13140
   495
val radd_Inl_iff = thm "radd_Inl_iff";
paulson@13140
   496
val radd_Inr_iff = thm "radd_Inr_iff";
paulson@13140
   497
val radd_Inr_Inl_iff = thm "radd_Inr_Inl_iff";
paulson@13140
   498
val raddE = thm "raddE";
paulson@13140
   499
val radd_type = thm "radd_type";
paulson@13140
   500
val field_radd = thm "field_radd";
paulson@13140
   501
val linear_radd = thm "linear_radd";
paulson@13140
   502
val wf_on_radd = thm "wf_on_radd";
paulson@13140
   503
val wf_radd = thm "wf_radd";
paulson@13140
   504
val well_ord_radd = thm "well_ord_radd";
paulson@13140
   505
val sum_bij = thm "sum_bij";
paulson@13140
   506
val sum_ord_iso_cong = thm "sum_ord_iso_cong";
paulson@13140
   507
val sum_disjoint_bij = thm "sum_disjoint_bij";
paulson@13140
   508
val sum_assoc_bij = thm "sum_assoc_bij";
paulson@13140
   509
val sum_assoc_ord_iso = thm "sum_assoc_ord_iso";
paulson@13140
   510
val rmult_iff = thm "rmult_iff";
paulson@13140
   511
val rmultE = thm "rmultE";
paulson@13140
   512
val rmult_type = thm "rmult_type";
paulson@13140
   513
val field_rmult = thm "field_rmult";
paulson@13140
   514
val linear_rmult = thm "linear_rmult";
paulson@13140
   515
val wf_on_rmult = thm "wf_on_rmult";
paulson@13140
   516
val wf_rmult = thm "wf_rmult";
paulson@13140
   517
val well_ord_rmult = thm "well_ord_rmult";
paulson@13140
   518
val prod_bij = thm "prod_bij";
paulson@13140
   519
val prod_ord_iso_cong = thm "prod_ord_iso_cong";
paulson@13140
   520
val singleton_prod_bij = thm "singleton_prod_bij";
paulson@13140
   521
val singleton_prod_ord_iso = thm "singleton_prod_ord_iso";
paulson@13140
   522
val prod_sum_singleton_bij = thm "prod_sum_singleton_bij";
paulson@13140
   523
val prod_sum_singleton_ord_iso = thm "prod_sum_singleton_ord_iso";
paulson@13140
   524
val sum_prod_distrib_bij = thm "sum_prod_distrib_bij";
paulson@13140
   525
val sum_prod_distrib_ord_iso = thm "sum_prod_distrib_ord_iso";
paulson@13140
   526
val prod_assoc_bij = thm "prod_assoc_bij";
paulson@13140
   527
val prod_assoc_ord_iso = thm "prod_assoc_ord_iso";
paulson@13140
   528
val rvimage_iff = thm "rvimage_iff";
paulson@13140
   529
val rvimage_type = thm "rvimage_type";
paulson@13140
   530
val field_rvimage = thm "field_rvimage";
paulson@13140
   531
val rvimage_converse = thm "rvimage_converse";
paulson@13140
   532
val irrefl_rvimage = thm "irrefl_rvimage";
paulson@13140
   533
val trans_on_rvimage = thm "trans_on_rvimage";
paulson@13140
   534
val part_ord_rvimage = thm "part_ord_rvimage";
paulson@13140
   535
val linear_rvimage = thm "linear_rvimage";
paulson@13140
   536
val tot_ord_rvimage = thm "tot_ord_rvimage";
paulson@13140
   537
val wf_rvimage = thm "wf_rvimage";
paulson@13140
   538
val wf_on_rvimage = thm "wf_on_rvimage";
paulson@13140
   539
val well_ord_rvimage = thm "well_ord_rvimage";
paulson@13140
   540
val ord_iso_rvimage = thm "ord_iso_rvimage";
paulson@13140
   541
val ord_iso_rvimage_eq = thm "ord_iso_rvimage_eq";
paulson@13140
   542
val measure_eq_rvimage_Memrel = thm "measure_eq_rvimage_Memrel";
paulson@13140
   543
val wf_measure = thm "wf_measure";
paulson@13140
   544
val measure_iff = thm "measure_iff";
paulson@13140
   545
*}
paulson@13140
   546
lcp@437
   547
end