doc-next-gen

Mathlib.Data.Finset.Empty

Module docstring

{"# Empty and nonempty finite sets

This file defines the empty finite set ∅ and a predicate for nonempty Finsets.

Main declarations

  • Finset.Nonempty: A finset is nonempty if it has elements. This is equivalent to saying s ≠ ∅.
  • Finset.empty: Denoted by . The finset associated to any type consisting of no elements.

Tags

finite sets, finset

","### Nonempty ","### empty "}

Finset.Nonempty definition
(s : Finset α) : Prop
Full source
/-- The property `s.Nonempty` expresses the fact that the finset `s` is not empty. It should be used
in theorem assumptions instead of `∃ x, x ∈ s` or `s ≠ ∅` as it gives access to a nice API thanks
to the dot notation. -/
protected def Nonempty (s : Finset α) : Prop := ∃ x : α, x ∈ s
Nonempty finite set
Informal description
A finite set \( s \) is called nonempty if there exists an element \( x \in s \).
Finset.coe_nonempty theorem
{s : Finset α} : (s : Set α).Nonempty ↔ s.Nonempty
Full source
@[simp, norm_cast]
theorem coe_nonempty {s : Finset α} : (s : Set α).Nonempty ↔ s.Nonempty :=
  Iff.rfl
Equivalence of Nonemptiness for Finite Sets and Their Subset Counterparts
Informal description
For any finite set $s$ of type $\alpha$, the set $s$ (viewed as a subset of $\alpha$) is nonempty if and only if the finite set $s$ itself is nonempty.
Finset.nonempty_coe_sort theorem
{s : Finset α} : Nonempty (s : Type _) ↔ s.Nonempty
Full source
theorem nonempty_coe_sort {s : Finset α} : NonemptyNonempty (s : Type _) ↔ s.Nonempty :=
  nonempty_subtype
Nonempty Subtype Characterization for Finite Sets
Informal description
For any finite set $s$ of type $\alpha$, the subtype corresponding to $s$ is nonempty (as a type) if and only if $s$ is nonempty (as a finite set).
Finset.Nonempty.exists_mem theorem
{s : Finset α} (h : s.Nonempty) : ∃ x : α, x ∈ s
Full source
theorem Nonempty.exists_mem {s : Finset α} (h : s.Nonempty) : ∃ x : α, x ∈ s :=
  h
Existence of Element in Nonempty Finite Set
Informal description
For any nonempty finite set $s$ of elements of type $\alpha$, there exists an element $x \in s$.
Finset.Nonempty.mono theorem
{s t : Finset α} (hst : s ⊆ t) (hs : s.Nonempty) : t.Nonempty
Full source
theorem Nonempty.mono {s t : Finset α} (hst : s ⊆ t) (hs : s.Nonempty) : t.Nonempty :=
  Set.Nonempty.mono hst hs
Nonempty Subset Implies Nonempty Superset for Finite Sets
Informal description
For any finite sets $s$ and $t$ of type $\alpha$, if $s$ is a nonempty subset of $t$ (i.e., $s \subseteq t$ and $s \neq \emptyset$), then $t$ is also nonempty.
Finset.Nonempty.forall_const theorem
{s : Finset α} (h : s.Nonempty) {p : Prop} : (∀ x ∈ s, p) ↔ p
Full source
theorem Nonempty.forall_const {s : Finset α} (h : s.Nonempty) {p : Prop} : (∀ x ∈ s, p) ↔ p :=
  let ⟨x, hx⟩ := h
  ⟨fun h => h x hx, fun h _ _ => h⟩
Universal Quantification over Nonempty Finite Set is Equivalent to Proposition
Informal description
For any nonempty finite set $s$ and any proposition $p$, the statement $(\forall x \in s, p)$ is equivalent to $p$.
Finset.Nonempty.to_subtype theorem
{s : Finset α} : s.Nonempty → Nonempty s
Full source
theorem Nonempty.to_subtype {s : Finset α} : s.NonemptyNonempty s :=
  nonempty_coe_sort.2
Nonempty Finite Set Implies Nonempty Subtype
Informal description
For any finite set $s$ of type $\alpha$, if $s$ is nonempty (i.e., there exists an element $x \in s$), then the subtype corresponding to $s$ is nonempty (i.e., there exists an element of the subtype $s$).
Finset.Nonempty.to_type theorem
{s : Finset α} : s.Nonempty → Nonempty α
Full source
theorem Nonempty.to_type {s : Finset α} : s.NonemptyNonempty α := fun ⟨x, _hx⟩ => ⟨x⟩
Nonempty finite set implies nonempty type
Informal description
For any finite set $s$ of type $\alpha$, if $s$ is nonempty (i.e., there exists an element $x \in s$), then the type $\alpha$ itself is nonempty (i.e., there exists an element of type $\alpha$).
Finset.empty definition
: Finset α
Full source
/-- The empty finset -/
protected def empty : Finset α :=
  ⟨0, nodup_zero⟩
Empty finite set
Informal description
The empty finite set, denoted by $\emptyset$, is the finite set associated to any type $\alpha$ that contains no elements. It is represented as a multiset with zero elements and no duplicates.
Finset.instEmptyCollection instance
: EmptyCollection (Finset α)
Full source
instance : EmptyCollection (Finset α) :=
  ⟨Finset.empty⟩
Empty Collection Structure on Finite Sets
Informal description
The finite sets of any type $\alpha$ form an empty collection, with the empty set $\emptyset$ as its element.
Finset.inhabitedFinset instance
: Inhabited (Finset α)
Full source
instance inhabitedFinset : Inhabited (Finset α) :=
  ⟨∅⟩
Inhabited Finite Sets
Informal description
For any type $\alpha$, the collection of finite sets of $\alpha$ is inhabited (i.e., contains at least one element).
Finset.empty_val theorem
: (∅ : Finset α).1 = 0
Full source
@[simp]
theorem empty_val : ( : Finset α).1 = 0 :=
  rfl
Empty Finite Set as Zero Multiset
Informal description
The underlying multiset of the empty finite set $\emptyset$ is equal to the zero multiset $0$.
Finset.not_nonempty_empty theorem
: ¬(∅ : Finset α).Nonempty
Full source
@[simp]
theorem not_nonempty_empty : ¬(∅ : Finset α).Nonempty := fun ⟨x, hx⟩ => not_mem_empty x hx
Empty Finite Set is Nonempty-Free
Informal description
The empty finite set $\emptyset$ is not nonempty, i.e., it does not contain any elements.
Finset.mk_zero theorem
: (⟨0, nodup_zero⟩ : Finset α) = ∅
Full source
@[simp]
theorem mk_zero : (⟨0, nodup_zero⟩ : Finset α) =  :=
  rfl
Empty Finite Set Construction: $\langle 0, \text{nodup\_zero}\rangle = \emptyset$
Informal description
The finite set constructed from the empty multiset $0$ (with no duplicates) is equal to the empty finite set $\emptyset$.
Finset.ne_empty_of_mem theorem
{a : α} {s : Finset α} (h : a ∈ s) : s ≠ ∅
Full source
theorem ne_empty_of_mem {a : α} {s : Finset α} (h : a ∈ s) : s ≠ ∅ := fun e =>
  not_mem_empty a <| e ▸ h
Non-emptiness of Finite Sets with Membership: $a \in s \implies s \neq \emptyset$
Informal description
For any element $a$ of type $\alpha$ and any finite set $s$ of type $\alpha$, if $a$ belongs to $s$, then $s$ is not equal to the empty set $\emptyset$.
Finset.Nonempty.ne_empty theorem
{s : Finset α} (h : s.Nonempty) : s ≠ ∅
Full source
theorem Nonempty.ne_empty {s : Finset α} (h : s.Nonempty) : s ≠ ∅ :=
  (Exists.elim h) fun _a => ne_empty_of_mem
Nonempty Finite Sets are Non-Empty: $s \text{ nonempty} \implies s \neq \emptyset$
Informal description
For any finite set $s$ of type $\alpha$, if $s$ is nonempty, then $s$ is not equal to the empty set $\emptyset$.
Finset.empty_subset theorem
(s : Finset α) : ∅ ⊆ s
Full source
@[simp]
theorem empty_subset (s : Finset α) : ∅ ⊆ s :=
  zero_subset _
Empty Set is Subset of Any Finite Set
Informal description
For any finite set $s$ of type $\alpha$, the empty set $\emptyset$ is a subset of $s$.
Finset.val_eq_zero theorem
{s : Finset α} : s.1 = 0 ↔ s = ∅
Full source
@[simp]
theorem val_eq_zero {s : Finset α} : s.1 = 0 ↔ s = ∅ :=
  @val_inj _ s 
Empty Finite Set Characterization via Multiset Equality: $s.1 = 0 \leftrightarrow s = \emptyset$
Informal description
For any finite set $s$ of type $\alpha$, the underlying multiset of $s$ is equal to the empty multiset $0$ if and only if $s$ is the empty finite set $\emptyset$.
Finset.subset_empty theorem
: s ⊆ ∅ ↔ s = ∅
Full source
@[simp] lemma subset_empty : s ⊆ ∅s ⊆ ∅ ↔ s = ∅ := subset_zero.trans val_eq_zero
Subset of Empty Finite Set is Empty: $s \subseteq \emptyset \leftrightarrow s = \emptyset$
Informal description
For any finite set $s$ of type $\alpha$, $s$ is a subset of the empty finite set $\emptyset$ if and only if $s$ is equal to $\emptyset$.
Finset.not_ssubset_empty theorem
(s : Finset α) : ¬s ⊂ ∅
Full source
@[simp]
theorem not_ssubset_empty (s : Finset α) : ¬s ⊂ ∅ := fun h =>
  let ⟨_, he, _⟩ := exists_of_ssubset h
  not_mem_empty _ he
No Finite Set is a Strict Subset of the Empty Set
Informal description
For any finite set $s$ of type $\alpha$, $s$ is not a strict subset of the empty finite set $\emptyset$.
Finset.nonempty_of_ne_empty theorem
{s : Finset α} (h : s ≠ ∅) : s.Nonempty
Full source
theorem nonempty_of_ne_empty {s : Finset α} (h : s ≠ ∅) : s.Nonempty :=
  exists_mem_of_ne_zero (mt val_eq_zero.1 h)
Nonempty Finite Set from Non-Empty Condition
Informal description
For any finite set $s$ of type $\alpha$, if $s$ is not equal to the empty set $\emptyset$, then $s$ is nonempty (i.e., there exists an element $x \in s$).
Finset.coe_empty theorem
: ((∅ : Finset α) : Set α) = ∅
Full source
@[simp, norm_cast]
theorem coe_empty : (( : Finset α) : Set α) =  :=
  Set.ext <| by simp
Empty Finite Set Coercion to Set: $\emptyset_{\text{Finset}} = \emptyset_{\text{Set}}$
Informal description
The underlying set of the empty finite set $\emptyset$ (of type `Finset α`) is equal to the empty set $\emptyset$ (of type `Set α$).
Finset.coe_eq_empty theorem
{s : Finset α} : (s : Set α) = ∅ ↔ s = ∅
Full source
@[simp, norm_cast]
theorem coe_eq_empty {s : Finset α} : (s : Set α) = ∅ ↔ s = ∅ := by rw [← coe_empty, coe_inj]
Equivalence of Empty Finite Set and Empty Set
Informal description
For any finite set $s$ of type $\alpha$, the underlying set of $s$ is equal to the empty set if and only if $s$ is the empty finite set. In other words, $(s : \text{Set } \alpha) = \emptyset \leftrightarrow s = \emptyset$.
Finset.isEmpty_coe_sort theorem
{s : Finset α} : IsEmpty (s : Type _) ↔ s = ∅
Full source
@[simp]
theorem isEmpty_coe_sort {s : Finset α} : IsEmptyIsEmpty (s : Type _) ↔ s = ∅ := by
  simpa using @Set.isEmpty_coe_sort α s
Empty Subtype Characterization for Finite Sets: $\text{IsEmpty}(s) \leftrightarrow s = \emptyset$
Informal description
For any finite set $s$ of type $\alpha$, the subtype corresponding to $s$ is empty if and only if $s$ is the empty finite set. In other words, $\text{IsEmpty}(s : \text{Type}) \leftrightarrow s = \emptyset$.
Finset.instIsEmpty instance
: IsEmpty (∅ : Finset α)
Full source
instance instIsEmpty : IsEmpty ( : Finset α) :=
  isEmpty_coe_sort.2 rfl
Empty Finite Set is Empty Type
Informal description
The empty finite set $\emptyset$ is an empty type, meaning it has no elements.
Finset.instOrderBot instance
: OrderBot (Finset α)
Full source
instance : OrderBot (Finset α) where
  bot := 
  bot_le := empty_subset
Finite Sets as an Order with Bottom Element $\emptyset$
Informal description
The finite sets of any type $\alpha$ form an order with a bottom element, where the empty set $\emptyset$ is the least element.
Finset.bot_eq_empty theorem
: (⊥ : Finset α) = ∅
Full source
@[simp]
theorem bot_eq_empty : ( : Finset α) =  :=
  rfl
Bottom Element Equals Empty Set in Finite Sets
Informal description
The bottom element in the order of finite sets of type $\alpha$ is equal to the empty set, i.e., $\bot = \emptyset$.
Finset.exists_mem_empty_iff theorem
(p : α → Prop) : (∃ x, x ∈ (∅ : Finset α) ∧ p x) ↔ False
Full source
theorem exists_mem_empty_iff (p : α → Prop) : (∃ x, x ∈ (∅ : Finset α) ∧ p x) ↔ False := by
  simp only [not_mem_empty, false_and, exists_false]
Existence in Empty Finite Set is False
Informal description
For any predicate $p$ on elements of type $\alpha$, the statement that there exists an element $x$ in the empty finite set $\emptyset$ such that $p(x)$ holds is equivalent to false. In other words, $\exists x \in \emptyset, p(x) \leftrightarrow \text{False}$.
Finset.forall_mem_empty_iff theorem
(p : α → Prop) : (∀ x, x ∈ (∅ : Finset α) → p x) ↔ True
Full source
theorem forall_mem_empty_iff (p : α → Prop) : (∀ x, x ∈ (∅ : Finset α) → p x) ↔ True :=
  iff_true_intro fun _ h => False.elim <| not_mem_empty _ h
Universal Quantification over Empty Finite Set is Trivially True
Informal description
For any predicate $p$ on elements of type $\alpha$, the statement that for all $x$ in the empty finite set $\emptyset$, $p(x)$ holds is equivalent to true. In other words, $\forall x \in \emptyset, p(x) \leftrightarrow \text{True}$.
Mathlib.Meta.proveFinsetNonempty definition
{u : Level} {α : Q(Type u)} (s : Q(Finset $α)) : MetaM (Option Q(Finset.Nonempty $s))
Full source
/-- Attempt to prove that a finset is nonempty using the `finsetNonempty` aesop rule-set.

You can add lemmas to the rule-set by tagging them with either:
* `aesop safe apply (rule_sets := [finsetNonempty])` if they are always a good idea to follow or
* `aesop unsafe apply (rule_sets := [finsetNonempty])` if they risk directing the search to a blind
  alley.

TODO: should some of the lemmas be `aesop safe simp` instead?
-/
def proveFinsetNonempty {u : Level} {α : Q(Type u)} (s : Q(Finset $α)) :
    MetaM (Option Q(Finset.Nonempty $s)) := do
  -- Aesop expects to operate on goals, so we're going to make a new goal.
  let goal ← Lean.Meta.mkFreshExprMVar q(Finset.Nonempty $s)
  let mvar := goal.mvarId!
  -- We want this to be fast, so use only the basic and `Finset.Nonempty`-specific rules.
  let rulesets ← Aesop.Frontend.getGlobalRuleSets #[`builtin, `finsetNonempty]
  let options : Aesop.Options' :=
    { terminal := true -- Fail if the new goal is not closed.
      generateScript := false
      useDefaultSimpSet := false -- Avoiding the whole simp set to speed up the tactic.
      warnOnNonterminal := false -- Don't show a warning on failure, simply return `none`.
      forwardMaxDepth? := none }
  let rules ← Aesop.mkLocalRuleSet rulesets options
  let (remainingGoals, _) ←
    try Aesop.search (options := options.toOptions) mvar (.some rules)
    catch _ => return none
  -- Fail if there are open goals remaining, this serves as an extra check for the
  -- Aesop configuration option `terminal := true`.
  if remainingGoals.size > 0 then return none
  Lean.getExprMVarAssignment? mvar
Automated proof of finite set nonemptiness
Informal description
A meta-level function that attempts to prove that a given finite set `s` is nonempty using the `finsetNonempty` automated proof rule-set. The function creates a fresh goal for the nonempty condition and uses Aesop's search with specific rules to try to close the goal. If successful, it returns the proof; otherwise, it returns `none`.