Zulip Chat Archive

Stream: Is there code for X?

Topic: Destructing positive nat


Joachim Breitner (Apr 19 2024 at 15:19):

Is there a more idiomatic way of writing that first proof line? I have 0 < n and want to replace n with (n + 1):

example (n : Nat) (hpos : 0 < n) (P : Nat  Prop): P n := by
  cases n with | zero => contradiction | succ n =>
  sorry

Eric Rodriguez (Apr 19 2024 at 15:23):

a terrible way I'm not a real fan of: obtain ⟨n, rfl : _ = n + 1⟩ := Nat.exists_eq_add_of_le' hpos

Joachim Breitner (Apr 19 2024 at 15:24):

Hmm, I like mine more so far :-D

Joachim Breitner (Apr 19 2024 at 15:25):

Huh, this works:

example (n : Nat) (hpos : 0 < n) (P : Nat  Prop) (h :  n, P (n+1)): P n := by
  let .succ n := n
  exact h n

What magic is at work here?

Joachim Breitner (Apr 19 2024 at 15:26):

Ah, missing cases are resolved using something at least as strong as contradiction. Neat!

Vincent Beffara (Apr 19 2024 at 15:32):

example (n : Nat) (hpos : 0 < n) (P : Nat  Prop) (h :  n, P (n+1)): P n := by
  match n with | n + 1 => exact h n

Ruben Van de Velde (Apr 19 2024 at 15:33):

obtain \<n, rfl\> := n.exists_eq_succ_of_ne_zero hpos.ne'

Vincent Beffara (Apr 19 2024 at 15:39):

example (n : Nat) (hpos : 0 < n) (P : Nat  Prop) (h :  n, P (n+1)): P n := by
  cases hpos <;> apply h

Last updated: May 02 2025 at 03:31 UTC