Skip to content

feat: Create Asymptotics/GrowthRates#468

Open
Timeroot wants to merge 2 commits intoleanprover:mainfrom
Timeroot:growthrates_1
Open

feat: Create Asymptotics/GrowthRates#468
Timeroot wants to merge 2 commits intoleanprover:mainfrom
Timeroot:growthrates_1

Conversation

@Timeroot
Copy link
Copy Markdown

@Timeroot Timeroot commented Apr 3, 2026

I'll copy the docstring from the file, because I think it explains pretty well what the goal here is. I'm trying to PR this into CSLib from CircuitComp.

Asymptotic Growth Rates

Named Growth Rates

This file collects about common "growth rates" that show up in complexity theory. While
IsBigO expresses growth rate up to a multiplicative constant, there are other important
classes not directly expressible as IsBigO. In rough order of literature frequency:

  • GrowthRate.poly: Polynomial growth, typically written poly(n) or n ^ O(1).
  • GrowthRate.polylog: (log n)^k, that is, a polynomial in the logarithm.
  • GrowthRate.exp: Exponential growth with any rate, often written exp(O(n))
  • GrowthRate.sublinear: Sublinear growth, typically written o(n).
  • GrowthRate.quasilinear: Growth as O(n * (log n)^k)
  • GrowthRate.quasipoly: Growth as O(2 ^ (log n)^k)
  • GrowthRate.primitiveRecursive: Growth as a primitive recursive function.
  • GrowthRate.computable: Any computable function. This excludes, for instance, the Busy
    Beaver function.

These are all given as a GrowthRate := Set (ℕ → ℕ). We have GrowthRate.bigO as a thin wrapper
around Asymptotics.IsBigO, likewise for littleO.

We also provide aliases for some of the more common Big-O classes, in order to work
with them more cleanly.

  • GrowthRate.const: O(1)
  • GrowthRate.log: O(log n)
  • GrowthRate.sqrt: O(sqrt n)
  • GrowthRate.linear: O(n)
  • GrowthRate.linearithmic: O(n * log n)
  • GrowthRate.two_pow: O(2 ^ n)
  • GrowthRate.e_pow: O(Real.exp n)

Where they involve functions with different definitions on
distinct types (e.g. Nat.sqrt vs. Real.sqrt, or (2 : ℕ) ^ · vs. (2 : ℝ) ^ .), we
want to have both forms.

Since all of these rates are Sets, their ordering of "faster growth" is given by the
subset relation . That is, where you might want to write f ≤ g where f and g
are growth rates, this is best written as f ⊆ g.

Lawful Growth Rates

We call a GrowthRate lawful if it is closed under dominating sequences, addition, and
composition with a sublinear function; and is nontrivial (it contains at least one function
besides zero).

This last condition is equivalent to containing the constant function 1; or, containing any
two distinct functions. These conditions are enough to get most desirable properties, and all
of above have LawfulGrowthRate instances. This allows reusable proofs for many common properties,
such as invariance under affine scaling.

Main Theorems

Most theorems in this file fall into one of three categories:

  • Equivalent definitions. Sometimes it's more convenient to have expressions as ℕ → ℕ,
    sometimes it's more convenient to work with real numbers. (For instance, e ^ n, or different
    bases of logarithms.) For instance, GrowthRate.log_iff_rlog relates GrowthRate.log to the
    real function Real.log, instead of its definition in terms of Nat.log 2.
  • Ordering. For instance, GrowthRate.exp_ssubset_primitiveRecursive shows that exp is a strict
    subset of primitiveRecursive.
  • Closure properties. For instance, GrowthRate.linear_comp says that any LawfulGrowthRate is
    closed under composition with any function f ∈ GrowthRate.linear. GrowthRate.poly_comp says
    that GrowthRate.poly is closed under composition. And GrowthRate.exp_mul says that
    GrowthRate.exp is closed under multiplication.
/-- A **Growth rate** is just any collection of `ℕ → ℕ`, but as a type alias intended for
discussing how quickly certain classes functions grow, as is often needed in asymptotic runtime
or memory analysis in computational complexity theory. A `LawfulGrowthRate` instance puts
constraints on this set behaving well in various ways.
-/
abbrev GrowthRate := Set (ℕ → ℕ)

I realize this is a big file at the moment. I've already done a lot of cleanup (many of the proofs, but not the majority, were from Aristotle) but there's still plenty of room for improvement I'll admit. It's doing a lot of things, and a lot of them are messy! Converting between Real logs and powers, Ints, and Nats; different bases, different powers, showing these things are all equivalent. The hope is that when these invariably come up in other asymptotic analysis, it's a bit easier; and it gives a "canonical spelling" for certain classes of growth rates, in a way that is currently lacking.

I do think it's probably better to split the file, and I'm hoping for input as to where. Also especially looking for feedback on the choice of LawfulGrowthRate axioms, I could reasonably see having more or fewer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant