Documentation

CslibFrontier.Computability.Complexity.Classes.Sparse.Prune

Pruning a level along a Hausdorff decomposition #

Arvind, Köbler and Mundhenk's procedure PRUNE [Arvind, Köbler and Mundhenk, Theorem 3.4] [AKM92], on an abstract list of nodes. Let N be a level whose members of a set L are exactly its first h + 1 nodes, and let L have a Hausdorff decomposition on N: there are sets C 0 ⊇ C 1 ⊇ ⋯ such that a node is in L exactly when it is in C (2 d) but not in C (2 d + 1) for some d < D. If each C j with j < 2 D reduces conjunctively to a set with at most s members on N, the queries Q j of a node all lying in it exactly when the node is in C j, then PRUNE keeps the node at position h (Cslib.Complexity.BTT.getElem_mem_prune) and keeps at most 2 D (s + 2) ^ (2 D) nodes (Cslib.Complexity.BTT.length_prune_le).

PRUNE works with positions in N. At depth d it runs SEARCH-RIGHT with the queries Q (2 d) from each start position (Cslib.Complexity.BTT.searchRightFrom), and SEARCH-LEFT with the queries Q (2 d + 1) from each position that SEARCH-RIGHT keeps (Cslib.Complexity.BTT.searchLeftFrom). SEARCH-LEFT is SEARCH-RIGHT on the positions up to its start in decreasing order. The positions kept by SEARCH-LEFT are the start positions of the next depth.

Why the node at position h is kept, following the source. At depth d, some start position l ≤ h begins a run of nodes in C (2 d) reaching h. Let r ≥ h end the longest such run. SEARCH-RIGHT keeps r, since the next node, if any, is outside C (2 d) (Cslib.Complexity.BTT.mem_searchRightFrom). The nodes after h up to r are in C (2 d) but not in L, so they are in C (2 d + 1). Let m start the longest run of nodes in C (2 d + 1) ending at r; SEARCH-LEFT keeps m (Cslib.Complexity.BTT.mem_searchLeftFrom). If the node at h is outside C (2 d + 1), then m = h + 1, and h is collected as r when r = h or as m - 1 otherwise. If it is in C (2 d + 1), then m ≤ h, and the nodes from m to h are in L and in C (2 d + 1), hence in C (2 d + 2): the argument repeats at depth d + 1 from m. At depth D that would put the node at h in every C j, so outside L; the recursion collects h before.

The source's SEARCH-RIGHT and SEARCH-LEFT stop once more than s distinct queries have been collected, and its PRUNE returns the nodes before those that SEARCH-LEFT keeps. Here both scans are Cslib.Complexity.BTT.searchRight, which reads the whole list and does not test its first node against the empty set of queries, so SEARCH-LEFT from r never keeps r + 1. The positions kept by SEARCH-RIGHT are collected as well, which covers the case r = h, where the source's SEARCH-LEFT keeps r + 1, possibly past the end of the level.

Main definitions #

Main results #

References #

SEARCH-RIGHT #

def Cslib.Complexity.BTT.hasNewQuery {α : Type u_1} {κ : Type u_2} [DecidableEq κ] (Q : α → List κ) (s : ℕ) (pre : List α) (z : α) :

The test of SEARCH-RIGHT at the node z after the nodes pre, with the queries Q and the bound s: the queries of the nodes pre have at most s distinct values, and z has a query that is not among them.

def Cslib.Complexity.BTT.searchRight {α : Type u_1} {κ : Type u_2} [DecidableEq κ] (Q : α → List κ) (s : ℕ) (l : List α) :
List α

SEARCH-RIGHT with the queries Q and the bound s, on a level in increasing order: keep each node whose successor z passes hasNewQuery with the nodes up to the node, and keep the last node.

theorem Cslib.Complexity.BTT.searchRight_sublist {α : Type u_1} {κ : Type u_2} [DecidableEq κ] {Q : α → List κ} {s : ℕ} (l : List α) :

SEARCH-RIGHT keeps a sublist of its level.

theorem Cslib.Complexity.BTT.length_searchRight_le {α : Type u_1} {κ : Type u_2} [DecidableEq κ] {Q : α → List κ} {s : ℕ} (l : List α) :
(searchRight Q s l).length ≤ s + 2

SEARCH-RIGHT keeps at most s + 2 nodes: the last one, and at most s + 1 others, since each raises the number of distinct queries seen, which is at most s when it is kept.

theorem Cslib.Complexity.BTT.mem_searchRight {α : Type u_1} {κ : Type u_2} [DecidableEq κ] {Q : α → List κ} {s : ℕ} {K : Set κ} (hc : ∀ (T : Finset κ), (∀ u ∈ T, u ∈ K) → T.card ≤ s) {A B : List α} {y : α} (hA : ∀ x ∈ A ++ [y], ∀ u ∈ Q x, u ∈ K) (hB : ∀ z ∈ B.head?, ∃ u ∈ Q z, u ∉ K) :
y ∈ searchRight Q s (A ++ y :: B)

SEARCH-RIGHT keeps the end of a run of nodes whose queries lie in a small set. If every query of the nodes A and of y lies in a set K whose finite subsets have at most s members, and the node after y, if any, has a query outside K, then SEARCH-RIGHT keeps y.

SEARCH-RIGHT and SEARCH-LEFT on positions #

def Cslib.Complexity.BTT.queriesAt {α : Type u_1} {κ : Type u_2} (Q : α → List κ) (N : List α) (i : ℕ) :
List κ

The queries Q of the node at position i of N; there are none past the end of N.

def Cslib.Complexity.BTT.searchRightFrom {α : Type u_1} {κ : Type u_2} [DecidableEq κ] (Q : α → List κ) (s : ℕ) (N : List α) (l : ℕ) :

SEARCH-RIGHT from the position l, with the queries Q and the bound s: the positions of N kept by Cslib.Complexity.BTT.searchRight on the positions from l on, in increasing order.

def Cslib.Complexity.BTT.searchLeftFrom {α : Type u_1} {κ : Type u_2} [DecidableEq κ] (Q : α → List κ) (s : ℕ) (N : List α) (r : ℕ) :

SEARCH-LEFT from the position r, with the queries Q and the bound s: the positions kept by Cslib.Complexity.BTT.searchRight on the positions up to r, in decreasing order.

theorem Cslib.Complexity.BTT.queriesAt_of_lt {α : Type u_1} {κ : Type u_2} {Q : α → List κ} {N : List α} {i : ℕ} (hi : i < N.length) :
queriesAt Q N i = Q N[i]
theorem Cslib.Complexity.BTT.length_searchRightFrom_le {α : Type u_1} {κ : Type u_2} [DecidableEq κ] {Q : α → List κ} {s : ℕ} {N : List α} (l : ℕ) :
(searchRightFrom Q s N l).length ≤ s + 2
theorem Cslib.Complexity.BTT.length_searchLeftFrom_le {α : Type u_1} {κ : Type u_2} [DecidableEq κ] {Q : α → List κ} {s : ℕ} {N : List α} (r : ℕ) :
(searchLeftFrom Q s N r).length ≤ s + 2
theorem Cslib.Complexity.BTT.mem_searchRightFrom {α : Type u_1} {κ : Type u_2} [DecidableEq κ] {Q : α → List κ} {s : ℕ} {N : List α} {C : α → Prop} {K : Set κ} (hC : ∀ y ∈ N, C y ↔ ∀ w ∈ Q y, w ∈ K) (hc : ∀ (T : Finset κ), (∀ w ∈ T, w ∈ K) → T.card ≤ s) {l r : ℕ} (hlr : l ≤ r) (hr : r < N.length) (hrun : ∀ (i : ℕ) (hi : i < N.length), l ≤ i → i ≤ r → C N[i]) (hnext : ∀ (hr' : r + 1 < N.length), ¬C N[r + 1]) :

SEARCH-RIGHT keeps the end of a run (the source's Claim 1). If the nodes at the positions from l to r are in a set C whose members are the nodes with all their queries in K, which has at most s members, and the node after r, if any, is not in C, then SEARCH-RIGHT from l keeps r.

theorem Cslib.Complexity.BTT.mem_searchLeftFrom {α : Type u_1} {κ : Type u_2} [DecidableEq κ] {Q : α → List κ} {s : ℕ} {N : List α} {C : α → Prop} {K : Set κ} (hC : ∀ y ∈ N, C y ↔ ∀ w ∈ Q y, w ∈ K) (hc : ∀ (T : Finset κ), (∀ w ∈ T, w ∈ K) → T.card ≤ s) {m r : ℕ} (hmr : m ≤ r) (hr : r < N.length) (hrun : ∀ (i : ℕ) (hi : i < N.length), m ≤ i → i ≤ r → C N[i]) (hprev : ∀ (hm : 0 < m), ¬C N[m - 1]) :

SEARCH-LEFT keeps the start of a run (the source's Claim 2). If the nodes at the positions from m to r are in a set C whose members are the nodes with all their queries in K, which has at most s members, and the node before m, if any, is not in C, then SEARCH-LEFT from r keeps m.

PRUNE #

def Cslib.Complexity.BTT.prunePositions {α : Type u_1} {κ : Type u_2} [DecidableEq κ] (Q : ℕ → α → List κ) (s : ℕ) (N : List α) :
ℕ → ℕ → List ℕ → List ℕ

PRUNE on positions: the positions of N collected at the depths d, …, d + n - 1 from the start positions starts, with the queries Q and the bound s. At depth d, SEARCH-RIGHT with the queries Q (2 d) runs from every start position, and SEARCH-LEFT with the queries Q (2 d + 1) from every position it keeps. The positions kept by SEARCH-RIGHT, the positions before those kept by SEARCH-LEFT, and the positions collected from the latter at the next depths are collected.

def Cslib.Complexity.BTT.prune {α : Type u_1} {κ : Type u_2} [DecidableEq κ] (Q : ℕ → α → List κ) (s D : ℕ) (N : List α) :
List α

PRUNE with the queries Q, the bound s and D depths: the nodes of N at the positions collected from the first position, in their order in N.

theorem Cslib.Complexity.BTT.prune_sublist {α : Type u_1} {κ : Type u_2} [DecidableEq κ] {Q : ℕ → α → List κ} {s D : ℕ} {N : List α} :
(prune Q s D N).Sublist N
theorem Cslib.Complexity.BTT.getElem_mem_prune_of_mem {α : Type u_1} {κ : Type u_2} [DecidableEq κ] {Q : ℕ → α → List κ} {s D : ℕ} {N : List α} {h : ℕ} (hh : h < N.length) (hmem : h ∈ prunePositions Q s N D 0 [0]) :
N[h] ∈ prune Q s D N

A node at a collected position is kept.

theorem Cslib.Complexity.BTT.length_prunePositions_le {α : Type u_1} {κ : Type u_2} [DecidableEq κ] {Q : ℕ → α → List κ} {s : ℕ} {N : List α} (n d : ℕ) (starts : List ℕ) :
(prunePositions Q s N n d starts).length ≤ 2 * n * starts.length * (s + 2) ^ (2 * n)

At most 2 n (s + 2) ^ (2 n) positions are collected from each start position.

theorem Cslib.Complexity.BTT.length_prune_le {α : Type u_1} {κ : Type u_2} [DecidableEq κ] {Q : ℕ → α → List κ} {s D : ℕ} {N : List α} :
(prune Q s D N).length ≤ 2 * D * (s + 2) ^ (2 * D)

PRUNE keeps at most 2 D (s + 2) ^ (2 D) nodes.

theorem Cslib.Complexity.BTT.getElem_mem_prune {α : Type u_1} {κ : Type u_2} [DecidableEq κ] {Q : ℕ → α → List κ} {s D : ℕ} {N : List α} {C : ℕ → α → Prop} {K : ℕ → Set κ} {h : ℕ} (hh : h < N.length) (hnest : ∀ (j : ℕ), ∀ y ∈ N, C (j + 1) y → C j y) (hleft : ∀ (i : ℕ) (hi : i < N.length), i ≤ h ↔ ∃ d < D, C (2 * d) N[i] ∧ ¬C (2 * d + 1) N[i]) (hQ : ∀ j < 2 * D, ∀ y ∈ N, C j y ↔ ∀ w ∈ Q j y, w ∈ K j) (hc : ∀ j < 2 * D, ∀ (T : Finset κ), (∀ w ∈ T, w ∈ K j) → T.card ≤ s) :
N[h] ∈ prune Q s D N

PRUNE keeps the last node of the level in L (the source's Claim 3). Let the sets C j decrease along N, and let L be ⋃ d < D, C (2 d) \ C (2 d + 1) on N, whose members in N are exactly the nodes at positions i ≤ h. If, for each j < 2 D, the nodes of N in C j are those with all their queries Q j in a set K j with at most s members, then PRUNE keeps the node at position h.

Polynomial time #

theorem Cslib.Complexity.BTT.computableInPolyTime_hasNewQuery {γ α κ : Type} {encIn : γ ↪ List Bool} {encA : α ↪ List Bool} {encK : κ ↪ List Bool} [DecidableEq κ] {Q : γ → α → List κ} {s : γ → ℕ} {pre : γ → List α} {z : γ → α} (hQ : Turing.MultiTapeTM.ComputableInPolyTime (fun (p : γ × α) => Q p.1 p.2) (Turing.MultiTapeTM.encPair encIn encA) (Turing.MultiTapeTM.encList encK)) (hs : Turing.MultiTapeTM.ComputableInPolyTime s encIn Turing.MultiTapeTM.encUnary) (hpre : Turing.MultiTapeTM.ComputableInPolyTime pre encIn (Turing.MultiTapeTM.encList encA)) (hz : Turing.MultiTapeTM.ComputableInPolyTime z encIn encA) :
Turing.MultiTapeTM.ComputableInPolyTime (fun (x : γ) => hasNewQuery (Q x) (s x) (pre x) (z x)) encIn Turing.MultiTapeTM.encBool

The test of SEARCH-RIGHT is polynomial-time.

theorem Cslib.Complexity.BTT.computableInPolyTime_searchRight {γ α κ : Type} {encIn : γ ↪ List Bool} {encA : α ↪ List Bool} {encK : κ ↪ List Bool} [DecidableEq κ] {Q : γ → α → List κ} {s : γ → ℕ} {l : γ → List α} (hQ : Turing.MultiTapeTM.ComputableInPolyTime (fun (p : γ × α) => Q p.1 p.2) (Turing.MultiTapeTM.encPair encIn encA) (Turing.MultiTapeTM.encList encK)) (hs : Turing.MultiTapeTM.ComputableInPolyTime s encIn Turing.MultiTapeTM.encUnary) (hl : Turing.MultiTapeTM.ComputableInPolyTime l encIn (Turing.MultiTapeTM.encList encA)) :
Turing.MultiTapeTM.ComputableInPolyTime (fun (x : γ) => searchRight (Q x) (s x) (l x)) encIn (Turing.MultiTapeTM.encList encA)

SEARCH-RIGHT is polynomial-time, for polynomial-time queries, bound and level.

The queries at a position are polynomial-time.

SEARCH-RIGHT from a computed position is polynomial-time.

SEARCH-LEFT from a computed position is polynomial-time.

PRUNE on positions with a fixed number n of depths from a fixed depth d is polynomial-time, uniformly in the start positions.

theorem Cslib.Complexity.BTT.computableInPolyTime_prune {γ α κ : Type} {encIn : γ ↪ List Bool} {encA : α ↪ List Bool} {encK : κ ↪ List Bool} [DecidableEq κ] {Q : γ → ℕ → α → List κ} {s : γ → ℕ} {N : γ → List α} (D : ℕ) (hQ : ∀ (j : ℕ), Turing.MultiTapeTM.ComputableInPolyTime (fun (p : γ × α) => Q p.1 j p.2) (Turing.MultiTapeTM.encPair encIn encA) (Turing.MultiTapeTM.encList encK)) (hs : Turing.MultiTapeTM.ComputableInPolyTime s encIn Turing.MultiTapeTM.encUnary) (hN : Turing.MultiTapeTM.ComputableInPolyTime N encIn (Turing.MultiTapeTM.encList encA)) :
Turing.MultiTapeTM.ComputableInPolyTime (fun (x : γ) => prune (Q x) (s x) D (N x)) encIn (Turing.MultiTapeTM.encList encA)

PRUNE with a fixed number D of depths is polynomial-time, for polynomial-time queries, bound and level.