Formulas #
A formula over a signature is a tree of operation symbols with inputs at its leaves, that is, a
circuit in which every gate is read once. It is evaluated under an interpretation like a circuit
(Formula.eval). Formulas are the free monad on the polynomial functor of the signature; a
dedicated inductive type gives them readable constructors and structural induction. Equality of
formulas is decidable, constructively, when equality of operation symbols is
(Formula.decidableEq), so concrete formulas can be compared by decide.
The leaf size Formula.leafSize counts the input leaves, the measure of formula lower bounds
Jukna, Chapter 6. Nullary operations, such as constants, are not counted: constants
can be eliminated from a formula for a nonconstant function, so this changes no lower bound, and
it gives constant functions leaf size zero. Formula.size counts the operation nodes, constants
included. A formula of depth d with operations of arity at most r has at most r ^ d leaves
(Formula.leafSize_le_pow_depth) and, for r ≥ 2, fewer than r ^ d operation nodes
(Formula.size_lt_pow_depth); with s operation nodes it has at most (r - 1) s + 1 leaves
(Formula.leafSize_le). The least depth of a formula computing a function, with given costs of the
operations, is Formula.minDepthWith; it is ⊤ when no formula computes the function, as happens
for monotone formulas. A formula is a circuit with one gate for each operation node and at most
its depth (Formula.toCircuit). Counting only the leaves labelled by inputs of a set Y
(Formula.leafSizeIn) splits the leaf size among disjoint blocks of inputs
(Formula.sum_leafSizeIn_le_leafSize), and a formula with no leaf in Y depends only on the
inputs outside Y (Formula.dependsOn_eval_of_leafSizeIn_eq_zero). An operation of arity two
folds a list of k formulas into a balanced tree (Formula.balanced, by List.balancedFold) of
depth ⌈log₂ k⌉ above them, the usual way to replace a gate of unbounded fan-in.
Main definitions #
Cslib.Circuits.Formula: formulas over a signature.Cslib.Circuits.Formula.eval,Cslib.Circuits.Formula.Computes: evaluation.Cslib.Circuits.Formula.leafSize,Cslib.Circuits.Formula.size,Cslib.Circuits.Formula.depth: the number of input leaves, the number of operation nodes, and the depth.Cslib.Circuits.Formula.leafSizeIn: the number of input leaves in a set of inputs.Cslib.Circuits.Formula.cost: the sum of operation weights, with input leaves free.Cslib.Circuits.Formula.depthWith: the depth when each operation costs a given number of levels.Cslib.Circuits.Formula.minDepthWith: the least depth with costs of a formula computing a function, inℕ∞.Cslib.Circuits.Formula.gate₂,Cslib.Circuits.Formula.balanced: an operation of arity two applied to two formulas, and the balanced tree of such an operation over a list of formulas.Cslib.Circuits.Formula.bind: substitution of formulas for the inputs;Formula.renamerenames the inputs, andFormula.liftandFormula.substLastadd an input and substitute for it.Cslib.Circuits.Formula.toCircuit: a formula as a single-output circuit.
Main results #
Cslib.Circuits.Formula.map_eval: evaluation commutes with homomorphisms.Cslib.Circuits.Formula.minDepthWith_le,Cslib.Circuits.Formula.le_minDepthWith_iff,Cslib.Circuits.Formula.exists_depthWith_eq_minDepthWith: upper and lower bounds on the least depth, which is attained when some formula computes the function.Cslib.Circuits.Formula.leafSize_le_pow_depth,Cslib.Circuits.Formula.leafSize_le: leaf size under bounded fan-in.Cslib.Circuits.Formula.size_lt_pow_depth: size under bounded fan-in.Cslib.Circuits.Formula.depth_bind_le,Cslib.Circuits.Formula.size_bind_le: depth and size after substitution.Cslib.Circuits.Formula.size_balanced_add_one,Cslib.Circuits.Formula.depthWith_balanced_le: a balanced tree overk ≥ 1formulas addsk - 1nodes and⌈log₂ k⌉levels.Cslib.Circuits.Formula.Computes.toCircuit,Cslib.Circuits.Formula.size_toCircuit,Cslib.Circuits.Formula.depth_toCircuit_le: a formula is a circuit computing the same function, of the same size and at most the same depth.Cslib.Circuits.Formula.cost_toCircuit: compilation preserves arbitrary operation weights.
References #
A formula over the signature σ with inputs Fin n: an input, or an operation applied to
formulas.
- input {σ : Signature} {n : ℕ} (i : Fin n) : Formula σ n
An input.
- gate {σ : Signature} {n : ℕ} (op : σ.Op) (args : Fin (σ.Arity op) → Formula σ n) : Formula σ n
An operation applied to formulas for its arguments.
Instances For
Formulas have decidable equality when operation symbols do: compare the operations at the roots, then the arguments pointwise.
Evaluate a formula under an interpretation.
Instances For
Evaluating a formula commutes with a homomorphism.
A formula computes f when it agrees with f on every input.
Instances For
Disjoint blocks of inputs share out the leaves.
A formula with no leaf in Y depends only on the inputs outside Y.
A formula with no leaf in Y ignores the inputs in Y.
Balanced trees #
The balanced tree of an operation of arity two over a list of formulas
(List.balancedFold): unit for the empty list, the formula for a singleton, and for k ≥ 2
formulas the operation applied to the trees of the first ⌊k / 2⌋ formulas and of the others.
Instances For
A balanced tree is deeper than its formulas by ⌈log₂⌉ of their number times the cost of the
operation; unit only matters for the empty list.
Least depth #
The least depth is at most the depth of every formula computing the function.
Lower bounds on the least depth are lower bounds on the depth of every formula computing the function, including when there is none.
The least depth is finite exactly when some formula computes the function.
When some formula computes the function, the least depth is attained.