Zulip Chat Archive

Stream: mathlib4

Topic: List.union


Johan Commelin (Jan 10 2023 at 13:56):

@[simp] theorem nil_union (l : List α) : nil.union l = l := by simp [List.union, foldr]

@[simp] theorem cons_union (a : α) (l₁ l₂ : List α) :
    (a :: l₁).union l₂ = (l₁.union l₂).insert a := by simp [List.union, foldr]

Why do these not use union notation? Now they are basically unusable.

Eric Wieser (Jan 10 2023 at 13:57):

This is a question about mathlib3, right? Looks like docs4#List.cons_union used notation in docs#list.cons_union. Is this a mathport bug?

Johan Commelin (Jan 10 2023 at 14:00):

It looks like a Std bug.

Johan Commelin (Jan 10 2023 at 14:00):

This is in Std/Data/List/Lemmas and it's not using any notation.

Johan Commelin (Jan 10 2023 at 16:13):

I'm currently just passing the instance to simp. I don't think mathlib uses it too much anyway.

Mario Carneiro (Jan 10 2023 at 17:30):

I'm not sure I would call it a bug, but we need versions of these theorems that use the notation as well. I'm not even sure the notation is available in that file

Eric Wieser (Jan 10 2023 at 17:33):

I'd argue we don't need versions that use the .union spelling, as long as we have a lemma to refold union to the notation

Mario Carneiro (Jan 10 2023 at 17:37):

I mean the notation might not be imported, or even if it is it might not be desirable. This is std we're talking about, programmers won't reach for the funny cup operator when they can call list.union

Eric Wieser (Jan 10 2023 at 17:41):

The notation docs4#List.instUnionList is also in Std

Mario Carneiro (Jan 10 2023 at 17:49):

it is, but not all of Std imports every other part

Mario Carneiro (Jan 10 2023 at 17:51):

I don't think it would be a huge deal to have it imported if it isn't already though

Johan Commelin (Jan 10 2023 at 17:53):

@Mario Carneiro I personally don't really care about what Std looks like. But we'll have a naming clash if we want both versions.

Johan Commelin (Jan 10 2023 at 17:54):

Why do we want notation for List?

Mario Carneiro (Jan 10 2023 at 17:55):

'cause it's called union I guess?

Mario Carneiro (Jan 10 2023 at 17:55):

I'm neutral on the notation. There are a lot of weird lemmas about list.union that don't really make sense if you think about it like a set union

Mario Carneiro (Jan 10 2023 at 17:56):

like the fact that the left list is a prefix and the right list is a sublist subperm

Mario Carneiro (Jan 10 2023 at 17:58):

I'm okay with eric's suggestion as well, of having a simp lemma to fold the notation and state all the lemmas with the notation

Eric Wieser (Jan 10 2023 at 18:00):

I'm also fine with removing the notation; I just think having two ways to spell exactly the same thing is a disaster when building a library of theorems.

Johan Commelin (Jan 10 2023 at 18:22):

I vote for removing the notation. Unless Std wants to use the notation everywhere.

James Gallicchio (Jan 11 2023 at 00:55):

I would never use this notation in programming-stuff. too confusing.

Chris Hughes (Jan 11 2023 at 11:31):

We have the same problem for List.insert

Johan Commelin (Jan 11 2023 at 11:32):

Just simp only [instInsertList]

Johan Commelin (Jan 11 2023 at 11:32):

After that, everything works.

Chris Hughes (Jan 11 2023 at 11:32):

But which is the notation we should be using?

Yaël Dillies (Jan 11 2023 at 11:33):

docs4#HasInsert.Insert ?

Yaël Dillies (Jan 11 2023 at 11:33):

Hmm, that doesn't exist

Chris Hughes (Jan 11 2023 at 11:34):

It's docs4#Insert.insert

Chris Hughes (Jan 11 2023 at 11:34):

docs4#Insert

Chris Hughes (Jan 11 2023 at 11:40):

Why did we even introduce has_insert.insert? It's a notation typeclass for something we don't even have notation for

Yaël Dillies (Jan 11 2023 at 11:43):

Yes it is. The notation is {a, b, c}

Chris Hughes (Jan 11 2023 at 12:05):

So we need to refactor Std to get rid of all mention of List.insert?

Johan Commelin (Jan 11 2023 at 12:16):

I think it's not clear whether Std wants to use notation for Lists or avoid it. But it shouldn't try to do both.

Johan Commelin (Jan 11 2023 at 12:17):

Is this blocking the port of Data.List.Perm in a nasty way? Or can you work around it?

Mario Carneiro (Jan 11 2023 at 12:18):

Using set notation for lists seems misleading at best

Mario Carneiro (Jan 11 2023 at 12:19):

although I think it won't activate unless you use a bunch of inserts on empty, while the simp normal form for the empty list is of course []

Mario Carneiro (Jan 11 2023 at 12:20):

so in the case of insert I'm inclined to rewrite from Insert.insert to List.insert

Chris Hughes (Jan 11 2023 at 12:21):

What about just deleting the Insert instance for list then?

Mario Carneiro (Jan 11 2023 at 12:22):

or that

Mario Carneiro (Jan 11 2023 at 12:22):

maybe it would be best to try these refactors out in mathlib3 first though

Chris Hughes (Jan 11 2023 at 12:22):

That's different from the mathlib3 convention where we use has_insert.insert everywhere for lists

Johan Commelin (Jan 11 2023 at 12:23):

That's going to be another speedbump for the port.

Johan Commelin (Jan 11 2023 at 12:23):

I would rather just simp [instInsertList] and continue.

Johan Commelin (Jan 11 2023 at 12:24):

Once Std figures out which of the two options it prefers, we can adjust mathlib

Mario Carneiro (Jan 11 2023 at 12:25):

Is there a need to make an immediate ruling? I think you can add simp lemmas to work around any impedance mismatch if you want to have a particular behavior for the port

Johan Commelin (Jan 11 2023 at 12:26):

Right, that's basically what I'm suggesting, I think

Chris Hughes (Jan 11 2023 at 12:26):

For the port we'll use List.insert because that's what the lemmas in Std already use. I'll make a PR changing everything I can find

Chris Hughes (Jan 11 2023 at 12:39):

https://github.com/leanprover-community/mathlib4/pull/1487

Eric Wieser (Jan 11 2023 at 13:21):

Chris Hughes said:

That's different from the mathlib3 convention where we use has_insert.insert everywhere for lists

Do you have an example? I've never seen insert used on lists before.

Eric Wieser (Jan 11 2023 at 13:22):

Seems pretty random; docs#list.suffix_insert vs docs#list.sublist_insert are right next to each other and use different choices.

Eric Wieser (Jan 11 2023 at 13:23):

It looks to me like this is entirely accidental, and the author didn't realize that list.insert was protected so insert x l and l.insert x are not syntactically identical


Last updated: Dec 20 2023 at 11:08 UTC