src/HOL/Library/Sublist.thy
author traytel
Wed, 19 Feb 2014 10:30:21 +0100
changeset 55579 207538943038
parent 54538 ba7392b52a7c
child 57497 4106a2bc066a
permissions -rw-r--r--
reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
49087
7a17ba4bc997 added author
Christian Sternagel
parents: 45236
diff changeset
     1
(*  Title:      HOL/Library/Sublist.thy
10330
4362e906b745 "List prefixes" library theory (replaces old Lex/Prefix);
wenzelm
parents:
diff changeset
     2
    Author:     Tobias Nipkow and Markus Wenzel, TU Muenchen
49087
7a17ba4bc997 added author
Christian Sternagel
parents: 45236
diff changeset
     3
    Author:     Christian Sternagel, JAIST
10330
4362e906b745 "List prefixes" library theory (replaces old Lex/Prefix);
wenzelm
parents:
diff changeset
     4
*)
4362e906b745 "List prefixes" library theory (replaces old Lex/Prefix);
wenzelm
parents:
diff changeset
     5
55579
207538943038 reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents: 54538
diff changeset
     6
header {* List prefixes, suffixes, and homeomorphic embedding *}
10330
4362e906b745 "List prefixes" library theory (replaces old Lex/Prefix);
wenzelm
parents:
diff changeset
     7
49087
7a17ba4bc997 added author
Christian Sternagel
parents: 45236
diff changeset
     8
theory Sublist
7a17ba4bc997 added author
Christian Sternagel
parents: 45236
diff changeset
     9
imports Main
15131
c69542757a4d New theory header syntax.
nipkow
parents: 14981
diff changeset
    10
begin
10330
4362e906b745 "List prefixes" library theory (replaces old Lex/Prefix);
wenzelm
parents:
diff changeset
    11
55579
207538943038 reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents: 54538
diff changeset
    12
subsection {* Prefix order on lists *}
207538943038 reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents: 54538
diff changeset
    13
207538943038 reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents: 54538
diff changeset
    14
definition prefixeq :: "'a list \<Rightarrow> 'a list \<Rightarrow> bool"
207538943038 reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents: 54538
diff changeset
    15
  where "prefixeq xs ys \<longleftrightarrow> (\<exists>zs. ys = xs @ zs)"
207538943038 reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents: 54538
diff changeset
    16
207538943038 reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents: 54538
diff changeset
    17
definition prefix :: "'a list \<Rightarrow> 'a list \<Rightarrow> bool"
207538943038 reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents: 54538
diff changeset
    18
  where "prefix xs ys \<longleftrightarrow> prefixeq xs ys \<and> xs \<noteq> ys"
207538943038 reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents: 54538
diff changeset
    19
207538943038 reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents: 54538
diff changeset
    20
interpretation prefix_order: order prefixeq prefix
207538943038 reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents: 54538
diff changeset
    21
  by default (auto simp: prefixeq_def prefix_def)
207538943038 reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents: 54538
diff changeset
    22
207538943038 reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents: 54538
diff changeset
    23
interpretation prefix_bot: order_bot Nil prefixeq prefix
207538943038 reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents: 54538
diff changeset
    24
  by default (simp add: prefixeq_def)
207538943038 reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents: 54538
diff changeset
    25
207538943038 reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents: 54538
diff changeset
    26
lemma prefixeqI [intro?]: "ys = xs @ zs \<Longrightarrow> prefixeq xs ys"
207538943038 reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents: 54538
diff changeset
    27
  unfolding prefixeq_def by blast
207538943038 reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents: 54538
diff changeset
    28
207538943038 reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents: 54538
diff changeset
    29
lemma prefixeqE [elim?]:
207538943038 reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents: 54538
diff changeset
    30
  assumes "prefixeq xs ys"
207538943038 reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents: 54538
diff changeset
    31
  obtains zs where "ys = xs @ zs"
207538943038 reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents: 54538
diff changeset
    32
  using assms unfolding prefixeq_def by blast
207538943038 reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents: 54538
diff changeset
    33
207538943038 reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents: 54538
diff changeset
    34
lemma prefixI' [intro?]: "ys = xs @ z # zs \<Longrightarrow> prefix xs ys"
207538943038 reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents: 54538
diff changeset
    35
  unfolding prefix_def prefixeq_def by blast
207538943038 reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents: 54538
diff changeset
    36
207538943038 reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents: 54538
diff changeset
    37
lemma prefixE' [elim?]:
207538943038 reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents: 54538
diff changeset
    38
  assumes "prefix xs ys"
207538943038 reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents: 54538
diff changeset
    39
  obtains z zs where "ys = xs @ z # zs"
207538943038 reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents: 54538
diff changeset
    40
proof -
207538943038 reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents: 54538
diff changeset
    41
  from `prefix xs ys` obtain us where "ys = xs @ us" and "xs \<noteq> ys"
207538943038 reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents: 54538
diff changeset
    42
    unfolding prefix_def prefixeq_def by blast
207538943038 reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents: 54538
diff changeset
    43
  with that show ?thesis by (auto simp add: neq_Nil_conv)
207538943038 reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents: 54538
diff changeset
    44
qed
207538943038 reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents: 54538
diff changeset
    45
207538943038 reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents: 54538
diff changeset
    46
lemma prefixI [intro?]: "prefixeq xs ys \<Longrightarrow> xs \<noteq> ys \<Longrightarrow> prefix xs ys"
207538943038 reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents: 54538
diff changeset
    47
  unfolding prefix_def by blast
207538943038 reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents: 54538
diff changeset
    48
207538943038 reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents: 54538
diff changeset
    49
lemma prefixE [elim?]:
207538943038 reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents: 54538
diff changeset
    50
  fixes xs ys :: "'a list"
207538943038 reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents: 54538
diff changeset
    51
  assumes "prefix xs ys"
207538943038 reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents: 54538
diff changeset
    52
  obtains "prefixeq xs ys" and "xs \<noteq> ys"
207538943038 reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents: 54538
diff changeset
    53
  using assms unfolding prefix_def by blast
207538943038 reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents: 54538
diff changeset
    54
207538943038 reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents: 54538
diff changeset
    55
207538943038 reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents: 54538
diff changeset
    56
subsection {* Basic properties of prefixes *}
207538943038 reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents: 54538
diff changeset
    57
207538943038 reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents: 54538
diff changeset
    58
theorem Nil_prefixeq [iff]: "prefixeq [] xs"
207538943038 reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents: 54538
diff changeset
    59
  by (simp add: prefixeq_def)
207538943038 reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents: 54538
diff changeset
    60
207538943038 reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents: 54538
diff changeset
    61
theorem prefixeq_Nil [simp]: "(prefixeq xs []) = (xs = [])"
207538943038 reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents: 54538
diff changeset
    62
  by (induct xs) (simp_all add: prefixeq_def)
207538943038 reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents: 54538
diff changeset
    63
207538943038 reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents: 54538
diff changeset
    64
lemma prefixeq_snoc [simp]: "prefixeq xs (ys @ [y]) \<longleftrightarrow> xs = ys @ [y] \<or> prefixeq xs ys"
207538943038 reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents: 54538
diff changeset
    65
proof
207538943038 reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents: 54538
diff changeset
    66
  assume "prefixeq xs (ys @ [y])"
207538943038 reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents: 54538
diff changeset
    67
  then obtain zs where zs: "ys @ [y] = xs @ zs" ..
207538943038 reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents: 54538
diff changeset
    68
  show "xs = ys @ [y] \<or> prefixeq xs ys"
207538943038 reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents: 54538
diff changeset
    69
    by (metis append_Nil2 butlast_append butlast_snoc prefixeqI zs)
207538943038 reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents: 54538
diff changeset
    70
next
207538943038 reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents: 54538
diff changeset
    71
  assume "xs = ys @ [y] \<or> prefixeq xs ys"
207538943038 reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents: 54538
diff changeset
    72
  then show "prefixeq xs (ys @ [y])"
207538943038 reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents: 54538
diff changeset
    73
    by (metis prefix_order.eq_iff prefix_order.order_trans prefixeqI)
207538943038 reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents: 54538
diff changeset
    74
qed
207538943038 reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents: 54538
diff changeset
    75
207538943038 reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents: 54538
diff changeset
    76
lemma Cons_prefixeq_Cons [simp]: "prefixeq (x # xs) (y # ys) = (x = y \<and> prefixeq xs ys)"
207538943038 reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents: 54538
diff changeset
    77
  by (auto simp add: prefixeq_def)
207538943038 reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents: 54538
diff changeset
    78
207538943038 reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents: 54538
diff changeset
    79
lemma prefixeq_code [code]:
207538943038 reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents: 54538
diff changeset
    80
  "prefixeq [] xs \<longleftrightarrow> True"
207538943038 reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents: 54538
diff changeset
    81
  "prefixeq (x # xs) [] \<longleftrightarrow> False"
207538943038 reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents: 54538
diff changeset
    82
  "prefixeq (x # xs) (y # ys) \<longleftrightarrow> x = y \<and> prefixeq xs ys"
207538943038 reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents: 54538
diff changeset
    83
  by simp_all
207538943038 reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents: 54538
diff changeset
    84
207538943038 reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents: 54538
diff changeset
    85
lemma same_prefixeq_prefixeq [simp]: "prefixeq (xs @ ys) (xs @ zs) = prefixeq ys zs"
207538943038 reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents: 54538
diff changeset
    86
  by (induct xs) simp_all
207538943038 reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents: 54538
diff changeset
    87
207538943038 reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents: 54538
diff changeset
    88
lemma same_prefixeq_nil [iff]: "prefixeq (xs @ ys) xs = (ys = [])"
207538943038 reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents: 54538
diff changeset
    89
  by (metis append_Nil2 append_self_conv prefix_order.eq_iff prefixeqI)
207538943038 reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents: 54538
diff changeset
    90
207538943038 reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents: 54538
diff changeset
    91
lemma prefixeq_prefixeq [simp]: "prefixeq xs ys \<Longrightarrow> prefixeq xs (ys @ zs)"
207538943038 reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents: 54538
diff changeset
    92
  by (metis prefix_order.le_less_trans prefixeqI prefixE prefixI)
207538943038 reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents: 54538
diff changeset
    93
207538943038 reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents: 54538
diff changeset
    94
lemma append_prefixeqD: "prefixeq (xs @ ys) zs \<Longrightarrow> prefixeq xs zs"
207538943038 reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents: 54538
diff changeset
    95
  by (auto simp add: prefixeq_def)
207538943038 reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents: 54538
diff changeset
    96
207538943038 reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents: 54538
diff changeset
    97
theorem prefixeq_Cons: "prefixeq xs (y # ys) = (xs = [] \<or> (\<exists>zs. xs = y # zs \<and> prefixeq zs ys))"
207538943038 reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents: 54538
diff changeset
    98
  by (cases xs) (auto simp add: prefixeq_def)
207538943038 reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents: 54538
diff changeset
    99
207538943038 reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents: 54538
diff changeset
   100
theorem prefixeq_append:
207538943038 reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents: 54538
diff changeset
   101
  "prefixeq xs (ys @ zs) = (prefixeq xs ys \<or> (\<exists>us. xs = ys @ us \<and> prefixeq us zs))"
207538943038 reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents: 54538
diff changeset
   102
  apply (induct zs rule: rev_induct)
207538943038 reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents: 54538
diff changeset
   103
   apply force
207538943038 reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents: 54538
diff changeset
   104
  apply (simp del: append_assoc add: append_assoc [symmetric])
207538943038 reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents: 54538
diff changeset
   105
  apply (metis append_eq_appendI)
207538943038 reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents: 54538
diff changeset
   106
  done
207538943038 reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents: 54538
diff changeset
   107
207538943038 reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents: 54538
diff changeset
   108
lemma append_one_prefixeq:
207538943038 reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents: 54538
diff changeset
   109
  "prefixeq xs ys \<Longrightarrow> length xs < length ys \<Longrightarrow> prefixeq (xs @ [ys ! length xs]) ys"
207538943038 reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents: 54538
diff changeset
   110
  proof (unfold prefixeq_def)
207538943038 reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents: 54538
diff changeset
   111
    assume a1: "\<exists>zs. ys = xs @ zs"
207538943038 reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents: 54538
diff changeset
   112
    then obtain sk :: "'a list" where sk: "ys = xs @ sk" by fastforce
207538943038 reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents: 54538
diff changeset
   113
    assume a2: "length xs < length ys"
207538943038 reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents: 54538
diff changeset
   114
    have f1: "\<And>v. ([]\<Colon>'a list) @ v = v" using append_Nil2 by simp
207538943038 reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents: 54538
diff changeset
   115
    have "[] \<noteq> sk" using a1 a2 sk less_not_refl by force
207538943038 reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents: 54538
diff changeset
   116
    hence "\<exists>v. xs @ hd sk # v = ys" using sk by (metis hd_Cons_tl)
207538943038 reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents: 54538
diff changeset
   117
    thus "\<exists>zs. ys = (xs @ [ys ! length xs]) @ zs" using f1 by fastforce
207538943038 reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents: 54538
diff changeset
   118
  qed
207538943038 reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents: 54538
diff changeset
   119
207538943038 reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents: 54538
diff changeset
   120
theorem prefixeq_length_le: "prefixeq xs ys \<Longrightarrow> length xs \<le> length ys"
207538943038 reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents: 54538
diff changeset
   121
  by (auto simp add: prefixeq_def)
207538943038 reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents: 54538
diff changeset
   122
207538943038 reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents: 54538
diff changeset
   123
lemma prefixeq_same_cases:
207538943038 reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents: 54538
diff changeset
   124
  "prefixeq (xs\<^sub>1::'a list) ys \<Longrightarrow> prefixeq xs\<^sub>2 ys \<Longrightarrow> prefixeq xs\<^sub>1 xs\<^sub>2 \<or> prefixeq xs\<^sub>2 xs\<^sub>1"
207538943038 reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents: 54538
diff changeset
   125
  unfolding prefixeq_def by (force simp: append_eq_append_conv2)
207538943038 reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents: 54538
diff changeset
   126
207538943038 reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents: 54538
diff changeset
   127
lemma set_mono_prefixeq: "prefixeq xs ys \<Longrightarrow> set xs \<subseteq> set ys"
207538943038 reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents: 54538
diff changeset
   128
  by (auto simp add: prefixeq_def)
207538943038 reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents: 54538
diff changeset
   129
207538943038 reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents: 54538
diff changeset
   130
lemma take_is_prefixeq: "prefixeq (take n xs) xs"
207538943038 reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents: 54538
diff changeset
   131
  unfolding prefixeq_def by (metis append_take_drop_id)
207538943038 reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents: 54538
diff changeset
   132
207538943038 reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents: 54538
diff changeset
   133
lemma map_prefixeqI: "prefixeq xs ys \<Longrightarrow> prefixeq (map f xs) (map f ys)"
207538943038 reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents: 54538
diff changeset
   134
  by (auto simp: prefixeq_def)
207538943038 reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents: 54538
diff changeset
   135
207538943038 reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents: 54538
diff changeset
   136
lemma prefixeq_length_less: "prefix xs ys \<Longrightarrow> length xs < length ys"
207538943038 reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents: 54538
diff changeset
   137
  by (auto simp: prefix_def prefixeq_def)
207538943038 reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents: 54538
diff changeset
   138
207538943038 reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents: 54538
diff changeset
   139
lemma prefix_simps [simp, code]:
207538943038 reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents: 54538
diff changeset
   140
  "prefix xs [] \<longleftrightarrow> False"
207538943038 reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents: 54538
diff changeset
   141
  "prefix [] (x # xs) \<longleftrightarrow> True"
207538943038 reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents: 54538
diff changeset
   142
  "prefix (x # xs) (y # ys) \<longleftrightarrow> x = y \<and> prefix xs ys"
207538943038 reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents: 54538
diff changeset
   143
  by (simp_all add: prefix_def cong: conj_cong)
207538943038 reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents: 54538
diff changeset
   144
207538943038 reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents: 54538
diff changeset
   145
lemma take_prefix: "prefix xs ys \<Longrightarrow> prefix (take n xs) ys"
207538943038 reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents: 54538
diff changeset
   146
  apply (induct n arbitrary: xs ys)
207538943038 reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents: 54538
diff changeset
   147
   apply (case_tac ys, simp_all)[1]
207538943038 reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents: 54538
diff changeset
   148
  apply (metis prefix_order.less_trans prefixI take_is_prefixeq)
207538943038 reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents: 54538
diff changeset
   149
  done
207538943038 reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents: 54538
diff changeset
   150
207538943038 reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents: 54538
diff changeset
   151
lemma not_prefixeq_cases:
207538943038 reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents: 54538
diff changeset
   152
  assumes pfx: "\<not> prefixeq ps ls"
207538943038 reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents: 54538
diff changeset
   153
  obtains
207538943038 reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents: 54538
diff changeset
   154
    (c1) "ps \<noteq> []" and "ls = []"
207538943038 reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents: 54538
diff changeset
   155
  | (c2) a as x xs where "ps = a#as" and "ls = x#xs" and "x = a" and "\<not> prefixeq as xs"
207538943038 reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents: 54538
diff changeset
   156
  | (c3) a as x xs where "ps = a#as" and "ls = x#xs" and "x \<noteq> a"
207538943038 reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents: 54538
diff changeset
   157
proof (cases ps)
207538943038 reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents: 54538
diff changeset
   158
  case Nil
207538943038 reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents: 54538
diff changeset
   159
  then show ?thesis using pfx by simp
207538943038 reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents: 54538
diff changeset
   160
next
207538943038 reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents: 54538
diff changeset
   161
  case (Cons a as)
207538943038 reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents: 54538
diff changeset
   162
  note c = `ps = a#as`
207538943038 reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents: 54538
diff changeset
   163
  show ?thesis
207538943038 reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents: 54538
diff changeset
   164
  proof (cases ls)
207538943038 reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents: 54538
diff changeset
   165
    case Nil then show ?thesis by (metis append_Nil2 pfx c1 same_prefixeq_nil)
207538943038 reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents: 54538
diff changeset
   166
  next
207538943038 reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents: 54538
diff changeset
   167
    case (Cons x xs)
207538943038 reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents: 54538
diff changeset
   168
    show ?thesis
207538943038 reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents: 54538
diff changeset
   169
    proof (cases "x = a")
207538943038 reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents: 54538
diff changeset
   170
      case True
207538943038 reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents: 54538
diff changeset
   171
      have "\<not> prefixeq as xs" using pfx c Cons True by simp
207538943038 reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents: 54538
diff changeset
   172
      with c Cons True show ?thesis by (rule c2)
207538943038 reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents: 54538
diff changeset
   173
    next
207538943038 reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents: 54538
diff changeset
   174
      case False
207538943038 reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents: 54538
diff changeset
   175
      with c Cons show ?thesis by (rule c3)
207538943038 reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents: 54538
diff changeset
   176
    qed
207538943038 reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents: 54538
diff changeset
   177
  qed
207538943038 reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents: 54538
diff changeset
   178
qed
207538943038 reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents: 54538
diff changeset
   179
207538943038 reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents: 54538
diff changeset
   180
lemma not_prefixeq_induct [consumes 1, case_names Nil Neq Eq]:
207538943038 reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents: 54538
diff changeset
   181
  assumes np: "\<not> prefixeq ps ls"
207538943038 reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents: 54538
diff changeset
   182
    and base: "\<And>x xs. P (x#xs) []"
207538943038 reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents: 54538
diff changeset
   183
    and r1: "\<And>x xs y ys. x \<noteq> y \<Longrightarrow> P (x#xs) (y#ys)"
207538943038 reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents: 54538
diff changeset
   184
    and r2: "\<And>x xs y ys. \<lbrakk> x = y; \<not> prefixeq xs ys; P xs ys \<rbrakk> \<Longrightarrow> P (x#xs) (y#ys)"
207538943038 reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents: 54538
diff changeset
   185
  shows "P ps ls" using np
207538943038 reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents: 54538
diff changeset
   186
proof (induct ls arbitrary: ps)
207538943038 reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents: 54538
diff changeset
   187
  case Nil then show ?case
207538943038 reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents: 54538
diff changeset
   188
    by (auto simp: neq_Nil_conv elim!: not_prefixeq_cases intro!: base)
207538943038 reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents: 54538
diff changeset
   189
next
207538943038 reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents: 54538
diff changeset
   190
  case (Cons y ys)
207538943038 reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents: 54538
diff changeset
   191
  then have npfx: "\<not> prefixeq ps (y # ys)" by simp
207538943038 reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents: 54538
diff changeset
   192
  then obtain x xs where pv: "ps = x # xs"
207538943038 reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents: 54538
diff changeset
   193
    by (rule not_prefixeq_cases) auto
207538943038 reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents: 54538
diff changeset
   194
  show ?case by (metis Cons.hyps Cons_prefixeq_Cons npfx pv r1 r2)
207538943038 reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents: 54538
diff changeset
   195
qed
207538943038 reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents: 54538
diff changeset
   196
207538943038 reverted ba7392b52a7c: List_Prefix not needed anymore by codatatypes
traytel
parents: 54538
diff changeset
   197
10389
c7d8901ab269 proper setup of "parallel";
wenzelm
parents: 10330
diff changeset
   198
subsection {* Parallel lists *}
c7d8901ab269 proper setup of "parallel";
wenzelm
parents: 10330
diff changeset
   199
50516
ed6b40d15d1c renamed "emb" to "list_hembeq";
Christian Sternagel
parents: 49107
diff changeset
   200
definition parallel :: "'a list \<Rightarrow> 'a list \<Rightarrow> bool"  (infixl "\<parallel>" 50)
49107
ec34e9df0514 misc tuning;
wenzelm
parents: 49087
diff changeset
   201
  where "(xs \<parallel> ys) = (\<not> prefixeq xs ys \<and> \<not> prefixeq ys xs)"
10389
c7d8901ab269 proper setup of "parallel";
wenzelm
parents: 10330
diff changeset
   202
50516
ed6b40d15d1c renamed "emb" to "list_hembeq";
Christian Sternagel
parents: 49107
diff changeset
   203
lemma parallelI [intro]: "\<not> prefixeq xs ys \<Longrightarrow> \<not> prefixeq ys xs \<Longrightarrow> xs \<parallel> ys"
25692
eda4958ab0d2 tuned proofs, document;
wenzelm
parents: 25665
diff changeset
   204
  unfolding parallel_def by blast
10330
4362e906b745 "List prefixes" library theory (replaces old Lex/Prefix);
wenzelm
parents:
diff changeset
   205
10389
c7d8901ab269 proper setup of "parallel";
wenzelm
parents: 10330
diff changeset
   206
lemma parallelE [elim]:
25692
eda4958ab0d2 tuned proofs, document;
wenzelm
parents: 25665
diff changeset
   207
  assumes "xs \<parallel> ys"
49087
7a17ba4bc997 added author
Christian Sternagel
parents: 45236
diff changeset
   208
  obtains "\<not> prefixeq xs ys \<and> \<not> prefixeq ys xs"
25692
eda4958ab0d2 tuned proofs, document;
wenzelm
parents: 25665
diff changeset
   209
  using assms unfolding parallel_def by blast
10330
4362e906b745 "List prefixes" library theory (replaces old Lex/Prefix);
wenzelm
parents:
diff changeset
   210
49087
7a17ba4bc997 added author
Christian Sternagel
parents: 45236
diff changeset
   211
theorem prefixeq_cases:
7a17ba4bc997 added author
Christian Sternagel
parents: 45236
diff changeset
   212
  obtains "prefixeq xs ys" | "prefix ys xs" | "xs \<parallel> ys"
7a17ba4bc997 added author
Christian Sternagel
parents: 45236
diff changeset
   213
  unfolding parallel_def prefix_def by blast
10330
4362e906b745 "List prefixes" library theory (replaces old Lex/Prefix);
wenzelm
parents:
diff changeset
   214
10389
c7d8901ab269 proper setup of "parallel";
wenzelm
parents: 10330
diff changeset
   215
theorem parallel_decomp:
50516
ed6b40d15d1c renamed "emb" to "list_hembeq";
Christian Sternagel
parents: 49107
diff changeset
   216
  "xs \<parallel> ys \<Longrightarrow> \<exists>as b bs c cs. b \<noteq> c \<and> xs = as @ b # bs \<and> ys = as @ c # cs"
10408
d8b3613158b1 improved: 'induct' handle non-atomic goals;
wenzelm
parents: 10389
diff changeset
   217
proof (induct xs rule: rev_induct)
11987
bf31b35949ce tuned induct proofs;
wenzelm
parents: 11780
diff changeset
   218
  case Nil
23254
99644a53f16d tuned proofs;
wenzelm
parents: 22178
diff changeset
   219
  then have False by auto
99644a53f16d tuned proofs;
wenzelm
parents: 22178
diff changeset
   220
  then show ?case ..
10408
d8b3613158b1 improved: 'induct' handle non-atomic goals;
wenzelm
parents: 10389
diff changeset
   221
next
11987
bf31b35949ce tuned induct proofs;
wenzelm
parents: 11780
diff changeset
   222
  case (snoc x xs)
bf31b35949ce tuned induct proofs;
wenzelm
parents: 11780
diff changeset
   223
  show ?case
49087
7a17ba4bc997 added author
Christian Sternagel
parents: 45236
diff changeset
   224
  proof (rule prefixeq_cases)
7a17ba4bc997 added author
Christian Sternagel
parents: 45236
diff changeset
   225
    assume le: "prefixeq xs ys"
10408
d8b3613158b1 improved: 'induct' handle non-atomic goals;
wenzelm
parents: 10389
diff changeset
   226
    then obtain ys' where ys: "ys = xs @ ys'" ..
d8b3613158b1 improved: 'induct' handle non-atomic goals;
wenzelm
parents: 10389
diff changeset
   227
    show ?thesis
d8b3613158b1 improved: 'induct' handle non-atomic goals;
wenzelm
parents: 10389
diff changeset
   228
    proof (cases ys')
25564
4ca31a3706a4 R&F: added sgn lemma
nipkow
parents: 25356
diff changeset
   229
      assume "ys' = []"
49087
7a17ba4bc997 added author
Christian Sternagel
parents: 45236
diff changeset
   230
      then show ?thesis by (metis append_Nil2 parallelE prefixeqI snoc.prems ys)
10389
c7d8901ab269 proper setup of "parallel";
wenzelm
parents: 10330
diff changeset
   231
    next
10408
d8b3613158b1 improved: 'induct' handle non-atomic goals;
wenzelm
parents: 10389
diff changeset
   232
      fix c cs assume ys': "ys' = c # cs"
54483
9f24325c2550 optimized more bad apples
blanchet
parents: 53015
diff changeset
   233
      have "x \<noteq> c" using snoc.prems ys ys' by fastforce
9f24325c2550 optimized more bad apples
blanchet
parents: 53015
diff changeset
   234
      thus "\<exists>as b bs c cs. b \<noteq> c \<and> xs @ [x] = as @ b # bs \<and> ys = as @ c # cs"
9f24325c2550 optimized more bad apples
blanchet
parents: 53015
diff changeset
   235
        using ys ys' by blast
10389
c7d8901ab269 proper setup of "parallel";
wenzelm
parents: 10330
diff changeset
   236
    qed
10408
d8b3613158b1 improved: 'induct' handle non-atomic goals;
wenzelm
parents: 10389
diff changeset
   237
  next
49107
ec34e9df0514 misc tuning;
wenzelm
parents: 49087
diff changeset
   238
    assume "prefix ys xs"
ec34e9df0514 misc tuning;
wenzelm
parents: 49087
diff changeset
   239
    then have "prefixeq ys (xs @ [x])" by (simp add: prefix_def)
11987
bf31b35949ce tuned induct proofs;
wenzelm
parents: 11780
diff changeset
   240
    with snoc have False by blast
23254
99644a53f16d tuned proofs;
wenzelm
parents: 22178
diff changeset
   241
    then show ?thesis ..
10408
d8b3613158b1 improved: 'induct' handle non-atomic goals;
wenzelm
parents: 10389
diff changeset
   242
  next
d8b3613158b1 improved: 'induct' handle non-atomic goals;
wenzelm
parents: 10389
diff changeset
   243
    assume "xs \<parallel> ys"
11987
bf31b35949ce tuned induct proofs;
wenzelm
parents: 11780
diff changeset
   244
    with snoc obtain as b bs c cs where neq: "(b::'a) \<noteq> c"
10408
d8b3613158b1 improved: 'induct' handle non-atomic goals;
wenzelm
parents: 10389
diff changeset
   245
      and xs: "xs = as @ b # bs" and ys: "ys = as @ c # cs"
d8b3613158b1 improved: 'induct' handle non-atomic goals;
wenzelm
parents: 10389
diff changeset
   246
      by blast
d8b3613158b1 improved: 'induct' handle non-atomic goals;
wenzelm
parents: 10389
diff changeset
   247
    from xs have "xs @ [x] = as @ b # (bs @ [x])" by simp
d8b3613158b1 improved: 'induct' handle non-atomic goals;
wenzelm
parents: 10389
diff changeset
   248
    with neq ys show ?thesis by blast
10389
c7d8901ab269 proper setup of "parallel";
wenzelm
parents: 10330
diff changeset
   249
  qed
c7d8901ab269 proper setup of "parallel";
wenzelm
parents: 10330
diff changeset
   250
qed
10330
4362e906b745 "List prefixes" library theory (replaces old Lex/Prefix);
wenzelm
parents:
diff changeset
   251
25564
4ca31a3706a4 R&F: added sgn lemma
nipkow
parents: 25356
diff changeset
   252
lemma parallel_append: "a \<parallel> b \<Longrightarrow> a @ c \<parallel> b @ d"
25692
eda4958ab0d2 tuned proofs, document;
wenzelm
parents: 25665
diff changeset
   253
  apply (rule parallelI)
eda4958ab0d2 tuned proofs, document;
wenzelm
parents: 25665
diff changeset
   254
    apply (erule parallelE, erule conjE,
49087
7a17ba4bc997 added author
Christian Sternagel
parents: 45236
diff changeset
   255
      induct rule: not_prefixeq_induct, simp+)+
25692
eda4958ab0d2 tuned proofs, document;
wenzelm
parents: 25665
diff changeset
   256
  done
25299
c3542f70b0fd misc lemmas about prefix, postfix, and parallel
kleing
parents: 23394
diff changeset
   257
25692
eda4958ab0d2 tuned proofs, document;
wenzelm
parents: 25665
diff changeset
   258
lemma parallel_appendI: "xs \<parallel> ys \<Longrightarrow> x = xs @ xs' \<Longrightarrow> y = ys @ ys' \<Longrightarrow> x \<parallel> y"
eda4958ab0d2 tuned proofs, document;
wenzelm
parents: 25665
diff changeset
   259
  by (simp add: parallel_append)
25299
c3542f70b0fd misc lemmas about prefix, postfix, and parallel
kleing
parents: 23394
diff changeset
   260
25692
eda4958ab0d2 tuned proofs, document;
wenzelm
parents: 25665
diff changeset
   261
lemma parallel_commute: "a \<parallel> b \<longleftrightarrow> b \<parallel> a"
eda4958ab0d2 tuned proofs, document;
wenzelm
parents: 25665
diff changeset
   262
  unfolding parallel_def by auto
14538
1d9d75a8efae removed o2l and fold_rel; moved postfix to Library/List_Prefix.thy
oheimb
parents: 14300
diff changeset
   263
25356
059c03630d6e tuned presentation;
wenzelm
parents: 25355
diff changeset
   264
49087
7a17ba4bc997 added author
Christian Sternagel
parents: 45236
diff changeset
   265
subsection {* Suffix order on lists *}
17201
3bdf1dfcdee4 reactivate postfix by change of syntax;
wenzelm
parents: 15355
diff changeset
   266
49107
ec34e9df0514 misc tuning;
wenzelm
parents: 49087
diff changeset
   267
definition suffixeq :: "'a list \<Rightarrow> 'a list \<Rightarrow> bool"
ec34e9df0514 misc tuning;
wenzelm
parents: 49087
diff changeset
   268
  where "suffixeq xs ys = (\<exists>zs. ys = zs @ xs)"
49087
7a17ba4bc997 added author
Christian Sternagel
parents: 45236
diff changeset
   269
49107
ec34e9df0514 misc tuning;
wenzelm
parents: 49087
diff changeset
   270
definition suffix :: "'a list \<Rightarrow> 'a list \<Rightarrow> bool"
ec34e9df0514 misc tuning;
wenzelm
parents: 49087
diff changeset
   271
  where "suffix xs ys \<longleftrightarrow> (\<exists>us. ys = us @ xs \<and> us \<noteq> [])"
14538
1d9d75a8efae removed o2l and fold_rel; moved postfix to Library/List_Prefix.thy
oheimb
parents: 14300
diff changeset
   272
49087
7a17ba4bc997 added author
Christian Sternagel
parents: 45236
diff changeset
   273
lemma suffix_imp_suffixeq:
7a17ba4bc997 added author
Christian Sternagel
parents: 45236
diff changeset
   274
  "suffix xs ys \<Longrightarrow> suffixeq xs ys"
7a17ba4bc997 added author
Christian Sternagel
parents: 45236
diff changeset
   275
  by (auto simp: suffixeq_def suffix_def)
7a17ba4bc997 added author
Christian Sternagel
parents: 45236
diff changeset
   276
50516
ed6b40d15d1c renamed "emb" to "list_hembeq";
Christian Sternagel
parents: 49107
diff changeset
   277
lemma suffixeqI [intro?]: "ys = zs @ xs \<Longrightarrow> suffixeq xs ys"
49087
7a17ba4bc997 added author
Christian Sternagel
parents: 45236
diff changeset
   278
  unfolding suffixeq_def by blast
21305
d41eddfd2b66 tuned proofs;
wenzelm
parents: 19086
diff changeset
   279
49087
7a17ba4bc997 added author
Christian Sternagel
parents: 45236
diff changeset
   280
lemma suffixeqE [elim?]:
7a17ba4bc997 added author
Christian Sternagel
parents: 45236
diff changeset
   281
  assumes "suffixeq xs ys"
7a17ba4bc997 added author
Christian Sternagel
parents: 45236
diff changeset
   282
  obtains zs where "ys = zs @ xs"
7a17ba4bc997 added author
Christian Sternagel
parents: 45236
diff changeset
   283
  using assms unfolding suffixeq_def by blast
21305
d41eddfd2b66 tuned proofs;
wenzelm
parents: 19086
diff changeset
   284
49087
7a17ba4bc997 added author
Christian Sternagel
parents: 45236
diff changeset
   285
lemma suffixeq_refl [iff]: "suffixeq xs xs"
7a17ba4bc997 added author
Christian Sternagel
parents: 45236
diff changeset
   286
  by (auto simp add: suffixeq_def)
7a17ba4bc997 added author
Christian Sternagel
parents: 45236
diff changeset
   287
lemma suffix_trans:
7a17ba4bc997 added author
Christian Sternagel
parents: 45236
diff changeset
   288
  "suffix xs ys \<Longrightarrow> suffix ys zs \<Longrightarrow> suffix xs zs"
7a17ba4bc997 added author
Christian Sternagel
parents: 45236
diff changeset
   289
  by (auto simp: suffix_def)
7a17ba4bc997 added author
Christian Sternagel
parents: 45236
diff changeset
   290
lemma suffixeq_trans: "\<lbrakk>suffixeq xs ys; suffixeq ys zs\<rbrakk> \<Longrightarrow> suffixeq xs zs"
7a17ba4bc997 added author
Christian Sternagel
parents: 45236
diff changeset
   291
  by (auto simp add: suffixeq_def)
7a17ba4bc997 added author
Christian Sternagel
parents: 45236
diff changeset
   292
lemma suffixeq_antisym: "\<lbrakk>suffixeq xs ys; suffixeq ys xs\<rbrakk> \<Longrightarrow> xs = ys"
7a17ba4bc997 added author
Christian Sternagel
parents: 45236
diff changeset
   293
  by (auto simp add: suffixeq_def)
7a17ba4bc997 added author
Christian Sternagel
parents: 45236
diff changeset
   294
7a17ba4bc997 added author
Christian Sternagel
parents: 45236
diff changeset
   295
lemma suffixeq_tl [simp]: "suffixeq (tl xs) xs"
7a17ba4bc997 added author
Christian Sternagel
parents: 45236
diff changeset
   296
  by (induct xs) (auto simp: suffixeq_def)
14538
1d9d75a8efae removed o2l and fold_rel; moved postfix to Library/List_Prefix.thy
oheimb
parents: 14300
diff changeset
   297
49087
7a17ba4bc997 added author
Christian Sternagel
parents: 45236
diff changeset
   298
lemma suffix_tl [simp]: "xs \<noteq> [] \<Longrightarrow> suffix (tl xs) xs"
7a17ba4bc997 added author
Christian Sternagel
parents: 45236
diff changeset
   299
  by (induct xs) (auto simp: suffix_def)
14538
1d9d75a8efae removed o2l and fold_rel; moved postfix to Library/List_Prefix.thy
oheimb
parents: 14300
diff changeset
   300
49087
7a17ba4bc997 added author
Christian Sternagel
parents: 45236
diff changeset
   301
lemma Nil_suffixeq [iff]: "suffixeq [] xs"
7a17ba4bc997 added author
Christian Sternagel
parents: 45236
diff changeset
   302
  by (simp add: suffixeq_def)
7a17ba4bc997 added author
Christian Sternagel
parents: 45236
diff changeset
   303
lemma suffixeq_Nil [simp]: "(suffixeq xs []) = (xs = [])"
7a17ba4bc997 added author
Christian Sternagel
parents: 45236
diff changeset
   304
  by (auto simp add: suffixeq_def)
7a17ba4bc997 added author
Christian Sternagel
parents: 45236
diff changeset
   305
49107
ec34e9df0514 misc tuning;
wenzelm
parents: 49087
diff changeset
   306
lemma suffixeq_ConsI: "suffixeq xs ys \<Longrightarrow> suffixeq xs (y # ys)"
49087
7a17ba4bc997 added author
Christian Sternagel
parents: 45236
diff changeset
   307
  by (auto simp add: suffixeq_def)
49107
ec34e9df0514 misc tuning;
wenzelm
parents: 49087
diff changeset
   308
lemma suffixeq_ConsD: "suffixeq (x # xs) ys \<Longrightarrow> suffixeq xs ys"
49087
7a17ba4bc997 added author
Christian Sternagel
parents: 45236
diff changeset
   309
  by (auto simp add: suffixeq_def)
14538
1d9d75a8efae removed o2l and fold_rel; moved postfix to Library/List_Prefix.thy
oheimb
parents: 14300
diff changeset
   310
49087
7a17ba4bc997 added author
Christian Sternagel
parents: 45236
diff changeset
   311
lemma suffixeq_appendI: "suffixeq xs ys \<Longrightarrow> suffixeq xs (zs @ ys)"
7a17ba4bc997 added author
Christian Sternagel
parents: 45236
diff changeset
   312
  by (auto simp add: suffixeq_def)
7a17ba4bc997 added author
Christian Sternagel
parents: 45236
diff changeset
   313
lemma suffixeq_appendD: "suffixeq (zs @ xs) ys \<Longrightarrow> suffixeq xs ys"
7a17ba4bc997 added author
Christian Sternagel
parents: 45236
diff changeset
   314
  by (auto simp add: suffixeq_def)
7a17ba4bc997 added author
Christian Sternagel
parents: 45236
diff changeset
   315
7a17ba4bc997 added author
Christian Sternagel
parents: 45236
diff changeset
   316
lemma suffix_set_subset:
7a17ba4bc997 added author
Christian Sternagel
parents: 45236
diff changeset
   317
  "suffix xs ys \<Longrightarrow> set xs \<subseteq> set ys" by (auto simp: suffix_def)
14538
1d9d75a8efae removed o2l and fold_rel; moved postfix to Library/List_Prefix.thy
oheimb
parents: 14300
diff changeset
   318
49087
7a17ba4bc997 added author
Christian Sternagel
parents: 45236
diff changeset
   319
lemma suffixeq_set_subset:
7a17ba4bc997 added author
Christian Sternagel
parents: 45236
diff changeset
   320
  "suffixeq xs ys \<Longrightarrow> set xs \<subseteq> set ys" by (auto simp: suffixeq_def)
7a17ba4bc997 added author
Christian Sternagel
parents: 45236
diff changeset
   321
49107
ec34e9df0514 misc tuning;
wenzelm
parents: 49087
diff changeset
   322
lemma suffixeq_ConsD2: "suffixeq (x # xs) (y # ys) \<Longrightarrow> suffixeq xs ys"
21305
d41eddfd2b66 tuned proofs;
wenzelm
parents: 19086
diff changeset
   323
proof -
49107
ec34e9df0514 misc tuning;
wenzelm
parents: 49087
diff changeset
   324
  assume "suffixeq (x # xs) (y # ys)"
ec34e9df0514 misc tuning;
wenzelm
parents: 49087
diff changeset
   325
  then obtain zs where "y # ys = zs @ x # xs" ..
49087
7a17ba4bc997 added author
Christian Sternagel
parents: 45236
diff changeset
   326
  then show ?thesis
7a17ba4bc997 added author
Christian Sternagel
parents: 45236
diff changeset
   327
    by (induct zs) (auto intro!: suffixeq_appendI suffixeq_ConsI)
21305
d41eddfd2b66 tuned proofs;
wenzelm
parents: 19086
diff changeset
   328
qed
14538
1d9d75a8efae removed o2l and fold_rel; moved postfix to Library/List_Prefix.thy
oheimb
parents: 14300
diff changeset
   329
49087
7a17ba4bc997 added author
Christian Sternagel
parents: 45236
diff changeset
   330
lemma suffixeq_to_prefixeq [code]: "suffixeq xs ys \<longleftrightarrow> prefixeq (rev xs) (rev ys)"
7a17ba4bc997 added author
Christian Sternagel
parents: 45236
diff changeset
   331
proof
7a17ba4bc997 added author
Christian Sternagel
parents: 45236
diff changeset
   332
  assume "suffixeq xs ys"
7a17ba4bc997 added author
Christian Sternagel
parents: 45236
diff changeset
   333
  then obtain zs where "ys = zs @ xs" ..
7a17ba4bc997 added author
Christian Sternagel
parents: 45236
diff changeset
   334
  then have "rev ys = rev xs @ rev zs" by simp
7a17ba4bc997 added author
Christian Sternagel
parents: 45236
diff changeset
   335
  then show "prefixeq (rev xs) (rev ys)" ..
7a17ba4bc997 added author
Christian Sternagel
parents: 45236
diff changeset
   336
next
7a17ba4bc997 added author
Christian Sternagel
parents: 45236
diff changeset
   337
  assume "prefixeq (rev xs) (rev ys)"
7a17ba4bc997 added author
Christian Sternagel
parents: 45236
diff changeset
   338
  then obtain zs where "rev ys = rev xs @ zs" ..
7a17ba4bc997 added author
Christian Sternagel
parents: 45236
diff changeset
   339
  then have "rev (rev ys) = rev zs @ rev (rev xs)" by simp
7a17ba4bc997 added author
Christian Sternagel
parents: 45236
diff changeset
   340
  then have "ys = rev zs @ xs" by simp
7a17ba4bc997 added author
Christian Sternagel
parents: 45236
diff changeset
   341
  then show "suffixeq xs ys" ..
21305
d41eddfd2b66 tuned proofs;
wenzelm
parents: 19086
diff changeset
   342
qed
14538
1d9d75a8efae removed o2l and fold_rel; moved postfix to Library/List_Prefix.thy
oheimb
parents: 14300
diff changeset
   343
49087
7a17ba4bc997 added author
Christian Sternagel
parents: 45236
diff changeset
   344
lemma distinct_suffixeq: "distinct ys \<Longrightarrow> suffixeq xs ys \<Longrightarrow> distinct xs"
7a17ba4bc997 added author
Christian Sternagel
parents: 45236
diff changeset
   345
  by (clarsimp elim!: suffixeqE)
17201
3bdf1dfcdee4 reactivate postfix by change of syntax;
wenzelm
parents: 15355
diff changeset
   346
49087
7a17ba4bc997 added author
Christian Sternagel
parents: 45236
diff changeset
   347
lemma suffixeq_map: "suffixeq xs ys \<Longrightarrow> suffixeq (map f xs) (map f ys)"
7a17ba4bc997 added author
Christian Sternagel
parents: 45236
diff changeset
   348
  by (auto elim!: suffixeqE intro: suffixeqI)
25299
c3542f70b0fd misc lemmas about prefix, postfix, and parallel
kleing
parents: 23394
diff changeset
   349
49087
7a17ba4bc997 added author
Christian Sternagel
parents: 45236
diff changeset
   350
lemma suffixeq_drop: "suffixeq (drop n as) as"
7a17ba4bc997 added author
Christian Sternagel
parents: 45236
diff changeset
   351
  unfolding suffixeq_def
25692
eda4958ab0d2 tuned proofs, document;
wenzelm
parents: 25665
diff changeset
   352
  apply (rule exI [where x = "take n as"])
eda4958ab0d2 tuned proofs, document;
wenzelm
parents: 25665
diff changeset
   353
  apply simp
eda4958ab0d2 tuned proofs, document;
wenzelm
parents: 25665
diff changeset
   354
  done
25299
c3542f70b0fd misc lemmas about prefix, postfix, and parallel
kleing
parents: 23394
diff changeset
   355
49087
7a17ba4bc997 added author
Christian Sternagel
parents: 45236
diff changeset
   356
lemma suffixeq_take: "suffixeq xs ys \<Longrightarrow> ys = take (length ys - length xs) ys @ xs"
49107
ec34e9df0514 misc tuning;
wenzelm
parents: 49087
diff changeset
   357
  by (auto elim!: suffixeqE)
25299
c3542f70b0fd misc lemmas about prefix, postfix, and parallel
kleing
parents: 23394
diff changeset
   358
49107
ec34e9df0514 misc tuning;
wenzelm
parents: 49087
diff changeset
   359
lemma suffixeq_suffix_reflclp_conv: "suffixeq = suffix\<^sup>=\<^sup>="
49087
7a17ba4bc997 added author
Christian Sternagel
parents: 45236
diff changeset
   360
proof (intro ext iffI)
7a17ba4bc997 added author
Christian Sternagel
parents: 45236
diff changeset
   361
  fix xs ys :: "'a list"
7a17ba4bc997 added author
Christian Sternagel
parents: 45236
diff changeset
   362
  assume "suffixeq xs ys"
7a17ba4bc997 added author
Christian Sternagel
parents: 45236
diff changeset
   363
  show "suffix\<^sup>=\<^sup>= xs ys"
7a17ba4bc997 added author
Christian Sternagel
parents: 45236
diff changeset
   364
  proof
7a17ba4bc997 added author
Christian Sternagel
parents: 45236
diff changeset
   365
    assume "xs \<noteq> ys"
49107
ec34e9df0514 misc tuning;
wenzelm
parents: 49087
diff changeset
   366
    with `suffixeq xs ys` show "suffix xs ys"
ec34e9df0514 misc tuning;
wenzelm
parents: 49087
diff changeset
   367
      by (auto simp: suffixeq_def suffix_def)
49087
7a17ba4bc997 added author
Christian Sternagel
parents: 45236
diff changeset
   368
  qed
7a17ba4bc997 added author
Christian Sternagel
parents: 45236
diff changeset
   369
next
7a17ba4bc997 added author
Christian Sternagel
parents: 45236
diff changeset
   370
  fix xs ys :: "'a list"
7a17ba4bc997 added author
Christian Sternagel
parents: 45236
diff changeset
   371
  assume "suffix\<^sup>=\<^sup>= xs ys"
49107
ec34e9df0514 misc tuning;
wenzelm
parents: 49087
diff changeset
   372
  then show "suffixeq xs ys"
49087
7a17ba4bc997 added author
Christian Sternagel
parents: 45236
diff changeset
   373
  proof
49107
ec34e9df0514 misc tuning;
wenzelm
parents: 49087
diff changeset
   374
    assume "suffix xs ys" then show "suffixeq xs ys"
ec34e9df0514 misc tuning;
wenzelm
parents: 49087
diff changeset
   375
      by (rule suffix_imp_suffixeq)
49087
7a17ba4bc997 added author
Christian Sternagel
parents: 45236
diff changeset
   376
  next
49107
ec34e9df0514 misc tuning;
wenzelm
parents: 49087
diff changeset
   377
    assume "xs = ys" then show "suffixeq xs ys"
ec34e9df0514 misc tuning;
wenzelm
parents: 49087
diff changeset
   378
      by (auto simp: suffixeq_def)
49087
7a17ba4bc997 added author
Christian Sternagel
parents: 45236
diff changeset
   379
  qed
7a17ba4bc997 added author
Christian Sternagel
parents: 45236
diff changeset
   380
qed
7a17ba4bc997 added author
Christian Sternagel
parents: 45236
diff changeset
   381
7a17ba4bc997 added author
Christian Sternagel
parents: 45236
diff changeset
   382
lemma parallelD1: "x \<parallel> y \<Longrightarrow> \<not> prefixeq x y"
25692
eda4958ab0d2 tuned proofs, document;
wenzelm
parents: 25665
diff changeset
   383
  by blast
25299
c3542f70b0fd misc lemmas about prefix, postfix, and parallel
kleing
parents: 23394
diff changeset
   384
49087
7a17ba4bc997 added author
Christian Sternagel
parents: 45236
diff changeset
   385
lemma parallelD2: "x \<parallel> y \<Longrightarrow> \<not> prefixeq y x"
25692
eda4958ab0d2 tuned proofs, document;
wenzelm
parents: 25665
diff changeset
   386
  by blast
25355
69c0a39ba028 avoid implicit use of prems;
wenzelm
parents: 25322
diff changeset
   387
69c0a39ba028 avoid implicit use of prems;
wenzelm
parents: 25322
diff changeset
   388
lemma parallel_Nil1 [simp]: "\<not> x \<parallel> []"
25692
eda4958ab0d2 tuned proofs, document;
wenzelm
parents: 25665
diff changeset
   389
  unfolding parallel_def by simp
25355
69c0a39ba028 avoid implicit use of prems;
wenzelm
parents: 25322
diff changeset
   390
25299
c3542f70b0fd misc lemmas about prefix, postfix, and parallel
kleing
parents: 23394
diff changeset
   391
lemma parallel_Nil2 [simp]: "\<not> [] \<parallel> x"
25692
eda4958ab0d2 tuned proofs, document;
wenzelm
parents: 25665
diff changeset
   392
  unfolding parallel_def by simp
25299
c3542f70b0fd misc lemmas about prefix, postfix, and parallel
kleing
parents: 23394
diff changeset
   393
25564
4ca31a3706a4 R&F: added sgn lemma
nipkow
parents: 25356
diff changeset
   394
lemma Cons_parallelI1: "a \<noteq> b \<Longrightarrow> a # as \<parallel> b # bs"
25692
eda4958ab0d2 tuned proofs, document;
wenzelm
parents: 25665
diff changeset
   395
  by auto
25299
c3542f70b0fd misc lemmas about prefix, postfix, and parallel
kleing
parents: 23394
diff changeset
   396
25564
4ca31a3706a4 R&F: added sgn lemma
nipkow
parents: 25356
diff changeset
   397
lemma Cons_parallelI2: "\<lbrakk> a = b; as \<parallel> bs \<rbrakk> \<Longrightarrow> a # as \<parallel> b # bs"
49087
7a17ba4bc997 added author
Christian Sternagel
parents: 45236
diff changeset
   398
  by (metis Cons_prefixeq_Cons parallelE parallelI)
25665
faabc08af882 removed legacy proofs
nipkow
parents: 25595
diff changeset
   399
25299
c3542f70b0fd misc lemmas about prefix, postfix, and parallel
kleing
parents: 23394
diff changeset
   400
lemma not_equal_is_parallel:
c3542f70b0fd misc lemmas about prefix, postfix, and parallel
kleing
parents: 23394
diff changeset
   401
  assumes neq: "xs \<noteq> ys"
25356
059c03630d6e tuned presentation;
wenzelm
parents: 25355
diff changeset
   402
    and len: "length xs = length ys"
059c03630d6e tuned presentation;
wenzelm
parents: 25355
diff changeset
   403
  shows "xs \<parallel> ys"
25299
c3542f70b0fd misc lemmas about prefix, postfix, and parallel
kleing
parents: 23394
diff changeset
   404
  using len neq
25355
69c0a39ba028 avoid implicit use of prems;
wenzelm
parents: 25322
diff changeset
   405
proof (induct rule: list_induct2)
26445
17223cf843d8 explicit case names for rule list_induct2
haftmann
parents: 25764
diff changeset
   406
  case Nil
25356
059c03630d6e tuned presentation;
wenzelm
parents: 25355
diff changeset
   407
  then show ?case by simp
25299
c3542f70b0fd misc lemmas about prefix, postfix, and parallel
kleing
parents: 23394
diff changeset
   408
next
26445
17223cf843d8 explicit case names for rule list_induct2
haftmann
parents: 25764
diff changeset
   409
  case (Cons a as b bs)
25355
69c0a39ba028 avoid implicit use of prems;
wenzelm
parents: 25322
diff changeset
   410
  have ih: "as \<noteq> bs \<Longrightarrow> as \<parallel> bs" by fact
25299
c3542f70b0fd misc lemmas about prefix, postfix, and parallel
kleing
parents: 23394
diff changeset
   411
  show ?case
c3542f70b0fd misc lemmas about prefix, postfix, and parallel
kleing
parents: 23394
diff changeset
   412
  proof (cases "a = b")
25355
69c0a39ba028 avoid implicit use of prems;
wenzelm
parents: 25322
diff changeset
   413
    case True
26445
17223cf843d8 explicit case names for rule list_induct2
haftmann
parents: 25764
diff changeset
   414
    then have "as \<noteq> bs" using Cons by simp
25355
69c0a39ba028 avoid implicit use of prems;
wenzelm
parents: 25322
diff changeset
   415
    then show ?thesis by (rule Cons_parallelI2 [OF True ih])
25299
c3542f70b0fd misc lemmas about prefix, postfix, and parallel
kleing
parents: 23394
diff changeset
   416
  next
c3542f70b0fd misc lemmas about prefix, postfix, and parallel
kleing
parents: 23394
diff changeset
   417
    case False
25355
69c0a39ba028 avoid implicit use of prems;
wenzelm
parents: 25322
diff changeset
   418
    then show ?thesis by (rule Cons_parallelI1)
25299
c3542f70b0fd misc lemmas about prefix, postfix, and parallel
kleing
parents: 23394
diff changeset
   419
  qed
c3542f70b0fd misc lemmas about prefix, postfix, and parallel
kleing
parents: 23394
diff changeset
   420
qed
22178
29b95968272b made executable
haftmann
parents: 21404
diff changeset
   421
49107
ec34e9df0514 misc tuning;
wenzelm
parents: 49087
diff changeset
   422
lemma suffix_reflclp_conv: "suffix\<^sup>=\<^sup>= = suffixeq"
49087
7a17ba4bc997 added author
Christian Sternagel
parents: 45236
diff changeset
   423
  by (intro ext) (auto simp: suffixeq_def suffix_def)
7a17ba4bc997 added author
Christian Sternagel
parents: 45236
diff changeset
   424
49107
ec34e9df0514 misc tuning;
wenzelm
parents: 49087
diff changeset
   425
lemma suffix_lists: "suffix xs ys \<Longrightarrow> ys \<in> lists A \<Longrightarrow> xs \<in> lists A"
49087
7a17ba4bc997 added author
Christian Sternagel
parents: 45236
diff changeset
   426
  unfolding suffix_def by auto
7a17ba4bc997 added author
Christian Sternagel
parents: 45236
diff changeset
   427
7a17ba4bc997 added author
Christian Sternagel
parents: 45236
diff changeset
   428
50516
ed6b40d15d1c renamed "emb" to "list_hembeq";
Christian Sternagel
parents: 49107
diff changeset
   429
subsection {* Homeomorphic embedding on lists *}
49087
7a17ba4bc997 added author
Christian Sternagel
parents: 45236
diff changeset
   430
50516
ed6b40d15d1c renamed "emb" to "list_hembeq";
Christian Sternagel
parents: 49107
diff changeset
   431
inductive list_hembeq :: "('a \<Rightarrow> 'a \<Rightarrow> bool) \<Rightarrow> 'a list \<Rightarrow> 'a list \<Rightarrow> bool"
49087
7a17ba4bc997 added author
Christian Sternagel
parents: 45236
diff changeset
   432
  for P :: "('a \<Rightarrow> 'a \<Rightarrow> bool)"
7a17ba4bc997 added author
Christian Sternagel
parents: 45236
diff changeset
   433
where
50516
ed6b40d15d1c renamed "emb" to "list_hembeq";
Christian Sternagel
parents: 49107
diff changeset
   434
  list_hembeq_Nil [intro, simp]: "list_hembeq P [] ys"
ed6b40d15d1c renamed "emb" to "list_hembeq";
Christian Sternagel
parents: 49107
diff changeset
   435
| list_hembeq_Cons [intro] : "list_hembeq P xs ys \<Longrightarrow> list_hembeq P xs (y#ys)"
ed6b40d15d1c renamed "emb" to "list_hembeq";
Christian Sternagel
parents: 49107
diff changeset
   436
| list_hembeq_Cons2 [intro]: "P\<^sup>=\<^sup>= x y \<Longrightarrow> list_hembeq P xs ys \<Longrightarrow> list_hembeq P (x#xs) (y#ys)"
ed6b40d15d1c renamed "emb" to "list_hembeq";
Christian Sternagel
parents: 49107
diff changeset
   437
ed6b40d15d1c renamed "emb" to "list_hembeq";
Christian Sternagel
parents: 49107
diff changeset
   438
lemma list_hembeq_Nil2 [simp]:
ed6b40d15d1c renamed "emb" to "list_hembeq";
Christian Sternagel
parents: 49107
diff changeset
   439
  assumes "list_hembeq P xs []" shows "xs = []"
ed6b40d15d1c renamed "emb" to "list_hembeq";
Christian Sternagel
parents: 49107
diff changeset
   440
  using assms by (cases rule: list_hembeq.cases) auto
49087
7a17ba4bc997 added author
Christian Sternagel
parents: 45236
diff changeset
   441
50516
ed6b40d15d1c renamed "emb" to "list_hembeq";
Christian Sternagel
parents: 49107
diff changeset
   442
lemma list_hembeq_refl [simp, intro!]:
ed6b40d15d1c renamed "emb" to "list_hembeq";
Christian Sternagel
parents: 49107
diff changeset
   443
  "list_hembeq P xs xs"
ed6b40d15d1c renamed "emb" to "list_hembeq";
Christian Sternagel
parents: 49107
diff changeset
   444
  by (induct xs) auto
49087
7a17ba4bc997 added author
Christian Sternagel
parents: 45236
diff changeset
   445
50516
ed6b40d15d1c renamed "emb" to "list_hembeq";
Christian Sternagel
parents: 49107
diff changeset
   446
lemma list_hembeq_Cons_Nil [simp]: "list_hembeq P (x#xs) [] = False"
49087
7a17ba4bc997 added author
Christian Sternagel
parents: 45236
diff changeset
   447
proof -
50516
ed6b40d15d1c renamed "emb" to "list_hembeq";
Christian Sternagel
parents: 49107
diff changeset
   448
  { assume "list_hembeq P (x#xs) []"
ed6b40d15d1c renamed "emb" to "list_hembeq";
Christian Sternagel
parents: 49107
diff changeset
   449
    from list_hembeq_Nil2 [OF this] have False by simp
49087
7a17ba4bc997 added author
Christian Sternagel
parents: 45236
diff changeset
   450
  } moreover {
7a17ba4bc997 added author
Christian Sternagel
parents: 45236
diff changeset
   451
    assume False
50516
ed6b40d15d1c renamed "emb" to "list_hembeq";
Christian Sternagel
parents: 49107
diff changeset
   452
    then have "list_hembeq P (x#xs) []" by simp
49087
7a17ba4bc997 added author
Christian Sternagel
parents: 45236
diff changeset
   453
  } ultimately show ?thesis by blast
7a17ba4bc997 added author
Christian Sternagel
parents: 45236
diff changeset
   454
qed
7a17ba4bc997 added author
Christian Sternagel
parents: 45236
diff changeset
   455
50516
ed6b40d15d1c renamed "emb" to "list_hembeq";
Christian Sternagel
parents: 49107
diff changeset
   456
lemma list_hembeq_append2 [intro]: "list_hembeq P xs ys \<Longrightarrow> list_hembeq P xs (zs @ ys)"
49087
7a17ba4bc997 added author
Christian Sternagel
parents: 45236
diff changeset
   457
  by (induct zs) auto
7a17ba4bc997 added author
Christian Sternagel
parents: 45236
diff changeset
   458
50516
ed6b40d15d1c renamed "emb" to "list_hembeq";
Christian Sternagel
parents: 49107
diff changeset
   459
lemma list_hembeq_prefix [intro]:
ed6b40d15d1c renamed "emb" to "list_hembeq";
Christian Sternagel
parents: 49107
diff changeset
   460
  assumes "list_hembeq P xs ys" shows "list_hembeq P xs (ys @ zs)"
49087
7a17ba4bc997 added author
Christian Sternagel
parents: 45236
diff changeset
   461
  using assms
7a17ba4bc997 added author
Christian Sternagel
parents: 45236
diff changeset
   462
  by (induct arbitrary: zs) auto
7a17ba4bc997 added author
Christian Sternagel
parents: 45236
diff changeset
   463
50516
ed6b40d15d1c renamed "emb" to "list_hembeq";
Christian Sternagel
parents: 49107
diff changeset
   464
lemma list_hembeq_ConsD:
ed6b40d15d1c renamed "emb" to "list_hembeq";
Christian Sternagel
parents: 49107
diff changeset
   465
  assumes "list_hembeq P (x#xs) ys"
ed6b40d15d1c renamed "emb" to "list_hembeq";
Christian Sternagel
parents: 49107
diff changeset
   466
  shows "\<exists>us v vs. ys = us @ v # vs \<and> P\<^sup>=\<^sup>= x v \<and> list_hembeq P xs vs"
49087
7a17ba4bc997 added author
Christian Sternagel
parents: 45236
diff changeset
   467
using assms
49107
ec34e9df0514 misc tuning;
wenzelm
parents: 49087
diff changeset
   468
proof (induct x \<equiv> "x # xs" ys arbitrary: x xs)
50516
ed6b40d15d1c renamed "emb" to "list_hembeq";
Christian Sternagel
parents: 49107
diff changeset
   469
  case list_hembeq_Cons
49107
ec34e9df0514 misc tuning;
wenzelm
parents: 49087
diff changeset
   470
  then show ?case by (metis append_Cons)
49087
7a17ba4bc997 added author
Christian Sternagel
parents: 45236
diff changeset
   471
next
50516
ed6b40d15d1c renamed "emb" to "list_hembeq";
Christian Sternagel
parents: 49107
diff changeset
   472
  case (list_hembeq_Cons2 x y xs ys)
54483
9f24325c2550 optimized more bad apples
blanchet
parents: 53015
diff changeset
   473
  then show ?case by blast
49087
7a17ba4bc997 added author
Christian Sternagel
parents: 45236
diff changeset
   474
qed
7a17ba4bc997 added author
Christian Sternagel
parents: 45236
diff changeset
   475
50516
ed6b40d15d1c renamed "emb" to "list_hembeq";
Christian Sternagel
parents: 49107
diff changeset
   476
lemma list_hembeq_appendD:
ed6b40d15d1c renamed "emb" to "list_hembeq";
Christian Sternagel
parents: 49107
diff changeset
   477
  assumes "list_hembeq P (xs @ ys) zs"
ed6b40d15d1c renamed "emb" to "list_hembeq";
Christian Sternagel
parents: 49107
diff changeset
   478
  shows "\<exists>us vs. zs = us @ vs \<and> list_hembeq P xs us \<and> list_hembeq P ys vs"
49087
7a17ba4bc997 added author
Christian Sternagel
parents: 45236
diff changeset
   479
using assms
7a17ba4bc997 added author
Christian Sternagel
parents: 45236
diff changeset
   480
proof (induction xs arbitrary: ys zs)
49107
ec34e9df0514 misc tuning;
wenzelm
parents: 49087
diff changeset
   481
  case Nil then show ?case by auto
49087
7a17ba4bc997 added author
Christian Sternagel
parents: 45236
diff changeset
   482
next
7a17ba4bc997 added author
Christian Sternagel
parents: 45236
diff changeset
   483
  case (Cons x xs)
54483
9f24325c2550 optimized more bad apples
blanchet
parents: 53015
diff changeset
   484
  then obtain us v vs where
9f24325c2550 optimized more bad apples
blanchet
parents: 53015
diff changeset
   485
    zs: "zs = us @ v # vs" and p: "P\<^sup>=\<^sup>= x v" and lh: "list_hembeq P (xs @ ys) vs"
9f24325c2550 optimized more bad apples
blanchet
parents: 53015
diff changeset
   486
    by (auto dest: list_hembeq_ConsD)
9f24325c2550 optimized more bad apples
blanchet
parents: 53015
diff changeset
   487
  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
9f24325c2550 optimized more bad apples
blanchet
parents: 53015
diff changeset
   488
    sk: "\<forall>x\<^sub>0 x\<^sub>1. \<not> list_hembeq 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_hembeq P xs (sk\<^sub>0 x\<^sub>0 x\<^sub>1) \<and> list_hembeq P x\<^sub>0 (sk\<^sub>1 x\<^sub>0 x\<^sub>1)"
9f24325c2550 optimized more bad apples
blanchet
parents: 53015
diff changeset
   489
    using Cons(1) by (metis (no_types))
9f24325c2550 optimized more bad apples
blanchet
parents: 53015
diff changeset
   490
  hence "\<forall>x\<^sub>2. list_hembeq P (x # xs) (x\<^sub>2 @ v # sk\<^sub>0 ys vs)" using p lh by auto
9f24325c2550 optimized more bad apples
blanchet
parents: 53015
diff changeset
   491
  thus ?case using lh zs sk by (metis (no_types) append_Cons append_assoc)
49087
7a17ba4bc997 added author
Christian Sternagel
parents: 45236
diff changeset
   492
qed
7a17ba4bc997 added author
Christian Sternagel
parents: 45236
diff changeset
   493
50516
ed6b40d15d1c renamed "emb" to "list_hembeq";
Christian Sternagel
parents: 49107
diff changeset
   494
lemma list_hembeq_suffix:
ed6b40d15d1c renamed "emb" to "list_hembeq";
Christian Sternagel
parents: 49107
diff changeset
   495
  assumes "list_hembeq P xs ys" and "suffix ys zs"
ed6b40d15d1c renamed "emb" to "list_hembeq";
Christian Sternagel
parents: 49107
diff changeset
   496
  shows "list_hembeq P xs zs"
ed6b40d15d1c renamed "emb" to "list_hembeq";
Christian Sternagel
parents: 49107
diff changeset
   497
  using assms(2) and list_hembeq_append2 [OF assms(1)] by (auto simp: suffix_def)
49087
7a17ba4bc997 added author
Christian Sternagel
parents: 45236
diff changeset
   498
50516
ed6b40d15d1c renamed "emb" to "list_hembeq";
Christian Sternagel
parents: 49107
diff changeset
   499
lemma list_hembeq_suffixeq:
ed6b40d15d1c renamed "emb" to "list_hembeq";
Christian Sternagel
parents: 49107
diff changeset
   500
  assumes "list_hembeq P xs ys" and "suffixeq ys zs"
ed6b40d15d1c renamed "emb" to "list_hembeq";
Christian Sternagel
parents: 49107
diff changeset
   501
  shows "list_hembeq P xs zs"
ed6b40d15d1c renamed "emb" to "list_hembeq";
Christian Sternagel
parents: 49107
diff changeset
   502
  using assms and list_hembeq_suffix unfolding suffixeq_suffix_reflclp_conv by auto
49087
7a17ba4bc997 added author
Christian Sternagel
parents: 45236
diff changeset
   503
50516
ed6b40d15d1c renamed "emb" to "list_hembeq";
Christian Sternagel
parents: 49107
diff changeset
   504
lemma list_hembeq_length: "list_hembeq P xs ys \<Longrightarrow> length xs \<le> length ys"
ed6b40d15d1c renamed "emb" to "list_hembeq";
Christian Sternagel
parents: 49107
diff changeset
   505
  by (induct rule: list_hembeq.induct) auto
49087
7a17ba4bc997 added author
Christian Sternagel
parents: 45236
diff changeset
   506
50516
ed6b40d15d1c renamed "emb" to "list_hembeq";
Christian Sternagel
parents: 49107
diff changeset
   507
lemma list_hembeq_trans:
ed6b40d15d1c renamed "emb" to "list_hembeq";
Christian Sternagel
parents: 49107
diff changeset
   508
  assumes "\<And>x y z. \<lbrakk>x \<in> A; y \<in> A; z \<in> A; P x y; P y z\<rbrakk> \<Longrightarrow> P x z"
ed6b40d15d1c renamed "emb" to "list_hembeq";
Christian Sternagel
parents: 49107
diff changeset
   509
  shows "\<And>xs ys zs. \<lbrakk>xs \<in> lists A; ys \<in> lists A; zs \<in> lists A;
ed6b40d15d1c renamed "emb" to "list_hembeq";
Christian Sternagel
parents: 49107
diff changeset
   510
    list_hembeq P xs ys; list_hembeq P ys zs\<rbrakk> \<Longrightarrow> list_hembeq P xs zs"
ed6b40d15d1c renamed "emb" to "list_hembeq";
Christian Sternagel
parents: 49107
diff changeset
   511
proof -
49087
7a17ba4bc997 added author
Christian Sternagel
parents: 45236
diff changeset
   512
  fix xs ys zs
50516
ed6b40d15d1c renamed "emb" to "list_hembeq";
Christian Sternagel
parents: 49107
diff changeset
   513
  assume "list_hembeq P xs ys" and "list_hembeq P ys zs"
49087
7a17ba4bc997 added author
Christian Sternagel
parents: 45236
diff changeset
   514
    and "xs \<in> lists A" and "ys \<in> lists A" and "zs \<in> lists A"
50516
ed6b40d15d1c renamed "emb" to "list_hembeq";
Christian Sternagel
parents: 49107
diff changeset
   515
  then show "list_hembeq P xs zs"
49087
7a17ba4bc997 added author
Christian Sternagel
parents: 45236
diff changeset
   516
  proof (induction arbitrary: zs)
50516
ed6b40d15d1c renamed "emb" to "list_hembeq";
Christian Sternagel
parents: 49107
diff changeset
   517
    case list_hembeq_Nil show ?case by blast
49087
7a17ba4bc997 added author
Christian Sternagel
parents: 45236
diff changeset
   518
  next
50516
ed6b40d15d1c renamed "emb" to "list_hembeq";
Christian Sternagel
parents: 49107
diff changeset
   519
    case (list_hembeq_Cons xs ys y)
ed6b40d15d1c renamed "emb" to "list_hembeq";
Christian Sternagel
parents: 49107
diff changeset
   520
    from list_hembeq_ConsD [OF `list_hembeq P (y#ys) zs`] obtain us v vs
ed6b40d15d1c renamed "emb" to "list_hembeq";
Christian Sternagel
parents: 49107
diff changeset
   521
      where zs: "zs = us @ v # vs" and "P\<^sup>=\<^sup>= y v" and "list_hembeq P ys vs" by blast
ed6b40d15d1c renamed "emb" to "list_hembeq";
Christian Sternagel
parents: 49107
diff changeset
   522
    then have "list_hembeq P ys (v#vs)" by blast
ed6b40d15d1c renamed "emb" to "list_hembeq";
Christian Sternagel
parents: 49107
diff changeset
   523
    then have "list_hembeq P ys zs" unfolding zs by (rule list_hembeq_append2)
ed6b40d15d1c renamed "emb" to "list_hembeq";
Christian Sternagel
parents: 49107
diff changeset
   524
    from list_hembeq_Cons.IH [OF this] and list_hembeq_Cons.prems show ?case by simp
49087
7a17ba4bc997 added author
Christian Sternagel
parents: 45236
diff changeset
   525
  next
50516
ed6b40d15d1c renamed "emb" to "list_hembeq";
Christian Sternagel
parents: 49107
diff changeset
   526
    case (list_hembeq_Cons2 x y xs ys)
ed6b40d15d1c renamed "emb" to "list_hembeq";
Christian Sternagel
parents: 49107
diff changeset
   527
    from list_hembeq_ConsD [OF `list_hembeq P (y#ys) zs`] obtain us v vs
ed6b40d15d1c renamed "emb" to "list_hembeq";
Christian Sternagel
parents: 49107
diff changeset
   528
      where zs: "zs = us @ v # vs" and "P\<^sup>=\<^sup>= y v" and "list_hembeq P ys vs" by blast
ed6b40d15d1c renamed "emb" to "list_hembeq";
Christian Sternagel
parents: 49107
diff changeset
   529
    with list_hembeq_Cons2 have "list_hembeq P xs vs" by simp
ed6b40d15d1c renamed "emb" to "list_hembeq";
Christian Sternagel
parents: 49107
diff changeset
   530
    moreover have "P\<^sup>=\<^sup>= x v"
49087
7a17ba4bc997 added author
Christian Sternagel
parents: 45236
diff changeset
   531
    proof -
7a17ba4bc997 added author
Christian Sternagel
parents: 45236
diff changeset
   532
      from zs and `zs \<in> lists A` have "v \<in> A" by auto
50516
ed6b40d15d1c renamed "emb" to "list_hembeq";
Christian Sternagel
parents: 49107
diff changeset
   533
      moreover have "x \<in> A" and "y \<in> A" using list_hembeq_Cons2 by simp_all
ed6b40d15d1c renamed "emb" to "list_hembeq";
Christian Sternagel
parents: 49107
diff changeset
   534
      ultimately show ?thesis
ed6b40d15d1c renamed "emb" to "list_hembeq";
Christian Sternagel
parents: 49107
diff changeset
   535
        using `P\<^sup>=\<^sup>= x y` and `P\<^sup>=\<^sup>= y v` and assms
ed6b40d15d1c renamed "emb" to "list_hembeq";
Christian Sternagel
parents: 49107
diff changeset
   536
        by blast
49087
7a17ba4bc997 added author
Christian Sternagel
parents: 45236
diff changeset
   537
    qed
50516
ed6b40d15d1c renamed "emb" to "list_hembeq";
Christian Sternagel
parents: 49107
diff changeset
   538
    ultimately have "list_hembeq P (x#xs) (v#vs)" by blast
ed6b40d15d1c renamed "emb" to "list_hembeq";
Christian Sternagel
parents: 49107
diff changeset
   539
    then show ?case unfolding zs by (rule list_hembeq_append2)
49087
7a17ba4bc997 added author
Christian Sternagel
parents: 45236
diff changeset
   540
  qed
7a17ba4bc997 added author
Christian Sternagel
parents: 45236
diff changeset
   541
qed
7a17ba4bc997 added author
Christian Sternagel
parents: 45236
diff changeset
   542
7a17ba4bc997 added author
Christian Sternagel
parents: 45236
diff changeset
   543
50516
ed6b40d15d1c renamed "emb" to "list_hembeq";
Christian Sternagel
parents: 49107
diff changeset
   544
subsection {* Sublists (special case of homeomorphic embedding) *}
49087
7a17ba4bc997 added author
Christian Sternagel
parents: 45236
diff changeset
   545
50516
ed6b40d15d1c renamed "emb" to "list_hembeq";
Christian Sternagel
parents: 49107
diff changeset
   546
abbreviation sublisteq :: "'a list \<Rightarrow> 'a list \<Rightarrow> bool"
ed6b40d15d1c renamed "emb" to "list_hembeq";
Christian Sternagel
parents: 49107
diff changeset
   547
  where "sublisteq xs ys \<equiv> list_hembeq (op =) xs ys"
49087
7a17ba4bc997 added author
Christian Sternagel
parents: 45236
diff changeset
   548
50516
ed6b40d15d1c renamed "emb" to "list_hembeq";
Christian Sternagel
parents: 49107
diff changeset
   549
lemma sublisteq_Cons2: "sublisteq xs ys \<Longrightarrow> sublisteq (x#xs) (x#ys)" by auto
49087
7a17ba4bc997 added author
Christian Sternagel
parents: 45236
diff changeset
   550
50516
ed6b40d15d1c renamed "emb" to "list_hembeq";
Christian Sternagel
parents: 49107
diff changeset
   551
lemma sublisteq_same_length:
ed6b40d15d1c renamed "emb" to "list_hembeq";
Christian Sternagel
parents: 49107
diff changeset
   552
  assumes "sublisteq xs ys" and "length xs = length ys" shows "xs = ys"
ed6b40d15d1c renamed "emb" to "list_hembeq";
Christian Sternagel
parents: 49107
diff changeset
   553
  using assms by (induct) (auto dest: list_hembeq_length)
49087
7a17ba4bc997 added author
Christian Sternagel
parents: 45236
diff changeset
   554
50516
ed6b40d15d1c renamed "emb" to "list_hembeq";
Christian Sternagel
parents: 49107
diff changeset
   555
lemma not_sublisteq_length [simp]: "length ys < length xs \<Longrightarrow> \<not> sublisteq xs ys"
ed6b40d15d1c renamed "emb" to "list_hembeq";
Christian Sternagel
parents: 49107
diff changeset
   556
  by (metis list_hembeq_length linorder_not_less)
49087
7a17ba4bc997 added author
Christian Sternagel
parents: 45236
diff changeset
   557
7a17ba4bc997 added author
Christian Sternagel
parents: 45236
diff changeset
   558
lemma [code]:
50516
ed6b40d15d1c renamed "emb" to "list_hembeq";
Christian Sternagel
parents: 49107
diff changeset
   559
  "list_hembeq P [] ys \<longleftrightarrow> True"
ed6b40d15d1c renamed "emb" to "list_hembeq";
Christian Sternagel
parents: 49107
diff changeset
   560
  "list_hembeq P (x#xs) [] \<longleftrightarrow> False"
49087
7a17ba4bc997 added author
Christian Sternagel
parents: 45236
diff changeset
   561
  by (simp_all)
7a17ba4bc997 added author
Christian Sternagel
parents: 45236
diff changeset
   562
50516
ed6b40d15d1c renamed "emb" to "list_hembeq";
Christian Sternagel
parents: 49107
diff changeset
   563
lemma sublisteq_Cons': "sublisteq (x#xs) ys \<Longrightarrow> sublisteq xs ys"
54483
9f24325c2550 optimized more bad apples
blanchet
parents: 53015
diff changeset
   564
  by (induct xs, simp, blast dest: list_hembeq_ConsD)
49087
7a17ba4bc997 added author
Christian Sternagel
parents: 45236
diff changeset
   565
50516
ed6b40d15d1c renamed "emb" to "list_hembeq";
Christian Sternagel
parents: 49107
diff changeset
   566
lemma sublisteq_Cons2':
ed6b40d15d1c renamed "emb" to "list_hembeq";
Christian Sternagel
parents: 49107
diff changeset
   567
  assumes "sublisteq (x#xs) (x#ys)" shows "sublisteq xs ys"
ed6b40d15d1c renamed "emb" to "list_hembeq";
Christian Sternagel
parents: 49107
diff changeset
   568
  using assms by (cases) (rule sublisteq_Cons')
49087
7a17ba4bc997 added author
Christian Sternagel
parents: 45236
diff changeset
   569
50516
ed6b40d15d1c renamed "emb" to "list_hembeq";
Christian Sternagel
parents: 49107
diff changeset
   570
lemma sublisteq_Cons2_neq:
ed6b40d15d1c renamed "emb" to "list_hembeq";
Christian Sternagel
parents: 49107
diff changeset
   571
  assumes "sublisteq (x#xs) (y#ys)"
ed6b40d15d1c renamed "emb" to "list_hembeq";
Christian Sternagel
parents: 49107
diff changeset
   572
  shows "x \<noteq> y \<Longrightarrow> sublisteq (x#xs) ys"
49087
7a17ba4bc997 added author
Christian Sternagel
parents: 45236
diff changeset
   573
  using assms by (cases) auto
7a17ba4bc997 added author
Christian Sternagel
parents: 45236
diff changeset
   574
50516
ed6b40d15d1c renamed "emb" to "list_hembeq";
Christian Sternagel
parents: 49107
diff changeset
   575
lemma sublisteq_Cons2_iff [simp, code]:
ed6b40d15d1c renamed "emb" to "list_hembeq";
Christian Sternagel
parents: 49107
diff changeset
   576
  "sublisteq (x#xs) (y#ys) = (if x = y then sublisteq xs ys else sublisteq (x#xs) ys)"
ed6b40d15d1c renamed "emb" to "list_hembeq";
Christian Sternagel
parents: 49107
diff changeset
   577
  by (metis list_hembeq_Cons sublisteq_Cons2 sublisteq_Cons2' sublisteq_Cons2_neq)
49087
7a17ba4bc997 added author
Christian Sternagel
parents: 45236
diff changeset
   578
50516
ed6b40d15d1c renamed "emb" to "list_hembeq";
Christian Sternagel
parents: 49107
diff changeset
   579
lemma sublisteq_append': "sublisteq (zs @ xs) (zs @ ys) \<longleftrightarrow> sublisteq xs ys"
49087
7a17ba4bc997 added author
Christian Sternagel
parents: 45236
diff changeset
   580
  by (induct zs) simp_all
7a17ba4bc997 added author
Christian Sternagel
parents: 45236
diff changeset
   581
50516
ed6b40d15d1c renamed "emb" to "list_hembeq";
Christian Sternagel
parents: 49107
diff changeset
   582
lemma sublisteq_refl [simp, intro!]: "sublisteq xs xs" by (induct xs) simp_all
49087
7a17ba4bc997 added author
Christian Sternagel
parents: 45236
diff changeset
   583
50516
ed6b40d15d1c renamed "emb" to "list_hembeq";
Christian Sternagel
parents: 49107
diff changeset
   584
lemma sublisteq_antisym:
ed6b40d15d1c renamed "emb" to "list_hembeq";
Christian Sternagel
parents: 49107
diff changeset
   585
  assumes "sublisteq xs ys" and "sublisteq ys xs"
49087
7a17ba4bc997 added author
Christian Sternagel
parents: 45236
diff changeset
   586
  shows "xs = ys"
7a17ba4bc997 added author
Christian Sternagel
parents: 45236
diff changeset
   587
using assms
7a17ba4bc997 added author
Christian Sternagel
parents: 45236
diff changeset
   588
proof (induct)
50516
ed6b40d15d1c renamed "emb" to "list_hembeq";
Christian Sternagel
parents: 49107
diff changeset
   589
  case list_hembeq_Nil
ed6b40d15d1c renamed "emb" to "list_hembeq";
Christian Sternagel
parents: 49107
diff changeset
   590
  from list_hembeq_Nil2 [OF this] show ?case by simp
49087
7a17ba4bc997 added author
Christian Sternagel
parents: 45236
diff changeset
   591
next
50516
ed6b40d15d1c renamed "emb" to "list_hembeq";
Christian Sternagel
parents: 49107
diff changeset
   592
  case list_hembeq_Cons2
54483
9f24325c2550 optimized more bad apples
blanchet
parents: 53015
diff changeset
   593
  thus ?case by simp
49087
7a17ba4bc997 added author
Christian Sternagel
parents: 45236
diff changeset
   594
next
50516
ed6b40d15d1c renamed "emb" to "list_hembeq";
Christian Sternagel
parents: 49107
diff changeset
   595
  case list_hembeq_Cons
54483
9f24325c2550 optimized more bad apples
blanchet
parents: 53015
diff changeset
   596
  hence False using sublisteq_Cons' by fastforce
9f24325c2550 optimized more bad apples
blanchet
parents: 53015
diff changeset
   597
  thus ?case ..
49087
7a17ba4bc997 added author
Christian Sternagel
parents: 45236
diff changeset
   598
qed
7a17ba4bc997 added author
Christian Sternagel
parents: 45236
diff changeset
   599
50516
ed6b40d15d1c renamed "emb" to "list_hembeq";
Christian Sternagel
parents: 49107
diff changeset
   600
lemma sublisteq_trans: "sublisteq xs ys \<Longrightarrow> sublisteq ys zs \<Longrightarrow> sublisteq xs zs"
ed6b40d15d1c renamed "emb" to "list_hembeq";
Christian Sternagel
parents: 49107
diff changeset
   601
  by (rule list_hembeq_trans [of UNIV "op ="]) auto
49087
7a17ba4bc997 added author
Christian Sternagel
parents: 45236
diff changeset
   602
50516
ed6b40d15d1c renamed "emb" to "list_hembeq";
Christian Sternagel
parents: 49107
diff changeset
   603
lemma sublisteq_append_le_same_iff: "sublisteq (xs @ ys) ys \<longleftrightarrow> xs = []"
ed6b40d15d1c renamed "emb" to "list_hembeq";
Christian Sternagel
parents: 49107
diff changeset
   604
  by (auto dest: list_hembeq_length)
49087
7a17ba4bc997 added author
Christian Sternagel
parents: 45236
diff changeset
   605
50516
ed6b40d15d1c renamed "emb" to "list_hembeq";
Christian Sternagel
parents: 49107
diff changeset
   606
lemma list_hembeq_append_mono:
ed6b40d15d1c renamed "emb" to "list_hembeq";
Christian Sternagel
parents: 49107
diff changeset
   607
  "\<lbrakk> list_hembeq P xs xs'; list_hembeq P ys ys' \<rbrakk> \<Longrightarrow> list_hembeq P (xs@ys) (xs'@ys')"
ed6b40d15d1c renamed "emb" to "list_hembeq";
Christian Sternagel
parents: 49107
diff changeset
   608
  apply (induct rule: list_hembeq.induct)
ed6b40d15d1c renamed "emb" to "list_hembeq";
Christian Sternagel
parents: 49107
diff changeset
   609
    apply (metis eq_Nil_appendI list_hembeq_append2)
ed6b40d15d1c renamed "emb" to "list_hembeq";
Christian Sternagel
parents: 49107
diff changeset
   610
   apply (metis append_Cons list_hembeq_Cons)
ed6b40d15d1c renamed "emb" to "list_hembeq";
Christian Sternagel
parents: 49107
diff changeset
   611
  apply (metis append_Cons list_hembeq_Cons2)
49107
ec34e9df0514 misc tuning;
wenzelm
parents: 49087
diff changeset
   612
  done
49087
7a17ba4bc997 added author
Christian Sternagel
parents: 45236
diff changeset
   613
7a17ba4bc997 added author
Christian Sternagel
parents: 45236
diff changeset
   614
7a17ba4bc997 added author
Christian Sternagel
parents: 45236
diff changeset
   615
subsection {* Appending elements *}
7a17ba4bc997 added author
Christian Sternagel
parents: 45236
diff changeset
   616
50516
ed6b40d15d1c renamed "emb" to "list_hembeq";
Christian Sternagel
parents: 49107
diff changeset
   617
lemma sublisteq_append [simp]:
ed6b40d15d1c renamed "emb" to "list_hembeq";
Christian Sternagel
parents: 49107
diff changeset
   618
  "sublisteq (xs @ zs) (ys @ zs) \<longleftrightarrow> sublisteq xs ys" (is "?l = ?r")
49087
7a17ba4bc997 added author
Christian Sternagel
parents: 45236
diff changeset
   619
proof
50516
ed6b40d15d1c renamed "emb" to "list_hembeq";
Christian Sternagel
parents: 49107
diff changeset
   620
  { fix xs' ys' xs ys zs :: "'a list" assume "sublisteq xs' ys'"
ed6b40d15d1c renamed "emb" to "list_hembeq";
Christian Sternagel
parents: 49107
diff changeset
   621
    then have "xs' = xs @ zs & ys' = ys @ zs \<longrightarrow> sublisteq xs ys"
49087
7a17ba4bc997 added author
Christian Sternagel
parents: 45236
diff changeset
   622
    proof (induct arbitrary: xs ys zs)
50516
ed6b40d15d1c renamed "emb" to "list_hembeq";
Christian Sternagel
parents: 49107
diff changeset
   623
      case list_hembeq_Nil show ?case by simp
49087
7a17ba4bc997 added author
Christian Sternagel
parents: 45236
diff changeset
   624
    next
50516
ed6b40d15d1c renamed "emb" to "list_hembeq";
Christian Sternagel
parents: 49107
diff changeset
   625
      case (list_hembeq_Cons xs' ys' x)
ed6b40d15d1c renamed "emb" to "list_hembeq";
Christian Sternagel
parents: 49107
diff changeset
   626
      { assume "ys=[]" then have ?case using list_hembeq_Cons(1) by auto }
49087
7a17ba4bc997 added author
Christian Sternagel
parents: 45236
diff changeset
   627
      moreover
7a17ba4bc997 added author
Christian Sternagel
parents: 45236
diff changeset
   628
      { fix us assume "ys = x#us"
50516
ed6b40d15d1c renamed "emb" to "list_hembeq";
Christian Sternagel
parents: 49107
diff changeset
   629
        then have ?case using list_hembeq_Cons(2) by(simp add: list_hembeq.list_hembeq_Cons) }
49087
7a17ba4bc997 added author
Christian Sternagel
parents: 45236
diff changeset
   630
      ultimately show ?case by (auto simp:Cons_eq_append_conv)
7a17ba4bc997 added author
Christian Sternagel
parents: 45236
diff changeset
   631
    next
50516
ed6b40d15d1c renamed "emb" to "list_hembeq";
Christian Sternagel
parents: 49107
diff changeset
   632
      case (list_hembeq_Cons2 x y xs' ys')
ed6b40d15d1c renamed "emb" to "list_hembeq";
Christian Sternagel
parents: 49107
diff changeset
   633
      { assume "xs=[]" then have ?case using list_hembeq_Cons2(1) by auto }
49087
7a17ba4bc997 added author
Christian Sternagel
parents: 45236
diff changeset
   634
      moreover
50516
ed6b40d15d1c renamed "emb" to "list_hembeq";
Christian Sternagel
parents: 49107
diff changeset
   635
      { fix us vs assume "xs=x#us" "ys=x#vs" then have ?case using list_hembeq_Cons2 by auto}
49087
7a17ba4bc997 added author
Christian Sternagel
parents: 45236
diff changeset
   636
      moreover
50516
ed6b40d15d1c renamed "emb" to "list_hembeq";
Christian Sternagel
parents: 49107
diff changeset
   637
      { fix us assume "xs=x#us" "ys=[]" then have ?case using list_hembeq_Cons2(2) by bestsimp }
ed6b40d15d1c renamed "emb" to "list_hembeq";
Christian Sternagel
parents: 49107
diff changeset
   638
      ultimately show ?case using `op =\<^sup>=\<^sup>= x y` by (auto simp: Cons_eq_append_conv)
49087
7a17ba4bc997 added author
Christian Sternagel
parents: 45236
diff changeset
   639
    qed }
7a17ba4bc997 added author
Christian Sternagel
parents: 45236
diff changeset
   640
  moreover assume ?l
7a17ba4bc997 added author
Christian Sternagel
parents: 45236
diff changeset
   641
  ultimately show ?r by blast
7a17ba4bc997 added author
Christian Sternagel
parents: 45236
diff changeset
   642
next
50516
ed6b40d15d1c renamed "emb" to "list_hembeq";
Christian Sternagel
parents: 49107
diff changeset
   643
  assume ?r then show ?l by (metis list_hembeq_append_mono sublisteq_refl)
49087
7a17ba4bc997 added author
Christian Sternagel
parents: 45236
diff changeset
   644
qed
7a17ba4bc997 added author
Christian Sternagel
parents: 45236
diff changeset
   645
50516
ed6b40d15d1c renamed "emb" to "list_hembeq";
Christian Sternagel
parents: 49107
diff changeset
   646
lemma sublisteq_drop_many: "sublisteq xs ys \<Longrightarrow> sublisteq xs (zs @ ys)"
49087
7a17ba4bc997 added author
Christian Sternagel
parents: 45236
diff changeset
   647
  by (induct zs) auto
7a17ba4bc997 added author
Christian Sternagel
parents: 45236
diff changeset
   648
50516
ed6b40d15d1c renamed "emb" to "list_hembeq";
Christian Sternagel
parents: 49107
diff changeset
   649
lemma sublisteq_rev_drop_many: "sublisteq xs ys \<Longrightarrow> sublisteq xs (ys @ zs)"
ed6b40d15d1c renamed "emb" to "list_hembeq";
Christian Sternagel
parents: 49107
diff changeset
   650
  by (metis append_Nil2 list_hembeq_Nil list_hembeq_append_mono)
49087
7a17ba4bc997 added author
Christian Sternagel
parents: 45236
diff changeset
   651
7a17ba4bc997 added author
Christian Sternagel
parents: 45236
diff changeset
   652
7a17ba4bc997 added author
Christian Sternagel
parents: 45236
diff changeset
   653
subsection {* Relation to standard list operations *}
7a17ba4bc997 added author
Christian Sternagel
parents: 45236
diff changeset
   654
50516
ed6b40d15d1c renamed "emb" to "list_hembeq";
Christian Sternagel
parents: 49107
diff changeset
   655
lemma sublisteq_map:
ed6b40d15d1c renamed "emb" to "list_hembeq";
Christian Sternagel
parents: 49107
diff changeset
   656
  assumes "sublisteq xs ys" shows "sublisteq (map f xs) (map f ys)"
49087
7a17ba4bc997 added author
Christian Sternagel
parents: 45236
diff changeset
   657
  using assms by (induct) auto
7a17ba4bc997 added author
Christian Sternagel
parents: 45236
diff changeset
   658
50516
ed6b40d15d1c renamed "emb" to "list_hembeq";
Christian Sternagel
parents: 49107
diff changeset
   659
lemma sublisteq_filter_left [simp]: "sublisteq (filter P xs) xs"
49087
7a17ba4bc997 added author
Christian Sternagel
parents: 45236
diff changeset
   660
  by (induct xs) auto
7a17ba4bc997 added author
Christian Sternagel
parents: 45236
diff changeset
   661
50516
ed6b40d15d1c renamed "emb" to "list_hembeq";
Christian Sternagel
parents: 49107
diff changeset
   662
lemma sublisteq_filter [simp]:
ed6b40d15d1c renamed "emb" to "list_hembeq";
Christian Sternagel
parents: 49107
diff changeset
   663
  assumes "sublisteq xs ys" shows "sublisteq (filter P xs) (filter P ys)"
54483
9f24325c2550 optimized more bad apples
blanchet
parents: 53015
diff changeset
   664
  using assms by induct auto
49087
7a17ba4bc997 added author
Christian Sternagel
parents: 45236
diff changeset
   665
50516
ed6b40d15d1c renamed "emb" to "list_hembeq";
Christian Sternagel
parents: 49107
diff changeset
   666
lemma "sublisteq xs ys \<longleftrightarrow> (\<exists>N. xs = sublist ys N)" (is "?L = ?R")
49087
7a17ba4bc997 added author
Christian Sternagel
parents: 45236
diff changeset
   667
proof
7a17ba4bc997 added author
Christian Sternagel
parents: 45236
diff changeset
   668
  assume ?L
49107
ec34e9df0514 misc tuning;
wenzelm
parents: 49087
diff changeset
   669
  then show ?R
49087
7a17ba4bc997 added author
Christian Sternagel
parents: 45236
diff changeset
   670
  proof (induct)
50516
ed6b40d15d1c renamed "emb" to "list_hembeq";
Christian Sternagel
parents: 49107
diff changeset
   671
    case list_hembeq_Nil show ?case by (metis sublist_empty)
49087
7a17ba4bc997 added author
Christian Sternagel
parents: 45236
diff changeset
   672
  next
50516
ed6b40d15d1c renamed "emb" to "list_hembeq";
Christian Sternagel
parents: 49107
diff changeset
   673
    case (list_hembeq_Cons xs ys x)
49087
7a17ba4bc997 added author
Christian Sternagel
parents: 45236
diff changeset
   674
    then obtain N where "xs = sublist ys N" by blast
49107
ec34e9df0514 misc tuning;
wenzelm
parents: 49087
diff changeset
   675
    then have "xs = sublist (x#ys) (Suc ` N)"
49087
7a17ba4bc997 added author
Christian Sternagel
parents: 45236
diff changeset
   676
      by (clarsimp simp add:sublist_Cons inj_image_mem_iff)
49107
ec34e9df0514 misc tuning;
wenzelm
parents: 49087
diff changeset
   677
    then show ?case by blast
49087
7a17ba4bc997 added author
Christian Sternagel
parents: 45236
diff changeset
   678
  next
50516
ed6b40d15d1c renamed "emb" to "list_hembeq";
Christian Sternagel
parents: 49107
diff changeset
   679
    case (list_hembeq_Cons2 x y xs ys)
49087
7a17ba4bc997 added author
Christian Sternagel
parents: 45236
diff changeset
   680
    then obtain N where "xs = sublist ys N" by blast
49107
ec34e9df0514 misc tuning;
wenzelm
parents: 49087
diff changeset
   681
    then have "x#xs = sublist (x#ys) (insert 0 (Suc ` N))"
49087
7a17ba4bc997 added author
Christian Sternagel
parents: 45236
diff changeset
   682
      by (clarsimp simp add:sublist_Cons inj_image_mem_iff)
50516
ed6b40d15d1c renamed "emb" to "list_hembeq";
Christian Sternagel
parents: 49107
diff changeset
   683
    moreover from list_hembeq_Cons2 have "x = y" by simp
ed6b40d15d1c renamed "emb" to "list_hembeq";
Christian Sternagel
parents: 49107
diff changeset
   684
    ultimately show ?case by blast
49087
7a17ba4bc997 added author
Christian Sternagel
parents: 45236
diff changeset
   685
  qed
7a17ba4bc997 added author
Christian Sternagel
parents: 45236
diff changeset
   686
next
7a17ba4bc997 added author
Christian Sternagel
parents: 45236
diff changeset
   687
  assume ?R
7a17ba4bc997 added author
Christian Sternagel
parents: 45236
diff changeset
   688
  then obtain N where "xs = sublist ys N" ..
50516
ed6b40d15d1c renamed "emb" to "list_hembeq";
Christian Sternagel
parents: 49107
diff changeset
   689
  moreover have "sublisteq (sublist ys N) ys"
49107
ec34e9df0514 misc tuning;
wenzelm
parents: 49087
diff changeset
   690
  proof (induct ys arbitrary: N)
49087
7a17ba4bc997 added author
Christian Sternagel
parents: 45236
diff changeset
   691
    case Nil show ?case by simp
7a17ba4bc997 added author
Christian Sternagel
parents: 45236
diff changeset
   692
  next
49107
ec34e9df0514 misc tuning;
wenzelm
parents: 49087
diff changeset
   693
    case Cons then show ?case by (auto simp: sublist_Cons)
49087
7a17ba4bc997 added author
Christian Sternagel
parents: 45236
diff changeset
   694
  qed
7a17ba4bc997 added author
Christian Sternagel
parents: 45236
diff changeset
   695
  ultimately show ?L by simp
7a17ba4bc997 added author
Christian Sternagel
parents: 45236
diff changeset
   696
qed
7a17ba4bc997 added author
Christian Sternagel
parents: 45236
diff changeset
   697
10330
4362e906b745 "List prefixes" library theory (replaces old Lex/Prefix);
wenzelm
parents:
diff changeset
   698
end