src/HOL/Library/List_lexord.thy
author haftmann
Sun May 06 21:50:17 2007 +0200 (2007-05-06)
changeset 22845 5f9138bcb3d7
parent 22744 5cbe966d67a2
child 25502 9200b36280c0
permissions -rw-r--r--
changed code generator invocation syntax
     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 [code func del] = list_less_def list_le_def
    17 
    18 instance list :: (order) order
    19   apply (intro_classes, unfold list_ord_defs)
    20   apply safe
    21   apply (rule_tac r1 = "{(a::'a,b). a < b}" in lexord_irreflexive [THEN notE])
    22   apply simp
    23   apply assumption
    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 (blast intro: lexord_trans transI order_less_trans)
    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 instance list :: (linorder) distrib_lattice
    38   "inf \<equiv> min"
    39   "sup \<equiv> max"
    40   by intro_classes
    41     (auto simp add: inf_list_def sup_list_def min_max.sup_inf_distrib1)
    42 
    43 lemmas [code func del] = inf_list_def sup_list_def
    44 
    45 lemma not_less_Nil [simp]: "\<not> (x < [])"
    46   by (unfold list_less_def) simp
    47 
    48 lemma Nil_less_Cons [simp]: "[] < a # x"
    49   by (unfold list_less_def) simp
    50 
    51 lemma Cons_less_Cons [simp]: "a # x < b # y \<longleftrightarrow> a < b \<or> a = b \<and> x < y"
    52   by (unfold list_less_def) simp
    53 
    54 lemma le_Nil [simp]: "x \<le> [] \<longleftrightarrow> x = []"
    55   by (unfold list_ord_defs, cases x) auto
    56 
    57 lemma Nil_le_Cons [simp]: "[] \<le> x"
    58   by (unfold list_ord_defs, cases x) auto
    59 
    60 lemma Cons_le_Cons [simp]: "a # x \<le> b # y \<longleftrightarrow> a < b \<or> a = b \<and> x \<le> y"
    61   by (unfold list_ord_defs) auto
    62 
    63 lemma less_code [code func]:
    64   "xs < ([]\<Colon>'a\<Colon>{eq, order} list) \<longleftrightarrow> False"
    65   "[] < (x\<Colon>'a\<Colon>{eq, order}) # xs \<longleftrightarrow> True"
    66   "(x\<Colon>'a\<Colon>{eq, order}) # xs < y # ys \<longleftrightarrow> x < y \<or> x = y \<and> xs < ys"
    67   by simp_all
    68 
    69 lemma less_eq_code [code func]:
    70   "x # xs \<le> ([]\<Colon>'a\<Colon>{eq, order} list) \<longleftrightarrow> False"
    71   "[] \<le> (xs\<Colon>'a\<Colon>{eq, order} list) \<longleftrightarrow> True"
    72   "(x\<Colon>'a\<Colon>{eq, order}) # xs \<le> y # ys \<longleftrightarrow> x < y \<or> x = y \<and> xs \<le> ys"
    73   by simp_all
    74 
    75 end