Zulip Chat Archive

Stream: general

Topic: failed to synthesize type class instance


Kenny Lau (Jul 25 2020 at 09:12):

class foo : Type.

theorem zero_eq_zero_of_foo [foo] : 0 = 0 := rfl

example : 0 = 0 := by rw zero_eq_zero_of_foo

Kenny Lau (Jul 25 2020 at 09:12):

error:

invalid rewrite tactic, failed to synthesize type class instance
state:
⊢ 0 = 0

Kenny Lau (Jul 25 2020 at 09:12):

is it possible to know which type class instance it failed to synthesize?

Mario Carneiro (Jul 25 2020 at 16:30):

I think it failed to synthesize foo

Mario Carneiro (Jul 25 2020 at 16:32):

more to the point, you can just provide the explicit args to the rewrite, and that should be enough to get typeclass inference to trigger

Mario Carneiro (Jul 25 2020 at 16:33):

I think you can also write something like rw @zero_eq_zero_of_foo _ so that the typeclass inference is done beforehand instead of in the rewrite

Bernd Losert (Dec 05 2021 at 10:56):

This is the error:

error: failed to synthesize type class instance for
α : Type u_1,
β : Type u_2,
f : α  β,
t : convergence_space β,
x : α,
l l' : filter α,
hl : l.ne_bot,
h₀ : l  l',
h₁ : conv (map f l') (f x),
h₂ : map f l  map f l'
 l.ne_bot
state:
α : Type u_1,
β : Type u_2,
f : α  β,
t : convergence_space β,
x : α,
l l' : filter α,
hl : l.ne_bot,
h₀ : l  l',
h₁ : conv (map f l') (f x),
h₂ : map f l  map f l'
 conv (map f l) (f x)

I don't understand this. It seems that it needs an l.ne_bot, but there is one already, namely hl. I am at a loss about what to do here.

Yury G. Kudryashov (Dec 05 2021 at 10:57):

An #mwe would help

Bernd Losert (Dec 05 2021 at 10:58):

I tried making a mwe, but they all work.

Yury G. Kudryashov (Dec 05 2021 at 10:59):

Does lemma assume (hl : l.ne_bot) or [hl : l.ne_bot]? In the former case, you need resetI.

Bernd Losert (Dec 05 2021 at 10:59):

It uses [hl : l.ne_bot].

Bernd Losert (Dec 05 2021 at 11:00):

Here's the lemma:

(le_conv :  {x : α} {l l' : filter α} [ne_bot l], l  l'  conv l' x  conv l x)

Yury G. Kudryashov (Dec 05 2021 at 11:01):

You need resetI or introI

Yury G. Kudryashov (Dec 05 2021 at 11:01):

Why do you need ne_bot here?

Bernd Losert (Dec 05 2021 at 11:01):

In this silly example: the [ne_bot l] works without me doing anything special:

def foo (l : filter α) [ne_bot l] : filter α := l
theorem bar (l : filter α) [ne_bot l] (f : α  β) : filter β :=
begin
  intros,
  have l' : filter β, from foo (map f l),
  exact l'
end

Bernd Losert (Dec 05 2021 at 11:02):

Yury G. Kudryashov said:

Why do you need ne_bot here?

That's part of the lemma.

Yury G. Kudryashov (Dec 05 2021 at 11:02):

What is the statement of the lemma you're trying to prove?

Yury G. Kudryashov (Dec 05 2021 at 11:03):

IMHO conv shouldn't assume ne_bot, and the trivial filter should converge to any point.

Yury G. Kudryashov (Dec 05 2021 at 11:04):

(note that the same sequence can converge to two different points in a non-Hausdorff topological space)

Bernd Losert (Dec 05 2021 at 11:04):

Ah, I just noticed something. In the silly example, if I replace intros with intros l lh f, then it stops working. I'm also doing this in the real proof.

Yury G. Kudryashov (Dec 05 2021 at 11:05):

Why do you need intros in the example?

Bernd Losert (Dec 05 2021 at 11:05):

Is there a special rule regarding intros of variables for instance arguments.

Bernd Losert (Dec 05 2021 at 11:05):

The intros is there to simulate what I'm doing in the real proof.

Yury G. Kudryashov (Dec 05 2021 at 11:06):

Is it actually

theorem bar (l : filter α) [ne_bot l] (f : α  β) : filter β :=

or

theorem bar :  (l : filter α) [ne_bot l] (f : α  β), filter β :=

Bernd Losert (Dec 05 2021 at 11:06):

It's the first one.

Yury G. Kudryashov (Dec 05 2021 at 11:06):

This intros is a no-op.

Bernd Losert (Dec 05 2021 at 11:07):

Ah, OK.

Bernd Losert (Dec 05 2021 at 11:07):

Let me use a forall then.

Yury G. Kudryashov (Dec 05 2021 at 11:08):

Use introI or intros l hl, resetI to introduce instance vars.

Bernd Losert (Dec 05 2021 at 11:08):

Aha. It produces the same error.

Yury G. Kudryashov (Dec 05 2021 at 11:09):

And these lemmas should not need [ne_bot l].

Bernd Losert (Dec 05 2021 at 11:10):

Yury G. Kudryashov said:

Use introI or intros l hl, resetI to introduce instance vars.

It works. Cool. Where is this documented? Is it in "Theorem Provinig in Lean"?

Yury G. Kudryashov (Dec 05 2021 at 11:10):

tactic#resetI

Bernd Losert (Dec 05 2021 at 11:11):

Ah, so it's a mathlib specific tactic? It's not part of core Lean? Interesting.

Bernd Losert (Dec 05 2021 at 11:12):

I need the [ne_bot l] since I need to rule out the bottom filter.

Yury G. Kudryashov (Dec 05 2021 at 11:13):

Why do you need to rule out the bottom filter?

Yury G. Kudryashov (Dec 05 2021 at 11:15):

If conv l x corresponds to l ≤ nhds x, then you should have ∀ x, conv ⊥ x.

Bernd Losert (Dec 05 2021 at 11:17):

I'm working in the more general setting of convergence spaces, so there are no neighborhoods. But yeah, I want to rule out ∀ x, conv ⊥ x because that will always be the case according to the convergence space axioms without the [ne_bot l] constraint.

Yury G. Kudryashov (Dec 05 2021 at 11:18):

Why do you want to rule out this?

Yury G. Kudryashov (Dec 05 2021 at 11:18):

A topological space should define a convergence space, and in a topological space this is true.

Bernd Losert (Dec 05 2021 at 11:21):

Is it? I may be misunderstanding something. If the space is Hausdorff, then every filter has at most one limit. This won't work if the bottom filter converges to everything. Unless... Hausdorff means that every ne_bot filter has at most one limit.

Yury G. Kudryashov (Dec 05 2021 at 11:21):

If the space is Hausdorff, then every nontrivial filter has at most one limit.

Yury G. Kudryashov (Dec 05 2021 at 11:23):

docs#tendsto_nhds_unique

Bernd Losert (Dec 05 2021 at 11:23):

OK. That's the part that was missing in my mind. It's a bit confusing since Lean allows the bottom filter to be a filter, but in the literature this is ruled out.

Yury G. Kudryashov (Dec 05 2021 at 11:23):

It is very convenient to have a docs#complete_lattice structure on filters.

Yury G. Kudryashov (Dec 05 2021 at 11:24):

But you have to adjust statements/proofs from textbooks.

Bernd Losert (Dec 05 2021 at 11:25):

Yeah. I'm having some problem adjusting things as you can tell.

Bernd Losert (Dec 05 2021 at 11:25):

Thanks for your help. Much appreciated.

Reid Barton (Dec 05 2021 at 15:01):

I think using the class ne_bot is not helping here. You can also just write (hl : l ≠ ⊥) and it should make life simpler and easier.


Last updated: Dec 20 2023 at 11:08 UTC