Zulip Chat Archive

Stream: general

Topic: data out of emptiness


Sebastien Gouezel (Sep 06 2021 at 14:28):

Look at the following (on current mathlib):

import linear_algebra.determinant

def linear_equiv.of_det_ne_zero
  {๐•œ : Type*} [field ๐•œ] {M : Type*} [add_comm_group M] [module ๐•œ M]
  [finite_dimensional ๐•œ M] {f : M โ†’โ‚—[๐•œ] M} (hf : linear_map.det f โ‰  0) :
  M โ‰ƒโ‚—[๐•œ] M :=
begin
  rw โ† linear_map.det_to_matrix (finite_dimensional.fin_basis ๐•œ M) at hf,
  -- goals accomplished
end

Lean says that there is no goal left, after an innocent rewrite. Printing the def, it turns out that it uses linear_equiv.refl ๐•œ M as the definition. My guess is that rw tries refl after a rewrite, and indeed here refl works, but it is not the usual one :-) I am sure I can work this around, but I wanted to share this with you as the unexpected proof of the day.

Yakov Pechersky (Sep 06 2021 at 14:38):

Are the refl, symm, and trans tags for (linear_)equivs solely to make calc mode for data work properly?

Kevin Buzzard (Sep 06 2021 at 14:59):

Of course refl also works to close the goal, so this proof is not so surpsiring. Note that in contrast to the term rfl, the tactic refl will close any goal of the form R X X with R a reflexive relation such that theorem saying R X X is tagged with @[refl] (and #print linear_equiv.refl shows that it is).

Kevin Buzzard (Sep 06 2021 at 14:59):

I think that the symmetry tactic looks for @[symm] tags.

Eric Wieser (Sep 06 2021 at 19:40):

I don't think rw ... at has any right to touch the main goal, so IMO this is a bug

Kyle Miller (Sep 06 2021 at 19:48):

rw does a weak version of refl at the end. It does tactic.reflexivity reducible, where refl does tactic.reflexivity semireducible. I gather that this means rw's version of refl will only unfold definitions marked reducible, for example abbreviations.

Eric Wieser (Sep 06 2021 at 19:52):

I don't think it should do that for rw ... at h, only for rw ... or rw ... at โŠข. I can't think of any situation in which doing it for the former would be anything but surprising and unhelpful

Kyle Miller (Sep 06 2021 at 20:00):

I just mean to confirm Sebastien's guess (though with the caveat that it's not quite refl).

If you wanted to make it only do this when it's rewriting the goal, this might be a replacement for rw_core (though I didn't test it)

private meta def rw_core (rs : parse rw_rules) (loca : parse location) (cfg : rewrite_cfg) : tactic unit :=
match loca with
| loc.wildcard := loca.try_apply (rw_hyp cfg rs.rules) (rw_goal cfg rs.rules >> try (reflexivity reducible))
| _            := loca.apply (rw_hyp cfg rs.rules) (rw_goal cfg rs.rules >> try (reflexivity reducible))
end >> (returnopt rs.end_pos >>= save_info <|> skip)

Eric Rodriguez (Sep 06 2021 at 20:16):

I think it'd be nice if we could give it a separate argument for reducibility - I find often that I want to do rw! where it does rw and then a stronger refl. Would everyone be fine with both of these in core lean?

Mario Carneiro (Sep 06 2021 at 21:59):

I prefer using rw; refl for this

Martin Dvoล™รกk (Sep 07 2021 at 14:46):

Is the conclusion that @Kyle Miller was indeed right โ€” that rw does a weak version of refl even when it is called asrw ... at h? Or is it something else that closed the goal?

Martin Dvoล™รกk (Sep 07 2021 at 15:59):

That was a question. I am really confused now.

Kevin Buzzard (Sep 07 2021 at 16:00):

You can experiment for yourself:

import tactic

example (a b : โ„•) (h : a + b = 37) : 2 = 2 :=
begin
  rw add_comm at h,
end

Floris van Doorn (Sep 07 2021 at 16:07):

That is correct, Martin. rw ... at h does try a weak version of refl.

Martin Dvoล™รกk (Sep 07 2021 at 16:08):

Thank you!

Eric Wieser (Sep 07 2021 at 16:29):

If you have a multiple choice question I recommend separate messages to avoid reactions being confusing!


Last updated: Dec 20 2023 at 11:08 UTC