src/HOL/Library/List_Prefix.thy
changeset 14300 bf8b8c9425c3
parent 12338 de0f4a63baa5
child 14538 1d9d75a8efae
equal deleted inserted replaced
14299:0b5c0b0a3eba 14300:bf8b8c9425c3
   104   then obtain us where "ys = xs @ us" ..
   104   then obtain us where "ys = xs @ us" ..
   105   hence "ys @ zs = xs @ (us @ zs)" by simp
   105   hence "ys @ zs = xs @ (us @ zs)" by simp
   106   thus ?thesis ..
   106   thus ?thesis ..
   107 qed
   107 qed
   108 
   108 
       
   109 lemma append_prefixD: "xs @ ys \<le> zs \<Longrightarrow> xs \<le> zs"
       
   110 by(simp add:prefix_def) blast
       
   111 
   109 theorem prefix_Cons: "(xs \<le> y # ys) = (xs = [] \<or> (\<exists>zs. xs = y # zs \<and> zs \<le> ys))"
   112 theorem prefix_Cons: "(xs \<le> y # ys) = (xs = [] \<or> (\<exists>zs. xs = y # zs \<and> zs \<le> ys))"
   110   by (cases xs) (auto simp add: prefix_def)
   113   by (cases xs) (auto simp add: prefix_def)
   111 
   114 
   112 theorem prefix_append:
   115 theorem prefix_append:
   113     "(xs \<le> ys @ zs) = (xs \<le> ys \<or> (\<exists>us. xs = ys @ us \<and> us \<le> zs))"
   116     "(xs \<le> ys @ zs) = (xs \<le> ys \<or> (\<exists>us. xs = ys @ us \<and> us \<le> zs))"
   126    apply auto
   129    apply auto
   127   done
   130   done
   128 
   131 
   129 theorem prefix_length_le: "xs \<le> ys ==> length xs \<le> length ys"
   132 theorem prefix_length_le: "xs \<le> ys ==> length xs \<le> length ys"
   130   by (auto simp add: prefix_def)
   133   by (auto simp add: prefix_def)
       
   134 
       
   135 
       
   136 lemma prefix_same_cases:
       
   137  "\<lbrakk> (xs\<^isub>1::'a list) \<le> ys; xs\<^isub>2 \<le> ys \<rbrakk> \<Longrightarrow> xs\<^isub>1 \<le> xs\<^isub>2 \<or> xs\<^isub>2 \<le> xs\<^isub>1"
       
   138 apply(simp add:prefix_def)
       
   139 apply(erule exE)+
       
   140 apply(simp add: append_eq_append_conv_if split:if_splits)
       
   141  apply(rule disjI2)
       
   142  apply(rule_tac x = "drop (size xs\<^isub>2) xs\<^isub>1" in exI)
       
   143  apply clarify
       
   144  apply(drule sym)
       
   145  apply(insert append_take_drop_id[of "length xs\<^isub>2" xs\<^isub>1])
       
   146  apply simp
       
   147 apply(rule disjI1)
       
   148 apply(rule_tac x = "drop (size xs\<^isub>1) xs\<^isub>2" in exI)
       
   149 apply clarify
       
   150 apply(insert append_take_drop_id[of "length xs\<^isub>1" xs\<^isub>2])
       
   151 apply simp
       
   152 done
       
   153 
       
   154 lemma set_mono_prefix:
       
   155  "xs \<le> ys \<Longrightarrow> set xs \<subseteq> set ys"
       
   156 by(fastsimp simp add:prefix_def)
   131 
   157 
   132 
   158 
   133 subsection {* Parallel lists *}
   159 subsection {* Parallel lists *}
   134 
   160 
   135 constdefs
   161 constdefs