src/HOL/Gfp.ML
author wenzelm
Fri, 03 Jul 1998 18:05:03 +0200
changeset 5126 01cbf154d926
parent 5069 3ea049f7979d
child 5148 74919e8f221c
permissions -rw-r--r--
theory Main includes everything;
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
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
     6
For gfp.thy.  The Knaster-Tarski Theorem for greatest fixed points.
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
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    15
val prems = goalw Gfp.thy [gfp_def] "[| X <= f(X) |] ==> X <= gfp(f)";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    16
by (rtac (CollectI RS Union_upper) 1);
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    17
by (resolve_tac prems 1);
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    18
qed "gfp_upperbound";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    19
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    20
val prems = goalw Gfp.thy [gfp_def]
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    21
    "[| !!u. u <= f(u) ==> u<=X |] ==> gfp(f) <= X";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    22
by (REPEAT (ares_tac ([Union_least]@prems) 1));
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    23
by (etac CollectD 1);
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    24
qed "gfp_least";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    25
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    26
val [mono] = goal Gfp.thy "mono(f) ==> gfp(f) <= f(gfp(f))";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    27
by (EVERY1 [rtac gfp_least, rtac subset_trans, atac,
1465
5d7a7e439cec expanded tabs
clasohm
parents: 923
diff changeset
    28
            rtac (mono RS monoD), rtac gfp_upperbound, atac]);
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    29
qed "gfp_lemma2";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    30
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    31
val [mono] = goal Gfp.thy "mono(f) ==> f(gfp(f)) <= gfp(f)";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    32
by (EVERY1 [rtac gfp_upperbound, rtac (mono RS monoD), 
1465
5d7a7e439cec expanded tabs
clasohm
parents: 923
diff changeset
    33
            rtac gfp_lemma2, rtac mono]);
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    34
qed "gfp_lemma3";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    35
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    36
val [mono] = goal Gfp.thy "mono(f) ==> gfp(f) = f(gfp(f))";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    37
by (REPEAT (resolve_tac [equalityI,gfp_lemma2,gfp_lemma3,mono] 1));
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    38
qed "gfp_Tarski";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    39
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    40
(*** Coinduction rules for greatest fixed points ***)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    41
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    42
(*weak version*)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    43
val prems = goal Gfp.thy
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    44
    "[| a: X;  X <= f(X) |] ==> a : gfp(f)";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    45
by (rtac (gfp_upperbound RS subsetD) 1);
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    46
by (REPEAT (ares_tac prems 1));
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    47
qed "weak_coinduct";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    48
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    49
val [prem,mono] = goal Gfp.thy
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    50
    "[| X <= f(X Un gfp(f));  mono(f) |] ==>  \
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    51
\    X Un gfp(f) <= f(X Un gfp(f))";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    52
by (rtac (prem RS Un_least) 1);
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    53
by (rtac (mono RS gfp_lemma2 RS subset_trans) 1);
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    54
by (rtac (Un_upper2 RS subset_trans) 1);
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    55
by (rtac (mono RS mono_Un) 1);
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    56
qed "coinduct_lemma";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    57
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    58
(*strong version, thanks to Coen & Frost*)
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 3842
diff changeset
    59
Goal
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    60
    "!!X. [| mono(f);  a: X;  X <= f(X Un gfp(f)) |] ==> a : gfp(f)";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    61
by (rtac (coinduct_lemma RSN (2, weak_coinduct)) 1);
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    62
by (REPEAT (ares_tac [UnI1, Un_least] 1));
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    63
qed "coinduct";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    64
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    65
val [mono,prem] = goal Gfp.thy
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    66
    "[| mono(f);  a: gfp(f) |] ==> a: f(X Un gfp(f))";
1465
5d7a7e439cec expanded tabs
clasohm
parents: 923
diff changeset
    67
by (rtac (mono RS mono_Un RS subsetD) 1);
5d7a7e439cec expanded tabs
clasohm
parents: 923
diff changeset
    68
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
    69
by (rtac prem 1);
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    70
qed "gfp_fun_UnI2";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    71
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    72
(***  Even Stronger version of coinduct  [by Martin Coen]
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    73
         - instead of the condition  X <= f(X)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    74
                           consider  X <= (f(X) Un f(f(X)) ...) Un gfp(X) ***)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    75
3842
b55686a7b22c fixed dots;
wenzelm
parents: 2036
diff changeset
    76
val [prem] = goal Gfp.thy "mono(f) ==> mono(%x. f(x) Un X Un B)";
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    77
by (REPEAT (ares_tac [subset_refl, monoI, Un_mono, prem RS monoD] 1));
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    78
qed "coinduct3_mono_lemma";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    79
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    80
val [prem,mono] = goal Gfp.thy
3842
b55686a7b22c fixed dots;
wenzelm
parents: 2036
diff changeset
    81
    "[| X <= f(lfp(%x. f(x) Un X Un gfp(f)));  mono(f) |] ==> \
b55686a7b22c fixed dots;
wenzelm
parents: 2036
diff changeset
    82
\    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
    83
by (rtac subset_trans 1);
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    84
by (rtac (mono RS coinduct3_mono_lemma RS lfp_lemma3) 1);
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    85
by (rtac (Un_least RS Un_least) 1);
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    86
by (rtac subset_refl 1);
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    87
by (rtac prem 1);
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    88
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
    89
by (rtac (mono RS monoD) 1);
2036
62ff902eeffc Ran expandshort; used stac instead of ssubst
paulson
parents: 1465
diff changeset
    90
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
    91
by (rtac Un_upper2 1);
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    92
qed "coinduct3_lemma";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    93
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    94
val prems = goal Gfp.thy
3842
b55686a7b22c fixed dots;
wenzelm
parents: 2036
diff changeset
    95
    "[| 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
    96
by (rtac (coinduct3_lemma RSN (2,weak_coinduct)) 1);
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    97
by (resolve_tac (prems RL [coinduct3_mono_lemma RS lfp_Tarski RS ssubst]) 1);
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    98
by (rtac (UnI2 RS UnI1) 1);
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    99
by (REPEAT (resolve_tac prems 1));
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   100
qed "coinduct3";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   101
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   102
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   103
(** Definition forms of gfp_Tarski and coinduct, to control unfolding **)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   104
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   105
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
   106
by (rewtac rew);
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   107
by (rtac (mono RS gfp_Tarski) 1);
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   108
qed "def_gfp_Tarski";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   109
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   110
val rew::prems = goal Gfp.thy
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   111
    "[| 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
   112
by (rewtac rew);
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   113
by (REPEAT (ares_tac (map (rewrite_rule [rew]) prems @ [coinduct]) 1));
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   114
qed "def_coinduct";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   115
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   116
(*The version used in the induction/coinduction package*)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   117
val prems = goal Gfp.thy
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   118
    "[| A == gfp(%w. Collect(P(w)));  mono(%w. Collect(P(w)));  \
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   119
\       a: X;  !!z. z: X ==> P (X Un A) z |] ==> \
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   120
\    a : A";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   121
by (rtac def_coinduct 1);
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   122
by (REPEAT (ares_tac (prems @ [subsetI,CollectI]) 1));
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   123
qed "def_Collect_coinduct";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   124
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   125
val rew::prems = goal Gfp.thy
3842
b55686a7b22c fixed dots;
wenzelm
parents: 2036
diff changeset
   126
    "[| 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
   127
by (rewtac rew);
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   128
by (REPEAT (ares_tac (map (rewrite_rule [rew]) prems @ [coinduct3]) 1));
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   129
qed "def_coinduct3";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   130
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   131
(*Monotonicity of gfp!*)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   132
val prems = goal Gfp.thy
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   133
    "[| mono(f);  !!Z. f(Z)<=g(Z) |] ==> gfp(f) <= gfp(g)";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   134
by (rtac gfp_upperbound 1);
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   135
by (rtac subset_trans 1);
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   136
by (rtac gfp_lemma2 1);
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   137
by (resolve_tac prems 1);
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   138
by (resolve_tac prems 1);
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   139
val gfp_mono = result();
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   140
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   141
(*Monotonicity of gfp!*)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   142
val [prem] = goal Gfp.thy "[| !!Z. f(Z)<=g(Z) |] ==> gfp(f) <= gfp(g)";
1465
5d7a7e439cec expanded tabs
clasohm
parents: 923
diff changeset
   143
by (rtac (gfp_upperbound RS gfp_least) 1);
5d7a7e439cec expanded tabs
clasohm
parents: 923
diff changeset
   144
by (etac (prem RSN (2,subset_trans)) 1);
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   145
qed "gfp_mono";