src/HOL/BNF_Wellorder_Embedding.thy
author blanchet
Wed Jan 22 09:45:30 2014 +0100 (2014-01-22)
changeset 55101 57c875e488bd
parent 55059 ef2e0fb783c6
child 55811 aa1acc25126b
permissions -rw-r--r--
whitespace tuning
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
blanchet@55059
     8
header {* Well-Order Embeddings as Needed by Bounded Natural Functors *}
blanchet@48975
     9
blanchet@55056
    10
theory BNF_Wellorder_Embedding
blanchet@55056
    11
imports Zorn 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)
blanchet@55023
   308
    show  "inj_on f (under r a)"
blanchet@55023
   309
    using * by (metis (no_types) under_Field subset_inj_on)
blanchet@48975
   310
  next
blanchet@55023
   311
    fix b assume "b \<in> under r a"
blanchet@55023
   312
    thus "f b \<in> under r' (f a)"
blanchet@55023
   313
    unfolding under_def using **
blanchet@48975
   314
    by (auto simp add: compat_def)
blanchet@48975
   315
  next
blanchet@55023
   316
    fix b' assume *****: "b' \<in> under r' (f a)"
blanchet@48975
   317
    hence "b' \<in> f`(Field r)"
blanchet@48975
   318
    using 2 by auto
blanchet@48975
   319
    with Field_def[of r] obtain b where
blanchet@48975
   320
    3: "b \<in> Field r" and 4: "b' = f b" by auto
blanchet@48975
   321
    have "(b,a): r"
blanchet@48975
   322
    proof-
blanchet@48975
   323
      {assume "(a,b) \<in> r"
blanchet@48975
   324
       with ** 4 have "(f a, b'): r'"
blanchet@48975
   325
       by (auto simp add: compat_def)
blanchet@48975
   326
       with ***** Antisym' have "f a = b'"
blanchet@55023
   327
       by(auto simp add: under_def antisym_def)
blanchet@48975
   328
       with 3 **** 4 * have "a = b"
blanchet@48975
   329
       by(auto simp add: inj_on_def)
blanchet@48975
   330
      }
blanchet@48975
   331
      moreover
blanchet@48975
   332
      {assume "a = b"
blanchet@48975
   333
       hence "(b,a) \<in> r" using Refl **** 3
blanchet@48975
   334
       by (auto simp add: refl_on_def)
blanchet@48975
   335
      }
blanchet@48975
   336
      ultimately
blanchet@48975
   337
      show ?thesis using Total **** 3 by (fastforce simp add: total_on_def)
blanchet@48975
   338
    qed
blanchet@55023
   339
    with 4 show  "b' \<in> f`(under r a)"
blanchet@55023
   340
    unfolding under_def by auto
blanchet@48975
   341
  qed
blanchet@48975
   342
qed
blanchet@48975
   343
blanchet@48975
   344
lemma inv_into_ofilter_embed:
blanchet@48975
   345
assumes WELL: "Well_order r" and OF: "wo_rel.ofilter r A" and
blanchet@55023
   346
        BIJ: "\<forall>b \<in> A. bij_betw f (under r b) (under r' (f b))" and
blanchet@48975
   347
        IMAGE: "f ` A = Field r'"
blanchet@48975
   348
shows "embed r' r (inv_into A f)"
blanchet@48975
   349
proof-
blanchet@48975
   350
  (* Preliminary facts *)
blanchet@48975
   351
  have Well: "wo_rel r"
blanchet@48975
   352
  using WELL wo_rel_def[of r] by simp
blanchet@48975
   353
  have Refl: "Refl r"
blanchet@48975
   354
  using Well wo_rel.REFL[of r] by simp
blanchet@48975
   355
  have Total: "Total r"
blanchet@48975
   356
  using Well wo_rel.TOTAL[of r] by simp
blanchet@48975
   357
  (* Main proof *)
blanchet@48975
   358
  have 1: "bij_betw f A (Field r')"
blanchet@48975
   359
  proof(unfold bij_betw_def inj_on_def, auto simp add: IMAGE)
blanchet@48975
   360
    fix b1 b2
blanchet@48975
   361
    assume *: "b1 \<in> A" and **: "b2 \<in> A" and
blanchet@48975
   362
           ***: "f b1 = f b2"
blanchet@48975
   363
    have 11: "b1 \<in> Field r \<and> b2 \<in> Field r"
blanchet@48975
   364
    using * ** Well OF by (auto simp add: wo_rel.ofilter_def)
blanchet@48975
   365
    moreover
blanchet@48975
   366
    {assume "(b1,b2) \<in> r"
blanchet@55023
   367
     hence "b1 \<in> under r b2 \<and> b2 \<in> under r b2"
blanchet@55023
   368
     unfolding under_def using 11 Refl
blanchet@48975
   369
     by (auto simp add: refl_on_def)
blanchet@48975
   370
     hence "b1 = b2" using BIJ * ** ***
blanchet@54482
   371
     by (simp add: bij_betw_def inj_on_def)
blanchet@48975
   372
    }
blanchet@48975
   373
    moreover
blanchet@48975
   374
     {assume "(b2,b1) \<in> r"
blanchet@55023
   375
     hence "b1 \<in> under r b1 \<and> b2 \<in> under r b1"
blanchet@55023
   376
     unfolding under_def using 11 Refl
blanchet@48975
   377
     by (auto simp add: refl_on_def)
blanchet@48975
   378
     hence "b1 = b2" using BIJ * ** ***
blanchet@54482
   379
     by (simp add: bij_betw_def inj_on_def)
blanchet@48975
   380
    }
blanchet@48975
   381
    ultimately
blanchet@48975
   382
    show "b1 = b2"
blanchet@48975
   383
    using Total by (auto simp add: total_on_def)
blanchet@48975
   384
  qed
blanchet@48975
   385
  (*  *)
blanchet@48975
   386
  let ?f' = "(inv_into A f)"
blanchet@48975
   387
  (*  *)
blanchet@55023
   388
  have 2: "\<forall>b \<in> A. bij_betw ?f' (under r' (f b)) (under r b)"
blanchet@48975
   389
  proof(clarify)
blanchet@48975
   390
    fix b assume *: "b \<in> A"
blanchet@55023
   391
    hence "under r b \<le> A"
blanchet@48975
   392
    using Well OF by(auto simp add: wo_rel.ofilter_def)
blanchet@48975
   393
    moreover
blanchet@55023
   394
    have "f ` (under r b) = under r' (f b)"
blanchet@48975
   395
    using * BIJ by (auto simp add: bij_betw_def)
blanchet@48975
   396
    ultimately
blanchet@55023
   397
    show "bij_betw ?f' (under r' (f b)) (under r b)"
blanchet@48975
   398
    using 1 by (auto simp add: bij_betw_inv_into_subset)
blanchet@48975
   399
  qed
blanchet@48975
   400
  (*  *)
blanchet@55023
   401
  have 3: "\<forall>b' \<in> Field r'. bij_betw ?f' (under r' b') (under r (?f' b'))"
blanchet@48975
   402
  proof(clarify)
blanchet@48975
   403
    fix b' assume *: "b' \<in> Field r'"
blanchet@48975
   404
    have "b' = f (?f' b')" using * 1
blanchet@48975
   405
    by (auto simp add: bij_betw_inv_into_right)
blanchet@48975
   406
    moreover
blanchet@48975
   407
    {obtain b where 31: "b \<in> A" and "f b = b'" using IMAGE * by force
blanchet@48975
   408
     hence "?f' b' = b" using 1 by (auto simp add: bij_betw_inv_into_left)
blanchet@48975
   409
     with 31 have "?f' b' \<in> A" by auto
blanchet@48975
   410
    }
blanchet@48975
   411
    ultimately
blanchet@55023
   412
    show  "bij_betw ?f' (under r' b') (under r (?f' b'))"
blanchet@48975
   413
    using 2 by auto
blanchet@48975
   414
  qed
blanchet@48975
   415
  (*  *)
blanchet@48975
   416
  thus ?thesis unfolding embed_def .
blanchet@48975
   417
qed
blanchet@48975
   418
blanchet@48975
   419
lemma inv_into_underS_embed:
blanchet@48975
   420
assumes WELL: "Well_order r" and
blanchet@55023
   421
        BIJ: "\<forall>b \<in> underS r a. bij_betw f (under r b) (under r' (f b))" and
blanchet@48975
   422
        IN: "a \<in> Field r" and
blanchet@55023
   423
        IMAGE: "f ` (underS r a) = Field r'"
blanchet@55023
   424
shows "embed r' r (inv_into (underS r a) f)"
blanchet@48975
   425
using assms
blanchet@48975
   426
by(auto simp add: wo_rel_def wo_rel.underS_ofilter inv_into_ofilter_embed)
blanchet@48975
   427
blanchet@48975
   428
lemma inv_into_Field_embed:
blanchet@48975
   429
assumes WELL: "Well_order r" and EMB: "embed r r' f" and
blanchet@48975
   430
        IMAGE: "Field r' \<le> f ` (Field r)"
blanchet@48975
   431
shows "embed r' r (inv_into (Field r) f)"
blanchet@48975
   432
proof-
blanchet@55023
   433
  have "(\<forall>b \<in> Field r. bij_betw f (under r b) (under r' (f b)))"
blanchet@48975
   434
  using EMB by (auto simp add: embed_def)
blanchet@48975
   435
  moreover
blanchet@48975
   436
  have "f ` (Field r) \<le> Field r'"
blanchet@48975
   437
  using EMB WELL by (auto simp add: embed_Field)
blanchet@48975
   438
  ultimately
blanchet@48975
   439
  show ?thesis using assms
blanchet@48975
   440
  by(auto simp add: wo_rel_def wo_rel.Field_ofilter inv_into_ofilter_embed)
blanchet@48975
   441
qed
blanchet@48975
   442
blanchet@48975
   443
lemma inv_into_Field_embed_bij_betw:
blanchet@48975
   444
assumes WELL: "Well_order r" and
blanchet@48975
   445
        EMB: "embed r r' f" and BIJ: "bij_betw f (Field r) (Field r')"
blanchet@48975
   446
shows "embed r' r (inv_into (Field r) f)"
blanchet@48975
   447
proof-
blanchet@48975
   448
  have "Field r' \<le> f ` (Field r)"
blanchet@48975
   449
  using BIJ by (auto simp add: bij_betw_def)
blanchet@48975
   450
  thus ?thesis using assms
blanchet@48975
   451
  by(auto simp add: inv_into_Field_embed)
blanchet@48975
   452
qed
blanchet@48975
   453
blanchet@48975
   454
blanchet@48975
   455
subsection {* Given any two well-orders, one can be embedded in the other *}
blanchet@48975
   456
blanchet@48975
   457
text{* Here is an overview of the proof of of this fact, stated in theorem
blanchet@48975
   458
@{text "wellorders_totally_ordered"}:
blanchet@48975
   459
blanchet@48975
   460
   Fix the well-orders @{text "r::'a rel"} and @{text "r'::'a' rel"}.
blanchet@48975
   461
   Attempt to define an embedding @{text "f::'a \<Rightarrow> 'a'"} from @{text "r"} to @{text "r'"} in the
blanchet@48975
   462
   natural way by well-order recursion ("hoping" that @{text "Field r"} turns out to be smaller
blanchet@48975
   463
   than @{text "Field r'"}), but also record, at the recursive step, in a function
blanchet@48975
   464
   @{text "g::'a \<Rightarrow> bool"}, the extra information of whether @{text "Field r'"}
blanchet@48975
   465
   gets exhausted or not.
blanchet@48975
   466
blanchet@48975
   467
   If @{text "Field r'"} does not get exhausted, then @{text "Field r"} is indeed smaller
blanchet@48975
   468
   and @{text "f"} is the desired embedding from @{text "r"} to @{text "r'"}
blanchet@48975
   469
   (lemma @{text "wellorders_totally_ordered_aux"}).
blanchet@48975
   470
blanchet@48975
   471
   Otherwise, it means that @{text "Field r'"} is the smaller one, and the inverse of
blanchet@48975
   472
   (the "good" segment of) @{text "f"} is the desired embedding from @{text "r'"} to @{text "r"}
blanchet@48975
   473
   (lemma @{text "wellorders_totally_ordered_aux2"}).
blanchet@48975
   474
*}
blanchet@48975
   475
blanchet@48975
   476
lemma wellorders_totally_ordered_aux:
blanchet@48975
   477
fixes r ::"'a rel"  and r'::"'a' rel" and
blanchet@48975
   478
      f :: "'a \<Rightarrow> 'a'" and a::'a
blanchet@48975
   479
assumes WELL: "Well_order r" and WELL': "Well_order r'" and IN: "a \<in> Field r" and
blanchet@55023
   480
        IH: "\<forall>b \<in> underS r a. bij_betw f (under r b) (under r' (f b))" and
blanchet@55023
   481
        NOT: "f ` (underS r a) \<noteq> Field r'" and SUC: "f a = wo_rel.suc r' (f`(underS r a))"
blanchet@55023
   482
shows "bij_betw f (under r a) (under r' (f a))"
blanchet@48975
   483
proof-
blanchet@48975
   484
  (* Preliminary facts *)
blanchet@48975
   485
  have Well: "wo_rel r" using WELL unfolding wo_rel_def .
blanchet@48975
   486
  hence Refl: "Refl r" using wo_rel.REFL[of r] by auto
blanchet@48975
   487
  have Trans: "trans r" using Well wo_rel.TRANS[of r] by auto
blanchet@48975
   488
  have Well': "wo_rel r'" using WELL' unfolding wo_rel_def .
blanchet@55023
   489
  have OF: "wo_rel.ofilter r (underS r a)"
blanchet@48975
   490
  by (auto simp add: Well wo_rel.underS_ofilter)
blanchet@55023
   491
  hence UN: "underS r a = (\<Union>  b \<in> underS r a. under r b)"
blanchet@55023
   492
  using Well wo_rel.ofilter_under_UNION[of r "underS r a"] by blast
blanchet@55023
   493
  (* Gather facts about elements of underS r a *)
blanchet@55023
   494
  {fix b assume *: "b \<in> underS r a"
blanchet@55023
   495
   hence t0: "(b,a) \<in> r \<and> b \<noteq> a" unfolding underS_def by auto
blanchet@48975
   496
   have t1: "b \<in> Field r"
blanchet@55023
   497
   using * underS_Field[of r a] by auto
blanchet@55023
   498
   have t2: "f`(under r b) = under r' (f b)"
blanchet@48975
   499
   using IH * by (auto simp add: bij_betw_def)
blanchet@55023
   500
   hence t3: "wo_rel.ofilter r' (f`(under r b))"
blanchet@48975
   501
   using Well' by (auto simp add: wo_rel.under_ofilter)
blanchet@55023
   502
   have "f`(under r b) \<le> Field r'"
blanchet@55023
   503
   using t2 by (auto simp add: under_Field)
blanchet@48975
   504
   moreover
blanchet@55023
   505
   have "b \<in> under r b"
blanchet@55023
   506
   using t1 by(auto simp add: Refl Refl_under_in)
blanchet@48975
   507
   ultimately
blanchet@48975
   508
   have t4:  "f b \<in> Field r'" by auto
blanchet@55023
   509
   have "f`(under r b) = under r' (f b) \<and>
blanchet@55023
   510
         wo_rel.ofilter r' (f`(under r b)) \<and>
blanchet@48975
   511
         f b \<in> Field r'"
blanchet@48975
   512
   using t2 t3 t4 by auto
blanchet@48975
   513
  }
blanchet@48975
   514
  hence bFact:
blanchet@55023
   515
  "\<forall>b \<in> underS r a. f`(under r b) = under r' (f b) \<and>
blanchet@55023
   516
                       wo_rel.ofilter r' (f`(under r b)) \<and>
blanchet@48975
   517
                       f b \<in> Field r'" by blast
blanchet@48975
   518
  (*  *)
blanchet@55023
   519
  have subField: "f`(underS r a) \<le> Field r'"
blanchet@48975
   520
  using bFact by blast
blanchet@48975
   521
  (*  *)
blanchet@55023
   522
  have OF': "wo_rel.ofilter r' (f`(underS r a))"
blanchet@48975
   523
  proof-
blanchet@55023
   524
    have "f`(underS r a) = f`(\<Union>  b \<in> underS r a. under r b)"
blanchet@48975
   525
    using UN by auto
blanchet@55023
   526
    also have "\<dots> = (\<Union>  b \<in> underS r a. f`(under r b))" by blast
blanchet@55023
   527
    also have "\<dots> = (\<Union>  b \<in> underS r a. (under r' (f b)))"
blanchet@48975
   528
    using bFact by auto
blanchet@48975
   529
    finally
blanchet@55023
   530
    have "f`(underS r a) = (\<Union>  b \<in> underS r a. (under r' (f b)))" .
blanchet@48975
   531
    thus ?thesis
blanchet@48975
   532
    using Well' bFact
blanchet@55023
   533
          wo_rel.ofilter_UNION[of r' "underS r a" "\<lambda> b. under r' (f b)"] by fastforce
blanchet@48975
   534
  qed
blanchet@48975
   535
  (*  *)
blanchet@55023
   536
  have "f`(underS r a) \<union> AboveS r' (f`(underS r a)) = Field r'"
blanchet@48975
   537
  using Well' OF' by (auto simp add: wo_rel.ofilter_AboveS_Field)
blanchet@55023
   538
  hence NE: "AboveS r' (f`(underS r a)) \<noteq> {}"
blanchet@48975
   539
  using subField NOT by blast
blanchet@48975
   540
  (* Main proof *)
blanchet@55023
   541
  have INCL1: "f`(underS r a) \<le> underS r' (f a) "
blanchet@48975
   542
  proof(auto)
blanchet@55023
   543
    fix b assume *: "b \<in> underS r a"
blanchet@48975
   544
    have "f b \<noteq> f a \<and> (f b, f a) \<in> r'"
blanchet@48975
   545
    using subField Well' SUC NE *
blanchet@55023
   546
          wo_rel.suc_greater[of r' "f`(underS r a)" "f b"] by force
blanchet@55023
   547
    thus "f b \<in> underS r' (f a)"
blanchet@55023
   548
    unfolding underS_def by simp
blanchet@48975
   549
  qed
blanchet@48975
   550
  (*  *)
blanchet@55023
   551
  have INCL2: "underS r' (f a) \<le> f`(underS r a)"
blanchet@48975
   552
  proof
blanchet@55023
   553
    fix b' assume "b' \<in> underS r' (f a)"
blanchet@48975
   554
    hence "b' \<noteq> f a \<and> (b', f a) \<in> r'"
blanchet@55023
   555
    unfolding underS_def by simp
blanchet@55023
   556
    thus "b' \<in> f`(underS r a)"
blanchet@48975
   557
    using Well' SUC NE OF'
blanchet@55023
   558
          wo_rel.suc_ofilter_in[of r' "f ` underS r a" b'] by auto
blanchet@48975
   559
  qed
blanchet@48975
   560
  (*  *)
blanchet@55023
   561
  have INJ: "inj_on f (underS r a)"
blanchet@48975
   562
  proof-
blanchet@55023
   563
    have "\<forall>b \<in> underS r a. inj_on f (under r b)"
blanchet@48975
   564
    using IH by (auto simp add: bij_betw_def)
blanchet@48975
   565
    moreover
blanchet@55023
   566
    have "\<forall>b. wo_rel.ofilter r (under r b)"
blanchet@48975
   567
    using Well by (auto simp add: wo_rel.under_ofilter)
blanchet@48975
   568
    ultimately show  ?thesis
blanchet@48975
   569
    using WELL bFact UN
blanchet@55023
   570
          UNION_inj_on_ofilter[of r "underS r a" "\<lambda>b. under r b" f]
blanchet@48975
   571
    by auto
blanchet@48975
   572
  qed
blanchet@48975
   573
  (*  *)
blanchet@55023
   574
  have BIJ: "bij_betw f (underS r a) (underS r' (f a))"
blanchet@48975
   575
  unfolding bij_betw_def
blanchet@48975
   576
  using INJ INCL1 INCL2 by auto
blanchet@48975
   577
  (*  *)
blanchet@48975
   578
  have "f a \<in> Field r'"
blanchet@48975
   579
  using Well' subField NE SUC
blanchet@48975
   580
  by (auto simp add: wo_rel.suc_inField)
blanchet@48975
   581
  thus ?thesis
blanchet@48975
   582
  using WELL WELL' IN BIJ under_underS_bij_betw[of r r' a f] by auto
blanchet@48975
   583
qed
blanchet@48975
   584
blanchet@48975
   585
lemma wellorders_totally_ordered_aux2:
blanchet@48975
   586
fixes r ::"'a rel"  and r'::"'a' rel" and
blanchet@48975
   587
      f :: "'a \<Rightarrow> 'a'" and g :: "'a \<Rightarrow> bool"  and a::'a
blanchet@48975
   588
assumes WELL: "Well_order r" and WELL': "Well_order r'" and
blanchet@48975
   589
MAIN1:
blanchet@55023
   590
  "\<And> a. (False \<notin> g`(underS r a) \<and> f`(underS r a) \<noteq> Field r'
blanchet@55023
   591
          \<longrightarrow> f a = wo_rel.suc r' (f`(underS r a)) \<and> g a = True)
blanchet@48975
   592
         \<and>
blanchet@55023
   593
         (\<not>(False \<notin> (g`(underS r a)) \<and> f`(underS r a) \<noteq> Field r')
blanchet@48975
   594
          \<longrightarrow> g a = False)" and
blanchet@55023
   595
MAIN2: "\<And> a. a \<in> Field r \<and> False \<notin> g`(under r a) \<longrightarrow>
blanchet@55023
   596
              bij_betw f (under r a) (under r' (f a))" and
blanchet@55023
   597
Case: "a \<in> Field r \<and> False \<in> g`(under r a)"
blanchet@48975
   598
shows "\<exists>f'. embed r' r f'"
blanchet@48975
   599
proof-
blanchet@48975
   600
  have Well: "wo_rel r" using WELL unfolding wo_rel_def .
blanchet@48975
   601
  hence Refl: "Refl r" using wo_rel.REFL[of r] by auto
blanchet@48975
   602
  have Trans: "trans r" using Well wo_rel.TRANS[of r] by auto
blanchet@48975
   603
  have Antisym: "antisym r" using Well wo_rel.ANTISYM[of r] by auto
blanchet@48975
   604
  have Well': "wo_rel r'" using WELL' unfolding wo_rel_def .
blanchet@48975
   605
  (*  *)
blanchet@55023
   606
  have 0: "under r a = underS r a \<union> {a}"
blanchet@55023
   607
  using Refl Case by(auto simp add: Refl_under_underS)
blanchet@48975
   608
  (*  *)
blanchet@48975
   609
  have 1: "g a = False"
blanchet@48975
   610
  proof-
blanchet@48975
   611
    {assume "g a \<noteq> False"
blanchet@55023
   612
     with 0 Case have "False \<in> g`(underS r a)" by blast
blanchet@48975
   613
     with MAIN1 have "g a = False" by blast}
blanchet@48975
   614
    thus ?thesis by blast
blanchet@48975
   615
  qed
blanchet@48975
   616
  let ?A = "{a \<in> Field r. g a = False}"
blanchet@48975
   617
  let ?a = "(wo_rel.minim r ?A)"
blanchet@48975
   618
  (*  *)
blanchet@48975
   619
  have 2: "?A \<noteq> {} \<and> ?A \<le> Field r" using Case 1 by blast
blanchet@48975
   620
  (*  *)
blanchet@55023
   621
  have 3: "False \<notin> g`(underS r ?a)"
blanchet@48975
   622
  proof
blanchet@55023
   623
    assume "False \<in> g`(underS r ?a)"
blanchet@55023
   624
    then obtain b where "b \<in> underS r ?a" and 31: "g b = False" by auto
blanchet@48975
   625
    hence 32: "(b,?a) \<in> r \<and> b \<noteq> ?a"
blanchet@55023
   626
    by (auto simp add: underS_def)
blanchet@48975
   627
    hence "b \<in> Field r" unfolding Field_def by auto
blanchet@48975
   628
    with 31 have "b \<in> ?A" by auto
blanchet@48975
   629
    hence "(?a,b) \<in> r" using wo_rel.minim_least 2 Well by fastforce
blanchet@48975
   630
    (* again: why worked without type annotations? *)
blanchet@48975
   631
    with 32 Antisym show False
blanchet@48975
   632
    by (auto simp add: antisym_def)
blanchet@48975
   633
  qed
blanchet@48975
   634
  have temp: "?a \<in> ?A"
blanchet@48975
   635
  using Well 2 wo_rel.minim_in[of r ?A] by auto
blanchet@48975
   636
  hence 4: "?a \<in> Field r" by auto
blanchet@48975
   637
  (*   *)
blanchet@48975
   638
  have 5: "g ?a = False" using temp by blast
blanchet@48975
   639
  (*  *)
blanchet@55023
   640
  have 6: "f`(underS r ?a) = Field r'"
blanchet@48975
   641
  using MAIN1[of ?a] 3 5 by blast
blanchet@48975
   642
  (*  *)
blanchet@55023
   643
  have 7: "\<forall>b \<in> underS r ?a. bij_betw f (under r b) (under r' (f b))"
blanchet@48975
   644
  proof
blanchet@55023
   645
    fix b assume as: "b \<in> underS r ?a"
blanchet@48975
   646
    moreover
blanchet@55023
   647
    have "wo_rel.ofilter r (underS r ?a)"
blanchet@48975
   648
    using Well by (auto simp add: wo_rel.underS_ofilter)
blanchet@48975
   649
    ultimately
blanchet@55023
   650
    have "False \<notin> g`(under r b)" using 3 Well by (subst (asm) wo_rel.ofilter_def) fast+
blanchet@48975
   651
    moreover have "b \<in> Field r"
blanchet@55023
   652
    unfolding Field_def using as by (auto simp add: underS_def)
blanchet@48975
   653
    ultimately
blanchet@55023
   654
    show "bij_betw f (under r b) (under r' (f b))"
blanchet@48975
   655
    using MAIN2 by auto
blanchet@48975
   656
  qed
blanchet@48975
   657
  (*  *)
blanchet@55023
   658
  have "embed r' r (inv_into (underS r ?a) f)"
blanchet@48975
   659
  using WELL WELL' 7 4 6 inv_into_underS_embed[of r ?a f r'] by auto
blanchet@48975
   660
  thus ?thesis
blanchet@48975
   661
  unfolding embed_def by blast
blanchet@48975
   662
qed
blanchet@48975
   663
blanchet@48975
   664
theorem wellorders_totally_ordered:
blanchet@48975
   665
fixes r ::"'a rel"  and r'::"'a' rel"
blanchet@48975
   666
assumes WELL: "Well_order r" and WELL': "Well_order r'"
blanchet@48975
   667
shows "(\<exists>f. embed r r' f) \<or> (\<exists>f'. embed r' r f')"
blanchet@48975
   668
proof-
blanchet@48975
   669
  (* Preliminary facts *)
blanchet@48975
   670
  have Well: "wo_rel r" using WELL unfolding wo_rel_def .
blanchet@48975
   671
  hence Refl: "Refl r" using wo_rel.REFL[of r] by auto
blanchet@48975
   672
  have Trans: "trans r" using Well wo_rel.TRANS[of r] by auto
blanchet@48975
   673
  have Well': "wo_rel r'" using WELL' unfolding wo_rel_def .
blanchet@48975
   674
  (* Main proof *)
blanchet@48975
   675
  obtain H where H_def: "H =
blanchet@55023
   676
  (\<lambda>h a. if False \<notin> (snd o h)`(underS r a) \<and> (fst o h)`(underS r a) \<noteq> Field r'
blanchet@55023
   677
                then (wo_rel.suc r' ((fst o h)`(underS r a)), True)
blanchet@48975
   678
                else (undefined, False))" by blast
blanchet@48975
   679
  have Adm: "wo_rel.adm_wo r H"
blanchet@48975
   680
  using Well
blanchet@48975
   681
  proof(unfold wo_rel.adm_wo_def, clarify)
blanchet@48975
   682
    fix h1::"'a \<Rightarrow> 'a' * bool" and h2::"'a \<Rightarrow> 'a' * bool" and x
blanchet@55023
   683
    assume "\<forall>y\<in>underS r x. h1 y = h2 y"
blanchet@55023
   684
    hence "\<forall>y\<in>underS r x. (fst o h1) y = (fst o h2) y \<and>
blanchet@48975
   685
                          (snd o h1) y = (snd o h2) y" by auto
blanchet@55023
   686
    hence "(fst o h1)`(underS r x) = (fst o h2)`(underS r x) \<and>
blanchet@55023
   687
           (snd o h1)`(underS r x) = (snd o h2)`(underS r x)"
wenzelm@49922
   688
      by (auto simp add: image_def)
wenzelm@49922
   689
    thus "H h1 x = H h2 x" by (simp add: H_def del: not_False_in_image_Ball)
blanchet@48975
   690
  qed
blanchet@48975
   691
  (* More constant definitions:  *)
blanchet@48975
   692
  obtain h::"'a \<Rightarrow> 'a' * bool" and f::"'a \<Rightarrow> 'a'" and g::"'a \<Rightarrow> bool"
blanchet@48975
   693
  where h_def: "h = wo_rel.worec r H" and
blanchet@48975
   694
        f_def: "f = fst o h" and g_def: "g = snd o h" by blast
blanchet@48975
   695
  obtain test where test_def:
blanchet@55023
   696
  "test = (\<lambda> a. False \<notin> (g`(underS r a)) \<and> f`(underS r a) \<noteq> Field r')" by blast
blanchet@48975
   697
  (*  *)
blanchet@48975
   698
  have *: "\<And> a. h a  = H h a"
blanchet@48975
   699
  using Adm Well wo_rel.worec_fixpoint[of r H] by (simp add: h_def)
blanchet@48975
   700
  have Main1:
blanchet@55023
   701
  "\<And> a. (test a \<longrightarrow> f a = wo_rel.suc r' (f`(underS r a)) \<and> g a = True) \<and>
blanchet@48975
   702
         (\<not>(test a) \<longrightarrow> g a = False)"
blanchet@48975
   703
  proof-  (* How can I prove this withou fixing a? *)
blanchet@55023
   704
    fix a show "(test a \<longrightarrow> f a = wo_rel.suc r' (f`(underS r a)) \<and> g a = True) \<and>
blanchet@48975
   705
                (\<not>(test a) \<longrightarrow> g a = False)"
blanchet@48975
   706
    using *[of a] test_def f_def g_def H_def by auto
blanchet@48975
   707
  qed
blanchet@48975
   708
  (*  *)
blanchet@55023
   709
  let ?phi = "\<lambda> a. a \<in> Field r \<and> False \<notin> g`(under r a) \<longrightarrow>
blanchet@55023
   710
                   bij_betw f (under r a) (under r' (f a))"
blanchet@48975
   711
  have Main2: "\<And> a. ?phi a"
blanchet@48975
   712
  proof-
blanchet@48975
   713
    fix a show "?phi a"
blanchet@48975
   714
    proof(rule wo_rel.well_order_induct[of r ?phi],
blanchet@48975
   715
          simp only: Well, clarify)
blanchet@48975
   716
      fix a
blanchet@48975
   717
      assume IH: "\<forall>b. b \<noteq> a \<and> (b,a) \<in> r \<longrightarrow> ?phi b" and
blanchet@48975
   718
             *: "a \<in> Field r" and
blanchet@55023
   719
             **: "False \<notin> g`(under r a)"
blanchet@55023
   720
      have 1: "\<forall>b \<in> underS r a. bij_betw f (under r b) (under r' (f b))"
blanchet@48975
   721
      proof(clarify)
blanchet@55023
   722
        fix b assume ***: "b \<in> underS r a"
blanchet@55023
   723
        hence 0: "(b,a) \<in> r \<and> b \<noteq> a" unfolding underS_def by auto
blanchet@48975
   724
        moreover have "b \<in> Field r"
blanchet@55023
   725
        using *** underS_Field[of r a] by auto
blanchet@55023
   726
        moreover have "False \<notin> g`(under r b)"
blanchet@55023
   727
        using 0 ** Trans under_incr[of r b a] by auto
blanchet@55023
   728
        ultimately show "bij_betw f (under r b) (under r' (f b))"
blanchet@48975
   729
        using IH by auto
blanchet@48975
   730
      qed
blanchet@48975
   731
      (*  *)
blanchet@55023
   732
      have 21: "False \<notin> g`(underS r a)"
blanchet@55023
   733
      using ** underS_subset_under[of r a] by auto
blanchet@55023
   734
      have 22: "g`(under r a) \<le> {True}" using ** by auto
blanchet@55023
   735
      moreover have 23: "a \<in> under r a"
blanchet@55023
   736
      using Refl * by (auto simp add: Refl_under_in)
blanchet@48975
   737
      ultimately have 24: "g a = True" by blast
blanchet@55023
   738
      have 2: "f`(underS r a) \<noteq> Field r'"
blanchet@48975
   739
      proof
blanchet@55023
   740
        assume "f`(underS r a) = Field r'"
blanchet@48975
   741
        hence "g a = False" using Main1 test_def by blast
blanchet@48975
   742
        with 24 show False using ** by blast
blanchet@48975
   743
      qed
blanchet@48975
   744
      (*  *)
blanchet@55023
   745
      have 3: "f a = wo_rel.suc r' (f`(underS r a))"
blanchet@48975
   746
      using 21 2 Main1 test_def by blast
blanchet@48975
   747
      (*  *)
blanchet@55023
   748
      show "bij_betw f (under r a) (under r' (f a))"
blanchet@48975
   749
      using WELL  WELL' 1 2 3 *
blanchet@48975
   750
            wellorders_totally_ordered_aux[of r r' a f] by auto
blanchet@48975
   751
    qed
blanchet@48975
   752
  qed
blanchet@48975
   753
  (*  *)
blanchet@55023
   754
  let ?chi = "(\<lambda> a. a \<in> Field r \<and> False \<in> g`(under r a))"
blanchet@48975
   755
  show ?thesis
blanchet@48975
   756
  proof(cases "\<exists>a. ?chi a")
blanchet@48975
   757
    assume "\<not> (\<exists>a. ?chi a)"
blanchet@55023
   758
    hence "\<forall>a \<in> Field r.  bij_betw f (under r a) (under r' (f a))"
blanchet@48975
   759
    using Main2 by blast
blanchet@48975
   760
    thus ?thesis unfolding embed_def by blast
blanchet@48975
   761
  next
blanchet@48975
   762
    assume "\<exists>a. ?chi a"
blanchet@48975
   763
    then obtain a where "?chi a" by blast
blanchet@48975
   764
    hence "\<exists>f'. embed r' r f'"
blanchet@48975
   765
    using wellorders_totally_ordered_aux2[of r r' g f a]
blanchet@54482
   766
          WELL WELL' Main1 Main2 test_def by fast
blanchet@48975
   767
    thus ?thesis by blast
blanchet@48975
   768
  qed
blanchet@48975
   769
qed
blanchet@48975
   770
blanchet@48975
   771
blanchet@55101
   772
subsection {* Uniqueness of embeddings *}
blanchet@48975
   773
blanchet@48975
   774
text{* Here we show a fact complementary to the one from the previous subsection -- namely,
blanchet@48975
   775
that between any two well-orders there is {\em at most} one embedding, and is the one
blanchet@48975
   776
definable by the expected well-order recursive equation.  As a consequence, any two
blanchet@48975
   777
embeddings of opposite directions are mutually inverse. *}
blanchet@48975
   778
blanchet@48975
   779
lemma embed_determined:
blanchet@48975
   780
assumes WELL: "Well_order r" and WELL': "Well_order r'" and
blanchet@48975
   781
        EMB: "embed r r' f" and IN: "a \<in> Field r"
blanchet@55023
   782
shows "f a = wo_rel.suc r' (f`(underS r a))"
blanchet@48975
   783
proof-
blanchet@55023
   784
  have "bij_betw f (underS r a) (underS r' (f a))"
blanchet@48975
   785
  using assms by (auto simp add: embed_underS)
blanchet@55023
   786
  hence "f`(underS r a) = underS r' (f a)"
blanchet@48975
   787
  by (auto simp add: bij_betw_def)
blanchet@48975
   788
  moreover
blanchet@48975
   789
  {have "f a \<in> Field r'" using IN
blanchet@48975
   790
   using EMB WELL embed_Field[of r r' f] by auto
blanchet@55023
   791
   hence "f a = wo_rel.suc r' (underS r' (f a))"
blanchet@48975
   792
   using WELL' by (auto simp add: wo_rel_def wo_rel.suc_underS)
blanchet@48975
   793
  }
blanchet@48975
   794
  ultimately show ?thesis by simp
blanchet@48975
   795
qed
blanchet@48975
   796
blanchet@48975
   797
lemma embed_unique:
blanchet@48975
   798
assumes WELL: "Well_order r" and WELL': "Well_order r'" and
blanchet@48975
   799
        EMBf: "embed r r' f" and EMBg: "embed r r' g"
blanchet@48975
   800
shows "a \<in> Field r \<longrightarrow> f a = g a"
blanchet@48975
   801
proof(rule wo_rel.well_order_induct[of r], auto simp add: WELL wo_rel_def)
blanchet@48975
   802
  fix a
blanchet@48975
   803
  assume IH: "\<forall>b. b \<noteq> a \<and> (b,a): r \<longrightarrow> b \<in> Field r \<longrightarrow> f b = g b" and
blanchet@48975
   804
         *: "a \<in> Field r"
blanchet@55023
   805
  hence "\<forall>b \<in> underS r a. f b = g b"
blanchet@55023
   806
  unfolding underS_def by (auto simp add: Field_def)
blanchet@55023
   807
  hence "f`(underS r a) = g`(underS r a)" by force
blanchet@48975
   808
  thus "f a = g a"
blanchet@48975
   809
  using assms * embed_determined[of r r' f a] embed_determined[of r r' g a] by auto
blanchet@48975
   810
qed
blanchet@48975
   811
blanchet@48975
   812
lemma embed_bothWays_inverse:
blanchet@48975
   813
assumes WELL: "Well_order r" and WELL': "Well_order r'" and
blanchet@48975
   814
        EMB: "embed r r' f" and EMB': "embed r' r f'"
blanchet@48975
   815
shows "(\<forall>a \<in> Field r. f'(f a) = a) \<and> (\<forall>a' \<in> Field r'. f(f' a') = a')"
blanchet@48975
   816
proof-
blanchet@48975
   817
  have "embed r r (f' o f)" using assms
blanchet@48975
   818
  by(auto simp add: comp_embed)
blanchet@48975
   819
  moreover have "embed r r id" using assms
blanchet@48975
   820
  by (auto simp add: id_embed)
blanchet@48975
   821
  ultimately have "\<forall>a \<in> Field r. f'(f a) = a"
blanchet@48975
   822
  using assms embed_unique[of r r "f' o f" id] id_def by auto
blanchet@48975
   823
  moreover
blanchet@48975
   824
  {have "embed r' r' (f o f')" using assms
blanchet@48975
   825
   by(auto simp add: comp_embed)
blanchet@48975
   826
   moreover have "embed r' r' id" using assms
blanchet@48975
   827
   by (auto simp add: id_embed)
blanchet@48975
   828
   ultimately have "\<forall>a' \<in> Field r'. f(f' a') = a'"
blanchet@48975
   829
   using assms embed_unique[of r' r' "f o f'" id] id_def by auto
blanchet@48975
   830
  }
blanchet@48975
   831
  ultimately show ?thesis by blast
blanchet@48975
   832
qed
blanchet@48975
   833
blanchet@48975
   834
lemma embed_bothWays_bij_betw:
blanchet@48975
   835
assumes WELL: "Well_order r" and WELL': "Well_order r'" and
blanchet@48975
   836
        EMB: "embed r r' f" and EMB': "embed r' r g"
blanchet@48975
   837
shows "bij_betw f (Field r) (Field r')"
blanchet@48975
   838
proof-
blanchet@48975
   839
  let ?A = "Field r"  let ?A' = "Field r'"
blanchet@48975
   840
  have "embed r r (g o f) \<and> embed r' r' (f o g)"
blanchet@48975
   841
  using assms by (auto simp add: comp_embed)
blanchet@48975
   842
  hence 1: "(\<forall>a \<in> ?A. g(f a) = a) \<and> (\<forall>a' \<in> ?A'. f(g a') = a')"
blanchet@48975
   843
  using WELL id_embed[of r] embed_unique[of r r "g o f" id]
blanchet@48975
   844
        WELL' id_embed[of r'] embed_unique[of r' r' "f o g" id]
blanchet@48975
   845
        id_def by auto
blanchet@48975
   846
  have 2: "(\<forall>a \<in> ?A. f a \<in> ?A') \<and> (\<forall>a' \<in> ?A'. g a' \<in> ?A)"
blanchet@48975
   847
  using assms embed_Field[of r r' f] embed_Field[of r' r g] by blast
blanchet@48975
   848
  (*  *)
blanchet@48975
   849
  show ?thesis
blanchet@48975
   850
  proof(unfold bij_betw_def inj_on_def, auto simp add: 2)
blanchet@48975
   851
    fix a b assume *: "a \<in> ?A" "b \<in> ?A" and **: "f a = f b"
blanchet@48975
   852
    have "a = g(f a) \<and> b = g(f b)" using * 1 by auto
blanchet@48975
   853
    with ** show "a = b" by auto
blanchet@48975
   854
  next
blanchet@48975
   855
    fix a' assume *: "a' \<in> ?A'"
blanchet@48975
   856
    hence "g a' \<in> ?A \<and> f(g a') = a'" using 1 2 by auto
blanchet@48975
   857
    thus "a' \<in> f ` ?A" by force
blanchet@48975
   858
  qed
blanchet@48975
   859
qed
blanchet@48975
   860
blanchet@48975
   861
lemma embed_bothWays_iso:
blanchet@48975
   862
assumes WELL: "Well_order r"  and WELL': "Well_order r'" and
blanchet@48975
   863
        EMB: "embed r r' f" and EMB': "embed r' r g"
blanchet@48975
   864
shows "iso r r' f"
blanchet@48975
   865
unfolding iso_def using assms by (auto simp add: embed_bothWays_bij_betw)
blanchet@48975
   866
blanchet@48975
   867
blanchet@55101
   868
subsection {* More properties of embeddings, strict embeddings and isomorphisms *}
blanchet@48975
   869
blanchet@48975
   870
lemma embed_bothWays_Field_bij_betw:
blanchet@48975
   871
assumes WELL: "Well_order r" and WELL': "Well_order r'" and
blanchet@48975
   872
        EMB: "embed r r' f" and EMB': "embed r' r f'"
blanchet@48975
   873
shows "bij_betw f (Field r) (Field r')"
blanchet@48975
   874
proof-
blanchet@48975
   875
  have "(\<forall>a \<in> Field r. f'(f a) = a) \<and> (\<forall>a' \<in> Field r'. f(f' a') = a')"
blanchet@48975
   876
  using assms by (auto simp add: embed_bothWays_inverse)
blanchet@48975
   877
  moreover
blanchet@48975
   878
  have "f`(Field r) \<le> Field r' \<and> f' ` (Field r') \<le> Field r"
blanchet@48975
   879
  using assms by (auto simp add: embed_Field)
blanchet@48975
   880
  ultimately
blanchet@48975
   881
  show ?thesis using bij_betw_byWitness[of "Field r" f' f "Field r'"] by auto
blanchet@48975
   882
qed
blanchet@48975
   883
blanchet@48975
   884
lemma embedS_comp_embed:
blanchet@48975
   885
assumes WELL: "Well_order r" and WELL': "Well_order r'" and WELL'': "Well_order r''"
blanchet@48975
   886
        and  EMB: "embedS r r' f" and EMB': "embed r' r'' f'"
blanchet@48975
   887
shows "embedS r r'' (f' o f)"
blanchet@48975
   888
proof-
blanchet@48975
   889
  let ?g = "(f' o f)"  let ?h = "inv_into (Field r) ?g"
blanchet@48975
   890
  have 1: "embed r r' f \<and> \<not> (bij_betw f (Field r) (Field r'))"
blanchet@48975
   891
  using EMB by (auto simp add: embedS_def)
blanchet@48975
   892
  hence 2: "embed r r'' ?g"
blanchet@48975
   893
  using WELL EMB' comp_embed[of r r' f r'' f'] by auto
blanchet@48975
   894
  moreover
blanchet@48975
   895
  {assume "bij_betw ?g (Field r) (Field r'')"
blanchet@48975
   896
   hence "embed r'' r ?h" using 2 WELL
blanchet@48975
   897
   by (auto simp add: inv_into_Field_embed_bij_betw)
blanchet@48975
   898
   hence "embed r' r (?h o f')" using WELL' EMB'
blanchet@48975
   899
   by (auto simp add: comp_embed)
blanchet@48975
   900
   hence "bij_betw f (Field r) (Field r')" using WELL WELL' 1
blanchet@48975
   901
   by (auto simp add: embed_bothWays_Field_bij_betw)
blanchet@48975
   902
   with 1 have False by blast
blanchet@48975
   903
  }
blanchet@48975
   904
  ultimately show ?thesis unfolding embedS_def by auto
blanchet@48975
   905
qed
blanchet@48975
   906
blanchet@48975
   907
lemma embed_comp_embedS:
blanchet@48975
   908
assumes WELL: "Well_order r" and WELL': "Well_order r'" and WELL'': "Well_order r''"
blanchet@48975
   909
        and  EMB: "embed r r' f" and EMB': "embedS r' r'' f'"
blanchet@48975
   910
shows "embedS r r'' (f' o f)"
blanchet@48975
   911
proof-
blanchet@48975
   912
  let ?g = "(f' o f)"  let ?h = "inv_into (Field r) ?g"
blanchet@48975
   913
  have 1: "embed r' r'' f' \<and> \<not> (bij_betw f' (Field r') (Field r''))"
blanchet@48975
   914
  using EMB' by (auto simp add: embedS_def)
blanchet@48975
   915
  hence 2: "embed r r'' ?g"
blanchet@48975
   916
  using WELL EMB comp_embed[of r r' f r'' f'] by auto
blanchet@48975
   917
  moreover
blanchet@48975
   918
  {assume "bij_betw ?g (Field r) (Field r'')"
blanchet@48975
   919
   hence "embed r'' r ?h" using 2 WELL
blanchet@48975
   920
   by (auto simp add: inv_into_Field_embed_bij_betw)
blanchet@48975
   921
   hence "embed r'' r' (f o ?h)" using WELL'' EMB
blanchet@48975
   922
   by (auto simp add: comp_embed)
blanchet@48975
   923
   hence "bij_betw f' (Field r') (Field r'')" using WELL' WELL'' 1
blanchet@48975
   924
   by (auto simp add: embed_bothWays_Field_bij_betw)
blanchet@48975
   925
   with 1 have False by blast
blanchet@48975
   926
  }
blanchet@48975
   927
  ultimately show ?thesis unfolding embedS_def by auto
blanchet@48975
   928
qed
blanchet@48975
   929
blanchet@48975
   930
lemma embed_comp_iso:
blanchet@48975
   931
assumes WELL: "Well_order r" and WELL': "Well_order r'" and WELL'': "Well_order r''"
blanchet@48975
   932
        and  EMB: "embed r r' f" and EMB': "iso r' r'' f'"
blanchet@48975
   933
shows "embed r r'' (f' o f)"
blanchet@48975
   934
using assms unfolding iso_def
blanchet@48975
   935
by (auto simp add: comp_embed)
blanchet@48975
   936
blanchet@48975
   937
lemma iso_comp_embed:
blanchet@48975
   938
assumes WELL: "Well_order r" and WELL': "Well_order r'" and WELL'': "Well_order r''"
blanchet@48975
   939
        and  EMB: "iso r r' f" and EMB': "embed r' r'' f'"
blanchet@48975
   940
shows "embed r r'' (f' o f)"
blanchet@48975
   941
using assms unfolding iso_def
blanchet@48975
   942
by (auto simp add: comp_embed)
blanchet@48975
   943
blanchet@48975
   944
lemma embedS_comp_iso:
blanchet@48975
   945
assumes WELL: "Well_order r" and WELL': "Well_order r'" and WELL'': "Well_order r''"
blanchet@48975
   946
        and  EMB: "embedS r r' f" and EMB': "iso r' r'' f'"
blanchet@48975
   947
shows "embedS r r'' (f' o f)"
blanchet@48975
   948
using assms unfolding iso_def
blanchet@48975
   949
by (auto simp add: embedS_comp_embed)
blanchet@48975
   950
blanchet@48975
   951
lemma iso_comp_embedS:
blanchet@48975
   952
assumes WELL: "Well_order r" and WELL': "Well_order r'" and WELL'': "Well_order r''"
blanchet@48975
   953
        and  EMB: "iso r r' f" and EMB': "embedS r' r'' f'"
blanchet@48975
   954
shows "embedS r r'' (f' o f)"
blanchet@48975
   955
using assms unfolding iso_def  using embed_comp_embedS
blanchet@48975
   956
by (auto simp add: embed_comp_embedS)
blanchet@48975
   957
blanchet@48975
   958
lemma embedS_Field:
blanchet@48975
   959
assumes WELL: "Well_order r" and EMB: "embedS r r' f"
blanchet@48975
   960
shows "f ` (Field r) < Field r'"
blanchet@48975
   961
proof-
blanchet@48975
   962
  have "f`(Field r) \<le> Field r'" using assms
blanchet@48975
   963
  by (auto simp add: embed_Field embedS_def)
blanchet@48975
   964
  moreover
blanchet@48975
   965
  {have "inj_on f (Field r)" using assms
blanchet@48975
   966
   by (auto simp add: embedS_def embed_inj_on)
blanchet@48975
   967
   hence "f`(Field r) \<noteq> Field r'" using EMB
blanchet@48975
   968
   by (auto simp add: embedS_def bij_betw_def)
blanchet@48975
   969
  }
blanchet@48975
   970
  ultimately show ?thesis by blast
blanchet@48975
   971
qed
blanchet@48975
   972
blanchet@48975
   973
lemma embedS_iff:
blanchet@48975
   974
assumes WELL: "Well_order r" and ISO: "embed r r' f"
blanchet@48975
   975
shows "embedS r r' f = (f ` (Field r) < Field r')"
blanchet@48975
   976
proof
blanchet@48975
   977
  assume "embedS r r' f"
blanchet@48975
   978
  thus "f ` Field r \<subset> Field r'"
blanchet@48975
   979
  using WELL by (auto simp add: embedS_Field)
blanchet@48975
   980
next
blanchet@48975
   981
  assume "f ` Field r \<subset> Field r'"
blanchet@48975
   982
  hence "\<not> bij_betw f (Field r) (Field r')"
blanchet@48975
   983
  unfolding bij_betw_def by blast
blanchet@48975
   984
  thus "embedS r r' f" unfolding embedS_def
blanchet@48975
   985
  using ISO by auto
blanchet@48975
   986
qed
blanchet@48975
   987
blanchet@48975
   988
lemma iso_Field:
blanchet@48975
   989
"iso r r' f \<Longrightarrow> f ` (Field r) = Field r'"
blanchet@48975
   990
using assms by (auto simp add: iso_def bij_betw_def)
blanchet@48975
   991
blanchet@48975
   992
lemma iso_iff:
blanchet@48975
   993
assumes "Well_order r"
blanchet@48975
   994
shows "iso r r' f = (embed r r' f \<and> f ` (Field r) = Field r')"
blanchet@48975
   995
proof
blanchet@48975
   996
  assume "iso r r' f"
blanchet@48975
   997
  thus "embed r r' f \<and> f ` (Field r) = Field r'"
blanchet@48975
   998
  by (auto simp add: iso_Field iso_def)
blanchet@48975
   999
next
blanchet@48975
  1000
  assume *: "embed r r' f \<and> f ` Field r = Field r'"
blanchet@48975
  1001
  hence "inj_on f (Field r)" using assms by (auto simp add: embed_inj_on)
blanchet@48975
  1002
  with * have "bij_betw f (Field r) (Field r')"
blanchet@48975
  1003
  unfolding bij_betw_def by simp
blanchet@48975
  1004
  with * show "iso r r' f" unfolding iso_def by auto
blanchet@48975
  1005
qed
blanchet@48975
  1006
blanchet@48975
  1007
lemma iso_iff2:
blanchet@48975
  1008
assumes "Well_order r"
blanchet@48975
  1009
shows "iso r r' f = (bij_betw f (Field r) (Field r') \<and>
blanchet@48975
  1010
                     (\<forall>a \<in> Field r. \<forall>b \<in> Field r.
blanchet@48975
  1011
                         (((a,b) \<in> r) = ((f a, f b) \<in> r'))))"
blanchet@48975
  1012
using assms
blanchet@48975
  1013
proof(auto simp add: iso_def)
blanchet@48975
  1014
  fix a b
blanchet@48975
  1015
  assume "embed r r' f"
blanchet@48975
  1016
  hence "compat r r' f" using embed_compat[of r] by auto
blanchet@48975
  1017
  moreover assume "(a,b) \<in> r"
blanchet@48975
  1018
  ultimately show "(f a, f b) \<in> r'" using compat_def[of r] by auto
blanchet@48975
  1019
next
blanchet@48975
  1020
  let ?f' = "inv_into (Field r) f"
blanchet@48975
  1021
  assume "embed r r' f" and 1: "bij_betw f (Field r) (Field r')"
blanchet@48975
  1022
  hence "embed r' r ?f'" using assms
blanchet@48975
  1023
  by (auto simp add: inv_into_Field_embed_bij_betw)
blanchet@48975
  1024
  hence 2: "compat r' r ?f'" using embed_compat[of r'] by auto
blanchet@48975
  1025
  fix a b assume *: "a \<in> Field r" "b \<in> Field r" and **: "(f a,f b) \<in> r'"
blanchet@48975
  1026
  hence "?f'(f a) = a \<and> ?f'(f b) = b" using 1
blanchet@48975
  1027
  by (auto simp add: bij_betw_inv_into_left)
blanchet@48975
  1028
  thus "(a,b) \<in> r" using ** 2 compat_def[of r' r ?f'] by fastforce
blanchet@48975
  1029
next
blanchet@48975
  1030
  assume *: "bij_betw f (Field r) (Field r')" and
blanchet@48975
  1031
         **: "\<forall>a\<in>Field r. \<forall>b\<in>Field r. ((a, b) \<in> r) = ((f a, f b) \<in> r')"
blanchet@55023
  1032
  have 1: "\<And> a. under r a \<le> Field r \<and> under r' (f a) \<le> Field r'"
blanchet@55023
  1033
  by (auto simp add: under_Field)
blanchet@48975
  1034
  have 2: "inj_on f (Field r)" using * by (auto simp add: bij_betw_def)
blanchet@48975
  1035
  {fix a assume ***: "a \<in> Field r"
blanchet@55023
  1036
   have "bij_betw f (under r a) (under r' (f a))"
blanchet@48975
  1037
   proof(unfold bij_betw_def, auto)
blanchet@55023
  1038
     show "inj_on f (under r a)"
blanchet@54482
  1039
     using 1 2 by (metis subset_inj_on)
blanchet@48975
  1040
   next
blanchet@55023
  1041
     fix b assume "b \<in> under r a"
blanchet@48975
  1042
     hence "a \<in> Field r \<and> b \<in> Field r \<and> (b,a) \<in> r"
blanchet@55023
  1043
     unfolding under_def by (auto simp add: Field_def Range_def Domain_def)
blanchet@55023
  1044
     with 1 ** show "f b \<in> under r' (f a)"
blanchet@55023
  1045
     unfolding under_def by auto
blanchet@48975
  1046
   next
blanchet@55023
  1047
     fix b' assume "b' \<in> under r' (f a)"
blanchet@55023
  1048
     hence 3: "(b',f a) \<in> r'" unfolding under_def by simp
blanchet@48975
  1049
     hence "b' \<in> Field r'" unfolding Field_def by auto
blanchet@48975
  1050
     with * obtain b where "b \<in> Field r \<and> f b = b'"
blanchet@48975
  1051
     unfolding bij_betw_def by force
blanchet@48975
  1052
     with 3 ** ***
blanchet@55023
  1053
     show "b' \<in> f ` (under r a)" unfolding under_def by blast
blanchet@48975
  1054
   qed
blanchet@48975
  1055
  }
blanchet@48975
  1056
  thus "embed r r' f" unfolding embed_def using * by auto
blanchet@48975
  1057
qed
blanchet@48975
  1058
blanchet@48975
  1059
lemma iso_iff3:
blanchet@48975
  1060
assumes WELL: "Well_order r" and WELL': "Well_order r'"
blanchet@48975
  1061
shows "iso r r' f = (bij_betw f (Field r) (Field r') \<and> compat r r' f)"
blanchet@48975
  1062
proof
blanchet@48975
  1063
  assume "iso r r' f"
blanchet@48975
  1064
  thus "bij_betw f (Field r) (Field r') \<and> compat r r' f"
blanchet@48975
  1065
  unfolding compat_def using WELL by (auto simp add: iso_iff2 Field_def)
blanchet@48975
  1066
next
blanchet@48975
  1067
  have Well: "wo_rel r \<and> wo_rel r'" using WELL WELL'
blanchet@48975
  1068
  by (auto simp add: wo_rel_def)
blanchet@48975
  1069
  assume *: "bij_betw f (Field r) (Field r') \<and> compat r r' f"
blanchet@48975
  1070
  thus "iso r r' f"
blanchet@48975
  1071
  unfolding "compat_def" using assms
blanchet@48975
  1072
  proof(auto simp add: iso_iff2)
blanchet@48975
  1073
    fix a b assume **: "a \<in> Field r" "b \<in> Field r" and
blanchet@48975
  1074
                  ***: "(f a, f b) \<in> r'"
blanchet@48975
  1075
    {assume "(b,a) \<in> r \<or> b = a"
blanchet@48975
  1076
     hence "(b,a): r"using Well ** wo_rel.REFL[of r] refl_on_def[of _ r] by blast
blanchet@48975
  1077
     hence "(f b, f a) \<in> r'" using * unfolding compat_def by auto
blanchet@48975
  1078
     hence "f a = f b"
blanchet@48975
  1079
     using Well *** wo_rel.ANTISYM[of r'] antisym_def[of r'] by blast
blanchet@48975
  1080
     hence "a = b" using * ** unfolding bij_betw_def inj_on_def by auto
blanchet@48975
  1081
     hence "(a,b) \<in> r" using Well ** wo_rel.REFL[of r] refl_on_def[of _ r] by blast
blanchet@48975
  1082
    }
blanchet@48975
  1083
    thus "(a,b) \<in> r"
blanchet@48975
  1084
    using Well ** wo_rel.TOTAL[of r] total_on_def[of _ r] by blast
blanchet@48975
  1085
  qed
blanchet@48975
  1086
qed
blanchet@48975
  1087
blanchet@48975
  1088
end