Documentation

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

Native reversal and binary slicing of framed lists #

Reversal and taking or dropping a binary-counted prefix use space linear in the actual encoded list and counter. Every intermediate list is a prefix, suffix or reversal of stored input data; large binary counts never cause a list of that length to be allocated.

Main results #

Reverse a framed list in native space linear in its actual encoded storage.

theorem Turing.MultiTapeTM.ComputableInSpace.listDrop {α : Type} (enc : α ↪ List Bool) :
ComputableInSpace (fun (q : List α × ℕ) => List.drop q.2 q.1) (encPair (encList enc) encNat) (encList enc) fun (q : List α × ℕ) => ((encPair (encList enc) encNat) q).length

Drop a binary-counted prefix without allocating storage according to its numeric length.

theorem Turing.MultiTapeTM.ComputableInSpace.listTake {α : Type} (enc : α ↪ List Bool) :
ComputableInSpace (fun (q : List α × ℕ) => List.take q.2 q.1) (encPair (encList enc) encNat) (encList enc) fun (q : List α × ℕ) => ((encPair (encList enc) encNat) q).length

Take a binary-counted prefix using space linear in the actual framed list and counter.

Drop a binary-counted prefix of a bit word in space linear in the word and counter.

Right shift a binary natural in space linear in the value and the binary offset. The drop count is capped at the value's bit length. The suffix is already the canonical encoding, including the empty word for zero.

theorem Turing.MultiTapeTM.ComputableInSpace.budget_natModTwoPow {α : Type} {encIn : α ↪ List Bool} {B z d : α → ℕ} (hz : ComputableInSpace z encIn encNat B) (hd : ComputableInSpace d encIn encNat B) :
ComputableInSpace (fun (x : α) => z x % 2 ^ d x) encIn encNat B

Keep the low d bits of a binary natural within the budget of the two arguments. Capping d at the actual binary length of the value bounds the temporary modulus.

Read the bit of a bit word at a binary index, or fallback beyond its end, in space linear in the word and index.

Reverse a bit word in space linear in its length.