src/HOL/ex/Tarski.thy
author wenzelm
Wed Jun 22 10:09:20 2016 +0200 (2016-06-22)
changeset 63343 fb5d8a50c641
parent 62390 842917225d56
child 64915 2bb0152d82cf
permissions -rw-r--r--
bundle lifting_syntax;
     1 (*  Title:      HOL/ex/Tarski.thy
     2     Author:     Florian Kammüller, Cambridge University Computer Laboratory
     3 *)
     4 
     5 section \<open>The Full Theorem of Tarski\<close>
     6 
     7 theory Tarski
     8 imports Main "~~/src/HOL/Library/FuncSet"
     9 begin
    10 
    11 text \<open>
    12   Minimal version of lattice theory plus the full theorem of Tarski:
    13   The fixedpoints of a complete lattice themselves form a complete
    14   lattice.
    15 
    16   Illustrates first-class theories, using the Sigma representation of
    17   structures.  Tidied and converted to Isar by lcp.
    18 \<close>
    19 
    20 record 'a potype =
    21   pset  :: "'a set"
    22   order :: "('a * 'a) set"
    23 
    24 definition
    25   monotone :: "['a => 'a, 'a set, ('a *'a)set] => bool" where
    26   "monotone f A r = (\<forall>x\<in>A. \<forall>y\<in>A. (x, y): r --> ((f x), (f y)) : r)"
    27 
    28 definition
    29   least :: "['a => bool, 'a potype] => 'a" where
    30   "least P po = (SOME x. x: pset po & P x &
    31                        (\<forall>y \<in> pset po. P y --> (x,y): order po))"
    32 
    33 definition
    34   greatest :: "['a => bool, 'a potype] => 'a" where
    35   "greatest P po = (SOME x. x: pset po & P x &
    36                           (\<forall>y \<in> pset po. P y --> (y,x): order po))"
    37 
    38 definition
    39   lub  :: "['a set, 'a potype] => 'a" where
    40   "lub S po = least (%x. \<forall>y\<in>S. (y,x): order po) po"
    41 
    42 definition
    43   glb  :: "['a set, 'a potype] => 'a" where
    44   "glb S po = greatest (%x. \<forall>y\<in>S. (x,y): order po) po"
    45 
    46 definition
    47   isLub :: "['a set, 'a potype, 'a] => bool" where
    48   "isLub S po = (%L. (L: pset po & (\<forall>y\<in>S. (y,L): order po) &
    49                    (\<forall>z\<in>pset po. (\<forall>y\<in>S. (y,z): order po) --> (L,z): order po)))"
    50 
    51 definition
    52   isGlb :: "['a set, 'a potype, 'a] => bool" where
    53   "isGlb S po = (%G. (G: pset po & (\<forall>y\<in>S. (G,y): order po) &
    54                  (\<forall>z \<in> pset po. (\<forall>y\<in>S. (z,y): order po) --> (z,G): order po)))"
    55 
    56 definition
    57   "fix"    :: "[('a => 'a), 'a set] => 'a set" where
    58   "fix f A  = {x. x: A & f x = x}"
    59 
    60 definition
    61   interval :: "[('a*'a) set,'a, 'a ] => 'a set" where
    62   "interval r a b = {x. (a,x): r & (x,b): r}"
    63 
    64 
    65 definition
    66   Bot :: "'a potype => 'a" where
    67   "Bot po = least (%x. True) po"
    68 
    69 definition
    70   Top :: "'a potype => 'a" where
    71   "Top po = greatest (%x. True) po"
    72 
    73 definition
    74   PartialOrder :: "('a potype) set" where
    75   "PartialOrder = {P. refl_on (pset P) (order P) & antisym (order P) &
    76                        trans (order P)}"
    77 
    78 definition
    79   CompleteLattice :: "('a potype) set" where
    80   "CompleteLattice = {cl. cl: PartialOrder &
    81                         (\<forall>S. S \<subseteq> pset cl --> (\<exists>L. isLub S cl L)) &
    82                         (\<forall>S. S \<subseteq> pset cl --> (\<exists>G. isGlb S cl G))}"
    83 
    84 definition
    85   CLF_set :: "('a potype * ('a => 'a)) set" where
    86   "CLF_set = (SIGMA cl: CompleteLattice.
    87             {f. f: pset cl \<rightarrow> pset cl & monotone f (pset cl) (order cl)})"
    88 
    89 definition
    90   induced :: "['a set, ('a * 'a) set] => ('a *'a)set" where
    91   "induced A r = {(a,b). a : A & b: A & (a,b): r}"
    92 
    93 
    94 definition
    95   sublattice :: "('a potype * 'a set)set" where
    96   "sublattice =
    97       (SIGMA cl: CompleteLattice.
    98           {S. S \<subseteq> pset cl &
    99            (| pset = S, order = induced S (order cl) |): CompleteLattice})"
   100 
   101 abbreviation
   102   sublat :: "['a set, 'a potype] => bool"  ("_ <<= _" [51,50]50) where
   103   "S <<= cl == S : sublattice `` {cl}"
   104 
   105 definition
   106   dual :: "'a potype => 'a potype" where
   107   "dual po = (| pset = pset po, order = converse (order po) |)"
   108 
   109 locale S =
   110   fixes cl :: "'a potype"
   111     and A  :: "'a set"
   112     and r  :: "('a * 'a) set"
   113   defines A_def: "A == pset cl"
   114      and  r_def: "r == order cl"
   115 
   116 locale PO = S +
   117   assumes cl_po:  "cl : PartialOrder"
   118 
   119 locale CL = S +
   120   assumes cl_co:  "cl : CompleteLattice"
   121 
   122 sublocale CL < po?: PO
   123 apply (simp_all add: A_def r_def)
   124 apply unfold_locales
   125 using cl_co unfolding CompleteLattice_def by auto
   126 
   127 locale CLF = S +
   128   fixes f :: "'a => 'a"
   129     and P :: "'a set"
   130   assumes f_cl:  "(cl,f) : CLF_set" (*was the equivalent "f : CLF_set``{cl}"*)
   131   defines P_def: "P == fix f A"
   132 
   133 sublocale CLF < cl?: CL
   134 apply (simp_all add: A_def r_def)
   135 apply unfold_locales
   136 using f_cl unfolding CLF_set_def by auto
   137 
   138 locale Tarski = CLF +
   139   fixes Y     :: "'a set"
   140     and intY1 :: "'a set"
   141     and v     :: "'a"
   142   assumes
   143     Y_ss: "Y \<subseteq> P"
   144   defines
   145     intY1_def: "intY1 == interval r (lub Y cl) (Top cl)"
   146     and v_def: "v == glb {x. ((%x: intY1. f x) x, x): induced intY1 r &
   147                              x: intY1}
   148                       (| pset=intY1, order=induced intY1 r|)"
   149 
   150 
   151 subsection \<open>Partial Order\<close>
   152 
   153 lemma (in PO) dual:
   154   "PO (dual cl)"
   155 apply unfold_locales
   156 using cl_po
   157 unfolding PartialOrder_def dual_def
   158 by auto
   159 
   160 lemma (in PO) PO_imp_refl_on [simp]: "refl_on A r"
   161 apply (insert cl_po)
   162 apply (simp add: PartialOrder_def A_def r_def)
   163 done
   164 
   165 lemma (in PO) PO_imp_sym [simp]: "antisym r"
   166 apply (insert cl_po)
   167 apply (simp add: PartialOrder_def r_def)
   168 done
   169 
   170 lemma (in PO) PO_imp_trans [simp]: "trans r"
   171 apply (insert cl_po)
   172 apply (simp add: PartialOrder_def r_def)
   173 done
   174 
   175 lemma (in PO) reflE: "x \<in> A ==> (x, x) \<in> r"
   176 apply (insert cl_po)
   177 apply (simp add: PartialOrder_def refl_on_def A_def r_def)
   178 done
   179 
   180 lemma (in PO) antisymE: "[| (a, b) \<in> r; (b, a) \<in> r |] ==> a = b"
   181 apply (insert cl_po)
   182 apply (simp add: PartialOrder_def antisym_def r_def)
   183 done
   184 
   185 lemma (in PO) transE: "[| (a, b) \<in> r; (b, c) \<in> r|] ==> (a,c) \<in> r"
   186 apply (insert cl_po)
   187 apply (simp add: PartialOrder_def r_def)
   188 apply (unfold trans_def, fast)
   189 done
   190 
   191 lemma (in PO) monotoneE:
   192      "[| monotone f A r;  x \<in> A; y \<in> A; (x, y) \<in> r |] ==> (f x, f y) \<in> r"
   193 by (simp add: monotone_def)
   194 
   195 lemma (in PO) po_subset_po:
   196      "S \<subseteq> A ==> (| pset = S, order = induced S r |) \<in> PartialOrder"
   197 apply (simp (no_asm) add: PartialOrder_def)
   198 apply auto
   199 \<comment> \<open>refl\<close>
   200 apply (simp add: refl_on_def induced_def)
   201 apply (blast intro: reflE)
   202 \<comment> \<open>antisym\<close>
   203 apply (simp add: antisym_def induced_def)
   204 apply (blast intro: antisymE)
   205 \<comment> \<open>trans\<close>
   206 apply (simp add: trans_def induced_def)
   207 apply (blast intro: transE)
   208 done
   209 
   210 lemma (in PO) indE: "[| (x, y) \<in> induced S r; S \<subseteq> A |] ==> (x, y) \<in> r"
   211 by (simp add: add: induced_def)
   212 
   213 lemma (in PO) indI: "[| (x, y) \<in> r; x \<in> S; y \<in> S |] ==> (x, y) \<in> induced S r"
   214 by (simp add: add: induced_def)
   215 
   216 lemma (in CL) CL_imp_ex_isLub: "S \<subseteq> A ==> \<exists>L. isLub S cl L"
   217 apply (insert cl_co)
   218 apply (simp add: CompleteLattice_def A_def)
   219 done
   220 
   221 declare (in CL) cl_co [simp]
   222 
   223 lemma isLub_lub: "(\<exists>L. isLub S cl L) = isLub S cl (lub S cl)"
   224 by (simp add: lub_def least_def isLub_def some_eq_ex [symmetric])
   225 
   226 lemma isGlb_glb: "(\<exists>G. isGlb S cl G) = isGlb S cl (glb S cl)"
   227 by (simp add: glb_def greatest_def isGlb_def some_eq_ex [symmetric])
   228 
   229 lemma isGlb_dual_isLub: "isGlb S cl = isLub S (dual cl)"
   230 by (simp add: isLub_def isGlb_def dual_def converse_unfold)
   231 
   232 lemma isLub_dual_isGlb: "isLub S cl = isGlb S (dual cl)"
   233 by (simp add: isLub_def isGlb_def dual_def converse_unfold)
   234 
   235 lemma (in PO) dualPO: "dual cl \<in> PartialOrder"
   236 apply (insert cl_po)
   237 apply (simp add: PartialOrder_def dual_def refl_on_converse
   238                  trans_converse antisym_converse)
   239 done
   240 
   241 lemma Rdual:
   242      "\<forall>S. (S \<subseteq> A -->( \<exists>L. isLub S (| pset = A, order = r|) L))
   243       ==> \<forall>S. (S \<subseteq> A --> (\<exists>G. isGlb S (| pset = A, order = r|) G))"
   244 apply safe
   245 apply (rule_tac x = "lub {y. y \<in> A & (\<forall>k \<in> S. (y, k) \<in> r)}
   246                       (|pset = A, order = r|) " in exI)
   247 apply (drule_tac x = "{y. y \<in> A & (\<forall>k \<in> S. (y,k) \<in> r) }" in spec)
   248 apply (drule mp, fast)
   249 apply (simp add: isLub_lub isGlb_def)
   250 apply (simp add: isLub_def, blast)
   251 done
   252 
   253 lemma lub_dual_glb: "lub S cl = glb S (dual cl)"
   254 by (simp add: lub_def glb_def least_def greatest_def dual_def converse_unfold)
   255 
   256 lemma glb_dual_lub: "glb S cl = lub S (dual cl)"
   257 by (simp add: lub_def glb_def least_def greatest_def dual_def converse_unfold)
   258 
   259 lemma CL_subset_PO: "CompleteLattice \<subseteq> PartialOrder"
   260 by (simp add: PartialOrder_def CompleteLattice_def, fast)
   261 
   262 lemmas CL_imp_PO = CL_subset_PO [THEN subsetD]
   263 
   264 (*declare CL_imp_PO [THEN PO.PO_imp_refl, simp]
   265 declare CL_imp_PO [THEN PO.PO_imp_sym, simp]
   266 declare CL_imp_PO [THEN PO.PO_imp_trans, simp]*)
   267 
   268 lemma (in CL) CO_refl_on: "refl_on A r"
   269 by (rule PO_imp_refl_on)
   270 
   271 lemma (in CL) CO_antisym: "antisym r"
   272 by (rule PO_imp_sym)
   273 
   274 lemma (in CL) CO_trans: "trans r"
   275 by (rule PO_imp_trans)
   276 
   277 lemma CompleteLatticeI:
   278      "[| po \<in> PartialOrder; (\<forall>S. S \<subseteq> pset po --> (\<exists>L. isLub S po L));
   279          (\<forall>S. S \<subseteq> pset po --> (\<exists>G. isGlb S po G))|]
   280       ==> po \<in> CompleteLattice"
   281 apply (unfold CompleteLattice_def, blast)
   282 done
   283 
   284 lemma (in CL) CL_dualCL: "dual cl \<in> CompleteLattice"
   285 apply (insert cl_co)
   286 apply (simp add: CompleteLattice_def dual_def)
   287 apply (fold dual_def)
   288 apply (simp add: isLub_dual_isGlb [symmetric] isGlb_dual_isLub [symmetric]
   289                  dualPO)
   290 done
   291 
   292 lemma (in PO) dualA_iff: "pset (dual cl) = pset cl"
   293 by (simp add: dual_def)
   294 
   295 lemma (in PO) dualr_iff: "((x, y) \<in> (order(dual cl))) = ((y, x) \<in> order cl)"
   296 by (simp add: dual_def)
   297 
   298 lemma (in PO) monotone_dual:
   299      "monotone f (pset cl) (order cl) 
   300      ==> monotone f (pset (dual cl)) (order(dual cl))"
   301 by (simp add: monotone_def dualA_iff dualr_iff)
   302 
   303 lemma (in PO) interval_dual:
   304      "[| x \<in> A; y \<in> A|] ==> interval r x y = interval (order(dual cl)) y x"
   305 apply (simp add: interval_def dualr_iff)
   306 apply (fold r_def, fast)
   307 done
   308 
   309 lemma (in PO) trans:
   310   "(x, y) \<in> r \<Longrightarrow> (y, z) \<in> r \<Longrightarrow> (x, z) \<in> r"
   311 using cl_po apply (auto simp add: PartialOrder_def r_def)
   312 unfolding trans_def by blast 
   313 
   314 lemma (in PO) interval_not_empty:
   315   "interval r a b \<noteq> {} ==> (a, b) \<in> r"
   316 apply (simp add: interval_def)
   317 using trans by blast
   318 
   319 lemma (in PO) interval_imp_mem: "x \<in> interval r a b ==> (a, x) \<in> r"
   320 by (simp add: interval_def)
   321 
   322 lemma (in PO) left_in_interval:
   323      "[| a \<in> A; b \<in> A; interval r a b \<noteq> {} |] ==> a \<in> interval r a b"
   324 apply (simp (no_asm_simp) add: interval_def)
   325 apply (simp add: PO_imp_trans interval_not_empty)
   326 apply (simp add: reflE)
   327 done
   328 
   329 lemma (in PO) right_in_interval:
   330      "[| a \<in> A; b \<in> A; interval r a b \<noteq> {} |] ==> b \<in> interval r a b"
   331 apply (simp (no_asm_simp) add: interval_def)
   332 apply (simp add: PO_imp_trans interval_not_empty)
   333 apply (simp add: reflE)
   334 done
   335 
   336 
   337 subsection \<open>sublattice\<close>
   338 
   339 lemma (in PO) sublattice_imp_CL:
   340      "S <<= cl  ==> (| pset = S, order = induced S r |) \<in> CompleteLattice"
   341 by (simp add: sublattice_def CompleteLattice_def r_def)
   342 
   343 lemma (in CL) sublatticeI:
   344      "[| S \<subseteq> A; (| pset = S, order = induced S r |) \<in> CompleteLattice |]
   345       ==> S <<= cl"
   346 by (simp add: sublattice_def A_def r_def)
   347 
   348 lemma (in CL) dual:
   349   "CL (dual cl)"
   350 apply unfold_locales
   351 using cl_co unfolding CompleteLattice_def
   352 apply (simp add: dualPO isGlb_dual_isLub [symmetric] isLub_dual_isGlb [symmetric] dualA_iff)
   353 done
   354 
   355 
   356 subsection \<open>lub\<close>
   357 
   358 lemma (in CL) lub_unique: "[| S \<subseteq> A; isLub S cl x; isLub S cl L|] ==> x = L"
   359 apply (rule antisymE)
   360 apply (auto simp add: isLub_def r_def)
   361 done
   362 
   363 lemma (in CL) lub_upper: "[|S \<subseteq> A; x \<in> S|] ==> (x, lub S cl) \<in> r"
   364 apply (rule CL_imp_ex_isLub [THEN exE], assumption)
   365 apply (unfold lub_def least_def)
   366 apply (rule some_equality [THEN ssubst])
   367   apply (simp add: isLub_def)
   368  apply (simp add: lub_unique A_def isLub_def)
   369 apply (simp add: isLub_def r_def)
   370 done
   371 
   372 lemma (in CL) lub_least:
   373      "[| S \<subseteq> A; L \<in> A; \<forall>x \<in> S. (x,L) \<in> r |] ==> (lub S cl, L) \<in> r"
   374 apply (rule CL_imp_ex_isLub [THEN exE], assumption)
   375 apply (unfold lub_def least_def)
   376 apply (rule_tac s=x in some_equality [THEN ssubst])
   377   apply (simp add: isLub_def)
   378  apply (simp add: lub_unique A_def isLub_def)
   379 apply (simp add: isLub_def r_def A_def)
   380 done
   381 
   382 lemma (in CL) lub_in_lattice: "S \<subseteq> A ==> lub S cl \<in> A"
   383 apply (rule CL_imp_ex_isLub [THEN exE], assumption)
   384 apply (unfold lub_def least_def)
   385 apply (subst some_equality)
   386 apply (simp add: isLub_def)
   387 prefer 2 apply (simp add: isLub_def A_def)
   388 apply (simp add: lub_unique A_def isLub_def)
   389 done
   390 
   391 lemma (in CL) lubI:
   392      "[| S \<subseteq> A; L \<in> A; \<forall>x \<in> S. (x,L) \<in> r;
   393          \<forall>z \<in> A. (\<forall>y \<in> S. (y,z) \<in> r) --> (L,z) \<in> r |] ==> L = lub S cl"
   394 apply (rule lub_unique, assumption)
   395 apply (simp add: isLub_def A_def r_def)
   396 apply (unfold isLub_def)
   397 apply (rule conjI)
   398 apply (fold A_def r_def)
   399 apply (rule lub_in_lattice, assumption)
   400 apply (simp add: lub_upper lub_least)
   401 done
   402 
   403 lemma (in CL) lubIa: "[| S \<subseteq> A; isLub S cl L |] ==> L = lub S cl"
   404 by (simp add: lubI isLub_def A_def r_def)
   405 
   406 lemma (in CL) isLub_in_lattice: "isLub S cl L ==> L \<in> A"
   407 by (simp add: isLub_def  A_def)
   408 
   409 lemma (in CL) isLub_upper: "[|isLub S cl L; y \<in> S|] ==> (y, L) \<in> r"
   410 by (simp add: isLub_def r_def)
   411 
   412 lemma (in CL) isLub_least:
   413      "[| isLub S cl L; z \<in> A; \<forall>y \<in> S. (y, z) \<in> r|] ==> (L, z) \<in> r"
   414 by (simp add: isLub_def A_def r_def)
   415 
   416 lemma (in CL) isLubI:
   417      "[| L \<in> A; \<forall>y \<in> S. (y, L) \<in> r;
   418          (\<forall>z \<in> A. (\<forall>y \<in> S. (y, z):r) --> (L, z) \<in> r)|] ==> isLub S cl L"
   419 by (simp add: isLub_def A_def r_def)
   420 
   421 
   422 subsection \<open>glb\<close>
   423 
   424 lemma (in CL) glb_in_lattice: "S \<subseteq> A ==> glb S cl \<in> A"
   425 apply (subst glb_dual_lub)
   426 apply (simp add: A_def)
   427 apply (rule dualA_iff [THEN subst])
   428 apply (rule CL.lub_in_lattice)
   429 apply (rule dual)
   430 apply (simp add: dualA_iff)
   431 done
   432 
   433 lemma (in CL) glb_lower: "[|S \<subseteq> A; x \<in> S|] ==> (glb S cl, x) \<in> r"
   434 apply (subst glb_dual_lub)
   435 apply (simp add: r_def)
   436 apply (rule dualr_iff [THEN subst])
   437 apply (rule CL.lub_upper)
   438 apply (rule dual)
   439 apply (simp add: dualA_iff A_def, assumption)
   440 done
   441 
   442 text \<open>
   443   Reduce the sublattice property by using substructural properties;
   444   abandoned see \<open>Tarski_4.ML\<close>.
   445 \<close>
   446 
   447 lemma (in CLF) [simp]:
   448     "f: pset cl \<rightarrow> pset cl & monotone f (pset cl) (order cl)"
   449 apply (insert f_cl)
   450 apply (simp add: CLF_set_def)
   451 done
   452 
   453 declare (in CLF) f_cl [simp]
   454 
   455 
   456 lemma (in CLF) f_in_funcset: "f \<in> A \<rightarrow> A"
   457 by (simp add: A_def)
   458 
   459 lemma (in CLF) monotone_f: "monotone f A r"
   460 by (simp add: A_def r_def)
   461 
   462 lemma (in CLF) CLF_dual: "(dual cl, f) \<in> CLF_set"
   463 apply (simp add: CLF_set_def  CL_dualCL monotone_dual)
   464 apply (simp add: dualA_iff)
   465 done
   466 
   467 lemma (in CLF) dual:
   468   "CLF (dual cl) f"
   469 apply (rule CLF.intro)
   470 apply (rule CLF_dual)
   471 done
   472 
   473 
   474 subsection \<open>fixed points\<close>
   475 
   476 lemma fix_subset: "fix f A \<subseteq> A"
   477 by (simp add: fix_def, fast)
   478 
   479 lemma fix_imp_eq: "x \<in> fix f A ==> f x = x"
   480 by (simp add: fix_def)
   481 
   482 lemma fixf_subset:
   483      "[| A \<subseteq> B; x \<in> fix (%y: A. f y) A |] ==> x \<in> fix f B"
   484 by (simp add: fix_def, auto)
   485 
   486 
   487 subsection \<open>lemmas for Tarski, lub\<close>
   488 lemma (in CLF) lubH_le_flubH:
   489      "H = {x. (x, f x) \<in> r & x \<in> A} ==> (lub H cl, f (lub H cl)) \<in> r"
   490 apply (rule lub_least, fast)
   491 apply (rule f_in_funcset [THEN funcset_mem])
   492 apply (rule lub_in_lattice, fast)
   493 \<comment> \<open>\<open>\<forall>x:H. (x, f (lub H r)) \<in> r\<close>\<close>
   494 apply (rule ballI)
   495 apply (rule transE)
   496 \<comment> \<open>instantiates \<open>(x, ???z) \<in> order cl to (x, f x)\<close>,\<close>
   497 \<comment> \<open>because of the def of \<open>H\<close>\<close>
   498 apply fast
   499 \<comment> \<open>so it remains to show \<open>(f x, f (lub H cl)) \<in> r\<close>\<close>
   500 apply (rule_tac f = "f" in monotoneE)
   501 apply (rule monotone_f, fast)
   502 apply (rule lub_in_lattice, fast)
   503 apply (rule lub_upper, fast)
   504 apply assumption
   505 done
   506 
   507 lemma (in CLF) flubH_le_lubH:
   508      "[|  H = {x. (x, f x) \<in> r & x \<in> A} |] ==> (f (lub H cl), lub H cl) \<in> r"
   509 apply (rule lub_upper, fast)
   510 apply (rule_tac t = "H" in ssubst, assumption)
   511 apply (rule CollectI)
   512 apply (rule conjI)
   513 apply (rule_tac [2] f_in_funcset [THEN funcset_mem])
   514 apply (rule_tac [2] lub_in_lattice)
   515 prefer 2 apply fast
   516 apply (rule_tac f = "f" in monotoneE)
   517 apply (rule monotone_f)
   518   apply (blast intro: lub_in_lattice)
   519  apply (blast intro: lub_in_lattice f_in_funcset [THEN funcset_mem])
   520 apply (simp add: lubH_le_flubH)
   521 done
   522 
   523 lemma (in CLF) lubH_is_fixp:
   524      "H = {x. (x, f x) \<in> r & x \<in> A} ==> lub H cl \<in> fix f A"
   525 apply (simp add: fix_def)
   526 apply (rule conjI)
   527 apply (rule lub_in_lattice, fast)
   528 apply (rule antisymE)
   529 apply (simp add: flubH_le_lubH)
   530 apply (simp add: lubH_le_flubH)
   531 done
   532 
   533 lemma (in CLF) fix_in_H:
   534      "[| H = {x. (x, f x) \<in> r & x \<in> A};  x \<in> P |] ==> x \<in> H"
   535 by (simp add: P_def fix_imp_eq [of _ f A] reflE CO_refl_on
   536                     fix_subset [of f A, THEN subsetD])
   537 
   538 lemma (in CLF) fixf_le_lubH:
   539      "H = {x. (x, f x) \<in> r & x \<in> A} ==> \<forall>x \<in> fix f A. (x, lub H cl) \<in> r"
   540 apply (rule ballI)
   541 apply (rule lub_upper, fast)
   542 apply (rule fix_in_H)
   543 apply (simp_all add: P_def)
   544 done
   545 
   546 lemma (in CLF) lubH_least_fixf:
   547      "H = {x. (x, f x) \<in> r & x \<in> A}
   548       ==> \<forall>L. (\<forall>y \<in> fix f A. (y,L) \<in> r) --> (lub H cl, L) \<in> r"
   549 apply (rule allI)
   550 apply (rule impI)
   551 apply (erule bspec)
   552 apply (rule lubH_is_fixp, assumption)
   553 done
   554 
   555 subsection \<open>Tarski fixpoint theorem 1, first part\<close>
   556 lemma (in CLF) T_thm_1_lub: "lub P cl = lub {x. (x, f x) \<in> r & x \<in> A} cl"
   557 apply (rule sym)
   558 apply (simp add: P_def)
   559 apply (rule lubI)
   560 apply (rule fix_subset)
   561 apply (rule lub_in_lattice, fast)
   562 apply (simp add: fixf_le_lubH)
   563 apply (simp add: lubH_least_fixf)
   564 done
   565 
   566 lemma (in CLF) glbH_is_fixp: "H = {x. (f x, x) \<in> r & x \<in> A} ==> glb H cl \<in> P"
   567   \<comment> \<open>Tarski for glb\<close>
   568 apply (simp add: glb_dual_lub P_def A_def r_def)
   569 apply (rule dualA_iff [THEN subst])
   570 apply (rule CLF.lubH_is_fixp)
   571 apply (rule dual)
   572 apply (simp add: dualr_iff dualA_iff)
   573 done
   574 
   575 lemma (in CLF) T_thm_1_glb: "glb P cl = glb {x. (f x, x) \<in> r & x \<in> A} cl"
   576 apply (simp add: glb_dual_lub P_def A_def r_def)
   577 apply (rule dualA_iff [THEN subst])
   578 apply (simp add: CLF.T_thm_1_lub [of _ f, OF dual]
   579                  dualPO CL_dualCL CLF_dual dualr_iff)
   580 done
   581 
   582 subsection \<open>interval\<close>
   583 
   584 lemma (in CLF) rel_imp_elem: "(x, y) \<in> r ==> x \<in> A"
   585 apply (insert CO_refl_on)
   586 apply (simp add: refl_on_def, blast)
   587 done
   588 
   589 lemma (in CLF) interval_subset: "[| a \<in> A; b \<in> A |] ==> interval r a b \<subseteq> A"
   590 apply (simp add: interval_def)
   591 apply (blast intro: rel_imp_elem)
   592 done
   593 
   594 lemma (in CLF) intervalI:
   595      "[| (a, x) \<in> r; (x, b) \<in> r |] ==> x \<in> interval r a b"
   596 by (simp add: interval_def)
   597 
   598 lemma (in CLF) interval_lemma1:
   599      "[| S \<subseteq> interval r a b; x \<in> S |] ==> (a, x) \<in> r"
   600 by (unfold interval_def, fast)
   601 
   602 lemma (in CLF) interval_lemma2:
   603      "[| S \<subseteq> interval r a b; x \<in> S |] ==> (x, b) \<in> r"
   604 by (unfold interval_def, fast)
   605 
   606 lemma (in CLF) a_less_lub:
   607      "[| S \<subseteq> A; S \<noteq> {};
   608          \<forall>x \<in> S. (a,x) \<in> r; \<forall>y \<in> S. (y, L) \<in> r |] ==> (a,L) \<in> r"
   609 by (blast intro: transE)
   610 
   611 lemma (in CLF) glb_less_b:
   612      "[| S \<subseteq> A; S \<noteq> {};
   613          \<forall>x \<in> S. (x,b) \<in> r; \<forall>y \<in> S. (G, y) \<in> r |] ==> (G,b) \<in> r"
   614 by (blast intro: transE)
   615 
   616 lemma (in CLF) S_intv_cl:
   617      "[| a \<in> A; b \<in> A; S \<subseteq> interval r a b |]==> S \<subseteq> A"
   618 by (simp add: subset_trans [OF _ interval_subset])
   619 
   620 lemma (in CLF) L_in_interval:
   621      "[| a \<in> A; b \<in> A; S \<subseteq> interval r a b;
   622          S \<noteq> {}; isLub S cl L; interval r a b \<noteq> {} |] ==> L \<in> interval r a b"
   623 apply (rule intervalI)
   624 apply (rule a_less_lub)
   625 prefer 2 apply assumption
   626 apply (simp add: S_intv_cl)
   627 apply (rule ballI)
   628 apply (simp add: interval_lemma1)
   629 apply (simp add: isLub_upper)
   630 \<comment> \<open>\<open>(L, b) \<in> r\<close>\<close>
   631 apply (simp add: isLub_least interval_lemma2)
   632 done
   633 
   634 lemma (in CLF) G_in_interval:
   635      "[| a \<in> A; b \<in> A; interval r a b \<noteq> {}; S \<subseteq> interval r a b; isGlb S cl G;
   636          S \<noteq> {} |] ==> G \<in> interval r a b"
   637 apply (simp add: interval_dual)
   638 apply (simp add: CLF.L_in_interval [of _ f, OF dual]
   639                  dualA_iff A_def isGlb_dual_isLub)
   640 done
   641 
   642 lemma (in CLF) intervalPO:
   643      "[| a \<in> A; b \<in> A; interval r a b \<noteq> {} |]
   644       ==> (| pset = interval r a b, order = induced (interval r a b) r |)
   645           \<in> PartialOrder"
   646 apply (rule po_subset_po)
   647 apply (simp add: interval_subset)
   648 done
   649 
   650 lemma (in CLF) intv_CL_lub:
   651  "[| a \<in> A; b \<in> A; interval r a b \<noteq> {} |]
   652   ==> \<forall>S. S \<subseteq> interval r a b -->
   653           (\<exists>L. isLub S (| pset = interval r a b,
   654                           order = induced (interval r a b) r |)  L)"
   655 apply (intro strip)
   656 apply (frule S_intv_cl [THEN CL_imp_ex_isLub])
   657 prefer 2 apply assumption
   658 apply assumption
   659 apply (erule exE)
   660 \<comment> \<open>define the lub for the interval as\<close>
   661 apply (rule_tac x = "if S = {} then a else L" in exI)
   662 apply (simp (no_asm_simp) add: isLub_def split del: if_split)
   663 apply (intro impI conjI)
   664 \<comment> \<open>\<open>(if S = {} then a else L) \<in> interval r a b\<close>\<close>
   665 apply (simp add: CL_imp_PO L_in_interval)
   666 apply (simp add: left_in_interval)
   667 \<comment> \<open>lub prop 1\<close>
   668 apply (case_tac "S = {}")
   669 \<comment> \<open>\<open>S = {}, y \<in> S = False => everything\<close>\<close>
   670 apply fast
   671 \<comment> \<open>\<open>S \<noteq> {}\<close>\<close>
   672 apply simp
   673 \<comment> \<open>\<open>\<forall>y:S. (y, L) \<in> induced (interval r a b) r\<close>\<close>
   674 apply (rule ballI)
   675 apply (simp add: induced_def  L_in_interval)
   676 apply (rule conjI)
   677 apply (rule subsetD)
   678 apply (simp add: S_intv_cl, assumption)
   679 apply (simp add: isLub_upper)
   680 \<comment> \<open>\<open>\<forall>z:interval r a b. (\<forall>y:S. (y, z) \<in> induced (interval r a b) r \<longrightarrow> (if S = {} then a else L, z) \<in> induced (interval r a b) r\<close>\<close>
   681 apply (rule ballI)
   682 apply (rule impI)
   683 apply (case_tac "S = {}")
   684 \<comment> \<open>\<open>S = {}\<close>\<close>
   685 apply simp
   686 apply (simp add: induced_def  interval_def)
   687 apply (rule conjI)
   688 apply (rule reflE, assumption)
   689 apply (rule interval_not_empty)
   690 apply (simp add: interval_def)
   691 \<comment> \<open>\<open>S \<noteq> {}\<close>\<close>
   692 apply simp
   693 apply (simp add: induced_def  L_in_interval)
   694 apply (rule isLub_least, assumption)
   695 apply (rule subsetD)
   696 prefer 2 apply assumption
   697 apply (simp add: S_intv_cl, fast)
   698 done
   699 
   700 lemmas (in CLF) intv_CL_glb = intv_CL_lub [THEN Rdual]
   701 
   702 lemma (in CLF) interval_is_sublattice:
   703      "[| a \<in> A; b \<in> A; interval r a b \<noteq> {} |]
   704         ==> interval r a b <<= cl"
   705 apply (rule sublatticeI)
   706 apply (simp add: interval_subset)
   707 apply (rule CompleteLatticeI)
   708 apply (simp add: intervalPO)
   709  apply (simp add: intv_CL_lub)
   710 apply (simp add: intv_CL_glb)
   711 done
   712 
   713 lemmas (in CLF) interv_is_compl_latt =
   714     interval_is_sublattice [THEN sublattice_imp_CL]
   715 
   716 
   717 subsection \<open>Top and Bottom\<close>
   718 lemma (in CLF) Top_dual_Bot: "Top cl = Bot (dual cl)"
   719 by (simp add: Top_def Bot_def least_def greatest_def dualA_iff dualr_iff)
   720 
   721 lemma (in CLF) Bot_dual_Top: "Bot cl = Top (dual cl)"
   722 by (simp add: Top_def Bot_def least_def greatest_def dualA_iff dualr_iff)
   723 
   724 lemma (in CLF) Bot_in_lattice: "Bot cl \<in> A"
   725 apply (simp add: Bot_def least_def)
   726 apply (rule_tac a="glb A cl" in someI2)
   727 apply (simp_all add: glb_in_lattice glb_lower 
   728                      r_def [symmetric] A_def [symmetric])
   729 done
   730 
   731 lemma (in CLF) Top_in_lattice: "Top cl \<in> A"
   732 apply (simp add: Top_dual_Bot A_def)
   733 apply (rule dualA_iff [THEN subst])
   734 apply (rule CLF.Bot_in_lattice [OF dual])
   735 done
   736 
   737 lemma (in CLF) Top_prop: "x \<in> A ==> (x, Top cl) \<in> r"
   738 apply (simp add: Top_def greatest_def)
   739 apply (rule_tac a="lub A cl" in someI2)
   740 apply (rule someI2)
   741 apply (simp_all add: lub_in_lattice lub_upper 
   742                      r_def [symmetric] A_def [symmetric])
   743 done
   744 
   745 lemma (in CLF) Bot_prop: "x \<in> A ==> (Bot cl, x) \<in> r"
   746 apply (simp add: Bot_dual_Top r_def)
   747 apply (rule dualr_iff [THEN subst])
   748 apply (rule CLF.Top_prop [OF dual])
   749 apply (simp add: dualA_iff A_def)
   750 done
   751 
   752 lemma (in CLF) Top_intv_not_empty: "x \<in> A  ==> interval r x (Top cl) \<noteq> {}"
   753 apply (rule notI)
   754 apply (drule_tac a = "Top cl" in equals0D)
   755 apply (simp add: interval_def)
   756 apply (simp add: refl_on_def Top_in_lattice Top_prop)
   757 done
   758 
   759 lemma (in CLF) Bot_intv_not_empty: "x \<in> A ==> interval r (Bot cl) x \<noteq> {}"
   760 apply (simp add: Bot_dual_Top)
   761 apply (subst interval_dual)
   762 prefer 2 apply assumption
   763 apply (simp add: A_def)
   764 apply (rule dualA_iff [THEN subst])
   765 apply (rule CLF.Top_in_lattice [OF dual])
   766 apply (rule CLF.Top_intv_not_empty [OF dual])
   767 apply (simp add: dualA_iff A_def)
   768 done
   769 
   770 subsection \<open>fixed points form a partial order\<close>
   771 
   772 lemma (in CLF) fixf_po: "(| pset = P, order = induced P r|) \<in> PartialOrder"
   773 by (simp add: P_def fix_subset po_subset_po)
   774 
   775 lemma (in Tarski) Y_subset_A: "Y \<subseteq> A"
   776 apply (rule subset_trans [OF _ fix_subset])
   777 apply (rule Y_ss [simplified P_def])
   778 done
   779 
   780 lemma (in Tarski) lubY_in_A: "lub Y cl \<in> A"
   781   by (rule Y_subset_A [THEN lub_in_lattice])
   782 
   783 lemma (in Tarski) lubY_le_flubY: "(lub Y cl, f (lub Y cl)) \<in> r"
   784 apply (rule lub_least)
   785 apply (rule Y_subset_A)
   786 apply (rule f_in_funcset [THEN funcset_mem])
   787 apply (rule lubY_in_A)
   788 \<comment> \<open>\<open>Y \<subseteq> P ==> f x = x\<close>\<close>
   789 apply (rule ballI)
   790 apply (rule_tac t = "x" in fix_imp_eq [THEN subst])
   791 apply (erule Y_ss [simplified P_def, THEN subsetD])
   792 \<comment> \<open>\<open>reduce (f x, f (lub Y cl)) \<in> r to (x, lub Y cl) \<in> r\<close> by monotonicity\<close>
   793 apply (rule_tac f = "f" in monotoneE)
   794 apply (rule monotone_f)
   795 apply (simp add: Y_subset_A [THEN subsetD])
   796 apply (rule lubY_in_A)
   797 apply (simp add: lub_upper Y_subset_A)
   798 done
   799 
   800 lemma (in Tarski) intY1_subset: "intY1 \<subseteq> A"
   801 apply (unfold intY1_def)
   802 apply (rule interval_subset)
   803 apply (rule lubY_in_A)
   804 apply (rule Top_in_lattice)
   805 done
   806 
   807 lemmas (in Tarski) intY1_elem = intY1_subset [THEN subsetD]
   808 
   809 lemma (in Tarski) intY1_f_closed: "x \<in> intY1 \<Longrightarrow> f x \<in> intY1"
   810 apply (simp add: intY1_def  interval_def)
   811 apply (rule conjI)
   812 apply (rule transE)
   813 apply (rule lubY_le_flubY)
   814 \<comment> \<open>\<open>(f (lub Y cl), f x) \<in> r\<close>\<close>
   815 apply (rule_tac f=f in monotoneE)
   816 apply (rule monotone_f)
   817 apply (rule lubY_in_A)
   818 apply (simp add: intY1_def interval_def  intY1_elem)
   819 apply (simp add: intY1_def  interval_def)
   820 \<comment> \<open>\<open>(f x, Top cl) \<in> r\<close>\<close>
   821 apply (rule Top_prop)
   822 apply (rule f_in_funcset [THEN funcset_mem])
   823 apply (simp add: intY1_def interval_def  intY1_elem)
   824 done
   825 
   826 lemma (in Tarski) intY1_mono:
   827      "monotone (%x: intY1. f x) intY1 (induced intY1 r)"
   828 apply (auto simp add: monotone_def induced_def intY1_f_closed)
   829 apply (blast intro: intY1_elem monotone_f [THEN monotoneE])
   830 done
   831 
   832 lemma (in Tarski) intY1_is_cl:
   833     "(| pset = intY1, order = induced intY1 r |) \<in> CompleteLattice"
   834 apply (unfold intY1_def)
   835 apply (rule interv_is_compl_latt)
   836 apply (rule lubY_in_A)
   837 apply (rule Top_in_lattice)
   838 apply (rule Top_intv_not_empty)
   839 apply (rule lubY_in_A)
   840 done
   841 
   842 lemma (in Tarski) v_in_P: "v \<in> P"
   843 apply (unfold P_def)
   844 apply (rule_tac A = "intY1" in fixf_subset)
   845 apply (rule intY1_subset)
   846 unfolding v_def
   847 apply (rule CLF.glbH_is_fixp [OF CLF.intro, unfolded CLF_set_def, of "\<lparr>pset = intY1, order = induced intY1 r\<rparr>", simplified])
   848 apply auto
   849 apply (rule intY1_is_cl)
   850 apply (erule intY1_f_closed)
   851 apply (rule intY1_mono)
   852 done
   853 
   854 lemma (in Tarski) z_in_interval:
   855      "[| z \<in> P; \<forall>y\<in>Y. (y, z) \<in> induced P r |] ==> z \<in> intY1"
   856 apply (unfold intY1_def P_def)
   857 apply (rule intervalI)
   858 prefer 2
   859  apply (erule fix_subset [THEN subsetD, THEN Top_prop])
   860 apply (rule lub_least)
   861 apply (rule Y_subset_A)
   862 apply (fast elim!: fix_subset [THEN subsetD])
   863 apply (simp add: induced_def)
   864 done
   865 
   866 lemma (in Tarski) f'z_in_int_rel: "[| z \<in> P; \<forall>y\<in>Y. (y, z) \<in> induced P r |]
   867       ==> ((%x: intY1. f x) z, z) \<in> induced intY1 r"
   868 apply (simp add: induced_def  intY1_f_closed z_in_interval P_def)
   869 apply (simp add: fix_imp_eq [of _ f A] fix_subset [of f A, THEN subsetD]
   870                  reflE)
   871 done
   872 
   873 lemma (in Tarski) tarski_full_lemma:
   874      "\<exists>L. isLub Y (| pset = P, order = induced P r |) L"
   875 apply (rule_tac x = "v" in exI)
   876 apply (simp add: isLub_def)
   877 \<comment> \<open>\<open>v \<in> P\<close>\<close>
   878 apply (simp add: v_in_P)
   879 apply (rule conjI)
   880 \<comment> \<open>\<open>v\<close> is lub\<close>
   881 \<comment> \<open>\<open>1. \<forall>y:Y. (y, v) \<in> induced P r\<close>\<close>
   882 apply (rule ballI)
   883 apply (simp add: induced_def subsetD v_in_P)
   884 apply (rule conjI)
   885 apply (erule Y_ss [THEN subsetD])
   886 apply (rule_tac b = "lub Y cl" in transE)
   887 apply (rule lub_upper)
   888 apply (rule Y_subset_A, assumption)
   889 apply (rule_tac b = "Top cl" in interval_imp_mem)
   890 apply (simp add: v_def)
   891 apply (fold intY1_def)
   892 apply (rule CL.glb_in_lattice [OF CL.intro [OF intY1_is_cl], simplified])
   893 apply auto
   894 apply (rule indI)
   895   prefer 3 apply assumption
   896  prefer 2 apply (simp add: v_in_P)
   897 apply (unfold v_def)
   898 apply (rule indE)
   899 apply (rule_tac [2] intY1_subset)
   900 apply (rule CL.glb_lower [OF CL.intro [OF intY1_is_cl], simplified])
   901   apply (simp add: CL_imp_PO intY1_is_cl)
   902  apply force
   903 apply (simp add: induced_def intY1_f_closed z_in_interval)
   904 apply (simp add: P_def fix_imp_eq [of _ f A] reflE
   905                  fix_subset [of f A, THEN subsetD])
   906 done
   907 
   908 lemma CompleteLatticeI_simp:
   909      "[| (| pset = A, order = r |) \<in> PartialOrder;
   910          \<forall>S. S \<subseteq> A --> (\<exists>L. isLub S (| pset = A, order = r |)  L) |]
   911     ==> (| pset = A, order = r |) \<in> CompleteLattice"
   912 by (simp add: CompleteLatticeI Rdual)
   913 
   914 theorem (in CLF) Tarski_full:
   915      "(| pset = P, order = induced P r|) \<in> CompleteLattice"
   916 apply (rule CompleteLatticeI_simp)
   917 apply (rule fixf_po, clarify)
   918 apply (simp add: P_def A_def r_def)
   919 apply (rule Tarski.tarski_full_lemma [OF Tarski.intro [OF _ Tarski_axioms.intro]])
   920 proof - show "CLF cl f" .. qed
   921 
   922 end