Zulip Chat Archive

Stream: lean4

Topic: Mutual inductive universe


Henrik Böving (Mar 04 2023 at 15:59):

mutual

inductive A : Type where
| a (arg : B)

inductive B : Type where
| b (arg : ST.Ref Unit A)

end

This gives me:

(kernel) mutually inductive types must live in the same universe

but..these types to live in the same universe right? After all the elaborator did not complain about the : Type annotation and if I was to split up the mutual by setting A = Nat in B and B = Nat in A respectively they do end up living in the proper universes.

Is this a bug?

Kevin Buzzard (Mar 04 2023 at 16:29):

This works though:

structure stref (α β : Type) : Type

mutual

inductive A : Type where
| a (arg : B)

inductive B : Type where
| b (arg : stref Unit A)

end

Henrik Böving (Mar 04 2023 at 16:31):

Ah I think I'm onto something:

fails

opaque RefPointed : NonemptyType.{0}

structure Ref (σ : Type) (α : Type) : Type where
  ref : RefPointed.type
  h   : Nonempty α

mutual


inductive A : Type where
| a (arg : B)

inductive B : Type where
| b (arg : Ref Unit A)

end

works

opaque RefPointed : NonemptyType.{0}

structure Ref (σ : Type) (α : Type) : Type where
  ref : RefPointed.type
  -- POOF! h   : Nonempty α

mutual


inductive A : Type where
| a (arg : B)

inductive B : Type where
| b (arg : Ref Unit A)

end

Henrik Böving (Mar 04 2023 at 16:38):

Alternatively further minimized of course:

structure Ref1 (σ : Type) (α : Type) : Type where
  --h   : Nonempty α

structure Ref2 (σ : Type) (α : Type) : Type where
  h   : Nonempty α

mutual


inductive A : Type where
| a (arg : B)

inductive B : Type where
| b (arg : Ref2 Unit A)

end

Reid Barton (Mar 04 2023 at 17:16):

This doesn't seem too surprising, after all if you put a random thing instead of Ref2 then it would be unsound, so there will also be cases where it would be fine but Lean still rejects it

Henrik Böving (Mar 04 2023 at 17:18):

Can you elaborate? I don't understand what is wrong

Reid Barton (Mar 04 2023 at 17:19):

For example if Ref2 Unit A unfolds to A -> False, that would be Bad

Henrik Böving (Mar 04 2023 at 17:21):

Right but that would be a non positive occurence and not a universe error would it?

Reid Barton (Mar 04 2023 at 17:21):

Even here it is not very obvious to me what induction principle Lean is supposed to generate for these types

Reid Barton (Mar 04 2023 at 17:21):

oh well, I don't really trust Lean to produce the correct error message

Reid Barton (Mar 04 2023 at 17:22):

Maybe it is connected to the Prop-truncation of Nonempty though?

Reid Barton (Mar 04 2023 at 17:24):

Already this fails

mutual

inductive A : Type where
| a (arg : B)

inductive B : Type where
| b (arg : Nonempty A)

end

Reid Barton (Mar 04 2023 at 17:27):

or even

inductive A : Type where
| a (arg : Nonempty A)

Reid Barton (Mar 04 2023 at 17:29):

I am not saying that it should be allowed or shouldn't be allowed, just that I am not surprised that it is currently not allowed.

Sebastian Ullrich (Mar 04 2023 at 17:35):

Yes, Nonempty is inlined, which makes this a mixed-Type/Prop mutual inductive

Henrik Böving (Mar 04 2023 at 17:41):

:( So I cannot have mutual inductives with mutable references for now?

Reid Barton (Mar 04 2023 at 17:48):

If you could have one then you could build a cyclic reference right? I was under the impression that was intended to be impossible

Mario Carneiro (Mar 04 2023 at 22:18):

you can do it with an unsafe inductive


Last updated: Dec 20 2023 at 11:08 UTC