Zulip Chat Archive

Stream: general

Topic: match on pnat


Etienne Laurin (Mar 03 2022 at 00:33):

Is it possible to teach lean to match on mathlib's pnat?

import data.pnat.basic

-- invalid function application in pattern, it cannot be reduced to a constructor (possible solution
example (a : +) := match a with
| 1 := tt
| _ := ff
end

Etienne Laurin (Mar 03 2022 at 00:35):

Are there any advantages of defining pnat using subtype instead of something like

inductive pnat' | pnat_succ (nat_pred : )
instance : has_one pnat' := ⟨⟨0⟩⟩

-- OK
example (a : pnat') := match a with
| 1 := tt
| _ := ff
end

Adam Topaz (Mar 03 2022 at 00:43):

You can still pattern match, for example like this:

import data.pnat.basic

example (a : +) := match a with
| 0,h := false.elim $ by simpa using h
| 1,h := tt
| _ := ff
end

(there may be some other spelling for the false.elim case, but you get the point...)

Adam Topaz (Mar 03 2022 at 00:47):

Or you can use docs#pnat.rec_on directly:

import data.pnat.basic

example (a : +) : bool :=
pnat.rec_on a tt (λ _ _, ff)

Kevin Buzzard (Mar 03 2022 at 08:26):

I guess you don't even have to fill in the \<0,h\> branch


Last updated: Dec 20 2023 at 11:08 UTC