src/HOL/Library/Sublist.thy
changeset 73186 ce90865dbaeb
parent 71789 3b6547bdf6e2
child 73380 99c1c4f89605
equal deleted inserted replaced
73185:b310b93563f6 73186:ce90865dbaeb
   474 
   474 
   475 theorem prefix_cases:
   475 theorem prefix_cases:
   476   obtains "prefix xs ys" | "strict_prefix ys xs" | "xs \<parallel> ys"
   476   obtains "prefix xs ys" | "strict_prefix ys xs" | "xs \<parallel> ys"
   477   unfolding parallel_def strict_prefix_def by blast
   477   unfolding parallel_def strict_prefix_def by blast
   478 
   478 
       
   479 lemma parallel_cancel:  "a#xs \<parallel> a#ys \<Longrightarrow> xs \<parallel> ys"
       
   480   by (simp add: parallel_def)
       
   481 
   479 theorem parallel_decomp:
   482 theorem parallel_decomp:
   480   "xs \<parallel> ys \<Longrightarrow> \<exists>as b bs c cs. b \<noteq> c \<and> xs = as @ b # bs \<and> ys = as @ c # cs"
   483   "xs \<parallel> ys \<Longrightarrow> \<exists>as b bs c cs. b \<noteq> c \<and> xs = as @ b # bs \<and> ys = as @ c # cs"
   481 proof (induct xs rule: rev_induct)
   484 proof (induct rule: list_induct2', blast, force, force)
   482   case Nil
   485   case (4 x xs y ys)
   483   then have False by auto
   486   then show ?case
   484   then show ?case ..
   487   proof (cases "x \<noteq> y", blast)
   485 next
   488     assume "\<not> x \<noteq> y" hence "x = y" by blast
   486   case (snoc x xs)
   489     then show ?thesis
   487   show ?case
   490       using "4.hyps"[OF parallel_cancel[OF "4.prems"[folded \<open>x = y\<close>]]]
   488   proof (rule prefix_cases)
   491       by (meson Cons_eq_appendI)
   489     assume le: "prefix xs ys"
       
   490     then obtain ys' where ys: "ys = xs @ ys'" ..
       
   491     show ?thesis
       
   492     proof (cases ys')
       
   493       assume "ys' = []"
       
   494       then show ?thesis by (metis append_Nil2 parallelE prefixI snoc.prems ys)
       
   495     next
       
   496       fix c cs assume ys': "ys' = c # cs"
       
   497       have "x \<noteq> c" using snoc.prems ys ys' by fastforce
       
   498       thus "\<exists>as b bs c cs. b \<noteq> c \<and> xs @ [x] = as @ b # bs \<and> ys = as @ c # cs"
       
   499         using ys ys' by blast
       
   500     qed
       
   501   next
       
   502     assume "strict_prefix ys xs"
       
   503     then have "prefix ys (xs @ [x])" by (simp add: strict_prefix_def)
       
   504     with snoc have False by blast
       
   505     then show ?thesis ..
       
   506   next
       
   507     assume "xs \<parallel> ys"
       
   508     with snoc obtain as b bs c cs where neq: "(b::'a) \<noteq> c"
       
   509       and xs: "xs = as @ b # bs" and ys: "ys = as @ c # cs"
       
   510       by blast
       
   511     from xs have "xs @ [x] = as @ b # (bs @ [x])" by simp
       
   512     with neq ys show ?thesis by blast
       
   513   qed
   492   qed
   514 qed
   493 qed
   515 
   494 
   516 lemma parallel_append: "a \<parallel> b \<Longrightarrow> a @ c \<parallel> b @ d"
   495 lemma parallel_append: "a \<parallel> b \<Longrightarrow> a @ c \<parallel> b @ d"
   517   apply (rule parallelI)
   496   apply (rule parallelI)