src/CCL/Gfp.thy
author haftmann
Fri Jun 19 21:08:07 2009 +0200 (2009-06-19)
changeset 31726 ffd2dc631d88
parent 21404 eb85850d3eb7
child 32153 a0e57fb1b930
permissions -rw-r--r--
merged
wenzelm@17456
     1
(*  Title:      CCL/Gfp.thy
clasohm@0
     2
    ID:         $Id$
clasohm@1474
     3
    Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
clasohm@0
     4
    Copyright   1992  University of Cambridge
clasohm@0
     5
*)
clasohm@0
     6
wenzelm@17456
     7
header {* Greatest fixed points *}
wenzelm@17456
     8
wenzelm@17456
     9
theory Gfp
wenzelm@17456
    10
imports Lfp
wenzelm@17456
    11
begin
wenzelm@17456
    12
wenzelm@20140
    13
definition
wenzelm@21404
    14
  gfp :: "['a set=>'a set] => 'a set" where -- "greatest fixed point"
wenzelm@17456
    15
  "gfp(f) == Union({u. u <= f(u)})"
wenzelm@17456
    16
wenzelm@20140
    17
(* gfp(f) is the least upper bound of {u. u <= f(u)} *)
wenzelm@20140
    18
wenzelm@20140
    19
lemma gfp_upperbound: "[| A <= f(A) |] ==> A <= gfp(f)"
wenzelm@20140
    20
  unfolding gfp_def by blast
wenzelm@20140
    21
wenzelm@20140
    22
lemma gfp_least: "[| !!u. u <= f(u) ==> u<=A |] ==> gfp(f) <= A"
wenzelm@20140
    23
  unfolding gfp_def by blast
wenzelm@20140
    24
wenzelm@20140
    25
lemma gfp_lemma2: "mono(f) ==> gfp(f) <= f(gfp(f))"
wenzelm@20140
    26
  by (rule gfp_least, rule subset_trans, assumption, erule monoD,
wenzelm@20140
    27
    rule gfp_upperbound, assumption)
wenzelm@20140
    28
wenzelm@20140
    29
lemma gfp_lemma3: "mono(f) ==> f(gfp(f)) <= gfp(f)"
wenzelm@20140
    30
  by (rule gfp_upperbound, frule monoD, rule gfp_lemma2, assumption+)
wenzelm@20140
    31
wenzelm@20140
    32
lemma gfp_Tarski: "mono(f) ==> gfp(f) = f(gfp(f))"
wenzelm@20140
    33
  by (rule equalityI gfp_lemma2 gfp_lemma3 | assumption)+
wenzelm@20140
    34
wenzelm@20140
    35
wenzelm@20140
    36
(*** Coinduction rules for greatest fixed points ***)
wenzelm@20140
    37
wenzelm@20140
    38
(*weak version*)
wenzelm@20140
    39
lemma coinduct: "[| a: A;  A <= f(A) |] ==> a : gfp(f)"
wenzelm@20140
    40
  by (blast dest: gfp_upperbound)
wenzelm@20140
    41
wenzelm@20140
    42
lemma coinduct2_lemma:
wenzelm@20140
    43
  "[| A <= f(A) Un gfp(f);  mono(f) |] ==>   
wenzelm@20140
    44
    A Un gfp(f) <= f(A Un gfp(f))"
wenzelm@20140
    45
  apply (rule subset_trans)
wenzelm@20140
    46
   prefer 2
wenzelm@20140
    47
   apply (erule mono_Un)
wenzelm@20140
    48
  apply (rule subst, erule gfp_Tarski)
wenzelm@20140
    49
  apply (erule Un_least)
wenzelm@20140
    50
  apply (rule Un_upper2)
wenzelm@20140
    51
  done
wenzelm@20140
    52
wenzelm@20140
    53
(*strong version, thanks to Martin Coen*)
wenzelm@20140
    54
lemma coinduct2:
wenzelm@20140
    55
  "[| a: A;  A <= f(A) Un gfp(f);  mono(f) |] ==> a : gfp(f)"
wenzelm@20140
    56
  apply (rule coinduct)
wenzelm@20140
    57
   prefer 2
wenzelm@20140
    58
   apply (erule coinduct2_lemma, assumption)
wenzelm@20140
    59
  apply blast
wenzelm@20140
    60
  done
wenzelm@20140
    61
wenzelm@20140
    62
(***  Even Stronger version of coinduct  [by Martin Coen]
wenzelm@20140
    63
         - instead of the condition  A <= f(A)
wenzelm@20140
    64
                           consider  A <= (f(A) Un f(f(A)) ...) Un gfp(A) ***)
wenzelm@20140
    65
wenzelm@20140
    66
lemma coinduct3_mono_lemma: "mono(f) ==> mono(%x. f(x) Un A Un B)"
wenzelm@20140
    67
  by (rule monoI) (blast dest: monoD)
wenzelm@20140
    68
wenzelm@20140
    69
lemma coinduct3_lemma:
wenzelm@20140
    70
  assumes prem: "A <= f(lfp(%x. f(x) Un A Un gfp(f)))"
wenzelm@20140
    71
    and mono: "mono(f)"
wenzelm@20140
    72
  shows "lfp(%x. f(x) Un A Un gfp(f)) <= f(lfp(%x. f(x) Un A Un gfp(f)))"
wenzelm@20140
    73
  apply (rule subset_trans)
wenzelm@20140
    74
   apply (rule mono [THEN coinduct3_mono_lemma, THEN lfp_lemma3])
wenzelm@20140
    75
  apply (rule Un_least [THEN Un_least])
wenzelm@20140
    76
    apply (rule subset_refl)
wenzelm@20140
    77
   apply (rule prem)
wenzelm@20140
    78
  apply (rule mono [THEN gfp_Tarski, THEN equalityD1, THEN subset_trans])
wenzelm@20140
    79
  apply (rule mono [THEN monoD])
wenzelm@20140
    80
  apply (subst mono [THEN coinduct3_mono_lemma, THEN lfp_Tarski])
wenzelm@20140
    81
  apply (rule Un_upper2)
wenzelm@20140
    82
  done
wenzelm@20140
    83
wenzelm@20140
    84
lemma coinduct3:
wenzelm@20140
    85
  assumes 1: "a:A"
wenzelm@20140
    86
    and 2: "A <= f(lfp(%x. f(x) Un A Un gfp(f)))"
wenzelm@20140
    87
    and 3: "mono(f)"
wenzelm@20140
    88
  shows "a : gfp(f)"
wenzelm@20140
    89
  apply (rule coinduct)
wenzelm@20140
    90
   prefer 2
wenzelm@20140
    91
   apply (rule coinduct3_lemma [OF 2 3])
wenzelm@20140
    92
  apply (subst lfp_Tarski [OF coinduct3_mono_lemma, OF 3])
wenzelm@20140
    93
  using 1 apply blast
wenzelm@20140
    94
  done
wenzelm@20140
    95
wenzelm@20140
    96
wenzelm@20140
    97
subsection {* Definition forms of @{text "gfp_Tarski"}, to control unfolding *}
wenzelm@20140
    98
wenzelm@20140
    99
lemma def_gfp_Tarski: "[| h==gfp(f);  mono(f) |] ==> h = f(h)"
wenzelm@20140
   100
  apply unfold
wenzelm@20140
   101
  apply (erule gfp_Tarski)
wenzelm@20140
   102
  done
wenzelm@20140
   103
wenzelm@20140
   104
lemma def_coinduct: "[| h==gfp(f);  a:A;  A <= f(A) |] ==> a: h"
wenzelm@20140
   105
  apply unfold
wenzelm@20140
   106
  apply (erule coinduct)
wenzelm@20140
   107
  apply assumption
wenzelm@20140
   108
  done
wenzelm@20140
   109
wenzelm@20140
   110
lemma def_coinduct2: "[| h==gfp(f);  a:A;  A <= f(A) Un h; mono(f) |] ==> a: h"
wenzelm@20140
   111
  apply unfold
wenzelm@20140
   112
  apply (erule coinduct2)
wenzelm@20140
   113
   apply assumption
wenzelm@20140
   114
  apply assumption
wenzelm@20140
   115
  done
wenzelm@20140
   116
wenzelm@20140
   117
lemma def_coinduct3: "[| h==gfp(f);  a:A;  A <= f(lfp(%x. f(x) Un A Un h)); mono(f) |] ==> a: h"
wenzelm@20140
   118
  apply unfold
wenzelm@20140
   119
  apply (erule coinduct3)
wenzelm@20140
   120
   apply assumption
wenzelm@20140
   121
  apply assumption
wenzelm@20140
   122
  done
wenzelm@20140
   123
wenzelm@20140
   124
(*Monotonicity of gfp!*)
wenzelm@20140
   125
lemma gfp_mono: "[| mono(f);  !!Z. f(Z)<=g(Z) |] ==> gfp(f) <= gfp(g)"
wenzelm@20140
   126
  apply (rule gfp_upperbound)
wenzelm@20140
   127
  apply (rule subset_trans)
wenzelm@20140
   128
   apply (rule gfp_lemma2)
wenzelm@20140
   129
   apply assumption
wenzelm@20140
   130
  apply (erule meta_spec)
wenzelm@20140
   131
  done
wenzelm@17456
   132
clasohm@0
   133
end