Zulip Chat Archive

Stream: mathlib4

Topic: Instance inference error


Gareth Ma (Oct 18 2023 at 20:04):

Error. Why? Bug? Should file?

import Mathlib.Tactic

theorem thm1 {ι : Type*} [SeminormedAddCommGroup ι] : 1 = 0 := sorry

/-
▶ 5:86-5:90: error:
typeclass instance problem is stuck, it is often due to metavariables
  SeminormedAddCommGroup ?m.131
-/
example {ι : Type*} [h : SeminormedAddCommGroup ι] (f :   ι) : f 1 = f 0 := by rw [thm1]

/- Works -/
example {ι : Type*} [h : SeminormedAddCommGroup ι] (f :   ι) : f 1 = f 0 := by rw [@thm1 _ h]

Alex J. Best (Oct 18 2023 at 20:05):

How is Lean supposed to know which iota you want to apply thm1 with by itself?

Gareth Ma (Oct 18 2023 at 20:06):

What do you mean, there's one iota right

Alex J. Best (Oct 18 2023 at 20:07):

Well you named them both iota but that doesn't mean Lean will automatically use iota for the argument iota when the theorem is applied (indeed that would be kind of annoying)

Rémy Degenne (Oct 18 2023 at 20:08):

Your code is the same as this, with different letters for the types:

import Mathlib.Tactic

theorem thm1 {A : Type*} [SeminormedAddCommGroup A] : 1 = 0 := sorry

/-
▶ 5:86-5:90: error:
typeclass instance problem is stuck, it is often due to metavariables
  SeminormedAddCommGroup ?m.131
-/
example {B : Type*} [h : SeminormedAddCommGroup B] (f :   B) : f 1 = f 0 := by rw [thm1]

/- Works -/
example {C : Type*} [h : SeminormedAddCommGroup C] (f :   C) : f 1 = f 0 := by rw [@thm1 _ h]

Gareth Ma (Oct 18 2023 at 20:08):

Ahhh hmm that makes sense, thanks!

Gareth Ma (Oct 18 2023 at 20:08):

In hindsight it sounds stupid haha

Alex J. Best (Oct 18 2023 at 20:20):

You are not the first person to ask this, dont worry!


Last updated: Dec 20 2023 at 11:08 UTC