Zulip Chat Archive

Stream: mathlib4

Topic: weird interaction between `mod_cases` and `induction`


David Renshaw (Jan 25 2023 at 23:21):

This looks to me like an elaboration bug in the mod_cases tactic.

import Mathlib.Tactic.ModCases

theorem foo (n : ) (z : ) : n = n := by
  induction n with
  | zero => rfl
  | succ n ih =>
     mod_cases z % 3
     · sorry
     · sorry
     · sorry

/-
type mismatch
  sorryAx ?m.55
has type
  ?m.55 : Sort ?u.54
but is expected to have type
   Nat.succ _uniq.37 = Nat.succ _uniq.37 : Prop
-/

Heather Macbeth (Jan 26 2023 at 04:30):

@David Renshaw Thanks for discovering this! :upside_down: I'd like to record it, could you open an issue for it?

David Renshaw (Jan 26 2023 at 13:19):

https://github.com/leanprover-community/mathlib4/issues/1851

David Renshaw (Jan 26 2023 at 19:15):

Adding a withMainContext fixes this. PR incoming.

David Renshaw (Jan 26 2023 at 19:23):

https://github.com/leanprover-community/mathlib4/pull/1865

David Renshaw (Jan 26 2023 at 19:43):

It's somewhat surprising to me that the main goal and the local context are independent pieces of implicit state.

David Renshaw (Jan 26 2023 at 19:44):

I think I had kind of assumed that if the main goal is set to something, then the local context must be set to match it.

Jannis Limperg (Jan 26 2023 at 21:43):

Nope. The whole withContext situation is by far the biggest footgun in the API.

Mario Carneiro (Jan 26 2023 at 21:51):

David Renshaw said:

I think I had kind of assumed that if the main goal is set to something, then the local context must be set to match it.

This wouldn't really work, since "the main goal" is not really a piece of state, the list of goals is the state and these can be "accidentally" solved by doing other things

Mario Carneiro (Jan 26 2023 at 21:51):

getMainGoal calculates the first unassigned metavariable on the spot

David Renshaw (Jan 26 2023 at 21:52):

yeah, having mvarId.assign possibly change the local context seems like it would maybe be bad

Mario Carneiro (Jan 26 2023 at 21:53):

One way to make it slightly less footgunny would be to have TacticM not extend MetaM at all but require you to "enter" a particular metavariable's context to run things


Last updated: Dec 20 2023 at 11:08 UTC