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

# algorithm-compensated-sum

The groupant beside algorithms/src/compensated_sum/mod.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 descriptive instance
- **source:** [`algorithms/src/compensated_sum/mod.rs`](https://github.com/ElamurAI/mova-free/blob/main/algorithms/src/compensated_sum/mod.rs)
- **source SHA-256:** `387ef988f6a3a072…`
- **repository folder:** [`algorithms/src/compensated_sum/mod.rs.groupant`](https://github.com/ElamurAI/mova-free/tree/main/algorithms/src/compensated_sum/mod.rs.groupant)
- **repository commit:** `855da7bd4a7b`

> **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` |
| **descriptant** | present | [descriptant](#descriptant) |
| **invariant** | partial | [approximant](#approximant) |
| **tests** | existing checks referenced | [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.

| id | 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) |
| `magnitude_branch` | magnitude_branch | partial source derived model | [magnitude_branch](#magnitude-branch) |
| `lost_unit_recovery` | lost_unit_recovery | partial source derived model | [lost_unit_recovery](#lost-unit-recovery) |
| `subnormal_boundary` | subnormal_boundary | partial source derived model | [subnormal_boundary](#subnormal-boundary) |
| `overflow_refusal` | overflow_refusal | partial source derived model | [overflow_refusal](#overflow-refusal) |

## Model text


### descriptant

#### compensated_sum mod.rs

Neumaier accumulates total and correction, selecting correction formula by magnitude. Return total+correction with all inputs and each state finite. Mathematical target is the real sum, but f64 rounding and underflow remain.

Original std-only implementation. Literature: see module-level Clenshaw (1955), Horner (1819), Neumaier (1974), or Lyness (1969) citation as applicable; citations are algorithm references, not copied code.

Epoch 2026-10-30: independent polynomial/basis/integer fixtures and explicit finite-error partitions. Simpson hidden bump demonstrates limits of sampled estimates. An initial correction-denominator mutant survived tight-tolerance tests; a loose-tolerance quartic assertion was added to isolate the correction, and that mutant was then rejected. No speed claim; no percentages inferred from finite observations. Rust syntax projection is partial, without macro expansion, type resolution or semantic proof.

### model

### behavior_complement

Let D be validated inputs and F the source f64 transition relation including tagged errors/status. Behavior complement is all candidate (input, output) pairs not in F: in particular nonfinite successful values, wrong recurrence results and falsely universal error guarantees. Invalid-input observations are errors, not approximate numeric answers. Neumaier accumulates total and correction, selecting correction formula by magnitude. Return total+correction with all inputs and each state finite. Mathematical target is the real sum, but f64 rounding and underflow remain.

### reverse_reconstruction

[1,2] and [3] both map to 3; zero-sum insertions preserve real totals but may change rounded traversal. The fiber contains many lengths/orders and cannot recover terms or correction state from final sum.

### magnitude_branch

When abs(total)>=abs(value), correction adds (total-next)+value, otherwise (value-next)+total. Both cancellation orders are exercised.

### lost_unit_recovery

[1e16,1,-1e16] yields 1; naive left fold yields 0. This particular witness is exact but does not establish exactness for all slices.

### subnormal_boundary

Two smallest positive subnormals return twice that quantum. Gradual underflow semantics assumed; no flush-to-zero transformation is requested.

### overflow_refusal

MAX+MAX is rejected; compensation never licenses an infinite total. Reject nonfinite input before state changes. Mathematical summability does not remove order-dependent overflow.


### approximant

#### Forward model and invariant

Neumaier accumulates total and correction, selecting correction formula by magnitude. Return total+correction with all inputs and each state finite. Mathematical target is the real sum, but f64 rounding and underflow remain.

Invariant: all successful scalar results are finite; invalid input and nonfinite arithmetic stay distinct from values. Simpson pending panels partition the original interval, cached values match their abscissae and evaluations stay within budget. Tests preserve fixture independence and never infer universal accuracy from passing samples.

Cost: O(n) validation and reduction, O(1) state, no allocation.

Numerical scope: real formulas motivate f64 recurrences, not bitwise real semantics. No universal relative bound near zero/cancellation. No useful cheaper certified executable surrogate chosen; this remains an explicit gap.

### tests

#### Evidence

cancellation_oracle covers both magnitude branches and exact i64 sums for 100 finite integer fixtures; subnormal/empty/overflow fixtures.

Compiled production negative control: Replace final total+correction with total-correction; cancellation_oracle fails. Original bytes restored and named positive test rerun. Full algorithms library passes twice debug and twice release with identical sorted test-name/results; receipts bind logs under $MOVA_DATA/runs/octopus-wave19-numeric-2026-10-30. Source projection generated twice and compared before installation. Strict crate all-target Clippy attempted; outcome in receipt.
