src/HOL/BNF_Wellorder_Relation.thy
author wenzelm
Fri Jun 26 10:20:33 2015 +0200 (2015-06-26)
changeset 60585 48fdff264eb2
parent 58889 5b7a9633cfa8
child 60758 d8d85a8172b5
permissions -rw-r--r--
tuned whitespace;
blanchet@55056
     1
(*  Title:      HOL/BNF_Wellorder_Relation.thy
blanchet@48975
     2
    Author:     Andrei Popescu, TU Muenchen
blanchet@48975
     3
    Copyright   2012
blanchet@48975
     4
blanchet@55059
     5
Well-order relations as needed by bounded natural functors.
blanchet@48975
     6
*)
blanchet@48975
     7
wenzelm@58889
     8
section {* Well-Order Relations as Needed by Bounded Natural Functors *}
blanchet@48975
     9
blanchet@55056
    10
theory BNF_Wellorder_Relation
blanchet@55027
    11
imports Order_Relation
blanchet@48975
    12
begin
blanchet@48975
    13
blanchet@48975
    14
text{* In this section, we develop basic concepts and results pertaining
blanchet@48975
    15
to well-order relations.  Note that we consider well-order relations
blanchet@48975
    16
as {\em non-strict relations},
blanchet@48975
    17
i.e., as containing the diagonals of their fields. *}
blanchet@48975
    18
blanchet@55023
    19
locale wo_rel =
blanchet@55023
    20
  fixes r :: "'a rel"
blanchet@55023
    21
  assumes WELL: "Well_order r"
blanchet@48975
    22
begin
blanchet@48975
    23
blanchet@48975
    24
text{* The following context encompasses all this section. In other words,
blanchet@48975
    25
for the whole section, we consider a fixed well-order relation @{term "r"}. *}
blanchet@48975
    26
blanchet@48975
    27
(* context wo_rel  *)
blanchet@48975
    28
blanchet@55026
    29
abbreviation under where "under \<equiv> Order_Relation.under r"
blanchet@55026
    30
abbreviation underS where "underS \<equiv> Order_Relation.underS r"
blanchet@55026
    31
abbreviation Under where "Under \<equiv> Order_Relation.Under r"
blanchet@55026
    32
abbreviation UnderS where "UnderS \<equiv> Order_Relation.UnderS r"
blanchet@55026
    33
abbreviation above where "above \<equiv> Order_Relation.above r"
blanchet@55026
    34
abbreviation aboveS where "aboveS \<equiv> Order_Relation.aboveS r"
blanchet@55026
    35
abbreviation Above where "Above \<equiv> Order_Relation.Above r"
blanchet@55026
    36
abbreviation AboveS where "AboveS \<equiv> Order_Relation.AboveS r"
traytel@55173
    37
abbreviation ofilter where "ofilter \<equiv> Order_Relation.ofilter r"
traytel@55173
    38
lemmas ofilter_def = Order_Relation.ofilter_def[of r]
blanchet@55023
    39
blanchet@48975
    40
blanchet@48975
    41
subsection {* Auxiliaries *}
blanchet@48975
    42
blanchet@48975
    43
lemma REFL: "Refl r"
blanchet@48975
    44
using WELL order_on_defs[of _ r] by auto
blanchet@48975
    45
blanchet@48975
    46
lemma TRANS: "trans r"
blanchet@48975
    47
using WELL order_on_defs[of _ r] by auto
blanchet@48975
    48
blanchet@48975
    49
lemma ANTISYM: "antisym r"
blanchet@48975
    50
using WELL order_on_defs[of _ r] by auto
blanchet@48975
    51
blanchet@48975
    52
lemma TOTAL: "Total r"
blanchet@48975
    53
using WELL order_on_defs[of _ r] by auto
blanchet@48975
    54
blanchet@48975
    55
lemma TOTALS: "\<forall>a \<in> Field r. \<forall>b \<in> Field r. (a,b) \<in> r \<or> (b,a) \<in> r"
blanchet@48975
    56
using REFL TOTAL refl_on_def[of _ r] total_on_def[of _ r] by force
blanchet@48975
    57
blanchet@48975
    58
lemma LIN: "Linear_order r"
blanchet@48975
    59
using WELL well_order_on_def[of _ r] by auto
blanchet@48975
    60
blanchet@48975
    61
lemma WF: "wf (r - Id)"
blanchet@48975
    62
using WELL well_order_on_def[of _ r] by auto
blanchet@48975
    63
blanchet@48975
    64
lemma cases_Total:
blanchet@48975
    65
"\<And> phi a b. \<lbrakk>{a,b} <= Field r; ((a,b) \<in> r \<Longrightarrow> phi a b); ((b,a) \<in> r \<Longrightarrow> phi a b)\<rbrakk>
blanchet@48975
    66
             \<Longrightarrow> phi a b"
blanchet@48975
    67
using TOTALS by auto
blanchet@48975
    68
blanchet@48975
    69
lemma cases_Total3:
blanchet@48975
    70
"\<And> phi a b. \<lbrakk>{a,b} \<le> Field r; ((a,b) \<in> r - Id \<or> (b,a) \<in> r - Id \<Longrightarrow> phi a b);
blanchet@48975
    71
              (a = b \<Longrightarrow> phi a b)\<rbrakk>  \<Longrightarrow> phi a b"
blanchet@48975
    72
using TOTALS by auto
blanchet@48975
    73
blanchet@48975
    74
blanchet@55101
    75
subsection {* Well-founded induction and recursion adapted to non-strict well-order relations *}
blanchet@48975
    76
blanchet@48975
    77
text{* Here we provide induction and recursion principles specific to {\em non-strict}
blanchet@48975
    78
well-order relations.
blanchet@48975
    79
Although minor variations of those for well-founded relations, they will be useful
blanchet@48975
    80
for doing away with the tediousness of
blanchet@48975
    81
having to take out the diagonal each time in order to switch to a well-founded relation. *}
blanchet@48975
    82
blanchet@48975
    83
lemma well_order_induct:
blanchet@48975
    84
assumes IND: "\<And>x. \<forall>y. y \<noteq> x \<and> (y, x) \<in> r \<longrightarrow> P y \<Longrightarrow> P x"
blanchet@48975
    85
shows "P a"
blanchet@48975
    86
proof-
blanchet@48975
    87
  have "\<And>x. \<forall>y. (y, x) \<in> r - Id \<longrightarrow> P y \<Longrightarrow> P x"
blanchet@48975
    88
  using IND by blast
blanchet@48975
    89
  thus "P a" using WF wf_induct[of "r - Id" P a] by blast
blanchet@48975
    90
qed
blanchet@48975
    91
blanchet@48975
    92
definition
blanchet@48975
    93
worec :: "(('a \<Rightarrow> 'b) \<Rightarrow> 'a \<Rightarrow> 'b) \<Rightarrow> 'a \<Rightarrow> 'b"
blanchet@48975
    94
where
blanchet@48975
    95
"worec F \<equiv> wfrec (r - Id) F"
blanchet@48975
    96
blanchet@48975
    97
definition
blanchet@48975
    98
adm_wo :: "(('a \<Rightarrow> 'b) \<Rightarrow> 'a \<Rightarrow> 'b) \<Rightarrow> bool"
blanchet@48975
    99
where
blanchet@48975
   100
"adm_wo H \<equiv> \<forall>f g x. (\<forall>y \<in> underS x. f y = g y) \<longrightarrow> H f x = H g x"
blanchet@48975
   101
blanchet@48975
   102
lemma worec_fixpoint:
blanchet@48975
   103
assumes ADM: "adm_wo H"
blanchet@48975
   104
shows "worec H = H (worec H)"
blanchet@48975
   105
proof-
blanchet@48975
   106
  let ?rS = "r - Id"
blanchet@48975
   107
  have "adm_wf (r - Id) H"
blanchet@48975
   108
  unfolding adm_wf_def
blanchet@55023
   109
  using ADM adm_wo_def[of H] underS_def[of r] by auto
blanchet@48975
   110
  hence "wfrec ?rS H = H (wfrec ?rS H)"
blanchet@48975
   111
  using WF wfrec_fixpoint[of ?rS H] by simp
blanchet@48975
   112
  thus ?thesis unfolding worec_def .
blanchet@48975
   113
qed
blanchet@48975
   114
blanchet@48975
   115
blanchet@55101
   116
subsection {* The notions of maximum, minimum, supremum, successor and order filter *}
blanchet@48975
   117
blanchet@48975
   118
text{*
blanchet@48975
   119
We define the successor {\em of a set}, and not of an element (the latter is of course
blanchet@48975
   120
a particular case).  Also, we define the maximum {\em of two elements}, @{text "max2"},
blanchet@48975
   121
and the minimum {\em of a set}, @{text "minim"} -- we chose these variants since we
blanchet@48975
   122
consider them the most useful for well-orders.  The minimum is defined in terms of the
blanchet@48975
   123
auxiliary relational operator @{text "isMinim"}.  Then, supremum and successor are
blanchet@48975
   124
defined in terms of minimum as expected.
blanchet@48975
   125
The minimum is only meaningful for non-empty sets, and the successor is only
blanchet@48975
   126
meaningful for sets for which strict upper bounds exist.
blanchet@48975
   127
Order filters for well-orders are also known as ``initial segments". *}
blanchet@48975
   128
blanchet@48975
   129
definition max2 :: "'a \<Rightarrow> 'a \<Rightarrow> 'a"
blanchet@48975
   130
where "max2 a b \<equiv> if (a,b) \<in> r then b else a"
blanchet@48975
   131
blanchet@48975
   132
definition isMinim :: "'a set \<Rightarrow> 'a \<Rightarrow> bool"
blanchet@48975
   133
where "isMinim A b \<equiv> b \<in> A \<and> (\<forall>a \<in> A. (b,a) \<in> r)"
blanchet@48975
   134
blanchet@48975
   135
definition minim :: "'a set \<Rightarrow> 'a"
blanchet@48975
   136
where "minim A \<equiv> THE b. isMinim A b"
blanchet@48975
   137
blanchet@48975
   138
definition supr :: "'a set \<Rightarrow> 'a"
blanchet@48975
   139
where "supr A \<equiv> minim (Above A)"
blanchet@48975
   140
blanchet@48975
   141
definition suc :: "'a set \<Rightarrow> 'a"
blanchet@48975
   142
where "suc A \<equiv> minim (AboveS A)"
blanchet@48975
   143
blanchet@48975
   144
blanchet@48975
   145
subsubsection {* Properties of max2 *}
blanchet@48975
   146
blanchet@48975
   147
lemma max2_greater_among:
blanchet@48975
   148
assumes "a \<in> Field r" and "b \<in> Field r"
blanchet@48975
   149
shows "(a, max2 a b) \<in> r \<and> (b, max2 a b) \<in> r \<and> max2 a b \<in> {a,b}"
blanchet@48975
   150
proof-
blanchet@48975
   151
  {assume "(a,b) \<in> r"
blanchet@48975
   152
   hence ?thesis using max2_def assms REFL refl_on_def
blanchet@48975
   153
   by (auto simp add: refl_on_def)
blanchet@48975
   154
  }
blanchet@48975
   155
  moreover
blanchet@48975
   156
  {assume "a = b"
blanchet@48975
   157
   hence "(a,b) \<in> r" using REFL  assms
blanchet@48975
   158
   by (auto simp add: refl_on_def)
blanchet@48975
   159
  }
blanchet@48975
   160
  moreover
blanchet@48975
   161
  {assume *: "a \<noteq> b \<and> (b,a) \<in> r"
blanchet@48975
   162
   hence "(a,b) \<notin> r" using ANTISYM
blanchet@48975
   163
   by (auto simp add: antisym_def)
blanchet@48975
   164
   hence ?thesis using * max2_def assms REFL refl_on_def
blanchet@48975
   165
   by (auto simp add: refl_on_def)
blanchet@48975
   166
  }
blanchet@48975
   167
  ultimately show ?thesis using assms TOTAL
blanchet@48975
   168
  total_on_def[of "Field r" r] by blast
blanchet@48975
   169
qed
blanchet@48975
   170
blanchet@48975
   171
lemma max2_greater:
blanchet@48975
   172
assumes "a \<in> Field r" and "b \<in> Field r"
blanchet@48975
   173
shows "(a, max2 a b) \<in> r \<and> (b, max2 a b) \<in> r"
blanchet@48975
   174
using assms by (auto simp add: max2_greater_among)
blanchet@48975
   175
blanchet@48975
   176
lemma max2_among:
blanchet@48975
   177
assumes "a \<in> Field r" and "b \<in> Field r"
blanchet@48975
   178
shows "max2 a b \<in> {a, b}"
blanchet@48975
   179
using assms max2_greater_among[of a b] by simp
blanchet@48975
   180
blanchet@48975
   181
lemma max2_equals1:
blanchet@48975
   182
assumes "a \<in> Field r" and "b \<in> Field r"
blanchet@48975
   183
shows "(max2 a b = a) = ((b,a) \<in> r)"
blanchet@48975
   184
using assms ANTISYM unfolding antisym_def using TOTALS
blanchet@48975
   185
by(auto simp add: max2_def max2_among)
blanchet@48975
   186
blanchet@48975
   187
lemma max2_equals2:
blanchet@48975
   188
assumes "a \<in> Field r" and "b \<in> Field r"
blanchet@48975
   189
shows "(max2 a b = b) = ((a,b) \<in> r)"
blanchet@48975
   190
using assms ANTISYM unfolding antisym_def using TOTALS
blanchet@48975
   191
unfolding max2_def by auto
blanchet@48975
   192
blanchet@48975
   193
blanchet@48975
   194
subsubsection {* Existence and uniqueness for isMinim and well-definedness of minim *}
blanchet@48975
   195
blanchet@48975
   196
lemma isMinim_unique:
blanchet@48975
   197
assumes MINIM: "isMinim B a" and MINIM': "isMinim B a'"
blanchet@48975
   198
shows "a = a'"
blanchet@48975
   199
proof-
blanchet@48975
   200
  {have "a \<in> B"
blanchet@48975
   201
   using MINIM isMinim_def by simp
blanchet@48975
   202
   hence "(a',a) \<in> r"
blanchet@48975
   203
   using MINIM' isMinim_def by simp
blanchet@48975
   204
  }
blanchet@48975
   205
  moreover
blanchet@48975
   206
  {have "a' \<in> B"
blanchet@48975
   207
   using MINIM' isMinim_def by simp
blanchet@48975
   208
   hence "(a,a') \<in> r"
blanchet@48975
   209
   using MINIM isMinim_def by simp
blanchet@48975
   210
  }
blanchet@48975
   211
  ultimately
blanchet@48975
   212
  show ?thesis using ANTISYM antisym_def[of r] by blast
blanchet@48975
   213
qed
blanchet@48975
   214
blanchet@48975
   215
lemma Well_order_isMinim_exists:
blanchet@48975
   216
assumes SUB: "B \<le> Field r" and NE: "B \<noteq> {}"
blanchet@48975
   217
shows "\<exists>b. isMinim B b"
blanchet@48975
   218
proof-
traytel@51764
   219
  from spec[OF WF[unfolded wf_eq_minimal[of "r - Id"]], of B] NE obtain b where
traytel@51764
   220
  *: "b \<in> B \<and> (\<forall>b'. b' \<noteq> b \<and> (b',b) \<in> r \<longrightarrow> b' \<notin> B)" by auto
blanchet@48975
   221
  show ?thesis
blanchet@48975
   222
  proof(simp add: isMinim_def, rule exI[of _ b], auto)
blanchet@48975
   223
    show "b \<in> B" using * by simp
blanchet@48975
   224
  next
blanchet@48975
   225
    fix b' assume As: "b' \<in> B"
blanchet@48975
   226
    hence **: "b \<in> Field r \<and> b' \<in> Field r" using As SUB * by auto
blanchet@48975
   227
    (*  *)
blanchet@48975
   228
    from As  * have "b' = b \<or> (b',b) \<notin> r" by auto
blanchet@48975
   229
    moreover
blanchet@48975
   230
    {assume "b' = b"
blanchet@48975
   231
     hence "(b,b') \<in> r"
blanchet@48975
   232
     using ** REFL by (auto simp add: refl_on_def)
blanchet@48975
   233
    }
blanchet@48975
   234
    moreover
blanchet@48975
   235
    {assume "b' \<noteq> b \<and> (b',b) \<notin> r"
blanchet@48975
   236
     hence "(b,b') \<in> r"
blanchet@48975
   237
     using ** TOTAL by (auto simp add: total_on_def)
blanchet@48975
   238
    }
blanchet@48975
   239
    ultimately show "(b,b') \<in> r" by blast
blanchet@48975
   240
  qed
blanchet@48975
   241
qed
blanchet@48975
   242
blanchet@48975
   243
lemma minim_isMinim:
blanchet@48975
   244
assumes SUB: "B \<le> Field r" and NE: "B \<noteq> {}"
blanchet@48975
   245
shows "isMinim B (minim B)"
blanchet@48975
   246
proof-
blanchet@48975
   247
  let ?phi = "(\<lambda> b. isMinim B b)"
blanchet@48975
   248
  from assms Well_order_isMinim_exists
blanchet@48975
   249
  obtain b where *: "?phi b" by blast
blanchet@48975
   250
  moreover
blanchet@48975
   251
  have "\<And> b'. ?phi b' \<Longrightarrow> b' = b"
blanchet@48975
   252
  using isMinim_unique * by auto
blanchet@48975
   253
  ultimately show ?thesis
blanchet@48975
   254
  unfolding minim_def using theI[of ?phi b] by blast
blanchet@48975
   255
qed
blanchet@48975
   256
blanchet@48975
   257
subsubsection{* Properties of minim *}
blanchet@48975
   258
blanchet@48975
   259
lemma minim_in:
blanchet@48975
   260
assumes "B \<le> Field r" and "B \<noteq> {}"
blanchet@48975
   261
shows "minim B \<in> B"
blanchet@48975
   262
proof-
blanchet@48975
   263
  from minim_isMinim[of B] assms
blanchet@48975
   264
  have "isMinim B (minim B)" by simp
blanchet@48975
   265
  thus ?thesis by (simp add: isMinim_def)
blanchet@48975
   266
qed
blanchet@48975
   267
blanchet@48975
   268
lemma minim_inField:
blanchet@48975
   269
assumes "B \<le> Field r" and "B \<noteq> {}"
blanchet@48975
   270
shows "minim B \<in> Field r"
blanchet@48975
   271
proof-
blanchet@48975
   272
  have "minim B \<in> B" using assms by (simp add: minim_in)
blanchet@48975
   273
  thus ?thesis using assms by blast
blanchet@48975
   274
qed
blanchet@48975
   275
blanchet@48975
   276
lemma minim_least:
blanchet@48975
   277
assumes  SUB: "B \<le> Field r" and IN: "b \<in> B"
blanchet@48975
   278
shows "(minim B, b) \<in> r"
blanchet@48975
   279
proof-
blanchet@48975
   280
  from minim_isMinim[of B] assms
blanchet@48975
   281
  have "isMinim B (minim B)" by auto
blanchet@48975
   282
  thus ?thesis by (auto simp add: isMinim_def IN)
blanchet@48975
   283
qed
blanchet@48975
   284
blanchet@48975
   285
lemma equals_minim:
blanchet@48975
   286
assumes SUB: "B \<le> Field r" and IN: "a \<in> B" and
blanchet@48975
   287
        LEAST: "\<And> b. b \<in> B \<Longrightarrow> (a,b) \<in> r"
blanchet@48975
   288
shows "a = minim B"
blanchet@48975
   289
proof-
blanchet@48975
   290
  from minim_isMinim[of B] assms
blanchet@48975
   291
  have "isMinim B (minim B)" by auto
blanchet@48975
   292
  moreover have "isMinim B a" using IN LEAST isMinim_def by auto
blanchet@48975
   293
  ultimately show ?thesis
blanchet@48975
   294
  using isMinim_unique by auto
blanchet@48975
   295
qed
blanchet@48975
   296
blanchet@48975
   297
subsubsection{* Properties of successor *}
blanchet@48975
   298
blanchet@48975
   299
lemma suc_AboveS:
blanchet@48975
   300
assumes SUB: "B \<le> Field r" and ABOVES: "AboveS B \<noteq> {}"
blanchet@48975
   301
shows "suc B \<in> AboveS B"
blanchet@48975
   302
proof(unfold suc_def)
blanchet@48975
   303
  have "AboveS B \<le> Field r"
blanchet@55023
   304
  using AboveS_Field[of r] by auto
blanchet@48975
   305
  thus "minim (AboveS B) \<in> AboveS B"
blanchet@48975
   306
  using assms by (simp add: minim_in)
blanchet@48975
   307
qed
blanchet@48975
   308
blanchet@48975
   309
lemma suc_greater:
blanchet@48975
   310
assumes SUB: "B \<le> Field r" and ABOVES: "AboveS B \<noteq> {}" and
blanchet@48975
   311
        IN: "b \<in> B"
blanchet@48975
   312
shows "suc B \<noteq> b \<and> (b,suc B) \<in> r"
blanchet@48975
   313
proof-
blanchet@48975
   314
  from assms suc_AboveS
blanchet@48975
   315
  have "suc B \<in> AboveS B" by simp
blanchet@55023
   316
  with IN AboveS_def[of r] show ?thesis by simp
blanchet@48975
   317
qed
blanchet@48975
   318
blanchet@48975
   319
lemma suc_least_AboveS:
blanchet@48975
   320
assumes ABOVES: "a \<in> AboveS B"
blanchet@48975
   321
shows "(suc B,a) \<in> r"
blanchet@48975
   322
proof(unfold suc_def)
blanchet@48975
   323
  have "AboveS B \<le> Field r"
blanchet@55023
   324
  using AboveS_Field[of r] by auto
blanchet@48975
   325
  thus "(minim (AboveS B),a) \<in> r"
blanchet@48975
   326
  using assms minim_least by simp
blanchet@48975
   327
qed
blanchet@48975
   328
blanchet@48975
   329
lemma suc_inField:
blanchet@48975
   330
assumes "B \<le> Field r" and "AboveS B \<noteq> {}"
blanchet@48975
   331
shows "suc B \<in> Field r"
blanchet@48975
   332
proof-
blanchet@48975
   333
  have "suc B \<in> AboveS B" using suc_AboveS assms by simp
blanchet@48975
   334
  thus ?thesis
blanchet@55023
   335
  using assms AboveS_Field[of r] by auto
blanchet@48975
   336
qed
blanchet@48975
   337
blanchet@48975
   338
lemma equals_suc_AboveS:
blanchet@48975
   339
assumes SUB: "B \<le> Field r" and ABV: "a \<in> AboveS B" and
blanchet@48975
   340
        MINIM: "\<And> a'. a' \<in> AboveS B \<Longrightarrow> (a,a') \<in> r"
blanchet@48975
   341
shows "a = suc B"
blanchet@48975
   342
proof(unfold suc_def)
blanchet@48975
   343
  have "AboveS B \<le> Field r"
blanchet@55023
   344
  using AboveS_Field[of r B] by auto
blanchet@48975
   345
  thus "a = minim (AboveS B)"
blanchet@48975
   346
  using assms equals_minim
blanchet@48975
   347
  by simp
blanchet@48975
   348
qed
blanchet@48975
   349
blanchet@48975
   350
lemma suc_underS:
blanchet@48975
   351
assumes IN: "a \<in> Field r"
blanchet@48975
   352
shows "a = suc (underS a)"
blanchet@48975
   353
proof-
blanchet@48975
   354
  have "underS a \<le> Field r"
blanchet@55023
   355
  using underS_Field[of r] by auto
blanchet@48975
   356
  moreover
blanchet@48975
   357
  have "a \<in> AboveS (underS a)"
blanchet@55023
   358
  using in_AboveS_underS IN by fast
blanchet@48975
   359
  moreover
blanchet@48975
   360
  have "\<forall>a' \<in> AboveS (underS a). (a,a') \<in> r"
blanchet@48975
   361
  proof(clarify)
blanchet@48975
   362
    fix a'
blanchet@48975
   363
    assume *: "a' \<in> AboveS (underS a)"
blanchet@48975
   364
    hence **: "a' \<in> Field r"
blanchet@55023
   365
    using AboveS_Field by fast
blanchet@48975
   366
    {assume "(a,a') \<notin> r"
blanchet@48975
   367
     hence "a' = a \<or> (a',a) \<in> r"
blanchet@48975
   368
     using TOTAL IN ** by (auto simp add: total_on_def)
blanchet@48975
   369
     moreover
blanchet@48975
   370
     {assume "a' = a"
blanchet@48975
   371
      hence "(a,a') \<in> r"
blanchet@48975
   372
      using REFL IN ** by (auto simp add: refl_on_def)
blanchet@48975
   373
     }
blanchet@48975
   374
     moreover
blanchet@48975
   375
     {assume "a' \<noteq> a \<and> (a',a) \<in> r"
blanchet@48975
   376
      hence "a' \<in> underS a"
blanchet@48975
   377
      unfolding underS_def by simp
blanchet@48975
   378
      hence "a' \<notin> AboveS (underS a)"
blanchet@55023
   379
      using AboveS_disjoint by fast
blanchet@48975
   380
      with * have False by simp
blanchet@48975
   381
     }
blanchet@48975
   382
     ultimately have "(a,a') \<in> r" by blast
blanchet@48975
   383
    }
blanchet@48975
   384
    thus  "(a, a') \<in> r" by blast
blanchet@48975
   385
  qed
blanchet@48975
   386
  ultimately show ?thesis
blanchet@48975
   387
  using equals_suc_AboveS by auto
blanchet@48975
   388
qed
blanchet@48975
   389
blanchet@48975
   390
blanchet@54477
   391
subsubsection {* Properties of order filters *}
blanchet@48975
   392
blanchet@48975
   393
lemma under_ofilter:
blanchet@48975
   394
"ofilter (under a)"
blanchet@48975
   395
proof(unfold ofilter_def under_def, auto simp add: Field_def)
blanchet@48975
   396
  fix aa x
blanchet@48975
   397
  assume "(aa,a) \<in> r" "(x,aa) \<in> r"
blanchet@48975
   398
  thus "(x,a) \<in> r"
blanchet@48975
   399
  using TRANS trans_def[of r] by blast
blanchet@48975
   400
qed
blanchet@48975
   401
blanchet@48975
   402
lemma underS_ofilter:
blanchet@48975
   403
"ofilter (underS a)"
blanchet@48975
   404
proof(unfold ofilter_def underS_def under_def, auto simp add: Field_def)
blanchet@48975
   405
  fix aa assume "(a, aa) \<in> r" "(aa, a) \<in> r" and DIFF: "aa \<noteq> a"
blanchet@48975
   406
  thus False
blanchet@48975
   407
  using ANTISYM antisym_def[of r] by blast
blanchet@48975
   408
next
blanchet@48975
   409
  fix aa x
blanchet@48975
   410
  assume "(aa,a) \<in> r" "aa \<noteq> a" "(x,aa) \<in> r"
blanchet@48975
   411
  thus "(x,a) \<in> r"
blanchet@48975
   412
  using TRANS trans_def[of r] by blast
blanchet@48975
   413
qed
blanchet@48975
   414
blanchet@48975
   415
lemma Field_ofilter:
blanchet@48975
   416
"ofilter (Field r)"
blanchet@48975
   417
by(unfold ofilter_def under_def, auto simp add: Field_def)
blanchet@48975
   418
blanchet@48975
   419
lemma ofilter_underS_Field:
blanchet@48975
   420
"ofilter A = ((\<exists>a \<in> Field r. A = underS a) \<or> (A = Field r))"
blanchet@48975
   421
proof
blanchet@48975
   422
  assume "(\<exists>a\<in>Field r. A = underS a) \<or> A = Field r"
blanchet@48975
   423
  thus "ofilter A"
blanchet@48975
   424
  by (auto simp: underS_ofilter Field_ofilter)
blanchet@48975
   425
next
blanchet@48975
   426
  assume *: "ofilter A"
blanchet@48975
   427
  let ?One = "(\<exists>a\<in>Field r. A = underS a)"
blanchet@48975
   428
  let ?Two = "(A = Field r)"
blanchet@48975
   429
  show "?One \<or> ?Two"
blanchet@48975
   430
  proof(cases ?Two, simp)
blanchet@48975
   431
    let ?B = "(Field r) - A"
blanchet@48975
   432
    let ?a = "minim ?B"
blanchet@48975
   433
    assume "A \<noteq> Field r"
blanchet@48975
   434
    moreover have "A \<le> Field r" using * ofilter_def by simp
blanchet@48975
   435
    ultimately have 1: "?B \<noteq> {}" by blast
blanchet@48975
   436
    hence 2: "?a \<in> Field r" using minim_inField[of ?B] by blast
blanchet@48975
   437
    have 3: "?a \<in> ?B" using minim_in[of ?B] 1 by blast
blanchet@48975
   438
    hence 4: "?a \<notin> A" by blast
traytel@55173
   439
    have 5: "A \<le> Field r" using * ofilter_def by auto
blanchet@48975
   440
    (*  *)
blanchet@48975
   441
    moreover
blanchet@48975
   442
    have "A = underS ?a"
blanchet@48975
   443
    proof
blanchet@48975
   444
      show "A \<le> underS ?a"
blanchet@48975
   445
      proof(unfold underS_def, auto simp add: 4)
blanchet@48975
   446
        fix x assume **: "x \<in> A"
blanchet@48975
   447
        hence 11: "x \<in> Field r" using 5 by auto
blanchet@48975
   448
        have 12: "x \<noteq> ?a" using 4 ** by auto
blanchet@48975
   449
        have 13: "under x \<le> A" using * ofilter_def ** by auto
blanchet@48975
   450
        {assume "(x,?a) \<notin> r"
blanchet@48975
   451
         hence "(?a,x) \<in> r"
blanchet@48975
   452
         using TOTAL total_on_def[of "Field r" r]
blanchet@48975
   453
               2 4 11 12 by auto
blanchet@55023
   454
         hence "?a \<in> under x" using under_def[of r] by auto
blanchet@48975
   455
         hence "?a \<in> A" using ** 13 by blast
blanchet@48975
   456
         with 4 have False by simp
blanchet@48975
   457
        }
blanchet@48975
   458
        thus "(x,?a) \<in> r" by blast
blanchet@48975
   459
      qed
blanchet@48975
   460
    next
blanchet@48975
   461
      show "underS ?a \<le> A"
blanchet@48975
   462
      proof(unfold underS_def, auto)
blanchet@48975
   463
        fix x
blanchet@48975
   464
        assume **: "x \<noteq> ?a" and ***: "(x,?a) \<in> r"
blanchet@48975
   465
        hence 11: "x \<in> Field r" using Field_def by fastforce
blanchet@48975
   466
         {assume "x \<notin> A"
blanchet@48975
   467
          hence "x \<in> ?B" using 11 by auto
blanchet@48975
   468
          hence "(?a,x) \<in> r" using 3 minim_least[of ?B x] by blast
blanchet@48975
   469
          hence False
blanchet@48975
   470
          using ANTISYM antisym_def[of r] ** *** by auto
blanchet@48975
   471
         }
blanchet@48975
   472
        thus "x \<in> A" by blast
blanchet@48975
   473
      qed
blanchet@48975
   474
    qed
blanchet@48975
   475
    ultimately have ?One using 2 by blast
blanchet@48975
   476
    thus ?thesis by simp
blanchet@48975
   477
  qed
blanchet@48975
   478
qed
blanchet@48975
   479
blanchet@48975
   480
lemma ofilter_UNION:
wenzelm@60585
   481
"(\<And> i. i \<in> I \<Longrightarrow> ofilter(A i)) \<Longrightarrow> ofilter (\<Union>i \<in> I. A i)"
blanchet@48975
   482
unfolding ofilter_def by blast
blanchet@48975
   483
blanchet@48975
   484
lemma ofilter_under_UNION:
blanchet@48975
   485
assumes "ofilter A"
wenzelm@60585
   486
shows "A = (\<Union>a \<in> A. under a)"
blanchet@48975
   487
proof
blanchet@48975
   488
  have "\<forall>a \<in> A. under a \<le> A"
blanchet@48975
   489
  using assms ofilter_def by auto
wenzelm@60585
   490
  thus "(\<Union>a \<in> A. under a) \<le> A" by blast
blanchet@48975
   491
next
blanchet@48975
   492
  have "\<forall>a \<in> A. a \<in> under a"
blanchet@55023
   493
  using REFL Refl_under_in[of r] assms ofilter_def[of A] by blast
wenzelm@60585
   494
  thus "A \<le> (\<Union>a \<in> A. under a)" by blast
blanchet@48975
   495
qed
blanchet@48975
   496
blanchet@48975
   497
subsubsection{* Other properties *}
blanchet@48975
   498
blanchet@48975
   499
lemma ofilter_linord:
blanchet@48975
   500
assumes OF1: "ofilter A" and OF2: "ofilter B"
blanchet@48975
   501
shows "A \<le> B \<or> B \<le> A"
blanchet@48975
   502
proof(cases "A = Field r")
blanchet@48975
   503
  assume Case1: "A = Field r"
blanchet@48975
   504
  hence "B \<le> A" using OF2 ofilter_def by auto
blanchet@48975
   505
  thus ?thesis by simp
blanchet@48975
   506
next
blanchet@48975
   507
  assume Case2: "A \<noteq> Field r"
blanchet@48975
   508
  with ofilter_underS_Field OF1 obtain a where
blanchet@48975
   509
  1: "a \<in> Field r \<and> A = underS a" by auto
blanchet@48975
   510
  show ?thesis
blanchet@48975
   511
  proof(cases "B = Field r")
blanchet@48975
   512
    assume Case21: "B = Field r"
blanchet@48975
   513
    hence "A \<le> B" using OF1 ofilter_def by auto
blanchet@48975
   514
    thus ?thesis by simp
blanchet@48975
   515
  next
blanchet@48975
   516
    assume Case22: "B \<noteq> Field r"
blanchet@48975
   517
    with ofilter_underS_Field OF2 obtain b where
blanchet@48975
   518
    2: "b \<in> Field r \<and> B = underS b" by auto
blanchet@48975
   519
    have "a = b \<or> (a,b) \<in> r \<or> (b,a) \<in> r"
blanchet@48975
   520
    using 1 2 TOTAL total_on_def[of _ r] by auto
blanchet@48975
   521
    moreover
blanchet@48975
   522
    {assume "a = b" with 1 2 have ?thesis by auto
blanchet@48975
   523
    }
blanchet@48975
   524
    moreover
blanchet@48975
   525
    {assume "(a,b) \<in> r"
blanchet@55023
   526
     with underS_incr[of r] TRANS ANTISYM 1 2
blanchet@48975
   527
     have "A \<le> B" by auto
blanchet@48975
   528
     hence ?thesis by auto
blanchet@48975
   529
    }
blanchet@48975
   530
    moreover
blanchet@48975
   531
     {assume "(b,a) \<in> r"
blanchet@55023
   532
     with underS_incr[of r] TRANS ANTISYM 1 2
blanchet@48975
   533
     have "B \<le> A" by auto
blanchet@48975
   534
     hence ?thesis by auto
blanchet@48975
   535
    }
blanchet@48975
   536
    ultimately show ?thesis by blast
blanchet@48975
   537
  qed
blanchet@48975
   538
qed
blanchet@48975
   539
blanchet@48975
   540
lemma ofilter_AboveS_Field:
blanchet@48975
   541
assumes "ofilter A"
blanchet@48975
   542
shows "A \<union> (AboveS A) = Field r"
blanchet@48975
   543
proof
blanchet@48975
   544
  show "A \<union> (AboveS A) \<le> Field r"
blanchet@55023
   545
  using assms ofilter_def AboveS_Field[of r] by auto
blanchet@48975
   546
next
blanchet@48975
   547
  {fix x assume *: "x \<in> Field r" and **: "x \<notin> A"
blanchet@48975
   548
   {fix y assume ***: "y \<in> A"
blanchet@48975
   549
    with ** have 1: "y \<noteq> x" by auto
blanchet@48975
   550
    {assume "(y,x) \<notin> r"
blanchet@48975
   551
     moreover
blanchet@48975
   552
     have "y \<in> Field r" using assms ofilter_def *** by auto
blanchet@48975
   553
     ultimately have "(x,y) \<in> r"
blanchet@48975
   554
     using 1 * TOTAL total_on_def[of _ r] by auto
blanchet@55023
   555
     with *** assms ofilter_def under_def[of r] have "x \<in> A" by auto
blanchet@48975
   556
     with ** have False by contradiction
blanchet@48975
   557
    }
blanchet@48975
   558
    hence "(y,x) \<in> r" by blast
blanchet@48975
   559
    with 1 have "y \<noteq> x \<and> (y,x) \<in> r" by auto
blanchet@48975
   560
   }
blanchet@48975
   561
   with * have "x \<in> AboveS A" unfolding AboveS_def by auto
blanchet@48975
   562
  }
blanchet@48975
   563
  thus "Field r \<le> A \<union> (AboveS A)" by blast
blanchet@48975
   564
qed
blanchet@48975
   565
blanchet@48975
   566
lemma suc_ofilter_in:
blanchet@48975
   567
assumes OF: "ofilter A" and ABOVE_NE: "AboveS A \<noteq> {}" and
blanchet@48975
   568
        REL: "(b,suc A) \<in> r" and DIFF: "b \<noteq> suc A"
blanchet@48975
   569
shows "b \<in> A"
blanchet@48975
   570
proof-
blanchet@48975
   571
  have *: "suc A \<in> Field r \<and> b \<in> Field r"
blanchet@55023
   572
  using WELL REL well_order_on_domain[of "Field r"] by auto
blanchet@48975
   573
  {assume **: "b \<notin> A"
blanchet@48975
   574
   hence "b \<in> AboveS A"
blanchet@48975
   575
   using OF * ofilter_AboveS_Field by auto
blanchet@48975
   576
   hence "(suc A, b) \<in> r"
blanchet@48975
   577
   using suc_least_AboveS by auto
blanchet@48975
   578
   hence False using REL DIFF ANTISYM *
blanchet@48975
   579
   by (auto simp add: antisym_def)
blanchet@48975
   580
  }
blanchet@48975
   581
  thus ?thesis by blast
blanchet@48975
   582
qed
blanchet@48975
   583
blanchet@48975
   584
end (* context wo_rel *)
blanchet@48975
   585
blanchet@48975
   586
end