Composable natural-number index codecs for hardness reductions #
Many polynomial-time and parsimonious reductions allocate fresh natural-number variable or vertex
names across several disjoint roles — original vertices or variables, fixed hub/pendant gadgets,
clause-splitting pairs, occurrence-splitting triples, or layered arc gadgets — and then discharge
injectivity, non-collision between roles, partial decoding, binary bit-length bounds, and
ComputableInPolyTime certificates under Turing.MultiTapeTM.encNat.
Cslib.Complexity.NatCodec α packages a computable numbering encode : α → ℕ together with its
exact partial inverse decode? : ℕ → Option α (decode? n = some a ↔ encode a = n). Combinators
build compound namespaces without ad-hoc parity or Nat.unpair arithmetic:
NatCodec.nat,NatCodec.fin: base codecs forℕandFin k.NatCodec.shift,NatCodec.finSum: offset a namespace byk, or reserve0, …, k - 1forFin kwhile shifting a payload namespace abovek.NatCodec.sum: interleave two namespaces at even (2 * c₁ a) and odd (2 * c₂ b + 1) indices, with automatic range disjointness (disjoint_range_sum).NatCodec.pair: combine two namespaces through Cantor-style pairingNat.pair, doubling worst-case binary bit-length (Nat.size_pair_le,NatCodec.size_pair_le).
All combinators carry @[fun_prop] ComputableInPolyTime rules into encNat, using
Turing.MultiTapeTM.ComputableInPolyTime.sumElim from PolyTime.Sum.
Main definitions #
Cslib.Complexity.NatCodec: computable natural-number codec with exact partial inversedecode?and embedding coercionNatCodec.toEmbedding.Cslib.Complexity.NatCodec.nat,Cslib.Complexity.NatCodec.fin: base codecs.Cslib.Complexity.NatCodec.shift,Cslib.Complexity.NatCodec.finSum,Cslib.Complexity.NatCodec.sum,Cslib.Complexity.NatCodec.pair: offset, finite-prefix sum, even/odd sum, andNat.pairproduct combinators.
Main results #
Cslib.Complexity.NatCodec.injective,Cslib.Complexity.NatCodec.decode?_eq_some_iff,Cslib.Complexity.NatCodec.decode?_eq_none_iff: injectivity and exact range characterization ofdecode?.Cslib.Complexity.NatCodec.disjoint_range_finSum,Cslib.Complexity.NatCodec.disjoint_range_sum: automatic non-collision between summands.Nat.size_pair_le,Cslib.Complexity.NatCodec.size_finSum_le,Cslib.Complexity.NatCodec.size_sum_le,Cslib.Complexity.NatCodec.size_pair_le: binary bit-length bounds (Nat.sizeand(encNat ·).length).Cslib.Complexity.NatCodec.computableInPolyTime_finSum,Cslib.Complexity.NatCodec.computableInPolyTime_sum,Cslib.Complexity.NatCodec.computableInPolyTime_pair:@[fun_prop]polynomial-time certificates underencNat(includingencUnaryleaves viacomputableInPolyTime_nat_unary).
A computable injective numbering encode : α → ℕ equipped with its exact partial inverse
decode? : ℕ → Option α (decode? n = some a ↔ encode a = n).
- encode : α → ℕ
Assign a natural-number index to
a. Encoding followed by
decode?recovers the input.Any
some areturned bydecode? nencodes back ton.
Instances For
Every NatCodec is injective.
Binary word length of c a under encNat equals (c a).size.
Base codecs and combinators #
Even and odd branches of NatCodec.sum occupy disjoint subsets of ℕ.
Product codec combining c₁ and c₂ through Nat.pair / Nat.unpair.
Binary bit-length bounds #
Interleaving via NatCodec.sum adds at most one binary digit to the payload index.
Polynomial-time computability under encNat #
Unary natural indices convert to binary encNat indices in polynomial time.