src/HOL/Library/List_lexord.thy
author kuncar
Fri Dec 09 18:07:04 2011 +0100 (2011-12-09)
changeset 45802 b16f976db515
parent 38857 97775f3e8722
child 52729 412c9e0381a1
permissions -rw-r--r--
Quotient_Info stores only relation maps
nipkow@15737
     1
(*  Title:      HOL/Library/List_lexord.thy
nipkow@15737
     2
    Author:     Norbert Voelker
nipkow@15737
     3
*)
nipkow@15737
     4
wenzelm@17200
     5
header {* Lexicographic order on lists *}
nipkow@15737
     6
nipkow@15737
     7
theory List_lexord
haftmann@30663
     8
imports List Main
nipkow@15737
     9
begin
nipkow@15737
    10
haftmann@25764
    11
instantiation list :: (ord) ord
haftmann@25764
    12
begin
haftmann@25764
    13
haftmann@25764
    14
definition
haftmann@37474
    15
  list_less_def: "xs < ys \<longleftrightarrow> (xs, ys) \<in> lexord {(u, v). u < v}"
haftmann@25764
    16
haftmann@25764
    17
definition
haftmann@37474
    18
  list_le_def: "(xs :: _ list) \<le> ys \<longleftrightarrow> xs < ys \<or> xs = ys"
haftmann@25764
    19
haftmann@25764
    20
instance ..
haftmann@25764
    21
haftmann@25764
    22
end
nipkow@15737
    23
wenzelm@17200
    24
instance list :: (order) order
haftmann@27682
    25
proof
haftmann@27682
    26
  fix xs :: "'a list"
haftmann@27682
    27
  show "xs \<le> xs" by (simp add: list_le_def)
haftmann@27682
    28
next
haftmann@27682
    29
  fix xs ys zs :: "'a list"
haftmann@27682
    30
  assume "xs \<le> ys" and "ys \<le> zs"
haftmann@27682
    31
  then show "xs \<le> zs" by (auto simp add: list_le_def list_less_def)
haftmann@27682
    32
    (rule lexord_trans, auto intro: transI)
haftmann@27682
    33
next
haftmann@27682
    34
  fix xs ys :: "'a list"
haftmann@27682
    35
  assume "xs \<le> ys" and "ys \<le> xs"
haftmann@27682
    36
  then show "xs = ys" apply (auto simp add: list_le_def list_less_def)
haftmann@27682
    37
  apply (rule lexord_irreflexive [THEN notE])
haftmann@27682
    38
  defer
haftmann@27682
    39
  apply (rule lexord_trans) apply (auto intro: transI) done
haftmann@27682
    40
next
haftmann@27682
    41
  fix xs ys :: "'a list"
haftmann@27682
    42
  show "xs < ys \<longleftrightarrow> xs \<le> ys \<and> \<not> ys \<le> xs" 
haftmann@27682
    43
  apply (auto simp add: list_less_def list_le_def)
haftmann@27682
    44
  defer
haftmann@27682
    45
  apply (rule lexord_irreflexive [THEN notE])
haftmann@27682
    46
  apply auto
haftmann@27682
    47
  apply (rule lexord_irreflexive [THEN notE])
haftmann@27682
    48
  defer
haftmann@27682
    49
  apply (rule lexord_trans) apply (auto intro: transI) done
haftmann@27682
    50
qed
nipkow@15737
    51
haftmann@21458
    52
instance list :: (linorder) linorder
haftmann@27682
    53
proof
haftmann@27682
    54
  fix xs ys :: "'a list"
haftmann@27682
    55
  have "(xs, ys) \<in> lexord {(u, v). u < v} \<or> xs = ys \<or> (ys, xs) \<in> lexord {(u, v). u < v}"
haftmann@27682
    56
    by (rule lexord_linear) auto
haftmann@27682
    57
  then show "xs \<le> ys \<or> ys \<le> xs" 
haftmann@27682
    58
    by (auto simp add: list_le_def list_less_def)
haftmann@27682
    59
qed
nipkow@15737
    60
haftmann@25764
    61
instantiation list :: (linorder) distrib_lattice
haftmann@25764
    62
begin
haftmann@25764
    63
haftmann@25764
    64
definition
haftmann@37765
    65
  "(inf \<Colon> 'a list \<Rightarrow> _) = min"
haftmann@25764
    66
haftmann@25764
    67
definition
haftmann@37765
    68
  "(sup \<Colon> 'a list \<Rightarrow> _) = max"
haftmann@25764
    69
haftmann@25764
    70
instance
haftmann@22483
    71
  by intro_classes
haftmann@22483
    72
    (auto simp add: inf_list_def sup_list_def min_max.sup_inf_distrib1)
haftmann@22483
    73
haftmann@25764
    74
end
haftmann@25764
    75
haftmann@22177
    76
lemma not_less_Nil [simp]: "\<not> (x < [])"
wenzelm@17200
    77
  by (unfold list_less_def) simp
nipkow@15737
    78
haftmann@22177
    79
lemma Nil_less_Cons [simp]: "[] < a # x"
wenzelm@17200
    80
  by (unfold list_less_def) simp
nipkow@15737
    81
haftmann@22177
    82
lemma Cons_less_Cons [simp]: "a # x < b # y \<longleftrightarrow> a < b \<or> a = b \<and> x < y"
wenzelm@17200
    83
  by (unfold list_less_def) simp
nipkow@15737
    84
haftmann@22177
    85
lemma le_Nil [simp]: "x \<le> [] \<longleftrightarrow> x = []"
haftmann@25502
    86
  by (unfold list_le_def, cases x) auto
haftmann@22177
    87
haftmann@22177
    88
lemma Nil_le_Cons [simp]: "[] \<le> x"
haftmann@25502
    89
  by (unfold list_le_def, cases x) auto
nipkow@15737
    90
haftmann@22177
    91
lemma Cons_le_Cons [simp]: "a # x \<le> b # y \<longleftrightarrow> a < b \<or> a = b \<and> x \<le> y"
haftmann@25502
    92
  by (unfold list_le_def) auto
nipkow@15737
    93
haftmann@37474
    94
instantiation list :: (order) bot
haftmann@37474
    95
begin
haftmann@37474
    96
haftmann@37474
    97
definition
haftmann@37474
    98
  "bot = []"
haftmann@37474
    99
haftmann@37474
   100
instance proof
haftmann@37474
   101
qed (simp add: bot_list_def)
haftmann@37474
   102
haftmann@37474
   103
end
haftmann@37474
   104
haftmann@37474
   105
lemma less_list_code [code]:
haftmann@38857
   106
  "xs < ([]\<Colon>'a\<Colon>{equal, order} list) \<longleftrightarrow> False"
haftmann@38857
   107
  "[] < (x\<Colon>'a\<Colon>{equal, order}) # xs \<longleftrightarrow> True"
haftmann@38857
   108
  "(x\<Colon>'a\<Colon>{equal, order}) # xs < y # ys \<longleftrightarrow> x < y \<or> x = y \<and> xs < ys"
haftmann@22177
   109
  by simp_all
haftmann@22177
   110
haftmann@37474
   111
lemma less_eq_list_code [code]:
haftmann@38857
   112
  "x # xs \<le> ([]\<Colon>'a\<Colon>{equal, order} list) \<longleftrightarrow> False"
haftmann@38857
   113
  "[] \<le> (xs\<Colon>'a\<Colon>{equal, order} list) \<longleftrightarrow> True"
haftmann@38857
   114
  "(x\<Colon>'a\<Colon>{equal, order}) # xs \<le> y # ys \<longleftrightarrow> x < y \<or> x = y \<and> xs \<le> ys"
haftmann@22177
   115
  by simp_all
haftmann@22177
   116
wenzelm@17200
   117
end