-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathStack.v
More file actions
64 lines (56 loc) · 1.47 KB
/
Stack.v
File metadata and controls
64 lines (56 loc) · 1.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
(*
* Module: Stack
*
* Description:
* This module defines a stack and functions that determine properties of
* stacks.
*)
(* Load Coq Standard Library modules *)
Require Import Arith.
Require Import List.
(*
* Inductive Type: stack
*
* Description:
* This type describes a stack. A stack is just a region of memory, and
* this inductive type merely ensures that the stack's lower address is
* less than its upper address and that it doesn't use the zero address.
*
* Note:
* This code is a modified version of the pair constructor from
* http://www.cis.upenn.edu/~bcpierce/sf/Lists.html#lab47.
*)
Inductive Stack : Type :=
stack : nat -> nat -> Stack.
Notation "( x , y )" := (stack x y).
(*
* Define a function to indicate that a stack is well-formed.
*)
Definition stackWellFormed (s : Stack) : Prop :=
match s with
(x,y) => (0 < x < y)
end.
(*
* Define a function that determines that all the stacks in a list are
* well formed.
*)
Fixpoint stacksWellFormed (sl : list Stack) : Prop :=
match sl with
| nil => True
| h :: t => (stackWellFormed h) /\ stacksWellFormed (t)
end.
(*
* Function: within
*
* Description:
* Determine whether a value (usually a stack pointer) falls within the stack.
*)
Definition within (n : nat) (s : Stack) : Prop :=
match s with
(x,y) => (x <= n <= y)
end.
Fixpoint Within (n : nat) (sl : list Stack) : Prop :=
match sl with
| nil => False
| h :: t => (within n h) \/ (Within n t)
end.