The areas / V03. Sets, finite structures and big operators
Mathlib.Data.Set.Operations
71 declarations and 7 deprecated aliases. Mathlib docs · Source
Basic definitions about sets
In this file we define various operations on sets.
We also provide basic lemmas needed to unfold the definitions.
More advanced theorems about these definitions are located in other files in Mathlib/Data/Set.
Main definitions
- complement of a set and set difference;
Set.preimage f s, a.k.a.f ⁻¹' s: preimage of a set;Set.range f: the range of a function; it is more general thanf '' univbecause it allows functions fromSort*;s ×ˢ t: product ofs : Set αandt : Set βas a set inα × β;Set.diagonal: the diagonal inα × α;Set.offDiag s: the part ofs ×ˢ sthat is off the diagonal;Set.pi: indexed product of a family of sets∀ i, Set (α i), as a set in∀ i, α i;Set.EqOn f g s: the predicate saying that two functions are equal on a set;Set.MapsTo f s t: the predicate saying thatfsends all points ofstot;Set.MapsTo.restrict: restrictf : α → βtof' : s → tprovided thatSet.MapsTo f s t;Set.restrictPreimage: restrictf : α → βtof' : (f ⁻¹' t) → t;Set.InjOn: the predicate saying thatfis injective on a set;Set.SurjOn f s t: the predicate saying thatt ⊆ f '' s;Set.BijOn f s t: the predicate saying thatfis injective onsandf '' s = t;Set.graphOn: the graph of a function on a set;Set.LeftInvOn,Set.RightInvOn,Set.InvOn: the predicates saying thatf'is a left, right or two-sided inverse offons,t, or both;Set.image2: the image of a pair of sets under a binary operation, mostly useful to define pointwise algebraic operations on sets;Set.seq: monadicseqoperation on sets; we don't use monadic notation to ensure support for maps between different universes.
Notation
f '' s: image of a set;f ⁻¹' s: preimage of a set;s ×ˢ t: the product of sets;s ∪ t: the union of two sets;s ∩ t: the intersection of two sets;sᶜ: the complement of a set;s \ t: the difference of two sets.
Tags
set, image, preimage
Lemmas about mem and Set.ofPred
Operations
theorem Subtype.coind.congr_simp E1 #
∀ {α : Sort u_4} {β : Sort u_5} (f f_1 : α → β) (e_f : f = f_1) {p : β → Prop} (h : ∀ (a : α), p (f a)) (a a_1 : α),
a = a_1 → Subtype.coind f h a = Subtype.coind f_1 ⋯ a_1
theorem Set.mem_ofPred_eq E0 #
∀ {α : Type u} {x : α} {p : α → Prop}, (x ∈ {y | p y}) = p x
theorem Set.mem_ofPred E0 #
∀ {α : Type u} {a : α} {p : α → Prop}, a ∈ {x | p x} ↔ p a
theorem Membership.mem.out E1 #
∀ {α : Type u} {a : α} {p : α → Prop}, a ∈ {x | p x} → p a
If h : a ∈ {x | p x} then h.out : p x. These are definitionally equal, but this can
nevertheless be useful for various reasons, e.g. to apply further projection notation or in an
argument to simp.
theorem Set.notMem_ofPred_iff E0 #
∀ {α : Type u} {a : α} {p : α → Prop}, a ∉ {x | p x} ↔ ¬p a
theorem Set.ofPred_mem_eq E0 #
∀ {α : Type u} {s : Set α}, {x | x ∈ s} = s
theorem Set.mem_univ E0 #
∀ {α : Type u} (x : α), x ∈ Set.univ
instance Set.instCompl E0 #
{α : Type u} → Compl (Set α)
theorem Set.mem_compl_iff E0 #
∀ {α : Type u} (s : Set α) (x : α), x ∈ sᶜ ↔ x ∉ s
theorem Set.sdiff_eq E0 #
∀ {α : Type u} (s t : Set α), s \ t = s ∩ tᶜ
theorem Set.mem_sdiff E0 #
∀ {α : Type u} {s t : Set α} (x : α), x ∈ s \ t ↔ x ∈ s ∧ x ∉ t
theorem Set.mem_sdiff_of_mem E0 #
∀ {α : Type u} {s t : Set α} {x : α}, x ∈ s → x ∉ t → x ∈ s \ t
def Set.preimage E1 #
{α : Type u} → {β : Type v} → (α → β) → Set β → Set α
The preimage of s : Set β by f : α → β, written f ⁻¹' s,
is the set of x : α such that f x ∈ s.
def Set.«term_⁻¹'_» E1 #
Lean.TrailingParserDescr
f ⁻¹' t denotes the preimage of t : Set β under the function f : α → β.
theorem Set.mem_preimage E0 #
∀ {α : Type u} {β : Type v} {f : α → β} {s : Set β} {a : α}, a ∈ f ⁻¹' s ↔ f a ∈ s
def Set.term_''_ E1 #
Lean.TrailingParserDescr
f '' s denotes the image of s : Set α under the function f : α → β.
theorem Set.mem_image E0 #
∀ {α : Type u} {β : Type v} (f : α → β) (s : Set α) (y : β), y ∈ f '' s ↔ ∃ x ∈ s, f x = y
theorem Set.mem_image_of_mem E0 #
∀ {α : Type u} {β : Type v} (f : α → β) {x : α} {a : Set α}, x ∈ a → f x ∈ f '' a
def Set.imageFactorization E1 #
{α : Type u} → {β : Type v} → (f : α → β) → (s : Set α) → ↑s → ↑(f '' s)
Restriction of f to s factors through s.imageFactorization f : s → f '' s.
def Set.kernImage E1 #
{α : Type u} → {β : Type v} → (α → β) → Set α → Set β
kernImage f s is the set of y such that f ⁻¹ y ⊆ s.
theorem Set.subset_kernImage_iff E0 #
∀ {α : Type u} {β : Type v} {s : Set β} {t : Set α} {f : α → β}, s ⊆ Set.kernImage f t ↔ f ⁻¹' s ⊆ t
def Set.range E1 #
{α : Type u} → {ι : Sort u_1} → (ι → α) → Set α
Range of a function.
This function is more flexible than f '' univ, as the image requires that the domain is in Type
and not an arbitrary Sort.
theorem Set.mem_range E0 #
∀ {α : Type u} {ι : Sort u_1} {f : ι → α} {x : α}, x ∈ Set.range f ↔ ∃ y, f y = x
theorem Set.mem_range_self E0 #
∀ {α : Type u} {ι : Sort u_1} {f : ι → α} (i : ι), f i ∈ Set.range f
def Set.rangeFactorization E1 #
{α : Type u} → {ι : Sort u_1} → (f : ι → α) → ι → ↑(Set.range f)
Any map f : ι → α factors through a map rangeFactorization f : ι → range f.
theorem Set.rangeFactorization_injective E0 #
∀ {α : Type u} {ι : Sort u_1} {f : ι → α}, Function.Injective (Set.rangeFactorization f) ↔ Function.Injective f
theorem Set.rangeFactorization_surjective E0 #
∀ {α : Type u} {ι : Sort u_1} {f : ι → α}, Function.Surjective (Set.rangeFactorization f)
theorem Set.rangeFactorization_bijective E0 #
∀ {α : Type u} {ι : Sort u_1} {f : ι → α}, Function.Bijective (Set.rangeFactorization f) ↔ Function.Injective f
theorem Set.rangeFactorization_eq_rangeFactorization_iff E0 #
∀ {ι : Sort u_2} {α : Type u_3} {f : ι → α} (a b : ι),
Set.rangeFactorization f a = Set.rangeFactorization f b ↔ f a = f b
theorem Set.rangeFactorization_eq_iff E0 #
∀ {ι : Sort u_2} {α : Type u_3} {f : ι → α} (a : ι) (b : ↑(Set.range f)), Set.rangeFactorization f a = b ↔ f a = ↑b
def Set.rangeSplitting E1 #
{α : Type u} → {β : Type v} → (f : α → β) → ↑(Set.range f) → α
We can use the axiom of choice to pick a preimage for every element of range f.
theorem Set.apply_rangeSplitting E1 #
∀ {α : Type u} {β : Type v} (f : α → β) (x : ↑(Set.range f)), f (Set.rangeSplitting f x) = ↑x
theorem Set.comp_rangeSplitting E0 #
∀ {α : Type u} {β : Type v} (f : α → β), f ∘ Set.rangeSplitting f = Subtype.val
theorem Set.Subtype.range_coind E1 #
∀ {α : Type u} {β : Type v} (f : α → β) {p : β → Prop} (h : ∀ (a : α), p (f a)),
Set.range (Subtype.coind f h) = Subtype.val ⁻¹' Set.range f
def Set.prod E3 #
{α : Type u} → {β : Type v} → Set α → Set β → Set (α × β)
The Cartesian product Set.prod s t is the set of (a, b) such that a ∈ s and b ∈ t.
instance Set.instSProd E0 #
{α : Type u} → {β : Type v} → SProd (Set α) (Set β) (Set (α × β))
theorem Set.prod_eq E0 #
∀ {α : Type u} {β : Type v} (s : Set α) (t : Set β), s ×ˢ t = Prod.fst ⁻¹' s ∩ Prod.snd ⁻¹' t
theorem Set.mem_prod_eq E0 #
∀ {α : Type u} {β : Type v} {s : Set α} {t : Set β} {p : α × β}, (p ∈ s ×ˢ t) = (p.1 ∈ s ∧ p.2 ∈ t)
theorem Set.mem_prod E0 #
∀ {α : Type u} {β : Type v} {s : Set α} {t : Set β} {p : α × β}, p ∈ s ×ˢ t ↔ p.1 ∈ s ∧ p.2 ∈ t
theorem Set.prodMk_mem_set_prod_eq E0 #
∀ {α : Type u} {β : Type v} {a : α} {b : β} {s : Set α} {t : Set β}, ((a, b) ∈ s ×ˢ t) = (a ∈ s ∧ b ∈ t)
theorem Set.mk_mem_prod E1 #
∀ {α : Type u} {β : Type v} {a : α} {b : β} {s : Set α} {t : Set β}, a ∈ s → b ∈ t → (a, b) ∈ s ×ˢ t
theorem Set.prod_image_left E1 #
∀ {α : Type u} {β : Type v} {γ : Type w} (f : α → γ) (s : Set α) (t : Set β),
(f '' s) ×ˢ t = (fun x ↦ (f x.1, x.2)) '' s ×ˢ t
theorem Set.prod_image_right E1 #
∀ {α : Type u} {β : Type v} {γ : Type w} (f : α → γ) (s : Set α) (t : Set β),
t ×ˢ (f '' s) = (fun x ↦ (x.1, f x.2)) '' t ×ˢ s
def Set.diagonal E3 #
(α : Type u_1) → Set (α × α)
diagonal α is the set of α × α consisting of all pairs of the form (a, a).
theorem Set.mem_diagonal E0 #
∀ {α : Type u} (x : α), (x, x) ∈ Set.diagonal α
theorem Set.mem_diagonal_iff E0 #
∀ {α : Type u} {x : α × α}, x ∈ Set.diagonal α ↔ x.1 = x.2
def Set.offDiag E3 #
{α : Type u} → Set α → Set (α × α)
The off-diagonal of a set s is the set of pairs (a, b) with a, b ∈ s and a ≠ b.
theorem Set.mem_offDiag E0 #
∀ {α : Type u} {x : α × α} {s : Set α}, x ∈ s.offDiag ↔ x.1 ∈ s ∧ x.2 ∈ s ∧ x.1 ≠ x.2
def Set.pi E3 #
{ι : Type u_1} → {α : ι → Type u_2} → Set ι → ((i : ι) → Set (α i)) → Set ((i : ι) → α i)
Given an index set ι and a family of sets t : Π i, Set (α i), pi s t
is the set of dependent functions f : Πa, π a such that f i belongs to t i
whenever i ∈ s.
theorem Set.mem_pi E0 #
∀ {ι : Type u_1} {α : ι → Type u_2} {s : Set ι} {t : (i : ι) → Set (α i)} {f : (i : ι) → α i},
f ∈ s.pi t ↔ ∀ i ∈ s, f i ∈ t i
theorem Set.mem_univ_pi E0 #
∀ {ι : Type u_1} {α : ι → Type u_2} {t : (i : ι) → Set (α i)} {f : (i : ι) → α i},
f ∈ Set.univ.pi t ↔ ∀ (i : ι), f i ∈ t i
def Set.EqOn E1 #
{α : Type u} → {β : Type v} → (α → β) → (α → β) → Set α → Prop
Two functions f₁ f₂ : α → β are equal on s if f₁ x = f₂ x for all x ∈ s.
def Set.MapsTo E1 #
{α : Type u} → {β : Type v} → (α → β) → Set α → Set β → Prop
MapsTo f s t means that the image of s is contained in t.
theorem Set.mapsTo_image E1 #
∀ {α : Type u} {β : Type v} (f : α → β) (s : Set α), Set.MapsTo f s (f '' s)
theorem Set.mapsTo_preimage E1 #
∀ {α : Type u} {β : Type v} (f : α → β) (t : Set β), Set.MapsTo f (f ⁻¹' t) t
def Set.MapsTo.restrict E3 #
{α : Type u} → {β : Type v} → (f : α → β) → (s : Set α) → (t : Set β) → Set.MapsTo f s t → ↑s → ↑t
Given a map f sending s : Set α into t : Set β, restrict domain of f to s
and the codomain to t. Same as Subtype.map.
def Set.restrictPreimage E3 #
{α : Type u} → {β : Type v} → (t : Set β) → (f : α → β) → ↑(f ⁻¹' t) → ↑t
The restriction of a function onto the preimage of a set.
theorem Set.restrictPreimage_coe E0 #
∀ {α : Type u} {β : Type v} (t : Set β) (f : α → β) (a : ↑(f ⁻¹' t)), ↑(t.restrictPreimage f a) = f ↑a
def Set.InjOn E3 #
{α : Type u} → {β : Type v} → (α → β) → Set α → Prop
f is injective on s if the restriction of f to s is injective.
def Set.graphOn E3 #
{α : Type u} → {β : Type v} → (α → β) → Set α → Set (α × β)
The graph of a function f : α → β on a set s.
def Set.SurjOn E1 #
{α : Type u} → {β : Type v} → (α → β) → Set α → Set β → Prop
f is surjective from s to t if t is contained in the image of s.
def Set.BijOn E1 #
{α : Type u} → {β : Type v} → (α → β) → Set α → Set β → Prop
f is bijective from s to t if f is injective on s and f '' s = t.
def Set.LeftInvOn E3 #
{α : Type u} → {β : Type v} → (β → α) → (α → β) → Set α → Prop
g is a left inverse to f on s means that g (f x) = x for all x ∈ s.
abbrev Set.RightInvOn E3 #
{α : Type u} → {β : Type v} → (β → α) → (α → β) → Set β → Prop
g is a right inverse to f on t if f (g x) = x for all x ∈ t.
def Set.InvOn E3 #
{α : Type u} → {β : Type v} → (β → α) → (α → β) → Set α → Set β → Prop
g is an inverse to f viewed as a map from s to t
def Set.image2 E3 #
{α : Type u} → {β : Type v} → {γ : Type w} → (α → β → γ) → Set α → Set β → Set γ
The image of a binary function f : α → β → γ as a function Set α → Set β → Set γ.
Mathematically this should be thought of as the image of the corresponding function α × β → γ.
theorem Set.mem_image2 E0 #
∀ {α : Type u} {β : Type v} {γ : Type w} {f : α → β → γ} {s : Set α} {t : Set β} {c : γ},
c ∈ Set.image2 f s t ↔ ∃ a ∈ s, ∃ b ∈ t, f a b = c
theorem Set.mem_image2_of_mem E0 #
∀ {α : Type u} {β : Type v} {γ : Type w} {f : α → β → γ} {s : Set α} {t : Set β} {a : α} {b : β},
a ∈ s → b ∈ t → f a b ∈ Set.image2 f s t
def Set.seq E3 #
{α : Type u} → {β : Type v} → Set (α → β) → Set α → Set β
Given a set s of functions α → β and t : Set α, seq s t is the union of f '' t over
all f ∈ s.
theorem Set.mem_seq_iff E0 #
∀ {α : Type u} {β : Type v} {s : Set (α → β)} {t : Set α} {b : β}, b ∈ s.seq t ↔ ∃ f ∈ s, ∃ a ∈ t, f a = b
theorem Set.seq_eq_image2 E1 #
∀ {α : Type u} {β : Type v} (s : Set (α → β)) (t : Set α), s.seq t = Set.image2 (fun f a ↦ f a) s t
Deprecated aliases
| Name | New name | Since |
|---|---|---|
Set.diff_eq | Set.sdiff_eq | 2026-06-03 |
Set.mem_diff | Set.mem_sdiff | 2026-06-03 |
Set.mem_diff_of_mem | Set.mem_sdiff_of_mem | 2026-06-03 |
Set.mem_setOf | Set.mem_ofPred | 2026-07-09 |
Set.mem_setOf_eq | Set.mem_ofPred_eq | 2026-07-09 |
Set.notMem_setOf_iff | Set.notMem_ofPred_iff | 2026-07-09 |
Set.setOf_mem_eq | Set.ofPred_mem_eq | 2026-07-09 |