src/HOL/Library/List_Prefix.thy
author berghofe
Fri, 01 Jul 2005 13:54:12 +0200
changeset 16633 208ebc9311f2
parent 15355 0de05d104060
child 17201 3bdf1dfcdee4
permissions -rw-r--r--
Implemented trick (due to Tobias Nipkow) for fine-tuning simplification of premises of congruence rules.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10330
4362e906b745 "List prefixes" library theory (replaces old Lex/Prefix);
wenzelm
parents:
diff changeset
     1
(*  Title:      HOL/Library/List_Prefix.thy
4362e906b745 "List prefixes" library theory (replaces old Lex/Prefix);
wenzelm
parents:
diff changeset
     2
    ID:         $Id$
4362e906b745 "List prefixes" library theory (replaces old Lex/Prefix);
wenzelm
parents:
diff changeset
     3
    Author:     Tobias Nipkow and Markus Wenzel, TU Muenchen
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
14706
71590b7733b7 tuned document;
wenzelm
parents: 14538
diff changeset
     6
header {* List prefixes and postfixes *}
10330
4362e906b745 "List prefixes" library theory (replaces old Lex/Prefix);
wenzelm
parents:
diff changeset
     7
15131
c69542757a4d New theory header syntax.
nipkow
parents: 14981
diff changeset
     8
theory List_Prefix
15140
322485b816ac import -> imports
nipkow
parents: 15131
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
4362e906b745 "List prefixes" library theory (replaces old Lex/Prefix);
wenzelm
parents:
diff changeset
    12
subsection {* Prefix order on lists *}
4362e906b745 "List prefixes" library theory (replaces old Lex/Prefix);
wenzelm
parents:
diff changeset
    13
12338
de0f4a63baa5 renamed class "term" to "type" (actually "HOL.type");
wenzelm
parents: 11987
diff changeset
    14
instance list :: (type) ord ..
10330
4362e906b745 "List prefixes" library theory (replaces old Lex/Prefix);
wenzelm
parents:
diff changeset
    15
4362e906b745 "List prefixes" library theory (replaces old Lex/Prefix);
wenzelm
parents:
diff changeset
    16
defs (overloaded)
10389
c7d8901ab269 proper setup of "parallel";
wenzelm
parents: 10330
diff changeset
    17
  prefix_def: "xs \<le> ys == \<exists>zs. ys = xs @ zs"
c7d8901ab269 proper setup of "parallel";
wenzelm
parents: 10330
diff changeset
    18
  strict_prefix_def: "xs < ys == xs \<le> ys \<and> xs \<noteq> (ys::'a list)"
10330
4362e906b745 "List prefixes" library theory (replaces old Lex/Prefix);
wenzelm
parents:
diff changeset
    19
12338
de0f4a63baa5 renamed class "term" to "type" (actually "HOL.type");
wenzelm
parents: 11987
diff changeset
    20
instance list :: (type) order
10389
c7d8901ab269 proper setup of "parallel";
wenzelm
parents: 10330
diff changeset
    21
  by intro_classes (auto simp add: prefix_def strict_prefix_def)
10330
4362e906b745 "List prefixes" library theory (replaces old Lex/Prefix);
wenzelm
parents:
diff changeset
    22
10389
c7d8901ab269 proper setup of "parallel";
wenzelm
parents: 10330
diff changeset
    23
lemma prefixI [intro?]: "ys = xs @ zs ==> xs \<le> ys"
c7d8901ab269 proper setup of "parallel";
wenzelm
parents: 10330
diff changeset
    24
  by (unfold prefix_def) blast
10330
4362e906b745 "List prefixes" library theory (replaces old Lex/Prefix);
wenzelm
parents:
diff changeset
    25
10389
c7d8901ab269 proper setup of "parallel";
wenzelm
parents: 10330
diff changeset
    26
lemma prefixE [elim?]: "xs \<le> ys ==> (!!zs. ys = xs @ zs ==> C) ==> C"
c7d8901ab269 proper setup of "parallel";
wenzelm
parents: 10330
diff changeset
    27
  by (unfold prefix_def) blast
10330
4362e906b745 "List prefixes" library theory (replaces old Lex/Prefix);
wenzelm
parents:
diff changeset
    28
10870
9444e3cf37e1 added strict_prefixI', strict_prefixE';
wenzelm
parents: 10512
diff changeset
    29
lemma strict_prefixI' [intro?]: "ys = xs @ z # zs ==> xs < ys"
9444e3cf37e1 added strict_prefixI', strict_prefixE';
wenzelm
parents: 10512
diff changeset
    30
  by (unfold strict_prefix_def prefix_def) blast
9444e3cf37e1 added strict_prefixI', strict_prefixE';
wenzelm
parents: 10512
diff changeset
    31
9444e3cf37e1 added strict_prefixI', strict_prefixE';
wenzelm
parents: 10512
diff changeset
    32
lemma strict_prefixE' [elim?]:
9444e3cf37e1 added strict_prefixI', strict_prefixE';
wenzelm
parents: 10512
diff changeset
    33
    "xs < ys ==> (!!z zs. ys = xs @ z # zs ==> C) ==> C"
9444e3cf37e1 added strict_prefixI', strict_prefixE';
wenzelm
parents: 10512
diff changeset
    34
proof -
9444e3cf37e1 added strict_prefixI', strict_prefixE';
wenzelm
parents: 10512
diff changeset
    35
  assume r: "!!z zs. ys = xs @ z # zs ==> C"
9444e3cf37e1 added strict_prefixI', strict_prefixE';
wenzelm
parents: 10512
diff changeset
    36
  assume "xs < ys"
9444e3cf37e1 added strict_prefixI', strict_prefixE';
wenzelm
parents: 10512
diff changeset
    37
  then obtain us where "ys = xs @ us" and "xs \<noteq> ys"
9444e3cf37e1 added strict_prefixI', strict_prefixE';
wenzelm
parents: 10512
diff changeset
    38
    by (unfold strict_prefix_def prefix_def) blast
9444e3cf37e1 added strict_prefixI', strict_prefixE';
wenzelm
parents: 10512
diff changeset
    39
  with r show ?thesis by (auto simp add: neq_Nil_conv)
9444e3cf37e1 added strict_prefixI', strict_prefixE';
wenzelm
parents: 10512
diff changeset
    40
qed
9444e3cf37e1 added strict_prefixI', strict_prefixE';
wenzelm
parents: 10512
diff changeset
    41
10389
c7d8901ab269 proper setup of "parallel";
wenzelm
parents: 10330
diff changeset
    42
lemma strict_prefixI [intro?]: "xs \<le> ys ==> xs \<noteq> ys ==> xs < (ys::'a list)"
c7d8901ab269 proper setup of "parallel";
wenzelm
parents: 10330
diff changeset
    43
  by (unfold strict_prefix_def) blast
10330
4362e906b745 "List prefixes" library theory (replaces old Lex/Prefix);
wenzelm
parents:
diff changeset
    44
10389
c7d8901ab269 proper setup of "parallel";
wenzelm
parents: 10330
diff changeset
    45
lemma strict_prefixE [elim?]:
c7d8901ab269 proper setup of "parallel";
wenzelm
parents: 10330
diff changeset
    46
    "xs < ys ==> (xs \<le> ys ==> xs \<noteq> (ys::'a list) ==> C) ==> C"
c7d8901ab269 proper setup of "parallel";
wenzelm
parents: 10330
diff changeset
    47
  by (unfold strict_prefix_def) blast
10330
4362e906b745 "List prefixes" library theory (replaces old Lex/Prefix);
wenzelm
parents:
diff changeset
    48
4362e906b745 "List prefixes" library theory (replaces old Lex/Prefix);
wenzelm
parents:
diff changeset
    49
10389
c7d8901ab269 proper setup of "parallel";
wenzelm
parents: 10330
diff changeset
    50
subsection {* Basic properties of prefixes *}
10330
4362e906b745 "List prefixes" library theory (replaces old Lex/Prefix);
wenzelm
parents:
diff changeset
    51
4362e906b745 "List prefixes" library theory (replaces old Lex/Prefix);
wenzelm
parents:
diff changeset
    52
theorem Nil_prefix [iff]: "[] \<le> xs"
10389
c7d8901ab269 proper setup of "parallel";
wenzelm
parents: 10330
diff changeset
    53
  by (simp add: prefix_def)
10330
4362e906b745 "List prefixes" library theory (replaces old Lex/Prefix);
wenzelm
parents:
diff changeset
    54
4362e906b745 "List prefixes" library theory (replaces old Lex/Prefix);
wenzelm
parents:
diff changeset
    55
theorem prefix_Nil [simp]: "(xs \<le> []) = (xs = [])"
10389
c7d8901ab269 proper setup of "parallel";
wenzelm
parents: 10330
diff changeset
    56
  by (induct xs) (simp_all add: prefix_def)
10330
4362e906b745 "List prefixes" library theory (replaces old Lex/Prefix);
wenzelm
parents:
diff changeset
    57
4362e906b745 "List prefixes" library theory (replaces old Lex/Prefix);
wenzelm
parents:
diff changeset
    58
lemma prefix_snoc [simp]: "(xs \<le> ys @ [y]) = (xs = ys @ [y] \<or> xs \<le> ys)"
10389
c7d8901ab269 proper setup of "parallel";
wenzelm
parents: 10330
diff changeset
    59
proof
c7d8901ab269 proper setup of "parallel";
wenzelm
parents: 10330
diff changeset
    60
  assume "xs \<le> ys @ [y]"
c7d8901ab269 proper setup of "parallel";
wenzelm
parents: 10330
diff changeset
    61
  then obtain zs where zs: "ys @ [y] = xs @ zs" ..
c7d8901ab269 proper setup of "parallel";
wenzelm
parents: 10330
diff changeset
    62
  show "xs = ys @ [y] \<or> xs \<le> ys"
c7d8901ab269 proper setup of "parallel";
wenzelm
parents: 10330
diff changeset
    63
  proof (cases zs rule: rev_cases)
c7d8901ab269 proper setup of "parallel";
wenzelm
parents: 10330
diff changeset
    64
    assume "zs = []"
c7d8901ab269 proper setup of "parallel";
wenzelm
parents: 10330
diff changeset
    65
    with zs have "xs = ys @ [y]" by simp
c7d8901ab269 proper setup of "parallel";
wenzelm
parents: 10330
diff changeset
    66
    thus ?thesis ..
c7d8901ab269 proper setup of "parallel";
wenzelm
parents: 10330
diff changeset
    67
  next
c7d8901ab269 proper setup of "parallel";
wenzelm
parents: 10330
diff changeset
    68
    fix z zs' assume "zs = zs' @ [z]"
c7d8901ab269 proper setup of "parallel";
wenzelm
parents: 10330
diff changeset
    69
    with zs have "ys = xs @ zs'" by simp
c7d8901ab269 proper setup of "parallel";
wenzelm
parents: 10330
diff changeset
    70
    hence "xs \<le> ys" ..
c7d8901ab269 proper setup of "parallel";
wenzelm
parents: 10330
diff changeset
    71
    thus ?thesis ..
c7d8901ab269 proper setup of "parallel";
wenzelm
parents: 10330
diff changeset
    72
  qed
c7d8901ab269 proper setup of "parallel";
wenzelm
parents: 10330
diff changeset
    73
next
c7d8901ab269 proper setup of "parallel";
wenzelm
parents: 10330
diff changeset
    74
  assume "xs = ys @ [y] \<or> xs \<le> ys"
c7d8901ab269 proper setup of "parallel";
wenzelm
parents: 10330
diff changeset
    75
  thus "xs \<le> ys @ [y]"
c7d8901ab269 proper setup of "parallel";
wenzelm
parents: 10330
diff changeset
    76
  proof
c7d8901ab269 proper setup of "parallel";
wenzelm
parents: 10330
diff changeset
    77
    assume "xs = ys @ [y]"
c7d8901ab269 proper setup of "parallel";
wenzelm
parents: 10330
diff changeset
    78
    thus ?thesis by simp
c7d8901ab269 proper setup of "parallel";
wenzelm
parents: 10330
diff changeset
    79
  next
c7d8901ab269 proper setup of "parallel";
wenzelm
parents: 10330
diff changeset
    80
    assume "xs \<le> ys"
c7d8901ab269 proper setup of "parallel";
wenzelm
parents: 10330
diff changeset
    81
    then obtain zs where "ys = xs @ zs" ..
c7d8901ab269 proper setup of "parallel";
wenzelm
parents: 10330
diff changeset
    82
    hence "ys @ [y] = xs @ (zs @ [y])" by simp
c7d8901ab269 proper setup of "parallel";
wenzelm
parents: 10330
diff changeset
    83
    thus ?thesis ..
c7d8901ab269 proper setup of "parallel";
wenzelm
parents: 10330
diff changeset
    84
  qed
c7d8901ab269 proper setup of "parallel";
wenzelm
parents: 10330
diff changeset
    85
qed
10330
4362e906b745 "List prefixes" library theory (replaces old Lex/Prefix);
wenzelm
parents:
diff changeset
    86
4362e906b745 "List prefixes" library theory (replaces old Lex/Prefix);
wenzelm
parents:
diff changeset
    87
lemma Cons_prefix_Cons [simp]: "(x # xs \<le> y # ys) = (x = y \<and> xs \<le> ys)"
10389
c7d8901ab269 proper setup of "parallel";
wenzelm
parents: 10330
diff changeset
    88
  by (auto simp add: prefix_def)
10330
4362e906b745 "List prefixes" library theory (replaces old Lex/Prefix);
wenzelm
parents:
diff changeset
    89
4362e906b745 "List prefixes" library theory (replaces old Lex/Prefix);
wenzelm
parents:
diff changeset
    90
lemma same_prefix_prefix [simp]: "(xs @ ys \<le> xs @ zs) = (ys \<le> zs)"
10389
c7d8901ab269 proper setup of "parallel";
wenzelm
parents: 10330
diff changeset
    91
  by (induct xs) simp_all
10330
4362e906b745 "List prefixes" library theory (replaces old Lex/Prefix);
wenzelm
parents:
diff changeset
    92
10389
c7d8901ab269 proper setup of "parallel";
wenzelm
parents: 10330
diff changeset
    93
lemma same_prefix_nil [iff]: "(xs @ ys \<le> xs) = (ys = [])"
c7d8901ab269 proper setup of "parallel";
wenzelm
parents: 10330
diff changeset
    94
proof -
c7d8901ab269 proper setup of "parallel";
wenzelm
parents: 10330
diff changeset
    95
  have "(xs @ ys \<le> xs @ []) = (ys \<le> [])" by (rule same_prefix_prefix)
c7d8901ab269 proper setup of "parallel";
wenzelm
parents: 10330
diff changeset
    96
  thus ?thesis by simp
c7d8901ab269 proper setup of "parallel";
wenzelm
parents: 10330
diff changeset
    97
qed
10330
4362e906b745 "List prefixes" library theory (replaces old Lex/Prefix);
wenzelm
parents:
diff changeset
    98
4362e906b745 "List prefixes" library theory (replaces old Lex/Prefix);
wenzelm
parents:
diff changeset
    99
lemma prefix_prefix [simp]: "xs \<le> ys ==> xs \<le> ys @ zs"
10389
c7d8901ab269 proper setup of "parallel";
wenzelm
parents: 10330
diff changeset
   100
proof -
c7d8901ab269 proper setup of "parallel";
wenzelm
parents: 10330
diff changeset
   101
  assume "xs \<le> ys"
c7d8901ab269 proper setup of "parallel";
wenzelm
parents: 10330
diff changeset
   102
  then obtain us where "ys = xs @ us" ..
c7d8901ab269 proper setup of "parallel";
wenzelm
parents: 10330
diff changeset
   103
  hence "ys @ zs = xs @ (us @ zs)" by simp
c7d8901ab269 proper setup of "parallel";
wenzelm
parents: 10330
diff changeset
   104
  thus ?thesis ..
c7d8901ab269 proper setup of "parallel";
wenzelm
parents: 10330
diff changeset
   105
qed
10330
4362e906b745 "List prefixes" library theory (replaces old Lex/Prefix);
wenzelm
parents:
diff changeset
   106
14300
bf8b8c9425c3 *** empty log message ***
nipkow
parents: 12338
diff changeset
   107
lemma append_prefixD: "xs @ ys \<le> zs \<Longrightarrow> xs \<le> zs"
bf8b8c9425c3 *** empty log message ***
nipkow
parents: 12338
diff changeset
   108
by(simp add:prefix_def) blast
bf8b8c9425c3 *** empty log message ***
nipkow
parents: 12338
diff changeset
   109
10330
4362e906b745 "List prefixes" library theory (replaces old Lex/Prefix);
wenzelm
parents:
diff changeset
   110
theorem prefix_Cons: "(xs \<le> y # ys) = (xs = [] \<or> (\<exists>zs. xs = y # zs \<and> zs \<le> ys))"
10389
c7d8901ab269 proper setup of "parallel";
wenzelm
parents: 10330
diff changeset
   111
  by (cases xs) (auto simp add: prefix_def)
10330
4362e906b745 "List prefixes" library theory (replaces old Lex/Prefix);
wenzelm
parents:
diff changeset
   112
4362e906b745 "List prefixes" library theory (replaces old Lex/Prefix);
wenzelm
parents:
diff changeset
   113
theorem prefix_append:
4362e906b745 "List prefixes" library theory (replaces old Lex/Prefix);
wenzelm
parents:
diff changeset
   114
    "(xs \<le> ys @ zs) = (xs \<le> ys \<or> (\<exists>us. xs = ys @ us \<and> us \<le> zs))"
4362e906b745 "List prefixes" library theory (replaces old Lex/Prefix);
wenzelm
parents:
diff changeset
   115
  apply (induct zs rule: rev_induct)
4362e906b745 "List prefixes" library theory (replaces old Lex/Prefix);
wenzelm
parents:
diff changeset
   116
   apply force
4362e906b745 "List prefixes" library theory (replaces old Lex/Prefix);
wenzelm
parents:
diff changeset
   117
  apply (simp del: append_assoc add: append_assoc [symmetric])
4362e906b745 "List prefixes" library theory (replaces old Lex/Prefix);
wenzelm
parents:
diff changeset
   118
  apply simp
4362e906b745 "List prefixes" library theory (replaces old Lex/Prefix);
wenzelm
parents:
diff changeset
   119
  apply blast
4362e906b745 "List prefixes" library theory (replaces old Lex/Prefix);
wenzelm
parents:
diff changeset
   120
  done
4362e906b745 "List prefixes" library theory (replaces old Lex/Prefix);
wenzelm
parents:
diff changeset
   121
4362e906b745 "List prefixes" library theory (replaces old Lex/Prefix);
wenzelm
parents:
diff changeset
   122
lemma append_one_prefix:
4362e906b745 "List prefixes" library theory (replaces old Lex/Prefix);
wenzelm
parents:
diff changeset
   123
    "xs \<le> ys ==> length xs < length ys ==> xs @ [ys ! length xs] \<le> ys"
4362e906b745 "List prefixes" library theory (replaces old Lex/Prefix);
wenzelm
parents:
diff changeset
   124
  apply (unfold prefix_def)
4362e906b745 "List prefixes" library theory (replaces old Lex/Prefix);
wenzelm
parents:
diff changeset
   125
  apply (auto simp add: nth_append)
10389
c7d8901ab269 proper setup of "parallel";
wenzelm
parents: 10330
diff changeset
   126
  apply (case_tac zs)
10330
4362e906b745 "List prefixes" library theory (replaces old Lex/Prefix);
wenzelm
parents:
diff changeset
   127
   apply auto
4362e906b745 "List prefixes" library theory (replaces old Lex/Prefix);
wenzelm
parents:
diff changeset
   128
  done
4362e906b745 "List prefixes" library theory (replaces old Lex/Prefix);
wenzelm
parents:
diff changeset
   129
4362e906b745 "List prefixes" library theory (replaces old Lex/Prefix);
wenzelm
parents:
diff changeset
   130
theorem prefix_length_le: "xs \<le> ys ==> length xs \<le> length ys"
10389
c7d8901ab269 proper setup of "parallel";
wenzelm
parents: 10330
diff changeset
   131
  by (auto simp add: prefix_def)
10330
4362e906b745 "List prefixes" library theory (replaces old Lex/Prefix);
wenzelm
parents:
diff changeset
   132
4362e906b745 "List prefixes" library theory (replaces old Lex/Prefix);
wenzelm
parents:
diff changeset
   133
14300
bf8b8c9425c3 *** empty log message ***
nipkow
parents: 12338
diff changeset
   134
lemma prefix_same_cases:
bf8b8c9425c3 *** empty log message ***
nipkow
parents: 12338
diff changeset
   135
 "\<lbrakk> (xs\<^isub>1::'a list) \<le> ys; xs\<^isub>2 \<le> ys \<rbrakk> \<Longrightarrow> xs\<^isub>1 \<le> xs\<^isub>2 \<or> xs\<^isub>2 \<le> xs\<^isub>1"
bf8b8c9425c3 *** empty log message ***
nipkow
parents: 12338
diff changeset
   136
apply(simp add:prefix_def)
bf8b8c9425c3 *** empty log message ***
nipkow
parents: 12338
diff changeset
   137
apply(erule exE)+
bf8b8c9425c3 *** empty log message ***
nipkow
parents: 12338
diff changeset
   138
apply(simp add: append_eq_append_conv_if split:if_splits)
bf8b8c9425c3 *** empty log message ***
nipkow
parents: 12338
diff changeset
   139
 apply(rule disjI2)
bf8b8c9425c3 *** empty log message ***
nipkow
parents: 12338
diff changeset
   140
 apply(rule_tac x = "drop (size xs\<^isub>2) xs\<^isub>1" in exI)
bf8b8c9425c3 *** empty log message ***
nipkow
parents: 12338
diff changeset
   141
 apply clarify
bf8b8c9425c3 *** empty log message ***
nipkow
parents: 12338
diff changeset
   142
 apply(drule sym)
bf8b8c9425c3 *** empty log message ***
nipkow
parents: 12338
diff changeset
   143
 apply(insert append_take_drop_id[of "length xs\<^isub>2" xs\<^isub>1])
bf8b8c9425c3 *** empty log message ***
nipkow
parents: 12338
diff changeset
   144
 apply simp
bf8b8c9425c3 *** empty log message ***
nipkow
parents: 12338
diff changeset
   145
apply(rule disjI1)
bf8b8c9425c3 *** empty log message ***
nipkow
parents: 12338
diff changeset
   146
apply(rule_tac x = "drop (size xs\<^isub>1) xs\<^isub>2" in exI)
bf8b8c9425c3 *** empty log message ***
nipkow
parents: 12338
diff changeset
   147
apply clarify
bf8b8c9425c3 *** empty log message ***
nipkow
parents: 12338
diff changeset
   148
apply(insert append_take_drop_id[of "length xs\<^isub>1" xs\<^isub>2])
bf8b8c9425c3 *** empty log message ***
nipkow
parents: 12338
diff changeset
   149
apply simp
bf8b8c9425c3 *** empty log message ***
nipkow
parents: 12338
diff changeset
   150
done
bf8b8c9425c3 *** empty log message ***
nipkow
parents: 12338
diff changeset
   151
bf8b8c9425c3 *** empty log message ***
nipkow
parents: 12338
diff changeset
   152
lemma set_mono_prefix:
bf8b8c9425c3 *** empty log message ***
nipkow
parents: 12338
diff changeset
   153
 "xs \<le> ys \<Longrightarrow> set xs \<subseteq> set ys"
bf8b8c9425c3 *** empty log message ***
nipkow
parents: 12338
diff changeset
   154
by(fastsimp simp add:prefix_def)
bf8b8c9425c3 *** empty log message ***
nipkow
parents: 12338
diff changeset
   155
bf8b8c9425c3 *** empty log message ***
nipkow
parents: 12338
diff changeset
   156
10389
c7d8901ab269 proper setup of "parallel";
wenzelm
parents: 10330
diff changeset
   157
subsection {* Parallel lists *}
c7d8901ab269 proper setup of "parallel";
wenzelm
parents: 10330
diff changeset
   158
c7d8901ab269 proper setup of "parallel";
wenzelm
parents: 10330
diff changeset
   159
constdefs
c7d8901ab269 proper setup of "parallel";
wenzelm
parents: 10330
diff changeset
   160
  parallel :: "'a list => 'a list => bool"    (infixl "\<parallel>" 50)
c7d8901ab269 proper setup of "parallel";
wenzelm
parents: 10330
diff changeset
   161
  "xs \<parallel> ys == \<not> xs \<le> ys \<and> \<not> ys \<le> xs"
c7d8901ab269 proper setup of "parallel";
wenzelm
parents: 10330
diff changeset
   162
c7d8901ab269 proper setup of "parallel";
wenzelm
parents: 10330
diff changeset
   163
lemma parallelI [intro]: "\<not> xs \<le> ys ==> \<not> ys \<le> xs ==> xs \<parallel> ys"
c7d8901ab269 proper setup of "parallel";
wenzelm
parents: 10330
diff changeset
   164
  by (unfold parallel_def) blast
10330
4362e906b745 "List prefixes" library theory (replaces old Lex/Prefix);
wenzelm
parents:
diff changeset
   165
10389
c7d8901ab269 proper setup of "parallel";
wenzelm
parents: 10330
diff changeset
   166
lemma parallelE [elim]:
c7d8901ab269 proper setup of "parallel";
wenzelm
parents: 10330
diff changeset
   167
    "xs \<parallel> ys ==> (\<not> xs \<le> ys ==> \<not> ys \<le> xs ==> C) ==> C"
c7d8901ab269 proper setup of "parallel";
wenzelm
parents: 10330
diff changeset
   168
  by (unfold parallel_def) blast
10330
4362e906b745 "List prefixes" library theory (replaces old Lex/Prefix);
wenzelm
parents:
diff changeset
   169
10389
c7d8901ab269 proper setup of "parallel";
wenzelm
parents: 10330
diff changeset
   170
theorem prefix_cases:
c7d8901ab269 proper setup of "parallel";
wenzelm
parents: 10330
diff changeset
   171
  "(xs \<le> ys ==> C) ==>
10512
wenzelm
parents: 10408
diff changeset
   172
    (ys < xs ==> C) ==>
10389
c7d8901ab269 proper setup of "parallel";
wenzelm
parents: 10330
diff changeset
   173
    (xs \<parallel> ys ==> C) ==> C"
10512
wenzelm
parents: 10408
diff changeset
   174
  by (unfold parallel_def strict_prefix_def) blast
10330
4362e906b745 "List prefixes" library theory (replaces old Lex/Prefix);
wenzelm
parents:
diff changeset
   175
10389
c7d8901ab269 proper setup of "parallel";
wenzelm
parents: 10330
diff changeset
   176
theorem parallel_decomp:
c7d8901ab269 proper setup of "parallel";
wenzelm
parents: 10330
diff changeset
   177
  "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
   178
proof (induct xs rule: rev_induct)
11987
bf31b35949ce tuned induct proofs;
wenzelm
parents: 11780
diff changeset
   179
  case Nil
bf31b35949ce tuned induct proofs;
wenzelm
parents: 11780
diff changeset
   180
  hence False by auto
bf31b35949ce tuned induct proofs;
wenzelm
parents: 11780
diff changeset
   181
  thus ?case ..
10408
d8b3613158b1 improved: 'induct' handle non-atomic goals;
wenzelm
parents: 10389
diff changeset
   182
next
11987
bf31b35949ce tuned induct proofs;
wenzelm
parents: 11780
diff changeset
   183
  case (snoc x xs)
bf31b35949ce tuned induct proofs;
wenzelm
parents: 11780
diff changeset
   184
  show ?case
10408
d8b3613158b1 improved: 'induct' handle non-atomic goals;
wenzelm
parents: 10389
diff changeset
   185
  proof (rule prefix_cases)
d8b3613158b1 improved: 'induct' handle non-atomic goals;
wenzelm
parents: 10389
diff changeset
   186
    assume le: "xs \<le> ys"
d8b3613158b1 improved: 'induct' handle non-atomic goals;
wenzelm
parents: 10389
diff changeset
   187
    then obtain ys' where ys: "ys = xs @ ys'" ..
d8b3613158b1 improved: 'induct' handle non-atomic goals;
wenzelm
parents: 10389
diff changeset
   188
    show ?thesis
d8b3613158b1 improved: 'induct' handle non-atomic goals;
wenzelm
parents: 10389
diff changeset
   189
    proof (cases ys')
d8b3613158b1 improved: 'induct' handle non-atomic goals;
wenzelm
parents: 10389
diff changeset
   190
      assume "ys' = []" with ys have "xs = ys" by simp
11987
bf31b35949ce tuned induct proofs;
wenzelm
parents: 11780
diff changeset
   191
      with snoc have "[x] \<parallel> []" by auto
10408
d8b3613158b1 improved: 'induct' handle non-atomic goals;
wenzelm
parents: 10389
diff changeset
   192
      hence False by blast
10389
c7d8901ab269 proper setup of "parallel";
wenzelm
parents: 10330
diff changeset
   193
      thus ?thesis ..
c7d8901ab269 proper setup of "parallel";
wenzelm
parents: 10330
diff changeset
   194
    next
10408
d8b3613158b1 improved: 'induct' handle non-atomic goals;
wenzelm
parents: 10389
diff changeset
   195
      fix c cs assume ys': "ys' = c # cs"
11987
bf31b35949ce tuned induct proofs;
wenzelm
parents: 11780
diff changeset
   196
      with snoc ys have "xs @ [x] \<parallel> xs @ c # cs" by (simp only:)
10408
d8b3613158b1 improved: 'induct' handle non-atomic goals;
wenzelm
parents: 10389
diff changeset
   197
      hence "x \<noteq> c" by auto
d8b3613158b1 improved: 'induct' handle non-atomic goals;
wenzelm
parents: 10389
diff changeset
   198
      moreover have "xs @ [x] = xs @ x # []" by simp
d8b3613158b1 improved: 'induct' handle non-atomic goals;
wenzelm
parents: 10389
diff changeset
   199
      moreover from ys ys' have "ys = xs @ c # cs" by (simp only:)
d8b3613158b1 improved: 'induct' handle non-atomic goals;
wenzelm
parents: 10389
diff changeset
   200
      ultimately show ?thesis by blast
10389
c7d8901ab269 proper setup of "parallel";
wenzelm
parents: 10330
diff changeset
   201
    qed
10408
d8b3613158b1 improved: 'induct' handle non-atomic goals;
wenzelm
parents: 10389
diff changeset
   202
  next
10512
wenzelm
parents: 10408
diff changeset
   203
    assume "ys < xs" hence "ys \<le> xs @ [x]" by (simp add: strict_prefix_def)
11987
bf31b35949ce tuned induct proofs;
wenzelm
parents: 11780
diff changeset
   204
    with snoc have False by blast
10408
d8b3613158b1 improved: 'induct' handle non-atomic goals;
wenzelm
parents: 10389
diff changeset
   205
    thus ?thesis ..
d8b3613158b1 improved: 'induct' handle non-atomic goals;
wenzelm
parents: 10389
diff changeset
   206
  next
d8b3613158b1 improved: 'induct' handle non-atomic goals;
wenzelm
parents: 10389
diff changeset
   207
    assume "xs \<parallel> ys"
11987
bf31b35949ce tuned induct proofs;
wenzelm
parents: 11780
diff changeset
   208
    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
   209
      and xs: "xs = as @ b # bs" and ys: "ys = as @ c # cs"
d8b3613158b1 improved: 'induct' handle non-atomic goals;
wenzelm
parents: 10389
diff changeset
   210
      by blast
d8b3613158b1 improved: 'induct' handle non-atomic goals;
wenzelm
parents: 10389
diff changeset
   211
    from xs have "xs @ [x] = as @ b # (bs @ [x])" by simp
d8b3613158b1 improved: 'induct' handle non-atomic goals;
wenzelm
parents: 10389
diff changeset
   212
    with neq ys show ?thesis by blast
10389
c7d8901ab269 proper setup of "parallel";
wenzelm
parents: 10330
diff changeset
   213
  qed
c7d8901ab269 proper setup of "parallel";
wenzelm
parents: 10330
diff changeset
   214
qed
10330
4362e906b745 "List prefixes" library theory (replaces old Lex/Prefix);
wenzelm
parents:
diff changeset
   215
14538
1d9d75a8efae removed o2l and fold_rel; moved postfix to Library/List_Prefix.thy
oheimb
parents: 14300
diff changeset
   216
1d9d75a8efae removed o2l and fold_rel; moved postfix to Library/List_Prefix.thy
oheimb
parents: 14300
diff changeset
   217
subsection {* Postfix order on lists *}
15355
0de05d104060 Removed postfix >= because of new >= sugar
nipkow
parents: 15140
diff changeset
   218
(*
14538
1d9d75a8efae removed o2l and fold_rel; moved postfix to Library/List_Prefix.thy
oheimb
parents: 14300
diff changeset
   219
constdefs
1d9d75a8efae removed o2l and fold_rel; moved postfix to Library/List_Prefix.thy
oheimb
parents: 14300
diff changeset
   220
  postfix :: "'a list => 'a list => bool"  ("(_/ >= _)" [51, 50] 50)
1d9d75a8efae removed o2l and fold_rel; moved postfix to Library/List_Prefix.thy
oheimb
parents: 14300
diff changeset
   221
  "xs >= ys == \<exists>zs. xs = zs @ ys"
1d9d75a8efae removed o2l and fold_rel; moved postfix to Library/List_Prefix.thy
oheimb
parents: 14300
diff changeset
   222
14706
71590b7733b7 tuned document;
wenzelm
parents: 14538
diff changeset
   223
lemma postfix_refl [simp, intro!]: "xs >= xs"
71590b7733b7 tuned document;
wenzelm
parents: 14538
diff changeset
   224
  by (auto simp add: postfix_def)
71590b7733b7 tuned document;
wenzelm
parents: 14538
diff changeset
   225
lemma postfix_trans: "\<lbrakk>xs >= ys; ys >= zs\<rbrakk> \<Longrightarrow> xs >= zs"
71590b7733b7 tuned document;
wenzelm
parents: 14538
diff changeset
   226
  by (auto simp add: postfix_def)
71590b7733b7 tuned document;
wenzelm
parents: 14538
diff changeset
   227
lemma postfix_antisym: "\<lbrakk>xs >= ys; ys >= xs\<rbrakk> \<Longrightarrow> xs = ys"
71590b7733b7 tuned document;
wenzelm
parents: 14538
diff changeset
   228
  by (auto simp add: postfix_def)
14538
1d9d75a8efae removed o2l and fold_rel; moved postfix to Library/List_Prefix.thy
oheimb
parents: 14300
diff changeset
   229
14706
71590b7733b7 tuned document;
wenzelm
parents: 14538
diff changeset
   230
lemma Nil_postfix [iff]: "xs >= []"
71590b7733b7 tuned document;
wenzelm
parents: 14538
diff changeset
   231
  by (simp add: postfix_def)
71590b7733b7 tuned document;
wenzelm
parents: 14538
diff changeset
   232
lemma postfix_Nil [simp]: "([] >= xs) = (xs = [])"
71590b7733b7 tuned document;
wenzelm
parents: 14538
diff changeset
   233
  by (auto simp add:postfix_def)
14538
1d9d75a8efae removed o2l and fold_rel; moved postfix to Library/List_Prefix.thy
oheimb
parents: 14300
diff changeset
   234
14706
71590b7733b7 tuned document;
wenzelm
parents: 14538
diff changeset
   235
lemma postfix_ConsI: "xs >= ys \<Longrightarrow> x#xs >= ys"
71590b7733b7 tuned document;
wenzelm
parents: 14538
diff changeset
   236
  by (auto simp add: postfix_def)
71590b7733b7 tuned document;
wenzelm
parents: 14538
diff changeset
   237
lemma postfix_ConsD: "xs >= y#ys \<Longrightarrow> xs >= ys"
71590b7733b7 tuned document;
wenzelm
parents: 14538
diff changeset
   238
  by (auto simp add: postfix_def)
14538
1d9d75a8efae removed o2l and fold_rel; moved postfix to Library/List_Prefix.thy
oheimb
parents: 14300
diff changeset
   239
14706
71590b7733b7 tuned document;
wenzelm
parents: 14538
diff changeset
   240
lemma postfix_appendI: "xs >= ys \<Longrightarrow> zs @ xs >= ys"
71590b7733b7 tuned document;
wenzelm
parents: 14538
diff changeset
   241
  by (auto simp add: postfix_def)
71590b7733b7 tuned document;
wenzelm
parents: 14538
diff changeset
   242
lemma postfix_appendD: "xs >= zs @ ys \<Longrightarrow> xs >= ys"
71590b7733b7 tuned document;
wenzelm
parents: 14538
diff changeset
   243
  by(auto simp add: postfix_def)
14538
1d9d75a8efae removed o2l and fold_rel; moved postfix to Library/List_Prefix.thy
oheimb
parents: 14300
diff changeset
   244
1d9d75a8efae removed o2l and fold_rel; moved postfix to Library/List_Prefix.thy
oheimb
parents: 14300
diff changeset
   245
lemma postfix_is_subset_lemma: "xs = zs @ ys \<Longrightarrow> set ys \<subseteq> set xs"
14706
71590b7733b7 tuned document;
wenzelm
parents: 14538
diff changeset
   246
  by (induct zs, auto)
14538
1d9d75a8efae removed o2l and fold_rel; moved postfix to Library/List_Prefix.thy
oheimb
parents: 14300
diff changeset
   247
lemma postfix_is_subset: "xs >= ys \<Longrightarrow> set ys \<subseteq> set xs"
14706
71590b7733b7 tuned document;
wenzelm
parents: 14538
diff changeset
   248
  by (unfold postfix_def, erule exE, erule postfix_is_subset_lemma)
14538
1d9d75a8efae removed o2l and fold_rel; moved postfix to Library/List_Prefix.thy
oheimb
parents: 14300
diff changeset
   249
1d9d75a8efae removed o2l and fold_rel; moved postfix to Library/List_Prefix.thy
oheimb
parents: 14300
diff changeset
   250
lemma postfix_ConsD2_lemma [rule_format]: "x#xs = zs @ y#ys \<longrightarrow> xs >= ys"
14706
71590b7733b7 tuned document;
wenzelm
parents: 14538
diff changeset
   251
  by (induct zs, auto intro!: postfix_appendI postfix_ConsI)
14538
1d9d75a8efae removed o2l and fold_rel; moved postfix to Library/List_Prefix.thy
oheimb
parents: 14300
diff changeset
   252
lemma postfix_ConsD2: "x#xs >= y#ys \<Longrightarrow> xs >= ys"
14706
71590b7733b7 tuned document;
wenzelm
parents: 14538
diff changeset
   253
  by (auto simp add: postfix_def dest!: postfix_ConsD2_lemma)
14538
1d9d75a8efae removed o2l and fold_rel; moved postfix to Library/List_Prefix.thy
oheimb
parents: 14300
diff changeset
   254
1d9d75a8efae removed o2l and fold_rel; moved postfix to Library/List_Prefix.thy
oheimb
parents: 14300
diff changeset
   255
lemma postfix2prefix: "(xs >= ys) = (rev ys <= rev xs)"
14706
71590b7733b7 tuned document;
wenzelm
parents: 14538
diff changeset
   256
  apply (unfold prefix_def postfix_def, safe)
71590b7733b7 tuned document;
wenzelm
parents: 14538
diff changeset
   257
  apply (rule_tac x = "rev zs" in exI, simp)
71590b7733b7 tuned document;
wenzelm
parents: 14538
diff changeset
   258
  apply (rule_tac x = "rev zs" in exI)
71590b7733b7 tuned document;
wenzelm
parents: 14538
diff changeset
   259
  apply (rule rev_is_rev_conv [THEN iffD1], simp)
71590b7733b7 tuned document;
wenzelm
parents: 14538
diff changeset
   260
  done
15355
0de05d104060 Removed postfix >= because of new >= sugar
nipkow
parents: 15140
diff changeset
   261
*)
10330
4362e906b745 "List prefixes" library theory (replaces old Lex/Prefix);
wenzelm
parents:
diff changeset
   262
end