Zulip Chat Archive

Stream: Is there code for X?

Topic: General topology lemma (complement is connected)


Béranger Seguin (Dec 17 2025 at 16:08):

Hi everyone!

I needed the following lemma from general topology (see e.g., Kuratowski, Introduction to Set Theory and Topology, Chap. XVI, §3, Theorem 4): if X is connected, A⊆X is connected, C is a connected component of X∖A, then X∖C is connected. I wrote a ≈150lines proof of this (this is AxiomC3_general in this code).

Is this lemma actually somewhere in mathlib, to avoid me proving it? Should it? It is important enough that it is one of the four properties of connected sets retained in this axiomatisation of the notion (property (iv) is equivalent to this, cf. top of page 4).

Thanks to everybody! And I'm always happy to hear about ways to write my proofs in a more canonical/idiomatic way :-)
Béranger

Vlad Tsyrklevich (Dec 17 2025 at 16:34):

Do you know about grind? You are doing a fair number of things manually that grind can help with, e.g. your wlog statements and some intermediate statement like MUNVdisj are handled by a single call to grind

Vlad Tsyrklevich (Dec 17 2025 at 16:46):

Small style comments, instead of by apply I'd just give a term, e.g.
have CinXmA : C ⊆ X \ A := connectedComponentIn_subset _ _
have yinC : y ∈ C := mem_connectedComponentIn ynotinA

Use exact instead of apply when it closes the goal

Instead of

    by_contra UVdisj
    rw [not_nonempty_iff_eq_empty] at UVdisj

Use

    by_contra! UVdisj

to simplify the negation at once

There is something called dot notaiton, instead of IsOpen.union Mopen Uopen you can make it shorter by writing Mopen.union Uopen since Mopen is of type IsOpen.

Vlad Tsyrklevich (Dec 17 2025 at 16:48):

For selecting an implication of an Iff, prefer using the names .mp and .mpr instead of .1 and .2

Vlad Tsyrklevich (Dec 17 2025 at 16:51):

Instead of a series of applys/intros, you can often merge these into a single refine statement. Especially as a beginner I found these refines in mathlib a bit hard to read, but once you have done some golfing of your own proofs and combining consecutive applys intro refines, you will find them more concise and therefore readable

Vlad Tsyrklevich (Dec 17 2025 at 16:57):

I have not tried to golf the first proof much, and I could probably go further with the second proof but I think this is enough to show you some new ideas

Vlad Tsyrklevich (Dec 17 2025 at 16:59):

Note in some places I use some syntax like <| where a <| b <| c <| <| d <| e is syntax sugar for a (b (c (d e))) but avoids all the nested parentheses. This is one of those things that I found a bit confusing bit earlier but once you use it a bit yourself you see that it really reduces parentheses and makes proofs more readable.

Vlad Tsyrklevich (Dec 17 2025 at 17:01):

I have focused solely on golfing downing the proof, I have not looked at the contents of the proof or to see if any improvements may be made by using mathlib itself more.

Béranger Seguin (Dec 17 2025 at 17:15):

This is incredible! I indeed did not know about grind. Almost feels like cheating!
I updated my code using some of your recommandations.

Snir Broshi (Dec 17 2025 at 22:01):

Tried to shorten your updated code further:


Last updated: Dec 20 2025 at 21:32 UTC