Zulip Chat Archive

Stream: general

Topic: deep recursion


Johan Commelin (Mar 12 2019 at 13:11):

How can I debug the following error?

deep recursion was detected at 'replace' (potential solution: increase stack space in your system)

It showed up while trying to define a class. As far as I can see there is no loop or something...

Kenny Lau (Mar 12 2019 at 13:15):

have you tried turning Lean off and on again?

Johan Commelin (Mar 12 2019 at 13:15):

Yes, in fact I have.

Johan Commelin (Mar 12 2019 at 14:07):

I've found the culprit:

-- somewhere in the perfectoid project
local attribute [instance] topological_add_group.to_uniform_space

Johan Commelin (Mar 12 2019 at 14:18):

I've now put a section ... end around this attribute (and its one use) and the problem is gone.
So... this question is solved. Thanks for letting me rubber-duck this issue!

Yaël Dillies (Nov 26 2021 at 21:02):

I'm hitting this error in #7123. MWE

import data.fintype.basic

open_locale classical

/-- A finite bounded lattice is complete. -/
noncomputable instance fintype.to_complete_lattice (α : Type*) [fintype α] [hl : lattice α]
  [hb : bounded_order α] :
  complete_lattice α :=
{ Sup := λ s, s.to_finset.sup id,
  Inf := λ s, s.to_finset.inf id,
  le_Sup := sorry,
  Sup_le := sorry,
  Inf_le := sorry,
  le_Inf := sorry,
  .. hl, .. hb }

variables {α : Type*} [bounded_order α]
-- deep recursion was detected at 'expression equality test' (potential solution: increase stack
-- space in your system)

and I don't know how to circumvent it.

Yaël Dillies (Nov 26 2021 at 21:06):

Precisely, it happens because [bounded_order α] looks for [has_le α], which it tries to get from [complete_lattice α], which it tries to get using fintype.to_complete_lattice, which needs [bounded_order α]... This instance is bad, and I know it, but in this PR I need it to prove 2 lemmas about it (and then it's used once on fin).

Yakov Pechersky (Nov 26 2021 at 21:07):

does lowering priority help?

Yaël Dillies (Nov 26 2021 at 21:07):

Should I simply give up on stating those lemmas generally and simply provide them for fin?

Yaël Dillies (Nov 26 2021 at 21:08):

Nope...

Yaël Dillies (Nov 26 2021 at 21:09):

Btw Yakov this is an unforeseen consequence of your refactor :sad:

Yakov Pechersky (Nov 26 2021 at 21:09):

Yeah I can see that

Yakov Pechersky (Nov 26 2021 at 21:09):

I'll have to take a look in a couple of days

Yaël Dillies (Nov 26 2021 at 21:14):

One solution is

variables {α : Type*} [ : lattice α] [@bounded_order α $ @preorder.to_has_le α $ @partial_order.to_preorder α $ semilattice_inf.to_partial_order α]

:nauseated:

Eric Wieser (Nov 26 2021 at 22:10):

If this instance is bad, why not make it a def?

Yaël Dillies (Nov 26 2021 at 22:12):

In the PR, it is a def. The point was to make it an instance for one section to prove general lemmas about when it's used, but TC inference already pukes at the variables.

Eric Wieser (Nov 26 2021 at 22:13):

I think it would be better to use by haveI := ...; exact ... in the theorem statement

Eric Wieser (Nov 26 2021 at 22:14):

(which elaborates without any let bindings)

Yaël Dillies (Nov 27 2021 at 09:35):

So I solved it by simply swapping the variables and local attribute.

variables {ι α : Type*} [fintype ι] [fintype α] [lattice α] [bounded_order α]

-- this line is crucially *after* the `variables` so that `bounded_order` gets filled in correctly
local attribute [instance] fintype.to_complete_lattice

Apparently Lean fills in the arguments in stuff declared in variables at declaration time rather than at each lemma?

Floris van Doorn (Nov 27 2021 at 11:12):

This is correct. For example, see the difference here:

variables {α : Type*}
example : α =  := sorry -- error
example {β : Type*} : β =  := sorry -- no error

The first example fails, because α : Type u_1, and the universe variable u_1 cannot be unified with 0. The second example works, because the universe metavariable in the type of β can be unified with 0 (of course, the Type* is super misleading, since it's just Type).

Yakov Pechersky (Nov 27 2021 at 22:14):

Ah, I see, you wanted to have bounded_order without specifying the order (has_le) or anything else. Yeah, that won't work.

Yakov Pechersky (Nov 27 2021 at 22:39):

Do you get the the same style of error if you invoke a new type alpha and [topological_group alpha] without saying [group alpha]?


Last updated: Dec 20 2023 at 11:08 UTC