src/CCL/gfp.ML
 author oheimb Fri Jun 02 20:38:28 2000 +0200 (2000-06-02) changeset 9028 8a1ec8f05f14 parent 0 a5a9c433f639 permissions -rw-r--r--
 clasohm@0 ` 1` ```(* Title: CCL/gfp ``` clasohm@0 ` 2` ``` ID: \$Id\$ ``` clasohm@0 ` 3` clasohm@0 ` 4` ```Modified version of ``` clasohm@0 ` 5` ``` Title: HOL/gfp ``` clasohm@0 ` 6` ``` Author: Lawrence C Paulson, Cambridge University Computer Laboratory ``` clasohm@0 ` 7` ``` Copyright 1993 University of Cambridge ``` clasohm@0 ` 8` clasohm@0 ` 9` ```For gfp.thy. The Knaster-Tarski Theorem for greatest fixed points. ``` clasohm@0 ` 10` ```*) ``` clasohm@0 ` 11` clasohm@0 ` 12` ```open Gfp; ``` clasohm@0 ` 13` clasohm@0 ` 14` ```(*** Proof of Knaster-Tarski Theorem using gfp ***) ``` clasohm@0 ` 15` clasohm@0 ` 16` ```(* gfp(f) is the least upper bound of {u. u <= f(u)} *) ``` clasohm@0 ` 17` clasohm@0 ` 18` ```val prems = goalw Gfp.thy [gfp_def] "[| A <= f(A) |] ==> A <= gfp(f)"; ``` clasohm@0 ` 19` ```by (rtac (CollectI RS Union_upper) 1); ``` clasohm@0 ` 20` ```by (resolve_tac prems 1); ``` clasohm@0 ` 21` ```val gfp_upperbound = result(); ``` clasohm@0 ` 22` clasohm@0 ` 23` ```val prems = goalw Gfp.thy [gfp_def] ``` clasohm@0 ` 24` ``` "[| !!u. u <= f(u) ==> u<=A |] ==> gfp(f) <= A"; ``` clasohm@0 ` 25` ```by (REPEAT (ares_tac ([Union_least]@prems) 1)); ``` clasohm@0 ` 26` ```by (etac CollectD 1); ``` clasohm@0 ` 27` ```val gfp_least = result(); ``` clasohm@0 ` 28` clasohm@0 ` 29` ```val [mono] = goal Gfp.thy "mono(f) ==> gfp(f) <= f(gfp(f))"; ``` clasohm@0 ` 30` ```by (EVERY1 [rtac gfp_least, rtac subset_trans, atac, ``` clasohm@0 ` 31` ``` rtac (mono RS monoD), rtac gfp_upperbound, atac]); ``` clasohm@0 ` 32` ```val gfp_lemma2 = result(); ``` clasohm@0 ` 33` clasohm@0 ` 34` ```val [mono] = goal Gfp.thy "mono(f) ==> f(gfp(f)) <= gfp(f)"; ``` clasohm@0 ` 35` ```by (EVERY1 [rtac gfp_upperbound, rtac (mono RS monoD), ``` clasohm@0 ` 36` ``` rtac gfp_lemma2, rtac mono]); ``` clasohm@0 ` 37` ```val gfp_lemma3 = result(); ``` clasohm@0 ` 38` clasohm@0 ` 39` ```val [mono] = goal Gfp.thy "mono(f) ==> gfp(f) = f(gfp(f))"; ``` clasohm@0 ` 40` ```by (REPEAT (resolve_tac [equalityI,gfp_lemma2,gfp_lemma3,mono] 1)); ``` clasohm@0 ` 41` ```val gfp_Tarski = result(); ``` clasohm@0 ` 42` clasohm@0 ` 43` ```(*** Coinduction rules for greatest fixed points ***) ``` clasohm@0 ` 44` clasohm@0 ` 45` ```(*weak version*) ``` clasohm@0 ` 46` ```val prems = goal Gfp.thy ``` clasohm@0 ` 47` ``` "[| a: A; A <= f(A) |] ==> a : gfp(f)"; ``` clasohm@0 ` 48` ```by (rtac (gfp_upperbound RS subsetD) 1); ``` clasohm@0 ` 49` ```by (REPEAT (ares_tac prems 1)); ``` clasohm@0 ` 50` ```val coinduct = result(); ``` clasohm@0 ` 51` clasohm@0 ` 52` ```val [prem,mono] = goal Gfp.thy ``` clasohm@0 ` 53` ``` "[| A <= f(A) Un gfp(f); mono(f) |] ==> \ ``` clasohm@0 ` 54` ```\ A Un gfp(f) <= f(A Un gfp(f))"; ``` clasohm@0 ` 55` ```by (rtac subset_trans 1); ``` clasohm@0 ` 56` ```by (rtac (mono RS mono_Un) 2); ``` clasohm@0 ` 57` ```by (rtac (mono RS gfp_Tarski RS subst) 1); ``` clasohm@0 ` 58` ```by (rtac (prem RS Un_least) 1); ``` clasohm@0 ` 59` ```by (rtac Un_upper2 1); ``` clasohm@0 ` 60` ```val coinduct2_lemma = result(); ``` clasohm@0 ` 61` clasohm@0 ` 62` ```(*strong version, thanks to Martin Coen*) ``` clasohm@0 ` 63` ```val prems = goal Gfp.thy ``` clasohm@0 ` 64` ``` "[| a: A; A <= f(A) Un gfp(f); mono(f) |] ==> a : gfp(f)"; ``` clasohm@0 ` 65` ```by (rtac (coinduct2_lemma RSN (2,coinduct)) 1); ``` clasohm@0 ` 66` ```by (REPEAT (resolve_tac (prems@[UnI1]) 1)); ``` clasohm@0 ` 67` ```val coinduct2 = result(); ``` clasohm@0 ` 68` clasohm@0 ` 69` ```(*** Even Stronger version of coinduct [by Martin Coen] ``` clasohm@0 ` 70` ``` - instead of the condition A <= f(A) ``` clasohm@0 ` 71` ``` consider A <= (f(A) Un f(f(A)) ...) Un gfp(A) ***) ``` clasohm@0 ` 72` clasohm@0 ` 73` ```val [prem] = goal Gfp.thy "mono(f) ==> mono(%x.f(x) Un A Un B)"; ``` clasohm@0 ` 74` ```by (REPEAT (ares_tac [subset_refl, monoI, Un_mono, prem RS monoD] 1)); ``` clasohm@0 ` 75` ```val coinduct3_mono_lemma= result(); ``` clasohm@0 ` 76` clasohm@0 ` 77` ```val [prem,mono] = goal Gfp.thy ``` clasohm@0 ` 78` ``` "[| A <= f(lfp(%x.f(x) Un A Un gfp(f))); mono(f) |] ==> \ ``` clasohm@0 ` 79` ```\ lfp(%x.f(x) Un A Un gfp(f)) <= f(lfp(%x.f(x) Un A Un gfp(f)))"; ``` clasohm@0 ` 80` ```by (rtac subset_trans 1); ``` clasohm@0 ` 81` ```br (mono RS coinduct3_mono_lemma RS lfp_lemma3) 1; ``` clasohm@0 ` 82` ```by (rtac (Un_least RS Un_least) 1); ``` clasohm@0 ` 83` ```br subset_refl 1; ``` clasohm@0 ` 84` ```br prem 1; ``` clasohm@0 ` 85` ```br (mono RS gfp_Tarski RS equalityD1 RS subset_trans) 1; ``` clasohm@0 ` 86` ```by (rtac (mono RS monoD) 1); ``` clasohm@0 ` 87` ```by (rtac (mono RS coinduct3_mono_lemma RS lfp_Tarski RS ssubst) 1); ``` clasohm@0 ` 88` ```by (rtac Un_upper2 1); ``` clasohm@0 ` 89` ```val coinduct3_lemma = result(); ``` clasohm@0 ` 90` clasohm@0 ` 91` ```val prems = goal Gfp.thy ``` clasohm@0 ` 92` ``` "[| a:A; A <= f(lfp(%x.f(x) Un A Un gfp(f))); mono(f) |] ==> a : gfp(f)"; ``` clasohm@0 ` 93` ```by (rtac (coinduct3_lemma RSN (2,coinduct)) 1); ``` clasohm@0 ` 94` ```brs (prems RL [coinduct3_mono_lemma RS lfp_Tarski RS ssubst]) 1; ``` clasohm@0 ` 95` ```br (UnI2 RS UnI1) 1; ``` clasohm@0 ` 96` ```by (REPEAT (resolve_tac prems 1)); ``` clasohm@0 ` 97` ```val coinduct3 = result(); ``` clasohm@0 ` 98` clasohm@0 ` 99` clasohm@0 ` 100` ```(** Definition forms of gfp_Tarski, to control unfolding **) ``` clasohm@0 ` 101` clasohm@0 ` 102` ```val [rew,mono] = goal Gfp.thy "[| h==gfp(f); mono(f) |] ==> h = f(h)"; ``` clasohm@0 ` 103` ```by (rewtac rew); ``` clasohm@0 ` 104` ```by (rtac (mono RS gfp_Tarski) 1); ``` clasohm@0 ` 105` ```val def_gfp_Tarski = result(); ``` clasohm@0 ` 106` clasohm@0 ` 107` ```val rew::prems = goal Gfp.thy ``` clasohm@0 ` 108` ``` "[| h==gfp(f); a:A; A <= f(A) |] ==> a: h"; ``` clasohm@0 ` 109` ```by (rewtac rew); ``` clasohm@0 ` 110` ```by (REPEAT (ares_tac (prems @ [coinduct]) 1)); ``` clasohm@0 ` 111` ```val def_coinduct = result(); ``` clasohm@0 ` 112` clasohm@0 ` 113` ```val rew::prems = goal Gfp.thy ``` clasohm@0 ` 114` ``` "[| h==gfp(f); a:A; A <= f(A) Un h; mono(f) |] ==> a: h"; ``` clasohm@0 ` 115` ```by (rewtac rew); ``` clasohm@0 ` 116` ```by (REPEAT (ares_tac (map (rewrite_rule [rew]) prems @ [coinduct2]) 1)); ``` clasohm@0 ` 117` ```val def_coinduct2 = result(); ``` clasohm@0 ` 118` clasohm@0 ` 119` ```val rew::prems = goal Gfp.thy ``` clasohm@0 ` 120` ``` "[| h==gfp(f); a:A; A <= f(lfp(%x.f(x) Un A Un h)); mono(f) |] ==> a: h"; ``` clasohm@0 ` 121` ```by (rewtac rew); ``` clasohm@0 ` 122` ```by (REPEAT (ares_tac (map (rewrite_rule [rew]) prems @ [coinduct3]) 1)); ``` clasohm@0 ` 123` ```val def_coinduct3 = result(); ``` clasohm@0 ` 124` clasohm@0 ` 125` ```(*Monotonicity of gfp!*) ``` clasohm@0 ` 126` ```val prems = goal Gfp.thy ``` clasohm@0 ` 127` ``` "[| mono(f); !!Z. f(Z)<=g(Z) |] ==> gfp(f) <= gfp(g)"; ``` clasohm@0 ` 128` ```by (rtac gfp_upperbound 1); ``` clasohm@0 ` 129` ```by (rtac subset_trans 1); ``` clasohm@0 ` 130` ```by (rtac gfp_lemma2 1); ``` clasohm@0 ` 131` ```by (resolve_tac prems 1); ``` clasohm@0 ` 132` ```by (resolve_tac prems 1); ``` clasohm@0 ` 133` ```val gfp_mono = result(); ```