Zulip Chat Archive

Stream: lean4

Topic: Feedback on some exercises


James Sully (Jun 02 2023 at 11:21):

Hi! I'm working through the exercises from chapter 3 of Theorem Proving in Lean 4.

I've done about a third of them, and I'm looking for some general feedback on style that I might be able to incorporate into later solutions. Would anyone be willing to give me a quick code review? I'd greatly appreciate it. Here are my solutions so far.

In particular I'm looking for feedback on

  • code neatness
  • making things more idiomatic
  • variable naming
  • succinctness
  • places I can use show, have, suffices to make things more readable - I don't feel like I have a good intuition for how/where to use them, or when to use have vs let

James Sully (Jun 02 2023 at 11:29):

nitpicks especially welcome

Eric Wieser (Jun 02 2023 at 11:29):

or when to use have vs let

The general rule is "use have for proofs, use let for data"

Eric Wieser (Jun 02 2023 at 11:30):

In your code you don't have any data, so you don't need let at all

James Sully (Jun 02 2023 at 11:31):

Thank you, noted

Bulhwi Cha (Jun 03 2023 at 13:41):

De Morgan's law 1:

(show ¬p from λ hp => h_n_pOrq  Or.inl <| hp)
(show ¬q from λ hq => h_n_pOrq  Or.inr <| hq)

Suggestion:

(show ¬p from h_n_pOrq  Or.inl)
(show ¬q from h_n_pOrq  Or.inr)

Bulhwi Cha (Jun 03 2023 at 13:53):

¬(p ∧ q) → ¬p ∨ ¬q (classical):

have ifNotP := show ¬p  ¬p  ¬q from
  λ hnp => Or.inl hnp

Suggestion:

have ifNotP := show ¬p  ¬p  ¬q from Or.inl

Bulhwi Cha (Jun 03 2023 at 14:02):

(p → q) → (¬p ∨ q) (classical):

(show p   ¬p  q from λ hp  => Or.inr (hpq hp))
(show ¬p  ¬p  q from λ hnp => Or.inl hnp)

Suggestion:

(show  p  ¬p  q from λ hp => Or.inr (hpq hp))
(show ¬p  ¬p  q from Or.inl)

Last updated: Dec 20 2023 at 11:08 UTC