Elamur GroupantsโŒ•
โ˜ฐ

algorithm-totient-sieve-tests

The groupant beside algorithms/src/totient_sieve/tests.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
astpartialsyntax.json
costconditionalCost
descriptantpresentdescriptant
invariantpartialInvariant
testsbounded executedevidence

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.

idtypelabelwhere
behavior_complementbehavior_complementpartial relational specificationbehavior_complement
reverse_reconstructionreverse_reconstructionpartial relational specificationreverse_reconstruction
coprime_oraclecoprime_oraclepartial relational specificationcoprime_oracle
divisor_identitydivisor_identitypartial relational specificationdivisor_identity
resource_partitionresource_partitionpartial relational specificationresource_partition
prime_updateprime_updatepartial relational specificationprime_update

Model text

descriptant

algorithm-totient-sieve-tests

Epoch2026-10-30: original implementation and independent fixtures. Prospective relation: Finite executable observation: Return inclusive phi table, phi(0)=0, phi(1)=1; phi(k) counts integers1..k coprime to k. Initialize phi(k)=k, then for each prime p eliminate its factor by phi(multiple)-=phi(multiple)/p. Reject n>1000000 before allocation. Reference: Hardy and Wright, An Introduction to the Theory of Numbers, chapter V, Euler's function and its product formula. Assertions check independent arithmetic oracles, boundaries and identities; passing fixtures do not establish untested behavior.

Predicted cost: O(n log log n) arithmetic and O(n) storage. GCD oracle through2048 has O(N^2 log N) upper bound. Allocation failure follows Vec policy.

Compiled controls are rejected and exact bytes restored. Six file roots contain36 typed views, no fragments. Twice-identical partial syntax binds source; macros remain opaque. No semantic AST, formal proof, approximate surrogate or speed claim.

model

algorithm-totient-sieve-tests

Forward

Finite executable observation: Return inclusive phi table, phi(0)=0, phi(1)=1; phi(k) counts integers1..k coprime to k. Initialize phi(k)=k, then for each prime p eliminate its factor by phi(multiple)-=phi(multiple)/p. Reject n>1000000 before allocation. Reference: Hardy and Wright, An Introduction to the Theory of Numbers, chapter V, Euler's function and its product formula. Assertions check independent arithmetic oracles, boundaries and identities; passing fixtures do not establish untested behavior.

Invariant

Entries equal k times product(1-1/p) over processed prime divisors; updates divide exactly. 0<=phi(k)<=k; cap bounds indices.

Cost

O(n log log n) arithmetic and O(n) storage. GCD oracle through2048 has O(N^2 log N) upper bound. Allocation failure follows Vec policy.

behavior_complement

Universe is fixture executions and assertion outcomes. A passing actual/expected mismatch is excluded; failure cannot count as success. This finite complement does not cover all API calls.

reverse_reconstruction

Passing summary retains every implementation agreeing on exercised fixtures, including implementations wrong elsewhere. Failure locates an observed disagreement but cannot alone distinguish oracle and implementation defects.

coprime_oracle

GCD counting independently checks each n=1..2048 without prime-factor elimination.

divisor_identity

For n>=1, sum_{d|n} phi(d)=n; tests check n<=512, partitioning integers by gcd.

resource_partition

n=0,1 and MAX_N accepted; phi(MAX_N)=400000. MAX_N+1 and usize::MAX rejected before allocation.

prime_update

phi(p)=p identifies prime p>=2. Omitting subtraction compiles and fails exhaustive_gcd_oracle.

evidence

Evidence

Source SHA-256: 2b39f420ef0c2c90a5baa6b74dc4a74e68f4a3103eb751be2a43eaad341e32ba.

Nine tests total, three per algorithm, pass twice debug and twice release with identical normalized outcomes. Three compiled production controls fail exhaustive_gcd_oracle, exhaustive_factor_oracle and exhaustive_iterative_oracle; exact bytes restored before positives. Strict all-target Clippy and narrow formatting pass. External wave16 numeric bundle retains logs. Finite checks do not establish universal correctness or allocator success.

This page in Markdown โ†’ https://md.groupants.elamur.ai/free/en/mova/algorithms/src/totient_sieve/tests.rs.groupant/