File tree Expand file tree Collapse file tree 2 files changed +31
-1
lines changed Expand file tree Collapse file tree 2 files changed +31
-1
lines changed Original file line number Diff line number Diff line change
1
+ Require Import Coq.Arith.Arith.
2
+ Require Import RGref.DSL.DSL.
3
+
4
+ (** * A Strictly Positive Monotonic Counter
5
+ A monotonically increasing non-zero counter.
6
+ A slightly better basic example than the plain monotonic counter since this one has a nontrivial refinement. *)
7
+
8
+ Definition increasing : hrel nat := (fun n n' _ _ => n <= n').
9
+ Hint Unfold increasing.
10
+
11
+ Definition pos : hpred nat := (fun n _ => n > 0).
12
+
13
+ (** We'll give the Program extension some hints for this module *)
14
+ Local Obligation Tactic := intros; eauto with arith; compute; eauto with arith.
15
+
16
+ (** Now the definition of a verified monotonically increasing counter is
17
+ barely more work than a completely unchecked counter. *)
18
+ Program Definition posmonotonic_counter := ref{nat|pos}[increasing,increasing].
19
+
20
+ Program Definition read_counter (c:posmonotonic_counter) : nat := !c.
21
+
22
+ Program Definition inc_monotonic { Γ } (p:posmonotonic_counter) : rgref Γ unit Γ :=
23
+ [p]:= !p + 1.
24
+
25
+ Program Definition mkCounter { Γ } (u:unit) : rgref Γ posmonotonic_counter Γ :=
26
+ Alloc 1.
27
+
28
+ Program Example test_counter { Γ } (u:unit) : rgref Γ unit Γ :=
29
+ x <- mkCounter tt;
30
+ inc_monotonic x.
Original file line number Diff line number Diff line change 1
1
#! /bin/bash
2
2
export CORE=" RGref/DSL/LinearEnv.v RGref/DSL/DSL.v RGref/DSL/Theories.v RGref/DSL/Core.v RGref/DSL/Monad.v"
3
- export EXAMPLES=" AppendOnlyLinkedList.v MonotonicCounter.v PrependOnlyPureList.v CounterModule.v RCC.v ReferenceImmutability.v LinkedList.v"
3
+ export EXAMPLES=" PosMonotonicCounter.v AppendOnlyLinkedList.v MonotonicCounter.v PrependOnlyPureList.v CounterModule.v RCC.v ReferenceImmutability.v LinkedList.v"
4
4
export BUGS=" KnownUnsoundnessExamples.v"
5
5
coq_makefile -arg -impredicative-set -R RGref RGref $CORE $EXAMPLES $BUGS > Makefile
6
6
touch .depend
You can’t perform that action at this time.
0 commit comments