feat: Create Asymptotics/GrowthRates#468
Open
Timeroot wants to merge 2 commits intoleanprover:mainfrom
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
IsBigOexpresses growth rate up to a multiplicative constant, there are other importantclasses not directly expressible as
IsBigO. In rough order of literature frequency:GrowthRate.poly: Polynomial growth, typically writtenpoly(n)orn ^ O(1).GrowthRate.polylog:(log n)^k, that is, a polynomial in the logarithm.GrowthRate.exp: Exponential growth with any rate, often writtenexp(O(n))GrowthRate.sublinear: Sublinear growth, typically writteno(n).GrowthRate.quasilinear: Growth asO(n * (log n)^k)GrowthRate.quasipoly: Growth asO(2 ^ (log n)^k)GrowthRate.primitiveRecursive: Growth as a primitive recursive function.GrowthRate.computable: Any computable function. This excludes, for instance, the BusyBeaver function.
These are all given as a
GrowthRate := Set (ℕ → ℕ). We haveGrowthRate.bigOas a thin wrapperaround
Asymptotics.IsBigO, likewise forlittleO.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.sqrtvs.Real.sqrt, or(2 : ℕ) ^ ·vs.(2 : ℝ) ^ .), wewant to have both forms.
Since all of these rates are
Sets, their ordering of "faster growth" is given by thesubset relation
⊆. That is, where you might want to writef ≤ gwherefandgare growth rates, this is best written as
f ⊆ g.Lawful Growth Rates
We call a
GrowthRatelawful if it is closed under dominating sequences, addition, andcomposition 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
LawfulGrowthRateinstances. 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:
ℕ → ℕ,sometimes it's more convenient to work with real numbers. (For instance,
e ^ n, or differentbases of logarithms.) For instance,
GrowthRate.log_iff_rlogrelatesGrowthRate.logto thereal function
Real.log, instead of its definition in terms ofNat.log 2.GrowthRate.exp_ssubset_primitiveRecursiveshows thatexpis a strictsubset of
primitiveRecursive.GrowthRate.linear_compsays that any LawfulGrowthRate isclosed under composition with any function
f ∈ GrowthRate.linear.GrowthRate.poly_compsaysthat
GrowthRate.polyis closed under composition. AndGrowthRate.exp_mulsays thatGrowthRate.expis closed under multiplication.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
LawfulGrowthRateaxioms, I could reasonably see having more or fewer.