Zulip Chat Archive

Stream: mathlib4

Topic: import tactic


Kevin Buzzard (Apr 03 2023 at 18:21):

In lean 3 whenever I am teaching I start my files with import tactic. It's a great, easy to remember, useful import which gets everything I need to do logic, natural numbers, all the basic stuff. It does basic group theory, equivalence relations etc etc. It imports a really nice chunk of mathlib. It was written once and got out of date: I don't think it imported stuff like slim_check or omega and one would occasionally run into other tactics which we'd forgotten to put in there, but who cares. It worked modulo obscure edge cases and that was exactly what I needed for teaching.

Is it possible to emulate this experience in mathlib4 by me or someone else writing Mathlib/Tactic.lean which imports all of the tactic files which are there today, and who cares if it gets out of date? I'm writing basic logic files and I've just to import Mathlib.Tactic.LeftRight so I can port the or sheet! I don't want to have to put beginners through seeing that.

Patrick Massot (Apr 03 2023 at 18:35):

I agree we need that. I would merge a PR adding it. A couple of weeks ago there was a crazy discussion where Martin felt he needed to explain what to import in a beginner tactic cheat sheet. This shouldn't be needed. It should be import Tactic.

Jireh Loreaux (Apr 03 2023 at 18:55):

I'm not exactly disagreeing that having this would be nice, but I think the issue is that we want to prevent people from writing import Tactic in mathlib. Of course, we could demand that reviewers don't merge PRs with this, but I think it's hard to avoid it being abused (even unintentionally).

Kevin, as at least a temporary workaround, couldn't you just create a file in your project repo called Tactic.lean and import all the relevant pieces you want into that?

Yaël Dillies (Apr 03 2023 at 18:58):

The problem is that we also don't want a rogue file in no folder, and it needs to be under Mathlib. So it seems the best we can do is import Mathlib.Tactic.Basic.

Sebastian Ullrich (Apr 03 2023 at 19:00):

Jireh Loreaux said:

I'm not exactly disagreeing that having this would be nice, but I think the issue is that we want to prevent people from writing import Tactic in mathlib. Of course, we could demand that reviewers don't merge PRs with this, but I think it's hard to avoid it being abused (even unintentionally).

That sounds like something that could be trivially linted against inside mathlib

Yaël Dillies (Apr 03 2023 at 19:06):

In fact, we already did so for other imports.

Kevin Buzzard (Apr 03 2023 at 19:11):

import Mathlib.Tactic.Basic does not even import left and right which I typically cover in lecture 1 of an introductory lean course for undergraduates (that was what motivated me to start this thread)

Yaël Dillies (Apr 03 2023 at 19:12):

Oh wait, that's already a file!

Kevin Buzzard (Apr 03 2023 at 19:12):

It's too basic

Kevin Buzzard (Apr 03 2023 at 19:12):

It's what I was using instead of import tactic

Adam Topaz (Apr 03 2023 at 19:16):

we could put a file called Tactic.lean with the relevant imports in the Mathlib folder, and use import Mathlib.Tactic

Adam Topaz (Apr 03 2023 at 19:18):

does Lean4 support Default.lean files?

Kyle Miller (Apr 03 2023 at 19:21):

Incidentally, there's both Mathlib.Tactic.Basic and Mathlib.Tactic.Core, and I'm not sure what is supposed to go in each.

Kyle Miller (Apr 03 2023 at 19:21):

Could there be a comprehensive Mathlib.Tactic.All, Mathlib.AllTactics, or Mathlib.Tactics?

Adam Topaz (Apr 03 2023 at 19:22):

why not just Mathlib.Tactic?

Adam Topaz (Apr 03 2023 at 19:23):

Mathlib.Tactic.All also sounds good to me!

Kevin Buzzard (Apr 03 2023 at 19:26):

We have import Mathlib for "import all of mathlib" after all. That's probably also banned in mathlib.

Patrick Massot (Apr 03 2023 at 19:30):

Writing a linter to prevent import Tactic in mathlib should be very easy.

Mario Carneiro (Apr 03 2023 at 20:18):

The obvious and canonical solution to this is to port tactic -> Mathlib.Tactic just like every other file in mathlib

Mario Carneiro (Apr 03 2023 at 20:18):

We don't need a Default.lean file, it would just be Mathlib/Tactic.lean

Mario Carneiro (Apr 03 2023 at 20:20):

As for the list getting out of date, that is hopefully something that can be solved by a PR; I don't think it was really ever "curated" because it doesn't get much use inside mathlib itself so people that use it (e.g. in classes and downstream projects) need to provide input for maintenance

Mario Carneiro (Apr 03 2023 at 20:21):

Kevin Buzzard said:

We have import Mathlib for "import all of mathlib" after all. That's probably also banned in mathlib.

We don't even need a lint for this one, as lean itself will get angry if you do it since it is a circular reference

Yaël Dillies (Apr 03 2023 at 20:21):

But then are we going to end up with default files outside the folders they belong to?

Mario Carneiro (Apr 03 2023 at 20:21):

yes

Yaël Dillies (Apr 03 2023 at 20:21):

That sounds bad.

Mario Carneiro (Apr 03 2023 at 20:21):

:shrug:

Kyle Miller (Apr 03 2023 at 20:23):

How difficult would it be for Mathlib/Tactic.lean to be required to import all of Mathlib/Tactic, and (bonus) have Mathlib.lean import just Mathlib.Tactic?

Mario Carneiro (Apr 03 2023 at 20:25):

it would complicate the one-liner which calculates Mathlib.lean

Mario Carneiro (Apr 03 2023 at 20:26):

you could use a similar one-liner to calculate Mathlib.Tactic, or even calculate all "default" files (lean files with the same name as a directory)

Mario Carneiro (Apr 03 2023 at 20:27):

I think it would actually make import Mathlib.Tactic less useful though, since the original import tactic did not contain everything on purpose

Mario Carneiro (Apr 03 2023 at 20:28):

On the other hand, one of the things we have talked about re: improving precompilation is to reduce the number of entry points, in which case having a one-stop shop Mathlib.Tactic containing everything we want to compile would be a good thing, even inside mathlib

Mario Carneiro (Apr 03 2023 at 20:29):

Some of the tactics are more (mathematically) advanced though and this plays havoc with our dependency graph

Yaël Dillies (Apr 03 2023 at 20:29):

Can we change the way import works so that import x imports x.lean if it exists, or x/y.lean for all y else?

Yaël Dillies (Apr 03 2023 at 20:30):

That sounds like the only way to effectively have all those default files without cluttering every folder which has subfolders.

Mario Carneiro (Apr 03 2023 at 20:31):

To some extent this is a design decision, you don't necessarily want to require directory traversals to build things

Mario Carneiro (Apr 03 2023 at 20:33):

Plus, I actually have a file called Mathlib/Test.lean in which I put random crap people ask me on zulip, and I wouldn't want it to be impossible for that file to exist without getting built by lake build

Mario Carneiro (Apr 03 2023 at 20:34):

currently I can do this by just not putting it in Mathlib.lean and adding it to .git/info/exclude so it isn't pushed in PRs

Kyle Miller (Apr 03 2023 at 20:35):

I'm not sure there's really any issue regarding clutter, but one concrete problem I can think of is that it's a little inconvenient to move modules around since you have to remember to move its sibling. (Of course, if you move a module you also have to update imports everywhere too.)

Mario Carneiro (Apr 03 2023 at 20:36):

"build everything in the directory" might be right for a pristine copy of mathlib but it is probably less likely to be correct for many peoples' mathlib development setups, so separating the two (and checking that they agree in CI) seems like the right approach

Mario Carneiro (Apr 03 2023 at 20:38):

Kyle Miller said:

I'm not sure there's really any issue regarding clutter, but one concrete problem I can think of is that it's a little inconvenient to move modules around since you have to remember to move its sibling. (Of course, if you move a module you also have to update imports everywhere too.)

This could be a code assist BTW

Scott Morrison (Apr 03 2023 at 22:24):

I'm not sure why we are talking about default files here. There's no proposal to generally introduce default files, there's just a single file, Mathlib/Tactic.lean.

Eric Wieser (Apr 04 2023 at 07:23):

I think @Yaël Dillies is indirectly arguing the feature should be reintroduced; which I'm sympathetic to, but isn't really relevant to this conversation (or a good use of Lean4 dev time)

Kevin Buzzard (Apr 04 2023 at 11:42):

mathlib4#3263

Scott Morrison (Apr 04 2023 at 23:37):

My quick merge is not a vote against adding CI that enforces that it imports everything. We can still do that. :-)


Last updated: Dec 20 2023 at 11:08 UTC