Commit e4be440
feat(#92): widths need not agree for
Implements the #92 ruling across both engines, plus two bugs found while
verifying it.
## The rule
`T-Eq-Word` required both operands at the same width. That was inconsistent
with the rest of the language in four ways, all recorded in #92:
* `tComposeWord` already WIDENS to max n m — a program could compose two
braids it was then forbidden to compare;
* `~` accepted differing widths and, since TG-7, evaluates through the SAME
`Braid_equiv.equiv` — identical operands, identical answer, one rejected;
* `eqIdBraid`/`eqBraidId` decide "is this braid trivial?" against
`identity : word 0`, so under the old rule they could only ever fire when
the braid was empty — the step relation had rules for a question the
typing rule forbade asking;
* `braid_equiv.equiv` has no width parameter at all.
Lean `tEqWord` now takes (n m); `infer`'s `.eq` case drops the `if n = m`.
OCaml `Eq` mirrors it. Match arms join on width for words (max) and still
require exact agreement for everything else.
## The metatheory did not need patching
Progress, Preservation, Determinism, TypeSafety, infer_sound and
infer_complete all still hold — `lean Tangle.lean` reports 0 errors, and the
sorry/axiom gate passes. The `infer_sound` proof got SIMPLER: with no `if
n = m` there is no inner `split` left to case on, which is a decent sign the
restriction was load-bearing for nothing.
TG-3 regenerated and kernel-checked: 496 obligations, 0 errors. 46 of them
flipped from `= none` to `= some .bool` — precisely the `identity == braid`
shape that was previously unreachable.
## Two bugs found while verifying
1. STATEMENT ORDER. `parse_file_recovering` in bin/main.ml did
`stmts := prog @ !stmts` and then `List.rev` on the flattened result. That
reversal is right for an accumulator built by prepending single items — as
`diagnostics` is — but whole SEGMENTS were prepended, so every program came
out backwards: `def x; def y; def z` parsed to [z; y; x]. Any program whose
statements depend on order failed at evaluation with "Unbound variable".
The test suites never caught it because they call `Tangle.Parser.program`
directly; only the CLI goes through the recovering path. Now accumulates
segments and flattens in order.
2. A FALSE ASSERTION in examples/trefoil.tangle:
assert reversed == braid[s1, s1, s1]
`reverse` reverses the word AND negates exponents, so it yields the INVERSE
braid. writhe(trefoil) = 3 but writhe(reversed) = -3, and writhe is
invariant under the braid relations, so they cannot be equal. The assertion
had been wrong since it was written; nothing ran the examples until #89.
Corrected to braid[s1^-1, s1^-1, s1^-1], which passes.
## Result
examples evaluating : 2/7 -> 7/7 (all now in the must-run set)
lib/stdlib.tangle : did not typecheck -> typechecks
conformance : 18/19 (v11 add{} is the Harvard sub-language, #94)
## Trusted base
Registered as A-TG-92.1: the embedding Bn -> Bn+1 that justifies cross-width
comparison is standard mathematics but is asserted IN PROSE, not mechanised.
What is machine-checked is that the metatheory holds under the widened rule
and that OCaml still agrees with Lean on the corpus.
Tests: 6 new typecheck cases including two negatives (mismatched KINDS still
rejected; match arms of different kinds still rejected) so widening cannot
degrade into "anything compares to anything". Three test_check cases
repointed at an error that is still an error.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>==, and match arms join on width1 parent 1223ea6 commit e4be440
11 files changed
Lines changed: 212 additions & 97 deletions
File tree
- compiler
- bin
- lib
- test
- tg3
- examples
- proofs
- scripts
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
33 | 33 | | |
34 | 34 | | |
35 | 35 | | |
| 36 | + | |
36 | 37 | | |
37 | 38 | | |
38 | 39 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
49 | 49 | | |
50 | 50 | | |
51 | 51 | | |
52 | | - | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
53 | 64 | | |
54 | 65 | | |
55 | 66 | | |
56 | 67 | | |
57 | | - | |
| 68 | + | |
58 | 69 | | |
59 | 70 | | |
60 | 71 | | |
| |||
76 | 87 | | |
77 | 88 | | |
78 | 89 | | |
79 | | - | |
| 90 | + | |
| 91 | + | |
80 | 92 | | |
81 | 93 | | |
82 | 94 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
90 | 90 | | |
91 | 91 | | |
92 | 92 | | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
93 | 105 | | |
94 | 106 | | |
95 | 107 | | |
| |||
321 | 333 | | |
322 | 334 | | |
323 | 335 | | |
324 | | - | |
325 | | - | |
326 | 336 | | |
327 | 337 | | |
328 | 338 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
399 | 399 | | |
400 | 400 | | |
401 | 401 | | |
402 | | - | |
403 | | - | |
404 | | - | |
405 | | - | |
406 | | - | |
407 | | - | |
408 | | - | |
| 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 | + | |
409 | 434 | | |
410 | 435 | | |
411 | 436 | | |
| |||
571 | 596 | | |
572 | 597 | | |
573 | 598 | | |
574 | | - | |
575 | | - | |
576 | | - | |
| 599 | + | |
| 600 | + | |
| 601 | + | |
| 602 | + | |
| 603 | + | |
| 604 | + | |
| 605 | + | |
577 | 606 | | |
578 | 607 | | |
579 | 608 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
43 | 43 | | |
44 | 44 | | |
45 | 45 | | |
46 | | - | |
47 | | - | |
48 | | - | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
49 | 50 | | |
50 | | - | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
51 | 56 | | |
52 | 57 | | |
53 | 58 | | |
| |||
61 | 66 | | |
62 | 67 | | |
63 | 68 | | |
64 | | - | |
| 69 | + | |
65 | 70 | | |
66 | 71 | | |
67 | 72 | | |
68 | | - | |
| 73 | + | |
69 | 74 | | |
70 | 75 | | |
71 | 76 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1062 | 1062 | | |
1063 | 1063 | | |
1064 | 1064 | | |
1065 | | - | |
1066 | | - | |
| 1065 | + | |
| 1066 | + | |
| 1067 | + | |
| 1068 | + | |
| 1069 | + | |
| 1070 | + | |
| 1071 | + | |
| 1072 | + | |
| 1073 | + | |
| 1074 | + | |
| 1075 | + | |
| 1076 | + | |
| 1077 | + | |
| 1078 | + | |
| 1079 | + | |
| 1080 | + | |
| 1081 | + | |
| 1082 | + | |
| 1083 | + | |
| 1084 | + | |
| 1085 | + | |
| 1086 | + | |
| 1087 | + | |
| 1088 | + | |
| 1089 | + | |
| 1090 | + | |
| 1091 | + | |
| 1092 | + | |
| 1093 | + | |
| 1094 | + | |
| 1095 | + | |
| 1096 | + | |
| 1097 | + | |
1067 | 1098 | | |
1068 | 1099 | | |
1069 | 1100 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
357 | 357 | | |
358 | 358 | | |
359 | 359 | | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
360 | 364 | | |
361 | 365 | | |
362 | 366 | | |
363 | 367 | | |
364 | | - | |
| 368 | + | |
365 | 369 | | |
366 | 370 | | |
367 | 371 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
66 | 66 | | |
67 | 67 | | |
68 | 68 | | |
69 | | - | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
70 | 78 | | |
71 | 79 | | |
72 | 80 | | |
| |||
0 commit comments