src/HOL/Library/Sublist.thy
author nipkow
Wed May 25 17:40:56 2016 +0200 (2016-05-25)
changeset 63149 f5dbab18c404
parent 63117 acb6d72fc42e
child 63155 ea8540c71581
permissions -rw-r--r--
renamed suffix(eq)
Christian@49087
     1
(*  Title:      HOL/Library/Sublist.thy
wenzelm@10330
     2
    Author:     Tobias Nipkow and Markus Wenzel, TU Muenchen
Christian@49087
     3
    Author:     Christian Sternagel, JAIST
wenzelm@10330
     4
*)
wenzelm@10330
     5
wenzelm@60500
     6
section \<open>List prefixes, suffixes, and homeomorphic embedding\<close>
wenzelm@10330
     7
Christian@49087
     8
theory Sublist
Christian@49087
     9
imports Main
nipkow@15131
    10
begin
wenzelm@10330
    11
wenzelm@60500
    12
subsection \<open>Prefix order on lists\<close>
traytel@55579
    13
nipkow@63117
    14
definition prefix :: "'a list \<Rightarrow> 'a list \<Rightarrow> bool"
nipkow@63117
    15
  where "prefix xs ys \<longleftrightarrow> (\<exists>zs. ys = xs @ zs)"
traytel@55579
    16
nipkow@63117
    17
definition strict_prefix :: "'a list \<Rightarrow> 'a list \<Rightarrow> bool"
nipkow@63117
    18
  where "strict_prefix xs ys \<longleftrightarrow> prefix xs ys \<and> xs \<noteq> ys"
traytel@55579
    19
nipkow@63117
    20
interpretation prefix_order: order prefix strict_prefix
nipkow@63117
    21
  by standard (auto simp: prefix_def strict_prefix_def)
traytel@55579
    22
nipkow@63117
    23
interpretation prefix_bot: order_bot Nil prefix strict_prefix
nipkow@63117
    24
  by standard (simp add: prefix_def)
traytel@55579
    25
nipkow@63117
    26
lemma prefixI [intro?]: "ys = xs @ zs \<Longrightarrow> prefix xs ys"
nipkow@63117
    27
  unfolding prefix_def by blast
traytel@55579
    28
nipkow@63117
    29
lemma prefixE [elim?]:
nipkow@63117
    30
  assumes "prefix xs ys"
traytel@55579
    31
  obtains zs where "ys = xs @ zs"
nipkow@63117
    32
  using assms unfolding prefix_def by blast
traytel@55579
    33
nipkow@63117
    34
lemma strict_prefixI' [intro?]: "ys = xs @ z # zs \<Longrightarrow> strict_prefix xs ys"
nipkow@63117
    35
  unfolding strict_prefix_def prefix_def by blast
traytel@55579
    36
nipkow@63117
    37
lemma strict_prefixE' [elim?]:
nipkow@63117
    38
  assumes "strict_prefix xs ys"
traytel@55579
    39
  obtains z zs where "ys = xs @ z # zs"
traytel@55579
    40
proof -
nipkow@63117
    41
  from \<open>strict_prefix xs ys\<close> obtain us where "ys = xs @ us" and "xs \<noteq> ys"
nipkow@63117
    42
    unfolding strict_prefix_def prefix_def by blast
traytel@55579
    43
  with that show ?thesis by (auto simp add: neq_Nil_conv)
traytel@55579
    44
qed
traytel@55579
    45
nipkow@63117
    46
lemma strict_prefixI [intro?]: "prefix xs ys \<Longrightarrow> xs \<noteq> ys \<Longrightarrow> strict_prefix xs ys"
nipkow@63117
    47
  unfolding strict_prefix_def by blast
traytel@55579
    48
nipkow@63117
    49
lemma strict_prefixE [elim?]:
traytel@55579
    50
  fixes xs ys :: "'a list"
nipkow@63117
    51
  assumes "strict_prefix xs ys"
nipkow@63117
    52
  obtains "prefix xs ys" and "xs \<noteq> ys"
nipkow@63117
    53
  using assms unfolding strict_prefix_def by blast
traytel@55579
    54
traytel@55579
    55
wenzelm@60500
    56
subsection \<open>Basic properties of prefixes\<close>
traytel@55579
    57
nipkow@63117
    58
theorem Nil_prefix [iff]: "prefix [] xs"
nipkow@63117
    59
  by (simp add: prefix_def)
traytel@55579
    60
nipkow@63117
    61
theorem prefix_Nil [simp]: "(prefix xs []) = (xs = [])"
nipkow@63117
    62
  by (induct xs) (simp_all add: prefix_def)
traytel@55579
    63
nipkow@63117
    64
lemma prefix_snoc [simp]: "prefix xs (ys @ [y]) \<longleftrightarrow> xs = ys @ [y] \<or> prefix xs ys"
traytel@55579
    65
proof
nipkow@63117
    66
  assume "prefix xs (ys @ [y])"
traytel@55579
    67
  then obtain zs where zs: "ys @ [y] = xs @ zs" ..
nipkow@63117
    68
  show "xs = ys @ [y] \<or> prefix xs ys"
nipkow@63117
    69
    by (metis append_Nil2 butlast_append butlast_snoc prefixI zs)
traytel@55579
    70
next
nipkow@63117
    71
  assume "xs = ys @ [y] \<or> prefix xs ys"
nipkow@63117
    72
  then show "prefix xs (ys @ [y])"
nipkow@63117
    73
    by (metis prefix_order.eq_iff prefix_order.order_trans prefixI)
traytel@55579
    74
qed
traytel@55579
    75
nipkow@63117
    76
lemma Cons_prefix_Cons [simp]: "prefix (x # xs) (y # ys) = (x = y \<and> prefix xs ys)"
nipkow@63117
    77
  by (auto simp add: prefix_def)
traytel@55579
    78
nipkow@63117
    79
lemma prefix_code [code]:
nipkow@63117
    80
  "prefix [] xs \<longleftrightarrow> True"
nipkow@63117
    81
  "prefix (x # xs) [] \<longleftrightarrow> False"
nipkow@63117
    82
  "prefix (x # xs) (y # ys) \<longleftrightarrow> x = y \<and> prefix xs ys"
traytel@55579
    83
  by simp_all
traytel@55579
    84
nipkow@63117
    85
lemma same_prefix_prefix [simp]: "prefix (xs @ ys) (xs @ zs) = prefix ys zs"
traytel@55579
    86
  by (induct xs) simp_all
traytel@55579
    87
nipkow@63117
    88
lemma same_prefix_nil [iff]: "prefix (xs @ ys) xs = (ys = [])"
nipkow@63117
    89
  by (metis append_Nil2 append_self_conv prefix_order.eq_iff prefixI)
traytel@55579
    90
nipkow@63117
    91
lemma prefix_prefix [simp]: "prefix xs ys \<Longrightarrow> prefix xs (ys @ zs)"
nipkow@63117
    92
  by (metis prefix_order.le_less_trans prefixI strict_prefixE strict_prefixI)
traytel@55579
    93
nipkow@63117
    94
lemma append_prefixD: "prefix (xs @ ys) zs \<Longrightarrow> prefix xs zs"
nipkow@63117
    95
  by (auto simp add: prefix_def)
traytel@55579
    96
nipkow@63117
    97
theorem prefix_Cons: "prefix xs (y # ys) = (xs = [] \<or> (\<exists>zs. xs = y # zs \<and> prefix zs ys))"
nipkow@63117
    98
  by (cases xs) (auto simp add: prefix_def)
traytel@55579
    99
nipkow@63117
   100
theorem prefix_append:
nipkow@63117
   101
  "prefix xs (ys @ zs) = (prefix xs ys \<or> (\<exists>us. xs = ys @ us \<and> prefix us zs))"
traytel@55579
   102
  apply (induct zs rule: rev_induct)
traytel@55579
   103
   apply force
traytel@55579
   104
  apply (simp del: append_assoc add: append_assoc [symmetric])
traytel@55579
   105
  apply (metis append_eq_appendI)
traytel@55579
   106
  done
traytel@55579
   107
nipkow@63117
   108
lemma append_one_prefix:
nipkow@63117
   109
  "prefix xs ys \<Longrightarrow> length xs < length ys \<Longrightarrow> prefix (xs @ [ys ! length xs]) ys"
nipkow@63117
   110
  proof (unfold prefix_def)
traytel@55579
   111
    assume a1: "\<exists>zs. ys = xs @ zs"
traytel@55579
   112
    then obtain sk :: "'a list" where sk: "ys = xs @ sk" by fastforce
traytel@55579
   113
    assume a2: "length xs < length ys"
wenzelm@61076
   114
    have f1: "\<And>v. ([]::'a list) @ v = v" using append_Nil2 by simp
traytel@55579
   115
    have "[] \<noteq> sk" using a1 a2 sk less_not_refl by force
traytel@55579
   116
    hence "\<exists>v. xs @ hd sk # v = ys" using sk by (metis hd_Cons_tl)
traytel@55579
   117
    thus "\<exists>zs. ys = (xs @ [ys ! length xs]) @ zs" using f1 by fastforce
traytel@55579
   118
  qed
traytel@55579
   119
nipkow@63117
   120
theorem prefix_length_le: "prefix xs ys \<Longrightarrow> length xs \<le> length ys"
nipkow@63117
   121
  by (auto simp add: prefix_def)
traytel@55579
   122
nipkow@63117
   123
lemma prefix_same_cases:
nipkow@63117
   124
  "prefix (xs\<^sub>1::'a list) ys \<Longrightarrow> prefix xs\<^sub>2 ys \<Longrightarrow> prefix xs\<^sub>1 xs\<^sub>2 \<or> prefix xs\<^sub>2 xs\<^sub>1"
nipkow@63117
   125
  unfolding prefix_def by (force simp: append_eq_append_conv2)
traytel@55579
   126
nipkow@63117
   127
lemma set_mono_prefix: "prefix xs ys \<Longrightarrow> set xs \<subseteq> set ys"
nipkow@63117
   128
  by (auto simp add: prefix_def)
traytel@55579
   129
nipkow@63117
   130
lemma take_is_prefix: "prefix (take n xs) xs"
nipkow@63117
   131
  unfolding prefix_def by (metis append_take_drop_id)
traytel@55579
   132
nipkow@63117
   133
lemma map_prefixI: "prefix xs ys \<Longrightarrow> prefix (map f xs) (map f ys)"
nipkow@63117
   134
  by (auto simp: prefix_def)
traytel@55579
   135
nipkow@63117
   136
lemma prefix_length_less: "strict_prefix xs ys \<Longrightarrow> length xs < length ys"
nipkow@63117
   137
  by (auto simp: strict_prefix_def prefix_def)
traytel@55579
   138
nipkow@63117
   139
lemma strict_prefix_simps [simp, code]:
nipkow@63117
   140
  "strict_prefix xs [] \<longleftrightarrow> False"
nipkow@63117
   141
  "strict_prefix [] (x # xs) \<longleftrightarrow> True"
nipkow@63117
   142
  "strict_prefix (x # xs) (y # ys) \<longleftrightarrow> x = y \<and> strict_prefix xs ys"
nipkow@63117
   143
  by (simp_all add: strict_prefix_def cong: conj_cong)
traytel@55579
   144
nipkow@63117
   145
lemma take_strict_prefix: "strict_prefix xs ys \<Longrightarrow> strict_prefix (take n xs) ys"
traytel@55579
   146
  apply (induct n arbitrary: xs ys)
wenzelm@59997
   147
   apply (case_tac ys; simp)
nipkow@63117
   148
  apply (metis prefix_order.less_trans strict_prefixI take_is_prefix)
traytel@55579
   149
  done
traytel@55579
   150
nipkow@63117
   151
lemma not_prefix_cases:
nipkow@63117
   152
  assumes pfx: "\<not> prefix ps ls"
traytel@55579
   153
  obtains
traytel@55579
   154
    (c1) "ps \<noteq> []" and "ls = []"
nipkow@63117
   155
  | (c2) a as x xs where "ps = a#as" and "ls = x#xs" and "x = a" and "\<not> prefix as xs"
traytel@55579
   156
  | (c3) a as x xs where "ps = a#as" and "ls = x#xs" and "x \<noteq> a"
traytel@55579
   157
proof (cases ps)
traytel@55579
   158
  case Nil
traytel@55579
   159
  then show ?thesis using pfx by simp
traytel@55579
   160
next
traytel@55579
   161
  case (Cons a as)
wenzelm@60500
   162
  note c = \<open>ps = a#as\<close>
traytel@55579
   163
  show ?thesis
traytel@55579
   164
  proof (cases ls)
nipkow@63117
   165
    case Nil then show ?thesis by (metis append_Nil2 pfx c1 same_prefix_nil)
traytel@55579
   166
  next
traytel@55579
   167
    case (Cons x xs)
traytel@55579
   168
    show ?thesis
traytel@55579
   169
    proof (cases "x = a")
traytel@55579
   170
      case True
nipkow@63117
   171
      have "\<not> prefix as xs" using pfx c Cons True by simp
traytel@55579
   172
      with c Cons True show ?thesis by (rule c2)
traytel@55579
   173
    next
traytel@55579
   174
      case False
traytel@55579
   175
      with c Cons show ?thesis by (rule c3)
traytel@55579
   176
    qed
traytel@55579
   177
  qed
traytel@55579
   178
qed
traytel@55579
   179
nipkow@63117
   180
lemma not_prefix_induct [consumes 1, case_names Nil Neq Eq]:
nipkow@63117
   181
  assumes np: "\<not> prefix ps ls"
traytel@55579
   182
    and base: "\<And>x xs. P (x#xs) []"
traytel@55579
   183
    and r1: "\<And>x xs y ys. x \<noteq> y \<Longrightarrow> P (x#xs) (y#ys)"
nipkow@63117
   184
    and r2: "\<And>x xs y ys. \<lbrakk> x = y; \<not> prefix xs ys; P xs ys \<rbrakk> \<Longrightarrow> P (x#xs) (y#ys)"
traytel@55579
   185
  shows "P ps ls" using np
traytel@55579
   186
proof (induct ls arbitrary: ps)
traytel@55579
   187
  case Nil then show ?case
nipkow@63117
   188
    by (auto simp: neq_Nil_conv elim!: not_prefix_cases intro!: base)
traytel@55579
   189
next
traytel@55579
   190
  case (Cons y ys)
nipkow@63117
   191
  then have npfx: "\<not> prefix ps (y # ys)" by simp
traytel@55579
   192
  then obtain x xs where pv: "ps = x # xs"
nipkow@63117
   193
    by (rule not_prefix_cases) auto
nipkow@63117
   194
  show ?case by (metis Cons.hyps Cons_prefix_Cons npfx pv r1 r2)
traytel@55579
   195
qed
traytel@55579
   196
traytel@55579
   197
wenzelm@60500
   198
subsection \<open>Parallel lists\<close>
wenzelm@10389
   199
Christian@50516
   200
definition parallel :: "'a list \<Rightarrow> 'a list \<Rightarrow> bool"  (infixl "\<parallel>" 50)
nipkow@63117
   201
  where "(xs \<parallel> ys) = (\<not> prefix xs ys \<and> \<not> prefix ys xs)"
wenzelm@10389
   202
nipkow@63117
   203
lemma parallelI [intro]: "\<not> prefix xs ys \<Longrightarrow> \<not> prefix ys xs \<Longrightarrow> xs \<parallel> ys"
wenzelm@25692
   204
  unfolding parallel_def by blast
wenzelm@10330
   205
wenzelm@10389
   206
lemma parallelE [elim]:
wenzelm@25692
   207
  assumes "xs \<parallel> ys"
nipkow@63117
   208
  obtains "\<not> prefix xs ys \<and> \<not> prefix ys xs"
wenzelm@25692
   209
  using assms unfolding parallel_def by blast
wenzelm@10330
   210
nipkow@63117
   211
theorem prefix_cases:
nipkow@63117
   212
  obtains "prefix xs ys" | "strict_prefix ys xs" | "xs \<parallel> ys"
nipkow@63117
   213
  unfolding parallel_def strict_prefix_def by blast
wenzelm@10330
   214
wenzelm@10389
   215
theorem parallel_decomp:
Christian@50516
   216
  "xs \<parallel> ys \<Longrightarrow> \<exists>as b bs c cs. b \<noteq> c \<and> xs = as @ b # bs \<and> ys = as @ c # cs"
wenzelm@10408
   217
proof (induct xs rule: rev_induct)
wenzelm@11987
   218
  case Nil
wenzelm@23254
   219
  then have False by auto
wenzelm@23254
   220
  then show ?case ..
wenzelm@10408
   221
next
wenzelm@11987
   222
  case (snoc x xs)
wenzelm@11987
   223
  show ?case
nipkow@63117
   224
  proof (rule prefix_cases)
nipkow@63117
   225
    assume le: "prefix xs ys"
wenzelm@10408
   226
    then obtain ys' where ys: "ys = xs @ ys'" ..
wenzelm@10408
   227
    show ?thesis
wenzelm@10408
   228
    proof (cases ys')
nipkow@25564
   229
      assume "ys' = []"
nipkow@63117
   230
      then show ?thesis by (metis append_Nil2 parallelE prefixI snoc.prems ys)
wenzelm@10389
   231
    next
wenzelm@10408
   232
      fix c cs assume ys': "ys' = c # cs"
blanchet@54483
   233
      have "x \<noteq> c" using snoc.prems ys ys' by fastforce
blanchet@54483
   234
      thus "\<exists>as b bs c cs. b \<noteq> c \<and> xs @ [x] = as @ b # bs \<and> ys = as @ c # cs"
blanchet@54483
   235
        using ys ys' by blast
wenzelm@10389
   236
    qed
wenzelm@10408
   237
  next
nipkow@63117
   238
    assume "strict_prefix ys xs"
nipkow@63117
   239
    then have "prefix ys (xs @ [x])" by (simp add: strict_prefix_def)
wenzelm@11987
   240
    with snoc have False by blast
wenzelm@23254
   241
    then show ?thesis ..
wenzelm@10408
   242
  next
wenzelm@10408
   243
    assume "xs \<parallel> ys"
wenzelm@11987
   244
    with snoc obtain as b bs c cs where neq: "(b::'a) \<noteq> c"
wenzelm@10408
   245
      and xs: "xs = as @ b # bs" and ys: "ys = as @ c # cs"
wenzelm@10408
   246
      by blast
wenzelm@10408
   247
    from xs have "xs @ [x] = as @ b # (bs @ [x])" by simp
wenzelm@10408
   248
    with neq ys show ?thesis by blast
wenzelm@10389
   249
  qed
wenzelm@10389
   250
qed
wenzelm@10330
   251
nipkow@25564
   252
lemma parallel_append: "a \<parallel> b \<Longrightarrow> a @ c \<parallel> b @ d"
wenzelm@25692
   253
  apply (rule parallelI)
wenzelm@25692
   254
    apply (erule parallelE, erule conjE,
nipkow@63117
   255
      induct rule: not_prefix_induct, simp+)+
wenzelm@25692
   256
  done
kleing@25299
   257
wenzelm@25692
   258
lemma parallel_appendI: "xs \<parallel> ys \<Longrightarrow> x = xs @ xs' \<Longrightarrow> y = ys @ ys' \<Longrightarrow> x \<parallel> y"
wenzelm@25692
   259
  by (simp add: parallel_append)
kleing@25299
   260
wenzelm@25692
   261
lemma parallel_commute: "a \<parallel> b \<longleftrightarrow> b \<parallel> a"
wenzelm@25692
   262
  unfolding parallel_def by auto
oheimb@14538
   263
wenzelm@25356
   264
wenzelm@60500
   265
subsection \<open>Suffix order on lists\<close>
wenzelm@17201
   266
nipkow@63149
   267
definition suffix :: "'a list \<Rightarrow> 'a list \<Rightarrow> bool"
nipkow@63149
   268
  where "suffix xs ys = (\<exists>zs. ys = zs @ xs)"
Christian@49087
   269
nipkow@63149
   270
definition strict_suffix :: "'a list \<Rightarrow> 'a list \<Rightarrow> bool"
nipkow@63149
   271
  where "strict_suffix xs ys \<longleftrightarrow> (\<exists>us. ys = us @ xs \<and> us \<noteq> [])"
oheimb@14538
   272
nipkow@63149
   273
lemma strict_suffix_imp_suffix:
nipkow@63149
   274
  "strict_suffix xs ys \<Longrightarrow> suffix xs ys"
nipkow@63149
   275
  by (auto simp: suffix_def strict_suffix_def)
Christian@49087
   276
nipkow@63149
   277
lemma suffixI [intro?]: "ys = zs @ xs \<Longrightarrow> suffix xs ys"
nipkow@63149
   278
  unfolding suffix_def by blast
wenzelm@21305
   279
nipkow@63149
   280
lemma suffixE [elim?]:
nipkow@63149
   281
  assumes "suffix xs ys"
Christian@49087
   282
  obtains zs where "ys = zs @ xs"
nipkow@63149
   283
  using assms unfolding suffix_def by blast
wenzelm@21305
   284
nipkow@63149
   285
lemma suffix_refl [iff]: "suffix xs xs"
nipkow@63149
   286
  by (auto simp add: suffix_def)
nipkow@63149
   287
Christian@49087
   288
lemma suffix_trans:
Christian@49087
   289
  "suffix xs ys \<Longrightarrow> suffix ys zs \<Longrightarrow> suffix xs zs"
Christian@49087
   290
  by (auto simp: suffix_def)
nipkow@63149
   291
nipkow@63149
   292
lemma strict_suffix_trans:
nipkow@63149
   293
  "\<lbrakk>strict_suffix xs ys; strict_suffix ys zs\<rbrakk> \<Longrightarrow> strict_suffix xs zs"
nipkow@63149
   294
by (auto simp add: strict_suffix_def)
Christian@49087
   295
nipkow@63149
   296
lemma suffix_antisym: "\<lbrakk>suffix xs ys; suffix ys xs\<rbrakk> \<Longrightarrow> xs = ys"
nipkow@63149
   297
  by (auto simp add: suffix_def)
oheimb@14538
   298
nipkow@63149
   299
lemma suffix_tl [simp]: "suffix (tl xs) xs"
Christian@49087
   300
  by (induct xs) (auto simp: suffix_def)
oheimb@14538
   301
nipkow@63149
   302
lemma strict_suffix_tl [simp]: "xs \<noteq> [] \<Longrightarrow> strict_suffix (tl xs) xs"
nipkow@63149
   303
  by (induct xs) (auto simp: strict_suffix_def)
nipkow@63149
   304
nipkow@63149
   305
lemma Nil_suffix [iff]: "suffix [] xs"
nipkow@63149
   306
  by (simp add: suffix_def)
Christian@49087
   307
nipkow@63149
   308
lemma suffix_Nil [simp]: "(suffix xs []) = (xs = [])"
nipkow@63149
   309
  by (auto simp add: suffix_def)
nipkow@63149
   310
nipkow@63149
   311
lemma suffix_ConsI: "suffix xs ys \<Longrightarrow> suffix xs (y # ys)"
nipkow@63149
   312
  by (auto simp add: suffix_def)
nipkow@63149
   313
nipkow@63149
   314
lemma suffix_ConsD: "suffix (x # xs) ys \<Longrightarrow> suffix xs ys"
nipkow@63149
   315
  by (auto simp add: suffix_def)
oheimb@14538
   316
nipkow@63149
   317
lemma suffix_appendI: "suffix xs ys \<Longrightarrow> suffix xs (zs @ ys)"
nipkow@63149
   318
  by (auto simp add: suffix_def)
nipkow@63149
   319
nipkow@63149
   320
lemma suffix_appendD: "suffix (zs @ xs) ys \<Longrightarrow> suffix xs ys"
nipkow@63149
   321
  by (auto simp add: suffix_def)
Christian@49087
   322
nipkow@63149
   323
lemma strict_suffix_set_subset: "strict_suffix xs ys \<Longrightarrow> set xs \<subseteq> set ys"
nipkow@63149
   324
by (auto simp: strict_suffix_def)
oheimb@14538
   325
nipkow@63149
   326
lemma suffix_set_subset: "suffix xs ys \<Longrightarrow> set xs \<subseteq> set ys"
nipkow@63149
   327
by (auto simp: suffix_def)
Christian@49087
   328
nipkow@63149
   329
lemma suffix_ConsD2: "suffix (x # xs) (y # ys) \<Longrightarrow> suffix xs ys"
wenzelm@21305
   330
proof -
nipkow@63149
   331
  assume "suffix (x # xs) (y # ys)"
wenzelm@49107
   332
  then obtain zs where "y # ys = zs @ x # xs" ..
Christian@49087
   333
  then show ?thesis
nipkow@63149
   334
    by (induct zs) (auto intro!: suffix_appendI suffix_ConsI)
wenzelm@21305
   335
qed
oheimb@14538
   336
nipkow@63149
   337
lemma suffix_to_prefix [code]: "suffix xs ys \<longleftrightarrow> prefix (rev xs) (rev ys)"
Christian@49087
   338
proof
nipkow@63149
   339
  assume "suffix xs ys"
Christian@49087
   340
  then obtain zs where "ys = zs @ xs" ..
Christian@49087
   341
  then have "rev ys = rev xs @ rev zs" by simp
nipkow@63117
   342
  then show "prefix (rev xs) (rev ys)" ..
Christian@49087
   343
next
nipkow@63117
   344
  assume "prefix (rev xs) (rev ys)"
Christian@49087
   345
  then obtain zs where "rev ys = rev xs @ zs" ..
Christian@49087
   346
  then have "rev (rev ys) = rev zs @ rev (rev xs)" by simp
Christian@49087
   347
  then have "ys = rev zs @ xs" by simp
nipkow@63149
   348
  then show "suffix xs ys" ..
wenzelm@21305
   349
qed
oheimb@14538
   350
nipkow@63149
   351
lemma distinct_suffix: "distinct ys \<Longrightarrow> suffix xs ys \<Longrightarrow> distinct xs"
nipkow@63149
   352
  by (clarsimp elim!: suffixE)
wenzelm@17201
   353
nipkow@63149
   354
lemma suffix_map: "suffix xs ys \<Longrightarrow> suffix (map f xs) (map f ys)"
nipkow@63149
   355
  by (auto elim!: suffixE intro: suffixI)
kleing@25299
   356
nipkow@63149
   357
lemma suffix_drop: "suffix (drop n as) as"
nipkow@63149
   358
  unfolding suffix_def
wenzelm@25692
   359
  apply (rule exI [where x = "take n as"])
wenzelm@25692
   360
  apply simp
wenzelm@25692
   361
  done
kleing@25299
   362
nipkow@63149
   363
lemma suffix_take: "suffix xs ys \<Longrightarrow> ys = take (length ys - length xs) ys @ xs"
nipkow@63149
   364
  by (auto elim!: suffixE)
kleing@25299
   365
nipkow@63149
   366
lemma strict_suffix_reflclp_conv: "strict_suffix\<^sup>=\<^sup>= = suffix"
nipkow@63149
   367
by (intro ext) (auto simp: suffix_def strict_suffix_def)
nipkow@63149
   368
nipkow@63149
   369
lemma suffix_lists: "suffix xs ys \<Longrightarrow> ys \<in> lists A \<Longrightarrow> xs \<in> lists A"
nipkow@63149
   370
  unfolding suffix_def by auto
Christian@49087
   371
nipkow@63117
   372
lemma parallelD1: "x \<parallel> y \<Longrightarrow> \<not> prefix x y"
wenzelm@25692
   373
  by blast
kleing@25299
   374
nipkow@63117
   375
lemma parallelD2: "x \<parallel> y \<Longrightarrow> \<not> prefix y x"
wenzelm@25692
   376
  by blast
wenzelm@25355
   377
wenzelm@25355
   378
lemma parallel_Nil1 [simp]: "\<not> x \<parallel> []"
wenzelm@25692
   379
  unfolding parallel_def by simp
wenzelm@25355
   380
kleing@25299
   381
lemma parallel_Nil2 [simp]: "\<not> [] \<parallel> x"
wenzelm@25692
   382
  unfolding parallel_def by simp
kleing@25299
   383
nipkow@25564
   384
lemma Cons_parallelI1: "a \<noteq> b \<Longrightarrow> a # as \<parallel> b # bs"
wenzelm@25692
   385
  by auto
kleing@25299
   386
nipkow@25564
   387
lemma Cons_parallelI2: "\<lbrakk> a = b; as \<parallel> bs \<rbrakk> \<Longrightarrow> a # as \<parallel> b # bs"
nipkow@63117
   388
  by (metis Cons_prefix_Cons parallelE parallelI)
nipkow@25665
   389
kleing@25299
   390
lemma not_equal_is_parallel:
kleing@25299
   391
  assumes neq: "xs \<noteq> ys"
wenzelm@25356
   392
    and len: "length xs = length ys"
wenzelm@25356
   393
  shows "xs \<parallel> ys"
kleing@25299
   394
  using len neq
wenzelm@25355
   395
proof (induct rule: list_induct2)
haftmann@26445
   396
  case Nil
wenzelm@25356
   397
  then show ?case by simp
kleing@25299
   398
next
haftmann@26445
   399
  case (Cons a as b bs)
wenzelm@25355
   400
  have ih: "as \<noteq> bs \<Longrightarrow> as \<parallel> bs" by fact
kleing@25299
   401
  show ?case
kleing@25299
   402
  proof (cases "a = b")
wenzelm@25355
   403
    case True
haftmann@26445
   404
    then have "as \<noteq> bs" using Cons by simp
wenzelm@25355
   405
    then show ?thesis by (rule Cons_parallelI2 [OF True ih])
kleing@25299
   406
  next
kleing@25299
   407
    case False
wenzelm@25355
   408
    then show ?thesis by (rule Cons_parallelI1)
kleing@25299
   409
  qed
kleing@25299
   410
qed
haftmann@22178
   411
Christian@49087
   412
wenzelm@60500
   413
subsection \<open>Homeomorphic embedding on lists\<close>
Christian@49087
   414
Christian@57497
   415
inductive list_emb :: "('a \<Rightarrow> 'a \<Rightarrow> bool) \<Rightarrow> 'a list \<Rightarrow> 'a list \<Rightarrow> bool"
Christian@49087
   416
  for P :: "('a \<Rightarrow> 'a \<Rightarrow> bool)"
Christian@49087
   417
where
Christian@57497
   418
  list_emb_Nil [intro, simp]: "list_emb P [] ys"
Christian@57497
   419
| list_emb_Cons [intro] : "list_emb P xs ys \<Longrightarrow> list_emb P xs (y#ys)"
Christian@57498
   420
| list_emb_Cons2 [intro]: "P x y \<Longrightarrow> list_emb P xs ys \<Longrightarrow> list_emb P (x#xs) (y#ys)"
Christian@50516
   421
Christian@57499
   422
lemma list_emb_mono:                         
Christian@57499
   423
  assumes "\<And>x y. P x y \<longrightarrow> Q x y"
Christian@57499
   424
  shows "list_emb P xs ys \<longrightarrow> list_emb Q xs ys"
Christian@57499
   425
proof                                        
Christian@57499
   426
  assume "list_emb P xs ys"                    
Christian@57499
   427
  then show "list_emb Q xs ys" by (induct) (auto simp: assms)
Christian@57499
   428
qed 
Christian@57499
   429
Christian@57497
   430
lemma list_emb_Nil2 [simp]:
Christian@57497
   431
  assumes "list_emb P xs []" shows "xs = []"
Christian@57497
   432
  using assms by (cases rule: list_emb.cases) auto
Christian@49087
   433
Christian@57498
   434
lemma list_emb_refl:
Christian@57498
   435
  assumes "\<And>x. x \<in> set xs \<Longrightarrow> P x x"
Christian@57498
   436
  shows "list_emb P xs xs"
Christian@57498
   437
  using assms by (induct xs) auto
Christian@49087
   438
Christian@57497
   439
lemma list_emb_Cons_Nil [simp]: "list_emb P (x#xs) [] = False"
Christian@49087
   440
proof -
Christian@57497
   441
  { assume "list_emb P (x#xs) []"
Christian@57497
   442
    from list_emb_Nil2 [OF this] have False by simp
Christian@49087
   443
  } moreover {
Christian@49087
   444
    assume False
Christian@57497
   445
    then have "list_emb P (x#xs) []" by simp
Christian@49087
   446
  } ultimately show ?thesis by blast
Christian@49087
   447
qed
Christian@49087
   448
Christian@57497
   449
lemma list_emb_append2 [intro]: "list_emb P xs ys \<Longrightarrow> list_emb P xs (zs @ ys)"
Christian@49087
   450
  by (induct zs) auto
Christian@49087
   451
Christian@57497
   452
lemma list_emb_prefix [intro]:
Christian@57497
   453
  assumes "list_emb P xs ys" shows "list_emb P xs (ys @ zs)"
Christian@49087
   454
  using assms
Christian@49087
   455
  by (induct arbitrary: zs) auto
Christian@49087
   456
Christian@57497
   457
lemma list_emb_ConsD:
Christian@57497
   458
  assumes "list_emb P (x#xs) ys"
Christian@57498
   459
  shows "\<exists>us v vs. ys = us @ v # vs \<and> P x v \<and> list_emb P xs vs"
Christian@49087
   460
using assms
wenzelm@49107
   461
proof (induct x \<equiv> "x # xs" ys arbitrary: x xs)
Christian@57497
   462
  case list_emb_Cons
wenzelm@49107
   463
  then show ?case by (metis append_Cons)
Christian@49087
   464
next
Christian@57497
   465
  case (list_emb_Cons2 x y xs ys)
blanchet@54483
   466
  then show ?case by blast
Christian@49087
   467
qed
Christian@49087
   468
Christian@57497
   469
lemma list_emb_appendD:
Christian@57497
   470
  assumes "list_emb P (xs @ ys) zs"
Christian@57497
   471
  shows "\<exists>us vs. zs = us @ vs \<and> list_emb P xs us \<and> list_emb P ys vs"
Christian@49087
   472
using assms
Christian@49087
   473
proof (induction xs arbitrary: ys zs)
wenzelm@49107
   474
  case Nil then show ?case by auto
Christian@49087
   475
next
Christian@49087
   476
  case (Cons x xs)
blanchet@54483
   477
  then obtain us v vs where
Christian@57498
   478
    zs: "zs = us @ v # vs" and p: "P x v" and lh: "list_emb P (xs @ ys) vs"
Christian@57497
   479
    by (auto dest: list_emb_ConsD)
blanchet@54483
   480
  obtain sk\<^sub>0 :: "'a list \<Rightarrow> 'a list \<Rightarrow> 'a list" and sk\<^sub>1 :: "'a list \<Rightarrow> 'a list \<Rightarrow> 'a list" where
Christian@57497
   481
    sk: "\<forall>x\<^sub>0 x\<^sub>1. \<not> list_emb P (xs @ x\<^sub>0) x\<^sub>1 \<or> sk\<^sub>0 x\<^sub>0 x\<^sub>1 @ sk\<^sub>1 x\<^sub>0 x\<^sub>1 = x\<^sub>1 \<and> list_emb P xs (sk\<^sub>0 x\<^sub>0 x\<^sub>1) \<and> list_emb P x\<^sub>0 (sk\<^sub>1 x\<^sub>0 x\<^sub>1)"
blanchet@54483
   482
    using Cons(1) by (metis (no_types))
Christian@57497
   483
  hence "\<forall>x\<^sub>2. list_emb P (x # xs) (x\<^sub>2 @ v # sk\<^sub>0 ys vs)" using p lh by auto
blanchet@54483
   484
  thus ?case using lh zs sk by (metis (no_types) append_Cons append_assoc)
Christian@49087
   485
qed
Christian@49087
   486
nipkow@63149
   487
lemma list_emb_strict_suffix:
nipkow@63149
   488
  assumes "list_emb P xs ys" and "strict_suffix ys zs"
nipkow@63149
   489
  shows "list_emb P xs zs"
nipkow@63149
   490
  using assms(2) and list_emb_append2 [OF assms(1)] by (auto simp: strict_suffix_def)
nipkow@63149
   491
Christian@57497
   492
lemma list_emb_suffix:
Christian@57497
   493
  assumes "list_emb P xs ys" and "suffix ys zs"
Christian@57497
   494
  shows "list_emb P xs zs"
nipkow@63149
   495
using assms and list_emb_strict_suffix
nipkow@63149
   496
unfolding strict_suffix_reflclp_conv[symmetric] by auto
Christian@49087
   497
Christian@57497
   498
lemma list_emb_length: "list_emb P xs ys \<Longrightarrow> length xs \<le> length ys"
Christian@57497
   499
  by (induct rule: list_emb.induct) auto
Christian@49087
   500
Christian@57497
   501
lemma list_emb_trans:
Christian@57500
   502
  assumes "\<And>x y z. \<lbrakk>x \<in> set xs; y \<in> set ys; z \<in> set zs; P x y; P y z\<rbrakk> \<Longrightarrow> P x z"
Christian@57500
   503
  shows "\<lbrakk>list_emb P xs ys; list_emb P ys zs\<rbrakk> \<Longrightarrow> list_emb P xs zs"
Christian@50516
   504
proof -
Christian@57497
   505
  assume "list_emb P xs ys" and "list_emb P ys zs"
Christian@57500
   506
  then show "list_emb P xs zs" using assms
Christian@49087
   507
  proof (induction arbitrary: zs)
Christian@57497
   508
    case list_emb_Nil show ?case by blast
Christian@49087
   509
  next
Christian@57497
   510
    case (list_emb_Cons xs ys y)
wenzelm@60500
   511
    from list_emb_ConsD [OF \<open>list_emb P (y#ys) zs\<close>] obtain us v vs
Christian@57500
   512
      where zs: "zs = us @ v # vs" and "P\<^sup>=\<^sup>= y v" and "list_emb P ys vs" by blast
Christian@57497
   513
    then have "list_emb P ys (v#vs)" by blast
Christian@57497
   514
    then have "list_emb P ys zs" unfolding zs by (rule list_emb_append2)
Christian@57500
   515
    from list_emb_Cons.IH [OF this] and list_emb_Cons.prems show ?case by auto
Christian@49087
   516
  next
Christian@57497
   517
    case (list_emb_Cons2 x y xs ys)
wenzelm@60500
   518
    from list_emb_ConsD [OF \<open>list_emb P (y#ys) zs\<close>] obtain us v vs
Christian@57498
   519
      where zs: "zs = us @ v # vs" and "P y v" and "list_emb P ys vs" by blast
Christian@57500
   520
    with list_emb_Cons2 have "list_emb P xs vs" by auto
Christian@57498
   521
    moreover have "P x v"
Christian@49087
   522
    proof -
Christian@57500
   523
      from zs have "v \<in> set zs" by auto
Christian@57500
   524
      moreover have "x \<in> set (x#xs)" and "y \<in> set (y#ys)" by simp_all
Christian@50516
   525
      ultimately show ?thesis
wenzelm@60500
   526
        using \<open>P x y\<close> and \<open>P y v\<close> and list_emb_Cons2
Christian@50516
   527
        by blast
Christian@49087
   528
    qed
Christian@57497
   529
    ultimately have "list_emb P (x#xs) (v#vs)" by blast
Christian@57497
   530
    then show ?case unfolding zs by (rule list_emb_append2)
Christian@49087
   531
  qed
Christian@49087
   532
qed
Christian@49087
   533
Christian@57500
   534
lemma list_emb_set:
Christian@57500
   535
  assumes "list_emb P xs ys" and "x \<in> set xs"
Christian@57500
   536
  obtains y where "y \<in> set ys" and "P x y"
Christian@57500
   537
  using assms by (induct) auto
Christian@57500
   538
Christian@49087
   539
wenzelm@60500
   540
subsection \<open>Sublists (special case of homeomorphic embedding)\<close>
Christian@49087
   541
Christian@50516
   542
abbreviation sublisteq :: "'a list \<Rightarrow> 'a list \<Rightarrow> bool"
Christian@57497
   543
  where "sublisteq xs ys \<equiv> list_emb (op =) xs ys"
Christian@49087
   544
Christian@50516
   545
lemma sublisteq_Cons2: "sublisteq xs ys \<Longrightarrow> sublisteq (x#xs) (x#ys)" by auto
Christian@49087
   546
Christian@50516
   547
lemma sublisteq_same_length:
Christian@50516
   548
  assumes "sublisteq xs ys" and "length xs = length ys" shows "xs = ys"
Christian@57497
   549
  using assms by (induct) (auto dest: list_emb_length)
Christian@49087
   550
Christian@50516
   551
lemma not_sublisteq_length [simp]: "length ys < length xs \<Longrightarrow> \<not> sublisteq xs ys"
Christian@57497
   552
  by (metis list_emb_length linorder_not_less)
Christian@49087
   553
Christian@49087
   554
lemma [code]:
Christian@57497
   555
  "list_emb P [] ys \<longleftrightarrow> True"
Christian@57497
   556
  "list_emb P (x#xs) [] \<longleftrightarrow> False"
Christian@49087
   557
  by (simp_all)
Christian@49087
   558
Christian@50516
   559
lemma sublisteq_Cons': "sublisteq (x#xs) ys \<Longrightarrow> sublisteq xs ys"
Christian@57497
   560
  by (induct xs, simp, blast dest: list_emb_ConsD)
Christian@49087
   561
Christian@50516
   562
lemma sublisteq_Cons2':
Christian@50516
   563
  assumes "sublisteq (x#xs) (x#ys)" shows "sublisteq xs ys"
Christian@50516
   564
  using assms by (cases) (rule sublisteq_Cons')
Christian@49087
   565
Christian@50516
   566
lemma sublisteq_Cons2_neq:
Christian@50516
   567
  assumes "sublisteq (x#xs) (y#ys)"
Christian@50516
   568
  shows "x \<noteq> y \<Longrightarrow> sublisteq (x#xs) ys"
Christian@49087
   569
  using assms by (cases) auto
Christian@49087
   570
Christian@50516
   571
lemma sublisteq_Cons2_iff [simp, code]:
Christian@50516
   572
  "sublisteq (x#xs) (y#ys) = (if x = y then sublisteq xs ys else sublisteq (x#xs) ys)"
Christian@57497
   573
  by (metis list_emb_Cons sublisteq_Cons2 sublisteq_Cons2' sublisteq_Cons2_neq)
Christian@49087
   574
Christian@50516
   575
lemma sublisteq_append': "sublisteq (zs @ xs) (zs @ ys) \<longleftrightarrow> sublisteq xs ys"
Christian@49087
   576
  by (induct zs) simp_all
Christian@49087
   577
Christian@50516
   578
lemma sublisteq_refl [simp, intro!]: "sublisteq xs xs" by (induct xs) simp_all
Christian@49087
   579
Christian@50516
   580
lemma sublisteq_antisym:
Christian@50516
   581
  assumes "sublisteq xs ys" and "sublisteq ys xs"
Christian@49087
   582
  shows "xs = ys"
Christian@49087
   583
using assms
Christian@49087
   584
proof (induct)
Christian@57497
   585
  case list_emb_Nil
Christian@57497
   586
  from list_emb_Nil2 [OF this] show ?case by simp
Christian@49087
   587
next
Christian@57497
   588
  case list_emb_Cons2
blanchet@54483
   589
  thus ?case by simp
Christian@49087
   590
next
Christian@57497
   591
  case list_emb_Cons
blanchet@54483
   592
  hence False using sublisteq_Cons' by fastforce
blanchet@54483
   593
  thus ?case ..
Christian@49087
   594
qed
Christian@49087
   595
Christian@50516
   596
lemma sublisteq_trans: "sublisteq xs ys \<Longrightarrow> sublisteq ys zs \<Longrightarrow> sublisteq xs zs"
Christian@57500
   597
  by (rule list_emb_trans [of _ _ _ "op ="]) auto
Christian@49087
   598
Christian@50516
   599
lemma sublisteq_append_le_same_iff: "sublisteq (xs @ ys) ys \<longleftrightarrow> xs = []"
Christian@57497
   600
  by (auto dest: list_emb_length)
Christian@49087
   601
Christian@57497
   602
lemma list_emb_append_mono:
Christian@57497
   603
  "\<lbrakk> list_emb P xs xs'; list_emb P ys ys' \<rbrakk> \<Longrightarrow> list_emb P (xs@ys) (xs'@ys')"
Christian@57497
   604
  apply (induct rule: list_emb.induct)
Christian@57497
   605
    apply (metis eq_Nil_appendI list_emb_append2)
Christian@57497
   606
   apply (metis append_Cons list_emb_Cons)
Christian@57497
   607
  apply (metis append_Cons list_emb_Cons2)
wenzelm@49107
   608
  done
Christian@49087
   609
Christian@49087
   610
wenzelm@60500
   611
subsection \<open>Appending elements\<close>
Christian@49087
   612
Christian@50516
   613
lemma sublisteq_append [simp]:
Christian@50516
   614
  "sublisteq (xs @ zs) (ys @ zs) \<longleftrightarrow> sublisteq xs ys" (is "?l = ?r")
Christian@49087
   615
proof
Christian@50516
   616
  { fix xs' ys' xs ys zs :: "'a list" assume "sublisteq xs' ys'"
Christian@50516
   617
    then have "xs' = xs @ zs & ys' = ys @ zs \<longrightarrow> sublisteq xs ys"
Christian@49087
   618
    proof (induct arbitrary: xs ys zs)
Christian@57497
   619
      case list_emb_Nil show ?case by simp
Christian@49087
   620
    next
Christian@57497
   621
      case (list_emb_Cons xs' ys' x)
Christian@57497
   622
      { assume "ys=[]" then have ?case using list_emb_Cons(1) by auto }
Christian@49087
   623
      moreover
Christian@49087
   624
      { fix us assume "ys = x#us"
Christian@57497
   625
        then have ?case using list_emb_Cons(2) by(simp add: list_emb.list_emb_Cons) }
Christian@49087
   626
      ultimately show ?case by (auto simp:Cons_eq_append_conv)
Christian@49087
   627
    next
Christian@57497
   628
      case (list_emb_Cons2 x y xs' ys')
Christian@57497
   629
      { assume "xs=[]" then have ?case using list_emb_Cons2(1) by auto }
Christian@49087
   630
      moreover
Christian@57497
   631
      { fix us vs assume "xs=x#us" "ys=x#vs" then have ?case using list_emb_Cons2 by auto}
Christian@49087
   632
      moreover
Christian@57497
   633
      { fix us assume "xs=x#us" "ys=[]" then have ?case using list_emb_Cons2(2) by bestsimp }
wenzelm@60500
   634
      ultimately show ?case using \<open>op = x y\<close> by (auto simp: Cons_eq_append_conv)
Christian@49087
   635
    qed }
Christian@49087
   636
  moreover assume ?l
Christian@49087
   637
  ultimately show ?r by blast
Christian@49087
   638
next
Christian@57497
   639
  assume ?r then show ?l by (metis list_emb_append_mono sublisteq_refl)
Christian@49087
   640
qed
Christian@49087
   641
Christian@50516
   642
lemma sublisteq_drop_many: "sublisteq xs ys \<Longrightarrow> sublisteq xs (zs @ ys)"
Christian@49087
   643
  by (induct zs) auto
Christian@49087
   644
Christian@50516
   645
lemma sublisteq_rev_drop_many: "sublisteq xs ys \<Longrightarrow> sublisteq xs (ys @ zs)"
Christian@57497
   646
  by (metis append_Nil2 list_emb_Nil list_emb_append_mono)
Christian@49087
   647
Christian@49087
   648
wenzelm@60500
   649
subsection \<open>Relation to standard list operations\<close>
Christian@49087
   650
Christian@50516
   651
lemma sublisteq_map:
Christian@50516
   652
  assumes "sublisteq xs ys" shows "sublisteq (map f xs) (map f ys)"
Christian@49087
   653
  using assms by (induct) auto
Christian@49087
   654
Christian@50516
   655
lemma sublisteq_filter_left [simp]: "sublisteq (filter P xs) xs"
Christian@49087
   656
  by (induct xs) auto
Christian@49087
   657
Christian@50516
   658
lemma sublisteq_filter [simp]:
Christian@50516
   659
  assumes "sublisteq xs ys" shows "sublisteq (filter P xs) (filter P ys)"
blanchet@54483
   660
  using assms by induct auto
Christian@49087
   661
Christian@50516
   662
lemma "sublisteq xs ys \<longleftrightarrow> (\<exists>N. xs = sublist ys N)" (is "?L = ?R")
Christian@49087
   663
proof
Christian@49087
   664
  assume ?L
wenzelm@49107
   665
  then show ?R
Christian@49087
   666
  proof (induct)
Christian@57497
   667
    case list_emb_Nil show ?case by (metis sublist_empty)
Christian@49087
   668
  next
Christian@57497
   669
    case (list_emb_Cons xs ys x)
Christian@49087
   670
    then obtain N where "xs = sublist ys N" by blast
wenzelm@49107
   671
    then have "xs = sublist (x#ys) (Suc ` N)"
Christian@49087
   672
      by (clarsimp simp add:sublist_Cons inj_image_mem_iff)
wenzelm@49107
   673
    then show ?case by blast
Christian@49087
   674
  next
Christian@57497
   675
    case (list_emb_Cons2 x y xs ys)
Christian@49087
   676
    then obtain N where "xs = sublist ys N" by blast
wenzelm@49107
   677
    then have "x#xs = sublist (x#ys) (insert 0 (Suc ` N))"
Christian@49087
   678
      by (clarsimp simp add:sublist_Cons inj_image_mem_iff)
Christian@57497
   679
    moreover from list_emb_Cons2 have "x = y" by simp
Christian@50516
   680
    ultimately show ?case by blast
Christian@49087
   681
  qed
Christian@49087
   682
next
Christian@49087
   683
  assume ?R
Christian@49087
   684
  then obtain N where "xs = sublist ys N" ..
Christian@50516
   685
  moreover have "sublisteq (sublist ys N) ys"
wenzelm@49107
   686
  proof (induct ys arbitrary: N)
Christian@49087
   687
    case Nil show ?case by simp
Christian@49087
   688
  next
wenzelm@49107
   689
    case Cons then show ?case by (auto simp: sublist_Cons)
Christian@49087
   690
  qed
Christian@49087
   691
  ultimately show ?L by simp
Christian@49087
   692
qed
Christian@49087
   693
wenzelm@10330
   694
end