src/HOL/BNF_LFP.thy
author blanchet
Mon, 03 Mar 2014 12:48:20 +0100
changeset 55862 b458558cbcc2
parent 55856 bddaada24074
child 55863 fa3a1ec69a1b
permissions -rw-r--r--
optimized simple non-recursive datatypes by reusing 'case' for 'rec' constant
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
55059
ef2e0fb783c6 tuned comments
blanchet
parents: 55058
diff changeset
     1
(*  Title:      HOL/BNF_LFP.thy
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
     2
    Author:     Dmitriy Traytel, TU Muenchen
53305
29c267cb9314 rationalized files
blanchet
parents: 52913
diff changeset
     3
    Author:     Lorenz Panny, TU Muenchen
29c267cb9314 rationalized files
blanchet
parents: 52913
diff changeset
     4
    Author:     Jasmin Blanchette, TU Muenchen
29c267cb9314 rationalized files
blanchet
parents: 52913
diff changeset
     5
    Copyright   2012, 2013
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
     6
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
     7
Least fixed point operation on bounded natural functors.
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
     8
*)
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
     9
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
    10
header {* Least Fixed Point Operation on Bounded Natural Functors *}
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
    11
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
    12
theory BNF_LFP
53311
802ae7dae691 tuned theory name
blanchet
parents: 53310
diff changeset
    13
imports BNF_FP_Base
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
    14
keywords
53305
29c267cb9314 rationalized files
blanchet
parents: 52913
diff changeset
    15
  "datatype_new" :: thy_decl and
55575
a5e33e18fb5c moved 'primrec' up (for real this time) and removed temporary 'old_primrec'
blanchet
parents: 55571
diff changeset
    16
  "datatype_compat" :: thy_decl
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
    17
begin
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
    18
49312
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    19
lemma subset_emptyI: "(\<And>x. x \<in> A \<Longrightarrow> False) \<Longrightarrow> A \<subseteq> {}"
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    20
by blast
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    21
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    22
lemma image_Collect_subsetI:
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    23
  "(\<And>x. P x \<Longrightarrow> f x \<in> B) \<Longrightarrow> f ` {x. P x} \<subseteq> B"
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    24
by blast
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    25
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    26
lemma Collect_restrict: "{x. x \<in> X \<and> P x} \<subseteq> X"
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    27
by auto
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    28
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    29
lemma prop_restrict: "\<lbrakk>x \<in> Z; Z \<subseteq> {x. x \<in> X \<and> P x}\<rbrakk> \<Longrightarrow> P x"
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    30
by auto
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    31
55023
38db7814481d get rid of 'rel' locale, to facilitate inclusion of 'Order_Relation_More_FP' into 'Order_Relation'
blanchet
parents: 54841
diff changeset
    32
lemma underS_I: "\<lbrakk>i \<noteq> j; (i, j) \<in> R\<rbrakk> \<Longrightarrow> i \<in> underS R j"
38db7814481d get rid of 'rel' locale, to facilitate inclusion of 'Order_Relation_More_FP' into 'Order_Relation'
blanchet
parents: 54841
diff changeset
    33
unfolding underS_def by simp
49312
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    34
55023
38db7814481d get rid of 'rel' locale, to facilitate inclusion of 'Order_Relation_More_FP' into 'Order_Relation'
blanchet
parents: 54841
diff changeset
    35
lemma underS_E: "i \<in> underS R j \<Longrightarrow> i \<noteq> j \<and> (i, j) \<in> R"
38db7814481d get rid of 'rel' locale, to facilitate inclusion of 'Order_Relation_More_FP' into 'Order_Relation'
blanchet
parents: 54841
diff changeset
    36
unfolding underS_def by simp
49312
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    37
55023
38db7814481d get rid of 'rel' locale, to facilitate inclusion of 'Order_Relation_More_FP' into 'Order_Relation'
blanchet
parents: 54841
diff changeset
    38
lemma underS_Field: "i \<in> underS R j \<Longrightarrow> i \<in> Field R"
38db7814481d get rid of 'rel' locale, to facilitate inclusion of 'Order_Relation_More_FP' into 'Order_Relation'
blanchet
parents: 54841
diff changeset
    39
unfolding underS_def Field_def by auto
49312
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    40
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    41
lemma FieldI2: "(i, j) \<in> R \<Longrightarrow> j \<in> Field R"
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    42
unfolding Field_def by auto
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    43
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    44
lemma fst_convol': "fst (<f, g> x) = f x"
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    45
using fst_convol unfolding convol_def by simp
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    46
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    47
lemma snd_convol': "snd (<f, g> x) = g x"
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    48
using snd_convol unfolding convol_def by simp
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    49
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    50
lemma convol_expand_snd: "fst o f = g \<Longrightarrow>  <g, snd o f> = f"
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    51
unfolding convol_def by auto
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    52
55811
aa1acc25126b load Metis a little later
traytel
parents: 55770
diff changeset
    53
lemma convol_expand_snd':
aa1acc25126b load Metis a little later
traytel
parents: 55770
diff changeset
    54
  assumes "(fst o f = g)"
aa1acc25126b load Metis a little later
traytel
parents: 55770
diff changeset
    55
  shows "h = snd o f \<longleftrightarrow> <g, h> = f"
aa1acc25126b load Metis a little later
traytel
parents: 55770
diff changeset
    56
proof -
aa1acc25126b load Metis a little later
traytel
parents: 55770
diff changeset
    57
  from assms have *: "<g, snd o f> = f" by (rule convol_expand_snd)
aa1acc25126b load Metis a little later
traytel
parents: 55770
diff changeset
    58
  then have "h = snd o f \<longleftrightarrow> h = snd o <g, snd o f>" by simp
aa1acc25126b load Metis a little later
traytel
parents: 55770
diff changeset
    59
  moreover have "\<dots> \<longleftrightarrow> h = snd o f" by (simp add: snd_convol)
aa1acc25126b load Metis a little later
traytel
parents: 55770
diff changeset
    60
  moreover have "\<dots> \<longleftrightarrow> <g, h> = f" by (subst (2) *[symmetric]) (auto simp: convol_def fun_eq_iff)
aa1acc25126b load Metis a little later
traytel
parents: 55770
diff changeset
    61
  ultimately show ?thesis by simp
aa1acc25126b load Metis a little later
traytel
parents: 55770
diff changeset
    62
qed
51739
3514b90d0a8b (co)rec is (just as the (un)fold) the unique morphism;
traytel
parents: 49635
diff changeset
    63
49312
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    64
definition inver where
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    65
  "inver g f A = (ALL a : A. g (f a) = a)"
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    66
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    67
lemma bij_betw_iff_ex:
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    68
  "bij_betw f A B = (EX g. g ` B = A \<and> inver g f A \<and> inver f g B)" (is "?L = ?R")
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    69
proof (rule iffI)
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    70
  assume ?L
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    71
  hence f: "f ` A = B" and inj_f: "inj_on f A" unfolding bij_betw_def by auto
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    72
  let ?phi = "% b a. a : A \<and> f a = b"
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    73
  have "ALL b : B. EX a. ?phi b a" using f by blast
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    74
  then obtain g where g: "ALL b : B. g b : A \<and> f (g b) = b"
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    75
    using bchoice[of B ?phi] by blast
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    76
  hence gg: "ALL b : f ` A. g b : A \<and> f (g b) = b" using f by blast
49326
a063a96c8662 got rid of metis calls
blanchet
parents: 49312
diff changeset
    77
  have gf: "inver g f A" unfolding inver_def
55811
aa1acc25126b load Metis a little later
traytel
parents: 55770
diff changeset
    78
  proof
aa1acc25126b load Metis a little later
traytel
parents: 55770
diff changeset
    79
    fix a assume "a \<in> A"
aa1acc25126b load Metis a little later
traytel
parents: 55770
diff changeset
    80
    then show "g (f a) = a" using the_inv_into_f_f[OF inj_f, of "g (f a)"]
aa1acc25126b load Metis a little later
traytel
parents: 55770
diff changeset
    81
      the_inv_into_f_f[OF inj_f, of a] gg imageI[of a A f] by auto
aa1acc25126b load Metis a little later
traytel
parents: 55770
diff changeset
    82
  qed
49312
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    83
  moreover have "g ` B \<le> A \<and> inver f g B" using g unfolding inver_def by blast
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    84
  moreover have "A \<le> g ` B"
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    85
  proof safe
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    86
    fix a assume a: "a : A"
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    87
    hence "f a : B" using f by auto
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    88
    moreover have "a = g (f a)" using a gf unfolding inver_def by auto
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    89
    ultimately show "a : g ` B" by blast
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    90
  qed
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    91
  ultimately show ?R by blast
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    92
next
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    93
  assume ?R
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    94
  then obtain g where g: "g ` B = A \<and> inver g f A \<and> inver f g B" by blast
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    95
  show ?L unfolding bij_betw_def
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    96
  proof safe
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    97
    show "inj_on f A" unfolding inj_on_def
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    98
    proof safe
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    99
      fix a1 a2 assume a: "a1 : A"  "a2 : A" and "f a1 = f a2"
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
   100
      hence "g (f a1) = g (f a2)" by simp
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
   101
      thus "a1 = a2" using a g unfolding inver_def by simp
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
   102
    qed
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
   103
  next
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
   104
    fix a assume "a : A"
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
   105
    then obtain b where b: "b : B" and a: "a = g b" using g by blast
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
   106
    hence "b = f (g b)" using g unfolding inver_def by auto
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
   107
    thus "f a : B" unfolding a using b by simp
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
   108
  next
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
   109
    fix b assume "b : B"
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
   110
    hence "g b : A \<and> b = f (g b)" using g unfolding inver_def by auto
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
   111
    thus "b : f ` A" by auto
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
   112
  qed
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
   113
qed
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
   114
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
   115
lemma bij_betw_ex_weakE:
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
   116
  "\<lbrakk>bij_betw f A B\<rbrakk> \<Longrightarrow> \<exists>g. g ` B \<subseteq> A \<and> inver g f A \<and> inver f g B"
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
   117
by (auto simp only: bij_betw_iff_ex)
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
   118
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
   119
lemma inver_surj: "\<lbrakk>g ` B \<subseteq> A; f ` A \<subseteq> B; inver g f A\<rbrakk> \<Longrightarrow> g ` B = A"
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
   120
unfolding inver_def by auto (rule rev_image_eqI, auto)
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
   121
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
   122
lemma inver_mono: "\<lbrakk>A \<subseteq> B; inver f g B\<rbrakk> \<Longrightarrow> inver f g A"
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
   123
unfolding inver_def by auto
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
   124
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
   125
lemma inver_pointfree: "inver f g A = (\<forall>a \<in> A. (f o g) a = a)"
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
   126
unfolding inver_def by simp
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
   127
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
   128
lemma bij_betwE: "bij_betw f A B \<Longrightarrow> \<forall>a\<in>A. f a \<in> B"
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
   129
unfolding bij_betw_def by auto
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
   130
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
   131
lemma bij_betw_imageE: "bij_betw f A B \<Longrightarrow> f ` A = B"
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
   132
unfolding bij_betw_def by auto
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
   133
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
   134
lemma inverE: "\<lbrakk>inver f f' A; x \<in> A\<rbrakk> \<Longrightarrow> f (f' x) = x"
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
   135
unfolding inver_def by auto
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
   136
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
   137
lemma bij_betw_inver1: "bij_betw f A B \<Longrightarrow> inver (inv_into A f) f A"
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
   138
unfolding bij_betw_def inver_def by auto
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
   139
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
   140
lemma bij_betw_inver2: "bij_betw f A B \<Longrightarrow> inver f (inv_into A f) B"
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
   141
unfolding bij_betw_def inver_def by auto
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
   142
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
   143
lemma bij_betwI: "\<lbrakk>bij_betw g B A; inver g f A; inver f g B\<rbrakk> \<Longrightarrow> bij_betw f A B"
49326
a063a96c8662 got rid of metis calls
blanchet
parents: 49312
diff changeset
   144
by (drule bij_betw_imageE, unfold bij_betw_iff_ex) blast
49312
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
   145
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
   146
lemma bij_betwI':
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
   147
  "\<lbrakk>\<And>x y. \<lbrakk>x \<in> X; y \<in> X\<rbrakk> \<Longrightarrow> (f x = f y) = (x = y);
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
   148
    \<And>x. x \<in> X \<Longrightarrow> f x \<in> Y;
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
   149
    \<And>y. y \<in> Y \<Longrightarrow> \<exists>x \<in> X. y = f x\<rbrakk> \<Longrightarrow> bij_betw f X Y"
53695
a66d211ab34e tuned proofs
traytel
parents: 53311
diff changeset
   150
unfolding bij_betw_def inj_on_def by blast
49312
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
   151
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
   152
lemma surj_fun_eq:
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
   153
  assumes surj_on: "f ` X = UNIV" and eq_on: "\<forall>x \<in> X. (g1 o f) x = (g2 o f) x"
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
   154
  shows "g1 = g2"
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
   155
proof (rule ext)
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
   156
  fix y
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
   157
  from surj_on obtain x where "x \<in> X" and "y = f x" by blast
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
   158
  thus "g1 y = g2 y" using eq_on by simp
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
   159
qed
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
   160
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
   161
lemma Card_order_wo_rel: "Card_order r \<Longrightarrow> wo_rel r"
49514
45e3e564e306 tuned whitespace
blanchet
parents: 49510
diff changeset
   162
unfolding wo_rel_def card_order_on_def by blast
49312
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
   163
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
   164
lemma Cinfinite_limit: "\<lbrakk>x \<in> Field r; Cinfinite r\<rbrakk> \<Longrightarrow>
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
   165
  \<exists>y \<in> Field r. x \<noteq> y \<and> (x, y) \<in> r"
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
   166
unfolding cinfinite_def by (auto simp add: infinite_Card_order_limit)
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
   167
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
   168
lemma Card_order_trans:
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
   169
  "\<lbrakk>Card_order r; x \<noteq> y; (x, y) \<in> r; y \<noteq> z; (y, z) \<in> r\<rbrakk> \<Longrightarrow> x \<noteq> z \<and> (x, z) \<in> r"
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
   170
unfolding card_order_on_def well_order_on_def linear_order_on_def
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
   171
  partial_order_on_def preorder_on_def trans_def antisym_def by blast
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
   172
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
   173
lemma Cinfinite_limit2:
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
   174
 assumes x1: "x1 \<in> Field r" and x2: "x2 \<in> Field r" and r: "Cinfinite r"
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
   175
 shows "\<exists>y \<in> Field r. (x1 \<noteq> y \<and> (x1, y) \<in> r) \<and> (x2 \<noteq> y \<and> (x2, y) \<in> r)"
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
   176
proof -
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
   177
  from r have trans: "trans r" and total: "Total r" and antisym: "antisym r"
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
   178
    unfolding card_order_on_def well_order_on_def linear_order_on_def
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
   179
      partial_order_on_def preorder_on_def by auto
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
   180
  obtain y1 where y1: "y1 \<in> Field r" "x1 \<noteq> y1" "(x1, y1) \<in> r"
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
   181
    using Cinfinite_limit[OF x1 r] by blast
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
   182
  obtain y2 where y2: "y2 \<in> Field r" "x2 \<noteq> y2" "(x2, y2) \<in> r"
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
   183
    using Cinfinite_limit[OF x2 r] by blast
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
   184
  show ?thesis
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
   185
  proof (cases "y1 = y2")
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
   186
    case True with y1 y2 show ?thesis by blast
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
   187
  next
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
   188
    case False
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
   189
    with y1(1) y2(1) total have "(y1, y2) \<in> r \<or> (y2, y1) \<in> r"
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
   190
      unfolding total_on_def by auto
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
   191
    thus ?thesis
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
   192
    proof
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
   193
      assume *: "(y1, y2) \<in> r"
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
   194
      with trans y1(3) have "(x1, y2) \<in> r" unfolding trans_def by blast
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
   195
      with False y1 y2 * antisym show ?thesis by (cases "x1 = y2") (auto simp: antisym_def)
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
   196
    next
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
   197
      assume *: "(y2, y1) \<in> r"
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
   198
      with trans y2(3) have "(x2, y1) \<in> r" unfolding trans_def by blast
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
   199
      with False y1 y2 * antisym show ?thesis by (cases "x2 = y1") (auto simp: antisym_def)
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
   200
    qed
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
   201
  qed
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
   202
qed
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
   203
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
   204
lemma Cinfinite_limit_finite: "\<lbrakk>finite X; X \<subseteq> Field r; Cinfinite r\<rbrakk>
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
   205
 \<Longrightarrow> \<exists>y \<in> Field r. \<forall>x \<in> X. (x \<noteq> y \<and> (x, y) \<in> r)"
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
   206
proof (induct X rule: finite_induct)
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
   207
  case empty thus ?case unfolding cinfinite_def using ex_in_conv[of "Field r"] finite.emptyI by auto
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
   208
next
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
   209
  case (insert x X)
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
   210
  then obtain y where y: "y \<in> Field r" "\<forall>x \<in> X. (x \<noteq> y \<and> (x, y) \<in> r)" by blast
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
   211
  then obtain z where z: "z \<in> Field r" "x \<noteq> z \<and> (x, z) \<in> r" "y \<noteq> z \<and> (y, z) \<in> r"
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
   212
    using Cinfinite_limit2[OF _ y(1) insert(5), of x] insert(4) by blast
49326
a063a96c8662 got rid of metis calls
blanchet
parents: 49312
diff changeset
   213
  show ?case
a063a96c8662 got rid of metis calls
blanchet
parents: 49312
diff changeset
   214
    apply (intro bexI ballI)
a063a96c8662 got rid of metis calls
blanchet
parents: 49312
diff changeset
   215
    apply (erule insertE)
a063a96c8662 got rid of metis calls
blanchet
parents: 49312
diff changeset
   216
    apply hypsubst
a063a96c8662 got rid of metis calls
blanchet
parents: 49312
diff changeset
   217
    apply (rule z(2))
a063a96c8662 got rid of metis calls
blanchet
parents: 49312
diff changeset
   218
    using Card_order_trans[OF insert(5)[THEN conjunct2]] y(2) z(3)
a063a96c8662 got rid of metis calls
blanchet
parents: 49312
diff changeset
   219
    apply blast
a063a96c8662 got rid of metis calls
blanchet
parents: 49312
diff changeset
   220
    apply (rule z(1))
a063a96c8662 got rid of metis calls
blanchet
parents: 49312
diff changeset
   221
    done
49312
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
   222
qed
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
   223
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
   224
lemma insert_subsetI: "\<lbrakk>x \<in> A; X \<subseteq> A\<rbrakk> \<Longrightarrow> insert x X \<subseteq> A"
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
   225
by auto
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
   226
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
   227
(*helps resolution*)
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
   228
lemma well_order_induct_imp:
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
   229
  "wo_rel r \<Longrightarrow> (\<And>x. \<forall>y. y \<noteq> x \<and> (y, x) \<in> r \<longrightarrow> y \<in> Field r \<longrightarrow> P y \<Longrightarrow> x \<in> Field r \<longrightarrow> P x) \<Longrightarrow>
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
   230
     x \<in> Field r \<longrightarrow> P x"
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
   231
by (erule wo_rel.well_order_induct)
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
   232
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
   233
lemma meta_spec2:
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
   234
  assumes "(\<And>x y. PROP P x y)"
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
   235
  shows "PROP P x y"
55084
8ee9aabb2bca rationalized lemmas
blanchet
parents: 55066
diff changeset
   236
by (rule assms)
49312
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
   237
54841
af71b753c459 express weak pullback property of bnfs only in terms of the relator
traytel
parents: 54246
diff changeset
   238
lemma nchotomy_relcomppE:
55811
aa1acc25126b load Metis a little later
traytel
parents: 55770
diff changeset
   239
  assumes "\<And>y. \<exists>x. y = f x" "(r OO s) a c" "\<And>b. r a (f b) \<Longrightarrow> s (f b) c \<Longrightarrow> P"
aa1acc25126b load Metis a little later
traytel
parents: 55770
diff changeset
   240
  shows P
aa1acc25126b load Metis a little later
traytel
parents: 55770
diff changeset
   241
proof (rule relcompp.cases[OF assms(2)], hypsubst)
aa1acc25126b load Metis a little later
traytel
parents: 55770
diff changeset
   242
  fix b assume "r a b" "s b c"
aa1acc25126b load Metis a little later
traytel
parents: 55770
diff changeset
   243
  moreover from assms(1) obtain b' where "b = f b'" by blast
aa1acc25126b load Metis a little later
traytel
parents: 55770
diff changeset
   244
  ultimately show P by (blast intro: assms(3))
aa1acc25126b load Metis a little later
traytel
parents: 55770
diff changeset
   245
qed
54841
af71b753c459 express weak pullback property of bnfs only in terms of the relator
traytel
parents: 54246
diff changeset
   246
55066
blanchet
parents: 55062
diff changeset
   247
lemma vimage2p_fun_rel: "fun_rel (vimage2p f g R) R f g"
52731
dacd47a0633f transfer rule for {c,d}tor_{,un}fold
traytel
parents: 52635
diff changeset
   248
  unfolding fun_rel_def vimage2p_def by auto
dacd47a0633f transfer rule for {c,d}tor_{,un}fold
traytel
parents: 52635
diff changeset
   249
dacd47a0633f transfer rule for {c,d}tor_{,un}fold
traytel
parents: 52635
diff changeset
   250
lemma predicate2D_vimage2p: "\<lbrakk>R \<le> vimage2p f g S; R x y\<rbrakk> \<Longrightarrow> S (f x) (g y)"
dacd47a0633f transfer rule for {c,d}tor_{,un}fold
traytel
parents: 52635
diff changeset
   251
  unfolding vimage2p_def by auto
dacd47a0633f transfer rule for {c,d}tor_{,un}fold
traytel
parents: 52635
diff changeset
   252
55084
8ee9aabb2bca rationalized lemmas
blanchet
parents: 55066
diff changeset
   253
lemma id_transfer: "fun_rel A A id id"
55851
3d40cf74726c optimize cardinal bounds involving natLeq (omega)
blanchet
parents: 55811
diff changeset
   254
  unfolding fun_rel_def by simp
55084
8ee9aabb2bca rationalized lemmas
blanchet
parents: 55066
diff changeset
   255
55770
f2cf7f92c9ac intermediate typedef for the type of the bound (local to lfp)
traytel
parents: 55575
diff changeset
   256
lemma ssubst_Pair_rhs: "\<lbrakk>(r, s) \<in> R; s' = s\<rbrakk> \<Longrightarrow> (r, s') \<in> R"
55851
3d40cf74726c optimize cardinal bounds involving natLeq (omega)
blanchet
parents: 55811
diff changeset
   257
  by (rule ssubst)
55770
f2cf7f92c9ac intermediate typedef for the type of the bound (local to lfp)
traytel
parents: 55575
diff changeset
   258
55062
6d3fad6f01c9 made BNF compile after move to HOL
blanchet
parents: 55059
diff changeset
   259
ML_file "Tools/BNF/bnf_lfp_util.ML"
6d3fad6f01c9 made BNF compile after move to HOL
blanchet
parents: 55059
diff changeset
   260
ML_file "Tools/BNF/bnf_lfp_tactics.ML"
6d3fad6f01c9 made BNF compile after move to HOL
blanchet
parents: 55059
diff changeset
   261
ML_file "Tools/BNF/bnf_lfp.ML"
6d3fad6f01c9 made BNF compile after move to HOL
blanchet
parents: 55059
diff changeset
   262
ML_file "Tools/BNF/bnf_lfp_compat.ML"
55571
a6153343c44f prepare two-stage 'primrec' setup
blanchet
parents: 55538
diff changeset
   263
ML_file "Tools/BNF/bnf_lfp_rec_sugar_more.ML"
49309
f20b24214ac2 split basic BNFs into really basic ones and others, and added Andreas Lochbihler's "option" BNF
blanchet
parents: 49308
diff changeset
   264
55084
8ee9aabb2bca rationalized lemmas
blanchet
parents: 55066
diff changeset
   265
hide_fact (open) id_transfer
8ee9aabb2bca rationalized lemmas
blanchet
parents: 55066
diff changeset
   266
55856
bddaada24074 got rid of automatically generated fold constant and theorems (to reduce overhead)
blanchet
parents: 55851
diff changeset
   267
datatype_new 'a F = F 'a
bddaada24074 got rid of automatically generated fold constant and theorems (to reduce overhead)
blanchet
parents: 55851
diff changeset
   268
55862
b458558cbcc2 optimized simple non-recursive datatypes by reusing 'case' for 'rec' constant
blanchet
parents: 55856
diff changeset
   269
primrec f where
b458558cbcc2 optimized simple non-recursive datatypes by reusing 'case' for 'rec' constant
blanchet
parents: 55856
diff changeset
   270
  "f (F x) = x"
b458558cbcc2 optimized simple non-recursive datatypes by reusing 'case' for 'rec' constant
blanchet
parents: 55856
diff changeset
   271
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   272
end