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
     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_less_def [code func del]: "(xs::('a::ord) list) < ys \<longleftrightarrow> (xs, ys) \<in> lexord {(u,v). u < v}"
    14   list_le_def [code func del]: "(xs::('a::ord) list) \<le> ys \<longleftrightarrow> (xs < ys \<or> xs = ys)" ..
    15 
    16 instance list :: (order) order
    17   apply (intro_classes, unfold list_less_def list_le_def)
    18   apply safe
    19   apply (rule_tac r1 = "{(a::'a,b). a < b}" in lexord_irreflexive [THEN notE])
    20   apply simp
    21   apply assumption
    22   apply (blast intro: lexord_trans transI order_less_trans)
    23   apply (rule_tac r1 = "{(a::'a,b). a < b}" in lexord_irreflexive [THEN notE])
    24   apply simp
    25   apply (blast intro: lexord_trans transI order_less_trans)
    26   done
    27 
    28 instance list :: (linorder) linorder
    29   apply (intro_classes, unfold list_le_def list_less_def, safe)
    30   apply (cut_tac x = x and y = y and  r = "{(a,b). a < b}"  in lexord_linear)
    31    apply force
    32   apply simp
    33   done
    34 
    35 instance list :: (linorder) distrib_lattice
    36   [code func del]: "(inf \<Colon> 'a list \<Rightarrow> _) = min"
    37   [code func del]: "(sup \<Colon> 'a list \<Rightarrow> _) = max"
    38   by intro_classes
    39     (auto simp add: inf_list_def sup_list_def min_max.sup_inf_distrib1)
    40 
    41 lemma not_less_Nil [simp]: "\<not> (x < [])"
    42   by (unfold list_less_def) simp
    43 
    44 lemma Nil_less_Cons [simp]: "[] < a # x"
    45   by (unfold list_less_def) simp
    46 
    47 lemma Cons_less_Cons [simp]: "a # x < b # y \<longleftrightarrow> a < b \<or> a = b \<and> x < y"
    48   by (unfold list_less_def) simp
    49 
    50 lemma le_Nil [simp]: "x \<le> [] \<longleftrightarrow> x = []"
    51   by (unfold list_le_def, cases x) auto
    52 
    53 lemma Nil_le_Cons [simp]: "[] \<le> x"
    54   by (unfold list_le_def, cases x) auto
    55 
    56 lemma Cons_le_Cons [simp]: "a # x \<le> b # y \<longleftrightarrow> a < b \<or> a = b \<and> x \<le> y"
    57   by (unfold list_le_def) auto
    58 
    59 lemma less_code [code func]:
    60   "xs < ([]\<Colon>'a\<Colon>{eq, order} list) \<longleftrightarrow> False"
    61   "[] < (x\<Colon>'a\<Colon>{eq, order}) # xs \<longleftrightarrow> True"
    62   "(x\<Colon>'a\<Colon>{eq, order}) # xs < y # ys \<longleftrightarrow> x < y \<or> x = y \<and> xs < ys"
    63   by simp_all
    64 
    65 lemma less_eq_code [code func]:
    66   "x # xs \<le> ([]\<Colon>'a\<Colon>{eq, order} list) \<longleftrightarrow> False"
    67   "[] \<le> (xs\<Colon>'a\<Colon>{eq, order} list) \<longleftrightarrow> True"
    68   "(x\<Colon>'a\<Colon>{eq, order}) # xs \<le> y # ys \<longleftrightarrow> x < y \<or> x = y \<and> xs \<le> ys"
    69   by simp_all
    70 
    71 end