69145
|
1 |
theory Array_Specs
|
|
2 |
imports Main
|
|
3 |
begin
|
|
4 |
|
|
5 |
text \<open>Array Specifications\<close>
|
|
6 |
|
|
7 |
locale Array =
|
|
8 |
fixes lookup :: "'ar \<Rightarrow> nat \<Rightarrow> 'a"
|
|
9 |
fixes update :: "nat \<Rightarrow> 'a \<Rightarrow> 'ar \<Rightarrow> 'ar"
|
|
10 |
fixes len :: "'ar \<Rightarrow> nat"
|
|
11 |
fixes array :: "'a list \<Rightarrow> 'ar"
|
|
12 |
|
|
13 |
fixes list :: "'ar \<Rightarrow> 'a list"
|
|
14 |
fixes invar :: "'ar \<Rightarrow> bool"
|
|
15 |
|
|
16 |
assumes lookup: "invar ar \<Longrightarrow> n < len ar \<Longrightarrow> lookup ar n = list ar ! n"
|
|
17 |
assumes update: "invar ar \<Longrightarrow> n < len ar \<Longrightarrow> list(update n x ar) = (list ar)[n:=x]"
|
|
18 |
assumes len_array: "invar ar \<Longrightarrow> len ar = length (list ar)"
|
|
19 |
assumes array: "list (array xs) = xs"
|
|
20 |
|
|
21 |
assumes invar_update: "invar ar \<Longrightarrow> n < len ar \<Longrightarrow> invar(update n x ar)"
|
|
22 |
assumes invar_array: "invar(array xs)"
|
|
23 |
|
|
24 |
locale Array_Flex = Array +
|
|
25 |
fixes add_lo :: "'a \<Rightarrow> 'ar \<Rightarrow> 'ar"
|
|
26 |
fixes del_lo :: "'ar \<Rightarrow> 'ar"
|
|
27 |
fixes add_hi :: "'a \<Rightarrow> 'ar \<Rightarrow> 'ar"
|
|
28 |
fixes del_hi :: "'ar \<Rightarrow> 'ar"
|
|
29 |
|
|
30 |
assumes add_lo: "invar ar \<Longrightarrow> list(add_lo a ar) = a # list ar"
|
|
31 |
assumes del_lo: "invar ar \<Longrightarrow> list(del_lo ar) = tl (list ar)"
|
|
32 |
assumes add_hi: "invar ar \<Longrightarrow> list(add_hi a ar) = list ar @ [a]"
|
|
33 |
assumes del_hi: "invar ar \<Longrightarrow> list(del_hi ar) = butlast (list ar)"
|
|
34 |
|
|
35 |
assumes invar_add_lo: "invar ar \<Longrightarrow> invar (add_lo a ar)"
|
|
36 |
assumes invar_del_lo: "invar ar \<Longrightarrow> invar (del_lo ar)"
|
|
37 |
assumes invar_add_hi: "invar ar \<Longrightarrow> invar (add_hi a ar)"
|
|
38 |
assumes invar_del_hi: "invar ar \<Longrightarrow> invar (del_hi ar)"
|
|
39 |
|
|
40 |
end |