author | paulson <lp15@cam.ac.uk> |
Fri, 21 Aug 2020 12:42:57 +0100 | |
changeset 72184 | 881bd98bddee |
parent 72164 | b7c54ff7f2dd |
child 75716 | f6695e7aff32 |
permissions | -rw-r--r-- |
71766
1249b998e377
New theory Library/List_Lenlexorder.thy, a type class instantiation for well-ordering lists
paulson <lp15@cam.ac.uk>
parents:
diff
changeset
|
1 |
(* Title: HOL/Library/List_Lenlexorder.thy |
1249b998e377
New theory Library/List_Lenlexorder.thy, a type class instantiation for well-ordering lists
paulson <lp15@cam.ac.uk>
parents:
diff
changeset
|
2 |
*) |
1249b998e377
New theory Library/List_Lenlexorder.thy, a type class instantiation for well-ordering lists
paulson <lp15@cam.ac.uk>
parents:
diff
changeset
|
3 |
|
1249b998e377
New theory Library/List_Lenlexorder.thy, a type class instantiation for well-ordering lists
paulson <lp15@cam.ac.uk>
parents:
diff
changeset
|
4 |
section \<open>Lexicographic order on lists\<close> |
1249b998e377
New theory Library/List_Lenlexorder.thy, a type class instantiation for well-ordering lists
paulson <lp15@cam.ac.uk>
parents:
diff
changeset
|
5 |
|
1249b998e377
New theory Library/List_Lenlexorder.thy, a type class instantiation for well-ordering lists
paulson <lp15@cam.ac.uk>
parents:
diff
changeset
|
6 |
theory List_Lenlexorder |
1249b998e377
New theory Library/List_Lenlexorder.thy, a type class instantiation for well-ordering lists
paulson <lp15@cam.ac.uk>
parents:
diff
changeset
|
7 |
imports Main |
1249b998e377
New theory Library/List_Lenlexorder.thy, a type class instantiation for well-ordering lists
paulson <lp15@cam.ac.uk>
parents:
diff
changeset
|
8 |
begin |
1249b998e377
New theory Library/List_Lenlexorder.thy, a type class instantiation for well-ordering lists
paulson <lp15@cam.ac.uk>
parents:
diff
changeset
|
9 |
|
1249b998e377
New theory Library/List_Lenlexorder.thy, a type class instantiation for well-ordering lists
paulson <lp15@cam.ac.uk>
parents:
diff
changeset
|
10 |
|
1249b998e377
New theory Library/List_Lenlexorder.thy, a type class instantiation for well-ordering lists
paulson <lp15@cam.ac.uk>
parents:
diff
changeset
|
11 |
instantiation list :: (ord) ord |
1249b998e377
New theory Library/List_Lenlexorder.thy, a type class instantiation for well-ordering lists
paulson <lp15@cam.ac.uk>
parents:
diff
changeset
|
12 |
begin |
1249b998e377
New theory Library/List_Lenlexorder.thy, a type class instantiation for well-ordering lists
paulson <lp15@cam.ac.uk>
parents:
diff
changeset
|
13 |
|
1249b998e377
New theory Library/List_Lenlexorder.thy, a type class instantiation for well-ordering lists
paulson <lp15@cam.ac.uk>
parents:
diff
changeset
|
14 |
definition |
1249b998e377
New theory Library/List_Lenlexorder.thy, a type class instantiation for well-ordering lists
paulson <lp15@cam.ac.uk>
parents:
diff
changeset
|
15 |
list_less_def: "xs < ys \<longleftrightarrow> (xs, ys) \<in> lenlex {(u, v). u < v}" |
1249b998e377
New theory Library/List_Lenlexorder.thy, a type class instantiation for well-ordering lists
paulson <lp15@cam.ac.uk>
parents:
diff
changeset
|
16 |
|
1249b998e377
New theory Library/List_Lenlexorder.thy, a type class instantiation for well-ordering lists
paulson <lp15@cam.ac.uk>
parents:
diff
changeset
|
17 |
definition |
1249b998e377
New theory Library/List_Lenlexorder.thy, a type class instantiation for well-ordering lists
paulson <lp15@cam.ac.uk>
parents:
diff
changeset
|
18 |
list_le_def: "(xs :: _ list) \<le> ys \<longleftrightarrow> xs < ys \<or> xs = ys" |
1249b998e377
New theory Library/List_Lenlexorder.thy, a type class instantiation for well-ordering lists
paulson <lp15@cam.ac.uk>
parents:
diff
changeset
|
19 |
|
1249b998e377
New theory Library/List_Lenlexorder.thy, a type class instantiation for well-ordering lists
paulson <lp15@cam.ac.uk>
parents:
diff
changeset
|
20 |
instance .. |
1249b998e377
New theory Library/List_Lenlexorder.thy, a type class instantiation for well-ordering lists
paulson <lp15@cam.ac.uk>
parents:
diff
changeset
|
21 |
|
1249b998e377
New theory Library/List_Lenlexorder.thy, a type class instantiation for well-ordering lists
paulson <lp15@cam.ac.uk>
parents:
diff
changeset
|
22 |
end |
1249b998e377
New theory Library/List_Lenlexorder.thy, a type class instantiation for well-ordering lists
paulson <lp15@cam.ac.uk>
parents:
diff
changeset
|
23 |
|
1249b998e377
New theory Library/List_Lenlexorder.thy, a type class instantiation for well-ordering lists
paulson <lp15@cam.ac.uk>
parents:
diff
changeset
|
24 |
instance list :: (order) order |
1249b998e377
New theory Library/List_Lenlexorder.thy, a type class instantiation for well-ordering lists
paulson <lp15@cam.ac.uk>
parents:
diff
changeset
|
25 |
proof |
1249b998e377
New theory Library/List_Lenlexorder.thy, a type class instantiation for well-ordering lists
paulson <lp15@cam.ac.uk>
parents:
diff
changeset
|
26 |
have tr: "trans {(u, v::'a). u < v}" |
1249b998e377
New theory Library/List_Lenlexorder.thy, a type class instantiation for well-ordering lists
paulson <lp15@cam.ac.uk>
parents:
diff
changeset
|
27 |
using trans_def by fastforce |
1249b998e377
New theory Library/List_Lenlexorder.thy, a type class instantiation for well-ordering lists
paulson <lp15@cam.ac.uk>
parents:
diff
changeset
|
28 |
have \<section>: False |
1249b998e377
New theory Library/List_Lenlexorder.thy, a type class instantiation for well-ordering lists
paulson <lp15@cam.ac.uk>
parents:
diff
changeset
|
29 |
if "(xs,ys) \<in> lenlex {(u, v). u < v}" "(ys,xs) \<in> lenlex {(u, v). u < v}" for xs ys :: "'a list" |
1249b998e377
New theory Library/List_Lenlexorder.thy, a type class instantiation for well-ordering lists
paulson <lp15@cam.ac.uk>
parents:
diff
changeset
|
30 |
proof - |
1249b998e377
New theory Library/List_Lenlexorder.thy, a type class instantiation for well-ordering lists
paulson <lp15@cam.ac.uk>
parents:
diff
changeset
|
31 |
have "(xs,xs) \<in> lenlex {(u, v). u < v}" |
72184 | 32 |
using that transD [OF lenlex_transI [OF tr]] by blast |
71766
1249b998e377
New theory Library/List_Lenlexorder.thy, a type class instantiation for well-ordering lists
paulson <lp15@cam.ac.uk>
parents:
diff
changeset
|
33 |
then show False |
1249b998e377
New theory Library/List_Lenlexorder.thy, a type class instantiation for well-ordering lists
paulson <lp15@cam.ac.uk>
parents:
diff
changeset
|
34 |
by (meson case_prodD lenlex_irreflexive less_irrefl mem_Collect_eq) |
1249b998e377
New theory Library/List_Lenlexorder.thy, a type class instantiation for well-ordering lists
paulson <lp15@cam.ac.uk>
parents:
diff
changeset
|
35 |
qed |
1249b998e377
New theory Library/List_Lenlexorder.thy, a type class instantiation for well-ordering lists
paulson <lp15@cam.ac.uk>
parents:
diff
changeset
|
36 |
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 well-ordering lists
paulson <lp15@cam.ac.uk>
parents:
diff
changeset
|
37 |
show "xs \<le> zs" if "xs \<le> ys" and "ys \<le> zs" for xs ys zs :: "'a list" |
72184 | 38 |
using that transD [OF lenlex_transI [OF tr]] by (auto simp add: list_le_def list_less_def) |
71766
1249b998e377
New theory Library/List_Lenlexorder.thy, a type class instantiation for well-ordering lists
paulson <lp15@cam.ac.uk>
parents:
diff
changeset
|
39 |
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 well-ordering lists
paulson <lp15@cam.ac.uk>
parents:
diff
changeset
|
40 |
using \<section> that list_le_def list_less_def by blast |
1249b998e377
New theory Library/List_Lenlexorder.thy, a type class instantiation for well-ordering lists
paulson <lp15@cam.ac.uk>
parents:
diff
changeset
|
41 |
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 well-ordering lists
paulson <lp15@cam.ac.uk>
parents:
diff
changeset
|
42 |
by (auto simp add: list_less_def list_le_def dest: \<section>) |
1249b998e377
New theory Library/List_Lenlexorder.thy, a type class instantiation for well-ordering lists
paulson <lp15@cam.ac.uk>
parents:
diff
changeset
|
43 |
qed |
1249b998e377
New theory Library/List_Lenlexorder.thy, a type class instantiation for well-ordering lists
paulson <lp15@cam.ac.uk>
parents:
diff
changeset
|
44 |
|
1249b998e377
New theory Library/List_Lenlexorder.thy, a type class instantiation for well-ordering lists
paulson <lp15@cam.ac.uk>
parents:
diff
changeset
|
45 |
instance list :: (linorder) linorder |
1249b998e377
New theory Library/List_Lenlexorder.thy, a type class instantiation for well-ordering lists
paulson <lp15@cam.ac.uk>
parents:
diff
changeset
|
46 |
proof |
1249b998e377
New theory Library/List_Lenlexorder.thy, a type class instantiation for well-ordering lists
paulson <lp15@cam.ac.uk>
parents:
diff
changeset
|
47 |
fix xs ys :: "'a list" |
1249b998e377
New theory Library/List_Lenlexorder.thy, a type class instantiation for well-ordering lists
paulson <lp15@cam.ac.uk>
parents:
diff
changeset
|
48 |
have "total (lenlex {(u, v::'a). u < v})" |
1249b998e377
New theory Library/List_Lenlexorder.thy, a type class instantiation for well-ordering lists
paulson <lp15@cam.ac.uk>
parents:
diff
changeset
|
49 |
by (rule total_lenlex) (auto simp: total_on_def) |
1249b998e377
New theory Library/List_Lenlexorder.thy, a type class instantiation for well-ordering lists
paulson <lp15@cam.ac.uk>
parents:
diff
changeset
|
50 |
then show "xs \<le> ys \<or> ys \<le> xs" |
1249b998e377
New theory Library/List_Lenlexorder.thy, a type class instantiation for well-ordering lists
paulson <lp15@cam.ac.uk>
parents:
diff
changeset
|
51 |
by (auto simp add: total_on_def list_le_def list_less_def) |
1249b998e377
New theory Library/List_Lenlexorder.thy, a type class instantiation for well-ordering lists
paulson <lp15@cam.ac.uk>
parents:
diff
changeset
|
52 |
qed |
1249b998e377
New theory Library/List_Lenlexorder.thy, a type class instantiation for well-ordering lists
paulson <lp15@cam.ac.uk>
parents:
diff
changeset
|
53 |
|
1249b998e377
New theory Library/List_Lenlexorder.thy, a type class instantiation for well-ordering lists
paulson <lp15@cam.ac.uk>
parents:
diff
changeset
|
54 |
instantiation list :: (linorder) distrib_lattice |
1249b998e377
New theory Library/List_Lenlexorder.thy, a type class instantiation for well-ordering lists
paulson <lp15@cam.ac.uk>
parents:
diff
changeset
|
55 |
begin |
1249b998e377
New theory Library/List_Lenlexorder.thy, a type class instantiation for well-ordering lists
paulson <lp15@cam.ac.uk>
parents:
diff
changeset
|
56 |
|
1249b998e377
New theory Library/List_Lenlexorder.thy, a type class instantiation for well-ordering lists
paulson <lp15@cam.ac.uk>
parents:
diff
changeset
|
57 |
definition "(inf :: 'a list \<Rightarrow> _) = min" |
1249b998e377
New theory Library/List_Lenlexorder.thy, a type class instantiation for well-ordering lists
paulson <lp15@cam.ac.uk>
parents:
diff
changeset
|
58 |
|
1249b998e377
New theory Library/List_Lenlexorder.thy, a type class instantiation for well-ordering lists
paulson <lp15@cam.ac.uk>
parents:
diff
changeset
|
59 |
definition "(sup :: 'a list \<Rightarrow> _) = max" |
1249b998e377
New theory Library/List_Lenlexorder.thy, a type class instantiation for well-ordering lists
paulson <lp15@cam.ac.uk>
parents:
diff
changeset
|
60 |
|
1249b998e377
New theory Library/List_Lenlexorder.thy, a type class instantiation for well-ordering lists
paulson <lp15@cam.ac.uk>
parents:
diff
changeset
|
61 |
instance |
1249b998e377
New theory Library/List_Lenlexorder.thy, a type class instantiation for well-ordering lists
paulson <lp15@cam.ac.uk>
parents:
diff
changeset
|
62 |
by standard (auto simp add: inf_list_def sup_list_def max_min_distrib2) |
1249b998e377
New theory Library/List_Lenlexorder.thy, a type class instantiation for well-ordering lists
paulson <lp15@cam.ac.uk>
parents:
diff
changeset
|
63 |
|
1249b998e377
New theory Library/List_Lenlexorder.thy, a type class instantiation for well-ordering lists
paulson <lp15@cam.ac.uk>
parents:
diff
changeset
|
64 |
end |
1249b998e377
New theory Library/List_Lenlexorder.thy, a type class instantiation for well-ordering lists
paulson <lp15@cam.ac.uk>
parents:
diff
changeset
|
65 |
|
1249b998e377
New theory Library/List_Lenlexorder.thy, a type class instantiation for well-ordering lists
paulson <lp15@cam.ac.uk>
parents:
diff
changeset
|
66 |
lemma not_less_Nil [simp]: "\<not> x < []" |
1249b998e377
New theory Library/List_Lenlexorder.thy, a type class instantiation for well-ordering lists
paulson <lp15@cam.ac.uk>
parents:
diff
changeset
|
67 |
by (simp add: list_less_def) |
1249b998e377
New theory Library/List_Lenlexorder.thy, a type class instantiation for well-ordering lists
paulson <lp15@cam.ac.uk>
parents:
diff
changeset
|
68 |
|
1249b998e377
New theory Library/List_Lenlexorder.thy, a type class instantiation for well-ordering lists
paulson <lp15@cam.ac.uk>
parents:
diff
changeset
|
69 |
lemma Nil_less_Cons [simp]: "[] < a # x" |
1249b998e377
New theory Library/List_Lenlexorder.thy, a type class instantiation for well-ordering lists
paulson <lp15@cam.ac.uk>
parents:
diff
changeset
|
70 |
by (simp add: list_less_def) |
1249b998e377
New theory Library/List_Lenlexorder.thy, a type class instantiation for well-ordering lists
paulson <lp15@cam.ac.uk>
parents:
diff
changeset
|
71 |
|
72184 | 72 |
lemma Cons_less_Cons: "a # x < b # y \<longleftrightarrow> length x < length y \<or> length x = length y \<and> (a < b \<or> a = b \<and> x < y)" |
73 |
using lenlex_length |
|
74 |
by (fastforce simp: list_less_def Cons_lenlex_iff) |
|
75 |
||
71766
1249b998e377
New theory Library/List_Lenlexorder.thy, a type class instantiation for well-ordering lists
paulson <lp15@cam.ac.uk>
parents:
diff
changeset
|
76 |
lemma le_Nil [simp]: "x \<le> [] \<longleftrightarrow> x = []" |
1249b998e377
New theory Library/List_Lenlexorder.thy, a type class instantiation for well-ordering lists
paulson <lp15@cam.ac.uk>
parents:
diff
changeset
|
77 |
unfolding list_le_def by (cases x) auto |
1249b998e377
New theory Library/List_Lenlexorder.thy, a type class instantiation for well-ordering lists
paulson <lp15@cam.ac.uk>
parents:
diff
changeset
|
78 |
|
1249b998e377
New theory Library/List_Lenlexorder.thy, a type class instantiation for well-ordering lists
paulson <lp15@cam.ac.uk>
parents:
diff
changeset
|
79 |
lemma Nil_le_Cons [simp]: "[] \<le> x" |
1249b998e377
New theory Library/List_Lenlexorder.thy, a type class instantiation for well-ordering lists
paulson <lp15@cam.ac.uk>
parents:
diff
changeset
|
80 |
unfolding list_le_def by (cases x) auto |
1249b998e377
New theory Library/List_Lenlexorder.thy, a type class instantiation for well-ordering lists
paulson <lp15@cam.ac.uk>
parents:
diff
changeset
|
81 |
|
72184 | 82 |
lemma Cons_le_Cons: "a # x \<le> b # y \<longleftrightarrow> length x < length y \<or> length x = length y \<and> (a < b \<or> a = b \<and> x \<le> y)" |
83 |
by (auto simp: list_le_def Cons_less_Cons) |
|
84 |
||
71766
1249b998e377
New theory Library/List_Lenlexorder.thy, a type class instantiation for well-ordering lists
paulson <lp15@cam.ac.uk>
parents:
diff
changeset
|
85 |
instantiation list :: (order) order_bot |
1249b998e377
New theory Library/List_Lenlexorder.thy, a type class instantiation for well-ordering lists
paulson <lp15@cam.ac.uk>
parents:
diff
changeset
|
86 |
begin |
1249b998e377
New theory Library/List_Lenlexorder.thy, a type class instantiation for well-ordering lists
paulson <lp15@cam.ac.uk>
parents:
diff
changeset
|
87 |
|
1249b998e377
New theory Library/List_Lenlexorder.thy, a type class instantiation for well-ordering lists
paulson <lp15@cam.ac.uk>
parents:
diff
changeset
|
88 |
definition "bot = []" |
1249b998e377
New theory Library/List_Lenlexorder.thy, a type class instantiation for well-ordering lists
paulson <lp15@cam.ac.uk>
parents:
diff
changeset
|
89 |
|
1249b998e377
New theory Library/List_Lenlexorder.thy, a type class instantiation for well-ordering lists
paulson <lp15@cam.ac.uk>
parents:
diff
changeset
|
90 |
instance |
1249b998e377
New theory Library/List_Lenlexorder.thy, a type class instantiation for well-ordering lists
paulson <lp15@cam.ac.uk>
parents:
diff
changeset
|
91 |
by standard (simp add: bot_list_def) |
1249b998e377
New theory Library/List_Lenlexorder.thy, a type class instantiation for well-ordering lists
paulson <lp15@cam.ac.uk>
parents:
diff
changeset
|
92 |
|
1249b998e377
New theory Library/List_Lenlexorder.thy, a type class instantiation for well-ordering lists
paulson <lp15@cam.ac.uk>
parents:
diff
changeset
|
93 |
end |
1249b998e377
New theory Library/List_Lenlexorder.thy, a type class instantiation for well-ordering lists
paulson <lp15@cam.ac.uk>
parents:
diff
changeset
|
94 |
|
1249b998e377
New theory Library/List_Lenlexorder.thy, a type class instantiation for well-ordering lists
paulson <lp15@cam.ac.uk>
parents:
diff
changeset
|
95 |
end |