Mentions légales du service
Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
why3
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Container registry
Monitor
Service Desk
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Why3
why3
Commits
40c581c4
Commit
40c581c4
authored
14 years ago
by
Jean-Christophe Filliâtre
Browse files
Options
Downloads
Patches
Plain Diff
stdlib: more functions on arrays
parent
e3112ae1
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
modules/stdlib.mlw
+67
-3
67 additions, 3 deletions
modules/stdlib.mlw
tests/test-pgm-jcf.mlw
+6
-1
6 additions, 1 deletion
tests/test-pgm-jcf.mlw
with
73 additions
and
4 deletions
modules/stdlib.mlw
+
67
−
3
View file @
40c581c4
...
...
@@ -22,13 +22,77 @@ module Array
mutable type array 'a model t int 'a
parameter ([]) : a
:
array 'a -> i:int ->
parameter ([]) : a
:
array 'a -> i:int ->
{ 0 <= i < length a } 'a reads a { result = a[i] }
parameter ([<-]) : a
:
array 'a -> i:int -> v:'a ->
parameter ([<-]) : a
:
array 'a -> i:int -> v:'a ->
{ 0 <= i < length a } unit writes a { a = (old a)[i <- v] }
parameter length : a : array 'a -> {} int reads a { result = length a }
parameter length : a:array 'a -> {} int reads a { result = length a }
parameter make : n:int -> v:'a ->
{}
array 'a
{ length result = n and forall i:int. 0 <= i < n -> result[i] = v}
parameter append : a1:array 'a -> a2:array 'a ->
{}
array 'a
{ length result = length a1 + length a2 and
(forall i:int. 0 <= i < length a1 -> result[i] = a1[i]) and
(forall i:int. 0 <= i < length a2 -> result[length a1 + i] = a2[i]) }
(* concat : 'a array list -> 'a array *)
parameter sub : a:array 'a -> ofs:int -> len:int ->
{ 0 <= ofs and ofs + len <= length a }
array 'a
{ length result = len and
forall i:int. 0 <= i < len -> result[i] = a[ofs + i] }
parameter copy : a:array 'a ->
{}
array 'a
{ length result = length a and
forall i:int. 0 <= i < length result -> result[i] = a[i] }
parameter fill : a:array 'a -> ofs:int -> len:int -> v:'a ->
{ 0 <= ofs and ofs + len <= length a }
unit
writes a
{ (forall i:int.
(0 <= i < ofs or ofs + len <= i < length a) -> a[i] = (old a)[i]) and
(forall i:int.
ofs <= i < ofs + len -> a[i] = v) }
(* blit : 'a array -> int -> 'a array -> int -> int -> unit *)
(* to_list / of_list *)
end
module TestArray
use import int.Int
use import module Array
let test1 () =
let a1 = make 17 2 in
assert { a1[3] = 2 };
a1[3 <- 4];
assert { a1[3] = 4 };
let a2 = make 25 3 in
assert { a2[0] = 3 }; (* needed to prove a[17]=3 below *)
let a = append a1 a2 in
assert { length a = 42 };
assert { a[3] = 4 };
assert { a[17] = 3 };
()
let test2 () =
let a = make 17 True in
fill a 10 4 False;
assert { a[10] = False }
end
...
...
This diff is collapsed.
Click to expand it.
tests/test-pgm-jcf.mlw
+
6
−
1
View file @
40c581c4
module P
use import int.Int
use import module stdlib.Ref
use import module stdlib.Array
let foo () =
{}
let a = make 17 42 in
a[0]
{result=42}
parameter c : ghost int
axiom a : c = 1
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment