author  blanchet 
Wed, 23 Apr 2014 10:23:26 +0200  
changeset 56642  15cd15f9b40c 
parent 56641  029997d3b5d8 
child 56643  41d3596d8a64 
permissions  rwrr 
55059  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  3 
Author: Lorenz Panny, TU Muenchen 
4 
Author: Jasmin Blanchette, TU Muenchen 

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  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  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  19 
lemma subset_emptyI: "(\<And>x. x \<in> A \<Longrightarrow> False) \<Longrightarrow> A \<subseteq> {}" 
20 
by blast 

21 

56346  22 
lemma image_Collect_subsetI: "(\<And>x. P x \<Longrightarrow> f x \<in> B) \<Longrightarrow> f ` {x. P x} \<subseteq> B" 
49312  23 
by blast 
24 

25 
lemma Collect_restrict: "{x. x \<in> X \<and> P x} \<subseteq> X" 

26 
by auto 

27 

28 
lemma prop_restrict: "\<lbrakk>x \<in> Z; Z \<subseteq> {x. x \<in> X \<and> P x}\<rbrakk> \<Longrightarrow> P x" 

29 
by auto 

30 

55023
38db7814481d
get rid of 'rel' locale, to facilitate inclusion of 'Order_Relation_More_FP' into 'Order_Relation'
blanchet
parents:
54841
diff
changeset

31 
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

32 
unfolding underS_def by simp 
49312  33 

55023
38db7814481d
get rid of 'rel' locale, to facilitate inclusion of 'Order_Relation_More_FP' into 'Order_Relation'
blanchet
parents:
54841
diff
changeset

34 
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

35 
unfolding underS_def by simp 
49312  36 

55023
38db7814481d
get rid of 'rel' locale, to facilitate inclusion of 'Order_Relation_More_FP' into 'Order_Relation'
blanchet
parents:
54841
diff
changeset

37 
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

38 
unfolding underS_def Field_def by auto 
49312  39 

40 
lemma FieldI2: "(i, j) \<in> R \<Longrightarrow> j \<in> Field R" 

41 
unfolding Field_def by auto 

42 

43 
lemma fst_convol': "fst (<f, g> x) = f x" 

44 
using fst_convol unfolding convol_def by simp 

45 

46 
lemma snd_convol': "snd (<f, g> x) = g x" 

47 
using snd_convol unfolding convol_def by simp 

48 

49 
lemma convol_expand_snd: "fst o f = g \<Longrightarrow> <g, snd o f> = f" 

50 
unfolding convol_def by auto 

51 

55811  52 
lemma convol_expand_snd': 
53 
assumes "(fst o f = g)" 

54 
shows "h = snd o f \<longleftrightarrow> <g, h> = f" 

55 
proof  

56 
from assms have *: "<g, snd o f> = f" by (rule convol_expand_snd) 

57 
then have "h = snd o f \<longleftrightarrow> h = snd o <g, snd o f>" by simp 

58 
moreover have "\<dots> \<longleftrightarrow> h = snd o f" by (simp add: snd_convol) 

59 
moreover have "\<dots> \<longleftrightarrow> <g, h> = f" by (subst (2) *[symmetric]) (auto simp: convol_def fun_eq_iff) 

60 
ultimately show ?thesis by simp 

61 
qed 

49312  62 
lemma bij_betwE: "bij_betw f A B \<Longrightarrow> \<forall>a\<in>A. f a \<in> B" 
63 
unfolding bij_betw_def by auto 

64 

65 
lemma bij_betw_imageE: "bij_betw f A B \<Longrightarrow> f ` A = B" 

66 
unfolding bij_betw_def by auto 

67 

56237  68 
lemma f_the_inv_into_f_bij_betw: "bij_betw f A B \<Longrightarrow> 
69 
(bij_betw f A B \<Longrightarrow> x \<in> B) \<Longrightarrow> f (the_inv_into A f x) = x" 

70 
unfolding bij_betw_def by (blast intro: f_the_inv_into_f) 

49312  71 

56237  72 
lemma ex_bij_betw: "A \<le>o (r :: 'b rel) \<Longrightarrow> \<exists>f B :: 'b set. bij_betw f B A" 
73 
by (subst (asm) internalize_card_of_ordLeq) 

74 
(auto dest!: iffD2[OF card_of_ordIso ordIso_symmetric]) 

49312  75 

76 
lemma bij_betwI': 

77 
"\<lbrakk>\<And>x y. \<lbrakk>x \<in> X; y \<in> X\<rbrakk> \<Longrightarrow> (f x = f y) = (x = y); 

78 
\<And>x. x \<in> X \<Longrightarrow> f x \<in> Y; 

79 
\<And>y. y \<in> Y \<Longrightarrow> \<exists>x \<in> X. y = f x\<rbrakk> \<Longrightarrow> bij_betw f X Y" 

53695  80 
unfolding bij_betw_def inj_on_def by blast 
49312  81 

82 
lemma surj_fun_eq: 

83 
assumes surj_on: "f ` X = UNIV" and eq_on: "\<forall>x \<in> X. (g1 o f) x = (g2 o f) x" 

84 
shows "g1 = g2" 

85 
proof (rule ext) 

86 
fix y 

87 
from surj_on obtain x where "x \<in> X" and "y = f x" by blast 

88 
thus "g1 y = g2 y" using eq_on by simp 

89 
qed 

90 

91 
lemma Card_order_wo_rel: "Card_order r \<Longrightarrow> wo_rel r" 

49514  92 
unfolding wo_rel_def card_order_on_def by blast 
49312  93 

94 
lemma Cinfinite_limit: "\<lbrakk>x \<in> Field r; Cinfinite r\<rbrakk> \<Longrightarrow> 

95 
\<exists>y \<in> Field r. x \<noteq> y \<and> (x, y) \<in> r" 

96 
unfolding cinfinite_def by (auto simp add: infinite_Card_order_limit) 

97 

98 
lemma Card_order_trans: 

99 
"\<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" 

100 
unfolding card_order_on_def well_order_on_def linear_order_on_def 

101 
partial_order_on_def preorder_on_def trans_def antisym_def by blast 

102 

103 
lemma Cinfinite_limit2: 

104 
assumes x1: "x1 \<in> Field r" and x2: "x2 \<in> Field r" and r: "Cinfinite r" 

105 
shows "\<exists>y \<in> Field r. (x1 \<noteq> y \<and> (x1, y) \<in> r) \<and> (x2 \<noteq> y \<and> (x2, y) \<in> r)" 

106 
proof  

107 
from r have trans: "trans r" and total: "Total r" and antisym: "antisym r" 

108 
unfolding card_order_on_def well_order_on_def linear_order_on_def 

109 
partial_order_on_def preorder_on_def by auto 

110 
obtain y1 where y1: "y1 \<in> Field r" "x1 \<noteq> y1" "(x1, y1) \<in> r" 

111 
using Cinfinite_limit[OF x1 r] by blast 

112 
obtain y2 where y2: "y2 \<in> Field r" "x2 \<noteq> y2" "(x2, y2) \<in> r" 

113 
using Cinfinite_limit[OF x2 r] by blast 

114 
show ?thesis 

115 
proof (cases "y1 = y2") 

116 
case True with y1 y2 show ?thesis by blast 

117 
next 

118 
case False 

119 
with y1(1) y2(1) total have "(y1, y2) \<in> r \<or> (y2, y1) \<in> r" 

120 
unfolding total_on_def by auto 

121 
thus ?thesis 

122 
proof 

123 
assume *: "(y1, y2) \<in> r" 

124 
with trans y1(3) have "(x1, y2) \<in> r" unfolding trans_def by blast 

125 
with False y1 y2 * antisym show ?thesis by (cases "x1 = y2") (auto simp: antisym_def) 

126 
next 

127 
assume *: "(y2, y1) \<in> r" 

128 
with trans y2(3) have "(x2, y1) \<in> r" unfolding trans_def by blast 

129 
with False y1 y2 * antisym show ?thesis by (cases "x2 = y1") (auto simp: antisym_def) 

130 
qed 

131 
qed 

132 
qed 

133 

134 
lemma Cinfinite_limit_finite: "\<lbrakk>finite X; X \<subseteq> Field r; Cinfinite r\<rbrakk> 

135 
\<Longrightarrow> \<exists>y \<in> Field r. \<forall>x \<in> X. (x \<noteq> y \<and> (x, y) \<in> r)" 

136 
proof (induct X rule: finite_induct) 

137 
case empty thus ?case unfolding cinfinite_def using ex_in_conv[of "Field r"] finite.emptyI by auto 

138 
next 

139 
case (insert x X) 

140 
then obtain y where y: "y \<in> Field r" "\<forall>x \<in> X. (x \<noteq> y \<and> (x, y) \<in> r)" by blast 

141 
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" 

142 
using Cinfinite_limit2[OF _ y(1) insert(5), of x] insert(4) by blast 

49326  143 
show ?case 
144 
apply (intro bexI ballI) 

145 
apply (erule insertE) 

146 
apply hypsubst 

147 
apply (rule z(2)) 

148 
using Card_order_trans[OF insert(5)[THEN conjunct2]] y(2) z(3) 

149 
apply blast 

150 
apply (rule z(1)) 

151 
done 

49312  152 
qed 
153 

154 
lemma insert_subsetI: "\<lbrakk>x \<in> A; X \<subseteq> A\<rbrakk> \<Longrightarrow> insert x X \<subseteq> A" 

155 
by auto 

156 

157 
(*helps resolution*) 

158 
lemma well_order_induct_imp: 

159 
"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> 

160 
x \<in> Field r \<longrightarrow> P x" 

161 
by (erule wo_rel.well_order_induct) 

162 

163 
lemma meta_spec2: 

164 
assumes "(\<And>x y. PROP P x y)" 

165 
shows "PROP P x y" 

55084  166 
by (rule assms) 
49312  167 

54841
af71b753c459
express weak pullback property of bnfs only in terms of the relator
traytel
parents:
54246
diff
changeset

168 
lemma nchotomy_relcomppE: 
55811  169 
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" 
170 
shows P 

171 
proof (rule relcompp.cases[OF assms(2)], hypsubst) 

172 
fix b assume "r a b" "s b c" 

173 
moreover from assms(1) obtain b' where "b = f b'" by blast 

174 
ultimately show P by (blast intro: assms(3)) 

175 
qed 

54841
af71b753c459
express weak pullback property of bnfs only in terms of the relator
traytel
parents:
54246
diff
changeset

176 

55945  177 
lemma vimage2p_rel_fun: "rel_fun (vimage2p f g R) R f g" 
178 
unfolding rel_fun_def vimage2p_def by auto 

52731  179 

180 
lemma predicate2D_vimage2p: "\<lbrakk>R \<le> vimage2p f g S; R x y\<rbrakk> \<Longrightarrow> S (f x) (g y)" 

181 
unfolding vimage2p_def by auto 

182 

55945  183 
lemma id_transfer: "rel_fun A A id id" 
184 
unfolding rel_fun_def by simp 

55084  185 

55770
f2cf7f92c9ac
intermediate typedef for the type of the bound (local to lfp)
traytel
parents:
55575
diff
changeset

186 
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

187 
by (rule ssubst) 
55770
f2cf7f92c9ac
intermediate typedef for the type of the bound (local to lfp)
traytel
parents:
55575
diff
changeset

188 

56640
0a35354137a5
generate 'rec_o_map' and 'size_o_map' in size extension
blanchet
parents:
56639
diff
changeset

189 
lemma fun_cong_unused_0: "f = (\<lambda>x. g) \<Longrightarrow> f (\<lambda>x. 0) = g" 
0a35354137a5
generate 'rec_o_map' and 'size_o_map' in size extension
blanchet
parents:
56639
diff
changeset

190 
by (erule arg_cong) 
0a35354137a5
generate 'rec_o_map' and 'size_o_map' in size extension
blanchet
parents:
56639
diff
changeset

191 

56638  192 
lemma snd_o_convol: "(snd \<circ> (\<lambda>x. (f x, g x))) = g" 
193 
by (rule ext) simp 

194 

195 
lemma inj_on_convol_id: "inj_on (\<lambda>x. (x, f x)) X" 

196 
unfolding inj_on_def by simp 

197 

56640
0a35354137a5
generate 'rec_o_map' and 'size_o_map' in size extension
blanchet
parents:
56639
diff
changeset

198 
lemma case_prod_app: "case_prod f x y = case_prod (\<lambda>l r. f l r y) x" 
0a35354137a5
generate 'rec_o_map' and 'size_o_map' in size extension
blanchet
parents:
56639
diff
changeset

199 
by (case_tac x) simp 
0a35354137a5
generate 'rec_o_map' and 'size_o_map' in size extension
blanchet
parents:
56639
diff
changeset

200 

0a35354137a5
generate 'rec_o_map' and 'size_o_map' in size extension
blanchet
parents:
56639
diff
changeset

201 
lemma case_sum_o_map_sum: "case_sum l r (map_sum f g x) = case_sum (l \<circ> f) (r \<circ> g) x" 
0a35354137a5
generate 'rec_o_map' and 'size_o_map' in size extension
blanchet
parents:
56639
diff
changeset

202 
by (case_tac x) simp+ 
0a35354137a5
generate 'rec_o_map' and 'size_o_map' in size extension
blanchet
parents:
56639
diff
changeset

203 

0a35354137a5
generate 'rec_o_map' and 'size_o_map' in size extension
blanchet
parents:
56639
diff
changeset

204 
lemma case_prod_o_map_prod: "case_prod h (map_prod f g x) = case_prod (\<lambda>l r. h (f l) (g r)) x" 
0a35354137a5
generate 'rec_o_map' and 'size_o_map' in size extension
blanchet
parents:
56639
diff
changeset

205 
by (case_tac x) simp+ 
0a35354137a5
generate 'rec_o_map' and 'size_o_map' in size extension
blanchet
parents:
56639
diff
changeset

206 

0a35354137a5
generate 'rec_o_map' and 'size_o_map' in size extension
blanchet
parents:
56639
diff
changeset

207 
lemma prod_inj_map: "inj f \<Longrightarrow> inj g \<Longrightarrow> inj (map_prod f g)" 
0a35354137a5
generate 'rec_o_map' and 'size_o_map' in size extension
blanchet
parents:
56639
diff
changeset

208 
by (simp add: inj_on_def) 
0a35354137a5
generate 'rec_o_map' and 'size_o_map' in size extension
blanchet
parents:
56639
diff
changeset

209 

55062  210 
ML_file "Tools/BNF/bnf_lfp_util.ML" 
211 
ML_file "Tools/BNF/bnf_lfp_tactics.ML" 

212 
ML_file "Tools/BNF/bnf_lfp.ML" 

213 
ML_file "Tools/BNF/bnf_lfp_compat.ML" 

55571  214 
ML_file "Tools/BNF/bnf_lfp_rec_sugar_more.ML" 
56638  215 
ML_file "Tools/BNF/bnf_lfp_size.ML" 
49309
f20b24214ac2
split basic BNFs into really basic ones and others, and added Andreas Lochbihler's "option" BNF
blanchet
parents:
49308
diff
changeset

216 

55084  217 
hide_fact (open) id_transfer 
218 

48975
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset

219 
end 