Elamur Groupants⌕
☰

mova-elephant-merge

The groupant beside tools/elephant/src/merge.rs in the Mova repository: what the code computes, what it never does, how to go back from its outputs, its invariants, cost and checks.

Facts

Implementation material. A Mova code model describes this code at one source revision: partial models, finite checks and their stated scope. It is not a reviewed general exposition, and its labels are shown as written, never raised.

Components

componentlabelwhere
ApproximantpartialForward approximant
Astpartialsyntax.json
CompositionpartialComposition
CostpartialCost
DescriptantpresentDescriptant
InvariantpartialInvariant
Testsfinite evidenceTests

Obernants

The typed relations around the forward model: the behaviour complement (what the code never does), the reverse reconstruction (every input compatible with an output) and specialised views.

relationtypelabelwhere
Behavior complementbehavior complementpartial source derived modelBehavior complement
Reverse reconstructionreverse reconstructionpartial source derived modelReverse reconstruction

Model text

Descriptant

The tamping merge: parts or runs, each added or subtracted, into one canonical run (the signed counts restricted to positive ones, in key order, with exactly the OOV words its records use). Source: tools/elephant/src/merge.rs.

Forward approximant

k-way merge of the OOV tables -> union ranks, monotone rank maps and signed frequency sums (no word held); merge pass 1 (binary heap over sorted streams, keys remapped, signed sums): negative -> error, zero -> dropped, positive -> counted and OOV words marked; canonical table = marked words, streamed again from the inputs into the output; merge pass 2 sums in union ranks and writes records remapped into canonical ranks.

Invariant

Counts form a commutative group, so compact is invariant under the order and grouping of its inputs (associativity, commutativity) and subtraction is exact ((a+b)-a = canonical b); a merged count above u32 or below 0 is refused; inputs must share the store's format.

Cost

Two streaming reads of the records, O(R log k) for R records and k inputs, and two of the OOV tables; memory 4 bytes per input OOV entry plus 9 bytes per union word, no strings or records held; one write. Measured 2026-11-06: 4 runs + 5 parts (35.1 M records out) in 21-23 s at 0.04 GB; 11 whole-Wikipedia parts (126.0 M records in, 77.8 M out, 2.0 M OOV words) in 69 s at 0.10 GB.

Composition

Parent: elephant. Called by store::tamp.

Behavior complement

Never holds the records in memory; never mixes formats; never writes a non-positive count. Evidence status: source-derived model with finite checks, not a proof.

Reverse reconstruction

Given the output and all inputs but one, the missing input's positive counts are recoverable by subtraction; the merge tree is not recoverable (it does not matter, by the invariant).

Tests

Checks

merge::tests: order-free bytes, exact subtraction, retraction of what was not added refused, a format-1 input in a format-2 merge refused; lsm: two merge trees on the 50 000-article pass write the same 143 MB run. These are finite fixtures and measurements; not a proof.

History

2026-11-06 · document

Epoch 2026-11-06

First model, written with the source (the Elephant made incremental and an animal on Mova).

Provenance

This page in Markdown → https://md.groupants.elamur.ai/free/en/mova/tools/elephant/src/merge.rs.groupant/