@hviana/sema 0.9.3 → 0.9.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. package/AGENTS.md +16 -7
  2. package/dist/src/mind/learning.js +11 -12
  3. package/dist/src/mind/mind.js +4 -4
  4. package/dist/src/mind/types.d.ts +10 -15
  5. package/dist/src/store.d.ts +10 -10
  6. package/dist/src/store.js +5 -5
  7. package/docs/INDEX.md +62 -59
  8. package/docs/INVARIANTS.md +36 -18
  9. package/docs/PHILOSOPHY.md +317 -0
  10. package/docs/architecture/bounded-reads.md +31 -71
  11. package/docs/architecture/caches.md +61 -81
  12. package/docs/architecture/closure.md +88 -107
  13. package/docs/architecture/commonality.md +47 -38
  14. package/docs/architecture/cost-model.md +57 -79
  15. package/docs/architecture/determinism.md +43 -55
  16. package/docs/architecture/evidence.md +158 -235
  17. package/docs/architecture/exact-vs-approximate.md +41 -35
  18. package/docs/architecture/factored-machinery.md +34 -20
  19. package/docs/architecture/fold-contract.md +110 -118
  20. package/docs/architecture/halo-sketch.md +105 -96
  21. package/docs/architecture/match-project.md +51 -42
  22. package/docs/architecture/mechanism-market.md +87 -91
  23. package/docs/architecture/memoization.md +60 -74
  24. package/docs/architecture/meter.md +37 -47
  25. package/docs/architecture/saturation.md +75 -101
  26. package/docs/architecture/store.md +118 -99
  27. package/docs/architecture/thresholds.md +66 -73
  28. package/docs/failures/tempting-but-wrong.md +139 -165
  29. package/docs/harness/gates.md +27 -32
  30. package/docs/mechanisms/alu.md +22 -69
  31. package/docs/mechanisms/cast.md +76 -71
  32. package/docs/mechanisms/confluence.md +22 -29
  33. package/docs/mechanisms/cover.md +58 -66
  34. package/docs/mechanisms/extraction.md +33 -37
  35. package/docs/mechanisms/prefix-completion.md +36 -39
  36. package/docs/mechanisms/recall.md +60 -53
  37. package/docs/mechanisms/reference.md +63 -49
  38. package/jsr.json +1 -1
  39. package/package.json +1 -1
  40. package/src/alu/README.md +90 -298
  41. package/src/derive/README.md +94 -256
  42. package/src/mind/learning.ts +11 -12
  43. package/src/mind/mind.ts +4 -4
  44. package/src/mind/types.ts +10 -15
  45. package/src/rabitq-ivf/README.md +11 -8
  46. package/src/store.ts +5 -5
@@ -1,120 +1,101 @@
1
- # Closure — One Law, One Unit, Every Transition
2
-
3
- > **Law:** a step is admitted only when it CLOSES the derivation, or MOVES to
4
- > structure it has not consumed, or CARRIES material the asker left unaccounted.
5
-
6
- One unit, one law and one engine, asked by every tier that decides whether to
7
- continue: the chart's frontier, the market's candidates, the post-grounding
8
- walk, fusion, and the mechanisms' own gates. None re-spells a condition the law
9
- owns.
10
-
11
- ## The unit — `src/mind/derivation.ts`
12
-
13
- | Field | What it is |
14
- | ----------- | ----------------------------------------------------- |
15
- | `product` | the answer bytes so far |
16
- | `accounted` | the spans of the asker's bytes it explains |
17
- | `remainder` | what the asker still owes, per span, at the `W` floor |
18
- | `cost` | the currency's total for the steps taken |
19
- | `fixed` | a declared fixpoint: no transition is offered |
20
- | `used` | the anchors the producer speaks for |
21
-
22
- No identity field (`resolve(product)` is one), no structure field, no frontier
23
- field, no producer field, and no count of any kind. The witnesses `contains` and
24
- `moves` are the LAYER's: it holds the structure and hands them in, so the law
25
- never probes the store.
26
-
27
- ## The boundary
28
-
29
- `product` (what it stands on, its identity being `resolve(product)`),
30
- `accounted` (the price its steps summed) and `remainder` (the question's debt,
31
- at one quantum) are the derivation's own. What it REACHED and what it SPENT are
32
- the layer's (`reaches`, `consumed`), never a field here: the law decides
33
- admission and consumption, the layer decides frontier and termination.
1
+ # Closure — One Law for Every Transition
2
+
3
+ > **Law:** a step is admitted only when it **closes** the derivation, **moves**
4
+ > to structure the derivation has not consumed, or **carries** material the
5
+ > asker left unaccounted.
6
+
7
+ **Why.** Every tier that decides whether to continue asks this one law, and none
8
+ re-spells a condition it owns. Those tiers are the chart's frontier, the market,
9
+ the walk after grounding, fusion, and the mechanisms' own gates. Without the law
10
+ a derivation could wander: restate what it already said, cycle, or extend into
11
+ facts nobody asked for.
12
+
13
+ ## The unit — `DerivationState` (`src/mind/derivation.ts`)
14
+
15
+ | Field | Meaning |
16
+ | ----------- | ----------------------------------------------------------------------------------- |
17
+ | `product` | the answer bytes, what the derivation stands on; its identity is `resolve(product)` |
18
+ | `accounted` | the asker's spans its steps explain, a cost quantity |
19
+ | `remainder` | what the asker still owes, per span, at the `W` floor; empty means **closed** |
20
+ | `cost` | its position on the ladder |
21
+ | `fixed` | a declared fixpoint: the query _is_ the context, so no transition is offered |
22
+ | `used` | the anchors the product speaks for; an empty set declares that it voices nothing |
23
+
24
+ There is no identity field, no frontier, no producer and no count. What the
25
+ derivation _reached_ and _spent_ belongs to the layer, which holds the structure
26
+ and hands the law its witnesses (`contains`, `moves`). The law never probes the
27
+ store.
34
28
 
35
29
  ## The transition
36
30
 
37
- `admissible(state, continuation, query, W)` returns the witnesses the step pays
38
- in, or `null`; `advance(state, continuation, witnesses)` is the only transition.
39
- The remainder is consumed only by a declared move, and only by the material that
40
- move CARRIES: `carries` admits by ENGAGEMENT and consumes nothing, a move
41
- consumes what its window proves. Whole-span draining was refuted by `test/110`,
42
- the window alone by `test/138`. The state is BORN owing what its product does
43
- not carry.
44
-
45
- The walk ends when the layer stops offering or the law refuses; owning no
46
- search, the law cannot prevent a cycle — that is the layer's, over the structure
47
- it holds. A transition is only ever `advance`: a fusion the law refuses is not
48
- taken (there is no hand-built fallback).
31
+ `admissible(state, continuation, query, W)` returns the witnesses a step pays
32
+ in, or `null`. `advance(state, continuation, witnesses)` is the only transition.
33
+ No state is built by hand anywhere else (`test/137.7`).
34
+
35
+ - **A state is born owing** everything its product does not carry.
36
+ - **`carries` admits by engagement and consumes nothing.** Only a declared move
37
+ consumes, and only the material its window proves. Both shortcuts were
38
+ refuted: draining whole spans (`test/110`) and trusting the window alone
39
+ (`test/138`).
40
+ - **A step the question did not name pays from what it still owes.** Naming is
41
+ the evidence law (`evidence.md`).
42
+ - **The law owns no search, so it cannot prevent a cycle.** That belongs to the
43
+ layer, which holds the structure. A fusion the law refuses is simply not
44
+ taken, and there is no hand-built fallback.
49
45
 
50
46
  ## The engine — `closeOver`
51
47
 
52
- `closeOver(state, query, W, layers, enter?)` closes a derivation under the law,
53
- layer by layer. A layer (`ClosureLayer`) is a named `Offer` with its own
54
- instrumentation hooks; each is walked by `closure` to its own end, and the state
55
- it reaches is the state the next layer is offered against. Layers are PHASES, in
56
- order, never revisited.
57
-
58
- - **¬FIXED is the engine's.** A fixed state admits no transition, so no layer is
59
- entered for it — the walk-skip and fusion-skip a caller used to spell by hand
60
- are the law's first clause, taken before any layer pays.
61
- - **Engagement is the layer's.** A layer that has nothing to offer a state
62
- (`engages`) is not entered: no offer, no meter phase.
63
- - **The pipeline's post-grounding stage IS the engine**, with two layers: the
64
- walk (`walkLayer` — forward absorb or pivot) and the fusion (`fusionLayer` —
65
- one composed transition, engaged only while the derivation is open). There is
66
- no hand-built state anywhere outside `advance` (`test/137.7`).
67
-
68
- ## The four quantities (trap 13), and where each stands
69
-
70
- | Quantity | Status |
71
- | ----------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
72
- | offer of a hop | Consequence. Chart: the corpus's continuations under the READ cap, each a MOVE priced STEP, the search decides (`test/112`). Walk: absorb/pivot, the law admits. |
73
- | depth of a join | Consequence. The join consumes the shortest tail prefix naming a learnt key that leads — CONTAINS (resolves) ∧ MOVES (leads) — and chains until the tail is consumed; no count (`test/108`). It is priced for the facts a lightest derivation STANDS ON, round by round (`solve`'s join license), never for every fact the exploration reaches — the `deepen` cure for the `recompleteNode` trap. |
74
- | scope of a gap | Consequence for alignment (`alignAround` walks outward, no cap). NOT for recognition's interior pass: its reach `W⁴ + 2r` bounds an exhaustive embedded-form probe; exact unbounded reach needs a whole-stream index the store does not have. |
75
- | scope of a substitution | Consequence: the gap between two aligned anchors (`unexplainedSpans`), gated as scaffolding by the global commonality reading. The filler-unanimity window (`chainReach`) is a derived decision scale, not an explosion cap. |
76
-
77
- ## One cost home
78
-
79
- `moves + PASS · unaccountedBytes` is computed in ONE place (`pipeline.ts`,
80
- `weigh`). A mechanism reports `moves` and `accounted` — what it did — and never
81
- a price; `cover` reports its chart derivation's work.
82
-
83
- ## Three limits, proved and left out
84
-
85
- 1. **The chart cannot evaluate accounting** — its interface has no parameter for
86
- it, and carrying it per item was measured and rejected. The chart reads the
87
- same law off an item: identity is its `key`, continuation the rule's
88
- existence, progress the frontier advancing, closure the goal test, `fix` is
89
- `fixed`.
90
- 2. **Closure by the query's position in the graph is not a term of the unit** —
91
- `reason`'s echo guards stop with the remainder non-empty, and recall's
92
- reverse tiers close with an empty accounting. That is a fact about the
93
- asker's material in the store, available only to the layer holding it.
94
- 3. **The extension is not priced into the market** (`test/136.2`): the engine
95
- closes the WINNER only; pricing each candidate's closure would run the walk
96
- for every candidate, and that comparison has not been measured.
48
+ `closeOver(state, query, W, layers)` closes a derivation layer by layer. A layer
49
+ (`ClosureLayer`) is a named offer with its own instrumentation. Layers are
50
+ phases: each runs to its own end, in order, and is never revisited.
51
+
52
+ - **"Not fixed" is checked first.** A fixed state admits no transition, so no
53
+ layer is entered.
54
+ - **Engagement is the layer's.** A layer with nothing to offer a state
55
+ (`engages`) is not entered, and pays no offer and no meter phase.
56
+ - **The pipeline's post-grounding stage is this engine,** with two layers. The
57
+ walk (`walkLayer`) absorbs forward or pivots. The fusion (`fusionLayer`) makes
58
+ one composed transition, and engages only while the derivation is open.
59
+
60
+ ## What the law decides, and what it does not
61
+
62
+ - **The offer of a hop is a consequence.** The chart offers the corpus's
63
+ continuations under the read cap, each a move priced `STEP`, and the search
64
+ decides (`test/112`).
65
+ - **The depth of a join is a consequence.** A join consumes the shortest tail
66
+ prefix that names a learnt key leading somewhere, and chains until the tail is
67
+ consumed (`test/108`). It is priced only for the facts the lightest derivation
68
+ stands on, never for everything the exploration reached (`test/150`).
69
+ - **A gap's reach is not a consequence everywhere.** In alignment it is: the
70
+ walk goes outward with no cap. Recognition's interior pass is bounded at
71
+ `W⁴ + 2r`, because exact unbounded reach would need a whole-stream index the
72
+ store does not have.
73
+
74
+ Three limits were proved and deliberately left out:
75
+
76
+ 1. **The chart cannot evaluate accounting.** Carrying it per item was measured
77
+ and rejected, so the chart reads the law off its items: identity is the key,
78
+ continuation is a rule existing, closure is the goal test.
79
+ 2. **Closure by the query's position in the graph is the layer's, not the
80
+ unit's.** The echo guards stop with the remainder non-empty, and recall's
81
+ reverse tiers close with nothing accounted.
82
+ 3. **The extension is not priced into the market.** Only the winner is closed,
83
+ because pricing every candidate's closure has not been measured
84
+ (`test/136.2`).
97
85
 
98
86
  ## Layering
99
87
 
100
- Imports `../bytes.js` only, and sits below `graph-search.ts`, `match.ts`,
101
- `rationale.ts` and `pipeline.ts`. The span algebra lives here too — the law's
102
- vocabulary, not the tracer's.
88
+ `derivation.ts` imports only `../bytes.js` and sits below `graph-search.ts`,
89
+ `match.ts`, `rationale.ts` and `pipeline.ts`. The span algebra
90
+ (`unexplainedSpans` and its relatives) lives here as the law's vocabulary.
103
91
 
104
92
  ## Pins
105
93
 
106
- - `test/133`–`137` — the law's home, readings, refusal, limits.
107
- - `test/138` — a cycle cannot close it, a carried move can.
108
- - `test/139` — carrying is ENGAGEMENT, not explanation.
109
- - `test/140` — irrelevant supply changes nothing.
94
+ - `test/133`–`137` — the law's home, its readings, refusal and limits.
95
+ - `test/138`, `test/139` — a cycle cannot close a derivation, and a carried move
96
+ can; carrying is engagement, not explanation.
110
97
  - `test/142`, `test/143` — the offer's contract, and the cycles.
111
- - `test/144`, `test/146`, `test/147` — identity is content, the `contains` gate,
112
- the witness ladder.
113
- - `test/137.7` — no transition is built by hand outside the law.
114
- - `test/149` — the engine: ¬FIXED first, layers as phases, engagement, a refusal
115
- ends one layer, and the pipeline sequences no layer by hand.
116
- - `test/150` — the join prices the facts a derivation stands on, not every fact
117
- the exploration reaches (a hub's degree changes nothing).
118
- - `test/151` — the cover's other async premises (connectors, concept hops) are
119
- resolved where the search reaches them; a span's cheapest completion
120
- dominates; a grounding on the whole query pays no fusion climb.
98
+ - `test/149` — the engine: "not fixed" first, layers as phases, engagement, and
99
+ no layer sequenced by hand.
100
+ - `test/150`, `test/151` — the join prices only what the derivation stands on,
101
+ and a hub's degree costs nothing.
@@ -1,54 +1,63 @@
1
- # Three Measures of Commonality
1
+ # Commonality — What Is Shared, Relative to Whom
2
2
 
3
- Sema needs "what is shared" in three populations: corpus-global (how widely a
4
- structure is reused), weave-local (what a local cohort of overlapping forms
5
- agrees on), and container-local (how many containers hold a byte window).
6
- Different data, different formulas, never conflated.
3
+ > **Law:** every judgement of relevance cuts a population into what it shares
4
+ > (frame, scaffolding) and what varies (filler, the discriminating part). The
5
+ > cut is always read over a named population. Sema uses three populations, with
6
+ > three measures, and never substitutes one for another.
7
7
 
8
- ## Corpus-global — `reachOf` + `dominates`
8
+ Commonality and discrimination are the two sides of one cut, and the cut has no
9
+ absolute answer. `the importance of` is frame among the essay prompts aligned to
10
+ a question and filler across the corpus. Reading one population's cut with
11
+ another population's measure was refuted every time it was tried (`test/17`, and
12
+ the container-as-hub saturation in `saturation.md`).
9
13
 
10
- _Defined in `src/mind/traverse.ts` + `src/geometry.ts`; used by climb,
11
- containment, IDF pooling._
14
+ ## The three populations
12
15
 
13
- For a node id, `reachOf(id, N)` counts how many learnt contexts contain it
14
- (capped graph walks, memoised per response in `sharedReachMemo`).
15
- `dominates(reach, N)` asks whether that reach is above the corpus-determined
16
- majority threshold (`geometry.ts`, over `N`). Minority reach discriminates (a
17
- filler), majority reach is scaffolding. Powers the climb, edge following and
18
- vote pooling.
16
+ **Corpus contexts: how widely a node is used.**
19
17
 
20
- ## Weave-local — `depth[]` + `MIN_WEAVE` + `dominates`
18
+ - Measure: `reachOf(id, N)`, the learnt contexts its containment and edge climb
19
+ reaches, capped and memoized in `sharedReachMemo`.
20
+ - Cut: `dominates(reach, N)`. A majority is scaffolding, and a minority
21
+ discriminates. The climb reads the graded form of the same cut, weighing a
22
+ region by `ln(N/c)`.
23
+ - Read by the consensus climb, `confluence`'s gate and edge following.
21
24
 
22
- _Defined and gated in `src/mind/mechanisms/cast.ts` (`depth[]` from the shared
23
- weave, `MIN_WEAVE`); used by CAST._
25
+ **The cohort: the structures aligned to this question.**
24
26
 
25
- For an alignment weave, `depth[i]` counts how many aligned structures cover byte
26
- `i` of the query; `MIN_WEAVE = 2` requires agreement beyond a pair (pairs are
27
- ambiguous with insertions), and `dominates(depth[i], aligned)` a majority of the
28
- cohort:
27
+ - Measure: `depth[i]`, the number of distinct structures in the weave that cover
28
+ byte `i`. They are counted as distinct, never by weight.
29
+ - Cut: `frame(i) ⇔ depth[i] > MIN_WEAVE ∧ dominates(depth[i], aligned)`, with
30
+ `MIN_WEAVE = 2`, because a pair is ambiguous when insertions are possible.
31
+ - Read by CAST (`cast.ts`).
29
32
 
30
- ```
31
- frame(i) ⇔ depth[i] > MIN_WEAVE ∧ dominates(depth[i], aligned)
32
- ```
33
+ **Places: where a window occurs.**
33
34
 
34
- This powers CAST's frame gate — what the cohort shares vs what differentiates
35
- one member — and never consults corpus reach.
35
+ - Measure: `containersSlice(id, 0, bound + 1).length`, the window's containers.
36
+ - Cut: `0` anchors nothing, and `≥ 2` marks the window as reused. Above the hub
37
+ bound, the window is scaffolding.
38
+ - Read by the bridge and by attention, which anchor on the rarest window first,
39
+ and by the scaffolding readings (`scaffoldExtents`,
40
+ `allWindowsAreScaffolding`).
36
41
 
37
- The three answer different questions over different populations; CAST's frame
38
- must not be replaced by a reach check, and the climb must not be driven by weave
39
- depth.
42
+ **Scaffolding is nobody's evidence and nobody's debt.** A window in more than
43
+ `√N` places explains nothing, because every fact holds it. So a step cannot pay
44
+ the question by restating `is`, and a cover span made only of scaffolding is not
45
+ accounted (`evidence.md`).
40
46
 
41
- ## Container-local — the window's rarity
47
+ `hubWindows` floors that bound at `chainReach(W) = W²`. Inside one deposit's
48
+ fold, a window is already contained by up to that many chunks and branches. On a
49
+ store of a few facts, `√N` alone would call every window scaffolding, which
50
+ measures fold structure, not commonness (`test/22`).
42
51
 
43
- _Defined in `src/mind/bridge.ts` (`containersSlice(id, 0, bound + 1).length`);
44
- used by the bridge, and by attention's anchoring._
45
-
46
- `rarity` counts how many containers hold a byte window: zero anchors nothing,
47
- two or more marks it REUSED (`winReused`), and the bridge sorts its anchors by
48
- it, so the rarest leads. Purpose: choosing what to anchor on.
52
+ Two limits bound every cut. Below lies chance: one pair, or a resemblance under
53
+ `3/√D`, cannot be told from accident. Above lies ubiquity: what everyone holds
54
+ discriminates nothing and abstracts nothing.
49
55
 
50
56
  ## Pins
51
57
 
52
- - `test/17` — weave-local frame / `MIN_WEAVE` / `dominates` vs corpus-global
53
- reach.
58
+ - `test/17` — the weave-local frame, `MIN_WEAVE` and `dominates`, against corpus
59
+ reach (the reorder probe).
54
60
  - `test/34` — containment and reach-driven disambiguation.
61
+ - `test/73` — a question made only of scaffolding is abstained from by the
62
+ bridge.
63
+ - `test/22` — the hub floor on small stores.
@@ -1,87 +1,65 @@
1
1
  # Cost Model — One Currency
2
2
 
3
- Every mechanism and every byte competes on one cost ladder defined in
4
- `src/mind/graph-search.ts`. GraphSearch and `pipeline.ts:think` use the same
5
- units, so a mechanism-level choice and a byte-level choice are the same kind of
6
- decision: a lightest derivation.
7
-
8
- ## Ladder (`src/mind/graph-search.ts`)
9
-
10
- | Cost | Value | Meaning |
11
- | --------- | ------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
12
- | `MICRO` | `1e-3` | Recognised advance (one `rec` bridge); per-byte unit of the A\* heuristic. A recomposed form's onward edge is also `MICRO`. |
13
- | `STEP` | `1` | Every edge hop (first or fifth), every computed result, every projection. Charging every hop makes the lightest derivation the shortest chain. |
14
- | `CONCEPT` | `10` | Halo-mediated act (synonym hop, consensus climb) and abandoning an edge chain early (`CONCEPT` above chain cost — genuine fixpoint at `+0` always beats giving up at same depth). |
15
- | `PASS` | `1000` / byte | Carrying a byte nothing explains. Dominates everything so the search always prefers to recognise. |
16
-
17
- Only the **ordering** `MICRO < STEP < CONCEPT < PASS` matters; any constants
18
- with that order give the same derivations.
19
-
20
- ## Pipeline weighing (`src/mind/pipeline.ts:think`)
21
-
22
- Candidates are weighed in ONE place — a mechanism reports `moves` and
23
- `accounted`, never a price:
24
-
25
- ```
26
- weight = moves + PASS * unaccounted_bytes
27
- grade = floor(weight / STEP)
28
- ```
29
-
30
- `unaccounted` is what no `accounted` span covers. Comparison is at `STEP`
31
- resolution: lowest `grade` wins; at equal grade fewer `scaffolding` bytes
32
- (answer bytes lifted from unrecognised spans) wins; then list order.
33
-
34
- ## Two semirings
35
-
36
- - **(min, +) tropical** — lightest derivation in `GraphSearch` via `src/derive`
37
- (`lightestDerivation`). Cost accumulates with `+`, choice selects `min`.
38
- Powers `cover`/`form`/`out`, edge following, fusing, and the A\* agenda
39
- (`g + h`).
40
-
41
- - **(+, +) arithmetic** — evidence pooling in `src/mind/attention.ts:poolVotes`.
42
- Each region's vote is an axiom; rules carry `Rule.combine = 'sum'` so costs to
43
- the same anchor **add** rather than minimise. Powers IDF-weighted consensus,
44
- `votes`/`votesIdf`/`support`, and `regionSupport`/`regionPeak`.
45
-
46
- ## Admissibility
47
-
48
- The A\* heuristic is admissible and consistent:
49
-
50
- ```
51
- h(it) = (queryLen - right) * MICRO
52
- ```
53
-
54
- `right` is `p` for `cover(p)` or `j` for `form/out [i,j)`. `MICRO` is the
55
- minimum per-byte cost in the ladder (every real per-byte cost is `>= MICRO`,
56
- including `PASS`), and only the suffix past `right` is counted, so `h` never
57
- exceeds the true remaining cost.
58
-
59
- ## Dominance — why `PASS ≫ STEP` does not flood the chart
60
-
61
- The heuristic charges `MICRO` for a byte the goal will pay `PASS` for, so a
62
- cover that leaves bytes unexplained lets the search spend up to `PASS / STEP`
63
- hops looking for one more explained byte. Coverage itself cannot use them: every
64
- recognised completion of `[i, j)` advances the cover from `i` to `j` at the same
65
- `MICRO`. So a form or completion of `[i, j)` whose cost has reached that of a
66
- completion of `[i, j)` already yielded is DOMINATED and fires no rule
67
- (`buildSearch`, metered as `searchDominated`): every completion it could lead to
68
- costs at least as much, and a tie goes to the one yielded first. What a
69
- completion's BYTES could still do — fuse, splice, join — fires from the
70
- completion the search would stand on for that span, the same cure the join
71
- license and `deepen` apply. The first hop's stop-here (`STEP + CONCEPT`) is then
72
- a real horizon: no chain deeper than it is expanded.
3
+ > **Law:** every choice, whether a byte inside the search or a mechanism in the
4
+ > market, is a lightest derivation on one ladder (`mind/graph-search.ts`). The
5
+ > price is the question left unexplained, never confidence.
6
+
7
+ **Why.** Exact identity yields no confidence to choose by. What can be measured
8
+ exactly is how much of the question an answer accounts for. Pricing that makes
9
+ the winner the reading that explains the most, not the one most eager to speak.
10
+ When nothing explains the question, silence is the lightest answer.
11
+
12
+ ## The ladder
13
+
14
+ | Cost | Value | Charged for |
15
+ | --------- | ----------- | -------------------------------------------------------------------------------------------------------------------------------------------- |
16
+ | `MICRO` | `1e-3` | a recognised advance, and a recomposed form's onward edge; it is also the A\* heuristic's unit per byte |
17
+ | `STEP` | `1` | every edge hop, computed result and projection. Charging every hop makes the lightest derivation the shortest chain |
18
+ | `CONCEPT` | `10` | an act mediated by a halo (a synonym hop, the consensus climb), and abandoning a chain early, so that a real fixpoint always beats giving up |
19
+ | `PASS` | `1000`/byte | carrying a byte nothing explains. It dominates everything, so the search always prefers to recognise |
20
+
21
+ Only the order `MICRO < STEP < CONCEPT < PASS` matters. Any constants with that
22
+ order give the same derivations. The market weighs candidates on the same
23
+ ladder, `moves + PASS·unaccounted`, compared at `STEP` grade
24
+ (`mechanism-market.md`).
25
+
26
+ ## Two semirings, one engine (`src/derive`)
27
+
28
+ - **(min, +), the tropical semiring:** the lightest derivation. Costs add along
29
+ a derivation, and the cheapest route to a conclusion wins. This powers
30
+ `cover`, form and continuation rules, edge following, fusion, and the A\*
31
+ agenda.
32
+ - **(+, +), the arithmetic semiring:** pooled evidence. Rules with
33
+ `combine: "sum"` add every independent line of evidence for a conclusion
34
+ instead of keeping the cheapest. This powers the consensus climb's votes
35
+ (`poolVotes`).
36
+
37
+ ## Admissibility and dominance
38
+
39
+ The heuristic `h = (queryLen − right) · MICRO` is admissible and consistent.
40
+ `MICRO` is the smallest cost per byte, and only the suffix past the item is
41
+ counted.
42
+
43
+ Because the heuristic charges `MICRO` for a byte the goal will charge `PASS`
44
+ for, the search could spend up to `PASS/STEP` hops looking for one more
45
+ explained byte. Coverage cannot use them: every recognised completion of
46
+ `[i, j)` advances the cover at the same price. So a form or completion of
47
+ `[i, j)` that costs as much as one already yielded is **dominated**, and fires
48
+ no rule (`searchDominated`). Fusion, splicing and joining fire from the
49
+ completion the search stands on, never from every alternative it reached. That
50
+ makes the first hop's stop-here (`STEP + CONCEPT`) a real horizon.
73
51
 
74
52
  ## Policy is not cost
75
53
 
76
- "Computation always wins" is **not** priced into the ladder (a computed result
77
- costs `STEP`, same as a learned edge). It is enforced by masking: `cover.ts`
78
- removes recognised sites overlapped by a `ComputedResult`, so the computation is
79
- the sole completion there. Keep policy in callers; keep the engine neutral.
54
+ "Computation always wins" is not priced. A computed result costs `STEP`, like a
55
+ learnt edge. It is enforced by masking: `cover.ts` removes any recognised site
56
+ overlapped by a computed span. Keep policy in the callers, and keep the engine
57
+ neutral. Tuning `PASS` to encode a preference breaks the one contract the ladder
58
+ has, its order.
80
59
 
81
60
  ## Pins
82
61
 
83
- - `test/52` — climb consensus instrumentation
84
- - `test/53` — cross-region probe instrumentation
85
- - `test/54` — evidence `k` instrumentation
86
- - `test/55` — cost meter (`Meter`, `CostReport`, `searchPops`/`searchPushes`)
87
- - `test/151` — dominance: a hub's degree generates no chart work
62
+ - `test/04`, `test/55` — the decider's weighing, and the cost meter.
63
+ - `test/151` — dominance: a hub's degree generates no work in the chart.
64
+ - `test/52`, `test/53`, `test/54` — instrumentation of the climb, the
65
+ cross-region probe and evidence `k`.
@@ -1,73 +1,61 @@
1
- # Determinism — Same Seed + Same Deposits + Same Query ⇒ Same Bytes
1
+ # Determinism — Same Seed, Same Deposits, Same Question, Same Bytes
2
2
 
3
- ## The law
3
+ > **Law:** the same `seed`, the same deposit order and the same query give a
4
+ > byte-identical answer. Every path that can reach output is a function of
5
+ > `(seed, store contents, query bytes)`.
4
6
 
5
- > Same `seed` + same deposit order + same query ⇒ byte-identical answer.
7
+ **Why.** An answer meant to be audited, contested or certified must replay.
8
+ Reproducibility is a property of the architecture, not a flag.
6
9
 
7
- Determinism is the product. Every code path that can reach output must be
8
- deterministic given `(seed, store contents, query bytes)`.
10
+ ## Forbidden on a behavioural path
9
11
 
10
- ## Forbidden
12
+ - `Math.random` and `Date.now`.
13
+ - Iteration over an unordered collection whose order can reach output.
11
14
 
12
- No `Math.random` or `Date.now` in behaviour, and no iteration over unordered
13
- collections where order can reach output. Example-only uses
14
- (`example/train_base`) are outside the library contract. If a test becomes
15
- flaky, the contract was broken, not the test.
15
+ If a test becomes flaky, the contract was broken, not the test. Uses inside
16
+ `example/` are outside the library contract.
16
17
 
17
18
  ## All randomness flows from `seed`
18
19
 
19
- `MindConfig.seed` (`src/config.ts:resolveConfig`, `DEFAULT_CONFIG`) is the sole
20
- entropy root. Subsystems derive deterministically:
20
+ `MindConfig.seed` (`config.ts`) is the only entropy root:
21
21
 
22
- - **Alphabet** — `Alphabet` (`src/alphabet.ts`) via `rng` (`src/vec.ts:rng`)
23
- seeded as `seed ^ seedMask`; builds 16→64→256 vectors.
24
- - **Keyring / Space** — `Space.seats` (`src/sema.ts:Space`) via `makeKeyring`
25
- (`src/vec.ts:makeKeyring`) and `rng` seeded from `seed` in `Mind`
26
- (`src/mind/mind.ts`); `fold`/`twoEndedSeat`/`companySignature` are pure over
27
- `Space`.
28
- - **Vector indexes** — `VectorDatabase` (`src/rabitq-ivf/src/database.ts`) and
29
- `Prng` (`src/rabitq-ivf/src/rabitq.ts`) seeded from config; insertion order is
30
- the stored order, not a random choice.
22
+ - the **alphabet** (`alphabet.ts`) is drawn from `rng(seed ^ seedMask)`;
23
+ - the **keyring of seats** (`makeKeyring`) is drawn from the seed in `Mind`;
24
+ - the **vector indexes** (`rabitq-ivf`) are seeded from config, and insertion
25
+ order is their stored order;
26
+ - **company signatures** are seeded by node id (`companySignature`), not by the
27
+ seed or by observation order. That is why halo comparisons survive a change of
28
+ seed while gist comparisons do not (`halo-sketch.md`).
31
29
 
32
- No other PRNG source may affect grounding. Thresholds in `geometry.ts` are
33
- derived from `D`/`W`/`N`, not sampled.
30
+ ## Ties are broken by the corpus
34
31
 
35
- ## Tie-breaks are corpus-determined
32
+ Every choice bottoms out in a fixed order, and the fallback is
33
+ **first-inserted**: the lowest node id, or the `LIMIT 1` insertion order. Never
34
+ last-inserted, because that would make an answer depend on recency instead of
35
+ evidence. The order of teaching is part of what was taught, and a correction
36
+ prevails only by evidence.
36
37
 
37
- Every choice bottoms out in a fixed ordering — insertion order or lowest node id
38
- — not interchangeable (`test/34`). The fallback is **first-inserted**:
38
+ - **`chooseNext` / `guidedFirst`** (`traverse.ts`) try three things in turn: a
39
+ continuation the question names (`evidence.md`); then distributional support,
40
+ `prevCount` and then halo mass; then first-inserted.
41
+ - **`chooseAmong`** takes `argmaxCosine` over `candidateGist`, capped at
42
+ `hubCap`, and resolves ties by stable scan.
43
+ - **Ties in the junction bridge** go to the shortest interior, then the lowest
44
+ node id.
39
45
 
40
- - `guidedFirst` (`src/mind/traverse.ts:guidedFirst`) — guided pick via
41
- `chooseNext` else first-inserted edge (`nextFirst` LIMIT 1).
42
- - `chooseNext` (`src/mind/traverse.ts:chooseNext`) — capped `nextFirst` read
43
- (`hubBound`), ranked by `prevCount` then `haloMass`; equal ⇒ first-inserted.
44
- - `chooseAmong` (`src/mind/traverse.ts:chooseAmong`) — `hubCap` + `argmaxCosine`
45
- over `candidateGist`; first-inserted on tie via stable scan.
46
- - `companySignature` (`src/sema.ts:companySignature`) — `rng(id ^ 0x9e3779b9)`,
47
- i.e. seeded by node id, not observation order.
46
+ When you add a choice among equals, name its tie-break explicitly and make it
47
+ corpus-determined.
48
48
 
49
- Never use last-inserted.
49
+ ## Memoization and tracing must not change the answer
50
50
 
51
- ## Memoization and trace must not break identity
52
-
53
- Per-response memos (`Precomputed`, `perceiveMemo`, `recogniseMemo`, `climbMemo`,
54
- `_resolvedSubtrees` via `foldTree`, `_edgeChoice`, `_gistCache` in
55
- `src/mind/mind.ts` / `src/mind/pipeline-mechanism.ts` /
56
- `src/mind/primitives.ts`) are sound because asking never writes. Only
57
- `guidedNext`/`sharedReachMemo` are trace-bypassed;
58
- `perceiveMemo`/`recogniseMemo`/`climbMemo` are always consulted — `foldTree`'s
59
- subtree fast path skips `visit` (and site emission) for cached subtrees, so
60
- bypassing makes `recognise` non-idempotent.
61
-
62
- ## Follow it
63
-
64
- When you add any choice among equals, name the tie-break explicitly and make it
65
- corpus-determined. Thread new randomness through `seed`-derived `rng`; never
66
- call `Math.random`/`Date.now` on a behavioural path.
51
+ Memos are sound because asking never writes. Which ones a trace bypasses, and
52
+ why the pick memo is cleared when the climb publishes its points, is
53
+ `memoization.md`'s trace boundary.
67
54
 
68
55
  ## Pins
69
56
 
70
- - `test/42` pins recognition idempotence under trace — traced and untraced
71
- `recognise` must return the same cached object and site count.
72
- - Determinism suites — `test/03`, `test/04`, `test/08`, `test/20` — assert same
73
- seed + same training ⇒ byte-identical answers and stores.
57
+ - `test/20`, `test/03`, `test/04`, `test/08` — the same seed and the same
58
+ training give byte-identical answers and stores.
59
+ - `test/42` — recognition is idempotent under trace.
60
+ - `test/155.4` — traced and untraced responses agree after the climb publishes.
61
+ - `test/34` — tie-breaks are corpus-determined, not interchangeable.