Zulip Chat Archive

Stream: mathlib4

Topic: orderDual defeq abuse


Kim Morrison (Mar 20 2025 at 00:25):

We still have quite a number of places in Mathlib where we are abusing the defeq of OrderDual.

One that I ran into today was docs#Dense.borel_eq_generateFrom_Ioc_mem_aux. Would anyone be interested in taking a look?

Kim Morrison (Mar 20 2025 at 00:26):

The first convert can be improved to

  convert hd.orderDual.borel_eq_generateFrom_Ico_mem_aux (by simpa using hbot)
    fun x y hlt he => hIoo (ofDual y) (ofDual x) hlt _ using 2

but this is still not right.

One can put seal OrderDual in above the declaration to ensure that defeq abuse is avoided! :-)

Wrenna Robson (Jul 12 2025 at 08:08):

I kept hitting this today. OrderDual is just very annoying to work with.

Wrenna Robson (Jul 12 2025 at 08:08):

What does "seal" do?

Wrenna Robson (Jul 12 2025 at 08:15):

One issue is tbf I constantly find myself wishing for a type that represents order-reversing homomorphisms (and isomorphisms).

Wrenna Robson (Jul 12 2025 at 08:16):

We generally define these using OrderDual but it somewhat funnels you into accidentally defeq abusing.

Junyan Xu (Jul 12 2025 at 08:19):

I thought defeq abusing OrderDual in proofs is a feature not a bug ...

Wrenna Robson (Jul 12 2025 at 08:20):

I just had an issue with using PartialOrder.lift where even when putting in ofDual explicitly it lifted the wrong order.

Wrenna Robson (Jul 12 2025 at 08:20):

Junyan Xu said:

I thought defeq abusing OrderDual in proofs is a feature not a bug ...

I think of it as a cowboy era thing in some ways.

Wrenna Robson (Jul 12 2025 at 08:21):

I think in an ideal world OrderDual would be a one-element structure.

Wrenna Robson (Jul 12 2025 at 08:22):

The issue is it encourages things like (OrderDual (OrderDual (a)) = a. And that's inherently a bit evil.

Junyan Xu (Jul 12 2025 at 08:27):

Yeah the instances on αᵒᵈᵒᵈ are the same as (I mean defeq to) those on α. Is there an example of abusing this in defs in mathlib?

Yaël Dillies (Jul 12 2025 at 08:33):

Junyan Xu said:

the instances on αᵒᵈᵒᵈ are the same as those on α

This is unfortunately wishful thinking, and some operations disagree, but there are so few that I can't even remember a single one off the top of my head

Kenny Lau (Jul 12 2025 at 10:38):

how can they disagree if Xdd is isomorphic to X

Wrenna Robson (Jul 12 2025 at 10:40):

Isomorphism is not equality.

Yaël Dillies (Jul 12 2025 at 10:40):

Equality is not definitional equality

Jovan Gerbscheid (Jul 13 2025 at 17:25):

We will need to use OrderDual a lot less once the to_dual attribute makes it to mathlib.

Wrenna Robson (Jul 14 2025 at 08:55):

What will that attribute do?

Jovan Gerbscheid (Jul 14 2025 at 10:08):

It is very similar to @[to_additive], which takes a theorem, replaces every * with a + where appropriate, and produces a proof of the translates version by translating the original proof. Instead, @[to_dual] will replace every a ≤ b with b ≤ a where appropriate, and dualize whatever can be dualized, e.g. maxmin.

Wrenna Robson (Jul 14 2025 at 12:32):

Right. But that wouldn't let you avoid the use of it for e.g. defining an order-reversing map.

Jovan Gerbscheid (Jul 14 2025 at 12:37):

Exactly, but I would expect that those kind of uses don't do much defeq abuse.


Last updated: Dec 20 2025 at 21:32 UTC