Zulip Chat Archive
Stream: general
Topic: type mismatch for fin n
Kevin Buzzard (Mar 11 2018 at 19:38):
I am surprised that this doesn't typecheck:
Kevin Buzzard (Mar 11 2018 at 19:38):
def subtypeadd {m : ℕ} {n : ℕ} (A : fin m) (B : fin n) : fin (m+n) := ⟨A.val+B.val,add_lt_add A.is_lt B.is_lt⟩ example (A : fin 3) (B : fin 4) (C : fin 7) : A = ⟨2,dec_trivial⟩ → B = ⟨0,dec_trivial⟩ → C = subtypeadd A B → C = ⟨2,dec_trivial⟩ := sorry
Kevin Buzzard (Mar 11 2018 at 19:39):
It complains at subtypeadd
that A
has type fin 3
and it expects it to have type fin 6
??
Mario Carneiro (Mar 11 2018 at 19:42):
I think this is the default elaboration strategy's fault
Kevin Buzzard (Mar 11 2018 at 19:42):
It's hard for me to see what's going on because it doesn't typecheck so I don't have any term to work with
Kevin Buzzard (Mar 11 2018 at 19:43):
Obviously I can fix it with @
Kevin Buzzard (Mar 11 2018 at 19:43):
but here -- hey -- can you be the elaborator like you sometimes do?
Mario Carneiro (Mar 11 2018 at 19:43):
You can make it typecheck by writing @subtypeadd _ _ A B
or adding @[elab_simple]
to the definition of subtypeadd
Kevin Buzzard (Mar 11 2018 at 19:43):
You have to figure out what m and n are
Kevin Buzzard (Mar 11 2018 at 19:43):
and the only clues you have are that A : fin m and A : fin 3
Kevin Buzzard (Mar 11 2018 at 19:44):
what do you think
Kevin Buzzard (Mar 11 2018 at 19:44):
mr elaborator
Mario Carneiro (Mar 11 2018 at 19:45):
It sees that the goal is fin 7
and so has to solve 7 =?= ?m1 + ?m2
. I think if you unfold 7 enough (bit1 (bit1 one)
) you get bit0 (bit1 one) + 1
, i.e. 6+1
. So it's the most obvious split and lean takes it
Kevin Buzzard (Mar 11 2018 at 19:45):
Aah excellent!
Kevin Buzzard (Mar 11 2018 at 19:46):
so in fact this is a fun game
Kevin Buzzard (Mar 11 2018 at 19:46):
guess the error
Kevin Buzzard (Mar 11 2018 at 19:46):
example (A : fin 3) (B : fin 5) (C : fin 8) : A = ⟨2,dec_trivial⟩ → B = ⟨0,dec_trivial⟩ → C = subtypeadd A B → C = ⟨2,dec_trivial⟩ := sorry
Kevin Buzzard (Mar 11 2018 at 19:46):
you have to guess the spurious complaint that Lean makes
Kevin Buzzard (Mar 11 2018 at 19:49):
for fin 2n
it wants A : fin n
and for fin (2n+1)
it wants A : fin (2n)
Last updated: Dec 20 2023 at 11:08 UTC