Duplicate flags with shared comparisons and saved swaps #
A sorted array has a repeated key at a position exactly when that key equals a neighbor.
adjacentDuplicateCircuit computes each adjacent equality once and shares it between the
neighbors. It adds one OR gate per record; the last record reuses the first equality output,
which is false, for its missing successor. The empty array uses no gates.
duplicateFlagsCircuit accepts an arbitrary array of 2 ^ d records. It sorts by selected key
coordinates, computes the flags, then reverses the saved swaps on the flags alone. Outputs refer
to the original positions, including when complete records repeat. No record identifiers or
second sort are needed. Header and payload bits can be retained by free input wiring.
Costs include constants and negations. Gate counts do not certify construction runtime.
Main definitions #
Cslib.Circuits.Boolean.adjacentDuplicateCircuit: share adjacent-key equality tests.Cslib.Circuits.Boolean.duplicateFlagsCircuit: duplicate flags in original input order.
Main results #
Cslib.Circuits.Boolean.eval_adjacentDuplicateCircuit_iff: exact detection on sorted keys.Cslib.Circuits.Boolean.eval_duplicateFlagsCircuit_iff: exact detection on arbitrary inputs.Cslib.Circuits.Boolean.cost_program_duplicateFlagsCircuit: exact weighted gate cost.Cslib.Circuits.Boolean.size_duplicateFlagsCircuit: exact total gate count.
References #
Simplifies MassProduction/Nonuniform/AdjacentDuplicates.lean and the conflict-detection construction in S. Schlesinger, Boolean circuit mass production formalization, using the saved decisions of K. E. Batcher, Sorting Networks and Their Applications.
Sharing the equality outputs adds exactly one OR gate per record.
Sort once, flag repeated selected keys, and return flags to original positions.
Instances For
A flag is true exactly when another original record has the same selected key.
Exact weighted cost of one sort, shared adjacent tests, OR gates, and flag restoration.
Exact total gate count, including empty keys and zero-width records.