Repository navigation
Expand file tree
/
Copy pathPROOF.bend
More file actions
16078 lines (12111 loc) · 477 KB
/
Copy pathPROOF.bend
File metadata and controls
16078 lines (12111 loc) · 477 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
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
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import ./src/core/cad-install.bend as CADINSTALL
import ./src/server/wire.bend as WIRE
import ./src/server/watch-plan.bend as WATCHPLAN
import ./src/server/review-window.bend as REVIEWWINDOW
import ./src/server/db.bend as HISTORYDB
import ./test/conversation-proof/window_final.bend as CONVROOT
import ./test/conversation-proof/floor_shape_only.bend as CONVSHAPE
import ./test/conversation-proof/production_clipping.bend as CONVPROOF
import ./src/server/conversation-frame.bend as CONVFRAME
import ./src/core/thin.bend as CONVINDEX
import ./src/core/account-fallback.bend as ACCOUNTRECOVERY
import ./src/core/mailtriage.bend as MTRI
import ./src/core/mailowner.bend as MAILOWN
import ./src/web/composer-bar.bend as CBAR
import ./src/core/outbox.bend as OB
import ./test/sync_report_proof.bend as SYNCREPORT
import ./test/ui_laws_proof.bend as UILAWS
import ./src/core/allowance.bend as ALLOWANCE
import ./src/core/lazy-tools.bend as LTOOLS
import ./src/core/range.bend as BRANGE
import ./src/core/vdict.bend as VDICT
import ./src/server/review-history.bend as REVIEWHISTORY
import ./src/server/thin-view.bend as THINREVIEW
import ./src/core/plot-error.bend as PLOTERROR
import ./src/web/workspace.bend as WSK
import ./src/core/search-fold.bend as SFOLD
import ./src/core/live-checkpoint.bend as LCP
import ./src/core/restartretry.bend as WDRETRY
import ./src/core/signal.bend as SIGREV
import ./test/liveness_proof.bend as LVPROOF
import ./src/core/liveness.bend as LIVEWATCH
import ./test/timeline_virtual_proof.bend as TLVIRTUALPROOF
import ./test/native_history_window_proof.bend as NATIVEHISTORYPROOF
import ./src/server/thin-actor.bend as CHATSIDE
import ./src/core/sidebar-read.bend as SIDEREAD
import Base
import ./src/core/wire-retention.bend as WRET
import ./src/server/modelcache.bend as MCACHE
import ./src/core/pathrecords.bend as PR
import ./src/server/thin-sidebar.bend as CHATDERIVED
import ./test/sidebar_input_proof.bend as SIDEINPUTPROOF
import ./src/core/thin.bend as THINL # S3 lazy thin index
import ./src/server/thin-mail.bend as TMAILL # S3 lazy mail cache
import ./src/core/storedb.bend as SDB # S1 indexed store
import ./test/mobile_loading_proof.bend as PRESENTPROOF
import ./src/core/mailcontinuity.bend as MCN
import ./test/mem_score_lazy_proof.bend as MSCORE
import ./src/core/refresh.bend as RFSH
import ./src/core/auth.bend as AUTH
import ./src/core/http.bend as HTTPAUTH
import ./src/core/pcb2d.bend as PCB2 # PCB viewer text
import ./src/app/side_rows.bend as SR
import ./src/app/side_row_types.bend as SRT
import ./src/gfx/draw.bend as D
import ./src/server/botnet.bend as MPLOG # mail perf runtime count
import ./src/server/server.bend as MPCREDIT # mail perf
import ./src/core/schematic.bend as SC # kicad fork viewers
import ./src/core/charter.bend as CH # mail 2c
import ./src/core/mailrun.bend as MRUN # mail 2c
import ./src/app/mailroom.bend as MRUI # mail ui
import ./src/server/mailstore.bend as MIX # mail index
import ./src/app/mm.bend as MM # window memos
import ./src/core/kexport.bend as KEX
import ./src/core/i18n.bend as I18
import ./test/fixtures/i18n_fallback.bend as I18F
import ./src/core/mail.bend as ML # mail 1
import ./src/core/mailbody.bend as MB # mail 2a
import ./src/core/mailview.bend as MVW # mail view
import ./src/core/ref.bend as MREF # mail 2b
import ./src/core/stamp.bend as STP
import ./src/core/subs.bend as SUBSTEP
import ./src/core/kihealth.bend as KH
import ./src/core/tz.bend as TZ
import ./src/core/when.bend as WH
import ./src/core/sched.bend as SCH
import ./src/core/locks.bend as LCK
import ./src/gfx/text.bend as X
import ./src/core/bothub.bend as BHS
import ./src/core/bot.bend as BOT
import ./src/core/botui.bend as BU
import ./LAWS.bend as Laws
import ./src/core/model.bend as M
import ./src/app/viewer.bend as V
import ./src/core/board.bend as B
import ./src/core/semver.bend as SV
import ./src/app/nui.bend as N
import ./src/core/hub.bend as H
import ./src/core/ship.bend as SHP # deploy main
import ./src/core/refs.bend as RF
import ./src/core/todo.bend as TD
import ./src/core/acp.bend as AC
import ./src/core/mcp.bend as MC
import ./src/core/ride.bend as RD
import ./src/core/handoff.bend as HD
import ./src/core/agent.bend as AG
import ./src/core/fuzzy.bend as FZ
import ./src/mobile/notify.bend as Nt
import ./src/core/notice.bend as NO
import ./src/core/codec.bend as C
import ./src/core/json.bend as J
import ./src/core/attach.bend as AT
import ./src/core/svg.bend as SVG
import ./src/core/lightbox.bend as LBX
import ./src/core/links.bend as LK
import ./src/web/dom.bend as DM
import ./src/core/tailnet.bend as TN
import ./src/gfx/tiles.bend as T
import ./src/gfx/raster.bend as R
import ./src/gfx/font.bend as F
import ./src/app/layout.bend as L
import ./src/core/eq.bend as Q
import ./src/server/thin-content-eq.bend as CONTENTEQ # view delta (H)
import ./src/server/thin-delta.bend as VDELTA # view delta (H)
import ./src/core/gh.bend as GH
import ./src/core/fold.bend as FO
import ./src/core/subs.bend as SB
import ./src/core/plot.bend as PL
import ./src/core/look.bend as LO
import ./src/core/hist.bend as HS
import ./src/mobile/view.bend as MV
import ./src/core/pcb3d.bend as P3
import ./src/gfx/mesh.bend as MS
import ./src/gfx/face.bend as FA
import ./src/core/glb.bend as G
import ./src/mobile/picker.bend as MP
import ./src/mobile/hubs.bend as Hb
import ./src/mobile/bots.bend as MBN
import ./src/core/space.bend as SPC
import ./src/core/client.bend as U
import ./src/core/menu.bend as MN
import ./src/core/hier.bend as HI
import ./src/core/boot.bend as BT
import ./src/core/store.bend as ST
import ./src/core/thin.bend as JTHIN # J2: JS stack
import ./src/core/sign.bend as SG
import ./src/core/cron.bend as CR
import ./src/core/google.bend as GO
import ./src/core/cat.bend as CAT
import ./src/core/voice.bend as VO
import ./src/core/once.bend as ON
import ./src/core/bom.bend as BOM
import ./src/core/cad.bend as CAD
import ./src/core/checks.bend as CHK
import ./src/core/release.bend as REL
import ./src/core/plane.bend as PLN
import ./src/core/uber.bend as UBR
import ./src/core/ubersync.bend as UBS
import ./src/core/ubop.bend as UBO
import ./test/sidebar_content_proof.bend as CONTENTPROOF
import ./test/sidebar_full_branch_test.bend as FULLBRANCH
import ./test/sidebar_draft_image_test.bend as SIDEDRAFTPROOF
import ./test/secret_proof.bend as SECPROOF
import ./test/secret_box_proof.bend as SECBP
import ./src/core/landing.bend as LAND
import ./src/server/cacheio.bend as CACHEIO
import ./src/server/static-http.bend as STATICHTTP
import ./src/server/host.bend as STATICIO
# Lemmas
# ------
law bool_cmp_refl:
for +b: Bool
{Bool.cmp(b, b) == EQ{} : Cmp}
def bool_cmp_refl(b):
match b:
case False{}:
{==}
case True{}:
{==}
law word_cmp_refl:
for n: Nat
for +w: Word(n)
{Word.cmp(n, w, w) == EQ{} : Cmp}
def word_cmp_refl(n, w):
match n:
case 0n:
{==}
case 1n+p:
match w:
case WCon{+b, +t}:
%Equal.sym(Cmp, Word.cmp(p, t, t), EQ{}, word_cmp_refl(p, t)) : {Word.cmp.fin(b, b, _) == EQ{} : Cmp}
bool_cmp_refl(b)
law u32_cmp_refl:
for +x: U32
{U32.cmp(x, x) == EQ{} : Cmp}
def u32_cmp_refl(x):
match x:
case U32{+w}:
word_cmp_refl(32n, w)
# a string compares equal to itself, handing both copies back
law string_cmp_refl:
for +s: String
{String.cmp(s, s) == ((s, s), EQ{}) : (String & String) & Cmp}
def string_cmp_refl(s):
match s:
case SNil{}:
{==}
case SCon{+h, +t}:
match h:
case Chr{+x}:
%Equal.sym(Cmp, U32.cmp(x, x), EQ{}, u32_cmp_refl(x)) : {String.cmp.fin(t, t, ((Chr{x}, Chr{x}), _)) == ((SCon{Chr{x}, t}, SCon{Chr{x}, t}), EQ{}) : (String & String) & Cmp}
%Equal.sym((String & String) & Cmp, String.cmp(t, t), ((t, t), EQ{}), string_cmp_refl(t)) : {String.cmp.rec(Chr{x}, Chr{x}, _) == ((SCon{Chr{x}, t}, SCon{Chr{x}, t}), EQ{}) : (String & String) & Cmp}
{==}
# False is not True
def Bool.disc(b: Bool) -> Type:
match b:
case False{}:
Unit
case True{}:
Empty
law false_ne_true:
for e: {False{} == True{} : Bool}
Empty
def false_ne_true(e):
%e : Bool.disc(_)
Unit{}
# anything is at least zero
law ge_zero:
for +a: Nat
{Nat.is_ge(a, 0n) == True{} : Bool}
def ge_zero(a):
match a:
case 0n:
{==}
case 1n+p:
{==}
# n is never at least n + 1 + k
law ge_past:
for n: Nat
for +k: Nat
{Nat.is_ge(n, Nat.add(n, 1n+k)) == False{} : Bool}
def ge_past(n, k):
match n:
case 0n:
{==}
case 1n+p:
ge_past(p, k)
# moving the left side forward keeps a >= b
law ge_add:
for a: Nat
for b: Nat
for +d: Nat
for h: {Nat.is_ge(a, b) == True{} : Bool}
{Nat.is_ge(Nat.add(a, d), b) == True{} : Bool}
def ge_add(a, b, d, h):
match a b:
case 0n 0n:
ge_zero(d)
case 0n 1n+q:
Empty.absurd({Nat.is_ge(Nat.add(0n, d), 1n+q) == True{} : Bool}, false_ne_true(h))
case 1n+p 0n:
ge_zero(1n+Nat.add(p, d))
case 1n+p 1n+q:
ge_add(p, q, d, h)
law add_succ_r:
for a: Nat
for -b: Nat
{Nat.add(a, 1n+b) == 1n+Nat.add(a, b) : Nat}
def add_succ_r(a, b):
match a:
case 0n:
{==}
case 1n+p:
%add_succ_r(p, b) : {1n+Nat.add(p, 1n+b) == 1n+_ : Nat}
{==}
# x + y is one more than x + z when y is one more than z
law add_lift:
for x: Nat
for y: Nat
for z: Nat
for h: {y == 1n+z : Nat}
{Nat.add(x, y) == 1n+Nat.add(x, z) : Nat}
def add_lift(x, y, z, h):
%Equal.sym(Nat, y, 1n+z, h) : {Nat.add(x, _) == 1n+Nat.add(x, z) : Nat}
add_succ_r(x, z)
# one put adds exactly one thread to the shelves
law put_count:
for sh: M.Shelf
for -t: M.Thread
for s: M.Shelves
{M.Shelves.count(M.Shelves.put(sh, t, s)) == 1n+M.Shelves.count(s) : Nat}
def put_count(sh, t, s):
match sh s:
case M.Pinned{} M.Shelves{+p, +a, +st, +h, +sn}:
{==}
case M.Active{} M.Shelves{+p, +a, +st, +h, +sn}:
add_lift(List.length(&2, M.Thread, p), Nat.add(1n+List.length(&2, M.Thread, a), Nat.add(List.length(&2, M.Thread, st), Nat.add(List.length(&2, M.Thread, h), List.length(&2, M.Thread, sn)))), Nat.add(List.length(&2, M.Thread, a), Nat.add(List.length(&2, M.Thread, st), Nat.add(List.length(&2, M.Thread, h), List.length(&2, M.Thread, sn)))), {==})
case M.Settled{} M.Shelves{+p, +a, +st, +h, +sn}:
add_lift(List.length(&2, M.Thread, p), Nat.add(List.length(&2, M.Thread, a), Nat.add(1n+List.length(&2, M.Thread, st), Nat.add(List.length(&2, M.Thread, h), List.length(&2, M.Thread, sn)))), Nat.add(List.length(&2, M.Thread, a), Nat.add(List.length(&2, M.Thread, st), Nat.add(List.length(&2, M.Thread, h), List.length(&2, M.Thread, sn)))), add_lift(List.length(&2, M.Thread, a), Nat.add(1n+List.length(&2, M.Thread, st), Nat.add(List.length(&2, M.Thread, h), List.length(&2, M.Thread, sn))), Nat.add(List.length(&2, M.Thread, st), Nat.add(List.length(&2, M.Thread, h), List.length(&2, M.Thread, sn))), {==}))
case M.Hidden{} M.Shelves{+p, +a, +st, +h, +sn}:
add_lift(List.length(&2, M.Thread, p), Nat.add(List.length(&2, M.Thread, a), Nat.add(List.length(&2, M.Thread, st), Nat.add(1n+List.length(&2, M.Thread, h), List.length(&2, M.Thread, sn)))), Nat.add(List.length(&2, M.Thread, a), Nat.add(List.length(&2, M.Thread, st), Nat.add(List.length(&2, M.Thread, h), List.length(&2, M.Thread, sn)))), add_lift(List.length(&2, M.Thread, a), Nat.add(List.length(&2, M.Thread, st), Nat.add(1n+List.length(&2, M.Thread, h), List.length(&2, M.Thread, sn))), Nat.add(List.length(&2, M.Thread, st), Nat.add(List.length(&2, M.Thread, h), List.length(&2, M.Thread, sn))), add_lift(List.length(&2, M.Thread, st), Nat.add(1n+List.length(&2, M.Thread, h), List.length(&2, M.Thread, sn)), Nat.add(List.length(&2, M.Thread, h), List.length(&2, M.Thread, sn)), {==})))
case M.Snoozed{} M.Shelves{+p, +a, +st, +h, +sn}:
add_lift(List.length(&2, M.Thread, p), Nat.add(List.length(&2, M.Thread, a), Nat.add(List.length(&2, M.Thread, st), Nat.add(List.length(&2, M.Thread, h), 1n+List.length(&2, M.Thread, sn)))), Nat.add(List.length(&2, M.Thread, a), Nat.add(List.length(&2, M.Thread, st), Nat.add(List.length(&2, M.Thread, h), List.length(&2, M.Thread, sn)))), add_lift(List.length(&2, M.Thread, a), Nat.add(List.length(&2, M.Thread, st), Nat.add(List.length(&2, M.Thread, h), 1n+List.length(&2, M.Thread, sn))), Nat.add(List.length(&2, M.Thread, st), Nat.add(List.length(&2, M.Thread, h), List.length(&2, M.Thread, sn))), add_lift(List.length(&2, M.Thread, st), Nat.add(List.length(&2, M.Thread, h), 1n+List.length(&2, M.Thread, sn)), Nat.add(List.length(&2, M.Thread, h), List.length(&2, M.Thread, sn)), add_succ_r(List.length(&2, M.Thread, h), List.length(&2, M.Thread, sn)))))
# Laws
# ----
def Laws.string_eq_refl(s):
%Equal.sym((String & String) & Cmp, String.cmp(s, s), ((s, s), EQ{}), string_cmp_refl(s)) : {Cmp.is_eq(Pair.snd(String & String, Cmp, _)) == True{} : Bool}
{==}
def Laws.settle_at_window(last, w):
Nat.ge_refl(Nat.add(last, w))
def Laws.settle_fresh(now, w):
ge_past(now, w)
def Laws.settle_monotone(now, last, w, d, h):
ge_add(now, Nat.add(last, w), d, h)
def Laws.settle_never_running(now, w, pending, archived, o):
{==}
def Laws.settle_never_pending(t, p, archived, o, stale):
match t:
case M.Idle{}:
{==}
case M.Running{}:
{==}
case M.Completed{}:
{==}
case M.Interrupted{}:
{==}
case M.Failed{}:
{==}
def Laws.settle_respects_unsettle(busy, archived, stale):
match busy archived:
case False{} False{}:
{==}
case False{} True{}:
{==}
case True{} False{}:
{==}
case True{} True{}:
{==}
def Laws.sidebar_split_at_count(ts, navs, now):
match ts:
case Nil{}:
{==}
case +t <> +rest:
Equal.trans(Nat, M.Shelves.count(M.Shelves.put(M.Shelf.at(t, M.Nav.until(M.Nav.get(navs, M.Thread.id(t))), now), t, M.Sidebar.split.at(rest, navs, now))),
1n+M.Shelves.count(M.Sidebar.split.at(rest, navs, now)), 1n+List.length(&2, M.Thread, rest),
put_count(M.Shelf.at(t, M.Nav.until(M.Nav.get(navs, M.Thread.id(t))), now), t, M.Sidebar.split.at(rest, navs, now)),
Equal.cong(Nat, Nat, x => 1n+x, M.Shelves.count(M.Sidebar.split.at(rest, navs, now)), List.length(&2, M.Thread, rest),
Laws.sidebar_split_at_count(rest, navs, now)))
def Laws.settle_never_snoozed(now, w, t, until, h):
%Equal.sym(Bool, Nat.is_ge(now, until), False{}, h) : {M.Settle.auto.s(Bool.not(_), now, w, t, until) == False{} : Bool}
{==}
def Laws.snooze_wakes(now, until, h):
%Equal.sym(Bool, Nat.is_ge(now, until), True{}, h) : {Bool.not(_) == False{} : Bool}
{==}
def Laws.replay_snoc(es, s, e):
match es:
case Nil{}:
{==}
case h <> t:
Laws.replay_snoc(t, M.State.apply(s, h), e)
def Laws.sidebar_split_count(ts):
match ts:
case Nil{}:
{==}
case +t <> +rest:
Equal.trans(Nat, M.Shelves.count(M.Shelves.put(M.Shelf.of(t), t, M.Sidebar.split(rest))),
1n+M.Shelves.count(M.Sidebar.split(rest)), 1n+List.length(&2, M.Thread, rest),
put_count(M.Shelf.of(t), t, M.Sidebar.split(rest)),
Equal.cong(Nat, Nat, x => 1n+x, M.Shelves.count(M.Sidebar.split(rest)), List.length(&2, M.Thread, rest),
Laws.sidebar_split_count(rest)))
# Viewer lemmas
# -------------
law sub_self:
for a: Nat
{Nat.sub(a, a) == 0n : Nat}
def sub_self(a):
match a:
case 0n:
{==}
case 1n+p:
sub_self(p)
law key_fin_rec:
for -h1: Char
for -h2: Char
for r: (String & String) & Cmp
{V.Key.cmp.fin(String.cmp.rec(h1, h2, r)) == V.Key.cmp.fin(r) : Cmp}
def key_fin_rec(h1, h2, r):
match r:
case (ab, c):
match ab:
case (a, b):
{==}
# a key is in order with itself
law key_cmp_refl:
for +s: String
{V.Key.cmp(s, s) == EQ{} : Cmp}
def key_cmp_refl(s):
match s:
case SNil{}:
{==}
case SCon{+h, +t}:
match h:
case Chr{+x}:
%Equal.sym(Cmp, U32.cmp(x, x), EQ{}, u32_cmp_refl(x)) : {V.Key.cmp.fin(String.cmp.fin(t, t, ((Chr{x}, Chr{x}), _))) == EQ{} : Cmp}
Equal.trans(Cmp, V.Key.cmp.fin(String.cmp.rec(Chr{x}, Chr{x}, String.cmp(t, t))),
V.Key.cmp.fin(String.cmp(t, t)), EQ{},
key_fin_rec(Chr{x}, Chr{x}, String.cmp(t, t)), key_cmp_refl(t))
law u32_eq_refl:
for +x: U32
{U32.is_eq(x, x) == True{} : Bool}
def u32_eq_refl(x):
%Equal.sym(Cmp, U32.cmp(x, x), EQ{}, u32_cmp_refl(x)) : {Cmp.is_eq(_) == True{} : Bool}
{==}
# the scene order puts an item level with itself
law scene_cmp_refl:
for +k: String
for +l: U32
{V.Scene.cmp.k(U32.cmp(l, l), k, k) == EQ{} : Cmp}
def scene_cmp_refl(k, l):
%Equal.sym(Cmp, U32.cmp(l, l), EQ{}, u32_cmp_refl(l)) : {V.Scene.cmp.k(_, k, k) == EQ{} : Cmp}
key_cmp_refl(k)
# Viewer laws
# -----------
def Laws.fade_done(born, k):
%Equal.sym(Bool, Nat.is_ge(Nat.add(Nat.add(born, V.Fade.ms()), k), Nat.add(born, V.Fade.ms())), True{},
ge_add(Nat.add(born, V.Fade.ms()), Nat.add(born, V.Fade.ms()), k, Nat.ge_refl(Nat.add(born, V.Fade.ms()))))
: {V.Fade.alpha.k(_, Nat.sub(Nat.add(Nat.add(born, V.Fade.ms()), k), born)) == 255 : U32}
{==}
# on the dark ground the look is the kind's own, comparison or not
law look_dark_own:
for d: Bool
for +kind: U32
for +layer: U32
{LO.Look.of.t.d(d, False{}, kind, layer) == LO.Look.of.d(d, kind, layer) : U32 & U32}
def look_dark_own(d, kind, layer):
match d:
case True{}:
{==}
case False{}:
{==}
def Laws.look_flip_none(kind, layer):
look_dark_own(LO.Look.is_diff(kind), kind, layer)
def Laws.look_flip_hides():
{==}
def Laws.look_flip_shows():
{==}
def Laws.look_light_same_alpha():
{==}
def Laws.look_grounds_not_layers():
{==}
def Laws.theme_dark_as_is(c):
{==}
def Laws.look_flip_twice():
{==}
def Laws.ops_hidden_draws_nothing(p, l, v, c, now, born, kind, flip, rest, h):
%Equal.sym(Bool, V.Look.shows(kind, l, flip), False{}, h)
: {V.Ops.cull(Bool.and(_, Nat.is_lt(U32.to_nat(l), V.Look.count(kind))), p, l, v, c, V.Fade.alpha(now, born), kind, flip, rest) == rest : List<&2, R.Op>}
{==}
def Laws.pick_hidden_skipped(hit, area, key, bk, ba):
match hit:
case True{}:
{==}
case False{}:
{==}
def Laws.fade_start(born):
%Equal.sym(Bool, Nat.is_ge(born, Nat.add(born, V.Fade.ms())), False{}, ge_past(born, 219n))
: {V.Fade.alpha.k(_, Nat.sub(born, born)) == 0 : U32}
%Equal.sym(Nat, Nat.sub(born, born), 0n, sub_self(born)) : {V.Fade.alpha.k(False{}, _) == 0 : U32}
{==}
def Laws.scene_merge_self(ss, now):
match ss:
case Nil{}:
{==}
case V.Seen{B.Item{+k, +s, +l, +p, +i}, +b} <> +t:
%Equal.sym(Cmp, V.Scene.cmp.k(U32.cmp(l, l), k, k), EQ{}, scene_cmp_refl(k, l))
: {V.Scene.merge(V.Seen{B.Item{k, s, l, p, i}, b} <> t, B.Item{k, s, l, p, i} <> V.Scene.items(t), _, now) == V.Seen{B.Item{k, s, l, p, i}, b} <> t : List<&2, V.Seen>}
%Equal.sym(Bool, U32.is_eq(s, s), True{}, u32_eq_refl(s))
: {V.Scene.keep(_, B.Item{k, s, l, p, i}, b, now) <> V.Scene.merge(t, V.Scene.items(t), V.Scene.heads(t, V.Scene.items(t)), now) == V.Seen{B.Item{k, s, l, p, i}, b} <> t : List<&2, V.Seen>}
Equal.cong(List<&2, V.Seen>, List<&2, V.Seen>, xs => V.Seen{B.Item{k, s, l, p, i}, b} <> xs,
V.Scene.merge(t, V.Scene.items(t), V.Scene.heads(t, V.Scene.items(t)), now), t, Laws.scene_merge_self(t, now))
# Update lemmas and laws
# ----------------------
law nat_cmp_refl:
for a: Nat
{Nat.cmp(a, a) == EQ{} : Cmp}
def nat_cmp_refl(a):
match a:
case 0n:
{==}
case 1n+p:
nat_cmp_refl(p)
law pre_cmp_refl:
for b: Bool
{SV.Ver.pre_cmp(b, b) == EQ{} : Cmp}
def pre_cmp_refl(b):
match b:
case True{}:
{==}
case False{}:
{==}
def Laws.semver_cmp_refl(v):
match v:
case SV.Ver{+a, +b, +c, +p, +d, +n}:
%Equal.sym(Cmp, Nat.cmp(a, a), EQ{}, nat_cmp_refl(a)) : {SV.Ver.then(_, SV.Ver.then(Nat.cmp(b, b), SV.Ver.then(Nat.cmp(c, c), SV.Ver.then(SV.Ver.pre_cmp(p, p), SV.Ver.then(Nat.cmp(d, d), Nat.cmp(n, n)))))) == EQ{} : Cmp}
%Equal.sym(Cmp, Nat.cmp(b, b), EQ{}, nat_cmp_refl(b)) : {SV.Ver.then(_, SV.Ver.then(Nat.cmp(c, c), SV.Ver.then(SV.Ver.pre_cmp(p, p), SV.Ver.then(Nat.cmp(d, d), Nat.cmp(n, n))))) == EQ{} : Cmp}
%Equal.sym(Cmp, Nat.cmp(c, c), EQ{}, nat_cmp_refl(c)) : {SV.Ver.then(_, SV.Ver.then(SV.Ver.pre_cmp(p, p), SV.Ver.then(Nat.cmp(d, d), Nat.cmp(n, n)))) == EQ{} : Cmp}
%Equal.sym(Cmp, SV.Ver.pre_cmp(p, p), EQ{}, pre_cmp_refl(p)) : {SV.Ver.then(_, SV.Ver.then(Nat.cmp(d, d), Nat.cmp(n, n))) == EQ{} : Cmp}
%Equal.sym(Cmp, Nat.cmp(d, d), EQ{}, nat_cmp_refl(d)) : {SV.Ver.then(_, Nat.cmp(n, n)) == EQ{} : Cmp}
nat_cmp_refl(n)
def Laws.update_never_same(v):
%Equal.sym(Cmp, SV.Ver.cmp(v, v), EQ{}, Laws.semver_cmp_refl(v)) : {Cmp.is_gt(_) == False{} : Bool}
{==}
def Laws.update_off_managed(c, t, a):
{==}
def Laws.update_appimage_managed(o, c, t):
match o:
case SNil{}:
{==}
case SCon{h, r}:
{==}
law nat_cmp_succ:
for n: Nat
{Nat.cmp(1n+n, n) == GT{} : Cmp}
def nat_cmp_succ(n):
match n:
case 0n:
{==}
case 1n+p:
nat_cmp_succ(p)
def Laws.semver_pre_before_release(a, b, c, d, n):
%Equal.sym(Cmp, Nat.cmp(a, a), EQ{}, nat_cmp_refl(a)) : {Cmp.is_gt(SV.Ver.then(_, SV.Ver.then(Nat.cmp(b, b), SV.Ver.then(Nat.cmp(c, c), SV.Ver.then(GT{}, SV.Ver.then(Nat.cmp(0n, d), Nat.cmp(0n, n))))))) == True{} : Bool}
%Equal.sym(Cmp, Nat.cmp(b, b), EQ{}, nat_cmp_refl(b)) : {Cmp.is_gt(SV.Ver.then(_, SV.Ver.then(Nat.cmp(c, c), SV.Ver.then(GT{}, SV.Ver.then(Nat.cmp(0n, d), Nat.cmp(0n, n)))))) == True{} : Bool}
%Equal.sym(Cmp, Nat.cmp(c, c), EQ{}, nat_cmp_refl(c)) : {Cmp.is_gt(SV.Ver.then(_, SV.Ver.then(GT{}, SV.Ver.then(Nat.cmp(0n, d), Nat.cmp(0n, n))))) == True{} : Bool}
{==}
def Laws.semver_nightly_later(a, b, c, d, n):
%Equal.sym(Cmp, Nat.cmp(a, a), EQ{}, nat_cmp_refl(a)) : {Cmp.is_gt(SV.Ver.then(_, SV.Ver.then(Nat.cmp(b, b), SV.Ver.then(Nat.cmp(c, c), SV.Ver.then(EQ{}, SV.Ver.then(Nat.cmp(d, d), Nat.cmp(1n+n, n))))))) == True{} : Bool}
%Equal.sym(Cmp, Nat.cmp(b, b), EQ{}, nat_cmp_refl(b)) : {Cmp.is_gt(SV.Ver.then(_, SV.Ver.then(Nat.cmp(c, c), SV.Ver.then(EQ{}, SV.Ver.then(Nat.cmp(d, d), Nat.cmp(1n+n, n)))))) == True{} : Bool}
%Equal.sym(Cmp, Nat.cmp(c, c), EQ{}, nat_cmp_refl(c)) : {Cmp.is_gt(SV.Ver.then(_, SV.Ver.then(EQ{}, SV.Ver.then(Nat.cmp(d, d), Nat.cmp(1n+n, n))))) == True{} : Bool}
%Equal.sym(Cmp, Nat.cmp(d, d), EQ{}, nat_cmp_refl(d)) : {Cmp.is_gt(SV.Ver.then(EQ{}, SV.Ver.then(_, Nat.cmp(1n+n, n)))) == True{} : Bool}
%Equal.sym(Cmp, Nat.cmp(1n+n, n), GT{}, nat_cmp_succ(n)) : {Cmp.is_gt(SV.Ver.then(EQ{}, SV.Ver.then(EQ{}, _))) == True{} : Bool}
{==}
def Laws.semver_nightly_next_day(a, b, c, d, n, m):
%Equal.sym(Cmp, Nat.cmp(a, a), EQ{}, nat_cmp_refl(a)) : {Cmp.is_gt(SV.Ver.then(_, SV.Ver.then(Nat.cmp(b, b), SV.Ver.then(Nat.cmp(c, c), SV.Ver.then(EQ{}, SV.Ver.then(Nat.cmp(1n+d, d), Nat.cmp(m, n))))))) == True{} : Bool}
%Equal.sym(Cmp, Nat.cmp(b, b), EQ{}, nat_cmp_refl(b)) : {Cmp.is_gt(SV.Ver.then(_, SV.Ver.then(Nat.cmp(c, c), SV.Ver.then(EQ{}, SV.Ver.then(Nat.cmp(1n+d, d), Nat.cmp(m, n)))))) == True{} : Bool}
%Equal.sym(Cmp, Nat.cmp(c, c), EQ{}, nat_cmp_refl(c)) : {Cmp.is_gt(SV.Ver.then(_, SV.Ver.then(EQ{}, SV.Ver.then(Nat.cmp(1n+d, d), Nat.cmp(m, n))))) == True{} : Bool}
%Equal.sym(Cmp, Nat.cmp(1n+d, d), GT{}, nat_cmp_succ(d)) : {Cmp.is_gt(SV.Ver.then(EQ{}, SV.Ver.then(EQ{}, SV.Ver.then(_, Nat.cmp(m, n))))) == True{} : Bool}
{==}
# Attachment lemmas and laws
# --------------------------
law attach_chr_ok:
for b: Bool
for +c: U32
for e: {AT.Att.ok(c) == b : Bool}
{AT.Att.ok(AT.Att.chr(b, c)) == True{} : Bool}
def attach_chr_ok(b, c, e):
match b:
case True{}:
e
case False{}:
{==}
def Laws.attach_clean_ok(s):
match s:
case SNil{}:
{==}
case SCon{Chr{+c}, t}:
%Equal.sym(Bool, AT.Att.ok(AT.Att.chr(AT.Att.ok(c), c)), True{}, attach_chr_ok(AT.Att.ok(c), c, {==})) : {Bool.and(_, AT.Att.all_ok(AT.Att.clean(t))) == True{} : Bool}
Laws.attach_clean_ok(t)
def Laws.drop_non_file_ignored(c, s, rest, h):
%Equal.sym(Bool, Char.is_eq(c, 'f'), False{}, h) : {AT.Att.uri.keep(String.starts_with.if(s, "ile:", _), SCon{c, s}, rest) == rest : List<&2, String>}
{==}
def Laws.drop_uri_list_example():
{==}
# Orchestration laws
# ------------------
def Laws.task_terminal_absorbing(cur, want, h):
match cur:
case M.TaskQueued{}:
Empty.absurd({M.TaskState.next(M.TaskQueued{}, want) == M.TaskQueued{} : M.TaskState}, false_ne_true(h))
case M.TaskRunning{}:
Empty.absurd({M.TaskState.next(M.TaskRunning{}, want) == M.TaskRunning{} : M.TaskState}, false_ne_true(h))
case M.TaskDone{}:
{==}
case M.TaskFailed{}:
{==}
case M.TaskCancelled{}:
{==}
def Laws.task_never_requeued():
{==}
def Laws.task_delivered_once(t):
match t:
case M.Task{_, _, _, _, st, _, _, _, _}:
match st:
case M.TaskQueued{}:
{==}
case M.TaskRunning{}:
{==}
case M.TaskDone{}:
{==}
case M.TaskFailed{}:
{==}
case M.TaskCancelled{}:
{==}
# n + k is never less than n
law lt_add_self:
for n: Nat
for +k: Nat
{Nat.is_lt(Nat.add(n, k), n) == False{} : Bool}
def lt_add_self(n, k):
match n:
case 0n:
match k:
case 0n:
{==}
case 1n+p:
{==}
case 1n+p:
lt_add_self(p, k)
def Laws.delegation_bounded(k):
lt_add_self(M.Task.max_depth(), k)
def Laws.setting_default(k, d):
{==}
def Laws.nui_with_own_vw(n):
match n:
case N.Nui{u, w, hh, mx, my, sd, sc, ca, fo, pa, hi, ms, vw}:
{==}
def Laws.stale_board_ignored(n, key, items, now, h):
%Equal.sym(Bool, N.Vw.fresh_for(N.Nui.vw(n), key), False{}, h) : {N.Nui.with_vw(n, N.Vw.if(_, N.Nui.vw(n), v => N.Vw.board.same(v, key, items, now))) == n : N.Nui}
Laws.nui_with_own_vw(n)
def Laws.resume_is_replay(a, b, s):
match a:
case Nil{}:
{==}
case h <> t:
Laws.resume_is_replay(t, b, M.State.apply(s, h))
def Laws.post_running_delivers(s, now, th, msg, role, text, h1, h2):
%Equal.sym(Bool, H.Hub.running(H.Hub.thread(s, th)), True{}, h1) : {H.Hub.post.w(_, M.Worktree.gone(H.Hub.thread(s, th)), M.Worktree.waits(s, H.Hub.thread(s, th), now), s, now, th, msg, role, text) == H.Hub.deliver.r(True{}, s, now, th, msg, role, text) : H.Step}
%Equal.sym(Bool, M.Worktree.waits(s, H.Hub.thread(s, th), now), False{}, h2) : {H.Hub.deliver(True{}, _, s, now, th, msg, role, text) == H.Hub.deliver.r(True{}, s, now, th, msg, role, text) : H.Step}
{==}
def Laws.deliver_held_go(b, th, now):
match b:
case True{}:
{==}
case False{}:
{==}
def Laws.deliver_held_steer(b1, b2, th, id, now):
match b1 b2:
case True{} True{}:
{==}
case True{} False{}:
{==}
case False{} True{}:
{==}
case False{} False{}:
{==}
def Laws.deliver_held_restart(b1, b2, b3, th, id, now, v, r):
match b1 b2 b3:
case True{} True{} True{}:
{==}
case True{} True{} False{}:
{==}
case True{} False{} True{}:
{==}
case True{} False{} False{}:
{==}
case False{} True{} True{}:
{==}
case False{} True{} False{}:
{==}
case False{} False{} True{}:
{==}
case False{} False{} False{}:
{==}
# A running non-Claude turn always takes automatic messages on its ride.
law ride_held_k:
for q: Bool
for +s: M.State
for +now: Nat
for +th: String
for +msg: String
for role: M.Role
for +text: String
{H.Deliver.held(H.Queue.changes(H.Hub.deliver.ride(q, s, now, th, msg, role, text))) == False{} : Bool}
def ride_held_k(q, s, now, th, msg, role, text):
match q:
case True{}:
{==}
case False{}:
{==}
# an idle thread: the turn starts, with whatever rode (nothing held)
law ride_post_held:
for e: Bool
for +s: M.State
for +now: Nat
for +th: String
for +msg: String
for role: M.Role
for +text: String
{H.Deliver.held(H.Queue.changes(H.Ride.post(e, s, now, th, msg, role, text))) == False{} : Bool}
def ride_post_held(e, s, now, th, msg, role, text):
match e:
case True{}:
Laws.deliver_held_go(String.is_empty(M.Queue.of(s, th)), th, now)
case False{}:
Laws.deliver_held_go(String.is_empty(M.Queue.join(M.Queue.of(s, th), RD.Ride.input(H.Ride.of(s, th)))), th, now)
def Laws.deliver_held_steer_k(c, s, now, th, msg, role, text):
match c:
case True{}:
Laws.deliver_held_go(String.is_empty(M.Queue.of(s, th)), th, now)
case False{}:
ride_held_k(String.is_empty(M.Queue.of(s, th)), s, now, th, msg, role, text)
def Laws.deliver_never_waits(run, s, now, th, msg, role, text):
match run:
case True{}:
Laws.deliver_held_steer_k(String.eq(H.Hub.provider(H.Hub.thread(s, th)), "claude"), s, now, th, msg, role, text)
case False{}:
ride_post_held(String.is_empty(H.Ride.of(s, th)), s, now, th, msg, role, text)
def Laws.deliver_claude_running():
{==}
def Laws.resend_stored_once(s, now, client, id, th, text, msg, h1, h2):
%Equal.sym(Bool, String.is_empty(msg), False{}, h1) : {H.Queue.changes(H.Hub.turn.m(s, now, client, id, th, text, Bool.pick(String, _, H.Hub.id("m", now, H.Hub.seq(s)), msg), Bool.not(_))) == [] : List<&2, M.Change>}
%Equal.sym(Bool, H.Hub.has_msg(H.Hub.entries(s), msg), True{}, h2) : {H.Queue.changes(H.Hub.turn.k(_, s, now, client, id, th, msg, text)) == [] : List<&2, M.Change>}
{==}
def Laws.has_msg_unnamed_skips(s, msg):
{==}
def Laws.mcp_last_newest():
{==}
def Laws.task_finish_not_ended_same(s, now, thread, cs, os, h):
%Equal.sym(H.Ended, H.Task.ended(cs), H.NotEnded{}, h) : {H.Task.finish.e(_, s, now, thread, cs, os) == H.Step{cs, os} : H.Step}
{==}
def Laws.inbox_running_delivers(s, now, from, to, role, text, msg, h1, h2):
%Equal.sym(Bool, H.Hub.running(H.Hub.thread(s, to)), True{}, h1) : {H.Hub.inbox.w(_, M.Worktree.gone(H.Hub.thread(s, to)), M.Worktree.waits(s, H.Hub.thread(s, to), now), s, now, from, to, role, text, msg) == H.Hub.deliver.r(True{}, s, now, to, msg, role, text) : H.Step}
%Equal.sym(Bool, M.Worktree.waits(s, H.Hub.thread(s, to), now), False{}, h2) : {H.Hub.deliver(True{}, _, s, now, to, msg, role, text) == H.Hub.deliver.r(True{}, s, now, to, msg, role, text) : H.Step}
{==}
law or_true_r:
for b: Bool
{Bool.or(b, True{}) == True{} : Bool}
def or_true_r(b):
match b:
case False{}:
{==}
case True{}:
{==}