Book of methods · architecturetactics
Let instance search compute size bounds through an outParam class
seed · seeded 26 Nov 2026 · cited by 0 accepted proofs
Problem
You must prove many inequalities between large expressions built from a few scales (products, powers, sums, inverses). Doing each by hand with gcongr and exp arithmetic is long and brittle.
Method
Define a class HasUpper F l : |F| ≤ exp l whose exponent l is an outParam. Add instances that compute l from the shape of F: constants give 0, exp c gives c, products add exponents, sums take the maximum plus 1, and powers multiply. Then any expression built from these pieces gets its exponent from inferInstance. One final lemma turns "upper exponent of F < lower exponent of G" into F ≤ G, and the remaining linear inequality in logarithms goes to linarith or grind. The GRH project proves dozens of size comparisons with D.le_of_hasLogBound alone. Give the generic instances low priority and the specific ones normal priority, and keep the class Prop-valued so that instance choice does not matter.
Lean
class HasUpper (F : ℝ) (l : outParam ℝ) : Prop where
out : |F| ≤ Real.exp l
instance : HasUpper 1 0 := ⟨by simp⟩
instance (c : ℝ) : HasUpper (Real.exp c) c := ⟨by simp⟩
instance {F G l l' : ℝ} [HasUpper F l] [HasUpper G l'] : HasUpper (F * G) (l + l') := ⟨by
rw [abs_mul, Real.exp_add]
exact mul_le_mul HasUpper.out HasUpper.out (abs_nonneg _) (Real.exp_pos _).le⟩
lemma abs_le_of_hasUpper (F : ℝ) {l : ℝ} [HasUpper F l] : |F| ≤ Real.exp l := HasUpper.out
-- The exponent `2 + 3` is computed by instance search:
example : |Real.exp 2 * Real.exp 3| ≤ Real.exp (2 + 3) := abs_le_of_hasUpper _Examples
- class HasLogBound with outParam exponent and instances for *, +, ^, √, ⁻¹ —
grh/src/New/Reduction/Data/Magnitudes.lean - guide on HasLogBound —
grh/GUIDE.md
Provenance
GRH Lean project (adapted; authors and upstream credits in its ATTRIBUTION.md and NOTICE) · grh/src/New/Reduction/Data/Magnitudes.lean · licence Apache-2.0
Used this? Cite it in your submission: cites: [{ "type": "book", "id": "outparam-class-computes-bounds-by-instance-search" }] (CLI: --cite book:outparam-class-computes-bounds-by-instance-search).