Zulip Chat Archive

Stream: general

Topic: Question about {! !}


Stanislas Polu (Jun 09 2022 at 10:43):

Hi! The following proof seems to type-check. Any idea what is going on?

import data.finset.basic
import data.nat.interval

example
  (vertices : finset )
  (diagonals : finset (finset ))
  (h₀ : vertices = finset.Icc 1 5)
  (h₁ :  (m n : ), ({m,n} : finset )  diagonals 
    {m,n}  vertices  m  n  m  n + 1  m  n - 1  {m,n}  ({1,5} : finset )) :
  diagonals.card = 5 :=
begin
  have h₂ : diagonals = {! {2,4}, {1,3}, {3,5} !}, {
    dec_trivial!,
  },
  rw h₂,
  dec_trivial!,
end

Stanislas Polu (Jun 09 2022 at 10:50):

Some weird interaction with the docstring parser?

Jason Rute (Jun 09 2022 at 10:55):

Do you know about hole commands using {! … !}? I’m struggling to find documentation to show you, but you can search for it hear on Zulip.

Stanislas Polu (Jun 09 2022 at 10:56):

It vaguely appears in comments in tactic/core.lean

Stanislas Polu (Jun 09 2022 at 10:57):

Clearly unused and undocumented

Jason Rute (Jun 09 2022 at 10:57):

In short, they are, or used to be, a way to highlight some code and prompt vs code to give you a lightbulb with possible actions (like expanding a template for a match).

Stanislas Polu (Jun 09 2022 at 10:58):

Models will find holes :) I guess I need to blacklist {!

Jason Rute (Jun 09 2022 at 10:58):

Yes, I don’t think you want your model producing them. :)

Stanislas Polu (Jun 09 2022 at 10:59):

Probably needs a fix in Lean as well I think would be sad to introduce false without lean make complaining about it

Jason Rute (Jun 09 2022 at 11:00):

I would make a GitHub issue for lean 3 community edition.

Stanislas Polu (Jun 09 2022 at 11:04):

Filed here: https://github.com/leanprover-community/lean/issues/725

Alex J. Best (Jun 09 2022 at 11:21):

What do you mean it seems to type-check, I get declaration [anonymous] uses sorry

Sebastien Gouezel (Jun 09 2022 at 11:22):

Can you get a proof of false from it?

Sebastien Gouezel (Jun 09 2022 at 11:22):

I also see the sorry.

Mario Carneiro (Jun 09 2022 at 11:27):

The source of the issue is that {! !} seems to produce a synthetic sorry (printed as ??), which suppresses most error reporting about it because this happens after an error was already reported so the knock on errors are unhelpful

Stanislas Polu (Jun 09 2022 at 11:28):

Ah you're right that we have a sorry :+1: So we're safe

Mario Carneiro (Jun 09 2022 at 11:29):

if you replace the hole command with (λ) or something then you will notice the tactics also seem to succeed

Mario Carneiro (Jun 09 2022 at 11:30):

I'm inclined to call this not-a-bug

Stanislas Polu (Jun 09 2022 at 11:30):

Yep closed the issue

Stanislas Polu (Jun 09 2022 at 11:32):

Source of the confusion on my end comes from the fact that we don't use the lean --make command output to "find out sorry" and instead inspect the code for sorry and admit.

Stanislas Polu (Jun 09 2022 at 11:32):

Is there a way to make lean --make error (instead of warning) in presence of any form of sorry ?

Mario Carneiro (Jun 09 2022 at 11:36):

just look for {!

Alex J. Best (Jun 09 2022 at 11:42):

Do you have any other warnings in the project?

Alex J. Best (Jun 09 2022 at 11:42):

Because the exit code of the process will be 1 in the case of warnings, and 0 otherwise, so maybe you can just use that?

Mario Carneiro (Jun 09 2022 at 11:43):

It looks like using trust level 0 will cause an error when you use sorry

Mario Carneiro (Jun 09 2022 at 11:43):

the exit code of lean is 0 in the case of sorry normally

Mario Carneiro (Jun 09 2022 at 11:46):

$ echo "def foo : nat := sorry" > test.lean
$ lean test.lean
/test.lean:1:0: warning: declaration 'foo' uses sorry
$ echo $?
0
$ lean test.lean -t0
/test.lean:1:17: error: failed to expand macro
$ echo $?
1

Alex J. Best (Jun 09 2022 at 11:47):

Hmm it seems there is a difference between lean and lean --make here, in my test the first also resulted in 1 with lean --make

Mario Carneiro (Jun 09 2022 at 11:50):

I'm not reproducing, both lean and lean --make have the same error code behavior

Mario Carneiro (Jun 09 2022 at 11:51):

although lean --make will not report an error if the sorry was in a file that has already been compiled (even if you use -t2 to compile it the first time and -t0 for the second)

Mario Carneiro (Jun 09 2022 at 11:52):

The sorry macro has trust level 2, so if you use -t1 or -t0 then sorry causes errors

Mario Carneiro (Jun 09 2022 at 11:54):

-t1 is probably the most appropriate setting here. -t0 will also expand other macros like strings and expr quote

Mario Carneiro (Jun 09 2022 at 11:55):

(the default setting is the amusingly named LEAN_BELIEVER_TRUST_LEVEL = 1024 but there aren't any other effects for values higher than 2)

Alex J. Best (Jun 09 2022 at 11:56):

My mistake! Sorry for the noise :smile:

Stanislas Polu (Jun 09 2022 at 11:57):

Thanks Mario! Will experiment with trust levels :+1:

Mario Carneiro (Jun 09 2022 at 12:00):

the only one of gabriel's examples from the issue that typechecks at -t0 is

example : false :=
begin
  tactic.add_decl (declaration.ax `very.clever [] `(false)),
  exact very.clever,
end

Mario Carneiro (Jun 09 2022 at 12:03):

however that example fails if it is made into a theorem. If it is a def then it's equivalent to actually adding an axiom very.clever; you have to #print axioms foo to detect this


Last updated: Dec 20 2023 at 11:08 UTC