Zulip Chat Archive

Stream: mathlib4

Topic: unexpected variables


Jireh Loreaux (Dec 16 2022 at 21:05):

I'm currently about 1/3 of the way through porting Data.Fin.Basic and I ran into an interesting problem. I tried to minimize it, but I can maybe take it further if need be. The problem is that some variables were declared at the beginning of the file, and in one declaration they were not used, but Lean still assumed that they were, so they were included in the type signature. In Lean 3 if this sort of problem came up we could use omit, but that's not an option anymore. (EDIT: ignore the mwe and look at the message with foo below)

mwe

Jireh Loreaux (Dec 16 2022 at 21:06):

I think the reason this might be happening is that the proof does cases n and a b : Fin n, so these are affected by the cases, which makes Lean think these variables were used.

Jireh Loreaux (Dec 16 2022 at 21:10):

Confirmed.

variable {n : Nat}
variable {a : Fin n}

theorem foo (c : Fin n) : c = c := by
  cases n
  · rfl
  · rfl

#check @foo
-- @foo : ∀ {n : Nat} {a : Fin n} (c : Fin n), c = c

theorem bar (c : Fin n) : c = c := rfl

#check @bar
-- @bar : ∀ {n : Nat} (c : Fin n), c = c

Jireh Loreaux (Dec 16 2022 at 21:15):

One short-term workaround is to do clear a before cases, but that seems really gross. This feels like a bug to me, but I'll wait for someone with more knowledge to weigh in.

Kevin Buzzard (Dec 16 2022 at 21:18):

Oh that's interesting! I've seen tactic states which are randomly full of variables you're not using, but I had the impression that the actual signature of the declaration didn't mention them. But here clearly a should not be involved, and yet is.

Jireh Loreaux (Dec 16 2022 at 21:22):

Right, I think what happens is that it looks through the proof to see if you used them and if you didn't, then it omits them, but if you did then they are included. In this case, I think it's getting confused because when you do cases n then you get (in the first case) a : Fin Nat.zero in the tactic state. I assume then that the term being produced includes this modification to a somehow, even though it wasn't necessary, and then Lean includes it in the type signature.

Kevin Buzzard (Dec 16 2022 at 21:39):

For me this is a Lean 4 bug. I don't recall it happening in Lean 3.

Jireh Loreaux (Dec 16 2022 at 21:40):

Yeah, i've considered posting it in #lean4, but I wasn't sure.

Kevin Buzzard (Dec 16 2022 at 21:44):

Yeah you've minimised it, go for it!

Jireh Loreaux (Dec 16 2022 at 21:46):

crossposted: https://leanprover.zulipchat.com/#narrow/stream/270676-lean4/topic/bug.20in.20included.20variables


Last updated: Dec 20 2023 at 11:08 UTC