Zulip Chat Archive

Stream: new members

Topic: what is the problem?


Michael Werman (Jan 12 2021 at 10:06):

def a: fin 2  
 |0 := 1
 |1 := 2

thanks,

Eric Wieser (Jan 12 2021 at 10:48):

This works:

def foo : fin 2  
| 0, _ := 1
| 1, _ := 2
| n + 2, h := by linarith

Eric Wieser (Jan 12 2021 at 10:48):

Perhaps the docs for fin should provide an example of case-matching

Eric Wieser (Jan 12 2021 at 10:51):

Or the linarith-free version:

def foo : fin 2  
| 0, _ := 1
| 1, _ := 2
| n + 2, h := false.elim $ n.not_lt_zero $ add_lt_iff_neg_right.mp h
-- or          (not_lt_of_ge (nat.le_add_left 2 n) h).elim

Is there any way to teach the equation compiler to insert this case automatically?

Yakov Pechersky (Jan 12 2021 at 14:08):

One can define it by sending 0 to 1 and _ (that is, everything else) to 2


Last updated: Dec 20 2023 at 11:08 UTC