I've been pondering how to work with O() notation #Lean4. Lean4 does already sup...

@tao@mathstodon.xyz

I've been pondering how to work with O() notation
#Lean4. Lean4 does already supports a version \(f = O(g) \) of this notation when comparing two functions \(f,g\) of some parameter \(n\) (and one also needs to specify a filter on the parameter space, but never mind that for now). However, in many analysis applications one actually works with expressions such as \( f(n) = g(n) + O(h(n))\), \( f(n) \leq g(n)+O(h(n)) + O(k(n))\), etc., where (a) the parameter \(n\) has been made explicit, and (b) the O() notation is applied to one or more terms, but not necessarily to the entire right-hand side. A typical usage:

\( (n+1)^{e^{1/n}} = (n+1)^{1 + O(1/n)}\)

=exp((log𝑛+𝑂(1/𝑛))(1+𝑂(1/𝑛))

\( = \exp( \log n + O(\log n/n) ) \)

\( = n (1 + O(\log n/n)) \)

\( = n + O(\log n) \)

as \(n \to \infty\).

In principle, (a) can be dealt with in Lean by function extensionality (\(f=g\) iff \(f(n)=g(n)\) for all \(n\)) and (b) can be dealt with by opening and closing existential quantifiers, but this would be quite tiresome; for instance, formalizing the above calculation this way would definitely be unpleasant, as one would have to open and close quantifiers and functions incessantly.

It occurs to me that what one could do instead in many situations is replace the implied constants by explicitly named constants \(C_1, C_2, C_3, \dots\), with each constant defined (possibly nonconstructively, for instance using the `Exists.choose` routine in lean) from preceding ones. This is usually slightly painful to do in Mathematical English - but mostly because it forces one to write out the details in the proof *that one would write anyway* when formalizing. So it may be the path of least resistance.