Skip to content

Commit c504f08

Browse files
committed
vm_setoid
1 parent 9f224fa commit c504f08

File tree

6 files changed

+54
-24
lines changed

6 files changed

+54
-24
lines changed

_CoqProject

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ theories/TokenMachine.v
66
theories/TransitionSystem.v
77
theories/Queue.v
88
theories/Pid.v
9+
theories/ListSelector.v
910
theories/VM.v
1011
theories/Handlers/Storage.v
1112
theories/Handlers/Mailbox.v

theories/ListSelector.v

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
From Coq Require Import
22
List.
3+
34
Import ListNotations.
45

6+
From Hammer Require Import
7+
Tactics.
8+
59
Section defn.
610
Context {A : Type}.
711

@@ -15,14 +19,11 @@ End defn.
1519

1620
Section tests.
1721
Goal forall a l',
18-
Pick [1; 2] a l' ->
19-
(a = 1 /\ l' = [2]) \/ (a = 2 /\ l' = [1]).
22+
Pick [1; 2; 3] a l' ->
23+
(a = 1 /\ l' = [2; 3]) \/
24+
(a = 2 /\ l' = [1; 3]) \/
25+
(a = 3 /\ l' = [1; 2]).
2026
Proof.
21-
intros a l' H.
22-
inversion_clear H.
23-
- now left.
24-
- inversion_clear H0.
25-
+ now right.
26-
+ inversion H.
27+
sauto.
2728
Qed.
2829
End tests.

theories/Multifunction.v

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ Section mfun_prod.
207207
Context {A B C D : Type} `{setoidA : Setoid A} `{setoidB : Setoid B} `{setoidC : Setoid C} `{setoidD : Setoid D}.
208208

209209
Program Definition mfun_prod (f : @MFun A B setoidA setoidB) (g : @MFun C D setoidC setoidD) :
210-
@MFun (A * C) (B * D) (setoidPair A C) (setoidPair B D) :=
210+
@MFun (A * C) (B * D) (pair_setoid A C) (pair_setoid B D) :=
211211
{| morphism x y :=
212212
let (x_l, x_r) := x in
213213
let (y_l, y_r) := y in
@@ -224,7 +224,7 @@ Section mfun_sum.
224224
Context {A A' B : Type} `{setoidA : Setoid A} `{setoidA' : Setoid A'} `{setoidB : Setoid B}.
225225

226226
Program Definition mfun_sum_l (f : @MFun A A' setoidA setoidA') :
227-
@MFun (A * B) (A' * B) (setoidPair A B) (setoidPair A' B) :=
227+
@MFun (A * B) (A' * B) (pair_setoid A B) (pair_setoid A' B) :=
228228
{| morphism x y :=
229229
let (x_l, x_r) := x in
230230
let (y_l, y_r) := y in
@@ -237,7 +237,7 @@ Section mfun_sum.
237237
Qed.
238238

239239
Program Definition mfun_sum_r (f : @MFun A A' setoidA setoidA') :
240-
@MFun (B * A) (B * A') (setoidPair B A) (setoidPair B A') :=
240+
@MFun (B * A) (B * A') (pair_setoid B A) (pair_setoid B A') :=
241241
{| morphism x y :=
242242
let (x_l, x_r) := x in
243243
let (y_l, y_r) := y in

theories/Setoids.v

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,32 @@
11
From Coq Require Export
2-
SetoidClass.
2+
SetoidClass
3+
Permutation.
34

45
From Coq Require Import
56
Program.
67

78
From Hammer Require Import
89
Tactics.
910

10-
Section setoid_pair.
11+
Section pair.
1112
Context (A B : Type) `{Setoid A} `{Setoid B}.
1213

13-
Program Instance setoidPair : Setoid (A * B) :=
14+
Global Program Instance pair_setoid : Setoid (A * B) :=
1415
{| equiv (a b : (A * B)) :=
1516
let (a_l, a_r) := a in
1617
let (b_l, b_r) := b in
1718
equiv a_l b_l /\ equiv a_r b_r;
1819
|}.
1920
Solve All Obligations with sauto unfold:Reflexive,Symmetric,Transitive.
20-
End setoid_pair.
21+
End pair.
2122

22-
Section setoid_option.
23+
Definition pair_setoid' {A B : Type} (a : Setoid A) (b : Setoid B) :=
24+
@pair_setoid A B a b.
25+
26+
Section option.
2327
Context (T : Type) `{Setoid T}.
2428

25-
Program Instance setoid_option : Setoid (option T) :=
29+
Global Program Instance setoid_option : Setoid (option T) :=
2630
{| equiv (a b : option T) :=
2731
match a, b with
2832
| Some a, Some b => equiv a b
@@ -31,4 +35,11 @@ Section setoid_option.
3135
end;
3236
|}.
3337
Solve All Obligations with sauto unfold:Reflexive,Symmetric,Transitive.
34-
End setoid_option.
38+
End option.
39+
40+
Section permutation.
41+
Context (T : Type).
42+
43+
Global Program Instance setoid_permutation : Setoid (list T) | 10 :=
44+
{| equiv a b := Permutation a b |}.
45+
End permutation.

theories/TransitionSystem.v

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ Section TransitionSystem.
2828
Definition ts_ret (Event : Type) := option (Event * State).
2929

3030
Definition ts_ret_setoid (Event : Type) (Hss : Setoid State) :=
31-
let sp := @setoidPair Event State (eq_setoid _) Hss in
31+
let sp := @pair_setoid Event State (eq_setoid _) Hss in
3232
@setoid_option (Event * State) sp.
3333

3434
Class TransitionSystem {Event : Type} :=

theories/VM.v

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
From Coq Require Import
22
List
33
ZArith
4-
SetoidClass.
4+
SetoidClass
5+
SetoidDec.
56
Import ListNotations.
67

78
From SLOT Require Import
89
Setoids
910
TransitionSystem
10-
Pid.
11+
Pid
12+
ListSelector.
1113

1214
From Hammer Require Import
1315
Tactics.
@@ -21,7 +23,7 @@ Section IOHandler.
2123
Context {Request : Type} {Reply : Request -> Type}.
2224

2325
Definition MFunRet Ret State `{HRet : Setoid Ret} `{HState : Setoid State} :=
24-
@MFun State (Ret * State) HState (@setoidPair _ _ HRet HState).
26+
@MFun State (Ret * State) HState (@pair_setoid _ _ HRet HState).
2527

2628
Class IOHandler := {
2729
h_state : Type;
@@ -39,8 +41,7 @@ Section VM.
3941
| p_dead : (* Program terminted *)
4042
Program
4143
| p_yield :
42-
(* Wait for signal.
43-
44+
(* Interrupt the computation without producing any side effects.
4445
This primitive is used to softly introduce the concept of
4546
Erlang's "reductions", and to side-step termination checker,
4647
making programs non-Turing in a practically useful, as opposed
@@ -77,6 +78,22 @@ Section VM.
7778

7879
#[export] Instance etaX : Settable _ := settable! mkVM <world; runq; sleepq; child_ctr>.
7980

81+
Program Definition vm_setoid : Setoid VM :=
82+
{| equiv a b :=
83+
let (w1, rq1, sq1, cc1) := a in
84+
let (w2, rq2, sq2, cc2) := b in
85+
let w_eq := @equiv _ h_setoid in
86+
let p_eq := @equiv _ (setoid_permutation (PID * Program)) in
87+
w_eq w1 w2 /\
88+
p_eq rq1 rq2 /\
89+
p_eq sq1 sq2 /\
90+
@equiv _ (eq_setoid _) cc1 cc2;
91+
|}.
92+
Next Obligation.
93+
sauto unfold:Reflexive,Symmetric,Transitive
94+
use:Permutation_sym,Permutation_trans.
95+
Qed.
96+
8097
Definition new_child_id (parent : PID) (v : VM) : VM * positive :=
8198
let cc := child_ctr v in
8299
let (cc, ctr) :=

0 commit comments

Comments
 (0)