src/HOL/Library/List_lexord.thy
author haftmann
Thu Jun 26 10:07:01 2008 +0200 (2008-06-26)
changeset 27368 9f90ac19e32b
parent 25764 878c37886eed
child 27487 c8a6ce181805
permissions -rw-r--r--
established Plain theory and image
nipkow@15737
     1
(*  Title:      HOL/Library/List_lexord.thy
nipkow@15737
     2
    ID:         $Id$
nipkow@15737
     3
    Author:     Norbert Voelker
nipkow@15737
     4
*)
nipkow@15737
     5
wenzelm@17200
     6
header {* Lexicographic order on lists *}
nipkow@15737
     7
nipkow@15737
     8
theory List_lexord
haftmann@27368
     9
imports Plain List
nipkow@15737
    10
begin
nipkow@15737
    11
haftmann@25764
    12
instantiation list :: (ord) ord
haftmann@25764
    13
begin
haftmann@25764
    14
haftmann@25764
    15
definition
haftmann@25502
    16
  list_less_def [code func del]: "(xs::('a::ord) list) < ys \<longleftrightarrow> (xs, ys) \<in> lexord {(u,v). u < v}"
haftmann@25764
    17
haftmann@25764
    18
definition
haftmann@25764
    19
  list_le_def [code func del]: "(xs::('a::ord) list) \<le> ys \<longleftrightarrow> (xs < ys \<or> xs = ys)"
haftmann@25764
    20
haftmann@25764
    21
instance ..
haftmann@25764
    22
haftmann@25764
    23
end
nipkow@15737
    24
wenzelm@17200
    25
instance list :: (order) order
haftmann@25502
    26
  apply (intro_classes, unfold list_less_def list_le_def)
haftmann@22316
    27
  apply safe
nipkow@15737
    28
  apply (rule_tac r1 = "{(a::'a,b). a < b}" in lexord_irreflexive [THEN notE])
nipkow@15737
    29
  apply simp
wenzelm@17200
    30
  apply assumption
haftmann@22316
    31
  apply (blast intro: lexord_trans transI order_less_trans)
haftmann@22316
    32
  apply (rule_tac r1 = "{(a::'a,b). a < b}" in lexord_irreflexive [THEN notE])
haftmann@22316
    33
  apply simp
haftmann@22316
    34
  apply (blast intro: lexord_trans transI order_less_trans)
wenzelm@17200
    35
  done
nipkow@15737
    36
haftmann@21458
    37
instance list :: (linorder) linorder
nipkow@15737
    38
  apply (intro_classes, unfold list_le_def list_less_def, safe)
wenzelm@17200
    39
  apply (cut_tac x = x and y = y and  r = "{(a,b). a < b}"  in lexord_linear)
wenzelm@17200
    40
   apply force
wenzelm@17200
    41
  apply simp
wenzelm@17200
    42
  done
nipkow@15737
    43
haftmann@25764
    44
instantiation list :: (linorder) distrib_lattice
haftmann@25764
    45
begin
haftmann@25764
    46
haftmann@25764
    47
definition
haftmann@25502
    48
  [code func del]: "(inf \<Colon> 'a list \<Rightarrow> _) = min"
haftmann@25764
    49
haftmann@25764
    50
definition
haftmann@25502
    51
  [code func del]: "(sup \<Colon> 'a list \<Rightarrow> _) = max"
haftmann@25764
    52
haftmann@25764
    53
instance
haftmann@22483
    54
  by intro_classes
haftmann@22483
    55
    (auto simp add: inf_list_def sup_list_def min_max.sup_inf_distrib1)
haftmann@22483
    56
haftmann@25764
    57
end
haftmann@25764
    58
haftmann@22177
    59
lemma not_less_Nil [simp]: "\<not> (x < [])"
wenzelm@17200
    60
  by (unfold list_less_def) simp
nipkow@15737
    61
haftmann@22177
    62
lemma Nil_less_Cons [simp]: "[] < a # x"
wenzelm@17200
    63
  by (unfold list_less_def) simp
nipkow@15737
    64
haftmann@22177
    65
lemma Cons_less_Cons [simp]: "a # x < b # y \<longleftrightarrow> a < b \<or> a = b \<and> x < y"
wenzelm@17200
    66
  by (unfold list_less_def) simp
nipkow@15737
    67
haftmann@22177
    68
lemma le_Nil [simp]: "x \<le> [] \<longleftrightarrow> x = []"
haftmann@25502
    69
  by (unfold list_le_def, cases x) auto
haftmann@22177
    70
haftmann@22177
    71
lemma Nil_le_Cons [simp]: "[] \<le> x"
haftmann@25502
    72
  by (unfold list_le_def, cases x) auto
nipkow@15737
    73
haftmann@22177
    74
lemma Cons_le_Cons [simp]: "a # x \<le> b # y \<longleftrightarrow> a < b \<or> a = b \<and> x \<le> y"
haftmann@25502
    75
  by (unfold list_le_def) auto
nipkow@15737
    76
haftmann@22177
    77
lemma less_code [code func]:
haftmann@22177
    78
  "xs < ([]\<Colon>'a\<Colon>{eq, order} list) \<longleftrightarrow> False"
haftmann@22177
    79
  "[] < (x\<Colon>'a\<Colon>{eq, order}) # xs \<longleftrightarrow> True"
haftmann@22177
    80
  "(x\<Colon>'a\<Colon>{eq, order}) # xs < y # ys \<longleftrightarrow> x < y \<or> x = y \<and> xs < ys"
haftmann@22177
    81
  by simp_all
haftmann@22177
    82
haftmann@22177
    83
lemma less_eq_code [code func]:
haftmann@22177
    84
  "x # xs \<le> ([]\<Colon>'a\<Colon>{eq, order} list) \<longleftrightarrow> False"
haftmann@22177
    85
  "[] \<le> (xs\<Colon>'a\<Colon>{eq, order} list) \<longleftrightarrow> True"
haftmann@22177
    86
  "(x\<Colon>'a\<Colon>{eq, order}) # xs \<le> y # ys \<longleftrightarrow> x < y \<or> x = y \<and> xs \<le> ys"
haftmann@22177
    87
  by simp_all
haftmann@22177
    88
wenzelm@17200
    89
end