Zulip Chat Archive
Stream: mathlib4
Topic: Proposal: Add decidable membership for Interval
Ka Wing Li (Dec 26 2025 at 01:43):
I am proposing to add the following
instance [Preorder α] : Membership α (Interval α) where
mem := sorry
instance [Preorder α] [DecidableLE α] (x : α) (i : NonemptyInterval α) : Decidable (x ∈ i) :=
sorry
instance [Preorder α] [DecidableLE α] (x : α) (i : Interval α) : Decidable (x ∈ i) :=
sorry
Ka Wing Li (Dec 26 2025 at 01:48):
It will allow us to do something like
def interval : Interval ℕ := { fst := 0, snd := 10, fst_le_snd := by grind : NonemptyInterval ℕ}
#eval 5 ∈ interval -- true
example : 5 ∈ interval := by
simp [interval]
Aaron Liu (Dec 26 2025 at 01:50):
Do we already get the membership instance or is that new
Ka Wing Li (Dec 26 2025 at 01:51):
As far as I know, I haven't found any implementation about it.
Ka Wing Li (Dec 26 2025 at 01:52):
Originated from #Is there code for X? > membership with interval
Ka Wing Li (Dec 26 2025 at 03:03):
After I add the implementations, it seems broke Interval.mem_pure
Ka Wing Li (Dec 26 2025 at 03:06):
The proof does not need to go to SetLike; does it even need to be a PartialOrder?
@[simp]
theorem mem_pure : b ∈ pure a ↔ b = a := by
simp [pure]
-- original proof
-- rw [← SetLike.mem_coe, coe_pure, mem_singleton_iff]
Aaron Liu (Dec 26 2025 at 03:19):
So it looks like there was already another membership instance
Aaron Liu (Dec 26 2025 at 03:19):
You should get rid of your new membership and just use the old one
Ka Wing Li (Dec 26 2025 at 03:20):
Yet, the older one has a stronger requirement of PartialOrder instead of a weaker requirement of Preorder in the new definition.
Aaron Liu (Dec 26 2025 at 03:22):
oh I guess representation as a set isn't faithful if you don't have antisymmetry
Aaron Liu (Dec 26 2025 at 03:23):
in that case I don't think Interval correctly captures my intuition on what an interval is
Aaron Liu (Dec 26 2025 at 03:23):
so I wouldn't be too concerned about preorders
Ka Wing Li (Dec 26 2025 at 03:42):
I think we can have intervals well defined in a preorder set.
Ka Wing Li (Dec 26 2025 at 03:43):
So far from isabelle I found membership of interval still uses preorder.
Ka Wing Li (Dec 26 2025 at 03:45):
NonemptyInterval.instCoeSet still uses preorder. I am wondering where do we end up with partial order in mathlib.
Robin Arnez (Dec 26 2025 at 12:16):
The reason we need PartialOrder is that SetLike requires the map into a Set to be injective, i.e. two different intervals should also yield two different Sets.
Ka Wing Li (Dec 26 2025 at 16:11):
Btw, I have made a PR at mathlib4#33299
Ka Wing Li (Dec 26 2025 at 16:12):
Interesting, I am curious why Setlike requires Partialorder / injective?
Ka Wing Li (Dec 26 2025 at 18:14):
It is sad that we will never be able to define the following without breaking definitional equality
instance {α β} [Membership α β] : Membership α (WithBot β) where
mem
| ⊥ => fun _ => False
| (b : β) => fun a => a ∈ b
Ka Wing Li (Dec 26 2025 at 18:20):
I am curious about the following
An alternative to SetLike could have been an extensional Membership typeclass:
class ExtMembership (α : out_param <| Type u) (β : Type v) extends Membership α β where
(ext_iff : ∀ {s t : β}, s = t ↔ ∀ (x : α), x ∈ s ↔ x ∈ t)
While this is equivalent, SetLike conveniently uses a carrier set projection directly.
Ka Wing Li (Dec 26 2025 at 18:23):
ExtMembership looks good, which does not require injectivity.
Aaron Liu (Dec 26 2025 at 18:39):
no it definitely does require injectivity
Ka Wing Li (Dec 26 2025 at 18:42):
Hmm, I don't see how?
Ka Wing Li (Dec 26 2025 at 18:43):
Copied an image from wiki
image.png
Ka Wing Li (Dec 26 2025 at 18:47):
For this preorder set with x R y defined by over naturral number. I can define intervals [4, 11] and [6, 9], which are equal. And the corresponding set is just {4,5,6,7,8,9,10,11}.
Ka Wing Li (Dec 26 2025 at 18:50):
And it satisfies ext_iff.
Aaron Liu (Dec 26 2025 at 18:58):
but [4, 11] ≠ [6, 9] because their left endpoints aren't equal
Aaron Liu (Dec 26 2025 at 18:58):
but they have the same members
Aaron Liu (Dec 26 2025 at 18:59):
so it's not extensional
Johan Commelin (Dec 26 2025 at 19:00):
Doesn't that depend on your definition of interval? The lemma [a,b] = [c,d] \iff a = c \and b = d will be false. So then we prove that lemma under the stronger partial order assumption...
Aaron Liu (Dec 26 2025 at 19:02):
I was just going off how the type docs#Interval works
Ka Wing Li (Dec 26 2025 at 19:02):
Hmm, I am thinking about extensionality:
Aaron Liu (Dec 26 2025 at 19:03):
well if you quotient by extensionality you get extensionality for free
Johan Commelin (Dec 26 2025 at 19:04):
Aaron Liu said:
I was just going off how the type docs#Interval works
Fair enough. :smiley:
I hadn't looked at it :man_facepalming:
Ka Wing Li (Dec 26 2025 at 19:05):
Hmm, ain't partial order kind of like a quotient of preorder? Let me lookup more info.
Aaron Liu (Dec 26 2025 at 19:05):
an Interval is either the empty interval, or a docs#NonemptyInterval which bundles its two endpoints and a proof the the left endpoint is smaller than the right endpoint
Aaron Liu (Dec 26 2025 at 19:06):
Ka Wing Li said:
Hmm, ain't partial order kind of like a quotient of preorder? Let me lookup more info.
Ka Wing Li (Dec 26 2025 at 19:17):
Is there anything like . Galois connection / natural transformation / ..., can't remember the terminology.
Ka Wing Li (Dec 26 2025 at 19:18):
a weaker form of extensionality
Aaron Liu (Dec 26 2025 at 19:21):
not sure what you mean
Aaron Liu (Dec 26 2025 at 19:21):
what is
Ka Wing Li (Dec 26 2025 at 19:22):
Like the intervals
Aaron Liu (Dec 26 2025 at 19:23):
do you mean docs#AntisymmRel
Ka Wing Li (Dec 26 2025 at 19:25):
Just realised interesting stuff: for Preorder a, we have Preorder (NonemptyInterval a)
Ka Wing Li (Dec 26 2025 at 19:25):
Yes, is the docs#AntisymmRel. I am asking about the part.
Aaron Liu (Dec 26 2025 at 19:26):
I don't think we have anything exactly like that then
Aaron Liu (Dec 26 2025 at 19:26):
I guess you could build it with docs#RelIso
Aaron Liu (Dec 26 2025 at 19:27):
or maybe docs#RelEmbedding
Ka Wing Li (Dec 26 2025 at 19:32):
Hmm, then we are going back to docs#OrderEmbedding to docs#SetLike :joy:
Ka Wing Li (Dec 26 2025 at 19:32):
Nvm
Ka Wing Li (Dec 26 2025 at 20:09):
Quick question, why docs#RelEmbedding has to be injective?
Ka Wing Li (Dec 26 2025 at 20:11):
Originated from why docs#OrderEmbedding has to be injective?
Ka Wing Li (Dec 26 2025 at 20:12):
Mathematically we just need
Ka Wing Li (Dec 26 2025 at 20:13):
imaging working on preorder set
Aaron Liu (Dec 26 2025 at 20:16):
I feel like it's not as common to have something like that
Aaron Liu (Dec 26 2025 at 20:16):
where it's both ways
Aaron Liu (Dec 26 2025 at 20:16):
unless it's an embedding of one thing as a sub-thing of another thing
Ka Wing Li (Dec 26 2025 at 20:24):
Hmm, it's not that uncommon if we work on the category of preorder sets.
Ka Wing Li (Dec 26 2025 at 20:27):
Anyway thanks!
Last updated: Feb 28 2026 at 14:05 UTC