author  paulson <lp15@cam.ac.uk> 
Tue, 18 Aug 2020 14:44:59 +0100  
changeset 72166  bb37571139bf 
parent 71766  1249b998e377 
child 72169  2d7619fc0e1a 
permissions  rwrr 
68312  1 
(* Title: HOL/Library/List_Lexorder.thy 
15737  2 
Author: Norbert Voelker 
3 
*) 

4 

60500  5 
section \<open>Lexicographic order on lists\<close> 
15737  6 

68312  7 
theory List_Lexorder 
53214  8 
imports Main 
15737  9 
begin 
10 

25764  11 
instantiation list :: (ord) ord 
12 
begin 

13 

14 
definition 

37474  15 
list_less_def: "xs < ys \<longleftrightarrow> (xs, ys) \<in> lexord {(u, v). u < v}" 
25764  16 

17 
definition 

37474  18 
list_le_def: "(xs :: _ list) \<le> ys \<longleftrightarrow> xs < ys \<or> xs = ys" 
25764  19 

20 
instance .. 

21 

22 
end 

15737  23 

17200  24 
instance list :: (order) order 
27682  25 
proof 
71766
1249b998e377
New theory Library/List_Lenlexorder.thy, a type class instantiation for wellordering lists
paulson <lp15@cam.ac.uk>
parents:
68312
diff
changeset

26 
let ?r = "{(u, v::'a). u < v}" 
1249b998e377
New theory Library/List_Lenlexorder.thy, a type class instantiation for wellordering lists
paulson <lp15@cam.ac.uk>
parents:
68312
diff
changeset

27 
have tr: "trans ?r" 
1249b998e377
New theory Library/List_Lenlexorder.thy, a type class instantiation for wellordering lists
paulson <lp15@cam.ac.uk>
parents:
68312
diff
changeset

28 
using trans_def by fastforce 
72166
bb37571139bf
fixed for new lexorder. And the effing indentation!
paulson <lp15@cam.ac.uk>
parents:
71766
diff
changeset

29 
have *: "antisym {(u, v::'a). u < v}" 
bb37571139bf
fixed for new lexorder. And the effing indentation!
paulson <lp15@cam.ac.uk>
parents:
71766
diff
changeset

30 
using antisym_def by fastforce 
71766
1249b998e377
New theory Library/List_Lenlexorder.thy, a type class instantiation for wellordering lists
paulson <lp15@cam.ac.uk>
parents:
68312
diff
changeset

31 
have \<section>: False 
1249b998e377
New theory Library/List_Lenlexorder.thy, a type class instantiation for wellordering lists
paulson <lp15@cam.ac.uk>
parents:
68312
diff
changeset

32 
if "(xs,ys) \<in> lexord ?r" "(ys,xs) \<in> lexord ?r" for xs ys :: "'a list" 
1249b998e377
New theory Library/List_Lenlexorder.thy, a type class instantiation for wellordering lists
paulson <lp15@cam.ac.uk>
parents:
68312
diff
changeset

33 
proof  
1249b998e377
New theory Library/List_Lenlexorder.thy, a type class instantiation for wellordering lists
paulson <lp15@cam.ac.uk>
parents:
68312
diff
changeset

34 
have "(xs,xs) \<in> lexord ?r" 
72166
bb37571139bf
fixed for new lexorder. And the effing indentation!
paulson <lp15@cam.ac.uk>
parents:
71766
diff
changeset

35 
using lexord_trans that tr * by blast 
71766
1249b998e377
New theory Library/List_Lenlexorder.thy, a type class instantiation for wellordering lists
paulson <lp15@cam.ac.uk>
parents:
68312
diff
changeset

36 
then show False 
1249b998e377
New theory Library/List_Lenlexorder.thy, a type class instantiation for wellordering lists
paulson <lp15@cam.ac.uk>
parents:
68312
diff
changeset

37 
by (meson case_prodD lexord_irreflexive less_irrefl mem_Collect_eq) 
1249b998e377
New theory Library/List_Lenlexorder.thy, a type class instantiation for wellordering lists
paulson <lp15@cam.ac.uk>
parents:
68312
diff
changeset

38 
qed 
1249b998e377
New theory Library/List_Lenlexorder.thy, a type class instantiation for wellordering lists
paulson <lp15@cam.ac.uk>
parents:
68312
diff
changeset

39 
show "xs \<le> xs" for xs :: "'a list" by (simp add: list_le_def) 
1249b998e377
New theory Library/List_Lenlexorder.thy, a type class instantiation for wellordering lists
paulson <lp15@cam.ac.uk>
parents:
68312
diff
changeset

40 
show "xs \<le> zs" if "xs \<le> ys" and "ys \<le> zs" for xs ys zs :: "'a list" 
72166
bb37571139bf
fixed for new lexorder. And the effing indentation!
paulson <lp15@cam.ac.uk>
parents:
71766
diff
changeset

41 
using that transD [OF lexord_transI [OF tr]] * 
bb37571139bf
fixed for new lexorder. And the effing indentation!
paulson <lp15@cam.ac.uk>
parents:
71766
diff
changeset

42 
by (auto simp add: list_le_def list_less_def) 
71766
1249b998e377
New theory Library/List_Lenlexorder.thy, a type class instantiation for wellordering lists
paulson <lp15@cam.ac.uk>
parents:
68312
diff
changeset

43 
show "xs = ys" if "xs \<le> ys" "ys \<le> xs" for xs ys :: "'a list" 
1249b998e377
New theory Library/List_Lenlexorder.thy, a type class instantiation for wellordering lists
paulson <lp15@cam.ac.uk>
parents:
68312
diff
changeset

44 
using \<section> that list_le_def list_less_def by blast 
1249b998e377
New theory Library/List_Lenlexorder.thy, a type class instantiation for wellordering lists
paulson <lp15@cam.ac.uk>
parents:
68312
diff
changeset

45 
show "xs < ys \<longleftrightarrow> xs \<le> ys \<and> \<not> ys \<le> xs" for xs ys :: "'a list" 
1249b998e377
New theory Library/List_Lenlexorder.thy, a type class instantiation for wellordering lists
paulson <lp15@cam.ac.uk>
parents:
68312
diff
changeset

46 
by (auto simp add: list_less_def list_le_def dest: \<section>) 
27682  47 
qed 
15737  48 

21458  49 
instance list :: (linorder) linorder 
27682  50 
proof 
51 
fix xs ys :: "'a list" 

71766
1249b998e377
New theory Library/List_Lenlexorder.thy, a type class instantiation for wellordering lists
paulson <lp15@cam.ac.uk>
parents:
68312
diff
changeset

52 
have "total (lexord {(u, v::'a). u < v})" 
1249b998e377
New theory Library/List_Lenlexorder.thy, a type class instantiation for wellordering lists
paulson <lp15@cam.ac.uk>
parents:
68312
diff
changeset

53 
by (rule total_lexord) (auto simp: total_on_def) 
53214  54 
then show "xs \<le> ys \<or> ys \<le> xs" 
71766
1249b998e377
New theory Library/List_Lenlexorder.thy, a type class instantiation for wellordering lists
paulson <lp15@cam.ac.uk>
parents:
68312
diff
changeset

55 
by (auto simp add: total_on_def list_le_def list_less_def) 
27682  56 
qed 
15737  57 

25764  58 
instantiation list :: (linorder) distrib_lattice 
59 
begin 

60 

61076  61 
definition "(inf :: 'a list \<Rightarrow> _) = min" 
25764  62 

61076  63 
definition "(sup :: 'a list \<Rightarrow> _) = max" 
25764  64 

65 
instance 

60679  66 
by standard (auto simp add: inf_list_def sup_list_def max_min_distrib2) 
22483  67 

25764  68 
end 
69 

53214  70 
lemma not_less_Nil [simp]: "\<not> x < []" 
71 
by (simp add: list_less_def) 

15737  72 

22177  73 
lemma Nil_less_Cons [simp]: "[] < a # x" 
53214  74 
by (simp add: list_less_def) 
15737  75 

72166
bb37571139bf
fixed for new lexorder. And the effing indentation!
paulson <lp15@cam.ac.uk>
parents:
71766
diff
changeset

76 
lemma Cons_less_Cons [simp]: "a # x < b # y \<longleftrightarrow> (if a = b then x < y else a < b)" 
53214  77 
by (simp add: list_less_def) 
15737  78 

22177  79 
lemma le_Nil [simp]: "x \<le> [] \<longleftrightarrow> x = []" 
53214  80 
unfolding list_le_def by (cases x) auto 
22177  81 

82 
lemma Nil_le_Cons [simp]: "[] \<le> x" 

53214  83 
unfolding list_le_def by (cases x) auto 
15737  84 

22177  85 
lemma Cons_le_Cons [simp]: "a # x \<le> b # y \<longleftrightarrow> a < b \<or> a = b \<and> x \<le> y" 
53214  86 
unfolding list_le_def by auto 
15737  87 

52729
412c9e0381a1
factored syntactic type classes for bot and top (by Alessandro Coglio)
haftmann
parents:
38857
diff
changeset

88 
instantiation list :: (order) order_bot 
37474  89 
begin 
90 

53214  91 
definition "bot = []" 
37474  92 

53214  93 
instance 
60679  94 
by standard (simp add: bot_list_def) 
37474  95 

96 
end 

97 

98 
lemma less_list_code [code]: 

61076  99 
"xs < ([]::'a::{equal, order} list) \<longleftrightarrow> False" 
100 
"[] < (x::'a::{equal, order}) # xs \<longleftrightarrow> True" 

101 
"(x::'a::{equal, order}) # xs < y # ys \<longleftrightarrow> x < y \<or> x = y \<and> xs < ys" 

22177  102 
by simp_all 
103 

37474  104 
lemma less_eq_list_code [code]: 
61076  105 
"x # xs \<le> ([]::'a::{equal, order} list) \<longleftrightarrow> False" 
106 
"[] \<le> (xs::'a::{equal, order} list) \<longleftrightarrow> True" 

107 
"(x::'a::{equal, order}) # xs \<le> y # ys \<longleftrightarrow> x < y \<or> x = y \<and> xs \<le> ys" 

22177  108 
by simp_all 
109 

17200  110 
end 