Zulip Chat Archive

Stream: new members

Topic: Convert `fin n` to `fin (n+1)`


Tage Johansson (Nov 02 2022 at 06:20):

Hello,

Is there an easy way to convert a number of type fin n to fin (n+1). I tried library_search and got fin.succ but this obviously increases the number by one which is not what I want. I just want to cast/coerse/lift the number to a larger fin type.

I'd prefer a solution that looks very short and doesn't confuse the reader of the code. Something like ↑n or n.xxx.

Thanks,
Tage

Andrew Yang (Nov 02 2022 at 06:26):

docs#fin.cast_le should do.

Damiano Testa (Nov 02 2022 at 06:31):

In fact, both of the following work:

example (n : ) (a : fin n) : fin (n+1) :=
fin.cast_le n.le_succ a

example (n : ) (a : fin n) : fin (n+1) :=
fin.of_nat a

Andrew Yang (Nov 02 2022 at 06:33):

I'd advise for the former. The latter is actually a % succ n, which could cause problems later on.

Reid Barton (Nov 02 2022 at 06:43):

docs#fin.cast_succ


Last updated: Dec 20 2023 at 11:08 UTC