---
title: "mova-elephant-merge — Mova code model"
description: "Mova code model of tools/elephant/src/merge.rs: components with their labels, obernants and the model text."
url: "https://groupants.elamur.ai/free/en/mova/tools/elephant/src/merge.rs.groupant/"
---
Elamur: [Mova](https://md.mova.elamur.ai/free/en/) · [Dictionary](https://md.dictionary.elamur.ai/free/en/) · [Research](https://md.research.elamur.ai/free/en/) · **Groupants**

This page as HTML: <https://groupants.elamur.ai/free/en/mova/tools/elephant/src/merge.rs.groupant/>

# 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

- **kind:** groupant
- **status:** partial source bound model
- **source:** [`tools/elephant/src/merge.rs`](https://github.com/ElamurAI/mova-free/blob/main/tools/elephant/src/merge.rs)
- **repository folder:** [`tools/elephant/src/merge.rs.groupant`](https://github.com/ElamurAI/mova-free/tree/main/tools/elephant/src/merge.rs.groupant)

> **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

| component | label | where |
|---|---|---|
| **Approximant** | partial | [Forward approximant](#forward-approximant) |
| **Ast** | partial | `syntax.json` |
| **Composition** | partial | [Composition](#composition) |
| **Cost** | partial | [Cost](#cost) |
| **Descriptant** | present | [Descriptant](#descriptant) |
| **Invariant** | partial | [Invariant](#invariant) |
| **Tests** | finite evidence | [Tests](#tests) |

## 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.

| relation | type | label | where |
|---|---|---|---|
| Behavior complement | behavior complement | partial source derived model | [Behavior complement](#behavior-complement) |
| Reverse reconstruction | reverse reconstruction | partial source derived model | [Reverse reconstruction](#reverse-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

- **source SHA-256:** `1c395a4ee4841ff0…`
- **repository commit:** `f55191f0d47f`
