Concrete native modular triangle-counting code #
The program computes three actual unsigned residue arrays, a spread table by its binary recurrence, two zero-padded cyclic-monomial matrices, the actual seven-product Strassen product, and the selected coefficient sum. It contains no triple-enumeration loop and takes no table, layout, multiplication, result or execution certificate as input.
Pointers, dimensions and modulus are unsigned words; the original three weight arrays hold canonical signed words. Monomial coefficients are written directly as canonical signed zero or one. The existing residue loop explicitly decodes its nonnegative remainders. The last scan explicitly decodes the nonnegative product coefficients before unsigned addition.
The source algorithm is Programs/Sec3/Theorem17/Hashing/CountPrime.lean at pinned revision
16a5ce41304fcdaea4e0be7c132e1c361dc26da5. This native adaptation uses the genuine standard
division/remainder instructions and the existing signed remainder kernel instead of Light's
bit-doubling residue table. This module defines code; Exec, Flat,
SourceBounds and TimeBound prove the complete native correctness, initialized execution,
logarithmic admission, width-independent prefix bounds and charged subcubic resource claims.
Low helper-bank registers, reused only between completed calls.
Low helper result / argument register.
Low helper power-base register.
Low helper power-exponent register.
Low residue input pointer.
Low residue output pointer.
Low residue length.
Low signed modulus.
First low Strassen matrix pointer.
Second low Strassen matrix pointer.
Low Strassen output pointer.
Low Strassen scratch pointer.
Low Strassen matrix depth.
Low Strassen coefficient length.
Original side length.
Positive runtime modulus.
Original canonical signed AB matrix.
Original canonical signed BC matrix, indexed by (b,c).
Original canonical signed AC matrix.
Beginning of caller-disjoint dirty workspace.
Raw unsigned modular-zero count.
Raw / canonical signed zero.
Raw unsigned one.
Raw unsigned two, also the canonical signed word for one.
Raw unsigned four.
Actual computed ceiling binary logarithm of the side.
Padded power-of-two side.
Original matrix word count.
Padded coefficient word count.
First unsigned residue block.
Second unsigned residue block.
Third unsigned residue block.
Actually computed binary-to-base-four spread table.
First zero-padded monomial matrix.
Second zero-padded monomial matrix, with BC transposed.
Actual signed-coefficient product.
Reused scalar/recursive multiplication scratch, followed by explicit frames.
Outer table, matrix or pair index.
Inner coefficient index.
Computed row.
Computed column.
Computed Morton index.
Spread of the current row.
Spread of the current column.
Base of one coefficient block.
Actual unsigned residue, or the out-of-range padding sentinel p.
Actual indexed address.
Arithmetic / loaded-word temporary.
Canonical signed encoding of the positive modulus.
Current unsigned residue-array pointer.
Current coefficient-matrix pointer.
Number of padded matrix cells.
Real constant initialization and the existing native ceiling logarithm call.
Runtime powers, lengths and every actual workspace pointer.
Call the existing actual signed-residue array loop on one original matrix.
Initialize the first actual spread-table word and its next unwritten index.
Compute one spread-table entry from its strictly earlier half-index entry.
Compute the whole spread table; no table is supplied by the caller.
Load actual row/column spread words and interleave their positions.
Compute the true row-major source position, with the actual BC transpose when requested.
Store one actual canonical signed monomial coefficient and advance its index.
Write one whole actual monomial coefficient block, including each padding zero.
Guard the real residue read and use the out-of-range key p for every padded cell.
One real padded matrix cell: compute coordinates/Morton address, select the admitted residue or padding sentinel, write every coefficient, and advance the original cell index.
Create a complete zero-padded cyclic matrix from real residue words.
Invoke the actual fixed Strassen controller in the low 64-register bank.
One actual selected-coefficient read and unsigned count accumulation.
Read and add exactly one coefficient for each original AB pair.
Compute the actual logarithm and all runtime layout metadata.
Compute all three original residue matrices by actual signed-remainder calls.
Compute the spread table and both complete padded coefficient matrices.
Concrete runtime-parameter counter; every multiplication is actual native code.
Ordinary initialized input: raw (n,p), followed by the three canonical signed arrays.
Fixed initialized counter code, independent of dimensions, modulus and physical width.
The complete counter is one finite standard native program with no word-width reads.