Fixed native code for pruned tensor queries #
The controller uses an explicit depth-first stack. Query and value directories have one row per depth. A shared timestamp directory deduplicates child suffixes without clearing a dense array at every node. Encoded products and sums use the existing native signed kernels.
Main definitions #
PrunedQuery.kernel: evaluator with explicit caller-supplied array and scratch addresses.PrunedQuery.program: initialized-input wrapper computing all addresses from the depth and query-count headers.
Client execution interfaces are exec_kernel in Pruned.Kernel, runs and runs_bilinear
in Pruned.Flat, and runs_wide in Pruned.Width. Other stage exec_* lemmas and controller
invariants under Pruned/ are internal implementation APIs. They are public to compose proofs
across the stage modules, rather than intended as independent caller contracts.
References #
The query-set recursion is from [AlmanWilliams2026, Section 2.4.2], selectively adapted from
Anthropic's formal-math revision 16a5ce41304fcdaea4e0be7c132e1c361dc26da5,
pinned source. The explicit iterative stack and
timestamp implementation are new native code; the source machine is not imported.
The program has a fixed register bank, including nine signed-arithmetic scratch registers.
Original tensor depth, loaded from the ordinary input header.
Computed encoding-array length and per-depth directory capacity, 10^L.
Pointer to the left canonical signed encoding array.
Pointer to the right canonical signed encoding array.
Pointer to the original unsigned query-code list, including repeats.
Number of supplied queries, before native deduplication.
Pointer to the answer list, in the original query order.
Caller-supplied start of the explicit stack and directory workspace.
Current timestamp generation for native query deduplication.
Pointer to the first four-word stack frame.
Pointer to the first per-depth distinct-query row.
Pointer to the first per-depth signed-value row.
Pointer to the shared query-membership timestamp directory.
Current stack depth, with zero denoting the root.
Controller phase: zero for entry, one for dispatch, two for returned-child accumulation.
Traversal flag; returning from the root sets this to zero.
Raw unsigned constant one for counters and offsets.
Raw unsigned radix ten for the fixed term and query dictionaries.
Inner-output wildcard digit, in the existing term numbering.
Raw unsigned width of a stack frame: four words.
Address of the currently loaded stack frame.
Number of distinct requests stored in the current frame.
Processed least-significant leaf digits of the current node.
Place value of the next leaf digit, 10^level.
Next term number to dispatch or accumulate.
Loop counter for powers, scans, clearing, accumulation and reporting.
Distinct child count computed by the actual timestamp scan.
Current numerical output-string code loaded from a query list.
First output digit computed by remainder modulo ten.
Remaining output digits computed by division by ten.
Scratch address used by native indexed loads and stores.
Scratch word for arithmetic, branch fallbacks and loaded values.
Scratch word for row-size and address products.
Timestamp loaded from the membership directory.
Address of the current depth's request row.
Address of the current depth's accumulator row.
Address of the next depth's computed request row.
Address of the next depth's returned-value row.
Computed child stack depth.
Computed address of the frame about to be pushed.
Computed leaf prefix of the child about to be pushed.
Computed leaf place value for the child about to be pushed.
Raw unsigned constant zero.
Raw unsigned constant two, initialized with the fixed scalar constants.
Constant initialization, before the generic depth-controlled power routine.
Embed the five-register native power routine into the pruned-query register bank.
Initialize constants and compute the actual encoding-array length 10^L.
Separate stack frames, query lists, value directories and membership timestamps.
Append one previously unseen suffix and mark it with the current epoch.
The two fixed suffix kernels either divide a selected child query or copy a root query.
A selected child suffix is computed by an actual unsigned division.
Load the next supplied query and compute its actual first digit.
Root queries are copied directly; child queries are filtered by the native digit tests.
One deduplicating scan step, including input indexing, dispatch and counter increment.
Initialize one query scan with a genuinely fresh native epoch.
Scan and deduplicate an explicit source list.
Point the deduplicating root scan at the actual supplied query list.
Store the four actual root-frame words and enter its first controller phase.
Deduplicate supplied queries into the root list; the original list remains read-only.
Load the current frame and compute its depth-specific list/value addresses.
Return to the parent's accumulation phase, or finish the root.
Load both actual encoded words at the current leaf prefix.
One requested leaf product, using the existing native signed multiplication kernel.
Evaluate a requested leaf from the actual two encoded words.
One actual indexed store for an explicitly listed requested value.
Clear exactly the requested parent values, not the full dense directory.
Store the actual next-term counter and enter the frame's dispatch phase.
Initialize the stored next-term counter after sparse accumulator clearing.
Initialize requested values and the frame's next-term counter.
Entry phase: multiply at a leaf; otherwise initialize the requested accumulators.
Form and deduplicate a child request set using actual tests, loads and stores.
Advance the parent's term after an empty child or after accumulating its returned values.
Push a nonempty child, with the exact least-significant-first leaf leafPrefix.
Dispatch the next of the ten actual terms, recursing only on nonempty computed sets.
Load the two encoded operands at the actual parent query and child suffix addresses.
Store the signed sum back at the computed parent query address.
Add one returned child value to its parent's actual signed accumulator.
Select the returned child by the same two real digit comparisons as child construction.
Load, dispatch and advance one actual parent query.
Consume a returned child's values at the explicitly listed contributing parent queries.
Traverse the parent requests once, then advance the stored term counter.
One explicit-stack controller step. Every branch and frame address is native work.
One actual lookup and indexed output store, including the reporting counter.
Report results in the original input query order, including repeated queries.
The common stack evaluator after powers and caller parameters have been initialized.
Evaluate the computed root, then report the original query list.
Generic native evaluator with explicit pointer arguments and a fresh timestamp epoch.
Load the two ordinary scalar input headers.
Compute all initial array/output/scratch pointers from the actual array and query lengths.
One finite program reading the header and encoded arrays from ordinary initialized memory.
The same program is used at every word width; it never reads the physical word size.
A fixed bound on both control code and all arithmetic blocks, including the final halt.