Zulip Chat Archive

Stream: new members

Topic: fin n


Alex Zhang (May 27 2021 at 13:29):

theorem test_1 (n : ) : ( i in fin n, 1) = n :=
begin
  sorry
end

Why cannot I apply \sigma\ to fin n ?
The above gives me the error message
image.png

Alex Zhang (May 27 2021 at 13:34):

I am confused...

Eric Wieser (May 27 2021 at 13:35):

∑ i : fin n, 1

Eric Wieser (May 27 2021 at 13:35):

which is short for ∑ i in (finset.univ : finset (fin n)), 1 (docs#finset.univ)

Alex Zhang (May 27 2021 at 13:45):

Thank you, Eric!

Johan Commelin (May 27 2021 at 13:54):

@Alex Zhang the difference is whether you sum over a set (i.e. a subset) or over the full type.
In the first case you use i in s, in the second i : X.

Alex Zhang (May 27 2021 at 14:30):

Thanks for all your kind help above!
This formalization using fin n gives me the error message:
image.png

theorem test_1 (n j: nat)(i : fin n) (h: i <(j+1)): 1=1 :=
begin
  sorry
end

Why does this happen and how can I fix this issue?

Anne Baanen (May 27 2021 at 14:34):

This happens when checking i < j + 1 because Lean does the following to check the types:

  • the two sides of < should have the same type
  • let's check i: this is a fin n, so the other side should also be a fin n
  • let's check j + 1: the two sides of + should have the same type, namely fin n
  • j is not a fin n but a , and there's no coercion from to fin n, error!

Anne Baanen (May 27 2021 at 14:35):

The solution is to hint that you actually want to compare the two values as natural numbers:

theorem test_1 (n j: nat)(i : fin n) (h: (i : ) < j + 1) : 1=1 :=
begin
  sorry
end

Anne Baanen (May 27 2021 at 14:37):

  • the two sides of < should have the same type
  • let's check (i : ℕ): this is obviously a , so the other side should also be a
  • let's check that i is a : it's actually a fin n, but I know how to convert from fin n to (docs#fin.fin_to_nat), so apply the coercion
  • let's check j + 1: the two sides of + should have the same type, namely
  • ...

Kevin Buzzard (May 27 2021 at 14:37):

@Alex Zhang remember that i : fin n does not mean "ii is a natural number, and somewhere in the system there is a proof that i<ni<n". It means "i is a pair, consisting of a natural number i.1 and a proof i.2 that i.1 < n". You are confusing i and i.1.

Kevin Buzzard (May 27 2021 at 14:40):

PS I cannot see your screenshots very well at all on my device. Can you just cut and paste errors in between triple quotes like you quote your code? People usually reserve screenshots only for issues which are VS Code specific.

Alex Zhang (May 27 2021 at 14:40):

Anne Baanen said:

The solution is to hint that you actually want to compare the two values as natural numbers:

theorem test_1 (n j: nat)(i : fin n) (h: (i : ) < j + 1) : 1=1 :=
begin
  sorry
end

Cool! I can only fix it by changing the direction of < before..which looks like a silly way.

Kevin Buzzard (May 27 2021 at 14:41):

Yes, because > is illegal :-)

Alex Zhang (May 27 2021 at 14:41):

Kevin Buzzard said:

PS I cannot see your screenshots very well at all on my device. Can you just cut and paste errors in between triple quotes like you quote your code? People usually reserve screenshots only for issues which are VS Code specific.

Got it and no problem!

Kevin Buzzard (May 27 2021 at 14:42):

Either that or I'll have to go and find my glasses :-)


Last updated: Dec 20 2023 at 11:08 UTC