src/HOL/Library/Sublist.thy
author Christian Sternagel
Wed, 29 Aug 2012 11:05:44 +0900
changeset 49082 d71cdd1171c3
parent 45236 src/HOL/Library/List_Prefix.thy@ac4a2a66707d
permissions -rw-r--r--
more lemmas on suffixes and embedding
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
49082
d71cdd1171c3 more lemmas on suffixes and embedding
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
4362e906b745 "List prefixes" library theory (replaces old Lex/Prefix);
wenzelm
parents:
diff changeset
     3
*)
4362e906b745 "List prefixes" library theory (replaces old Lex/Prefix);
wenzelm
parents:
diff changeset
     4
49082
d71cdd1171c3 more lemmas on suffixes and embedding
Christian Sternagel
parents: 45236
diff changeset
     5
header {* List prefixes, suffixes, and embedding*}
10330
4362e906b745 "List prefixes" library theory (replaces old Lex/Prefix);
wenzelm
parents:
diff changeset
     6
49082
d71cdd1171c3 more lemmas on suffixes and embedding
Christian Sternagel
parents: 45236
diff changeset
     7
theory Sublist
30663
0b6aff7451b2 Main is (Complex_Main) base entry point in library theories
haftmann
parents: 28562
diff changeset
     8
imports List Main
15131
c69542757a4d New theory header syntax.
nipkow
parents: 14981
diff changeset
     9
begin
10330
4362e906b745 "List prefixes" library theory (replaces old Lex/Prefix);
wenzelm
parents:
diff changeset
    10
4362e906b745 "List prefixes" library theory (replaces old Lex/Prefix);
wenzelm
parents:
diff changeset
    11
subsection {* Prefix order on lists *}
4362e906b745 "List prefixes" library theory (replaces old Lex/Prefix);
wenzelm
parents:
diff changeset
    12
37474
ce943f9edf5e added bot instances; tuned
haftmann
parents: 30663
diff changeset
    13
instantiation list :: (type) "{order, bot}"
25764
878c37886eed removed some legacy instantiations
haftmann
parents: 25692
diff changeset
    14
begin
878c37886eed removed some legacy instantiations
haftmann
parents: 25692
diff changeset
    15
878c37886eed removed some legacy instantiations
haftmann
parents: 25692
diff changeset
    16
definition
49082
d71cdd1171c3 more lemmas on suffixes and embedding
Christian Sternagel
parents: 45236
diff changeset
    17
  prefixeq_def: "xs \<le> ys \<longleftrightarrow> (\<exists>zs. ys = xs @ zs)"
10330
4362e906b745 "List prefixes" library theory (replaces old Lex/Prefix);
wenzelm
parents:
diff changeset
    18
25764
878c37886eed removed some legacy instantiations
haftmann
parents: 25692
diff changeset
    19
definition
49082
d71cdd1171c3 more lemmas on suffixes and embedding
Christian Sternagel
parents: 45236
diff changeset
    20
  prefix_def: "xs < ys \<longleftrightarrow> xs \<le> ys \<and> xs \<noteq> (ys::'a list)"
10330
4362e906b745 "List prefixes" library theory (replaces old Lex/Prefix);
wenzelm
parents:
diff changeset
    21
37474
ce943f9edf5e added bot instances; tuned
haftmann
parents: 30663
diff changeset
    22
definition
ce943f9edf5e added bot instances; tuned
haftmann
parents: 30663
diff changeset
    23
  "bot = []"
ce943f9edf5e added bot instances; tuned
haftmann
parents: 30663
diff changeset
    24
ce943f9edf5e added bot instances; tuned
haftmann
parents: 30663
diff changeset
    25
instance proof
49082
d71cdd1171c3 more lemmas on suffixes and embedding
Christian Sternagel
parents: 45236
diff changeset
    26
qed (auto simp add: prefixeq_def prefix_def bot_list_def)
10330
4362e906b745 "List prefixes" library theory (replaces old Lex/Prefix);
wenzelm
parents:
diff changeset
    27
25764
878c37886eed removed some legacy instantiations
haftmann
parents: 25692
diff changeset
    28
end
878c37886eed removed some legacy instantiations
haftmann
parents: 25692
diff changeset
    29
49082
d71cdd1171c3 more lemmas on suffixes and embedding
Christian Sternagel
parents: 45236
diff changeset
    30
lemma prefixeqI [intro?]: "ys = xs @ zs ==> xs \<le> ys"
d71cdd1171c3 more lemmas on suffixes and embedding
Christian Sternagel
parents: 45236
diff changeset
    31
  unfolding prefixeq_def by blast
10330
4362e906b745 "List prefixes" library theory (replaces old Lex/Prefix);
wenzelm
parents:
diff changeset
    32
49082
d71cdd1171c3 more lemmas on suffixes and embedding
Christian Sternagel
parents: 45236
diff changeset
    33
lemma prefixeqE [elim?]:
21305
d41eddfd2b66 tuned proofs;
wenzelm
parents: 19086
diff changeset
    34
  assumes "xs \<le> ys"
d41eddfd2b66 tuned proofs;
wenzelm
parents: 19086
diff changeset
    35
  obtains zs where "ys = xs @ zs"
49082
d71cdd1171c3 more lemmas on suffixes and embedding
Christian Sternagel
parents: 45236
diff changeset
    36
  using assms unfolding prefixeq_def by blast
10330
4362e906b745 "List prefixes" library theory (replaces old Lex/Prefix);
wenzelm
parents:
diff changeset
    37
49082
d71cdd1171c3 more lemmas on suffixes and embedding
Christian Sternagel
parents: 45236
diff changeset
    38
lemma prefixI' [intro?]: "ys = xs @ z # zs ==> xs < ys"
d71cdd1171c3 more lemmas on suffixes and embedding
Christian Sternagel
parents: 45236
diff changeset
    39
  unfolding prefix_def prefixeq_def by blast
10870
9444e3cf37e1 added strict_prefixI', strict_prefixE';
wenzelm
parents: 10512
diff changeset
    40
49082
d71cdd1171c3 more lemmas on suffixes and embedding
Christian Sternagel
parents: 45236
diff changeset
    41
lemma prefixE' [elim?]:
21305
d41eddfd2b66 tuned proofs;
wenzelm
parents: 19086
diff changeset
    42
  assumes "xs < ys"
d41eddfd2b66 tuned proofs;
wenzelm
parents: 19086
diff changeset
    43
  obtains z zs where "ys = xs @ z # zs"
10870
9444e3cf37e1 added strict_prefixI', strict_prefixE';
wenzelm
parents: 10512
diff changeset
    44
proof -
21305
d41eddfd2b66 tuned proofs;
wenzelm
parents: 19086
diff changeset
    45
  from `xs < ys` obtain us where "ys = xs @ us" and "xs \<noteq> ys"
49082
d71cdd1171c3 more lemmas on suffixes and embedding
Christian Sternagel
parents: 45236
diff changeset
    46
    unfolding prefix_def prefixeq_def by blast
21305
d41eddfd2b66 tuned proofs;
wenzelm
parents: 19086
diff changeset
    47
  with that show ?thesis by (auto simp add: neq_Nil_conv)
10870
9444e3cf37e1 added strict_prefixI', strict_prefixE';
wenzelm
parents: 10512
diff changeset
    48
qed
9444e3cf37e1 added strict_prefixI', strict_prefixE';
wenzelm
parents: 10512
diff changeset
    49
49082
d71cdd1171c3 more lemmas on suffixes and embedding
Christian Sternagel
parents: 45236
diff changeset
    50
lemma prefixI [intro?]: "xs \<le> ys ==> xs \<noteq> ys ==> xs < (ys::'a list)"
d71cdd1171c3 more lemmas on suffixes and embedding
Christian Sternagel
parents: 45236
diff changeset
    51
  unfolding prefix_def by blast
10330
4362e906b745 "List prefixes" library theory (replaces old Lex/Prefix);
wenzelm
parents:
diff changeset
    52
49082
d71cdd1171c3 more lemmas on suffixes and embedding
Christian Sternagel
parents: 45236
diff changeset
    53
lemma prefixE [elim?]:
21305
d41eddfd2b66 tuned proofs;
wenzelm
parents: 19086
diff changeset
    54
  fixes xs ys :: "'a list"
d41eddfd2b66 tuned proofs;
wenzelm
parents: 19086
diff changeset
    55
  assumes "xs < ys"
d41eddfd2b66 tuned proofs;
wenzelm
parents: 19086
diff changeset
    56
  obtains "xs \<le> ys" and "xs \<noteq> ys"
49082
d71cdd1171c3 more lemmas on suffixes and embedding
Christian Sternagel
parents: 45236
diff changeset
    57
  using assms unfolding prefix_def by blast
10330
4362e906b745 "List prefixes" library theory (replaces old Lex/Prefix);
wenzelm
parents:
diff changeset
    58
4362e906b745 "List prefixes" library theory (replaces old Lex/Prefix);
wenzelm
parents:
diff changeset
    59
10389
c7d8901ab269 proper setup of "parallel";
wenzelm
parents: 10330
diff changeset
    60
subsection {* Basic properties of prefixes *}
10330
4362e906b745 "List prefixes" library theory (replaces old Lex/Prefix);
wenzelm
parents:
diff changeset
    61
49082
d71cdd1171c3 more lemmas on suffixes and embedding
Christian Sternagel
parents: 45236
diff changeset
    62
theorem Nil_prefixeq [iff]: "[] \<le> xs"
d71cdd1171c3 more lemmas on suffixes and embedding
Christian Sternagel
parents: 45236
diff changeset
    63
  by (simp add: prefixeq_def)
10330
4362e906b745 "List prefixes" library theory (replaces old Lex/Prefix);
wenzelm
parents:
diff changeset
    64
49082
d71cdd1171c3 more lemmas on suffixes and embedding
Christian Sternagel
parents: 45236
diff changeset
    65
theorem prefixeq_Nil [simp]: "(xs \<le> []) = (xs = [])"
d71cdd1171c3 more lemmas on suffixes and embedding
Christian Sternagel
parents: 45236
diff changeset
    66
  by (induct xs) (simp_all add: prefixeq_def)
10330
4362e906b745 "List prefixes" library theory (replaces old Lex/Prefix);
wenzelm
parents:
diff changeset
    67
49082
d71cdd1171c3 more lemmas on suffixes and embedding
Christian Sternagel
parents: 45236
diff changeset
    68
lemma prefixeq_snoc [simp]: "(xs \<le> ys @ [y]) = (xs = ys @ [y] \<or> xs \<le> ys)"
10389
c7d8901ab269 proper setup of "parallel";
wenzelm
parents: 10330
diff changeset
    69
proof
c7d8901ab269 proper setup of "parallel";
wenzelm
parents: 10330
diff changeset
    70
  assume "xs \<le> ys @ [y]"
c7d8901ab269 proper setup of "parallel";
wenzelm
parents: 10330
diff changeset
    71
  then obtain zs where zs: "ys @ [y] = xs @ zs" ..
c7d8901ab269 proper setup of "parallel";
wenzelm
parents: 10330
diff changeset
    72
  show "xs = ys @ [y] \<or> xs \<le> ys"
49082
d71cdd1171c3 more lemmas on suffixes and embedding
Christian Sternagel
parents: 45236
diff changeset
    73
    by (metis append_Nil2 butlast_append butlast_snoc prefixeqI zs)
10389
c7d8901ab269 proper setup of "parallel";
wenzelm
parents: 10330
diff changeset
    74
next
c7d8901ab269 proper setup of "parallel";
wenzelm
parents: 10330
diff changeset
    75
  assume "xs = ys @ [y] \<or> xs \<le> ys"
23254
99644a53f16d tuned proofs;
wenzelm
parents: 22178
diff changeset
    76
  then show "xs \<le> ys @ [y]"
49082
d71cdd1171c3 more lemmas on suffixes and embedding
Christian Sternagel
parents: 45236
diff changeset
    77
    by (metis order_eq_iff order_trans prefixeqI)
10389
c7d8901ab269 proper setup of "parallel";
wenzelm
parents: 10330
diff changeset
    78
qed
10330
4362e906b745 "List prefixes" library theory (replaces old Lex/Prefix);
wenzelm
parents:
diff changeset
    79
49082
d71cdd1171c3 more lemmas on suffixes and embedding
Christian Sternagel
parents: 45236
diff changeset
    80
lemma Cons_prefixeq_Cons [simp]: "(x # xs \<le> y # ys) = (x = y \<and> xs \<le> ys)"
d71cdd1171c3 more lemmas on suffixes and embedding
Christian Sternagel
parents: 45236
diff changeset
    81
  by (auto simp add: prefixeq_def)
10330
4362e906b745 "List prefixes" library theory (replaces old Lex/Prefix);
wenzelm
parents:
diff changeset
    82
37474
ce943f9edf5e added bot instances; tuned
haftmann
parents: 30663
diff changeset
    83
lemma less_eq_list_code [code]:
38857
97775f3e8722 renamed class/constant eq to equal; tuned some instantiations
haftmann
parents: 37474
diff changeset
    84
  "([]\<Colon>'a\<Colon>{equal, ord} list) \<le> xs \<longleftrightarrow> True"
97775f3e8722 renamed class/constant eq to equal; tuned some instantiations
haftmann
parents: 37474
diff changeset
    85
  "(x\<Colon>'a\<Colon>{equal, ord}) # xs \<le> [] \<longleftrightarrow> False"
97775f3e8722 renamed class/constant eq to equal; tuned some instantiations
haftmann
parents: 37474
diff changeset
    86
  "(x\<Colon>'a\<Colon>{equal, ord}) # xs \<le> y # ys \<longleftrightarrow> x = y \<and> xs \<le> ys"
37474
ce943f9edf5e added bot instances; tuned
haftmann
parents: 30663
diff changeset
    87
  by simp_all
ce943f9edf5e added bot instances; tuned
haftmann
parents: 30663
diff changeset
    88
49082
d71cdd1171c3 more lemmas on suffixes and embedding
Christian Sternagel
parents: 45236
diff changeset
    89
lemma same_prefixeq_prefixeq [simp]: "(xs @ ys \<le> xs @ zs) = (ys \<le> zs)"
10389
c7d8901ab269 proper setup of "parallel";
wenzelm
parents: 10330
diff changeset
    90
  by (induct xs) simp_all
10330
4362e906b745 "List prefixes" library theory (replaces old Lex/Prefix);
wenzelm
parents:
diff changeset
    91
49082
d71cdd1171c3 more lemmas on suffixes and embedding
Christian Sternagel
parents: 45236
diff changeset
    92
lemma same_prefixeq_nil [iff]: "(xs @ ys \<le> xs) = (ys = [])"
d71cdd1171c3 more lemmas on suffixes and embedding
Christian Sternagel
parents: 45236
diff changeset
    93
  by (metis append_Nil2 append_self_conv order_eq_iff prefixeqI)
25665
faabc08af882 removed legacy proofs
nipkow
parents: 25595
diff changeset
    94
49082
d71cdd1171c3 more lemmas on suffixes and embedding
Christian Sternagel
parents: 45236
diff changeset
    95
lemma prefixeq_prefixeq [simp]: "xs \<le> ys ==> xs \<le> ys @ zs"
d71cdd1171c3 more lemmas on suffixes and embedding
Christian Sternagel
parents: 45236
diff changeset
    96
  by (metis order_le_less_trans prefixeqI prefixE prefixI)
25665
faabc08af882 removed legacy proofs
nipkow
parents: 25595
diff changeset
    97
49082
d71cdd1171c3 more lemmas on suffixes and embedding
Christian Sternagel
parents: 45236
diff changeset
    98
lemma append_prefixeqD: "xs @ ys \<le> zs \<Longrightarrow> xs \<le> zs"
d71cdd1171c3 more lemmas on suffixes and embedding
Christian Sternagel
parents: 45236
diff changeset
    99
  by (auto simp add: prefixeq_def)
14300
bf8b8c9425c3 *** empty log message ***
nipkow
parents: 12338
diff changeset
   100
49082
d71cdd1171c3 more lemmas on suffixes and embedding
Christian Sternagel
parents: 45236
diff changeset
   101
theorem prefixeq_Cons: "(xs \<le> y # ys) = (xs = [] \<or> (\<exists>zs. xs = y # zs \<and> zs \<le> ys))"
d71cdd1171c3 more lemmas on suffixes and embedding
Christian Sternagel
parents: 45236
diff changeset
   102
  by (cases xs) (auto simp add: prefixeq_def)
10330
4362e906b745 "List prefixes" library theory (replaces old Lex/Prefix);
wenzelm
parents:
diff changeset
   103
49082
d71cdd1171c3 more lemmas on suffixes and embedding
Christian Sternagel
parents: 45236
diff changeset
   104
theorem prefixeq_append:
25564
4ca31a3706a4 R&F: added sgn lemma
nipkow
parents: 25356
diff changeset
   105
  "(xs \<le> ys @ zs) = (xs \<le> ys \<or> (\<exists>us. xs = ys @ us \<and> us \<le> zs))"
10330
4362e906b745 "List prefixes" library theory (replaces old Lex/Prefix);
wenzelm
parents:
diff changeset
   106
  apply (induct zs rule: rev_induct)
4362e906b745 "List prefixes" library theory (replaces old Lex/Prefix);
wenzelm
parents:
diff changeset
   107
   apply force
4362e906b745 "List prefixes" library theory (replaces old Lex/Prefix);
wenzelm
parents:
diff changeset
   108
  apply (simp del: append_assoc add: append_assoc [symmetric])
25564
4ca31a3706a4 R&F: added sgn lemma
nipkow
parents: 25356
diff changeset
   109
  apply (metis append_eq_appendI)
10330
4362e906b745 "List prefixes" library theory (replaces old Lex/Prefix);
wenzelm
parents:
diff changeset
   110
  done
4362e906b745 "List prefixes" library theory (replaces old Lex/Prefix);
wenzelm
parents:
diff changeset
   111
49082
d71cdd1171c3 more lemmas on suffixes and embedding
Christian Sternagel
parents: 45236
diff changeset
   112
lemma append_one_prefixeq:
25564
4ca31a3706a4 R&F: added sgn lemma
nipkow
parents: 25356
diff changeset
   113
  "xs \<le> ys ==> length xs < length ys ==> xs @ [ys ! length xs] \<le> ys"
49082
d71cdd1171c3 more lemmas on suffixes and embedding
Christian Sternagel
parents: 45236
diff changeset
   114
  unfolding prefixeq_def
25692
eda4958ab0d2 tuned proofs, document;
wenzelm
parents: 25665
diff changeset
   115
  by (metis Cons_eq_appendI append_eq_appendI append_eq_conv_conj
eda4958ab0d2 tuned proofs, document;
wenzelm
parents: 25665
diff changeset
   116
    eq_Nil_appendI nth_drop')
25665
faabc08af882 removed legacy proofs
nipkow
parents: 25595
diff changeset
   117
49082
d71cdd1171c3 more lemmas on suffixes and embedding
Christian Sternagel
parents: 45236
diff changeset
   118
theorem prefixeq_length_le: "xs \<le> ys ==> length xs \<le> length ys"
d71cdd1171c3 more lemmas on suffixes and embedding
Christian Sternagel
parents: 45236
diff changeset
   119
  by (auto simp add: prefixeq_def)
10330
4362e906b745 "List prefixes" library theory (replaces old Lex/Prefix);
wenzelm
parents:
diff changeset
   120
49082
d71cdd1171c3 more lemmas on suffixes and embedding
Christian Sternagel
parents: 45236
diff changeset
   121
lemma prefixeq_same_cases:
25564
4ca31a3706a4 R&F: added sgn lemma
nipkow
parents: 25356
diff changeset
   122
  "(xs\<^isub>1::'a list) \<le> ys \<Longrightarrow> xs\<^isub>2 \<le> ys \<Longrightarrow> xs\<^isub>1 \<le> xs\<^isub>2 \<or> xs\<^isub>2 \<le> xs\<^isub>1"
49082
d71cdd1171c3 more lemmas on suffixes and embedding
Christian Sternagel
parents: 45236
diff changeset
   123
  unfolding prefixeq_def by (metis append_eq_append_conv2)
25665
faabc08af882 removed legacy proofs
nipkow
parents: 25595
diff changeset
   124
49082
d71cdd1171c3 more lemmas on suffixes and embedding
Christian Sternagel
parents: 45236
diff changeset
   125
lemma set_mono_prefixeq: "xs \<le> ys \<Longrightarrow> set xs \<subseteq> set ys"
d71cdd1171c3 more lemmas on suffixes and embedding
Christian Sternagel
parents: 45236
diff changeset
   126
  by (auto simp add: prefixeq_def)
14300
bf8b8c9425c3 *** empty log message ***
nipkow
parents: 12338
diff changeset
   127
49082
d71cdd1171c3 more lemmas on suffixes and embedding
Christian Sternagel
parents: 45236
diff changeset
   128
lemma take_is_prefixeq: "take n xs \<le> xs"
d71cdd1171c3 more lemmas on suffixes and embedding
Christian Sternagel
parents: 45236
diff changeset
   129
  unfolding prefixeq_def by (metis append_take_drop_id)
25665
faabc08af882 removed legacy proofs
nipkow
parents: 25595
diff changeset
   130
49082
d71cdd1171c3 more lemmas on suffixes and embedding
Christian Sternagel
parents: 45236
diff changeset
   131
lemma map_prefixeqI: "xs \<le> ys \<Longrightarrow> map f xs \<le> map f ys"
d71cdd1171c3 more lemmas on suffixes and embedding
Christian Sternagel
parents: 45236
diff changeset
   132
  by (auto simp: prefixeq_def)
25322
e2eac0c30ff5 map and prefix
kleing
parents: 25299
diff changeset
   133
49082
d71cdd1171c3 more lemmas on suffixes and embedding
Christian Sternagel
parents: 45236
diff changeset
   134
lemma prefixeq_length_less: "xs < ys \<Longrightarrow> length xs < length ys"
d71cdd1171c3 more lemmas on suffixes and embedding
Christian Sternagel
parents: 45236
diff changeset
   135
  by (auto simp: prefix_def prefixeq_def)
25665
faabc08af882 removed legacy proofs
nipkow
parents: 25595
diff changeset
   136
49082
d71cdd1171c3 more lemmas on suffixes and embedding
Christian Sternagel
parents: 45236
diff changeset
   137
lemma prefix_simps [simp, code]:
37474
ce943f9edf5e added bot instances; tuned
haftmann
parents: 30663
diff changeset
   138
  "xs < [] \<longleftrightarrow> False"
ce943f9edf5e added bot instances; tuned
haftmann
parents: 30663
diff changeset
   139
  "[] < x # xs \<longleftrightarrow> True"
ce943f9edf5e added bot instances; tuned
haftmann
parents: 30663
diff changeset
   140
  "x # xs < y # ys \<longleftrightarrow> x = y \<and> xs < ys"
49082
d71cdd1171c3 more lemmas on suffixes and embedding
Christian Sternagel
parents: 45236
diff changeset
   141
  by (simp_all add: prefix_def cong: conj_cong)
25299
c3542f70b0fd misc lemmas about prefix, postfix, and parallel
kleing
parents: 23394
diff changeset
   142
49082
d71cdd1171c3 more lemmas on suffixes and embedding
Christian Sternagel
parents: 45236
diff changeset
   143
lemma take_prefix: "xs < ys \<Longrightarrow> take n xs < ys"
25692
eda4958ab0d2 tuned proofs, document;
wenzelm
parents: 25665
diff changeset
   144
  apply (induct n arbitrary: xs ys)
eda4958ab0d2 tuned proofs, document;
wenzelm
parents: 25665
diff changeset
   145
   apply (case_tac ys, simp_all)[1]
49082
d71cdd1171c3 more lemmas on suffixes and embedding
Christian Sternagel
parents: 45236
diff changeset
   146
  apply (metis order_less_trans prefixI take_is_prefixeq)
25692
eda4958ab0d2 tuned proofs, document;
wenzelm
parents: 25665
diff changeset
   147
  done
25299
c3542f70b0fd misc lemmas about prefix, postfix, and parallel
kleing
parents: 23394
diff changeset
   148
49082
d71cdd1171c3 more lemmas on suffixes and embedding
Christian Sternagel
parents: 45236
diff changeset
   149
lemma not_prefixeq_cases:
25299
c3542f70b0fd misc lemmas about prefix, postfix, and parallel
kleing
parents: 23394
diff changeset
   150
  assumes pfx: "\<not> ps \<le> ls"
25356
059c03630d6e tuned presentation;
wenzelm
parents: 25355
diff changeset
   151
  obtains
059c03630d6e tuned presentation;
wenzelm
parents: 25355
diff changeset
   152
    (c1) "ps \<noteq> []" and "ls = []"
059c03630d6e tuned presentation;
wenzelm
parents: 25355
diff changeset
   153
  | (c2) a as x xs where "ps = a#as" and "ls = x#xs" and "x = a" and "\<not> as \<le> xs"
059c03630d6e tuned presentation;
wenzelm
parents: 25355
diff changeset
   154
  | (c3) a as x xs where "ps = a#as" and "ls = x#xs" and "x \<noteq> a"
25299
c3542f70b0fd misc lemmas about prefix, postfix, and parallel
kleing
parents: 23394
diff changeset
   155
proof (cases ps)
25692
eda4958ab0d2 tuned proofs, document;
wenzelm
parents: 25665
diff changeset
   156
  case Nil then show ?thesis using pfx by simp
25299
c3542f70b0fd misc lemmas about prefix, postfix, and parallel
kleing
parents: 23394
diff changeset
   157
next
c3542f70b0fd misc lemmas about prefix, postfix, and parallel
kleing
parents: 23394
diff changeset
   158
  case (Cons a as)
25692
eda4958ab0d2 tuned proofs, document;
wenzelm
parents: 25665
diff changeset
   159
  note c = `ps = a#as`
25299
c3542f70b0fd misc lemmas about prefix, postfix, and parallel
kleing
parents: 23394
diff changeset
   160
  show ?thesis
c3542f70b0fd misc lemmas about prefix, postfix, and parallel
kleing
parents: 23394
diff changeset
   161
  proof (cases ls)
49082
d71cdd1171c3 more lemmas on suffixes and embedding
Christian Sternagel
parents: 45236
diff changeset
   162
    case Nil then show ?thesis by (metis append_Nil2 pfx c1 same_prefixeq_nil)
25299
c3542f70b0fd misc lemmas about prefix, postfix, and parallel
kleing
parents: 23394
diff changeset
   163
  next
c3542f70b0fd misc lemmas about prefix, postfix, and parallel
kleing
parents: 23394
diff changeset
   164
    case (Cons x xs)
c3542f70b0fd misc lemmas about prefix, postfix, and parallel
kleing
parents: 23394
diff changeset
   165
    show ?thesis
c3542f70b0fd misc lemmas about prefix, postfix, and parallel
kleing
parents: 23394
diff changeset
   166
    proof (cases "x = a")
25355
69c0a39ba028 avoid implicit use of prems;
wenzelm
parents: 25322
diff changeset
   167
      case True
69c0a39ba028 avoid implicit use of prems;
wenzelm
parents: 25322
diff changeset
   168
      have "\<not> as \<le> xs" using pfx c Cons True by simp
69c0a39ba028 avoid implicit use of prems;
wenzelm
parents: 25322
diff changeset
   169
      with c Cons True show ?thesis by (rule c2)
69c0a39ba028 avoid implicit use of prems;
wenzelm
parents: 25322
diff changeset
   170
    next
69c0a39ba028 avoid implicit use of prems;
wenzelm
parents: 25322
diff changeset
   171
      case False
69c0a39ba028 avoid implicit use of prems;
wenzelm
parents: 25322
diff changeset
   172
      with c Cons show ?thesis by (rule c3)
25299
c3542f70b0fd misc lemmas about prefix, postfix, and parallel
kleing
parents: 23394
diff changeset
   173
    qed
c3542f70b0fd misc lemmas about prefix, postfix, and parallel
kleing
parents: 23394
diff changeset
   174
  qed
c3542f70b0fd misc lemmas about prefix, postfix, and parallel
kleing
parents: 23394
diff changeset
   175
qed
c3542f70b0fd misc lemmas about prefix, postfix, and parallel
kleing
parents: 23394
diff changeset
   176
49082
d71cdd1171c3 more lemmas on suffixes and embedding
Christian Sternagel
parents: 45236
diff changeset
   177
lemma not_prefixeq_induct [consumes 1, case_names Nil Neq Eq]:
25299
c3542f70b0fd misc lemmas about prefix, postfix, and parallel
kleing
parents: 23394
diff changeset
   178
  assumes np: "\<not> ps \<le> ls"
25356
059c03630d6e tuned presentation;
wenzelm
parents: 25355
diff changeset
   179
    and base: "\<And>x xs. P (x#xs) []"
059c03630d6e tuned presentation;
wenzelm
parents: 25355
diff changeset
   180
    and r1: "\<And>x xs y ys. x \<noteq> y \<Longrightarrow> P (x#xs) (y#ys)"
059c03630d6e tuned presentation;
wenzelm
parents: 25355
diff changeset
   181
    and r2: "\<And>x xs y ys. \<lbrakk> x = y; \<not> xs \<le> ys; P xs ys \<rbrakk> \<Longrightarrow> P (x#xs) (y#ys)"
059c03630d6e tuned presentation;
wenzelm
parents: 25355
diff changeset
   182
  shows "P ps ls" using np
25299
c3542f70b0fd misc lemmas about prefix, postfix, and parallel
kleing
parents: 23394
diff changeset
   183
proof (induct ls arbitrary: ps)
25355
69c0a39ba028 avoid implicit use of prems;
wenzelm
parents: 25322
diff changeset
   184
  case Nil then show ?case
49082
d71cdd1171c3 more lemmas on suffixes and embedding
Christian Sternagel
parents: 45236
diff changeset
   185
    by (auto simp: neq_Nil_conv elim!: not_prefixeq_cases intro!: base)
25299
c3542f70b0fd misc lemmas about prefix, postfix, and parallel
kleing
parents: 23394
diff changeset
   186
next
25355
69c0a39ba028 avoid implicit use of prems;
wenzelm
parents: 25322
diff changeset
   187
  case (Cons y ys)
69c0a39ba028 avoid implicit use of prems;
wenzelm
parents: 25322
diff changeset
   188
  then have npfx: "\<not> ps \<le> (y # ys)" by simp
69c0a39ba028 avoid implicit use of prems;
wenzelm
parents: 25322
diff changeset
   189
  then obtain x xs where pv: "ps = x # xs"
49082
d71cdd1171c3 more lemmas on suffixes and embedding
Christian Sternagel
parents: 45236
diff changeset
   190
    by (rule not_prefixeq_cases) auto
d71cdd1171c3 more lemmas on suffixes and embedding
Christian Sternagel
parents: 45236
diff changeset
   191
  show ?case by (metis Cons.hyps Cons_prefixeq_Cons npfx pv r1 r2)
25299
c3542f70b0fd misc lemmas about prefix, postfix, and parallel
kleing
parents: 23394
diff changeset
   192
qed
14300
bf8b8c9425c3 *** empty log message ***
nipkow
parents: 12338
diff changeset
   193
25356
059c03630d6e tuned presentation;
wenzelm
parents: 25355
diff changeset
   194
10389
c7d8901ab269 proper setup of "parallel";
wenzelm
parents: 10330
diff changeset
   195
subsection {* Parallel lists *}
c7d8901ab269 proper setup of "parallel";
wenzelm
parents: 10330
diff changeset
   196
19086
1b3780be6cc2 new-style definitions/abbreviations;
wenzelm
parents: 18730
diff changeset
   197
definition
21404
eb85850d3eb7 more robust syntax for definition/abbreviation/notation;
wenzelm
parents: 21305
diff changeset
   198
  parallel :: "'a list => 'a list => bool"  (infixl "\<parallel>" 50) where
19086
1b3780be6cc2 new-style definitions/abbreviations;
wenzelm
parents: 18730
diff changeset
   199
  "(xs \<parallel> ys) = (\<not> xs \<le> ys \<and> \<not> ys \<le> xs)"
10389
c7d8901ab269 proper setup of "parallel";
wenzelm
parents: 10330
diff changeset
   200
c7d8901ab269 proper setup of "parallel";
wenzelm
parents: 10330
diff changeset
   201
lemma parallelI [intro]: "\<not> xs \<le> ys ==> \<not> ys \<le> xs ==> xs \<parallel> ys"
25692
eda4958ab0d2 tuned proofs, document;
wenzelm
parents: 25665
diff changeset
   202
  unfolding parallel_def by blast
10330
4362e906b745 "List prefixes" library theory (replaces old Lex/Prefix);
wenzelm
parents:
diff changeset
   203
10389
c7d8901ab269 proper setup of "parallel";
wenzelm
parents: 10330
diff changeset
   204
lemma parallelE [elim]:
25692
eda4958ab0d2 tuned proofs, document;
wenzelm
parents: 25665
diff changeset
   205
  assumes "xs \<parallel> ys"
eda4958ab0d2 tuned proofs, document;
wenzelm
parents: 25665
diff changeset
   206
  obtains "\<not> xs \<le> ys \<and> \<not> ys \<le> xs"
eda4958ab0d2 tuned proofs, document;
wenzelm
parents: 25665
diff changeset
   207
  using assms unfolding parallel_def by blast
10330
4362e906b745 "List prefixes" library theory (replaces old Lex/Prefix);
wenzelm
parents:
diff changeset
   208
49082
d71cdd1171c3 more lemmas on suffixes and embedding
Christian Sternagel
parents: 45236
diff changeset
   209
theorem prefixeq_cases:
25692
eda4958ab0d2 tuned proofs, document;
wenzelm
parents: 25665
diff changeset
   210
  obtains "xs \<le> ys" | "ys < xs" | "xs \<parallel> ys"
49082
d71cdd1171c3 more lemmas on suffixes and embedding
Christian Sternagel
parents: 45236
diff changeset
   211
  unfolding parallel_def prefix_def by blast
10330
4362e906b745 "List prefixes" library theory (replaces old Lex/Prefix);
wenzelm
parents:
diff changeset
   212
10389
c7d8901ab269 proper setup of "parallel";
wenzelm
parents: 10330
diff changeset
   213
theorem parallel_decomp:
c7d8901ab269 proper setup of "parallel";
wenzelm
parents: 10330
diff changeset
   214
  "xs \<parallel> ys ==> \<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
   215
proof (induct xs rule: rev_induct)
11987
bf31b35949ce tuned induct proofs;
wenzelm
parents: 11780
diff changeset
   216
  case Nil
23254
99644a53f16d tuned proofs;
wenzelm
parents: 22178
diff changeset
   217
  then have False by auto
99644a53f16d tuned proofs;
wenzelm
parents: 22178
diff changeset
   218
  then show ?case ..
10408
d8b3613158b1 improved: 'induct' handle non-atomic goals;
wenzelm
parents: 10389
diff changeset
   219
next
11987
bf31b35949ce tuned induct proofs;
wenzelm
parents: 11780
diff changeset
   220
  case (snoc x xs)
bf31b35949ce tuned induct proofs;
wenzelm
parents: 11780
diff changeset
   221
  show ?case
49082
d71cdd1171c3 more lemmas on suffixes and embedding
Christian Sternagel
parents: 45236
diff changeset
   222
  proof (rule prefixeq_cases)
10408
d8b3613158b1 improved: 'induct' handle non-atomic goals;
wenzelm
parents: 10389
diff changeset
   223
    assume le: "xs \<le> ys"
d8b3613158b1 improved: 'induct' handle non-atomic goals;
wenzelm
parents: 10389
diff changeset
   224
    then obtain ys' where ys: "ys = xs @ ys'" ..
d8b3613158b1 improved: 'induct' handle non-atomic goals;
wenzelm
parents: 10389
diff changeset
   225
    show ?thesis
d8b3613158b1 improved: 'induct' handle non-atomic goals;
wenzelm
parents: 10389
diff changeset
   226
    proof (cases ys')
25564
4ca31a3706a4 R&F: added sgn lemma
nipkow
parents: 25356
diff changeset
   227
      assume "ys' = []"
49082
d71cdd1171c3 more lemmas on suffixes and embedding
Christian Sternagel
parents: 45236
diff changeset
   228
      then show ?thesis by (metis append_Nil2 parallelE prefixeqI snoc.prems ys)
10389
c7d8901ab269 proper setup of "parallel";
wenzelm
parents: 10330
diff changeset
   229
    next
10408
d8b3613158b1 improved: 'induct' handle non-atomic goals;
wenzelm
parents: 10389
diff changeset
   230
      fix c cs assume ys': "ys' = c # cs"
25692
eda4958ab0d2 tuned proofs, document;
wenzelm
parents: 25665
diff changeset
   231
      then show ?thesis
49082
d71cdd1171c3 more lemmas on suffixes and embedding
Christian Sternagel
parents: 45236
diff changeset
   232
        by (metis Cons_eq_appendI eq_Nil_appendI parallelE prefixeqI
d71cdd1171c3 more lemmas on suffixes and embedding
Christian Sternagel
parents: 45236
diff changeset
   233
          same_prefixeq_prefixeq snoc.prems ys)
10389
c7d8901ab269 proper setup of "parallel";
wenzelm
parents: 10330
diff changeset
   234
    qed
10408
d8b3613158b1 improved: 'induct' handle non-atomic goals;
wenzelm
parents: 10389
diff changeset
   235
  next
49082
d71cdd1171c3 more lemmas on suffixes and embedding
Christian Sternagel
parents: 45236
diff changeset
   236
    assume "ys < xs" then have "ys \<le> xs @ [x]" by (simp add: prefix_def)
11987
bf31b35949ce tuned induct proofs;
wenzelm
parents: 11780
diff changeset
   237
    with snoc have False by blast
23254
99644a53f16d tuned proofs;
wenzelm
parents: 22178
diff changeset
   238
    then show ?thesis ..
10408
d8b3613158b1 improved: 'induct' handle non-atomic goals;
wenzelm
parents: 10389
diff changeset
   239
  next
d8b3613158b1 improved: 'induct' handle non-atomic goals;
wenzelm
parents: 10389
diff changeset
   240
    assume "xs \<parallel> ys"
11987
bf31b35949ce tuned induct proofs;
wenzelm
parents: 11780
diff changeset
   241
    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
   242
      and xs: "xs = as @ b # bs" and ys: "ys = as @ c # cs"
d8b3613158b1 improved: 'induct' handle non-atomic goals;
wenzelm
parents: 10389
diff changeset
   243
      by blast
d8b3613158b1 improved: 'induct' handle non-atomic goals;
wenzelm
parents: 10389
diff changeset
   244
    from xs have "xs @ [x] = as @ b # (bs @ [x])" by simp
d8b3613158b1 improved: 'induct' handle non-atomic goals;
wenzelm
parents: 10389
diff changeset
   245
    with neq ys show ?thesis by blast
10389
c7d8901ab269 proper setup of "parallel";
wenzelm
parents: 10330
diff changeset
   246
  qed
c7d8901ab269 proper setup of "parallel";
wenzelm
parents: 10330
diff changeset
   247
qed
10330
4362e906b745 "List prefixes" library theory (replaces old Lex/Prefix);
wenzelm
parents:
diff changeset
   248
25564
4ca31a3706a4 R&F: added sgn lemma
nipkow
parents: 25356
diff changeset
   249
lemma parallel_append: "a \<parallel> b \<Longrightarrow> a @ c \<parallel> b @ d"
25692
eda4958ab0d2 tuned proofs, document;
wenzelm
parents: 25665
diff changeset
   250
  apply (rule parallelI)
eda4958ab0d2 tuned proofs, document;
wenzelm
parents: 25665
diff changeset
   251
    apply (erule parallelE, erule conjE,
49082
d71cdd1171c3 more lemmas on suffixes and embedding
Christian Sternagel
parents: 45236
diff changeset
   252
      induct rule: not_prefixeq_induct, simp+)+
25692
eda4958ab0d2 tuned proofs, document;
wenzelm
parents: 25665
diff changeset
   253
  done
25299
c3542f70b0fd misc lemmas about prefix, postfix, and parallel
kleing
parents: 23394
diff changeset
   254
25692
eda4958ab0d2 tuned proofs, document;
wenzelm
parents: 25665
diff changeset
   255
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
   256
  by (simp add: parallel_append)
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_commute: "a \<parallel> b \<longleftrightarrow> b \<parallel> a"
eda4958ab0d2 tuned proofs, document;
wenzelm
parents: 25665
diff changeset
   259
  unfolding parallel_def by auto
14538
1d9d75a8efae removed o2l and fold_rel; moved postfix to Library/List_Prefix.thy
oheimb
parents: 14300
diff changeset
   260
25356
059c03630d6e tuned presentation;
wenzelm
parents: 25355
diff changeset
   261
49082
d71cdd1171c3 more lemmas on suffixes and embedding
Christian Sternagel
parents: 45236
diff changeset
   262
subsection {* Suffix order on lists *}
17201
3bdf1dfcdee4 reactivate postfix by change of syntax;
wenzelm
parents: 15355
diff changeset
   263
19086
1b3780be6cc2 new-style definitions/abbreviations;
wenzelm
parents: 18730
diff changeset
   264
definition
49082
d71cdd1171c3 more lemmas on suffixes and embedding
Christian Sternagel
parents: 45236
diff changeset
   265
  suffixeq :: "'a list => 'a list => bool" where
d71cdd1171c3 more lemmas on suffixes and embedding
Christian Sternagel
parents: 45236
diff changeset
   266
  "suffixeq xs ys = (\<exists>zs. ys = zs @ xs)"
d71cdd1171c3 more lemmas on suffixes and embedding
Christian Sternagel
parents: 45236
diff changeset
   267
d71cdd1171c3 more lemmas on suffixes and embedding
Christian Sternagel
parents: 45236
diff changeset
   268
definition suffix :: "'a list \<Rightarrow> 'a list \<Rightarrow> bool" where
d71cdd1171c3 more lemmas on suffixes and embedding
Christian Sternagel
parents: 45236
diff changeset
   269
  "suffix xs ys \<equiv> \<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
   270
49082
d71cdd1171c3 more lemmas on suffixes and embedding
Christian Sternagel
parents: 45236
diff changeset
   271
lemma suffix_imp_suffixeq:
d71cdd1171c3 more lemmas on suffixes and embedding
Christian Sternagel
parents: 45236
diff changeset
   272
  "suffix xs ys \<Longrightarrow> suffixeq xs ys"
d71cdd1171c3 more lemmas on suffixes and embedding
Christian Sternagel
parents: 45236
diff changeset
   273
  by (auto simp: suffixeq_def suffix_def)
d71cdd1171c3 more lemmas on suffixes and embedding
Christian Sternagel
parents: 45236
diff changeset
   274
d71cdd1171c3 more lemmas on suffixes and embedding
Christian Sternagel
parents: 45236
diff changeset
   275
lemma suffixeqI [intro?]: "ys = zs @ xs ==> suffixeq xs ys"
d71cdd1171c3 more lemmas on suffixes and embedding
Christian Sternagel
parents: 45236
diff changeset
   276
  unfolding suffixeq_def by blast
21305
d41eddfd2b66 tuned proofs;
wenzelm
parents: 19086
diff changeset
   277
49082
d71cdd1171c3 more lemmas on suffixes and embedding
Christian Sternagel
parents: 45236
diff changeset
   278
lemma suffixeqE [elim?]:
d71cdd1171c3 more lemmas on suffixes and embedding
Christian Sternagel
parents: 45236
diff changeset
   279
  assumes "suffixeq xs ys"
d71cdd1171c3 more lemmas on suffixes and embedding
Christian Sternagel
parents: 45236
diff changeset
   280
  obtains zs where "ys = zs @ xs"
d71cdd1171c3 more lemmas on suffixes and embedding
Christian Sternagel
parents: 45236
diff changeset
   281
  using assms unfolding suffixeq_def by blast
21305
d41eddfd2b66 tuned proofs;
wenzelm
parents: 19086
diff changeset
   282
49082
d71cdd1171c3 more lemmas on suffixes and embedding
Christian Sternagel
parents: 45236
diff changeset
   283
lemma suffixeq_refl [iff]: "suffixeq xs xs"
d71cdd1171c3 more lemmas on suffixes and embedding
Christian Sternagel
parents: 45236
diff changeset
   284
  by (auto simp add: suffixeq_def)
d71cdd1171c3 more lemmas on suffixes and embedding
Christian Sternagel
parents: 45236
diff changeset
   285
lemma suffix_trans:
d71cdd1171c3 more lemmas on suffixes and embedding
Christian Sternagel
parents: 45236
diff changeset
   286
  "suffix xs ys \<Longrightarrow> suffix ys zs \<Longrightarrow> suffix xs zs"
d71cdd1171c3 more lemmas on suffixes and embedding
Christian Sternagel
parents: 45236
diff changeset
   287
  by (auto simp: suffix_def)
d71cdd1171c3 more lemmas on suffixes and embedding
Christian Sternagel
parents: 45236
diff changeset
   288
lemma suffixeq_trans: "\<lbrakk>suffixeq xs ys; suffixeq ys zs\<rbrakk> \<Longrightarrow> suffixeq xs zs"
d71cdd1171c3 more lemmas on suffixes and embedding
Christian Sternagel
parents: 45236
diff changeset
   289
  by (auto simp add: suffixeq_def)
d71cdd1171c3 more lemmas on suffixes and embedding
Christian Sternagel
parents: 45236
diff changeset
   290
lemma suffixeq_antisym: "\<lbrakk>suffixeq xs ys; suffixeq ys xs\<rbrakk> \<Longrightarrow> xs = ys"
d71cdd1171c3 more lemmas on suffixes and embedding
Christian Sternagel
parents: 45236
diff changeset
   291
  by (auto simp add: suffixeq_def)
d71cdd1171c3 more lemmas on suffixes and embedding
Christian Sternagel
parents: 45236
diff changeset
   292
d71cdd1171c3 more lemmas on suffixes and embedding
Christian Sternagel
parents: 45236
diff changeset
   293
lemma suffixeq_tl [simp]: "suffixeq (tl xs) xs"
d71cdd1171c3 more lemmas on suffixes and embedding
Christian Sternagel
parents: 45236
diff changeset
   294
  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
   295
49082
d71cdd1171c3 more lemmas on suffixes and embedding
Christian Sternagel
parents: 45236
diff changeset
   296
lemma suffix_tl [simp]: "xs \<noteq> [] \<Longrightarrow> suffix (tl xs) xs"
d71cdd1171c3 more lemmas on suffixes and embedding
Christian Sternagel
parents: 45236
diff changeset
   297
  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
   298
49082
d71cdd1171c3 more lemmas on suffixes and embedding
Christian Sternagel
parents: 45236
diff changeset
   299
lemma Nil_suffixeq [iff]: "suffixeq [] xs"
d71cdd1171c3 more lemmas on suffixes and embedding
Christian Sternagel
parents: 45236
diff changeset
   300
  by (simp add: suffixeq_def)
d71cdd1171c3 more lemmas on suffixes and embedding
Christian Sternagel
parents: 45236
diff changeset
   301
lemma suffixeq_Nil [simp]: "(suffixeq xs []) = (xs = [])"
d71cdd1171c3 more lemmas on suffixes and embedding
Christian Sternagel
parents: 45236
diff changeset
   302
  by (auto simp add: suffixeq_def)
d71cdd1171c3 more lemmas on suffixes and embedding
Christian Sternagel
parents: 45236
diff changeset
   303
d71cdd1171c3 more lemmas on suffixes and embedding
Christian Sternagel
parents: 45236
diff changeset
   304
lemma suffixeq_ConsI: "suffixeq xs ys \<Longrightarrow> suffixeq xs (y#ys)"
d71cdd1171c3 more lemmas on suffixes and embedding
Christian Sternagel
parents: 45236
diff changeset
   305
  by (auto simp add: suffixeq_def)
d71cdd1171c3 more lemmas on suffixes and embedding
Christian Sternagel
parents: 45236
diff changeset
   306
lemma suffixeq_ConsD: "suffixeq (x#xs) ys \<Longrightarrow> suffixeq xs ys"
d71cdd1171c3 more lemmas on suffixes and embedding
Christian Sternagel
parents: 45236
diff changeset
   307
  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
   308
49082
d71cdd1171c3 more lemmas on suffixes and embedding
Christian Sternagel
parents: 45236
diff changeset
   309
lemma suffixeq_appendI: "suffixeq xs ys \<Longrightarrow> suffixeq xs (zs @ ys)"
d71cdd1171c3 more lemmas on suffixes and embedding
Christian Sternagel
parents: 45236
diff changeset
   310
  by (auto simp add: suffixeq_def)
d71cdd1171c3 more lemmas on suffixes and embedding
Christian Sternagel
parents: 45236
diff changeset
   311
lemma suffixeq_appendD: "suffixeq (zs @ xs) ys \<Longrightarrow> suffixeq xs ys"
d71cdd1171c3 more lemmas on suffixes and embedding
Christian Sternagel
parents: 45236
diff changeset
   312
  by (auto simp add: suffixeq_def)
d71cdd1171c3 more lemmas on suffixes and embedding
Christian Sternagel
parents: 45236
diff changeset
   313
d71cdd1171c3 more lemmas on suffixes and embedding
Christian Sternagel
parents: 45236
diff changeset
   314
lemma suffix_set_subset:
d71cdd1171c3 more lemmas on suffixes and embedding
Christian Sternagel
parents: 45236
diff changeset
   315
  "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
   316
49082
d71cdd1171c3 more lemmas on suffixes and embedding
Christian Sternagel
parents: 45236
diff changeset
   317
lemma suffixeq_set_subset:
d71cdd1171c3 more lemmas on suffixes and embedding
Christian Sternagel
parents: 45236
diff changeset
   318
  "suffixeq xs ys \<Longrightarrow> set xs \<subseteq> set ys" by (auto simp: suffixeq_def)
d71cdd1171c3 more lemmas on suffixes and embedding
Christian Sternagel
parents: 45236
diff changeset
   319
d71cdd1171c3 more lemmas on suffixes and embedding
Christian Sternagel
parents: 45236
diff changeset
   320
lemma suffixeq_ConsD2: "suffixeq (x#xs) (y#ys) ==> suffixeq xs ys"
21305
d41eddfd2b66 tuned proofs;
wenzelm
parents: 19086
diff changeset
   321
proof -
49082
d71cdd1171c3 more lemmas on suffixes and embedding
Christian Sternagel
parents: 45236
diff changeset
   322
  assume "suffixeq (x#xs) (y#ys)"
d71cdd1171c3 more lemmas on suffixes and embedding
Christian Sternagel
parents: 45236
diff changeset
   323
  then obtain zs where "y#ys = zs @ x#xs" ..
d71cdd1171c3 more lemmas on suffixes and embedding
Christian Sternagel
parents: 45236
diff changeset
   324
  then show ?thesis
d71cdd1171c3 more lemmas on suffixes and embedding
Christian Sternagel
parents: 45236
diff changeset
   325
    by (induct zs) (auto intro!: suffixeq_appendI suffixeq_ConsI)
21305
d41eddfd2b66 tuned proofs;
wenzelm
parents: 19086
diff changeset
   326
qed
14538
1d9d75a8efae removed o2l and fold_rel; moved postfix to Library/List_Prefix.thy
oheimb
parents: 14300
diff changeset
   327
49082
d71cdd1171c3 more lemmas on suffixes and embedding
Christian Sternagel
parents: 45236
diff changeset
   328
lemma suffixeq_to_prefixeq [code]: "suffixeq xs ys \<longleftrightarrow> rev xs \<le> rev ys"
d71cdd1171c3 more lemmas on suffixes and embedding
Christian Sternagel
parents: 45236
diff changeset
   329
proof
d71cdd1171c3 more lemmas on suffixes and embedding
Christian Sternagel
parents: 45236
diff changeset
   330
  assume "suffixeq xs ys"
d71cdd1171c3 more lemmas on suffixes and embedding
Christian Sternagel
parents: 45236
diff changeset
   331
  then obtain zs where "ys = zs @ xs" ..
d71cdd1171c3 more lemmas on suffixes and embedding
Christian Sternagel
parents: 45236
diff changeset
   332
  then have "rev ys = rev xs @ rev zs" by simp
d71cdd1171c3 more lemmas on suffixes and embedding
Christian Sternagel
parents: 45236
diff changeset
   333
  then show "rev xs <= rev ys" ..
d71cdd1171c3 more lemmas on suffixes and embedding
Christian Sternagel
parents: 45236
diff changeset
   334
next
d71cdd1171c3 more lemmas on suffixes and embedding
Christian Sternagel
parents: 45236
diff changeset
   335
  assume "rev xs <= rev ys"
d71cdd1171c3 more lemmas on suffixes and embedding
Christian Sternagel
parents: 45236
diff changeset
   336
  then obtain zs where "rev ys = rev xs @ zs" ..
d71cdd1171c3 more lemmas on suffixes and embedding
Christian Sternagel
parents: 45236
diff changeset
   337
  then have "rev (rev ys) = rev zs @ rev (rev xs)" by simp
d71cdd1171c3 more lemmas on suffixes and embedding
Christian Sternagel
parents: 45236
diff changeset
   338
  then have "ys = rev zs @ xs" by simp
d71cdd1171c3 more lemmas on suffixes and embedding
Christian Sternagel
parents: 45236
diff changeset
   339
  then show "suffixeq xs ys" ..
21305
d41eddfd2b66 tuned proofs;
wenzelm
parents: 19086
diff changeset
   340
qed
14538
1d9d75a8efae removed o2l and fold_rel; moved postfix to Library/List_Prefix.thy
oheimb
parents: 14300
diff changeset
   341
49082
d71cdd1171c3 more lemmas on suffixes and embedding
Christian Sternagel
parents: 45236
diff changeset
   342
lemma distinct_suffixeq: "distinct ys \<Longrightarrow> suffixeq xs ys \<Longrightarrow> distinct xs"
d71cdd1171c3 more lemmas on suffixes and embedding
Christian Sternagel
parents: 45236
diff changeset
   343
  by (clarsimp elim!: suffixeqE)
17201
3bdf1dfcdee4 reactivate postfix by change of syntax;
wenzelm
parents: 15355
diff changeset
   344
49082
d71cdd1171c3 more lemmas on suffixes and embedding
Christian Sternagel
parents: 45236
diff changeset
   345
lemma suffixeq_map: "suffixeq xs ys \<Longrightarrow> suffixeq (map f xs) (map f ys)"
d71cdd1171c3 more lemmas on suffixes and embedding
Christian Sternagel
parents: 45236
diff changeset
   346
  by (auto elim!: suffixeqE intro: suffixeqI)
25299
c3542f70b0fd misc lemmas about prefix, postfix, and parallel
kleing
parents: 23394
diff changeset
   347
49082
d71cdd1171c3 more lemmas on suffixes and embedding
Christian Sternagel
parents: 45236
diff changeset
   348
lemma suffixeq_drop: "suffixeq (drop n as) as"
d71cdd1171c3 more lemmas on suffixes and embedding
Christian Sternagel
parents: 45236
diff changeset
   349
  unfolding suffixeq_def
25692
eda4958ab0d2 tuned proofs, document;
wenzelm
parents: 25665
diff changeset
   350
  apply (rule exI [where x = "take n as"])
eda4958ab0d2 tuned proofs, document;
wenzelm
parents: 25665
diff changeset
   351
  apply simp
eda4958ab0d2 tuned proofs, document;
wenzelm
parents: 25665
diff changeset
   352
  done
25299
c3542f70b0fd misc lemmas about prefix, postfix, and parallel
kleing
parents: 23394
diff changeset
   353
49082
d71cdd1171c3 more lemmas on suffixes and embedding
Christian Sternagel
parents: 45236
diff changeset
   354
lemma suffixeq_take: "suffixeq xs ys \<Longrightarrow> ys = take (length ys - length xs) ys @ xs"
d71cdd1171c3 more lemmas on suffixes and embedding
Christian Sternagel
parents: 45236
diff changeset
   355
  by (clarsimp elim!: suffixeqE)
d71cdd1171c3 more lemmas on suffixes and embedding
Christian Sternagel
parents: 45236
diff changeset
   356
d71cdd1171c3 more lemmas on suffixes and embedding
Christian Sternagel
parents: 45236
diff changeset
   357
lemma suffixeq_suffix_reflclp_conv:
d71cdd1171c3 more lemmas on suffixes and embedding
Christian Sternagel
parents: 45236
diff changeset
   358
  "suffixeq = suffix\<^sup>=\<^sup>="
d71cdd1171c3 more lemmas on suffixes and embedding
Christian Sternagel
parents: 45236
diff changeset
   359
proof (intro ext iffI)
d71cdd1171c3 more lemmas on suffixes and embedding
Christian Sternagel
parents: 45236
diff changeset
   360
  fix xs ys :: "'a list"
d71cdd1171c3 more lemmas on suffixes and embedding
Christian Sternagel
parents: 45236
diff changeset
   361
  assume "suffixeq xs ys"
d71cdd1171c3 more lemmas on suffixes and embedding
Christian Sternagel
parents: 45236
diff changeset
   362
  show "suffix\<^sup>=\<^sup>= xs ys"
d71cdd1171c3 more lemmas on suffixes and embedding
Christian Sternagel
parents: 45236
diff changeset
   363
  proof
d71cdd1171c3 more lemmas on suffixes and embedding
Christian Sternagel
parents: 45236
diff changeset
   364
    assume "xs \<noteq> ys"
d71cdd1171c3 more lemmas on suffixes and embedding
Christian Sternagel
parents: 45236
diff changeset
   365
    with `suffixeq xs ys` show "suffix xs ys" by (auto simp: suffixeq_def suffix_def)
d71cdd1171c3 more lemmas on suffixes and embedding
Christian Sternagel
parents: 45236
diff changeset
   366
  qed
d71cdd1171c3 more lemmas on suffixes and embedding
Christian Sternagel
parents: 45236
diff changeset
   367
next
d71cdd1171c3 more lemmas on suffixes and embedding
Christian Sternagel
parents: 45236
diff changeset
   368
  fix xs ys :: "'a list"
d71cdd1171c3 more lemmas on suffixes and embedding
Christian Sternagel
parents: 45236
diff changeset
   369
  assume "suffix\<^sup>=\<^sup>= xs ys"
d71cdd1171c3 more lemmas on suffixes and embedding
Christian Sternagel
parents: 45236
diff changeset
   370
  thus "suffixeq xs ys"
d71cdd1171c3 more lemmas on suffixes and embedding
Christian Sternagel
parents: 45236
diff changeset
   371
  proof
d71cdd1171c3 more lemmas on suffixes and embedding
Christian Sternagel
parents: 45236
diff changeset
   372
    assume "suffix xs ys" thus "suffixeq xs ys" by (rule suffix_imp_suffixeq)
d71cdd1171c3 more lemmas on suffixes and embedding
Christian Sternagel
parents: 45236
diff changeset
   373
  next
d71cdd1171c3 more lemmas on suffixes and embedding
Christian Sternagel
parents: 45236
diff changeset
   374
    assume "xs = ys" thus "suffixeq xs ys" by (auto simp: suffixeq_def)
d71cdd1171c3 more lemmas on suffixes and embedding
Christian Sternagel
parents: 45236
diff changeset
   375
  qed
d71cdd1171c3 more lemmas on suffixes and embedding
Christian Sternagel
parents: 45236
diff changeset
   376
qed
25299
c3542f70b0fd misc lemmas about prefix, postfix, and parallel
kleing
parents: 23394
diff changeset
   377
25356
059c03630d6e tuned presentation;
wenzelm
parents: 25355
diff changeset
   378
lemma parallelD1: "x \<parallel> y \<Longrightarrow> \<not> x \<le> y"
25692
eda4958ab0d2 tuned proofs, document;
wenzelm
parents: 25665
diff changeset
   379
  by blast
25299
c3542f70b0fd misc lemmas about prefix, postfix, and parallel
kleing
parents: 23394
diff changeset
   380
25356
059c03630d6e tuned presentation;
wenzelm
parents: 25355
diff changeset
   381
lemma parallelD2: "x \<parallel> y \<Longrightarrow> \<not> y \<le> x"
25692
eda4958ab0d2 tuned proofs, document;
wenzelm
parents: 25665
diff changeset
   382
  by blast
25355
69c0a39ba028 avoid implicit use of prems;
wenzelm
parents: 25322
diff changeset
   383
69c0a39ba028 avoid implicit use of prems;
wenzelm
parents: 25322
diff changeset
   384
lemma parallel_Nil1 [simp]: "\<not> x \<parallel> []"
25692
eda4958ab0d2 tuned proofs, document;
wenzelm
parents: 25665
diff changeset
   385
  unfolding parallel_def by simp
25355
69c0a39ba028 avoid implicit use of prems;
wenzelm
parents: 25322
diff changeset
   386
25299
c3542f70b0fd misc lemmas about prefix, postfix, and parallel
kleing
parents: 23394
diff changeset
   387
lemma parallel_Nil2 [simp]: "\<not> [] \<parallel> x"
25692
eda4958ab0d2 tuned proofs, document;
wenzelm
parents: 25665
diff changeset
   388
  unfolding parallel_def by simp
25299
c3542f70b0fd misc lemmas about prefix, postfix, and parallel
kleing
parents: 23394
diff changeset
   389
25564
4ca31a3706a4 R&F: added sgn lemma
nipkow
parents: 25356
diff changeset
   390
lemma Cons_parallelI1: "a \<noteq> b \<Longrightarrow> a # as \<parallel> b # bs"
25692
eda4958ab0d2 tuned proofs, document;
wenzelm
parents: 25665
diff changeset
   391
  by auto
25299
c3542f70b0fd misc lemmas about prefix, postfix, and parallel
kleing
parents: 23394
diff changeset
   392
25564
4ca31a3706a4 R&F: added sgn lemma
nipkow
parents: 25356
diff changeset
   393
lemma Cons_parallelI2: "\<lbrakk> a = b; as \<parallel> bs \<rbrakk> \<Longrightarrow> a # as \<parallel> b # bs"
49082
d71cdd1171c3 more lemmas on suffixes and embedding
Christian Sternagel
parents: 45236
diff changeset
   394
  by (metis Cons_prefixeq_Cons parallelE parallelI)
25665
faabc08af882 removed legacy proofs
nipkow
parents: 25595
diff changeset
   395
25299
c3542f70b0fd misc lemmas about prefix, postfix, and parallel
kleing
parents: 23394
diff changeset
   396
lemma not_equal_is_parallel:
c3542f70b0fd misc lemmas about prefix, postfix, and parallel
kleing
parents: 23394
diff changeset
   397
  assumes neq: "xs \<noteq> ys"
25356
059c03630d6e tuned presentation;
wenzelm
parents: 25355
diff changeset
   398
    and len: "length xs = length ys"
059c03630d6e tuned presentation;
wenzelm
parents: 25355
diff changeset
   399
  shows "xs \<parallel> ys"
25299
c3542f70b0fd misc lemmas about prefix, postfix, and parallel
kleing
parents: 23394
diff changeset
   400
  using len neq
25355
69c0a39ba028 avoid implicit use of prems;
wenzelm
parents: 25322
diff changeset
   401
proof (induct rule: list_induct2)
26445
17223cf843d8 explicit case names for rule list_induct2
haftmann
parents: 25764
diff changeset
   402
  case Nil
25356
059c03630d6e tuned presentation;
wenzelm
parents: 25355
diff changeset
   403
  then show ?case by simp
25299
c3542f70b0fd misc lemmas about prefix, postfix, and parallel
kleing
parents: 23394
diff changeset
   404
next
26445
17223cf843d8 explicit case names for rule list_induct2
haftmann
parents: 25764
diff changeset
   405
  case (Cons a as b bs)
25355
69c0a39ba028 avoid implicit use of prems;
wenzelm
parents: 25322
diff changeset
   406
  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
   407
  show ?case
c3542f70b0fd misc lemmas about prefix, postfix, and parallel
kleing
parents: 23394
diff changeset
   408
  proof (cases "a = b")
25355
69c0a39ba028 avoid implicit use of prems;
wenzelm
parents: 25322
diff changeset
   409
    case True
26445
17223cf843d8 explicit case names for rule list_induct2
haftmann
parents: 25764
diff changeset
   410
    then have "as \<noteq> bs" using Cons by simp
25355
69c0a39ba028 avoid implicit use of prems;
wenzelm
parents: 25322
diff changeset
   411
    then show ?thesis by (rule Cons_parallelI2 [OF True ih])
25299
c3542f70b0fd misc lemmas about prefix, postfix, and parallel
kleing
parents: 23394
diff changeset
   412
  next
c3542f70b0fd misc lemmas about prefix, postfix, and parallel
kleing
parents: 23394
diff changeset
   413
    case False
25355
69c0a39ba028 avoid implicit use of prems;
wenzelm
parents: 25322
diff changeset
   414
    then show ?thesis by (rule Cons_parallelI1)
25299
c3542f70b0fd misc lemmas about prefix, postfix, and parallel
kleing
parents: 23394
diff changeset
   415
  qed
c3542f70b0fd misc lemmas about prefix, postfix, and parallel
kleing
parents: 23394
diff changeset
   416
qed
22178
29b95968272b made executable
haftmann
parents: 21404
diff changeset
   417
49082
d71cdd1171c3 more lemmas on suffixes and embedding
Christian Sternagel
parents: 45236
diff changeset
   418
lemma suffix_reflclp_conv:
d71cdd1171c3 more lemmas on suffixes and embedding
Christian Sternagel
parents: 45236
diff changeset
   419
  "suffix\<^sup>=\<^sup>= = suffixeq"
d71cdd1171c3 more lemmas on suffixes and embedding
Christian Sternagel
parents: 45236
diff changeset
   420
  by (intro ext) (auto simp: suffixeq_def suffix_def)
d71cdd1171c3 more lemmas on suffixes and embedding
Christian Sternagel
parents: 45236
diff changeset
   421
d71cdd1171c3 more lemmas on suffixes and embedding
Christian Sternagel
parents: 45236
diff changeset
   422
lemma suffix_lists:
d71cdd1171c3 more lemmas on suffixes and embedding
Christian Sternagel
parents: 45236
diff changeset
   423
  "suffix xs ys \<Longrightarrow> ys \<in> lists A \<Longrightarrow> xs \<in> lists A"
d71cdd1171c3 more lemmas on suffixes and embedding
Christian Sternagel
parents: 45236
diff changeset
   424
  unfolding suffix_def by auto
d71cdd1171c3 more lemmas on suffixes and embedding
Christian Sternagel
parents: 45236
diff changeset
   425
d71cdd1171c3 more lemmas on suffixes and embedding
Christian Sternagel
parents: 45236
diff changeset
   426
d71cdd1171c3 more lemmas on suffixes and embedding
Christian Sternagel
parents: 45236
diff changeset
   427
subsection {* Embedding on lists *}
d71cdd1171c3 more lemmas on suffixes and embedding
Christian Sternagel
parents: 45236
diff changeset
   428
d71cdd1171c3 more lemmas on suffixes and embedding
Christian Sternagel
parents: 45236
diff changeset
   429
inductive
d71cdd1171c3 more lemmas on suffixes and embedding
Christian Sternagel
parents: 45236
diff changeset
   430
  emb :: "('a \<Rightarrow> 'a \<Rightarrow> bool) \<Rightarrow> 'a list \<Rightarrow> 'a list \<Rightarrow> bool"
d71cdd1171c3 more lemmas on suffixes and embedding
Christian Sternagel
parents: 45236
diff changeset
   431
  for P :: "('a \<Rightarrow> 'a \<Rightarrow> bool)"
d71cdd1171c3 more lemmas on suffixes and embedding
Christian Sternagel
parents: 45236
diff changeset
   432
where
d71cdd1171c3 more lemmas on suffixes and embedding
Christian Sternagel
parents: 45236
diff changeset
   433
  emb_Nil [intro, simp]: "emb P [] ys"
d71cdd1171c3 more lemmas on suffixes and embedding
Christian Sternagel
parents: 45236
diff changeset
   434
| emb_Cons [intro] : "emb P xs ys \<Longrightarrow> emb P xs (y#ys)"
d71cdd1171c3 more lemmas on suffixes and embedding
Christian Sternagel
parents: 45236
diff changeset
   435
| emb_Cons2 [intro]: "P x y \<Longrightarrow> emb P xs ys \<Longrightarrow> emb P (x#xs) (y#ys)"
d71cdd1171c3 more lemmas on suffixes and embedding
Christian Sternagel
parents: 45236
diff changeset
   436
d71cdd1171c3 more lemmas on suffixes and embedding
Christian Sternagel
parents: 45236
diff changeset
   437
lemma emb_Nil2 [simp]:
d71cdd1171c3 more lemmas on suffixes and embedding
Christian Sternagel
parents: 45236
diff changeset
   438
  assumes "emb P xs []" shows "xs = []"
d71cdd1171c3 more lemmas on suffixes and embedding
Christian Sternagel
parents: 45236
diff changeset
   439
  using assms by (cases rule: emb.cases) auto
d71cdd1171c3 more lemmas on suffixes and embedding
Christian Sternagel
parents: 45236
diff changeset
   440
d71cdd1171c3 more lemmas on suffixes and embedding
Christian Sternagel
parents: 45236
diff changeset
   441
lemma emb_append2 [intro]:
d71cdd1171c3 more lemmas on suffixes and embedding
Christian Sternagel
parents: 45236
diff changeset
   442
  "emb P xs ys \<Longrightarrow> emb P xs (zs @ ys)"
d71cdd1171c3 more lemmas on suffixes and embedding
Christian Sternagel
parents: 45236
diff changeset
   443
  by (induct zs) auto
d71cdd1171c3 more lemmas on suffixes and embedding
Christian Sternagel
parents: 45236
diff changeset
   444
d71cdd1171c3 more lemmas on suffixes and embedding
Christian Sternagel
parents: 45236
diff changeset
   445
lemma emb_prefix [intro]:
d71cdd1171c3 more lemmas on suffixes and embedding
Christian Sternagel
parents: 45236
diff changeset
   446
  assumes "emb P xs ys" shows "emb P xs (ys @ zs)"
d71cdd1171c3 more lemmas on suffixes and embedding
Christian Sternagel
parents: 45236
diff changeset
   447
  using assms
d71cdd1171c3 more lemmas on suffixes and embedding
Christian Sternagel
parents: 45236
diff changeset
   448
  by (induct arbitrary: zs) auto
d71cdd1171c3 more lemmas on suffixes and embedding
Christian Sternagel
parents: 45236
diff changeset
   449
d71cdd1171c3 more lemmas on suffixes and embedding
Christian Sternagel
parents: 45236
diff changeset
   450
lemma emb_ConsD:
d71cdd1171c3 more lemmas on suffixes and embedding
Christian Sternagel
parents: 45236
diff changeset
   451
  assumes "emb P (x#xs) ys"
d71cdd1171c3 more lemmas on suffixes and embedding
Christian Sternagel
parents: 45236
diff changeset
   452
  shows "\<exists>us v vs. ys = us @ v # vs \<and> P x v \<and> emb P xs vs"
d71cdd1171c3 more lemmas on suffixes and embedding
Christian Sternagel
parents: 45236
diff changeset
   453
using assms
d71cdd1171c3 more lemmas on suffixes and embedding
Christian Sternagel
parents: 45236
diff changeset
   454
proof (induct x\<equiv>"x#xs" y\<equiv>"ys" arbitrary: x xs ys)
d71cdd1171c3 more lemmas on suffixes and embedding
Christian Sternagel
parents: 45236
diff changeset
   455
  case emb_Cons thus ?case by (metis append_Cons)
d71cdd1171c3 more lemmas on suffixes and embedding
Christian Sternagel
parents: 45236
diff changeset
   456
next
d71cdd1171c3 more lemmas on suffixes and embedding
Christian Sternagel
parents: 45236
diff changeset
   457
  case (emb_Cons2 x y xs ys)
d71cdd1171c3 more lemmas on suffixes and embedding
Christian Sternagel
parents: 45236
diff changeset
   458
  thus ?case by (cases xs) (auto, blast+)
d71cdd1171c3 more lemmas on suffixes and embedding
Christian Sternagel
parents: 45236
diff changeset
   459
qed
d71cdd1171c3 more lemmas on suffixes and embedding
Christian Sternagel
parents: 45236
diff changeset
   460
d71cdd1171c3 more lemmas on suffixes and embedding
Christian Sternagel
parents: 45236
diff changeset
   461
lemma emb_appendD:
d71cdd1171c3 more lemmas on suffixes and embedding
Christian Sternagel
parents: 45236
diff changeset
   462
  assumes "emb P (xs @ ys) zs"
d71cdd1171c3 more lemmas on suffixes and embedding
Christian Sternagel
parents: 45236
diff changeset
   463
  shows "\<exists>us vs. zs = us @ vs \<and> emb P xs us \<and> emb P ys vs"
d71cdd1171c3 more lemmas on suffixes and embedding
Christian Sternagel
parents: 45236
diff changeset
   464
using assms
d71cdd1171c3 more lemmas on suffixes and embedding
Christian Sternagel
parents: 45236
diff changeset
   465
proof (induction xs arbitrary: ys zs)
d71cdd1171c3 more lemmas on suffixes and embedding
Christian Sternagel
parents: 45236
diff changeset
   466
  case Nil thus ?case by auto
d71cdd1171c3 more lemmas on suffixes and embedding
Christian Sternagel
parents: 45236
diff changeset
   467
next
d71cdd1171c3 more lemmas on suffixes and embedding
Christian Sternagel
parents: 45236
diff changeset
   468
  case (Cons x xs)
d71cdd1171c3 more lemmas on suffixes and embedding
Christian Sternagel
parents: 45236
diff changeset
   469
  then obtain us v vs where "zs = us @ v # vs"
d71cdd1171c3 more lemmas on suffixes and embedding
Christian Sternagel
parents: 45236
diff changeset
   470
    and "P x v" and "emb P (xs @ ys) vs" by (auto dest: emb_ConsD)
d71cdd1171c3 more lemmas on suffixes and embedding
Christian Sternagel
parents: 45236
diff changeset
   471
  with Cons show ?case by (metis append_Cons append_assoc emb_Cons2 emb_append2)
d71cdd1171c3 more lemmas on suffixes and embedding
Christian Sternagel
parents: 45236
diff changeset
   472
qed
d71cdd1171c3 more lemmas on suffixes and embedding
Christian Sternagel
parents: 45236
diff changeset
   473
d71cdd1171c3 more lemmas on suffixes and embedding
Christian Sternagel
parents: 45236
diff changeset
   474
lemma emb_suffix:
d71cdd1171c3 more lemmas on suffixes and embedding
Christian Sternagel
parents: 45236
diff changeset
   475
  assumes "emb P xs ys" and "suffix ys zs"
d71cdd1171c3 more lemmas on suffixes and embedding
Christian Sternagel
parents: 45236
diff changeset
   476
  shows "emb P xs zs"
d71cdd1171c3 more lemmas on suffixes and embedding
Christian Sternagel
parents: 45236
diff changeset
   477
  using assms(2) and emb_append2 [OF assms(1)] by (auto simp: suffix_def)
d71cdd1171c3 more lemmas on suffixes and embedding
Christian Sternagel
parents: 45236
diff changeset
   478
d71cdd1171c3 more lemmas on suffixes and embedding
Christian Sternagel
parents: 45236
diff changeset
   479
lemma emb_suffixeq:
d71cdd1171c3 more lemmas on suffixes and embedding
Christian Sternagel
parents: 45236
diff changeset
   480
  assumes "emb P xs ys" and "suffixeq ys zs"
d71cdd1171c3 more lemmas on suffixes and embedding
Christian Sternagel
parents: 45236
diff changeset
   481
  shows "emb P xs zs"
d71cdd1171c3 more lemmas on suffixes and embedding
Christian Sternagel
parents: 45236
diff changeset
   482
  using assms and emb_suffix unfolding suffixeq_suffix_reflclp_conv by auto
d71cdd1171c3 more lemmas on suffixes and embedding
Christian Sternagel
parents: 45236
diff changeset
   483
10330
4362e906b745 "List prefixes" library theory (replaces old Lex/Prefix);
wenzelm
parents:
diff changeset
   484
end