Zulip Chat Archive

Stream: Is there code for X?

Topic: type class in "forall/exists"


Winston Yin (Jun 09 2021 at 15:01):

Why is Lean unable to infer add_comm_monoid M for module R M in the following:

def test
  (R : Type _) [semiring R] : Prop :=
 (M : Type _) [add_comm_monoid M] [module R M], true

Winston Yin (Jun 09 2021 at 15:02):

In the same vein, how can I say "there exists some type M with a module structure over R such that..."?

Winston Yin (Jun 09 2021 at 15:04):

Oops might've been the wrong stream. My apologies

Riccardo Brasca (Jun 09 2021 at 15:04):

Class inference is used to have [monoid M] when you already have [group M], or similarly. What you are saying looks a little weird mathematically. What are trying to do?

Johan Commelin (Jun 09 2021 at 15:05):

Is your question: every module is an additive monoid, why can't Lean figure this out?

Riccardo Brasca (Jun 09 2021 at 15:06):

If you want to prove your proposition (why it is a def?), you can say use R. Then the goals are solved by apply_instance.

Johan Commelin (Jun 09 2021 at 15:06):

The problem is, some things are modules over several rings. But they should be an additive monoid in a unique way, otherwise Lean gets confused.

Johan Commelin (Jun 09 2021 at 15:07):

So that's why we write [add_comm_monoid M] [module R M] (and [module R M] doesn't work if Lean can't find add_comm_monoid M)

Winston Yin (Jun 09 2021 at 15:08):

I'll clarify my confusion

Winston Yin (Jun 09 2021 at 15:09):

This works:

def test2
  (R : Type _) [semiring R] (M : Type _) [add_comm_monoid M] [module R M] : Prop := true

(Suppose I'm just trying to define some predicate on R and M)

Winston Yin (Jun 09 2021 at 15:09):

Lean is able to infer add_comm_monoid M before it infers module R M

Winston Yin (Jun 09 2021 at 15:10):

But in the test above, when (M : Type _) [add_comm_monoid M] [module R M] are in the body of the definition behind an exists, Lean is no longer inferring add_comm_monoid M for the purpose of module R M

Oliver Nash (Jun 09 2021 at 15:11):

What are you trying to say mathematically?

Johan Commelin (Jun 09 2021 at 15:11):

@Winston Yin ok, I see. Write by exactI before [module R M]

Johan Commelin (Jun 09 2021 at 15:12):

The problem is that Lean at certain points freezes the type class instance cache for performance reasons.

Johan Commelin (Jun 09 2021 at 15:13):

And [add_comm_monoid M] is not in the cache when [module R M] needs it.

Johan Commelin (Jun 09 2021 at 15:13):

I think the cache gets frozen after the :. So with existential statements, you need to reset the cache manually. You can do this using by exactI.

Winston Yin (Jun 09 2021 at 15:13):

What I'm actually trying to do: define the notion of the decomposability of a group representation, so that if a vector space V is a representation (of a group, over a field, etc), it is decomposable if there exist V1 and V2 with V = V1 \oplus V2

Johan Commelin (Jun 09 2021 at 15:14):

def test
  (R : Type _) [semiring R] : Prop :=
 (M : Type _) [add_comm_monoid M], by exactI [module R M]

should work

Johan Commelin (Jun 09 2021 at 15:14):

Winston Yin said:

What I'm actually trying to do: define the notion of the decomposability of a group representation, so that if a vector space V is a representation (of a group, over a field, etc), it is decomposable if there exist V1 and V2 with V = V1 \oplus V2

I would use V1 V2 : subrepresentation V for that, I think.

Winston Yin (Jun 09 2021 at 15:14):

Let me try exactI

Johan Commelin (Jun 09 2021 at 15:15):

For the definition I would use subreps. But then add a lemma that if V = V1 \oplus V2 for random nontrivial reps V1 and V2, then of course V is decomposable.

Johan Commelin (Jun 09 2021 at 15:16):

Using subreps in the definition saves you all the trouble of \exists (a type) [that is a monoid], by exactI [and a module]

Winston Yin (Jun 09 2021 at 15:16):

Sorry, I wrote true earlier to simplify things. But I meant to write some Prop that depends on M itself

Johan Commelin (Jun 09 2021 at 15:16):

So write by exactI \exist [module R M], blabla

Winston Yin (Jun 09 2021 at 15:17):

I'll try to rephrase in terms of subreps

Notification Bot (Jun 10 2021 at 08:46):

This topic was moved by Scott Morrison to #general > type class in "forall/exists"


Last updated: Dec 20 2023 at 11:08 UTC