Bounding a quantity by the structure of a term #
circuit_bound proves a bound m ≤ b between natural numbers when m is determined by the
structure of a term: the depth, size or cost of a circuit built with combinators from named
pieces. It replaces the hand-written chain
apply (Circuit.depth_append_le _ _).trans
apply max_le
· apply Circuit.depth_pi_le
intro i
exact (Formula.depth_toCircuit_le _).trans (by simp [generateFormula])
· apply Circuit.depth_pi_le
intro i
exact (Formula.depth_toCircuit_le _).trans (by simp [propagateFormula])
by circuit_bound [step, generateFormula, propagateFormula].
How it works #
The tactic computes an upper bound of m and leaves the comparison of that bound with b to
omega, falling back to splitting top-level maxs and nlinarith / grind when the comparison is
polynomial rather than linear. It bounds sums, products, powers with a fixed exponent, maxima,
finite sums, mapped list sums, finite suprema and conditionals from bounds of their parts. At any
other term t it tries, in this order:
- If
toccurs inb, it keepst. - A local hypothesis
t ≤ cort = c, possibly under quantifiers: an induction hypothesis, or a bound∀ j, (cs j).depth ≤ Dof a family. - A theorem tagged
@[circuit_bound]whose left-hand side matchest; it then bounds the right-hand side. The rules of the combinators and the bounds of named constructions are registered this way. - The simp set
circuit_simpswith the lemmas given in brackets, which unfolds the listed definitions and applies exact rules such asCircuit.depth_wiring; it then bounds the result. - Otherwise it keeps
t.
The traversal knows nothing about circuits: the tagged theorems and the simp set are the only
circuit-specific parts, and they are attached in CslibFrontier.Computability.Circuit.Simps.
When to use something else #
- For an equation
m = b, usesimp only [circuit_simps, …]andomega: no bound has to be chosen. - When the arithmetic after the structural bound is beyond
omega,nlinarithandgrind(for instance, higher-degree monotonicity or exponent arithmetic), state the structural bound as ahaveproved bycircuit_boundand finish by hand, or rewrite withgrw [Circuit.depth_comp_le, h]and continue with the goal it leaves.
Main definitions #
circuit_bound: the tactic.
Implementation notes #
dite_le_max, forall_mem_ofFn and sum_map_le_length_mul are used in the proofs the tactic
builds, so they are public. The other monotonicity steps use Nat.add_le_add, Nat.mul_le_mul,
Nat.pow_le_pow_left, max_le_max, ite_le_sup, Finset.sum_le_sum and Finset.sup_le.
circuit_bound proves a goal m ≤ b between natural numbers by bounding m along the
structure of the term it measures, typically the depth, size or cost of a circuit, and comparing
the bound with b by omega (falling back to splitting top-level maxs and nlinarith / grind
for polynomial comparisons).
circuit_bound [step, generateFormula]also unfolds the definitionsstepandgenerateFormulaand uses any other simp lemma in the list; the simp setcircuit_simpsis always used.- A named sub-circuit is bounded by a theorem tagged
@[circuit_bound], such as(adder w).depth ≤ 6, or by a local hypothesis, such as an induction hypothesis. Without either its measure stays in the bound, which suits a goal(wrap M).depth ≤ M.depth + 1. - A family, as in
Circuit.pi fun j => cs jorList.ofFn fun j => cs j, needs a bound that does not depend onj. The tactic finds it when everycs jhas the same structural bound, also throughif … then … else. Otherwise state it first:have h : ∀ j, (cs j).depth ≤ D := ….
When it fails, the error shows the comparison omega/nlinarith/grind could not prove, the
sub-terms for which a bound was expected but none is registered or assumed, and the families whose
bound depends on the index. set_option trace.circuit_bound true shows the bounds it used.
Use grw [Circuit.depth_comp_le, h] instead when one step is wanted inside a larger inequality,
when the goal is not of the form m ≤ b, or when the arithmetic that remains is beyond omega,
nlinarith and grind; a structural bound stated as a have and proved by circuit_bound also
serves the last case. For an equation m = b use simp only [circuit_simps, …].
Elaborate circuit_bound: bound the left-hand side, then compare with omega (falling back to
splitting top-level maxs and nlinarith / grind).