feat(TimeM): relate timed costs to big-O #1083
My comments assume this PR was motivated by cslib-community/fad#83. I see two problems:
Problem 1
[Coe T ℝ] doesn't work with TimeM Nat α. So far, FAD has used TimeM Nat all over the place, but Mathlib has no instance of Coe ℕ ℝ. The coercion ℕ → ℝ is given by NatCast. So the proposed definition does not work for any definition in FAD.
Two possible solutions:
Nat and use NatCast. This would be easier, but I don't think it is the right direction from a library point of view.
(toReal : T → ℝ).
Problem 2
You are fixing the filter atTop and the index Nat.
At cslib-community/fad#83 the cost function is given by a pair ℕ × ℕ, and so we would need to pass to Mathlib IsBigO the atTop ×ˢ atTop filter. But your definition is fixing IsBigO atTop .... In that way, this PR is not flexible enough. One possible suggestion would be to generalize your definitions to something like
def IsTheta {ι α T : Type*} (toReal : T → ℝ) (l : Filter ι)
(cost : ι → TimeM T α) (g : ι → ℝ) : Prop :=
Asymptotics.IsTheta l (fun i => toReal (cost i).time) g
For the case of one variable, we could still use atTop.
Coe T Real if T gets Nat will not work. The IsBigO atTop is too specific. The name isBigO should be IsBigO by our conventions since it returns Prop.
same as above.
Requested changes.
Inspecting this issue more closely, the only common cost type for which Coe T ℝ resolves seems to be ℝ ≥ 0. Even T := ℝ fails, since there is no reflexive Coe instance.
It may be worth to explore the connection of this PR with #468
arademaker
cdbattags
Mathlib's
Asymptotics.IsBigOandIsThetacompare two functions along a filter.TimeM.timeis one scalar, so a size-indexed computation does not fit that API by itself.This adds
TimeM.isBigOandTimeM.isThetainCslib/Algorithms/Lean/TimeM/Asymptotics.lean. They coerce(cost n).timetoℝand ask Mathlib whether that function ofnis big-O or big-Theta ofgatFilter.atTop. The module is separate fromTimeM.leanso existingTimeMclients do not import analysis.lake build Cslib.Algorithms.Lean.TimeM.Asymptoticssucceeded, andlake exe mk_allleft the new import inCslib.lean.Drafted with Grok 4.7, the 500k-context high-effort setting, in Cursor. I used it to read
TimeMand Mathlib'sAsymptotics.IsBigO/IsThetaand to write these two definitions. This repository has noLLM-generatedlabel; the disclosure above is the step CONTRIBUTING.md asks for, via the Mathlib policy.