src/HOL/BNF_Wellorder_Embedding.thy
author haftmann
Fri Jun 19 07:53:35 2015 +0200 (2015-06-19)
changeset 60517 f16e4fb20652
parent 58889 5b7a9633cfa8
child 60585 48fdff264eb2
permissions -rw-r--r--
separate class for notions specific for integral (semi)domains, in contrast to fields where these are trivial
blanchet@55056
     1
(*  Title:      HOL/BNF_Wellorder_Embedding.thy
blanchet@48975
     2
    Author:     Andrei Popescu, TU Muenchen
blanchet@48975
     3
    Copyright   2012
blanchet@48975
     4
blanchet@55059
     5
Well-order embeddings as needed by bounded natural functors.
blanchet@48975
     6
*)
blanchet@48975
     7
wenzelm@58889
     8
section {* Well-Order Embeddings as Needed by Bounded Natural Functors *}
blanchet@48975
     9
blanchet@55056
    10
theory BNF_Wellorder_Embedding
traytel@55936
    11
imports Hilbert_Choice BNF_Wellorder_Relation
blanchet@48975
    12
begin
blanchet@48975
    13
blanchet@48975
    14
text{* In this section, we introduce well-order {\em embeddings} and {\em isomorphisms} and
blanchet@48975
    15
prove their basic properties.  The notion of embedding is considered from the point
blanchet@48975
    16
of view of the theory of ordinals, and therefore requires the source to be injected
blanchet@48975
    17
as an {\em initial segment} (i.e., {\em order filter}) of the target.  A main result
blanchet@48975
    18
of this section is the existence of embeddings (in one direction or another) between
blanchet@48975
    19
any two well-orders, having as a consequence the fact that, given any two sets on
blanchet@48975
    20
any two types, one is smaller than (i.e., can be injected into) the other. *}
blanchet@48975
    21
blanchet@48975
    22
blanchet@48975
    23
subsection {* Auxiliaries *}
blanchet@48975
    24
blanchet@48975
    25
lemma UNION_inj_on_ofilter:
blanchet@48975
    26
assumes WELL: "Well_order r" and
blanchet@48975
    27
        OF: "\<And> i. i \<in> I \<Longrightarrow> wo_rel.ofilter r (A i)" and
blanchet@48975
    28
       INJ: "\<And> i. i \<in> I \<Longrightarrow> inj_on f (A i)"
blanchet@48975
    29
shows "inj_on f (\<Union> i \<in> I. A i)"
blanchet@48975
    30
proof-
blanchet@48975
    31
  have "wo_rel r" using WELL by (simp add: wo_rel_def)
blanchet@48975
    32
  hence "\<And> i j. \<lbrakk>i \<in> I; j \<in> I\<rbrakk> \<Longrightarrow> A i <= A j \<or> A j <= A i"
blanchet@48975
    33
  using wo_rel.ofilter_linord[of r] OF by blast
blanchet@48975
    34
  with WELL INJ show ?thesis
blanchet@48975
    35
  by (auto simp add: inj_on_UNION_chain)
blanchet@48975
    36
qed
blanchet@48975
    37
blanchet@48975
    38
lemma under_underS_bij_betw:
blanchet@48975
    39
assumes WELL: "Well_order r" and WELL': "Well_order r'" and
blanchet@48975
    40
        IN: "a \<in> Field r" and IN': "f a \<in> Field r'" and
blanchet@55023
    41
        BIJ: "bij_betw f (underS r a) (underS r' (f a))"
blanchet@55023
    42
shows "bij_betw f (under r a) (under r' (f a))"
blanchet@48975
    43
proof-
blanchet@55023
    44
  have "a \<notin> underS r a \<and> f a \<notin> underS r' (f a)"
blanchet@55023
    45
  unfolding underS_def by auto
blanchet@48975
    46
  moreover
blanchet@48975
    47
  {have "Refl r \<and> Refl r'" using WELL WELL'
blanchet@48975
    48
   by (auto simp add: order_on_defs)
blanchet@55023
    49
   hence "under r a = underS r a \<union> {a} \<and>
blanchet@55023
    50
          under r' (f a) = underS r' (f a) \<union> {f a}"
blanchet@55023
    51
   using IN IN' by(auto simp add: Refl_under_underS)
blanchet@48975
    52
  }
blanchet@48975
    53
  ultimately show ?thesis
blanchet@55023
    54
  using BIJ notIn_Un_bij_betw[of a "underS r a" f "underS r' (f a)"] by auto
blanchet@48975
    55
qed
blanchet@48975
    56
blanchet@48975
    57
blanchet@48975
    58
subsection {* (Well-order) embeddings, strict embeddings, isomorphisms and order-compatible
blanchet@55101
    59
functions *}
blanchet@48975
    60
blanchet@48975
    61
text{* Standardly, a function is an embedding of a well-order in another if it injectively and
blanchet@48975
    62
order-compatibly maps the former into an order filter of the latter.
blanchet@48975
    63
Here we opt for a more succinct definition (operator @{text "embed"}),
blanchet@48975
    64
asking that, for any element in the source, the function should be a bijection
blanchet@48975
    65
between the set of strict lower bounds of that element
blanchet@48975
    66
and the set of strict lower bounds of its image.  (Later we prove equivalence with
blanchet@48975
    67
the standard definition -- lemma @{text "embed_iff_compat_inj_on_ofilter"}.)
blanchet@48975
    68
A {\em strict embedding} (operator @{text "embedS"})  is a non-bijective embedding
blanchet@55101
    69
and an isomorphism (operator @{text "iso"}) is a bijective embedding. *}
blanchet@48975
    70
blanchet@48975
    71
definition embed :: "'a rel \<Rightarrow> 'a' rel \<Rightarrow> ('a \<Rightarrow> 'a') \<Rightarrow> bool"
blanchet@48975
    72
where
blanchet@55023
    73
"embed r r' f \<equiv> \<forall>a \<in> Field r. bij_betw f (under r a) (under r' (f a))"
blanchet@48975
    74
blanchet@48975
    75
lemmas embed_defs = embed_def embed_def[abs_def]
blanchet@48975
    76
blanchet@48975
    77
text {* Strict embeddings: *}
blanchet@48975
    78
blanchet@48975
    79
definition embedS :: "'a rel \<Rightarrow> 'a' rel \<Rightarrow> ('a \<Rightarrow> 'a') \<Rightarrow> bool"
blanchet@48975
    80
where
blanchet@48975
    81
"embedS r r' f \<equiv> embed r r' f \<and> \<not> bij_betw f (Field r) (Field r')"
blanchet@48975
    82
blanchet@48975
    83
lemmas embedS_defs = embedS_def embedS_def[abs_def]
blanchet@48975
    84
blanchet@48975
    85
definition iso :: "'a rel \<Rightarrow> 'a' rel \<Rightarrow> ('a \<Rightarrow> 'a') \<Rightarrow> bool"
blanchet@48975
    86
where
blanchet@48975
    87
"iso r r' f \<equiv> embed r r' f \<and> bij_betw f (Field r) (Field r')"
blanchet@48975
    88
blanchet@48975
    89
lemmas iso_defs = iso_def iso_def[abs_def]
blanchet@48975
    90
blanchet@48975
    91
definition compat :: "'a rel \<Rightarrow> 'a' rel \<Rightarrow> ('a \<Rightarrow> 'a') \<Rightarrow> bool"
blanchet@48975
    92
where
blanchet@48975
    93
"compat r r' f \<equiv> \<forall>a b. (a,b) \<in> r \<longrightarrow> (f a, f b) \<in> r'"
blanchet@48975
    94
blanchet@48975
    95
lemma compat_wf:
blanchet@48975
    96
assumes CMP: "compat r r' f" and WF: "wf r'"
blanchet@48975
    97
shows "wf r"
blanchet@48975
    98
proof-
blanchet@48975
    99
  have "r \<le> inv_image r' f"
blanchet@48975
   100
  unfolding inv_image_def using CMP
blanchet@48975
   101
  by (auto simp add: compat_def)
blanchet@48975
   102
  with WF show ?thesis
blanchet@48975
   103
  using wf_inv_image[of r' f] wf_subset[of "inv_image r' f"] by auto
blanchet@48975
   104
qed
blanchet@48975
   105
blanchet@48975
   106
lemma id_embed: "embed r r id"
blanchet@48975
   107
by(auto simp add: id_def embed_def bij_betw_def)
blanchet@48975
   108
blanchet@48975
   109
lemma id_iso: "iso r r id"
blanchet@48975
   110
by(auto simp add: id_def embed_def iso_def bij_betw_def)
blanchet@48975
   111
blanchet@48975
   112
lemma embed_in_Field:
blanchet@48975
   113
assumes WELL: "Well_order r" and
blanchet@48975
   114
        EMB: "embed r r' f" and IN: "a \<in> Field r"
blanchet@48975
   115
shows "f a \<in> Field r'"
blanchet@48975
   116
proof-
blanchet@48975
   117
  have Well: "wo_rel r"
blanchet@48975
   118
  using WELL by (auto simp add: wo_rel_def)
blanchet@48975
   119
  hence 1: "Refl r"
blanchet@48975
   120
  by (auto simp add: wo_rel.REFL)
blanchet@55023
   121
  hence "a \<in> under r a" using IN Refl_under_in by fastforce
blanchet@55023
   122
  hence "f a \<in> under r' (f a)"
blanchet@48975
   123
  using EMB IN by (auto simp add: embed_def bij_betw_def)
blanchet@48975
   124
  thus ?thesis unfolding Field_def
blanchet@55023
   125
  by (auto simp: under_def)
blanchet@48975
   126
qed
blanchet@48975
   127
blanchet@48975
   128
lemma comp_embed:
blanchet@48975
   129
assumes WELL: "Well_order r" and
blanchet@48975
   130
        EMB: "embed r r' f" and EMB': "embed r' r'' f'"
blanchet@48975
   131
shows "embed r r'' (f' o f)"
blanchet@48975
   132
proof(unfold embed_def, auto)
blanchet@48975
   133
  fix a assume *: "a \<in> Field r"
blanchet@55023
   134
  hence "bij_betw f (under r a) (under r' (f a))"
blanchet@48975
   135
  using embed_def[of r] EMB by auto
blanchet@48975
   136
  moreover
blanchet@48975
   137
  {have "f a \<in> Field r'"
blanchet@48975
   138
   using EMB WELL * by (auto simp add: embed_in_Field)
blanchet@55023
   139
   hence "bij_betw f' (under r' (f a)) (under r'' (f' (f a)))"
blanchet@48975
   140
   using embed_def[of r'] EMB' by auto
blanchet@48975
   141
  }
blanchet@48975
   142
  ultimately
blanchet@55023
   143
  show "bij_betw (f' \<circ> f) (under r a) (under r'' (f'(f a)))"
blanchet@48975
   144
  by(auto simp add: bij_betw_trans)
blanchet@48975
   145
qed
blanchet@48975
   146
blanchet@48975
   147
lemma comp_iso:
blanchet@48975
   148
assumes WELL: "Well_order r" and
blanchet@48975
   149
        EMB: "iso r r' f" and EMB': "iso r' r'' f'"
blanchet@48975
   150
shows "iso r r'' (f' o f)"
blanchet@48975
   151
using assms unfolding iso_def
blanchet@48975
   152
by (auto simp add: comp_embed bij_betw_trans)
blanchet@48975
   153
blanchet@55101
   154
text{* That @{text "embedS"} is also preserved by function composition shall be proved only later. *}
blanchet@48975
   155
blanchet@48975
   156
lemma embed_Field:
blanchet@48975
   157
"\<lbrakk>Well_order r; embed r r' f\<rbrakk> \<Longrightarrow> f`(Field r) \<le> Field r'"
blanchet@48975
   158
by (auto simp add: embed_in_Field)
blanchet@48975
   159
blanchet@48975
   160
lemma embed_preserves_ofilter:
blanchet@48975
   161
assumes WELL: "Well_order r" and WELL': "Well_order r'" and
blanchet@48975
   162
        EMB: "embed r r' f" and OF: "wo_rel.ofilter r A"
blanchet@48975
   163
shows "wo_rel.ofilter r' (f`A)"
blanchet@48975
   164
proof-
blanchet@48975
   165
  (* Preliminary facts *)
blanchet@48975
   166
  from WELL have Well: "wo_rel r" unfolding wo_rel_def .
blanchet@48975
   167
  from WELL' have Well': "wo_rel r'" unfolding wo_rel_def .
blanchet@48975
   168
  from OF have 0: "A \<le> Field r" by(auto simp add: Well wo_rel.ofilter_def)
blanchet@48975
   169
  (* Main proof *)
blanchet@48975
   170
  show ?thesis  using Well' WELL EMB 0 embed_Field[of r r' f]
blanchet@48975
   171
  proof(unfold wo_rel.ofilter_def, auto simp add: image_def)
blanchet@48975
   172
    fix a b'
blanchet@55023
   173
    assume *: "a \<in> A" and **: "b' \<in> under r' (f a)"
blanchet@48975
   174
    hence "a \<in> Field r" using 0 by auto
blanchet@55023
   175
    hence "bij_betw f (under r a) (under r' (f a))"
blanchet@48975
   176
    using * EMB by (auto simp add: embed_def)
blanchet@55023
   177
    hence "f`(under r a) = under r' (f a)"
blanchet@48975
   178
    by (simp add: bij_betw_def)
blanchet@55023
   179
    with ** image_def[of f "under r a"] obtain b where
blanchet@55023
   180
    1: "b \<in> under r a \<and> b' = f b" by blast
blanchet@48975
   181
    hence "b \<in> A" using Well * OF
blanchet@48975
   182
    by (auto simp add: wo_rel.ofilter_def)
blanchet@48975
   183
    with 1 show "\<exists>b \<in> A. b' = f b" by blast
blanchet@48975
   184
  qed
blanchet@48975
   185
qed
blanchet@48975
   186
blanchet@48975
   187
lemma embed_Field_ofilter:
blanchet@48975
   188
assumes WELL: "Well_order r" and WELL': "Well_order r'" and
blanchet@48975
   189
        EMB: "embed r r' f"
blanchet@48975
   190
shows "wo_rel.ofilter r' (f`(Field r))"
blanchet@48975
   191
proof-
blanchet@48975
   192
  have "wo_rel.ofilter r (Field r)"
blanchet@48975
   193
  using WELL by (auto simp add: wo_rel_def wo_rel.Field_ofilter)
blanchet@48975
   194
  with WELL WELL' EMB
blanchet@48975
   195
  show ?thesis by (auto simp add: embed_preserves_ofilter)
blanchet@48975
   196
qed
blanchet@48975
   197
blanchet@48975
   198
lemma embed_compat:
blanchet@48975
   199
assumes EMB: "embed r r' f"
blanchet@48975
   200
shows "compat r r' f"
blanchet@48975
   201
proof(unfold compat_def, clarify)
blanchet@48975
   202
  fix a b
blanchet@48975
   203
  assume *: "(a,b) \<in> r"
blanchet@48975
   204
  hence 1: "b \<in> Field r" using Field_def[of r] by blast
blanchet@55023
   205
  have "a \<in> under r b"
blanchet@55023
   206
  using * under_def[of r] by simp
blanchet@55023
   207
  hence "f a \<in> under r' (f b)"
blanchet@48975
   208
  using EMB embed_def[of r r' f]
blanchet@55023
   209
        bij_betw_def[of f "under r b" "under r' (f b)"]
blanchet@55023
   210
        image_def[of f "under r b"] 1 by auto
blanchet@48975
   211
  thus "(f a, f b) \<in> r'"
blanchet@55023
   212
  by (auto simp add: under_def)
blanchet@48975
   213
qed
blanchet@48975
   214
blanchet@48975
   215
lemma embed_inj_on:
blanchet@48975
   216
assumes WELL: "Well_order r" and EMB: "embed r r' f"
blanchet@48975
   217
shows "inj_on f (Field r)"
blanchet@48975
   218
proof(unfold inj_on_def, clarify)
blanchet@48975
   219
  (* Preliminary facts *)
blanchet@48975
   220
  from WELL have Well: "wo_rel r" unfolding wo_rel_def .
blanchet@48975
   221
  with wo_rel.TOTAL[of r]
blanchet@48975
   222
  have Total: "Total r" by simp
blanchet@48975
   223
  from Well wo_rel.REFL[of r]
blanchet@48975
   224
  have Refl: "Refl r" by simp
blanchet@48975
   225
  (* Main proof *)
blanchet@48975
   226
  fix a b
blanchet@48975
   227
  assume *: "a \<in> Field r" and **: "b \<in> Field r" and
blanchet@48975
   228
         ***: "f a = f b"
blanchet@48975
   229
  hence 1: "a \<in> Field r \<and> b \<in> Field r"
blanchet@48975
   230
  unfolding Field_def by auto
blanchet@48975
   231
  {assume "(a,b) \<in> r"
blanchet@55023
   232
   hence "a \<in> under r b \<and> b \<in> under r b"
blanchet@55023
   233
   using Refl by(auto simp add: under_def refl_on_def)
blanchet@48975
   234
   hence "a = b"
blanchet@48975
   235
   using EMB 1 ***
blanchet@48975
   236
   by (auto simp add: embed_def bij_betw_def inj_on_def)
blanchet@48975
   237
  }
blanchet@48975
   238
  moreover
blanchet@48975
   239
  {assume "(b,a) \<in> r"
blanchet@55023
   240
   hence "a \<in> under r a \<and> b \<in> under r a"
blanchet@55023
   241
   using Refl by(auto simp add: under_def refl_on_def)
blanchet@48975
   242
   hence "a = b"
blanchet@48975
   243
   using EMB 1 ***
blanchet@48975
   244
   by (auto simp add: embed_def bij_betw_def inj_on_def)
blanchet@48975
   245
  }
blanchet@48975
   246
  ultimately
blanchet@48975
   247
  show "a = b" using Total 1
blanchet@48975
   248
  by (auto simp add: total_on_def)
blanchet@48975
   249
qed
blanchet@48975
   250
blanchet@48975
   251
lemma embed_underS:
wenzelm@49753
   252
assumes WELL: "Well_order r" and WELL': "Well_order r'" and
blanchet@48975
   253
        EMB: "embed r r' f" and IN: "a \<in> Field r"
blanchet@55023
   254
shows "bij_betw f (underS r a) (underS r' (f a))"
blanchet@48975
   255
proof-
blanchet@55023
   256
  have "bij_betw f (under r a) (under r' (f a))"
blanchet@48975
   257
  using assms by (auto simp add: embed_def)
blanchet@48975
   258
  moreover
blanchet@48975
   259
  {have "f a \<in> Field r'" using assms  embed_Field[of r r' f] by auto
blanchet@55023
   260
   hence "under r a = underS r a \<union> {a} \<and>
blanchet@55023
   261
          under r' (f a) = underS r' (f a) \<union> {f a}"
blanchet@55023
   262
   using assms by (auto simp add: order_on_defs Refl_under_underS)
blanchet@48975
   263
  }
blanchet@48975
   264
  moreover
blanchet@55023
   265
  {have "a \<notin> underS r a \<and> f a \<notin> underS r' (f a)"
blanchet@55023
   266
   unfolding underS_def by blast
blanchet@48975
   267
  }
blanchet@48975
   268
  ultimately show ?thesis
blanchet@48975
   269
  by (auto simp add: notIn_Un_bij_betw3)
blanchet@48975
   270
qed
blanchet@48975
   271
blanchet@48975
   272
lemma embed_iff_compat_inj_on_ofilter:
blanchet@48975
   273
assumes WELL: "Well_order r" and WELL': "Well_order r'"
blanchet@48975
   274
shows "embed r r' f = (compat r r' f \<and> inj_on f (Field r) \<and> wo_rel.ofilter r' (f`(Field r)))"
blanchet@48975
   275
using assms
blanchet@48975
   276
proof(auto simp add: embed_compat embed_inj_on embed_Field_ofilter,
blanchet@48975
   277
      unfold embed_def, auto) (* get rid of one implication *)
blanchet@48975
   278
  fix a
blanchet@48975
   279
  assume *: "inj_on f (Field r)" and
blanchet@48975
   280
         **: "compat r r' f" and
blanchet@48975
   281
         ***: "wo_rel.ofilter r' (f`(Field r))" and
blanchet@48975
   282
         ****: "a \<in> Field r"
blanchet@48975
   283
  (* Preliminary facts *)
blanchet@48975
   284
  have Well: "wo_rel r"
blanchet@48975
   285
  using WELL wo_rel_def[of r] by simp
blanchet@48975
   286
  hence Refl: "Refl r"
blanchet@48975
   287
  using wo_rel.REFL[of r] by simp
blanchet@48975
   288
  have Total: "Total r"
blanchet@48975
   289
  using Well wo_rel.TOTAL[of r] by simp
blanchet@48975
   290
  have Well': "wo_rel r'"
blanchet@48975
   291
  using WELL' wo_rel_def[of r'] by simp
blanchet@48975
   292
  hence Antisym': "antisym r'"
blanchet@48975
   293
  using wo_rel.ANTISYM[of r'] by simp
blanchet@48975
   294
  have "(a,a) \<in> r"
blanchet@48975
   295
  using **** Well wo_rel.REFL[of r]
blanchet@48975
   296
        refl_on_def[of _ r] by auto
blanchet@48975
   297
  hence "(f a, f a) \<in> r'"
blanchet@48975
   298
  using ** by(auto simp add: compat_def)
blanchet@48975
   299
  hence 0: "f a \<in> Field r'"
blanchet@48975
   300
  unfolding Field_def by auto
blanchet@48975
   301
  have "f a \<in> f`(Field r)"
blanchet@48975
   302
  using **** by auto
blanchet@55023
   303
  hence 2: "under r' (f a) \<le> f`(Field r)"
blanchet@48975
   304
  using Well' *** wo_rel.ofilter_def[of r' "f`(Field r)"] by fastforce
blanchet@48975
   305
  (* Main proof *)
blanchet@55023
   306
  show "bij_betw f (under r a) (under r' (f a))"
blanchet@48975
   307
  proof(unfold bij_betw_def, auto)
traytel@55811
   308
    show  "inj_on f (under r a)" by (rule subset_inj_on[OF * under_Field])
blanchet@48975
   309
  next
blanchet@55023
   310
    fix b assume "b \<in> under r a"
blanchet@55023
   311
    thus "f b \<in> under r' (f a)"
blanchet@55023
   312
    unfolding under_def using **
blanchet@48975
   313
    by (auto simp add: compat_def)
blanchet@48975
   314
  next
blanchet@55023
   315
    fix b' assume *****: "b' \<in> under r' (f a)"
blanchet@48975
   316
    hence "b' \<in> f`(Field r)"
blanchet@48975
   317
    using 2 by auto
blanchet@48975
   318
    with Field_def[of r] obtain b where
blanchet@48975
   319
    3: "b \<in> Field r" and 4: "b' = f b" by auto
blanchet@48975
   320
    have "(b,a): r"
blanchet@48975
   321
    proof-
blanchet@48975
   322
      {assume "(a,b) \<in> r"
blanchet@48975
   323
       with ** 4 have "(f a, b'): r'"
blanchet@48975
   324
       by (auto simp add: compat_def)
blanchet@48975
   325
       with ***** Antisym' have "f a = b'"
blanchet@55023
   326
       by(auto simp add: under_def antisym_def)
blanchet@48975
   327
       with 3 **** 4 * have "a = b"
blanchet@48975
   328
       by(auto simp add: inj_on_def)
blanchet@48975
   329
      }
blanchet@48975
   330
      moreover
blanchet@48975
   331
      {assume "a = b"
blanchet@48975
   332
       hence "(b,a) \<in> r" using Refl **** 3
blanchet@48975
   333
       by (auto simp add: refl_on_def)
blanchet@48975
   334
      }
blanchet@48975
   335
      ultimately
blanchet@48975
   336
      show ?thesis using Total **** 3 by (fastforce simp add: total_on_def)
blanchet@48975
   337
    qed
blanchet@55023
   338
    with 4 show  "b' \<in> f`(under r a)"
blanchet@55023
   339
    unfolding under_def by auto
blanchet@48975
   340
  qed
blanchet@48975
   341
qed
blanchet@48975
   342
blanchet@48975
   343
lemma inv_into_ofilter_embed:
blanchet@48975
   344
assumes WELL: "Well_order r" and OF: "wo_rel.ofilter r A" and
blanchet@55023
   345
        BIJ: "\<forall>b \<in> A. bij_betw f (under r b) (under r' (f b))" and
blanchet@48975
   346
        IMAGE: "f ` A = Field r'"
blanchet@48975
   347
shows "embed r' r (inv_into A f)"
blanchet@48975
   348
proof-
blanchet@48975
   349
  (* Preliminary facts *)
blanchet@48975
   350
  have Well: "wo_rel r"
blanchet@48975
   351
  using WELL wo_rel_def[of r] by simp
blanchet@48975
   352
  have Refl: "Refl r"
blanchet@48975
   353
  using Well wo_rel.REFL[of r] by simp
blanchet@48975
   354
  have Total: "Total r"
blanchet@48975
   355
  using Well wo_rel.TOTAL[of r] by simp
blanchet@48975
   356
  (* Main proof *)
blanchet@48975
   357
  have 1: "bij_betw f A (Field r')"
blanchet@48975
   358
  proof(unfold bij_betw_def inj_on_def, auto simp add: IMAGE)
blanchet@48975
   359
    fix b1 b2
blanchet@48975
   360
    assume *: "b1 \<in> A" and **: "b2 \<in> A" and
blanchet@48975
   361
           ***: "f b1 = f b2"
blanchet@48975
   362
    have 11: "b1 \<in> Field r \<and> b2 \<in> Field r"
blanchet@48975
   363
    using * ** Well OF by (auto simp add: wo_rel.ofilter_def)
blanchet@48975
   364
    moreover
blanchet@48975
   365
    {assume "(b1,b2) \<in> r"
blanchet@55023
   366
     hence "b1 \<in> under r b2 \<and> b2 \<in> under r b2"
blanchet@55023
   367
     unfolding under_def using 11 Refl
blanchet@48975
   368
     by (auto simp add: refl_on_def)
blanchet@48975
   369
     hence "b1 = b2" using BIJ * ** ***
blanchet@54482
   370
     by (simp add: bij_betw_def inj_on_def)
blanchet@48975
   371
    }
blanchet@48975
   372
    moreover
blanchet@48975
   373
     {assume "(b2,b1) \<in> r"
blanchet@55023
   374
     hence "b1 \<in> under r b1 \<and> b2 \<in> under r b1"
blanchet@55023
   375
     unfolding under_def using 11 Refl
blanchet@48975
   376
     by (auto simp add: refl_on_def)
blanchet@48975
   377
     hence "b1 = b2" using BIJ * ** ***
blanchet@54482
   378
     by (simp add: bij_betw_def inj_on_def)
blanchet@48975
   379
    }
blanchet@48975
   380
    ultimately
blanchet@48975
   381
    show "b1 = b2"
blanchet@48975
   382
    using Total by (auto simp add: total_on_def)
blanchet@48975
   383
  qed
blanchet@48975
   384
  (*  *)
blanchet@48975
   385
  let ?f' = "(inv_into A f)"
blanchet@48975
   386
  (*  *)
blanchet@55023
   387
  have 2: "\<forall>b \<in> A. bij_betw ?f' (under r' (f b)) (under r b)"
blanchet@48975
   388
  proof(clarify)
blanchet@48975
   389
    fix b assume *: "b \<in> A"
blanchet@55023
   390
    hence "under r b \<le> A"
blanchet@48975
   391
    using Well OF by(auto simp add: wo_rel.ofilter_def)
blanchet@48975
   392
    moreover
blanchet@55023
   393
    have "f ` (under r b) = under r' (f b)"
blanchet@48975
   394
    using * BIJ by (auto simp add: bij_betw_def)
blanchet@48975
   395
    ultimately
blanchet@55023
   396
    show "bij_betw ?f' (under r' (f b)) (under r b)"
blanchet@48975
   397
    using 1 by (auto simp add: bij_betw_inv_into_subset)
blanchet@48975
   398
  qed
blanchet@48975
   399
  (*  *)
blanchet@55023
   400
  have 3: "\<forall>b' \<in> Field r'. bij_betw ?f' (under r' b') (under r (?f' b'))"
blanchet@48975
   401
  proof(clarify)
blanchet@48975
   402
    fix b' assume *: "b' \<in> Field r'"
blanchet@48975
   403
    have "b' = f (?f' b')" using * 1
blanchet@48975
   404
    by (auto simp add: bij_betw_inv_into_right)
blanchet@48975
   405
    moreover
blanchet@48975
   406
    {obtain b where 31: "b \<in> A" and "f b = b'" using IMAGE * by force
blanchet@48975
   407
     hence "?f' b' = b" using 1 by (auto simp add: bij_betw_inv_into_left)
blanchet@48975
   408
     with 31 have "?f' b' \<in> A" by auto
blanchet@48975
   409
    }
blanchet@48975
   410
    ultimately
blanchet@55023
   411
    show  "bij_betw ?f' (under r' b') (under r (?f' b'))"
blanchet@48975
   412
    using 2 by auto
blanchet@48975
   413
  qed
blanchet@48975
   414
  (*  *)
blanchet@48975
   415
  thus ?thesis unfolding embed_def .
blanchet@48975
   416
qed
blanchet@48975
   417
blanchet@48975
   418
lemma inv_into_underS_embed:
blanchet@48975
   419
assumes WELL: "Well_order r" and
blanchet@55023
   420
        BIJ: "\<forall>b \<in> underS r a. bij_betw f (under r b) (under r' (f b))" and
blanchet@48975
   421
        IN: "a \<in> Field r" and
blanchet@55023
   422
        IMAGE: "f ` (underS r a) = Field r'"
blanchet@55023
   423
shows "embed r' r (inv_into (underS r a) f)"
blanchet@48975
   424
using assms
blanchet@48975
   425
by(auto simp add: wo_rel_def wo_rel.underS_ofilter inv_into_ofilter_embed)
blanchet@48975
   426
blanchet@48975
   427
lemma inv_into_Field_embed:
blanchet@48975
   428
assumes WELL: "Well_order r" and EMB: "embed r r' f" and
blanchet@48975
   429
        IMAGE: "Field r' \<le> f ` (Field r)"
blanchet@48975
   430
shows "embed r' r (inv_into (Field r) f)"
blanchet@48975
   431
proof-
blanchet@55023
   432
  have "(\<forall>b \<in> Field r. bij_betw f (under r b) (under r' (f b)))"
blanchet@48975
   433
  using EMB by (auto simp add: embed_def)
blanchet@48975
   434
  moreover
blanchet@48975
   435
  have "f ` (Field r) \<le> Field r'"
blanchet@48975
   436
  using EMB WELL by (auto simp add: embed_Field)
blanchet@48975
   437
  ultimately
blanchet@48975
   438
  show ?thesis using assms
blanchet@48975
   439
  by(auto simp add: wo_rel_def wo_rel.Field_ofilter inv_into_ofilter_embed)
blanchet@48975
   440
qed
blanchet@48975
   441
blanchet@48975
   442
lemma inv_into_Field_embed_bij_betw:
blanchet@48975
   443
assumes WELL: "Well_order r" and
blanchet@48975
   444
        EMB: "embed r r' f" and BIJ: "bij_betw f (Field r) (Field r')"
blanchet@48975
   445
shows "embed r' r (inv_into (Field r) f)"
blanchet@48975
   446
proof-
blanchet@48975
   447
  have "Field r' \<le> f ` (Field r)"
blanchet@48975
   448
  using BIJ by (auto simp add: bij_betw_def)
blanchet@48975
   449
  thus ?thesis using assms
blanchet@48975
   450
  by(auto simp add: inv_into_Field_embed)
blanchet@48975
   451
qed
blanchet@48975
   452
blanchet@48975
   453
blanchet@48975
   454
subsection {* Given any two well-orders, one can be embedded in the other *}
blanchet@48975
   455
blanchet@48975
   456
text{* Here is an overview of the proof of of this fact, stated in theorem
blanchet@48975
   457
@{text "wellorders_totally_ordered"}:
blanchet@48975
   458
blanchet@48975
   459
   Fix the well-orders @{text "r::'a rel"} and @{text "r'::'a' rel"}.
blanchet@48975
   460
   Attempt to define an embedding @{text "f::'a \<Rightarrow> 'a'"} from @{text "r"} to @{text "r'"} in the
blanchet@48975
   461
   natural way by well-order recursion ("hoping" that @{text "Field r"} turns out to be smaller
blanchet@48975
   462
   than @{text "Field r'"}), but also record, at the recursive step, in a function
blanchet@48975
   463
   @{text "g::'a \<Rightarrow> bool"}, the extra information of whether @{text "Field r'"}
blanchet@48975
   464
   gets exhausted or not.
blanchet@48975
   465
blanchet@48975
   466
   If @{text "Field r'"} does not get exhausted, then @{text "Field r"} is indeed smaller
blanchet@48975
   467
   and @{text "f"} is the desired embedding from @{text "r"} to @{text "r'"}
blanchet@48975
   468
   (lemma @{text "wellorders_totally_ordered_aux"}).
blanchet@48975
   469
blanchet@48975
   470
   Otherwise, it means that @{text "Field r'"} is the smaller one, and the inverse of
blanchet@48975
   471
   (the "good" segment of) @{text "f"} is the desired embedding from @{text "r'"} to @{text "r"}
blanchet@48975
   472
   (lemma @{text "wellorders_totally_ordered_aux2"}).
blanchet@48975
   473
*}
blanchet@48975
   474
blanchet@48975
   475
lemma wellorders_totally_ordered_aux:
blanchet@48975
   476
fixes r ::"'a rel"  and r'::"'a' rel" and
blanchet@48975
   477
      f :: "'a \<Rightarrow> 'a'" and a::'a
blanchet@48975
   478
assumes WELL: "Well_order r" and WELL': "Well_order r'" and IN: "a \<in> Field r" and
blanchet@55023
   479
        IH: "\<forall>b \<in> underS r a. bij_betw f (under r b) (under r' (f b))" and
blanchet@55023
   480
        NOT: "f ` (underS r a) \<noteq> Field r'" and SUC: "f a = wo_rel.suc r' (f`(underS r a))"
blanchet@55023
   481
shows "bij_betw f (under r a) (under r' (f a))"
blanchet@48975
   482
proof-
blanchet@48975
   483
  (* Preliminary facts *)
blanchet@48975
   484
  have Well: "wo_rel r" using WELL unfolding wo_rel_def .
blanchet@48975
   485
  hence Refl: "Refl r" using wo_rel.REFL[of r] by auto
blanchet@48975
   486
  have Trans: "trans r" using Well wo_rel.TRANS[of r] by auto
blanchet@48975
   487
  have Well': "wo_rel r'" using WELL' unfolding wo_rel_def .
blanchet@55023
   488
  have OF: "wo_rel.ofilter r (underS r a)"
blanchet@48975
   489
  by (auto simp add: Well wo_rel.underS_ofilter)
blanchet@55023
   490
  hence UN: "underS r a = (\<Union>  b \<in> underS r a. under r b)"
blanchet@55023
   491
  using Well wo_rel.ofilter_under_UNION[of r "underS r a"] by blast
blanchet@55023
   492
  (* Gather facts about elements of underS r a *)
blanchet@55023
   493
  {fix b assume *: "b \<in> underS r a"
blanchet@55023
   494
   hence t0: "(b,a) \<in> r \<and> b \<noteq> a" unfolding underS_def by auto
blanchet@48975
   495
   have t1: "b \<in> Field r"
blanchet@55023
   496
   using * underS_Field[of r a] by auto
blanchet@55023
   497
   have t2: "f`(under r b) = under r' (f b)"
blanchet@48975
   498
   using IH * by (auto simp add: bij_betw_def)
blanchet@55023
   499
   hence t3: "wo_rel.ofilter r' (f`(under r b))"
blanchet@48975
   500
   using Well' by (auto simp add: wo_rel.under_ofilter)
blanchet@55023
   501
   have "f`(under r b) \<le> Field r'"
blanchet@55023
   502
   using t2 by (auto simp add: under_Field)
blanchet@48975
   503
   moreover
blanchet@55023
   504
   have "b \<in> under r b"
blanchet@55023
   505
   using t1 by(auto simp add: Refl Refl_under_in)
blanchet@48975
   506
   ultimately
blanchet@48975
   507
   have t4:  "f b \<in> Field r'" by auto
blanchet@55023
   508
   have "f`(under r b) = under r' (f b) \<and>
blanchet@55023
   509
         wo_rel.ofilter r' (f`(under r b)) \<and>
blanchet@48975
   510
         f b \<in> Field r'"
blanchet@48975
   511
   using t2 t3 t4 by auto
blanchet@48975
   512
  }
blanchet@48975
   513
  hence bFact:
blanchet@55023
   514
  "\<forall>b \<in> underS r a. f`(under r b) = under r' (f b) \<and>
blanchet@55023
   515
                       wo_rel.ofilter r' (f`(under r b)) \<and>
blanchet@48975
   516
                       f b \<in> Field r'" by blast
blanchet@48975
   517
  (*  *)
blanchet@55023
   518
  have subField: "f`(underS r a) \<le> Field r'"
blanchet@48975
   519
  using bFact by blast
blanchet@48975
   520
  (*  *)
blanchet@55023
   521
  have OF': "wo_rel.ofilter r' (f`(underS r a))"
blanchet@48975
   522
  proof-
blanchet@55023
   523
    have "f`(underS r a) = f`(\<Union>  b \<in> underS r a. under r b)"
blanchet@48975
   524
    using UN by auto
blanchet@55023
   525
    also have "\<dots> = (\<Union>  b \<in> underS r a. f`(under r b))" by blast
blanchet@55023
   526
    also have "\<dots> = (\<Union>  b \<in> underS r a. (under r' (f b)))"
blanchet@48975
   527
    using bFact by auto
blanchet@48975
   528
    finally
blanchet@55023
   529
    have "f`(underS r a) = (\<Union>  b \<in> underS r a. (under r' (f b)))" .
blanchet@48975
   530
    thus ?thesis
blanchet@48975
   531
    using Well' bFact
blanchet@55023
   532
          wo_rel.ofilter_UNION[of r' "underS r a" "\<lambda> b. under r' (f b)"] by fastforce
blanchet@48975
   533
  qed
blanchet@48975
   534
  (*  *)
blanchet@55023
   535
  have "f`(underS r a) \<union> AboveS r' (f`(underS r a)) = Field r'"
blanchet@48975
   536
  using Well' OF' by (auto simp add: wo_rel.ofilter_AboveS_Field)
blanchet@55023
   537
  hence NE: "AboveS r' (f`(underS r a)) \<noteq> {}"
blanchet@48975
   538
  using subField NOT by blast
blanchet@48975
   539
  (* Main proof *)
blanchet@55023
   540
  have INCL1: "f`(underS r a) \<le> underS r' (f a) "
blanchet@48975
   541
  proof(auto)
blanchet@55023
   542
    fix b assume *: "b \<in> underS r a"
blanchet@48975
   543
    have "f b \<noteq> f a \<and> (f b, f a) \<in> r'"
blanchet@48975
   544
    using subField Well' SUC NE *
blanchet@55023
   545
          wo_rel.suc_greater[of r' "f`(underS r a)" "f b"] by force
blanchet@55023
   546
    thus "f b \<in> underS r' (f a)"
blanchet@55023
   547
    unfolding underS_def by simp
blanchet@48975
   548
  qed
blanchet@48975
   549
  (*  *)
blanchet@55023
   550
  have INCL2: "underS r' (f a) \<le> f`(underS r a)"
blanchet@48975
   551
  proof
blanchet@55023
   552
    fix b' assume "b' \<in> underS r' (f a)"
blanchet@48975
   553
    hence "b' \<noteq> f a \<and> (b', f a) \<in> r'"
blanchet@55023
   554
    unfolding underS_def by simp
blanchet@55023
   555
    thus "b' \<in> f`(underS r a)"
blanchet@48975
   556
    using Well' SUC NE OF'
blanchet@55023
   557
          wo_rel.suc_ofilter_in[of r' "f ` underS r a" b'] by auto
blanchet@48975
   558
  qed
blanchet@48975
   559
  (*  *)
blanchet@55023
   560
  have INJ: "inj_on f (underS r a)"
blanchet@48975
   561
  proof-
blanchet@55023
   562
    have "\<forall>b \<in> underS r a. inj_on f (under r b)"
blanchet@48975
   563
    using IH by (auto simp add: bij_betw_def)
blanchet@48975
   564
    moreover
blanchet@55023
   565
    have "\<forall>b. wo_rel.ofilter r (under r b)"
blanchet@48975
   566
    using Well by (auto simp add: wo_rel.under_ofilter)
blanchet@48975
   567
    ultimately show  ?thesis
blanchet@48975
   568
    using WELL bFact UN
blanchet@55023
   569
          UNION_inj_on_ofilter[of r "underS r a" "\<lambda>b. under r b" f]
blanchet@48975
   570
    by auto
blanchet@48975
   571
  qed
blanchet@48975
   572
  (*  *)
blanchet@55023
   573
  have BIJ: "bij_betw f (underS r a) (underS r' (f a))"
blanchet@48975
   574
  unfolding bij_betw_def
blanchet@48975
   575
  using INJ INCL1 INCL2 by auto
blanchet@48975
   576
  (*  *)
blanchet@48975
   577
  have "f a \<in> Field r'"
blanchet@48975
   578
  using Well' subField NE SUC
blanchet@48975
   579
  by (auto simp add: wo_rel.suc_inField)
blanchet@48975
   580
  thus ?thesis
blanchet@48975
   581
  using WELL WELL' IN BIJ under_underS_bij_betw[of r r' a f] by auto
blanchet@48975
   582
qed
blanchet@48975
   583
blanchet@48975
   584
lemma wellorders_totally_ordered_aux2:
blanchet@48975
   585
fixes r ::"'a rel"  and r'::"'a' rel" and
blanchet@48975
   586
      f :: "'a \<Rightarrow> 'a'" and g :: "'a \<Rightarrow> bool"  and a::'a
blanchet@48975
   587
assumes WELL: "Well_order r" and WELL': "Well_order r'" and
blanchet@48975
   588
MAIN1:
blanchet@55023
   589
  "\<And> a. (False \<notin> g`(underS r a) \<and> f`(underS r a) \<noteq> Field r'
blanchet@55023
   590
          \<longrightarrow> f a = wo_rel.suc r' (f`(underS r a)) \<and> g a = True)
blanchet@48975
   591
         \<and>
blanchet@55023
   592
         (\<not>(False \<notin> (g`(underS r a)) \<and> f`(underS r a) \<noteq> Field r')
blanchet@48975
   593
          \<longrightarrow> g a = False)" and
blanchet@55023
   594
MAIN2: "\<And> a. a \<in> Field r \<and> False \<notin> g`(under r a) \<longrightarrow>
blanchet@55023
   595
              bij_betw f (under r a) (under r' (f a))" and
blanchet@55023
   596
Case: "a \<in> Field r \<and> False \<in> g`(under r a)"
blanchet@48975
   597
shows "\<exists>f'. embed r' r f'"
blanchet@48975
   598
proof-
blanchet@48975
   599
  have Well: "wo_rel r" using WELL unfolding wo_rel_def .
blanchet@48975
   600
  hence Refl: "Refl r" using wo_rel.REFL[of r] by auto
blanchet@48975
   601
  have Trans: "trans r" using Well wo_rel.TRANS[of r] by auto
blanchet@48975
   602
  have Antisym: "antisym r" using Well wo_rel.ANTISYM[of r] by auto
blanchet@48975
   603
  have Well': "wo_rel r'" using WELL' unfolding wo_rel_def .
blanchet@48975
   604
  (*  *)
blanchet@55023
   605
  have 0: "under r a = underS r a \<union> {a}"
blanchet@55023
   606
  using Refl Case by(auto simp add: Refl_under_underS)
blanchet@48975
   607
  (*  *)
blanchet@48975
   608
  have 1: "g a = False"
blanchet@48975
   609
  proof-
blanchet@48975
   610
    {assume "g a \<noteq> False"
blanchet@55023
   611
     with 0 Case have "False \<in> g`(underS r a)" by blast
blanchet@48975
   612
     with MAIN1 have "g a = False" by blast}
blanchet@48975
   613
    thus ?thesis by blast
blanchet@48975
   614
  qed
blanchet@48975
   615
  let ?A = "{a \<in> Field r. g a = False}"
blanchet@48975
   616
  let ?a = "(wo_rel.minim r ?A)"
blanchet@48975
   617
  (*  *)
blanchet@48975
   618
  have 2: "?A \<noteq> {} \<and> ?A \<le> Field r" using Case 1 by blast
blanchet@48975
   619
  (*  *)
blanchet@55023
   620
  have 3: "False \<notin> g`(underS r ?a)"
blanchet@48975
   621
  proof
blanchet@55023
   622
    assume "False \<in> g`(underS r ?a)"
blanchet@55023
   623
    then obtain b where "b \<in> underS r ?a" and 31: "g b = False" by auto
blanchet@48975
   624
    hence 32: "(b,?a) \<in> r \<and> b \<noteq> ?a"
blanchet@55023
   625
    by (auto simp add: underS_def)
blanchet@48975
   626
    hence "b \<in> Field r" unfolding Field_def by auto
blanchet@48975
   627
    with 31 have "b \<in> ?A" by auto
blanchet@48975
   628
    hence "(?a,b) \<in> r" using wo_rel.minim_least 2 Well by fastforce
blanchet@48975
   629
    (* again: why worked without type annotations? *)
blanchet@48975
   630
    with 32 Antisym show False
blanchet@48975
   631
    by (auto simp add: antisym_def)
blanchet@48975
   632
  qed
blanchet@48975
   633
  have temp: "?a \<in> ?A"
blanchet@48975
   634
  using Well 2 wo_rel.minim_in[of r ?A] by auto
blanchet@48975
   635
  hence 4: "?a \<in> Field r" by auto
blanchet@48975
   636
  (*   *)
blanchet@48975
   637
  have 5: "g ?a = False" using temp by blast
blanchet@48975
   638
  (*  *)
blanchet@55023
   639
  have 6: "f`(underS r ?a) = Field r'"
blanchet@48975
   640
  using MAIN1[of ?a] 3 5 by blast
blanchet@48975
   641
  (*  *)
blanchet@55023
   642
  have 7: "\<forall>b \<in> underS r ?a. bij_betw f (under r b) (under r' (f b))"
blanchet@48975
   643
  proof
blanchet@55023
   644
    fix b assume as: "b \<in> underS r ?a"
blanchet@48975
   645
    moreover
blanchet@55023
   646
    have "wo_rel.ofilter r (underS r ?a)"
blanchet@48975
   647
    using Well by (auto simp add: wo_rel.underS_ofilter)
blanchet@48975
   648
    ultimately
blanchet@55023
   649
    have "False \<notin> g`(under r b)" using 3 Well by (subst (asm) wo_rel.ofilter_def) fast+
blanchet@48975
   650
    moreover have "b \<in> Field r"
blanchet@55023
   651
    unfolding Field_def using as by (auto simp add: underS_def)
blanchet@48975
   652
    ultimately
blanchet@55023
   653
    show "bij_betw f (under r b) (under r' (f b))"
blanchet@48975
   654
    using MAIN2 by auto
blanchet@48975
   655
  qed
blanchet@48975
   656
  (*  *)
blanchet@55023
   657
  have "embed r' r (inv_into (underS r ?a) f)"
blanchet@48975
   658
  using WELL WELL' 7 4 6 inv_into_underS_embed[of r ?a f r'] by auto
blanchet@48975
   659
  thus ?thesis
blanchet@48975
   660
  unfolding embed_def by blast
blanchet@48975
   661
qed
blanchet@48975
   662
blanchet@48975
   663
theorem wellorders_totally_ordered:
blanchet@48975
   664
fixes r ::"'a rel"  and r'::"'a' rel"
blanchet@48975
   665
assumes WELL: "Well_order r" and WELL': "Well_order r'"
blanchet@48975
   666
shows "(\<exists>f. embed r r' f) \<or> (\<exists>f'. embed r' r f')"
blanchet@48975
   667
proof-
blanchet@48975
   668
  (* Preliminary facts *)
blanchet@48975
   669
  have Well: "wo_rel r" using WELL unfolding wo_rel_def .
blanchet@48975
   670
  hence Refl: "Refl r" using wo_rel.REFL[of r] by auto
blanchet@48975
   671
  have Trans: "trans r" using Well wo_rel.TRANS[of r] by auto
blanchet@48975
   672
  have Well': "wo_rel r'" using WELL' unfolding wo_rel_def .
blanchet@48975
   673
  (* Main proof *)
blanchet@48975
   674
  obtain H where H_def: "H =
blanchet@55023
   675
  (\<lambda>h a. if False \<notin> (snd o h)`(underS r a) \<and> (fst o h)`(underS r a) \<noteq> Field r'
blanchet@55023
   676
                then (wo_rel.suc r' ((fst o h)`(underS r a)), True)
blanchet@48975
   677
                else (undefined, False))" by blast
blanchet@48975
   678
  have Adm: "wo_rel.adm_wo r H"
blanchet@48975
   679
  using Well
blanchet@48975
   680
  proof(unfold wo_rel.adm_wo_def, clarify)
blanchet@48975
   681
    fix h1::"'a \<Rightarrow> 'a' * bool" and h2::"'a \<Rightarrow> 'a' * bool" and x
blanchet@55023
   682
    assume "\<forall>y\<in>underS r x. h1 y = h2 y"
blanchet@55023
   683
    hence "\<forall>y\<in>underS r x. (fst o h1) y = (fst o h2) y \<and>
blanchet@48975
   684
                          (snd o h1) y = (snd o h2) y" by auto
blanchet@55023
   685
    hence "(fst o h1)`(underS r x) = (fst o h2)`(underS r x) \<and>
blanchet@55023
   686
           (snd o h1)`(underS r x) = (snd o h2)`(underS r x)"
wenzelm@49922
   687
      by (auto simp add: image_def)
wenzelm@49922
   688
    thus "H h1 x = H h2 x" by (simp add: H_def del: not_False_in_image_Ball)
blanchet@48975
   689
  qed
blanchet@48975
   690
  (* More constant definitions:  *)
blanchet@48975
   691
  obtain h::"'a \<Rightarrow> 'a' * bool" and f::"'a \<Rightarrow> 'a'" and g::"'a \<Rightarrow> bool"
blanchet@48975
   692
  where h_def: "h = wo_rel.worec r H" and
blanchet@48975
   693
        f_def: "f = fst o h" and g_def: "g = snd o h" by blast
blanchet@48975
   694
  obtain test where test_def:
blanchet@55023
   695
  "test = (\<lambda> a. False \<notin> (g`(underS r a)) \<and> f`(underS r a) \<noteq> Field r')" by blast
blanchet@48975
   696
  (*  *)
blanchet@48975
   697
  have *: "\<And> a. h a  = H h a"
blanchet@48975
   698
  using Adm Well wo_rel.worec_fixpoint[of r H] by (simp add: h_def)
blanchet@48975
   699
  have Main1:
blanchet@55023
   700
  "\<And> a. (test a \<longrightarrow> f a = wo_rel.suc r' (f`(underS r a)) \<and> g a = True) \<and>
blanchet@48975
   701
         (\<not>(test a) \<longrightarrow> g a = False)"
blanchet@48975
   702
  proof-  (* How can I prove this withou fixing a? *)
blanchet@55023
   703
    fix a show "(test a \<longrightarrow> f a = wo_rel.suc r' (f`(underS r a)) \<and> g a = True) \<and>
blanchet@48975
   704
                (\<not>(test a) \<longrightarrow> g a = False)"
blanchet@48975
   705
    using *[of a] test_def f_def g_def H_def by auto
blanchet@48975
   706
  qed
blanchet@48975
   707
  (*  *)
blanchet@55023
   708
  let ?phi = "\<lambda> a. a \<in> Field r \<and> False \<notin> g`(under r a) \<longrightarrow>
blanchet@55023
   709
                   bij_betw f (under r a) (under r' (f a))"
blanchet@48975
   710
  have Main2: "\<And> a. ?phi a"
blanchet@48975
   711
  proof-
blanchet@48975
   712
    fix a show "?phi a"
blanchet@48975
   713
    proof(rule wo_rel.well_order_induct[of r ?phi],
blanchet@48975
   714
          simp only: Well, clarify)
blanchet@48975
   715
      fix a
blanchet@48975
   716
      assume IH: "\<forall>b. b \<noteq> a \<and> (b,a) \<in> r \<longrightarrow> ?phi b" and
blanchet@48975
   717
             *: "a \<in> Field r" and
blanchet@55023
   718
             **: "False \<notin> g`(under r a)"
blanchet@55023
   719
      have 1: "\<forall>b \<in> underS r a. bij_betw f (under r b) (under r' (f b))"
blanchet@48975
   720
      proof(clarify)
blanchet@55023
   721
        fix b assume ***: "b \<in> underS r a"
blanchet@55023
   722
        hence 0: "(b,a) \<in> r \<and> b \<noteq> a" unfolding underS_def by auto
blanchet@48975
   723
        moreover have "b \<in> Field r"
blanchet@55023
   724
        using *** underS_Field[of r a] by auto
blanchet@55023
   725
        moreover have "False \<notin> g`(under r b)"
blanchet@55023
   726
        using 0 ** Trans under_incr[of r b a] by auto
blanchet@55023
   727
        ultimately show "bij_betw f (under r b) (under r' (f b))"
blanchet@48975
   728
        using IH by auto
blanchet@48975
   729
      qed
blanchet@48975
   730
      (*  *)
blanchet@55023
   731
      have 21: "False \<notin> g`(underS r a)"
blanchet@55023
   732
      using ** underS_subset_under[of r a] by auto
blanchet@55023
   733
      have 22: "g`(under r a) \<le> {True}" using ** by auto
blanchet@55023
   734
      moreover have 23: "a \<in> under r a"
blanchet@55023
   735
      using Refl * by (auto simp add: Refl_under_in)
blanchet@48975
   736
      ultimately have 24: "g a = True" by blast
blanchet@55023
   737
      have 2: "f`(underS r a) \<noteq> Field r'"
blanchet@48975
   738
      proof
blanchet@55023
   739
        assume "f`(underS r a) = Field r'"
blanchet@48975
   740
        hence "g a = False" using Main1 test_def by blast
blanchet@48975
   741
        with 24 show False using ** by blast
blanchet@48975
   742
      qed
blanchet@48975
   743
      (*  *)
blanchet@55023
   744
      have 3: "f a = wo_rel.suc r' (f`(underS r a))"
blanchet@48975
   745
      using 21 2 Main1 test_def by blast
blanchet@48975
   746
      (*  *)
blanchet@55023
   747
      show "bij_betw f (under r a) (under r' (f a))"
blanchet@48975
   748
      using WELL  WELL' 1 2 3 *
blanchet@48975
   749
            wellorders_totally_ordered_aux[of r r' a f] by auto
blanchet@48975
   750
    qed
blanchet@48975
   751
  qed
blanchet@48975
   752
  (*  *)
blanchet@55023
   753
  let ?chi = "(\<lambda> a. a \<in> Field r \<and> False \<in> g`(under r a))"
blanchet@48975
   754
  show ?thesis
blanchet@48975
   755
  proof(cases "\<exists>a. ?chi a")
blanchet@48975
   756
    assume "\<not> (\<exists>a. ?chi a)"
blanchet@55023
   757
    hence "\<forall>a \<in> Field r.  bij_betw f (under r a) (under r' (f a))"
blanchet@48975
   758
    using Main2 by blast
blanchet@48975
   759
    thus ?thesis unfolding embed_def by blast
blanchet@48975
   760
  next
blanchet@48975
   761
    assume "\<exists>a. ?chi a"
blanchet@48975
   762
    then obtain a where "?chi a" by blast
blanchet@48975
   763
    hence "\<exists>f'. embed r' r f'"
blanchet@48975
   764
    using wellorders_totally_ordered_aux2[of r r' g f a]
blanchet@54482
   765
          WELL WELL' Main1 Main2 test_def by fast
blanchet@48975
   766
    thus ?thesis by blast
blanchet@48975
   767
  qed
blanchet@48975
   768
qed
blanchet@48975
   769
blanchet@48975
   770
blanchet@55101
   771
subsection {* Uniqueness of embeddings *}
blanchet@48975
   772
blanchet@48975
   773
text{* Here we show a fact complementary to the one from the previous subsection -- namely,
blanchet@48975
   774
that between any two well-orders there is {\em at most} one embedding, and is the one
blanchet@48975
   775
definable by the expected well-order recursive equation.  As a consequence, any two
blanchet@48975
   776
embeddings of opposite directions are mutually inverse. *}
blanchet@48975
   777
blanchet@48975
   778
lemma embed_determined:
blanchet@48975
   779
assumes WELL: "Well_order r" and WELL': "Well_order r'" and
blanchet@48975
   780
        EMB: "embed r r' f" and IN: "a \<in> Field r"
blanchet@55023
   781
shows "f a = wo_rel.suc r' (f`(underS r a))"
blanchet@48975
   782
proof-
blanchet@55023
   783
  have "bij_betw f (underS r a) (underS r' (f a))"
blanchet@48975
   784
  using assms by (auto simp add: embed_underS)
blanchet@55023
   785
  hence "f`(underS r a) = underS r' (f a)"
blanchet@48975
   786
  by (auto simp add: bij_betw_def)
blanchet@48975
   787
  moreover
blanchet@48975
   788
  {have "f a \<in> Field r'" using IN
blanchet@48975
   789
   using EMB WELL embed_Field[of r r' f] by auto
blanchet@55023
   790
   hence "f a = wo_rel.suc r' (underS r' (f a))"
blanchet@48975
   791
   using WELL' by (auto simp add: wo_rel_def wo_rel.suc_underS)
blanchet@48975
   792
  }
blanchet@48975
   793
  ultimately show ?thesis by simp
blanchet@48975
   794
qed
blanchet@48975
   795
blanchet@48975
   796
lemma embed_unique:
blanchet@48975
   797
assumes WELL: "Well_order r" and WELL': "Well_order r'" and
blanchet@48975
   798
        EMBf: "embed r r' f" and EMBg: "embed r r' g"
blanchet@48975
   799
shows "a \<in> Field r \<longrightarrow> f a = g a"
blanchet@48975
   800
proof(rule wo_rel.well_order_induct[of r], auto simp add: WELL wo_rel_def)
blanchet@48975
   801
  fix a
blanchet@48975
   802
  assume IH: "\<forall>b. b \<noteq> a \<and> (b,a): r \<longrightarrow> b \<in> Field r \<longrightarrow> f b = g b" and
blanchet@48975
   803
         *: "a \<in> Field r"
blanchet@55023
   804
  hence "\<forall>b \<in> underS r a. f b = g b"
blanchet@55023
   805
  unfolding underS_def by (auto simp add: Field_def)
blanchet@55023
   806
  hence "f`(underS r a) = g`(underS r a)" by force
blanchet@48975
   807
  thus "f a = g a"
blanchet@48975
   808
  using assms * embed_determined[of r r' f a] embed_determined[of r r' g a] by auto
blanchet@48975
   809
qed
blanchet@48975
   810
blanchet@48975
   811
lemma embed_bothWays_inverse:
blanchet@48975
   812
assumes WELL: "Well_order r" and WELL': "Well_order r'" and
blanchet@48975
   813
        EMB: "embed r r' f" and EMB': "embed r' r f'"
blanchet@48975
   814
shows "(\<forall>a \<in> Field r. f'(f a) = a) \<and> (\<forall>a' \<in> Field r'. f(f' a') = a')"
blanchet@48975
   815
proof-
blanchet@48975
   816
  have "embed r r (f' o f)" using assms
blanchet@48975
   817
  by(auto simp add: comp_embed)
blanchet@48975
   818
  moreover have "embed r r id" using assms
blanchet@48975
   819
  by (auto simp add: id_embed)
blanchet@48975
   820
  ultimately have "\<forall>a \<in> Field r. f'(f a) = a"
blanchet@48975
   821
  using assms embed_unique[of r r "f' o f" id] id_def by auto
blanchet@48975
   822
  moreover
blanchet@48975
   823
  {have "embed r' r' (f o f')" using assms
blanchet@48975
   824
   by(auto simp add: comp_embed)
blanchet@48975
   825
   moreover have "embed r' r' id" using assms
blanchet@48975
   826
   by (auto simp add: id_embed)
blanchet@48975
   827
   ultimately have "\<forall>a' \<in> Field r'. f(f' a') = a'"
blanchet@48975
   828
   using assms embed_unique[of r' r' "f o f'" id] id_def by auto
blanchet@48975
   829
  }
blanchet@48975
   830
  ultimately show ?thesis by blast
blanchet@48975
   831
qed
blanchet@48975
   832
blanchet@48975
   833
lemma embed_bothWays_bij_betw:
blanchet@48975
   834
assumes WELL: "Well_order r" and WELL': "Well_order r'" and
blanchet@48975
   835
        EMB: "embed r r' f" and EMB': "embed r' r g"
blanchet@48975
   836
shows "bij_betw f (Field r) (Field r')"
blanchet@48975
   837
proof-
blanchet@48975
   838
  let ?A = "Field r"  let ?A' = "Field r'"
blanchet@48975
   839
  have "embed r r (g o f) \<and> embed r' r' (f o g)"
blanchet@48975
   840
  using assms by (auto simp add: comp_embed)
blanchet@48975
   841
  hence 1: "(\<forall>a \<in> ?A. g(f a) = a) \<and> (\<forall>a' \<in> ?A'. f(g a') = a')"
blanchet@48975
   842
  using WELL id_embed[of r] embed_unique[of r r "g o f" id]
blanchet@48975
   843
        WELL' id_embed[of r'] embed_unique[of r' r' "f o g" id]
blanchet@48975
   844
        id_def by auto
blanchet@48975
   845
  have 2: "(\<forall>a \<in> ?A. f a \<in> ?A') \<and> (\<forall>a' \<in> ?A'. g a' \<in> ?A)"
blanchet@48975
   846
  using assms embed_Field[of r r' f] embed_Field[of r' r g] by blast
blanchet@48975
   847
  (*  *)
blanchet@48975
   848
  show ?thesis
blanchet@48975
   849
  proof(unfold bij_betw_def inj_on_def, auto simp add: 2)
blanchet@48975
   850
    fix a b assume *: "a \<in> ?A" "b \<in> ?A" and **: "f a = f b"
blanchet@48975
   851
    have "a = g(f a) \<and> b = g(f b)" using * 1 by auto
blanchet@48975
   852
    with ** show "a = b" by auto
blanchet@48975
   853
  next
blanchet@48975
   854
    fix a' assume *: "a' \<in> ?A'"
blanchet@48975
   855
    hence "g a' \<in> ?A \<and> f(g a') = a'" using 1 2 by auto
blanchet@48975
   856
    thus "a' \<in> f ` ?A" by force
blanchet@48975
   857
  qed
blanchet@48975
   858
qed
blanchet@48975
   859
blanchet@48975
   860
lemma embed_bothWays_iso:
blanchet@48975
   861
assumes WELL: "Well_order r"  and WELL': "Well_order r'" and
blanchet@48975
   862
        EMB: "embed r r' f" and EMB': "embed r' r g"
blanchet@48975
   863
shows "iso r r' f"
blanchet@48975
   864
unfolding iso_def using assms by (auto simp add: embed_bothWays_bij_betw)
blanchet@48975
   865
blanchet@48975
   866
blanchet@55101
   867
subsection {* More properties of embeddings, strict embeddings and isomorphisms *}
blanchet@48975
   868
blanchet@48975
   869
lemma embed_bothWays_Field_bij_betw:
blanchet@48975
   870
assumes WELL: "Well_order r" and WELL': "Well_order r'" and
blanchet@48975
   871
        EMB: "embed r r' f" and EMB': "embed r' r f'"
blanchet@48975
   872
shows "bij_betw f (Field r) (Field r')"
blanchet@48975
   873
proof-
blanchet@48975
   874
  have "(\<forall>a \<in> Field r. f'(f a) = a) \<and> (\<forall>a' \<in> Field r'. f(f' a') = a')"
blanchet@48975
   875
  using assms by (auto simp add: embed_bothWays_inverse)
blanchet@48975
   876
  moreover
blanchet@48975
   877
  have "f`(Field r) \<le> Field r' \<and> f' ` (Field r') \<le> Field r"
blanchet@48975
   878
  using assms by (auto simp add: embed_Field)
blanchet@48975
   879
  ultimately
blanchet@48975
   880
  show ?thesis using bij_betw_byWitness[of "Field r" f' f "Field r'"] by auto
blanchet@48975
   881
qed
blanchet@48975
   882
blanchet@48975
   883
lemma embedS_comp_embed:
blanchet@48975
   884
assumes WELL: "Well_order r" and WELL': "Well_order r'" and WELL'': "Well_order r''"
blanchet@48975
   885
        and  EMB: "embedS r r' f" and EMB': "embed r' r'' f'"
blanchet@48975
   886
shows "embedS r r'' (f' o f)"
blanchet@48975
   887
proof-
blanchet@48975
   888
  let ?g = "(f' o f)"  let ?h = "inv_into (Field r) ?g"
blanchet@48975
   889
  have 1: "embed r r' f \<and> \<not> (bij_betw f (Field r) (Field r'))"
blanchet@48975
   890
  using EMB by (auto simp add: embedS_def)
blanchet@48975
   891
  hence 2: "embed r r'' ?g"
blanchet@48975
   892
  using WELL EMB' comp_embed[of r r' f r'' f'] by auto
blanchet@48975
   893
  moreover
blanchet@48975
   894
  {assume "bij_betw ?g (Field r) (Field r'')"
blanchet@48975
   895
   hence "embed r'' r ?h" using 2 WELL
blanchet@48975
   896
   by (auto simp add: inv_into_Field_embed_bij_betw)
blanchet@48975
   897
   hence "embed r' r (?h o f')" using WELL' EMB'
blanchet@48975
   898
   by (auto simp add: comp_embed)
blanchet@48975
   899
   hence "bij_betw f (Field r) (Field r')" using WELL WELL' 1
blanchet@48975
   900
   by (auto simp add: embed_bothWays_Field_bij_betw)
blanchet@48975
   901
   with 1 have False by blast
blanchet@48975
   902
  }
blanchet@48975
   903
  ultimately show ?thesis unfolding embedS_def by auto
blanchet@48975
   904
qed
blanchet@48975
   905
blanchet@48975
   906
lemma embed_comp_embedS:
blanchet@48975
   907
assumes WELL: "Well_order r" and WELL': "Well_order r'" and WELL'': "Well_order r''"
blanchet@48975
   908
        and  EMB: "embed r r' f" and EMB': "embedS r' r'' f'"
blanchet@48975
   909
shows "embedS r r'' (f' o f)"
blanchet@48975
   910
proof-
blanchet@48975
   911
  let ?g = "(f' o f)"  let ?h = "inv_into (Field r) ?g"
blanchet@48975
   912
  have 1: "embed r' r'' f' \<and> \<not> (bij_betw f' (Field r') (Field r''))"
blanchet@48975
   913
  using EMB' by (auto simp add: embedS_def)
blanchet@48975
   914
  hence 2: "embed r r'' ?g"
blanchet@48975
   915
  using WELL EMB comp_embed[of r r' f r'' f'] by auto
blanchet@48975
   916
  moreover
blanchet@48975
   917
  {assume "bij_betw ?g (Field r) (Field r'')"
blanchet@48975
   918
   hence "embed r'' r ?h" using 2 WELL
blanchet@48975
   919
   by (auto simp add: inv_into_Field_embed_bij_betw)
blanchet@48975
   920
   hence "embed r'' r' (f o ?h)" using WELL'' EMB
blanchet@48975
   921
   by (auto simp add: comp_embed)
blanchet@48975
   922
   hence "bij_betw f' (Field r') (Field r'')" using WELL' WELL'' 1
blanchet@48975
   923
   by (auto simp add: embed_bothWays_Field_bij_betw)
blanchet@48975
   924
   with 1 have False by blast
blanchet@48975
   925
  }
blanchet@48975
   926
  ultimately show ?thesis unfolding embedS_def by auto
blanchet@48975
   927
qed
blanchet@48975
   928
blanchet@48975
   929
lemma embed_comp_iso:
blanchet@48975
   930
assumes WELL: "Well_order r" and WELL': "Well_order r'" and WELL'': "Well_order r''"
blanchet@48975
   931
        and  EMB: "embed r r' f" and EMB': "iso r' r'' f'"
blanchet@48975
   932
shows "embed r r'' (f' o f)"
blanchet@48975
   933
using assms unfolding iso_def
blanchet@48975
   934
by (auto simp add: comp_embed)
blanchet@48975
   935
blanchet@48975
   936
lemma iso_comp_embed:
blanchet@48975
   937
assumes WELL: "Well_order r" and WELL': "Well_order r'" and WELL'': "Well_order r''"
blanchet@48975
   938
        and  EMB: "iso r r' f" and EMB': "embed r' r'' f'"
blanchet@48975
   939
shows "embed r r'' (f' o f)"
blanchet@48975
   940
using assms unfolding iso_def
blanchet@48975
   941
by (auto simp add: comp_embed)
blanchet@48975
   942
blanchet@48975
   943
lemma embedS_comp_iso:
blanchet@48975
   944
assumes WELL: "Well_order r" and WELL': "Well_order r'" and WELL'': "Well_order r''"
blanchet@48975
   945
        and  EMB: "embedS r r' f" and EMB': "iso r' r'' f'"
blanchet@48975
   946
shows "embedS r r'' (f' o f)"
blanchet@48975
   947
using assms unfolding iso_def
blanchet@48975
   948
by (auto simp add: embedS_comp_embed)
blanchet@48975
   949
blanchet@48975
   950
lemma iso_comp_embedS:
blanchet@48975
   951
assumes WELL: "Well_order r" and WELL': "Well_order r'" and WELL'': "Well_order r''"
blanchet@48975
   952
        and  EMB: "iso r r' f" and EMB': "embedS r' r'' f'"
blanchet@48975
   953
shows "embedS r r'' (f' o f)"
blanchet@48975
   954
using assms unfolding iso_def  using embed_comp_embedS
blanchet@48975
   955
by (auto simp add: embed_comp_embedS)
blanchet@48975
   956
blanchet@48975
   957
lemma embedS_Field:
blanchet@48975
   958
assumes WELL: "Well_order r" and EMB: "embedS r r' f"
blanchet@48975
   959
shows "f ` (Field r) < Field r'"
blanchet@48975
   960
proof-
blanchet@48975
   961
  have "f`(Field r) \<le> Field r'" using assms
blanchet@48975
   962
  by (auto simp add: embed_Field embedS_def)
blanchet@48975
   963
  moreover
blanchet@48975
   964
  {have "inj_on f (Field r)" using assms
blanchet@48975
   965
   by (auto simp add: embedS_def embed_inj_on)
blanchet@48975
   966
   hence "f`(Field r) \<noteq> Field r'" using EMB
blanchet@48975
   967
   by (auto simp add: embedS_def bij_betw_def)
blanchet@48975
   968
  }
blanchet@48975
   969
  ultimately show ?thesis by blast
blanchet@48975
   970
qed
blanchet@48975
   971
blanchet@48975
   972
lemma embedS_iff:
blanchet@48975
   973
assumes WELL: "Well_order r" and ISO: "embed r r' f"
blanchet@48975
   974
shows "embedS r r' f = (f ` (Field r) < Field r')"
blanchet@48975
   975
proof
blanchet@48975
   976
  assume "embedS r r' f"
blanchet@48975
   977
  thus "f ` Field r \<subset> Field r'"
blanchet@48975
   978
  using WELL by (auto simp add: embedS_Field)
blanchet@48975
   979
next
blanchet@48975
   980
  assume "f ` Field r \<subset> Field r'"
blanchet@48975
   981
  hence "\<not> bij_betw f (Field r) (Field r')"
blanchet@48975
   982
  unfolding bij_betw_def by blast
blanchet@48975
   983
  thus "embedS r r' f" unfolding embedS_def
blanchet@48975
   984
  using ISO by auto
blanchet@48975
   985
qed
blanchet@48975
   986
blanchet@48975
   987
lemma iso_Field:
blanchet@48975
   988
"iso r r' f \<Longrightarrow> f ` (Field r) = Field r'"
blanchet@48975
   989
using assms by (auto simp add: iso_def bij_betw_def)
blanchet@48975
   990
blanchet@48975
   991
lemma iso_iff:
blanchet@48975
   992
assumes "Well_order r"
blanchet@48975
   993
shows "iso r r' f = (embed r r' f \<and> f ` (Field r) = Field r')"
blanchet@48975
   994
proof
blanchet@48975
   995
  assume "iso r r' f"
blanchet@48975
   996
  thus "embed r r' f \<and> f ` (Field r) = Field r'"
blanchet@48975
   997
  by (auto simp add: iso_Field iso_def)
blanchet@48975
   998
next
blanchet@48975
   999
  assume *: "embed r r' f \<and> f ` Field r = Field r'"
blanchet@48975
  1000
  hence "inj_on f (Field r)" using assms by (auto simp add: embed_inj_on)
blanchet@48975
  1001
  with * have "bij_betw f (Field r) (Field r')"
blanchet@48975
  1002
  unfolding bij_betw_def by simp
blanchet@48975
  1003
  with * show "iso r r' f" unfolding iso_def by auto
blanchet@48975
  1004
qed
blanchet@48975
  1005
blanchet@48975
  1006
lemma iso_iff2:
blanchet@48975
  1007
assumes "Well_order r"
blanchet@48975
  1008
shows "iso r r' f = (bij_betw f (Field r) (Field r') \<and>
blanchet@48975
  1009
                     (\<forall>a \<in> Field r. \<forall>b \<in> Field r.
blanchet@48975
  1010
                         (((a,b) \<in> r) = ((f a, f b) \<in> r'))))"
blanchet@48975
  1011
using assms
blanchet@48975
  1012
proof(auto simp add: iso_def)
blanchet@48975
  1013
  fix a b
blanchet@48975
  1014
  assume "embed r r' f"
blanchet@48975
  1015
  hence "compat r r' f" using embed_compat[of r] by auto
blanchet@48975
  1016
  moreover assume "(a,b) \<in> r"
blanchet@48975
  1017
  ultimately show "(f a, f b) \<in> r'" using compat_def[of r] by auto
blanchet@48975
  1018
next
blanchet@48975
  1019
  let ?f' = "inv_into (Field r) f"
blanchet@48975
  1020
  assume "embed r r' f" and 1: "bij_betw f (Field r) (Field r')"
blanchet@48975
  1021
  hence "embed r' r ?f'" using assms
blanchet@48975
  1022
  by (auto simp add: inv_into_Field_embed_bij_betw)
blanchet@48975
  1023
  hence 2: "compat r' r ?f'" using embed_compat[of r'] by auto
blanchet@48975
  1024
  fix a b assume *: "a \<in> Field r" "b \<in> Field r" and **: "(f a,f b) \<in> r'"
blanchet@48975
  1025
  hence "?f'(f a) = a \<and> ?f'(f b) = b" using 1
blanchet@48975
  1026
  by (auto simp add: bij_betw_inv_into_left)
blanchet@48975
  1027
  thus "(a,b) \<in> r" using ** 2 compat_def[of r' r ?f'] by fastforce
blanchet@48975
  1028
next
blanchet@48975
  1029
  assume *: "bij_betw f (Field r) (Field r')" and
blanchet@48975
  1030
         **: "\<forall>a\<in>Field r. \<forall>b\<in>Field r. ((a, b) \<in> r) = ((f a, f b) \<in> r')"
blanchet@55023
  1031
  have 1: "\<And> a. under r a \<le> Field r \<and> under r' (f a) \<le> Field r'"
blanchet@55023
  1032
  by (auto simp add: under_Field)
blanchet@48975
  1033
  have 2: "inj_on f (Field r)" using * by (auto simp add: bij_betw_def)
blanchet@48975
  1034
  {fix a assume ***: "a \<in> Field r"
blanchet@55023
  1035
   have "bij_betw f (under r a) (under r' (f a))"
blanchet@48975
  1036
   proof(unfold bij_betw_def, auto)
traytel@55811
  1037
     show "inj_on f (under r a)" using 1 2 subset_inj_on by blast
blanchet@48975
  1038
   next
blanchet@55023
  1039
     fix b assume "b \<in> under r a"
blanchet@48975
  1040
     hence "a \<in> Field r \<and> b \<in> Field r \<and> (b,a) \<in> r"
blanchet@55023
  1041
     unfolding under_def by (auto simp add: Field_def Range_def Domain_def)
blanchet@55023
  1042
     with 1 ** show "f b \<in> under r' (f a)"
blanchet@55023
  1043
     unfolding under_def by auto
blanchet@48975
  1044
   next
blanchet@55023
  1045
     fix b' assume "b' \<in> under r' (f a)"
blanchet@55023
  1046
     hence 3: "(b',f a) \<in> r'" unfolding under_def by simp
blanchet@48975
  1047
     hence "b' \<in> Field r'" unfolding Field_def by auto
blanchet@48975
  1048
     with * obtain b where "b \<in> Field r \<and> f b = b'"
blanchet@48975
  1049
     unfolding bij_betw_def by force
blanchet@48975
  1050
     with 3 ** ***
blanchet@55023
  1051
     show "b' \<in> f ` (under r a)" unfolding under_def by blast
blanchet@48975
  1052
   qed
blanchet@48975
  1053
  }
blanchet@48975
  1054
  thus "embed r r' f" unfolding embed_def using * by auto
blanchet@48975
  1055
qed
blanchet@48975
  1056
blanchet@48975
  1057
lemma iso_iff3:
blanchet@48975
  1058
assumes WELL: "Well_order r" and WELL': "Well_order r'"
blanchet@48975
  1059
shows "iso r r' f = (bij_betw f (Field r) (Field r') \<and> compat r r' f)"
blanchet@48975
  1060
proof
blanchet@48975
  1061
  assume "iso r r' f"
blanchet@48975
  1062
  thus "bij_betw f (Field r) (Field r') \<and> compat r r' f"
blanchet@48975
  1063
  unfolding compat_def using WELL by (auto simp add: iso_iff2 Field_def)
blanchet@48975
  1064
next
blanchet@48975
  1065
  have Well: "wo_rel r \<and> wo_rel r'" using WELL WELL'
blanchet@48975
  1066
  by (auto simp add: wo_rel_def)
blanchet@48975
  1067
  assume *: "bij_betw f (Field r) (Field r') \<and> compat r r' f"
blanchet@48975
  1068
  thus "iso r r' f"
blanchet@48975
  1069
  unfolding "compat_def" using assms
blanchet@48975
  1070
  proof(auto simp add: iso_iff2)
blanchet@48975
  1071
    fix a b assume **: "a \<in> Field r" "b \<in> Field r" and
blanchet@48975
  1072
                  ***: "(f a, f b) \<in> r'"
blanchet@48975
  1073
    {assume "(b,a) \<in> r \<or> b = a"
blanchet@48975
  1074
     hence "(b,a): r"using Well ** wo_rel.REFL[of r] refl_on_def[of _ r] by blast
blanchet@48975
  1075
     hence "(f b, f a) \<in> r'" using * unfolding compat_def by auto
blanchet@48975
  1076
     hence "f a = f b"
blanchet@48975
  1077
     using Well *** wo_rel.ANTISYM[of r'] antisym_def[of r'] by blast
blanchet@48975
  1078
     hence "a = b" using * ** unfolding bij_betw_def inj_on_def by auto
blanchet@48975
  1079
     hence "(a,b) \<in> r" using Well ** wo_rel.REFL[of r] refl_on_def[of _ r] by blast
blanchet@48975
  1080
    }
blanchet@48975
  1081
    thus "(a,b) \<in> r"
blanchet@48975
  1082
    using Well ** wo_rel.TOTAL[of r] total_on_def[of _ r] by blast
blanchet@48975
  1083
  qed
blanchet@48975
  1084
qed
blanchet@48975
  1085
blanchet@48975
  1086
end