8 imports Bifinite |
8 imports Bifinite |
9 begin |
9 begin |
10 |
10 |
11 subsection {* Ordering on type @{typ "'a + 'b"} *} |
11 subsection {* Ordering on type @{typ "'a + 'b"} *} |
12 |
12 |
13 instantiation "+" :: (sq_ord, sq_ord) sq_ord |
13 instantiation "+" :: (below, below) below |
14 begin |
14 begin |
15 |
15 |
16 definition |
16 definition below_sum_def: |
17 less_sum_def: "x \<sqsubseteq> y \<equiv> case x of |
17 "x \<sqsubseteq> y \<equiv> case x of |
18 Inl a \<Rightarrow> (case y of Inl b \<Rightarrow> a \<sqsubseteq> b | Inr b \<Rightarrow> False) | |
18 Inl a \<Rightarrow> (case y of Inl b \<Rightarrow> a \<sqsubseteq> b | Inr b \<Rightarrow> False) | |
19 Inr a \<Rightarrow> (case y of Inl b \<Rightarrow> False | Inr b \<Rightarrow> a \<sqsubseteq> b)" |
19 Inr a \<Rightarrow> (case y of Inl b \<Rightarrow> False | Inr b \<Rightarrow> a \<sqsubseteq> b)" |
20 |
20 |
21 instance .. |
21 instance .. |
22 end |
22 end |
23 |
23 |
24 lemma Inl_less_iff [simp]: "Inl x \<sqsubseteq> Inl y = x \<sqsubseteq> y" |
24 lemma Inl_below_Inl [simp]: "Inl x \<sqsubseteq> Inl y = x \<sqsubseteq> y" |
25 unfolding less_sum_def by simp |
25 unfolding below_sum_def by simp |
26 |
26 |
27 lemma Inr_less_iff [simp]: "Inr x \<sqsubseteq> Inr y = x \<sqsubseteq> y" |
27 lemma Inr_below_Inr [simp]: "Inr x \<sqsubseteq> Inr y = x \<sqsubseteq> y" |
28 unfolding less_sum_def by simp |
28 unfolding below_sum_def by simp |
29 |
29 |
30 lemma Inl_less_Inr [simp]: "\<not> Inl x \<sqsubseteq> Inr y" |
30 lemma Inl_below_Inr [simp]: "\<not> Inl x \<sqsubseteq> Inr y" |
31 unfolding less_sum_def by simp |
31 unfolding below_sum_def by simp |
32 |
32 |
33 lemma Inr_less_Inl [simp]: "\<not> Inr x \<sqsubseteq> Inl y" |
33 lemma Inr_below_Inl [simp]: "\<not> Inr x \<sqsubseteq> Inl y" |
34 unfolding less_sum_def by simp |
34 unfolding below_sum_def by simp |
35 |
35 |
36 lemma Inl_mono: "x \<sqsubseteq> y \<Longrightarrow> Inl x \<sqsubseteq> Inl y" |
36 lemma Inl_mono: "x \<sqsubseteq> y \<Longrightarrow> Inl x \<sqsubseteq> Inl y" |
37 by simp |
37 by simp |
38 |
38 |
39 lemma Inr_mono: "x \<sqsubseteq> y \<Longrightarrow> Inr x \<sqsubseteq> Inr y" |
39 lemma Inr_mono: "x \<sqsubseteq> y \<Longrightarrow> Inr x \<sqsubseteq> Inr y" |
40 by simp |
40 by simp |
41 |
41 |
42 lemma Inl_lessE: "\<lbrakk>Inl a \<sqsubseteq> x; \<And>b. \<lbrakk>x = Inl b; a \<sqsubseteq> b\<rbrakk> \<Longrightarrow> R\<rbrakk> \<Longrightarrow> R" |
42 lemma Inl_belowE: "\<lbrakk>Inl a \<sqsubseteq> x; \<And>b. \<lbrakk>x = Inl b; a \<sqsubseteq> b\<rbrakk> \<Longrightarrow> R\<rbrakk> \<Longrightarrow> R" |
43 by (cases x, simp_all) |
43 by (cases x, simp_all) |
44 |
44 |
45 lemma Inr_lessE: "\<lbrakk>Inr a \<sqsubseteq> x; \<And>b. \<lbrakk>x = Inr b; a \<sqsubseteq> b\<rbrakk> \<Longrightarrow> R\<rbrakk> \<Longrightarrow> R" |
45 lemma Inr_belowE: "\<lbrakk>Inr a \<sqsubseteq> x; \<And>b. \<lbrakk>x = Inr b; a \<sqsubseteq> b\<rbrakk> \<Longrightarrow> R\<rbrakk> \<Longrightarrow> R" |
46 by (cases x, simp_all) |
46 by (cases x, simp_all) |
47 |
47 |
48 lemmas sum_less_elims = Inl_lessE Inr_lessE |
48 lemmas sum_below_elims = Inl_belowE Inr_belowE |
49 |
49 |
50 lemma sum_less_cases: |
50 lemma sum_below_cases: |
51 "\<lbrakk>x \<sqsubseteq> y; |
51 "\<lbrakk>x \<sqsubseteq> y; |
52 \<And>a b. \<lbrakk>x = Inl a; y = Inl b; a \<sqsubseteq> b\<rbrakk> \<Longrightarrow> R; |
52 \<And>a b. \<lbrakk>x = Inl a; y = Inl b; a \<sqsubseteq> b\<rbrakk> \<Longrightarrow> R; |
53 \<And>a b. \<lbrakk>x = Inr a; y = Inr b; a \<sqsubseteq> b\<rbrakk> \<Longrightarrow> R\<rbrakk> |
53 \<And>a b. \<lbrakk>x = Inr a; y = Inr b; a \<sqsubseteq> b\<rbrakk> \<Longrightarrow> R\<rbrakk> |
54 \<Longrightarrow> R" |
54 \<Longrightarrow> R" |
55 by (cases x, safe elim!: sum_less_elims, auto) |
55 by (cases x, safe elim!: sum_below_elims, auto) |
56 |
56 |
57 subsection {* Sum type is a complete partial order *} |
57 subsection {* Sum type is a complete partial order *} |
58 |
58 |
59 instance "+" :: (po, po) po |
59 instance "+" :: (po, po) po |
60 proof |
60 proof |
62 show "x \<sqsubseteq> x" |
62 show "x \<sqsubseteq> x" |
63 by (induct x, simp_all) |
63 by (induct x, simp_all) |
64 next |
64 next |
65 fix x y :: "'a + 'b" |
65 fix x y :: "'a + 'b" |
66 assume "x \<sqsubseteq> y" and "y \<sqsubseteq> x" thus "x = y" |
66 assume "x \<sqsubseteq> y" and "y \<sqsubseteq> x" thus "x = y" |
67 by (induct x, auto elim!: sum_less_elims intro: antisym_less) |
67 by (induct x, auto elim!: sum_below_elims intro: below_antisym) |
68 next |
68 next |
69 fix x y z :: "'a + 'b" |
69 fix x y z :: "'a + 'b" |
70 assume "x \<sqsubseteq> y" and "y \<sqsubseteq> z" thus "x \<sqsubseteq> z" |
70 assume "x \<sqsubseteq> y" and "y \<sqsubseteq> z" thus "x \<sqsubseteq> z" |
71 by (induct x, auto elim!: sum_less_elims intro: trans_less) |
71 by (induct x, auto elim!: sum_below_elims intro: below_trans) |
72 qed |
72 qed |
73 |
73 |
74 lemma monofun_inv_Inl: "monofun (\<lambda>p. THE a. p = Inl a)" |
74 lemma monofun_inv_Inl: "monofun (\<lambda>p. THE a. p = Inl a)" |
75 by (rule monofunI, erule sum_less_cases, simp_all) |
75 by (rule monofunI, erule sum_below_cases, simp_all) |
76 |
76 |
77 lemma monofun_inv_Inr: "monofun (\<lambda>p. THE b. p = Inr b)" |
77 lemma monofun_inv_Inr: "monofun (\<lambda>p. THE b. p = Inr b)" |
78 by (rule monofunI, erule sum_less_cases, simp_all) |
78 by (rule monofunI, erule sum_below_cases, simp_all) |
79 |
79 |
80 lemma sum_chain_cases: |
80 lemma sum_chain_cases: |
81 assumes Y: "chain Y" |
81 assumes Y: "chain Y" |
82 assumes A: "\<And>A. \<lbrakk>chain A; Y = (\<lambda>i. Inl (A i))\<rbrakk> \<Longrightarrow> R" |
82 assumes A: "\<And>A. \<lbrakk>chain A; Y = (\<lambda>i. Inl (A i))\<rbrakk> \<Longrightarrow> R" |
83 assumes B: "\<And>B. \<lbrakk>chain B; Y = (\<lambda>i. Inr (B i))\<rbrakk> \<Longrightarrow> R" |
83 assumes B: "\<And>B. \<lbrakk>chain B; Y = (\<lambda>i. Inr (B i))\<rbrakk> \<Longrightarrow> R" |
85 apply (cases "Y 0") |
85 apply (cases "Y 0") |
86 apply (rule A) |
86 apply (rule A) |
87 apply (rule ch2ch_monofun [OF monofun_inv_Inl Y]) |
87 apply (rule ch2ch_monofun [OF monofun_inv_Inl Y]) |
88 apply (rule ext) |
88 apply (rule ext) |
89 apply (cut_tac j=i in chain_mono [OF Y le0], simp) |
89 apply (cut_tac j=i in chain_mono [OF Y le0], simp) |
90 apply (erule Inl_lessE, simp) |
90 apply (erule Inl_belowE, simp) |
91 apply (rule B) |
91 apply (rule B) |
92 apply (rule ch2ch_monofun [OF monofun_inv_Inr Y]) |
92 apply (rule ch2ch_monofun [OF monofun_inv_Inr Y]) |
93 apply (rule ext) |
93 apply (rule ext) |
94 apply (cut_tac j=i in chain_mono [OF Y le0], simp) |
94 apply (cut_tac j=i in chain_mono [OF Y le0], simp) |
95 apply (erule Inr_lessE, simp) |
95 apply (erule Inr_belowE, simp) |
96 done |
96 done |
97 |
97 |
98 lemma is_lub_Inl: "range S <<| x \<Longrightarrow> range (\<lambda>i. Inl (S i)) <<| Inl x" |
98 lemma is_lub_Inl: "range S <<| x \<Longrightarrow> range (\<lambda>i. Inl (S i)) <<| Inl x" |
99 apply (rule is_lubI) |
99 apply (rule is_lubI) |
100 apply (rule ub_rangeI) |
100 apply (rule ub_rangeI) |
101 apply (simp add: is_ub_lub) |
101 apply (simp add: is_ub_lub) |
102 apply (frule ub_rangeD [where i=arbitrary]) |
102 apply (frule ub_rangeD [where i=arbitrary]) |
103 apply (erule Inl_lessE, simp) |
103 apply (erule Inl_belowE, simp) |
104 apply (erule is_lub_lub) |
104 apply (erule is_lub_lub) |
105 apply (rule ub_rangeI) |
105 apply (rule ub_rangeI) |
106 apply (drule ub_rangeD, simp) |
106 apply (drule ub_rangeD, simp) |
107 done |
107 done |
108 |
108 |
109 lemma is_lub_Inr: "range S <<| x \<Longrightarrow> range (\<lambda>i. Inr (S i)) <<| Inr x" |
109 lemma is_lub_Inr: "range S <<| x \<Longrightarrow> range (\<lambda>i. Inr (S i)) <<| Inr x" |
110 apply (rule is_lubI) |
110 apply (rule is_lubI) |
111 apply (rule ub_rangeI) |
111 apply (rule ub_rangeI) |
112 apply (simp add: is_ub_lub) |
112 apply (simp add: is_ub_lub) |
113 apply (frule ub_rangeD [where i=arbitrary]) |
113 apply (frule ub_rangeD [where i=arbitrary]) |
114 apply (erule Inr_lessE, simp) |
114 apply (erule Inr_belowE, simp) |
115 apply (erule is_lub_lub) |
115 apply (erule is_lub_lub) |
116 apply (rule ub_rangeI) |
116 apply (rule ub_rangeI) |
117 apply (drule ub_rangeD, simp) |
117 apply (drule ub_rangeD, simp) |
118 done |
118 done |
119 |
119 |