Documentation

CslibFrontier.Computability.Complexity.Classes.CountingHierarchy.UnaryModularList

Same-level unary modular collection, sums and products #

unaryModularList collects polynomially many binary oracle values in order, reducing each before appending it. The loop invariant bounds the index, list length and every stored entry under every supported reply of an arbitrary stateful handler. unaryModularList_mem therefore retains one fixed counting oracle at the original level.

unaryModularSum and unaryModularProduct reuse this list and the certified binary arithmetic programs. The reduced list and its sum and product have polynomial encoded lengths because the count is unary and the modulus is binary. At modulus zero the evaluators give the ordinary natural sum and product.

Adapted from LeanCanny.CountingHierarchy.UnaryModularList and UnaryModularAggregation at lean-canny commit 970f28a5ecefc1327402ade16c068aa4b1b2c183.

Collect the first n values in order, reducing each at modulus p.

theorem Cslib.Complexity.unaryModularList_get (n p : ℕ) (f : ℕ → ℕ) {i : ℕ} (hi : i < n) :
(unaryModularList n p f)[i]?.getD 0 = f i % p

Every genuine index reads exactly the corresponding modular value.

A plain polynomial-time callback yields a polynomial-time modular list. No positive-modulus hypothesis is needed: at modulus zero its values are unchanged.

theorem Cslib.Complexity.unaryModularList_mem {α : Type} {enc : α ↪ List Bool} {a : ℕ} {count modulus : α → ℕ} {f : α × ℕ → ℕ} (hcount : Turing.MultiTapeTM.ComputableInPolyTime count enc Turing.MultiTapeTM.encUnary) (hmod : Turing.MultiTapeTM.ComputableInPolyTime modulus enc Turing.MultiTapeTM.encNat) (hpos : ∀ (w : α), 0 < modulus w) (hf : f ∈ CountingFunction a (Turing.MultiTapeTM.encPair enc Turing.MultiTapeTM.encNat) Turing.MultiTapeTM.encNat) :
(fun (w : α) => unaryModularList (count w) (modulus w) fun (i : ℕ) => f (w, i)) ∈ CountingFunction a enc (Turing.MultiTapeTM.encList Turing.MultiTapeTM.encNat)

All stateful handlers obey the storage bound, because each returned oracle value is reduced before it is appended to the output list.

Sum a polynomially long list of reduced values and reduce the sum once more. The total modulus-zero value is the unreduced natural sum.

theorem Cslib.Complexity.unaryModularSum_eq (n p : ℕ) (v : ℕ → ℕ) :
unaryModularSum n p v = (∑ i ∈ Finset.range n, v i) % p

Reducing the summands before adding gives the actual sum modulo p, including p = 0.

Polynomially many modular summands use one fixed oracle at the original function level. The unary count bounds the collected list; no exponential index enumeration is used.

theorem Cslib.Complexity.unaryModularSum_cast (n p : ℕ) (v : ℕ → ℕ) :
↑(unaryModularSum n p v) = ∑ i : Fin n, ↑(v ↑i)

The total sum evaluator casts to the actual finite sum, for every modulus.

Multiply the collected residues and reduce once more.

At positive modulus, a unary number of factors uses one fixed oracle at the original function level. The intermediate product has at most the sum of the binary factor lengths.

theorem Cslib.Complexity.unaryModularProduct_cast (n p : ℕ) (v : ℕ → ℕ) :
↑(unaryModularProduct n p v) = ∏ i : Fin n, ↑(v ↑i)

The evaluator casts to the actual finite product at every modulus.