src/HOL/Library/Sublist_Order.thy
author Christian Sternagel
Thu Aug 30 13:06:04 2012 +0900 (2012-08-30)
changeset 49088 5cd8b4426a57
parent 49085 4eef5c2ff5ad
child 49093 fdc301f592c4
permissions -rw-r--r--
Main is implicitly imported via Sublist
     1 (*  Title:      HOL/Library/Sublist_Order.thy
     2     Authors:    Peter Lammich, Uni Muenster <peter.lammich@uni-muenster.de>
     3                 Florian Haftmann, Tobias Nipkow, TU Muenchen
     4 *)
     5 
     6 header {* Sublist Ordering *}
     7 
     8 theory Sublist_Order
     9 imports Sublist
    10 begin
    11 
    12 text {*
    13   This theory defines sublist ordering on lists.
    14   A list @{text ys} is a sublist of a list @{text xs},
    15   iff one obtains @{text ys} by erasing some elements from @{text xs}.
    16 *}
    17 
    18 subsection {* Definitions and basic lemmas *}
    19 
    20 instantiation list :: (type) ord
    21 begin
    22 
    23 definition
    24   "(xs :: 'a list) \<le> ys \<longleftrightarrow> sub xs ys"
    25 
    26 definition
    27   "(xs :: 'a list) < ys \<longleftrightarrow> xs \<le> ys \<and> \<not> ys \<le> xs"
    28 
    29 instance ..
    30 
    31 end
    32 
    33 instance list :: (type) order
    34 proof
    35   fix xs ys :: "'a list"
    36   show "xs < ys \<longleftrightarrow> xs \<le> ys \<and> \<not> ys \<le> xs" unfolding less_list_def .. 
    37 next
    38   fix xs :: "'a list"
    39   show "xs \<le> xs" by (simp add: less_eq_list_def)
    40 next
    41   fix xs ys :: "'a list"
    42   assume "xs <= ys" and "ys <= xs"
    43   thus "xs = ys" by (unfold less_eq_list_def) (rule sub_antisym)
    44 next
    45   fix xs ys zs :: "'a list"
    46   assume "xs <= ys" and "ys <= zs"
    47   thus "xs <= zs" by (unfold less_eq_list_def) (rule sub_trans)
    48 qed
    49 
    50 lemma less_list_length: "xs < ys \<Longrightarrow> length xs < length ys"
    51   by (metis emb_length sub_same_length le_neq_implies_less less_list_def less_eq_list_def)
    52 
    53 lemma less_list_empty [simp]: "[] < xs \<longleftrightarrow> xs \<noteq> []"
    54   by (metis less_eq_list_def emb_Nil order_less_le)
    55 
    56 lemma less_list_below_empty [simp]: "xs < [] \<longleftrightarrow> False"
    57   by (metis emb_Nil less_eq_list_def less_list_def)
    58 
    59 lemma less_list_drop: "xs < ys \<Longrightarrow> xs < x # ys"
    60   by (unfold less_le less_eq_list_def) (auto)
    61 
    62 lemma less_list_take_iff: "x # xs < x # ys \<longleftrightarrow> xs < ys"
    63   by (metis sub_Cons2_iff less_list_def less_eq_list_def)
    64 
    65 lemma less_list_drop_many: "xs < ys \<Longrightarrow> xs < zs @ ys"
    66   by (metis sub_append_le_same_iff sub_drop_many order_less_le self_append_conv2 less_eq_list_def)
    67 
    68 lemma less_list_take_many_iff: "zs @ xs < zs @ ys \<longleftrightarrow> xs < ys"
    69   by (metis less_list_def less_eq_list_def sub_append')
    70 
    71 lemma less_list_rev_take: "xs @ zs < ys @ zs \<longleftrightarrow> xs < ys"
    72   by (unfold less_le less_eq_list_def) auto
    73 
    74 end