---
title: "treestore-frag — Mova code model"
description: "Mova code model of tools/treestore/src/frag.rs: components with their labels, obernants and the model text."
url: "https://groupants.elamur.ai/free/en/mova/tools/treestore/src/frag.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/treestore/src/frag.rs.groupant/>

# treestore-frag

The groupant beside tools/treestore/src/frag.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/treestore/src/frag.rs`](https://github.com/ElamurAI/mova-free/blob/main/tools/treestore/src/frag.rs)
- **repository folder:** [`tools/treestore/src/frag.rs.groupant`](https://github.com/ElamurAI/mova-free/tree/main/tools/treestore/src/frag.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 | [Approximant](#approximant) |
| **Ast** | partial | `syntax.json` |
| **Composition** | partial | [Composition](#composition) |
| **Cost** | symbolic source derived | [Invariant](#invariant) |
| **Descriptant** | present | [Descriptant](#descriptant) |
| **Invariant** | partial | [Invariant](#invariant) |
| **Tests** | executed bounded checks | [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 meta-dictionary of typical structures: frequent runs of token shapes (tag tuple, relation, relative head) learned
by pair merging (Gage 1994; Re-Pair, Larsson & Moffat 2000). With relative heads, a run whose heads point inside it is
a tree fragment. Epoch 2026-11-06: measured gain over single shapes is small (see approximant).

### Approximant

learn: repeat n times: take the most frequent adjacent pair (ties: smallest pair) with count ≥ min, give it a new
symbol, replace its occurrences left to right; counts are updated incrementally (a lazy max-heap). encode: merge the
lowest-rank pair present until none. expand: symbol → shapes.
Measured on shard 00050 (structure stream + escapes): shape ids alone 2.04 MB (context coder), 1024 fragments 2.01 MB
(−1.5 %), 4096 fragments 2.12 MB, 16384 fragments 2.30 MB; under zstd only: shapes 2.49 MB, 4096 fragments 2.44 MB.
The gain of the structure coding comes from the joint shape symbol (split columns 3.23–3.50 MB → shapes 2.04 MB).

### Invariant

expand ∘ encode = id on every shape sequence (also unseen ones; symbols below `base` expand to themselves). learn is
deterministic. Cost: learn O(merges · affected sentences · length); encode O(len · merges applied).

### Composition

model::train learns it from the sample; codec writes encode(shapes) to the `shape` stream and expands while decoding
until the sentence's token count is reached.

### Behavior complement

Does not learn non-contiguous subtrees (only runs in word order), does not use the context coder's statistics, and
does not prune fragments that do not pay off.

### Reverse reconstruction

Exact: a fragment sequence has one expansion; a shape sequence has one encoding for fixed merges.

### Tests

`frag::tests::learn_encode_expand` (first merge = most frequent pair, round trip, unseen sequence, determinism, the
negative control that an unknown symbol does not expand).

## Provenance

- **source SHA-256:** `b9826fca0f9d862a…`
- **repository commit:** `f55191f0d47f`
