Documentation

CslibFrontier.Computability.BranchingProgram.Basic

Deterministic branching programs #

A deterministic branching program over inputs x : ι → α is a directed acyclic graph in which every node is either a sink returning a Boolean output or a query node that reads a coordinate i : ι and moves to the node chosen by the letter x i. Its output on x is the sink reached from a designated start node Arora and Barak, Section 13.4.4, Jukna, Section 1.3. Any coordinate may be queried at any node, and a coordinate may be queried several times along a path.

The nodes are listed in a topological order. BranchingProgram.Nodes ι α n is a sequence of n nodes in which a query node moves only to earlier nodes, so acyclicity is part of the representation, as it is for the straight-line programs Cslib.Circuits.Program. A BranchingProgram is such a sequence with a start node, and its size is its number of nodes, the measure BP(f) of Jukna, Section 15.1. The output (BranchingProgram.eval) is defined by structural recursion on the sequence, so it computes by decide on a concrete program. The sources fix one accepting and one rejecting sink; here any number of nodes may be sinks.

A program is often easier to describe as a graph on a finite type of structured nodes, such as the configurations of a machine, with a rank that decreases along every edge (BranchingProgram.Graph). Listing the nodes of such a graph by rank gives a branching program with one node for each node of the graph (BranchingProgram.Graph.toBranchingProgram, BranchingProgram.Graph.size_toBranchingProgram), whose outputs unfold along the edges of the graph (BranchingProgram.Graph.evalNode_sink, BranchingProgram.Graph.evalNode_branch).

Main definitions #

Main results #

References #

inductive Cslib.BranchingPrograms.BranchingProgram.Step (ι : Type u_1) (α : Type u_2) (Node : Type u_3) :
Type (max (max u_1 u_2) u_3)

The action at a node of a deterministic branching program over inputs ι → α whose successors lie in Node: either a sink returning a Boolean value, or a query that reads coordinate i and moves to next a on the letter a.

  • sink {ι : Type u_1} {α : Type u_2} {Node : Type u_3} (b : Bool) : Step ι α Node

    A sink returning b.

  • branch {ι : Type u_1} {α : Type u_2} {Node : Type u_3} (i : ι) (next : α → Node) : Step ι α Node

    A query reading coordinate i and moving to next a on the letter a.

def Cslib.BranchingPrograms.BranchingProgram.Step.rename {ι : Type u_1} {κ : Type u_2} {α : Type u_3} {Node : Type u_5} (f : ι → κ) :
Step ι α Node → Step κ α Node

The action that queries f i wherever step queries i.

def Cslib.BranchingPrograms.BranchingProgram.Step.comap {ι : Type u_1} {α : Type u_3} {β : Type u_4} {Node : Type u_5} (g : β → α) :
Step ι α Node → Step ι β Node

The action over the alphabet β that reads each letter b as g b.

inductive Cslib.BranchingPrograms.BranchingProgram.Nodes (ι : Type u_6) (α : Type u_7) :
ℕ → Type (max u_6 u_7)

A sequence of n nodes in topological order: each node is a sink, or queries a coordinate and moves to an earlier node.

  • empty {ι : Type u_6} {α : Type u_7} : Nodes ι α 0

    The empty sequence.

  • node {ι : Type u_6} {α : Type u_7} {n : ℕ} (P : Nodes ι α n) (step : Step ι α (Fin n)) : Nodes ι α (n + 1)

    The nodes of P followed by a node acting by step.

def Cslib.BranchingPrograms.BranchingProgram.Nodes.eval {ι : Type u_1} {α : Type u_3} (x : ι → α) {n : ℕ} :
Nodes ι α n → Fin n → Bool

The output reached from each node on the input x.

@[simp]
theorem Cslib.BranchingPrograms.BranchingProgram.Nodes.eval_node_castSucc {ι : Type u_1} {α : Type u_3} {n : ℕ} (P : Nodes ι α n) (step : Step ι α (Fin n)) (x : ι → α) (v : Fin n) :
eval x (P.node step) v.castSucc = eval x P v

An earlier node reaches the same output in a longer sequence.

@[simp]
theorem Cslib.BranchingPrograms.BranchingProgram.Nodes.eval_node_last_sink {ι : Type u_1} {α : Type u_3} {n : ℕ} (P : Nodes ι α n) (b : Bool) (x : ι → α) :
eval x (P.node (Step.sink b)) (Fin.last n) = b

A sink returns its value.

@[simp]
theorem Cslib.BranchingPrograms.BranchingProgram.Nodes.eval_node_last_branch {ι : Type u_1} {α : Type u_3} {n : ℕ} (P : Nodes ι α n) (i : ι) (next : α → Fin n) (x : ι → α) :
eval x (P.node (Step.branch i next)) (Fin.last n) = eval x P (next (x i))

A query node reaches the output of the node it moves to.

def Cslib.BranchingPrograms.BranchingProgram.Nodes.rename {ι : Type u_1} {κ : Type u_2} {α : Type u_3} (f : ι → κ) {n : ℕ} :
Nodes ι α n → Nodes κ α n

The sequence that queries f i wherever P queries i.

@[simp]
theorem Cslib.BranchingPrograms.BranchingProgram.Nodes.eval_rename {ι : Type u_1} {κ : Type u_2} {α : Type u_3} (f : ι → κ) (x : κ → α) {n : ℕ} (P : Nodes ι α n) (v : Fin n) :
eval x (rename f P) v = eval (x ∘ f) P v

Renaming the coordinates by f evaluates on x ∘ f.

def Cslib.BranchingPrograms.BranchingProgram.Nodes.comap {ι : Type u_1} {α : Type u_3} {β : Type u_4} (g : β → α) {n : ℕ} :
Nodes ι α n → Nodes ι β n

The sequence over the alphabet β that reads each letter b as g b.

@[simp]
theorem Cslib.BranchingPrograms.BranchingProgram.Nodes.eval_comap {ι : Type u_1} {α : Type u_3} {β : Type u_4} (g : β → α) (x : ι → β) {n : ℕ} (P : Nodes ι α n) (v : Fin n) :
eval x (comap g P) v = eval (g ∘ x) P v

Pulling back along g evaluates on g ∘ x.

def Cslib.BranchingPrograms.BranchingProgram.Nodes.ofFn {ι : Type u_1} {α : Type u_3} {n : ℕ} :
((k : ℕ) → k < n → Step ι α (Fin k)) → Nodes ι α n

The sequence whose node k acts by f k.

theorem Cslib.BranchingPrograms.BranchingProgram.Nodes.eval_ofFn_sink {ι : Type u_1} {α : Type u_3} (x : ι → α) {n : ℕ} (f : (k : ℕ) → k < n → Step ι α (Fin k)) (k : ℕ) (hk : k < n) {b : Bool} :
f k hk = Step.sink b → eval x (ofFn f) ⟨k, hk⟩ = b

A sink of ofFn f returns its value.

theorem Cslib.BranchingPrograms.BranchingProgram.Nodes.eval_ofFn_branch {ι : Type u_1} {α : Type u_3} (x : ι → α) {n : ℕ} (f : (k : ℕ) → k < n → Step ι α (Fin k)) (k : ℕ) (hk : k < n) {i : ι} {next : α → Fin k} :
f k hk = Step.branch i next → eval x (ofFn f) ⟨k, hk⟩ = eval x (ofFn f) (Fin.castLE ⋯ (next (x i)))

A query node of ofFn f reaches the output of the node it moves to.

structure Cslib.BranchingPrograms.BranchingProgram (ι : Type u_1) (α : Type u_2) :
Type (max u_1 u_2)

A deterministic branching program over inputs ι → α: nodes in topological order, each a sink or a query moving to an earlier node, with a start node Arora and Barak, Section 13.4.4. Its size is its number of nodes Jukna, Section 15.1.

  • size : ℕ

    The number of nodes.

  • nodes : Nodes ι α self.size

    The nodes, in topological order.

  • start : Fin self.size

    The start node.

def Cslib.BranchingPrograms.BranchingProgram.eval {ι : Type u_1} {α : Type u_3} (P : BranchingProgram ι α) (x : ι → α) :

The output of P on the input x: the value of the sink reached from the start node.

The one-node branching program returning the constant b.

@[simp]
theorem Cslib.BranchingPrograms.BranchingProgram.eval_const {ι : Type u_1} {α : Type u_3} (b : Bool) (x : ι → α) :
(const ι α b).eval x = b

The constant program returns its value on every input.

@[simp]
theorem Cslib.BranchingPrograms.BranchingProgram.size_const {ι : Type u_1} {α : Type u_3} (b : Bool) :
(const ι α b).size = 1

The constant program has one node.

theorem Cslib.BranchingPrograms.BranchingProgram.eval_eq_of_size_le_one {ι : Type u_1} {α : Type u_3} (P : BranchingProgram ι α) (hsize : P.size ≤ 1) (x y : ι → α) :
P.eval x = P.eval y

A branching program with at most one node cannot query its input, so it is constant.

def Cslib.BranchingPrograms.BranchingProgram.rename {ι : Type u_1} {κ : Type u_2} {α : Type u_3} (f : ι → κ) (P : BranchingProgram ι α) :

The branching program that queries f i wherever P queries i.

@[simp]
theorem Cslib.BranchingPrograms.BranchingProgram.eval_rename {ι : Type u_1} {κ : Type u_2} {α : Type u_3} (f : ι → κ) (P : BranchingProgram ι α) (x : κ → α) :
(rename f P).eval x = P.eval (x ∘ f)

Renaming the coordinates by f evaluates on x ∘ f.

@[simp]
theorem Cslib.BranchingPrograms.BranchingProgram.size_rename {ι : Type u_1} {κ : Type u_2} {α : Type u_3} (f : ι → κ) (P : BranchingProgram ι α) :
(rename f P).size = P.size

Renaming the coordinates keeps the nodes.

def Cslib.BranchingPrograms.BranchingProgram.comap {ι : Type u_1} {α : Type u_3} {β : Type u_4} (g : β → α) (P : BranchingProgram ι α) :

The branching program over the alphabet β that reads each letter b as g b.

@[simp]
theorem Cslib.BranchingPrograms.BranchingProgram.eval_comap {ι : Type u_1} {α : Type u_3} {β : Type u_4} (g : β → α) (P : BranchingProgram ι α) (x : ι → β) :
(comap g P).eval x = P.eval (g ∘ x)

Pulling back along g evaluates on g ∘ x.

@[simp]
theorem Cslib.BranchingPrograms.BranchingProgram.size_comap {ι : Type u_1} {α : Type u_3} {β : Type u_4} (g : β → α) (P : BranchingProgram ι α) :
(comap g P).size = P.size

Pulling back along a map of alphabets keeps the nodes.

Programs described as graphs #

structure Cslib.BranchingPrograms.BranchingProgram.Graph (ι : Type u_6) (α : Type u_7) (Node : Type u_8) :
Type (max (max u_6 u_7) u_8)

A deterministic branching program described as a graph on the nodes Node: each node is a sink or a query, and every edge out of a query node leads to a node of strictly smaller rank, which makes the graph acyclic. For finite Node, Graph.toBranchingProgram lists the nodes by rank.

  • start : Node

    The start node.

  • node : Node → Step ι α Node

    The action at each node.

  • rank : Node → ℕ

    A rank decreasing along every edge.

  • rank_lt (v : Node) (i : ι) (next : α → Node) (a : α) : self.node v = Step.branch i next → self.rank (next a) < self.rank v

    Every edge out of a query node leads to a node of strictly smaller rank.

noncomputable def Cslib.BranchingPrograms.BranchingProgram.Graph.toBranchingProgram {ι : Type u_1} {α : Type u_3} {Node : Type u_5} [Fintype Node] (G : Graph ι α Node) :

The branching program of a graph on a finite node type: its nodes listed by rank.

@[simp]

The branching program of a graph has one node for each node of the graph.

noncomputable def Cslib.BranchingPrograms.BranchingProgram.Graph.evalNode {ι : Type u_1} {α : Type u_3} {Node : Type u_5} [Fintype Node] (G : Graph ι α Node) (x : ι → α) (v : Node) :

The output the branching program of G reaches from the node v on the input x.

theorem Cslib.BranchingPrograms.BranchingProgram.Graph.eval_toBranchingProgram {ι : Type u_1} {α : Type u_3} {Node : Type u_5} [Fintype Node] (G : Graph ι α Node) (x : ι → α) :

The output of the branching program of G is the output reached from the start node.

theorem Cslib.BranchingPrograms.BranchingProgram.Graph.evalNode_sink {ι : Type u_1} {α : Type u_3} {Node : Type u_5} [Fintype Node] {G : Graph ι α Node} (x : ι → α) {v : Node} {b : Bool} (h : G.node v = Step.sink b) :
G.evalNode x v = b

A sink of the graph returns its value.

theorem Cslib.BranchingPrograms.BranchingProgram.Graph.evalNode_branch {ι : Type u_1} {α : Type u_3} {Node : Type u_5} [Fintype Node] {G : Graph ι α Node} (x : ι → α) {v : Node} {i : ι} {next : α → Node} (h : G.node v = Step.branch i next) :
G.evalNode x v = G.evalNode x (next (x i))

A query node of the graph reaches the output of the node it moves to.