Zulip Chat Archive

Stream: mathlib4

Topic: default proofs


Jireh Loreaux (Nov 18 2022 at 21:08):

I don't understand why the first of these works, but the second fails. An explanation would be most welcome.

class Foo where
  X : 

class Bar extends Foo where
  X := 5
  hX : X = 5 := by rfl  -- works

class Baz extends Foo where
  X := 5
  hX : X = 5 := rfl -- fails

David Renshaw (Nov 18 2022 at 21:39):

I think this is related to https://leanprover.zulipchat.com/#narrow/stream/270676-lean4/topic/when.20are.20struct.20field.20defaults.20evaluated.3F/near/290407486

David Renshaw (Nov 18 2022 at 21:40):

The := by syntax means that the field is evaluated lazily as a tactic. In particular, it's not evaluated until an instance of the class is defined (if I understand correctly).

David Renshaw (Nov 18 2022 at 21:43):

In the second case, my understanding is that the plain := syntax means that the term should be evaluated immediately.

David Renshaw (Nov 18 2022 at 21:47):

Note that your example doesn't work if you do this:

class Bar extends Foo where
  X := 5
  hX : X = 5 := let () := (); by rfl

David Renshaw (Nov 18 2022 at 21:47):

That avoids the special syntax overload for := by and therefore causes the term to be evaluated eagerly.

David Renshaw (Nov 18 2022 at 21:48):

My feeling is that it would be better if we had actually clearly different syntax to distinguish these two different things.

Jireh Loreaux (Nov 18 2022 at 21:48):

Hmmm... okay. This behavior is a bit strange to me. I would have expected that the default proof would use the value from the default field. So I would have expected the eagerly evaluated one to work too.

Jireh Loreaux (Nov 18 2022 at 21:49):

But if this is the behavior, certainly a special syntax other than by would be preferable to highlight the distinction.

Mario Carneiro (Nov 18 2022 at 21:50):

:= by is a special keyword in this context

David Renshaw (Nov 18 2022 at 21:50):

I think you don't have enough information here to prove that X = 5 eagerly.

Mario Carneiro (Nov 18 2022 at 21:50):

I usually use := (by ... if I want to disable it

Mario Carneiro (Nov 18 2022 at 21:50):

yes, by rfl is the right solution in this example

David Renshaw (Nov 18 2022 at 21:50):

Like, it's a default value for X, right? and a different value for X could be supplied by an instance?

Jireh Loreaux (Nov 18 2022 at 21:52):

Sure, I understand that, but I would have expected the eager evaluation to use the default value when compiling the class declaration and then when defining an instance of this class if the default value is overridden then the proof field needs to be supplied.

Mario Carneiro (Nov 18 2022 at 21:53):

this is also the syntax for auto params BTW, def foo (x : 0 < y := by simp) : Nat := 0

Mario Carneiro (Nov 18 2022 at 21:54):

Yes it is something to be aware of but I think it is a reasonable syntax. It makes more sense than lean 3's x : Ty . tac stylistically


Last updated: Dec 20 2023 at 11:08 UTC