Zulip Chat Archive
Stream: lean4
Topic: Proving intersection of two proofs
Kevin Ikeland (Dec 07 2023 at 01:44):
example : 9 ∈ odd_perfects :=
nine_is_odd : 9 ∈ odds := ⟨4, rfl⟩
nine_is_perfect_square : 9 ∈ perfect_squares := ⟨3, rfl⟩
How do I prove 9 is odd and a perfect square using a proof within a proof?
Mario Carneiro (Dec 07 2023 at 01:46):
Could you give a complete #mwe for this example?
Mario Carneiro (Dec 07 2023 at 01:47):
what you have written is not valid syntax
Kevin Ikeland (Dec 07 2023 at 01:48):
def odds : Set Nat := { n : Nat | ∃ m, n = 2 * m + 1 }
def perfect_squares : Set Nat := { n : Nat | ∃ m, n = m^2 }
def odd_perfects : Set Nat := odds ∩ perfect_squares
example : 9 ∈ odd_perfects :=
nine_is_odd : 9 ∈ odds := ⟨4, rfl⟩
nine_is_perfect_square : 9 ∈ perfect_squares := ⟨3, rfl⟩ ``` This is the complete code, I am not sure how to write it in valid syntax.
Mario Carneiro (Dec 07 2023 at 01:50):
import Mathlib.Data.Set.Basic
def odds : Set Nat := { n : Nat | ∃ m, n = 2 * m + 1 }
def perfect_squares : Set Nat := { n : Nat | ∃ m, n = m^2 }
def odd_perfects : Set Nat := odds ∩ perfect_squares
example : 9 ∈ odd_perfects :=
have nine_is_odd : 9 ∈ odds := ⟨4, rfl⟩
have nine_is_perfect_square : 9 ∈ perfect_squares := ⟨3, rfl⟩
show 9 ∈ odd_perfects from
show 9 ∈ odds ∧ 9 ∈ perfect_squares from
⟨nine_is_odd, nine_is_perfect_square⟩
Mario Carneiro (Dec 07 2023 at 01:50):
don't forget the imports
Mario Carneiro (Dec 07 2023 at 01:51):
the show
lines are unnecessary but show what the goal is. In particular lean knows that 9 ∈ odd_perfects
means the same thing as 9 ∈ odds ∧ 9 ∈ perfect_squares
by the definition of intersection
Kevin Ikeland (Dec 07 2023 at 01:52):
Okay got it. Thank you!
Last updated: Dec 20 2023 at 11:08 UTC