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