Documentation

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

Polynomial-time list operations #

List operations for the polynomial-time calculus, using Christian Reitwiessner's encodings, degree-bounded operations and fold rules. Indices use encUnary: an index returned by idxOf is at most the list length, irrespective of the encoding of its elements. In particular, looking up a variable with a large binary label does not require a certificate as long as that label.

Predicate counts and Boolean scans use only ListEncoding and SizedListEncoding: reading the list and bounding traversal suffice because the state is a unary counter or a Boolean. Raw bit strings and framed lists are both instances. No output-list construction capability is needed; counting folds a counter directly instead of constructing the matching sublist.

Main results #

theorem Turing.MultiTapeTM.ComputableTidilyInPolyTime.bitsAppend {γ : Type} {encIn : γ ↪ List Bool} {left right : γ → List Bool} (hleft : ComputableTidilyInPolyTime left encIn encBits) (hright : ComputableTidilyInPolyTime right encIn encBits) :
ComputableTidilyInPolyTime (fun (x : γ) => left x ++ right x) encIn encBits

Concatenate raw bit strings, charging for both computed words.

theorem Turing.MultiTapeTM.ComputableTidilyInPolyTime.bitsCons {γ : Type} {encIn : γ ↪ List Bool} {head : γ → Bool} {tail : γ → List Bool} (hhead : ComputableTidilyInPolyTime head encIn encBool) (htail : ComputableTidilyInPolyTime tail encIn encBits) :
ComputableTidilyInPolyTime (fun (x : γ) => head x :: tail x) encIn encBits

Prepend a computed bit to a raw bit string.

theorem Turing.MultiTapeTM.ComputableTidilyInPolyTime.headD {α : Type} {encA : α ↪ List Bool} {encL : List α ↪ List Bool} [ListEncoding encA encL] (fallback : α) :
ComputableTidilyInPolyTime (fun (list : List α) => list.headD fallback) encL encA

Read the head of any list encoding with a fixed fallback.

theorem Turing.MultiTapeTM.ComputableTidilyInPolyTime.listHeadDWithInput {α γ : Type} {encA : α ↪ List Bool} {encIn : γ ↪ List Bool} {list : γ → List α} (fallback : α) (hlist : ComputableTidilyInPolyTime list encIn (encList encA)) :
ComputableTidilyInPolyTime (fun (a : γ) => (list a).headD fallback) encIn encA

Read a computed framed list's head, inferring the element encoding from the list before composing with a later field projection.

Drop the head of any list encoding.

Test emptiness without decoding a list element or requiring a default value.

Test a framed list's emptiness, determining its element encoding for automation.

Test a raw bit string's emptiness using the standard Boolean element encoding.

Drop the head of a framed list, determining its element encoding for automation.

Drop the first raw bit. The raw encoding fixes the otherwise undetermined element encoding.

Reverse a raw bit string using an accumulator that grows by one bit per step.

theorem Turing.MultiTapeTM.ComputableTidilyInPolyTime.cons {α : Type} (enc : α ↪ List Bool) :
ComputableTidilyInPolyTime (fun (p : α × List α) => p.1 :: p.2) (encPair enc (encList enc)) (encList enc)

Prepending an element to a framed list is polynomial-time.

Concatenating two framed lists is polynomial-time.

theorem Turing.MultiTapeTM.ComputableTidilyInPolyTime.cons' {α γ : Type} {encA : α ↪ List Bool} {encIn : γ ↪ List Bool} {head : γ → α} {tail : γ → List α} (hhead : ComputableTidilyInPolyTime head encIn encA) (htail : ComputableTidilyInPolyTime tail encIn (encList encA)) :
ComputableTidilyInPolyTime (fun (x : γ) => head x :: tail x) encIn (encList encA)

Prepend computed data. The result encoding determines the element encoding before fun_prop searches for the two component certificates.

theorem Turing.MultiTapeTM.ComputableTidilyInPolyTime.listAppend' {α γ : Type} {encA : α ↪ List Bool} {encIn : γ ↪ List Bool} {left right : γ → List α} (hleft : ComputableTidilyInPolyTime left encIn (encList encA)) (hright : ComputableTidilyInPolyTime right encIn (encList encA)) :
ComputableTidilyInPolyTime (fun (x : γ) => left x ++ right x) encIn (encList encA)

Concatenate computed lists, inferring their shared encoding from the result.

Reverse a framed list; the accumulator is a permutation of a prefix of the input.

theorem Turing.MultiTapeTM.ComputableTidilyInPolyTime.listReverseWithInput {α γ : Type} {encA : α ↪ List Bool} {encIn : γ ↪ List Bool} {list : γ → List α} (hlist : ComputableTidilyInPolyTime list encIn (encList encA)) :
ComputableTidilyInPolyTime (fun (a : γ) => (list a).reverse) encIn (encList encA)

Reverse a computed framed list, inferring its element encoding from the result.

theorem Turing.MultiTapeTM.ComputableTidilyInPolyTime.findWith {α γ π : Type} {encA : α ↪ List Bool} {encIn : γ ↪ List Bool} {encP : π ↪ List Bool} {test : π × α → Bool} {par : γ → π} {list : γ → List α} (htest : ComputableTidilyInPolyTime test (encPair encP encA) encBool) (hpar : ComputableTidilyInPolyTime par encIn encP) (hlist : ComputableTidilyInPolyTime list encIn (encList encA)) :
ComputableTidilyInPolyTime (fun (x : γ) => List.find? (fun (a : α) => test (par x, a)) (list x)) encIn (encOption encA)

Find the first element passing a polynomial-time test with a fixed parameter. The list may have any polynomial encoded length.

theorem Turing.MultiTapeTM.ComputableTidilyInPolyTime.findWithInput {α γ : Type} {encA : α ↪ List Bool} {encIn : γ ↪ List Bool} {test : γ → α → Bool} {list : γ → List α} (hlist : ComputableTidilyInPolyTime list encIn (encList encA)) (htest : ComputableTidilyInPolyTime (fun (p : γ × α) => test p.1 p.2) (encPair encIn encA) encBool) :
ComputableTidilyInPolyTime (fun (x : γ) => List.find? (test x) (list x)) encIn (encOption encA)

Search with a predicate that captures the original input.

theorem Turing.MultiTapeTM.ComputableTidilyInPolyTime.filterWith {α γ π : Type} {encA : α ↪ List Bool} {encIn : γ ↪ List Bool} {encP : π ↪ List Bool} {test : π × α → Bool} {par : γ → π} {list : γ → List α} (htest : ComputableTidilyInPolyTime test (encPair encP encA) encBool) (hpar : ComputableTidilyInPolyTime par encIn encP) (hlist : ComputableTidilyInPolyTime list encIn (encList encA)) :
ComputableTidilyInPolyTime (fun (x : γ) => List.filter (fun (a : α) => test (par x, a)) (list x)) encIn (encList encA)

Keep the elements passing a polynomial-time test with a fixed parameter. The input list may have any polynomial encoded length.

theorem Turing.MultiTapeTM.ComputableTidilyInPolyTime.filterWithInput {α γ : Type} {encA : α ↪ List Bool} {encIn : γ ↪ List Bool} {test : γ → α → Bool} {list : γ → List α} (hlist : ComputableTidilyInPolyTime list encIn (encList encA)) (htest : ComputableTidilyInPolyTime (fun (p : γ × α) => test p.1 p.2) (encPair encIn encA) encBool) :
ComputableTidilyInPolyTime (fun (x : γ) => List.filter (test x) (list x)) encIn (encList encA)

Filter with a predicate that captures the original input.

Filtering a list by a polynomial-time test is polynomial-time.

theorem Turing.MultiTapeTM.ComputableTidilyInPolyTime.mapWith {α β γ π : Type} {encA : α ↪ List Bool} {encB : β ↪ List Bool} {encIn : γ ↪ List Bool} {encP : π ↪ List Bool} {f : π × α → β} {par : γ → π} {list : γ → List α} (hf : ComputableTidilyInPolyTime f (encPair encP encA) encB) (hpar : ComputableTidilyInPolyTime par encIn encP) (hlist : ComputableTidilyInPolyTime list encIn (encList encA)) :
ComputableTidilyInPolyTime (fun (x : γ) => List.map (fun (a : α) => f (par x, a)) (list x)) encIn (encList encB)

Map a polynomial-time function with a fixed parameter over a polynomial-time computable list. The list may have any polynomial encoded length.

theorem Turing.MultiTapeTM.ComputableTidilyInPolyTime.mapWithInput {α β γ : Type} {encA : α ↪ List Bool} {encB : β ↪ List Bool} {encIn : γ ↪ List Bool} {f : γ → α → β} {list : γ → List α} (hlist : ComputableTidilyInPolyTime list encIn (encList encA)) (hf : ComputableTidilyInPolyTime (fun (p : γ × α) => f p.1 p.2) (encPair encIn encA) encB) :
ComputableTidilyInPolyTime (fun (x : γ) => List.map (f x) (list x)) encIn (encList encB)

Map a function that also uses the original input. A single joint certificate in the input and list element makes the cost uniform across all elements. The list certificate is supplied first so that fun_prop can infer its element encoding before checking the body.

theorem Turing.MultiTapeTM.ComputableTidilyInPolyTime.map {α β : Type} {encA : α ↪ List Bool} {encB : β ↪ List Bool} {f : α → β} (hf : ComputableTidilyInPolyTime f encA encB) :

A polynomial-time function can be mapped over a list in polynomial time.

Read an optional head in any list encoding, without an inhabitant of the element type.

theorem Turing.MultiTapeTM.ComputableTidilyInPolyTime.mapConst {β γ : Type} {encB : β ↪ List Bool} {encIn : γ ↪ List Bool} {ι : Type u_1} (l : List ι) {f : γ → ι → β} (hf : ∀ i ∈ l, ComputableTidilyInPolyTime (fun (x : γ) => f x i) encIn encB) :
ComputableTidilyInPolyTime (fun (x : γ) => List.map (f x) l) encIn (encList encB)

Map an input-dependent function over a fixed list. Only its members need certificates; the list and its elements are not part of the computational input.

Concatenating a list of lists is polynomial-time.

theorem Turing.MultiTapeTM.ComputableTidilyInPolyTime.flatMapWith {α β γ π : Type} {encA : α ↪ List Bool} {encB : β ↪ List Bool} {encIn : γ ↪ List Bool} {encP : π ↪ List Bool} {f : π × α → List β} {par : γ → π} {list : γ → List α} (hf : ComputableTidilyInPolyTime f (encPair encP encA) (encList encB)) (hpar : ComputableTidilyInPolyTime par encIn encP) (hlist : ComputableTidilyInPolyTime list encIn (encList encA)) :
ComputableTidilyInPolyTime (fun (x : γ) => List.flatMap (fun (a : α) => f (par x, a)) (list x)) encIn (encList encB)

Concatenate polynomial-time lists computed from each element and a fixed parameter.

theorem Turing.MultiTapeTM.ComputableTidilyInPolyTime.flatMapWithInput {α β γ : Type} {encA : α ↪ List Bool} {encB : β ↪ List Bool} {encIn : γ ↪ List Bool} {f : γ → α → List β} {list : γ → List α} (hlist : ComputableTidilyInPolyTime list encIn (encList encA)) (hf : ComputableTidilyInPolyTime (fun (p : γ × α) => f p.1 p.2) (encPair encIn encA) (encList encB)) :
ComputableTidilyInPolyTime (fun (x : γ) => List.flatMap (f x) (list x)) encIn (encList encB)

Concatenate lists computed jointly from the original input and each list element. Like mapWithInput, this is a composition rule for fun_prop.

theorem Turing.MultiTapeTM.ComputableTidilyInPolyTime.flatMapConst {β γ : Type} {encB : β ↪ List Bool} {encIn : γ ↪ List Bool} {ι : Type u_1} (l : List ι) {f : γ → ι → List β} (hf : ∀ i ∈ l, ComputableTidilyInPolyTime (fun (x : γ) => f x i) encIn (encList encB)) :
ComputableTidilyInPolyTime (fun (x : γ) => List.flatMap (f x) l) encIn (encList encB)

Concatenate input-dependent lists indexed by a fixed list of parameters. No encoding of the fixed parameters is required.

theorem Turing.MultiTapeTM.ComputableTidilyInPolyTime.mapFilterConst {β γ : Type} {encB : β ↪ List Bool} {encIn : γ ↪ List Bool} {ι : Type u_1} (list : List ι) {test : γ → ι → Bool} {f : γ → ι → β} (htest : ∀ i ∈ list, ComputableTidilyInPolyTime (fun (a : γ) => test a i) encIn encBool) (hf : ∀ i ∈ list, ComputableTidilyInPolyTime (fun (a : γ) => f a i) encIn encB) :
ComputableTidilyInPolyTime (fun (a : γ) => List.map (f a) (List.filter (test a) list)) encIn (encList encB)

Filter and map a fixed list using computed guards and outputs. No encoding of the fixed parameters is required; only members of the list need certificates.

The length of a list, in unary, including raw bit strings.

Length of a framed list; the element encoding is inferred from the list encoding.

The encoded input length, computed in unary by reading the input word.

theorem Turing.MultiTapeTM.ComputableTidilyInPolyTime.length_bits_comp {α : Type} {input : α ↪ List Bool} {word : α → List Bool} (hword : ComputableTidilyInPolyTime word input encBits) :
ComputableTidilyInPolyTime (fun (a : α) => (word a).length) input encUnary

Length of a computed raw bit string, fixing the intermediate encoding for proof search. Registered after encoding_length so fun_prop first tries this rule on computed words.

theorem Turing.MultiTapeTM.ComputableTidilyInPolyTime.countPWith {α γ π : Type} {encA : α ↪ List Bool} {encIn : γ ↪ List Bool} {encP : π ↪ List Bool} {encL : List α ↪ List Bool} [ListEncoding encA encL] [SizedListEncoding encA encL] {test : π × α → Bool} {par : γ → π} {list : γ → List α} (htest : ComputableTidilyInPolyTime test (encPair encP encA) encBool) (hpar : ComputableTidilyInPolyTime par encIn encP) (hlist : ComputableTidilyInPolyTime list encIn encL) :
ComputableTidilyInPolyTime (fun (x : γ) => List.countP (fun (a : α) => test (par x, a)) (list x)) encIn encUnary

Count predicate matches directly over any readable, size-bounded list encoding. The accumulator is a unary counter; the certificate does not construct a list of matches.

theorem Turing.MultiTapeTM.ComputableTidilyInPolyTime.countPWithInput {α γ : Type} {encA : α ↪ List Bool} {encIn : γ ↪ List Bool} {test : γ → α → Bool} {list : γ → List α} (hlist : ComputableTidilyInPolyTime list encIn (encList encA)) (htest : ComputableTidilyInPolyTime (fun (p : γ × α) => test p.1 p.2) (encPair encIn encA) encBool) :
ComputableTidilyInPolyTime (fun (x : γ) => List.countP (test x) (list x)) encIn encUnary

Count matches of a predicate that captures the original input. The count is in unary.

theorem Turing.MultiTapeTM.ComputableTidilyInPolyTime.countWithInput {α γ : Type} {encA : α ↪ List Bool} {encIn : γ ↪ List Bool} [BEq α] [LawfulBEq α] {list : γ → List α} {value : γ → α} (hlist : ComputableTidilyInPolyTime list encIn (encList encA)) (hvalue : ComputableTidilyInPolyTime value encIn encA) :
ComputableTidilyInPolyTime (fun (x : γ) => List.count (value x) (list x)) encIn encUnary

Count occurrences of a computed value using lawful Boolean equality.

Enumerate 0, …, n - 1, with the bound and the elements in unary.

theorem Turing.MultiTapeTM.ComputableTidilyInPolyTime.replicate {α γ : Type} {encA : α ↪ List Bool} {encIn : γ ↪ List Bool} {count : γ → ℕ} {value : γ → α} (hcount : ComputableTidilyInPolyTime count encIn encUnary) (hvalue : ComputableTidilyInPolyTime value encIn encA) :
ComputableTidilyInPolyTime (fun (x : γ) => List.replicate (count x) (value x)) encIn (encList encA)

Repeat a computed value a computed unary number of times, charging every copy and delimiter.

theorem Turing.MultiTapeTM.ComputableTidilyInPolyTime.anyWithEncoding {α γ π : Type} {encA : α ↪ List Bool} {encIn : γ ↪ List Bool} {encP : π ↪ List Bool} {encL : List α ↪ List Bool} [ListEncoding encA encL] [SizedListEncoding encA encL] {test : π × α → Bool} {par : γ → π} {list : γ → List α} (htest : ComputableTidilyInPolyTime test (encPair encP encA) encBool) (hpar : ComputableTidilyInPolyTime par encIn encP) (hlist : ComputableTidilyInPolyTime list encIn encL) :
ComputableTidilyInPolyTime (fun (x : γ) => (list x).any fun (a : α) => test (par x, a)) encIn encBool

Scan any readable, size-bounded list encoding for a predicate match.

theorem Turing.MultiTapeTM.ComputableTidilyInPolyTime.allWithEncoding {α γ π : Type} {encA : α ↪ List Bool} {encIn : γ ↪ List Bool} {encP : π ↪ List Bool} {encL : List α ↪ List Bool} [ListEncoding encA encL] [SizedListEncoding encA encL] {test : π × α → Bool} {par : γ → π} {list : γ → List α} (htest : ComputableTidilyInPolyTime test (encPair encP encA) encBool) (hpar : ComputableTidilyInPolyTime par encIn encP) (hlist : ComputableTidilyInPolyTime list encIn encL) :
ComputableTidilyInPolyTime (fun (x : γ) => (list x).all fun (a : α) => test (par x, a)) encIn encBool

Test every element of any readable, size-bounded list encoding.

theorem Turing.MultiTapeTM.ComputableTidilyInPolyTime.anyWith {α γ π : Type} {encA : α ↪ List Bool} {encIn : γ ↪ List Bool} {encP : π ↪ List Bool} {test : π × α → Bool} {par : γ → π} {list : γ → List α} (htest : ComputableTidilyInPolyTime test (encPair encP encA) encBool) (hpar : ComputableTidilyInPolyTime par encIn encP) (hlist : ComputableTidilyInPolyTime list encIn (encList encA)) :
ComputableTidilyInPolyTime (fun (x : γ) => (list x).any fun (a : α) => test (par x, a)) encIn encBool

Test whether any element satisfies a polynomial-time predicate with a fixed parameter.

theorem Turing.MultiTapeTM.ComputableTidilyInPolyTime.allWith {α γ π : Type} {encA : α ↪ List Bool} {encIn : γ ↪ List Bool} {encP : π ↪ List Bool} {test : π × α → Bool} {par : γ → π} {list : γ → List α} (htest : ComputableTidilyInPolyTime test (encPair encP encA) encBool) (hpar : ComputableTidilyInPolyTime par encIn encP) (hlist : ComputableTidilyInPolyTime list encIn (encList encA)) :
ComputableTidilyInPolyTime (fun (x : γ) => (list x).all fun (a : α) => test (par x, a)) encIn encBool

Test whether every element satisfies a polynomial-time predicate with a fixed parameter.

theorem Turing.MultiTapeTM.ComputableTidilyInPolyTime.anyWithInput {α γ : Type} {encA : α ↪ List Bool} {encIn : γ ↪ List Bool} {test : γ → α → Bool} {list : γ → List α} (hlist : ComputableTidilyInPolyTime list encIn (encList encA)) (htest : ComputableTidilyInPolyTime (fun (p : γ × α) => test p.1 p.2) (encPair encIn encA) encBool) :
ComputableTidilyInPolyTime (fun (x : γ) => (list x).any (test x)) encIn encBool

Test whether any list element satisfies a predicate that captures the original input.

theorem Turing.MultiTapeTM.ComputableTidilyInPolyTime.allWithInput {α γ : Type} {encA : α ↪ List Bool} {encIn : γ ↪ List Bool} {test : γ → α → Bool} {list : γ → List α} (hlist : ComputableTidilyInPolyTime list encIn (encList encA)) (htest : ComputableTidilyInPolyTime (fun (p : γ × α) => test p.1 p.2) (encPair encIn encA) encBool) :
ComputableTidilyInPolyTime (fun (x : γ) => (list x).all (test x)) encIn encBool

Test whether every list element satisfies a predicate that captures the original input.

theorem Turing.MultiTapeTM.ComputableTidilyInPolyTime.allConst {γ : Type} {encIn : γ ↪ List Bool} {ι : Type u_1} (l : List ι) {test : γ → ι → Bool} (htest : ∀ i ∈ l, ComputableTidilyInPolyTime (fun (x : γ) => test x i) encIn encBool) :
ComputableTidilyInPolyTime (fun (x : γ) => l.all (test x)) encIn encBool

Test every element of a fixed list. Only its members need certificates; the list and its elements are fixed before the computational input and require no encoding.

theorem Turing.MultiTapeTM.ComputableTidilyInPolyTime.anyConst {γ : Type} {encIn : γ ↪ List Bool} {ι : Type u_1} (l : List ι) {test : γ → ι → Bool} (htest : ∀ i ∈ l, ComputableTidilyInPolyTime (fun (x : γ) => test x i) encIn encBool) :
ComputableTidilyInPolyTime (fun (x : γ) => l.any (test x)) encIn encBool

Test whether any element of a fixed list satisfies its input-dependent predicate. The fixed list needs no element encoding or uniform certificate over all possible elements.

The index of the first occurrence, or the list length if absent, computed in unary. The element itself can use any encoding.

theorem Turing.MultiTapeTM.ComputableTidilyInPolyTime.idxOfWithInput {α γ : Type} {encA : α ↪ List Bool} {encIn : γ ↪ List Bool} [DecidableEq α] {list : γ → List α} {value : γ → α} (hlist : ComputableTidilyInPolyTime list encIn (encList encA)) (hvalue : ComputableTidilyInPolyTime value encIn encA) :
ComputableTidilyInPolyTime (fun (x : γ) => List.idxOf (value x) (list x)) encIn encUnary

Find a computed value's first occurrence in a computed list.

theorem Turing.MultiTapeTM.ComputableTidilyInPolyTime.dropUnary {α : Type} {encA : α ↪ List Bool} {encL : List α ↪ List Bool} [ListEncoding encA encL] [SizedListEncoding encA encL] :
ComputableTidilyInPolyTime (fun (p : List α × ℕ) => List.drop p.2 p.1) (encPair encL encUnary) encL

Drop a unary number of elements from a sized list encoding, including raw bit strings.

theorem Turing.MultiTapeTM.ComputableTidilyInPolyTime.listDropWithInput {α γ : Type} {encA : α ↪ List Bool} {encIn : γ ↪ List Bool} {list : γ → List α} {count : γ → ℕ} (hlist : ComputableTidilyInPolyTime list encIn (encList encA)) (hcount : ComputableTidilyInPolyTime count encIn encUnary) :
ComputableTidilyInPolyTime (fun (x : γ) => List.drop (count x) (list x)) encIn (encList encA)

Drop a computed unary number of elements from a computed framed list.

Take a unary number of framed-list elements using certified reversal and dropping.

theorem Turing.MultiTapeTM.ComputableTidilyInPolyTime.listTakeWithInput {α γ : Type} {encA : α ↪ List Bool} {encIn : γ ↪ List Bool} {list : γ → List α} {count : γ → ℕ} (hlist : ComputableTidilyInPolyTime list encIn (encList encA)) (hcount : ComputableTidilyInPolyTime count encIn encUnary) :
ComputableTidilyInPolyTime (fun (x : γ) => List.take (count x) (list x)) encIn (encList encA)

Take a computed unary number of elements from a computed framed list.

theorem Turing.MultiTapeTM.ComputableTidilyInPolyTime.getElem? {α γ : Type} {encA : α ↪ List Bool} {encIn : γ ↪ List Bool} {encL : List α ↪ List Bool} {list : γ → List α} {index : γ → ℕ} (hlist : ComputableTidilyInPolyTime list encIn encL) (hindex : ComputableTidilyInPolyTime index encIn encUnary) [ListEncoding encA encL] [SizedListEncoding encA encL] :
ComputableTidilyInPolyTime (fun (x : γ) => (list x)[index x]?) encIn (encOption encA)

Look up a computed unary index, returning none outside a computed list. The list certificate determines its encoding before proof search checks the corresponding operation and size rules.

theorem Turing.MultiTapeTM.ComputableTidilyInPolyTime.bitsDropWithInput {γ : Type} {encIn : γ ↪ List Bool} {list : γ → List Bool} {count : γ → ℕ} (hlist : ComputableTidilyInPolyTime list encIn encBits) (hcount : ComputableTidilyInPolyTime count encIn encUnary) :
ComputableTidilyInPolyTime (fun (x : γ) => List.drop (count x) (list x)) encIn encBits

Drop a computed unary number of bits from a computed bit string.

Take a unary number of bits. Reversing and dropping reuses the certified list operations.

theorem Turing.MultiTapeTM.ComputableTidilyInPolyTime.bitsTakeWithInput {γ : Type} {encIn : γ ↪ List Bool} {list : γ → List Bool} {count : γ → ℕ} (hlist : ComputableTidilyInPolyTime list encIn encBits) (hcount : ComputableTidilyInPolyTime count encIn encUnary) :
ComputableTidilyInPolyTime (fun (x : γ) => List.take (count x) (list x)) encIn encBits

Take a computed unary number of bits from a computed bit string.

theorem Turing.MultiTapeTM.ComputableTidilyInPolyTime.listGetD {α : Type} {encA : α ↪ List Bool} {encL : List α ↪ List Bool} [ListEncoding encA encL] [SizedListEncoding encA encL] (d : α) :
ComputableTidilyInPolyTime (fun (p : List α × ℕ) => p.1.getD p.2 d) (encPair encL encUnary) encA

List lookup with a fixed default and a unary index, including lookup in raw bit strings.

Read a bit at a unary index with a fixed fallback. Fixing the raw encoding avoids guessing a list-encoding instance during compositional proof search.

theorem Turing.MultiTapeTM.ComputableTidilyInPolyTime.bitsGetDWithInput {γ : Type} {encIn : γ ↪ List Bool} {list : γ → List Bool} {index : γ → ℕ} (hlist : ComputableTidilyInPolyTime list encIn encBits) (hindex : ComputableTidilyInPolyTime index encIn encUnary) (fallback : Bool) :
ComputableTidilyInPolyTime (fun (x : γ) => (list x).getD (index x) fallback) encIn encBool

Read a computed bit string at a computed unary index.

theorem Turing.MultiTapeTM.ComputableTidilyInPolyTime.listGetD_binary {α γ : Type} {encA : α ↪ List Bool} {encIn : γ ↪ List Bool} {encL : List α ↪ List Bool} [ListEncoding encA encL] [SizedListEncoding encA encL] {l : γ → List α} {i : γ → ℕ} (d : α) (hl : ComputableTidilyInPolyTime l encIn encL) (hi : ComputableTidilyInPolyTime i encIn encNat) :
ComputableTidilyInPolyTime (fun (x : γ) => (l x).getD (i x) d) encIn encA

Lookup in a computed list at a computed binary index. The index is first capped at the length of the list, reading its binary digits most significant first and capping every partial value, so an index far beyond the list costs only its binary length; beyond the list every lookup returns the default.

theorem Turing.MultiTapeTM.ComputableTidilyInPolyTime.zip {α β : Type} (encA : α ↪ List Bool) (encB : β ↪ List Bool) :
ComputableTidilyInPolyTime (fun (p : List α × List β) => p.1.zip p.2) (encPair (encList encA) (encList encB)) (encList (encPair encA encB))

Zip framed lists, charging both inputs and every pair in the output.

Number the entries of a framed list with unary indices, charging the list and every index.

Plain polynomial-time automation #

theorem Turing.MultiTapeTM.ComputableInPolyTime.anyWithInput {α γ : Type} {encA : α ↪ List Bool} {encIn : γ ↪ List Bool} {test : γ → α → Bool} {list : γ → List α} (hlist : ComputableInPolyTime list encIn (encList encA)) (htest : ComputableInPolyTime (fun (p : γ × α) => test p.1 p.2) (encPair encIn encA) encBool) :
ComputableInPolyTime (fun (x : γ) => (list x).any (test x)) encIn encBool

Test whether any list element satisfies a predicate that captures the original input.

theorem Turing.MultiTapeTM.ComputableInPolyTime.bitsAppend {γ : Type} {encIn : γ ↪ List Bool} {left right : γ → List Bool} (hleft : ComputableInPolyTime left encIn encBits) (hright : ComputableInPolyTime right encIn encBits) :
ComputableInPolyTime (fun (x : γ) => left x ++ right x) encIn encBits

Concatenate raw bit strings, charging for both computed words.

theorem Turing.MultiTapeTM.ComputableInPolyTime.bitsTakeWithInput {γ : Type} {encIn : γ ↪ List Bool} {list : γ → List Bool} {count : γ → ℕ} (hlist : ComputableInPolyTime list encIn encBits) (hcount : ComputableInPolyTime count encIn encUnary) :
ComputableInPolyTime (fun (x : γ) => List.take (count x) (list x)) encIn encBits

Take a computed unary number of bits from a computed bit string.

The encoded input length, computed in unary by reading the input word.

theorem Turing.MultiTapeTM.ComputableInPolyTime.filterWithInput {α γ : Type} {encA : α ↪ List Bool} {encIn : γ ↪ List Bool} {test : γ → α → Bool} {list : γ → List α} (hlist : ComputableInPolyTime list encIn (encList encA)) (htest : ComputableInPolyTime (fun (p : γ × α) => test p.1 p.2) (encPair encIn encA) encBool) :
ComputableInPolyTime (fun (x : γ) => List.filter (test x) (list x)) encIn (encList encA)

Filter with a predicate that captures the original input.

theorem Turing.MultiTapeTM.ComputableInPolyTime.filter {α : Type} {encA : α ↪ List Bool} {test : α → Bool} (htest : ComputableInPolyTime test encA encBool) :

Filtering a list by a polynomial-time test is polynomial-time.

theorem Turing.MultiTapeTM.ComputableInPolyTime.mapConst {β γ : Type} {encB : β ↪ List Bool} {encIn : γ ↪ List Bool} {ι : Type u_1} (l : List ι) {f : γ → ι → β} (hf : ∀ i ∈ l, ComputableInPolyTime (fun (x : γ) => f x i) encIn encB) :
ComputableInPolyTime (fun (x : γ) => List.map (f x) l) encIn (encList encB)

Map an input-dependent function over a fixed list. Only its members need certificates; the list and its elements are not part of the computational input.

theorem Turing.MultiTapeTM.ComputableInPolyTime.flatMapConst {β γ : Type} {encB : β ↪ List Bool} {encIn : γ ↪ List Bool} {ι : Type u_1} (l : List ι) {f : γ → ι → List β} (hf : ∀ i ∈ l, ComputableInPolyTime (fun (x : γ) => f x i) encIn (encList encB)) :
ComputableInPolyTime (fun (x : γ) => List.flatMap (f x) l) encIn (encList encB)

Concatenate input-dependent lists indexed by a fixed list of parameters. No encoding of the fixed parameters is required; only members of the list need certificates.

theorem Turing.MultiTapeTM.ComputableInPolyTime.mapFilterConst {β γ : Type} {encB : β ↪ List Bool} {encIn : γ ↪ List Bool} {ι : Type u_1} (list : List ι) {test : γ → ι → Bool} {f : γ → ι → β} (htest : ∀ i ∈ list, ComputableInPolyTime (fun (a : γ) => test a i) encIn encBool) (hf : ∀ i ∈ list, ComputableInPolyTime (fun (a : γ) => f a i) encIn encB) :
ComputableInPolyTime (fun (a : γ) => List.map (f a) (List.filter (test a) list)) encIn (encList encB)

Filter and map a fixed list using computed guards and outputs, preserving order and duplicates. No encoding of the fixed parameters is required; only members need certificates.

theorem Turing.MultiTapeTM.ComputableInPolyTime.replicate {α γ : Type} {encA : α ↪ List Bool} {encIn : γ ↪ List Bool} {count : γ → ℕ} {value : γ → α} (hcount : ComputableInPolyTime count encIn encUnary) (hvalue : ComputableInPolyTime value encIn encA) :
ComputableInPolyTime (fun (x : γ) => List.replicate (count x) (value x)) encIn (encList encA)

Repeat a computed value a computed unary number of times, charging every copy and delimiter.

theorem Turing.MultiTapeTM.ComputableInPolyTime.flatMapWithInput {α β γ : Type} {encA : α ↪ List Bool} {encB : β ↪ List Bool} {encIn : γ ↪ List Bool} {f : γ → α → List β} {list : γ → List α} (hlist : ComputableInPolyTime list encIn (encList encA)) (hf : ComputableInPolyTime (fun (p : γ × α) => f p.1 p.2) (encPair encIn encA) (encList encB)) :
ComputableInPolyTime (fun (x : γ) => List.flatMap (f x) (list x)) encIn (encList encB)

Concatenate lists computed jointly from the original input and each list element. Like mapWithInput, this is a composition rule for fun_prop.

theorem Turing.MultiTapeTM.ComputableInPolyTime.headD {α : Type} {encA : α ↪ List Bool} {encL : List α ↪ List Bool} [_inst3 : ListEncoding encA encL] (fallback : α) :
ComputableInPolyTime (fun (list : List α) => list.headD fallback) encL encA

Read the head of any list encoding with a fixed fallback.

Length of a framed list, for any element encoding, with a unary result.

theorem Turing.MultiTapeTM.ComputableInPolyTime.countPWithInput {α γ : Type} {encA : α ↪ List Bool} {encIn : γ ↪ List Bool} {test : γ → α → Bool} {list : γ → List α} (hlist : ComputableInPolyTime list encIn (encList encA)) (htest : ComputableInPolyTime (fun (p : γ × α) => test p.1 p.2) (encPair encIn encA) encBool) :
ComputableInPolyTime (fun (x : γ) => List.countP (test x) (list x)) encIn encUnary

Count matches of a predicate that captures the original input. The count is in unary.

theorem Turing.MultiTapeTM.ComputableInPolyTime.listGetDWithInput {α γ : Type} {encA : α ↪ List Bool} {encIn : γ ↪ List Bool} {list : γ → List α} {index : γ → ℕ} (hlist : ComputableInPolyTime list encIn (encList encA)) (hindex : ComputableInPolyTime index encIn encUnary) (fallback : α) :
ComputableInPolyTime (fun (x : γ) => (list x).getD (index x) fallback) encIn encA

Read a computed framed list at a computed unary index with a fixed fallback, inferring the element encoding from the list.

theorem Turing.MultiTapeTM.ComputableInPolyTime.bitsGetDWithInput {γ : Type} {encIn : γ ↪ List Bool} {list : γ → List Bool} {index : γ → ℕ} (hlist : ComputableInPolyTime list encIn encBits) (hindex : ComputableInPolyTime index encIn encUnary) (fallback : Bool) :
ComputableInPolyTime (fun (x : γ) => (list x).getD (index x) fallback) encIn encBool

Read a computed bit string at a computed unary index. Registered after listGetDWithInput so fun_prop tries raw bit-string lookup before framed-list lookup on Bool.

theorem Turing.MultiTapeTM.ComputableInPolyTime.bitsDropWithInput {α : Type} {input : α ↪ List Bool} {list : α → List Bool} {count : α → ℕ} (hlist : ComputableInPolyTime list input encBits) (hcount : ComputableInPolyTime count input encUnary) :
ComputableInPolyTime (fun (a : α) => List.drop (count a) (list a)) input encBits

Drop a computed unary number of bits from a computed raw word. Counts beyond the word length return the empty word, with no promise on the count or input.

theorem Turing.MultiTapeTM.ComputableInPolyTime.length_bits_comp {α : Type} {input : α ↪ List Bool} {word : α → List Bool} (hword : ComputableInPolyTime word input encBits) :
ComputableInPolyTime (fun (a : α) => (word a).length) input encUnary

Length of a computed raw word, fixing the intermediate encoding for proof search.

theorem Turing.MultiTapeTM.ComputableInPolyTime.findWithInput {α γ : Type} {encA : α ↪ List Bool} {encIn : γ ↪ List Bool} {test : γ → α → Bool} {list : γ → List α} (hlist : ComputableInPolyTime list encIn (encList encA)) (htest : ComputableInPolyTime (fun (p : γ × α) => test p.1 p.2) (encPair encIn encA) encBool) :
ComputableInPolyTime (fun (x : γ) => List.find? (test x) (list x)) encIn (encOption encA)

Find the first list element passing a test that captures the original input.

theorem Turing.MultiTapeTM.ComputableInPolyTime.countPWith {α γ π : Type} {encA : α ↪ List Bool} {encIn : γ ↪ List Bool} {encP : π ↪ List Bool} {encL : List α ↪ List Bool} [ListEncoding encA encL] [SizedListEncoding encA encL] {test : π × α → Bool} {par : γ → π} {list : γ → List α} (htest : ComputableInPolyTime test (encPair encP encA) encBool) (hpar : ComputableInPolyTime par encIn encP) (hlist : ComputableInPolyTime list encIn encL) :
ComputableInPolyTime (fun (x : γ) => List.countP (fun (a : α) => test (par x, a)) (list x)) encIn encUnary

Count the list elements passing a test with a parameter, in unary.

theorem Turing.MultiTapeTM.ComputableInPolyTime.anyWithEncoding {α γ π : Type} {encA : α ↪ List Bool} {encIn : γ ↪ List Bool} {encP : π ↪ List Bool} {encL : List α ↪ List Bool} [ListEncoding encA encL] [SizedListEncoding encA encL] {test : π × α → Bool} {par : γ → π} {list : γ → List α} (htest : ComputableInPolyTime test (encPair encP encA) encBool) (hpar : ComputableInPolyTime par encIn encP) (hlist : ComputableInPolyTime list encIn encL) :
ComputableInPolyTime (fun (x : γ) => (list x).any fun (a : α) => test (par x, a)) encIn encBool

Test whether some list element passes a test with a parameter.

theorem Turing.MultiTapeTM.ComputableInPolyTime.allWithEncoding {α γ π : Type} {encA : α ↪ List Bool} {encIn : γ ↪ List Bool} {encP : π ↪ List Bool} {encL : List α ↪ List Bool} [ListEncoding encA encL] [SizedListEncoding encA encL] {test : π × α → Bool} {par : γ → π} {list : γ → List α} (htest : ComputableInPolyTime test (encPair encP encA) encBool) (hpar : ComputableInPolyTime par encIn encP) (hlist : ComputableInPolyTime list encIn encL) :
ComputableInPolyTime (fun (x : γ) => (list x).all fun (a : α) => test (par x, a)) encIn encBool

Test whether every list element passes a test with a parameter.

theorem Turing.MultiTapeTM.ComputableInPolyTime.zip {α β : Type} (encA : α ↪ List Bool) (encB : β ↪ List Bool) :
ComputableInPolyTime (fun (p : List α × List β) => p.1.zip p.2) (encPair (encList encA) (encList encB)) (encList (encPair encA encB))

Zip framed lists, charging both inputs and every pair in the output.

Framing a fixed Boolean encoding, or parsing its frames and converting each symbol, takes polynomial time. The encodings of false and true can be arbitrary fixed words.

theorem Turing.MultiTapeTM.trans_encList_polyTime {α : Type} (encIn : α ↪ List Bool) (enc : Bool ↪ List Bool) :
ComputableInPolyTime (fun (a : α) => a) encIn (encIn.trans (encList enc)) ∧ ComputableInPolyTime (fun (a : α) => a) (encIn.trans (encList enc)) encIn

The word conversion preserves an arbitrary caller-supplied encoding. No computable inverse of encIn is assumed: expose its word, convert that word, and reuse the resulting encoding.