src/HOL/Library/List_Prefix.thy
author nipkow
Mon Dec 17 17:01:54 2007 +0100 (2007-12-17)
changeset 25665 faabc08af882
parent 25595 6c48275f9c76
child 25692 eda4958ab0d2
permissions -rw-r--r--
removed legacy proofs
wenzelm@10330
     1
(*  Title:      HOL/Library/List_Prefix.thy
wenzelm@10330
     2
    ID:         $Id$
wenzelm@10330
     3
    Author:     Tobias Nipkow and Markus Wenzel, TU Muenchen
wenzelm@10330
     4
*)
wenzelm@10330
     5
wenzelm@14706
     6
header {* List prefixes and postfixes *}
wenzelm@10330
     7
nipkow@15131
     8
theory List_Prefix
haftmann@25595
     9
imports List
nipkow@15131
    10
begin
wenzelm@10330
    11
wenzelm@10330
    12
subsection {* Prefix order on lists *}
wenzelm@10330
    13
wenzelm@12338
    14
instance list :: (type) ord ..
wenzelm@10330
    15
wenzelm@10330
    16
defs (overloaded)
wenzelm@10389
    17
  prefix_def: "xs \<le> ys == \<exists>zs. ys = xs @ zs"
wenzelm@10389
    18
  strict_prefix_def: "xs < ys == xs \<le> ys \<and> xs \<noteq> (ys::'a list)"
wenzelm@10330
    19
wenzelm@12338
    20
instance list :: (type) order
wenzelm@10389
    21
  by intro_classes (auto simp add: prefix_def strict_prefix_def)
wenzelm@10330
    22
wenzelm@10389
    23
lemma prefixI [intro?]: "ys = xs @ zs ==> xs \<le> ys"
wenzelm@18730
    24
  unfolding prefix_def by blast
wenzelm@10330
    25
wenzelm@21305
    26
lemma prefixE [elim?]:
wenzelm@21305
    27
  assumes "xs \<le> ys"
wenzelm@21305
    28
  obtains zs where "ys = xs @ zs"
wenzelm@23394
    29
  using assms unfolding prefix_def by blast
wenzelm@10330
    30
wenzelm@10870
    31
lemma strict_prefixI' [intro?]: "ys = xs @ z # zs ==> xs < ys"
wenzelm@18730
    32
  unfolding strict_prefix_def prefix_def by blast
wenzelm@10870
    33
wenzelm@10870
    34
lemma strict_prefixE' [elim?]:
wenzelm@21305
    35
  assumes "xs < ys"
wenzelm@21305
    36
  obtains z zs where "ys = xs @ z # zs"
wenzelm@10870
    37
proof -
wenzelm@21305
    38
  from `xs < ys` obtain us where "ys = xs @ us" and "xs \<noteq> ys"
wenzelm@18730
    39
    unfolding strict_prefix_def prefix_def by blast
wenzelm@21305
    40
  with that show ?thesis by (auto simp add: neq_Nil_conv)
wenzelm@10870
    41
qed
wenzelm@10870
    42
wenzelm@10389
    43
lemma strict_prefixI [intro?]: "xs \<le> ys ==> xs \<noteq> ys ==> xs < (ys::'a list)"
wenzelm@18730
    44
  unfolding strict_prefix_def by blast
wenzelm@10330
    45
wenzelm@10389
    46
lemma strict_prefixE [elim?]:
wenzelm@21305
    47
  fixes xs ys :: "'a list"
wenzelm@21305
    48
  assumes "xs < ys"
wenzelm@21305
    49
  obtains "xs \<le> ys" and "xs \<noteq> ys"
wenzelm@23394
    50
  using assms unfolding strict_prefix_def by blast
wenzelm@10330
    51
wenzelm@10330
    52
wenzelm@10389
    53
subsection {* Basic properties of prefixes *}
wenzelm@10330
    54
wenzelm@10330
    55
theorem Nil_prefix [iff]: "[] \<le> xs"
wenzelm@10389
    56
  by (simp add: prefix_def)
wenzelm@10330
    57
wenzelm@10330
    58
theorem prefix_Nil [simp]: "(xs \<le> []) = (xs = [])"
wenzelm@10389
    59
  by (induct xs) (simp_all add: prefix_def)
wenzelm@10330
    60
wenzelm@10330
    61
lemma prefix_snoc [simp]: "(xs \<le> ys @ [y]) = (xs = ys @ [y] \<or> xs \<le> ys)"
wenzelm@10389
    62
proof
wenzelm@10389
    63
  assume "xs \<le> ys @ [y]"
wenzelm@10389
    64
  then obtain zs where zs: "ys @ [y] = xs @ zs" ..
wenzelm@10389
    65
  show "xs = ys @ [y] \<or> xs \<le> ys"
nipkow@25564
    66
    by (metis append_Nil2 butlast_append butlast_snoc prefixI zs)
wenzelm@10389
    67
next
wenzelm@10389
    68
  assume "xs = ys @ [y] \<or> xs \<le> ys"
wenzelm@23254
    69
  then show "xs \<le> ys @ [y]"
nipkow@25564
    70
    by (metis order_eq_iff strict_prefixE strict_prefixI' xt1(7))
wenzelm@10389
    71
qed
wenzelm@10330
    72
wenzelm@10330
    73
lemma Cons_prefix_Cons [simp]: "(x # xs \<le> y # ys) = (x = y \<and> xs \<le> ys)"
wenzelm@10389
    74
  by (auto simp add: prefix_def)
wenzelm@10330
    75
wenzelm@10330
    76
lemma same_prefix_prefix [simp]: "(xs @ ys \<le> xs @ zs) = (ys \<le> zs)"
wenzelm@10389
    77
  by (induct xs) simp_all
wenzelm@10330
    78
wenzelm@10389
    79
lemma same_prefix_nil [iff]: "(xs @ ys \<le> xs) = (ys = [])"
nipkow@25564
    80
by (metis append_Nil2 append_self_conv order_eq_iff prefixI)
nipkow@25665
    81
wenzelm@10330
    82
lemma prefix_prefix [simp]: "xs \<le> ys ==> xs \<le> ys @ zs"
nipkow@25564
    83
by (metis order_le_less_trans prefixI strict_prefixE strict_prefixI)
nipkow@25665
    84
nipkow@14300
    85
lemma append_prefixD: "xs @ ys \<le> zs \<Longrightarrow> xs \<le> zs"
wenzelm@17201
    86
  by (auto simp add: prefix_def)
nipkow@14300
    87
wenzelm@10330
    88
theorem prefix_Cons: "(xs \<le> y # ys) = (xs = [] \<or> (\<exists>zs. xs = y # zs \<and> zs \<le> ys))"
wenzelm@10389
    89
  by (cases xs) (auto simp add: prefix_def)
wenzelm@10330
    90
wenzelm@10330
    91
theorem prefix_append:
nipkow@25564
    92
  "(xs \<le> ys @ zs) = (xs \<le> ys \<or> (\<exists>us. xs = ys @ us \<and> us \<le> zs))"
wenzelm@10330
    93
  apply (induct zs rule: rev_induct)
wenzelm@10330
    94
   apply force
wenzelm@10330
    95
  apply (simp del: append_assoc add: append_assoc [symmetric])
nipkow@25564
    96
  apply (metis append_eq_appendI)
wenzelm@10330
    97
  done
wenzelm@10330
    98
wenzelm@10330
    99
lemma append_one_prefix:
nipkow@25564
   100
  "xs \<le> ys ==> length xs < length ys ==> xs @ [ys ! length xs] \<le> ys"
nipkow@25564
   101
by (unfold prefix_def)
nipkow@25564
   102
   (metis Cons_eq_appendI append_eq_appendI append_eq_conv_conj eq_Nil_appendI nth_drop')
nipkow@25665
   103
wenzelm@10330
   104
theorem prefix_length_le: "xs \<le> ys ==> length xs \<le> length ys"
wenzelm@10389
   105
  by (auto simp add: prefix_def)
wenzelm@10330
   106
nipkow@14300
   107
lemma prefix_same_cases:
nipkow@25564
   108
  "(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"
nipkow@25564
   109
by (unfold prefix_def) (metis append_eq_append_conv2)
nipkow@25665
   110
nipkow@25564
   111
lemma set_mono_prefix: "xs \<le> ys \<Longrightarrow> set xs \<subseteq> set ys"
nipkow@25564
   112
by (auto simp add: prefix_def)
nipkow@14300
   113
nipkow@25564
   114
lemma take_is_prefix: "take n xs \<le> xs"
nipkow@25564
   115
by (unfold prefix_def) (metis append_take_drop_id)
nipkow@25665
   116
wenzelm@25355
   117
lemma map_prefixI:
kleing@25322
   118
  "xs \<le> ys \<Longrightarrow> map f xs \<le> map f ys"
nipkow@25564
   119
by (clarsimp simp: prefix_def)
kleing@25322
   120
kleing@25299
   121
lemma prefix_length_less:
kleing@25299
   122
  "xs < ys \<Longrightarrow> length xs < length ys"
nipkow@25564
   123
by (clarsimp simp: strict_prefix_def prefix_def)
nipkow@25665
   124
kleing@25299
   125
lemma strict_prefix_simps [simp]:
kleing@25299
   126
  "xs < [] = False"
kleing@25299
   127
  "[] < (x # xs) = True"
kleing@25299
   128
  "(x # xs) < (y # ys) = (x = y \<and> xs < ys)"
nipkow@25564
   129
by (simp_all add: strict_prefix_def cong: conj_cong)
kleing@25299
   130
nipkow@25564
   131
lemma take_strict_prefix: "xs < ys \<Longrightarrow> take n xs < ys"
nipkow@25564
   132
apply (induct n arbitrary: xs ys)
nipkow@25564
   133
 apply (case_tac ys, simp_all)[1]
nipkow@25564
   134
apply (metis order_less_trans strict_prefixI take_is_prefix)
nipkow@25564
   135
done
kleing@25299
   136
wenzelm@25355
   137
lemma not_prefix_cases:
kleing@25299
   138
  assumes pfx: "\<not> ps \<le> ls"
wenzelm@25356
   139
  obtains
wenzelm@25356
   140
    (c1) "ps \<noteq> []" and "ls = []"
wenzelm@25356
   141
  | (c2) a as x xs where "ps = a#as" and "ls = x#xs" and "x = a" and "\<not> as \<le> xs"
wenzelm@25356
   142
  | (c3) a as x xs where "ps = a#as" and "ls = x#xs" and "x \<noteq> a"
kleing@25299
   143
proof (cases ps)
nipkow@25564
   144
  case Nil thus ?thesis using pfx by simp
kleing@25299
   145
next
kleing@25299
   146
  case (Cons a as)
nipkow@25564
   147
  hence c: "ps = a#as" .
kleing@25299
   148
  show ?thesis
kleing@25299
   149
  proof (cases ls)
nipkow@25564
   150
    case Nil thus ?thesis by (metis append_Nil2 pfx c1 same_prefix_nil)
kleing@25299
   151
  next
kleing@25299
   152
    case (Cons x xs)
kleing@25299
   153
    show ?thesis
kleing@25299
   154
    proof (cases "x = a")
wenzelm@25355
   155
      case True
wenzelm@25355
   156
      have "\<not> as \<le> xs" using pfx c Cons True by simp
wenzelm@25355
   157
      with c Cons True show ?thesis by (rule c2)
wenzelm@25355
   158
    next
wenzelm@25355
   159
      case False
wenzelm@25355
   160
      with c Cons show ?thesis by (rule c3)
kleing@25299
   161
    qed
kleing@25299
   162
  qed
kleing@25299
   163
qed
kleing@25299
   164
kleing@25299
   165
lemma not_prefix_induct [consumes 1, case_names Nil Neq Eq]:
kleing@25299
   166
  assumes np: "\<not> ps \<le> ls"
wenzelm@25356
   167
    and base: "\<And>x xs. P (x#xs) []"
wenzelm@25356
   168
    and r1: "\<And>x xs y ys. x \<noteq> y \<Longrightarrow> P (x#xs) (y#ys)"
wenzelm@25356
   169
    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
   170
  shows "P ps ls" using np
kleing@25299
   171
proof (induct ls arbitrary: ps)
wenzelm@25355
   172
  case Nil then show ?case
kleing@25299
   173
    by (auto simp: neq_Nil_conv elim!: not_prefix_cases intro!: base)
kleing@25299
   174
next
wenzelm@25355
   175
  case (Cons y ys)
wenzelm@25355
   176
  then have npfx: "\<not> ps \<le> (y # ys)" by simp
wenzelm@25355
   177
  then obtain x xs where pv: "ps = x # xs"
kleing@25299
   178
    by (rule not_prefix_cases) auto
nipkow@25564
   179
  show ?case by (metis Cons.hyps Cons_prefix_Cons npfx pv r1 r2)
kleing@25299
   180
qed
nipkow@14300
   181
wenzelm@25356
   182
wenzelm@10389
   183
subsection {* Parallel lists *}
wenzelm@10389
   184
wenzelm@19086
   185
definition
wenzelm@21404
   186
  parallel :: "'a list => 'a list => bool"  (infixl "\<parallel>" 50) where
wenzelm@19086
   187
  "(xs \<parallel> ys) = (\<not> xs \<le> ys \<and> \<not> ys \<le> xs)"
wenzelm@10389
   188
wenzelm@10389
   189
lemma parallelI [intro]: "\<not> xs \<le> ys ==> \<not> ys \<le> xs ==> xs \<parallel> ys"
nipkow@25564
   190
unfolding parallel_def by blast
wenzelm@10330
   191
wenzelm@10389
   192
lemma parallelE [elim]:
nipkow@25564
   193
assumes "xs \<parallel> ys"
nipkow@25564
   194
obtains "\<not> xs \<le> ys \<and> \<not> ys \<le> xs"
nipkow@25564
   195
using assms unfolding parallel_def by blast
wenzelm@10330
   196
wenzelm@10389
   197
theorem prefix_cases:
nipkow@25564
   198
obtains "xs \<le> ys" | "ys < xs" | "xs \<parallel> ys"
nipkow@25564
   199
unfolding parallel_def strict_prefix_def by blast
wenzelm@10330
   200
wenzelm@10389
   201
theorem parallel_decomp:
wenzelm@10389
   202
  "xs \<parallel> ys ==> \<exists>as b bs c cs. b \<noteq> c \<and> xs = as @ b # bs \<and> ys = as @ c # cs"
wenzelm@10408
   203
proof (induct xs rule: rev_induct)
wenzelm@11987
   204
  case Nil
wenzelm@23254
   205
  then have False by auto
wenzelm@23254
   206
  then show ?case ..
wenzelm@10408
   207
next
wenzelm@11987
   208
  case (snoc x xs)
wenzelm@11987
   209
  show ?case
wenzelm@10408
   210
  proof (rule prefix_cases)
wenzelm@10408
   211
    assume le: "xs \<le> ys"
wenzelm@10408
   212
    then obtain ys' where ys: "ys = xs @ ys'" ..
wenzelm@10408
   213
    show ?thesis
wenzelm@10408
   214
    proof (cases ys')
nipkow@25564
   215
      assume "ys' = []"
nipkow@25564
   216
      thus ?thesis by (metis append_Nil2 parallelE prefixI snoc.prems ys)
wenzelm@10389
   217
    next
wenzelm@10408
   218
      fix c cs assume ys': "ys' = c # cs"
nipkow@25564
   219
      thus ?thesis
nipkow@25564
   220
	by (metis Cons_eq_appendI eq_Nil_appendI parallelE prefixI same_prefix_prefix snoc.prems ys)
wenzelm@10389
   221
    qed
wenzelm@10408
   222
  next
wenzelm@23254
   223
    assume "ys < xs" then have "ys \<le> xs @ [x]" by (simp add: strict_prefix_def)
wenzelm@11987
   224
    with snoc have False by blast
wenzelm@23254
   225
    then show ?thesis ..
wenzelm@10408
   226
  next
wenzelm@10408
   227
    assume "xs \<parallel> ys"
wenzelm@11987
   228
    with snoc obtain as b bs c cs where neq: "(b::'a) \<noteq> c"
wenzelm@10408
   229
      and xs: "xs = as @ b # bs" and ys: "ys = as @ c # cs"
wenzelm@10408
   230
      by blast
wenzelm@10408
   231
    from xs have "xs @ [x] = as @ b # (bs @ [x])" by simp
wenzelm@10408
   232
    with neq ys show ?thesis by blast
wenzelm@10389
   233
  qed
wenzelm@10389
   234
qed
wenzelm@10330
   235
nipkow@25564
   236
lemma parallel_append: "a \<parallel> b \<Longrightarrow> a @ c \<parallel> b @ d"
nipkow@25564
   237
by (rule parallelI)
nipkow@25564
   238
   (erule parallelE, erule conjE,
nipkow@25564
   239
          induct rule: not_prefix_induct, simp+)+
kleing@25299
   240
nipkow@25564
   241
lemma parallel_appendI: "\<lbrakk> xs \<parallel> ys; x = xs @ xs' ; y = ys @ ys' \<rbrakk> \<Longrightarrow> x \<parallel> y"
nipkow@25564
   242
by simp (rule parallel_append)
kleing@25299
   243
wenzelm@25356
   244
lemma parallel_commute: "(a \<parallel> b) = (b \<parallel> a)"
nipkow@25564
   245
unfolding parallel_def by auto
oheimb@14538
   246
wenzelm@25356
   247
oheimb@14538
   248
subsection {* Postfix order on lists *}
wenzelm@17201
   249
wenzelm@19086
   250
definition
wenzelm@21404
   251
  postfix :: "'a list => 'a list => bool"  ("(_/ >>= _)" [51, 50] 50) where
wenzelm@19086
   252
  "(xs >>= ys) = (\<exists>zs. xs = zs @ ys)"
oheimb@14538
   253
wenzelm@21305
   254
lemma postfixI [intro?]: "xs = zs @ ys ==> xs >>= ys"
nipkow@25564
   255
unfolding postfix_def by blast
wenzelm@21305
   256
wenzelm@21305
   257
lemma postfixE [elim?]:
nipkow@25564
   258
assumes "xs >>= ys"
nipkow@25564
   259
obtains zs where "xs = zs @ ys"
nipkow@25564
   260
using assms unfolding postfix_def by blast
wenzelm@21305
   261
wenzelm@21305
   262
lemma postfix_refl [iff]: "xs >>= xs"
wenzelm@14706
   263
  by (auto simp add: postfix_def)
wenzelm@17201
   264
lemma postfix_trans: "\<lbrakk>xs >>= ys; ys >>= zs\<rbrakk> \<Longrightarrow> xs >>= zs"
wenzelm@14706
   265
  by (auto simp add: postfix_def)
wenzelm@17201
   266
lemma postfix_antisym: "\<lbrakk>xs >>= ys; ys >>= xs\<rbrakk> \<Longrightarrow> xs = ys"
wenzelm@14706
   267
  by (auto simp add: postfix_def)
oheimb@14538
   268
wenzelm@17201
   269
lemma Nil_postfix [iff]: "xs >>= []"
wenzelm@14706
   270
  by (simp add: postfix_def)
wenzelm@17201
   271
lemma postfix_Nil [simp]: "([] >>= xs) = (xs = [])"
wenzelm@21305
   272
  by (auto simp add: postfix_def)
oheimb@14538
   273
wenzelm@17201
   274
lemma postfix_ConsI: "xs >>= ys \<Longrightarrow> x#xs >>= ys"
wenzelm@14706
   275
  by (auto simp add: postfix_def)
wenzelm@17201
   276
lemma postfix_ConsD: "xs >>= y#ys \<Longrightarrow> xs >>= ys"
wenzelm@14706
   277
  by (auto simp add: postfix_def)
oheimb@14538
   278
wenzelm@17201
   279
lemma postfix_appendI: "xs >>= ys \<Longrightarrow> zs @ xs >>= ys"
wenzelm@14706
   280
  by (auto simp add: postfix_def)
wenzelm@17201
   281
lemma postfix_appendD: "xs >>= zs @ ys \<Longrightarrow> xs >>= ys"
wenzelm@21305
   282
  by (auto simp add: postfix_def)
oheimb@14538
   283
wenzelm@21305
   284
lemma postfix_is_subset: "xs >>= ys ==> set ys \<subseteq> set xs"
wenzelm@21305
   285
proof -
wenzelm@21305
   286
  assume "xs >>= ys"
wenzelm@21305
   287
  then obtain zs where "xs = zs @ ys" ..
wenzelm@21305
   288
  then show ?thesis by (induct zs) auto
wenzelm@21305
   289
qed
oheimb@14538
   290
wenzelm@21305
   291
lemma postfix_ConsD2: "x#xs >>= y#ys ==> xs >>= ys"
wenzelm@21305
   292
proof -
wenzelm@21305
   293
  assume "x#xs >>= y#ys"
wenzelm@21305
   294
  then obtain zs where "x#xs = zs @ y#ys" ..
wenzelm@21305
   295
  then show ?thesis
wenzelm@21305
   296
    by (induct zs) (auto intro!: postfix_appendI postfix_ConsI)
wenzelm@21305
   297
qed
oheimb@14538
   298
wenzelm@21305
   299
lemma postfix_to_prefix: "xs >>= ys \<longleftrightarrow> rev ys \<le> rev xs"
wenzelm@21305
   300
proof
wenzelm@21305
   301
  assume "xs >>= ys"
wenzelm@21305
   302
  then obtain zs where "xs = zs @ ys" ..
wenzelm@21305
   303
  then have "rev xs = rev ys @ rev zs" by simp
wenzelm@21305
   304
  then show "rev ys <= rev xs" ..
wenzelm@21305
   305
next
wenzelm@21305
   306
  assume "rev ys <= rev xs"
wenzelm@21305
   307
  then obtain zs where "rev xs = rev ys @ zs" ..
wenzelm@21305
   308
  then have "rev (rev xs) = rev zs @ rev (rev ys)" by simp
wenzelm@21305
   309
  then have "xs = rev zs @ ys" by simp
wenzelm@21305
   310
  then show "xs >>= ys" ..
wenzelm@21305
   311
qed
wenzelm@17201
   312
nipkow@25564
   313
lemma distinct_postfix: "distinct xs \<Longrightarrow> xs >>= ys \<Longrightarrow> distinct ys"
nipkow@25564
   314
by (clarsimp elim!: postfixE)
kleing@25299
   315
nipkow@25564
   316
lemma postfix_map: "xs >>= ys \<Longrightarrow> map f xs >>= map f ys"
nipkow@25564
   317
by (auto elim!: postfixE intro: postfixI)
kleing@25299
   318
wenzelm@25356
   319
lemma postfix_drop: "as >>= drop n as"
nipkow@25564
   320
unfolding postfix_def
nipkow@25564
   321
by (rule exI [where x = "take n as"]) simp
kleing@25299
   322
nipkow@25564
   323
lemma postfix_take: "xs >>= ys \<Longrightarrow> xs = take (length xs - length ys) xs @ ys"
nipkow@25564
   324
by (clarsimp elim!: postfixE)
kleing@25299
   325
wenzelm@25356
   326
lemma parallelD1: "x \<parallel> y \<Longrightarrow> \<not> x \<le> y"
nipkow@25564
   327
by blast
kleing@25299
   328
wenzelm@25356
   329
lemma parallelD2: "x \<parallel> y \<Longrightarrow> \<not> y \<le> x"
nipkow@25564
   330
by blast
wenzelm@25355
   331
wenzelm@25355
   332
lemma parallel_Nil1 [simp]: "\<not> x \<parallel> []"
nipkow@25564
   333
unfolding parallel_def by simp
wenzelm@25355
   334
kleing@25299
   335
lemma parallel_Nil2 [simp]: "\<not> [] \<parallel> x"
nipkow@25564
   336
unfolding parallel_def by simp
kleing@25299
   337
nipkow@25564
   338
lemma Cons_parallelI1: "a \<noteq> b \<Longrightarrow> a # as \<parallel> b # bs"
nipkow@25564
   339
by auto
kleing@25299
   340
nipkow@25564
   341
lemma Cons_parallelI2: "\<lbrakk> a = b; as \<parallel> bs \<rbrakk> \<Longrightarrow> a # as \<parallel> b # bs"
nipkow@25564
   342
by (metis Cons_prefix_Cons parallelE parallelI)
nipkow@25665
   343
kleing@25299
   344
lemma not_equal_is_parallel:
kleing@25299
   345
  assumes neq: "xs \<noteq> ys"
wenzelm@25356
   346
    and len: "length xs = length ys"
wenzelm@25356
   347
  shows "xs \<parallel> ys"
kleing@25299
   348
  using len neq
wenzelm@25355
   349
proof (induct rule: list_induct2)
wenzelm@25356
   350
  case 1
wenzelm@25356
   351
  then show ?case by simp
kleing@25299
   352
next
kleing@25299
   353
  case (2 a as b bs)
wenzelm@25355
   354
  have ih: "as \<noteq> bs \<Longrightarrow> as \<parallel> bs" by fact
kleing@25299
   355
  show ?case
kleing@25299
   356
  proof (cases "a = b")
wenzelm@25355
   357
    case True
wenzelm@25355
   358
    then have "as \<noteq> bs" using 2 by simp
wenzelm@25355
   359
    then show ?thesis by (rule Cons_parallelI2 [OF True ih])
kleing@25299
   360
  next
kleing@25299
   361
    case False
wenzelm@25355
   362
    then show ?thesis by (rule Cons_parallelI1)
kleing@25299
   363
  qed
kleing@25299
   364
qed
haftmann@22178
   365
wenzelm@25355
   366
wenzelm@25356
   367
subsection {* Executable code *}
haftmann@22178
   368
haftmann@22178
   369
lemma less_eq_code [code func]:
wenzelm@25356
   370
    "([]\<Colon>'a\<Colon>{eq, ord} list) \<le> xs \<longleftrightarrow> True"
wenzelm@25356
   371
    "(x\<Colon>'a\<Colon>{eq, ord}) # xs \<le> [] \<longleftrightarrow> False"
wenzelm@25356
   372
    "(x\<Colon>'a\<Colon>{eq, ord}) # xs \<le> y # ys \<longleftrightarrow> x = y \<and> xs \<le> ys"
haftmann@22178
   373
  by simp_all
haftmann@22178
   374
haftmann@22178
   375
lemma less_code [code func]:
wenzelm@25356
   376
    "xs < ([]\<Colon>'a\<Colon>{eq, ord} list) \<longleftrightarrow> False"
wenzelm@25356
   377
    "[] < (x\<Colon>'a\<Colon>{eq, ord})# xs \<longleftrightarrow> True"
wenzelm@25356
   378
    "(x\<Colon>'a\<Colon>{eq, ord}) # xs < y # ys \<longleftrightarrow> x = y \<and> xs < ys"
haftmann@22178
   379
  unfolding strict_prefix_def by auto
haftmann@22178
   380
haftmann@22178
   381
lemmas [code func] = postfix_to_prefix
haftmann@22178
   382
wenzelm@10330
   383
end