src/HOL/Data_Structures/Sorted_Less.thy
author wenzelm
Sat, 28 Nov 2020 15:15:53 +0100
changeset 72755 8dffbe01a3e1
parent 69597 ff784d5a5bfb
child 76749 11a24dab1880
permissions -rw-r--r--
support for Scala compile-time positions;
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
67406
23307fd33906 isabelle update_cartouches -c;
wenzelm
parents: 67399
diff changeset
     3
section \<open>Lists Sorted wrt $<$\<close>
61640
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
69505
cc2d676d5395 isabelle update_cartouches -t;
wenzelm
parents: 68125
diff changeset
    11
text \<open>Is a list sorted without duplicates, i.e., wrt \<open><\<close>?.\<close>
61640
44c9198f210c no CRLF
nipkow
parents: 61203
diff changeset
    12
66441
b9468503742a more reorganization around sorted_wrt
nipkow
parents: 61696
diff changeset
    13
abbreviation sorted :: "'a::linorder list \<Rightarrow> bool" where
67399
eab6ce8368fa ran isabelle update_op on all sources
nipkow
parents: 66441
diff changeset
    14
"sorted \<equiv> sorted_wrt (<)"
61640
44c9198f210c no CRLF
nipkow
parents: 61203
diff changeset
    15
68125
2e5b737810a6 announce sorted changes
nipkow
parents: 68109
diff changeset
    16
lemmas sorted_wrt_Cons = sorted_wrt.simps(2)
2e5b737810a6 announce sorted changes
nipkow
parents: 68109
diff changeset
    17
69597
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 69505
diff changeset
    18
text \<open>The definition of \<^const>\<open>sorted_wrt\<close> relates each element to all the elements after it.
68109
cebf36c14226 new def of sorted and sorted_wrt
nipkow
parents: 67406
diff changeset
    19
This causes a blowup of the formulas. Thus we simplify matters by only comparing adjacent elements.\<close>
cebf36c14226 new def of sorted and sorted_wrt
nipkow
parents: 67406
diff changeset
    20
68125
2e5b737810a6 announce sorted changes
nipkow
parents: 68109
diff changeset
    21
declare
2e5b737810a6 announce sorted changes
nipkow
parents: 68109
diff changeset
    22
  sorted_wrt.simps(2)[simp del]
2e5b737810a6 announce sorted changes
nipkow
parents: 68109
diff changeset
    23
  sorted_wrt1[simp] sorted_wrt2[OF transp_less, simp]
68109
cebf36c14226 new def of sorted and sorted_wrt
nipkow
parents: 67406
diff changeset
    24
61640
44c9198f210c no CRLF
nipkow
parents: 61203
diff changeset
    25
lemma sorted_cons: "sorted (x#xs) \<Longrightarrow> sorted xs"
66441
b9468503742a more reorganization around sorted_wrt
nipkow
parents: 61696
diff changeset
    26
by(simp add: sorted_wrt_Cons)
61640
44c9198f210c no CRLF
nipkow
parents: 61203
diff changeset
    27
44c9198f210c no CRLF
nipkow
parents: 61203
diff changeset
    28
lemma sorted_cons': "ASSUMPTION (sorted (x#xs)) \<Longrightarrow> sorted xs"
44c9198f210c no CRLF
nipkow
parents: 61203
diff changeset
    29
by(rule ASSUMPTION_D [THEN sorted_cons])
44c9198f210c no CRLF
nipkow
parents: 61203
diff changeset
    30
44c9198f210c no CRLF
nipkow
parents: 61203
diff changeset
    31
lemma sorted_snoc: "sorted (xs @ [y]) \<Longrightarrow> sorted xs"
66441
b9468503742a more reorganization around sorted_wrt
nipkow
parents: 61696
diff changeset
    32
by(simp add: sorted_wrt_append)
61640
44c9198f210c no CRLF
nipkow
parents: 61203
diff changeset
    33
44c9198f210c no CRLF
nipkow
parents: 61203
diff changeset
    34
lemma sorted_snoc': "ASSUMPTION (sorted (xs @ [y])) \<Longrightarrow> sorted xs"
44c9198f210c no CRLF
nipkow
parents: 61203
diff changeset
    35
by(rule ASSUMPTION_D [THEN sorted_snoc])
44c9198f210c no CRLF
nipkow
parents: 61203
diff changeset
    36
44c9198f210c no CRLF
nipkow
parents: 61203
diff changeset
    37
lemma sorted_mid_iff:
44c9198f210c no CRLF
nipkow
parents: 61203
diff changeset
    38
  "sorted(xs @ y # ys) = (sorted(xs @ [y]) \<and> sorted(y # ys))"
66441
b9468503742a more reorganization around sorted_wrt
nipkow
parents: 61696
diff changeset
    39
by(fastforce simp add: sorted_wrt_Cons sorted_wrt_append)
61640
44c9198f210c no CRLF
nipkow
parents: 61203
diff changeset
    40
44c9198f210c no CRLF
nipkow
parents: 61203
diff changeset
    41
lemma sorted_mid_iff2:
44c9198f210c no CRLF
nipkow
parents: 61203
diff changeset
    42
  "sorted(x # xs @ y # ys) =
44c9198f210c no CRLF
nipkow
parents: 61203
diff changeset
    43
  (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
    44
by(fastforce simp add: sorted_wrt_Cons sorted_wrt_append)
61640
44c9198f210c no CRLF
nipkow
parents: 61203
diff changeset
    45
44c9198f210c no CRLF
nipkow
parents: 61203
diff changeset
    46
lemma sorted_mid_iff': "NO_MATCH [] ys \<Longrightarrow>
44c9198f210c no CRLF
nipkow
parents: 61203
diff changeset
    47
  sorted(xs @ y # ys) = (sorted(xs @ [y]) \<and> sorted(y # ys))"
44c9198f210c no CRLF
nipkow
parents: 61203
diff changeset
    48
by(rule sorted_mid_iff)
44c9198f210c no CRLF
nipkow
parents: 61203
diff changeset
    49
44c9198f210c no CRLF
nipkow
parents: 61203
diff changeset
    50
lemmas sorted_lems = sorted_mid_iff' sorted_mid_iff2 sorted_cons' sorted_snoc'
44c9198f210c no CRLF
nipkow
parents: 61203
diff changeset
    51
69597
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 69505
diff changeset
    52
text\<open>Splay trees need two additional \<^const>\<open>sorted\<close> lemmas:\<close>
61696
ce6320b9ef9b moved lemmas
nipkow
parents: 61640
diff changeset
    53
ce6320b9ef9b moved lemmas
nipkow
parents: 61640
diff changeset
    54
lemma sorted_snoc_le:
ce6320b9ef9b moved lemmas
nipkow
parents: 61640
diff changeset
    55
  "ASSUMPTION(sorted(xs @ [x])) \<Longrightarrow> x \<le> y \<Longrightarrow> sorted (xs @ [y])"
66441
b9468503742a more reorganization around sorted_wrt
nipkow
parents: 61696
diff changeset
    56
by (auto simp add: sorted_wrt_append ASSUMPTION_def)
61696
ce6320b9ef9b moved lemmas
nipkow
parents: 61640
diff changeset
    57
ce6320b9ef9b moved lemmas
nipkow
parents: 61640
diff changeset
    58
lemma sorted_Cons_le:
ce6320b9ef9b moved lemmas
nipkow
parents: 61640
diff changeset
    59
  "ASSUMPTION(sorted(x # xs)) \<Longrightarrow> y \<le> x \<Longrightarrow> sorted (y # xs)"
66441
b9468503742a more reorganization around sorted_wrt
nipkow
parents: 61696
diff changeset
    60
by (auto simp add: sorted_wrt_Cons ASSUMPTION_def)
61696
ce6320b9ef9b moved lemmas
nipkow
parents: 61640
diff changeset
    61
61640
44c9198f210c no CRLF
nipkow
parents: 61203
diff changeset
    62
end