Alternating formulas #
An alternating formula of depth d over n variables is a formula in negation normal form
whose unbounded fan-in AND and OR gates alternate along every path from the root, with d gates on
each path and literals at the bottom (AltFormula n d): a literal (i, b) holds when bit i is
b, as in Logic.PL.Literal. Its root operation is given when it is evaluated
(AltFormula.eval), and its size counts the AND and OR gates; literals are free
(AltFormula.size). This is the model of constant-depth circuits in which negations are free and
only at the inputs. At depth two, alternating formulas are formulas in conjunctive or disjunctive
normal form (AltFormula.eval_and_eq_cnf_eval, AltFormula.eval_or_eq_dnf_eval).
Substituting literals for the inputs costs nothing (AltFormula.mapInputs), and negating every
input computes the negation with the dual root operation (AltFormula.eval_neg). Every function
has alternating formulas of depth two of size 2 ^ n + 1 (AltFormula.exists_depth_two).
An alternating formula of depth d is a circuit over the unbounded fan-in basis of AND/OR depth
at most d, and of depth at most d + 1 counting negations, with at most n more gates, computing
the negated inputs first (AltFormula.exists_circuit).
Main definitions #
Cslib.Circuits.Boolean.AltOp,Cslib.Circuits.Boolean.AltOp.dual: root operations (conjunction and disjunction) and De Morgan duality.Cslib.Circuits.Boolean.AltFormula: alternating formulas of a given depth.Cslib.Circuits.Boolean.AltFormula.eval,Cslib.Circuits.Boolean.AltFormula.size: their meaning, for a root operation, and their number of gates.Cslib.Circuits.Boolean.AltFormula.mapInputs,Cslib.Circuits.Boolean.AltFormula.neg: literal substitution and simultaneous input negation.Cslib.Circuits.Boolean.AltFormula.gate,Cslib.Circuits.Boolean.AltFormula.merge,Cslib.Circuits.Boolean.AltFormula.constant,Cslib.Circuits.Boolean.AltFormula.excludingClause,Cslib.Circuits.Boolean.AltFormula.cnf: combinators for building alternating formulas and normal forms.Cslib.Circuits.Boolean.AltFormula.toFormula,Cslib.Circuits.Boolean.AltFormula.literals,Cslib.Circuits.Boolean.AltFormula.literalsCircuit,Cslib.Circuits.Boolean.AltFormula.deMorganLiteralsCircuit: translation of alternating formulas to unbounded fan-in formulas and literal-layer circuits.
Main results #
Cslib.Circuits.Boolean.AltFormula.eval_and_eq_cnf_eval,Cslib.Circuits.Boolean.AltFormula.eval_or_eq_dnf_eval: depth two is conjunctive and disjunctive normal form.Cslib.Circuits.Boolean.AltFormula.exists_depth_two: normal forms as alternating formulas.Cslib.Circuits.Boolean.AltFormula.exists_circuit: alternating formulas as circuits over the unbounded fan-in basis.
The operation at the root of an alternating formula.
Instances For
De Morgan duality swaps conjunction and disjunction.
Instances For
Alternating formulas of depth d over n variables: literals at depth zero, and a list of
alternating formulas of depth d below each gate of depth d + 1. It is reducible, so that an
alternating formula of depth two is a formula in conjunctive or disjunctive normal form.
Instances For
The number of AND and OR gates; literals are free.
Instances For
Evaluate an alternating formula with op at the root.
Instances For
Substitute literals for the inputs. This changes no gates.
Instances For
Negate every input; with the dual root operation, this computes the negation
(AltFormula.eval_neg).
Instances For
Substituting literals for the inputs preserves the number of gates.
Evaluating an alternating formula after substituting literals is equivalent to evaluating the original formula on the evaluated literals.
Negating every input of an alternating formula preserves its size.
An alternating formula of depth two with a conjunction at the root is a formula in conjunctive normal form.
An alternating formula of depth two with a disjunction at the root is a formula in disjunctive normal form.
Building alternating formulas #
One gate over a finite family of alternating formulas.
Instances For
Evaluating gate fs with .and at the root holds iff every child evaluates to true with
.or at its root.
Evaluating gate fs with .or at the root holds iff some child evaluates to true with
.and at its root.
Merge the roots of a finite family of alternating formulas into one, without adding a gate layer.
Instances For
Evaluating merge fs with .and at the root holds iff every formula in the family evaluates
to true with .and at its root.
Evaluating merge fs with .or at the root holds iff some formula in the family evaluates to
true with .or at its root.
A constant, as an alternating formula of any depth at least two.
Instances For
The clause excluding exactly the input y.
Instances For
The clause excludingClause y evaluates to true on x with root .or iff x ≠ y.
excludingClause y has size 1.
The formula in conjunctive normal form excluding every false input of f.
Instances For
Normal forms: every Boolean function has alternating formulas of depth two, with either
root operation, of size at most 2 ^ n + 1.
Alternating formulas as circuits #
An alternating formula as a formula over the unbounded fan-in basis, on the positive inputs
0, …, n - 1 followed by the negated inputs n, …, 2 n - 1.
Instances For
Evaluating toFormula op f on the literal vector literals x agrees with eval op f x.
Translating an alternating formula to an unbounded fan-in formula preserves its gate count.
An alternating formula of depth d translates to a formula of depth at most d.
An alternating formula of depth d translates to a formula of AND/OR depth at most d.
The circuit computing the positive and the negated inputs, with one negation gate per input.
Instances For
literalsCircuit n evaluates to the vector literals x of positive and negated inputs.
literalsCircuit n uses n gates (one negation per input).
deMorganLiteralsCircuit n evaluates to the vector literals x of positive and negated
inputs.
deMorganLiteralsCircuit n uses n gates (one negation per input).
literalsCircuit n has depth at most 1.
Negations are free in the AND/OR depth, so the literals have AND/OR depth zero.
Alternating formulas are circuits: an alternating formula of depth d computing f
with root op is a circuit over the unbounded fan-in basis of AND/OR depth at most d, and of
depth at most d + 1 counting negations, with at most n more gates, negating every input
first.