src/HOL/Library/List_lexord.thy
author haftmann
Thu Nov 29 17:08:26 2007 +0100 (2007-11-29)
changeset 25502 9200b36280c0
parent 22845 5f9138bcb3d7
child 25595 6c48275f9c76
permissions -rw-r--r--
instance command as rudimentary class target
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
nipkow@15737
     9
imports Main
nipkow@15737
    10
begin
nipkow@15737
    11
haftmann@21458
    12
instance list :: (ord) ord
haftmann@25502
    13
  list_less_def [code func del]: "(xs::('a::ord) list) < ys \<longleftrightarrow> (xs, ys) \<in> lexord {(u,v). u < v}"
haftmann@25502
    14
  list_le_def [code func del]: "(xs::('a::ord) list) \<le> ys \<longleftrightarrow> (xs < ys \<or> xs = ys)" ..
nipkow@15737
    15
wenzelm@17200
    16
instance list :: (order) order
haftmann@25502
    17
  apply (intro_classes, unfold list_less_def list_le_def)
haftmann@22316
    18
  apply safe
nipkow@15737
    19
  apply (rule_tac r1 = "{(a::'a,b). a < b}" in lexord_irreflexive [THEN notE])
nipkow@15737
    20
  apply simp
wenzelm@17200
    21
  apply assumption
haftmann@22316
    22
  apply (blast intro: lexord_trans transI order_less_trans)
haftmann@22316
    23
  apply (rule_tac r1 = "{(a::'a,b). a < b}" in lexord_irreflexive [THEN notE])
haftmann@22316
    24
  apply simp
haftmann@22316
    25
  apply (blast intro: lexord_trans transI order_less_trans)
wenzelm@17200
    26
  done
nipkow@15737
    27
haftmann@21458
    28
instance list :: (linorder) linorder
nipkow@15737
    29
  apply (intro_classes, unfold list_le_def list_less_def, safe)
wenzelm@17200
    30
  apply (cut_tac x = x and y = y and  r = "{(a,b). a < b}"  in lexord_linear)
wenzelm@17200
    31
   apply force
wenzelm@17200
    32
  apply simp
wenzelm@17200
    33
  done
nipkow@15737
    34
haftmann@22483
    35
instance list :: (linorder) distrib_lattice
haftmann@25502
    36
  [code func del]: "(inf \<Colon> 'a list \<Rightarrow> _) = min"
haftmann@25502
    37
  [code func del]: "(sup \<Colon> 'a list \<Rightarrow> _) = max"
haftmann@22483
    38
  by intro_classes
haftmann@22483
    39
    (auto simp add: inf_list_def sup_list_def min_max.sup_inf_distrib1)
haftmann@22483
    40
haftmann@22177
    41
lemma not_less_Nil [simp]: "\<not> (x < [])"
wenzelm@17200
    42
  by (unfold list_less_def) simp
nipkow@15737
    43
haftmann@22177
    44
lemma Nil_less_Cons [simp]: "[] < a # x"
wenzelm@17200
    45
  by (unfold list_less_def) simp
nipkow@15737
    46
haftmann@22177
    47
lemma Cons_less_Cons [simp]: "a # x < b # y \<longleftrightarrow> a < b \<or> a = b \<and> x < y"
wenzelm@17200
    48
  by (unfold list_less_def) simp
nipkow@15737
    49
haftmann@22177
    50
lemma le_Nil [simp]: "x \<le> [] \<longleftrightarrow> x = []"
haftmann@25502
    51
  by (unfold list_le_def, cases x) auto
haftmann@22177
    52
haftmann@22177
    53
lemma Nil_le_Cons [simp]: "[] \<le> x"
haftmann@25502
    54
  by (unfold list_le_def, cases x) auto
nipkow@15737
    55
haftmann@22177
    56
lemma Cons_le_Cons [simp]: "a # x \<le> b # y \<longleftrightarrow> a < b \<or> a = b \<and> x \<le> y"
haftmann@25502
    57
  by (unfold list_le_def) auto
nipkow@15737
    58
haftmann@22177
    59
lemma less_code [code func]:
haftmann@22177
    60
  "xs < ([]\<Colon>'a\<Colon>{eq, order} list) \<longleftrightarrow> False"
haftmann@22177
    61
  "[] < (x\<Colon>'a\<Colon>{eq, order}) # xs \<longleftrightarrow> True"
haftmann@22177
    62
  "(x\<Colon>'a\<Colon>{eq, order}) # xs < y # ys \<longleftrightarrow> x < y \<or> x = y \<and> xs < ys"
haftmann@22177
    63
  by simp_all
haftmann@22177
    64
haftmann@22177
    65
lemma less_eq_code [code func]:
haftmann@22177
    66
  "x # xs \<le> ([]\<Colon>'a\<Colon>{eq, order} list) \<longleftrightarrow> False"
haftmann@22177
    67
  "[] \<le> (xs\<Colon>'a\<Colon>{eq, order} list) \<longleftrightarrow> True"
haftmann@22177
    68
  "(x\<Colon>'a\<Colon>{eq, order}) # xs \<le> y # ys \<longleftrightarrow> x < y \<or> x = y \<and> xs \<le> ys"
haftmann@22177
    69
  by simp_all
haftmann@22177
    70
wenzelm@17200
    71
end