src/HOL/Data_Structures/Set_by_Ordered.thy
author nipkow
Mon, 21 Sep 2015 14:44:32 +0200
changeset 61203 a8a8eca85801
child 61428 5e1938107371
permissions -rw-r--r--
New subdirectory for functional data structures
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
61203
a8a8eca85801 New subdirectory for functional data structures
nipkow
parents:
diff changeset
     1
(* Author: Tobias Nipkow *)
a8a8eca85801 New subdirectory for functional data structures
nipkow
parents:
diff changeset
     2
a8a8eca85801 New subdirectory for functional data structures
nipkow
parents:
diff changeset
     3
section {* Implementing Ordered Sets *}
a8a8eca85801 New subdirectory for functional data structures
nipkow
parents:
diff changeset
     4
a8a8eca85801 New subdirectory for functional data structures
nipkow
parents:
diff changeset
     5
theory Set_by_Ordered
a8a8eca85801 New subdirectory for functional data structures
nipkow
parents:
diff changeset
     6
imports List_Ins_Del
a8a8eca85801 New subdirectory for functional data structures
nipkow
parents:
diff changeset
     7
begin
a8a8eca85801 New subdirectory for functional data structures
nipkow
parents:
diff changeset
     8
a8a8eca85801 New subdirectory for functional data structures
nipkow
parents:
diff changeset
     9
locale Set =
a8a8eca85801 New subdirectory for functional data structures
nipkow
parents:
diff changeset
    10
fixes empty :: "'s"
a8a8eca85801 New subdirectory for functional data structures
nipkow
parents:
diff changeset
    11
fixes insert :: "'a \<Rightarrow> 's \<Rightarrow> 's"
a8a8eca85801 New subdirectory for functional data structures
nipkow
parents:
diff changeset
    12
fixes delete :: "'a \<Rightarrow> 's \<Rightarrow> 's"
a8a8eca85801 New subdirectory for functional data structures
nipkow
parents:
diff changeset
    13
fixes isin :: "'s \<Rightarrow> 'a \<Rightarrow> bool"
a8a8eca85801 New subdirectory for functional data structures
nipkow
parents:
diff changeset
    14
fixes set :: "'s \<Rightarrow> 'a set"
a8a8eca85801 New subdirectory for functional data structures
nipkow
parents:
diff changeset
    15
fixes invar :: "'s \<Rightarrow> bool"
a8a8eca85801 New subdirectory for functional data structures
nipkow
parents:
diff changeset
    16
assumes "set empty = {}"
a8a8eca85801 New subdirectory for functional data structures
nipkow
parents:
diff changeset
    17
assumes "invar s \<Longrightarrow> isin s a = (a \<in> set s)"
a8a8eca85801 New subdirectory for functional data structures
nipkow
parents:
diff changeset
    18
assumes "invar s \<Longrightarrow> set(insert a s) = Set.insert a (set s)"
a8a8eca85801 New subdirectory for functional data structures
nipkow
parents:
diff changeset
    19
assumes "invar s \<Longrightarrow> set(delete a s) = set s - {a}"
a8a8eca85801 New subdirectory for functional data structures
nipkow
parents:
diff changeset
    20
assumes "invar s \<Longrightarrow> invar(insert a s)"
a8a8eca85801 New subdirectory for functional data structures
nipkow
parents:
diff changeset
    21
assumes "invar s \<Longrightarrow> invar(delete a s)"
a8a8eca85801 New subdirectory for functional data structures
nipkow
parents:
diff changeset
    22
a8a8eca85801 New subdirectory for functional data structures
nipkow
parents:
diff changeset
    23
locale Set_by_Ordered =
a8a8eca85801 New subdirectory for functional data structures
nipkow
parents:
diff changeset
    24
fixes empty :: "'t"
a8a8eca85801 New subdirectory for functional data structures
nipkow
parents:
diff changeset
    25
fixes insert :: "'a::linorder \<Rightarrow> 't \<Rightarrow> 't"
a8a8eca85801 New subdirectory for functional data structures
nipkow
parents:
diff changeset
    26
fixes delete :: "'a \<Rightarrow> 't \<Rightarrow> 't"
a8a8eca85801 New subdirectory for functional data structures
nipkow
parents:
diff changeset
    27
fixes isin :: "'t \<Rightarrow> 'a \<Rightarrow> bool"
a8a8eca85801 New subdirectory for functional data structures
nipkow
parents:
diff changeset
    28
fixes inorder :: "'t \<Rightarrow> 'a list"
a8a8eca85801 New subdirectory for functional data structures
nipkow
parents:
diff changeset
    29
fixes wf :: "'t \<Rightarrow> bool"
a8a8eca85801 New subdirectory for functional data structures
nipkow
parents:
diff changeset
    30
assumes empty: "inorder empty = []"
a8a8eca85801 New subdirectory for functional data structures
nipkow
parents:
diff changeset
    31
assumes isin: "wf t \<and> sorted(inorder t) \<Longrightarrow>
a8a8eca85801 New subdirectory for functional data structures
nipkow
parents:
diff changeset
    32
  isin t a = (a \<in> elems (inorder t))"
a8a8eca85801 New subdirectory for functional data structures
nipkow
parents:
diff changeset
    33
assumes insert: "wf t \<and> sorted(inorder t) \<Longrightarrow>
a8a8eca85801 New subdirectory for functional data structures
nipkow
parents:
diff changeset
    34
  inorder(insert a t) = ins_list a (inorder t)"
a8a8eca85801 New subdirectory for functional data structures
nipkow
parents:
diff changeset
    35
assumes delete: "wf t \<and> sorted(inorder t) \<Longrightarrow>
a8a8eca85801 New subdirectory for functional data structures
nipkow
parents:
diff changeset
    36
  inorder(delete a t) = del_list a (inorder t)"
a8a8eca85801 New subdirectory for functional data structures
nipkow
parents:
diff changeset
    37
assumes wf_insert: "wf t \<and> sorted(inorder t) \<Longrightarrow> wf(insert a t)"
a8a8eca85801 New subdirectory for functional data structures
nipkow
parents:
diff changeset
    38
assumes wf_delete: "wf t \<and> sorted(inorder t) \<Longrightarrow> wf(delete a t)"
a8a8eca85801 New subdirectory for functional data structures
nipkow
parents:
diff changeset
    39
begin
a8a8eca85801 New subdirectory for functional data structures
nipkow
parents:
diff changeset
    40
a8a8eca85801 New subdirectory for functional data structures
nipkow
parents:
diff changeset
    41
sublocale Set
a8a8eca85801 New subdirectory for functional data structures
nipkow
parents:
diff changeset
    42
  empty insert delete isin "elems o inorder" "\<lambda>t. wf t \<and> sorted(inorder t)"
a8a8eca85801 New subdirectory for functional data structures
nipkow
parents:
diff changeset
    43
proof(standard, goal_cases)
a8a8eca85801 New subdirectory for functional data structures
nipkow
parents:
diff changeset
    44
  case 1 show ?case by (auto simp: empty)
a8a8eca85801 New subdirectory for functional data structures
nipkow
parents:
diff changeset
    45
next
a8a8eca85801 New subdirectory for functional data structures
nipkow
parents:
diff changeset
    46
  case 2 thus ?case by(simp add: isin)
a8a8eca85801 New subdirectory for functional data structures
nipkow
parents:
diff changeset
    47
next
a8a8eca85801 New subdirectory for functional data structures
nipkow
parents:
diff changeset
    48
  case 3 thus ?case by(simp add: insert)
a8a8eca85801 New subdirectory for functional data structures
nipkow
parents:
diff changeset
    49
next
a8a8eca85801 New subdirectory for functional data structures
nipkow
parents:
diff changeset
    50
  case (4 s a) show ?case
a8a8eca85801 New subdirectory for functional data structures
nipkow
parents:
diff changeset
    51
    using delete[OF 4, of a] 4 by (auto simp: distinct_if_sorted)
a8a8eca85801 New subdirectory for functional data structures
nipkow
parents:
diff changeset
    52
next
a8a8eca85801 New subdirectory for functional data structures
nipkow
parents:
diff changeset
    53
  case 5 thus ?case by(simp add: insert wf_insert sorted_ins_list)
a8a8eca85801 New subdirectory for functional data structures
nipkow
parents:
diff changeset
    54
next
a8a8eca85801 New subdirectory for functional data structures
nipkow
parents:
diff changeset
    55
  case 6 thus ?case by (auto simp: delete wf_delete sorted_del_list)
a8a8eca85801 New subdirectory for functional data structures
nipkow
parents:
diff changeset
    56
qed
a8a8eca85801 New subdirectory for functional data structures
nipkow
parents:
diff changeset
    57
a8a8eca85801 New subdirectory for functional data structures
nipkow
parents:
diff changeset
    58
end
a8a8eca85801 New subdirectory for functional data structures
nipkow
parents:
diff changeset
    59
a8a8eca85801 New subdirectory for functional data structures
nipkow
parents:
diff changeset
    60
end