src/HOL/Library/Sublist.thy
author Christian Sternagel
Wed Aug 29 10:46:11 2012 +0900 (2012-08-29)
changeset 49079 919e393510f4
parent 45236 src/HOL/Library/List_Prefix.thy@ac4a2a66707d
permissions -rw-r--r--
renamed (in Sublist): postfix ~> suffixeq, and dropped infix syntax >>=
Christian@49079
     1
(*  Title:      HOL/Library/Sublist.thy
wenzelm@10330
     2
    Author:     Tobias Nipkow and Markus Wenzel, TU Muenchen
wenzelm@10330
     3
*)
wenzelm@10330
     4
Christian@49079
     5
header {* List prefixes, suffixes, and embedding*}
wenzelm@10330
     6
Christian@49079
     7
theory Sublist
haftmann@30663
     8
imports List Main
nipkow@15131
     9
begin
wenzelm@10330
    10
wenzelm@10330
    11
subsection {* Prefix order on lists *}
wenzelm@10330
    12
haftmann@37474
    13
instantiation list :: (type) "{order, bot}"
haftmann@25764
    14
begin
haftmann@25764
    15
haftmann@25764
    16
definition
Christian@49079
    17
  prefixeq_def: "xs \<le> ys \<longleftrightarrow> (\<exists>zs. ys = xs @ zs)"
wenzelm@10330
    18
haftmann@25764
    19
definition
Christian@49079
    20
  prefix_def: "xs < ys \<longleftrightarrow> xs \<le> ys \<and> xs \<noteq> (ys::'a list)"
wenzelm@10330
    21
haftmann@37474
    22
definition
haftmann@37474
    23
  "bot = []"
haftmann@37474
    24
haftmann@37474
    25
instance proof
Christian@49079
    26
qed (auto simp add: prefixeq_def prefix_def bot_list_def)
wenzelm@10330
    27
haftmann@25764
    28
end
haftmann@25764
    29
Christian@49079
    30
lemma prefixeqI [intro?]: "ys = xs @ zs ==> xs \<le> ys"
Christian@49079
    31
  unfolding prefixeq_def by blast
wenzelm@10330
    32
Christian@49079
    33
lemma prefixeqE [elim?]:
wenzelm@21305
    34
  assumes "xs \<le> ys"
wenzelm@21305
    35
  obtains zs where "ys = xs @ zs"
Christian@49079
    36
  using assms unfolding prefixeq_def by blast
wenzelm@10330
    37
Christian@49079
    38
lemma prefixI' [intro?]: "ys = xs @ z # zs ==> xs < ys"
Christian@49079
    39
  unfolding prefix_def prefixeq_def by blast
wenzelm@10870
    40
Christian@49079
    41
lemma prefixE' [elim?]:
wenzelm@21305
    42
  assumes "xs < ys"
wenzelm@21305
    43
  obtains z zs where "ys = xs @ z # zs"
wenzelm@10870
    44
proof -
wenzelm@21305
    45
  from `xs < ys` obtain us where "ys = xs @ us" and "xs \<noteq> ys"
Christian@49079
    46
    unfolding prefix_def prefixeq_def by blast
wenzelm@21305
    47
  with that show ?thesis by (auto simp add: neq_Nil_conv)
wenzelm@10870
    48
qed
wenzelm@10870
    49
Christian@49079
    50
lemma prefixI [intro?]: "xs \<le> ys ==> xs \<noteq> ys ==> xs < (ys::'a list)"
Christian@49079
    51
  unfolding prefix_def by blast
wenzelm@10330
    52
Christian@49079
    53
lemma prefixE [elim?]:
wenzelm@21305
    54
  fixes xs ys :: "'a list"
wenzelm@21305
    55
  assumes "xs < ys"
wenzelm@21305
    56
  obtains "xs \<le> ys" and "xs \<noteq> ys"
Christian@49079
    57
  using assms unfolding prefix_def by blast
wenzelm@10330
    58
wenzelm@10330
    59
wenzelm@10389
    60
subsection {* Basic properties of prefixes *}
wenzelm@10330
    61
Christian@49079
    62
theorem Nil_prefixeq [iff]: "[] \<le> xs"
Christian@49079
    63
  by (simp add: prefixeq_def)
wenzelm@10330
    64
Christian@49079
    65
theorem prefixeq_Nil [simp]: "(xs \<le> []) = (xs = [])"
Christian@49079
    66
  by (induct xs) (simp_all add: prefixeq_def)
wenzelm@10330
    67
Christian@49079
    68
lemma prefixeq_snoc [simp]: "(xs \<le> ys @ [y]) = (xs = ys @ [y] \<or> xs \<le> ys)"
wenzelm@10389
    69
proof
wenzelm@10389
    70
  assume "xs \<le> ys @ [y]"
wenzelm@10389
    71
  then obtain zs where zs: "ys @ [y] = xs @ zs" ..
wenzelm@10389
    72
  show "xs = ys @ [y] \<or> xs \<le> ys"
Christian@49079
    73
    by (metis append_Nil2 butlast_append butlast_snoc prefixeqI zs)
wenzelm@10389
    74
next
wenzelm@10389
    75
  assume "xs = ys @ [y] \<or> xs \<le> ys"
wenzelm@23254
    76
  then show "xs \<le> ys @ [y]"
Christian@49079
    77
    by (metis order_eq_iff order_trans prefixeqI)
wenzelm@10389
    78
qed
wenzelm@10330
    79
Christian@49079
    80
lemma Cons_prefixeq_Cons [simp]: "(x # xs \<le> y # ys) = (x = y \<and> xs \<le> ys)"
Christian@49079
    81
  by (auto simp add: prefixeq_def)
wenzelm@10330
    82
haftmann@37474
    83
lemma less_eq_list_code [code]:
haftmann@38857
    84
  "([]\<Colon>'a\<Colon>{equal, ord} list) \<le> xs \<longleftrightarrow> True"
haftmann@38857
    85
  "(x\<Colon>'a\<Colon>{equal, ord}) # xs \<le> [] \<longleftrightarrow> False"
haftmann@38857
    86
  "(x\<Colon>'a\<Colon>{equal, ord}) # xs \<le> y # ys \<longleftrightarrow> x = y \<and> xs \<le> ys"
haftmann@37474
    87
  by simp_all
haftmann@37474
    88
Christian@49079
    89
lemma same_prefixeq_prefixeq [simp]: "(xs @ ys \<le> xs @ zs) = (ys \<le> zs)"
wenzelm@10389
    90
  by (induct xs) simp_all
wenzelm@10330
    91
Christian@49079
    92
lemma same_prefixeq_nil [iff]: "(xs @ ys \<le> xs) = (ys = [])"
Christian@49079
    93
  by (metis append_Nil2 append_self_conv order_eq_iff prefixeqI)
nipkow@25665
    94
Christian@49079
    95
lemma prefixeq_prefixeq [simp]: "xs \<le> ys ==> xs \<le> ys @ zs"
Christian@49079
    96
  by (metis order_le_less_trans prefixeqI prefixE prefixI)
nipkow@25665
    97
Christian@49079
    98
lemma append_prefixeqD: "xs @ ys \<le> zs \<Longrightarrow> xs \<le> zs"
Christian@49079
    99
  by (auto simp add: prefixeq_def)
nipkow@14300
   100
Christian@49079
   101
theorem prefixeq_Cons: "(xs \<le> y # ys) = (xs = [] \<or> (\<exists>zs. xs = y # zs \<and> zs \<le> ys))"
Christian@49079
   102
  by (cases xs) (auto simp add: prefixeq_def)
wenzelm@10330
   103
Christian@49079
   104
theorem prefixeq_append:
nipkow@25564
   105
  "(xs \<le> ys @ zs) = (xs \<le> ys \<or> (\<exists>us. xs = ys @ us \<and> us \<le> zs))"
wenzelm@10330
   106
  apply (induct zs rule: rev_induct)
wenzelm@10330
   107
   apply force
wenzelm@10330
   108
  apply (simp del: append_assoc add: append_assoc [symmetric])
nipkow@25564
   109
  apply (metis append_eq_appendI)
wenzelm@10330
   110
  done
wenzelm@10330
   111
Christian@49079
   112
lemma append_one_prefixeq:
nipkow@25564
   113
  "xs \<le> ys ==> length xs < length ys ==> xs @ [ys ! length xs] \<le> ys"
Christian@49079
   114
  unfolding prefixeq_def
wenzelm@25692
   115
  by (metis Cons_eq_appendI append_eq_appendI append_eq_conv_conj
wenzelm@25692
   116
    eq_Nil_appendI nth_drop')
nipkow@25665
   117
Christian@49079
   118
theorem prefixeq_length_le: "xs \<le> ys ==> length xs \<le> length ys"
Christian@49079
   119
  by (auto simp add: prefixeq_def)
wenzelm@10330
   120
Christian@49079
   121
lemma prefixeq_same_cases:
nipkow@25564
   122
  "(xs\<^isub>1::'a list) \<le> ys \<Longrightarrow> xs\<^isub>2 \<le> ys \<Longrightarrow> xs\<^isub>1 \<le> xs\<^isub>2 \<or> xs\<^isub>2 \<le> xs\<^isub>1"
Christian@49079
   123
  unfolding prefixeq_def by (metis append_eq_append_conv2)
nipkow@25665
   124
Christian@49079
   125
lemma set_mono_prefixeq: "xs \<le> ys \<Longrightarrow> set xs \<subseteq> set ys"
Christian@49079
   126
  by (auto simp add: prefixeq_def)
nipkow@14300
   127
Christian@49079
   128
lemma take_is_prefixeq: "take n xs \<le> xs"
Christian@49079
   129
  unfolding prefixeq_def by (metis append_take_drop_id)
nipkow@25665
   130
Christian@49079
   131
lemma map_prefixeqI: "xs \<le> ys \<Longrightarrow> map f xs \<le> map f ys"
Christian@49079
   132
  by (auto simp: prefixeq_def)
kleing@25322
   133
Christian@49079
   134
lemma prefixeq_length_less: "xs < ys \<Longrightarrow> length xs < length ys"
Christian@49079
   135
  by (auto simp: prefix_def prefixeq_def)
nipkow@25665
   136
Christian@49079
   137
lemma prefix_simps [simp, code]:
haftmann@37474
   138
  "xs < [] \<longleftrightarrow> False"
haftmann@37474
   139
  "[] < x # xs \<longleftrightarrow> True"
haftmann@37474
   140
  "x # xs < y # ys \<longleftrightarrow> x = y \<and> xs < ys"
Christian@49079
   141
  by (simp_all add: prefix_def cong: conj_cong)
kleing@25299
   142
Christian@49079
   143
lemma take_prefix: "xs < ys \<Longrightarrow> take n xs < ys"
wenzelm@25692
   144
  apply (induct n arbitrary: xs ys)
wenzelm@25692
   145
   apply (case_tac ys, simp_all)[1]
Christian@49079
   146
  apply (metis order_less_trans prefixI take_is_prefixeq)
wenzelm@25692
   147
  done
kleing@25299
   148
Christian@49079
   149
lemma not_prefixeq_cases:
kleing@25299
   150
  assumes pfx: "\<not> ps \<le> ls"
wenzelm@25356
   151
  obtains
wenzelm@25356
   152
    (c1) "ps \<noteq> []" and "ls = []"
wenzelm@25356
   153
  | (c2) a as x xs where "ps = a#as" and "ls = x#xs" and "x = a" and "\<not> as \<le> xs"
wenzelm@25356
   154
  | (c3) a as x xs where "ps = a#as" and "ls = x#xs" and "x \<noteq> a"
kleing@25299
   155
proof (cases ps)
wenzelm@25692
   156
  case Nil then show ?thesis using pfx by simp
kleing@25299
   157
next
kleing@25299
   158
  case (Cons a as)
wenzelm@25692
   159
  note c = `ps = a#as`
kleing@25299
   160
  show ?thesis
kleing@25299
   161
  proof (cases ls)
Christian@49079
   162
    case Nil then show ?thesis by (metis append_Nil2 pfx c1 same_prefixeq_nil)
kleing@25299
   163
  next
kleing@25299
   164
    case (Cons x xs)
kleing@25299
   165
    show ?thesis
kleing@25299
   166
    proof (cases "x = a")
wenzelm@25355
   167
      case True
wenzelm@25355
   168
      have "\<not> as \<le> xs" using pfx c Cons True by simp
wenzelm@25355
   169
      with c Cons True show ?thesis by (rule c2)
wenzelm@25355
   170
    next
wenzelm@25355
   171
      case False
wenzelm@25355
   172
      with c Cons show ?thesis by (rule c3)
kleing@25299
   173
    qed
kleing@25299
   174
  qed
kleing@25299
   175
qed
kleing@25299
   176
Christian@49079
   177
lemma not_prefixeq_induct [consumes 1, case_names Nil Neq Eq]:
kleing@25299
   178
  assumes np: "\<not> ps \<le> ls"
wenzelm@25356
   179
    and base: "\<And>x xs. P (x#xs) []"
wenzelm@25356
   180
    and r1: "\<And>x xs y ys. x \<noteq> y \<Longrightarrow> P (x#xs) (y#ys)"
wenzelm@25356
   181
    and r2: "\<And>x xs y ys. \<lbrakk> x = y; \<not> xs \<le> ys; P xs ys \<rbrakk> \<Longrightarrow> P (x#xs) (y#ys)"
wenzelm@25356
   182
  shows "P ps ls" using np
kleing@25299
   183
proof (induct ls arbitrary: ps)
wenzelm@25355
   184
  case Nil then show ?case
Christian@49079
   185
    by (auto simp: neq_Nil_conv elim!: not_prefixeq_cases intro!: base)
kleing@25299
   186
next
wenzelm@25355
   187
  case (Cons y ys)
wenzelm@25355
   188
  then have npfx: "\<not> ps \<le> (y # ys)" by simp
wenzelm@25355
   189
  then obtain x xs where pv: "ps = x # xs"
Christian@49079
   190
    by (rule not_prefixeq_cases) auto
Christian@49079
   191
  show ?case by (metis Cons.hyps Cons_prefixeq_Cons npfx pv r1 r2)
kleing@25299
   192
qed
nipkow@14300
   193
wenzelm@25356
   194
wenzelm@10389
   195
subsection {* Parallel lists *}
wenzelm@10389
   196
wenzelm@19086
   197
definition
wenzelm@21404
   198
  parallel :: "'a list => 'a list => bool"  (infixl "\<parallel>" 50) where
wenzelm@19086
   199
  "(xs \<parallel> ys) = (\<not> xs \<le> ys \<and> \<not> ys \<le> xs)"
wenzelm@10389
   200
wenzelm@10389
   201
lemma parallelI [intro]: "\<not> xs \<le> ys ==> \<not> ys \<le> xs ==> xs \<parallel> ys"
wenzelm@25692
   202
  unfolding parallel_def by blast
wenzelm@10330
   203
wenzelm@10389
   204
lemma parallelE [elim]:
wenzelm@25692
   205
  assumes "xs \<parallel> ys"
wenzelm@25692
   206
  obtains "\<not> xs \<le> ys \<and> \<not> ys \<le> xs"
wenzelm@25692
   207
  using assms unfolding parallel_def by blast
wenzelm@10330
   208
Christian@49079
   209
theorem prefixeq_cases:
wenzelm@25692
   210
  obtains "xs \<le> ys" | "ys < xs" | "xs \<parallel> ys"
Christian@49079
   211
  unfolding parallel_def prefix_def by blast
wenzelm@10330
   212
wenzelm@10389
   213
theorem parallel_decomp:
wenzelm@10389
   214
  "xs \<parallel> ys ==> \<exists>as b bs c cs. b \<noteq> c \<and> xs = as @ b # bs \<and> ys = as @ c # cs"
wenzelm@10408
   215
proof (induct xs rule: rev_induct)
wenzelm@11987
   216
  case Nil
wenzelm@23254
   217
  then have False by auto
wenzelm@23254
   218
  then show ?case ..
wenzelm@10408
   219
next
wenzelm@11987
   220
  case (snoc x xs)
wenzelm@11987
   221
  show ?case
Christian@49079
   222
  proof (rule prefixeq_cases)
wenzelm@10408
   223
    assume le: "xs \<le> ys"
wenzelm@10408
   224
    then obtain ys' where ys: "ys = xs @ ys'" ..
wenzelm@10408
   225
    show ?thesis
wenzelm@10408
   226
    proof (cases ys')
nipkow@25564
   227
      assume "ys' = []"
Christian@49079
   228
      then show ?thesis by (metis append_Nil2 parallelE prefixeqI snoc.prems ys)
wenzelm@10389
   229
    next
wenzelm@10408
   230
      fix c cs assume ys': "ys' = c # cs"
wenzelm@25692
   231
      then show ?thesis
Christian@49079
   232
        by (metis Cons_eq_appendI eq_Nil_appendI parallelE prefixeqI
Christian@49079
   233
          same_prefixeq_prefixeq snoc.prems ys)
wenzelm@10389
   234
    qed
wenzelm@10408
   235
  next
Christian@49079
   236
    assume "ys < xs" then have "ys \<le> xs @ [x]" by (simp add: prefix_def)
wenzelm@11987
   237
    with snoc have False by blast
wenzelm@23254
   238
    then show ?thesis ..
wenzelm@10408
   239
  next
wenzelm@10408
   240
    assume "xs \<parallel> ys"
wenzelm@11987
   241
    with snoc obtain as b bs c cs where neq: "(b::'a) \<noteq> c"
wenzelm@10408
   242
      and xs: "xs = as @ b # bs" and ys: "ys = as @ c # cs"
wenzelm@10408
   243
      by blast
wenzelm@10408
   244
    from xs have "xs @ [x] = as @ b # (bs @ [x])" by simp
wenzelm@10408
   245
    with neq ys show ?thesis by blast
wenzelm@10389
   246
  qed
wenzelm@10389
   247
qed
wenzelm@10330
   248
nipkow@25564
   249
lemma parallel_append: "a \<parallel> b \<Longrightarrow> a @ c \<parallel> b @ d"
wenzelm@25692
   250
  apply (rule parallelI)
wenzelm@25692
   251
    apply (erule parallelE, erule conjE,
Christian@49079
   252
      induct rule: not_prefixeq_induct, simp+)+
wenzelm@25692
   253
  done
kleing@25299
   254
wenzelm@25692
   255
lemma parallel_appendI: "xs \<parallel> ys \<Longrightarrow> x = xs @ xs' \<Longrightarrow> y = ys @ ys' \<Longrightarrow> x \<parallel> y"
wenzelm@25692
   256
  by (simp add: parallel_append)
kleing@25299
   257
wenzelm@25692
   258
lemma parallel_commute: "a \<parallel> b \<longleftrightarrow> b \<parallel> a"
wenzelm@25692
   259
  unfolding parallel_def by auto
oheimb@14538
   260
wenzelm@25356
   261
Christian@49079
   262
subsection {* Suffix order on lists *}
wenzelm@17201
   263
wenzelm@19086
   264
definition
Christian@49079
   265
  suffixeq :: "'a list => 'a list => bool" where
Christian@49079
   266
  "suffixeq xs ys = (\<exists>zs. xs = zs @ ys)"
oheimb@14538
   267
Christian@49079
   268
lemma suffixeqI [intro?]: "xs = zs @ ys ==> suffixeq xs ys"
Christian@49079
   269
  unfolding suffixeq_def by blast
wenzelm@21305
   270
Christian@49079
   271
lemma suffixeqE [elim?]:
Christian@49079
   272
  assumes "suffixeq xs ys"
wenzelm@25692
   273
  obtains zs where "xs = zs @ ys"
Christian@49079
   274
  using assms unfolding suffixeq_def by blast
wenzelm@21305
   275
Christian@49079
   276
lemma suffixeq_refl [iff]: "suffixeq xs xs"
Christian@49079
   277
  by (auto simp add: suffixeq_def)
Christian@49079
   278
lemma suffixeq_trans: "\<lbrakk>suffixeq xs ys; suffixeq ys zs\<rbrakk> \<Longrightarrow> suffixeq xs zs"
Christian@49079
   279
  by (auto simp add: suffixeq_def)
Christian@49079
   280
lemma suffixeq_antisym: "\<lbrakk>suffixeq xs ys; suffixeq ys xs\<rbrakk> \<Longrightarrow> xs = ys"
Christian@49079
   281
  by (auto simp add: suffixeq_def)
oheimb@14538
   282
Christian@49079
   283
lemma Nil_suffixeq [iff]: "suffixeq xs []"
Christian@49079
   284
  by (simp add: suffixeq_def)
Christian@49079
   285
lemma suffixeq_Nil [simp]: "(suffixeq [] xs) = (xs = [])"
Christian@49079
   286
  by (auto simp add: suffixeq_def)
oheimb@14538
   287
Christian@49079
   288
lemma suffixeq_ConsI: "suffixeq xs ys \<Longrightarrow> suffixeq (x#xs) ys"
Christian@49079
   289
  by (auto simp add: suffixeq_def)
Christian@49079
   290
lemma suffixeq_ConsD: "suffixeq xs (y#ys) \<Longrightarrow> suffixeq xs ys"
Christian@49079
   291
  by (auto simp add: suffixeq_def)
oheimb@14538
   292
Christian@49079
   293
lemma suffixeq_appendI: "suffixeq xs ys \<Longrightarrow> suffixeq (zs @ xs) ys"
Christian@49079
   294
  by (auto simp add: suffixeq_def)
Christian@49079
   295
lemma suffixeq_appendD: "suffixeq xs (zs @ ys) \<Longrightarrow> suffixeq xs ys"
Christian@49079
   296
  by (auto simp add: suffixeq_def)
oheimb@14538
   297
Christian@49079
   298
lemma suffixeq_is_subset: "suffixeq xs ys ==> set ys \<subseteq> set xs"
wenzelm@21305
   299
proof -
Christian@49079
   300
  assume "suffixeq xs ys"
wenzelm@21305
   301
  then obtain zs where "xs = zs @ ys" ..
wenzelm@21305
   302
  then show ?thesis by (induct zs) auto
wenzelm@21305
   303
qed
oheimb@14538
   304
Christian@49079
   305
lemma suffixeq_ConsD2: "suffixeq (x#xs) (y#ys) ==> suffixeq xs ys"
wenzelm@21305
   306
proof -
Christian@49079
   307
  assume "suffixeq (x#xs) (y#ys)"
wenzelm@21305
   308
  then obtain zs where "x#xs = zs @ y#ys" ..
wenzelm@21305
   309
  then show ?thesis
Christian@49079
   310
    by (induct zs) (auto intro!: suffixeq_appendI suffixeq_ConsI)
wenzelm@21305
   311
qed
oheimb@14538
   312
Christian@49079
   313
lemma suffixeq_to_prefixeq [code]: "suffixeq xs ys \<longleftrightarrow> rev ys \<le> rev xs"
wenzelm@21305
   314
proof
Christian@49079
   315
  assume "suffixeq xs ys"
wenzelm@21305
   316
  then obtain zs where "xs = zs @ ys" ..
wenzelm@21305
   317
  then have "rev xs = rev ys @ rev zs" by simp
wenzelm@21305
   318
  then show "rev ys <= rev xs" ..
wenzelm@21305
   319
next
wenzelm@21305
   320
  assume "rev ys <= rev xs"
wenzelm@21305
   321
  then obtain zs where "rev xs = rev ys @ zs" ..
wenzelm@21305
   322
  then have "rev (rev xs) = rev zs @ rev (rev ys)" by simp
wenzelm@21305
   323
  then have "xs = rev zs @ ys" by simp
Christian@49079
   324
  then show "suffixeq xs ys" ..
wenzelm@21305
   325
qed
wenzelm@17201
   326
Christian@49079
   327
lemma distinct_suffixeq: "distinct xs \<Longrightarrow> suffixeq xs ys \<Longrightarrow> distinct ys"
Christian@49079
   328
  by (clarsimp elim!: suffixeqE)
kleing@25299
   329
Christian@49079
   330
lemma suffixeq_map: "suffixeq xs ys \<Longrightarrow> suffixeq (map f xs) (map f ys)"
Christian@49079
   331
  by (auto elim!: suffixeqE intro: suffixeqI)
kleing@25299
   332
Christian@49079
   333
lemma suffixeq_drop: "suffixeq as (drop n as)"
Christian@49079
   334
  unfolding suffixeq_def
wenzelm@25692
   335
  apply (rule exI [where x = "take n as"])
wenzelm@25692
   336
  apply simp
wenzelm@25692
   337
  done
kleing@25299
   338
Christian@49079
   339
lemma suffixeq_take: "suffixeq xs ys \<Longrightarrow> xs = take (length xs - length ys) xs @ ys"
Christian@49079
   340
  by (clarsimp elim!: suffixeqE)
kleing@25299
   341
wenzelm@25356
   342
lemma parallelD1: "x \<parallel> y \<Longrightarrow> \<not> x \<le> y"
wenzelm@25692
   343
  by blast
kleing@25299
   344
wenzelm@25356
   345
lemma parallelD2: "x \<parallel> y \<Longrightarrow> \<not> y \<le> x"
wenzelm@25692
   346
  by blast
wenzelm@25355
   347
wenzelm@25355
   348
lemma parallel_Nil1 [simp]: "\<not> x \<parallel> []"
wenzelm@25692
   349
  unfolding parallel_def by simp
wenzelm@25355
   350
kleing@25299
   351
lemma parallel_Nil2 [simp]: "\<not> [] \<parallel> x"
wenzelm@25692
   352
  unfolding parallel_def by simp
kleing@25299
   353
nipkow@25564
   354
lemma Cons_parallelI1: "a \<noteq> b \<Longrightarrow> a # as \<parallel> b # bs"
wenzelm@25692
   355
  by auto
kleing@25299
   356
nipkow@25564
   357
lemma Cons_parallelI2: "\<lbrakk> a = b; as \<parallel> bs \<rbrakk> \<Longrightarrow> a # as \<parallel> b # bs"
Christian@49079
   358
  by (metis Cons_prefixeq_Cons parallelE parallelI)
nipkow@25665
   359
kleing@25299
   360
lemma not_equal_is_parallel:
kleing@25299
   361
  assumes neq: "xs \<noteq> ys"
wenzelm@25356
   362
    and len: "length xs = length ys"
wenzelm@25356
   363
  shows "xs \<parallel> ys"
kleing@25299
   364
  using len neq
wenzelm@25355
   365
proof (induct rule: list_induct2)
haftmann@26445
   366
  case Nil
wenzelm@25356
   367
  then show ?case by simp
kleing@25299
   368
next
haftmann@26445
   369
  case (Cons a as b bs)
wenzelm@25355
   370
  have ih: "as \<noteq> bs \<Longrightarrow> as \<parallel> bs" by fact
kleing@25299
   371
  show ?case
kleing@25299
   372
  proof (cases "a = b")
wenzelm@25355
   373
    case True
haftmann@26445
   374
    then have "as \<noteq> bs" using Cons by simp
wenzelm@25355
   375
    then show ?thesis by (rule Cons_parallelI2 [OF True ih])
kleing@25299
   376
  next
kleing@25299
   377
    case False
wenzelm@25355
   378
    then show ?thesis by (rule Cons_parallelI1)
kleing@25299
   379
  qed
kleing@25299
   380
qed
haftmann@22178
   381
wenzelm@10330
   382
end