Zulip Chat Archive

Stream: general

Topic: move init.algebra.order from core to mathlib?


Scott Morrison (Oct 14 2021 at 23:44):

In core lean, library/init/algebra/order.lean is not actually imported by anything else. Would anyone object if we moved it to mathlib?

Gabriel Ebner (Oct 15 2021 at 07:41):

Are you sure? At least init.algebra.functions imports it, and I find it hard to believe that max and min are unused.

Gabriel Ebner (Oct 15 2021 at 07:41):

But if it is unused (or we can easily make it unused), then I'm all for moving it to mathlib. Core Lean 4 doesn't have orders either.

Yaël Dillies (Oct 15 2021 at 08:21):

I'm all for it too. Just be wary that it is transitively imported by init.data.nat.lemmas which is imported by a bunch of other stuff too.

Yaël Dillies (Oct 15 2021 at 08:22):

I'll be happy to carry out the extraction this weekend.

Yaël Dillies (Oct 15 2021 at 08:24):

What's our general core extraction policy? In my opinion, we could empty core one file at a time, starting from the leaves of the import tree, but maybe swe don't want some of it in mathlib?

Johan Commelin (Oct 15 2021 at 08:31):

@Yaël Dillies Core extraction to mathlib usually happens in a big bump. Because you need to release a new version of Lean, and then bump mathlib to that new version.

Johan Commelin (Oct 15 2021 at 08:32):

Doing that 1 file at a time would get very tiresome quickly.

Yaël Dillies (Oct 15 2021 at 08:34):

Ah yeah. So what do we want to extract from core this time?

Scott Morrison (Oct 15 2021 at 08:56):

Err, yes I was totally wrong about being able to remove it. However I'm trying to remove all decidable instances embedded inside linear_order. So far it is going well, but I'm not sure how much remains.

Mario Carneiro (Oct 15 2021 at 08:59):

wait, why are you doing that?

Mario Carneiro (Oct 15 2021 at 09:00):

That's reversing a patch that was done a year or so ago

Scott Morrison (Oct 15 2021 at 09:00):

Really? :-) Oops. I better go read up on that. Why did we do that?

Mario Carneiro (Oct 15 2021 at 09:00):

to get rid of decidable_linear_order

Scott Morrison (Oct 15 2021 at 09:01):

But why not just have decidability of le completely separate?

Mario Carneiro (Oct 15 2021 at 09:01):

it turned out that linear_order without decidability was just annoying and useless

Mario Carneiro (Oct 15 2021 at 09:01):

so you had lots of undesirable decidable arguments to lemmas

Scott Morrison (Oct 15 2021 at 09:02):

I guess I was imagining that by the time we got to mathlib we would just turn on classical.

Mario Carneiro (Oct 15 2021 at 09:03):

sure, but in this case that means that you don't need to do anything to fill in the extra fields on linear_order

Scott Morrison (Oct 15 2021 at 09:03):

That's true. It was just upsetting me that the definition had this weird computational cruft in it. :-)

Scott Morrison (Oct 15 2021 at 09:03):

I'm not particularly attached!

Scott Morrison (Oct 15 2021 at 09:05):

The change seems pretty straightforward on the core side: https://github.com/leanprover-community/lean/pull/628.

But I'm happy to drop it.

Mario Carneiro (Oct 15 2021 at 09:05):

Also, there are a few choice-free proofs in mathlib, and one of the primary reasons for classical use in those cases was due to lemmas about linear orders that used classical instead of a decidable argument, even though literally every (constructively provable) linear_order instance in mathlib is a decidable_linear_order instance

Mario Carneiro (Oct 15 2021 at 09:05):

so it makes sense to bundle them together

Mario Carneiro (Oct 15 2021 at 09:08):

We had talks about a linter that would watch specific choice-free theorems to ensure they stay choice-free. I never got around to writing it, but I'm fairly sure your PR would fail the linter. :)

Scott Morrison (Oct 15 2021 at 09:08):

I guess the reason I started looking at this was continuing experiments with removing old_structure_cmd. I had a case where I wanted to make linear_order the "non-primary" parent, so (until we reach Lean4), I would have to copy and paste in all the fields of linear_order.

Scott Morrison (Oct 15 2021 at 09:09):

With this change, that would just be le_total. But as is I'd have to copy and paste a lot of cruft! :-)

Scott Morrison (Oct 15 2021 at 09:09):

Could that linter be as simple as a test that prints axioms, and a script that checks the output?

Mario Carneiro (Oct 15 2021 at 09:11):

Yes, although it is also possible to make it a bit nicer by using the axiom checker tactic that exists somewhere on zulip (search for @[intuit])

Scott Morrison (Oct 15 2021 at 09:11):

What do you think about this argument via old_structure_cmd in favour of stripping down linear_order?

Mario Carneiro (Oct 15 2021 at 09:11):

I'm not sure I have the whole context. What's the class diamond in question?

Mario Carneiro (Oct 15 2021 at 09:12):

I notice that linear_order has grown a max and min field since last I checked. I think this stuff just builds up over time

Mario Carneiro (Oct 15 2021 at 09:14):

One way to reduce the duplication is with a mixin that collects all the fields being added. Mathcomp does that systematically

Scott Morrison (Oct 15 2021 at 09:15):

(conditionally_)complete_linear_order has linear_order and (conditionally_)complete_lattice as parents.

Yaël Dillies (Oct 15 2021 at 09:15):

One thing that I would like to see off core is init.data.list.basic so that I can document it, but again it seems a bit hard as of now.

Scott Morrison (Oct 15 2021 at 09:16):

Here's a hand-drawn picture of the lattice hierarchy

Scott Morrison (Oct 15 2021 at 09:16):

@Yaël Dillies, you can send documentation PRs to core!

Yaël Dillies (Oct 15 2021 at 09:17):

I guess!

Yaël Dillies (Oct 15 2021 at 09:17):

Okay, one thing we can strip off core is all the stuff.

Scott Morrison (Oct 15 2021 at 09:26):

@Mario Carneiro, do you know why linear_order ended up with three separate decidable fields, when only the le is needed?

Mario Carneiro (Oct 15 2021 at 09:27):

As far as I know, it's always been like that. But I think the reasoning is the same as for why we have max and min or any number of other "redundant" fields: deriving one field from another can lead to diamond problems

Yaël Dillies (Oct 15 2021 at 09:29):

Scott Morrison said:

Here's a hand-drawn picture of the lattice hierarchy

Why isn't complete_linear_order extending conditionally_complete_linear_order?

Mario Carneiro (Oct 15 2021 at 09:29):

I think the sup function has a different type in those two cases

Yaël Dillies (Oct 15 2021 at 09:29):

Yeah, I did a similar thing recently with locally_finite_order. Only finset.Icc is needed but I also put Ico, Ioc and Ioo as fields.

Mario Carneiro (Oct 15 2021 at 09:30):

I can't think of any examples where you would want to use a conditionally_complete_linear_order lemma on a complete_linear_order. The extra assumptions are basically always unwanted

Gabriel Ebner (Oct 15 2021 at 09:32):

deriving one field from another can lead to diamond problems

It's not just diamonds, but also performance issues. A single equality check is typically faster than two less-than checks.

Yaël Dillies (Oct 15 2021 at 10:11):

Yaël Dillies said:

Okay, one thing we can strip off core is all the stuff.

How do I do that? For now, should I just open a PR to core that deletes the files?

Scott Morrison (Oct 15 2021 at 10:46):

Generally the thing to do is create a PR that modifies core, then build a local copy of Lean3, create a elan toolchain link pointing to that, then make a branch of mathlib in which you use elan override set to ask lean to use your local copy, and then make sure that you can fix mathlib. :-)

Scott Morrison (Oct 15 2021 at 10:47):

If so, then you ask for the PR to core to be merged.

Yaël Dillies (Oct 15 2021 at 10:49):

Uh uh, how do I do any of those steps?

Yaël Dillies (Oct 15 2021 at 10:49):

By "local copy of mathlib", do you mean a branch?

Yaël Dillies (Oct 15 2021 at 10:51):

And what should I do with the tests that are in core? Simply delete them and maybe restore them on the other side?

Johan Commelin (Oct 15 2021 at 10:57):

If the tests are testing stuff that you are removing, yes. If the tests are using stuff you remove as an example, but they are testing something else, then the test needs to be rewritten.

Yaël Dillies (Oct 15 2021 at 10:58):

Okay, how do I create a copy of Lean3?

Yaël Dillies (Oct 15 2021 at 10:59):

My current copy seems to not be set up properly.

Scott Morrison (Oct 15 2021 at 11:05):

The basic version is

git clone git@github.com:leanprover-community/lean.git
cd lean
mkdir -p build/release
cd build/release
cmake ../../src
make

Scott Morrison (Oct 15 2021 at 11:05):

and see https://github.com/leanprover-community/lean/blob/master/doc/make/index.md when things go wrong.

Scott Morrison (Oct 15 2021 at 11:07):

I didn't say a local copy of mathlib, I said a local copy of Lean3. (Although if you're using elan override, I prefer to make a new copy of mathlib to do that in, so that when I forget to remove the override life isn't too confusing...)

Scott Morrison (Oct 15 2021 at 11:08):

I better go to sleep, hopefully others can help. Good luck!

Yaël Dillies (Oct 15 2021 at 11:08):

Thanks!

Yaël Dillies (Oct 15 2021 at 11:25):

I'm stuck at cmake ../../src.

Eric Rodriguez (Oct 15 2021 at 11:29):

What do you mean stuck? Do you have cmake and make?

Yaël Dillies (Oct 15 2021 at 11:31):

I just installed cmake. Not sure I have make

Yaël Dillies (Oct 15 2021 at 11:35):

I am very bad at software stuff, I'm sorry.

Yaël Dillies (Oct 15 2021 at 11:53):

I've opened lean#629

Yaël Dillies (Oct 15 2021 at 11:54):

test.lean.extra.print_info fails, but it seems it was already doing so before?

Eric Rodriguez (Oct 15 2021 at 11:59):

I'm not sure what OS you're on, but this is a major PITA in Windows I remmeber

Yaël Dillies (Oct 15 2021 at 11:59):

I'm on Windows indeed :sob:

Eric Rodriguez (Oct 15 2021 at 12:00):

I wrote some install guide in the Lean repo if you want, also alternatively clion is pretty OK at dealing with it but that's a big install and you're not gonna mess with the c++ stuff I guess

Yaël Dillies (Oct 15 2021 at 12:46):

Seems like I got tricked by docgen not showing the default imports + the multi-imports lines.

Yaël Dillies (Oct 15 2021 at 12:49):

Could we get an import graph of core Lean?

Floris van Doorn (Oct 17 2021 at 12:42):

I noticed a problem that is related to this: docs#subtype.linear_order gives a different proof of decidable equality than docs#subtype.decidable_eq. I'm fixing this in #9701


Last updated: Dec 20 2023 at 11:08 UTC