src/HOL/Library/Sublist_Order.thy
author Christian Sternagel
Wed, 29 Aug 2012 12:24:26 +0900
changeset 49084 e3973567ed4f
parent 37765 26bdfb7b680b
child 49085 4eef5c2ff5ad
permissions -rw-r--r--
base Sublist_Order on Sublist (using a simplified form of embedding as sublist relation)
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
26735
39be3c7e643a added theory Sublist_Order
haftmann
parents:
diff changeset
     1
(*  Title:      HOL/Library/Sublist_Order.thy
39be3c7e643a added theory Sublist_Order
haftmann
parents:
diff changeset
     2
    Authors:    Peter Lammich, Uni Muenster <peter.lammich@uni-muenster.de>
33431
af516ed40e72 Completely overhauled
nipkow
parents: 30738
diff changeset
     3
                Florian Haftmann, Tobias Nipkow, TU Muenchen
26735
39be3c7e643a added theory Sublist_Order
haftmann
parents:
diff changeset
     4
*)
39be3c7e643a added theory Sublist_Order
haftmann
parents:
diff changeset
     5
39be3c7e643a added theory Sublist_Order
haftmann
parents:
diff changeset
     6
header {* Sublist Ordering *}
39be3c7e643a added theory Sublist_Order
haftmann
parents:
diff changeset
     7
39be3c7e643a added theory Sublist_Order
haftmann
parents:
diff changeset
     8
theory Sublist_Order
49084
e3973567ed4f base Sublist_Order on Sublist (using a simplified form of embedding as sublist relation)
Christian Sternagel
parents: 37765
diff changeset
     9
imports Main Sublist
26735
39be3c7e643a added theory Sublist_Order
haftmann
parents:
diff changeset
    10
begin
39be3c7e643a added theory Sublist_Order
haftmann
parents:
diff changeset
    11
39be3c7e643a added theory Sublist_Order
haftmann
parents:
diff changeset
    12
text {*
39be3c7e643a added theory Sublist_Order
haftmann
parents:
diff changeset
    13
  This theory defines sublist ordering on lists.
39be3c7e643a added theory Sublist_Order
haftmann
parents:
diff changeset
    14
  A list @{text ys} is a sublist of a list @{text xs},
39be3c7e643a added theory Sublist_Order
haftmann
parents:
diff changeset
    15
  iff one obtains @{text ys} by erasing some elements from @{text xs}.
39be3c7e643a added theory Sublist_Order
haftmann
parents:
diff changeset
    16
*}
39be3c7e643a added theory Sublist_Order
haftmann
parents:
diff changeset
    17
39be3c7e643a added theory Sublist_Order
haftmann
parents:
diff changeset
    18
subsection {* Definitions and basic lemmas *}
39be3c7e643a added theory Sublist_Order
haftmann
parents:
diff changeset
    19
33431
af516ed40e72 Completely overhauled
nipkow
parents: 30738
diff changeset
    20
instantiation list :: (type) ord
26735
39be3c7e643a added theory Sublist_Order
haftmann
parents:
diff changeset
    21
begin
39be3c7e643a added theory Sublist_Order
haftmann
parents:
diff changeset
    22
49084
e3973567ed4f base Sublist_Order on Sublist (using a simplified form of embedding as sublist relation)
Christian Sternagel
parents: 37765
diff changeset
    23
definition
e3973567ed4f base Sublist_Order on Sublist (using a simplified form of embedding as sublist relation)
Christian Sternagel
parents: 37765
diff changeset
    24
  "(xs :: 'a list) \<le> ys \<longleftrightarrow> emb (op =) xs ys"
26735
39be3c7e643a added theory Sublist_Order
haftmann
parents:
diff changeset
    25
39be3c7e643a added theory Sublist_Order
haftmann
parents:
diff changeset
    26
definition
49084
e3973567ed4f base Sublist_Order on Sublist (using a simplified form of embedding as sublist relation)
Christian Sternagel
parents: 37765
diff changeset
    27
  "(xs :: 'a list) < ys \<longleftrightarrow> xs \<le> ys \<and> \<not> ys \<le> xs"
26735
39be3c7e643a added theory Sublist_Order
haftmann
parents:
diff changeset
    28
33431
af516ed40e72 Completely overhauled
nipkow
parents: 30738
diff changeset
    29
instance proof qed
af516ed40e72 Completely overhauled
nipkow
parents: 30738
diff changeset
    30
af516ed40e72 Completely overhauled
nipkow
parents: 30738
diff changeset
    31
end
af516ed40e72 Completely overhauled
nipkow
parents: 30738
diff changeset
    32
49084
e3973567ed4f base Sublist_Order on Sublist (using a simplified form of embedding as sublist relation)
Christian Sternagel
parents: 37765
diff changeset
    33
lemma empty [simp, intro!]: "[] \<le> xs" by (auto simp: less_eq_list_def)
e3973567ed4f base Sublist_Order on Sublist (using a simplified form of embedding as sublist relation)
Christian Sternagel
parents: 37765
diff changeset
    34
e3973567ed4f base Sublist_Order on Sublist (using a simplified form of embedding as sublist relation)
Christian Sternagel
parents: 37765
diff changeset
    35
lemma drop: "xs \<le> ys \<Longrightarrow> xs \<le> (y # ys)"
e3973567ed4f base Sublist_Order on Sublist (using a simplified form of embedding as sublist relation)
Christian Sternagel
parents: 37765
diff changeset
    36
  by (unfold less_eq_list_def) blast
e3973567ed4f base Sublist_Order on Sublist (using a simplified form of embedding as sublist relation)
Christian Sternagel
parents: 37765
diff changeset
    37
e3973567ed4f base Sublist_Order on Sublist (using a simplified form of embedding as sublist relation)
Christian Sternagel
parents: 37765
diff changeset
    38
lemma take: "xs \<le> ys \<Longrightarrow> (x#xs) \<le> (x#ys)"
e3973567ed4f base Sublist_Order on Sublist (using a simplified form of embedding as sublist relation)
Christian Sternagel
parents: 37765
diff changeset
    39
  by (unfold less_eq_list_def) blast
e3973567ed4f base Sublist_Order on Sublist (using a simplified form of embedding as sublist relation)
Christian Sternagel
parents: 37765
diff changeset
    40
e3973567ed4f base Sublist_Order on Sublist (using a simplified form of embedding as sublist relation)
Christian Sternagel
parents: 37765
diff changeset
    41
lemmas le_list_induct [consumes 1, case_names empty drop take] =
e3973567ed4f base Sublist_Order on Sublist (using a simplified form of embedding as sublist relation)
Christian Sternagel
parents: 37765
diff changeset
    42
  emb.induct [of "op =", folded less_eq_list_def]
e3973567ed4f base Sublist_Order on Sublist (using a simplified form of embedding as sublist relation)
Christian Sternagel
parents: 37765
diff changeset
    43
e3973567ed4f base Sublist_Order on Sublist (using a simplified form of embedding as sublist relation)
Christian Sternagel
parents: 37765
diff changeset
    44
lemmas le_list_cases [consumes 1, case_names empty drop take] =
e3973567ed4f base Sublist_Order on Sublist (using a simplified form of embedding as sublist relation)
Christian Sternagel
parents: 37765
diff changeset
    45
  emb.cases [of "op =", folded less_eq_list_def]
e3973567ed4f base Sublist_Order on Sublist (using a simplified form of embedding as sublist relation)
Christian Sternagel
parents: 37765
diff changeset
    46
33431
af516ed40e72 Completely overhauled
nipkow
parents: 30738
diff changeset
    47
lemma le_list_length: "xs \<le> ys \<Longrightarrow> length xs \<le> length ys"
49084
e3973567ed4f base Sublist_Order on Sublist (using a simplified form of embedding as sublist relation)
Christian Sternagel
parents: 37765
diff changeset
    48
  by (induct rule: le_list_induct) auto
33431
af516ed40e72 Completely overhauled
nipkow
parents: 30738
diff changeset
    49
af516ed40e72 Completely overhauled
nipkow
parents: 30738
diff changeset
    50
lemma le_list_same_length: "xs \<le> ys \<Longrightarrow> length xs = length ys \<Longrightarrow> xs = ys"
49084
e3973567ed4f base Sublist_Order on Sublist (using a simplified form of embedding as sublist relation)
Christian Sternagel
parents: 37765
diff changeset
    51
  by (induct rule: le_list_induct) (auto dest: le_list_length)
33431
af516ed40e72 Completely overhauled
nipkow
parents: 30738
diff changeset
    52
af516ed40e72 Completely overhauled
nipkow
parents: 30738
diff changeset
    53
lemma not_le_list_length[simp]: "length ys < length xs \<Longrightarrow> ~ xs <= ys"
af516ed40e72 Completely overhauled
nipkow
parents: 30738
diff changeset
    54
by (metis le_list_length linorder_not_less)
af516ed40e72 Completely overhauled
nipkow
parents: 30738
diff changeset
    55
af516ed40e72 Completely overhauled
nipkow
parents: 30738
diff changeset
    56
lemma le_list_below_empty [simp]: "xs \<le> [] \<longleftrightarrow> xs = []"
af516ed40e72 Completely overhauled
nipkow
parents: 30738
diff changeset
    57
by (auto dest: le_list_length)
af516ed40e72 Completely overhauled
nipkow
parents: 30738
diff changeset
    58
af516ed40e72 Completely overhauled
nipkow
parents: 30738
diff changeset
    59
lemma le_list_drop_many: "xs \<le> ys \<Longrightarrow> xs \<le> zs @ ys"
49084
e3973567ed4f base Sublist_Order on Sublist (using a simplified form of embedding as sublist relation)
Christian Sternagel
parents: 37765
diff changeset
    60
by (induct zs) (auto simp: less_eq_list_def)
33431
af516ed40e72 Completely overhauled
nipkow
parents: 30738
diff changeset
    61
af516ed40e72 Completely overhauled
nipkow
parents: 30738
diff changeset
    62
lemma [code]: "[] <= xs \<longleftrightarrow> True"
49084
e3973567ed4f base Sublist_Order on Sublist (using a simplified form of embedding as sublist relation)
Christian Sternagel
parents: 37765
diff changeset
    63
by (simp add: less_eq_list_def)
33431
af516ed40e72 Completely overhauled
nipkow
parents: 30738
diff changeset
    64
af516ed40e72 Completely overhauled
nipkow
parents: 30738
diff changeset
    65
lemma [code]: "(x#xs) <= [] \<longleftrightarrow> False"
af516ed40e72 Completely overhauled
nipkow
parents: 30738
diff changeset
    66
by simp
af516ed40e72 Completely overhauled
nipkow
parents: 30738
diff changeset
    67
af516ed40e72 Completely overhauled
nipkow
parents: 30738
diff changeset
    68
lemma le_list_drop_Cons: assumes "x#xs <= ys" shows "xs <= ys"
af516ed40e72 Completely overhauled
nipkow
parents: 30738
diff changeset
    69
proof-
af516ed40e72 Completely overhauled
nipkow
parents: 30738
diff changeset
    70
  { fix xs' ys'
af516ed40e72 Completely overhauled
nipkow
parents: 30738
diff changeset
    71
    assume "xs' <= ys"
af516ed40e72 Completely overhauled
nipkow
parents: 30738
diff changeset
    72
    hence "ALL x xs. xs' = x#xs \<longrightarrow> xs <= ys"
49084
e3973567ed4f base Sublist_Order on Sublist (using a simplified form of embedding as sublist relation)
Christian Sternagel
parents: 37765
diff changeset
    73
    proof (induct rule: le_list_induct)
33431
af516ed40e72 Completely overhauled
nipkow
parents: 30738
diff changeset
    74
      case empty thus ?case by simp
af516ed40e72 Completely overhauled
nipkow
parents: 30738
diff changeset
    75
    next
49084
e3973567ed4f base Sublist_Order on Sublist (using a simplified form of embedding as sublist relation)
Christian Sternagel
parents: 37765
diff changeset
    76
      note drop' = drop
e3973567ed4f base Sublist_Order on Sublist (using a simplified form of embedding as sublist relation)
Christian Sternagel
parents: 37765
diff changeset
    77
      case drop thus ?case by (metis drop')
33431
af516ed40e72 Completely overhauled
nipkow
parents: 30738
diff changeset
    78
    next
49084
e3973567ed4f base Sublist_Order on Sublist (using a simplified form of embedding as sublist relation)
Christian Sternagel
parents: 37765
diff changeset
    79
      note t = take
33431
af516ed40e72 Completely overhauled
nipkow
parents: 30738
diff changeset
    80
      case take thus ?case by (simp add: drop)
af516ed40e72 Completely overhauled
nipkow
parents: 30738
diff changeset
    81
    qed }
af516ed40e72 Completely overhauled
nipkow
parents: 30738
diff changeset
    82
  from this[OF assms] show ?thesis by simp
af516ed40e72 Completely overhauled
nipkow
parents: 30738
diff changeset
    83
qed
af516ed40e72 Completely overhauled
nipkow
parents: 30738
diff changeset
    84
af516ed40e72 Completely overhauled
nipkow
parents: 30738
diff changeset
    85
lemma le_list_drop_Cons2:
af516ed40e72 Completely overhauled
nipkow
parents: 30738
diff changeset
    86
assumes "x#xs <= x#ys" shows "xs <= ys"
af516ed40e72 Completely overhauled
nipkow
parents: 30738
diff changeset
    87
using assms
49084
e3973567ed4f base Sublist_Order on Sublist (using a simplified form of embedding as sublist relation)
Christian Sternagel
parents: 37765
diff changeset
    88
proof (cases rule: le_list_cases)
33431
af516ed40e72 Completely overhauled
nipkow
parents: 30738
diff changeset
    89
  case drop thus ?thesis by (metis le_list_drop_Cons list.inject)
af516ed40e72 Completely overhauled
nipkow
parents: 30738
diff changeset
    90
qed simp_all
af516ed40e72 Completely overhauled
nipkow
parents: 30738
diff changeset
    91
af516ed40e72 Completely overhauled
nipkow
parents: 30738
diff changeset
    92
lemma le_list_drop_Cons_neq: assumes "x # xs <= y # ys"
af516ed40e72 Completely overhauled
nipkow
parents: 30738
diff changeset
    93
shows "x ~= y \<Longrightarrow> x # xs <= ys"
49084
e3973567ed4f base Sublist_Order on Sublist (using a simplified form of embedding as sublist relation)
Christian Sternagel
parents: 37765
diff changeset
    94
using assms by (cases rule: le_list_cases) auto
33431
af516ed40e72 Completely overhauled
nipkow
parents: 30738
diff changeset
    95
af516ed40e72 Completely overhauled
nipkow
parents: 30738
diff changeset
    96
lemma le_list_Cons2_iff[simp,code]: "(x#xs) <= (y#ys) \<longleftrightarrow>
af516ed40e72 Completely overhauled
nipkow
parents: 30738
diff changeset
    97
  (if x=y then xs <= ys else (x#xs) <= ys)"
af516ed40e72 Completely overhauled
nipkow
parents: 30738
diff changeset
    98
by (metis drop take le_list_drop_Cons2 le_list_drop_Cons_neq)
af516ed40e72 Completely overhauled
nipkow
parents: 30738
diff changeset
    99
af516ed40e72 Completely overhauled
nipkow
parents: 30738
diff changeset
   100
lemma le_list_take_many_iff: "zs @ xs \<le> zs @ ys \<longleftrightarrow> xs \<le> ys"
af516ed40e72 Completely overhauled
nipkow
parents: 30738
diff changeset
   101
by (induct zs) (auto intro: take)
af516ed40e72 Completely overhauled
nipkow
parents: 30738
diff changeset
   102
af516ed40e72 Completely overhauled
nipkow
parents: 30738
diff changeset
   103
lemma le_list_Cons_EX:
af516ed40e72 Completely overhauled
nipkow
parents: 30738
diff changeset
   104
  assumes "x # ys <= zs" shows "EX us vs. zs = us @ x # vs & ys <= vs"
af516ed40e72 Completely overhauled
nipkow
parents: 30738
diff changeset
   105
proof-
af516ed40e72 Completely overhauled
nipkow
parents: 30738
diff changeset
   106
  { fix xys zs :: "'a list" assume "xys <= zs"
af516ed40e72 Completely overhauled
nipkow
parents: 30738
diff changeset
   107
    hence "ALL x ys. xys = x#ys \<longrightarrow> (EX us vs. zs = us @ x # vs & ys <= vs)"
49084
e3973567ed4f base Sublist_Order on Sublist (using a simplified form of embedding as sublist relation)
Christian Sternagel
parents: 37765
diff changeset
   108
    proof (induct rule: le_list_induct)
33431
af516ed40e72 Completely overhauled
nipkow
parents: 30738
diff changeset
   109
      case empty show ?case by simp
af516ed40e72 Completely overhauled
nipkow
parents: 30738
diff changeset
   110
    next
af516ed40e72 Completely overhauled
nipkow
parents: 30738
diff changeset
   111
      case take thus ?case by (metis list.inject self_append_conv2)
af516ed40e72 Completely overhauled
nipkow
parents: 30738
diff changeset
   112
    next
af516ed40e72 Completely overhauled
nipkow
parents: 30738
diff changeset
   113
      case drop thus ?case by (metis append_eq_Cons_conv)
af516ed40e72 Completely overhauled
nipkow
parents: 30738
diff changeset
   114
    qed
af516ed40e72 Completely overhauled
nipkow
parents: 30738
diff changeset
   115
  } with assms show ?thesis by blast
af516ed40e72 Completely overhauled
nipkow
parents: 30738
diff changeset
   116
qed
af516ed40e72 Completely overhauled
nipkow
parents: 30738
diff changeset
   117
af516ed40e72 Completely overhauled
nipkow
parents: 30738
diff changeset
   118
instantiation list :: (type) order
af516ed40e72 Completely overhauled
nipkow
parents: 30738
diff changeset
   119
begin
26735
39be3c7e643a added theory Sublist_Order
haftmann
parents:
diff changeset
   120
39be3c7e643a added theory Sublist_Order
haftmann
parents:
diff changeset
   121
instance proof
39be3c7e643a added theory Sublist_Order
haftmann
parents:
diff changeset
   122
  fix xs ys :: "'a list"
27682
25aceefd4786 added class preorder
haftmann
parents: 27487
diff changeset
   123
  show "xs < ys \<longleftrightarrow> xs \<le> ys \<and> \<not> ys \<le> xs" unfolding less_list_def .. 
26735
39be3c7e643a added theory Sublist_Order
haftmann
parents:
diff changeset
   124
next
39be3c7e643a added theory Sublist_Order
haftmann
parents:
diff changeset
   125
  fix xs :: "'a list"
49084
e3973567ed4f base Sublist_Order on Sublist (using a simplified form of embedding as sublist relation)
Christian Sternagel
parents: 37765
diff changeset
   126
  show "xs \<le> xs" by (induct xs) (auto intro!: drop)
26735
39be3c7e643a added theory Sublist_Order
haftmann
parents:
diff changeset
   127
next
39be3c7e643a added theory Sublist_Order
haftmann
parents:
diff changeset
   128
  fix xs ys :: "'a list"
33431
af516ed40e72 Completely overhauled
nipkow
parents: 30738
diff changeset
   129
  assume "xs <= ys"
af516ed40e72 Completely overhauled
nipkow
parents: 30738
diff changeset
   130
  hence "ys <= xs \<longrightarrow> xs = ys"
49084
e3973567ed4f base Sublist_Order on Sublist (using a simplified form of embedding as sublist relation)
Christian Sternagel
parents: 37765
diff changeset
   131
  proof (induct rule: le_list_induct)
33431
af516ed40e72 Completely overhauled
nipkow
parents: 30738
diff changeset
   132
    case empty show ?case by simp
af516ed40e72 Completely overhauled
nipkow
parents: 30738
diff changeset
   133
  next
af516ed40e72 Completely overhauled
nipkow
parents: 30738
diff changeset
   134
    case take thus ?case by simp
af516ed40e72 Completely overhauled
nipkow
parents: 30738
diff changeset
   135
  next
af516ed40e72 Completely overhauled
nipkow
parents: 30738
diff changeset
   136
    case drop thus ?case
af516ed40e72 Completely overhauled
nipkow
parents: 30738
diff changeset
   137
      by(metis le_list_drop_Cons le_list_length Suc_length_conv Suc_n_not_le_n)
af516ed40e72 Completely overhauled
nipkow
parents: 30738
diff changeset
   138
  qed
af516ed40e72 Completely overhauled
nipkow
parents: 30738
diff changeset
   139
  moreover assume "ys <= xs"
26735
39be3c7e643a added theory Sublist_Order
haftmann
parents:
diff changeset
   140
  ultimately show "xs = ys" by blast
39be3c7e643a added theory Sublist_Order
haftmann
parents:
diff changeset
   141
next
39be3c7e643a added theory Sublist_Order
haftmann
parents:
diff changeset
   142
  fix xs ys zs :: "'a list"
33431
af516ed40e72 Completely overhauled
nipkow
parents: 30738
diff changeset
   143
  assume "xs <= ys"
af516ed40e72 Completely overhauled
nipkow
parents: 30738
diff changeset
   144
  hence "ys <= zs \<longrightarrow> xs <= zs"
49084
e3973567ed4f base Sublist_Order on Sublist (using a simplified form of embedding as sublist relation)
Christian Sternagel
parents: 37765
diff changeset
   145
  proof (induct arbitrary:zs rule: le_list_induct)
33431
af516ed40e72 Completely overhauled
nipkow
parents: 30738
diff changeset
   146
    case empty show ?case by simp
af516ed40e72 Completely overhauled
nipkow
parents: 30738
diff changeset
   147
  next
49084
e3973567ed4f base Sublist_Order on Sublist (using a simplified form of embedding as sublist relation)
Christian Sternagel
parents: 37765
diff changeset
   148
    note take' = take
e3973567ed4f base Sublist_Order on Sublist (using a simplified form of embedding as sublist relation)
Christian Sternagel
parents: 37765
diff changeset
   149
    case (take x y xs ys) show ?case
33431
af516ed40e72 Completely overhauled
nipkow
parents: 30738
diff changeset
   150
    proof
49084
e3973567ed4f base Sublist_Order on Sublist (using a simplified form of embedding as sublist relation)
Christian Sternagel
parents: 37765
diff changeset
   151
      assume "y # ys <= zs"
33431
af516ed40e72 Completely overhauled
nipkow
parents: 30738
diff changeset
   152
      with take show "x # xs <= zs"
49084
e3973567ed4f base Sublist_Order on Sublist (using a simplified form of embedding as sublist relation)
Christian Sternagel
parents: 37765
diff changeset
   153
        by(metis le_list_Cons_EX le_list_drop_many take')
26735
39be3c7e643a added theory Sublist_Order
haftmann
parents:
diff changeset
   154
    qed
33431
af516ed40e72 Completely overhauled
nipkow
parents: 30738
diff changeset
   155
  next
af516ed40e72 Completely overhauled
nipkow
parents: 30738
diff changeset
   156
    case drop thus ?case by (metis le_list_drop_Cons)
af516ed40e72 Completely overhauled
nipkow
parents: 30738
diff changeset
   157
  qed
af516ed40e72 Completely overhauled
nipkow
parents: 30738
diff changeset
   158
  moreover assume "ys <= zs"
af516ed40e72 Completely overhauled
nipkow
parents: 30738
diff changeset
   159
  ultimately show "xs <= zs" by blast
26735
39be3c7e643a added theory Sublist_Order
haftmann
parents:
diff changeset
   160
qed
39be3c7e643a added theory Sublist_Order
haftmann
parents:
diff changeset
   161
39be3c7e643a added theory Sublist_Order
haftmann
parents:
diff changeset
   162
end
39be3c7e643a added theory Sublist_Order
haftmann
parents:
diff changeset
   163
33431
af516ed40e72 Completely overhauled
nipkow
parents: 30738
diff changeset
   164
lemma le_list_append_le_same_iff: "xs @ ys <= ys \<longleftrightarrow> xs=[]"
af516ed40e72 Completely overhauled
nipkow
parents: 30738
diff changeset
   165
by (auto dest: le_list_length)
26735
39be3c7e643a added theory Sublist_Order
haftmann
parents:
diff changeset
   166
33431
af516ed40e72 Completely overhauled
nipkow
parents: 30738
diff changeset
   167
lemma le_list_append_mono: "\<lbrakk> xs <= xs'; ys <= ys' \<rbrakk> \<Longrightarrow> xs@ys <= xs'@ys'"
49084
e3973567ed4f base Sublist_Order on Sublist (using a simplified form of embedding as sublist relation)
Christian Sternagel
parents: 37765
diff changeset
   168
apply (induct rule: le_list_induct)
33431
af516ed40e72 Completely overhauled
nipkow
parents: 30738
diff changeset
   169
  apply (metis eq_Nil_appendI le_list_drop_many)
af516ed40e72 Completely overhauled
nipkow
parents: 30738
diff changeset
   170
 apply (metis Cons_eq_append_conv le_list_drop_Cons order_eq_refl order_trans)
af516ed40e72 Completely overhauled
nipkow
parents: 30738
diff changeset
   171
apply simp
af516ed40e72 Completely overhauled
nipkow
parents: 30738
diff changeset
   172
done
26735
39be3c7e643a added theory Sublist_Order
haftmann
parents:
diff changeset
   173
33431
af516ed40e72 Completely overhauled
nipkow
parents: 30738
diff changeset
   174
lemma less_list_length: "xs < ys \<Longrightarrow> length xs < length ys"
af516ed40e72 Completely overhauled
nipkow
parents: 30738
diff changeset
   175
by (metis le_list_length le_list_same_length le_neq_implies_less less_list_def)
26735
39be3c7e643a added theory Sublist_Order
haftmann
parents:
diff changeset
   176
33431
af516ed40e72 Completely overhauled
nipkow
parents: 30738
diff changeset
   177
lemma less_list_empty [simp]: "[] < xs \<longleftrightarrow> xs \<noteq> []"
af516ed40e72 Completely overhauled
nipkow
parents: 30738
diff changeset
   178
by (metis empty order_less_le)
af516ed40e72 Completely overhauled
nipkow
parents: 30738
diff changeset
   179
af516ed40e72 Completely overhauled
nipkow
parents: 30738
diff changeset
   180
lemma less_list_below_empty[simp]: "xs < [] \<longleftrightarrow> False"
af516ed40e72 Completely overhauled
nipkow
parents: 30738
diff changeset
   181
by (metis empty less_list_def)
af516ed40e72 Completely overhauled
nipkow
parents: 30738
diff changeset
   182
af516ed40e72 Completely overhauled
nipkow
parents: 30738
diff changeset
   183
lemma less_list_drop: "xs < ys \<Longrightarrow> xs < x # ys"
49084
e3973567ed4f base Sublist_Order on Sublist (using a simplified form of embedding as sublist relation)
Christian Sternagel
parents: 37765
diff changeset
   184
by (unfold less_le) (auto intro: drop)
26735
39be3c7e643a added theory Sublist_Order
haftmann
parents:
diff changeset
   185
33431
af516ed40e72 Completely overhauled
nipkow
parents: 30738
diff changeset
   186
lemma less_list_take_iff: "x # xs < x # ys \<longleftrightarrow> xs < ys"
af516ed40e72 Completely overhauled
nipkow
parents: 30738
diff changeset
   187
by (metis le_list_Cons2_iff less_list_def)
af516ed40e72 Completely overhauled
nipkow
parents: 30738
diff changeset
   188
af516ed40e72 Completely overhauled
nipkow
parents: 30738
diff changeset
   189
lemma less_list_drop_many: "xs < ys \<Longrightarrow> xs < zs @ ys"
af516ed40e72 Completely overhauled
nipkow
parents: 30738
diff changeset
   190
by(metis le_list_append_le_same_iff le_list_drop_many order_less_le self_append_conv2)
af516ed40e72 Completely overhauled
nipkow
parents: 30738
diff changeset
   191
af516ed40e72 Completely overhauled
nipkow
parents: 30738
diff changeset
   192
lemma less_list_take_many_iff: "zs @ xs < zs @ ys \<longleftrightarrow> xs < ys"
af516ed40e72 Completely overhauled
nipkow
parents: 30738
diff changeset
   193
by (metis le_list_take_many_iff less_list_def)
26735
39be3c7e643a added theory Sublist_Order
haftmann
parents:
diff changeset
   194
39be3c7e643a added theory Sublist_Order
haftmann
parents:
diff changeset
   195
39be3c7e643a added theory Sublist_Order
haftmann
parents:
diff changeset
   196
subsection {* Appending elements *}
39be3c7e643a added theory Sublist_Order
haftmann
parents:
diff changeset
   197
33431
af516ed40e72 Completely overhauled
nipkow
parents: 30738
diff changeset
   198
lemma le_list_rev_take_iff[simp]: "xs @ zs \<le> ys @ zs \<longleftrightarrow> xs \<le> ys" (is "?L = ?R")
af516ed40e72 Completely overhauled
nipkow
parents: 30738
diff changeset
   199
proof
af516ed40e72 Completely overhauled
nipkow
parents: 30738
diff changeset
   200
  { fix xs' ys' xs ys zs :: "'a list" assume "xs' <= ys'"
af516ed40e72 Completely overhauled
nipkow
parents: 30738
diff changeset
   201
    hence "xs' = xs @ zs & ys' = ys @ zs \<longrightarrow> xs <= ys"
49084
e3973567ed4f base Sublist_Order on Sublist (using a simplified form of embedding as sublist relation)
Christian Sternagel
parents: 37765
diff changeset
   202
    proof (induct arbitrary: xs ys zs rule: le_list_induct)
33431
af516ed40e72 Completely overhauled
nipkow
parents: 30738
diff changeset
   203
      case empty show ?case by simp
af516ed40e72 Completely overhauled
nipkow
parents: 30738
diff changeset
   204
    next
49084
e3973567ed4f base Sublist_Order on Sublist (using a simplified form of embedding as sublist relation)
Christian Sternagel
parents: 37765
diff changeset
   205
      note drop' = drop
33431
af516ed40e72 Completely overhauled
nipkow
parents: 30738
diff changeset
   206
      case (drop xs' ys' x)
af516ed40e72 Completely overhauled
nipkow
parents: 30738
diff changeset
   207
      { assume "ys=[]" hence ?case using drop(1) by auto }
af516ed40e72 Completely overhauled
nipkow
parents: 30738
diff changeset
   208
      moreover
af516ed40e72 Completely overhauled
nipkow
parents: 30738
diff changeset
   209
      { fix us assume "ys = x#us"
49084
e3973567ed4f base Sublist_Order on Sublist (using a simplified form of embedding as sublist relation)
Christian Sternagel
parents: 37765
diff changeset
   210
        hence ?case using drop(2) by(simp add: drop') }
33431
af516ed40e72 Completely overhauled
nipkow
parents: 30738
diff changeset
   211
      ultimately show ?case by (auto simp:Cons_eq_append_conv)
af516ed40e72 Completely overhauled
nipkow
parents: 30738
diff changeset
   212
    next
49084
e3973567ed4f base Sublist_Order on Sublist (using a simplified form of embedding as sublist relation)
Christian Sternagel
parents: 37765
diff changeset
   213
      case (take x y xs' ys')
33431
af516ed40e72 Completely overhauled
nipkow
parents: 30738
diff changeset
   214
      { assume "xs=[]" hence ?case using take(1) by auto }
af516ed40e72 Completely overhauled
nipkow
parents: 30738
diff changeset
   215
      moreover
49084
e3973567ed4f base Sublist_Order on Sublist (using a simplified form of embedding as sublist relation)
Christian Sternagel
parents: 37765
diff changeset
   216
      { fix us vs assume "xs=x#us" "ys=x#vs" hence ?case using take by auto}
33431
af516ed40e72 Completely overhauled
nipkow
parents: 30738
diff changeset
   217
      moreover
af516ed40e72 Completely overhauled
nipkow
parents: 30738
diff changeset
   218
      { fix us assume "xs=x#us" "ys=[]" hence ?case using take(2) by bestsimp }
49084
e3973567ed4f base Sublist_Order on Sublist (using a simplified form of embedding as sublist relation)
Christian Sternagel
parents: 37765
diff changeset
   219
      ultimately show ?case using `x = y` by (auto simp:Cons_eq_append_conv)
33431
af516ed40e72 Completely overhauled
nipkow
parents: 30738
diff changeset
   220
    qed }
af516ed40e72 Completely overhauled
nipkow
parents: 30738
diff changeset
   221
  moreover assume ?L
af516ed40e72 Completely overhauled
nipkow
parents: 30738
diff changeset
   222
  ultimately show ?R by blast
af516ed40e72 Completely overhauled
nipkow
parents: 30738
diff changeset
   223
next
af516ed40e72 Completely overhauled
nipkow
parents: 30738
diff changeset
   224
  assume ?R thus ?L by(metis le_list_append_mono order_refl)
af516ed40e72 Completely overhauled
nipkow
parents: 30738
diff changeset
   225
qed
af516ed40e72 Completely overhauled
nipkow
parents: 30738
diff changeset
   226
af516ed40e72 Completely overhauled
nipkow
parents: 30738
diff changeset
   227
lemma less_list_rev_take: "xs @ zs < ys @ zs \<longleftrightarrow> xs < ys"
af516ed40e72 Completely overhauled
nipkow
parents: 30738
diff changeset
   228
by (unfold less_le) auto
af516ed40e72 Completely overhauled
nipkow
parents: 30738
diff changeset
   229
af516ed40e72 Completely overhauled
nipkow
parents: 30738
diff changeset
   230
lemma le_list_rev_drop_many: "xs \<le> ys \<Longrightarrow> xs \<le> ys @ zs"
af516ed40e72 Completely overhauled
nipkow
parents: 30738
diff changeset
   231
by (metis append_Nil2 empty le_list_append_mono)
26735
39be3c7e643a added theory Sublist_Order
haftmann
parents:
diff changeset
   232
39be3c7e643a added theory Sublist_Order
haftmann
parents:
diff changeset
   233
39be3c7e643a added theory Sublist_Order
haftmann
parents:
diff changeset
   234
subsection {* Relation to standard list operations *}
39be3c7e643a added theory Sublist_Order
haftmann
parents:
diff changeset
   235
33431
af516ed40e72 Completely overhauled
nipkow
parents: 30738
diff changeset
   236
lemma le_list_map: "xs \<le> ys \<Longrightarrow> map f xs \<le> map f ys"
49084
e3973567ed4f base Sublist_Order on Sublist (using a simplified form of embedding as sublist relation)
Christian Sternagel
parents: 37765
diff changeset
   237
by (induct rule: le_list_induct) (auto intro: drop)
33431
af516ed40e72 Completely overhauled
nipkow
parents: 30738
diff changeset
   238
af516ed40e72 Completely overhauled
nipkow
parents: 30738
diff changeset
   239
lemma le_list_filter_left[simp]: "filter f xs \<le> xs"
49084
e3973567ed4f base Sublist_Order on Sublist (using a simplified form of embedding as sublist relation)
Christian Sternagel
parents: 37765
diff changeset
   240
by (induct xs) (auto intro: drop)
33431
af516ed40e72 Completely overhauled
nipkow
parents: 30738
diff changeset
   241
af516ed40e72 Completely overhauled
nipkow
parents: 30738
diff changeset
   242
lemma le_list_filter: "xs \<le> ys \<Longrightarrow> filter f xs \<le> filter f ys"
49084
e3973567ed4f base Sublist_Order on Sublist (using a simplified form of embedding as sublist relation)
Christian Sternagel
parents: 37765
diff changeset
   243
by (induct rule: le_list_induct) (auto intro: drop)
33431
af516ed40e72 Completely overhauled
nipkow
parents: 30738
diff changeset
   244
33499
haftmann
parents: 33431
diff changeset
   245
lemma "xs \<le> ys \<longleftrightarrow> (EX N. xs = sublist ys N)" (is "?L = ?R")
33431
af516ed40e72 Completely overhauled
nipkow
parents: 30738
diff changeset
   246
proof
af516ed40e72 Completely overhauled
nipkow
parents: 30738
diff changeset
   247
  assume ?L
af516ed40e72 Completely overhauled
nipkow
parents: 30738
diff changeset
   248
  thus ?R
49084
e3973567ed4f base Sublist_Order on Sublist (using a simplified form of embedding as sublist relation)
Christian Sternagel
parents: 37765
diff changeset
   249
  proof (induct rule: le_list_induct)
33431
af516ed40e72 Completely overhauled
nipkow
parents: 30738
diff changeset
   250
    case empty show ?case by (metis sublist_empty)
af516ed40e72 Completely overhauled
nipkow
parents: 30738
diff changeset
   251
  next
af516ed40e72 Completely overhauled
nipkow
parents: 30738
diff changeset
   252
    case (drop xs ys x)
af516ed40e72 Completely overhauled
nipkow
parents: 30738
diff changeset
   253
    then obtain N where "xs = sublist ys N" by blast
af516ed40e72 Completely overhauled
nipkow
parents: 30738
diff changeset
   254
    hence "xs = sublist (x#ys) (Suc ` N)"
af516ed40e72 Completely overhauled
nipkow
parents: 30738
diff changeset
   255
      by (clarsimp simp add:sublist_Cons inj_image_mem_iff)
af516ed40e72 Completely overhauled
nipkow
parents: 30738
diff changeset
   256
    thus ?case by blast
af516ed40e72 Completely overhauled
nipkow
parents: 30738
diff changeset
   257
  next
49084
e3973567ed4f base Sublist_Order on Sublist (using a simplified form of embedding as sublist relation)
Christian Sternagel
parents: 37765
diff changeset
   258
    case (take x y xs ys)
33431
af516ed40e72 Completely overhauled
nipkow
parents: 30738
diff changeset
   259
    then obtain N where "xs = sublist ys N" by blast
af516ed40e72 Completely overhauled
nipkow
parents: 30738
diff changeset
   260
    hence "x#xs = sublist (x#ys) (insert 0 (Suc ` N))"
af516ed40e72 Completely overhauled
nipkow
parents: 30738
diff changeset
   261
      by (clarsimp simp add:sublist_Cons inj_image_mem_iff)
49084
e3973567ed4f base Sublist_Order on Sublist (using a simplified form of embedding as sublist relation)
Christian Sternagel
parents: 37765
diff changeset
   262
    thus ?case unfolding `x = y` by blast
33431
af516ed40e72 Completely overhauled
nipkow
parents: 30738
diff changeset
   263
  qed
af516ed40e72 Completely overhauled
nipkow
parents: 30738
diff changeset
   264
next
af516ed40e72 Completely overhauled
nipkow
parents: 30738
diff changeset
   265
  assume ?R
af516ed40e72 Completely overhauled
nipkow
parents: 30738
diff changeset
   266
  then obtain N where "xs = sublist ys N" ..
af516ed40e72 Completely overhauled
nipkow
parents: 30738
diff changeset
   267
  moreover have "sublist ys N <= ys"
af516ed40e72 Completely overhauled
nipkow
parents: 30738
diff changeset
   268
  proof (induct ys arbitrary:N)
af516ed40e72 Completely overhauled
nipkow
parents: 30738
diff changeset
   269
    case Nil show ?case by simp
af516ed40e72 Completely overhauled
nipkow
parents: 30738
diff changeset
   270
  next
af516ed40e72 Completely overhauled
nipkow
parents: 30738
diff changeset
   271
    case Cons thus ?case by (auto simp add:sublist_Cons drop)
af516ed40e72 Completely overhauled
nipkow
parents: 30738
diff changeset
   272
  qed
af516ed40e72 Completely overhauled
nipkow
parents: 30738
diff changeset
   273
  ultimately show ?L by simp
af516ed40e72 Completely overhauled
nipkow
parents: 30738
diff changeset
   274
qed
26735
39be3c7e643a added theory Sublist_Order
haftmann
parents:
diff changeset
   275
39be3c7e643a added theory Sublist_Order
haftmann
parents:
diff changeset
   276
end