-
Notifications
You must be signed in to change notification settings - Fork 0
/
ReoCA.v
865 lines (712 loc) · 26.8 KB
/
ReoCA.v
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
Require Import CaMain.
Import ListNotations.
Set Implicit Arguments.
Set Maximal Implicit Insertion.
Obligation Tactic := program_simpl; congruence.
Module ReoCa.
Section ReoCa.
(* Parametric construction of constraint automata of Reo channels *)
Variable name state data: Set.
Definition ReoCABinaryChannel (a b: name) (states: set state) (initialStates : set state)
(transitionRelation : state -> set (set name * ConstraintAutomata.DC name data * state)):=
{|
ConstraintAutomata.Q := states;
ConstraintAutomata.N := [a;b];
ConstraintAutomata.T := transitionRelation;
ConstraintAutomata.Q0 := initialStates
|}.
(* Definition to build CA for Replicator and Merger channels *)
Definition ReoCATernaryChannel (a b c: name) (states: set state) (initialStates : set state)
(transitionRelation: state -> set (set name * ConstraintAutomata.DC name data * state)) :=
{|
ConstraintAutomata.Q := states;
ConstraintAutomata.N := [a;b;c];
ConstraintAutomata.T := transitionRelation;
ConstraintAutomata.Q0 := initialStates
|}.
End ReoCa.
End ReoCa.
(* Implementation Examples of canonical Constraint Automata as presented by Baier et al.'s paper *)
(* Sync channel CA *)
Inductive syncState := q0s.
Inductive syncPorts := E | F.
Program Instance syncStateEq: EqDec syncState eq :=
{equiv_dec x y :=
match x,y with
| q0s,q0s => in_left
end }.
Close Scope Q_scope.
Definition dataAssignmentBoth n :=
match n with
| 0 => 0
| 1 => 455
| Datatypes.S n => (1)
end.
Definition timeStampTestSync (n:nat) : QArith_base.Q :=
match n with
| 0 => 1#1
| S n => Z.of_N (N.of_nat(S n)) + 2#1 (* an example of a time stamp function, by injecting N to Z *)
end.
Lemma timeStampTestHoldsSync : forall n,
Qlt (timeStampTestSync n) (timeStampTestSync (S n)).
Proof.
intros. destruct n. unfold timeStampTestSync. simpl. reflexivity.
unfold timeStampTestSync.
apply orderZofNat. Defined.
Program Instance syncPortsEq: EqDec syncPorts eq :=
{equiv_dec x y :=
match x,y with
| E,E | F,F => in_left
| E,F | F,E => in_right
end }.
Definition portE := {|
ConstraintAutomata.id := E;
ConstraintAutomata.dataAssignment := dataAssignmentBoth;
ConstraintAutomata.timeStamp := timeStampTestSync;
ConstraintAutomata.tdsCond := timeStampTestHoldsSync;
ConstraintAutomata.index := 0 |}.
Definition portF:= {|
ConstraintAutomata.id := F;
ConstraintAutomata.dataAssignment := dataAssignmentBoth;
ConstraintAutomata.timeStamp := timeStampTestSync;
ConstraintAutomata.tdsCond := timeStampTestHoldsSync;
ConstraintAutomata.index := 0 |}.
Definition syncCaBehavior (s: syncState) :
set (set syncPorts * ConstraintAutomata.DC syncPorts nat * syncState) :=
match s with
| q0s => [([E;F] , ConstraintAutomata.eqDc nat E F, q0s)]
end.
Definition syncCA := {|
ConstraintAutomata.Q := [q0s];
ConstraintAutomata.N := [E;F];
ConstraintAutomata.T := syncCaBehavior;
ConstraintAutomata.Q0 := [q0s]
|}.
Definition paramSync := ReoCa.ReoCABinaryChannel E F [q0s] [q0s] syncCaBehavior.
Eval compute in ConstraintAutomata.run syncCA [portE;portF] 200.
(* LossySync CA *)
Inductive lossySyncStates := q0.
Inductive lossySyncPorts := A | B.
Program Instance lossySyncStateEq: EqDec lossySyncStates eq :=
{equiv_dec x y :=
match x,y with
| q0, q0 => in_left
end }.
Program Instance LossySyncPortsEq: EqDec lossySyncPorts eq :=
{equiv_dec x y :=
match x,y with
| A,A | B,B => in_left
| A,B | B,A => in_right
end }.
Definition dataAssignmentLossySyncBoth n :=
match n with
| 0 => 0
| 1 => 1
| S n => (1)
end.
Definition timeStampLossyA (n:nat) : QArith_base.Q :=
match n with
| 0 => 1#1
| S n => Z.of_N (N.of_nat(S n)) + 69#1
end.
Definition timeStampLossyB (n:nat) : QArith_base.Q :=
match n with
| 0 => 1#1
| S n => Z.of_N (N.of_nat(S n)) + 3#1
end.
Lemma timeStampTestHoldsLossyA: forall n,
Qlt (timeStampLossyA n) (timeStampLossyA (S n)).
Proof.
intros. destruct n. unfold timeStampLossyA. reflexivity.
unfold timeStampLossyA.
apply orderZofNat. Defined.
Lemma timeStampTestHoldsLossyB: forall n,
Qlt (timeStampLossyB n) (timeStampLossyB (S n)).
Proof.
intros. destruct n. unfold timeStampLossyB. reflexivity.
unfold timeStampLossyB.
apply orderZofNat. Defined.
Definition lossySyncCaBehavior (s: lossySyncStates) :
set (set lossySyncPorts * ConstraintAutomata.DC lossySyncPorts nat * lossySyncStates):=
match s with
| q0 => [([A;B] , ConstraintAutomata.eqDc nat A B, q0);
([A], (ConstraintAutomata.tDc lossySyncPorts nat), q0)]
end.
Definition lossySyncCA := {|
ConstraintAutomata.Q := [q0];
ConstraintAutomata.N := [A;B];
ConstraintAutomata.T := lossySyncCaBehavior;
ConstraintAutomata.Q0 := [q0]
|}.
Definition portA := {|
ConstraintAutomata.id := A;
ConstraintAutomata.dataAssignment := dataAssignmentLossySyncBoth;
ConstraintAutomata.timeStamp := timeStampLossyA;
ConstraintAutomata.tdsCond := timeStampTestHoldsLossyA;
ConstraintAutomata.index := 0 |}.
Definition portB:= {|
ConstraintAutomata.id := B;
ConstraintAutomata.dataAssignment := dataAssignmentLossySyncBoth;
ConstraintAutomata.timeStamp := timeStampLossyB;
ConstraintAutomata.tdsCond := timeStampTestHoldsLossyB;
ConstraintAutomata.index := 0 |}.
Eval compute in ConstraintAutomata.run lossySyncCA [portA;portB] 10. (*does not accept the TDS composed by portA and portB because
only B has data in theta.time(2), which is not comprised by the automaton's transitions *)
Definition paramLossySync := ReoCa.ReoCABinaryChannel A B [q0] [q0] lossySyncCaBehavior.
(* FIFO CA *)
Inductive FIFOStates : Type := q0F | p0F | p1F.
Inductive FIFOports : Type := AF | BF.
Program Instance portsEq : EqDec FIFOports eq :=
{equiv_dec x y :=
match x,y with
| AF,AF | BF,BF => in_left
| AF,BF | BF,AF => in_right
end }.
Definition dataAssignmentA n :=
match n with
| 0 => 0
| 1 => 0
| 2 => 1
| S n => (1)
end.
Definition dataAssignmentB n :=
match n with
| 0 => 0
| 1 => (0)
| 2 => 1
| S n => 1
end.
Definition timeStampFIFOA(n:nat) : QArith_base.Q :=
match n with
| 0 => 1#1
| 1 => 3#1
| 2 => 5#1
| 3 => 7#1
| 4 => 9#1
| 5 => 11#1
| S n => Z.of_N (N.of_nat(S n)) + 11#1
end.
Definition timeStampFIFOB (n:nat) : QArith_base.Q :=
match n with
| 0 => 2#1
| 1 => 4#1
| 2 => 6#1
| 3 => 8#1
| 4 => 10#1
| 5 => 12#1
| S n => Z.of_N (N.of_nat(S n)) + 10#1
end.
Lemma timeStampTestFIFOAHolds : forall n, Qlt (timeStampFIFOA n) (timeStampFIFOA (S n)).
Proof.
intros. destruct n. unfold timeStampFIFOA. reflexivity.
unfold timeStampFIFOA. case (n). reflexivity.
intros n0. case (n0). reflexivity.
intros n1. case (n1). reflexivity.
intros n2. case (n2). reflexivity.
intros n3. case (n3). reflexivity.
intros n4. unfold Qlt. apply orderZofNat. Defined.
Lemma timeStampTestFIFOBHolds : forall n,
Qlt (timeStampFIFOB n) (timeStampFIFOB (S n)).
Proof.
intros. destruct n. unfold timeStampFIFOB. reflexivity.
unfold timeStampFIFOB. case (n). reflexivity.
intros n0. case (n0). reflexivity.
intros n1. case (n1). reflexivity.
intros n2. case (n2). reflexivity.
intros n3. case (n3). reflexivity.
intros n4. unfold Qlt. apply orderZofNat. Defined.
Definition portAF := {|
ConstraintAutomata.id := AF;
ConstraintAutomata.dataAssignment := dataAssignmentA;
ConstraintAutomata.timeStamp := timeStampFIFOA;
ConstraintAutomata.tdsCond := timeStampTestFIFOAHolds;
ConstraintAutomata.index := 0 |}.
Definition portBF := {|
ConstraintAutomata.id := BF;
ConstraintAutomata.dataAssignment := dataAssignmentB;
ConstraintAutomata.timeStamp := timeStampFIFOB;
ConstraintAutomata.tdsCond := timeStampTestFIFOBHolds;
ConstraintAutomata.index := 0 |}.
Definition realports := [portAF;portBF].
Definition oneBoundedFIFOrel (s:FIFOStates) :
set (set FIFOports * ConstraintAutomata.DC FIFOports nat * FIFOStates) :=
match s with
| q0F => [([AF], (ConstraintAutomata.dc AF 0), p0F);
([AF], (ConstraintAutomata.dc AF 1), p1F)]
| p0F => [([BF], (ConstraintAutomata.dc BF 0), q0F)]
| p1F => [([BF], (ConstraintAutomata.dc BF 1), q0F)]
end.
Definition oneBoundedFIFOCA:= {|
ConstraintAutomata.Q := [q0F;p0F;p1F];
ConstraintAutomata.N := [AF;BF];
ConstraintAutomata.T := oneBoundedFIFOrel;
ConstraintAutomata.Q0 := [q0F]
|}.
Definition paramFIFO1 := ReoCa.ReoCABinaryChannel AF BF [q0F;p0F;p1F] [q0F] oneBoundedFIFOrel.
Lemma dataInAF: forall s, In AF (ConstraintAutomata.retrievePortsFromRespTransitions (ConstraintAutomata.T oneBoundedFIFOCA s)) <->
s = q0F.
Proof.
split.
- intros. destruct s.
+ reflexivity.
+ simpl in H. inversion H. discriminate. inversion H0.
+ simpl in H. inversion H. discriminate. inversion H0.
- intros. rewrite H. simpl. left. reflexivity.
Defined.
Eval compute in ConstraintAutomata.run oneBoundedFIFOCA realports 8.
(* SyncDrain CA *)
Inductive syncDrainState := q1D.
Inductive syncDrainPorts := AD | BD.
Program Instance syncDrainStateEq: EqDec syncDrainState eq :=
{equiv_dec x y :=
match x,y with
| q1D, q1D => in_left
end }.
Definition dataAssignmentSyncDrainBoth n :=
match n with
| 0 => 0
| 1 => 69
| S n => (1)
end.
Definition timeStampSyncDrain (n:nat) : QArith_base.Q :=
match n with
| 0 => 1#1
| S n => Z.of_N (N.of_nat(S n)) + 1#1
end.
Lemma timeStampSyncDrainHolds : forall n,
Qlt (timeStampSyncDrain n) (timeStampSyncDrain (S n)).
Proof.
intros. destruct n. unfold timeStampSyncDrain. reflexivity.
unfold timeStampSyncDrain. case (n). reflexivity.
intros n0. unfold timeStampSyncDrain. apply orderZofNat. Defined.
Program Instance syncDrainPortsEq: EqDec syncDrainPorts eq :=
{equiv_dec x y :=
match x,y with
| AD,AD | BD,BD => in_left
| AD,BD | BD,AD => in_right
end }.
Definition portAD := {|
ConstraintAutomata.id := AD;
ConstraintAutomata.dataAssignment := dataAssignmentSyncDrainBoth;
ConstraintAutomata.timeStamp := timeStampSyncDrain;
ConstraintAutomata.tdsCond := timeStampSyncDrainHolds;
ConstraintAutomata.index := 0 |}.
Definition portBD:= {|
ConstraintAutomata.id := BD;
ConstraintAutomata.dataAssignment := dataAssignmentSyncDrainBoth;
ConstraintAutomata.timeStamp := timeStampSyncDrain;
ConstraintAutomata.tdsCond := timeStampSyncDrainHolds;
ConstraintAutomata.index := 0 |}.
Definition syncDrainCaBehavior (s: syncDrainState) : set
(set syncDrainPorts * ConstraintAutomata.DC syncDrainPorts nat * syncDrainState) :=
match s with
| q1D => [([AD;BD] , ConstraintAutomata.tDc syncDrainPorts nat, q1D)]
end.
Definition SyncDrainCA := {|
ConstraintAutomata.Q := [q1D];
ConstraintAutomata.N := [AD;BD];
ConstraintAutomata.T := syncDrainCaBehavior;
ConstraintAutomata.Q0 := [q1D]
|}.
Eval compute in ConstraintAutomata.run SyncDrainCA [portAD;portBD] 15.
Definition paramSyncDrain := ReoCa.ReoCABinaryChannel AD BD [q1D] [q1D] syncDrainCaBehavior.
Check paramSyncDrain.
(* AsyncDrain *)
Inductive aSyncDrainState := q1A.
Inductive aSyncDrainPorts := AA | BA.
Program Instance aSyncDrainStateEq: EqDec aSyncDrainState eq :=
{equiv_dec x y :=
match x,y with
| q1A, q1A => in_left
end }.
Definition dataAssignmentASyncDrainBoth n :=
match n with
| 0 => 0
| 1 => 0
| S n => (1)
end.
Definition timeStampASyncDrainA (n:nat) : QArith_base.Q :=
match n with
| 0 => 0#1
| 1 => 3#1
| S n => Z.of_N (N.of_nat(S n)) + 7#1
end.
Definition timeStampASyncDrainB (n:nat) : QArith_base.Q :=
match n with
| 0 => 1#1
| 1 => 2#1
| S n => Z.of_N (N.of_nat(S n)) + 11#1
end.
Lemma timeStampASyncDrainHolds : forall n,
Qlt (timeStampASyncDrainA n) (timeStampASyncDrainA (S n)).
Proof.
intros. destruct n. unfold timeStampASyncDrainA. reflexivity.
unfold timeStampASyncDrainA. case (n). reflexivity.
intros n0. unfold timeStampASyncDrainA. apply orderZofNat. Defined.
Lemma timeStampASyncDrainBHolds : forall n,
Qlt (timeStampASyncDrainB n) (timeStampASyncDrainB (S n)).
Proof.
intros. destruct n. unfold timeStampASyncDrainB. reflexivity.
unfold timeStampASyncDrainB. case (n). reflexivity.
intros n0. unfold timeStampASyncDrainB. apply orderZofNat. Defined.
Program Instance aSyncDrainPortsEq: EqDec aSyncDrainPorts eq :=
{equiv_dec x y :=
match x,y with
| AA,AA | BA,BA => in_left
| AA,BA | BA,AA => in_right
end }.
Definition portAA := {|
ConstraintAutomata.id := AA;
ConstraintAutomata.dataAssignment := dataAssignmentASyncDrainBoth;
ConstraintAutomata.timeStamp := timeStampASyncDrainA;
ConstraintAutomata.tdsCond := timeStampASyncDrainHolds;
ConstraintAutomata.index := 0 |}.
Definition portBA:= {|
ConstraintAutomata.id := BA;
ConstraintAutomata.dataAssignment := dataAssignmentASyncDrainBoth;
ConstraintAutomata.timeStamp := timeStampASyncDrainB;
ConstraintAutomata.tdsCond := timeStampASyncDrainBHolds;
ConstraintAutomata.index := 0 |}.
Definition aSyncDrainCaBehavior (s: aSyncDrainState): set
(set aSyncDrainPorts * ConstraintAutomata.DC aSyncDrainPorts nat * aSyncDrainState) :=
match s with
| q1A => [([AA] , ConstraintAutomata.tDc aSyncDrainPorts nat, q1A);
([BA] , ConstraintAutomata.tDc aSyncDrainPorts nat, q1A)]
end.
Definition aSyncDrainCA := {|
ConstraintAutomata.Q := [q1A];
ConstraintAutomata.N := [AA;BA];
ConstraintAutomata.T := aSyncDrainCaBehavior;
ConstraintAutomata.Q0 := [q1A]
|}.
Eval compute in ConstraintAutomata.run aSyncDrainCA [portAA;portBA] 10.
Definition paramAsyncDrain := ReoCa.ReoCABinaryChannel AA BA [q1A] [q1A] aSyncDrainCaBehavior.
(* Filter CA *)
Inductive filterState := q1F.
Inductive filterPorts := C | D.
Program Instance filterStateEq: EqDec filterState eq :=
{equiv_dec x y :=
match x,y with
| q1F, q1F => in_left
end }.
Definition dataAssignmentfilterBoth n :=
match n with
| 0 => 0
| 1 => 0
| S n => (1)
end.
Definition timeStampfilterA (n:nat) : QArith_base.Q :=
match n with
| 0 => 0#1
| 1 => 3#1
| S n => Z.of_N (N.of_nat(S n)) + 7#1
end.
Definition timeStampfilterB (n:nat) : QArith_base.Q :=
match n with
| 0 => 4#1
| S n => Z.of_N (N.of_nat(S n)) + 20#1
end.
Lemma timeStampfilterHolds : forall n,
Qlt (timeStampfilterA n) (timeStampfilterA (S n)).
Proof.
intros. destruct n. unfold timeStampfilterA. reflexivity.
unfold timeStampfilterA. case (n). reflexivity.
intros n0. unfold timeStampfilterA. apply orderZofNat. Defined.
Lemma timeStampfilterBHolds : forall n,
Qlt (timeStampfilterB n) (timeStampfilterB (S n)).
Proof.
intros. destruct n. unfold timeStampfilterB. reflexivity.
unfold timeStampfilterB. apply orderZofNat. Defined.
Program Instance filterPortsEq: EqDec filterPorts eq :=
{equiv_dec x y :=
match x,y with
| C,C | D,D => in_left
| C,D | D,C => in_right
end }.
Definition portC := {|
ConstraintAutomata.id := C;
ConstraintAutomata.dataAssignment := dataAssignmentfilterBoth;
ConstraintAutomata.timeStamp := timeStampfilterA;
ConstraintAutomata.tdsCond := timeStampfilterHolds;
ConstraintAutomata.index := 0 |}.
Definition portD:= {|
ConstraintAutomata.id := D;
ConstraintAutomata.dataAssignment := dataAssignmentfilterBoth;
ConstraintAutomata.timeStamp := timeStampfilterB;
ConstraintAutomata.tdsCond := timeStampfilterBHolds;
ConstraintAutomata.index := 0 |}.
(*As an example, the filter condition over the data item in port A is the data should be 3 *)
Definition filterCaBehavior (s: filterState) : set
(set filterPorts * ConstraintAutomata.DC filterPorts nat * filterState) :=
match s with
| q1F => [([C;D] , ConstraintAutomata.andDc (ConstraintAutomata.dc C (3))
(ConstraintAutomata.eqDc nat C D), q1F);
([C] , ConstraintAutomata.negDc (ConstraintAutomata.dc C (3)), q1F)]
end.
(* The CA itself is formalized as *)
Definition filterCA := {|
ConstraintAutomata.Q := [q1F];
ConstraintAutomata.N := [C;D];
ConstraintAutomata.T := filterCaBehavior;
ConstraintAutomata.Q0 := [q1F]
|}.
Eval compute in ConstraintAutomata.run filterCA [portC;portD] 3.
Definition paramFilter := ReoCa.ReoCABinaryChannel C D [q1F] [q1F] filterCaBehavior.
(* Transform CA *)
Definition trasformFunction (n: nat) := n + 3.
Inductive transformState := q1T.
Inductive transformPorts := AT | BT.
Program Instance transformStateEq: EqDec transformState eq :=
{equiv_dec x y :=
match x,y with
| q1T, q1T => in_left
end }.
Definition dataAssignmenttransformAF n :=
match n with
| 0 => 0
| 1 => 0
| 2 => 0
| 3 => 0
| S n => (1)
end.
Definition dataAssignmenttransformBF n :=
match n with
| 0 => 3
| 1 => 3
| 2 => 3
| 3 => 3
| S n => (4)
end.
Definition timeStamptransformA (n:nat) : QArith_base.Q :=
match n with
| 0 => 0#1
| 1 => 2#1
| S n => Z.of_N (N.of_nat(S n)) + 11#1
end.
Definition timeStamptransformB (n:nat) : QArith_base.Q :=
match n with
| 0 => 0#1
| 1 => 2#1
| S n => Z.of_N (N.of_nat(S n)) + 11#1
end.
Lemma timeStamptransformHolds : forall n,
Qlt (timeStamptransformA n) (timeStamptransformA (S n)).
Proof.
intros. destruct n. unfold timeStamptransformA. reflexivity.
unfold timeStamptransformA. case n. reflexivity.
intros n0. apply orderZofNat. Defined.
Lemma timeStamptransformBHolds : forall n,
Qlt (timeStamptransformB n) (timeStamptransformB (S n)).
Proof.
intros. destruct n. unfold timeStamptransformB. reflexivity.
unfold timeStamptransformB. case n. reflexivity.
intros n0. apply orderZofNat. Defined.
Program Instance transformPortsEq: EqDec transformPorts eq :=
{equiv_dec x y :=
match x,y with
| AT,AT | BT,BT => in_left
| AT,BT | BT,AT => in_right
end }.
Definition portAT := {|
ConstraintAutomata.id := AT;
ConstraintAutomata.dataAssignment := dataAssignmenttransformAF;
ConstraintAutomata.timeStamp := timeStamptransformA;
ConstraintAutomata.tdsCond := timeStamptransformHolds;
ConstraintAutomata.index := 0 |}.
Definition portBT:= {|
ConstraintAutomata.id := BT;
ConstraintAutomata.dataAssignment := dataAssignmenttransformBF;
ConstraintAutomata.timeStamp := timeStamptransformB;
ConstraintAutomata.tdsCond := timeStamptransformBHolds;
ConstraintAutomata.index := 0 |}.
Definition transformCaBehavior (s: transformState) : set
(set transformPorts * ConstraintAutomata.DC transformPorts nat * transformState) :=
match s with
| q1T => [([AT;BT] , ConstraintAutomata.trDc trasformFunction AT BT, q1T)]
end.
Definition transformCA := {|
ConstraintAutomata.Q := [q1T];
ConstraintAutomata.N := [AT;BT];
ConstraintAutomata.T := transformCaBehavior;
ConstraintAutomata.Q0 := [q1T]
|}.
Eval compute in ConstraintAutomata.run transformCA [portAT;portBT] 10.
Definition paramTransform := ReoCa.ReoCABinaryChannel AT BT [q1T] [q1T] transformCaBehavior.
(* Merger CA*)
Inductive mergerState := q1M.
Inductive mergerPorts := AM | BM | CM.
Program Instance mergerStateEq: EqDec mergerState eq :=
{equiv_dec x y :=
match x,y with
| q1M, q1M => in_left
end }.
Definition dataAssignmentmergerBoth n :=
match n with
| 0 => 0
| 1 => 555
| 3 => 69
| S n => (1)
end.
Definition timeStampmergerA (n:nat) : QArith_base.Q :=
match n with
| 0 => 1#1
| 1 => 2#1
| S n => Z.of_N (N.of_nat(S n)) + 11#1
end.
Definition timeStampmergerB (n:nat) : QArith_base.Q :=
match n with
| 0 => 1#1
| 1 => 2#1
| S n => Z.of_N (N.of_nat(S n)) + 11#1
end.
Definition timeStampmergerC (n:nat) : QArith_base.Q :=
match n with
| 0 => 1#1
| 1 => 2#1
| S n => Z.of_N (N.of_nat(S n)) + 11#1
end.
Lemma timeStampmergerHolds : forall n,
Qlt (timeStampmergerA n) (timeStampmergerA (S n)).
Proof.
intros. destruct n. unfold timeStampmergerA. reflexivity.
unfold timeStampmergerA. case n. reflexivity.
intros n0. apply orderZofNat. Defined.
Lemma timeStampmergerBHolds : forall n,
Qlt (timeStampmergerB n) (timeStampmergerB (S n)).
Proof.
intros. destruct n. unfold timeStampmergerB. reflexivity.
unfold timeStampmergerB. case n. reflexivity.
intros n0. apply orderZofNat. Defined.
Lemma timeStampmergerCHolds : forall n,
Qlt (timeStampmergerC n) (timeStampmergerC (S n)).
Proof.
intros. destruct n. unfold timeStampmergerC. reflexivity.
unfold timeStampmergerC. case n. reflexivity.
intros n0. apply orderZofNat. Defined.
Program Instance mergerPortsEq: EqDec mergerPorts eq :=
{equiv_dec x y :=
match x,y with
| AM,AM | BM,BM | CM, CM => in_left
| AM,BM | AM,CM | BM,AM | BM,CM | CM, AM | CM, BM => in_right
end }.
Definition portAM := {|
ConstraintAutomata.id := AM;
ConstraintAutomata.dataAssignment := dataAssignmentmergerBoth;
ConstraintAutomata.timeStamp := timeStampmergerA;
ConstraintAutomata.tdsCond := timeStampmergerHolds;
ConstraintAutomata.index := 0 |}.
Definition portBM:= {|
ConstraintAutomata.id := BM;
ConstraintAutomata.dataAssignment := dataAssignmentmergerBoth;
ConstraintAutomata.timeStamp := timeStampmergerB;
ConstraintAutomata.tdsCond := timeStampmergerBHolds;
ConstraintAutomata.index := 0 |}.
Definition portCM:= {|
ConstraintAutomata.id := CM;
ConstraintAutomata.dataAssignment := dataAssignmentmergerBoth;
ConstraintAutomata.timeStamp := timeStampmergerC;
ConstraintAutomata.tdsCond := timeStampmergerCHolds;
ConstraintAutomata.index := 0 |}.
Definition mergerCaBehavior (s: mergerState) : set
(set mergerPorts * ConstraintAutomata.DC mergerPorts nat * mergerState) :=
match s with
| q1M => [([AM;CM] , ConstraintAutomata.eqDc nat AM CM, q1M);
([BM;CM] , ConstraintAutomata.eqDc nat BM CM, q1M)]
end.
Definition mergerCA := {|
ConstraintAutomata.Q := [q1M];
ConstraintAutomata.N := [AM;BM;CM];
ConstraintAutomata.T := mergerCaBehavior;
ConstraintAutomata.Q0 := [q1M]
|}.
Eval compute in ConstraintAutomata.run mergerCA [portAM;portBM;portCM] 10.
Definition paramMerger := ReoCa.ReoCATernaryChannel AM BM CM [q1M] [q1M] mergerCaBehavior.
(* Replicator CA *)
Inductive replicatorState := q1R.
Inductive replicatorPorts := AR | BR | CR.
Program Instance replicatorStateEq: EqDec replicatorState eq :=
{equiv_dec x y :=
match x,y with
| q1R, q1R => in_left
end }.
Definition dataAssignmentreplicatorBoth n :=
match n with
| 0 => 0
| 1 => 1
| 3 => 2
| S n => (1 + S n)
end.
Definition timeStampreplicatorA (n:nat) : QArith_base.Q :=
match n with
| 0 => 1#1
| 1 => 2#1
| S n => Z.of_N (N.of_nat(S n)) + 11#1
end.
Definition timeStampreplicatorB (n:nat) : QArith_base.Q :=
match n with
| 0 => 1#1
| 1 => 2#1
| S n => Z.of_N (N.of_nat(S n)) + 11#1
end.
Definition timeStampreplicatorC (n:nat) : QArith_base.Q :=
match n with
| 0 => 1#1
| 1 => 2#1
| S n => Z.of_N (N.of_nat(S n)) + 11#1
end.
Lemma timeStampreplicatorHolds : forall n,
Qlt (timeStampreplicatorA n) (timeStampreplicatorA (S n)).
Proof.
intros. destruct n. unfold timeStampreplicatorA. reflexivity.
unfold timeStampreplicatorA. case n. reflexivity.
intros n0. apply orderZofNat. Defined.
Lemma timeStampreplicatorBHolds : forall n,
Qlt (timeStampreplicatorB n) (timeStampreplicatorB (S n)).
Proof.
intros. destruct n. unfold timeStampreplicatorB. reflexivity.
unfold timeStampreplicatorB. case n. reflexivity.
intros n0. apply orderZofNat. Defined.
Lemma timeStampreplicatorCHolds : forall n,
Qlt (timeStampreplicatorC n) (timeStampreplicatorC (S n)).
Proof.
intros. destruct n. unfold timeStampreplicatorC. reflexivity.
unfold timeStampreplicatorC. case n. reflexivity.
intros n0. apply orderZofNat. Defined.
Program Instance replicatorPortsEq: EqDec replicatorPorts eq :=
{equiv_dec x y :=
match x,y with
| AR,AR | BR,BR | CR, CR => in_left
| AR,BR | AR,CR | BR,AR | BR,CR | CR, AR | CR, BR => in_right
end }.
Definition portAR := {|
ConstraintAutomata.id := AR;
ConstraintAutomata.dataAssignment := dataAssignmentreplicatorBoth;
ConstraintAutomata.timeStamp := timeStampreplicatorA;
ConstraintAutomata.tdsCond := timeStampreplicatorHolds;
ConstraintAutomata.index := 0 |}.
Definition portBR:= {|
ConstraintAutomata.id := BR;
ConstraintAutomata.dataAssignment := dataAssignmentreplicatorBoth;
ConstraintAutomata.timeStamp := timeStampreplicatorB;
ConstraintAutomata.tdsCond := timeStampreplicatorBHolds;
ConstraintAutomata.index := 0 |}.
Definition portCR:= {|
ConstraintAutomata.id := CR;
ConstraintAutomata.dataAssignment := dataAssignmentreplicatorBoth;
ConstraintAutomata.timeStamp := timeStampreplicatorC;
ConstraintAutomata.tdsCond := timeStampreplicatorCHolds;
ConstraintAutomata.index := 0 |}.
Definition replicatorCaBehavior (s: replicatorState) : set
(set replicatorPorts * ConstraintAutomata.DC replicatorPorts nat * replicatorState) :=
match s with
| q1R => [([AR;BR;CR] , ConstraintAutomata.andDc (ConstraintAutomata.eqDc nat AR BR)
(ConstraintAutomata.eqDc nat AR CR), q1R)]
end.
Definition replicatorCA := {|
ConstraintAutomata.Q := [q1R];
ConstraintAutomata.N := [AR;BR;CR];
ConstraintAutomata.T := replicatorCaBehavior;
ConstraintAutomata.Q0 := [q1R]
|}.
Eval compute in ConstraintAutomata.run replicatorCA [portAR;portBR;portCR] 11.
Definition paramReplicator := ReoCa.ReoCATernaryChannel AR BR CR [q1R] [q1R] replicatorCaBehavior.