src/HOL/Library/List_lexord.thy
author haftmann
Thu Jan 25 09:32:36 2007 +0100 (2007-01-25)
changeset 22177 515021e98684
parent 21458 475b321982f7
child 22316 f662831459de
permissions -rw-r--r--
improved
     1 (*  Title:      HOL/Library/List_lexord.thy
     2     ID:         $Id$
     3     Author:     Norbert Voelker
     4 *)
     5 
     6 header {* Lexicographic order on lists *}
     7 
     8 theory List_lexord
     9 imports Main
    10 begin
    11 
    12 instance list :: (ord) ord
    13   list_le_def:  "(xs::('a::ord) list) \<le> ys \<equiv> (xs < ys \<or> xs = ys)"
    14   list_less_def: "(xs::('a::ord) list) < ys \<equiv> (xs, ys) \<in> lexord {(u,v). u < v}" ..
    15 
    16 lemmas list_ord_defs = list_less_def list_le_def
    17 
    18 instance list :: (order) order
    19   apply (intro_classes, unfold list_ord_defs)
    20      apply (rule disjI2, safe)
    21     apply (blast intro: lexord_trans transI order_less_trans)
    22    apply (rule_tac r1 = "{(a::'a,b). a < b}" in lexord_irreflexive [THEN notE])
    23     apply simp
    24    apply (blast intro: lexord_trans transI order_less_trans)
    25   apply (rule_tac r1 = "{(a::'a,b). a < b}" in lexord_irreflexive [THEN notE])
    26   apply simp
    27   apply assumption
    28   done
    29 
    30 instance list :: (linorder) linorder
    31   apply (intro_classes, unfold list_le_def list_less_def, safe)
    32   apply (cut_tac x = x and y = y and  r = "{(a,b). a < b}"  in lexord_linear)
    33    apply force
    34   apply simp
    35   done
    36 
    37 lemma not_less_Nil [simp]: "\<not> (x < [])"
    38   by (unfold list_less_def) simp
    39 
    40 lemma Nil_less_Cons [simp]: "[] < a # x"
    41   by (unfold list_less_def) simp
    42 
    43 lemma Cons_less_Cons [simp]: "a # x < b # y \<longleftrightarrow> a < b \<or> a = b \<and> x < y"
    44   by (unfold list_less_def) simp
    45 
    46 lemma le_Nil [simp]: "x \<le> [] \<longleftrightarrow> x = []"
    47   by (unfold list_ord_defs, cases x) auto
    48 
    49 lemma Nil_le_Cons [simp]: "[] \<le> x"
    50   by (unfold list_ord_defs, cases x) auto
    51 
    52 lemma Cons_le_Cons [simp]: "a # x \<le> b # y \<longleftrightarrow> a < b \<or> a = b \<and> x \<le> y"
    53   by (unfold list_ord_defs) auto
    54 
    55 lemma less_code [code func]:
    56   "xs < ([]\<Colon>'a\<Colon>{eq, order} list) \<longleftrightarrow> False"
    57   "[] < (x\<Colon>'a\<Colon>{eq, order}) # xs \<longleftrightarrow> True"
    58   "(x\<Colon>'a\<Colon>{eq, order}) # xs < y # ys \<longleftrightarrow> x < y \<or> x = y \<and> xs < ys"
    59   by simp_all
    60 
    61 lemma less_eq_code [code func]:
    62   "x # xs \<le> ([]\<Colon>'a\<Colon>{eq, order} list) \<longleftrightarrow> False"
    63   "[] \<le> (xs\<Colon>'a\<Colon>{eq, order} list) \<longleftrightarrow> True"
    64   "(x\<Colon>'a\<Colon>{eq, order}) # xs \<le> y # ys \<longleftrightarrow> x < y \<or> x = y \<and> xs \<le> ys"
    65   by simp_all
    66 
    67 end