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