Zulip Chat Archive

Stream: general

Topic: Newbie error


Johan Commelin (May 08 2018 at 08:04):

I've got the following code

import algebra.ring data.finsupp

variables {R : Type*} [ring R]

section free_module
definition free_module (S : Type*) := finsupp S R
variables {S : Type*}

instance : module R (free_module S) := sorry

end free_module

Johan Commelin (May 08 2018 at 08:05):

And this is the error

don't know how to synthesize placeholder
context:
R : Type u_1,
_inst_1 : ring R,
S : Type u_2
⊢ Type ?

Johan Commelin (May 08 2018 at 08:05):

Aah, I should point out that the red squiggles are under free_module in the line with sorry

Mario Carneiro (May 08 2018 at 08:06):

Shouldn't R be explicit in free_module? It is not inferrable

Johan Commelin (May 08 2018 at 08:06):

I think the error means that it can't figure out in which universe free_module S lives

Johan Commelin (May 08 2018 at 08:06):

Aah, Ok, is that the problem. I thought it was automatically included, since I declared it a variable

Johan Commelin (May 08 2018 at 08:06):

Or should I then use () instead of {}

Kenny Lau (May 08 2018 at 08:07):

it isn't a parameter

Mario Carneiro (May 08 2018 at 08:07):

it is included, but the later use might refer to a different R

Johan Commelin (May 08 2018 at 08:09):

Ok... well, that fixed my problem. Thanks a lot!

Kenny Lau (May 08 2018 at 08:09):

no, don't use parameter

Kenny Lau (May 08 2018 at 08:09):

you won't be able to use it once you leave the section

Johan Commelin (May 08 2018 at 08:10):

Hmm, what do you mean?

Johan Commelin (May 08 2018 at 08:10):

I now have

import algebra.ring data.finsupp

variables {R : Type*} [ring R]

section free_module
definition free_module (R : Type*) [ring R] (S : Type*) := finsupp S R
variables {S : Type*}

instance : module R (free_module R S) :=
begin
split, -- tactic fails
end

end free_module

Johan Commelin (May 08 2018 at 08:11):

Is that wrong?

Kenny Lau (May 08 2018 at 08:11):

never mind

Kenny Lau (May 08 2018 at 08:11):

that isn't wrong

Johan Commelin (May 08 2018 at 08:11):

Ok, I don't mind learning a better way (-;

Johan Commelin (May 08 2018 at 08:12):

So, why is split failing? I expected to get 4 goals, according to the 4 axioms of a module

Kenny Lau (May 08 2018 at 08:12):

constructor

Kenny Lau (May 08 2018 at 08:12):

but you don't want to use it since it extends something

Kenny Lau (May 08 2018 at 08:12):

maybe if you really want to stay in tactic mode, do refine {..}

Johan Commelin (May 08 2018 at 08:18):

Well, I don't want to stay in tactic mode. It is just that I have no clue how to do things in term mode. And tactic mode helps me a bit (-;

Johan Commelin (May 08 2018 at 08:27):

So what would be the proper way to prove this instance?

Kenny Lau (May 08 2018 at 08:27):

instance : module R (free_module R S) :=
{ smul := _,
  smul_add := _ }

etc

Johan Commelin (May 08 2018 at 08:29):

Ok, thanks! I'll try to do that.

Johan Commelin (May 08 2018 at 08:46):

Lol, this is already in finsupp: to_module

Kenny Lau (May 08 2018 at 08:46):

lol

Johan Commelin (May 08 2018 at 09:25):

The errors continue:

import algebra.ring data.finsupp

variables {R : Type*} [decidable_eq R] [ring R]

section free_module
definition free_module (R : Type*) [ring R] (S : Type*) := finsupp S R
variables {S : Type*} [decidable_eq S]

instance : add_comm_monoid (free_module R S) := finsupp.add_comm_monoid
instance : module R (free_module R S) := finsupp.to_module
end free_module

section generators
variables {M : Type*} [module R M]

definition natural_map (S : set M) : free_module R S  M :=
λ x, x.sum (λ s r, r  s)

definition generated_submodule (S : set M) := set.range (natural_map S) -- fails

definition is_finitely_generated (M : Type*) [module R M] : Prop :=
 S : finset M, generated_submodule {x | x  S} = set.univ M -- fails

end generators

Johan Commelin (May 08 2018 at 09:26):

Errors:

generators.lean:19:57: error

failed to synthesize type class instance for
M : Type u_2,
S : set M
⊢ module ?m_1 M
generators.lean:19:57: error

don't know how to synthesize placeholder
context:
M : Type u_2,
S : set M
⊢ Type ?

Johan Commelin (May 08 2018 at 09:26):

But I am telling it that M is a module over R, so why can't it unify ?m_1 with R?

Kevin Buzzard (May 08 2018 at 10:36):

You started a new section so Lean has forgotten about the variable R

Kevin Buzzard (May 08 2018 at 10:37):

wait

Kevin Buzzard (May 08 2018 at 10:37):

that doesn't seem to be true

Kevin Buzzard (May 08 2018 at 10:39):

It seems to be because you don't ever mention R so the type class inference doesn't kick in

Kevin Buzzard (May 08 2018 at 10:41):

definition generated_submodule (S : set M) [module R M] := set.range (natural_map S) -- works

Kevin Buzzard (May 08 2018 at 10:41):

Type class inference is a strange thing

Kenny Lau (May 08 2018 at 10:41):

include R

Kevin Buzzard (May 08 2018 at 10:41):

I would still not say I had completely got the hang of it

Kevin Buzzard (May 08 2018 at 10:42):

include R
definition generated_submodule (S : set M) := set.range (natural_map S) -- works

Kevin Buzzard (May 08 2018 at 10:42):

Kenny's fix

Kevin Buzzard (May 08 2018 at 10:42):

What does include do?

Kevin Buzzard (May 08 2018 at 10:42):

I thought this was for including variable names in tactic proofs

Kevin Buzzard (May 08 2018 at 10:43):

As for the equality failing

Kevin Buzzard (May 08 2018 at 10:43):

set.univ : Π {α : Type u}, set α

Kevin Buzzard (May 08 2018 at 10:43):

set.univ doesn't take M, it guesses it.

Kevin Buzzard (May 08 2018 at 10:44):

definition is_finitely_generated (M : Type*) [module R M] : Prop :=
 S : finset M, generated_submodule {x | x  S} = set.univ -- works

Kevin Buzzard (May 08 2018 at 10:44):

Recently I realised that I pretty fully understood most Lean errors

Kevin Buzzard (May 08 2018 at 10:44):

i.e. I can look at the error and actually figure out what is wrong with my code, in many cases

Kevin Buzzard (May 08 2018 at 10:45):

type mismatch at application
  generated_submodule {x : M | x ∈ S} = set.univ M
term
  set.univ M
has type
  Prop : Type
but is expected to have type
  set M : Type ?

Kevin Buzzard (May 08 2018 at 10:45):

says "the right hand side is supposed to have type set M but it has type Prop so you have not written what you meant to write -- it doesn't typecheck."

Kevin Buzzard (May 08 2018 at 10:46):

You are attempting to assert that two sets are equal

Kevin Buzzard (May 08 2018 at 10:46):

so the correct type is set M

Kevin Buzzard (May 08 2018 at 10:46):

so the problem is that set.univ M has type Prop instead of type set M

Kevin Buzzard (May 08 2018 at 10:47):

and now you look at what set.univ actually does by hovering your mouse over set.univ

Kevin Buzzard (May 08 2018 at 10:47):

and you see your error

Kevin Buzzard (May 08 2018 at 10:48):

I would urge you @Johan Commelin to learn to read errors so you can find out the problem.

Kevin Buzzard (May 08 2018 at 10:49):

Sometimes the problem is that type class inference has failed. Type class inference is just something you have to get the hang of and I had to ask and ask here about it -- see my typeclass inference woes thread

Kevin Buzzard (May 08 2018 at 10:49):

But for other errors, try and make it so that there is exactly one error (i.e put sorry everywhere else) and then try and read the error.

Kevin Buzzard (May 08 2018 at 10:50):

And then hope that you can fix it

Johan Commelin (May 08 2018 at 11:09):

Ok, thanks! I hope to get the hang of it as well...

Chris Hughes (May 08 2018 at 14:24):

set.univ : set M should help

Chris Hughes (May 08 2018 at 14:28):

Or perhaps @set.univ M


Last updated: Dec 20 2023 at 11:08 UTC