Elamur GroupantsโŒ•
โ˜ฐ

algorithm-fast-walsh-hadamard

The groupant beside algorithms/src/fast_walsh_hadamard/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

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
character_diagonalizationcharacter_diagonalizationpartial relational specificationcharacter_diagonalization
inverse_domaininverse_domainpartial relational specificationinverse_domain
padding_shapepadding_shapepartial relational specificationpadding_shape
bilinearity_massbilinearity_masspartial relational specificationbilinearity_mass
overflow_validationoverflow_validationpartial relational specificationoverflow_validation
cost_crossovercost_crossoverpartial relational specificationcost_crossover

Model text

descriptant

Modeling epoch, 2026-10-30

Original implementation and finite oracle. For length n=2^d, H[k,i]=(-1)^popcount(k&i). Butterfly stages compute Hx, inverse scales by n^-1. XOR convolution is H((Ha)*(Hb))/n after zero extension to next_power_of_two(max lengths); empty operands return empty after caps.

The first epoch retains ambiguity explicitly: finite recurrence prefixes can have multiple minimum-order continuations, and convolution cannot uniquely identify operands. Independent Gaussian/matrix/direct-sum checks avoid relying only on reciprocal algorithms. Arithmetic is exact; there is no approximate production profile. Partial source projections do not resolve names, expand macros or prove semantics. Resource caps bound work but do not guarantee performance; allocator refusal is unforced.

model

fast_walsh_hadamard mod.rs

Forward

For length n=2^d, H[k,i]=(-1)^popcount(k&i). Butterfly stages compute Hx, inverse scales by n^-1. XOR convolution is H((Ha)*(Hb))/n after zero extension to next_power_of_two(max lengths); empty operands return empty after caps.

Invariant

Butterflies preserve residues in [0,p). Hยฒ=nI because distinct binary characters cancel. n is invertible since p is odd and n is a power of two. The chosen cap n<=2^20 also gives n<p. No primitive root assumption applies.

Cost

For padded n, three transforms perform 3nlog2(n)/2 butterflies, n pointwise products and n inverse scalings, plus O(log p) exponentiation; O(n) space. Direct transform is O(n log n+inverse*log p) and O(1) auxiliary storage. Padding and tiny inputs can lose against naive convolution.

behavior_complement

Within validated arrays and candidate outputs, transform values unequal to the binary character sum and convolution values unequal to XOR-index sums are absent. Shape-invalid transform calls paired with mutation or Ok are absent. Finite oracle evidence is not a universal Rust proof.

reverse_reconstruction

For a fixed length, H and normalized inverse uniquely recover field residues, but raw u64 representatives are ambiguous modulo p. For convolution output c, retain every pair (a,b) on the declared padded domain with Ha*Hb=Hc; factoring is generally nonunique, especially when spectra contain zeros.

character_diagonalization

Characters obey chi_k(i XOR j)=chi_k(i)chi_k(j), yielding H(a XOR-convolve b)=Ha*Hb. This diagonalizes XOR convolution specifically; ordinary index addition would require different characters and padding.

inverse_domain

Hยฒ=nI on binary index domains; n=2^d is nonzero in an odd prime field. n^-1 exists by Fermat. No primitive roots or n dividing p-1 premise is needed. Matrix and inverse tests exercise these equations independently.

padding_shape

For nonempty inputs length is next_power_of_two(max lengths); indices i XOR j stay inside this domain. Trailing zeros remain in output. A singleton identity can thus increase the visible length of a non-power-of-two input. Empty operands map to empty only after length caps.

bilinearity_mass

For equal padded domain, convolution is bilinear in residues and sum(c)=sum(a)*sum(b) modulo p. Neither property implies injectivity. Delta at index0 is the identity, while delta_i convolved with delta_i is delta0.

overflow_validation

Transform checks nonzero power-of-two before cap, then normalizes. Convolution checks both caps before empty. Errors from validation leave transform input unchanged. Add/sub intermediates<2p and products<2^60 fit u64; bounded dimensions make doubling safe. Allocation refusal remains unforced.

cost_crossover

Prospective model contrasts quadratic pair sums with3n log2(n)/2 butterflies plus linear products. Repeated release native timing at2,8,32,128,512 tests a dense crossover only; warmup/frequency variance and imbalance prevent universal speed assertions.

evidence

Evidence, 2026-10-30

Four tests per module pass twice debug and twice release with equal normalized identities. Independent production and oracle mutations compile and fail named assertions; exact source bytes are restored and positives rerun. Strict algorithm all-target Clippy and narrow formatting are checked. Raw logs: $MOVA_DATA/runs/octopus-wave11-numeric-2026-10-30/.

Prospective prediction precedes timing. Three release rounds: at n=2 FWHT219โ€“220ns vs naive25ns; n=8 315โ€“327ns vs159ns; n=32 431โ€“803ns vs1156โ€“2292ns; n=128 1693โ€“1720ns vs18312โ€“18442ns; n=512 7698โ€“8048ns vs280986โ€“283379ns. Dense sampled crossover lies between8 and32 here. CPU frequency/warmup variance is visible; no universal gain or approximation claim.

Timing SHA256 7a59dc9fba33456706c46b664076b3ff892b8ecfe2f1c9cebd8010f921adbc1a; prospective SHA256 a96a5a67d9a2f4aadb45a16247fc87e009897b44650160aef00b4649e3f3e236.

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