Documentation

CslibFrontier.Computability.Machines.Turing.MultiTape.Complexity.InSpace.StoredCount

Summing and counting over a range with a stored counter #

Turing.MultiTapeTM.ComputableInSpace.countWith counts the indices i < m a that satisfy a predicate p (i, a) of a stored index and the input, where p is in the context form of Turing.MultiTapeTM.ComputableInSpace.loopWith. The registers are the bound, the index and the count, so the space is that of the bound and of p, plus the logarithm of the length of the input, for any number of indices. Majority and existence over the range are corollaries.

Main results #

theorem Turing.MultiTapeTM.ComputableInSpace.sumWith {α : Type} {encA : α ↪ List Bool} {m : α → ℕ} {f : ℕ × α → ℕ} {S : α → ℕ} (hm : ComputableInSpace m encA encNat S) (hf : ComputableInSpace f (encPair encNat encA) encNat fun (q : ℕ × α) => (encNat q.1).length + S q.2) (hsum : BigOLe (fun (a : α) => (encNat (∑ i ∈ Finset.range (m a), f (i, a))).length) S) :
ComputableInSpace (fun (a : α) => ∑ i ∈ Finset.range (m a), f (i, a)) encA encNat fun (a : α) => S a + (encA a).length.log2

Summing with a stored counter. The range bound and each term are computed on the read-only input, with the current binary index available to the term computation. The budget also bounds the encoded total. All terms are natural, so partial sums meet the same bound.

theorem Turing.MultiTapeTM.ComputableInSpace.countWith {α : Type} {encA : α ↪ List Bool} {m : α → ℕ} {p : ℕ × α → Bool} {S : α → ℕ} (hm : ComputableInSpace m encA encNat S) (hp : ComputableInSpace p (encPair encNat encA) encBool fun (q : ℕ × α) => (encNat q.1).length + S q.2) :
ComputableInSpace (fun (a : α) => List.countP (fun (i : ℕ) => p (i, a)) (List.range (m a))) encA encNat fun (a : α) => S a + (encA a).length.log2

Counting with a stored counter. If the bound m is computable within S, and the predicate p takes a stored index and the input within the length of the index plus S, then the number of indices i < m a with p (i, a) is computable within S + log₂ n on inputs of length n.

theorem Turing.MultiTapeTM.ComputableInSpace.majorityWith {α : Type} {encA : α ↪ List Bool} {m : α → ℕ} {p : ℕ × α → Bool} {S : α → ℕ} (hm : ComputableInSpace m encA encNat S) (hp : ComputableInSpace p (encPair encNat encA) encBool fun (q : ℕ × α) => (encNat q.1).length + S q.2) :
ComputableInSpace (fun (a : α) => decide (m a < 2 * List.countP (fun (i : ℕ) => p (i, a)) (List.range (m a)))) encA encBool fun (a : α) => S a + (encA a).length.log2

Majority over a range. Whether more than half of the indices i < m a satisfy p (i, a), within S + log₂ n.

theorem Turing.MultiTapeTM.ComputableInSpace.anyWith {α : Type} {encA : α ↪ List Bool} {m : α → ℕ} {p : ℕ × α → Bool} {S : α → ℕ} (hm : ComputableInSpace m encA encNat S) (hp : ComputableInSpace p (encPair encNat encA) encBool fun (q : ℕ × α) => (encNat q.1).length + S q.2) :
ComputableInSpace (fun (a : α) => (List.range (m a)).any fun (i : ℕ) => p (i, a)) encA encBool fun (a : α) => S a + (encA a).length.log2

Existence over a range. Whether some index i < m a satisfies p (i, a), within S + log₂ n.