-
Notifications
You must be signed in to change notification settings - Fork 0
/
Connection.dfy
716 lines (678 loc) · 24.5 KB
/
Connection.dfy
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
module Connection {
import opened Circ
import opened Utils
import opened Scuf
import opened Subcircuit
import opened Eval
import opened ConservedSubcircuit
import opened MapFunction
import opened MapConnection
opaque ghost predicate ConnectionValid(c: Circuit, e1: Scuf, e2: Scuf, connection: map<NP, NP>)
requires ScValid(c, e1.sc)
requires ScValid(c, e2.sc)
{
&& (connection.Keys <= Seq.ToSet(e2.mp.inputs))
&& (connection.Values <= Seq.ToSet(e1.mp.outputs))
&& SetsNoIntersection(connection.Keys, c.PortSource.Keys)
}
lemma GetConnectionValid(c: Circuit, conn: ScufConnection)
requires c.Valid()
requires conn.SomewhatValid()
requires conn.ValidInCircuit(c)
ensures
var connection := conn.GetConnection();
ConnectionValid(c, conn.scuf_a, conn.scuf_b, connection)
{
reveal ConnectionValid();
}
lemma ConnectionValuesInE1(c: Circuit, e1: Scuf, e2: Scuf, connection: map<NP, NP>)
requires c.Valid()
requires e1.Valid(c)
requires e2.Valid(c)
requires ConnectionValid(c, e1, e2, connection)
ensures NPsInSc(e1.sc, connection.Values)
{
reveal ScValid();
reveal ConnectionValid();
reveal NPsInSc();
FOutputsInSc(c, e1);
}
lemma ConnectionKeysInE2(c: Circuit, e1: Scuf, e2: Scuf, connection: map<NP, NP>)
requires c.Valid()
requires e1.Valid(c)
requires e2.Valid(c)
requires ConnectionValid(c, e1, e2, connection)
ensures NPsInSc(e2.sc, connection.Keys)
{
reveal ScValid();
reveal ConnectionValid();
reveal NPsInSc();
FInputsInSc(c, e2);
}
lemma ConnectionKeysINPs(c: Circuit, e1: Scuf, e2: Scuf, connection: map<NP, NP>)
requires c.Valid()
requires e1.Valid(c)
requires e2.Valid(c)
requires ConnectionValid(c, e1, e2, connection)
ensures INPsValid(c, connection.Keys)
{
reveal ScValid();
reveal ConnectionValid();
reveal NPsInSc();
reveal INPsValid();
reveal Scuf.SomewhatValid();
ScufFInputsAreValid(c, e2);
}
lemma ConnectionValuesONPs(c: Circuit, e1: Scuf, e2: Scuf, connection: map<NP, NP>)
requires c.Valid()
requires e1.Valid(c)
requires e2.Valid(c)
requires ConnectionValid(c, e1, e2, connection)
ensures ONPsValid(c, connection.Values)
{
reveal ScValid();
reveal ConnectionValid();
reveal NPsInSc();
reveal ONPsValid();
reveal Scuf.SomewhatValid();
ScufFOutputsAreValid(c, e1);
}
lemma IsIslandInputsNotInPortSource(c: Circuit, e: Scuf)
requires c.Valid()
requires e.SomewhatValid(c)
requires IsIsland(c, e.sc)
ensures Seq.ToSet(e.mp.inputs) !! c.PortSource.Keys
{
reveal IsIsland();
reveal Scuf.SomewhatValid();
reveal ConnInputs();
reveal UnconnInputs();
}
ghost predicate ConnectEntitiesRequirements(c: Circuit, conn: ScufConnection) {
&& c.Valid()
&& conn.Valid()
&& conn.ValidInCircuit(c)
}
lemma ConnectionInSc(c: Circuit, conn: ScufConnection)
requires ConnectEntitiesRequirements(c, conn)
ensures
var connection := conn.GetConnection();
&& NPsInSc(conn.scuf_b.sc, connection.Keys)
&& NPsInSc(conn.scuf_a.sc, connection.Values)
&& NPsNotInSc(conn.scuf_b.sc, connection.Values)
&& NPsNotInSc(conn.scuf_a.sc, connection.Keys)
{
var connection := conn.GetConnection();
assert connection.Values <= Seq.ToSet(conn.scuf_a.mp.outputs);
assert connection.Keys == Seq.ToSet(conn.scuf_b.mp.inputs) - Seq.ToSet(conn.scuf_ab.mp.inputs);
reveal NPsInSc();
reveal NPsNotInSc();
reveal Seq.ToSet();
FOutputsInSc(c, conn.scuf_a);
FOutputsInSc(c, conn.scuf_b);
FInputsInSc(c, conn.scuf_a);
FInputsInSc(c, conn.scuf_b);
}
opaque predicate ConnectCircuitRequirements(c: Circuit, connection: map<NP, NP>)
{
&& (forall np :: np in connection.Keys ==> INPValid(c, np) && np !in c.PortSource)
&& (forall np :: np in connection.Values ==> ONPValid(c, np))
}
function ConnectCircuit(c: Circuit, connection: map<NP, NP>): (r: Circuit)
requires c.Valid()
requires ConnectCircuitRequirements(c, connection)
ensures r.Valid()
{
reveal Circuit.Valid();
reveal ConnectCircuitRequirements();
var new_c := Circuit(
c.NodeKind,
AddMaps(c.PortSource, connection)
);
assert new_c.PortSource.Values == c.PortSource.Values + connection.Values;
assert (forall np :: np in new_c.PortSource.Values ==> ONPValid(new_c, np));
assert (forall np :: np in new_c.PortSource.Keys ==> INPValid(new_c, np));
new_c
}
lemma ConnectCircuitOtherIsIsland(c: Circuit, connection: map<NP, NP>, e: Scuf)
requires c.Valid()
requires ConnectCircuitRequirements(c, connection)
requires e.Valid(c)
requires IsIsland(c, e.sc)
requires NPsNotInSc(e.sc, connection.Keys)
requires NPsNotInSc(e.sc, connection.Values)
ensures
var new_c := ConnectCircuit(c, connection);
IsIsland(new_c, e.sc)
{
reveal IsIsland();
var new_c := ConnectCircuit(c, connection);
assert new_c.PortSource.Keys == c.PortSource.Keys + connection.Keys;
assert forall np :: np in new_c.PortSource && np.n in e.sc ==> np in c.PortSource by {
reveal NPsNotInSc();
}
assert new_c.PortSource.Values == c.PortSource.Values + connection.Values;
assert (forall np :: np in new_c.PortSource && np.n in e.sc ==> new_c.PortSource[np].n in e.sc);
forall np | np in new_c.PortSource
ensures !((np.n !in e.sc) && (new_c.PortSource[np].n in e.sc))
{
if np.n !in e.sc && new_c.PortSource[np].n in e.sc {
assert np !in c.PortSource;
assert np in connection.Keys;
assert new_c.PortSource[np] in connection.Values;
reveal NPsNotInSc();
assert false;
}
}
assert (forall np :: np in new_c.PortSource && np.n !in e.sc ==> new_c.PortSource[np].n !in e.sc);
}
lemma ConnectEntitiesOtherConnUnchanged(c: Circuit, connection: map<NP, NP>, e: Scuf)
requires c.Valid()
requires ConnectCircuitRequirements(c, connection)
requires e.Valid(c)
requires NPsNotInSc(e.sc, connection.Keys)
requires NPsNotInSc(e.sc, connection.Values)
ensures
var new_c := ConnectCircuit(c, connection);
&& ScValid(new_c, e.sc)
&& (ConnInputs(c, e.sc) == ConnInputs(new_c, e.sc))
&& (UnconnInputs(c, e.sc) == UnconnInputs(new_c, e.sc))
&& (ConnOutputs(c, e.sc) == ConnOutputs(new_c, e.sc))
{
var new_c := ConnectCircuit(c, connection);
assert new_c.PortSource.Keys == c.PortSource.Keys + connection.Keys;
assert new_c.PortSource.Values == c.PortSource.Values + connection.Values;
assert ScValid(new_c, e.sc) by {
reveal ScValid();
}
forall np: NP | np.n in e.sc
ensures (np in ConnInputs(c, e.sc)) == (np in ConnInputs(new_c, e.sc))
ensures (np in UnconnInputs(c, e.sc)) == (np in UnconnInputs(new_c, e.sc))
{
assert np !in connection.Keys by {
reveal NPsNotInSc();
}
// ConnInputs conserved
if (np in c.PortSource) && (c.PortSource[np].n !in e.sc) {
assert np in new_c.PortSource;
assert new_c.PortSource[np].n !in e.sc;
}
if (np in new_c.PortSource) && (new_c.PortSource[np].n !in e.sc) {
assert np in c.PortSource;
assert c.PortSource[np].n !in e.sc;
}
// UnconnInputs conserved
if (np !in c.PortSource && INPValid(c, np)) {
assert (np !in new_c.PortSource);
assert INPValid(new_c, np);
}
if (np !in new_c.PortSource && INPValid(new_c, np)) {
assert np !in c.PortSource;
assert INPValid(c, np);
}
reveal ConnInputs();
reveal UnconnInputs();
}
forall np: NP | np.n !in e.sc
ensures
((np in c.PortSource) && (c.PortSource[np].n in e.sc)) ==
((np in new_c.PortSource) && (new_c.PortSource[np].n in e.sc))
{
// ConnOutputs conserved
if (np in c.PortSource) && (c.PortSource[np].n in e.sc) {
assert np in new_c.PortSource;
assert new_c.PortSource[np].n in e.sc;
}
if (np in new_c.PortSource) && (new_c.PortSource[np].n in e.sc) {
assert new_c.PortSource[np] !in connection.Values by {
reveal NPsNotInSc();
}
assert c.PortSource[np].n in e.sc;
assert np in c.PortSource;
}
}
reveal ConnInputs();
reveal UnconnInputs();
reveal ConnOutputs();
}
lemma ConnectCircuitOtherScufValid(c: Circuit, connection: map<NP, NP>, e: Scuf)
requires c.Valid()
requires ConnectCircuitRequirements(c, connection)
requires e.Valid(c)
requires NPsNotInSc(e.sc, connection.Keys)
requires NPsNotInSc(e.sc, connection.Values)
ensures
var new_c := ConnectCircuit(c, connection);
&& e.Valid(new_c)
{
ConnectEntitiesOtherConnUnchanged(c, connection, e);
var new_c := ConnectCircuit(c, connection);
assert ScValid(new_c, e.sc) by {
reveal ScValid();
}
assert e.SomewhatValid(new_c) by {
reveal Scuf.SomewhatValid();
assert ScValid(new_c, e.sc);
assert (AllONPs(new_c, e.sc) >= Seq.ToSet(e.mp.outputs) >= ConnOutputs(new_c, e.sc)) by {
reveal AllONPs();
assert new_c.NodeKind == c.NodeKind;
}
assert (Seq.ToSet(e.mp.inputs) == AllInputs(new_c, e.sc));
assert (Seq.ToSet(e.mp.state) == AllSeq(new_c, e.sc)) by {
reveal AllSeq();
}
}
assert NoInternalConnections(connection, e.sc) by {
reveal NPsNotInSc();
reveal NoInternalConnections();
}
ConnectCircuitConservesSubcircuit(c, connection, e.sc);
assert OutputsInFOutputs(new_c, e) by {
reveal Scuf.SomewhatValid();
assert OutputsInFOutputs(c, e);
reveal ConnOutputs();
assert ConnOutputs(new_c, e.sc) == ConnOutputs(c, e.sc);
}
ScufConserved(c, new_c, e);
}
lemma ConnectCircuitConservesSubcircuit(c: Circuit, connection: map<NP, NP>, sc: set<CNode>)
requires c.Valid()
requires ConnectCircuitRequirements(c, connection)
requires ScValid(c, sc)
requires NoInternalConnections(connection, sc)
ensures SubcircuitConserved(c, ConnectCircuit(c, connection), sc)
{
reveal NoInternalConnections();
var ca := c;
var cb := ConnectCircuit(c, connection);
reveal ScValid();
assert (forall n :: n in sc ==> n in cb.NodeKind);
assert (forall n :: n in sc ==> ca.NodeKind[n] == cb.NodeKind[n]);
assert (forall np: NP :: np.n in sc && np in ca.PortSource ==>
np in cb.PortSource && ca.PortSource[np] == cb.PortSource[np]);
assert (forall np: NP :: np.n in sc && np !in ca.PortSource && np in cb.PortSource ==>
cb.PortSource[np].n !in sc);
reveal SubcircuitConserved();
}
opaque predicate NoInternalConnections(connection: map<NP, NP>, sc: set<CNode>)
{
&& (forall np :: np in connection.Keys && np.n in sc ==> connection[np].n !in sc)
}
// opaque predicate ConnectionValuesInFOutputs(connection: map<NP, NP>, e: Scuf)
// {
// && (forall np :: np in connection.Values && np.n in e.sc ==> np in e.mf.outputs)
// }
predicate ConnectionsScufCompatible(connection: map<NP, NP>, e: Scuf)
{
// for e1
&& NoInternalConnections(connection, e.sc)
&& connection.Values <= Seq.ToSet(e.mp.outputs)
}
predicate ConnectionsScuf2Compatible(connection: map<NP, NP>, e: Scuf)
{
// for e2
&& NoInternalConnections(connection, e.sc)
&& NPsNotInSc(e.sc, connection.Values)
}
lemma ConnectCircuitEntitiesStillValid(c: Circuit, connection: map<NP, NP>, e: Scuf)
requires c.Valid()
requires ConnectCircuitRequirements(c, connection)
requires e.Valid(c)
requires ConnectionsScufCompatible(connection, e)
ensures e.Valid(ConnectCircuit(c, connection))
{
reveal NoInternalConnections();
var new_c := ConnectCircuit(c, connection);
ConnectCircuitConservesSubcircuit(c, connection, e.sc);
assert ScValid(new_c, e.sc) by {
reveal ScValid();
}
assert OutputsInFOutputs(new_c, e) by {
reveal ConnOutputs();
reveal Scuf.SomewhatValid();
assert OutputsInFOutputs(c, e);
//reveal ConnectionValuesInFOutputs();
//assert ConnectionValuesInFOutputs(connection, e);
}
ScufConserved(c, new_c, e);
}
lemma ConnectEntitiesIsIsland(c: Circuit, conn: ScufConnection)
requires ConnectEntitiesRequirements(c, conn)
ensures
var new_c := ConnectEntitiesImpl(c, conn);
IsIsland(new_c, conn.scuf_ab.sc)
{
reveal NPsInSc();
var new_c := ConnectEntitiesImpl(c, conn);
var e1 := conn.scuf_a;
var e2 := conn.scuf_b;
var e12 := conn.scuf_ab;
var sc1 := conn.scuf_a.sc;
var sc2 := conn.scuf_b.sc;
assert ScValid(c, sc1 + sc2) by {
reveal ScValid();
}
var sco := SubcircuitComplement(c, sc1 + sc2);
assert |sco * sc1| == 0;
assert |sco * sc2| == 0;
assert IsIsland(c, sc1);
assert IsIsland(c, sc2);
assert IsIsland(c, sc1 + sc2) by {
reveal IsIsland();
}
assert IsIsland(c, sco) by {
reveal ScValid();
IsIslandComplementIsIsland(c, sc1+sc2);
}
assert NoConnFromTo(c, sc1, sc2) by {reveal ScValid(); IsIslandNoConns(c, sc1, sc2);}
assert NoConnFromTo(c, sc1, sco) by {reveal ScValid(); IsIslandNoConns(c, sc1, sco);}
assert NoConnFromTo(c, sc2, sc1) by {reveal ScValid(); IsIslandNoConns(c, sc2, sc1);}
assert NoConnFromTo(c, sc2, sco) by {reveal ScValid(); IsIslandNoConns(c, sc2, sco);}
assert NoConnFromTo(c, sco, sc1) by {reveal ScValid(); IsIslandNoConns(c, sco, sc1);}
assert NoConnFromTo(c, sco, sc2) by {reveal ScValid(); IsIslandNoConns(c, sco, sc2);}
forall np: NP | np in new_c.PortSource
ensures np.n in sc1+sc2 ==> new_c.PortSource[np].n in sc1+sc2
ensures np.n !in sc1+sc2 ==> new_c.PortSource[np].n !in sc1+sc2
{
reveal Circuit.Valid();
reveal ConnectionValid();
reveal IsIsland();
reveal ConnectEntitiesImpl();
assert NodeValid(c, np.n);
InScOrComplement(c, sc1+sc2, np.n);
var connection := conn.GetConnection();
assert ConnectionValid(c, e1, e2, connection);
if np !in connection {
assert new_c.PortSource[np] == c.PortSource[np];
}
if np.n in sc1 {
assert np !in connection.Keys by {
ConnectionKeysInE2(c, e1, e2, connection);
reveal NPsInSc();
InThisNotInThat(np.n, e1.sc, e2.sc);
}
assert new_c.PortSource[np] == c.PortSource[np];
assert new_c.PortSource[np].n in sc1;
} else if np.n in sc2 {
if np in connection.Keys {
assert new_c.PortSource[np] == connection[np];
ConnectionValuesInE1(c, e1, e2, connection);
assert connection[np].n in sc1;
assert new_c.PortSource[np].n in sc1;
} else {
assert new_c.PortSource[np] == c.PortSource[np];
}
assert new_c.PortSource[np].n in sc1 + sc2;
} else {
assert np.n in sco;
assert np !in connection.Keys && np !in connection.Values by {
ConnectionKeysInE2(c, e1, e2, connection);
ConnectionValuesInE1(c, e1, e2, connection);
reveal NPsInSc();
}
assert new_c.PortSource[np] == c.PortSource[np];
assert new_c.PortSource[np].n !in sc1;
assert new_c.PortSource[np].n !in sc2;
}
}
reveal IsIsland();
assert e12.sc == sc1 + sc2 by {
reveal ConnectEntitiesImpl();
}
assert (forall np :: np in new_c.PortSource && np.n in e12.sc ==> new_c.PortSource[np].n in e12.sc);
assert (forall np :: np in new_c.PortSource && np.n !in e12.sc ==> new_c.PortSource[np].n !in e12.sc);
assert IsIsland(new_c, e12.sc);
}
lemma ConnectCircuitReqFromConnectEntitiesReq(c: Circuit, conn: ScufConnection)
requires ConnectEntitiesRequirements(c, conn)
ensures ConnectCircuitRequirements(c, conn.GetConnection())
{
reveal ConnectionValid();
reveal Scuf.SomewhatValid();
reveal ConnectCircuitRequirements();
var connection := conn.GetConnection();
ConnectionKeysINPs(c, conn.scuf_a, conn.scuf_b, connection);
ConnectionValuesONPs(c, conn.scuf_a, conn.scuf_b, connection);
reveal INPsValid();
reveal ONPsValid();
SetsNoIntersectionDuh(connection.Keys, c.PortSource.Keys);
assert (forall np :: np in connection.Keys ==> INPValid(c, np) && np !in c.PortSource);
assert (forall np :: np in connection.Values ==> ONPValid(c, np));
}
opaque function ConnectEntitiesImpl(
c: Circuit, conn: ScufConnection): (r: Circuit)
requires ConnectEntitiesRequirements(c, conn)
ensures r.Valid()
ensures r.NodeKind == c.NodeKind
{
var connection := conn.GetConnection();
assert ConnectCircuitRequirements(c, connection) by {
ConnectCircuitReqFromConnectEntitiesReq(c, conn);
}
var new_c := ConnectCircuit(c, connection);
new_c
}
lemma NPSetsNoIntersection(c: Circuit, conn: ScufConnection, nps1: set<NP>, nps2: set<NP>)
requires ConnectEntitiesRequirements(c, conn)
requires NPsInSc(conn.scuf_a.sc, nps1)
requires NPsInSc(conn.scuf_b.sc, nps2)
ensures SetsNoIntersection(nps1, nps2)
{
reveal NPsInSc();
var e1 := conn.scuf_a;
var e2 := conn.scuf_b;
if exists np :: np in nps1 && np in nps2 {
var np :| np in nps1 && np in nps2;
assert np.n in e1.sc && np.n in e2.sc;
assert SetsNoIntersection(e1.sc, e2.sc);
NotInBoth(np.n, e1.sc, e2.sc);
assert false;
}
}
lemma ReorderSets<T>(a: set<T>, b: set<T>, c: set<T>)
requires SetsNoIntersection(b, c)
ensures (a - b) + c == (a + c) - b
{
SetsNoIntersectionDuh(b, c);
assert !exists x :: x in b && x in c;
}
lemma ReorderSets2<T>(a: set<T>, b: set<T>, c: set<T>)
requires SetsNoIntersection(a, c)
ensures (a + b) - c == a + (b - c)
{
SetsNoIntersectionDuh(a, c);
assert !exists x :: x in a && x in c;
}
lemma ConnectEntitiesSomewhatValid(c: Circuit, conn: ScufConnection)
requires ConnectEntitiesRequirements(c, conn)
ensures
var new_c := ConnectEntitiesImpl(c, conn);
conn.scuf_ab.SomewhatValid(new_c)
{
var e1 := conn.scuf_a;
var e2 := conn.scuf_b;
var e12 := conn.scuf_ab;
ConnectEntitiesEntitiesStillValid(c, conn);
var new_c := ConnectEntitiesImpl(c, conn);
var connection := conn.GetConnection();
assert ScValid(new_c, e12.sc) && ScValid(new_c, e1.sc) && ScValid(new_c, e2.sc) by {
reveal ScValid();
reveal ConnectEntitiesImpl();
}
assert (AllONPs(new_c, e12.sc) >= Seq.ToSet(e12.mp.outputs)) by {
reveal AllONPs();
reveal Seq.ToSet();
assert AllONPs(new_c, e12.sc) == AllONPs(new_c, e1.sc) + AllONPs(new_c, e2.sc);
assert Seq.ToSet(e12.mp.outputs) <= Seq.ToSet(e1.mp.outputs) + Seq.ToSet(e2.mp.outputs);
calc {
AllONPs(new_c, e12.sc);
==
AllONPs(new_c, e1.sc) + AllONPs(new_c, e2.sc);
>=
{
reveal Scuf.SomewhatValid();
assert AllONPs(new_c, e1.sc) >= Seq.ToSet(e1.mp.outputs);
assert AllONPs(new_c, e2.sc) >= Seq.ToSet(e2.mp.outputs);
}
Seq.ToSet(e1.mp.outputs) + Seq.ToSet(e2.mp.outputs);
>=
Seq.ToSet(e12.mp.outputs);
}
}
assert (Seq.ToSet(e12.mp.outputs) >= ConnOutputs(new_c, e12.sc)) by {
ConnectEntitiesIsIsland(c, conn);
IsIslandNoOutputs(new_c, e12.sc);
assert |ConnOutputs(new_c, e12.sc)| == 0;
}
assert (Seq.ToSet(e12.mp.state) == AllSeq(new_c, e12.sc)) by {
reveal Seq.ToSet();
reveal AllSeq();
reveal ConnectEntitiesImpl();
reveal Scuf.SomewhatValid();
}
//ConnectEntitiesFOutputsCorrect(c, e1, e2, connection);
assert (Seq.ToSet(e12.mp.inputs) == AllInputs(new_c, e12.sc)) by {
calc {
AllInputs(new_c, e12.sc);
UnconnInputs(new_c, e12.sc) + ConnInputs(new_c, e12.sc);
{
reveal ScValid();
reveal UnconnInputs();
reveal ConnectEntitiesImpl();
assert UnconnInputs(new_c, e12.sc) == UnconnInputs(c, e12.sc)-connection.Keys;
}
(UnconnInputs(c, e12.sc)-connection.Keys) + ConnInputs(new_c, e12.sc);
{
ConnectEntitiesIsIsland(c, conn);
IsIslandNoInputs(new_c, e12.sc);
reveal IsIsland();
reveal ConnInputs();
assert |ConnInputs(new_c, e12.sc)| == 0;
}
(UnconnInputs(c, e12.sc)-connection.Keys);
{
reveal SeqInputs();
reveal ConnectEntitiesImpl();
assert SeqInputs(new_c, e12.sc) == SeqInputs(c, e12.sc);
}
(UnconnInputs(c, e12.sc)-connection.Keys);
{
UnconnInputsAdd(c, e1.sc, e2.sc);
reveal ConnectEntitiesImpl();
assert UnconnInputs(c, e12.sc) == UnconnInputs(c, e1.sc) + UnconnInputs(c, e2.sc);
}
((UnconnInputs(c, e1.sc)+UnconnInputs(c, e2.sc))-connection.Keys);
{
assert ConnectionValid(c, e1, e2, connection) by {
reveal ConnectionValid();
}
ConnectionKeysInE2(c, e1, e2, connection);
NPSetsNoIntersection(c, conn, UnconnInputs(c, e1.sc), connection.Keys);
assert |UnconnInputs(c, e1.sc) * connection.Keys| == 0;
ReorderSets2(UnconnInputs(c, e1.sc), UnconnInputs(c, e2.sc), connection.Keys);
}
UnconnInputs(c, e1.sc)+(UnconnInputs(c, e2.sc)-connection.Keys);
(UnconnInputs(c, e1.sc) + ((UnconnInputs(c, e2.sc)-connection.Keys)));
{
assert ConnectionValid(c, e1, e2, connection) by {
reveal ConnectionValid();
}
ConnectionKeysINPs(c, e1, e2, connection);
}
UnconnInputs(c, e1.sc) + (UnconnInputs(c, e2.sc) - connection.Keys);
{
reveal IsIsland();
reveal ConnInputs();
assert |ConnInputs(c, e1.sc)| == 0;
assert |ConnInputs(c, e2.sc)| == 0;
}
AllInputs(c, e1.sc) + (AllInputs(c, e2.sc) - connection.Keys);
{
reveal Scuf.SomewhatValid();
}
Seq.ToSet(e1.mp.inputs) + (Seq.ToSet(e2.mp.inputs) - connection.Keys);
{
reveal ConnectEntitiesImpl();
}
Seq.ToSet(e12.mp.inputs);
}
}
reveal Scuf.SomewhatValid();
}
lemma ConnectEntitiesEntitiesStillValid(c: Circuit, conn: ScufConnection)
requires ConnectEntitiesRequirements(c, conn)
ensures
&& ConnectCircuitRequirements(c, conn.GetConnection())
&& var new_c := ConnectEntitiesImpl(c, conn);
&& conn.scuf_a.Valid(new_c)
&& conn.scuf_b.Valid(new_c)
{
var e1 := conn.scuf_a;
var e2 := conn.scuf_b;
var new_c := ConnectEntitiesImpl(c, conn);
ConnectCircuitReqFromConnectEntitiesReq(c, conn);
var connection := conn.GetConnection();
assert connection.Values <= Seq.ToSet(e1.mp.outputs);
assert new_c == ConnectCircuit(c, connection) by {
reveal ConnectEntitiesImpl();
}
assert NoInternalConnections(connection, e1.sc) by {
reveal NoInternalConnections();
reveal ConnectionValid();
ConnectionKeysInE2(c, e1, e2, connection);
forall np | np in connection.Keys
ensures np.n !in e1.sc
{
assert SetsNoIntersection(e1.sc, e2.sc);
SetsNoIntersectionSymm(e1.sc, e2.sc);
reveal NPsInSc();
assert np.n in e2.sc;
InThisNotInThat(np.n, e2.sc, e1.sc);
}
}
assert connection.Values <= Seq.ToSet(e1.mp.outputs) by {
reveal ConnectionValid();
}
ConnectCircuitEntitiesStillValid(c, connection, e1);
assert ConnectionsScufCompatible(connection, e1);
assert NoInternalConnections(connection, e2.sc) by {
reveal NoInternalConnections();
reveal ConnectionValid();
ConnectionValuesInE1(c, e1, e2, connection);
forall np | np in connection.Values
ensures np.n !in e2.sc
{
assert SetsNoIntersection(e1.sc, e2.sc);
reveal NPsInSc();
assert np.n in e1.sc;
InThisNotInThat(np.n, e1.sc, e2.sc);
}
}
ConnectCircuitConservesSubcircuit(c, connection, e2.sc);
assert ScValid(new_c, e2.sc) by {
reveal ScValid();
}
assert OutputsInFOutputs(new_c, e2) by {
assert OutputsInFOutputs(c, e2) by {
reveal Scuf.SomewhatValid();
}
assert connection.Values <= Seq.ToSet(conn.scuf_a.mp.outputs);
assert AllONPs(c, e1.sc) >= Seq.ToSet(e1.mp.outputs) by {
reveal Scuf.SomewhatValid();
}
assert NPsInSc(e1.sc, connection.Values) by {
reveal AllONPs();
reveal NPsInSc();
}
assert NPsNotInSc(e2.sc, connection.Values) by {
reveal NPsInSc();
reveal NPsNotInSc();
}
assert ConnOutputs(c, e2.sc) == ConnOutputs(new_c, e2.sc) by {
reveal NPsNotInSc();
reveal ConnOutputs();
}
}
ScufConserved(c, new_c, e2);
}
}