src/HOL/Data_Structures/Sorted_Less.thy
author nipkow
Wed, 16 Aug 2017 21:14:11 +0200
changeset 66441 b9468503742a
parent 61696 ce6320b9ef9b
child 67399 eab6ce8368fa
permissions -rw-r--r--
more reorganization around sorted_wrt
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
61640
44c9198f210c no CRLF
nipkow
parents: 61203
diff changeset
     1
(* Author: Tobias Nipkow *)
44c9198f210c no CRLF
nipkow
parents: 61203
diff changeset
     2
44c9198f210c no CRLF
nipkow
parents: 61203
diff changeset
     3
section {* Lists Sorted wrt $<$ *}
44c9198f210c no CRLF
nipkow
parents: 61203
diff changeset
     4
44c9198f210c no CRLF
nipkow
parents: 61203
diff changeset
     5
theory Sorted_Less
44c9198f210c no CRLF
nipkow
parents: 61203
diff changeset
     6
imports Less_False
44c9198f210c no CRLF
nipkow
parents: 61203
diff changeset
     7
begin
44c9198f210c no CRLF
nipkow
parents: 61203
diff changeset
     8
44c9198f210c no CRLF
nipkow
parents: 61203
diff changeset
     9
hide_const sorted
44c9198f210c no CRLF
nipkow
parents: 61203
diff changeset
    10
44c9198f210c no CRLF
nipkow
parents: 61203
diff changeset
    11
text \<open>Is a list sorted without duplicates, i.e., wrt @{text"<"}?
44c9198f210c no CRLF
nipkow
parents: 61203
diff changeset
    12
Could go into theory List under a name like @{term sorted_less}.\<close>
44c9198f210c no CRLF
nipkow
parents: 61203
diff changeset
    13
66441
b9468503742a more reorganization around sorted_wrt
nipkow
parents: 61696
diff changeset
    14
abbreviation sorted :: "'a::linorder list \<Rightarrow> bool" where
b9468503742a more reorganization around sorted_wrt
nipkow
parents: 61696
diff changeset
    15
"sorted \<equiv> sorted_wrt (op <)"
61640
44c9198f210c no CRLF
nipkow
parents: 61203
diff changeset
    16
44c9198f210c no CRLF
nipkow
parents: 61203
diff changeset
    17
lemma sorted_cons: "sorted (x#xs) \<Longrightarrow> sorted xs"
66441
b9468503742a more reorganization around sorted_wrt
nipkow
parents: 61696
diff changeset
    18
by(simp add: sorted_wrt_Cons)
61640
44c9198f210c no CRLF
nipkow
parents: 61203
diff changeset
    19
44c9198f210c no CRLF
nipkow
parents: 61203
diff changeset
    20
lemma sorted_cons': "ASSUMPTION (sorted (x#xs)) \<Longrightarrow> sorted xs"
44c9198f210c no CRLF
nipkow
parents: 61203
diff changeset
    21
by(rule ASSUMPTION_D [THEN sorted_cons])
44c9198f210c no CRLF
nipkow
parents: 61203
diff changeset
    22
44c9198f210c no CRLF
nipkow
parents: 61203
diff changeset
    23
lemma sorted_snoc: "sorted (xs @ [y]) \<Longrightarrow> sorted xs"
66441
b9468503742a more reorganization around sorted_wrt
nipkow
parents: 61696
diff changeset
    24
by(simp add: sorted_wrt_append)
61640
44c9198f210c no CRLF
nipkow
parents: 61203
diff changeset
    25
44c9198f210c no CRLF
nipkow
parents: 61203
diff changeset
    26
lemma sorted_snoc': "ASSUMPTION (sorted (xs @ [y])) \<Longrightarrow> sorted xs"
44c9198f210c no CRLF
nipkow
parents: 61203
diff changeset
    27
by(rule ASSUMPTION_D [THEN sorted_snoc])
44c9198f210c no CRLF
nipkow
parents: 61203
diff changeset
    28
44c9198f210c no CRLF
nipkow
parents: 61203
diff changeset
    29
lemma sorted_mid_iff:
44c9198f210c no CRLF
nipkow
parents: 61203
diff changeset
    30
  "sorted(xs @ y # ys) = (sorted(xs @ [y]) \<and> sorted(y # ys))"
66441
b9468503742a more reorganization around sorted_wrt
nipkow
parents: 61696
diff changeset
    31
by(fastforce simp add: sorted_wrt_Cons sorted_wrt_append)
61640
44c9198f210c no CRLF
nipkow
parents: 61203
diff changeset
    32
44c9198f210c no CRLF
nipkow
parents: 61203
diff changeset
    33
lemma sorted_mid_iff2:
44c9198f210c no CRLF
nipkow
parents: 61203
diff changeset
    34
  "sorted(x # xs @ y # ys) =
44c9198f210c no CRLF
nipkow
parents: 61203
diff changeset
    35
  (sorted(x # xs) \<and> x < y \<and> sorted(xs @ [y]) \<and> sorted(y # ys))"
66441
b9468503742a more reorganization around sorted_wrt
nipkow
parents: 61696
diff changeset
    36
by(fastforce simp add: sorted_wrt_Cons sorted_wrt_append)
61640
44c9198f210c no CRLF
nipkow
parents: 61203
diff changeset
    37
44c9198f210c no CRLF
nipkow
parents: 61203
diff changeset
    38
lemma sorted_mid_iff': "NO_MATCH [] ys \<Longrightarrow>
44c9198f210c no CRLF
nipkow
parents: 61203
diff changeset
    39
  sorted(xs @ y # ys) = (sorted(xs @ [y]) \<and> sorted(y # ys))"
44c9198f210c no CRLF
nipkow
parents: 61203
diff changeset
    40
by(rule sorted_mid_iff)
44c9198f210c no CRLF
nipkow
parents: 61203
diff changeset
    41
44c9198f210c no CRLF
nipkow
parents: 61203
diff changeset
    42
lemmas sorted_lems = sorted_mid_iff' sorted_mid_iff2 sorted_cons' sorted_snoc'
44c9198f210c no CRLF
nipkow
parents: 61203
diff changeset
    43
61696
ce6320b9ef9b moved lemmas
nipkow
parents: 61640
diff changeset
    44
text\<open>Splay trees need two additional @{const sorted} lemmas:\<close>
ce6320b9ef9b moved lemmas
nipkow
parents: 61640
diff changeset
    45
ce6320b9ef9b moved lemmas
nipkow
parents: 61640
diff changeset
    46
lemma sorted_snoc_le:
ce6320b9ef9b moved lemmas
nipkow
parents: 61640
diff changeset
    47
  "ASSUMPTION(sorted(xs @ [x])) \<Longrightarrow> x \<le> y \<Longrightarrow> sorted (xs @ [y])"
66441
b9468503742a more reorganization around sorted_wrt
nipkow
parents: 61696
diff changeset
    48
by (auto simp add: sorted_wrt_append ASSUMPTION_def)
61696
ce6320b9ef9b moved lemmas
nipkow
parents: 61640
diff changeset
    49
ce6320b9ef9b moved lemmas
nipkow
parents: 61640
diff changeset
    50
lemma sorted_Cons_le:
ce6320b9ef9b moved lemmas
nipkow
parents: 61640
diff changeset
    51
  "ASSUMPTION(sorted(x # xs)) \<Longrightarrow> y \<le> x \<Longrightarrow> sorted (y # xs)"
66441
b9468503742a more reorganization around sorted_wrt
nipkow
parents: 61696
diff changeset
    52
by (auto simp add: sorted_wrt_Cons ASSUMPTION_def)
61696
ce6320b9ef9b moved lemmas
nipkow
parents: 61640
diff changeset
    53
61640
44c9198f210c no CRLF
nipkow
parents: 61203
diff changeset
    54
end