Zulip Chat Archive

Stream: Is there code for X?

Topic: checking a proof uses all its assumptions


Edwin Agnew (Aug 07 2022 at 23:05):

Is there code for a tactic which proves that some proof does or doesn’t use all of its assumptions?

For example, imagine someone writes a proof for a group that happens to not use the inverse assumption. Is there a way to automatically detect this so that a flag could be raised that the inverse assumption wasn’t used and therefore that proof is equally valid for a monoid?

In terms of what it means to use an assumption, it seems that tactics like by and show from are sufficient. Not sure what’s necessary because there’s probably edge cases like pmi

Yakov Pechersky (Aug 07 2022 at 23:05):

The linter does check if there are unused arguments

Edwin Agnew (Aug 07 2022 at 23:10):

And is there a way to access this linter or does it already raise a warning? I’m new to lean sorry

Yakov Pechersky (Aug 07 2022 at 23:13):

Try adding the #lint command below a lemma

Yakov Pechersky (Aug 07 2022 at 23:14):

import tactic

lemma foo (n : ) : 2 = 1 + 1 := rfl
#lint
/-
/- The `unused_arguments` linter reports: -/
/- UNUSED ARGUMENTS. -/
#check @foo /- argument 1: (n : ℕ) -/
-/

Edwin Agnew (Aug 07 2022 at 23:16):

wow thats perfect! thanks :)

Eric Wieser (Aug 07 2022 at 23:55):

That doesn't really address your original question though

Eric Wieser (Aug 07 2022 at 23:56):

It won't detect that you wrote [group G] but only needed [monoid G], as the argument is still "used", just not all of it

Yakov Pechersky (Aug 07 2022 at 23:56):

Alex has a complex linter/tactic that does this search

Eric Wieser (Aug 07 2022 at 23:57):

@Alex J. Best's paper about that should be linked on the community website somewhere

Eric Wieser (Aug 07 2022 at 23:57):

There's probably a talk on YouTube too

Stuart Presnell (Aug 08 2022 at 07:42):

@Alex J. Best: "Automatically Generalizing Theorems Using Typeclasses" at Formal Mathematics for Mathematicians 2021.

Stuart Presnell (Aug 08 2022 at 07:47):

For example, Alex's linter detects that a comm_ring has been used in a lemma when it would be sufficient to use a comm_semiring.

Eric Rodriguez (Aug 08 2022 at 10:39):

https://leanprover.zulipchat.com/#narrow/stream/113488-general/topic/An.20example.20of.20why.20formalization.20is.20useful/near/278293462 has a list of these generalisations applied to mathlib (a while ago). maybe it'd be nice to rerun it on current mathlib!

Riccardo Brasca (Aug 08 2022 at 10:48):

I can do it, but it took a few days last time, so we need to wait.

Alex J. Best (Aug 08 2022 at 10:51):

I can also run it again sometime and post the output if people want, I keep hoping to improve it first/or at least fix the obvious bugs, but never seem to find the time

Riccardo Brasca (Aug 08 2022 at 11:09):

I am running it. The last version at https://github.com/alexjbest/lean-generalisation seems working

Alex J. Best (Aug 08 2022 at 11:12):

How many cores? I think it still recommends euclidean domain as better than comm_ring sometimes

Alex J. Best (Aug 08 2022 at 11:12):

So while most of the output is ok still there are still somethings not to be trusted :smile:

Riccardo Brasca (Aug 08 2022 at 11:15):

There are 16 cores in the computer I am using, and it is using all of them at the moment. If I remember correctly, last time at some point it switched to use only one core, after it produced the rubbish output at the beginning

Riccardo Brasca (Aug 11 2022 at 15:39):

The result is here

Riccardo Brasca (Aug 11 2022 at 15:40):

https://github.com/leanprover-community/flt-regular/blob/master/res

Riccardo Brasca (Aug 11 2022 at 15:41):

(it's in the flt project just because it was in a computer I can access using my phone and this was the easiest way to make it public)

Riccardo Brasca (Aug 11 2022 at 15:43):

Feel free to create a gist or whatever

Yaël Dillies (Aug 11 2022 at 15:59):

ordered_comm_semiring ↝ linear_ordered_semifield :thinking:

Filippo A. E. Nuccio (Aug 11 2022 at 16:02):

What is a linear_ordered_semifield?

Yaël Dillies (Aug 11 2022 at 16:02):

docs#linear_ordered_semifield. It's a linearly ordered field, but without negation. Typically, nnreal

Filippo A. E. Nuccio (Aug 11 2022 at 16:03):

and does it exist in nature? :palm_tree:

Eric Rodriguez (Aug 11 2022 at 16:04):

Yaël Dillies said:

ordered_comm_semiring ↝ linear_ordered_semifield :thinking:

the linter loves euclidean_domain

Filippo A. E. Nuccio (Aug 11 2022 at 16:04):

And the advantage out of ordered_comm_semiring is that you can divide easily?

Yaël Dillies (Aug 11 2022 at 16:05):

The linter is completely wrong here. linear_ordered_semifield implies ordered_comm_semiring, so it makes no sense to "weaken" the latter to the former.

Eric Rodriguez (Aug 11 2022 at 16:09):

gist: https://gist.github.com/ericrbg/b89109c674b3e04a8f708afa13357911

Eric Rodriguez (Aug 11 2022 at 16:15):

the original version is here, I've force-pushed flt-regular to keep the history clean

Eric Rodriguez (Aug 11 2022 at 17:44):

#16012, #16013, #16014 for some of these (I think #16014 will actually be very helpful!)

Yaël Dillies (Aug 11 2022 at 17:46):

Wow! I didn't think division monoids would actually help further than basic files!

Alex J. Best (Aug 12 2022 at 03:34):

The linear ordered field thing is probably the same as the Euclidean domain issue mentioned above. But I still haven't had time to look into it.

Eric Rodriguez (Aug 12 2022 at 06:52):

I wonder if these are broken classes because linear ordered semifield is the class that causes the olean bug

Alex J. Best (Aug 12 2022 at 08:33):

That seems unlikely to me but who knows, it could be relevant somehow. My best guess is that there something wrong with the type class graph it constructs, maybe some instance with many arguments that isn't interpreted properly


Last updated: Dec 20 2023 at 11:08 UTC