src/HOL/Data_Structures/Set_Specs.thy
author wenzelm
Sun, 13 Dec 2020 23:11:41 +0100
changeset 72907 3883f536d84d
parent 71829 6f2663df8374
permissions -rw-r--r--
unused (see 29566b6810f7);
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
61640
44c9198f210c no CRLF
nipkow
parents: 61589
diff changeset
     1
(* Author: Tobias Nipkow *)
44c9198f210c no CRLF
nipkow
parents: 61589
diff changeset
     2
67965
aaa31cd0caef more name tuning
nipkow
parents: 67964
diff changeset
     3
section \<open>Specifications of Set ADT\<close>
61640
44c9198f210c no CRLF
nipkow
parents: 61589
diff changeset
     4
67965
aaa31cd0caef more name tuning
nipkow
parents: 67964
diff changeset
     5
theory Set_Specs
61640
44c9198f210c no CRLF
nipkow
parents: 61589
diff changeset
     6
imports List_Ins_Del
44c9198f210c no CRLF
nipkow
parents: 61589
diff changeset
     7
begin
44c9198f210c no CRLF
nipkow
parents: 61589
diff changeset
     8
67965
aaa31cd0caef more name tuning
nipkow
parents: 67964
diff changeset
     9
text \<open>The basic set interface with traditional \<open>set\<close>-based specification:\<close>
67964
08cc5ab18c84 better name; added binary operations
nipkow
parents: 67929
diff changeset
    10
61640
44c9198f210c no CRLF
nipkow
parents: 61589
diff changeset
    11
locale Set =
44c9198f210c no CRLF
nipkow
parents: 61589
diff changeset
    12
fixes empty :: "'s"
44c9198f210c no CRLF
nipkow
parents: 61589
diff changeset
    13
fixes insert :: "'a \<Rightarrow> 's \<Rightarrow> 's"
44c9198f210c no CRLF
nipkow
parents: 61589
diff changeset
    14
fixes delete :: "'a \<Rightarrow> 's \<Rightarrow> 's"
44c9198f210c no CRLF
nipkow
parents: 61589
diff changeset
    15
fixes isin :: "'s \<Rightarrow> 'a \<Rightarrow> bool"
44c9198f210c no CRLF
nipkow
parents: 61589
diff changeset
    16
fixes set :: "'s \<Rightarrow> 'a set"
44c9198f210c no CRLF
nipkow
parents: 61589
diff changeset
    17
fixes invar :: "'s \<Rightarrow> bool"
44c9198f210c no CRLF
nipkow
parents: 61589
diff changeset
    18
assumes set_empty:    "set empty = {}"
44c9198f210c no CRLF
nipkow
parents: 61589
diff changeset
    19
assumes set_isin:     "invar s \<Longrightarrow> isin s x = (x \<in> set s)"
70584
nipkow
parents: 68492
diff changeset
    20
assumes set_insert:   "invar s \<Longrightarrow> set(insert x s) = set s \<union> {x}"
61640
44c9198f210c no CRLF
nipkow
parents: 61589
diff changeset
    21
assumes set_delete:   "invar s \<Longrightarrow> set(delete x s) = set s - {x}"
44c9198f210c no CRLF
nipkow
parents: 61589
diff changeset
    22
assumes invar_empty:  "invar empty"
44c9198f210c no CRLF
nipkow
parents: 61589
diff changeset
    23
assumes invar_insert: "invar s \<Longrightarrow> invar(insert x s)"
44c9198f210c no CRLF
nipkow
parents: 61589
diff changeset
    24
assumes invar_delete: "invar s \<Longrightarrow> invar(delete x s)"
44c9198f210c no CRLF
nipkow
parents: 61589
diff changeset
    25
68492
c7e0a7bcacaf added lemmas; uniform names
nipkow
parents: 68440
diff changeset
    26
lemmas (in Set) set_specs =
c7e0a7bcacaf added lemmas; uniform names
nipkow
parents: 68440
diff changeset
    27
  set_empty set_isin set_insert set_delete invar_empty invar_insert invar_delete
67964
08cc5ab18c84 better name; added binary operations
nipkow
parents: 67929
diff changeset
    28
08cc5ab18c84 better name; added binary operations
nipkow
parents: 67929
diff changeset
    29
text \<open>The basic set interface with \<open>inorder\<close>-based specification:\<close>
08cc5ab18c84 better name; added binary operations
nipkow
parents: 67929
diff changeset
    30
61640
44c9198f210c no CRLF
nipkow
parents: 61589
diff changeset
    31
locale Set_by_Ordered =
44c9198f210c no CRLF
nipkow
parents: 61589
diff changeset
    32
fixes empty :: "'t"
44c9198f210c no CRLF
nipkow
parents: 61589
diff changeset
    33
fixes insert :: "'a::linorder \<Rightarrow> 't \<Rightarrow> 't"
44c9198f210c no CRLF
nipkow
parents: 61589
diff changeset
    34
fixes delete :: "'a \<Rightarrow> 't \<Rightarrow> 't"
44c9198f210c no CRLF
nipkow
parents: 61589
diff changeset
    35
fixes isin :: "'t \<Rightarrow> 'a \<Rightarrow> bool"
44c9198f210c no CRLF
nipkow
parents: 61589
diff changeset
    36
fixes inorder :: "'t \<Rightarrow> 'a list"
44c9198f210c no CRLF
nipkow
parents: 61589
diff changeset
    37
fixes inv :: "'t \<Rightarrow> bool"
68440
6826718f732d qualify interpretations to avoid clashes
nipkow
parents: 68439
diff changeset
    38
assumes inorder_empty: "inorder empty = []"
61640
44c9198f210c no CRLF
nipkow
parents: 61589
diff changeset
    39
assumes isin: "inv t \<and> sorted(inorder t) \<Longrightarrow>
67929
30486b96274d eliminated "elems"
nipkow
parents: 67406
diff changeset
    40
  isin t x = (x \<in> set (inorder t))"
68440
6826718f732d qualify interpretations to avoid clashes
nipkow
parents: 68439
diff changeset
    41
assumes inorder_insert: "inv t \<and> sorted(inorder t) \<Longrightarrow>
61640
44c9198f210c no CRLF
nipkow
parents: 61589
diff changeset
    42
  inorder(insert x t) = ins_list x (inorder t)"
68440
6826718f732d qualify interpretations to avoid clashes
nipkow
parents: 68439
diff changeset
    43
assumes inorder_delete: "inv t \<and> sorted(inorder t) \<Longrightarrow>
61640
44c9198f210c no CRLF
nipkow
parents: 61589
diff changeset
    44
  inorder(delete x t) = del_list x (inorder t)"
68440
6826718f732d qualify interpretations to avoid clashes
nipkow
parents: 68439
diff changeset
    45
assumes inorder_inv_empty:  "inv empty"
6826718f732d qualify interpretations to avoid clashes
nipkow
parents: 68439
diff changeset
    46
assumes inorder_inv_insert: "inv t \<and> sorted(inorder t) \<Longrightarrow> inv(insert x t)"
6826718f732d qualify interpretations to avoid clashes
nipkow
parents: 68439
diff changeset
    47
assumes inorder_inv_delete: "inv t \<and> sorted(inorder t) \<Longrightarrow> inv(delete x t)"
68492
c7e0a7bcacaf added lemmas; uniform names
nipkow
parents: 68440
diff changeset
    48
61640
44c9198f210c no CRLF
nipkow
parents: 61589
diff changeset
    49
begin
44c9198f210c no CRLF
nipkow
parents: 61589
diff changeset
    50
67964
08cc5ab18c84 better name; added binary operations
nipkow
parents: 67929
diff changeset
    51
text \<open>It implements the traditional specification:\<close>
08cc5ab18c84 better name; added binary operations
nipkow
parents: 67929
diff changeset
    52
68439
c8101022e52a more abstract names
nipkow
parents: 67965
diff changeset
    53
definition set :: "'t \<Rightarrow> 'a set" where
71829
6f2663df8374 "app" -> "join" for uniformity with Join theory; tuned defs
nipkow
parents: 70631
diff changeset
    54
"set = List.set o inorder"
68439
c8101022e52a more abstract names
nipkow
parents: 67965
diff changeset
    55
c8101022e52a more abstract names
nipkow
parents: 67965
diff changeset
    56
definition invar :: "'t \<Rightarrow> bool" where
71829
6f2663df8374 "app" -> "join" for uniformity with Join theory; tuned defs
nipkow
parents: 70631
diff changeset
    57
"invar t = (inv t \<and> sorted (inorder t))"
68439
c8101022e52a more abstract names
nipkow
parents: 67965
diff changeset
    58
61640
44c9198f210c no CRLF
nipkow
parents: 61589
diff changeset
    59
sublocale Set
68439
c8101022e52a more abstract names
nipkow
parents: 67965
diff changeset
    60
  empty insert delete isin set invar
61640
44c9198f210c no CRLF
nipkow
parents: 61589
diff changeset
    61
proof(standard, goal_cases)
68440
6826718f732d qualify interpretations to avoid clashes
nipkow
parents: 68439
diff changeset
    62
  case 1 show ?case by (auto simp: inorder_empty set_def)
61640
44c9198f210c no CRLF
nipkow
parents: 61589
diff changeset
    63
next
68439
c8101022e52a more abstract names
nipkow
parents: 67965
diff changeset
    64
  case 2 thus ?case by(simp add: isin invar_def set_def)
61640
44c9198f210c no CRLF
nipkow
parents: 61589
diff changeset
    65
next
68440
6826718f732d qualify interpretations to avoid clashes
nipkow
parents: 68439
diff changeset
    66
  case 3 thus ?case by(simp add: inorder_insert set_ins_list set_def invar_def)
61640
44c9198f210c no CRLF
nipkow
parents: 61589
diff changeset
    67
next
44c9198f210c no CRLF
nipkow
parents: 61589
diff changeset
    68
  case (4 s x) thus ?case
70631
f14b997da756 simplified proofs
nipkow
parents: 70584
diff changeset
    69
    by (auto simp: inorder_delete set_del_list invar_def set_def)
61640
44c9198f210c no CRLF
nipkow
parents: 61589
diff changeset
    70
next
68440
6826718f732d qualify interpretations to avoid clashes
nipkow
parents: 68439
diff changeset
    71
  case 5 thus ?case by(simp add: inorder_empty inorder_inv_empty invar_def)
61640
44c9198f210c no CRLF
nipkow
parents: 61589
diff changeset
    72
next
68440
6826718f732d qualify interpretations to avoid clashes
nipkow
parents: 68439
diff changeset
    73
  case 6 thus ?case by(simp add: inorder_insert inorder_inv_insert sorted_ins_list invar_def)
61640
44c9198f210c no CRLF
nipkow
parents: 61589
diff changeset
    74
next
68440
6826718f732d qualify interpretations to avoid clashes
nipkow
parents: 68439
diff changeset
    75
  case 7 thus ?case by (auto simp: inorder_delete inorder_inv_delete sorted_del_list invar_def)
61640
44c9198f210c no CRLF
nipkow
parents: 61589
diff changeset
    76
qed
44c9198f210c no CRLF
nipkow
parents: 61589
diff changeset
    77
44c9198f210c no CRLF
nipkow
parents: 61589
diff changeset
    78
end
44c9198f210c no CRLF
nipkow
parents: 61589
diff changeset
    79
67964
08cc5ab18c84 better name; added binary operations
nipkow
parents: 67929
diff changeset
    80
08cc5ab18c84 better name; added binary operations
nipkow
parents: 67929
diff changeset
    81
text \<open>Set2 = Set with binary operations:\<close>
08cc5ab18c84 better name; added binary operations
nipkow
parents: 67929
diff changeset
    82
08cc5ab18c84 better name; added binary operations
nipkow
parents: 67929
diff changeset
    83
locale Set2 = Set
08cc5ab18c84 better name; added binary operations
nipkow
parents: 67929
diff changeset
    84
  where insert = insert for insert :: "'a \<Rightarrow> 's \<Rightarrow> 's" (*for typing purposes only*) +
08cc5ab18c84 better name; added binary operations
nipkow
parents: 67929
diff changeset
    85
fixes union :: "'s \<Rightarrow> 's \<Rightarrow> 's"
08cc5ab18c84 better name; added binary operations
nipkow
parents: 67929
diff changeset
    86
fixes inter :: "'s \<Rightarrow> 's \<Rightarrow> 's"
08cc5ab18c84 better name; added binary operations
nipkow
parents: 67929
diff changeset
    87
fixes diff  :: "'s \<Rightarrow> 's \<Rightarrow> 's"
08cc5ab18c84 better name; added binary operations
nipkow
parents: 67929
diff changeset
    88
assumes set_union:   "\<lbrakk> invar s1; invar s2 \<rbrakk> \<Longrightarrow> set(union s1 s2) = set s1 \<union> set s2"
08cc5ab18c84 better name; added binary operations
nipkow
parents: 67929
diff changeset
    89
assumes set_inter:   "\<lbrakk> invar s1; invar s2 \<rbrakk> \<Longrightarrow> set(inter s1 s2) = set s1 \<inter> set s2"
08cc5ab18c84 better name; added binary operations
nipkow
parents: 67929
diff changeset
    90
assumes set_diff:   "\<lbrakk> invar s1; invar s2 \<rbrakk> \<Longrightarrow> set(diff s1 s2) = set s1 - set s2"
08cc5ab18c84 better name; added binary operations
nipkow
parents: 67929
diff changeset
    91
assumes invar_union:   "\<lbrakk> invar s1; invar s2 \<rbrakk> \<Longrightarrow> invar(union s1 s2)"
08cc5ab18c84 better name; added binary operations
nipkow
parents: 67929
diff changeset
    92
assumes invar_inter:   "\<lbrakk> invar s1; invar s2 \<rbrakk> \<Longrightarrow> invar(inter s1 s2)"
08cc5ab18c84 better name; added binary operations
nipkow
parents: 67929
diff changeset
    93
assumes invar_diff:   "\<lbrakk> invar s1; invar s2 \<rbrakk> \<Longrightarrow> invar(diff s1 s2)"
08cc5ab18c84 better name; added binary operations
nipkow
parents: 67929
diff changeset
    94
61640
44c9198f210c no CRLF
nipkow
parents: 61589
diff changeset
    95
end