Commit 6987d9a
authored
feat(formal): foundation-pack D2 + Q1-lite — drift detector + planner permutation (#93)
## Summary
Lands two more foundation-pack theorems from #77, on top of #87 (P2+P3)
and #90 (D1+C2). **Brings foundation pack to 5 of 8 closed**; the
remaining 3 (C7, N2, V2) are documented as blocked on spec gaps in #89,
#91, #92.
## What lands
### D2: Drift detector iff threshold (Drift.v extension)
| Theorem | Statement |
|---|---|
| `detect_drift_sound` | detector returns true ⇒ score > threshold |
| `detect_drift_complete` | detector returns false ⇒ score ≤ threshold |
Mirrors `DriftDetector::record` in `verisim-drift/src/lib.rs` line 419.
The trichotomy-via-`le_or_gt` axiom avoids classical reasoning; faithful
to the f64 total order in the Rust source (modulo NaN, ruled out by D1
clamps proved in #90).
### Q1-lite: Planner is a permutation (Planner.v, new module)
| Theorem | Statement |
|---|---|
| `planner_preserves_node_count` | `length lp = length (optimize lp)` |
| `planner_preserves_membership` | `In n lp ↔ In n (optimize lp)` |
| `planner_preserves_multiset` | `Permutation lp (optimize lp)` |
Audit findings (recorded in PR #90) found `Planner::optimize` is a
deterministic single-pass `stable_sort_by` over logical plan nodes —
never adds, never drops. We axiomatize this as `optimize_is_permutation`
and derive three structural-preservation corollaries.
**Full Q1** (semantic equivalence: same input data yields same result
set under logical vs physical) requires per-operator semantics
(`Similarity` HNSW k-NN, `Traversal` graph reachability,
`ProofVerification` contract check) and is deferred until those are
formalised. Structural preservation here lays the foundation: any future
semantic-equivalence proof can compose with `planner_preserves_multiset`
to argue executing the physical plan yields the same multiset of
per-node results as executing the logical plan.
## Cumulative foundation-pack progress
| # | Theorem | Module | Status | PR |
|---|---|---|---|---|
| 1 | P2 record_verify_iff_unchanged | Provenance.v | ✓ MERGED | #87 |
| 2 | P3 chain_linked_step + chain_linked | Provenance.v | ✓ MERGED |
#87 |
| 3 | D1 drift_score_in_unit_interval | Drift.v | ✓ MERGED | #90 |
| 4 | C2 txn_state_machine_well_formed | Transaction.v | ✓ MERGED | #90
|
| 5 | **D2 detect_drift_sound + complete** | **Drift.v** | **THIS PR** |
#93 |
| 6 | **Q1-lite planner_preserves_*** | **Planner.v** | **THIS PR** |
#93 |
| 7 | C7 wal_replay_idempotent | _todo_ | blocked | #89 |
| 8 | N2 normalize_idempotent | _todo_ | blocked | #91 |
| 9 | V2 vql_preservation | _todo_ | blocked | #92 |
5 of 8 foundation-pack theorems landed (P3 + D1 + D2 + C2 + Q1-lite); 3
blocked on spec gaps with concrete remediation paths filed.
## Whitelist guards (updated)
- **Drift.v**: D1 + D2 set of axioms — adds `f_detect_drift`,
`strictly_greater`, `le_or_gt`, `le_gt_exclusive`,
`detector_iff_threshold`
- **Planner.v**: `modality`, `condition`, `optimize`,
`optimize_is_permutation` (4 total)
## Local verify
```text
$ just -f formal/Justfile check-assumptions
OK(Provenance): 3 theorems x 4 Parameters whitelisted
OK(Drift): D1 (9 fns) + D2 (detector iff threshold) whitelisted
OK(Transaction): 3 theorems closed under global context (0 axioms)
OK(Planner): Q1-lite 3 theorems x 4 axioms whitelisted
```
## Test plan
- [x] All 4 modules compile under Coq 8.18.0 with no errors or admits
- [x] Per-module Print Assumptions matches declared whitelist
- [x] Transaction.v guard still asserts zero axioms
- [ ] CI workflow `Coq Build Oracle` passes (verify on PR)
Refs #77 (foundation pack tracking).1 parent 9a49587 commit 6987d9a
4 files changed
Lines changed: 214 additions & 8 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
60 | 60 | | |
61 | 61 | | |
62 | 62 | | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
63 | 69 | | |
64 | 70 | | |
65 | 71 | | |
| |||
81 | 87 | | |
82 | 88 | | |
83 | 89 | | |
84 | | - | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
85 | 93 | | |
86 | 94 | | |
87 | | - | |
| 95 | + | |
88 | 96 | | |
89 | 97 | | |
90 | 98 | | |
91 | 99 | | |
92 | 100 | | |
93 | 101 | | |
94 | 102 | | |
95 | | - | |
| 103 | + | |
96 | 104 | | |
97 | 105 | | |
98 | 106 | | |
| |||
110 | 118 | | |
111 | 119 | | |
112 | 120 | | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
130 | 130 | | |
131 | 131 | | |
132 | 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 | + | |
133 | 191 | | |
134 | 192 | | |
135 | 193 | | |
136 | 194 | | |
137 | | - | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
138 | 198 | | |
139 | 199 | | |
140 | 200 | | |
141 | 201 | | |
| 202 | + | |
| 203 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
15 | | - | |
| 15 | + | |
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
| |||
25 | 25 | | |
26 | 26 | | |
27 | 27 | | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
28 | 31 | | |
29 | 32 | | |
30 | 33 | | |
31 | 34 | | |
32 | | - | |
| 35 | + | |
33 | 36 | | |
34 | 37 | | |
35 | 38 | | |
| |||
44 | 47 | | |
45 | 48 | | |
46 | 49 | | |
47 | | - | |
| 50 | + | |
48 | 51 | | |
49 | 52 | | |
50 | 53 | | |
51 | | - | |
| 54 | + | |
52 | 55 | | |
53 | 56 | | |
54 | 57 | | |
| |||
60 | 63 | | |
61 | 64 | | |
62 | 65 | | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
63 | 76 | | |
64 | 77 | | |
65 | 78 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 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 | + | |
0 commit comments