Documentation

CslibFrontier.Foundations.Data.BinaryBranching

Binary branching #

A binary branching T : BinaryBranching σ marks some states as leaves (T.IsLeaf) and gives every state a false child and a true child (T.next). A word w : List Bool names the state reached by following its branches (walk). It is a node word when its proper prefixes reach inner states (IsNodeWord), and a leaf word when moreover it reaches a leaf (IsLeafWord). Leaf words are determined by the positions of their true branches (IsLeafWord.eq_of_getD_eq), so leaf words of length at most Λ with at most ρ true branches number at most ∑_{j ≤ ρ} (Λ choose j) (card_le_sum_choose_of_isLeafWord).

When no branch is infinite (Terminating, for instance when a measure decreases from every inner state to its children, Terminating.of_lt), every node word extends to a leaf word. A depth-first search (searchStep) keeps a stack of states and an accumulator, updated by an arbitrary function at each leaf. Started from a state, it takes fewer than twice as many steps as the state has leaves, and its accumulator becomes the fold of the update over a duplicate-free list of all leaf words; meanwhile its stack holds at most h + 1 states of the tree when the leaf words have length at most h (exists_iterate_searchStep). A function that is additive at inner states sums over the leaves to its value at the root (sum_leafWords_eq).

The sparsification procedures of Impagliazzo, Paturi and Zane and of counting sparsification are binary branchings whose leaves are the sparse clause sets.

Main definitions #

Main results #

structure Cslib.BinaryBranching (σ : Type u_1) :
Type u_1

A binary branching on states σ: some states are leaves, and every state has a false child and a true child, of which only those of inner states matter.

  • IsLeaf : σ → Prop

    The leaves.

  • next : σ → Bool → σ

    The false child and the true child of a state.

def Cslib.BinaryBranching.walk {σ : Type u_1} (T : BinaryBranching σ) :
σ → List Bool → σ

The state reached along a word of branches.

A node word: its proper prefixes reach inner states.

A leaf word: its proper prefixes reach inner states and it reaches a leaf.

noncomputable def Cslib.BinaryBranching.walkSeq {σ : Type u_1} (T : BinaryBranching σ) :
ℕ → σ → (ℕ → Bool) → σ

Follow the branch sequence f for at most n steps, stopping at a leaf.

noncomputable def Cslib.BinaryBranching.searchStep {σ : Type u_1} {α : Type u_2} (T : BinaryBranching σ) (f : α → σ → α) :
List σ × α → List σ × α

One step of the depth-first search, on a stack of states and an accumulator: a leaf on top is popped and the accumulator is updated with it by f; an inner state on top is replaced by its false and true children.

Every branch ends at a leaf: the relation between the children of an inner state and the state is well-founded.

Termination #

theorem Cslib.BinaryBranching.Terminating.of_lt {σ : Type u_1} {T : BinaryBranching σ} (μ : σ → ℕ) (hμ : ∀ (s : σ), ¬T.IsLeaf s → ∀ (b : Bool), μ (T.next s b) < μ s) :

A branching terminates when a natural-number measure decreases from every inner state to its children.

theorem Cslib.BinaryBranching.Terminating.induction {σ : Type u_1} {T : BinaryBranching σ} (hT : T.Terminating) {motive : σ → Prop} (leaf : ∀ (s : σ), T.IsLeaf s → motive s) (node : ∀ (s : σ), ¬T.IsLeaf s → (∀ (b : Bool), motive (T.next s b)) → motive s) (s : σ) :
motive s

Induction on a terminating branching. A property of the leaves that passes from the two children of every inner state to the state holds for every state.

Words #

theorem Cslib.BinaryBranching.walk_append {σ : Type u_1} {T : BinaryBranching σ} (s : σ) (u v : List Bool) :
T.walk s (u ++ v) = T.walk (T.walk s u) v
theorem Cslib.BinaryBranching.walk_take_succ {σ : Type u_1} {T : BinaryBranching σ} (s : σ) (w : List Bool) {i : ℕ} (hi : i < w.length) :
T.walk s (List.take (i + 1) w) = T.next (T.walk s (List.take i w)) (w.getD i false)
theorem Cslib.BinaryBranching.IsLeafWord.isNodeWord {σ : Type u_1} {T : BinaryBranching σ} {s : σ} {w : List Bool} (h : T.IsLeafWord s w) :

Every leaf word is a node word.

theorem Cslib.BinaryBranching.IsLeafWord.isLeaf_walk {σ : Type u_1} {T : BinaryBranching σ} {s : σ} {w : List Bool} (h : T.IsLeafWord s w) :
T.IsLeaf (T.walk s w)

Walking along a leaf word reaches a leaf.

theorem Cslib.BinaryBranching.IsLeafWord.eq_nil {σ : Type u_1} {T : BinaryBranching σ} {s : σ} (hs : T.IsLeaf s) {w : List Bool} (hw : T.IsLeafWord s w) :
w = []

The only leaf word of a leaf is the empty word.

theorem Cslib.BinaryBranching.isLeafWord_iff {σ : Type u_1} {T : BinaryBranching σ} {s : σ} {w : List Bool} :
T.IsLeafWord s w ↔ T.IsNodeWord s w ∧ T.IsLeaf (T.walk s w)

A leaf word is a node word reaching a leaf.

theorem Cslib.BinaryBranching.IsNodeWord.append {σ : Type u_1} {T : BinaryBranching σ} {s : σ} {u v : List Bool} (hu : T.IsNodeWord s u) (hv : T.IsNodeWord (T.walk s u) v) :
T.IsNodeWord s (u ++ v)
theorem Cslib.BinaryBranching.IsNodeWord.not_isLeaf_take {σ : Type u_1} {T : BinaryBranching σ} {s : σ} {w : List Bool} (h : T.IsNodeWord s w) (i : ℕ) :
i < w.length → ¬T.IsLeaf (T.walk s (List.take i w))

The proper prefixes of a node word reach inner states.

theorem Cslib.BinaryBranching.IsLeafWord.eq_of_getD_eq {σ : Type u_1} {T : BinaryBranching σ} {s : σ} {w w' : List Bool} (hw : T.IsLeafWord s w) (hw' : T.IsLeafWord s w') (h : ∀ (i : ℕ), w.getD i false = w'.getD i false) :
w = w'

Leaf words are determined by their true branches. Two leaf words with true branches at the same positions are equal.

theorem Cslib.BinaryBranching.exists_isNodeWord_walkSeq {σ : Type u_1} {T : BinaryBranching σ} (n : ℕ) (s : σ) (f : ℕ → Bool) :
∃ (w : List Bool), T.IsNodeWord s w ∧ T.walkSeq n s f = T.walk s w

Following a branch sequence ends at the state of some node word.

theorem Cslib.BinaryBranching.walkSeq_eq_walk {σ : Type u_1} {T : BinaryBranching σ} {s : σ} {w : List Bool} (hw : T.IsLeafWord s w) {f : ℕ → Bool} (hf : ∀ i < w.length, f i = w.getD i false) {n : ℕ} (hn : w.length ≤ n) :
T.walkSeq n s f = T.walk s w

Following a branch sequence that agrees with a leaf word, for at least as many steps, ends at that leaf.

theorem Cslib.BinaryBranching.card_le_sum_choose_of_isLeafWord {σ : Type u_1} {T : BinaryBranching σ} {s : σ} {W : Finset (List Bool)} (hW : ∀ w ∈ W, T.IsLeafWord s w) {Λ ρ : ℕ} (hlen : ∀ w ∈ W, w.length ≤ Λ) (hρ : ∀ w ∈ W, {i ∈ Finset.range w.length | w.getD i false = true}.card ≤ ρ) :
W.card ≤ ∑ j ∈ Finset.range (ρ + 1), Λ.choose j

Few leaf words. Leaf words of length at most Λ with at most ρ true branches number at most ∑_{j ≤ ρ} (Λ choose j).

Terminating branchings #

theorem Cslib.BinaryBranching.exists_isLeafWord {σ : Type u_1} {T : BinaryBranching σ} (hT : T.Terminating) (s : σ) :
∃ (w : List Bool), T.IsLeafWord s w

Every state has a leaf word.

theorem Cslib.BinaryBranching.IsNodeWord.exists_isLeafWord_append {σ : Type u_1} {T : BinaryBranching σ} (hT : T.Terminating) {s : σ} {w : List Bool} (h : T.IsNodeWord s w) :
∃ (u : List Bool), T.IsLeafWord s (w ++ u)

Every node word extends to a leaf word.

theorem Cslib.BinaryBranching.exists_iterate_searchStep {σ : Type u_1} {α : Type u_2} {T : BinaryBranching σ} (hT : T.Terminating) (f : α → σ → α) (s : σ) {h : ℕ} (hh : ∀ (w : List Bool), T.IsLeafWord s w → w.length ≤ h) :
∃ (L : List (List Bool)), L.Nodup ∧ (∀ (w : List Bool), w ∈ L ↔ T.IsLeafWord s w) ∧ ∃ (N : ℕ), N + 1 ≤ 2 * L.length ∧ ∀ (rest : List σ) (acc : α), (T.searchStep f)^[N] (s :: rest, acc) = (rest, List.foldl f acc (List.map (T.walk s) L)) ∧ ∀ i ≤ N, ∃ (stk : List σ) (L' : List (List Bool)), L' <+: L ∧ (T.searchStep f)^[i] (s :: rest, acc) = (stk ++ rest, List.foldl f acc (List.map (T.walk s) L')) ∧ stk.length ≤ h + 1 ∧ ∀ t ∈ stk, ∃ (w : List Bool), T.IsNodeWord s w ∧ w.length ≤ h ∧ T.walk s w = t

Depth-first search. Started from a state s above a stack rest, the search takes N steps, fewer than twice the number of leaves of s, to return to rest. Meanwhile it folds the update f over the leaves of s, in the order of a duplicate-free list L of the leaf words of s: after each step the accumulator is the fold over a prefix of L. If the leaf words of s have length at most h, the stack above rest consists of at most h + 1 states of the tree of s, reached along node words of length at most h.

theorem Cslib.BinaryBranching.sum_leafWords_eq {σ : Type u_1} {T : BinaryBranching σ} (hT : T.Terminating) {β : Type u_3} [AddCommMonoid β] {g : σ → β} (hg : ∀ (t : σ), ¬T.IsLeaf t → g t = g (T.next t false) + g (T.next t true)) (s : σ) {W : Finset (List Bool)} (hW : ∀ (w : List Bool), w ∈ W ↔ T.IsLeafWord s w) :
∑ w ∈ W, g (T.walk s w) = g s

Additive functions sum over the leaves. If g is the sum of its values at the two children of every inner state, then its sum over the leaf words of s is its value at s.