Documentation

CslibFrontier.Tactic.CircuitBound

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:

  1. If t occurs in b, it keeps t.
  2. A local hypothesis t ≤ c or t = c, possibly under quantifiers: an induction hypothesis, or a bound ∀ j, (cs j).depth ≤ D of a family.
  3. A theorem tagged @[circuit_bound] whose left-hand side matches t; it then bounds the right-hand side. The rules of the combinators and the bounds of named constructions are registered this way.
  4. The simp set circuit_simps with the lemmas given in brackets, which unfolds the listed definitions and applies exact rules such as Circuit.depth_wiring; it then bounds the result.
  5. 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 #

Main definitions #

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.

theorem Cslib.Tactic.CircuitBound.dite_le_max {p : Prop} [Decidable p] {a : p → ℕ} {b : ¬p → ℕ} {A B : ℕ} (ha : ∀ (h : p), a h ≤ A) (hb : ∀ (h : ¬p), b h ≤ B) :
dite p a b ≤ max A B

A dependent conditional is at most the larger of the bounds of its branches.

theorem Cslib.Tactic.CircuitBound.forall_mem_ofFn {α : Type u_1} {n : ℕ} {f : Fin n → α} {P : α → Prop} (h : ∀ (j : Fin n), P (f j)) (a : α) :
a ∈ List.ofFn f → P a

A predicate holding at every f j holds for every member of List.ofFn f.

theorem Cslib.Tactic.CircuitBound.sum_map_le_length_mul {α : Type u_1} {l : List α} {f : α → ℕ} {B : ℕ} (h : ∀ a ∈ l, f a ≤ B) :
(List.map f l).sum ≤ l.length * B

The sum of l.map f is at most l.length * B when every member of l satisfies f a ≤ B.

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 definitions step and generateFormula and uses any other simp lemma in the list; the simp set circuit_simps is 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 j or List.ofFn fun j => cs j, needs a bound that does not depend on j. The tactic finds it when every cs j has the same structural bound, also through if … 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).