src/HOL/Library/List_lexord.thy
author haftmann
Fri Jul 25 12:03:34 2008 +0200 (2008-07-25)
changeset 27682 25aceefd4786
parent 27487 c8a6ce181805
child 28562 4e74209f113e
permissions -rw-r--r--
added class preorder
     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 Plain "~~/src/HOL/List"
    10 begin
    11 
    12 instantiation list :: (ord) ord
    13 begin
    14 
    15 definition
    16   list_less_def [code func del]: "(xs::('a::ord) list) < ys \<longleftrightarrow> (xs, ys) \<in> lexord {(u,v). u < v}"
    17 
    18 definition
    19   list_le_def [code func del]: "(xs::('a::ord) list) \<le> ys \<longleftrightarrow> (xs < ys \<or> xs = ys)"
    20 
    21 instance ..
    22 
    23 end
    24 
    25 instance list :: (order) order
    26 proof
    27   fix xs :: "'a list"
    28   show "xs \<le> xs" by (simp add: list_le_def)
    29 next
    30   fix xs ys zs :: "'a list"
    31   assume "xs \<le> ys" and "ys \<le> zs"
    32   then show "xs \<le> zs" by (auto simp add: list_le_def list_less_def)
    33     (rule lexord_trans, auto intro: transI)
    34 next
    35   fix xs ys :: "'a list"
    36   assume "xs \<le> ys" and "ys \<le> xs"
    37   then show "xs = ys" apply (auto simp add: list_le_def list_less_def)
    38   apply (rule lexord_irreflexive [THEN notE])
    39   defer
    40   apply (rule lexord_trans) apply (auto intro: transI) done
    41 next
    42   fix xs ys :: "'a list"
    43   show "xs < ys \<longleftrightarrow> xs \<le> ys \<and> \<not> ys \<le> xs" 
    44   apply (auto simp add: list_less_def list_le_def)
    45   defer
    46   apply (rule lexord_irreflexive [THEN notE])
    47   apply auto
    48   apply (rule lexord_irreflexive [THEN notE])
    49   defer
    50   apply (rule lexord_trans) apply (auto intro: transI) done
    51 qed
    52 
    53 instance list :: (linorder) linorder
    54 proof
    55   fix xs ys :: "'a list"
    56   have "(xs, ys) \<in> lexord {(u, v). u < v} \<or> xs = ys \<or> (ys, xs) \<in> lexord {(u, v). u < v}"
    57     by (rule lexord_linear) auto
    58   then show "xs \<le> ys \<or> ys \<le> xs" 
    59     by (auto simp add: list_le_def list_less_def)
    60 qed
    61 
    62 instantiation list :: (linorder) distrib_lattice
    63 begin
    64 
    65 definition
    66   [code func del]: "(inf \<Colon> 'a list \<Rightarrow> _) = min"
    67 
    68 definition
    69   [code func del]: "(sup \<Colon> 'a list \<Rightarrow> _) = max"
    70 
    71 instance
    72   by intro_classes
    73     (auto simp add: inf_list_def sup_list_def min_max.sup_inf_distrib1)
    74 
    75 end
    76 
    77 lemma not_less_Nil [simp]: "\<not> (x < [])"
    78   by (unfold list_less_def) simp
    79 
    80 lemma Nil_less_Cons [simp]: "[] < a # x"
    81   by (unfold list_less_def) simp
    82 
    83 lemma Cons_less_Cons [simp]: "a # x < b # y \<longleftrightarrow> a < b \<or> a = b \<and> x < y"
    84   by (unfold list_less_def) simp
    85 
    86 lemma le_Nil [simp]: "x \<le> [] \<longleftrightarrow> x = []"
    87   by (unfold list_le_def, cases x) auto
    88 
    89 lemma Nil_le_Cons [simp]: "[] \<le> x"
    90   by (unfold list_le_def, cases x) auto
    91 
    92 lemma Cons_le_Cons [simp]: "a # x \<le> b # y \<longleftrightarrow> a < b \<or> a = b \<and> x \<le> y"
    93   by (unfold list_le_def) auto
    94 
    95 lemma less_code [code func]:
    96   "xs < ([]\<Colon>'a\<Colon>{eq, order} list) \<longleftrightarrow> False"
    97   "[] < (x\<Colon>'a\<Colon>{eq, order}) # xs \<longleftrightarrow> True"
    98   "(x\<Colon>'a\<Colon>{eq, order}) # xs < y # ys \<longleftrightarrow> x < y \<or> x = y \<and> xs < ys"
    99   by simp_all
   100 
   101 lemma less_eq_code [code func]:
   102   "x # xs \<le> ([]\<Colon>'a\<Colon>{eq, order} list) \<longleftrightarrow> False"
   103   "[] \<le> (xs\<Colon>'a\<Colon>{eq, order} list) \<longleftrightarrow> True"
   104   "(x\<Colon>'a\<Colon>{eq, order}) # xs \<le> y # ys \<longleftrightarrow> x < y \<or> x = y \<and> xs \<le> ys"
   105   by simp_all
   106 
   107 end