doc-next-gen

Mathlib.Data.Finset.Range

Module docstring

{"# Finite sets made of a range of elements.

Main declarations

Finset constructions

  • Finset.range: For any n : ℕ, range n is equal to {0, 1, ... , n - 1} ⊆ ℕ. This convention is consistent with other languages and normalizes card (range n) = n. Beware, n is not in range n.

Tags

finite sets, finset

","### range "}

Finset.range definition
(n : ℕ) : Finset ℕ
Full source
/-- `range n` is the set of natural numbers less than `n`. -/
def range (n : ) : Finset  :=
  ⟨_, nodup_range n⟩
Finite set of numbers from 0 to \( n-1 \)
Informal description
For a natural number \( n \), `range n` is the finite set of natural numbers \( \{0, 1, \ldots, n-1\} \). Note that \( n \) itself is not included in the set.
Finset.range_val theorem
(n : ℕ) : (range n).1 = Multiset.range n
Full source
@[simp]
theorem range_val (n : ) : (range n).1 = Multiset.range n :=
  rfl
Equality of Underlying Multiset for Finite Range of Natural Numbers
Informal description
For any natural number $n$, the underlying multiset of the finite set `range n` is equal to the multiset `Multiset.range n`, which consists of the natural numbers $\{0, 1, \ldots, n-1\}$.
Finset.mem_range theorem
: m ∈ range n ↔ m < n
Full source
@[simp]
theorem mem_range : m ∈ range nm ∈ range n ↔ m < n :=
  Multiset.mem_range
Membership in Finite Range: $m \in \{0, \ldots, n-1\} \leftrightarrow m < n$
Informal description
For natural numbers $m$ and $n$, the element $m$ belongs to the finite set $\{0, 1, \ldots, n-1\}$ if and only if $m < n$.
Finset.coe_range theorem
(n : ℕ) : (range n : Set ℕ) = Set.Iio n
Full source
@[simp, norm_cast]
theorem coe_range (n : ) : (range n : Set ) = Set.Iio n :=
  Set.ext fun _ => mem_range
Finite range as interval: $\{0, \ldots, n-1\} = (-\infty, n)$
Informal description
For any natural number $n$, the finite set $\{0, 1, \ldots, n-1\}$ (when viewed as a set) is equal to the interval $(-\infty, n)$ of natural numbers strictly less than $n$.
Finset.range_zero theorem
: range 0 = ∅
Full source
@[simp]
theorem range_zero : range 0 =  :=
  rfl
Range of Zero is Empty Set
Informal description
The finite set of natural numbers from $0$ to $-1$ (i.e., `range 0`) is equal to the empty set $\emptyset$.
Finset.range_one theorem
: range 1 = {0}
Full source
@[simp]
theorem range_one : range 1 = {0} :=
  rfl
Range of One is Singleton Zero
Informal description
The finite set of natural numbers from $0$ to $0$ (i.e., `range 1`) is equal to the singleton set $\{0\}$.
Finset.range_succ theorem
: range (succ n) = insert n (range n)
Full source
theorem range_succ : range (succ n) = insert n (range n) :=
  eq_of_veq <| (Multiset.range_succ n).trans <| (ndinsert_of_not_mem not_mem_range_self).symm
Recursive construction of finite range: $\text{range}(n+1) = \{n\} \cup \text{range}(n)$
Informal description
For any natural number $n$, the finite set $\{0, 1, \ldots, n\}$ is equal to the set obtained by inserting $n$ into the finite set $\{0, 1, \ldots, n-1\}$.
Finset.range_add_one theorem
: range (n + 1) = insert n (range n)
Full source
theorem range_add_one : range (n + 1) = insert n (range n) :=
  range_succ
Recursive construction of range: $\text{range}(n+1) = \{n\} \cup \text{range}(n)$
Informal description
For any natural number $n$, the finite set $\{0, 1, \ldots, n\}$ is equal to the union of $\{n\}$ with the finite set $\{0, 1, \ldots, n-1\}$.
Finset.not_mem_range_self theorem
: n ∉ range n
Full source
theorem not_mem_range_self : n ∉ range n :=
  Multiset.not_mem_range_self
$n \notin \{0, \ldots, n-1\}$ for natural numbers
Informal description
For any natural number $n$, the element $n$ does not belong to the finite set $\{0, 1, \ldots, n-1\}$.
Finset.self_mem_range_succ theorem
(n : ℕ) : n ∈ range (n + 1)
Full source
theorem self_mem_range_succ (n : ) : n ∈ range (n + 1) :=
  Multiset.self_mem_range_succ n
Self-inclusion in successor range: $n \in \{0, \ldots, n\}$
Informal description
For any natural number $n$, the element $n$ belongs to the finite set $\{0, 1, \ldots, n\}$.
Finset.range_subset theorem
{n m} : range n ⊆ range m ↔ n ≤ m
Full source
@[simp]
theorem range_subset {n m} : rangerange n ⊆ range mrange n ⊆ range m ↔ n ≤ m :=
  Multiset.range_subset
Subset Condition for Finite Range Sets: $\{0, \ldots, n-1\} \subseteq \{0, \ldots, m-1\} \iff n \leq m$
Informal description
For any natural numbers $n$ and $m$, the finite set $\{0, 1, \ldots, n-1\}$ is a subset of $\{0, 1, \ldots, m-1\}$ if and only if $n \leq m$.
Finset.range_mono theorem
: Monotone range
Full source
theorem range_mono : Monotone range := fun _ _ => range_subset.2
Monotonicity of the Finite Range Function
Informal description
The function `range : ℕ → Finset ℕ` is monotone, meaning that for any natural numbers $n$ and $m$, if $n \leq m$ then $\{0, 1, \ldots, n-1\} \subseteq \{0, 1, \ldots, m-1\}$.
Finset.mem_range_le theorem
{n x : ℕ} (hx : x ∈ range n) : x ≤ n
Full source
theorem mem_range_le {n x : } (hx : x ∈ range n) : x ≤ n :=
  (mem_range.1 hx).le
Upper Bound for Elements in Finite Range: $x \in \{0, \ldots, n-1\} \Rightarrow x \leq n$
Informal description
For any natural numbers $n$ and $x$, if $x$ belongs to the finite set $\{0, 1, \ldots, n-1\}$, then $x \leq n$.
Finset.mem_range_sub_ne_zero theorem
{n x : ℕ} (hx : x ∈ range n) : n - x ≠ 0
Full source
theorem mem_range_sub_ne_zero {n x : } (hx : x ∈ range n) : n - x ≠ 0 :=
  _root_.ne_of_gt <| Nat.sub_pos_of_lt <| mem_range.1 hx
Nonzero Difference in Finite Range: $x \in \{0, \ldots, n-1\} \Rightarrow n - x \neq 0$
Informal description
For any natural numbers $n$ and $x$, if $x$ belongs to the finite set $\{0, 1, \ldots, n-1\}$, then $n - x \neq 0$.
Finset.nonempty_range_succ theorem
: (range <| n + 1).Nonempty
Full source
@[aesop safe apply (rule_sets := [finsetNonempty])]
theorem nonempty_range_succ : (range <| n + 1).Nonempty :=
  nonempty_range_iff.2 n.succ_ne_zero
Nonempty Range for Successor: $\{0, \ldots, n\} \neq \emptyset$
Informal description
For any natural number $n$, the finite set $\{0, 1, \ldots, n\}$ is nonempty.
Finset.range_nontrivial theorem
{n : ℕ} (hn : 1 < n) : (Finset.range n).Nontrivial
Full source
lemma range_nontrivial {n : } (hn : 1 < n) : (Finset.range n).Nontrivial := by
  rw [Finset.Nontrivial, Finset.coe_range]
  exact ⟨0, Nat.zero_lt_one.trans hn, 1, hn, Nat.zero_ne_one⟩
Nontriviality of the Finite Range $\{0, \ldots, n-1\}$ for $n > 1$
Informal description
For any natural number $n$ such that $1 < n$, the finite set $\{0, 1, \ldots, n-1\}$ is nontrivial, meaning it contains at least two distinct elements.
Finset.exists_nat_subset_range theorem
(s : Finset ℕ) : ∃ n : ℕ, s ⊆ range n
Full source
theorem exists_nat_subset_range (s : Finset ) : ∃ n : ℕ, s ⊆ range n :=
  s.induction_on (by simp)
    fun a _ _ ⟨n, hn⟩ => ⟨max (a + 1) n, insert_subset (by simp) (hn.trans (by simp))⟩
Finite Subset of Natural Numbers is Contained in Some Range
Informal description
For any finite set $s$ of natural numbers, there exists a natural number $n$ such that $s$ is a subset of $\{0, 1, \ldots, n-1\}$.
notMemRangeEquiv definition
(k : ℕ) : { n // n ∉ range k } ≃ ℕ
Full source
/-- Equivalence between the set of natural numbers which are `≥ k` and `ℕ`, given by `n → n - k`. -/
def notMemRangeEquiv (k : ) : { n // n ∉ range k }{ n // n ∉ range k } ≃ ℕ where
  toFun i := i.1 - k
  invFun j := ⟨j + k, by simp⟩
  left_inv j := by
    rw [Subtype.ext_iff_val]
    apply Nat.sub_add_cancel
    simpa using j.2
  right_inv _ := Nat.add_sub_cancel_right _ _
Bijection between natural numbers outside range and all natural numbers
Informal description
For any natural number \( k \), there is a bijection between the set of natural numbers not in the range \(\{0, 1, \ldots, k-1\}\) and the set of all natural numbers \(\mathbb{N}\). The bijection is given by the function \( n \mapsto n - k \) in one direction and \( j \mapsto j + k \) in the other direction.
coe_notMemRangeEquiv theorem
(k : ℕ) : (notMemRangeEquiv k : { n // n ∉ range k } → ℕ) = fun (i : { n // n ∉ range k }) => i - k
Full source
@[simp]
theorem coe_notMemRangeEquiv (k : ) :
    (notMemRangeEquiv k : { n // n ∉ range k }) = fun (i : { n // n ∉ range k }) => i - k :=
  rfl
Function Form of the Bijection for Numbers Outside Range
Informal description
For any natural number $k$, the function associated with the equivalence `notMemRangeEquiv k` maps a natural number $n$ not in the range $\{0, 1, \ldots, k-1\}$ to $n - k$.
coe_notMemRangeEquiv_symm theorem
(k : ℕ) : ((notMemRangeEquiv k).symm : ℕ → { n // n ∉ range k }) = fun j => ⟨j + k, by simp⟩
Full source
@[simp]
theorem coe_notMemRangeEquiv_symm (k : ) :
    ((notMemRangeEquiv k).symm : { n // n ∉ range k }) = fun j => ⟨j + k, by simp⟩ :=
  rfl
Inverse of the Bijection for Numbers Outside Range
Informal description
For any natural number $k$, the inverse of the bijection `notMemRangeEquiv k` maps a natural number $j$ to the pair $\langle j + k, \text{by simp}\rangle$, where $\text{by simp}$ denotes a proof that $j + k$ is not in the range $\{0, 1, \ldots, k-1\}$.