src/CCL/Fix.thy
author wenzelm
Tue Jul 18 02:22:38 2006 +0200 (2006-07-18)
changeset 20140 98acc6d0fab6
parent 17456 bcf7544875b2
child 23467 d1b97708d5eb
permissions -rw-r--r--
removed obsolete ML files;
wenzelm@17456
     1
(*  Title:      CCL/Fix.thy
clasohm@0
     2
    ID:         $Id$
clasohm@1474
     3
    Author:     Martin Coen
clasohm@0
     4
    Copyright   1993  University of Cambridge
clasohm@0
     5
*)
clasohm@0
     6
wenzelm@17456
     7
header {* Tentative attempt at including fixed point induction; justified by Smith *}
wenzelm@17456
     8
wenzelm@17456
     9
theory Fix
wenzelm@17456
    10
imports Type
wenzelm@17456
    11
begin
clasohm@0
    12
clasohm@0
    13
consts
clasohm@1474
    14
  idgen      ::       "[i]=>i"
clasohm@0
    15
  INCL      :: "[i=>o]=>o"
clasohm@0
    16
wenzelm@17456
    17
axioms
wenzelm@17456
    18
  idgen_def:
wenzelm@3837
    19
  "idgen(f) == lam t. case(t,true,false,%x y.<f`x, f`y>,%u. lam x. f ` u(x))"
clasohm@0
    20
wenzelm@17456
    21
  INCL_def:   "INCL(%x. P(x)) == (ALL f.(ALL n:Nat. P(f^n`bot)) --> P(fix(f)))"
wenzelm@17456
    22
  po_INCL:    "INCL(%x. a(x) [= b(x))"
wenzelm@17456
    23
  INCL_subst: "INCL(P) ==> INCL(%x. P((g::i=>i)(x)))"
wenzelm@17456
    24
wenzelm@20140
    25
wenzelm@20140
    26
subsection {* Fixed Point Induction *}
wenzelm@20140
    27
wenzelm@20140
    28
lemma fix_ind:
wenzelm@20140
    29
  assumes base: "P(bot)"
wenzelm@20140
    30
    and step: "!!x. P(x) ==> P(f(x))"
wenzelm@20140
    31
    and incl: "INCL(P)"
wenzelm@20140
    32
  shows "P(fix(f))"
wenzelm@20140
    33
  apply (rule incl [unfolded INCL_def, rule_format])
wenzelm@20140
    34
  apply (rule Nat_ind [THEN ballI], assumption)
wenzelm@20140
    35
   apply simp_all
wenzelm@20140
    36
   apply (rule base)
wenzelm@20140
    37
  apply (erule step)
wenzelm@20140
    38
  done
wenzelm@20140
    39
wenzelm@20140
    40
wenzelm@20140
    41
subsection {* Inclusive Predicates *}
wenzelm@20140
    42
wenzelm@20140
    43
lemma inclXH: "INCL(P) <-> (ALL f. (ALL n:Nat. P(f ^ n ` bot)) --> P(fix(f)))"
wenzelm@20140
    44
  by (simp add: INCL_def)
wenzelm@20140
    45
wenzelm@20140
    46
lemma inclI: "[| !!f. ALL n:Nat. P(f^n`bot) ==> P(fix(f)) |] ==> INCL(%x. P(x))"
wenzelm@20140
    47
  unfolding inclXH by blast
wenzelm@20140
    48
wenzelm@20140
    49
lemma inclD: "[| INCL(P);  !!n. n:Nat ==> P(f^n`bot) |] ==> P(fix(f))"
wenzelm@20140
    50
  unfolding inclXH by blast
wenzelm@20140
    51
wenzelm@20140
    52
lemma inclE: "[| INCL(P);  (ALL n:Nat. P(f^n`bot))-->P(fix(f)) ==> R |] ==> R"
wenzelm@20140
    53
  by (blast dest: inclD)
wenzelm@20140
    54
wenzelm@20140
    55
wenzelm@20140
    56
subsection {* Lemmas for Inclusive Predicates *}
wenzelm@20140
    57
wenzelm@20140
    58
lemma npo_INCL: "INCL(%x.~ a(x) [= t)"
wenzelm@20140
    59
  apply (rule inclI)
wenzelm@20140
    60
  apply (drule bspec)
wenzelm@20140
    61
   apply (rule zeroT)
wenzelm@20140
    62
  apply (erule contrapos)
wenzelm@20140
    63
  apply (rule po_trans)
wenzelm@20140
    64
   prefer 2
wenzelm@20140
    65
   apply assumption
wenzelm@20140
    66
  apply (subst napplyBzero)
wenzelm@20140
    67
  apply (rule po_cong, rule po_bot)
wenzelm@20140
    68
  done
wenzelm@20140
    69
wenzelm@20140
    70
lemma conj_INCL: "[| INCL(P);  INCL(Q) |] ==> INCL(%x. P(x) & Q(x))"
wenzelm@20140
    71
  by (blast intro!: inclI dest!: inclD)
wenzelm@20140
    72
wenzelm@20140
    73
lemma all_INCL: "[| !!a. INCL(P(a)) |] ==> INCL(%x. ALL a. P(a,x))"
wenzelm@20140
    74
  by (blast intro!: inclI dest!: inclD)
wenzelm@20140
    75
wenzelm@20140
    76
lemma ball_INCL: "[| !!a. a:A ==> INCL(P(a)) |] ==> INCL(%x. ALL a:A. P(a,x))"
wenzelm@20140
    77
  by (blast intro!: inclI dest!: inclD)
wenzelm@20140
    78
wenzelm@20140
    79
lemma eq_INCL: "INCL(%x. a(x) = (b(x)::'a::prog))"
wenzelm@20140
    80
  apply (simp add: eq_iff)
wenzelm@20140
    81
  apply (rule conj_INCL po_INCL)+
wenzelm@20140
    82
  done
wenzelm@20140
    83
wenzelm@20140
    84
wenzelm@20140
    85
subsection {* Derivation of Reachability Condition *}
wenzelm@20140
    86
wenzelm@20140
    87
(* Fixed points of idgen *)
wenzelm@20140
    88
wenzelm@20140
    89
lemma fix_idgenfp: "idgen(fix(idgen)) = fix(idgen)"
wenzelm@20140
    90
  apply (rule fixB [symmetric])
wenzelm@20140
    91
  done
wenzelm@20140
    92
wenzelm@20140
    93
lemma id_idgenfp: "idgen(lam x. x) = lam x. x"
wenzelm@20140
    94
  apply (simp add: idgen_def)
wenzelm@20140
    95
  apply (rule term_case [THEN allI])
wenzelm@20140
    96
      apply simp_all
wenzelm@20140
    97
  done
wenzelm@20140
    98
wenzelm@20140
    99
(* All fixed points are lam-expressions *)
wenzelm@20140
   100
wenzelm@20140
   101
lemma idgenfp_lam: "idgen(d) = d ==> d = lam x. ?f(x)"
wenzelm@20140
   102
  apply (unfold idgen_def)
wenzelm@20140
   103
  apply (erule ssubst)
wenzelm@20140
   104
  apply (rule refl)
wenzelm@20140
   105
  done
wenzelm@20140
   106
wenzelm@20140
   107
(* Lemmas for rewriting fixed points of idgen *)
wenzelm@20140
   108
wenzelm@20140
   109
lemma l_lemma: "[| a = b;  a ` t = u |] ==> b ` t = u"
wenzelm@20140
   110
  by (simp add: idgen_def)
wenzelm@20140
   111
wenzelm@20140
   112
lemma idgen_lemmas:
wenzelm@20140
   113
  "idgen(d) = d ==> d ` bot = bot"
wenzelm@20140
   114
  "idgen(d) = d ==> d ` true = true"
wenzelm@20140
   115
  "idgen(d) = d ==> d ` false = false"
wenzelm@20140
   116
  "idgen(d) = d ==> d ` <a,b> = <d ` a,d ` b>"
wenzelm@20140
   117
  "idgen(d) = d ==> d ` (lam x. f(x)) = lam x. d ` f(x)"
wenzelm@20140
   118
  by (erule l_lemma, simp add: idgen_def)+
wenzelm@20140
   119
wenzelm@20140
   120
wenzelm@20140
   121
(* Proof of Reachability law - show that fix and lam x.x both give LEAST fixed points
wenzelm@20140
   122
  of idgen and hence are they same *)
wenzelm@20140
   123
wenzelm@20140
   124
lemma po_eta:
wenzelm@20140
   125
  "[| ALL x. t ` x [= u ` x;  EX f. t=lam x. f(x);  EX f. u=lam x. f(x) |] ==> t [= u"
wenzelm@20140
   126
  apply (drule cond_eta)+
wenzelm@20140
   127
  apply (erule ssubst)
wenzelm@20140
   128
  apply (erule ssubst)
wenzelm@20140
   129
  apply (rule po_lam [THEN iffD2])
wenzelm@20140
   130
  apply simp
wenzelm@20140
   131
  done
wenzelm@20140
   132
wenzelm@20140
   133
lemma po_eta_lemma: "idgen(d) = d ==> d = lam x. ?f(x)"
wenzelm@20140
   134
  apply (unfold idgen_def)
wenzelm@20140
   135
  apply (erule sym)
wenzelm@20140
   136
  done
wenzelm@20140
   137
wenzelm@20140
   138
lemma lemma1:
wenzelm@20140
   139
  "idgen(d) = d ==>
wenzelm@20140
   140
    {p. EX a b. p=<a,b> & (EX t. a=fix(idgen) ` t & b = d ` t)} <=
wenzelm@20140
   141
      POgen({p. EX a b. p=<a,b> & (EX t. a=fix(idgen) ` t  & b = d ` t)})"
wenzelm@20140
   142
  apply clarify
wenzelm@20140
   143
  apply (rule_tac t = t in term_case)
wenzelm@20140
   144
      apply (simp_all add: POgenXH idgen_lemmas idgen_lemmas [OF fix_idgenfp])
wenzelm@20140
   145
   apply blast
wenzelm@20140
   146
  apply fast
wenzelm@20140
   147
  done
wenzelm@20140
   148
wenzelm@20140
   149
lemma fix_least_idgen: "idgen(d) = d ==> fix(idgen) [= d"
wenzelm@20140
   150
  apply (rule allI [THEN po_eta])
wenzelm@20140
   151
    apply (rule lemma1 [THEN [2] po_coinduct])
wenzelm@20140
   152
     apply (blast intro: po_eta_lemma fix_idgenfp)+
wenzelm@20140
   153
  done
wenzelm@20140
   154
wenzelm@20140
   155
lemma lemma2:
wenzelm@20140
   156
  "idgen(d) = d ==>
wenzelm@20140
   157
    {p. EX a b. p=<a,b> & b = d ` a} <= POgen({p. EX a b. p=<a,b> & b = d ` a})"
wenzelm@20140
   158
  apply clarify
wenzelm@20140
   159
  apply (rule_tac t = a in term_case)
wenzelm@20140
   160
      apply (simp_all add: POgenXH idgen_lemmas)
wenzelm@20140
   161
  apply fast
wenzelm@20140
   162
  done
wenzelm@20140
   163
wenzelm@20140
   164
lemma id_least_idgen: "idgen(d) = d ==> lam x. x [= d"
wenzelm@20140
   165
  apply (rule allI [THEN po_eta])
wenzelm@20140
   166
    apply (rule lemma2 [THEN [2] po_coinduct])
wenzelm@20140
   167
     apply simp
wenzelm@20140
   168
    apply (fast intro: po_eta_lemma fix_idgenfp)+
wenzelm@20140
   169
  done
wenzelm@20140
   170
wenzelm@20140
   171
lemma reachability: "fix(idgen) = lam x. x"
wenzelm@20140
   172
  apply (fast intro: eq_iff [THEN iffD2]
wenzelm@20140
   173
    id_idgenfp [THEN fix_least_idgen] fix_idgenfp [THEN id_least_idgen])
wenzelm@20140
   174
  done
wenzelm@20140
   175
wenzelm@20140
   176
(********)
wenzelm@20140
   177
wenzelm@20140
   178
lemma id_apply: "f = lam x. x ==> f`t = t"
wenzelm@20140
   179
  apply (erule ssubst)
wenzelm@20140
   180
  apply (rule applyB)
wenzelm@20140
   181
  done
wenzelm@20140
   182
wenzelm@20140
   183
lemma term_ind:
wenzelm@20140
   184
  assumes "P(bot)" "P(true)" "P(false)"
wenzelm@20140
   185
    "!!x y.[| P(x);  P(y) |] ==> P(<x,y>)"
wenzelm@20140
   186
    "!!u.(!!x. P(u(x))) ==> P(lam x. u(x))"  "INCL(P)"
wenzelm@20140
   187
  shows "P(t)"
wenzelm@20140
   188
  apply (rule reachability [THEN id_apply, THEN subst])
wenzelm@20140
   189
  apply (rule_tac x = t in spec)
wenzelm@20140
   190
  apply (rule fix_ind)
wenzelm@20140
   191
    apply (unfold idgen_def)
wenzelm@20140
   192
    apply (rule allI)
wenzelm@20140
   193
    apply (subst applyBbot)
wenzelm@20140
   194
    apply assumption
wenzelm@20140
   195
   apply (rule allI)
wenzelm@20140
   196
   apply (rule applyB [THEN ssubst])
wenzelm@20140
   197
    apply (rule_tac t = "xa" in term_case)
wenzelm@20140
   198
       apply simp_all
wenzelm@20140
   199
       apply (fast intro: prems INCL_subst all_INCL)+
wenzelm@20140
   200
  done
clasohm@0
   201
clasohm@0
   202
end