Skip to content
The Lumenary

Formal mathematics laboratory

Lumenary.Sets

Sets

Formal library

  • SetdefDefinitionNo axioms
    SetLean 4Formally verified
    /-- A set of elements of `α` is a yes/no property of elements of `α`:
    `A x` is the statement "`x` belongs to `A`". -/
    def Set (α : Type u) : Type u := α → Prop
    Axioms used: No axiomsformal/Lumenary/Sets.leanTry it in the Lean web editor
  • instMembershipinstanceDefinitionNo axioms
    instMembershipLean 4Formally verified
    /-- `x ∈ A` means that `x` has the property `A`. -/
    instance instMembership : Membership α (Set α) := ⟨fun A x => A x⟩
    Axioms used: No axiomsformal/Lumenary/Sets.leanTry it in the Lean web editor
  • setOfdefDefinitionNo axioms
    setOfLean 4Formally verified
    /-- `setOf p` is the set of all `x` with property `p`. We write it `{x | p x}` (notation below). -/
    def setOf (p : α → Prop) : Set α := p
    Axioms used: No axiomsformal/Lumenary/Sets.leanTry it in the Lean web editor
  • mem_setOftheoremProved here from basic factsNo axioms
    mem_setOfLean 4Proved here from basic factsFormally verified
    /-- Belonging to `{x | p x}` means having property `p` — true by definition. -/
    theorem mem_setOf (p : α → Prop) (a : α) : a ∈ {x | p x} ↔ p a := Iff.rfl
    Axioms used: No axiomsformal/Lumenary/Sets.leanTry it in the Lean web editor
  • SubsetdefDefinitionNo axioms
    SubsetLean 4Formally verified
    /-- `A ⊆ B` ("`A` is a subset of `B`"): every member of `A` is a member of `B`.
    (Mathlib states this with a strict-implicit `∀ ⦃x⦄`; we keep `x` explicit for readability.) -/
    def Subset (A B : Set α) : Prop := ∀ x, x ∈ A → x ∈ B
    Axioms used: No axiomsformal/Lumenary/Sets.leanTry it in the Lean web editor
  • instHasSubsetinstanceDefinitionNo axioms
    instHasSubsetLean 4Formally verified
    /-- Lets us write `A ⊆ B` for `Subset A B`. -/
    instance instHasSubset : HasSubset (Set α) := ⟨Subset⟩
    Axioms used: No axiomsformal/Lumenary/Sets.leanTry it in the Lean web editor
  • uniondefDefinitionNo axioms
    unionLean 4Formally verified
    /-- The union `A ∪ B`: everything in `A` *or* in `B` (or both). -/
    def union (A B : Set α) : Set α := {x | x ∈ A ∨ x ∈ B}
    Axioms used: No axiomsformal/Lumenary/Sets.leanTry it in the Lean web editor
  • instUnioninstanceDefinitionNo axioms
    instUnionLean 4Formally verified
    /-- Lets us write `A ∪ B`. -/
    instance instUnion : Union (Set α) := ⟨union⟩
    Axioms used: No axiomsformal/Lumenary/Sets.leanTry it in the Lean web editor
  • interdefDefinitionNo axioms
    interLean 4Formally verified
    /-- The intersection `A ∩ B`: everything in `A` *and* in `B`. -/
    def inter (A B : Set α) : Set α := {x | x ∈ A ∧ x ∈ B}
    Axioms used: No axiomsformal/Lumenary/Sets.leanTry it in the Lean web editor
  • instInterinstanceDefinitionNo axioms
    instInterLean 4Formally verified
    /-- Lets us write `A ∩ B`. -/
    instance instInter : Inter (Set α) := ⟨inter⟩
    Axioms used: No axiomsformal/Lumenary/Sets.leanTry it in the Lean web editor
  • compldefDefinitionNo axioms
    complLean 4Formally verified
    /-- The complement `Aᶜ`: everything (of type `α`) that is *not* in `A`. -/
    def compl (A : Set α) : Set α := {x | x ∉ A}
    Axioms used: No axiomsformal/Lumenary/Sets.leanTry it in the Lean web editor
  • emptydefDefinitionNo axioms
    emptyLean 4Formally verified
    /-- The empty set: nothing belongs to it. (The underscore in `_x` says the name is unused.) -/
    def empty : Set α := {_x | False}
    Axioms used: No axiomsformal/Lumenary/Sets.leanTry it in the Lean web editor
  • instEmptyCollectioninstanceDefinitionNo axioms
    instEmptyCollectionLean 4Formally verified
    /-- Lets us write `∅` for the empty set. -/
    instance instEmptyCollection : EmptyCollection (Set α) := ⟨empty⟩
    Axioms used: No axiomsformal/Lumenary/Sets.leanTry it in the Lean web editor
  • univdefDefinitionNo axioms
    univLean 4Formally verified
    /-- The universal set: everything of type `α` belongs to it. -/
    def univ : Set α := {_x | True}
    Axioms used: No axiomsformal/Lumenary/Sets.leanTry it in the Lean web editor
  • proddefDefinitionNo axioms
    prodLean 4Formally verified
    /-- The Cartesian product `A ×ˢ B`: all pairs `(a, b)` with `a ∈ A` and `b ∈ B`. -/
    def prod (A : Set α) (B : Set β) : Set (α × β) := {p | p.1 ∈ A ∧ p.2 ∈ B}
    Axioms used: No axiomsformal/Lumenary/Sets.leanTry it in the Lean web editor
  • mem_uniontheoremProved here from basic factsNo axioms
    mem_unionLean 4Proved here from basic factsFormally verified
    /-- `x ∈ A ∪ B` means `x ∈ A ∨ x ∈ B`. -/
    theorem mem_union (x : α) (A B : Set α) : x ∈ A ∪ B ↔ x ∈ A ∨ x ∈ B := Iff.rfl
    Axioms used: No axiomsformal/Lumenary/Sets.leanTry it in the Lean web editor
  • mem_intertheoremProved here from basic factsNo axioms
    mem_interLean 4Proved here from basic factsFormally verified
    /-- `x ∈ A ∩ B` means `x ∈ A ∧ x ∈ B`. -/
    theorem mem_inter (x : α) (A B : Set α) : x ∈ A ∩ B ↔ x ∈ A ∧ x ∈ B := Iff.rfl
    Axioms used: No axiomsformal/Lumenary/Sets.leanTry it in the Lean web editor
  • mem_compltheoremProved here from basic factsNo axioms
    mem_complLean 4Proved here from basic factsFormally verified
    /-- `x ∈ Aᶜ` means `x ∉ A`. -/
    theorem mem_compl (x : α) (A : Set α) : x ∈ Aᶜ ↔ x ∉ A := Iff.rfl
    Axioms used: No axiomsformal/Lumenary/Sets.leanTry it in the Lean web editor
  • exttheoremProved here from basic factspropext, Quot.sound
    extLean 4Proved here from basic factsFormally verified
    /-- **Extensionality.** Two sets are equal when they have exactly the same members.
    This is where sets differ from lists: order and repetition are invisible.
    The proof uses function extensionality and propositional extensionality, so the axiom
    report lists `propext` and `Quot.sound` (from which `funext` is derived). -/
    theorem ext {A B : Set α} (h : ∀ x, x ∈ A ↔ x ∈ B) : A = B :=
      funext fun x => propext (h x)
    Axioms used: propext, Quot.soundformal/Lumenary/Sets.leanTry it in the Lean web editor
  • subset_refltheoremProved here from basic factsNo axioms
    subset_reflLean 4Proved here from basic factsFormally verified
    /-- Every set is a subset of itself. -/
    theorem subset_refl (A : Set α) : A ⊆ A := by
      intro x hx
      exact hx
    Axioms used: No axiomsformal/Lumenary/Sets.leanTry it in the Lean web editor
  • subset_transtheoremProved here from basic factsNo axioms
    subset_transLean 4Proved here from basic factsFormally verified
    /-- Inclusion is transitive: if `A ⊆ B` and `B ⊆ C` then `A ⊆ C`. -/
    theorem subset_trans {A B C : Set α} (hAB : A ⊆ B) (hBC : B ⊆ C) : A ⊆ C := by
      intro x hxA
      have hxB : x ∈ B := hAB x hxA
      exact hBC x hxB
    Axioms used: No axiomsformal/Lumenary/Sets.leanTry it in the Lean web editor
  • empty_subsettheoremProved here from basic factsNo axioms
    empty_subsetLean 4Proved here from basic factsFormally verified
    /-- The empty set is a subset of every set: there is no member of `∅` that could fail to be
    in `A`. (Logicians say the statement is *vacuously* true.) -/
    theorem empty_subset (A : Set α) : ∅ ⊆ A := by
      intro x hx
      -- `hx : x ∈ ∅` is a proof of `False`, and from `False` anything follows.
      exact False.elim hx
    Axioms used: No axiomsformal/Lumenary/Sets.leanTry it in the Lean web editor
  • subset_univtheoremProved here from basic factsNo axioms
    subset_univLean 4Proved here from basic factsFormally verified
    /-- Every set is a subset of the universal set. -/
    theorem subset_univ (A : Set α) : A ⊆ univ := by
      intro x _
      -- `x ∈ univ` is just `True`.
      trivial
    Axioms used: No axiomsformal/Lumenary/Sets.leanTry it in the Lean web editor
  • inter_subset_lefttheoremProved here from basic factsNo axioms
    inter_subset_leftLean 4Proved here from basic factsFormally verified
    /-- `A ∩ B ⊆ A`: whatever is in both sets is, in particular, in the first one. -/
    theorem inter_subset_left (A B : Set α) : A ∩ B ⊆ A := by
      intro x hx
      -- `hx : x ∈ A ∧ x ∈ B`; keep the left half.
      exact hx.1
    Axioms used: No axiomsformal/Lumenary/Sets.leanTry it in the Lean web editor
  • inter_subset_righttheoremProved here from basic factsNo axioms
    inter_subset_rightLean 4Proved here from basic factsFormally verified
    /-- `A ∩ B ⊆ B`: whatever is in both sets is, in particular, in the second one. -/
    theorem inter_subset_right (A B : Set α) : A ∩ B ⊆ B := by
      intro x hx
      -- `hx : x ∈ A ∧ x ∈ B`; keep the right half.
      exact hx.2
    Axioms used: No axiomsformal/Lumenary/Sets.leanTry it in the Lean web editor
  • subset_union_lefttheoremProved here from basic factsNo axioms
    subset_union_leftLean 4Proved here from basic factsFormally verified
    /-- `A ⊆ A ∪ B`: anything in `A` is in `A` or in `B`. -/
    theorem subset_union_left (A B : Set α) : A ⊆ A ∪ B := by
      intro x hx
      exact Or.inl hx
    Axioms used: No axiomsformal/Lumenary/Sets.leanTry it in the Lean web editor
  • union_commtheoremProved here from basic factspropext, Quot.sound
    union_commLean 4Proved here from basic factsFormally verified
    /-- Union is commutative: `A ∪ B = B ∪ A`. -/
    theorem union_comm (A B : Set α) : A ∪ B = B ∪ A := by
      apply ext
      intro x
      constructor
      · intro h
        -- `h : x ∈ A ∨ x ∈ B`, and "or" can be swapped.
        exact Or.symm h
      · intro h
        exact Or.symm h
    Axioms used: propext, Quot.soundformal/Lumenary/Sets.leanTry it in the Lean web editor
  • inter_commtheoremProved here from basic factspropext, Quot.sound
    inter_commLean 4Proved here from basic factsFormally verified
    /-- Intersection is commutative: `A ∩ B = B ∩ A`. -/
    theorem inter_comm (A B : Set α) : A ∩ B = B ∩ A := by
      apply ext
      intro x
      constructor
      · intro h
        -- `h : x ∈ A ∧ x ∈ B`, and "and" can be swapped.
        exact And.symm h
      · intro h
        exact And.symm h
    Axioms used: propext, Quot.soundformal/Lumenary/Sets.leanTry it in the Lean web editor
  • inter_union_distribtheoremProved here from basic factspropext, Quot.sound
    inter_union_distribLean 4Proved here from basic factsFormally verified
    /-- Intersection distributes over union: `A ∩ (B ∪ C) = (A ∩ B) ∪ (A ∩ C)`.
    (Mathlib analogue: `Set.inter_union_distrib_left`.) -/
    theorem inter_union_distrib (A B C : Set α) : A ∩ (B ∪ C) = (A ∩ B) ∪ (A ∩ C) := by
      apply ext
      intro x
      constructor
      · -- If `x ∈ A` and `x` is in `B` or `C`, look at which one.
        intro ⟨hA, hBC⟩
        cases hBC with
        | inl hB => exact Or.inl ⟨hA, hB⟩
        | inr hC => exact Or.inr ⟨hA, hC⟩
      · -- Either way round, `x ∈ A`, and `x` is in `B` or in `C`.
        intro h
        cases h with
        | inl hAB => exact ⟨hAB.1, Or.inl hAB.2⟩
        | inr hAC => exact ⟨hAC.1, Or.inr hAC.2⟩
    Axioms used: propext, Quot.soundformal/Lumenary/Sets.leanTry it in the Lean web editor
  • compl_uniontheoremProved here from basic factspropext, Quot.sound
    compl_unionLean 4Proved here from basic factsFormally verified
    /-- **De Morgan's law** for unions: `(A ∪ B)ᶜ = Aᶜ ∩ Bᶜ`.
    Not being in `A ∪ B` means being in neither set. This proof is constructive: it does not
    use the law of excluded middle. -/
    theorem compl_union (A B : Set α) : (A ∪ B)ᶜ = Aᶜ ∩ Bᶜ := by
      apply ext
      intro x
      constructor
      · intro h
        -- `h : ¬ (x ∈ A ∨ x ∈ B)`. If `x` were in `A`, it would be in `A ∪ B`; same for `B`.
        exact ⟨fun hA => h (Or.inl hA), fun hB => h (Or.inr hB)⟩
      · intro ⟨hnA, hnB⟩ hAB
        -- `x` is in `A` or in `B`, and both cases contradict what we know.
        cases hAB with
        | inl hA => exact hnA hA
        | inr hB => exact hnB hB
    Axioms used: propext, Quot.soundformal/Lumenary/Sets.leanTry it in the Lean web editor
  • compl_intertheoremProved here from basic factspropext, Classical.choice, Quot.sound
    compl_interLean 4Proved here from basic factsFormally verified
    /-- **De Morgan's law** for intersections: `(A ∩ B)ᶜ = Aᶜ ∪ Bᶜ`.
    The direction `(A ∩ B)ᶜ ⊆ Aᶜ ∪ Bᶜ` needs **classical logic**: knowing only that `x` is not in
    both sets, we must still decide *which* set it misses. We use excluded middle
    (`Classical.em`), so the axiom report for this theorem includes `Classical.choice`. -/
    theorem compl_inter (A B : Set α) : (A ∩ B)ᶜ = Aᶜ ∪ Bᶜ := by
      apply ext
      intro x
      constructor
      · intro h
        -- `h : ¬ (x ∈ A ∧ x ∈ B)`. Either `x ∈ A` or not (excluded middle).
        cases Classical.em (x ∈ A) with
        | inl hA =>
          -- Then `x` cannot also be in `B`.
          exact Or.inr (fun hB => h ⟨hA, hB⟩)
        | inr hnA => exact Or.inl hnA
      · intro h ⟨hA, hB⟩
        cases h with
        | inl hnA => exact hnA hA
        | inr hnB => exact hnB hB
    Axioms used: propext, Classical.choice, Quot.soundformal/Lumenary/Sets.leanTry it in the Lean web editor
  • mem_prodtheoremProved here from basic factsNo axioms
    mem_prodLean 4Proved here from basic factsFormally verified
    /-- A pair `(a, b)` is in `A ×ˢ B` exactly when `a ∈ A` and `b ∈ B`. True by definition. -/
    theorem mem_prod (a : α) (b : β) (A : Set α) (B : Set β) :
        (a, b) ∈ A ×ˢ B ↔ a ∈ A ∧ b ∈ B :=
      Iff.rfl
    Axioms used: No axiomsformal/Lumenary/Sets.leanTry it in the Lean web editor

Formal exercises

Each exercise contains a sorry for you to replace. Open it in the Lean web editor, or clone the repository and run lake build.

inter_subset_rightsorry × 1Try it in the Lean web editor
/-- Show that `A ∩ B ⊆ B`.
Hint: start with `intro x hx`. What does `hx : x ∈ A ∩ B` tell you? -/
theorem inter_subset_right (A B : Set α) : A ∩ B ⊆ B := by
  sorry
Show the compiled solution
inter_subset_rightLean 4Proved here from basic factsFormally verified
/-- `A ∩ B ⊆ B`: whatever is in both sets is, in particular, in the second one. -/
theorem inter_subset_right (A B : Set α) : A ∩ B ⊆ B := by
  intro x hx
  -- `hx : x ∈ A ∧ x ∈ B`; keep the right half.
  exact hx.2
Axioms used: No axiomsformal/Lumenary/Sets.leanTry it in the Lean web editor
union_commsorry × 1Try it in the Lean web editor
/-- Show that union is commutative.
Hint: `apply ext`, then `intro x` and `constructor`; `Or.symm` swaps the two sides of an "or". -/
theorem union_comm (A B : Set α) : A ∪ B = B ∪ A := by
  sorry
Show the compiled solution
union_commLean 4Proved here from basic factsFormally verified
/-- Union is commutative: `A ∪ B = B ∪ A`. -/
theorem union_comm (A B : Set α) : A ∪ B = B ∪ A := by
  apply ext
  intro x
  constructor
  · intro h
    -- `h : x ∈ A ∨ x ∈ B`, and "or" can be swapped.
    exact Or.symm h
  · intro h
    exact Or.symm h
Axioms used: propext, Quot.soundformal/Lumenary/Sets.leanTry it in the Lean web editor
compl_unionsorry × 1Try it in the Lean web editor
/-- De Morgan's law: not being in `A ∪ B` means being in neither `A` nor `B`.
Hint: `x ∈ Aᶜ` means `x ∈ A → False`. You do not need classical logic for this one. -/
theorem compl_union (A B : Set α) : (A ∪ B)ᶜ = Aᶜ ∩ Bᶜ := by
  sorry
Show the compiled solution
compl_unionLean 4Proved here from basic factsFormally verified
/-- **De Morgan's law** for unions: `(A ∪ B)ᶜ = Aᶜ ∩ Bᶜ`.
Not being in `A ∪ B` means being in neither set. This proof is constructive: it does not
use the law of excluded middle. -/
theorem compl_union (A B : Set α) : (A ∪ B)ᶜ = Aᶜ ∩ Bᶜ := by
  apply ext
  intro x
  constructor
  · intro h
    -- `h : ¬ (x ∈ A ∨ x ∈ B)`. If `x` were in `A`, it would be in `A ∪ B`; same for `B`.
    exact ⟨fun hA => h (Or.inl hA), fun hB => h (Or.inr hB)⟩
  · intro ⟨hnA, hnB⟩ hAB
    -- `x` is in `A` or in `B`, and both cases contradict what we know.
    cases hAB with
    | inl hA => exact hnA hA
    | inr hB => exact hnB hB
Axioms used: propext, Quot.soundformal/Lumenary/Sets.leanTry it in the Lean web editor