author | wenzelm |
Fri, 07 Aug 2020 22:28:04 +0200 | |
changeset 72118 | 84f716e72fa3 |
parent 68492 | c7e0a7bcacaf |
permissions | -rw-r--r-- |
66419
8194ed7cf2cb
separate file for priority queue interface; extended Leftist_Heap.
nipkow
parents:
diff
changeset
|
1 |
(* Author: Tobias Nipkow, Peter Lammich *) |
8194ed7cf2cb
separate file for priority queue interface; extended Leftist_Heap.
nipkow
parents:
diff
changeset
|
2 |
|
68492 | 3 |
section \<open>Priority Queue Specifications\<close> |
66419
8194ed7cf2cb
separate file for priority queue interface; extended Leftist_Heap.
nipkow
parents:
diff
changeset
|
4 |
|
68492 | 5 |
theory Priority_Queue_Specs |
66453
cc19f7ca2ed6
session-qualified theory imports: isabelle imports -U -i -d '~~/src/Benchmarks' -a;
wenzelm
parents:
66425
diff
changeset
|
6 |
imports "HOL-Library.Multiset" |
66419
8194ed7cf2cb
separate file for priority queue interface; extended Leftist_Heap.
nipkow
parents:
diff
changeset
|
7 |
begin |
8194ed7cf2cb
separate file for priority queue interface; extended Leftist_Heap.
nipkow
parents:
diff
changeset
|
8 |
|
68492 | 9 |
text \<open>Priority queue interface + specification:\<close> |
66419
8194ed7cf2cb
separate file for priority queue interface; extended Leftist_Heap.
nipkow
parents:
diff
changeset
|
10 |
|
8194ed7cf2cb
separate file for priority queue interface; extended Leftist_Heap.
nipkow
parents:
diff
changeset
|
11 |
locale Priority_Queue = |
8194ed7cf2cb
separate file for priority queue interface; extended Leftist_Heap.
nipkow
parents:
diff
changeset
|
12 |
fixes empty :: "'q" |
8194ed7cf2cb
separate file for priority queue interface; extended Leftist_Heap.
nipkow
parents:
diff
changeset
|
13 |
and is_empty :: "'q \<Rightarrow> bool" |
8194ed7cf2cb
separate file for priority queue interface; extended Leftist_Heap.
nipkow
parents:
diff
changeset
|
14 |
and insert :: "'a::linorder \<Rightarrow> 'q \<Rightarrow> 'q" |
8194ed7cf2cb
separate file for priority queue interface; extended Leftist_Heap.
nipkow
parents:
diff
changeset
|
15 |
and get_min :: "'q \<Rightarrow> 'a" |
68021 | 16 |
and del_min :: "'q \<Rightarrow> 'q" |
66419
8194ed7cf2cb
separate file for priority queue interface; extended Leftist_Heap.
nipkow
parents:
diff
changeset
|
17 |
and invar :: "'q \<Rightarrow> bool" |
8194ed7cf2cb
separate file for priority queue interface; extended Leftist_Heap.
nipkow
parents:
diff
changeset
|
18 |
and mset :: "'q \<Rightarrow> 'a multiset" |
8194ed7cf2cb
separate file for priority queue interface; extended Leftist_Heap.
nipkow
parents:
diff
changeset
|
19 |
assumes mset_empty: "mset empty = {#}" |
8194ed7cf2cb
separate file for priority queue interface; extended Leftist_Heap.
nipkow
parents:
diff
changeset
|
20 |
and is_empty: "invar q \<Longrightarrow> is_empty q = (mset q = {#})" |
8194ed7cf2cb
separate file for priority queue interface; extended Leftist_Heap.
nipkow
parents:
diff
changeset
|
21 |
and mset_insert: "invar q \<Longrightarrow> mset (insert x q) = mset q + {#x#}" |
68021 | 22 |
and mset_del_min: "invar q \<Longrightarrow> mset q \<noteq> {#} \<Longrightarrow> |
23 |
mset (del_min q) = mset q - {# get_min q #}" |
|
66419
8194ed7cf2cb
separate file for priority queue interface; extended Leftist_Heap.
nipkow
parents:
diff
changeset
|
24 |
and mset_get_min: "invar q \<Longrightarrow> mset q \<noteq> {#} \<Longrightarrow> get_min q = Min_mset (mset q)" |
8194ed7cf2cb
separate file for priority queue interface; extended Leftist_Heap.
nipkow
parents:
diff
changeset
|
25 |
and invar_empty: "invar empty" |
8194ed7cf2cb
separate file for priority queue interface; extended Leftist_Heap.
nipkow
parents:
diff
changeset
|
26 |
and invar_insert: "invar q \<Longrightarrow> invar (insert x q)" |
68021 | 27 |
and invar_del_min: "invar q \<Longrightarrow> mset q \<noteq> {#} \<Longrightarrow> invar (del_min q)" |
66419
8194ed7cf2cb
separate file for priority queue interface; extended Leftist_Heap.
nipkow
parents:
diff
changeset
|
28 |
|
66565 | 29 |
text \<open>Extend locale with \<open>merge\<close>. Need to enforce that \<open>'q\<close> is the same in both locales.\<close> |
66419
8194ed7cf2cb
separate file for priority queue interface; extended Leftist_Heap.
nipkow
parents:
diff
changeset
|
30 |
|
66565 | 31 |
locale Priority_Queue_Merge = Priority_Queue where empty = empty for empty :: 'q + |
32 |
fixes merge :: "'q \<Rightarrow> 'q \<Rightarrow> 'q" |
|
33 |
assumes mset_merge: "\<lbrakk> invar q1; invar q2 \<rbrakk> \<Longrightarrow> mset (merge q1 q2) = mset q1 + mset q2" |
|
34 |
and invar_merge: "\<lbrakk> invar q1; invar q2 \<rbrakk> \<Longrightarrow> invar (merge q1 q2)" |
|
66419
8194ed7cf2cb
separate file for priority queue interface; extended Leftist_Heap.
nipkow
parents:
diff
changeset
|
35 |
|
8194ed7cf2cb
separate file for priority queue interface; extended Leftist_Heap.
nipkow
parents:
diff
changeset
|
36 |
end |