src/HOL/Gfp.ML
author oheimb
Wed Jan 31 10:15:55 2001 +0100 (2001-01-31)
changeset 11008 f7333f055ef6
parent 10186 499637e8f2c6
child 11335 c150861633da
permissions -rw-r--r--
improved theory reference in comment
wenzelm@9422
     1
(*  Title:      HOL/Gfp.ML
clasohm@923
     2
    ID:         $Id$
clasohm@1465
     3
    Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
clasohm@923
     4
    Copyright   1993  University of Cambridge
clasohm@923
     5
paulson@5148
     6
The Knaster-Tarski Theorem for greatest fixed points.
clasohm@923
     7
*)
clasohm@923
     8
clasohm@923
     9
(*** Proof of Knaster-Tarski Theorem using gfp ***)
clasohm@923
    10
clasohm@923
    11
(* gfp(f) is the least upper bound of {u. u <= f(u)} *)
clasohm@923
    12
paulson@5148
    13
Goalw [gfp_def] "[| X <= f(X) |] ==> X <= gfp(f)";
paulson@5148
    14
by (etac (CollectI RS Union_upper) 1);
clasohm@923
    15
qed "gfp_upperbound";
clasohm@923
    16
paulson@10067
    17
val prems = Goalw [gfp_def]
clasohm@923
    18
    "[| !!u. u <= f(u) ==> u<=X |] ==> gfp(f) <= X";
clasohm@923
    19
by (REPEAT (ares_tac ([Union_least]@prems) 1));
clasohm@923
    20
by (etac CollectD 1);
clasohm@923
    21
qed "gfp_least";
clasohm@923
    22
paulson@5316
    23
Goal "mono(f) ==> gfp(f) <= f(gfp(f))";
clasohm@923
    24
by (EVERY1 [rtac gfp_least, rtac subset_trans, atac,
paulson@5316
    25
            etac monoD, rtac gfp_upperbound, atac]);
clasohm@923
    26
qed "gfp_lemma2";
clasohm@923
    27
paulson@5316
    28
Goal "mono(f) ==> f(gfp(f)) <= gfp(f)";
paulson@5316
    29
by (EVERY1 [rtac gfp_upperbound, rtac monoD, assume_tac,
paulson@5316
    30
            etac gfp_lemma2]);
clasohm@923
    31
qed "gfp_lemma3";
clasohm@923
    32
paulson@5316
    33
Goal "mono(f) ==> gfp(f) = f(gfp(f))";
paulson@5316
    34
by (REPEAT (ares_tac [equalityI,gfp_lemma2,gfp_lemma3] 1));
nipkow@10186
    35
qed "gfp_unfold";
clasohm@923
    36
clasohm@923
    37
(*** Coinduction rules for greatest fixed points ***)
clasohm@923
    38
clasohm@923
    39
(*weak version*)
paulson@5148
    40
Goal "[| a: X;  X <= f(X) |] ==> a : gfp(f)";
clasohm@923
    41
by (rtac (gfp_upperbound RS subsetD) 1);
paulson@5148
    42
by Auto_tac;
clasohm@923
    43
qed "weak_coinduct";
clasohm@923
    44
paulson@10067
    45
Goal "[| X <= f(X Un gfp(f));  mono(f) |] ==>  \
clasohm@923
    46
\    X Un gfp(f) <= f(X Un gfp(f))";
paulson@10067
    47
by (blast_tac (claset() addDs [gfp_lemma2, mono_Un]) 1); 
clasohm@923
    48
qed "coinduct_lemma";
clasohm@923
    49
clasohm@923
    50
(*strong version, thanks to Coen & Frost*)
paulson@5148
    51
Goal "[| mono(f);  a: X;  X <= f(X Un gfp(f)) |] ==> a : gfp(f)";
clasohm@923
    52
by (rtac (coinduct_lemma RSN (2, weak_coinduct)) 1);
clasohm@923
    53
by (REPEAT (ares_tac [UnI1, Un_least] 1));
clasohm@923
    54
qed "coinduct";
clasohm@923
    55
paulson@10067
    56
Goal "[| mono(f);  a: gfp(f) |] ==> a: f(X Un gfp(f))";
paulson@10067
    57
by (blast_tac (claset() addDs [gfp_lemma2, mono_Un]) 1); 
clasohm@923
    58
qed "gfp_fun_UnI2";
clasohm@923
    59
clasohm@923
    60
(***  Even Stronger version of coinduct  [by Martin Coen]
clasohm@923
    61
         - instead of the condition  X <= f(X)
clasohm@923
    62
                           consider  X <= (f(X) Un f(f(X)) ...) Un gfp(X) ***)
clasohm@923
    63
paulson@5316
    64
Goal "mono(f) ==> mono(%x. f(x) Un X Un B)";
paulson@5316
    65
by (REPEAT (ares_tac [subset_refl, monoI, Un_mono] 1 ORELSE etac monoD 1));
clasohm@923
    66
qed "coinduct3_mono_lemma";
clasohm@923
    67
paulson@10067
    68
Goal "[| X <= f(lfp(%x. f(x) Un X Un gfp(f)));  mono(f) |] ==> \
wenzelm@3842
    69
\    lfp(%x. f(x) Un X Un gfp(f)) <= f(lfp(%x. f(x) Un X Un gfp(f)))";
clasohm@923
    70
by (rtac subset_trans 1);
paulson@10067
    71
by (etac (coinduct3_mono_lemma RS lfp_lemma3) 1);
clasohm@923
    72
by (rtac (Un_least RS Un_least) 1);
clasohm@923
    73
by (rtac subset_refl 1);
paulson@10067
    74
by (assume_tac 1); 
nipkow@10186
    75
by (rtac (gfp_unfold RS equalityD1 RS subset_trans) 1);
paulson@10067
    76
by (assume_tac 1);
paulson@10067
    77
by (rtac monoD 1 THEN assume_tac 1);
nipkow@10186
    78
by (stac (coinduct3_mono_lemma RS lfp_unfold) 1);
paulson@10067
    79
by Auto_tac;  
clasohm@923
    80
qed "coinduct3_lemma";
clasohm@923
    81
paulson@5316
    82
Goal
paulson@5316
    83
  "[| mono(f);  a:X;  X <= f(lfp(%x. f(x) Un X Un gfp(f))) |] ==> a : gfp(f)";
clasohm@923
    84
by (rtac (coinduct3_lemma RSN (2,weak_coinduct)) 1);
nipkow@10186
    85
by (resolve_tac [coinduct3_mono_lemma RS lfp_unfold RS ssubst] 1);
paulson@5316
    86
by Auto_tac;
clasohm@923
    87
qed "coinduct3";
clasohm@923
    88
clasohm@923
    89
nipkow@10186
    90
(** Definition forms of gfp_unfold and coinduct, to control unfolding **)
clasohm@923
    91
paulson@10067
    92
Goal "[| A==gfp(f);  mono(f) |] ==> A = f(A)";
nipkow@10186
    93
by (auto_tac (claset() addSIs [gfp_unfold], simpset()));  
nipkow@10186
    94
qed "def_gfp_unfold";
clasohm@923
    95
paulson@10067
    96
Goal "[| A==gfp(f);  mono(f);  a:X;  X <= f(X Un A) |] ==> a: A";
paulson@10067
    97
by (auto_tac (claset() addSIs [coinduct], simpset()));  
clasohm@923
    98
qed "def_coinduct";
clasohm@923
    99
clasohm@923
   100
(*The version used in the induction/coinduction package*)
paulson@5316
   101
val prems = Goal
clasohm@923
   102
    "[| A == gfp(%w. Collect(P(w)));  mono(%w. Collect(P(w)));  \
clasohm@923
   103
\       a: X;  !!z. z: X ==> P (X Un A) z |] ==> \
clasohm@923
   104
\    a : A";
clasohm@923
   105
by (rtac def_coinduct 1);
clasohm@923
   106
by (REPEAT (ares_tac (prems @ [subsetI,CollectI]) 1));
clasohm@923
   107
qed "def_Collect_coinduct";
clasohm@923
   108
paulson@10067
   109
Goal "[| A==gfp(f); mono(f);  a:X;  X <= f(lfp(%x. f(x) Un X Un A)) |] \
paulson@10067
   110
\     ==> a: A";
paulson@10067
   111
by (auto_tac (claset() addSIs [coinduct3], simpset()));  
clasohm@923
   112
qed "def_coinduct3";
clasohm@923
   113
clasohm@923
   114
(*Monotonicity of gfp!*)
paulson@5316
   115
val [prem] = Goal "[| !!Z. f(Z)<=g(Z) |] ==> gfp(f) <= gfp(g)";
clasohm@1465
   116
by (rtac (gfp_upperbound RS gfp_least) 1);
clasohm@1465
   117
by (etac (prem RSN (2,subset_trans)) 1);
clasohm@923
   118
qed "gfp_mono";