Documentation

CslibFrontier.Computability.Machines.Turing.MultiTape.Complexity.PolyTime.Prefix

Polynomial-time prefix scans #

First-match indices and taking or dropping an initial segment are polynomial-time, including when the predicate captures the input. The first-match rule is extracted from the native edge-CSP walk API; the prefix rule also serves its ancestry construction.

theorem Turing.MultiTapeTM.ComputableInPolyTime.findIdxWithInput {α β : Type} {enc : α ↪ List Bool} {encB : β ↪ List Bool} {xs : α → List β} {pred : α → β → Bool} (hx : ComputableInPolyTime xs enc (encList encB)) (hp : ComputableInPolyTime (fun (p : α × β) => pred p.1 p.2) (encPair enc encB) encBool) :
ComputableInPolyTime (fun (a : α) => List.findIdx (pred a) (xs a)) enc encUnary

Find the first matching position, in unary; if there is none, return the list length.

theorem Turing.MultiTapeTM.ComputableInPolyTime.takeWhileWithInput {α β : Type} {enc : α ↪ List Bool} {encB : β ↪ List Bool} {xs : α → List β} {pred : α → β → Bool} (hx : ComputableInPolyTime xs enc (encList encB)) (hp : ComputableInPolyTime (fun (p : α × β) => pred p.1 p.2) (encPair enc encB) encBool) :
ComputableInPolyTime (fun (a : α) => List.takeWhile (pred a) (xs a)) enc (encList encB)

Take the maximal prefix passing an input-dependent polynomial-time predicate.

theorem Turing.MultiTapeTM.ComputableInPolyTime.dropWhileWithInput {α β : Type} {enc : α ↪ List Bool} {encB : β ↪ List Bool} {xs : α → List β} {pred : α → β → Bool} (hx : ComputableInPolyTime xs enc (encList encB)) (hp : ComputableInPolyTime (fun (p : α × β) => pred p.1 p.2) (encPair enc encB) encBool) :
ComputableInPolyTime (fun (a : α) => List.dropWhile (pred a) (xs a)) enc (encList encB)

Drop the maximal prefix passing an input-dependent polynomial-time predicate.