Zulip Chat Archive

Stream: new members

Topic: Using if-then-else definitions


Mark Dickinson (Nov 03 2018 at 20:37):

I'm missing something fundamental. If I've defined a function ℕ → ℕ by making use of the if-then-else construct, how do I go about proving anything about that function? For example, given:

definition nat_max (m n : ) := if m < n then n else m

How do I prove something like

lemma max_right (m n : ) : m < n  nat_max m n = n := sorry

? This seems as though it should be trivial, but I'm struggling. unfold nat_max, by_cases (m < n)gives me two cases, one of which is an easy contradiction. The other then looks like:

m n : ,
h : m < n
 m < n  @ite (m < n) (nat.decidable_lt m n)  n m = n

and at that point I'm stuck.

Chris Hughes (Nov 03 2018 at 20:38):

rw if_pos h

Mark Dickinson (Nov 03 2018 at 20:40):

Ah, and if_pos was the fundamental thing I was missing. Thank you!

Mark Dickinson (Nov 03 2018 at 20:47):

Meta-question: what's the right way for a newcomer to find out about things like if_pos? Is it reasonable to say that any attempt to learn Lean has to include reading through the source of the standard library at some point?

Mark Dickinson (Nov 03 2018 at 20:48):

Though looking at the definition of if_pos, I really _should_ have been able to construct it from first principles ...

Bryan Gin-ge Chen (Nov 03 2018 at 20:49):

Speaking as another relatively new member, the naming convention + the VS code extension's "Intellisense" window and then tactic.find are usually what I go to first. Then I ask here.

Chris Hughes (Nov 03 2018 at 20:49):

Ask on Zulip probably. Usually Ctrl-clicking on ite will take you to the file where it was defined, and there'll usually be all the obvious lemmas about it there, but that seems to not be the case this time.

Mark Dickinson (Nov 03 2018 at 20:57):

Thanks, both.

Kevin Buzzard (Nov 03 2018 at 21:03):

This time last year I remember Kenny and I fretting over exactly this question -- a constructor for ite -- and I found if_pos by grepping through the source code :-)


Last updated: Dec 20 2023 at 11:08 UTC