15737
|
1 |
(* Title: HOL/Library/List_lexord.thy
|
|
2 |
ID: $Id$
|
|
3 |
Author: Norbert Voelker
|
|
4 |
*)
|
|
5 |
|
17200
|
6 |
header {* Lexicographic order on lists *}
|
15737
|
7 |
|
|
8 |
theory List_lexord
|
|
9 |
imports Main
|
|
10 |
begin
|
|
11 |
|
21458
|
12 |
instance list :: (ord) ord
|
25502
|
13 |
list_less_def [code func del]: "(xs::('a::ord) list) < ys \<longleftrightarrow> (xs, ys) \<in> lexord {(u,v). u < v}"
|
|
14 |
list_le_def [code func del]: "(xs::('a::ord) list) \<le> ys \<longleftrightarrow> (xs < ys \<or> xs = ys)" ..
|
15737
|
15 |
|
17200
|
16 |
instance list :: (order) order
|
25502
|
17 |
apply (intro_classes, unfold list_less_def list_le_def)
|
22316
|
18 |
apply safe
|
15737
|
19 |
apply (rule_tac r1 = "{(a::'a,b). a < b}" in lexord_irreflexive [THEN notE])
|
|
20 |
apply simp
|
17200
|
21 |
apply assumption
|
22316
|
22 |
apply (blast intro: lexord_trans transI order_less_trans)
|
|
23 |
apply (rule_tac r1 = "{(a::'a,b). a < b}" in lexord_irreflexive [THEN notE])
|
|
24 |
apply simp
|
|
25 |
apply (blast intro: lexord_trans transI order_less_trans)
|
17200
|
26 |
done
|
15737
|
27 |
|
21458
|
28 |
instance list :: (linorder) linorder
|
15737
|
29 |
apply (intro_classes, unfold list_le_def list_less_def, safe)
|
17200
|
30 |
apply (cut_tac x = x and y = y and r = "{(a,b). a < b}" in lexord_linear)
|
|
31 |
apply force
|
|
32 |
apply simp
|
|
33 |
done
|
15737
|
34 |
|
22483
|
35 |
instance list :: (linorder) distrib_lattice
|
25502
|
36 |
[code func del]: "(inf \<Colon> 'a list \<Rightarrow> _) = min"
|
|
37 |
[code func del]: "(sup \<Colon> 'a list \<Rightarrow> _) = max"
|
22483
|
38 |
by intro_classes
|
|
39 |
(auto simp add: inf_list_def sup_list_def min_max.sup_inf_distrib1)
|
|
40 |
|
22177
|
41 |
lemma not_less_Nil [simp]: "\<not> (x < [])"
|
17200
|
42 |
by (unfold list_less_def) simp
|
15737
|
43 |
|
22177
|
44 |
lemma Nil_less_Cons [simp]: "[] < a # x"
|
17200
|
45 |
by (unfold list_less_def) simp
|
15737
|
46 |
|
22177
|
47 |
lemma Cons_less_Cons [simp]: "a # x < b # y \<longleftrightarrow> a < b \<or> a = b \<and> x < y"
|
17200
|
48 |
by (unfold list_less_def) simp
|
15737
|
49 |
|
22177
|
50 |
lemma le_Nil [simp]: "x \<le> [] \<longleftrightarrow> x = []"
|
25502
|
51 |
by (unfold list_le_def, cases x) auto
|
22177
|
52 |
|
|
53 |
lemma Nil_le_Cons [simp]: "[] \<le> x"
|
25502
|
54 |
by (unfold list_le_def, cases x) auto
|
15737
|
55 |
|
22177
|
56 |
lemma Cons_le_Cons [simp]: "a # x \<le> b # y \<longleftrightarrow> a < b \<or> a = b \<and> x \<le> y"
|
25502
|
57 |
by (unfold list_le_def) auto
|
15737
|
58 |
|
22177
|
59 |
lemma less_code [code func]:
|
|
60 |
"xs < ([]\<Colon>'a\<Colon>{eq, order} list) \<longleftrightarrow> False"
|
|
61 |
"[] < (x\<Colon>'a\<Colon>{eq, order}) # xs \<longleftrightarrow> True"
|
|
62 |
"(x\<Colon>'a\<Colon>{eq, order}) # xs < y # ys \<longleftrightarrow> x < y \<or> x = y \<and> xs < ys"
|
|
63 |
by simp_all
|
|
64 |
|
|
65 |
lemma less_eq_code [code func]:
|
|
66 |
"x # xs \<le> ([]\<Colon>'a\<Colon>{eq, order} list) \<longleftrightarrow> False"
|
|
67 |
"[] \<le> (xs\<Colon>'a\<Colon>{eq, order} list) \<longleftrightarrow> True"
|
|
68 |
"(x\<Colon>'a\<Colon>{eq, order}) # xs \<le> y # ys \<longleftrightarrow> x < y \<or> x = y \<and> xs \<le> ys"
|
|
69 |
by simp_all
|
|
70 |
|
17200
|
71 |
end
|