mathlib-duck
The groupant beside tools/mathlib/src/duck.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
| component | label | where |
|---|---|---|
| approximant | partial | approximant |
| ast | partial | syntax.json |
| cost | partial | invariant-and-cost |
| descriptant | present | descriptant |
| invariant | partial | invariant-and-cost |
| tests | bounded checks | 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.
| id | type | label | where |
|---|---|---|---|
behavior_complement | behavior_complement | partial source derived model | behavior_complement |
reverse_reconstruction | reverse_reconstruction | partial source derived model | reverse_reconstruction |
substitution_order | substitution_order | partial source derived model | substitution_order |
quote_transport | quote_transport | partial source derived model | quote_transport |
failure_precedence | failure_precedence | partial source derived model | failure_precedence |
lossy_output_decode | lossy_output_decode | partial source derived model | lossy_output_decode |
Model text
descriptant
mathlib-duck
run selects DUCKDB or HOME/bin/duckdb, spawns -bail -batch plus optional mode and db, writes SQL then waits; nonzero status or stderr Error: returns error, otherwise stdout is decoded lossily. fill folds ordered global replacements after doubling apostrophes.
Epoch 2026-10-31
Prospective model retained before changes. Existing production bytes are preserved; additions are bounded inline tests. Nine source groupants expose ingestion and routing boundaries; typed children bind exact source bytes and reuse their parent syntax projection. Native tests run twice per profile; behavior mutants run as compiled source changes and exact bytes are restored before positive checks.
Important retained observation: network-looking helpers are not all pure (DNS inside github_host and books build); selection deliberately excludes those effects. Mixed-format manifest order is not deterministic, and error paths do not imply rollback.
No network/DNS/download, real catalog/corpus/model/teacher or database execution. Effect paths are source-derived; finite helper tests are not universal verification. No executable percentage surrogate or speed claim; future caps require metric/domain/reference and remain 1/2/5/10%.
approximant
Forward relation
run selects DUCKDB or HOME/bin/duckdb, spawns -bail -batch plus optional mode and db, writes SQL then waits; nonzero status or stderr Error: returns error, otherwise stdout is decoded lossily. fill folds ordered global replacements after doubling apostrophes.
Model observations include returns, retained state and ordered partial effects; on external failures the successful-prefix relation replaces a total-function claim.
Composition
run selects DUCKDB or HOME/bin/duckdb, spawns -bail -batch plus optional mode and db, writes SQL then waits; nonzero status or stderr Error: returns error, otherwise stdout is decoded lossily. fill folds ordered global replacements after doubling apostrophes.
Scoped children isolate the declared contiguous source intervals. Their operations compose only where the source calls them; costs of overlapping parent/child descriptions are not added twice. Remaining effect paths retain explicit gaps.
catalog
behavior_complement
Subject: mathlib-duck, source SHA-256 9f7321a7f368a542a2a9cb3bd2c79adf590517f4d6a0c7b88c7adf254bac7946; finite transition observation.
If spawn fails, no SQL is written to a child by this call. If status is failure or stderr contains exact Error:, wrapper cannot return Ok(stdout). No claim that every DB failure uses that marker.
Domain: stated source predicates, bounded inputs and available resources; arithmetic assumptions and external effect gaps as in the invariant. Operator is the stated relation/projection; complement is a source-derived inner exclusion, reverse retains compatible antecedents. Other views are source-derived partial constraints, not inverse laws.
Evidence: tests.md identifies executed helpers and unexecuted paths. No universal guarantee follows from the finite fixtures.
reverse_reconstruction
Subject: mathlib-duck, source SHA-256 9f7321a7f368a542a2a9cb3bd2c79adf590517f4d6a0c7b88c7adf254bac7946; finite transition observation.
Given final SQL, reconstruct all original templates and ordered variable arrays whose repeated escaped substitutions yield it. Literal text and inserted values are indistinguishable; run output cannot uniquely reconstruct SQL, DB state or child diagnostics.
Domain: stated source predicates, bounded inputs and available resources; arithmetic assumptions and external effect gaps as in the invariant. Operator is the stated relation/projection; complement is a source-derived inner exclusion, reverse retains compatible antecedents. Other views are source-derived partial constraints, not inverse laws.
Evidence: tests.md identifies executed helpers and unexecuted paths. No universal guarantee follows from the finite fixtures.
substitution_order
Subject: mathlib-duck, source SHA-256 9f7321a7f368a542a2a9cb3bd2c79adf590517f4d6a0c7b88c7adf254bac7946; finite transition observation.
fill('{a}',[(a,'{b}'),(b,'x')])='x' while reversed variables yield '{b}'. Values can introduce later placeholders; this is sequential text substitution. Actual substitution_order_and_quotes constrains both.
Domain: stated source predicates, bounded inputs and available resources; arithmetic assumptions and external effect gaps as in the invariant. Operator is the stated relation/projection; complement is a source-derived inner exclusion, reverse retains compatible antecedents. Other views are source-derived partial constraints, not inverse laws.
Evidence: tests.md identifies executed helpers and unexecuted paths. No universal guarantee follows from the finite fixtures.
quote_transport
Subject: mathlib-duck, source SHA-256 9f7321a7f368a542a2a9cb3bd2c79adf590517f4d6a0c7b88c7adf254bac7946; finite transition observation.
Every apostrophe of each variable value becomes two before insertion; unrelated template quotes remain untouched. This is suitable only for templates whose quoting context is understood; arbitrary identifiers/SQL fragments are not made safe by doubling.
Domain: stated source predicates, bounded inputs and available resources; arithmetic assumptions and external effect gaps as in the invariant. Operator is the stated relation/projection; complement is a source-derived inner exclusion, reverse retains compatible antecedents. Other views are source-derived partial constraints, not inverse laws.
Evidence: tests.md identifies executed helpers and unexecuted paths. No universal guarantee follows from the finite fixtures.
failure_precedence
Subject: mathlib-duck, source SHA-256 9f7321a7f368a542a2a9cb3bd2c79adf590517f4d6a0c7b88c7adf254bac7946; finite transition observation.
Spawn precedes stdin extraction/write, which precedes wait, which precedes status/stderr check and lossy stdout. Earlier I/O errors short-circuit; write failure does not implement child termination/rollback.
Domain: stated source predicates, bounded inputs and available resources; arithmetic assumptions and external effect gaps as in the invariant. Operator is the stated relation/projection; complement is a source-derived inner exclusion, reverse retains compatible antecedents. Other views are source-derived partial constraints, not inverse laws.
Evidence: tests.md identifies executed helpers and unexecuted paths. No universal guarantee follows from the finite fixtures.
lossy_output_decode
On wrapper success, invalid UTF-8 stdout is replaced by U+FFFD; stderr is also decoded lossily before searching exact Error:. Distinct byte streams may produce equal returned text. This view is source-derived and no child process was executed.
Subject and source identity: manifest.json. Domain: scoped forward/invariant; relation is source-derived and partial. Evidence: tests.md distinguishes actual checks from unexecuted effect paths; finite fixtures do not prove all inputs.
tests
Bounded evidence
Selected actual source checks:
- mathlib::duck::wave33::substitution_order_and_quotes
These checks are file-level evidence; fragment branches not reached by these names remain source-derived.
External wave33 mathlib receipt retains native-commands.json, numeric statuses, raw debug/release logs, sorted exact outcomes, mutation logs and original/restored hashes. Seventeen named checks pass twice per profile; six production behavior mutants reject in both profiles, with restored positives. Source syntax is regenerated twice after formatting and compared byte-for-byte. Structural validation tests bindings, not Rust semantics.
No network/DNS/download, real catalog/corpus/model/teacher or database execution. Effect paths are source-derived; finite helper tests are not universal verification. No executable percentage surrogate or speed claim; future caps require metric/domain/reference and remain 1/2/5/10%.
invariant-and-cost
Invariant and cost
Invariant
Successful OS status is necessary but insufficient for wrapper success. Replacement order is observable; mode is a single argv element. No SQL parser or prepared statement semantics is supplied.
Cost
fill may expand repeatedly: cost is sum of intermediate string lengths plus replacement bytes. run stores complete stdout/stderr, memory O(output), child time and DB effects unbounded.
Domain and gaps
No network/DNS/download, real catalog/corpus/model/teacher or database execution. Effect paths are source-derived; finite helper tests are not universal verification. No executable percentage surrogate or speed claim; future caps require metric/domain/reference and remain 1/2/5/10%.
This page in Markdown โ https://md.groupants.elamur.ai/free/en/mova/tools/mathlib/src/duck.rs.groupant/