src/HOL/Gfp.ML
author wenzelm
Sun, 29 Nov 1998 13:16:47 +0100
changeset 5989 9670dae0143d
parent 5316 7a8975451a89
child 9422 4b6bc2b347e5
permissions -rw-r--r--
proof_general_trans (experimental);
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1465
5d7a7e439cec expanded tabs
clasohm
parents: 923
diff changeset
     1
(*  Title:      HOL/gfp
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
     2
    ID:         $Id$
1465
5d7a7e439cec expanded tabs
clasohm
parents: 923
diff changeset
     3
    Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
     4
    Copyright   1993  University of Cambridge
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
     5
5148
74919e8f221c More tidying and removal of "\!\!... from Goal commands
paulson
parents: 5069
diff changeset
     6
The Knaster-Tarski Theorem for greatest fixed points.
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
     7
*)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
     8
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
     9
open Gfp;
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    10
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    11
(*** Proof of Knaster-Tarski Theorem using gfp ***)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    12
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    13
(* gfp(f) is the least upper bound of {u. u <= f(u)} *)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    14
5148
74919e8f221c More tidying and removal of "\!\!... from Goal commands
paulson
parents: 5069
diff changeset
    15
Goalw [gfp_def] "[| X <= f(X) |] ==> X <= gfp(f)";
74919e8f221c More tidying and removal of "\!\!... from Goal commands
paulson
parents: 5069
diff changeset
    16
by (etac (CollectI RS Union_upper) 1);
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    17
qed "gfp_upperbound";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    18
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    19
val prems = goalw Gfp.thy [gfp_def]
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    20
    "[| !!u. u <= f(u) ==> u<=X |] ==> gfp(f) <= X";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    21
by (REPEAT (ares_tac ([Union_least]@prems) 1));
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    22
by (etac CollectD 1);
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    23
qed "gfp_least";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    24
5316
7a8975451a89 even more tidying of Goal commands
paulson
parents: 5148
diff changeset
    25
Goal "mono(f) ==> gfp(f) <= f(gfp(f))";
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    26
by (EVERY1 [rtac gfp_least, rtac subset_trans, atac,
5316
7a8975451a89 even more tidying of Goal commands
paulson
parents: 5148
diff changeset
    27
            etac monoD, rtac gfp_upperbound, atac]);
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    28
qed "gfp_lemma2";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    29
5316
7a8975451a89 even more tidying of Goal commands
paulson
parents: 5148
diff changeset
    30
Goal "mono(f) ==> f(gfp(f)) <= gfp(f)";
7a8975451a89 even more tidying of Goal commands
paulson
parents: 5148
diff changeset
    31
by (EVERY1 [rtac gfp_upperbound, rtac monoD, assume_tac,
7a8975451a89 even more tidying of Goal commands
paulson
parents: 5148
diff changeset
    32
            etac gfp_lemma2]);
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    33
qed "gfp_lemma3";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    34
5316
7a8975451a89 even more tidying of Goal commands
paulson
parents: 5148
diff changeset
    35
Goal "mono(f) ==> gfp(f) = f(gfp(f))";
7a8975451a89 even more tidying of Goal commands
paulson
parents: 5148
diff changeset
    36
by (REPEAT (ares_tac [equalityI,gfp_lemma2,gfp_lemma3] 1));
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    37
qed "gfp_Tarski";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    38
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    39
(*** Coinduction rules for greatest fixed points ***)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    40
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    41
(*weak version*)
5148
74919e8f221c More tidying and removal of "\!\!... from Goal commands
paulson
parents: 5069
diff changeset
    42
Goal "[| a: X;  X <= f(X) |] ==> a : gfp(f)";
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    43
by (rtac (gfp_upperbound RS subsetD) 1);
5148
74919e8f221c More tidying and removal of "\!\!... from Goal commands
paulson
parents: 5069
diff changeset
    44
by Auto_tac;
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    45
qed "weak_coinduct";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    46
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    47
val [prem,mono] = goal Gfp.thy
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    48
    "[| X <= f(X Un gfp(f));  mono(f) |] ==>  \
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    49
\    X Un gfp(f) <= f(X Un gfp(f))";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    50
by (rtac (prem RS Un_least) 1);
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    51
by (rtac (mono RS gfp_lemma2 RS subset_trans) 1);
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    52
by (rtac (Un_upper2 RS subset_trans) 1);
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    53
by (rtac (mono RS mono_Un) 1);
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    54
qed "coinduct_lemma";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    55
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    56
(*strong version, thanks to Coen & Frost*)
5148
74919e8f221c More tidying and removal of "\!\!... from Goal commands
paulson
parents: 5069
diff changeset
    57
Goal "[| mono(f);  a: X;  X <= f(X Un gfp(f)) |] ==> a : gfp(f)";
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    58
by (rtac (coinduct_lemma RSN (2, weak_coinduct)) 1);
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    59
by (REPEAT (ares_tac [UnI1, Un_least] 1));
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    60
qed "coinduct";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    61
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    62
val [mono,prem] = goal Gfp.thy
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    63
    "[| mono(f);  a: gfp(f) |] ==> a: f(X Un gfp(f))";
1465
5d7a7e439cec expanded tabs
clasohm
parents: 923
diff changeset
    64
by (rtac (mono RS mono_Un RS subsetD) 1);
5d7a7e439cec expanded tabs
clasohm
parents: 923
diff changeset
    65
by (rtac (mono RS gfp_lemma2 RS subsetD RS UnI2) 1);
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    66
by (rtac prem 1);
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    67
qed "gfp_fun_UnI2";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    68
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    69
(***  Even Stronger version of coinduct  [by Martin Coen]
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    70
         - instead of the condition  X <= f(X)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    71
                           consider  X <= (f(X) Un f(f(X)) ...) Un gfp(X) ***)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    72
5316
7a8975451a89 even more tidying of Goal commands
paulson
parents: 5148
diff changeset
    73
Goal "mono(f) ==> mono(%x. f(x) Un X Un B)";
7a8975451a89 even more tidying of Goal commands
paulson
parents: 5148
diff changeset
    74
by (REPEAT (ares_tac [subset_refl, monoI, Un_mono] 1 ORELSE etac monoD 1));
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    75
qed "coinduct3_mono_lemma";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    76
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    77
val [prem,mono] = goal Gfp.thy
3842
b55686a7b22c fixed dots;
wenzelm
parents: 2036
diff changeset
    78
    "[| X <= f(lfp(%x. f(x) Un X Un gfp(f)));  mono(f) |] ==> \
b55686a7b22c fixed dots;
wenzelm
parents: 2036
diff changeset
    79
\    lfp(%x. f(x) Un X Un gfp(f)) <= f(lfp(%x. f(x) Un X Un gfp(f)))";
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    80
by (rtac subset_trans 1);
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    81
by (rtac (mono RS coinduct3_mono_lemma RS lfp_lemma3) 1);
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    82
by (rtac (Un_least RS Un_least) 1);
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    83
by (rtac subset_refl 1);
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    84
by (rtac prem 1);
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    85
by (rtac (mono RS gfp_Tarski RS equalityD1 RS subset_trans) 1);
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    86
by (rtac (mono RS monoD) 1);
2036
62ff902eeffc Ran expandshort; used stac instead of ssubst
paulson
parents: 1465
diff changeset
    87
by (stac (mono RS coinduct3_mono_lemma RS lfp_Tarski) 1);
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    88
by (rtac Un_upper2 1);
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    89
qed "coinduct3_lemma";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    90
5316
7a8975451a89 even more tidying of Goal commands
paulson
parents: 5148
diff changeset
    91
Goal
7a8975451a89 even more tidying of Goal commands
paulson
parents: 5148
diff changeset
    92
  "[| mono(f);  a:X;  X <= f(lfp(%x. f(x) Un X Un gfp(f))) |] ==> a : gfp(f)";
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    93
by (rtac (coinduct3_lemma RSN (2,weak_coinduct)) 1);
5316
7a8975451a89 even more tidying of Goal commands
paulson
parents: 5148
diff changeset
    94
by (resolve_tac [coinduct3_mono_lemma RS lfp_Tarski RS ssubst] 1);
7a8975451a89 even more tidying of Goal commands
paulson
parents: 5148
diff changeset
    95
by Auto_tac;
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    96
qed "coinduct3";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    97
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    98
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    99
(** Definition forms of gfp_Tarski and coinduct, to control unfolding **)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   100
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   101
val [rew,mono] = goal Gfp.thy "[| A==gfp(f);  mono(f) |] ==> A = f(A)";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   102
by (rewtac rew);
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   103
by (rtac (mono RS gfp_Tarski) 1);
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   104
qed "def_gfp_Tarski";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   105
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   106
val rew::prems = goal Gfp.thy
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   107
    "[| A==gfp(f);  mono(f);  a:X;  X <= f(X Un A) |] ==> a: A";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   108
by (rewtac rew);
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   109
by (REPEAT (ares_tac (map (rewrite_rule [rew]) prems @ [coinduct]) 1));
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   110
qed "def_coinduct";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   111
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   112
(*The version used in the induction/coinduction package*)
5316
7a8975451a89 even more tidying of Goal commands
paulson
parents: 5148
diff changeset
   113
val prems = Goal
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   114
    "[| A == gfp(%w. Collect(P(w)));  mono(%w. Collect(P(w)));  \
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   115
\       a: X;  !!z. z: X ==> P (X Un A) z |] ==> \
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   116
\    a : A";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   117
by (rtac def_coinduct 1);
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   118
by (REPEAT (ares_tac (prems @ [subsetI,CollectI]) 1));
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   119
qed "def_Collect_coinduct";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   120
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   121
val rew::prems = goal Gfp.thy
3842
b55686a7b22c fixed dots;
wenzelm
parents: 2036
diff changeset
   122
    "[| A==gfp(f); mono(f);  a:X;  X <= f(lfp(%x. f(x) Un X Un A)) |] ==> a: A";
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   123
by (rewtac rew);
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   124
by (REPEAT (ares_tac (map (rewrite_rule [rew]) prems @ [coinduct3]) 1));
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   125
qed "def_coinduct3";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   126
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   127
(*Monotonicity of gfp!*)
5316
7a8975451a89 even more tidying of Goal commands
paulson
parents: 5148
diff changeset
   128
val [prem] = Goal "[| !!Z. f(Z)<=g(Z) |] ==> gfp(f) <= gfp(g)";
1465
5d7a7e439cec expanded tabs
clasohm
parents: 923
diff changeset
   129
by (rtac (gfp_upperbound RS gfp_least) 1);
5d7a7e439cec expanded tabs
clasohm
parents: 923
diff changeset
   130
by (etac (prem RSN (2,subset_trans)) 1);
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   131
qed "gfp_mono";