Zulip Chat Archive

Stream: new members

Topic: golf request: Topologist's sine curve


Vlad Tsyrklevich (Mar 07 2025 at 11:36):

As an exercise, I wanted to try formalizing the topologist's sine curve (just the connectedness/path connectedness conditions, there is not currently a predicate for local connectedness in Mathlib) and I was surprised by how hard it was. In retrospect, I think the usual textbook proof leans heavily on the visual intuition and skips a lot of the boring details of moving between the image/preimage. Connectedness was easy, but path connectedness is what took some effort. Working with a Path constructed by choice and its input unitInterval being a subtype introduced some nitpicky inequalities that you don't think about in the informal version.

I realize it's a bit long, but I wondered if anyone had ideas on how to cut out some of the work I'm doing. In particular I wasn't sure if there was a better way of dealing with subtypes or if I could have been using non-metric parts of the Topology API to better effect.

To state the proof in words: I start by contradiction to get a path from the origin, find the supremum of the set of values for which the path is at the origin (zeroSup), then find a contradiction by showing that for any delta, there exists a value outside of the epsilon-ball at the supremum.

EDIT: One thing I considered is re-normalizing the path so that (path x).1 = x, but this seemed like it may be as much work as it saves.

Michael Rothgang (Mar 07 2025 at 12:47):

(There is docs#LocallyConnectedSpace, but no notion of locally connected sets. This would be a welcome addition, though!)

Michael Rothgang (Mar 07 2025 at 12:48):

Would you like to PR this definition to mathlib - after it has been golfed? (To the Counterexamples directory, for instance.)

Vlad Tsyrklevich (Mar 07 2025 at 12:58):

I thought about it, it's a well-known example, but given the amount of fiddly manipulation required I wasn't sure if it's a good candidate. If others think it'd make a good candidate I'd be happy to

Michael Rothgang (Mar 07 2025 at 13:10):

In any case, here are some ideas for golfing/stylistic comments:

  • you can use dot notation to make your code more concise
    For example, IsConnected.image isConnected_Ioi fn this can equivalently be written as
    isConnected_Ioi.image fn this: Lean knows that isConnected_Ioi is type IsConnected ...,
    and deduces that you mean to apply the lemma IsConnected.image.

  • you can inline some very short haves: combined with the previous point,

    have : ContinuousOn fn fn_domain :=
      ContinuousOn.prod continuousOn_id this
    IsConnected.image isConnected_Ioi fn this

could become isConnected_Ioi.image fn (continuousOn_id.prod this).

  • your proofs have a lot of have's: often, it makes sense to promote them to individual lemmas
    (Mathlib code has a lot more lemmas than you'd see in a textbook or paper.)

Vlad Tsyrklevich (Mar 08 2025 at 12:42):

Thanks for the feedback! Originally I thought, there's no way I can split this up more, the logic is too intertwined, but that was clearly wrong. I did manage to split it up more so the proof of non-path-connectedness is now actually fairly short, now the path-renormalization is the ugliest bit, but still, I feel like I've learned more about how to work with mathlib in all of it this. I'll post the current state in case anyone cares to offer more feedback.

Jireh Loreaux (Mar 08 2025 at 15:11):

I would probably rephrase sine_diverges into something like this:

open Filter Real

example (y : ) (hy₁ : -1  y) (hy₂ : y  1) : ∃ᶠ x in atTop, sin x = y := sorry

Then you get the the related result that you want, namely

open Filter Real Topology

example (y : ) (hy₁ : -1  y) (hy₂ : y  1) : ∃ᶠ x in 𝓝[>] 0, sin x⁻¹ = y := sorry

by using docs#Filter.frequently_map and docs#inv_atTop₀.

In fact, the first result generalizes to any periodic function on (and can probably be generalized even further to other domains like ordered additive commutatve monoids where Tendsto (fun n : ℕ ↦ n • c) atTop atTop where c is the period of the function, and if you get this, then you can even multiplicativize the result).

open Filter

lemma Function.Periodic.frequently_atTop_real_eq : {β : Type*} {f :   β}
    {c : } (hf : f.Periodic c) (hc : c  0) {y : β} (hy : y  Set.Range f) :
    ∃ᶠ x in atTop, f x = y :=
  sorry

Last updated: May 02 2025 at 03:31 UTC