src/HOL/Gfp.ML
author wenzelm
Thu Mar 11 13:20:35 1999 +0100 (1999-03-11)
changeset 6349 f7750d816c21
parent 5316 7a8975451a89
child 9422 4b6bc2b347e5
permissions -rw-r--r--
removed foo_build_completed -- now handled by session management (via usedir);
clasohm@1465
     1
(*  Title:      HOL/gfp
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
open Gfp;
clasohm@923
    10
clasohm@923
    11
(*** Proof of Knaster-Tarski Theorem using gfp ***)
clasohm@923
    12
clasohm@923
    13
(* gfp(f) is the least upper bound of {u. u <= f(u)} *)
clasohm@923
    14
paulson@5148
    15
Goalw [gfp_def] "[| X <= f(X) |] ==> X <= gfp(f)";
paulson@5148
    16
by (etac (CollectI RS Union_upper) 1);
clasohm@923
    17
qed "gfp_upperbound";
clasohm@923
    18
clasohm@923
    19
val prems = goalw Gfp.thy [gfp_def]
clasohm@923
    20
    "[| !!u. u <= f(u) ==> u<=X |] ==> gfp(f) <= X";
clasohm@923
    21
by (REPEAT (ares_tac ([Union_least]@prems) 1));
clasohm@923
    22
by (etac CollectD 1);
clasohm@923
    23
qed "gfp_least";
clasohm@923
    24
paulson@5316
    25
Goal "mono(f) ==> gfp(f) <= f(gfp(f))";
clasohm@923
    26
by (EVERY1 [rtac gfp_least, rtac subset_trans, atac,
paulson@5316
    27
            etac monoD, rtac gfp_upperbound, atac]);
clasohm@923
    28
qed "gfp_lemma2";
clasohm@923
    29
paulson@5316
    30
Goal "mono(f) ==> f(gfp(f)) <= gfp(f)";
paulson@5316
    31
by (EVERY1 [rtac gfp_upperbound, rtac monoD, assume_tac,
paulson@5316
    32
            etac gfp_lemma2]);
clasohm@923
    33
qed "gfp_lemma3";
clasohm@923
    34
paulson@5316
    35
Goal "mono(f) ==> gfp(f) = f(gfp(f))";
paulson@5316
    36
by (REPEAT (ares_tac [equalityI,gfp_lemma2,gfp_lemma3] 1));
clasohm@923
    37
qed "gfp_Tarski";
clasohm@923
    38
clasohm@923
    39
(*** Coinduction rules for greatest fixed points ***)
clasohm@923
    40
clasohm@923
    41
(*weak version*)
paulson@5148
    42
Goal "[| a: X;  X <= f(X) |] ==> a : gfp(f)";
clasohm@923
    43
by (rtac (gfp_upperbound RS subsetD) 1);
paulson@5148
    44
by Auto_tac;
clasohm@923
    45
qed "weak_coinduct";
clasohm@923
    46
clasohm@923
    47
val [prem,mono] = goal Gfp.thy
clasohm@923
    48
    "[| X <= f(X Un gfp(f));  mono(f) |] ==>  \
clasohm@923
    49
\    X Un gfp(f) <= f(X Un gfp(f))";
clasohm@923
    50
by (rtac (prem RS Un_least) 1);
clasohm@923
    51
by (rtac (mono RS gfp_lemma2 RS subset_trans) 1);
clasohm@923
    52
by (rtac (Un_upper2 RS subset_trans) 1);
clasohm@923
    53
by (rtac (mono RS mono_Un) 1);
clasohm@923
    54
qed "coinduct_lemma";
clasohm@923
    55
clasohm@923
    56
(*strong version, thanks to Coen & Frost*)
paulson@5148
    57
Goal "[| mono(f);  a: X;  X <= f(X Un gfp(f)) |] ==> a : gfp(f)";
clasohm@923
    58
by (rtac (coinduct_lemma RSN (2, weak_coinduct)) 1);
clasohm@923
    59
by (REPEAT (ares_tac [UnI1, Un_least] 1));
clasohm@923
    60
qed "coinduct";
clasohm@923
    61
clasohm@923
    62
val [mono,prem] = goal Gfp.thy
clasohm@923
    63
    "[| mono(f);  a: gfp(f) |] ==> a: f(X Un gfp(f))";
clasohm@1465
    64
by (rtac (mono RS mono_Un RS subsetD) 1);
clasohm@1465
    65
by (rtac (mono RS gfp_lemma2 RS subsetD RS UnI2) 1);
clasohm@923
    66
by (rtac prem 1);
clasohm@923
    67
qed "gfp_fun_UnI2";
clasohm@923
    68
clasohm@923
    69
(***  Even Stronger version of coinduct  [by Martin Coen]
clasohm@923
    70
         - instead of the condition  X <= f(X)
clasohm@923
    71
                           consider  X <= (f(X) Un f(f(X)) ...) Un gfp(X) ***)
clasohm@923
    72
paulson@5316
    73
Goal "mono(f) ==> mono(%x. f(x) Un X Un B)";
paulson@5316
    74
by (REPEAT (ares_tac [subset_refl, monoI, Un_mono] 1 ORELSE etac monoD 1));
clasohm@923
    75
qed "coinduct3_mono_lemma";
clasohm@923
    76
clasohm@923
    77
val [prem,mono] = goal Gfp.thy
wenzelm@3842
    78
    "[| X <= f(lfp(%x. f(x) Un X Un gfp(f)));  mono(f) |] ==> \
wenzelm@3842
    79
\    lfp(%x. f(x) Un X Un gfp(f)) <= f(lfp(%x. f(x) Un X Un gfp(f)))";
clasohm@923
    80
by (rtac subset_trans 1);
clasohm@923
    81
by (rtac (mono RS coinduct3_mono_lemma RS lfp_lemma3) 1);
clasohm@923
    82
by (rtac (Un_least RS Un_least) 1);
clasohm@923
    83
by (rtac subset_refl 1);
clasohm@923
    84
by (rtac prem 1);
clasohm@923
    85
by (rtac (mono RS gfp_Tarski RS equalityD1 RS subset_trans) 1);
clasohm@923
    86
by (rtac (mono RS monoD) 1);
paulson@2036
    87
by (stac (mono RS coinduct3_mono_lemma RS lfp_Tarski) 1);
clasohm@923
    88
by (rtac Un_upper2 1);
clasohm@923
    89
qed "coinduct3_lemma";
clasohm@923
    90
paulson@5316
    91
Goal
paulson@5316
    92
  "[| mono(f);  a:X;  X <= f(lfp(%x. f(x) Un X Un gfp(f))) |] ==> a : gfp(f)";
clasohm@923
    93
by (rtac (coinduct3_lemma RSN (2,weak_coinduct)) 1);
paulson@5316
    94
by (resolve_tac [coinduct3_mono_lemma RS lfp_Tarski RS ssubst] 1);
paulson@5316
    95
by Auto_tac;
clasohm@923
    96
qed "coinduct3";
clasohm@923
    97
clasohm@923
    98
clasohm@923
    99
(** Definition forms of gfp_Tarski and coinduct, to control unfolding **)
clasohm@923
   100
clasohm@923
   101
val [rew,mono] = goal Gfp.thy "[| A==gfp(f);  mono(f) |] ==> A = f(A)";
clasohm@923
   102
by (rewtac rew);
clasohm@923
   103
by (rtac (mono RS gfp_Tarski) 1);
clasohm@923
   104
qed "def_gfp_Tarski";
clasohm@923
   105
clasohm@923
   106
val rew::prems = goal Gfp.thy
clasohm@923
   107
    "[| A==gfp(f);  mono(f);  a:X;  X <= f(X Un A) |] ==> a: A";
clasohm@923
   108
by (rewtac rew);
clasohm@923
   109
by (REPEAT (ares_tac (map (rewrite_rule [rew]) prems @ [coinduct]) 1));
clasohm@923
   110
qed "def_coinduct";
clasohm@923
   111
clasohm@923
   112
(*The version used in the induction/coinduction package*)
paulson@5316
   113
val prems = Goal
clasohm@923
   114
    "[| A == gfp(%w. Collect(P(w)));  mono(%w. Collect(P(w)));  \
clasohm@923
   115
\       a: X;  !!z. z: X ==> P (X Un A) z |] ==> \
clasohm@923
   116
\    a : A";
clasohm@923
   117
by (rtac def_coinduct 1);
clasohm@923
   118
by (REPEAT (ares_tac (prems @ [subsetI,CollectI]) 1));
clasohm@923
   119
qed "def_Collect_coinduct";
clasohm@923
   120
clasohm@923
   121
val rew::prems = goal Gfp.thy
wenzelm@3842
   122
    "[| A==gfp(f); mono(f);  a:X;  X <= f(lfp(%x. f(x) Un X Un A)) |] ==> a: A";
clasohm@923
   123
by (rewtac rew);
clasohm@923
   124
by (REPEAT (ares_tac (map (rewrite_rule [rew]) prems @ [coinduct3]) 1));
clasohm@923
   125
qed "def_coinduct3";
clasohm@923
   126
clasohm@923
   127
(*Monotonicity of gfp!*)
paulson@5316
   128
val [prem] = Goal "[| !!Z. f(Z)<=g(Z) |] ==> gfp(f) <= gfp(g)";
clasohm@1465
   129
by (rtac (gfp_upperbound RS gfp_least) 1);
clasohm@1465
   130
by (etac (prem RSN (2,subset_trans)) 1);
clasohm@923
   131
qed "gfp_mono";