state
stringlengths 0
159k
| srcUpToTactic
stringlengths 387
167k
| nextTactic
stringlengths 3
9k
| declUpToTactic
stringlengths 22
11.5k
| declId
stringlengths 38
95
| decl
stringlengths 16
1.89k
| file_tag
stringlengths 17
73
|
---|---|---|---|---|---|---|
case zero
α : Type u_1
β : Type u_2
γ : Type u_3
ι : Sort u_4
ι' : Sort u_5
f✝ : α → β
g : β → γ
f : α → α
⊢ preimage f^[Nat.zero] = (preimage f)^[Nat.zero]
|
/-
Copyright (c) 2014 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Leonardo de Moura
-/
import Mathlib.Data.Set.Basic
#align_import data.set.image from "leanprover-community/mathlib"@"001ffdc42920050657fd45bd2b8bfbec8eaaeb29"
/-!
# Images and preimages of sets
## Main definitions
* `preimage f t : Set α` : the preimage f⁻¹(t) (written `f ⁻¹' t` in Lean) of a subset of β.
* `range f : Set β` : the image of `univ` under `f`.
Also works for `{p : Prop} (f : p → α)` (unlike `image`)
## Notation
* `f ⁻¹' t` for `Set.preimage f t`
* `f '' s` for `Set.image f s`
## Tags
set, sets, image, preimage, pre-image, range
-/
set_option autoImplicit true
universe u v
open Function Set
namespace Set
variable {α β γ : Type*} {ι ι' : Sort*}
/-! ### Inverse image -/
/-- The preimage of `s : Set β` by `f : α → β`, written `f ⁻¹' s`,
is the set of `x : α` such that `f x ∈ s`. -/
def preimage {α : Type u} {β : Type v} (f : α → β) (s : Set β) : Set α :=
{ x | f x ∈ s }
#align set.preimage Set.preimage
/-- `f ⁻¹' t` denotes the preimage of `t : Set β` under the function `f : α → β`. -/
infixl:80 " ⁻¹' " => preimage
section Preimage
variable {f : α → β} {g : β → γ}
@[simp]
theorem preimage_empty : f ⁻¹' ∅ = ∅ :=
rfl
#align set.preimage_empty Set.preimage_empty
@[simp, mfld_simps]
theorem mem_preimage {s : Set β} {a : α} : a ∈ f ⁻¹' s ↔ f a ∈ s :=
Iff.rfl
#align set.mem_preimage Set.mem_preimage
theorem preimage_congr {f g : α → β} {s : Set β} (h : ∀ x : α, f x = g x) : f ⁻¹' s = g ⁻¹' s := by
congr with x
simp [h]
#align set.preimage_congr Set.preimage_congr
@[gcongr]
theorem preimage_mono {s t : Set β} (h : s ⊆ t) : f ⁻¹' s ⊆ f ⁻¹' t := fun _ hx => h hx
#align set.preimage_mono Set.preimage_mono
@[simp, mfld_simps]
theorem preimage_univ : f ⁻¹' univ = univ :=
rfl
#align set.preimage_univ Set.preimage_univ
theorem subset_preimage_univ {s : Set α} : s ⊆ f ⁻¹' univ :=
subset_univ _
#align set.subset_preimage_univ Set.subset_preimage_univ
@[simp, mfld_simps]
theorem preimage_inter {s t : Set β} : f ⁻¹' (s ∩ t) = f ⁻¹' s ∩ f ⁻¹' t :=
rfl
#align set.preimage_inter Set.preimage_inter
@[simp]
theorem preimage_union {s t : Set β} : f ⁻¹' (s ∪ t) = f ⁻¹' s ∪ f ⁻¹' t :=
rfl
#align set.preimage_union Set.preimage_union
@[simp]
theorem preimage_compl {s : Set β} : f ⁻¹' sᶜ = (f ⁻¹' s)ᶜ :=
rfl
#align set.preimage_compl Set.preimage_compl
@[simp]
theorem preimage_diff (f : α → β) (s t : Set β) : f ⁻¹' (s \ t) = f ⁻¹' s \ f ⁻¹' t :=
rfl
#align set.preimage_diff Set.preimage_diff
@[simp]
lemma preimage_symmDiff {f : α → β} (s t : Set β) : f ⁻¹' (s ∆ t) = (f ⁻¹' s) ∆ (f ⁻¹' t) :=
rfl
#align set.preimage_symm_diff Set.preimage_symmDiff
@[simp]
theorem preimage_ite (f : α → β) (s t₁ t₂ : Set β) :
f ⁻¹' s.ite t₁ t₂ = (f ⁻¹' s).ite (f ⁻¹' t₁) (f ⁻¹' t₂) :=
rfl
#align set.preimage_ite Set.preimage_ite
@[simp]
theorem preimage_setOf_eq {p : α → Prop} {f : β → α} : f ⁻¹' { a | p a } = { a | p (f a) } :=
rfl
#align set.preimage_set_of_eq Set.preimage_setOf_eq
@[simp]
theorem preimage_id_eq : preimage (id : α → α) = id :=
rfl
#align set.preimage_id_eq Set.preimage_id_eq
@[mfld_simps]
theorem preimage_id {s : Set α} : id ⁻¹' s = s :=
rfl
#align set.preimage_id Set.preimage_id
@[simp, mfld_simps]
theorem preimage_id' {s : Set α} : (fun x => x) ⁻¹' s = s :=
rfl
#align set.preimage_id' Set.preimage_id'
@[simp]
theorem preimage_const_of_mem {b : β} {s : Set β} (h : b ∈ s) : (fun _ : α => b) ⁻¹' s = univ :=
eq_univ_of_forall fun _ => h
#align set.preimage_const_of_mem Set.preimage_const_of_mem
@[simp]
theorem preimage_const_of_not_mem {b : β} {s : Set β} (h : b ∉ s) : (fun _ : α => b) ⁻¹' s = ∅ :=
eq_empty_of_subset_empty fun _ hx => h hx
#align set.preimage_const_of_not_mem Set.preimage_const_of_not_mem
theorem preimage_const (b : β) (s : Set β) [Decidable (b ∈ s)] :
(fun _ : α => b) ⁻¹' s = if b ∈ s then univ else ∅ := by
split_ifs with hb
exacts [preimage_const_of_mem hb, preimage_const_of_not_mem hb]
#align set.preimage_const Set.preimage_const
/-- If preimage of each singleton under `f : α → β` is either empty or the whole type,
then `f` is a constant. -/
lemma exists_eq_const_of_preimage_singleton [Nonempty β] {f : α → β}
(hf : ∀ b : β, f ⁻¹' {b} = ∅ ∨ f ⁻¹' {b} = univ) : ∃ b, f = const α b := by
rcases em (∃ b, f ⁻¹' {b} = univ) with ⟨b, hb⟩ | hf'
· exact ⟨b, funext fun x ↦ eq_univ_iff_forall.1 hb x⟩
· have : ∀ x b, f x ≠ b := fun x b ↦
eq_empty_iff_forall_not_mem.1 ((hf b).resolve_right fun h ↦ hf' ⟨b, h⟩) x
exact ⟨Classical.arbitrary β, funext fun x ↦ absurd rfl (this x _)⟩
theorem preimage_comp {s : Set γ} : g ∘ f ⁻¹' s = f ⁻¹' (g ⁻¹' s) :=
rfl
#align set.preimage_comp Set.preimage_comp
theorem preimage_comp_eq : preimage (g ∘ f) = preimage f ∘ preimage g :=
rfl
#align set.preimage_comp_eq Set.preimage_comp_eq
theorem preimage_iterate_eq {f : α → α} {n : ℕ} : Set.preimage f^[n] = (Set.preimage f)^[n] := by
induction' n with n ih; ·
|
simp
|
theorem preimage_iterate_eq {f : α → α} {n : ℕ} : Set.preimage f^[n] = (Set.preimage f)^[n] := by
induction' n with n ih; ·
|
Mathlib.Data.Set.Image.171_0.IJFiTzmYGOCpPSd
|
theorem preimage_iterate_eq {f : α → α} {n : ℕ} : Set.preimage f^[n] = (Set.preimage f)^[n]
|
Mathlib_Data_Set_Image
|
case succ
α : Type u_1
β : Type u_2
γ : Type u_3
ι : Sort u_4
ι' : Sort u_5
f✝ : α → β
g : β → γ
f : α → α
n : ℕ
ih : preimage f^[n] = (preimage f)^[n]
⊢ preimage f^[Nat.succ n] = (preimage f)^[Nat.succ n]
|
/-
Copyright (c) 2014 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Leonardo de Moura
-/
import Mathlib.Data.Set.Basic
#align_import data.set.image from "leanprover-community/mathlib"@"001ffdc42920050657fd45bd2b8bfbec8eaaeb29"
/-!
# Images and preimages of sets
## Main definitions
* `preimage f t : Set α` : the preimage f⁻¹(t) (written `f ⁻¹' t` in Lean) of a subset of β.
* `range f : Set β` : the image of `univ` under `f`.
Also works for `{p : Prop} (f : p → α)` (unlike `image`)
## Notation
* `f ⁻¹' t` for `Set.preimage f t`
* `f '' s` for `Set.image f s`
## Tags
set, sets, image, preimage, pre-image, range
-/
set_option autoImplicit true
universe u v
open Function Set
namespace Set
variable {α β γ : Type*} {ι ι' : Sort*}
/-! ### Inverse image -/
/-- The preimage of `s : Set β` by `f : α → β`, written `f ⁻¹' s`,
is the set of `x : α` such that `f x ∈ s`. -/
def preimage {α : Type u} {β : Type v} (f : α → β) (s : Set β) : Set α :=
{ x | f x ∈ s }
#align set.preimage Set.preimage
/-- `f ⁻¹' t` denotes the preimage of `t : Set β` under the function `f : α → β`. -/
infixl:80 " ⁻¹' " => preimage
section Preimage
variable {f : α → β} {g : β → γ}
@[simp]
theorem preimage_empty : f ⁻¹' ∅ = ∅ :=
rfl
#align set.preimage_empty Set.preimage_empty
@[simp, mfld_simps]
theorem mem_preimage {s : Set β} {a : α} : a ∈ f ⁻¹' s ↔ f a ∈ s :=
Iff.rfl
#align set.mem_preimage Set.mem_preimage
theorem preimage_congr {f g : α → β} {s : Set β} (h : ∀ x : α, f x = g x) : f ⁻¹' s = g ⁻¹' s := by
congr with x
simp [h]
#align set.preimage_congr Set.preimage_congr
@[gcongr]
theorem preimage_mono {s t : Set β} (h : s ⊆ t) : f ⁻¹' s ⊆ f ⁻¹' t := fun _ hx => h hx
#align set.preimage_mono Set.preimage_mono
@[simp, mfld_simps]
theorem preimage_univ : f ⁻¹' univ = univ :=
rfl
#align set.preimage_univ Set.preimage_univ
theorem subset_preimage_univ {s : Set α} : s ⊆ f ⁻¹' univ :=
subset_univ _
#align set.subset_preimage_univ Set.subset_preimage_univ
@[simp, mfld_simps]
theorem preimage_inter {s t : Set β} : f ⁻¹' (s ∩ t) = f ⁻¹' s ∩ f ⁻¹' t :=
rfl
#align set.preimage_inter Set.preimage_inter
@[simp]
theorem preimage_union {s t : Set β} : f ⁻¹' (s ∪ t) = f ⁻¹' s ∪ f ⁻¹' t :=
rfl
#align set.preimage_union Set.preimage_union
@[simp]
theorem preimage_compl {s : Set β} : f ⁻¹' sᶜ = (f ⁻¹' s)ᶜ :=
rfl
#align set.preimage_compl Set.preimage_compl
@[simp]
theorem preimage_diff (f : α → β) (s t : Set β) : f ⁻¹' (s \ t) = f ⁻¹' s \ f ⁻¹' t :=
rfl
#align set.preimage_diff Set.preimage_diff
@[simp]
lemma preimage_symmDiff {f : α → β} (s t : Set β) : f ⁻¹' (s ∆ t) = (f ⁻¹' s) ∆ (f ⁻¹' t) :=
rfl
#align set.preimage_symm_diff Set.preimage_symmDiff
@[simp]
theorem preimage_ite (f : α → β) (s t₁ t₂ : Set β) :
f ⁻¹' s.ite t₁ t₂ = (f ⁻¹' s).ite (f ⁻¹' t₁) (f ⁻¹' t₂) :=
rfl
#align set.preimage_ite Set.preimage_ite
@[simp]
theorem preimage_setOf_eq {p : α → Prop} {f : β → α} : f ⁻¹' { a | p a } = { a | p (f a) } :=
rfl
#align set.preimage_set_of_eq Set.preimage_setOf_eq
@[simp]
theorem preimage_id_eq : preimage (id : α → α) = id :=
rfl
#align set.preimage_id_eq Set.preimage_id_eq
@[mfld_simps]
theorem preimage_id {s : Set α} : id ⁻¹' s = s :=
rfl
#align set.preimage_id Set.preimage_id
@[simp, mfld_simps]
theorem preimage_id' {s : Set α} : (fun x => x) ⁻¹' s = s :=
rfl
#align set.preimage_id' Set.preimage_id'
@[simp]
theorem preimage_const_of_mem {b : β} {s : Set β} (h : b ∈ s) : (fun _ : α => b) ⁻¹' s = univ :=
eq_univ_of_forall fun _ => h
#align set.preimage_const_of_mem Set.preimage_const_of_mem
@[simp]
theorem preimage_const_of_not_mem {b : β} {s : Set β} (h : b ∉ s) : (fun _ : α => b) ⁻¹' s = ∅ :=
eq_empty_of_subset_empty fun _ hx => h hx
#align set.preimage_const_of_not_mem Set.preimage_const_of_not_mem
theorem preimage_const (b : β) (s : Set β) [Decidable (b ∈ s)] :
(fun _ : α => b) ⁻¹' s = if b ∈ s then univ else ∅ := by
split_ifs with hb
exacts [preimage_const_of_mem hb, preimage_const_of_not_mem hb]
#align set.preimage_const Set.preimage_const
/-- If preimage of each singleton under `f : α → β` is either empty or the whole type,
then `f` is a constant. -/
lemma exists_eq_const_of_preimage_singleton [Nonempty β] {f : α → β}
(hf : ∀ b : β, f ⁻¹' {b} = ∅ ∨ f ⁻¹' {b} = univ) : ∃ b, f = const α b := by
rcases em (∃ b, f ⁻¹' {b} = univ) with ⟨b, hb⟩ | hf'
· exact ⟨b, funext fun x ↦ eq_univ_iff_forall.1 hb x⟩
· have : ∀ x b, f x ≠ b := fun x b ↦
eq_empty_iff_forall_not_mem.1 ((hf b).resolve_right fun h ↦ hf' ⟨b, h⟩) x
exact ⟨Classical.arbitrary β, funext fun x ↦ absurd rfl (this x _)⟩
theorem preimage_comp {s : Set γ} : g ∘ f ⁻¹' s = f ⁻¹' (g ⁻¹' s) :=
rfl
#align set.preimage_comp Set.preimage_comp
theorem preimage_comp_eq : preimage (g ∘ f) = preimage f ∘ preimage g :=
rfl
#align set.preimage_comp_eq Set.preimage_comp_eq
theorem preimage_iterate_eq {f : α → α} {n : ℕ} : Set.preimage f^[n] = (Set.preimage f)^[n] := by
induction' n with n ih; · simp
|
rw [iterate_succ, iterate_succ', preimage_comp_eq, ih]
|
theorem preimage_iterate_eq {f : α → α} {n : ℕ} : Set.preimage f^[n] = (Set.preimage f)^[n] := by
induction' n with n ih; · simp
|
Mathlib.Data.Set.Image.171_0.IJFiTzmYGOCpPSd
|
theorem preimage_iterate_eq {f : α → α} {n : ℕ} : Set.preimage f^[n] = (Set.preimage f)^[n]
|
Mathlib_Data_Set_Image
|
α : Type u_1
β : Type u_2
γ : Type u_3
ι : Sort u_4
ι' : Sort u_5
f : α → β
g : β → γ
p : α → Prop
s : Set (Subtype p)
t : Set α
s_eq : s = Subtype.val ⁻¹' t
x : α
h : p x
⊢ { val := x, property := h } ∈ s ↔ x ∈ t
|
/-
Copyright (c) 2014 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Leonardo de Moura
-/
import Mathlib.Data.Set.Basic
#align_import data.set.image from "leanprover-community/mathlib"@"001ffdc42920050657fd45bd2b8bfbec8eaaeb29"
/-!
# Images and preimages of sets
## Main definitions
* `preimage f t : Set α` : the preimage f⁻¹(t) (written `f ⁻¹' t` in Lean) of a subset of β.
* `range f : Set β` : the image of `univ` under `f`.
Also works for `{p : Prop} (f : p → α)` (unlike `image`)
## Notation
* `f ⁻¹' t` for `Set.preimage f t`
* `f '' s` for `Set.image f s`
## Tags
set, sets, image, preimage, pre-image, range
-/
set_option autoImplicit true
universe u v
open Function Set
namespace Set
variable {α β γ : Type*} {ι ι' : Sort*}
/-! ### Inverse image -/
/-- The preimage of `s : Set β` by `f : α → β`, written `f ⁻¹' s`,
is the set of `x : α` such that `f x ∈ s`. -/
def preimage {α : Type u} {β : Type v} (f : α → β) (s : Set β) : Set α :=
{ x | f x ∈ s }
#align set.preimage Set.preimage
/-- `f ⁻¹' t` denotes the preimage of `t : Set β` under the function `f : α → β`. -/
infixl:80 " ⁻¹' " => preimage
section Preimage
variable {f : α → β} {g : β → γ}
@[simp]
theorem preimage_empty : f ⁻¹' ∅ = ∅ :=
rfl
#align set.preimage_empty Set.preimage_empty
@[simp, mfld_simps]
theorem mem_preimage {s : Set β} {a : α} : a ∈ f ⁻¹' s ↔ f a ∈ s :=
Iff.rfl
#align set.mem_preimage Set.mem_preimage
theorem preimage_congr {f g : α → β} {s : Set β} (h : ∀ x : α, f x = g x) : f ⁻¹' s = g ⁻¹' s := by
congr with x
simp [h]
#align set.preimage_congr Set.preimage_congr
@[gcongr]
theorem preimage_mono {s t : Set β} (h : s ⊆ t) : f ⁻¹' s ⊆ f ⁻¹' t := fun _ hx => h hx
#align set.preimage_mono Set.preimage_mono
@[simp, mfld_simps]
theorem preimage_univ : f ⁻¹' univ = univ :=
rfl
#align set.preimage_univ Set.preimage_univ
theorem subset_preimage_univ {s : Set α} : s ⊆ f ⁻¹' univ :=
subset_univ _
#align set.subset_preimage_univ Set.subset_preimage_univ
@[simp, mfld_simps]
theorem preimage_inter {s t : Set β} : f ⁻¹' (s ∩ t) = f ⁻¹' s ∩ f ⁻¹' t :=
rfl
#align set.preimage_inter Set.preimage_inter
@[simp]
theorem preimage_union {s t : Set β} : f ⁻¹' (s ∪ t) = f ⁻¹' s ∪ f ⁻¹' t :=
rfl
#align set.preimage_union Set.preimage_union
@[simp]
theorem preimage_compl {s : Set β} : f ⁻¹' sᶜ = (f ⁻¹' s)ᶜ :=
rfl
#align set.preimage_compl Set.preimage_compl
@[simp]
theorem preimage_diff (f : α → β) (s t : Set β) : f ⁻¹' (s \ t) = f ⁻¹' s \ f ⁻¹' t :=
rfl
#align set.preimage_diff Set.preimage_diff
@[simp]
lemma preimage_symmDiff {f : α → β} (s t : Set β) : f ⁻¹' (s ∆ t) = (f ⁻¹' s) ∆ (f ⁻¹' t) :=
rfl
#align set.preimage_symm_diff Set.preimage_symmDiff
@[simp]
theorem preimage_ite (f : α → β) (s t₁ t₂ : Set β) :
f ⁻¹' s.ite t₁ t₂ = (f ⁻¹' s).ite (f ⁻¹' t₁) (f ⁻¹' t₂) :=
rfl
#align set.preimage_ite Set.preimage_ite
@[simp]
theorem preimage_setOf_eq {p : α → Prop} {f : β → α} : f ⁻¹' { a | p a } = { a | p (f a) } :=
rfl
#align set.preimage_set_of_eq Set.preimage_setOf_eq
@[simp]
theorem preimage_id_eq : preimage (id : α → α) = id :=
rfl
#align set.preimage_id_eq Set.preimage_id_eq
@[mfld_simps]
theorem preimage_id {s : Set α} : id ⁻¹' s = s :=
rfl
#align set.preimage_id Set.preimage_id
@[simp, mfld_simps]
theorem preimage_id' {s : Set α} : (fun x => x) ⁻¹' s = s :=
rfl
#align set.preimage_id' Set.preimage_id'
@[simp]
theorem preimage_const_of_mem {b : β} {s : Set β} (h : b ∈ s) : (fun _ : α => b) ⁻¹' s = univ :=
eq_univ_of_forall fun _ => h
#align set.preimage_const_of_mem Set.preimage_const_of_mem
@[simp]
theorem preimage_const_of_not_mem {b : β} {s : Set β} (h : b ∉ s) : (fun _ : α => b) ⁻¹' s = ∅ :=
eq_empty_of_subset_empty fun _ hx => h hx
#align set.preimage_const_of_not_mem Set.preimage_const_of_not_mem
theorem preimage_const (b : β) (s : Set β) [Decidable (b ∈ s)] :
(fun _ : α => b) ⁻¹' s = if b ∈ s then univ else ∅ := by
split_ifs with hb
exacts [preimage_const_of_mem hb, preimage_const_of_not_mem hb]
#align set.preimage_const Set.preimage_const
/-- If preimage of each singleton under `f : α → β` is either empty or the whole type,
then `f` is a constant. -/
lemma exists_eq_const_of_preimage_singleton [Nonempty β] {f : α → β}
(hf : ∀ b : β, f ⁻¹' {b} = ∅ ∨ f ⁻¹' {b} = univ) : ∃ b, f = const α b := by
rcases em (∃ b, f ⁻¹' {b} = univ) with ⟨b, hb⟩ | hf'
· exact ⟨b, funext fun x ↦ eq_univ_iff_forall.1 hb x⟩
· have : ∀ x b, f x ≠ b := fun x b ↦
eq_empty_iff_forall_not_mem.1 ((hf b).resolve_right fun h ↦ hf' ⟨b, h⟩) x
exact ⟨Classical.arbitrary β, funext fun x ↦ absurd rfl (this x _)⟩
theorem preimage_comp {s : Set γ} : g ∘ f ⁻¹' s = f ⁻¹' (g ⁻¹' s) :=
rfl
#align set.preimage_comp Set.preimage_comp
theorem preimage_comp_eq : preimage (g ∘ f) = preimage f ∘ preimage g :=
rfl
#align set.preimage_comp_eq Set.preimage_comp_eq
theorem preimage_iterate_eq {f : α → α} {n : ℕ} : Set.preimage f^[n] = (Set.preimage f)^[n] := by
induction' n with n ih; · simp
rw [iterate_succ, iterate_succ', preimage_comp_eq, ih]
#align set.preimage_iterate_eq Set.preimage_iterate_eq
theorem preimage_preimage {g : β → γ} {f : α → β} {s : Set γ} :
f ⁻¹' (g ⁻¹' s) = (fun x => g (f x)) ⁻¹' s :=
preimage_comp.symm
#align set.preimage_preimage Set.preimage_preimage
theorem eq_preimage_subtype_val_iff {p : α → Prop} {s : Set (Subtype p)} {t : Set α} :
s = Subtype.val ⁻¹' t ↔ ∀ (x) (h : p x), (⟨x, h⟩ : Subtype p) ∈ s ↔ x ∈ t :=
⟨fun s_eq x h => by
|
rw [s_eq]
|
theorem eq_preimage_subtype_val_iff {p : α → Prop} {s : Set (Subtype p)} {t : Set α} :
s = Subtype.val ⁻¹' t ↔ ∀ (x) (h : p x), (⟨x, h⟩ : Subtype p) ∈ s ↔ x ∈ t :=
⟨fun s_eq x h => by
|
Mathlib.Data.Set.Image.181_0.IJFiTzmYGOCpPSd
|
theorem eq_preimage_subtype_val_iff {p : α → Prop} {s : Set (Subtype p)} {t : Set α} :
s = Subtype.val ⁻¹' t ↔ ∀ (x) (h : p x), (⟨x, h⟩ : Subtype p) ∈ s ↔ x ∈ t
|
Mathlib_Data_Set_Image
|
α : Type u_1
β : Type u_2
γ : Type u_3
ι : Sort u_4
ι' : Sort u_5
f : α → β
g : β → γ
p : α → Prop
s : Set (Subtype p)
t : Set α
s_eq : s = Subtype.val ⁻¹' t
x : α
h : p x
⊢ { val := x, property := h } ∈ Subtype.val ⁻¹' t ↔ x ∈ t
|
/-
Copyright (c) 2014 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Leonardo de Moura
-/
import Mathlib.Data.Set.Basic
#align_import data.set.image from "leanprover-community/mathlib"@"001ffdc42920050657fd45bd2b8bfbec8eaaeb29"
/-!
# Images and preimages of sets
## Main definitions
* `preimage f t : Set α` : the preimage f⁻¹(t) (written `f ⁻¹' t` in Lean) of a subset of β.
* `range f : Set β` : the image of `univ` under `f`.
Also works for `{p : Prop} (f : p → α)` (unlike `image`)
## Notation
* `f ⁻¹' t` for `Set.preimage f t`
* `f '' s` for `Set.image f s`
## Tags
set, sets, image, preimage, pre-image, range
-/
set_option autoImplicit true
universe u v
open Function Set
namespace Set
variable {α β γ : Type*} {ι ι' : Sort*}
/-! ### Inverse image -/
/-- The preimage of `s : Set β` by `f : α → β`, written `f ⁻¹' s`,
is the set of `x : α` such that `f x ∈ s`. -/
def preimage {α : Type u} {β : Type v} (f : α → β) (s : Set β) : Set α :=
{ x | f x ∈ s }
#align set.preimage Set.preimage
/-- `f ⁻¹' t` denotes the preimage of `t : Set β` under the function `f : α → β`. -/
infixl:80 " ⁻¹' " => preimage
section Preimage
variable {f : α → β} {g : β → γ}
@[simp]
theorem preimage_empty : f ⁻¹' ∅ = ∅ :=
rfl
#align set.preimage_empty Set.preimage_empty
@[simp, mfld_simps]
theorem mem_preimage {s : Set β} {a : α} : a ∈ f ⁻¹' s ↔ f a ∈ s :=
Iff.rfl
#align set.mem_preimage Set.mem_preimage
theorem preimage_congr {f g : α → β} {s : Set β} (h : ∀ x : α, f x = g x) : f ⁻¹' s = g ⁻¹' s := by
congr with x
simp [h]
#align set.preimage_congr Set.preimage_congr
@[gcongr]
theorem preimage_mono {s t : Set β} (h : s ⊆ t) : f ⁻¹' s ⊆ f ⁻¹' t := fun _ hx => h hx
#align set.preimage_mono Set.preimage_mono
@[simp, mfld_simps]
theorem preimage_univ : f ⁻¹' univ = univ :=
rfl
#align set.preimage_univ Set.preimage_univ
theorem subset_preimage_univ {s : Set α} : s ⊆ f ⁻¹' univ :=
subset_univ _
#align set.subset_preimage_univ Set.subset_preimage_univ
@[simp, mfld_simps]
theorem preimage_inter {s t : Set β} : f ⁻¹' (s ∩ t) = f ⁻¹' s ∩ f ⁻¹' t :=
rfl
#align set.preimage_inter Set.preimage_inter
@[simp]
theorem preimage_union {s t : Set β} : f ⁻¹' (s ∪ t) = f ⁻¹' s ∪ f ⁻¹' t :=
rfl
#align set.preimage_union Set.preimage_union
@[simp]
theorem preimage_compl {s : Set β} : f ⁻¹' sᶜ = (f ⁻¹' s)ᶜ :=
rfl
#align set.preimage_compl Set.preimage_compl
@[simp]
theorem preimage_diff (f : α → β) (s t : Set β) : f ⁻¹' (s \ t) = f ⁻¹' s \ f ⁻¹' t :=
rfl
#align set.preimage_diff Set.preimage_diff
@[simp]
lemma preimage_symmDiff {f : α → β} (s t : Set β) : f ⁻¹' (s ∆ t) = (f ⁻¹' s) ∆ (f ⁻¹' t) :=
rfl
#align set.preimage_symm_diff Set.preimage_symmDiff
@[simp]
theorem preimage_ite (f : α → β) (s t₁ t₂ : Set β) :
f ⁻¹' s.ite t₁ t₂ = (f ⁻¹' s).ite (f ⁻¹' t₁) (f ⁻¹' t₂) :=
rfl
#align set.preimage_ite Set.preimage_ite
@[simp]
theorem preimage_setOf_eq {p : α → Prop} {f : β → α} : f ⁻¹' { a | p a } = { a | p (f a) } :=
rfl
#align set.preimage_set_of_eq Set.preimage_setOf_eq
@[simp]
theorem preimage_id_eq : preimage (id : α → α) = id :=
rfl
#align set.preimage_id_eq Set.preimage_id_eq
@[mfld_simps]
theorem preimage_id {s : Set α} : id ⁻¹' s = s :=
rfl
#align set.preimage_id Set.preimage_id
@[simp, mfld_simps]
theorem preimage_id' {s : Set α} : (fun x => x) ⁻¹' s = s :=
rfl
#align set.preimage_id' Set.preimage_id'
@[simp]
theorem preimage_const_of_mem {b : β} {s : Set β} (h : b ∈ s) : (fun _ : α => b) ⁻¹' s = univ :=
eq_univ_of_forall fun _ => h
#align set.preimage_const_of_mem Set.preimage_const_of_mem
@[simp]
theorem preimage_const_of_not_mem {b : β} {s : Set β} (h : b ∉ s) : (fun _ : α => b) ⁻¹' s = ∅ :=
eq_empty_of_subset_empty fun _ hx => h hx
#align set.preimage_const_of_not_mem Set.preimage_const_of_not_mem
theorem preimage_const (b : β) (s : Set β) [Decidable (b ∈ s)] :
(fun _ : α => b) ⁻¹' s = if b ∈ s then univ else ∅ := by
split_ifs with hb
exacts [preimage_const_of_mem hb, preimage_const_of_not_mem hb]
#align set.preimage_const Set.preimage_const
/-- If preimage of each singleton under `f : α → β` is either empty or the whole type,
then `f` is a constant. -/
lemma exists_eq_const_of_preimage_singleton [Nonempty β] {f : α → β}
(hf : ∀ b : β, f ⁻¹' {b} = ∅ ∨ f ⁻¹' {b} = univ) : ∃ b, f = const α b := by
rcases em (∃ b, f ⁻¹' {b} = univ) with ⟨b, hb⟩ | hf'
· exact ⟨b, funext fun x ↦ eq_univ_iff_forall.1 hb x⟩
· have : ∀ x b, f x ≠ b := fun x b ↦
eq_empty_iff_forall_not_mem.1 ((hf b).resolve_right fun h ↦ hf' ⟨b, h⟩) x
exact ⟨Classical.arbitrary β, funext fun x ↦ absurd rfl (this x _)⟩
theorem preimage_comp {s : Set γ} : g ∘ f ⁻¹' s = f ⁻¹' (g ⁻¹' s) :=
rfl
#align set.preimage_comp Set.preimage_comp
theorem preimage_comp_eq : preimage (g ∘ f) = preimage f ∘ preimage g :=
rfl
#align set.preimage_comp_eq Set.preimage_comp_eq
theorem preimage_iterate_eq {f : α → α} {n : ℕ} : Set.preimage f^[n] = (Set.preimage f)^[n] := by
induction' n with n ih; · simp
rw [iterate_succ, iterate_succ', preimage_comp_eq, ih]
#align set.preimage_iterate_eq Set.preimage_iterate_eq
theorem preimage_preimage {g : β → γ} {f : α → β} {s : Set γ} :
f ⁻¹' (g ⁻¹' s) = (fun x => g (f x)) ⁻¹' s :=
preimage_comp.symm
#align set.preimage_preimage Set.preimage_preimage
theorem eq_preimage_subtype_val_iff {p : α → Prop} {s : Set (Subtype p)} {t : Set α} :
s = Subtype.val ⁻¹' t ↔ ∀ (x) (h : p x), (⟨x, h⟩ : Subtype p) ∈ s ↔ x ∈ t :=
⟨fun s_eq x h => by
rw [s_eq]
|
simp
|
theorem eq_preimage_subtype_val_iff {p : α → Prop} {s : Set (Subtype p)} {t : Set α} :
s = Subtype.val ⁻¹' t ↔ ∀ (x) (h : p x), (⟨x, h⟩ : Subtype p) ∈ s ↔ x ∈ t :=
⟨fun s_eq x h => by
rw [s_eq]
|
Mathlib.Data.Set.Image.181_0.IJFiTzmYGOCpPSd
|
theorem eq_preimage_subtype_val_iff {p : α → Prop} {s : Set (Subtype p)} {t : Set α} :
s = Subtype.val ⁻¹' t ↔ ∀ (x) (h : p x), (⟨x, h⟩ : Subtype p) ∈ s ↔ x ∈ t
|
Mathlib_Data_Set_Image
|
α : Type u_1
β : Type u_2
γ : Type u_3
ι : Sort u_4
ι' : Sort u_5
f : α → β
g : β → γ
p : α → Prop
s : Set (Subtype p)
t : Set α
h : ∀ (x : α) (h : p x), { val := x, property := h } ∈ s ↔ x ∈ t
x✝ : Subtype p
x : α
hx : p x
⊢ { val := x, property := hx } ∈ s ↔ { val := x, property := hx } ∈ Subtype.val ⁻¹' t
|
/-
Copyright (c) 2014 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Leonardo de Moura
-/
import Mathlib.Data.Set.Basic
#align_import data.set.image from "leanprover-community/mathlib"@"001ffdc42920050657fd45bd2b8bfbec8eaaeb29"
/-!
# Images and preimages of sets
## Main definitions
* `preimage f t : Set α` : the preimage f⁻¹(t) (written `f ⁻¹' t` in Lean) of a subset of β.
* `range f : Set β` : the image of `univ` under `f`.
Also works for `{p : Prop} (f : p → α)` (unlike `image`)
## Notation
* `f ⁻¹' t` for `Set.preimage f t`
* `f '' s` for `Set.image f s`
## Tags
set, sets, image, preimage, pre-image, range
-/
set_option autoImplicit true
universe u v
open Function Set
namespace Set
variable {α β γ : Type*} {ι ι' : Sort*}
/-! ### Inverse image -/
/-- The preimage of `s : Set β` by `f : α → β`, written `f ⁻¹' s`,
is the set of `x : α` such that `f x ∈ s`. -/
def preimage {α : Type u} {β : Type v} (f : α → β) (s : Set β) : Set α :=
{ x | f x ∈ s }
#align set.preimage Set.preimage
/-- `f ⁻¹' t` denotes the preimage of `t : Set β` under the function `f : α → β`. -/
infixl:80 " ⁻¹' " => preimage
section Preimage
variable {f : α → β} {g : β → γ}
@[simp]
theorem preimage_empty : f ⁻¹' ∅ = ∅ :=
rfl
#align set.preimage_empty Set.preimage_empty
@[simp, mfld_simps]
theorem mem_preimage {s : Set β} {a : α} : a ∈ f ⁻¹' s ↔ f a ∈ s :=
Iff.rfl
#align set.mem_preimage Set.mem_preimage
theorem preimage_congr {f g : α → β} {s : Set β} (h : ∀ x : α, f x = g x) : f ⁻¹' s = g ⁻¹' s := by
congr with x
simp [h]
#align set.preimage_congr Set.preimage_congr
@[gcongr]
theorem preimage_mono {s t : Set β} (h : s ⊆ t) : f ⁻¹' s ⊆ f ⁻¹' t := fun _ hx => h hx
#align set.preimage_mono Set.preimage_mono
@[simp, mfld_simps]
theorem preimage_univ : f ⁻¹' univ = univ :=
rfl
#align set.preimage_univ Set.preimage_univ
theorem subset_preimage_univ {s : Set α} : s ⊆ f ⁻¹' univ :=
subset_univ _
#align set.subset_preimage_univ Set.subset_preimage_univ
@[simp, mfld_simps]
theorem preimage_inter {s t : Set β} : f ⁻¹' (s ∩ t) = f ⁻¹' s ∩ f ⁻¹' t :=
rfl
#align set.preimage_inter Set.preimage_inter
@[simp]
theorem preimage_union {s t : Set β} : f ⁻¹' (s ∪ t) = f ⁻¹' s ∪ f ⁻¹' t :=
rfl
#align set.preimage_union Set.preimage_union
@[simp]
theorem preimage_compl {s : Set β} : f ⁻¹' sᶜ = (f ⁻¹' s)ᶜ :=
rfl
#align set.preimage_compl Set.preimage_compl
@[simp]
theorem preimage_diff (f : α → β) (s t : Set β) : f ⁻¹' (s \ t) = f ⁻¹' s \ f ⁻¹' t :=
rfl
#align set.preimage_diff Set.preimage_diff
@[simp]
lemma preimage_symmDiff {f : α → β} (s t : Set β) : f ⁻¹' (s ∆ t) = (f ⁻¹' s) ∆ (f ⁻¹' t) :=
rfl
#align set.preimage_symm_diff Set.preimage_symmDiff
@[simp]
theorem preimage_ite (f : α → β) (s t₁ t₂ : Set β) :
f ⁻¹' s.ite t₁ t₂ = (f ⁻¹' s).ite (f ⁻¹' t₁) (f ⁻¹' t₂) :=
rfl
#align set.preimage_ite Set.preimage_ite
@[simp]
theorem preimage_setOf_eq {p : α → Prop} {f : β → α} : f ⁻¹' { a | p a } = { a | p (f a) } :=
rfl
#align set.preimage_set_of_eq Set.preimage_setOf_eq
@[simp]
theorem preimage_id_eq : preimage (id : α → α) = id :=
rfl
#align set.preimage_id_eq Set.preimage_id_eq
@[mfld_simps]
theorem preimage_id {s : Set α} : id ⁻¹' s = s :=
rfl
#align set.preimage_id Set.preimage_id
@[simp, mfld_simps]
theorem preimage_id' {s : Set α} : (fun x => x) ⁻¹' s = s :=
rfl
#align set.preimage_id' Set.preimage_id'
@[simp]
theorem preimage_const_of_mem {b : β} {s : Set β} (h : b ∈ s) : (fun _ : α => b) ⁻¹' s = univ :=
eq_univ_of_forall fun _ => h
#align set.preimage_const_of_mem Set.preimage_const_of_mem
@[simp]
theorem preimage_const_of_not_mem {b : β} {s : Set β} (h : b ∉ s) : (fun _ : α => b) ⁻¹' s = ∅ :=
eq_empty_of_subset_empty fun _ hx => h hx
#align set.preimage_const_of_not_mem Set.preimage_const_of_not_mem
theorem preimage_const (b : β) (s : Set β) [Decidable (b ∈ s)] :
(fun _ : α => b) ⁻¹' s = if b ∈ s then univ else ∅ := by
split_ifs with hb
exacts [preimage_const_of_mem hb, preimage_const_of_not_mem hb]
#align set.preimage_const Set.preimage_const
/-- If preimage of each singleton under `f : α → β` is either empty or the whole type,
then `f` is a constant. -/
lemma exists_eq_const_of_preimage_singleton [Nonempty β] {f : α → β}
(hf : ∀ b : β, f ⁻¹' {b} = ∅ ∨ f ⁻¹' {b} = univ) : ∃ b, f = const α b := by
rcases em (∃ b, f ⁻¹' {b} = univ) with ⟨b, hb⟩ | hf'
· exact ⟨b, funext fun x ↦ eq_univ_iff_forall.1 hb x⟩
· have : ∀ x b, f x ≠ b := fun x b ↦
eq_empty_iff_forall_not_mem.1 ((hf b).resolve_right fun h ↦ hf' ⟨b, h⟩) x
exact ⟨Classical.arbitrary β, funext fun x ↦ absurd rfl (this x _)⟩
theorem preimage_comp {s : Set γ} : g ∘ f ⁻¹' s = f ⁻¹' (g ⁻¹' s) :=
rfl
#align set.preimage_comp Set.preimage_comp
theorem preimage_comp_eq : preimage (g ∘ f) = preimage f ∘ preimage g :=
rfl
#align set.preimage_comp_eq Set.preimage_comp_eq
theorem preimage_iterate_eq {f : α → α} {n : ℕ} : Set.preimage f^[n] = (Set.preimage f)^[n] := by
induction' n with n ih; · simp
rw [iterate_succ, iterate_succ', preimage_comp_eq, ih]
#align set.preimage_iterate_eq Set.preimage_iterate_eq
theorem preimage_preimage {g : β → γ} {f : α → β} {s : Set γ} :
f ⁻¹' (g ⁻¹' s) = (fun x => g (f x)) ⁻¹' s :=
preimage_comp.symm
#align set.preimage_preimage Set.preimage_preimage
theorem eq_preimage_subtype_val_iff {p : α → Prop} {s : Set (Subtype p)} {t : Set α} :
s = Subtype.val ⁻¹' t ↔ ∀ (x) (h : p x), (⟨x, h⟩ : Subtype p) ∈ s ↔ x ∈ t :=
⟨fun s_eq x h => by
rw [s_eq]
simp, fun h => ext fun ⟨x, hx⟩ => by
|
simp [h]
|
theorem eq_preimage_subtype_val_iff {p : α → Prop} {s : Set (Subtype p)} {t : Set α} :
s = Subtype.val ⁻¹' t ↔ ∀ (x) (h : p x), (⟨x, h⟩ : Subtype p) ∈ s ↔ x ∈ t :=
⟨fun s_eq x h => by
rw [s_eq]
simp, fun h => ext fun ⟨x, hx⟩ => by
|
Mathlib.Data.Set.Image.181_0.IJFiTzmYGOCpPSd
|
theorem eq_preimage_subtype_val_iff {p : α → Prop} {s : Set (Subtype p)} {t : Set α} :
s = Subtype.val ⁻¹' t ↔ ∀ (x) (h : p x), (⟨x, h⟩ : Subtype p) ∈ s ↔ x ∈ t
|
Mathlib_Data_Set_Image
|
α : Type u_1
β : Type u_2
γ : Type u_3
ι : Sort u_4
ι' : Sort u_5
f : α → β
g : β → γ
p : α → Prop
⊢ p ⁻¹' {True} = {a | p a}
|
/-
Copyright (c) 2014 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Leonardo de Moura
-/
import Mathlib.Data.Set.Basic
#align_import data.set.image from "leanprover-community/mathlib"@"001ffdc42920050657fd45bd2b8bfbec8eaaeb29"
/-!
# Images and preimages of sets
## Main definitions
* `preimage f t : Set α` : the preimage f⁻¹(t) (written `f ⁻¹' t` in Lean) of a subset of β.
* `range f : Set β` : the image of `univ` under `f`.
Also works for `{p : Prop} (f : p → α)` (unlike `image`)
## Notation
* `f ⁻¹' t` for `Set.preimage f t`
* `f '' s` for `Set.image f s`
## Tags
set, sets, image, preimage, pre-image, range
-/
set_option autoImplicit true
universe u v
open Function Set
namespace Set
variable {α β γ : Type*} {ι ι' : Sort*}
/-! ### Inverse image -/
/-- The preimage of `s : Set β` by `f : α → β`, written `f ⁻¹' s`,
is the set of `x : α` such that `f x ∈ s`. -/
def preimage {α : Type u} {β : Type v} (f : α → β) (s : Set β) : Set α :=
{ x | f x ∈ s }
#align set.preimage Set.preimage
/-- `f ⁻¹' t` denotes the preimage of `t : Set β` under the function `f : α → β`. -/
infixl:80 " ⁻¹' " => preimage
section Preimage
variable {f : α → β} {g : β → γ}
@[simp]
theorem preimage_empty : f ⁻¹' ∅ = ∅ :=
rfl
#align set.preimage_empty Set.preimage_empty
@[simp, mfld_simps]
theorem mem_preimage {s : Set β} {a : α} : a ∈ f ⁻¹' s ↔ f a ∈ s :=
Iff.rfl
#align set.mem_preimage Set.mem_preimage
theorem preimage_congr {f g : α → β} {s : Set β} (h : ∀ x : α, f x = g x) : f ⁻¹' s = g ⁻¹' s := by
congr with x
simp [h]
#align set.preimage_congr Set.preimage_congr
@[gcongr]
theorem preimage_mono {s t : Set β} (h : s ⊆ t) : f ⁻¹' s ⊆ f ⁻¹' t := fun _ hx => h hx
#align set.preimage_mono Set.preimage_mono
@[simp, mfld_simps]
theorem preimage_univ : f ⁻¹' univ = univ :=
rfl
#align set.preimage_univ Set.preimage_univ
theorem subset_preimage_univ {s : Set α} : s ⊆ f ⁻¹' univ :=
subset_univ _
#align set.subset_preimage_univ Set.subset_preimage_univ
@[simp, mfld_simps]
theorem preimage_inter {s t : Set β} : f ⁻¹' (s ∩ t) = f ⁻¹' s ∩ f ⁻¹' t :=
rfl
#align set.preimage_inter Set.preimage_inter
@[simp]
theorem preimage_union {s t : Set β} : f ⁻¹' (s ∪ t) = f ⁻¹' s ∪ f ⁻¹' t :=
rfl
#align set.preimage_union Set.preimage_union
@[simp]
theorem preimage_compl {s : Set β} : f ⁻¹' sᶜ = (f ⁻¹' s)ᶜ :=
rfl
#align set.preimage_compl Set.preimage_compl
@[simp]
theorem preimage_diff (f : α → β) (s t : Set β) : f ⁻¹' (s \ t) = f ⁻¹' s \ f ⁻¹' t :=
rfl
#align set.preimage_diff Set.preimage_diff
@[simp]
lemma preimage_symmDiff {f : α → β} (s t : Set β) : f ⁻¹' (s ∆ t) = (f ⁻¹' s) ∆ (f ⁻¹' t) :=
rfl
#align set.preimage_symm_diff Set.preimage_symmDiff
@[simp]
theorem preimage_ite (f : α → β) (s t₁ t₂ : Set β) :
f ⁻¹' s.ite t₁ t₂ = (f ⁻¹' s).ite (f ⁻¹' t₁) (f ⁻¹' t₂) :=
rfl
#align set.preimage_ite Set.preimage_ite
@[simp]
theorem preimage_setOf_eq {p : α → Prop} {f : β → α} : f ⁻¹' { a | p a } = { a | p (f a) } :=
rfl
#align set.preimage_set_of_eq Set.preimage_setOf_eq
@[simp]
theorem preimage_id_eq : preimage (id : α → α) = id :=
rfl
#align set.preimage_id_eq Set.preimage_id_eq
@[mfld_simps]
theorem preimage_id {s : Set α} : id ⁻¹' s = s :=
rfl
#align set.preimage_id Set.preimage_id
@[simp, mfld_simps]
theorem preimage_id' {s : Set α} : (fun x => x) ⁻¹' s = s :=
rfl
#align set.preimage_id' Set.preimage_id'
@[simp]
theorem preimage_const_of_mem {b : β} {s : Set β} (h : b ∈ s) : (fun _ : α => b) ⁻¹' s = univ :=
eq_univ_of_forall fun _ => h
#align set.preimage_const_of_mem Set.preimage_const_of_mem
@[simp]
theorem preimage_const_of_not_mem {b : β} {s : Set β} (h : b ∉ s) : (fun _ : α => b) ⁻¹' s = ∅ :=
eq_empty_of_subset_empty fun _ hx => h hx
#align set.preimage_const_of_not_mem Set.preimage_const_of_not_mem
theorem preimage_const (b : β) (s : Set β) [Decidable (b ∈ s)] :
(fun _ : α => b) ⁻¹' s = if b ∈ s then univ else ∅ := by
split_ifs with hb
exacts [preimage_const_of_mem hb, preimage_const_of_not_mem hb]
#align set.preimage_const Set.preimage_const
/-- If preimage of each singleton under `f : α → β` is either empty or the whole type,
then `f` is a constant. -/
lemma exists_eq_const_of_preimage_singleton [Nonempty β] {f : α → β}
(hf : ∀ b : β, f ⁻¹' {b} = ∅ ∨ f ⁻¹' {b} = univ) : ∃ b, f = const α b := by
rcases em (∃ b, f ⁻¹' {b} = univ) with ⟨b, hb⟩ | hf'
· exact ⟨b, funext fun x ↦ eq_univ_iff_forall.1 hb x⟩
· have : ∀ x b, f x ≠ b := fun x b ↦
eq_empty_iff_forall_not_mem.1 ((hf b).resolve_right fun h ↦ hf' ⟨b, h⟩) x
exact ⟨Classical.arbitrary β, funext fun x ↦ absurd rfl (this x _)⟩
theorem preimage_comp {s : Set γ} : g ∘ f ⁻¹' s = f ⁻¹' (g ⁻¹' s) :=
rfl
#align set.preimage_comp Set.preimage_comp
theorem preimage_comp_eq : preimage (g ∘ f) = preimage f ∘ preimage g :=
rfl
#align set.preimage_comp_eq Set.preimage_comp_eq
theorem preimage_iterate_eq {f : α → α} {n : ℕ} : Set.preimage f^[n] = (Set.preimage f)^[n] := by
induction' n with n ih; · simp
rw [iterate_succ, iterate_succ', preimage_comp_eq, ih]
#align set.preimage_iterate_eq Set.preimage_iterate_eq
theorem preimage_preimage {g : β → γ} {f : α → β} {s : Set γ} :
f ⁻¹' (g ⁻¹' s) = (fun x => g (f x)) ⁻¹' s :=
preimage_comp.symm
#align set.preimage_preimage Set.preimage_preimage
theorem eq_preimage_subtype_val_iff {p : α → Prop} {s : Set (Subtype p)} {t : Set α} :
s = Subtype.val ⁻¹' t ↔ ∀ (x) (h : p x), (⟨x, h⟩ : Subtype p) ∈ s ↔ x ∈ t :=
⟨fun s_eq x h => by
rw [s_eq]
simp, fun h => ext fun ⟨x, hx⟩ => by simp [h]⟩
#align set.eq_preimage_subtype_val_iff Set.eq_preimage_subtype_val_iff
theorem nonempty_of_nonempty_preimage {s : Set β} {f : α → β} (hf : (f ⁻¹' s).Nonempty) :
s.Nonempty :=
let ⟨x, hx⟩ := hf
⟨f x, hx⟩
#align set.nonempty_of_nonempty_preimage Set.nonempty_of_nonempty_preimage
@[simp] theorem preimage_singleton_true (p : α → Prop) : p ⁻¹' {True} = {a | p a} := by
|
ext
|
@[simp] theorem preimage_singleton_true (p : α → Prop) : p ⁻¹' {True} = {a | p a} := by
|
Mathlib.Data.Set.Image.194_0.IJFiTzmYGOCpPSd
|
@[simp] theorem preimage_singleton_true (p : α → Prop) : p ⁻¹' {True} = {a | p a}
|
Mathlib_Data_Set_Image
|
case h
α : Type u_1
β : Type u_2
γ : Type u_3
ι : Sort u_4
ι' : Sort u_5
f : α → β
g : β → γ
p : α → Prop
x✝ : α
⊢ x✝ ∈ p ⁻¹' {True} ↔ x✝ ∈ {a | p a}
|
/-
Copyright (c) 2014 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Leonardo de Moura
-/
import Mathlib.Data.Set.Basic
#align_import data.set.image from "leanprover-community/mathlib"@"001ffdc42920050657fd45bd2b8bfbec8eaaeb29"
/-!
# Images and preimages of sets
## Main definitions
* `preimage f t : Set α` : the preimage f⁻¹(t) (written `f ⁻¹' t` in Lean) of a subset of β.
* `range f : Set β` : the image of `univ` under `f`.
Also works for `{p : Prop} (f : p → α)` (unlike `image`)
## Notation
* `f ⁻¹' t` for `Set.preimage f t`
* `f '' s` for `Set.image f s`
## Tags
set, sets, image, preimage, pre-image, range
-/
set_option autoImplicit true
universe u v
open Function Set
namespace Set
variable {α β γ : Type*} {ι ι' : Sort*}
/-! ### Inverse image -/
/-- The preimage of `s : Set β` by `f : α → β`, written `f ⁻¹' s`,
is the set of `x : α` such that `f x ∈ s`. -/
def preimage {α : Type u} {β : Type v} (f : α → β) (s : Set β) : Set α :=
{ x | f x ∈ s }
#align set.preimage Set.preimage
/-- `f ⁻¹' t` denotes the preimage of `t : Set β` under the function `f : α → β`. -/
infixl:80 " ⁻¹' " => preimage
section Preimage
variable {f : α → β} {g : β → γ}
@[simp]
theorem preimage_empty : f ⁻¹' ∅ = ∅ :=
rfl
#align set.preimage_empty Set.preimage_empty
@[simp, mfld_simps]
theorem mem_preimage {s : Set β} {a : α} : a ∈ f ⁻¹' s ↔ f a ∈ s :=
Iff.rfl
#align set.mem_preimage Set.mem_preimage
theorem preimage_congr {f g : α → β} {s : Set β} (h : ∀ x : α, f x = g x) : f ⁻¹' s = g ⁻¹' s := by
congr with x
simp [h]
#align set.preimage_congr Set.preimage_congr
@[gcongr]
theorem preimage_mono {s t : Set β} (h : s ⊆ t) : f ⁻¹' s ⊆ f ⁻¹' t := fun _ hx => h hx
#align set.preimage_mono Set.preimage_mono
@[simp, mfld_simps]
theorem preimage_univ : f ⁻¹' univ = univ :=
rfl
#align set.preimage_univ Set.preimage_univ
theorem subset_preimage_univ {s : Set α} : s ⊆ f ⁻¹' univ :=
subset_univ _
#align set.subset_preimage_univ Set.subset_preimage_univ
@[simp, mfld_simps]
theorem preimage_inter {s t : Set β} : f ⁻¹' (s ∩ t) = f ⁻¹' s ∩ f ⁻¹' t :=
rfl
#align set.preimage_inter Set.preimage_inter
@[simp]
theorem preimage_union {s t : Set β} : f ⁻¹' (s ∪ t) = f ⁻¹' s ∪ f ⁻¹' t :=
rfl
#align set.preimage_union Set.preimage_union
@[simp]
theorem preimage_compl {s : Set β} : f ⁻¹' sᶜ = (f ⁻¹' s)ᶜ :=
rfl
#align set.preimage_compl Set.preimage_compl
@[simp]
theorem preimage_diff (f : α → β) (s t : Set β) : f ⁻¹' (s \ t) = f ⁻¹' s \ f ⁻¹' t :=
rfl
#align set.preimage_diff Set.preimage_diff
@[simp]
lemma preimage_symmDiff {f : α → β} (s t : Set β) : f ⁻¹' (s ∆ t) = (f ⁻¹' s) ∆ (f ⁻¹' t) :=
rfl
#align set.preimage_symm_diff Set.preimage_symmDiff
@[simp]
theorem preimage_ite (f : α → β) (s t₁ t₂ : Set β) :
f ⁻¹' s.ite t₁ t₂ = (f ⁻¹' s).ite (f ⁻¹' t₁) (f ⁻¹' t₂) :=
rfl
#align set.preimage_ite Set.preimage_ite
@[simp]
theorem preimage_setOf_eq {p : α → Prop} {f : β → α} : f ⁻¹' { a | p a } = { a | p (f a) } :=
rfl
#align set.preimage_set_of_eq Set.preimage_setOf_eq
@[simp]
theorem preimage_id_eq : preimage (id : α → α) = id :=
rfl
#align set.preimage_id_eq Set.preimage_id_eq
@[mfld_simps]
theorem preimage_id {s : Set α} : id ⁻¹' s = s :=
rfl
#align set.preimage_id Set.preimage_id
@[simp, mfld_simps]
theorem preimage_id' {s : Set α} : (fun x => x) ⁻¹' s = s :=
rfl
#align set.preimage_id' Set.preimage_id'
@[simp]
theorem preimage_const_of_mem {b : β} {s : Set β} (h : b ∈ s) : (fun _ : α => b) ⁻¹' s = univ :=
eq_univ_of_forall fun _ => h
#align set.preimage_const_of_mem Set.preimage_const_of_mem
@[simp]
theorem preimage_const_of_not_mem {b : β} {s : Set β} (h : b ∉ s) : (fun _ : α => b) ⁻¹' s = ∅ :=
eq_empty_of_subset_empty fun _ hx => h hx
#align set.preimage_const_of_not_mem Set.preimage_const_of_not_mem
theorem preimage_const (b : β) (s : Set β) [Decidable (b ∈ s)] :
(fun _ : α => b) ⁻¹' s = if b ∈ s then univ else ∅ := by
split_ifs with hb
exacts [preimage_const_of_mem hb, preimage_const_of_not_mem hb]
#align set.preimage_const Set.preimage_const
/-- If preimage of each singleton under `f : α → β` is either empty or the whole type,
then `f` is a constant. -/
lemma exists_eq_const_of_preimage_singleton [Nonempty β] {f : α → β}
(hf : ∀ b : β, f ⁻¹' {b} = ∅ ∨ f ⁻¹' {b} = univ) : ∃ b, f = const α b := by
rcases em (∃ b, f ⁻¹' {b} = univ) with ⟨b, hb⟩ | hf'
· exact ⟨b, funext fun x ↦ eq_univ_iff_forall.1 hb x⟩
· have : ∀ x b, f x ≠ b := fun x b ↦
eq_empty_iff_forall_not_mem.1 ((hf b).resolve_right fun h ↦ hf' ⟨b, h⟩) x
exact ⟨Classical.arbitrary β, funext fun x ↦ absurd rfl (this x _)⟩
theorem preimage_comp {s : Set γ} : g ∘ f ⁻¹' s = f ⁻¹' (g ⁻¹' s) :=
rfl
#align set.preimage_comp Set.preimage_comp
theorem preimage_comp_eq : preimage (g ∘ f) = preimage f ∘ preimage g :=
rfl
#align set.preimage_comp_eq Set.preimage_comp_eq
theorem preimage_iterate_eq {f : α → α} {n : ℕ} : Set.preimage f^[n] = (Set.preimage f)^[n] := by
induction' n with n ih; · simp
rw [iterate_succ, iterate_succ', preimage_comp_eq, ih]
#align set.preimage_iterate_eq Set.preimage_iterate_eq
theorem preimage_preimage {g : β → γ} {f : α → β} {s : Set γ} :
f ⁻¹' (g ⁻¹' s) = (fun x => g (f x)) ⁻¹' s :=
preimage_comp.symm
#align set.preimage_preimage Set.preimage_preimage
theorem eq_preimage_subtype_val_iff {p : α → Prop} {s : Set (Subtype p)} {t : Set α} :
s = Subtype.val ⁻¹' t ↔ ∀ (x) (h : p x), (⟨x, h⟩ : Subtype p) ∈ s ↔ x ∈ t :=
⟨fun s_eq x h => by
rw [s_eq]
simp, fun h => ext fun ⟨x, hx⟩ => by simp [h]⟩
#align set.eq_preimage_subtype_val_iff Set.eq_preimage_subtype_val_iff
theorem nonempty_of_nonempty_preimage {s : Set β} {f : α → β} (hf : (f ⁻¹' s).Nonempty) :
s.Nonempty :=
let ⟨x, hx⟩ := hf
⟨f x, hx⟩
#align set.nonempty_of_nonempty_preimage Set.nonempty_of_nonempty_preimage
@[simp] theorem preimage_singleton_true (p : α → Prop) : p ⁻¹' {True} = {a | p a} := by ext;
|
simp
|
@[simp] theorem preimage_singleton_true (p : α → Prop) : p ⁻¹' {True} = {a | p a} := by ext;
|
Mathlib.Data.Set.Image.194_0.IJFiTzmYGOCpPSd
|
@[simp] theorem preimage_singleton_true (p : α → Prop) : p ⁻¹' {True} = {a | p a}
|
Mathlib_Data_Set_Image
|
α : Type u_1
β : Type u_2
γ : Type u_3
ι : Sort u_4
ι' : Sort u_5
f : α → β
g : β → γ
p : α → Prop
⊢ p ⁻¹' {False} = {a | ¬p a}
|
/-
Copyright (c) 2014 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Leonardo de Moura
-/
import Mathlib.Data.Set.Basic
#align_import data.set.image from "leanprover-community/mathlib"@"001ffdc42920050657fd45bd2b8bfbec8eaaeb29"
/-!
# Images and preimages of sets
## Main definitions
* `preimage f t : Set α` : the preimage f⁻¹(t) (written `f ⁻¹' t` in Lean) of a subset of β.
* `range f : Set β` : the image of `univ` under `f`.
Also works for `{p : Prop} (f : p → α)` (unlike `image`)
## Notation
* `f ⁻¹' t` for `Set.preimage f t`
* `f '' s` for `Set.image f s`
## Tags
set, sets, image, preimage, pre-image, range
-/
set_option autoImplicit true
universe u v
open Function Set
namespace Set
variable {α β γ : Type*} {ι ι' : Sort*}
/-! ### Inverse image -/
/-- The preimage of `s : Set β` by `f : α → β`, written `f ⁻¹' s`,
is the set of `x : α` such that `f x ∈ s`. -/
def preimage {α : Type u} {β : Type v} (f : α → β) (s : Set β) : Set α :=
{ x | f x ∈ s }
#align set.preimage Set.preimage
/-- `f ⁻¹' t` denotes the preimage of `t : Set β` under the function `f : α → β`. -/
infixl:80 " ⁻¹' " => preimage
section Preimage
variable {f : α → β} {g : β → γ}
@[simp]
theorem preimage_empty : f ⁻¹' ∅ = ∅ :=
rfl
#align set.preimage_empty Set.preimage_empty
@[simp, mfld_simps]
theorem mem_preimage {s : Set β} {a : α} : a ∈ f ⁻¹' s ↔ f a ∈ s :=
Iff.rfl
#align set.mem_preimage Set.mem_preimage
theorem preimage_congr {f g : α → β} {s : Set β} (h : ∀ x : α, f x = g x) : f ⁻¹' s = g ⁻¹' s := by
congr with x
simp [h]
#align set.preimage_congr Set.preimage_congr
@[gcongr]
theorem preimage_mono {s t : Set β} (h : s ⊆ t) : f ⁻¹' s ⊆ f ⁻¹' t := fun _ hx => h hx
#align set.preimage_mono Set.preimage_mono
@[simp, mfld_simps]
theorem preimage_univ : f ⁻¹' univ = univ :=
rfl
#align set.preimage_univ Set.preimage_univ
theorem subset_preimage_univ {s : Set α} : s ⊆ f ⁻¹' univ :=
subset_univ _
#align set.subset_preimage_univ Set.subset_preimage_univ
@[simp, mfld_simps]
theorem preimage_inter {s t : Set β} : f ⁻¹' (s ∩ t) = f ⁻¹' s ∩ f ⁻¹' t :=
rfl
#align set.preimage_inter Set.preimage_inter
@[simp]
theorem preimage_union {s t : Set β} : f ⁻¹' (s ∪ t) = f ⁻¹' s ∪ f ⁻¹' t :=
rfl
#align set.preimage_union Set.preimage_union
@[simp]
theorem preimage_compl {s : Set β} : f ⁻¹' sᶜ = (f ⁻¹' s)ᶜ :=
rfl
#align set.preimage_compl Set.preimage_compl
@[simp]
theorem preimage_diff (f : α → β) (s t : Set β) : f ⁻¹' (s \ t) = f ⁻¹' s \ f ⁻¹' t :=
rfl
#align set.preimage_diff Set.preimage_diff
@[simp]
lemma preimage_symmDiff {f : α → β} (s t : Set β) : f ⁻¹' (s ∆ t) = (f ⁻¹' s) ∆ (f ⁻¹' t) :=
rfl
#align set.preimage_symm_diff Set.preimage_symmDiff
@[simp]
theorem preimage_ite (f : α → β) (s t₁ t₂ : Set β) :
f ⁻¹' s.ite t₁ t₂ = (f ⁻¹' s).ite (f ⁻¹' t₁) (f ⁻¹' t₂) :=
rfl
#align set.preimage_ite Set.preimage_ite
@[simp]
theorem preimage_setOf_eq {p : α → Prop} {f : β → α} : f ⁻¹' { a | p a } = { a | p (f a) } :=
rfl
#align set.preimage_set_of_eq Set.preimage_setOf_eq
@[simp]
theorem preimage_id_eq : preimage (id : α → α) = id :=
rfl
#align set.preimage_id_eq Set.preimage_id_eq
@[mfld_simps]
theorem preimage_id {s : Set α} : id ⁻¹' s = s :=
rfl
#align set.preimage_id Set.preimage_id
@[simp, mfld_simps]
theorem preimage_id' {s : Set α} : (fun x => x) ⁻¹' s = s :=
rfl
#align set.preimage_id' Set.preimage_id'
@[simp]
theorem preimage_const_of_mem {b : β} {s : Set β} (h : b ∈ s) : (fun _ : α => b) ⁻¹' s = univ :=
eq_univ_of_forall fun _ => h
#align set.preimage_const_of_mem Set.preimage_const_of_mem
@[simp]
theorem preimage_const_of_not_mem {b : β} {s : Set β} (h : b ∉ s) : (fun _ : α => b) ⁻¹' s = ∅ :=
eq_empty_of_subset_empty fun _ hx => h hx
#align set.preimage_const_of_not_mem Set.preimage_const_of_not_mem
theorem preimage_const (b : β) (s : Set β) [Decidable (b ∈ s)] :
(fun _ : α => b) ⁻¹' s = if b ∈ s then univ else ∅ := by
split_ifs with hb
exacts [preimage_const_of_mem hb, preimage_const_of_not_mem hb]
#align set.preimage_const Set.preimage_const
/-- If preimage of each singleton under `f : α → β` is either empty or the whole type,
then `f` is a constant. -/
lemma exists_eq_const_of_preimage_singleton [Nonempty β] {f : α → β}
(hf : ∀ b : β, f ⁻¹' {b} = ∅ ∨ f ⁻¹' {b} = univ) : ∃ b, f = const α b := by
rcases em (∃ b, f ⁻¹' {b} = univ) with ⟨b, hb⟩ | hf'
· exact ⟨b, funext fun x ↦ eq_univ_iff_forall.1 hb x⟩
· have : ∀ x b, f x ≠ b := fun x b ↦
eq_empty_iff_forall_not_mem.1 ((hf b).resolve_right fun h ↦ hf' ⟨b, h⟩) x
exact ⟨Classical.arbitrary β, funext fun x ↦ absurd rfl (this x _)⟩
theorem preimage_comp {s : Set γ} : g ∘ f ⁻¹' s = f ⁻¹' (g ⁻¹' s) :=
rfl
#align set.preimage_comp Set.preimage_comp
theorem preimage_comp_eq : preimage (g ∘ f) = preimage f ∘ preimage g :=
rfl
#align set.preimage_comp_eq Set.preimage_comp_eq
theorem preimage_iterate_eq {f : α → α} {n : ℕ} : Set.preimage f^[n] = (Set.preimage f)^[n] := by
induction' n with n ih; · simp
rw [iterate_succ, iterate_succ', preimage_comp_eq, ih]
#align set.preimage_iterate_eq Set.preimage_iterate_eq
theorem preimage_preimage {g : β → γ} {f : α → β} {s : Set γ} :
f ⁻¹' (g ⁻¹' s) = (fun x => g (f x)) ⁻¹' s :=
preimage_comp.symm
#align set.preimage_preimage Set.preimage_preimage
theorem eq_preimage_subtype_val_iff {p : α → Prop} {s : Set (Subtype p)} {t : Set α} :
s = Subtype.val ⁻¹' t ↔ ∀ (x) (h : p x), (⟨x, h⟩ : Subtype p) ∈ s ↔ x ∈ t :=
⟨fun s_eq x h => by
rw [s_eq]
simp, fun h => ext fun ⟨x, hx⟩ => by simp [h]⟩
#align set.eq_preimage_subtype_val_iff Set.eq_preimage_subtype_val_iff
theorem nonempty_of_nonempty_preimage {s : Set β} {f : α → β} (hf : (f ⁻¹' s).Nonempty) :
s.Nonempty :=
let ⟨x, hx⟩ := hf
⟨f x, hx⟩
#align set.nonempty_of_nonempty_preimage Set.nonempty_of_nonempty_preimage
@[simp] theorem preimage_singleton_true (p : α → Prop) : p ⁻¹' {True} = {a | p a} := by ext; simp
#align set.preimage_singleton_true Set.preimage_singleton_true
@[simp] theorem preimage_singleton_false (p : α → Prop) : p ⁻¹' {False} = {a | ¬p a} := by
|
ext
|
@[simp] theorem preimage_singleton_false (p : α → Prop) : p ⁻¹' {False} = {a | ¬p a} := by
|
Mathlib.Data.Set.Image.197_0.IJFiTzmYGOCpPSd
|
@[simp] theorem preimage_singleton_false (p : α → Prop) : p ⁻¹' {False} = {a | ¬p a}
|
Mathlib_Data_Set_Image
|
case h
α : Type u_1
β : Type u_2
γ : Type u_3
ι : Sort u_4
ι' : Sort u_5
f : α → β
g : β → γ
p : α → Prop
x✝ : α
⊢ x✝ ∈ p ⁻¹' {False} ↔ x✝ ∈ {a | ¬p a}
|
/-
Copyright (c) 2014 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Leonardo de Moura
-/
import Mathlib.Data.Set.Basic
#align_import data.set.image from "leanprover-community/mathlib"@"001ffdc42920050657fd45bd2b8bfbec8eaaeb29"
/-!
# Images and preimages of sets
## Main definitions
* `preimage f t : Set α` : the preimage f⁻¹(t) (written `f ⁻¹' t` in Lean) of a subset of β.
* `range f : Set β` : the image of `univ` under `f`.
Also works for `{p : Prop} (f : p → α)` (unlike `image`)
## Notation
* `f ⁻¹' t` for `Set.preimage f t`
* `f '' s` for `Set.image f s`
## Tags
set, sets, image, preimage, pre-image, range
-/
set_option autoImplicit true
universe u v
open Function Set
namespace Set
variable {α β γ : Type*} {ι ι' : Sort*}
/-! ### Inverse image -/
/-- The preimage of `s : Set β` by `f : α → β`, written `f ⁻¹' s`,
is the set of `x : α` such that `f x ∈ s`. -/
def preimage {α : Type u} {β : Type v} (f : α → β) (s : Set β) : Set α :=
{ x | f x ∈ s }
#align set.preimage Set.preimage
/-- `f ⁻¹' t` denotes the preimage of `t : Set β` under the function `f : α → β`. -/
infixl:80 " ⁻¹' " => preimage
section Preimage
variable {f : α → β} {g : β → γ}
@[simp]
theorem preimage_empty : f ⁻¹' ∅ = ∅ :=
rfl
#align set.preimage_empty Set.preimage_empty
@[simp, mfld_simps]
theorem mem_preimage {s : Set β} {a : α} : a ∈ f ⁻¹' s ↔ f a ∈ s :=
Iff.rfl
#align set.mem_preimage Set.mem_preimage
theorem preimage_congr {f g : α → β} {s : Set β} (h : ∀ x : α, f x = g x) : f ⁻¹' s = g ⁻¹' s := by
congr with x
simp [h]
#align set.preimage_congr Set.preimage_congr
@[gcongr]
theorem preimage_mono {s t : Set β} (h : s ⊆ t) : f ⁻¹' s ⊆ f ⁻¹' t := fun _ hx => h hx
#align set.preimage_mono Set.preimage_mono
@[simp, mfld_simps]
theorem preimage_univ : f ⁻¹' univ = univ :=
rfl
#align set.preimage_univ Set.preimage_univ
theorem subset_preimage_univ {s : Set α} : s ⊆ f ⁻¹' univ :=
subset_univ _
#align set.subset_preimage_univ Set.subset_preimage_univ
@[simp, mfld_simps]
theorem preimage_inter {s t : Set β} : f ⁻¹' (s ∩ t) = f ⁻¹' s ∩ f ⁻¹' t :=
rfl
#align set.preimage_inter Set.preimage_inter
@[simp]
theorem preimage_union {s t : Set β} : f ⁻¹' (s ∪ t) = f ⁻¹' s ∪ f ⁻¹' t :=
rfl
#align set.preimage_union Set.preimage_union
@[simp]
theorem preimage_compl {s : Set β} : f ⁻¹' sᶜ = (f ⁻¹' s)ᶜ :=
rfl
#align set.preimage_compl Set.preimage_compl
@[simp]
theorem preimage_diff (f : α → β) (s t : Set β) : f ⁻¹' (s \ t) = f ⁻¹' s \ f ⁻¹' t :=
rfl
#align set.preimage_diff Set.preimage_diff
@[simp]
lemma preimage_symmDiff {f : α → β} (s t : Set β) : f ⁻¹' (s ∆ t) = (f ⁻¹' s) ∆ (f ⁻¹' t) :=
rfl
#align set.preimage_symm_diff Set.preimage_symmDiff
@[simp]
theorem preimage_ite (f : α → β) (s t₁ t₂ : Set β) :
f ⁻¹' s.ite t₁ t₂ = (f ⁻¹' s).ite (f ⁻¹' t₁) (f ⁻¹' t₂) :=
rfl
#align set.preimage_ite Set.preimage_ite
@[simp]
theorem preimage_setOf_eq {p : α → Prop} {f : β → α} : f ⁻¹' { a | p a } = { a | p (f a) } :=
rfl
#align set.preimage_set_of_eq Set.preimage_setOf_eq
@[simp]
theorem preimage_id_eq : preimage (id : α → α) = id :=
rfl
#align set.preimage_id_eq Set.preimage_id_eq
@[mfld_simps]
theorem preimage_id {s : Set α} : id ⁻¹' s = s :=
rfl
#align set.preimage_id Set.preimage_id
@[simp, mfld_simps]
theorem preimage_id' {s : Set α} : (fun x => x) ⁻¹' s = s :=
rfl
#align set.preimage_id' Set.preimage_id'
@[simp]
theorem preimage_const_of_mem {b : β} {s : Set β} (h : b ∈ s) : (fun _ : α => b) ⁻¹' s = univ :=
eq_univ_of_forall fun _ => h
#align set.preimage_const_of_mem Set.preimage_const_of_mem
@[simp]
theorem preimage_const_of_not_mem {b : β} {s : Set β} (h : b ∉ s) : (fun _ : α => b) ⁻¹' s = ∅ :=
eq_empty_of_subset_empty fun _ hx => h hx
#align set.preimage_const_of_not_mem Set.preimage_const_of_not_mem
theorem preimage_const (b : β) (s : Set β) [Decidable (b ∈ s)] :
(fun _ : α => b) ⁻¹' s = if b ∈ s then univ else ∅ := by
split_ifs with hb
exacts [preimage_const_of_mem hb, preimage_const_of_not_mem hb]
#align set.preimage_const Set.preimage_const
/-- If preimage of each singleton under `f : α → β` is either empty or the whole type,
then `f` is a constant. -/
lemma exists_eq_const_of_preimage_singleton [Nonempty β] {f : α → β}
(hf : ∀ b : β, f ⁻¹' {b} = ∅ ∨ f ⁻¹' {b} = univ) : ∃ b, f = const α b := by
rcases em (∃ b, f ⁻¹' {b} = univ) with ⟨b, hb⟩ | hf'
· exact ⟨b, funext fun x ↦ eq_univ_iff_forall.1 hb x⟩
· have : ∀ x b, f x ≠ b := fun x b ↦
eq_empty_iff_forall_not_mem.1 ((hf b).resolve_right fun h ↦ hf' ⟨b, h⟩) x
exact ⟨Classical.arbitrary β, funext fun x ↦ absurd rfl (this x _)⟩
theorem preimage_comp {s : Set γ} : g ∘ f ⁻¹' s = f ⁻¹' (g ⁻¹' s) :=
rfl
#align set.preimage_comp Set.preimage_comp
theorem preimage_comp_eq : preimage (g ∘ f) = preimage f ∘ preimage g :=
rfl
#align set.preimage_comp_eq Set.preimage_comp_eq
theorem preimage_iterate_eq {f : α → α} {n : ℕ} : Set.preimage f^[n] = (Set.preimage f)^[n] := by
induction' n with n ih; · simp
rw [iterate_succ, iterate_succ', preimage_comp_eq, ih]
#align set.preimage_iterate_eq Set.preimage_iterate_eq
theorem preimage_preimage {g : β → γ} {f : α → β} {s : Set γ} :
f ⁻¹' (g ⁻¹' s) = (fun x => g (f x)) ⁻¹' s :=
preimage_comp.symm
#align set.preimage_preimage Set.preimage_preimage
theorem eq_preimage_subtype_val_iff {p : α → Prop} {s : Set (Subtype p)} {t : Set α} :
s = Subtype.val ⁻¹' t ↔ ∀ (x) (h : p x), (⟨x, h⟩ : Subtype p) ∈ s ↔ x ∈ t :=
⟨fun s_eq x h => by
rw [s_eq]
simp, fun h => ext fun ⟨x, hx⟩ => by simp [h]⟩
#align set.eq_preimage_subtype_val_iff Set.eq_preimage_subtype_val_iff
theorem nonempty_of_nonempty_preimage {s : Set β} {f : α → β} (hf : (f ⁻¹' s).Nonempty) :
s.Nonempty :=
let ⟨x, hx⟩ := hf
⟨f x, hx⟩
#align set.nonempty_of_nonempty_preimage Set.nonempty_of_nonempty_preimage
@[simp] theorem preimage_singleton_true (p : α → Prop) : p ⁻¹' {True} = {a | p a} := by ext; simp
#align set.preimage_singleton_true Set.preimage_singleton_true
@[simp] theorem preimage_singleton_false (p : α → Prop) : p ⁻¹' {False} = {a | ¬p a} := by ext;
|
simp
|
@[simp] theorem preimage_singleton_false (p : α → Prop) : p ⁻¹' {False} = {a | ¬p a} := by ext;
|
Mathlib.Data.Set.Image.197_0.IJFiTzmYGOCpPSd
|
@[simp] theorem preimage_singleton_false (p : α → Prop) : p ⁻¹' {False} = {a | ¬p a}
|
Mathlib_Data_Set_Image
|
α : Type u_1
β : Type u_2
γ : Type u_3
ι : Sort u_4
ι' : Sort u_5
f : α → β
g : β → γ
s u v : Set α
hsuv : s ⊆ u ∪ v
H : s ∩ (u ∩ v) = ∅
⊢ Subtype.val ⁻¹' u = (Subtype.val ⁻¹' v)ᶜ
|
/-
Copyright (c) 2014 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Leonardo de Moura
-/
import Mathlib.Data.Set.Basic
#align_import data.set.image from "leanprover-community/mathlib"@"001ffdc42920050657fd45bd2b8bfbec8eaaeb29"
/-!
# Images and preimages of sets
## Main definitions
* `preimage f t : Set α` : the preimage f⁻¹(t) (written `f ⁻¹' t` in Lean) of a subset of β.
* `range f : Set β` : the image of `univ` under `f`.
Also works for `{p : Prop} (f : p → α)` (unlike `image`)
## Notation
* `f ⁻¹' t` for `Set.preimage f t`
* `f '' s` for `Set.image f s`
## Tags
set, sets, image, preimage, pre-image, range
-/
set_option autoImplicit true
universe u v
open Function Set
namespace Set
variable {α β γ : Type*} {ι ι' : Sort*}
/-! ### Inverse image -/
/-- The preimage of `s : Set β` by `f : α → β`, written `f ⁻¹' s`,
is the set of `x : α` such that `f x ∈ s`. -/
def preimage {α : Type u} {β : Type v} (f : α → β) (s : Set β) : Set α :=
{ x | f x ∈ s }
#align set.preimage Set.preimage
/-- `f ⁻¹' t` denotes the preimage of `t : Set β` under the function `f : α → β`. -/
infixl:80 " ⁻¹' " => preimage
section Preimage
variable {f : α → β} {g : β → γ}
@[simp]
theorem preimage_empty : f ⁻¹' ∅ = ∅ :=
rfl
#align set.preimage_empty Set.preimage_empty
@[simp, mfld_simps]
theorem mem_preimage {s : Set β} {a : α} : a ∈ f ⁻¹' s ↔ f a ∈ s :=
Iff.rfl
#align set.mem_preimage Set.mem_preimage
theorem preimage_congr {f g : α → β} {s : Set β} (h : ∀ x : α, f x = g x) : f ⁻¹' s = g ⁻¹' s := by
congr with x
simp [h]
#align set.preimage_congr Set.preimage_congr
@[gcongr]
theorem preimage_mono {s t : Set β} (h : s ⊆ t) : f ⁻¹' s ⊆ f ⁻¹' t := fun _ hx => h hx
#align set.preimage_mono Set.preimage_mono
@[simp, mfld_simps]
theorem preimage_univ : f ⁻¹' univ = univ :=
rfl
#align set.preimage_univ Set.preimage_univ
theorem subset_preimage_univ {s : Set α} : s ⊆ f ⁻¹' univ :=
subset_univ _
#align set.subset_preimage_univ Set.subset_preimage_univ
@[simp, mfld_simps]
theorem preimage_inter {s t : Set β} : f ⁻¹' (s ∩ t) = f ⁻¹' s ∩ f ⁻¹' t :=
rfl
#align set.preimage_inter Set.preimage_inter
@[simp]
theorem preimage_union {s t : Set β} : f ⁻¹' (s ∪ t) = f ⁻¹' s ∪ f ⁻¹' t :=
rfl
#align set.preimage_union Set.preimage_union
@[simp]
theorem preimage_compl {s : Set β} : f ⁻¹' sᶜ = (f ⁻¹' s)ᶜ :=
rfl
#align set.preimage_compl Set.preimage_compl
@[simp]
theorem preimage_diff (f : α → β) (s t : Set β) : f ⁻¹' (s \ t) = f ⁻¹' s \ f ⁻¹' t :=
rfl
#align set.preimage_diff Set.preimage_diff
@[simp]
lemma preimage_symmDiff {f : α → β} (s t : Set β) : f ⁻¹' (s ∆ t) = (f ⁻¹' s) ∆ (f ⁻¹' t) :=
rfl
#align set.preimage_symm_diff Set.preimage_symmDiff
@[simp]
theorem preimage_ite (f : α → β) (s t₁ t₂ : Set β) :
f ⁻¹' s.ite t₁ t₂ = (f ⁻¹' s).ite (f ⁻¹' t₁) (f ⁻¹' t₂) :=
rfl
#align set.preimage_ite Set.preimage_ite
@[simp]
theorem preimage_setOf_eq {p : α → Prop} {f : β → α} : f ⁻¹' { a | p a } = { a | p (f a) } :=
rfl
#align set.preimage_set_of_eq Set.preimage_setOf_eq
@[simp]
theorem preimage_id_eq : preimage (id : α → α) = id :=
rfl
#align set.preimage_id_eq Set.preimage_id_eq
@[mfld_simps]
theorem preimage_id {s : Set α} : id ⁻¹' s = s :=
rfl
#align set.preimage_id Set.preimage_id
@[simp, mfld_simps]
theorem preimage_id' {s : Set α} : (fun x => x) ⁻¹' s = s :=
rfl
#align set.preimage_id' Set.preimage_id'
@[simp]
theorem preimage_const_of_mem {b : β} {s : Set β} (h : b ∈ s) : (fun _ : α => b) ⁻¹' s = univ :=
eq_univ_of_forall fun _ => h
#align set.preimage_const_of_mem Set.preimage_const_of_mem
@[simp]
theorem preimage_const_of_not_mem {b : β} {s : Set β} (h : b ∉ s) : (fun _ : α => b) ⁻¹' s = ∅ :=
eq_empty_of_subset_empty fun _ hx => h hx
#align set.preimage_const_of_not_mem Set.preimage_const_of_not_mem
theorem preimage_const (b : β) (s : Set β) [Decidable (b ∈ s)] :
(fun _ : α => b) ⁻¹' s = if b ∈ s then univ else ∅ := by
split_ifs with hb
exacts [preimage_const_of_mem hb, preimage_const_of_not_mem hb]
#align set.preimage_const Set.preimage_const
/-- If preimage of each singleton under `f : α → β` is either empty or the whole type,
then `f` is a constant. -/
lemma exists_eq_const_of_preimage_singleton [Nonempty β] {f : α → β}
(hf : ∀ b : β, f ⁻¹' {b} = ∅ ∨ f ⁻¹' {b} = univ) : ∃ b, f = const α b := by
rcases em (∃ b, f ⁻¹' {b} = univ) with ⟨b, hb⟩ | hf'
· exact ⟨b, funext fun x ↦ eq_univ_iff_forall.1 hb x⟩
· have : ∀ x b, f x ≠ b := fun x b ↦
eq_empty_iff_forall_not_mem.1 ((hf b).resolve_right fun h ↦ hf' ⟨b, h⟩) x
exact ⟨Classical.arbitrary β, funext fun x ↦ absurd rfl (this x _)⟩
theorem preimage_comp {s : Set γ} : g ∘ f ⁻¹' s = f ⁻¹' (g ⁻¹' s) :=
rfl
#align set.preimage_comp Set.preimage_comp
theorem preimage_comp_eq : preimage (g ∘ f) = preimage f ∘ preimage g :=
rfl
#align set.preimage_comp_eq Set.preimage_comp_eq
theorem preimage_iterate_eq {f : α → α} {n : ℕ} : Set.preimage f^[n] = (Set.preimage f)^[n] := by
induction' n with n ih; · simp
rw [iterate_succ, iterate_succ', preimage_comp_eq, ih]
#align set.preimage_iterate_eq Set.preimage_iterate_eq
theorem preimage_preimage {g : β → γ} {f : α → β} {s : Set γ} :
f ⁻¹' (g ⁻¹' s) = (fun x => g (f x)) ⁻¹' s :=
preimage_comp.symm
#align set.preimage_preimage Set.preimage_preimage
theorem eq_preimage_subtype_val_iff {p : α → Prop} {s : Set (Subtype p)} {t : Set α} :
s = Subtype.val ⁻¹' t ↔ ∀ (x) (h : p x), (⟨x, h⟩ : Subtype p) ∈ s ↔ x ∈ t :=
⟨fun s_eq x h => by
rw [s_eq]
simp, fun h => ext fun ⟨x, hx⟩ => by simp [h]⟩
#align set.eq_preimage_subtype_val_iff Set.eq_preimage_subtype_val_iff
theorem nonempty_of_nonempty_preimage {s : Set β} {f : α → β} (hf : (f ⁻¹' s).Nonempty) :
s.Nonempty :=
let ⟨x, hx⟩ := hf
⟨f x, hx⟩
#align set.nonempty_of_nonempty_preimage Set.nonempty_of_nonempty_preimage
@[simp] theorem preimage_singleton_true (p : α → Prop) : p ⁻¹' {True} = {a | p a} := by ext; simp
#align set.preimage_singleton_true Set.preimage_singleton_true
@[simp] theorem preimage_singleton_false (p : α → Prop) : p ⁻¹' {False} = {a | ¬p a} := by ext; simp
#align set.preimage_singleton_false Set.preimage_singleton_false
theorem preimage_subtype_coe_eq_compl {s u v : Set α} (hsuv : s ⊆ u ∪ v)
(H : s ∩ (u ∩ v) = ∅) : ((↑) : s → α) ⁻¹' u = ((↑) ⁻¹' v)ᶜ := by
|
ext ⟨x, x_in_s⟩
|
theorem preimage_subtype_coe_eq_compl {s u v : Set α} (hsuv : s ⊆ u ∪ v)
(H : s ∩ (u ∩ v) = ∅) : ((↑) : s → α) ⁻¹' u = ((↑) ⁻¹' v)ᶜ := by
|
Mathlib.Data.Set.Image.200_0.IJFiTzmYGOCpPSd
|
theorem preimage_subtype_coe_eq_compl {s u v : Set α} (hsuv : s ⊆ u ∪ v)
(H : s ∩ (u ∩ v) = ∅) : ((↑) : s → α) ⁻¹' u = ((↑) ⁻¹' v)ᶜ
|
Mathlib_Data_Set_Image
|
case h.mk
α : Type u_1
β : Type u_2
γ : Type u_3
ι : Sort u_4
ι' : Sort u_5
f : α → β
g : β → γ
s u v : Set α
hsuv : s ⊆ u ∪ v
H : s ∩ (u ∩ v) = ∅
x : α
x_in_s : x ∈ s
⊢ { val := x, property := x_in_s } ∈ Subtype.val ⁻¹' u ↔ { val := x, property := x_in_s } ∈ (Subtype.val ⁻¹' v)ᶜ
|
/-
Copyright (c) 2014 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Leonardo de Moura
-/
import Mathlib.Data.Set.Basic
#align_import data.set.image from "leanprover-community/mathlib"@"001ffdc42920050657fd45bd2b8bfbec8eaaeb29"
/-!
# Images and preimages of sets
## Main definitions
* `preimage f t : Set α` : the preimage f⁻¹(t) (written `f ⁻¹' t` in Lean) of a subset of β.
* `range f : Set β` : the image of `univ` under `f`.
Also works for `{p : Prop} (f : p → α)` (unlike `image`)
## Notation
* `f ⁻¹' t` for `Set.preimage f t`
* `f '' s` for `Set.image f s`
## Tags
set, sets, image, preimage, pre-image, range
-/
set_option autoImplicit true
universe u v
open Function Set
namespace Set
variable {α β γ : Type*} {ι ι' : Sort*}
/-! ### Inverse image -/
/-- The preimage of `s : Set β` by `f : α → β`, written `f ⁻¹' s`,
is the set of `x : α` such that `f x ∈ s`. -/
def preimage {α : Type u} {β : Type v} (f : α → β) (s : Set β) : Set α :=
{ x | f x ∈ s }
#align set.preimage Set.preimage
/-- `f ⁻¹' t` denotes the preimage of `t : Set β` under the function `f : α → β`. -/
infixl:80 " ⁻¹' " => preimage
section Preimage
variable {f : α → β} {g : β → γ}
@[simp]
theorem preimage_empty : f ⁻¹' ∅ = ∅ :=
rfl
#align set.preimage_empty Set.preimage_empty
@[simp, mfld_simps]
theorem mem_preimage {s : Set β} {a : α} : a ∈ f ⁻¹' s ↔ f a ∈ s :=
Iff.rfl
#align set.mem_preimage Set.mem_preimage
theorem preimage_congr {f g : α → β} {s : Set β} (h : ∀ x : α, f x = g x) : f ⁻¹' s = g ⁻¹' s := by
congr with x
simp [h]
#align set.preimage_congr Set.preimage_congr
@[gcongr]
theorem preimage_mono {s t : Set β} (h : s ⊆ t) : f ⁻¹' s ⊆ f ⁻¹' t := fun _ hx => h hx
#align set.preimage_mono Set.preimage_mono
@[simp, mfld_simps]
theorem preimage_univ : f ⁻¹' univ = univ :=
rfl
#align set.preimage_univ Set.preimage_univ
theorem subset_preimage_univ {s : Set α} : s ⊆ f ⁻¹' univ :=
subset_univ _
#align set.subset_preimage_univ Set.subset_preimage_univ
@[simp, mfld_simps]
theorem preimage_inter {s t : Set β} : f ⁻¹' (s ∩ t) = f ⁻¹' s ∩ f ⁻¹' t :=
rfl
#align set.preimage_inter Set.preimage_inter
@[simp]
theorem preimage_union {s t : Set β} : f ⁻¹' (s ∪ t) = f ⁻¹' s ∪ f ⁻¹' t :=
rfl
#align set.preimage_union Set.preimage_union
@[simp]
theorem preimage_compl {s : Set β} : f ⁻¹' sᶜ = (f ⁻¹' s)ᶜ :=
rfl
#align set.preimage_compl Set.preimage_compl
@[simp]
theorem preimage_diff (f : α → β) (s t : Set β) : f ⁻¹' (s \ t) = f ⁻¹' s \ f ⁻¹' t :=
rfl
#align set.preimage_diff Set.preimage_diff
@[simp]
lemma preimage_symmDiff {f : α → β} (s t : Set β) : f ⁻¹' (s ∆ t) = (f ⁻¹' s) ∆ (f ⁻¹' t) :=
rfl
#align set.preimage_symm_diff Set.preimage_symmDiff
@[simp]
theorem preimage_ite (f : α → β) (s t₁ t₂ : Set β) :
f ⁻¹' s.ite t₁ t₂ = (f ⁻¹' s).ite (f ⁻¹' t₁) (f ⁻¹' t₂) :=
rfl
#align set.preimage_ite Set.preimage_ite
@[simp]
theorem preimage_setOf_eq {p : α → Prop} {f : β → α} : f ⁻¹' { a | p a } = { a | p (f a) } :=
rfl
#align set.preimage_set_of_eq Set.preimage_setOf_eq
@[simp]
theorem preimage_id_eq : preimage (id : α → α) = id :=
rfl
#align set.preimage_id_eq Set.preimage_id_eq
@[mfld_simps]
theorem preimage_id {s : Set α} : id ⁻¹' s = s :=
rfl
#align set.preimage_id Set.preimage_id
@[simp, mfld_simps]
theorem preimage_id' {s : Set α} : (fun x => x) ⁻¹' s = s :=
rfl
#align set.preimage_id' Set.preimage_id'
@[simp]
theorem preimage_const_of_mem {b : β} {s : Set β} (h : b ∈ s) : (fun _ : α => b) ⁻¹' s = univ :=
eq_univ_of_forall fun _ => h
#align set.preimage_const_of_mem Set.preimage_const_of_mem
@[simp]
theorem preimage_const_of_not_mem {b : β} {s : Set β} (h : b ∉ s) : (fun _ : α => b) ⁻¹' s = ∅ :=
eq_empty_of_subset_empty fun _ hx => h hx
#align set.preimage_const_of_not_mem Set.preimage_const_of_not_mem
theorem preimage_const (b : β) (s : Set β) [Decidable (b ∈ s)] :
(fun _ : α => b) ⁻¹' s = if b ∈ s then univ else ∅ := by
split_ifs with hb
exacts [preimage_const_of_mem hb, preimage_const_of_not_mem hb]
#align set.preimage_const Set.preimage_const
/-- If preimage of each singleton under `f : α → β` is either empty or the whole type,
then `f` is a constant. -/
lemma exists_eq_const_of_preimage_singleton [Nonempty β] {f : α → β}
(hf : ∀ b : β, f ⁻¹' {b} = ∅ ∨ f ⁻¹' {b} = univ) : ∃ b, f = const α b := by
rcases em (∃ b, f ⁻¹' {b} = univ) with ⟨b, hb⟩ | hf'
· exact ⟨b, funext fun x ↦ eq_univ_iff_forall.1 hb x⟩
· have : ∀ x b, f x ≠ b := fun x b ↦
eq_empty_iff_forall_not_mem.1 ((hf b).resolve_right fun h ↦ hf' ⟨b, h⟩) x
exact ⟨Classical.arbitrary β, funext fun x ↦ absurd rfl (this x _)⟩
theorem preimage_comp {s : Set γ} : g ∘ f ⁻¹' s = f ⁻¹' (g ⁻¹' s) :=
rfl
#align set.preimage_comp Set.preimage_comp
theorem preimage_comp_eq : preimage (g ∘ f) = preimage f ∘ preimage g :=
rfl
#align set.preimage_comp_eq Set.preimage_comp_eq
theorem preimage_iterate_eq {f : α → α} {n : ℕ} : Set.preimage f^[n] = (Set.preimage f)^[n] := by
induction' n with n ih; · simp
rw [iterate_succ, iterate_succ', preimage_comp_eq, ih]
#align set.preimage_iterate_eq Set.preimage_iterate_eq
theorem preimage_preimage {g : β → γ} {f : α → β} {s : Set γ} :
f ⁻¹' (g ⁻¹' s) = (fun x => g (f x)) ⁻¹' s :=
preimage_comp.symm
#align set.preimage_preimage Set.preimage_preimage
theorem eq_preimage_subtype_val_iff {p : α → Prop} {s : Set (Subtype p)} {t : Set α} :
s = Subtype.val ⁻¹' t ↔ ∀ (x) (h : p x), (⟨x, h⟩ : Subtype p) ∈ s ↔ x ∈ t :=
⟨fun s_eq x h => by
rw [s_eq]
simp, fun h => ext fun ⟨x, hx⟩ => by simp [h]⟩
#align set.eq_preimage_subtype_val_iff Set.eq_preimage_subtype_val_iff
theorem nonempty_of_nonempty_preimage {s : Set β} {f : α → β} (hf : (f ⁻¹' s).Nonempty) :
s.Nonempty :=
let ⟨x, hx⟩ := hf
⟨f x, hx⟩
#align set.nonempty_of_nonempty_preimage Set.nonempty_of_nonempty_preimage
@[simp] theorem preimage_singleton_true (p : α → Prop) : p ⁻¹' {True} = {a | p a} := by ext; simp
#align set.preimage_singleton_true Set.preimage_singleton_true
@[simp] theorem preimage_singleton_false (p : α → Prop) : p ⁻¹' {False} = {a | ¬p a} := by ext; simp
#align set.preimage_singleton_false Set.preimage_singleton_false
theorem preimage_subtype_coe_eq_compl {s u v : Set α} (hsuv : s ⊆ u ∪ v)
(H : s ∩ (u ∩ v) = ∅) : ((↑) : s → α) ⁻¹' u = ((↑) ⁻¹' v)ᶜ := by
ext ⟨x, x_in_s⟩
|
constructor
|
theorem preimage_subtype_coe_eq_compl {s u v : Set α} (hsuv : s ⊆ u ∪ v)
(H : s ∩ (u ∩ v) = ∅) : ((↑) : s → α) ⁻¹' u = ((↑) ⁻¹' v)ᶜ := by
ext ⟨x, x_in_s⟩
|
Mathlib.Data.Set.Image.200_0.IJFiTzmYGOCpPSd
|
theorem preimage_subtype_coe_eq_compl {s u v : Set α} (hsuv : s ⊆ u ∪ v)
(H : s ∩ (u ∩ v) = ∅) : ((↑) : s → α) ⁻¹' u = ((↑) ⁻¹' v)ᶜ
|
Mathlib_Data_Set_Image
|
case h.mk.mp
α : Type u_1
β : Type u_2
γ : Type u_3
ι : Sort u_4
ι' : Sort u_5
f : α → β
g : β → γ
s u v : Set α
hsuv : s ⊆ u ∪ v
H : s ∩ (u ∩ v) = ∅
x : α
x_in_s : x ∈ s
⊢ { val := x, property := x_in_s } ∈ Subtype.val ⁻¹' u → { val := x, property := x_in_s } ∈ (Subtype.val ⁻¹' v)ᶜ
|
/-
Copyright (c) 2014 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Leonardo de Moura
-/
import Mathlib.Data.Set.Basic
#align_import data.set.image from "leanprover-community/mathlib"@"001ffdc42920050657fd45bd2b8bfbec8eaaeb29"
/-!
# Images and preimages of sets
## Main definitions
* `preimage f t : Set α` : the preimage f⁻¹(t) (written `f ⁻¹' t` in Lean) of a subset of β.
* `range f : Set β` : the image of `univ` under `f`.
Also works for `{p : Prop} (f : p → α)` (unlike `image`)
## Notation
* `f ⁻¹' t` for `Set.preimage f t`
* `f '' s` for `Set.image f s`
## Tags
set, sets, image, preimage, pre-image, range
-/
set_option autoImplicit true
universe u v
open Function Set
namespace Set
variable {α β γ : Type*} {ι ι' : Sort*}
/-! ### Inverse image -/
/-- The preimage of `s : Set β` by `f : α → β`, written `f ⁻¹' s`,
is the set of `x : α` such that `f x ∈ s`. -/
def preimage {α : Type u} {β : Type v} (f : α → β) (s : Set β) : Set α :=
{ x | f x ∈ s }
#align set.preimage Set.preimage
/-- `f ⁻¹' t` denotes the preimage of `t : Set β` under the function `f : α → β`. -/
infixl:80 " ⁻¹' " => preimage
section Preimage
variable {f : α → β} {g : β → γ}
@[simp]
theorem preimage_empty : f ⁻¹' ∅ = ∅ :=
rfl
#align set.preimage_empty Set.preimage_empty
@[simp, mfld_simps]
theorem mem_preimage {s : Set β} {a : α} : a ∈ f ⁻¹' s ↔ f a ∈ s :=
Iff.rfl
#align set.mem_preimage Set.mem_preimage
theorem preimage_congr {f g : α → β} {s : Set β} (h : ∀ x : α, f x = g x) : f ⁻¹' s = g ⁻¹' s := by
congr with x
simp [h]
#align set.preimage_congr Set.preimage_congr
@[gcongr]
theorem preimage_mono {s t : Set β} (h : s ⊆ t) : f ⁻¹' s ⊆ f ⁻¹' t := fun _ hx => h hx
#align set.preimage_mono Set.preimage_mono
@[simp, mfld_simps]
theorem preimage_univ : f ⁻¹' univ = univ :=
rfl
#align set.preimage_univ Set.preimage_univ
theorem subset_preimage_univ {s : Set α} : s ⊆ f ⁻¹' univ :=
subset_univ _
#align set.subset_preimage_univ Set.subset_preimage_univ
@[simp, mfld_simps]
theorem preimage_inter {s t : Set β} : f ⁻¹' (s ∩ t) = f ⁻¹' s ∩ f ⁻¹' t :=
rfl
#align set.preimage_inter Set.preimage_inter
@[simp]
theorem preimage_union {s t : Set β} : f ⁻¹' (s ∪ t) = f ⁻¹' s ∪ f ⁻¹' t :=
rfl
#align set.preimage_union Set.preimage_union
@[simp]
theorem preimage_compl {s : Set β} : f ⁻¹' sᶜ = (f ⁻¹' s)ᶜ :=
rfl
#align set.preimage_compl Set.preimage_compl
@[simp]
theorem preimage_diff (f : α → β) (s t : Set β) : f ⁻¹' (s \ t) = f ⁻¹' s \ f ⁻¹' t :=
rfl
#align set.preimage_diff Set.preimage_diff
@[simp]
lemma preimage_symmDiff {f : α → β} (s t : Set β) : f ⁻¹' (s ∆ t) = (f ⁻¹' s) ∆ (f ⁻¹' t) :=
rfl
#align set.preimage_symm_diff Set.preimage_symmDiff
@[simp]
theorem preimage_ite (f : α → β) (s t₁ t₂ : Set β) :
f ⁻¹' s.ite t₁ t₂ = (f ⁻¹' s).ite (f ⁻¹' t₁) (f ⁻¹' t₂) :=
rfl
#align set.preimage_ite Set.preimage_ite
@[simp]
theorem preimage_setOf_eq {p : α → Prop} {f : β → α} : f ⁻¹' { a | p a } = { a | p (f a) } :=
rfl
#align set.preimage_set_of_eq Set.preimage_setOf_eq
@[simp]
theorem preimage_id_eq : preimage (id : α → α) = id :=
rfl
#align set.preimage_id_eq Set.preimage_id_eq
@[mfld_simps]
theorem preimage_id {s : Set α} : id ⁻¹' s = s :=
rfl
#align set.preimage_id Set.preimage_id
@[simp, mfld_simps]
theorem preimage_id' {s : Set α} : (fun x => x) ⁻¹' s = s :=
rfl
#align set.preimage_id' Set.preimage_id'
@[simp]
theorem preimage_const_of_mem {b : β} {s : Set β} (h : b ∈ s) : (fun _ : α => b) ⁻¹' s = univ :=
eq_univ_of_forall fun _ => h
#align set.preimage_const_of_mem Set.preimage_const_of_mem
@[simp]
theorem preimage_const_of_not_mem {b : β} {s : Set β} (h : b ∉ s) : (fun _ : α => b) ⁻¹' s = ∅ :=
eq_empty_of_subset_empty fun _ hx => h hx
#align set.preimage_const_of_not_mem Set.preimage_const_of_not_mem
theorem preimage_const (b : β) (s : Set β) [Decidable (b ∈ s)] :
(fun _ : α => b) ⁻¹' s = if b ∈ s then univ else ∅ := by
split_ifs with hb
exacts [preimage_const_of_mem hb, preimage_const_of_not_mem hb]
#align set.preimage_const Set.preimage_const
/-- If preimage of each singleton under `f : α → β` is either empty or the whole type,
then `f` is a constant. -/
lemma exists_eq_const_of_preimage_singleton [Nonempty β] {f : α → β}
(hf : ∀ b : β, f ⁻¹' {b} = ∅ ∨ f ⁻¹' {b} = univ) : ∃ b, f = const α b := by
rcases em (∃ b, f ⁻¹' {b} = univ) with ⟨b, hb⟩ | hf'
· exact ⟨b, funext fun x ↦ eq_univ_iff_forall.1 hb x⟩
· have : ∀ x b, f x ≠ b := fun x b ↦
eq_empty_iff_forall_not_mem.1 ((hf b).resolve_right fun h ↦ hf' ⟨b, h⟩) x
exact ⟨Classical.arbitrary β, funext fun x ↦ absurd rfl (this x _)⟩
theorem preimage_comp {s : Set γ} : g ∘ f ⁻¹' s = f ⁻¹' (g ⁻¹' s) :=
rfl
#align set.preimage_comp Set.preimage_comp
theorem preimage_comp_eq : preimage (g ∘ f) = preimage f ∘ preimage g :=
rfl
#align set.preimage_comp_eq Set.preimage_comp_eq
theorem preimage_iterate_eq {f : α → α} {n : ℕ} : Set.preimage f^[n] = (Set.preimage f)^[n] := by
induction' n with n ih; · simp
rw [iterate_succ, iterate_succ', preimage_comp_eq, ih]
#align set.preimage_iterate_eq Set.preimage_iterate_eq
theorem preimage_preimage {g : β → γ} {f : α → β} {s : Set γ} :
f ⁻¹' (g ⁻¹' s) = (fun x => g (f x)) ⁻¹' s :=
preimage_comp.symm
#align set.preimage_preimage Set.preimage_preimage
theorem eq_preimage_subtype_val_iff {p : α → Prop} {s : Set (Subtype p)} {t : Set α} :
s = Subtype.val ⁻¹' t ↔ ∀ (x) (h : p x), (⟨x, h⟩ : Subtype p) ∈ s ↔ x ∈ t :=
⟨fun s_eq x h => by
rw [s_eq]
simp, fun h => ext fun ⟨x, hx⟩ => by simp [h]⟩
#align set.eq_preimage_subtype_val_iff Set.eq_preimage_subtype_val_iff
theorem nonempty_of_nonempty_preimage {s : Set β} {f : α → β} (hf : (f ⁻¹' s).Nonempty) :
s.Nonempty :=
let ⟨x, hx⟩ := hf
⟨f x, hx⟩
#align set.nonempty_of_nonempty_preimage Set.nonempty_of_nonempty_preimage
@[simp] theorem preimage_singleton_true (p : α → Prop) : p ⁻¹' {True} = {a | p a} := by ext; simp
#align set.preimage_singleton_true Set.preimage_singleton_true
@[simp] theorem preimage_singleton_false (p : α → Prop) : p ⁻¹' {False} = {a | ¬p a} := by ext; simp
#align set.preimage_singleton_false Set.preimage_singleton_false
theorem preimage_subtype_coe_eq_compl {s u v : Set α} (hsuv : s ⊆ u ∪ v)
(H : s ∩ (u ∩ v) = ∅) : ((↑) : s → α) ⁻¹' u = ((↑) ⁻¹' v)ᶜ := by
ext ⟨x, x_in_s⟩
constructor
·
|
intro x_in_u x_in_v
|
theorem preimage_subtype_coe_eq_compl {s u v : Set α} (hsuv : s ⊆ u ∪ v)
(H : s ∩ (u ∩ v) = ∅) : ((↑) : s → α) ⁻¹' u = ((↑) ⁻¹' v)ᶜ := by
ext ⟨x, x_in_s⟩
constructor
·
|
Mathlib.Data.Set.Image.200_0.IJFiTzmYGOCpPSd
|
theorem preimage_subtype_coe_eq_compl {s u v : Set α} (hsuv : s ⊆ u ∪ v)
(H : s ∩ (u ∩ v) = ∅) : ((↑) : s → α) ⁻¹' u = ((↑) ⁻¹' v)ᶜ
|
Mathlib_Data_Set_Image
|
case h.mk.mp
α : Type u_1
β : Type u_2
γ : Type u_3
ι : Sort u_4
ι' : Sort u_5
f : α → β
g : β → γ
s u v : Set α
hsuv : s ⊆ u ∪ v
H : s ∩ (u ∩ v) = ∅
x : α
x_in_s : x ∈ s
x_in_u : { val := x, property := x_in_s } ∈ Subtype.val ⁻¹' u
x_in_v : { val := x, property := x_in_s } ∈ Subtype.val ⁻¹' v
⊢ False
|
/-
Copyright (c) 2014 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Leonardo de Moura
-/
import Mathlib.Data.Set.Basic
#align_import data.set.image from "leanprover-community/mathlib"@"001ffdc42920050657fd45bd2b8bfbec8eaaeb29"
/-!
# Images and preimages of sets
## Main definitions
* `preimage f t : Set α` : the preimage f⁻¹(t) (written `f ⁻¹' t` in Lean) of a subset of β.
* `range f : Set β` : the image of `univ` under `f`.
Also works for `{p : Prop} (f : p → α)` (unlike `image`)
## Notation
* `f ⁻¹' t` for `Set.preimage f t`
* `f '' s` for `Set.image f s`
## Tags
set, sets, image, preimage, pre-image, range
-/
set_option autoImplicit true
universe u v
open Function Set
namespace Set
variable {α β γ : Type*} {ι ι' : Sort*}
/-! ### Inverse image -/
/-- The preimage of `s : Set β` by `f : α → β`, written `f ⁻¹' s`,
is the set of `x : α` such that `f x ∈ s`. -/
def preimage {α : Type u} {β : Type v} (f : α → β) (s : Set β) : Set α :=
{ x | f x ∈ s }
#align set.preimage Set.preimage
/-- `f ⁻¹' t` denotes the preimage of `t : Set β` under the function `f : α → β`. -/
infixl:80 " ⁻¹' " => preimage
section Preimage
variable {f : α → β} {g : β → γ}
@[simp]
theorem preimage_empty : f ⁻¹' ∅ = ∅ :=
rfl
#align set.preimage_empty Set.preimage_empty
@[simp, mfld_simps]
theorem mem_preimage {s : Set β} {a : α} : a ∈ f ⁻¹' s ↔ f a ∈ s :=
Iff.rfl
#align set.mem_preimage Set.mem_preimage
theorem preimage_congr {f g : α → β} {s : Set β} (h : ∀ x : α, f x = g x) : f ⁻¹' s = g ⁻¹' s := by
congr with x
simp [h]
#align set.preimage_congr Set.preimage_congr
@[gcongr]
theorem preimage_mono {s t : Set β} (h : s ⊆ t) : f ⁻¹' s ⊆ f ⁻¹' t := fun _ hx => h hx
#align set.preimage_mono Set.preimage_mono
@[simp, mfld_simps]
theorem preimage_univ : f ⁻¹' univ = univ :=
rfl
#align set.preimage_univ Set.preimage_univ
theorem subset_preimage_univ {s : Set α} : s ⊆ f ⁻¹' univ :=
subset_univ _
#align set.subset_preimage_univ Set.subset_preimage_univ
@[simp, mfld_simps]
theorem preimage_inter {s t : Set β} : f ⁻¹' (s ∩ t) = f ⁻¹' s ∩ f ⁻¹' t :=
rfl
#align set.preimage_inter Set.preimage_inter
@[simp]
theorem preimage_union {s t : Set β} : f ⁻¹' (s ∪ t) = f ⁻¹' s ∪ f ⁻¹' t :=
rfl
#align set.preimage_union Set.preimage_union
@[simp]
theorem preimage_compl {s : Set β} : f ⁻¹' sᶜ = (f ⁻¹' s)ᶜ :=
rfl
#align set.preimage_compl Set.preimage_compl
@[simp]
theorem preimage_diff (f : α → β) (s t : Set β) : f ⁻¹' (s \ t) = f ⁻¹' s \ f ⁻¹' t :=
rfl
#align set.preimage_diff Set.preimage_diff
@[simp]
lemma preimage_symmDiff {f : α → β} (s t : Set β) : f ⁻¹' (s ∆ t) = (f ⁻¹' s) ∆ (f ⁻¹' t) :=
rfl
#align set.preimage_symm_diff Set.preimage_symmDiff
@[simp]
theorem preimage_ite (f : α → β) (s t₁ t₂ : Set β) :
f ⁻¹' s.ite t₁ t₂ = (f ⁻¹' s).ite (f ⁻¹' t₁) (f ⁻¹' t₂) :=
rfl
#align set.preimage_ite Set.preimage_ite
@[simp]
theorem preimage_setOf_eq {p : α → Prop} {f : β → α} : f ⁻¹' { a | p a } = { a | p (f a) } :=
rfl
#align set.preimage_set_of_eq Set.preimage_setOf_eq
@[simp]
theorem preimage_id_eq : preimage (id : α → α) = id :=
rfl
#align set.preimage_id_eq Set.preimage_id_eq
@[mfld_simps]
theorem preimage_id {s : Set α} : id ⁻¹' s = s :=
rfl
#align set.preimage_id Set.preimage_id
@[simp, mfld_simps]
theorem preimage_id' {s : Set α} : (fun x => x) ⁻¹' s = s :=
rfl
#align set.preimage_id' Set.preimage_id'
@[simp]
theorem preimage_const_of_mem {b : β} {s : Set β} (h : b ∈ s) : (fun _ : α => b) ⁻¹' s = univ :=
eq_univ_of_forall fun _ => h
#align set.preimage_const_of_mem Set.preimage_const_of_mem
@[simp]
theorem preimage_const_of_not_mem {b : β} {s : Set β} (h : b ∉ s) : (fun _ : α => b) ⁻¹' s = ∅ :=
eq_empty_of_subset_empty fun _ hx => h hx
#align set.preimage_const_of_not_mem Set.preimage_const_of_not_mem
theorem preimage_const (b : β) (s : Set β) [Decidable (b ∈ s)] :
(fun _ : α => b) ⁻¹' s = if b ∈ s then univ else ∅ := by
split_ifs with hb
exacts [preimage_const_of_mem hb, preimage_const_of_not_mem hb]
#align set.preimage_const Set.preimage_const
/-- If preimage of each singleton under `f : α → β` is either empty or the whole type,
then `f` is a constant. -/
lemma exists_eq_const_of_preimage_singleton [Nonempty β] {f : α → β}
(hf : ∀ b : β, f ⁻¹' {b} = ∅ ∨ f ⁻¹' {b} = univ) : ∃ b, f = const α b := by
rcases em (∃ b, f ⁻¹' {b} = univ) with ⟨b, hb⟩ | hf'
· exact ⟨b, funext fun x ↦ eq_univ_iff_forall.1 hb x⟩
· have : ∀ x b, f x ≠ b := fun x b ↦
eq_empty_iff_forall_not_mem.1 ((hf b).resolve_right fun h ↦ hf' ⟨b, h⟩) x
exact ⟨Classical.arbitrary β, funext fun x ↦ absurd rfl (this x _)⟩
theorem preimage_comp {s : Set γ} : g ∘ f ⁻¹' s = f ⁻¹' (g ⁻¹' s) :=
rfl
#align set.preimage_comp Set.preimage_comp
theorem preimage_comp_eq : preimage (g ∘ f) = preimage f ∘ preimage g :=
rfl
#align set.preimage_comp_eq Set.preimage_comp_eq
theorem preimage_iterate_eq {f : α → α} {n : ℕ} : Set.preimage f^[n] = (Set.preimage f)^[n] := by
induction' n with n ih; · simp
rw [iterate_succ, iterate_succ', preimage_comp_eq, ih]
#align set.preimage_iterate_eq Set.preimage_iterate_eq
theorem preimage_preimage {g : β → γ} {f : α → β} {s : Set γ} :
f ⁻¹' (g ⁻¹' s) = (fun x => g (f x)) ⁻¹' s :=
preimage_comp.symm
#align set.preimage_preimage Set.preimage_preimage
theorem eq_preimage_subtype_val_iff {p : α → Prop} {s : Set (Subtype p)} {t : Set α} :
s = Subtype.val ⁻¹' t ↔ ∀ (x) (h : p x), (⟨x, h⟩ : Subtype p) ∈ s ↔ x ∈ t :=
⟨fun s_eq x h => by
rw [s_eq]
simp, fun h => ext fun ⟨x, hx⟩ => by simp [h]⟩
#align set.eq_preimage_subtype_val_iff Set.eq_preimage_subtype_val_iff
theorem nonempty_of_nonempty_preimage {s : Set β} {f : α → β} (hf : (f ⁻¹' s).Nonempty) :
s.Nonempty :=
let ⟨x, hx⟩ := hf
⟨f x, hx⟩
#align set.nonempty_of_nonempty_preimage Set.nonempty_of_nonempty_preimage
@[simp] theorem preimage_singleton_true (p : α → Prop) : p ⁻¹' {True} = {a | p a} := by ext; simp
#align set.preimage_singleton_true Set.preimage_singleton_true
@[simp] theorem preimage_singleton_false (p : α → Prop) : p ⁻¹' {False} = {a | ¬p a} := by ext; simp
#align set.preimage_singleton_false Set.preimage_singleton_false
theorem preimage_subtype_coe_eq_compl {s u v : Set α} (hsuv : s ⊆ u ∪ v)
(H : s ∩ (u ∩ v) = ∅) : ((↑) : s → α) ⁻¹' u = ((↑) ⁻¹' v)ᶜ := by
ext ⟨x, x_in_s⟩
constructor
· intro x_in_u x_in_v
|
exact eq_empty_iff_forall_not_mem.mp H x ⟨x_in_s, ⟨x_in_u, x_in_v⟩⟩
|
theorem preimage_subtype_coe_eq_compl {s u v : Set α} (hsuv : s ⊆ u ∪ v)
(H : s ∩ (u ∩ v) = ∅) : ((↑) : s → α) ⁻¹' u = ((↑) ⁻¹' v)ᶜ := by
ext ⟨x, x_in_s⟩
constructor
· intro x_in_u x_in_v
|
Mathlib.Data.Set.Image.200_0.IJFiTzmYGOCpPSd
|
theorem preimage_subtype_coe_eq_compl {s u v : Set α} (hsuv : s ⊆ u ∪ v)
(H : s ∩ (u ∩ v) = ∅) : ((↑) : s → α) ⁻¹' u = ((↑) ⁻¹' v)ᶜ
|
Mathlib_Data_Set_Image
|
case h.mk.mpr
α : Type u_1
β : Type u_2
γ : Type u_3
ι : Sort u_4
ι' : Sort u_5
f : α → β
g : β → γ
s u v : Set α
hsuv : s ⊆ u ∪ v
H : s ∩ (u ∩ v) = ∅
x : α
x_in_s : x ∈ s
⊢ { val := x, property := x_in_s } ∈ (Subtype.val ⁻¹' v)ᶜ → { val := x, property := x_in_s } ∈ Subtype.val ⁻¹' u
|
/-
Copyright (c) 2014 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Leonardo de Moura
-/
import Mathlib.Data.Set.Basic
#align_import data.set.image from "leanprover-community/mathlib"@"001ffdc42920050657fd45bd2b8bfbec8eaaeb29"
/-!
# Images and preimages of sets
## Main definitions
* `preimage f t : Set α` : the preimage f⁻¹(t) (written `f ⁻¹' t` in Lean) of a subset of β.
* `range f : Set β` : the image of `univ` under `f`.
Also works for `{p : Prop} (f : p → α)` (unlike `image`)
## Notation
* `f ⁻¹' t` for `Set.preimage f t`
* `f '' s` for `Set.image f s`
## Tags
set, sets, image, preimage, pre-image, range
-/
set_option autoImplicit true
universe u v
open Function Set
namespace Set
variable {α β γ : Type*} {ι ι' : Sort*}
/-! ### Inverse image -/
/-- The preimage of `s : Set β` by `f : α → β`, written `f ⁻¹' s`,
is the set of `x : α` such that `f x ∈ s`. -/
def preimage {α : Type u} {β : Type v} (f : α → β) (s : Set β) : Set α :=
{ x | f x ∈ s }
#align set.preimage Set.preimage
/-- `f ⁻¹' t` denotes the preimage of `t : Set β` under the function `f : α → β`. -/
infixl:80 " ⁻¹' " => preimage
section Preimage
variable {f : α → β} {g : β → γ}
@[simp]
theorem preimage_empty : f ⁻¹' ∅ = ∅ :=
rfl
#align set.preimage_empty Set.preimage_empty
@[simp, mfld_simps]
theorem mem_preimage {s : Set β} {a : α} : a ∈ f ⁻¹' s ↔ f a ∈ s :=
Iff.rfl
#align set.mem_preimage Set.mem_preimage
theorem preimage_congr {f g : α → β} {s : Set β} (h : ∀ x : α, f x = g x) : f ⁻¹' s = g ⁻¹' s := by
congr with x
simp [h]
#align set.preimage_congr Set.preimage_congr
@[gcongr]
theorem preimage_mono {s t : Set β} (h : s ⊆ t) : f ⁻¹' s ⊆ f ⁻¹' t := fun _ hx => h hx
#align set.preimage_mono Set.preimage_mono
@[simp, mfld_simps]
theorem preimage_univ : f ⁻¹' univ = univ :=
rfl
#align set.preimage_univ Set.preimage_univ
theorem subset_preimage_univ {s : Set α} : s ⊆ f ⁻¹' univ :=
subset_univ _
#align set.subset_preimage_univ Set.subset_preimage_univ
@[simp, mfld_simps]
theorem preimage_inter {s t : Set β} : f ⁻¹' (s ∩ t) = f ⁻¹' s ∩ f ⁻¹' t :=
rfl
#align set.preimage_inter Set.preimage_inter
@[simp]
theorem preimage_union {s t : Set β} : f ⁻¹' (s ∪ t) = f ⁻¹' s ∪ f ⁻¹' t :=
rfl
#align set.preimage_union Set.preimage_union
@[simp]
theorem preimage_compl {s : Set β} : f ⁻¹' sᶜ = (f ⁻¹' s)ᶜ :=
rfl
#align set.preimage_compl Set.preimage_compl
@[simp]
theorem preimage_diff (f : α → β) (s t : Set β) : f ⁻¹' (s \ t) = f ⁻¹' s \ f ⁻¹' t :=
rfl
#align set.preimage_diff Set.preimage_diff
@[simp]
lemma preimage_symmDiff {f : α → β} (s t : Set β) : f ⁻¹' (s ∆ t) = (f ⁻¹' s) ∆ (f ⁻¹' t) :=
rfl
#align set.preimage_symm_diff Set.preimage_symmDiff
@[simp]
theorem preimage_ite (f : α → β) (s t₁ t₂ : Set β) :
f ⁻¹' s.ite t₁ t₂ = (f ⁻¹' s).ite (f ⁻¹' t₁) (f ⁻¹' t₂) :=
rfl
#align set.preimage_ite Set.preimage_ite
@[simp]
theorem preimage_setOf_eq {p : α → Prop} {f : β → α} : f ⁻¹' { a | p a } = { a | p (f a) } :=
rfl
#align set.preimage_set_of_eq Set.preimage_setOf_eq
@[simp]
theorem preimage_id_eq : preimage (id : α → α) = id :=
rfl
#align set.preimage_id_eq Set.preimage_id_eq
@[mfld_simps]
theorem preimage_id {s : Set α} : id ⁻¹' s = s :=
rfl
#align set.preimage_id Set.preimage_id
@[simp, mfld_simps]
theorem preimage_id' {s : Set α} : (fun x => x) ⁻¹' s = s :=
rfl
#align set.preimage_id' Set.preimage_id'
@[simp]
theorem preimage_const_of_mem {b : β} {s : Set β} (h : b ∈ s) : (fun _ : α => b) ⁻¹' s = univ :=
eq_univ_of_forall fun _ => h
#align set.preimage_const_of_mem Set.preimage_const_of_mem
@[simp]
theorem preimage_const_of_not_mem {b : β} {s : Set β} (h : b ∉ s) : (fun _ : α => b) ⁻¹' s = ∅ :=
eq_empty_of_subset_empty fun _ hx => h hx
#align set.preimage_const_of_not_mem Set.preimage_const_of_not_mem
theorem preimage_const (b : β) (s : Set β) [Decidable (b ∈ s)] :
(fun _ : α => b) ⁻¹' s = if b ∈ s then univ else ∅ := by
split_ifs with hb
exacts [preimage_const_of_mem hb, preimage_const_of_not_mem hb]
#align set.preimage_const Set.preimage_const
/-- If preimage of each singleton under `f : α → β` is either empty or the whole type,
then `f` is a constant. -/
lemma exists_eq_const_of_preimage_singleton [Nonempty β] {f : α → β}
(hf : ∀ b : β, f ⁻¹' {b} = ∅ ∨ f ⁻¹' {b} = univ) : ∃ b, f = const α b := by
rcases em (∃ b, f ⁻¹' {b} = univ) with ⟨b, hb⟩ | hf'
· exact ⟨b, funext fun x ↦ eq_univ_iff_forall.1 hb x⟩
· have : ∀ x b, f x ≠ b := fun x b ↦
eq_empty_iff_forall_not_mem.1 ((hf b).resolve_right fun h ↦ hf' ⟨b, h⟩) x
exact ⟨Classical.arbitrary β, funext fun x ↦ absurd rfl (this x _)⟩
theorem preimage_comp {s : Set γ} : g ∘ f ⁻¹' s = f ⁻¹' (g ⁻¹' s) :=
rfl
#align set.preimage_comp Set.preimage_comp
theorem preimage_comp_eq : preimage (g ∘ f) = preimage f ∘ preimage g :=
rfl
#align set.preimage_comp_eq Set.preimage_comp_eq
theorem preimage_iterate_eq {f : α → α} {n : ℕ} : Set.preimage f^[n] = (Set.preimage f)^[n] := by
induction' n with n ih; · simp
rw [iterate_succ, iterate_succ', preimage_comp_eq, ih]
#align set.preimage_iterate_eq Set.preimage_iterate_eq
theorem preimage_preimage {g : β → γ} {f : α → β} {s : Set γ} :
f ⁻¹' (g ⁻¹' s) = (fun x => g (f x)) ⁻¹' s :=
preimage_comp.symm
#align set.preimage_preimage Set.preimage_preimage
theorem eq_preimage_subtype_val_iff {p : α → Prop} {s : Set (Subtype p)} {t : Set α} :
s = Subtype.val ⁻¹' t ↔ ∀ (x) (h : p x), (⟨x, h⟩ : Subtype p) ∈ s ↔ x ∈ t :=
⟨fun s_eq x h => by
rw [s_eq]
simp, fun h => ext fun ⟨x, hx⟩ => by simp [h]⟩
#align set.eq_preimage_subtype_val_iff Set.eq_preimage_subtype_val_iff
theorem nonempty_of_nonempty_preimage {s : Set β} {f : α → β} (hf : (f ⁻¹' s).Nonempty) :
s.Nonempty :=
let ⟨x, hx⟩ := hf
⟨f x, hx⟩
#align set.nonempty_of_nonempty_preimage Set.nonempty_of_nonempty_preimage
@[simp] theorem preimage_singleton_true (p : α → Prop) : p ⁻¹' {True} = {a | p a} := by ext; simp
#align set.preimage_singleton_true Set.preimage_singleton_true
@[simp] theorem preimage_singleton_false (p : α → Prop) : p ⁻¹' {False} = {a | ¬p a} := by ext; simp
#align set.preimage_singleton_false Set.preimage_singleton_false
theorem preimage_subtype_coe_eq_compl {s u v : Set α} (hsuv : s ⊆ u ∪ v)
(H : s ∩ (u ∩ v) = ∅) : ((↑) : s → α) ⁻¹' u = ((↑) ⁻¹' v)ᶜ := by
ext ⟨x, x_in_s⟩
constructor
· intro x_in_u x_in_v
exact eq_empty_iff_forall_not_mem.mp H x ⟨x_in_s, ⟨x_in_u, x_in_v⟩⟩
·
|
intro hx
|
theorem preimage_subtype_coe_eq_compl {s u v : Set α} (hsuv : s ⊆ u ∪ v)
(H : s ∩ (u ∩ v) = ∅) : ((↑) : s → α) ⁻¹' u = ((↑) ⁻¹' v)ᶜ := by
ext ⟨x, x_in_s⟩
constructor
· intro x_in_u x_in_v
exact eq_empty_iff_forall_not_mem.mp H x ⟨x_in_s, ⟨x_in_u, x_in_v⟩⟩
·
|
Mathlib.Data.Set.Image.200_0.IJFiTzmYGOCpPSd
|
theorem preimage_subtype_coe_eq_compl {s u v : Set α} (hsuv : s ⊆ u ∪ v)
(H : s ∩ (u ∩ v) = ∅) : ((↑) : s → α) ⁻¹' u = ((↑) ⁻¹' v)ᶜ
|
Mathlib_Data_Set_Image
|
case h.mk.mpr
α : Type u_1
β : Type u_2
γ : Type u_3
ι : Sort u_4
ι' : Sort u_5
f : α → β
g : β → γ
s u v : Set α
hsuv : s ⊆ u ∪ v
H : s ∩ (u ∩ v) = ∅
x : α
x_in_s : x ∈ s
hx : { val := x, property := x_in_s } ∈ (Subtype.val ⁻¹' v)ᶜ
⊢ { val := x, property := x_in_s } ∈ Subtype.val ⁻¹' u
|
/-
Copyright (c) 2014 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Leonardo de Moura
-/
import Mathlib.Data.Set.Basic
#align_import data.set.image from "leanprover-community/mathlib"@"001ffdc42920050657fd45bd2b8bfbec8eaaeb29"
/-!
# Images and preimages of sets
## Main definitions
* `preimage f t : Set α` : the preimage f⁻¹(t) (written `f ⁻¹' t` in Lean) of a subset of β.
* `range f : Set β` : the image of `univ` under `f`.
Also works for `{p : Prop} (f : p → α)` (unlike `image`)
## Notation
* `f ⁻¹' t` for `Set.preimage f t`
* `f '' s` for `Set.image f s`
## Tags
set, sets, image, preimage, pre-image, range
-/
set_option autoImplicit true
universe u v
open Function Set
namespace Set
variable {α β γ : Type*} {ι ι' : Sort*}
/-! ### Inverse image -/
/-- The preimage of `s : Set β` by `f : α → β`, written `f ⁻¹' s`,
is the set of `x : α` such that `f x ∈ s`. -/
def preimage {α : Type u} {β : Type v} (f : α → β) (s : Set β) : Set α :=
{ x | f x ∈ s }
#align set.preimage Set.preimage
/-- `f ⁻¹' t` denotes the preimage of `t : Set β` under the function `f : α → β`. -/
infixl:80 " ⁻¹' " => preimage
section Preimage
variable {f : α → β} {g : β → γ}
@[simp]
theorem preimage_empty : f ⁻¹' ∅ = ∅ :=
rfl
#align set.preimage_empty Set.preimage_empty
@[simp, mfld_simps]
theorem mem_preimage {s : Set β} {a : α} : a ∈ f ⁻¹' s ↔ f a ∈ s :=
Iff.rfl
#align set.mem_preimage Set.mem_preimage
theorem preimage_congr {f g : α → β} {s : Set β} (h : ∀ x : α, f x = g x) : f ⁻¹' s = g ⁻¹' s := by
congr with x
simp [h]
#align set.preimage_congr Set.preimage_congr
@[gcongr]
theorem preimage_mono {s t : Set β} (h : s ⊆ t) : f ⁻¹' s ⊆ f ⁻¹' t := fun _ hx => h hx
#align set.preimage_mono Set.preimage_mono
@[simp, mfld_simps]
theorem preimage_univ : f ⁻¹' univ = univ :=
rfl
#align set.preimage_univ Set.preimage_univ
theorem subset_preimage_univ {s : Set α} : s ⊆ f ⁻¹' univ :=
subset_univ _
#align set.subset_preimage_univ Set.subset_preimage_univ
@[simp, mfld_simps]
theorem preimage_inter {s t : Set β} : f ⁻¹' (s ∩ t) = f ⁻¹' s ∩ f ⁻¹' t :=
rfl
#align set.preimage_inter Set.preimage_inter
@[simp]
theorem preimage_union {s t : Set β} : f ⁻¹' (s ∪ t) = f ⁻¹' s ∪ f ⁻¹' t :=
rfl
#align set.preimage_union Set.preimage_union
@[simp]
theorem preimage_compl {s : Set β} : f ⁻¹' sᶜ = (f ⁻¹' s)ᶜ :=
rfl
#align set.preimage_compl Set.preimage_compl
@[simp]
theorem preimage_diff (f : α → β) (s t : Set β) : f ⁻¹' (s \ t) = f ⁻¹' s \ f ⁻¹' t :=
rfl
#align set.preimage_diff Set.preimage_diff
@[simp]
lemma preimage_symmDiff {f : α → β} (s t : Set β) : f ⁻¹' (s ∆ t) = (f ⁻¹' s) ∆ (f ⁻¹' t) :=
rfl
#align set.preimage_symm_diff Set.preimage_symmDiff
@[simp]
theorem preimage_ite (f : α → β) (s t₁ t₂ : Set β) :
f ⁻¹' s.ite t₁ t₂ = (f ⁻¹' s).ite (f ⁻¹' t₁) (f ⁻¹' t₂) :=
rfl
#align set.preimage_ite Set.preimage_ite
@[simp]
theorem preimage_setOf_eq {p : α → Prop} {f : β → α} : f ⁻¹' { a | p a } = { a | p (f a) } :=
rfl
#align set.preimage_set_of_eq Set.preimage_setOf_eq
@[simp]
theorem preimage_id_eq : preimage (id : α → α) = id :=
rfl
#align set.preimage_id_eq Set.preimage_id_eq
@[mfld_simps]
theorem preimage_id {s : Set α} : id ⁻¹' s = s :=
rfl
#align set.preimage_id Set.preimage_id
@[simp, mfld_simps]
theorem preimage_id' {s : Set α} : (fun x => x) ⁻¹' s = s :=
rfl
#align set.preimage_id' Set.preimage_id'
@[simp]
theorem preimage_const_of_mem {b : β} {s : Set β} (h : b ∈ s) : (fun _ : α => b) ⁻¹' s = univ :=
eq_univ_of_forall fun _ => h
#align set.preimage_const_of_mem Set.preimage_const_of_mem
@[simp]
theorem preimage_const_of_not_mem {b : β} {s : Set β} (h : b ∉ s) : (fun _ : α => b) ⁻¹' s = ∅ :=
eq_empty_of_subset_empty fun _ hx => h hx
#align set.preimage_const_of_not_mem Set.preimage_const_of_not_mem
theorem preimage_const (b : β) (s : Set β) [Decidable (b ∈ s)] :
(fun _ : α => b) ⁻¹' s = if b ∈ s then univ else ∅ := by
split_ifs with hb
exacts [preimage_const_of_mem hb, preimage_const_of_not_mem hb]
#align set.preimage_const Set.preimage_const
/-- If preimage of each singleton under `f : α → β` is either empty or the whole type,
then `f` is a constant. -/
lemma exists_eq_const_of_preimage_singleton [Nonempty β] {f : α → β}
(hf : ∀ b : β, f ⁻¹' {b} = ∅ ∨ f ⁻¹' {b} = univ) : ∃ b, f = const α b := by
rcases em (∃ b, f ⁻¹' {b} = univ) with ⟨b, hb⟩ | hf'
· exact ⟨b, funext fun x ↦ eq_univ_iff_forall.1 hb x⟩
· have : ∀ x b, f x ≠ b := fun x b ↦
eq_empty_iff_forall_not_mem.1 ((hf b).resolve_right fun h ↦ hf' ⟨b, h⟩) x
exact ⟨Classical.arbitrary β, funext fun x ↦ absurd rfl (this x _)⟩
theorem preimage_comp {s : Set γ} : g ∘ f ⁻¹' s = f ⁻¹' (g ⁻¹' s) :=
rfl
#align set.preimage_comp Set.preimage_comp
theorem preimage_comp_eq : preimage (g ∘ f) = preimage f ∘ preimage g :=
rfl
#align set.preimage_comp_eq Set.preimage_comp_eq
theorem preimage_iterate_eq {f : α → α} {n : ℕ} : Set.preimage f^[n] = (Set.preimage f)^[n] := by
induction' n with n ih; · simp
rw [iterate_succ, iterate_succ', preimage_comp_eq, ih]
#align set.preimage_iterate_eq Set.preimage_iterate_eq
theorem preimage_preimage {g : β → γ} {f : α → β} {s : Set γ} :
f ⁻¹' (g ⁻¹' s) = (fun x => g (f x)) ⁻¹' s :=
preimage_comp.symm
#align set.preimage_preimage Set.preimage_preimage
theorem eq_preimage_subtype_val_iff {p : α → Prop} {s : Set (Subtype p)} {t : Set α} :
s = Subtype.val ⁻¹' t ↔ ∀ (x) (h : p x), (⟨x, h⟩ : Subtype p) ∈ s ↔ x ∈ t :=
⟨fun s_eq x h => by
rw [s_eq]
simp, fun h => ext fun ⟨x, hx⟩ => by simp [h]⟩
#align set.eq_preimage_subtype_val_iff Set.eq_preimage_subtype_val_iff
theorem nonempty_of_nonempty_preimage {s : Set β} {f : α → β} (hf : (f ⁻¹' s).Nonempty) :
s.Nonempty :=
let ⟨x, hx⟩ := hf
⟨f x, hx⟩
#align set.nonempty_of_nonempty_preimage Set.nonempty_of_nonempty_preimage
@[simp] theorem preimage_singleton_true (p : α → Prop) : p ⁻¹' {True} = {a | p a} := by ext; simp
#align set.preimage_singleton_true Set.preimage_singleton_true
@[simp] theorem preimage_singleton_false (p : α → Prop) : p ⁻¹' {False} = {a | ¬p a} := by ext; simp
#align set.preimage_singleton_false Set.preimage_singleton_false
theorem preimage_subtype_coe_eq_compl {s u v : Set α} (hsuv : s ⊆ u ∪ v)
(H : s ∩ (u ∩ v) = ∅) : ((↑) : s → α) ⁻¹' u = ((↑) ⁻¹' v)ᶜ := by
ext ⟨x, x_in_s⟩
constructor
· intro x_in_u x_in_v
exact eq_empty_iff_forall_not_mem.mp H x ⟨x_in_s, ⟨x_in_u, x_in_v⟩⟩
· intro hx
|
exact Or.elim (hsuv x_in_s) id fun hx' => hx.elim hx'
|
theorem preimage_subtype_coe_eq_compl {s u v : Set α} (hsuv : s ⊆ u ∪ v)
(H : s ∩ (u ∩ v) = ∅) : ((↑) : s → α) ⁻¹' u = ((↑) ⁻¹' v)ᶜ := by
ext ⟨x, x_in_s⟩
constructor
· intro x_in_u x_in_v
exact eq_empty_iff_forall_not_mem.mp H x ⟨x_in_s, ⟨x_in_u, x_in_v⟩⟩
· intro hx
|
Mathlib.Data.Set.Image.200_0.IJFiTzmYGOCpPSd
|
theorem preimage_subtype_coe_eq_compl {s u v : Set α} (hsuv : s ⊆ u ∪ v)
(H : s ∩ (u ∩ v) = ∅) : ((↑) : s → α) ⁻¹' u = ((↑) ⁻¹' v)ᶜ
|
Mathlib_Data_Set_Image
|
α : Type u_1
β : Type u_2
γ : Type u_3
ι : Sort u_4
ι' : Sort u_5
f✝ : α → β
s✝ t : Set α
f : α → β
s : Set α
p : β → Prop
⊢ (∀ y ∈ f '' s, p y) ↔ ∀ x ∈ s, p (f x)
|
/-
Copyright (c) 2014 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Leonardo de Moura
-/
import Mathlib.Data.Set.Basic
#align_import data.set.image from "leanprover-community/mathlib"@"001ffdc42920050657fd45bd2b8bfbec8eaaeb29"
/-!
# Images and preimages of sets
## Main definitions
* `preimage f t : Set α` : the preimage f⁻¹(t) (written `f ⁻¹' t` in Lean) of a subset of β.
* `range f : Set β` : the image of `univ` under `f`.
Also works for `{p : Prop} (f : p → α)` (unlike `image`)
## Notation
* `f ⁻¹' t` for `Set.preimage f t`
* `f '' s` for `Set.image f s`
## Tags
set, sets, image, preimage, pre-image, range
-/
set_option autoImplicit true
universe u v
open Function Set
namespace Set
variable {α β γ : Type*} {ι ι' : Sort*}
/-! ### Inverse image -/
/-- The preimage of `s : Set β` by `f : α → β`, written `f ⁻¹' s`,
is the set of `x : α` such that `f x ∈ s`. -/
def preimage {α : Type u} {β : Type v} (f : α → β) (s : Set β) : Set α :=
{ x | f x ∈ s }
#align set.preimage Set.preimage
/-- `f ⁻¹' t` denotes the preimage of `t : Set β` under the function `f : α → β`. -/
infixl:80 " ⁻¹' " => preimage
section Preimage
variable {f : α → β} {g : β → γ}
@[simp]
theorem preimage_empty : f ⁻¹' ∅ = ∅ :=
rfl
#align set.preimage_empty Set.preimage_empty
@[simp, mfld_simps]
theorem mem_preimage {s : Set β} {a : α} : a ∈ f ⁻¹' s ↔ f a ∈ s :=
Iff.rfl
#align set.mem_preimage Set.mem_preimage
theorem preimage_congr {f g : α → β} {s : Set β} (h : ∀ x : α, f x = g x) : f ⁻¹' s = g ⁻¹' s := by
congr with x
simp [h]
#align set.preimage_congr Set.preimage_congr
@[gcongr]
theorem preimage_mono {s t : Set β} (h : s ⊆ t) : f ⁻¹' s ⊆ f ⁻¹' t := fun _ hx => h hx
#align set.preimage_mono Set.preimage_mono
@[simp, mfld_simps]
theorem preimage_univ : f ⁻¹' univ = univ :=
rfl
#align set.preimage_univ Set.preimage_univ
theorem subset_preimage_univ {s : Set α} : s ⊆ f ⁻¹' univ :=
subset_univ _
#align set.subset_preimage_univ Set.subset_preimage_univ
@[simp, mfld_simps]
theorem preimage_inter {s t : Set β} : f ⁻¹' (s ∩ t) = f ⁻¹' s ∩ f ⁻¹' t :=
rfl
#align set.preimage_inter Set.preimage_inter
@[simp]
theorem preimage_union {s t : Set β} : f ⁻¹' (s ∪ t) = f ⁻¹' s ∪ f ⁻¹' t :=
rfl
#align set.preimage_union Set.preimage_union
@[simp]
theorem preimage_compl {s : Set β} : f ⁻¹' sᶜ = (f ⁻¹' s)ᶜ :=
rfl
#align set.preimage_compl Set.preimage_compl
@[simp]
theorem preimage_diff (f : α → β) (s t : Set β) : f ⁻¹' (s \ t) = f ⁻¹' s \ f ⁻¹' t :=
rfl
#align set.preimage_diff Set.preimage_diff
@[simp]
lemma preimage_symmDiff {f : α → β} (s t : Set β) : f ⁻¹' (s ∆ t) = (f ⁻¹' s) ∆ (f ⁻¹' t) :=
rfl
#align set.preimage_symm_diff Set.preimage_symmDiff
@[simp]
theorem preimage_ite (f : α → β) (s t₁ t₂ : Set β) :
f ⁻¹' s.ite t₁ t₂ = (f ⁻¹' s).ite (f ⁻¹' t₁) (f ⁻¹' t₂) :=
rfl
#align set.preimage_ite Set.preimage_ite
@[simp]
theorem preimage_setOf_eq {p : α → Prop} {f : β → α} : f ⁻¹' { a | p a } = { a | p (f a) } :=
rfl
#align set.preimage_set_of_eq Set.preimage_setOf_eq
@[simp]
theorem preimage_id_eq : preimage (id : α → α) = id :=
rfl
#align set.preimage_id_eq Set.preimage_id_eq
@[mfld_simps]
theorem preimage_id {s : Set α} : id ⁻¹' s = s :=
rfl
#align set.preimage_id Set.preimage_id
@[simp, mfld_simps]
theorem preimage_id' {s : Set α} : (fun x => x) ⁻¹' s = s :=
rfl
#align set.preimage_id' Set.preimage_id'
@[simp]
theorem preimage_const_of_mem {b : β} {s : Set β} (h : b ∈ s) : (fun _ : α => b) ⁻¹' s = univ :=
eq_univ_of_forall fun _ => h
#align set.preimage_const_of_mem Set.preimage_const_of_mem
@[simp]
theorem preimage_const_of_not_mem {b : β} {s : Set β} (h : b ∉ s) : (fun _ : α => b) ⁻¹' s = ∅ :=
eq_empty_of_subset_empty fun _ hx => h hx
#align set.preimage_const_of_not_mem Set.preimage_const_of_not_mem
theorem preimage_const (b : β) (s : Set β) [Decidable (b ∈ s)] :
(fun _ : α => b) ⁻¹' s = if b ∈ s then univ else ∅ := by
split_ifs with hb
exacts [preimage_const_of_mem hb, preimage_const_of_not_mem hb]
#align set.preimage_const Set.preimage_const
/-- If preimage of each singleton under `f : α → β` is either empty or the whole type,
then `f` is a constant. -/
lemma exists_eq_const_of_preimage_singleton [Nonempty β] {f : α → β}
(hf : ∀ b : β, f ⁻¹' {b} = ∅ ∨ f ⁻¹' {b} = univ) : ∃ b, f = const α b := by
rcases em (∃ b, f ⁻¹' {b} = univ) with ⟨b, hb⟩ | hf'
· exact ⟨b, funext fun x ↦ eq_univ_iff_forall.1 hb x⟩
· have : ∀ x b, f x ≠ b := fun x b ↦
eq_empty_iff_forall_not_mem.1 ((hf b).resolve_right fun h ↦ hf' ⟨b, h⟩) x
exact ⟨Classical.arbitrary β, funext fun x ↦ absurd rfl (this x _)⟩
theorem preimage_comp {s : Set γ} : g ∘ f ⁻¹' s = f ⁻¹' (g ⁻¹' s) :=
rfl
#align set.preimage_comp Set.preimage_comp
theorem preimage_comp_eq : preimage (g ∘ f) = preimage f ∘ preimage g :=
rfl
#align set.preimage_comp_eq Set.preimage_comp_eq
theorem preimage_iterate_eq {f : α → α} {n : ℕ} : Set.preimage f^[n] = (Set.preimage f)^[n] := by
induction' n with n ih; · simp
rw [iterate_succ, iterate_succ', preimage_comp_eq, ih]
#align set.preimage_iterate_eq Set.preimage_iterate_eq
theorem preimage_preimage {g : β → γ} {f : α → β} {s : Set γ} :
f ⁻¹' (g ⁻¹' s) = (fun x => g (f x)) ⁻¹' s :=
preimage_comp.symm
#align set.preimage_preimage Set.preimage_preimage
theorem eq_preimage_subtype_val_iff {p : α → Prop} {s : Set (Subtype p)} {t : Set α} :
s = Subtype.val ⁻¹' t ↔ ∀ (x) (h : p x), (⟨x, h⟩ : Subtype p) ∈ s ↔ x ∈ t :=
⟨fun s_eq x h => by
rw [s_eq]
simp, fun h => ext fun ⟨x, hx⟩ => by simp [h]⟩
#align set.eq_preimage_subtype_val_iff Set.eq_preimage_subtype_val_iff
theorem nonempty_of_nonempty_preimage {s : Set β} {f : α → β} (hf : (f ⁻¹' s).Nonempty) :
s.Nonempty :=
let ⟨x, hx⟩ := hf
⟨f x, hx⟩
#align set.nonempty_of_nonempty_preimage Set.nonempty_of_nonempty_preimage
@[simp] theorem preimage_singleton_true (p : α → Prop) : p ⁻¹' {True} = {a | p a} := by ext; simp
#align set.preimage_singleton_true Set.preimage_singleton_true
@[simp] theorem preimage_singleton_false (p : α → Prop) : p ⁻¹' {False} = {a | ¬p a} := by ext; simp
#align set.preimage_singleton_false Set.preimage_singleton_false
theorem preimage_subtype_coe_eq_compl {s u v : Set α} (hsuv : s ⊆ u ∪ v)
(H : s ∩ (u ∩ v) = ∅) : ((↑) : s → α) ⁻¹' u = ((↑) ⁻¹' v)ᶜ := by
ext ⟨x, x_in_s⟩
constructor
· intro x_in_u x_in_v
exact eq_empty_iff_forall_not_mem.mp H x ⟨x_in_s, ⟨x_in_u, x_in_v⟩⟩
· intro hx
exact Or.elim (hsuv x_in_s) id fun hx' => hx.elim hx'
#align set.preimage_subtype_coe_eq_compl Set.preimage_subtype_coe_eq_compl
end Preimage
/-! ### Image of a set under a function -/
section Image
variable {f : α → β} {s t : Set α}
-- Porting note: `Set.image` is already defined in `Init.Set`
#align set.image Set.image
/-- `f '' s` denotes the image of `s : Set α` under the function `f : α → β`. -/
infixl:80 " '' " => image
theorem mem_image_iff_bex {f : α → β} {s : Set α} {y : β} :
y ∈ f '' s ↔ ∃ (x : _) (_ : x ∈ s), f x = y :=
bex_def.symm
#align set.mem_image_iff_bex Set.mem_image_iff_bex
@[simp]
theorem mem_image (f : α → β) (s : Set α) (y : β) : y ∈ f '' s ↔ ∃ x ∈ s, f x = y :=
Iff.rfl
#align set.mem_image Set.mem_image
theorem image_eta (f : α → β) : f '' s = (fun x => f x) '' s :=
rfl
#align set.image_eta Set.image_eta
@[mfld_simps]
theorem mem_image_of_mem (f : α → β) {x : α} {a : Set α} (h : x ∈ a) : f x ∈ f '' a :=
⟨_, h, rfl⟩
#align set.mem_image_of_mem Set.mem_image_of_mem
theorem _root_.Function.Injective.mem_set_image {f : α → β} (hf : Injective f) {s : Set α} {a : α} :
f a ∈ f '' s ↔ a ∈ s :=
⟨fun ⟨_, hb, Eq⟩ => hf Eq ▸ hb, mem_image_of_mem f⟩
#align function.injective.mem_set_image Function.Injective.mem_set_image
theorem ball_image_iff {f : α → β} {s : Set α} {p : β → Prop} :
(∀ y ∈ f '' s, p y) ↔ ∀ x ∈ s, p (f x) := by
|
simp
|
theorem ball_image_iff {f : α → β} {s : Set α} {p : β → Prop} :
(∀ y ∈ f '' s, p y) ↔ ∀ x ∈ s, p (f x) := by
|
Mathlib.Data.Set.Image.249_0.IJFiTzmYGOCpPSd
|
theorem ball_image_iff {f : α → β} {s : Set α} {p : β → Prop} :
(∀ y ∈ f '' s, p y) ↔ ∀ x ∈ s, p (f x)
|
Mathlib_Data_Set_Image
|
α : Type u_1
β : Type u_2
γ : Type u_3
ι : Sort u_4
ι' : Sort u_5
f✝ : α → β
s✝ t : Set α
f : α → β
s : Set α
p : β → Prop
⊢ (∃ y ∈ f '' s, p y) ↔ ∃ x ∈ s, p (f x)
|
/-
Copyright (c) 2014 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Leonardo de Moura
-/
import Mathlib.Data.Set.Basic
#align_import data.set.image from "leanprover-community/mathlib"@"001ffdc42920050657fd45bd2b8bfbec8eaaeb29"
/-!
# Images and preimages of sets
## Main definitions
* `preimage f t : Set α` : the preimage f⁻¹(t) (written `f ⁻¹' t` in Lean) of a subset of β.
* `range f : Set β` : the image of `univ` under `f`.
Also works for `{p : Prop} (f : p → α)` (unlike `image`)
## Notation
* `f ⁻¹' t` for `Set.preimage f t`
* `f '' s` for `Set.image f s`
## Tags
set, sets, image, preimage, pre-image, range
-/
set_option autoImplicit true
universe u v
open Function Set
namespace Set
variable {α β γ : Type*} {ι ι' : Sort*}
/-! ### Inverse image -/
/-- The preimage of `s : Set β` by `f : α → β`, written `f ⁻¹' s`,
is the set of `x : α` such that `f x ∈ s`. -/
def preimage {α : Type u} {β : Type v} (f : α → β) (s : Set β) : Set α :=
{ x | f x ∈ s }
#align set.preimage Set.preimage
/-- `f ⁻¹' t` denotes the preimage of `t : Set β` under the function `f : α → β`. -/
infixl:80 " ⁻¹' " => preimage
section Preimage
variable {f : α → β} {g : β → γ}
@[simp]
theorem preimage_empty : f ⁻¹' ∅ = ∅ :=
rfl
#align set.preimage_empty Set.preimage_empty
@[simp, mfld_simps]
theorem mem_preimage {s : Set β} {a : α} : a ∈ f ⁻¹' s ↔ f a ∈ s :=
Iff.rfl
#align set.mem_preimage Set.mem_preimage
theorem preimage_congr {f g : α → β} {s : Set β} (h : ∀ x : α, f x = g x) : f ⁻¹' s = g ⁻¹' s := by
congr with x
simp [h]
#align set.preimage_congr Set.preimage_congr
@[gcongr]
theorem preimage_mono {s t : Set β} (h : s ⊆ t) : f ⁻¹' s ⊆ f ⁻¹' t := fun _ hx => h hx
#align set.preimage_mono Set.preimage_mono
@[simp, mfld_simps]
theorem preimage_univ : f ⁻¹' univ = univ :=
rfl
#align set.preimage_univ Set.preimage_univ
theorem subset_preimage_univ {s : Set α} : s ⊆ f ⁻¹' univ :=
subset_univ _
#align set.subset_preimage_univ Set.subset_preimage_univ
@[simp, mfld_simps]
theorem preimage_inter {s t : Set β} : f ⁻¹' (s ∩ t) = f ⁻¹' s ∩ f ⁻¹' t :=
rfl
#align set.preimage_inter Set.preimage_inter
@[simp]
theorem preimage_union {s t : Set β} : f ⁻¹' (s ∪ t) = f ⁻¹' s ∪ f ⁻¹' t :=
rfl
#align set.preimage_union Set.preimage_union
@[simp]
theorem preimage_compl {s : Set β} : f ⁻¹' sᶜ = (f ⁻¹' s)ᶜ :=
rfl
#align set.preimage_compl Set.preimage_compl
@[simp]
theorem preimage_diff (f : α → β) (s t : Set β) : f ⁻¹' (s \ t) = f ⁻¹' s \ f ⁻¹' t :=
rfl
#align set.preimage_diff Set.preimage_diff
@[simp]
lemma preimage_symmDiff {f : α → β} (s t : Set β) : f ⁻¹' (s ∆ t) = (f ⁻¹' s) ∆ (f ⁻¹' t) :=
rfl
#align set.preimage_symm_diff Set.preimage_symmDiff
@[simp]
theorem preimage_ite (f : α → β) (s t₁ t₂ : Set β) :
f ⁻¹' s.ite t₁ t₂ = (f ⁻¹' s).ite (f ⁻¹' t₁) (f ⁻¹' t₂) :=
rfl
#align set.preimage_ite Set.preimage_ite
@[simp]
theorem preimage_setOf_eq {p : α → Prop} {f : β → α} : f ⁻¹' { a | p a } = { a | p (f a) } :=
rfl
#align set.preimage_set_of_eq Set.preimage_setOf_eq
@[simp]
theorem preimage_id_eq : preimage (id : α → α) = id :=
rfl
#align set.preimage_id_eq Set.preimage_id_eq
@[mfld_simps]
theorem preimage_id {s : Set α} : id ⁻¹' s = s :=
rfl
#align set.preimage_id Set.preimage_id
@[simp, mfld_simps]
theorem preimage_id' {s : Set α} : (fun x => x) ⁻¹' s = s :=
rfl
#align set.preimage_id' Set.preimage_id'
@[simp]
theorem preimage_const_of_mem {b : β} {s : Set β} (h : b ∈ s) : (fun _ : α => b) ⁻¹' s = univ :=
eq_univ_of_forall fun _ => h
#align set.preimage_const_of_mem Set.preimage_const_of_mem
@[simp]
theorem preimage_const_of_not_mem {b : β} {s : Set β} (h : b ∉ s) : (fun _ : α => b) ⁻¹' s = ∅ :=
eq_empty_of_subset_empty fun _ hx => h hx
#align set.preimage_const_of_not_mem Set.preimage_const_of_not_mem
theorem preimage_const (b : β) (s : Set β) [Decidable (b ∈ s)] :
(fun _ : α => b) ⁻¹' s = if b ∈ s then univ else ∅ := by
split_ifs with hb
exacts [preimage_const_of_mem hb, preimage_const_of_not_mem hb]
#align set.preimage_const Set.preimage_const
/-- If preimage of each singleton under `f : α → β` is either empty or the whole type,
then `f` is a constant. -/
lemma exists_eq_const_of_preimage_singleton [Nonempty β] {f : α → β}
(hf : ∀ b : β, f ⁻¹' {b} = ∅ ∨ f ⁻¹' {b} = univ) : ∃ b, f = const α b := by
rcases em (∃ b, f ⁻¹' {b} = univ) with ⟨b, hb⟩ | hf'
· exact ⟨b, funext fun x ↦ eq_univ_iff_forall.1 hb x⟩
· have : ∀ x b, f x ≠ b := fun x b ↦
eq_empty_iff_forall_not_mem.1 ((hf b).resolve_right fun h ↦ hf' ⟨b, h⟩) x
exact ⟨Classical.arbitrary β, funext fun x ↦ absurd rfl (this x _)⟩
theorem preimage_comp {s : Set γ} : g ∘ f ⁻¹' s = f ⁻¹' (g ⁻¹' s) :=
rfl
#align set.preimage_comp Set.preimage_comp
theorem preimage_comp_eq : preimage (g ∘ f) = preimage f ∘ preimage g :=
rfl
#align set.preimage_comp_eq Set.preimage_comp_eq
theorem preimage_iterate_eq {f : α → α} {n : ℕ} : Set.preimage f^[n] = (Set.preimage f)^[n] := by
induction' n with n ih; · simp
rw [iterate_succ, iterate_succ', preimage_comp_eq, ih]
#align set.preimage_iterate_eq Set.preimage_iterate_eq
theorem preimage_preimage {g : β → γ} {f : α → β} {s : Set γ} :
f ⁻¹' (g ⁻¹' s) = (fun x => g (f x)) ⁻¹' s :=
preimage_comp.symm
#align set.preimage_preimage Set.preimage_preimage
theorem eq_preimage_subtype_val_iff {p : α → Prop} {s : Set (Subtype p)} {t : Set α} :
s = Subtype.val ⁻¹' t ↔ ∀ (x) (h : p x), (⟨x, h⟩ : Subtype p) ∈ s ↔ x ∈ t :=
⟨fun s_eq x h => by
rw [s_eq]
simp, fun h => ext fun ⟨x, hx⟩ => by simp [h]⟩
#align set.eq_preimage_subtype_val_iff Set.eq_preimage_subtype_val_iff
theorem nonempty_of_nonempty_preimage {s : Set β} {f : α → β} (hf : (f ⁻¹' s).Nonempty) :
s.Nonempty :=
let ⟨x, hx⟩ := hf
⟨f x, hx⟩
#align set.nonempty_of_nonempty_preimage Set.nonempty_of_nonempty_preimage
@[simp] theorem preimage_singleton_true (p : α → Prop) : p ⁻¹' {True} = {a | p a} := by ext; simp
#align set.preimage_singleton_true Set.preimage_singleton_true
@[simp] theorem preimage_singleton_false (p : α → Prop) : p ⁻¹' {False} = {a | ¬p a} := by ext; simp
#align set.preimage_singleton_false Set.preimage_singleton_false
theorem preimage_subtype_coe_eq_compl {s u v : Set α} (hsuv : s ⊆ u ∪ v)
(H : s ∩ (u ∩ v) = ∅) : ((↑) : s → α) ⁻¹' u = ((↑) ⁻¹' v)ᶜ := by
ext ⟨x, x_in_s⟩
constructor
· intro x_in_u x_in_v
exact eq_empty_iff_forall_not_mem.mp H x ⟨x_in_s, ⟨x_in_u, x_in_v⟩⟩
· intro hx
exact Or.elim (hsuv x_in_s) id fun hx' => hx.elim hx'
#align set.preimage_subtype_coe_eq_compl Set.preimage_subtype_coe_eq_compl
end Preimage
/-! ### Image of a set under a function -/
section Image
variable {f : α → β} {s t : Set α}
-- Porting note: `Set.image` is already defined in `Init.Set`
#align set.image Set.image
/-- `f '' s` denotes the image of `s : Set α` under the function `f : α → β`. -/
infixl:80 " '' " => image
theorem mem_image_iff_bex {f : α → β} {s : Set α} {y : β} :
y ∈ f '' s ↔ ∃ (x : _) (_ : x ∈ s), f x = y :=
bex_def.symm
#align set.mem_image_iff_bex Set.mem_image_iff_bex
@[simp]
theorem mem_image (f : α → β) (s : Set α) (y : β) : y ∈ f '' s ↔ ∃ x ∈ s, f x = y :=
Iff.rfl
#align set.mem_image Set.mem_image
theorem image_eta (f : α → β) : f '' s = (fun x => f x) '' s :=
rfl
#align set.image_eta Set.image_eta
@[mfld_simps]
theorem mem_image_of_mem (f : α → β) {x : α} {a : Set α} (h : x ∈ a) : f x ∈ f '' a :=
⟨_, h, rfl⟩
#align set.mem_image_of_mem Set.mem_image_of_mem
theorem _root_.Function.Injective.mem_set_image {f : α → β} (hf : Injective f) {s : Set α} {a : α} :
f a ∈ f '' s ↔ a ∈ s :=
⟨fun ⟨_, hb, Eq⟩ => hf Eq ▸ hb, mem_image_of_mem f⟩
#align function.injective.mem_set_image Function.Injective.mem_set_image
theorem ball_image_iff {f : α → β} {s : Set α} {p : β → Prop} :
(∀ y ∈ f '' s, p y) ↔ ∀ x ∈ s, p (f x) := by simp
#align set.ball_image_iff Set.ball_image_iff
theorem ball_image_of_ball {f : α → β} {s : Set α} {p : β → Prop} (h : ∀ x ∈ s, p (f x)) :
∀ y ∈ f '' s, p y :=
ball_image_iff.2 h
#align set.ball_image_of_ball Set.ball_image_of_ball
theorem bex_image_iff {f : α → β} {s : Set α} {p : β → Prop} :
(∃ y ∈ f '' s, p y) ↔ ∃ x ∈ s, p (f x) := by
|
simp
|
theorem bex_image_iff {f : α → β} {s : Set α} {p : β → Prop} :
(∃ y ∈ f '' s, p y) ↔ ∃ x ∈ s, p (f x) := by
|
Mathlib.Data.Set.Image.258_0.IJFiTzmYGOCpPSd
|
theorem bex_image_iff {f : α → β} {s : Set α} {p : β → Prop} :
(∃ y ∈ f '' s, p y) ↔ ∃ x ∈ s, p (f x)
|
Mathlib_Data_Set_Image
|
α : Type u_1
β : Type u_2
γ : Type u_3
ι : Sort u_4
ι' : Sort u_5
f✝ : α → β
s✝ t : Set α
f g : α → β
s : Set α
h : ∀ a ∈ s, f a = g a
⊢ f '' s = g '' s
|
/-
Copyright (c) 2014 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Leonardo de Moura
-/
import Mathlib.Data.Set.Basic
#align_import data.set.image from "leanprover-community/mathlib"@"001ffdc42920050657fd45bd2b8bfbec8eaaeb29"
/-!
# Images and preimages of sets
## Main definitions
* `preimage f t : Set α` : the preimage f⁻¹(t) (written `f ⁻¹' t` in Lean) of a subset of β.
* `range f : Set β` : the image of `univ` under `f`.
Also works for `{p : Prop} (f : p → α)` (unlike `image`)
## Notation
* `f ⁻¹' t` for `Set.preimage f t`
* `f '' s` for `Set.image f s`
## Tags
set, sets, image, preimage, pre-image, range
-/
set_option autoImplicit true
universe u v
open Function Set
namespace Set
variable {α β γ : Type*} {ι ι' : Sort*}
/-! ### Inverse image -/
/-- The preimage of `s : Set β` by `f : α → β`, written `f ⁻¹' s`,
is the set of `x : α` such that `f x ∈ s`. -/
def preimage {α : Type u} {β : Type v} (f : α → β) (s : Set β) : Set α :=
{ x | f x ∈ s }
#align set.preimage Set.preimage
/-- `f ⁻¹' t` denotes the preimage of `t : Set β` under the function `f : α → β`. -/
infixl:80 " ⁻¹' " => preimage
section Preimage
variable {f : α → β} {g : β → γ}
@[simp]
theorem preimage_empty : f ⁻¹' ∅ = ∅ :=
rfl
#align set.preimage_empty Set.preimage_empty
@[simp, mfld_simps]
theorem mem_preimage {s : Set β} {a : α} : a ∈ f ⁻¹' s ↔ f a ∈ s :=
Iff.rfl
#align set.mem_preimage Set.mem_preimage
theorem preimage_congr {f g : α → β} {s : Set β} (h : ∀ x : α, f x = g x) : f ⁻¹' s = g ⁻¹' s := by
congr with x
simp [h]
#align set.preimage_congr Set.preimage_congr
@[gcongr]
theorem preimage_mono {s t : Set β} (h : s ⊆ t) : f ⁻¹' s ⊆ f ⁻¹' t := fun _ hx => h hx
#align set.preimage_mono Set.preimage_mono
@[simp, mfld_simps]
theorem preimage_univ : f ⁻¹' univ = univ :=
rfl
#align set.preimage_univ Set.preimage_univ
theorem subset_preimage_univ {s : Set α} : s ⊆ f ⁻¹' univ :=
subset_univ _
#align set.subset_preimage_univ Set.subset_preimage_univ
@[simp, mfld_simps]
theorem preimage_inter {s t : Set β} : f ⁻¹' (s ∩ t) = f ⁻¹' s ∩ f ⁻¹' t :=
rfl
#align set.preimage_inter Set.preimage_inter
@[simp]
theorem preimage_union {s t : Set β} : f ⁻¹' (s ∪ t) = f ⁻¹' s ∪ f ⁻¹' t :=
rfl
#align set.preimage_union Set.preimage_union
@[simp]
theorem preimage_compl {s : Set β} : f ⁻¹' sᶜ = (f ⁻¹' s)ᶜ :=
rfl
#align set.preimage_compl Set.preimage_compl
@[simp]
theorem preimage_diff (f : α → β) (s t : Set β) : f ⁻¹' (s \ t) = f ⁻¹' s \ f ⁻¹' t :=
rfl
#align set.preimage_diff Set.preimage_diff
@[simp]
lemma preimage_symmDiff {f : α → β} (s t : Set β) : f ⁻¹' (s ∆ t) = (f ⁻¹' s) ∆ (f ⁻¹' t) :=
rfl
#align set.preimage_symm_diff Set.preimage_symmDiff
@[simp]
theorem preimage_ite (f : α → β) (s t₁ t₂ : Set β) :
f ⁻¹' s.ite t₁ t₂ = (f ⁻¹' s).ite (f ⁻¹' t₁) (f ⁻¹' t₂) :=
rfl
#align set.preimage_ite Set.preimage_ite
@[simp]
theorem preimage_setOf_eq {p : α → Prop} {f : β → α} : f ⁻¹' { a | p a } = { a | p (f a) } :=
rfl
#align set.preimage_set_of_eq Set.preimage_setOf_eq
@[simp]
theorem preimage_id_eq : preimage (id : α → α) = id :=
rfl
#align set.preimage_id_eq Set.preimage_id_eq
@[mfld_simps]
theorem preimage_id {s : Set α} : id ⁻¹' s = s :=
rfl
#align set.preimage_id Set.preimage_id
@[simp, mfld_simps]
theorem preimage_id' {s : Set α} : (fun x => x) ⁻¹' s = s :=
rfl
#align set.preimage_id' Set.preimage_id'
@[simp]
theorem preimage_const_of_mem {b : β} {s : Set β} (h : b ∈ s) : (fun _ : α => b) ⁻¹' s = univ :=
eq_univ_of_forall fun _ => h
#align set.preimage_const_of_mem Set.preimage_const_of_mem
@[simp]
theorem preimage_const_of_not_mem {b : β} {s : Set β} (h : b ∉ s) : (fun _ : α => b) ⁻¹' s = ∅ :=
eq_empty_of_subset_empty fun _ hx => h hx
#align set.preimage_const_of_not_mem Set.preimage_const_of_not_mem
theorem preimage_const (b : β) (s : Set β) [Decidable (b ∈ s)] :
(fun _ : α => b) ⁻¹' s = if b ∈ s then univ else ∅ := by
split_ifs with hb
exacts [preimage_const_of_mem hb, preimage_const_of_not_mem hb]
#align set.preimage_const Set.preimage_const
/-- If preimage of each singleton under `f : α → β` is either empty or the whole type,
then `f` is a constant. -/
lemma exists_eq_const_of_preimage_singleton [Nonempty β] {f : α → β}
(hf : ∀ b : β, f ⁻¹' {b} = ∅ ∨ f ⁻¹' {b} = univ) : ∃ b, f = const α b := by
rcases em (∃ b, f ⁻¹' {b} = univ) with ⟨b, hb⟩ | hf'
· exact ⟨b, funext fun x ↦ eq_univ_iff_forall.1 hb x⟩
· have : ∀ x b, f x ≠ b := fun x b ↦
eq_empty_iff_forall_not_mem.1 ((hf b).resolve_right fun h ↦ hf' ⟨b, h⟩) x
exact ⟨Classical.arbitrary β, funext fun x ↦ absurd rfl (this x _)⟩
theorem preimage_comp {s : Set γ} : g ∘ f ⁻¹' s = f ⁻¹' (g ⁻¹' s) :=
rfl
#align set.preimage_comp Set.preimage_comp
theorem preimage_comp_eq : preimage (g ∘ f) = preimage f ∘ preimage g :=
rfl
#align set.preimage_comp_eq Set.preimage_comp_eq
theorem preimage_iterate_eq {f : α → α} {n : ℕ} : Set.preimage f^[n] = (Set.preimage f)^[n] := by
induction' n with n ih; · simp
rw [iterate_succ, iterate_succ', preimage_comp_eq, ih]
#align set.preimage_iterate_eq Set.preimage_iterate_eq
theorem preimage_preimage {g : β → γ} {f : α → β} {s : Set γ} :
f ⁻¹' (g ⁻¹' s) = (fun x => g (f x)) ⁻¹' s :=
preimage_comp.symm
#align set.preimage_preimage Set.preimage_preimage
theorem eq_preimage_subtype_val_iff {p : α → Prop} {s : Set (Subtype p)} {t : Set α} :
s = Subtype.val ⁻¹' t ↔ ∀ (x) (h : p x), (⟨x, h⟩ : Subtype p) ∈ s ↔ x ∈ t :=
⟨fun s_eq x h => by
rw [s_eq]
simp, fun h => ext fun ⟨x, hx⟩ => by simp [h]⟩
#align set.eq_preimage_subtype_val_iff Set.eq_preimage_subtype_val_iff
theorem nonempty_of_nonempty_preimage {s : Set β} {f : α → β} (hf : (f ⁻¹' s).Nonempty) :
s.Nonempty :=
let ⟨x, hx⟩ := hf
⟨f x, hx⟩
#align set.nonempty_of_nonempty_preimage Set.nonempty_of_nonempty_preimage
@[simp] theorem preimage_singleton_true (p : α → Prop) : p ⁻¹' {True} = {a | p a} := by ext; simp
#align set.preimage_singleton_true Set.preimage_singleton_true
@[simp] theorem preimage_singleton_false (p : α → Prop) : p ⁻¹' {False} = {a | ¬p a} := by ext; simp
#align set.preimage_singleton_false Set.preimage_singleton_false
theorem preimage_subtype_coe_eq_compl {s u v : Set α} (hsuv : s ⊆ u ∪ v)
(H : s ∩ (u ∩ v) = ∅) : ((↑) : s → α) ⁻¹' u = ((↑) ⁻¹' v)ᶜ := by
ext ⟨x, x_in_s⟩
constructor
· intro x_in_u x_in_v
exact eq_empty_iff_forall_not_mem.mp H x ⟨x_in_s, ⟨x_in_u, x_in_v⟩⟩
· intro hx
exact Or.elim (hsuv x_in_s) id fun hx' => hx.elim hx'
#align set.preimage_subtype_coe_eq_compl Set.preimage_subtype_coe_eq_compl
end Preimage
/-! ### Image of a set under a function -/
section Image
variable {f : α → β} {s t : Set α}
-- Porting note: `Set.image` is already defined in `Init.Set`
#align set.image Set.image
/-- `f '' s` denotes the image of `s : Set α` under the function `f : α → β`. -/
infixl:80 " '' " => image
theorem mem_image_iff_bex {f : α → β} {s : Set α} {y : β} :
y ∈ f '' s ↔ ∃ (x : _) (_ : x ∈ s), f x = y :=
bex_def.symm
#align set.mem_image_iff_bex Set.mem_image_iff_bex
@[simp]
theorem mem_image (f : α → β) (s : Set α) (y : β) : y ∈ f '' s ↔ ∃ x ∈ s, f x = y :=
Iff.rfl
#align set.mem_image Set.mem_image
theorem image_eta (f : α → β) : f '' s = (fun x => f x) '' s :=
rfl
#align set.image_eta Set.image_eta
@[mfld_simps]
theorem mem_image_of_mem (f : α → β) {x : α} {a : Set α} (h : x ∈ a) : f x ∈ f '' a :=
⟨_, h, rfl⟩
#align set.mem_image_of_mem Set.mem_image_of_mem
theorem _root_.Function.Injective.mem_set_image {f : α → β} (hf : Injective f) {s : Set α} {a : α} :
f a ∈ f '' s ↔ a ∈ s :=
⟨fun ⟨_, hb, Eq⟩ => hf Eq ▸ hb, mem_image_of_mem f⟩
#align function.injective.mem_set_image Function.Injective.mem_set_image
theorem ball_image_iff {f : α → β} {s : Set α} {p : β → Prop} :
(∀ y ∈ f '' s, p y) ↔ ∀ x ∈ s, p (f x) := by simp
#align set.ball_image_iff Set.ball_image_iff
theorem ball_image_of_ball {f : α → β} {s : Set α} {p : β → Prop} (h : ∀ x ∈ s, p (f x)) :
∀ y ∈ f '' s, p y :=
ball_image_iff.2 h
#align set.ball_image_of_ball Set.ball_image_of_ball
theorem bex_image_iff {f : α → β} {s : Set α} {p : β → Prop} :
(∃ y ∈ f '' s, p y) ↔ ∃ x ∈ s, p (f x) := by simp
#align set.bex_image_iff Set.bex_image_iff
theorem mem_image_elim {f : α → β} {s : Set α} {C : β → Prop} (h : ∀ x : α, x ∈ s → C (f x)) :
∀ {y : β}, y ∈ f '' s → C y
| _, ⟨a, a_in, rfl⟩ => h a a_in
#align set.mem_image_elim Set.mem_image_elim
theorem mem_image_elim_on {f : α → β} {s : Set α} {C : β → Prop} {y : β} (h_y : y ∈ f '' s)
(h : ∀ x : α, x ∈ s → C (f x)) : C y :=
mem_image_elim h h_y
#align set.mem_image_elim_on Set.mem_image_elim_on
-- Porting note: used to be `safe`
@[congr]
theorem image_congr {f g : α → β} {s : Set α} (h : ∀ a ∈ s, f a = g a) : f '' s = g '' s := by
|
ext x
|
@[congr]
theorem image_congr {f g : α → β} {s : Set α} (h : ∀ a ∈ s, f a = g a) : f '' s = g '' s := by
|
Mathlib.Data.Set.Image.273_0.IJFiTzmYGOCpPSd
|
@[congr]
theorem image_congr {f g : α → β} {s : Set α} (h : ∀ a ∈ s, f a = g a) : f '' s = g '' s
|
Mathlib_Data_Set_Image
|
case h
α : Type u_1
β : Type u_2
γ : Type u_3
ι : Sort u_4
ι' : Sort u_5
f✝ : α → β
s✝ t : Set α
f g : α → β
s : Set α
h : ∀ a ∈ s, f a = g a
x : β
⊢ x ∈ f '' s ↔ x ∈ g '' s
|
/-
Copyright (c) 2014 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Leonardo de Moura
-/
import Mathlib.Data.Set.Basic
#align_import data.set.image from "leanprover-community/mathlib"@"001ffdc42920050657fd45bd2b8bfbec8eaaeb29"
/-!
# Images and preimages of sets
## Main definitions
* `preimage f t : Set α` : the preimage f⁻¹(t) (written `f ⁻¹' t` in Lean) of a subset of β.
* `range f : Set β` : the image of `univ` under `f`.
Also works for `{p : Prop} (f : p → α)` (unlike `image`)
## Notation
* `f ⁻¹' t` for `Set.preimage f t`
* `f '' s` for `Set.image f s`
## Tags
set, sets, image, preimage, pre-image, range
-/
set_option autoImplicit true
universe u v
open Function Set
namespace Set
variable {α β γ : Type*} {ι ι' : Sort*}
/-! ### Inverse image -/
/-- The preimage of `s : Set β` by `f : α → β`, written `f ⁻¹' s`,
is the set of `x : α` such that `f x ∈ s`. -/
def preimage {α : Type u} {β : Type v} (f : α → β) (s : Set β) : Set α :=
{ x | f x ∈ s }
#align set.preimage Set.preimage
/-- `f ⁻¹' t` denotes the preimage of `t : Set β` under the function `f : α → β`. -/
infixl:80 " ⁻¹' " => preimage
section Preimage
variable {f : α → β} {g : β → γ}
@[simp]
theorem preimage_empty : f ⁻¹' ∅ = ∅ :=
rfl
#align set.preimage_empty Set.preimage_empty
@[simp, mfld_simps]
theorem mem_preimage {s : Set β} {a : α} : a ∈ f ⁻¹' s ↔ f a ∈ s :=
Iff.rfl
#align set.mem_preimage Set.mem_preimage
theorem preimage_congr {f g : α → β} {s : Set β} (h : ∀ x : α, f x = g x) : f ⁻¹' s = g ⁻¹' s := by
congr with x
simp [h]
#align set.preimage_congr Set.preimage_congr
@[gcongr]
theorem preimage_mono {s t : Set β} (h : s ⊆ t) : f ⁻¹' s ⊆ f ⁻¹' t := fun _ hx => h hx
#align set.preimage_mono Set.preimage_mono
@[simp, mfld_simps]
theorem preimage_univ : f ⁻¹' univ = univ :=
rfl
#align set.preimage_univ Set.preimage_univ
theorem subset_preimage_univ {s : Set α} : s ⊆ f ⁻¹' univ :=
subset_univ _
#align set.subset_preimage_univ Set.subset_preimage_univ
@[simp, mfld_simps]
theorem preimage_inter {s t : Set β} : f ⁻¹' (s ∩ t) = f ⁻¹' s ∩ f ⁻¹' t :=
rfl
#align set.preimage_inter Set.preimage_inter
@[simp]
theorem preimage_union {s t : Set β} : f ⁻¹' (s ∪ t) = f ⁻¹' s ∪ f ⁻¹' t :=
rfl
#align set.preimage_union Set.preimage_union
@[simp]
theorem preimage_compl {s : Set β} : f ⁻¹' sᶜ = (f ⁻¹' s)ᶜ :=
rfl
#align set.preimage_compl Set.preimage_compl
@[simp]
theorem preimage_diff (f : α → β) (s t : Set β) : f ⁻¹' (s \ t) = f ⁻¹' s \ f ⁻¹' t :=
rfl
#align set.preimage_diff Set.preimage_diff
@[simp]
lemma preimage_symmDiff {f : α → β} (s t : Set β) : f ⁻¹' (s ∆ t) = (f ⁻¹' s) ∆ (f ⁻¹' t) :=
rfl
#align set.preimage_symm_diff Set.preimage_symmDiff
@[simp]
theorem preimage_ite (f : α → β) (s t₁ t₂ : Set β) :
f ⁻¹' s.ite t₁ t₂ = (f ⁻¹' s).ite (f ⁻¹' t₁) (f ⁻¹' t₂) :=
rfl
#align set.preimage_ite Set.preimage_ite
@[simp]
theorem preimage_setOf_eq {p : α → Prop} {f : β → α} : f ⁻¹' { a | p a } = { a | p (f a) } :=
rfl
#align set.preimage_set_of_eq Set.preimage_setOf_eq
@[simp]
theorem preimage_id_eq : preimage (id : α → α) = id :=
rfl
#align set.preimage_id_eq Set.preimage_id_eq
@[mfld_simps]
theorem preimage_id {s : Set α} : id ⁻¹' s = s :=
rfl
#align set.preimage_id Set.preimage_id
@[simp, mfld_simps]
theorem preimage_id' {s : Set α} : (fun x => x) ⁻¹' s = s :=
rfl
#align set.preimage_id' Set.preimage_id'
@[simp]
theorem preimage_const_of_mem {b : β} {s : Set β} (h : b ∈ s) : (fun _ : α => b) ⁻¹' s = univ :=
eq_univ_of_forall fun _ => h
#align set.preimage_const_of_mem Set.preimage_const_of_mem
@[simp]
theorem preimage_const_of_not_mem {b : β} {s : Set β} (h : b ∉ s) : (fun _ : α => b) ⁻¹' s = ∅ :=
eq_empty_of_subset_empty fun _ hx => h hx
#align set.preimage_const_of_not_mem Set.preimage_const_of_not_mem
theorem preimage_const (b : β) (s : Set β) [Decidable (b ∈ s)] :
(fun _ : α => b) ⁻¹' s = if b ∈ s then univ else ∅ := by
split_ifs with hb
exacts [preimage_const_of_mem hb, preimage_const_of_not_mem hb]
#align set.preimage_const Set.preimage_const
/-- If preimage of each singleton under `f : α → β` is either empty or the whole type,
then `f` is a constant. -/
lemma exists_eq_const_of_preimage_singleton [Nonempty β] {f : α → β}
(hf : ∀ b : β, f ⁻¹' {b} = ∅ ∨ f ⁻¹' {b} = univ) : ∃ b, f = const α b := by
rcases em (∃ b, f ⁻¹' {b} = univ) with ⟨b, hb⟩ | hf'
· exact ⟨b, funext fun x ↦ eq_univ_iff_forall.1 hb x⟩
· have : ∀ x b, f x ≠ b := fun x b ↦
eq_empty_iff_forall_not_mem.1 ((hf b).resolve_right fun h ↦ hf' ⟨b, h⟩) x
exact ⟨Classical.arbitrary β, funext fun x ↦ absurd rfl (this x _)⟩
theorem preimage_comp {s : Set γ} : g ∘ f ⁻¹' s = f ⁻¹' (g ⁻¹' s) :=
rfl
#align set.preimage_comp Set.preimage_comp
theorem preimage_comp_eq : preimage (g ∘ f) = preimage f ∘ preimage g :=
rfl
#align set.preimage_comp_eq Set.preimage_comp_eq
theorem preimage_iterate_eq {f : α → α} {n : ℕ} : Set.preimage f^[n] = (Set.preimage f)^[n] := by
induction' n with n ih; · simp
rw [iterate_succ, iterate_succ', preimage_comp_eq, ih]
#align set.preimage_iterate_eq Set.preimage_iterate_eq
theorem preimage_preimage {g : β → γ} {f : α → β} {s : Set γ} :
f ⁻¹' (g ⁻¹' s) = (fun x => g (f x)) ⁻¹' s :=
preimage_comp.symm
#align set.preimage_preimage Set.preimage_preimage
theorem eq_preimage_subtype_val_iff {p : α → Prop} {s : Set (Subtype p)} {t : Set α} :
s = Subtype.val ⁻¹' t ↔ ∀ (x) (h : p x), (⟨x, h⟩ : Subtype p) ∈ s ↔ x ∈ t :=
⟨fun s_eq x h => by
rw [s_eq]
simp, fun h => ext fun ⟨x, hx⟩ => by simp [h]⟩
#align set.eq_preimage_subtype_val_iff Set.eq_preimage_subtype_val_iff
theorem nonempty_of_nonempty_preimage {s : Set β} {f : α → β} (hf : (f ⁻¹' s).Nonempty) :
s.Nonempty :=
let ⟨x, hx⟩ := hf
⟨f x, hx⟩
#align set.nonempty_of_nonempty_preimage Set.nonempty_of_nonempty_preimage
@[simp] theorem preimage_singleton_true (p : α → Prop) : p ⁻¹' {True} = {a | p a} := by ext; simp
#align set.preimage_singleton_true Set.preimage_singleton_true
@[simp] theorem preimage_singleton_false (p : α → Prop) : p ⁻¹' {False} = {a | ¬p a} := by ext; simp
#align set.preimage_singleton_false Set.preimage_singleton_false
theorem preimage_subtype_coe_eq_compl {s u v : Set α} (hsuv : s ⊆ u ∪ v)
(H : s ∩ (u ∩ v) = ∅) : ((↑) : s → α) ⁻¹' u = ((↑) ⁻¹' v)ᶜ := by
ext ⟨x, x_in_s⟩
constructor
· intro x_in_u x_in_v
exact eq_empty_iff_forall_not_mem.mp H x ⟨x_in_s, ⟨x_in_u, x_in_v⟩⟩
· intro hx
exact Or.elim (hsuv x_in_s) id fun hx' => hx.elim hx'
#align set.preimage_subtype_coe_eq_compl Set.preimage_subtype_coe_eq_compl
end Preimage
/-! ### Image of a set under a function -/
section Image
variable {f : α → β} {s t : Set α}
-- Porting note: `Set.image` is already defined in `Init.Set`
#align set.image Set.image
/-- `f '' s` denotes the image of `s : Set α` under the function `f : α → β`. -/
infixl:80 " '' " => image
theorem mem_image_iff_bex {f : α → β} {s : Set α} {y : β} :
y ∈ f '' s ↔ ∃ (x : _) (_ : x ∈ s), f x = y :=
bex_def.symm
#align set.mem_image_iff_bex Set.mem_image_iff_bex
@[simp]
theorem mem_image (f : α → β) (s : Set α) (y : β) : y ∈ f '' s ↔ ∃ x ∈ s, f x = y :=
Iff.rfl
#align set.mem_image Set.mem_image
theorem image_eta (f : α → β) : f '' s = (fun x => f x) '' s :=
rfl
#align set.image_eta Set.image_eta
@[mfld_simps]
theorem mem_image_of_mem (f : α → β) {x : α} {a : Set α} (h : x ∈ a) : f x ∈ f '' a :=
⟨_, h, rfl⟩
#align set.mem_image_of_mem Set.mem_image_of_mem
theorem _root_.Function.Injective.mem_set_image {f : α → β} (hf : Injective f) {s : Set α} {a : α} :
f a ∈ f '' s ↔ a ∈ s :=
⟨fun ⟨_, hb, Eq⟩ => hf Eq ▸ hb, mem_image_of_mem f⟩
#align function.injective.mem_set_image Function.Injective.mem_set_image
theorem ball_image_iff {f : α → β} {s : Set α} {p : β → Prop} :
(∀ y ∈ f '' s, p y) ↔ ∀ x ∈ s, p (f x) := by simp
#align set.ball_image_iff Set.ball_image_iff
theorem ball_image_of_ball {f : α → β} {s : Set α} {p : β → Prop} (h : ∀ x ∈ s, p (f x)) :
∀ y ∈ f '' s, p y :=
ball_image_iff.2 h
#align set.ball_image_of_ball Set.ball_image_of_ball
theorem bex_image_iff {f : α → β} {s : Set α} {p : β → Prop} :
(∃ y ∈ f '' s, p y) ↔ ∃ x ∈ s, p (f x) := by simp
#align set.bex_image_iff Set.bex_image_iff
theorem mem_image_elim {f : α → β} {s : Set α} {C : β → Prop} (h : ∀ x : α, x ∈ s → C (f x)) :
∀ {y : β}, y ∈ f '' s → C y
| _, ⟨a, a_in, rfl⟩ => h a a_in
#align set.mem_image_elim Set.mem_image_elim
theorem mem_image_elim_on {f : α → β} {s : Set α} {C : β → Prop} {y : β} (h_y : y ∈ f '' s)
(h : ∀ x : α, x ∈ s → C (f x)) : C y :=
mem_image_elim h h_y
#align set.mem_image_elim_on Set.mem_image_elim_on
-- Porting note: used to be `safe`
@[congr]
theorem image_congr {f g : α → β} {s : Set α} (h : ∀ a ∈ s, f a = g a) : f '' s = g '' s := by
ext x
|
rw [mem_image, mem_image]
|
@[congr]
theorem image_congr {f g : α → β} {s : Set α} (h : ∀ a ∈ s, f a = g a) : f '' s = g '' s := by
ext x
|
Mathlib.Data.Set.Image.273_0.IJFiTzmYGOCpPSd
|
@[congr]
theorem image_congr {f g : α → β} {s : Set α} (h : ∀ a ∈ s, f a = g a) : f '' s = g '' s
|
Mathlib_Data_Set_Image
|
case h
α : Type u_1
β : Type u_2
γ : Type u_3
ι : Sort u_4
ι' : Sort u_5
f✝ : α → β
s✝ t : Set α
f g : α → β
s : Set α
h : ∀ a ∈ s, f a = g a
x : β
⊢ (∃ x_1 ∈ s, f x_1 = x) ↔ ∃ x_1 ∈ s, g x_1 = x
|
/-
Copyright (c) 2014 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Leonardo de Moura
-/
import Mathlib.Data.Set.Basic
#align_import data.set.image from "leanprover-community/mathlib"@"001ffdc42920050657fd45bd2b8bfbec8eaaeb29"
/-!
# Images and preimages of sets
## Main definitions
* `preimage f t : Set α` : the preimage f⁻¹(t) (written `f ⁻¹' t` in Lean) of a subset of β.
* `range f : Set β` : the image of `univ` under `f`.
Also works for `{p : Prop} (f : p → α)` (unlike `image`)
## Notation
* `f ⁻¹' t` for `Set.preimage f t`
* `f '' s` for `Set.image f s`
## Tags
set, sets, image, preimage, pre-image, range
-/
set_option autoImplicit true
universe u v
open Function Set
namespace Set
variable {α β γ : Type*} {ι ι' : Sort*}
/-! ### Inverse image -/
/-- The preimage of `s : Set β` by `f : α → β`, written `f ⁻¹' s`,
is the set of `x : α` such that `f x ∈ s`. -/
def preimage {α : Type u} {β : Type v} (f : α → β) (s : Set β) : Set α :=
{ x | f x ∈ s }
#align set.preimage Set.preimage
/-- `f ⁻¹' t` denotes the preimage of `t : Set β` under the function `f : α → β`. -/
infixl:80 " ⁻¹' " => preimage
section Preimage
variable {f : α → β} {g : β → γ}
@[simp]
theorem preimage_empty : f ⁻¹' ∅ = ∅ :=
rfl
#align set.preimage_empty Set.preimage_empty
@[simp, mfld_simps]
theorem mem_preimage {s : Set β} {a : α} : a ∈ f ⁻¹' s ↔ f a ∈ s :=
Iff.rfl
#align set.mem_preimage Set.mem_preimage
theorem preimage_congr {f g : α → β} {s : Set β} (h : ∀ x : α, f x = g x) : f ⁻¹' s = g ⁻¹' s := by
congr with x
simp [h]
#align set.preimage_congr Set.preimage_congr
@[gcongr]
theorem preimage_mono {s t : Set β} (h : s ⊆ t) : f ⁻¹' s ⊆ f ⁻¹' t := fun _ hx => h hx
#align set.preimage_mono Set.preimage_mono
@[simp, mfld_simps]
theorem preimage_univ : f ⁻¹' univ = univ :=
rfl
#align set.preimage_univ Set.preimage_univ
theorem subset_preimage_univ {s : Set α} : s ⊆ f ⁻¹' univ :=
subset_univ _
#align set.subset_preimage_univ Set.subset_preimage_univ
@[simp, mfld_simps]
theorem preimage_inter {s t : Set β} : f ⁻¹' (s ∩ t) = f ⁻¹' s ∩ f ⁻¹' t :=
rfl
#align set.preimage_inter Set.preimage_inter
@[simp]
theorem preimage_union {s t : Set β} : f ⁻¹' (s ∪ t) = f ⁻¹' s ∪ f ⁻¹' t :=
rfl
#align set.preimage_union Set.preimage_union
@[simp]
theorem preimage_compl {s : Set β} : f ⁻¹' sᶜ = (f ⁻¹' s)ᶜ :=
rfl
#align set.preimage_compl Set.preimage_compl
@[simp]
theorem preimage_diff (f : α → β) (s t : Set β) : f ⁻¹' (s \ t) = f ⁻¹' s \ f ⁻¹' t :=
rfl
#align set.preimage_diff Set.preimage_diff
@[simp]
lemma preimage_symmDiff {f : α → β} (s t : Set β) : f ⁻¹' (s ∆ t) = (f ⁻¹' s) ∆ (f ⁻¹' t) :=
rfl
#align set.preimage_symm_diff Set.preimage_symmDiff
@[simp]
theorem preimage_ite (f : α → β) (s t₁ t₂ : Set β) :
f ⁻¹' s.ite t₁ t₂ = (f ⁻¹' s).ite (f ⁻¹' t₁) (f ⁻¹' t₂) :=
rfl
#align set.preimage_ite Set.preimage_ite
@[simp]
theorem preimage_setOf_eq {p : α → Prop} {f : β → α} : f ⁻¹' { a | p a } = { a | p (f a) } :=
rfl
#align set.preimage_set_of_eq Set.preimage_setOf_eq
@[simp]
theorem preimage_id_eq : preimage (id : α → α) = id :=
rfl
#align set.preimage_id_eq Set.preimage_id_eq
@[mfld_simps]
theorem preimage_id {s : Set α} : id ⁻¹' s = s :=
rfl
#align set.preimage_id Set.preimage_id
@[simp, mfld_simps]
theorem preimage_id' {s : Set α} : (fun x => x) ⁻¹' s = s :=
rfl
#align set.preimage_id' Set.preimage_id'
@[simp]
theorem preimage_const_of_mem {b : β} {s : Set β} (h : b ∈ s) : (fun _ : α => b) ⁻¹' s = univ :=
eq_univ_of_forall fun _ => h
#align set.preimage_const_of_mem Set.preimage_const_of_mem
@[simp]
theorem preimage_const_of_not_mem {b : β} {s : Set β} (h : b ∉ s) : (fun _ : α => b) ⁻¹' s = ∅ :=
eq_empty_of_subset_empty fun _ hx => h hx
#align set.preimage_const_of_not_mem Set.preimage_const_of_not_mem
theorem preimage_const (b : β) (s : Set β) [Decidable (b ∈ s)] :
(fun _ : α => b) ⁻¹' s = if b ∈ s then univ else ∅ := by
split_ifs with hb
exacts [preimage_const_of_mem hb, preimage_const_of_not_mem hb]
#align set.preimage_const Set.preimage_const
/-- If preimage of each singleton under `f : α → β` is either empty or the whole type,
then `f` is a constant. -/
lemma exists_eq_const_of_preimage_singleton [Nonempty β] {f : α → β}
(hf : ∀ b : β, f ⁻¹' {b} = ∅ ∨ f ⁻¹' {b} = univ) : ∃ b, f = const α b := by
rcases em (∃ b, f ⁻¹' {b} = univ) with ⟨b, hb⟩ | hf'
· exact ⟨b, funext fun x ↦ eq_univ_iff_forall.1 hb x⟩
· have : ∀ x b, f x ≠ b := fun x b ↦
eq_empty_iff_forall_not_mem.1 ((hf b).resolve_right fun h ↦ hf' ⟨b, h⟩) x
exact ⟨Classical.arbitrary β, funext fun x ↦ absurd rfl (this x _)⟩
theorem preimage_comp {s : Set γ} : g ∘ f ⁻¹' s = f ⁻¹' (g ⁻¹' s) :=
rfl
#align set.preimage_comp Set.preimage_comp
theorem preimage_comp_eq : preimage (g ∘ f) = preimage f ∘ preimage g :=
rfl
#align set.preimage_comp_eq Set.preimage_comp_eq
theorem preimage_iterate_eq {f : α → α} {n : ℕ} : Set.preimage f^[n] = (Set.preimage f)^[n] := by
induction' n with n ih; · simp
rw [iterate_succ, iterate_succ', preimage_comp_eq, ih]
#align set.preimage_iterate_eq Set.preimage_iterate_eq
theorem preimage_preimage {g : β → γ} {f : α → β} {s : Set γ} :
f ⁻¹' (g ⁻¹' s) = (fun x => g (f x)) ⁻¹' s :=
preimage_comp.symm
#align set.preimage_preimage Set.preimage_preimage
theorem eq_preimage_subtype_val_iff {p : α → Prop} {s : Set (Subtype p)} {t : Set α} :
s = Subtype.val ⁻¹' t ↔ ∀ (x) (h : p x), (⟨x, h⟩ : Subtype p) ∈ s ↔ x ∈ t :=
⟨fun s_eq x h => by
rw [s_eq]
simp, fun h => ext fun ⟨x, hx⟩ => by simp [h]⟩
#align set.eq_preimage_subtype_val_iff Set.eq_preimage_subtype_val_iff
theorem nonempty_of_nonempty_preimage {s : Set β} {f : α → β} (hf : (f ⁻¹' s).Nonempty) :
s.Nonempty :=
let ⟨x, hx⟩ := hf
⟨f x, hx⟩
#align set.nonempty_of_nonempty_preimage Set.nonempty_of_nonempty_preimage
@[simp] theorem preimage_singleton_true (p : α → Prop) : p ⁻¹' {True} = {a | p a} := by ext; simp
#align set.preimage_singleton_true Set.preimage_singleton_true
@[simp] theorem preimage_singleton_false (p : α → Prop) : p ⁻¹' {False} = {a | ¬p a} := by ext; simp
#align set.preimage_singleton_false Set.preimage_singleton_false
theorem preimage_subtype_coe_eq_compl {s u v : Set α} (hsuv : s ⊆ u ∪ v)
(H : s ∩ (u ∩ v) = ∅) : ((↑) : s → α) ⁻¹' u = ((↑) ⁻¹' v)ᶜ := by
ext ⟨x, x_in_s⟩
constructor
· intro x_in_u x_in_v
exact eq_empty_iff_forall_not_mem.mp H x ⟨x_in_s, ⟨x_in_u, x_in_v⟩⟩
· intro hx
exact Or.elim (hsuv x_in_s) id fun hx' => hx.elim hx'
#align set.preimage_subtype_coe_eq_compl Set.preimage_subtype_coe_eq_compl
end Preimage
/-! ### Image of a set under a function -/
section Image
variable {f : α → β} {s t : Set α}
-- Porting note: `Set.image` is already defined in `Init.Set`
#align set.image Set.image
/-- `f '' s` denotes the image of `s : Set α` under the function `f : α → β`. -/
infixl:80 " '' " => image
theorem mem_image_iff_bex {f : α → β} {s : Set α} {y : β} :
y ∈ f '' s ↔ ∃ (x : _) (_ : x ∈ s), f x = y :=
bex_def.symm
#align set.mem_image_iff_bex Set.mem_image_iff_bex
@[simp]
theorem mem_image (f : α → β) (s : Set α) (y : β) : y ∈ f '' s ↔ ∃ x ∈ s, f x = y :=
Iff.rfl
#align set.mem_image Set.mem_image
theorem image_eta (f : α → β) : f '' s = (fun x => f x) '' s :=
rfl
#align set.image_eta Set.image_eta
@[mfld_simps]
theorem mem_image_of_mem (f : α → β) {x : α} {a : Set α} (h : x ∈ a) : f x ∈ f '' a :=
⟨_, h, rfl⟩
#align set.mem_image_of_mem Set.mem_image_of_mem
theorem _root_.Function.Injective.mem_set_image {f : α → β} (hf : Injective f) {s : Set α} {a : α} :
f a ∈ f '' s ↔ a ∈ s :=
⟨fun ⟨_, hb, Eq⟩ => hf Eq ▸ hb, mem_image_of_mem f⟩
#align function.injective.mem_set_image Function.Injective.mem_set_image
theorem ball_image_iff {f : α → β} {s : Set α} {p : β → Prop} :
(∀ y ∈ f '' s, p y) ↔ ∀ x ∈ s, p (f x) := by simp
#align set.ball_image_iff Set.ball_image_iff
theorem ball_image_of_ball {f : α → β} {s : Set α} {p : β → Prop} (h : ∀ x ∈ s, p (f x)) :
∀ y ∈ f '' s, p y :=
ball_image_iff.2 h
#align set.ball_image_of_ball Set.ball_image_of_ball
theorem bex_image_iff {f : α → β} {s : Set α} {p : β → Prop} :
(∃ y ∈ f '' s, p y) ↔ ∃ x ∈ s, p (f x) := by simp
#align set.bex_image_iff Set.bex_image_iff
theorem mem_image_elim {f : α → β} {s : Set α} {C : β → Prop} (h : ∀ x : α, x ∈ s → C (f x)) :
∀ {y : β}, y ∈ f '' s → C y
| _, ⟨a, a_in, rfl⟩ => h a a_in
#align set.mem_image_elim Set.mem_image_elim
theorem mem_image_elim_on {f : α → β} {s : Set α} {C : β → Prop} {y : β} (h_y : y ∈ f '' s)
(h : ∀ x : α, x ∈ s → C (f x)) : C y :=
mem_image_elim h h_y
#align set.mem_image_elim_on Set.mem_image_elim_on
-- Porting note: used to be `safe`
@[congr]
theorem image_congr {f g : α → β} {s : Set α} (h : ∀ a ∈ s, f a = g a) : f '' s = g '' s := by
ext x
rw [mem_image, mem_image]
|
exact {
mp := by
rintro ⟨a, ha1, ha2⟩
exact ⟨a, ⟨ha1, (h a ha1) ▸ ha2⟩⟩,
mpr := by
rintro ⟨a, ha1, ha2⟩
exact ⟨a, ⟨ha1, (h a ha1) ▸ ha2⟩⟩
}
|
@[congr]
theorem image_congr {f g : α → β} {s : Set α} (h : ∀ a ∈ s, f a = g a) : f '' s = g '' s := by
ext x
rw [mem_image, mem_image]
|
Mathlib.Data.Set.Image.273_0.IJFiTzmYGOCpPSd
|
@[congr]
theorem image_congr {f g : α → β} {s : Set α} (h : ∀ a ∈ s, f a = g a) : f '' s = g '' s
|
Mathlib_Data_Set_Image
|
α : Type u_1
β : Type u_2
γ : Type u_3
ι : Sort u_4
ι' : Sort u_5
f✝ : α → β
s✝ t : Set α
f g : α → β
s : Set α
h : ∀ a ∈ s, f a = g a
x : β
⊢ (∃ x_1 ∈ s, f x_1 = x) → ∃ x_1 ∈ s, g x_1 = x
|
/-
Copyright (c) 2014 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Leonardo de Moura
-/
import Mathlib.Data.Set.Basic
#align_import data.set.image from "leanprover-community/mathlib"@"001ffdc42920050657fd45bd2b8bfbec8eaaeb29"
/-!
# Images and preimages of sets
## Main definitions
* `preimage f t : Set α` : the preimage f⁻¹(t) (written `f ⁻¹' t` in Lean) of a subset of β.
* `range f : Set β` : the image of `univ` under `f`.
Also works for `{p : Prop} (f : p → α)` (unlike `image`)
## Notation
* `f ⁻¹' t` for `Set.preimage f t`
* `f '' s` for `Set.image f s`
## Tags
set, sets, image, preimage, pre-image, range
-/
set_option autoImplicit true
universe u v
open Function Set
namespace Set
variable {α β γ : Type*} {ι ι' : Sort*}
/-! ### Inverse image -/
/-- The preimage of `s : Set β` by `f : α → β`, written `f ⁻¹' s`,
is the set of `x : α` such that `f x ∈ s`. -/
def preimage {α : Type u} {β : Type v} (f : α → β) (s : Set β) : Set α :=
{ x | f x ∈ s }
#align set.preimage Set.preimage
/-- `f ⁻¹' t` denotes the preimage of `t : Set β` under the function `f : α → β`. -/
infixl:80 " ⁻¹' " => preimage
section Preimage
variable {f : α → β} {g : β → γ}
@[simp]
theorem preimage_empty : f ⁻¹' ∅ = ∅ :=
rfl
#align set.preimage_empty Set.preimage_empty
@[simp, mfld_simps]
theorem mem_preimage {s : Set β} {a : α} : a ∈ f ⁻¹' s ↔ f a ∈ s :=
Iff.rfl
#align set.mem_preimage Set.mem_preimage
theorem preimage_congr {f g : α → β} {s : Set β} (h : ∀ x : α, f x = g x) : f ⁻¹' s = g ⁻¹' s := by
congr with x
simp [h]
#align set.preimage_congr Set.preimage_congr
@[gcongr]
theorem preimage_mono {s t : Set β} (h : s ⊆ t) : f ⁻¹' s ⊆ f ⁻¹' t := fun _ hx => h hx
#align set.preimage_mono Set.preimage_mono
@[simp, mfld_simps]
theorem preimage_univ : f ⁻¹' univ = univ :=
rfl
#align set.preimage_univ Set.preimage_univ
theorem subset_preimage_univ {s : Set α} : s ⊆ f ⁻¹' univ :=
subset_univ _
#align set.subset_preimage_univ Set.subset_preimage_univ
@[simp, mfld_simps]
theorem preimage_inter {s t : Set β} : f ⁻¹' (s ∩ t) = f ⁻¹' s ∩ f ⁻¹' t :=
rfl
#align set.preimage_inter Set.preimage_inter
@[simp]
theorem preimage_union {s t : Set β} : f ⁻¹' (s ∪ t) = f ⁻¹' s ∪ f ⁻¹' t :=
rfl
#align set.preimage_union Set.preimage_union
@[simp]
theorem preimage_compl {s : Set β} : f ⁻¹' sᶜ = (f ⁻¹' s)ᶜ :=
rfl
#align set.preimage_compl Set.preimage_compl
@[simp]
theorem preimage_diff (f : α → β) (s t : Set β) : f ⁻¹' (s \ t) = f ⁻¹' s \ f ⁻¹' t :=
rfl
#align set.preimage_diff Set.preimage_diff
@[simp]
lemma preimage_symmDiff {f : α → β} (s t : Set β) : f ⁻¹' (s ∆ t) = (f ⁻¹' s) ∆ (f ⁻¹' t) :=
rfl
#align set.preimage_symm_diff Set.preimage_symmDiff
@[simp]
theorem preimage_ite (f : α → β) (s t₁ t₂ : Set β) :
f ⁻¹' s.ite t₁ t₂ = (f ⁻¹' s).ite (f ⁻¹' t₁) (f ⁻¹' t₂) :=
rfl
#align set.preimage_ite Set.preimage_ite
@[simp]
theorem preimage_setOf_eq {p : α → Prop} {f : β → α} : f ⁻¹' { a | p a } = { a | p (f a) } :=
rfl
#align set.preimage_set_of_eq Set.preimage_setOf_eq
@[simp]
theorem preimage_id_eq : preimage (id : α → α) = id :=
rfl
#align set.preimage_id_eq Set.preimage_id_eq
@[mfld_simps]
theorem preimage_id {s : Set α} : id ⁻¹' s = s :=
rfl
#align set.preimage_id Set.preimage_id
@[simp, mfld_simps]
theorem preimage_id' {s : Set α} : (fun x => x) ⁻¹' s = s :=
rfl
#align set.preimage_id' Set.preimage_id'
@[simp]
theorem preimage_const_of_mem {b : β} {s : Set β} (h : b ∈ s) : (fun _ : α => b) ⁻¹' s = univ :=
eq_univ_of_forall fun _ => h
#align set.preimage_const_of_mem Set.preimage_const_of_mem
@[simp]
theorem preimage_const_of_not_mem {b : β} {s : Set β} (h : b ∉ s) : (fun _ : α => b) ⁻¹' s = ∅ :=
eq_empty_of_subset_empty fun _ hx => h hx
#align set.preimage_const_of_not_mem Set.preimage_const_of_not_mem
theorem preimage_const (b : β) (s : Set β) [Decidable (b ∈ s)] :
(fun _ : α => b) ⁻¹' s = if b ∈ s then univ else ∅ := by
split_ifs with hb
exacts [preimage_const_of_mem hb, preimage_const_of_not_mem hb]
#align set.preimage_const Set.preimage_const
/-- If preimage of each singleton under `f : α → β` is either empty or the whole type,
then `f` is a constant. -/
lemma exists_eq_const_of_preimage_singleton [Nonempty β] {f : α → β}
(hf : ∀ b : β, f ⁻¹' {b} = ∅ ∨ f ⁻¹' {b} = univ) : ∃ b, f = const α b := by
rcases em (∃ b, f ⁻¹' {b} = univ) with ⟨b, hb⟩ | hf'
· exact ⟨b, funext fun x ↦ eq_univ_iff_forall.1 hb x⟩
· have : ∀ x b, f x ≠ b := fun x b ↦
eq_empty_iff_forall_not_mem.1 ((hf b).resolve_right fun h ↦ hf' ⟨b, h⟩) x
exact ⟨Classical.arbitrary β, funext fun x ↦ absurd rfl (this x _)⟩
theorem preimage_comp {s : Set γ} : g ∘ f ⁻¹' s = f ⁻¹' (g ⁻¹' s) :=
rfl
#align set.preimage_comp Set.preimage_comp
theorem preimage_comp_eq : preimage (g ∘ f) = preimage f ∘ preimage g :=
rfl
#align set.preimage_comp_eq Set.preimage_comp_eq
theorem preimage_iterate_eq {f : α → α} {n : ℕ} : Set.preimage f^[n] = (Set.preimage f)^[n] := by
induction' n with n ih; · simp
rw [iterate_succ, iterate_succ', preimage_comp_eq, ih]
#align set.preimage_iterate_eq Set.preimage_iterate_eq
theorem preimage_preimage {g : β → γ} {f : α → β} {s : Set γ} :
f ⁻¹' (g ⁻¹' s) = (fun x => g (f x)) ⁻¹' s :=
preimage_comp.symm
#align set.preimage_preimage Set.preimage_preimage
theorem eq_preimage_subtype_val_iff {p : α → Prop} {s : Set (Subtype p)} {t : Set α} :
s = Subtype.val ⁻¹' t ↔ ∀ (x) (h : p x), (⟨x, h⟩ : Subtype p) ∈ s ↔ x ∈ t :=
⟨fun s_eq x h => by
rw [s_eq]
simp, fun h => ext fun ⟨x, hx⟩ => by simp [h]⟩
#align set.eq_preimage_subtype_val_iff Set.eq_preimage_subtype_val_iff
theorem nonempty_of_nonempty_preimage {s : Set β} {f : α → β} (hf : (f ⁻¹' s).Nonempty) :
s.Nonempty :=
let ⟨x, hx⟩ := hf
⟨f x, hx⟩
#align set.nonempty_of_nonempty_preimage Set.nonempty_of_nonempty_preimage
@[simp] theorem preimage_singleton_true (p : α → Prop) : p ⁻¹' {True} = {a | p a} := by ext; simp
#align set.preimage_singleton_true Set.preimage_singleton_true
@[simp] theorem preimage_singleton_false (p : α → Prop) : p ⁻¹' {False} = {a | ¬p a} := by ext; simp
#align set.preimage_singleton_false Set.preimage_singleton_false
theorem preimage_subtype_coe_eq_compl {s u v : Set α} (hsuv : s ⊆ u ∪ v)
(H : s ∩ (u ∩ v) = ∅) : ((↑) : s → α) ⁻¹' u = ((↑) ⁻¹' v)ᶜ := by
ext ⟨x, x_in_s⟩
constructor
· intro x_in_u x_in_v
exact eq_empty_iff_forall_not_mem.mp H x ⟨x_in_s, ⟨x_in_u, x_in_v⟩⟩
· intro hx
exact Or.elim (hsuv x_in_s) id fun hx' => hx.elim hx'
#align set.preimage_subtype_coe_eq_compl Set.preimage_subtype_coe_eq_compl
end Preimage
/-! ### Image of a set under a function -/
section Image
variable {f : α → β} {s t : Set α}
-- Porting note: `Set.image` is already defined in `Init.Set`
#align set.image Set.image
/-- `f '' s` denotes the image of `s : Set α` under the function `f : α → β`. -/
infixl:80 " '' " => image
theorem mem_image_iff_bex {f : α → β} {s : Set α} {y : β} :
y ∈ f '' s ↔ ∃ (x : _) (_ : x ∈ s), f x = y :=
bex_def.symm
#align set.mem_image_iff_bex Set.mem_image_iff_bex
@[simp]
theorem mem_image (f : α → β) (s : Set α) (y : β) : y ∈ f '' s ↔ ∃ x ∈ s, f x = y :=
Iff.rfl
#align set.mem_image Set.mem_image
theorem image_eta (f : α → β) : f '' s = (fun x => f x) '' s :=
rfl
#align set.image_eta Set.image_eta
@[mfld_simps]
theorem mem_image_of_mem (f : α → β) {x : α} {a : Set α} (h : x ∈ a) : f x ∈ f '' a :=
⟨_, h, rfl⟩
#align set.mem_image_of_mem Set.mem_image_of_mem
theorem _root_.Function.Injective.mem_set_image {f : α → β} (hf : Injective f) {s : Set α} {a : α} :
f a ∈ f '' s ↔ a ∈ s :=
⟨fun ⟨_, hb, Eq⟩ => hf Eq ▸ hb, mem_image_of_mem f⟩
#align function.injective.mem_set_image Function.Injective.mem_set_image
theorem ball_image_iff {f : α → β} {s : Set α} {p : β → Prop} :
(∀ y ∈ f '' s, p y) ↔ ∀ x ∈ s, p (f x) := by simp
#align set.ball_image_iff Set.ball_image_iff
theorem ball_image_of_ball {f : α → β} {s : Set α} {p : β → Prop} (h : ∀ x ∈ s, p (f x)) :
∀ y ∈ f '' s, p y :=
ball_image_iff.2 h
#align set.ball_image_of_ball Set.ball_image_of_ball
theorem bex_image_iff {f : α → β} {s : Set α} {p : β → Prop} :
(∃ y ∈ f '' s, p y) ↔ ∃ x ∈ s, p (f x) := by simp
#align set.bex_image_iff Set.bex_image_iff
theorem mem_image_elim {f : α → β} {s : Set α} {C : β → Prop} (h : ∀ x : α, x ∈ s → C (f x)) :
∀ {y : β}, y ∈ f '' s → C y
| _, ⟨a, a_in, rfl⟩ => h a a_in
#align set.mem_image_elim Set.mem_image_elim
theorem mem_image_elim_on {f : α → β} {s : Set α} {C : β → Prop} {y : β} (h_y : y ∈ f '' s)
(h : ∀ x : α, x ∈ s → C (f x)) : C y :=
mem_image_elim h h_y
#align set.mem_image_elim_on Set.mem_image_elim_on
-- Porting note: used to be `safe`
@[congr]
theorem image_congr {f g : α → β} {s : Set α} (h : ∀ a ∈ s, f a = g a) : f '' s = g '' s := by
ext x
rw [mem_image, mem_image]
exact {
mp := by
|
rintro ⟨a, ha1, ha2⟩
|
@[congr]
theorem image_congr {f g : α → β} {s : Set α} (h : ∀ a ∈ s, f a = g a) : f '' s = g '' s := by
ext x
rw [mem_image, mem_image]
exact {
mp := by
|
Mathlib.Data.Set.Image.273_0.IJFiTzmYGOCpPSd
|
@[congr]
theorem image_congr {f g : α → β} {s : Set α} (h : ∀ a ∈ s, f a = g a) : f '' s = g '' s
|
Mathlib_Data_Set_Image
|
case intro.intro
α : Type u_1
β : Type u_2
γ : Type u_3
ι : Sort u_4
ι' : Sort u_5
f✝ : α → β
s✝ t : Set α
f g : α → β
s : Set α
h : ∀ a ∈ s, f a = g a
x : β
a : α
ha1 : a ∈ s
ha2 : f a = x
⊢ ∃ x_1 ∈ s, g x_1 = x
|
/-
Copyright (c) 2014 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Leonardo de Moura
-/
import Mathlib.Data.Set.Basic
#align_import data.set.image from "leanprover-community/mathlib"@"001ffdc42920050657fd45bd2b8bfbec8eaaeb29"
/-!
# Images and preimages of sets
## Main definitions
* `preimage f t : Set α` : the preimage f⁻¹(t) (written `f ⁻¹' t` in Lean) of a subset of β.
* `range f : Set β` : the image of `univ` under `f`.
Also works for `{p : Prop} (f : p → α)` (unlike `image`)
## Notation
* `f ⁻¹' t` for `Set.preimage f t`
* `f '' s` for `Set.image f s`
## Tags
set, sets, image, preimage, pre-image, range
-/
set_option autoImplicit true
universe u v
open Function Set
namespace Set
variable {α β γ : Type*} {ι ι' : Sort*}
/-! ### Inverse image -/
/-- The preimage of `s : Set β` by `f : α → β`, written `f ⁻¹' s`,
is the set of `x : α` such that `f x ∈ s`. -/
def preimage {α : Type u} {β : Type v} (f : α → β) (s : Set β) : Set α :=
{ x | f x ∈ s }
#align set.preimage Set.preimage
/-- `f ⁻¹' t` denotes the preimage of `t : Set β` under the function `f : α → β`. -/
infixl:80 " ⁻¹' " => preimage
section Preimage
variable {f : α → β} {g : β → γ}
@[simp]
theorem preimage_empty : f ⁻¹' ∅ = ∅ :=
rfl
#align set.preimage_empty Set.preimage_empty
@[simp, mfld_simps]
theorem mem_preimage {s : Set β} {a : α} : a ∈ f ⁻¹' s ↔ f a ∈ s :=
Iff.rfl
#align set.mem_preimage Set.mem_preimage
theorem preimage_congr {f g : α → β} {s : Set β} (h : ∀ x : α, f x = g x) : f ⁻¹' s = g ⁻¹' s := by
congr with x
simp [h]
#align set.preimage_congr Set.preimage_congr
@[gcongr]
theorem preimage_mono {s t : Set β} (h : s ⊆ t) : f ⁻¹' s ⊆ f ⁻¹' t := fun _ hx => h hx
#align set.preimage_mono Set.preimage_mono
@[simp, mfld_simps]
theorem preimage_univ : f ⁻¹' univ = univ :=
rfl
#align set.preimage_univ Set.preimage_univ
theorem subset_preimage_univ {s : Set α} : s ⊆ f ⁻¹' univ :=
subset_univ _
#align set.subset_preimage_univ Set.subset_preimage_univ
@[simp, mfld_simps]
theorem preimage_inter {s t : Set β} : f ⁻¹' (s ∩ t) = f ⁻¹' s ∩ f ⁻¹' t :=
rfl
#align set.preimage_inter Set.preimage_inter
@[simp]
theorem preimage_union {s t : Set β} : f ⁻¹' (s ∪ t) = f ⁻¹' s ∪ f ⁻¹' t :=
rfl
#align set.preimage_union Set.preimage_union
@[simp]
theorem preimage_compl {s : Set β} : f ⁻¹' sᶜ = (f ⁻¹' s)ᶜ :=
rfl
#align set.preimage_compl Set.preimage_compl
@[simp]
theorem preimage_diff (f : α → β) (s t : Set β) : f ⁻¹' (s \ t) = f ⁻¹' s \ f ⁻¹' t :=
rfl
#align set.preimage_diff Set.preimage_diff
@[simp]
lemma preimage_symmDiff {f : α → β} (s t : Set β) : f ⁻¹' (s ∆ t) = (f ⁻¹' s) ∆ (f ⁻¹' t) :=
rfl
#align set.preimage_symm_diff Set.preimage_symmDiff
@[simp]
theorem preimage_ite (f : α → β) (s t₁ t₂ : Set β) :
f ⁻¹' s.ite t₁ t₂ = (f ⁻¹' s).ite (f ⁻¹' t₁) (f ⁻¹' t₂) :=
rfl
#align set.preimage_ite Set.preimage_ite
@[simp]
theorem preimage_setOf_eq {p : α → Prop} {f : β → α} : f ⁻¹' { a | p a } = { a | p (f a) } :=
rfl
#align set.preimage_set_of_eq Set.preimage_setOf_eq
@[simp]
theorem preimage_id_eq : preimage (id : α → α) = id :=
rfl
#align set.preimage_id_eq Set.preimage_id_eq
@[mfld_simps]
theorem preimage_id {s : Set α} : id ⁻¹' s = s :=
rfl
#align set.preimage_id Set.preimage_id
@[simp, mfld_simps]
theorem preimage_id' {s : Set α} : (fun x => x) ⁻¹' s = s :=
rfl
#align set.preimage_id' Set.preimage_id'
@[simp]
theorem preimage_const_of_mem {b : β} {s : Set β} (h : b ∈ s) : (fun _ : α => b) ⁻¹' s = univ :=
eq_univ_of_forall fun _ => h
#align set.preimage_const_of_mem Set.preimage_const_of_mem
@[simp]
theorem preimage_const_of_not_mem {b : β} {s : Set β} (h : b ∉ s) : (fun _ : α => b) ⁻¹' s = ∅ :=
eq_empty_of_subset_empty fun _ hx => h hx
#align set.preimage_const_of_not_mem Set.preimage_const_of_not_mem
theorem preimage_const (b : β) (s : Set β) [Decidable (b ∈ s)] :
(fun _ : α => b) ⁻¹' s = if b ∈ s then univ else ∅ := by
split_ifs with hb
exacts [preimage_const_of_mem hb, preimage_const_of_not_mem hb]
#align set.preimage_const Set.preimage_const
/-- If preimage of each singleton under `f : α → β` is either empty or the whole type,
then `f` is a constant. -/
lemma exists_eq_const_of_preimage_singleton [Nonempty β] {f : α → β}
(hf : ∀ b : β, f ⁻¹' {b} = ∅ ∨ f ⁻¹' {b} = univ) : ∃ b, f = const α b := by
rcases em (∃ b, f ⁻¹' {b} = univ) with ⟨b, hb⟩ | hf'
· exact ⟨b, funext fun x ↦ eq_univ_iff_forall.1 hb x⟩
· have : ∀ x b, f x ≠ b := fun x b ↦
eq_empty_iff_forall_not_mem.1 ((hf b).resolve_right fun h ↦ hf' ⟨b, h⟩) x
exact ⟨Classical.arbitrary β, funext fun x ↦ absurd rfl (this x _)⟩
theorem preimage_comp {s : Set γ} : g ∘ f ⁻¹' s = f ⁻¹' (g ⁻¹' s) :=
rfl
#align set.preimage_comp Set.preimage_comp
theorem preimage_comp_eq : preimage (g ∘ f) = preimage f ∘ preimage g :=
rfl
#align set.preimage_comp_eq Set.preimage_comp_eq
theorem preimage_iterate_eq {f : α → α} {n : ℕ} : Set.preimage f^[n] = (Set.preimage f)^[n] := by
induction' n with n ih; · simp
rw [iterate_succ, iterate_succ', preimage_comp_eq, ih]
#align set.preimage_iterate_eq Set.preimage_iterate_eq
theorem preimage_preimage {g : β → γ} {f : α → β} {s : Set γ} :
f ⁻¹' (g ⁻¹' s) = (fun x => g (f x)) ⁻¹' s :=
preimage_comp.symm
#align set.preimage_preimage Set.preimage_preimage
theorem eq_preimage_subtype_val_iff {p : α → Prop} {s : Set (Subtype p)} {t : Set α} :
s = Subtype.val ⁻¹' t ↔ ∀ (x) (h : p x), (⟨x, h⟩ : Subtype p) ∈ s ↔ x ∈ t :=
⟨fun s_eq x h => by
rw [s_eq]
simp, fun h => ext fun ⟨x, hx⟩ => by simp [h]⟩
#align set.eq_preimage_subtype_val_iff Set.eq_preimage_subtype_val_iff
theorem nonempty_of_nonempty_preimage {s : Set β} {f : α → β} (hf : (f ⁻¹' s).Nonempty) :
s.Nonempty :=
let ⟨x, hx⟩ := hf
⟨f x, hx⟩
#align set.nonempty_of_nonempty_preimage Set.nonempty_of_nonempty_preimage
@[simp] theorem preimage_singleton_true (p : α → Prop) : p ⁻¹' {True} = {a | p a} := by ext; simp
#align set.preimage_singleton_true Set.preimage_singleton_true
@[simp] theorem preimage_singleton_false (p : α → Prop) : p ⁻¹' {False} = {a | ¬p a} := by ext; simp
#align set.preimage_singleton_false Set.preimage_singleton_false
theorem preimage_subtype_coe_eq_compl {s u v : Set α} (hsuv : s ⊆ u ∪ v)
(H : s ∩ (u ∩ v) = ∅) : ((↑) : s → α) ⁻¹' u = ((↑) ⁻¹' v)ᶜ := by
ext ⟨x, x_in_s⟩
constructor
· intro x_in_u x_in_v
exact eq_empty_iff_forall_not_mem.mp H x ⟨x_in_s, ⟨x_in_u, x_in_v⟩⟩
· intro hx
exact Or.elim (hsuv x_in_s) id fun hx' => hx.elim hx'
#align set.preimage_subtype_coe_eq_compl Set.preimage_subtype_coe_eq_compl
end Preimage
/-! ### Image of a set under a function -/
section Image
variable {f : α → β} {s t : Set α}
-- Porting note: `Set.image` is already defined in `Init.Set`
#align set.image Set.image
/-- `f '' s` denotes the image of `s : Set α` under the function `f : α → β`. -/
infixl:80 " '' " => image
theorem mem_image_iff_bex {f : α → β} {s : Set α} {y : β} :
y ∈ f '' s ↔ ∃ (x : _) (_ : x ∈ s), f x = y :=
bex_def.symm
#align set.mem_image_iff_bex Set.mem_image_iff_bex
@[simp]
theorem mem_image (f : α → β) (s : Set α) (y : β) : y ∈ f '' s ↔ ∃ x ∈ s, f x = y :=
Iff.rfl
#align set.mem_image Set.mem_image
theorem image_eta (f : α → β) : f '' s = (fun x => f x) '' s :=
rfl
#align set.image_eta Set.image_eta
@[mfld_simps]
theorem mem_image_of_mem (f : α → β) {x : α} {a : Set α} (h : x ∈ a) : f x ∈ f '' a :=
⟨_, h, rfl⟩
#align set.mem_image_of_mem Set.mem_image_of_mem
theorem _root_.Function.Injective.mem_set_image {f : α → β} (hf : Injective f) {s : Set α} {a : α} :
f a ∈ f '' s ↔ a ∈ s :=
⟨fun ⟨_, hb, Eq⟩ => hf Eq ▸ hb, mem_image_of_mem f⟩
#align function.injective.mem_set_image Function.Injective.mem_set_image
theorem ball_image_iff {f : α → β} {s : Set α} {p : β → Prop} :
(∀ y ∈ f '' s, p y) ↔ ∀ x ∈ s, p (f x) := by simp
#align set.ball_image_iff Set.ball_image_iff
theorem ball_image_of_ball {f : α → β} {s : Set α} {p : β → Prop} (h : ∀ x ∈ s, p (f x)) :
∀ y ∈ f '' s, p y :=
ball_image_iff.2 h
#align set.ball_image_of_ball Set.ball_image_of_ball
theorem bex_image_iff {f : α → β} {s : Set α} {p : β → Prop} :
(∃ y ∈ f '' s, p y) ↔ ∃ x ∈ s, p (f x) := by simp
#align set.bex_image_iff Set.bex_image_iff
theorem mem_image_elim {f : α → β} {s : Set α} {C : β → Prop} (h : ∀ x : α, x ∈ s → C (f x)) :
∀ {y : β}, y ∈ f '' s → C y
| _, ⟨a, a_in, rfl⟩ => h a a_in
#align set.mem_image_elim Set.mem_image_elim
theorem mem_image_elim_on {f : α → β} {s : Set α} {C : β → Prop} {y : β} (h_y : y ∈ f '' s)
(h : ∀ x : α, x ∈ s → C (f x)) : C y :=
mem_image_elim h h_y
#align set.mem_image_elim_on Set.mem_image_elim_on
-- Porting note: used to be `safe`
@[congr]
theorem image_congr {f g : α → β} {s : Set α} (h : ∀ a ∈ s, f a = g a) : f '' s = g '' s := by
ext x
rw [mem_image, mem_image]
exact {
mp := by
rintro ⟨a, ha1, ha2⟩
|
exact ⟨a, ⟨ha1, (h a ha1) ▸ ha2⟩⟩
|
@[congr]
theorem image_congr {f g : α → β} {s : Set α} (h : ∀ a ∈ s, f a = g a) : f '' s = g '' s := by
ext x
rw [mem_image, mem_image]
exact {
mp := by
rintro ⟨a, ha1, ha2⟩
|
Mathlib.Data.Set.Image.273_0.IJFiTzmYGOCpPSd
|
@[congr]
theorem image_congr {f g : α → β} {s : Set α} (h : ∀ a ∈ s, f a = g a) : f '' s = g '' s
|
Mathlib_Data_Set_Image
|
α : Type u_1
β : Type u_2
γ : Type u_3
ι : Sort u_4
ι' : Sort u_5
f✝ : α → β
s✝ t : Set α
f g : α → β
s : Set α
h : ∀ a ∈ s, f a = g a
x : β
⊢ (∃ x_1 ∈ s, g x_1 = x) → ∃ x_1 ∈ s, f x_1 = x
|
/-
Copyright (c) 2014 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Leonardo de Moura
-/
import Mathlib.Data.Set.Basic
#align_import data.set.image from "leanprover-community/mathlib"@"001ffdc42920050657fd45bd2b8bfbec8eaaeb29"
/-!
# Images and preimages of sets
## Main definitions
* `preimage f t : Set α` : the preimage f⁻¹(t) (written `f ⁻¹' t` in Lean) of a subset of β.
* `range f : Set β` : the image of `univ` under `f`.
Also works for `{p : Prop} (f : p → α)` (unlike `image`)
## Notation
* `f ⁻¹' t` for `Set.preimage f t`
* `f '' s` for `Set.image f s`
## Tags
set, sets, image, preimage, pre-image, range
-/
set_option autoImplicit true
universe u v
open Function Set
namespace Set
variable {α β γ : Type*} {ι ι' : Sort*}
/-! ### Inverse image -/
/-- The preimage of `s : Set β` by `f : α → β`, written `f ⁻¹' s`,
is the set of `x : α` such that `f x ∈ s`. -/
def preimage {α : Type u} {β : Type v} (f : α → β) (s : Set β) : Set α :=
{ x | f x ∈ s }
#align set.preimage Set.preimage
/-- `f ⁻¹' t` denotes the preimage of `t : Set β` under the function `f : α → β`. -/
infixl:80 " ⁻¹' " => preimage
section Preimage
variable {f : α → β} {g : β → γ}
@[simp]
theorem preimage_empty : f ⁻¹' ∅ = ∅ :=
rfl
#align set.preimage_empty Set.preimage_empty
@[simp, mfld_simps]
theorem mem_preimage {s : Set β} {a : α} : a ∈ f ⁻¹' s ↔ f a ∈ s :=
Iff.rfl
#align set.mem_preimage Set.mem_preimage
theorem preimage_congr {f g : α → β} {s : Set β} (h : ∀ x : α, f x = g x) : f ⁻¹' s = g ⁻¹' s := by
congr with x
simp [h]
#align set.preimage_congr Set.preimage_congr
@[gcongr]
theorem preimage_mono {s t : Set β} (h : s ⊆ t) : f ⁻¹' s ⊆ f ⁻¹' t := fun _ hx => h hx
#align set.preimage_mono Set.preimage_mono
@[simp, mfld_simps]
theorem preimage_univ : f ⁻¹' univ = univ :=
rfl
#align set.preimage_univ Set.preimage_univ
theorem subset_preimage_univ {s : Set α} : s ⊆ f ⁻¹' univ :=
subset_univ _
#align set.subset_preimage_univ Set.subset_preimage_univ
@[simp, mfld_simps]
theorem preimage_inter {s t : Set β} : f ⁻¹' (s ∩ t) = f ⁻¹' s ∩ f ⁻¹' t :=
rfl
#align set.preimage_inter Set.preimage_inter
@[simp]
theorem preimage_union {s t : Set β} : f ⁻¹' (s ∪ t) = f ⁻¹' s ∪ f ⁻¹' t :=
rfl
#align set.preimage_union Set.preimage_union
@[simp]
theorem preimage_compl {s : Set β} : f ⁻¹' sᶜ = (f ⁻¹' s)ᶜ :=
rfl
#align set.preimage_compl Set.preimage_compl
@[simp]
theorem preimage_diff (f : α → β) (s t : Set β) : f ⁻¹' (s \ t) = f ⁻¹' s \ f ⁻¹' t :=
rfl
#align set.preimage_diff Set.preimage_diff
@[simp]
lemma preimage_symmDiff {f : α → β} (s t : Set β) : f ⁻¹' (s ∆ t) = (f ⁻¹' s) ∆ (f ⁻¹' t) :=
rfl
#align set.preimage_symm_diff Set.preimage_symmDiff
@[simp]
theorem preimage_ite (f : α → β) (s t₁ t₂ : Set β) :
f ⁻¹' s.ite t₁ t₂ = (f ⁻¹' s).ite (f ⁻¹' t₁) (f ⁻¹' t₂) :=
rfl
#align set.preimage_ite Set.preimage_ite
@[simp]
theorem preimage_setOf_eq {p : α → Prop} {f : β → α} : f ⁻¹' { a | p a } = { a | p (f a) } :=
rfl
#align set.preimage_set_of_eq Set.preimage_setOf_eq
@[simp]
theorem preimage_id_eq : preimage (id : α → α) = id :=
rfl
#align set.preimage_id_eq Set.preimage_id_eq
@[mfld_simps]
theorem preimage_id {s : Set α} : id ⁻¹' s = s :=
rfl
#align set.preimage_id Set.preimage_id
@[simp, mfld_simps]
theorem preimage_id' {s : Set α} : (fun x => x) ⁻¹' s = s :=
rfl
#align set.preimage_id' Set.preimage_id'
@[simp]
theorem preimage_const_of_mem {b : β} {s : Set β} (h : b ∈ s) : (fun _ : α => b) ⁻¹' s = univ :=
eq_univ_of_forall fun _ => h
#align set.preimage_const_of_mem Set.preimage_const_of_mem
@[simp]
theorem preimage_const_of_not_mem {b : β} {s : Set β} (h : b ∉ s) : (fun _ : α => b) ⁻¹' s = ∅ :=
eq_empty_of_subset_empty fun _ hx => h hx
#align set.preimage_const_of_not_mem Set.preimage_const_of_not_mem
theorem preimage_const (b : β) (s : Set β) [Decidable (b ∈ s)] :
(fun _ : α => b) ⁻¹' s = if b ∈ s then univ else ∅ := by
split_ifs with hb
exacts [preimage_const_of_mem hb, preimage_const_of_not_mem hb]
#align set.preimage_const Set.preimage_const
/-- If preimage of each singleton under `f : α → β` is either empty or the whole type,
then `f` is a constant. -/
lemma exists_eq_const_of_preimage_singleton [Nonempty β] {f : α → β}
(hf : ∀ b : β, f ⁻¹' {b} = ∅ ∨ f ⁻¹' {b} = univ) : ∃ b, f = const α b := by
rcases em (∃ b, f ⁻¹' {b} = univ) with ⟨b, hb⟩ | hf'
· exact ⟨b, funext fun x ↦ eq_univ_iff_forall.1 hb x⟩
· have : ∀ x b, f x ≠ b := fun x b ↦
eq_empty_iff_forall_not_mem.1 ((hf b).resolve_right fun h ↦ hf' ⟨b, h⟩) x
exact ⟨Classical.arbitrary β, funext fun x ↦ absurd rfl (this x _)⟩
theorem preimage_comp {s : Set γ} : g ∘ f ⁻¹' s = f ⁻¹' (g ⁻¹' s) :=
rfl
#align set.preimage_comp Set.preimage_comp
theorem preimage_comp_eq : preimage (g ∘ f) = preimage f ∘ preimage g :=
rfl
#align set.preimage_comp_eq Set.preimage_comp_eq
theorem preimage_iterate_eq {f : α → α} {n : ℕ} : Set.preimage f^[n] = (Set.preimage f)^[n] := by
induction' n with n ih; · simp
rw [iterate_succ, iterate_succ', preimage_comp_eq, ih]
#align set.preimage_iterate_eq Set.preimage_iterate_eq
theorem preimage_preimage {g : β → γ} {f : α → β} {s : Set γ} :
f ⁻¹' (g ⁻¹' s) = (fun x => g (f x)) ⁻¹' s :=
preimage_comp.symm
#align set.preimage_preimage Set.preimage_preimage
theorem eq_preimage_subtype_val_iff {p : α → Prop} {s : Set (Subtype p)} {t : Set α} :
s = Subtype.val ⁻¹' t ↔ ∀ (x) (h : p x), (⟨x, h⟩ : Subtype p) ∈ s ↔ x ∈ t :=
⟨fun s_eq x h => by
rw [s_eq]
simp, fun h => ext fun ⟨x, hx⟩ => by simp [h]⟩
#align set.eq_preimage_subtype_val_iff Set.eq_preimage_subtype_val_iff
theorem nonempty_of_nonempty_preimage {s : Set β} {f : α → β} (hf : (f ⁻¹' s).Nonempty) :
s.Nonempty :=
let ⟨x, hx⟩ := hf
⟨f x, hx⟩
#align set.nonempty_of_nonempty_preimage Set.nonempty_of_nonempty_preimage
@[simp] theorem preimage_singleton_true (p : α → Prop) : p ⁻¹' {True} = {a | p a} := by ext; simp
#align set.preimage_singleton_true Set.preimage_singleton_true
@[simp] theorem preimage_singleton_false (p : α → Prop) : p ⁻¹' {False} = {a | ¬p a} := by ext; simp
#align set.preimage_singleton_false Set.preimage_singleton_false
theorem preimage_subtype_coe_eq_compl {s u v : Set α} (hsuv : s ⊆ u ∪ v)
(H : s ∩ (u ∩ v) = ∅) : ((↑) : s → α) ⁻¹' u = ((↑) ⁻¹' v)ᶜ := by
ext ⟨x, x_in_s⟩
constructor
· intro x_in_u x_in_v
exact eq_empty_iff_forall_not_mem.mp H x ⟨x_in_s, ⟨x_in_u, x_in_v⟩⟩
· intro hx
exact Or.elim (hsuv x_in_s) id fun hx' => hx.elim hx'
#align set.preimage_subtype_coe_eq_compl Set.preimage_subtype_coe_eq_compl
end Preimage
/-! ### Image of a set under a function -/
section Image
variable {f : α → β} {s t : Set α}
-- Porting note: `Set.image` is already defined in `Init.Set`
#align set.image Set.image
/-- `f '' s` denotes the image of `s : Set α` under the function `f : α → β`. -/
infixl:80 " '' " => image
theorem mem_image_iff_bex {f : α → β} {s : Set α} {y : β} :
y ∈ f '' s ↔ ∃ (x : _) (_ : x ∈ s), f x = y :=
bex_def.symm
#align set.mem_image_iff_bex Set.mem_image_iff_bex
@[simp]
theorem mem_image (f : α → β) (s : Set α) (y : β) : y ∈ f '' s ↔ ∃ x ∈ s, f x = y :=
Iff.rfl
#align set.mem_image Set.mem_image
theorem image_eta (f : α → β) : f '' s = (fun x => f x) '' s :=
rfl
#align set.image_eta Set.image_eta
@[mfld_simps]
theorem mem_image_of_mem (f : α → β) {x : α} {a : Set α} (h : x ∈ a) : f x ∈ f '' a :=
⟨_, h, rfl⟩
#align set.mem_image_of_mem Set.mem_image_of_mem
theorem _root_.Function.Injective.mem_set_image {f : α → β} (hf : Injective f) {s : Set α} {a : α} :
f a ∈ f '' s ↔ a ∈ s :=
⟨fun ⟨_, hb, Eq⟩ => hf Eq ▸ hb, mem_image_of_mem f⟩
#align function.injective.mem_set_image Function.Injective.mem_set_image
theorem ball_image_iff {f : α → β} {s : Set α} {p : β → Prop} :
(∀ y ∈ f '' s, p y) ↔ ∀ x ∈ s, p (f x) := by simp
#align set.ball_image_iff Set.ball_image_iff
theorem ball_image_of_ball {f : α → β} {s : Set α} {p : β → Prop} (h : ∀ x ∈ s, p (f x)) :
∀ y ∈ f '' s, p y :=
ball_image_iff.2 h
#align set.ball_image_of_ball Set.ball_image_of_ball
theorem bex_image_iff {f : α → β} {s : Set α} {p : β → Prop} :
(∃ y ∈ f '' s, p y) ↔ ∃ x ∈ s, p (f x) := by simp
#align set.bex_image_iff Set.bex_image_iff
theorem mem_image_elim {f : α → β} {s : Set α} {C : β → Prop} (h : ∀ x : α, x ∈ s → C (f x)) :
∀ {y : β}, y ∈ f '' s → C y
| _, ⟨a, a_in, rfl⟩ => h a a_in
#align set.mem_image_elim Set.mem_image_elim
theorem mem_image_elim_on {f : α → β} {s : Set α} {C : β → Prop} {y : β} (h_y : y ∈ f '' s)
(h : ∀ x : α, x ∈ s → C (f x)) : C y :=
mem_image_elim h h_y
#align set.mem_image_elim_on Set.mem_image_elim_on
-- Porting note: used to be `safe`
@[congr]
theorem image_congr {f g : α → β} {s : Set α} (h : ∀ a ∈ s, f a = g a) : f '' s = g '' s := by
ext x
rw [mem_image, mem_image]
exact {
mp := by
rintro ⟨a, ha1, ha2⟩
exact ⟨a, ⟨ha1, (h a ha1) ▸ ha2⟩⟩,
mpr := by
|
rintro ⟨a, ha1, ha2⟩
|
@[congr]
theorem image_congr {f g : α → β} {s : Set α} (h : ∀ a ∈ s, f a = g a) : f '' s = g '' s := by
ext x
rw [mem_image, mem_image]
exact {
mp := by
rintro ⟨a, ha1, ha2⟩
exact ⟨a, ⟨ha1, (h a ha1) ▸ ha2⟩⟩,
mpr := by
|
Mathlib.Data.Set.Image.273_0.IJFiTzmYGOCpPSd
|
@[congr]
theorem image_congr {f g : α → β} {s : Set α} (h : ∀ a ∈ s, f a = g a) : f '' s = g '' s
|
Mathlib_Data_Set_Image
|
case intro.intro
α : Type u_1
β : Type u_2
γ : Type u_3
ι : Sort u_4
ι' : Sort u_5
f✝ : α → β
s✝ t : Set α
f g : α → β
s : Set α
h : ∀ a ∈ s, f a = g a
x : β
a : α
ha1 : a ∈ s
ha2 : g a = x
⊢ ∃ x_1 ∈ s, f x_1 = x
|
/-
Copyright (c) 2014 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Leonardo de Moura
-/
import Mathlib.Data.Set.Basic
#align_import data.set.image from "leanprover-community/mathlib"@"001ffdc42920050657fd45bd2b8bfbec8eaaeb29"
/-!
# Images and preimages of sets
## Main definitions
* `preimage f t : Set α` : the preimage f⁻¹(t) (written `f ⁻¹' t` in Lean) of a subset of β.
* `range f : Set β` : the image of `univ` under `f`.
Also works for `{p : Prop} (f : p → α)` (unlike `image`)
## Notation
* `f ⁻¹' t` for `Set.preimage f t`
* `f '' s` for `Set.image f s`
## Tags
set, sets, image, preimage, pre-image, range
-/
set_option autoImplicit true
universe u v
open Function Set
namespace Set
variable {α β γ : Type*} {ι ι' : Sort*}
/-! ### Inverse image -/
/-- The preimage of `s : Set β` by `f : α → β`, written `f ⁻¹' s`,
is the set of `x : α` such that `f x ∈ s`. -/
def preimage {α : Type u} {β : Type v} (f : α → β) (s : Set β) : Set α :=
{ x | f x ∈ s }
#align set.preimage Set.preimage
/-- `f ⁻¹' t` denotes the preimage of `t : Set β` under the function `f : α → β`. -/
infixl:80 " ⁻¹' " => preimage
section Preimage
variable {f : α → β} {g : β → γ}
@[simp]
theorem preimage_empty : f ⁻¹' ∅ = ∅ :=
rfl
#align set.preimage_empty Set.preimage_empty
@[simp, mfld_simps]
theorem mem_preimage {s : Set β} {a : α} : a ∈ f ⁻¹' s ↔ f a ∈ s :=
Iff.rfl
#align set.mem_preimage Set.mem_preimage
theorem preimage_congr {f g : α → β} {s : Set β} (h : ∀ x : α, f x = g x) : f ⁻¹' s = g ⁻¹' s := by
congr with x
simp [h]
#align set.preimage_congr Set.preimage_congr
@[gcongr]
theorem preimage_mono {s t : Set β} (h : s ⊆ t) : f ⁻¹' s ⊆ f ⁻¹' t := fun _ hx => h hx
#align set.preimage_mono Set.preimage_mono
@[simp, mfld_simps]
theorem preimage_univ : f ⁻¹' univ = univ :=
rfl
#align set.preimage_univ Set.preimage_univ
theorem subset_preimage_univ {s : Set α} : s ⊆ f ⁻¹' univ :=
subset_univ _
#align set.subset_preimage_univ Set.subset_preimage_univ
@[simp, mfld_simps]
theorem preimage_inter {s t : Set β} : f ⁻¹' (s ∩ t) = f ⁻¹' s ∩ f ⁻¹' t :=
rfl
#align set.preimage_inter Set.preimage_inter
@[simp]
theorem preimage_union {s t : Set β} : f ⁻¹' (s ∪ t) = f ⁻¹' s ∪ f ⁻¹' t :=
rfl
#align set.preimage_union Set.preimage_union
@[simp]
theorem preimage_compl {s : Set β} : f ⁻¹' sᶜ = (f ⁻¹' s)ᶜ :=
rfl
#align set.preimage_compl Set.preimage_compl
@[simp]
theorem preimage_diff (f : α → β) (s t : Set β) : f ⁻¹' (s \ t) = f ⁻¹' s \ f ⁻¹' t :=
rfl
#align set.preimage_diff Set.preimage_diff
@[simp]
lemma preimage_symmDiff {f : α → β} (s t : Set β) : f ⁻¹' (s ∆ t) = (f ⁻¹' s) ∆ (f ⁻¹' t) :=
rfl
#align set.preimage_symm_diff Set.preimage_symmDiff
@[simp]
theorem preimage_ite (f : α → β) (s t₁ t₂ : Set β) :
f ⁻¹' s.ite t₁ t₂ = (f ⁻¹' s).ite (f ⁻¹' t₁) (f ⁻¹' t₂) :=
rfl
#align set.preimage_ite Set.preimage_ite
@[simp]
theorem preimage_setOf_eq {p : α → Prop} {f : β → α} : f ⁻¹' { a | p a } = { a | p (f a) } :=
rfl
#align set.preimage_set_of_eq Set.preimage_setOf_eq
@[simp]
theorem preimage_id_eq : preimage (id : α → α) = id :=
rfl
#align set.preimage_id_eq Set.preimage_id_eq
@[mfld_simps]
theorem preimage_id {s : Set α} : id ⁻¹' s = s :=
rfl
#align set.preimage_id Set.preimage_id
@[simp, mfld_simps]
theorem preimage_id' {s : Set α} : (fun x => x) ⁻¹' s = s :=
rfl
#align set.preimage_id' Set.preimage_id'
@[simp]
theorem preimage_const_of_mem {b : β} {s : Set β} (h : b ∈ s) : (fun _ : α => b) ⁻¹' s = univ :=
eq_univ_of_forall fun _ => h
#align set.preimage_const_of_mem Set.preimage_const_of_mem
@[simp]
theorem preimage_const_of_not_mem {b : β} {s : Set β} (h : b ∉ s) : (fun _ : α => b) ⁻¹' s = ∅ :=
eq_empty_of_subset_empty fun _ hx => h hx
#align set.preimage_const_of_not_mem Set.preimage_const_of_not_mem
theorem preimage_const (b : β) (s : Set β) [Decidable (b ∈ s)] :
(fun _ : α => b) ⁻¹' s = if b ∈ s then univ else ∅ := by
split_ifs with hb
exacts [preimage_const_of_mem hb, preimage_const_of_not_mem hb]
#align set.preimage_const Set.preimage_const
/-- If preimage of each singleton under `f : α → β` is either empty or the whole type,
then `f` is a constant. -/
lemma exists_eq_const_of_preimage_singleton [Nonempty β] {f : α → β}
(hf : ∀ b : β, f ⁻¹' {b} = ∅ ∨ f ⁻¹' {b} = univ) : ∃ b, f = const α b := by
rcases em (∃ b, f ⁻¹' {b} = univ) with ⟨b, hb⟩ | hf'
· exact ⟨b, funext fun x ↦ eq_univ_iff_forall.1 hb x⟩
· have : ∀ x b, f x ≠ b := fun x b ↦
eq_empty_iff_forall_not_mem.1 ((hf b).resolve_right fun h ↦ hf' ⟨b, h⟩) x
exact ⟨Classical.arbitrary β, funext fun x ↦ absurd rfl (this x _)⟩
theorem preimage_comp {s : Set γ} : g ∘ f ⁻¹' s = f ⁻¹' (g ⁻¹' s) :=
rfl
#align set.preimage_comp Set.preimage_comp
theorem preimage_comp_eq : preimage (g ∘ f) = preimage f ∘ preimage g :=
rfl
#align set.preimage_comp_eq Set.preimage_comp_eq
theorem preimage_iterate_eq {f : α → α} {n : ℕ} : Set.preimage f^[n] = (Set.preimage f)^[n] := by
induction' n with n ih; · simp
rw [iterate_succ, iterate_succ', preimage_comp_eq, ih]
#align set.preimage_iterate_eq Set.preimage_iterate_eq
theorem preimage_preimage {g : β → γ} {f : α → β} {s : Set γ} :
f ⁻¹' (g ⁻¹' s) = (fun x => g (f x)) ⁻¹' s :=
preimage_comp.symm
#align set.preimage_preimage Set.preimage_preimage
theorem eq_preimage_subtype_val_iff {p : α → Prop} {s : Set (Subtype p)} {t : Set α} :
s = Subtype.val ⁻¹' t ↔ ∀ (x) (h : p x), (⟨x, h⟩ : Subtype p) ∈ s ↔ x ∈ t :=
⟨fun s_eq x h => by
rw [s_eq]
simp, fun h => ext fun ⟨x, hx⟩ => by simp [h]⟩
#align set.eq_preimage_subtype_val_iff Set.eq_preimage_subtype_val_iff
theorem nonempty_of_nonempty_preimage {s : Set β} {f : α → β} (hf : (f ⁻¹' s).Nonempty) :
s.Nonempty :=
let ⟨x, hx⟩ := hf
⟨f x, hx⟩
#align set.nonempty_of_nonempty_preimage Set.nonempty_of_nonempty_preimage
@[simp] theorem preimage_singleton_true (p : α → Prop) : p ⁻¹' {True} = {a | p a} := by ext; simp
#align set.preimage_singleton_true Set.preimage_singleton_true
@[simp] theorem preimage_singleton_false (p : α → Prop) : p ⁻¹' {False} = {a | ¬p a} := by ext; simp
#align set.preimage_singleton_false Set.preimage_singleton_false
theorem preimage_subtype_coe_eq_compl {s u v : Set α} (hsuv : s ⊆ u ∪ v)
(H : s ∩ (u ∩ v) = ∅) : ((↑) : s → α) ⁻¹' u = ((↑) ⁻¹' v)ᶜ := by
ext ⟨x, x_in_s⟩
constructor
· intro x_in_u x_in_v
exact eq_empty_iff_forall_not_mem.mp H x ⟨x_in_s, ⟨x_in_u, x_in_v⟩⟩
· intro hx
exact Or.elim (hsuv x_in_s) id fun hx' => hx.elim hx'
#align set.preimage_subtype_coe_eq_compl Set.preimage_subtype_coe_eq_compl
end Preimage
/-! ### Image of a set under a function -/
section Image
variable {f : α → β} {s t : Set α}
-- Porting note: `Set.image` is already defined in `Init.Set`
#align set.image Set.image
/-- `f '' s` denotes the image of `s : Set α` under the function `f : α → β`. -/
infixl:80 " '' " => image
theorem mem_image_iff_bex {f : α → β} {s : Set α} {y : β} :
y ∈ f '' s ↔ ∃ (x : _) (_ : x ∈ s), f x = y :=
bex_def.symm
#align set.mem_image_iff_bex Set.mem_image_iff_bex
@[simp]
theorem mem_image (f : α → β) (s : Set α) (y : β) : y ∈ f '' s ↔ ∃ x ∈ s, f x = y :=
Iff.rfl
#align set.mem_image Set.mem_image
theorem image_eta (f : α → β) : f '' s = (fun x => f x) '' s :=
rfl
#align set.image_eta Set.image_eta
@[mfld_simps]
theorem mem_image_of_mem (f : α → β) {x : α} {a : Set α} (h : x ∈ a) : f x ∈ f '' a :=
⟨_, h, rfl⟩
#align set.mem_image_of_mem Set.mem_image_of_mem
theorem _root_.Function.Injective.mem_set_image {f : α → β} (hf : Injective f) {s : Set α} {a : α} :
f a ∈ f '' s ↔ a ∈ s :=
⟨fun ⟨_, hb, Eq⟩ => hf Eq ▸ hb, mem_image_of_mem f⟩
#align function.injective.mem_set_image Function.Injective.mem_set_image
theorem ball_image_iff {f : α → β} {s : Set α} {p : β → Prop} :
(∀ y ∈ f '' s, p y) ↔ ∀ x ∈ s, p (f x) := by simp
#align set.ball_image_iff Set.ball_image_iff
theorem ball_image_of_ball {f : α → β} {s : Set α} {p : β → Prop} (h : ∀ x ∈ s, p (f x)) :
∀ y ∈ f '' s, p y :=
ball_image_iff.2 h
#align set.ball_image_of_ball Set.ball_image_of_ball
theorem bex_image_iff {f : α → β} {s : Set α} {p : β → Prop} :
(∃ y ∈ f '' s, p y) ↔ ∃ x ∈ s, p (f x) := by simp
#align set.bex_image_iff Set.bex_image_iff
theorem mem_image_elim {f : α → β} {s : Set α} {C : β → Prop} (h : ∀ x : α, x ∈ s → C (f x)) :
∀ {y : β}, y ∈ f '' s → C y
| _, ⟨a, a_in, rfl⟩ => h a a_in
#align set.mem_image_elim Set.mem_image_elim
theorem mem_image_elim_on {f : α → β} {s : Set α} {C : β → Prop} {y : β} (h_y : y ∈ f '' s)
(h : ∀ x : α, x ∈ s → C (f x)) : C y :=
mem_image_elim h h_y
#align set.mem_image_elim_on Set.mem_image_elim_on
-- Porting note: used to be `safe`
@[congr]
theorem image_congr {f g : α → β} {s : Set α} (h : ∀ a ∈ s, f a = g a) : f '' s = g '' s := by
ext x
rw [mem_image, mem_image]
exact {
mp := by
rintro ⟨a, ha1, ha2⟩
exact ⟨a, ⟨ha1, (h a ha1) ▸ ha2⟩⟩,
mpr := by
rintro ⟨a, ha1, ha2⟩
|
exact ⟨a, ⟨ha1, (h a ha1) ▸ ha2⟩⟩
|
@[congr]
theorem image_congr {f g : α → β} {s : Set α} (h : ∀ a ∈ s, f a = g a) : f '' s = g '' s := by
ext x
rw [mem_image, mem_image]
exact {
mp := by
rintro ⟨a, ha1, ha2⟩
exact ⟨a, ⟨ha1, (h a ha1) ▸ ha2⟩⟩,
mpr := by
rintro ⟨a, ha1, ha2⟩
|
Mathlib.Data.Set.Image.273_0.IJFiTzmYGOCpPSd
|
@[congr]
theorem image_congr {f g : α → β} {s : Set α} (h : ∀ a ∈ s, f a = g a) : f '' s = g '' s
|
Mathlib_Data_Set_Image
|
α : Type u_1
β : Type u_2
γ : Type u_3
ι : Sort u_4
ι' : Sort u_5
f : α → β
s t : Set α
h : s ⊆ t
⊢ f '' s ⊆ f '' t
|
/-
Copyright (c) 2014 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Leonardo de Moura
-/
import Mathlib.Data.Set.Basic
#align_import data.set.image from "leanprover-community/mathlib"@"001ffdc42920050657fd45bd2b8bfbec8eaaeb29"
/-!
# Images and preimages of sets
## Main definitions
* `preimage f t : Set α` : the preimage f⁻¹(t) (written `f ⁻¹' t` in Lean) of a subset of β.
* `range f : Set β` : the image of `univ` under `f`.
Also works for `{p : Prop} (f : p → α)` (unlike `image`)
## Notation
* `f ⁻¹' t` for `Set.preimage f t`
* `f '' s` for `Set.image f s`
## Tags
set, sets, image, preimage, pre-image, range
-/
set_option autoImplicit true
universe u v
open Function Set
namespace Set
variable {α β γ : Type*} {ι ι' : Sort*}
/-! ### Inverse image -/
/-- The preimage of `s : Set β` by `f : α → β`, written `f ⁻¹' s`,
is the set of `x : α` such that `f x ∈ s`. -/
def preimage {α : Type u} {β : Type v} (f : α → β) (s : Set β) : Set α :=
{ x | f x ∈ s }
#align set.preimage Set.preimage
/-- `f ⁻¹' t` denotes the preimage of `t : Set β` under the function `f : α → β`. -/
infixl:80 " ⁻¹' " => preimage
section Preimage
variable {f : α → β} {g : β → γ}
@[simp]
theorem preimage_empty : f ⁻¹' ∅ = ∅ :=
rfl
#align set.preimage_empty Set.preimage_empty
@[simp, mfld_simps]
theorem mem_preimage {s : Set β} {a : α} : a ∈ f ⁻¹' s ↔ f a ∈ s :=
Iff.rfl
#align set.mem_preimage Set.mem_preimage
theorem preimage_congr {f g : α → β} {s : Set β} (h : ∀ x : α, f x = g x) : f ⁻¹' s = g ⁻¹' s := by
congr with x
simp [h]
#align set.preimage_congr Set.preimage_congr
@[gcongr]
theorem preimage_mono {s t : Set β} (h : s ⊆ t) : f ⁻¹' s ⊆ f ⁻¹' t := fun _ hx => h hx
#align set.preimage_mono Set.preimage_mono
@[simp, mfld_simps]
theorem preimage_univ : f ⁻¹' univ = univ :=
rfl
#align set.preimage_univ Set.preimage_univ
theorem subset_preimage_univ {s : Set α} : s ⊆ f ⁻¹' univ :=
subset_univ _
#align set.subset_preimage_univ Set.subset_preimage_univ
@[simp, mfld_simps]
theorem preimage_inter {s t : Set β} : f ⁻¹' (s ∩ t) = f ⁻¹' s ∩ f ⁻¹' t :=
rfl
#align set.preimage_inter Set.preimage_inter
@[simp]
theorem preimage_union {s t : Set β} : f ⁻¹' (s ∪ t) = f ⁻¹' s ∪ f ⁻¹' t :=
rfl
#align set.preimage_union Set.preimage_union
@[simp]
theorem preimage_compl {s : Set β} : f ⁻¹' sᶜ = (f ⁻¹' s)ᶜ :=
rfl
#align set.preimage_compl Set.preimage_compl
@[simp]
theorem preimage_diff (f : α → β) (s t : Set β) : f ⁻¹' (s \ t) = f ⁻¹' s \ f ⁻¹' t :=
rfl
#align set.preimage_diff Set.preimage_diff
@[simp]
lemma preimage_symmDiff {f : α → β} (s t : Set β) : f ⁻¹' (s ∆ t) = (f ⁻¹' s) ∆ (f ⁻¹' t) :=
rfl
#align set.preimage_symm_diff Set.preimage_symmDiff
@[simp]
theorem preimage_ite (f : α → β) (s t₁ t₂ : Set β) :
f ⁻¹' s.ite t₁ t₂ = (f ⁻¹' s).ite (f ⁻¹' t₁) (f ⁻¹' t₂) :=
rfl
#align set.preimage_ite Set.preimage_ite
@[simp]
theorem preimage_setOf_eq {p : α → Prop} {f : β → α} : f ⁻¹' { a | p a } = { a | p (f a) } :=
rfl
#align set.preimage_set_of_eq Set.preimage_setOf_eq
@[simp]
theorem preimage_id_eq : preimage (id : α → α) = id :=
rfl
#align set.preimage_id_eq Set.preimage_id_eq
@[mfld_simps]
theorem preimage_id {s : Set α} : id ⁻¹' s = s :=
rfl
#align set.preimage_id Set.preimage_id
@[simp, mfld_simps]
theorem preimage_id' {s : Set α} : (fun x => x) ⁻¹' s = s :=
rfl
#align set.preimage_id' Set.preimage_id'
@[simp]
theorem preimage_const_of_mem {b : β} {s : Set β} (h : b ∈ s) : (fun _ : α => b) ⁻¹' s = univ :=
eq_univ_of_forall fun _ => h
#align set.preimage_const_of_mem Set.preimage_const_of_mem
@[simp]
theorem preimage_const_of_not_mem {b : β} {s : Set β} (h : b ∉ s) : (fun _ : α => b) ⁻¹' s = ∅ :=
eq_empty_of_subset_empty fun _ hx => h hx
#align set.preimage_const_of_not_mem Set.preimage_const_of_not_mem
theorem preimage_const (b : β) (s : Set β) [Decidable (b ∈ s)] :
(fun _ : α => b) ⁻¹' s = if b ∈ s then univ else ∅ := by
split_ifs with hb
exacts [preimage_const_of_mem hb, preimage_const_of_not_mem hb]
#align set.preimage_const Set.preimage_const
/-- If preimage of each singleton under `f : α → β` is either empty or the whole type,
then `f` is a constant. -/
lemma exists_eq_const_of_preimage_singleton [Nonempty β] {f : α → β}
(hf : ∀ b : β, f ⁻¹' {b} = ∅ ∨ f ⁻¹' {b} = univ) : ∃ b, f = const α b := by
rcases em (∃ b, f ⁻¹' {b} = univ) with ⟨b, hb⟩ | hf'
· exact ⟨b, funext fun x ↦ eq_univ_iff_forall.1 hb x⟩
· have : ∀ x b, f x ≠ b := fun x b ↦
eq_empty_iff_forall_not_mem.1 ((hf b).resolve_right fun h ↦ hf' ⟨b, h⟩) x
exact ⟨Classical.arbitrary β, funext fun x ↦ absurd rfl (this x _)⟩
theorem preimage_comp {s : Set γ} : g ∘ f ⁻¹' s = f ⁻¹' (g ⁻¹' s) :=
rfl
#align set.preimage_comp Set.preimage_comp
theorem preimage_comp_eq : preimage (g ∘ f) = preimage f ∘ preimage g :=
rfl
#align set.preimage_comp_eq Set.preimage_comp_eq
theorem preimage_iterate_eq {f : α → α} {n : ℕ} : Set.preimage f^[n] = (Set.preimage f)^[n] := by
induction' n with n ih; · simp
rw [iterate_succ, iterate_succ', preimage_comp_eq, ih]
#align set.preimage_iterate_eq Set.preimage_iterate_eq
theorem preimage_preimage {g : β → γ} {f : α → β} {s : Set γ} :
f ⁻¹' (g ⁻¹' s) = (fun x => g (f x)) ⁻¹' s :=
preimage_comp.symm
#align set.preimage_preimage Set.preimage_preimage
theorem eq_preimage_subtype_val_iff {p : α → Prop} {s : Set (Subtype p)} {t : Set α} :
s = Subtype.val ⁻¹' t ↔ ∀ (x) (h : p x), (⟨x, h⟩ : Subtype p) ∈ s ↔ x ∈ t :=
⟨fun s_eq x h => by
rw [s_eq]
simp, fun h => ext fun ⟨x, hx⟩ => by simp [h]⟩
#align set.eq_preimage_subtype_val_iff Set.eq_preimage_subtype_val_iff
theorem nonempty_of_nonempty_preimage {s : Set β} {f : α → β} (hf : (f ⁻¹' s).Nonempty) :
s.Nonempty :=
let ⟨x, hx⟩ := hf
⟨f x, hx⟩
#align set.nonempty_of_nonempty_preimage Set.nonempty_of_nonempty_preimage
@[simp] theorem preimage_singleton_true (p : α → Prop) : p ⁻¹' {True} = {a | p a} := by ext; simp
#align set.preimage_singleton_true Set.preimage_singleton_true
@[simp] theorem preimage_singleton_false (p : α → Prop) : p ⁻¹' {False} = {a | ¬p a} := by ext; simp
#align set.preimage_singleton_false Set.preimage_singleton_false
theorem preimage_subtype_coe_eq_compl {s u v : Set α} (hsuv : s ⊆ u ∪ v)
(H : s ∩ (u ∩ v) = ∅) : ((↑) : s → α) ⁻¹' u = ((↑) ⁻¹' v)ᶜ := by
ext ⟨x, x_in_s⟩
constructor
· intro x_in_u x_in_v
exact eq_empty_iff_forall_not_mem.mp H x ⟨x_in_s, ⟨x_in_u, x_in_v⟩⟩
· intro hx
exact Or.elim (hsuv x_in_s) id fun hx' => hx.elim hx'
#align set.preimage_subtype_coe_eq_compl Set.preimage_subtype_coe_eq_compl
end Preimage
/-! ### Image of a set under a function -/
section Image
variable {f : α → β} {s t : Set α}
-- Porting note: `Set.image` is already defined in `Init.Set`
#align set.image Set.image
/-- `f '' s` denotes the image of `s : Set α` under the function `f : α → β`. -/
infixl:80 " '' " => image
theorem mem_image_iff_bex {f : α → β} {s : Set α} {y : β} :
y ∈ f '' s ↔ ∃ (x : _) (_ : x ∈ s), f x = y :=
bex_def.symm
#align set.mem_image_iff_bex Set.mem_image_iff_bex
@[simp]
theorem mem_image (f : α → β) (s : Set α) (y : β) : y ∈ f '' s ↔ ∃ x ∈ s, f x = y :=
Iff.rfl
#align set.mem_image Set.mem_image
theorem image_eta (f : α → β) : f '' s = (fun x => f x) '' s :=
rfl
#align set.image_eta Set.image_eta
@[mfld_simps]
theorem mem_image_of_mem (f : α → β) {x : α} {a : Set α} (h : x ∈ a) : f x ∈ f '' a :=
⟨_, h, rfl⟩
#align set.mem_image_of_mem Set.mem_image_of_mem
theorem _root_.Function.Injective.mem_set_image {f : α → β} (hf : Injective f) {s : Set α} {a : α} :
f a ∈ f '' s ↔ a ∈ s :=
⟨fun ⟨_, hb, Eq⟩ => hf Eq ▸ hb, mem_image_of_mem f⟩
#align function.injective.mem_set_image Function.Injective.mem_set_image
theorem ball_image_iff {f : α → β} {s : Set α} {p : β → Prop} :
(∀ y ∈ f '' s, p y) ↔ ∀ x ∈ s, p (f x) := by simp
#align set.ball_image_iff Set.ball_image_iff
theorem ball_image_of_ball {f : α → β} {s : Set α} {p : β → Prop} (h : ∀ x ∈ s, p (f x)) :
∀ y ∈ f '' s, p y :=
ball_image_iff.2 h
#align set.ball_image_of_ball Set.ball_image_of_ball
theorem bex_image_iff {f : α → β} {s : Set α} {p : β → Prop} :
(∃ y ∈ f '' s, p y) ↔ ∃ x ∈ s, p (f x) := by simp
#align set.bex_image_iff Set.bex_image_iff
theorem mem_image_elim {f : α → β} {s : Set α} {C : β → Prop} (h : ∀ x : α, x ∈ s → C (f x)) :
∀ {y : β}, y ∈ f '' s → C y
| _, ⟨a, a_in, rfl⟩ => h a a_in
#align set.mem_image_elim Set.mem_image_elim
theorem mem_image_elim_on {f : α → β} {s : Set α} {C : β → Prop} {y : β} (h_y : y ∈ f '' s)
(h : ∀ x : α, x ∈ s → C (f x)) : C y :=
mem_image_elim h h_y
#align set.mem_image_elim_on Set.mem_image_elim_on
-- Porting note: used to be `safe`
@[congr]
theorem image_congr {f g : α → β} {s : Set α} (h : ∀ a ∈ s, f a = g a) : f '' s = g '' s := by
ext x
rw [mem_image, mem_image]
exact {
mp := by
rintro ⟨a, ha1, ha2⟩
exact ⟨a, ⟨ha1, (h a ha1) ▸ ha2⟩⟩,
mpr := by
rintro ⟨a, ha1, ha2⟩
exact ⟨a, ⟨ha1, (h a ha1) ▸ ha2⟩⟩
}
-- safe [ext_iff, iff_def]
#align set.image_congr Set.image_congr
/-- A common special case of `image_congr` -/
theorem image_congr' {f g : α → β} {s : Set α} (h : ∀ x : α, f x = g x) : f '' s = g '' s :=
image_congr fun x _ => h x
#align set.image_congr' Set.image_congr'
@[gcongr]
lemma image_mono (h : s ⊆ t) : f '' s ⊆ f '' t := by
|
rintro - ⟨a, ha, rfl⟩
|
@[gcongr]
lemma image_mono (h : s ⊆ t) : f '' s ⊆ f '' t := by
|
Mathlib.Data.Set.Image.293_0.IJFiTzmYGOCpPSd
|
@[gcongr]
lemma image_mono (h : s ⊆ t) : f '' s ⊆ f '' t
|
Mathlib_Data_Set_Image
|
case intro.intro
α : Type u_1
β : Type u_2
γ : Type u_3
ι : Sort u_4
ι' : Sort u_5
f : α → β
s t : Set α
h : s ⊆ t
a : α
ha : a ∈ s
⊢ f a ∈ f '' t
|
/-
Copyright (c) 2014 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Leonardo de Moura
-/
import Mathlib.Data.Set.Basic
#align_import data.set.image from "leanprover-community/mathlib"@"001ffdc42920050657fd45bd2b8bfbec8eaaeb29"
/-!
# Images and preimages of sets
## Main definitions
* `preimage f t : Set α` : the preimage f⁻¹(t) (written `f ⁻¹' t` in Lean) of a subset of β.
* `range f : Set β` : the image of `univ` under `f`.
Also works for `{p : Prop} (f : p → α)` (unlike `image`)
## Notation
* `f ⁻¹' t` for `Set.preimage f t`
* `f '' s` for `Set.image f s`
## Tags
set, sets, image, preimage, pre-image, range
-/
set_option autoImplicit true
universe u v
open Function Set
namespace Set
variable {α β γ : Type*} {ι ι' : Sort*}
/-! ### Inverse image -/
/-- The preimage of `s : Set β` by `f : α → β`, written `f ⁻¹' s`,
is the set of `x : α` such that `f x ∈ s`. -/
def preimage {α : Type u} {β : Type v} (f : α → β) (s : Set β) : Set α :=
{ x | f x ∈ s }
#align set.preimage Set.preimage
/-- `f ⁻¹' t` denotes the preimage of `t : Set β` under the function `f : α → β`. -/
infixl:80 " ⁻¹' " => preimage
section Preimage
variable {f : α → β} {g : β → γ}
@[simp]
theorem preimage_empty : f ⁻¹' ∅ = ∅ :=
rfl
#align set.preimage_empty Set.preimage_empty
@[simp, mfld_simps]
theorem mem_preimage {s : Set β} {a : α} : a ∈ f ⁻¹' s ↔ f a ∈ s :=
Iff.rfl
#align set.mem_preimage Set.mem_preimage
theorem preimage_congr {f g : α → β} {s : Set β} (h : ∀ x : α, f x = g x) : f ⁻¹' s = g ⁻¹' s := by
congr with x
simp [h]
#align set.preimage_congr Set.preimage_congr
@[gcongr]
theorem preimage_mono {s t : Set β} (h : s ⊆ t) : f ⁻¹' s ⊆ f ⁻¹' t := fun _ hx => h hx
#align set.preimage_mono Set.preimage_mono
@[simp, mfld_simps]
theorem preimage_univ : f ⁻¹' univ = univ :=
rfl
#align set.preimage_univ Set.preimage_univ
theorem subset_preimage_univ {s : Set α} : s ⊆ f ⁻¹' univ :=
subset_univ _
#align set.subset_preimage_univ Set.subset_preimage_univ
@[simp, mfld_simps]
theorem preimage_inter {s t : Set β} : f ⁻¹' (s ∩ t) = f ⁻¹' s ∩ f ⁻¹' t :=
rfl
#align set.preimage_inter Set.preimage_inter
@[simp]
theorem preimage_union {s t : Set β} : f ⁻¹' (s ∪ t) = f ⁻¹' s ∪ f ⁻¹' t :=
rfl
#align set.preimage_union Set.preimage_union
@[simp]
theorem preimage_compl {s : Set β} : f ⁻¹' sᶜ = (f ⁻¹' s)ᶜ :=
rfl
#align set.preimage_compl Set.preimage_compl
@[simp]
theorem preimage_diff (f : α → β) (s t : Set β) : f ⁻¹' (s \ t) = f ⁻¹' s \ f ⁻¹' t :=
rfl
#align set.preimage_diff Set.preimage_diff
@[simp]
lemma preimage_symmDiff {f : α → β} (s t : Set β) : f ⁻¹' (s ∆ t) = (f ⁻¹' s) ∆ (f ⁻¹' t) :=
rfl
#align set.preimage_symm_diff Set.preimage_symmDiff
@[simp]
theorem preimage_ite (f : α → β) (s t₁ t₂ : Set β) :
f ⁻¹' s.ite t₁ t₂ = (f ⁻¹' s).ite (f ⁻¹' t₁) (f ⁻¹' t₂) :=
rfl
#align set.preimage_ite Set.preimage_ite
@[simp]
theorem preimage_setOf_eq {p : α → Prop} {f : β → α} : f ⁻¹' { a | p a } = { a | p (f a) } :=
rfl
#align set.preimage_set_of_eq Set.preimage_setOf_eq
@[simp]
theorem preimage_id_eq : preimage (id : α → α) = id :=
rfl
#align set.preimage_id_eq Set.preimage_id_eq
@[mfld_simps]
theorem preimage_id {s : Set α} : id ⁻¹' s = s :=
rfl
#align set.preimage_id Set.preimage_id
@[simp, mfld_simps]
theorem preimage_id' {s : Set α} : (fun x => x) ⁻¹' s = s :=
rfl
#align set.preimage_id' Set.preimage_id'
@[simp]
theorem preimage_const_of_mem {b : β} {s : Set β} (h : b ∈ s) : (fun _ : α => b) ⁻¹' s = univ :=
eq_univ_of_forall fun _ => h
#align set.preimage_const_of_mem Set.preimage_const_of_mem
@[simp]
theorem preimage_const_of_not_mem {b : β} {s : Set β} (h : b ∉ s) : (fun _ : α => b) ⁻¹' s = ∅ :=
eq_empty_of_subset_empty fun _ hx => h hx
#align set.preimage_const_of_not_mem Set.preimage_const_of_not_mem
theorem preimage_const (b : β) (s : Set β) [Decidable (b ∈ s)] :
(fun _ : α => b) ⁻¹' s = if b ∈ s then univ else ∅ := by
split_ifs with hb
exacts [preimage_const_of_mem hb, preimage_const_of_not_mem hb]
#align set.preimage_const Set.preimage_const
/-- If preimage of each singleton under `f : α → β` is either empty or the whole type,
then `f` is a constant. -/
lemma exists_eq_const_of_preimage_singleton [Nonempty β] {f : α → β}
(hf : ∀ b : β, f ⁻¹' {b} = ∅ ∨ f ⁻¹' {b} = univ) : ∃ b, f = const α b := by
rcases em (∃ b, f ⁻¹' {b} = univ) with ⟨b, hb⟩ | hf'
· exact ⟨b, funext fun x ↦ eq_univ_iff_forall.1 hb x⟩
· have : ∀ x b, f x ≠ b := fun x b ↦
eq_empty_iff_forall_not_mem.1 ((hf b).resolve_right fun h ↦ hf' ⟨b, h⟩) x
exact ⟨Classical.arbitrary β, funext fun x ↦ absurd rfl (this x _)⟩
theorem preimage_comp {s : Set γ} : g ∘ f ⁻¹' s = f ⁻¹' (g ⁻¹' s) :=
rfl
#align set.preimage_comp Set.preimage_comp
theorem preimage_comp_eq : preimage (g ∘ f) = preimage f ∘ preimage g :=
rfl
#align set.preimage_comp_eq Set.preimage_comp_eq
theorem preimage_iterate_eq {f : α → α} {n : ℕ} : Set.preimage f^[n] = (Set.preimage f)^[n] := by
induction' n with n ih; · simp
rw [iterate_succ, iterate_succ', preimage_comp_eq, ih]
#align set.preimage_iterate_eq Set.preimage_iterate_eq
theorem preimage_preimage {g : β → γ} {f : α → β} {s : Set γ} :
f ⁻¹' (g ⁻¹' s) = (fun x => g (f x)) ⁻¹' s :=
preimage_comp.symm
#align set.preimage_preimage Set.preimage_preimage
theorem eq_preimage_subtype_val_iff {p : α → Prop} {s : Set (Subtype p)} {t : Set α} :
s = Subtype.val ⁻¹' t ↔ ∀ (x) (h : p x), (⟨x, h⟩ : Subtype p) ∈ s ↔ x ∈ t :=
⟨fun s_eq x h => by
rw [s_eq]
simp, fun h => ext fun ⟨x, hx⟩ => by simp [h]⟩
#align set.eq_preimage_subtype_val_iff Set.eq_preimage_subtype_val_iff
theorem nonempty_of_nonempty_preimage {s : Set β} {f : α → β} (hf : (f ⁻¹' s).Nonempty) :
s.Nonempty :=
let ⟨x, hx⟩ := hf
⟨f x, hx⟩
#align set.nonempty_of_nonempty_preimage Set.nonempty_of_nonempty_preimage
@[simp] theorem preimage_singleton_true (p : α → Prop) : p ⁻¹' {True} = {a | p a} := by ext; simp
#align set.preimage_singleton_true Set.preimage_singleton_true
@[simp] theorem preimage_singleton_false (p : α → Prop) : p ⁻¹' {False} = {a | ¬p a} := by ext; simp
#align set.preimage_singleton_false Set.preimage_singleton_false
theorem preimage_subtype_coe_eq_compl {s u v : Set α} (hsuv : s ⊆ u ∪ v)
(H : s ∩ (u ∩ v) = ∅) : ((↑) : s → α) ⁻¹' u = ((↑) ⁻¹' v)ᶜ := by
ext ⟨x, x_in_s⟩
constructor
· intro x_in_u x_in_v
exact eq_empty_iff_forall_not_mem.mp H x ⟨x_in_s, ⟨x_in_u, x_in_v⟩⟩
· intro hx
exact Or.elim (hsuv x_in_s) id fun hx' => hx.elim hx'
#align set.preimage_subtype_coe_eq_compl Set.preimage_subtype_coe_eq_compl
end Preimage
/-! ### Image of a set under a function -/
section Image
variable {f : α → β} {s t : Set α}
-- Porting note: `Set.image` is already defined in `Init.Set`
#align set.image Set.image
/-- `f '' s` denotes the image of `s : Set α` under the function `f : α → β`. -/
infixl:80 " '' " => image
theorem mem_image_iff_bex {f : α → β} {s : Set α} {y : β} :
y ∈ f '' s ↔ ∃ (x : _) (_ : x ∈ s), f x = y :=
bex_def.symm
#align set.mem_image_iff_bex Set.mem_image_iff_bex
@[simp]
theorem mem_image (f : α → β) (s : Set α) (y : β) : y ∈ f '' s ↔ ∃ x ∈ s, f x = y :=
Iff.rfl
#align set.mem_image Set.mem_image
theorem image_eta (f : α → β) : f '' s = (fun x => f x) '' s :=
rfl
#align set.image_eta Set.image_eta
@[mfld_simps]
theorem mem_image_of_mem (f : α → β) {x : α} {a : Set α} (h : x ∈ a) : f x ∈ f '' a :=
⟨_, h, rfl⟩
#align set.mem_image_of_mem Set.mem_image_of_mem
theorem _root_.Function.Injective.mem_set_image {f : α → β} (hf : Injective f) {s : Set α} {a : α} :
f a ∈ f '' s ↔ a ∈ s :=
⟨fun ⟨_, hb, Eq⟩ => hf Eq ▸ hb, mem_image_of_mem f⟩
#align function.injective.mem_set_image Function.Injective.mem_set_image
theorem ball_image_iff {f : α → β} {s : Set α} {p : β → Prop} :
(∀ y ∈ f '' s, p y) ↔ ∀ x ∈ s, p (f x) := by simp
#align set.ball_image_iff Set.ball_image_iff
theorem ball_image_of_ball {f : α → β} {s : Set α} {p : β → Prop} (h : ∀ x ∈ s, p (f x)) :
∀ y ∈ f '' s, p y :=
ball_image_iff.2 h
#align set.ball_image_of_ball Set.ball_image_of_ball
theorem bex_image_iff {f : α → β} {s : Set α} {p : β → Prop} :
(∃ y ∈ f '' s, p y) ↔ ∃ x ∈ s, p (f x) := by simp
#align set.bex_image_iff Set.bex_image_iff
theorem mem_image_elim {f : α → β} {s : Set α} {C : β → Prop} (h : ∀ x : α, x ∈ s → C (f x)) :
∀ {y : β}, y ∈ f '' s → C y
| _, ⟨a, a_in, rfl⟩ => h a a_in
#align set.mem_image_elim Set.mem_image_elim
theorem mem_image_elim_on {f : α → β} {s : Set α} {C : β → Prop} {y : β} (h_y : y ∈ f '' s)
(h : ∀ x : α, x ∈ s → C (f x)) : C y :=
mem_image_elim h h_y
#align set.mem_image_elim_on Set.mem_image_elim_on
-- Porting note: used to be `safe`
@[congr]
theorem image_congr {f g : α → β} {s : Set α} (h : ∀ a ∈ s, f a = g a) : f '' s = g '' s := by
ext x
rw [mem_image, mem_image]
exact {
mp := by
rintro ⟨a, ha1, ha2⟩
exact ⟨a, ⟨ha1, (h a ha1) ▸ ha2⟩⟩,
mpr := by
rintro ⟨a, ha1, ha2⟩
exact ⟨a, ⟨ha1, (h a ha1) ▸ ha2⟩⟩
}
-- safe [ext_iff, iff_def]
#align set.image_congr Set.image_congr
/-- A common special case of `image_congr` -/
theorem image_congr' {f g : α → β} {s : Set α} (h : ∀ x : α, f x = g x) : f '' s = g '' s :=
image_congr fun x _ => h x
#align set.image_congr' Set.image_congr'
@[gcongr]
lemma image_mono (h : s ⊆ t) : f '' s ⊆ f '' t := by
rintro - ⟨a, ha, rfl⟩;
|
exact mem_image_of_mem f (h ha)
|
@[gcongr]
lemma image_mono (h : s ⊆ t) : f '' s ⊆ f '' t := by
rintro - ⟨a, ha, rfl⟩;
|
Mathlib.Data.Set.Image.293_0.IJFiTzmYGOCpPSd
|
@[gcongr]
lemma image_mono (h : s ⊆ t) : f '' s ⊆ f '' t
|
Mathlib_Data_Set_Image
|
α : Type u_1
β : Type u_2
γ : Type u_3
ι : Sort u_4
ι' : Sort u_5
f : α → β
s t : Set α
g : β → γ
⊢ image (g ∘ f) = image g ∘ image f
|
/-
Copyright (c) 2014 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Leonardo de Moura
-/
import Mathlib.Data.Set.Basic
#align_import data.set.image from "leanprover-community/mathlib"@"001ffdc42920050657fd45bd2b8bfbec8eaaeb29"
/-!
# Images and preimages of sets
## Main definitions
* `preimage f t : Set α` : the preimage f⁻¹(t) (written `f ⁻¹' t` in Lean) of a subset of β.
* `range f : Set β` : the image of `univ` under `f`.
Also works for `{p : Prop} (f : p → α)` (unlike `image`)
## Notation
* `f ⁻¹' t` for `Set.preimage f t`
* `f '' s` for `Set.image f s`
## Tags
set, sets, image, preimage, pre-image, range
-/
set_option autoImplicit true
universe u v
open Function Set
namespace Set
variable {α β γ : Type*} {ι ι' : Sort*}
/-! ### Inverse image -/
/-- The preimage of `s : Set β` by `f : α → β`, written `f ⁻¹' s`,
is the set of `x : α` such that `f x ∈ s`. -/
def preimage {α : Type u} {β : Type v} (f : α → β) (s : Set β) : Set α :=
{ x | f x ∈ s }
#align set.preimage Set.preimage
/-- `f ⁻¹' t` denotes the preimage of `t : Set β` under the function `f : α → β`. -/
infixl:80 " ⁻¹' " => preimage
section Preimage
variable {f : α → β} {g : β → γ}
@[simp]
theorem preimage_empty : f ⁻¹' ∅ = ∅ :=
rfl
#align set.preimage_empty Set.preimage_empty
@[simp, mfld_simps]
theorem mem_preimage {s : Set β} {a : α} : a ∈ f ⁻¹' s ↔ f a ∈ s :=
Iff.rfl
#align set.mem_preimage Set.mem_preimage
theorem preimage_congr {f g : α → β} {s : Set β} (h : ∀ x : α, f x = g x) : f ⁻¹' s = g ⁻¹' s := by
congr with x
simp [h]
#align set.preimage_congr Set.preimage_congr
@[gcongr]
theorem preimage_mono {s t : Set β} (h : s ⊆ t) : f ⁻¹' s ⊆ f ⁻¹' t := fun _ hx => h hx
#align set.preimage_mono Set.preimage_mono
@[simp, mfld_simps]
theorem preimage_univ : f ⁻¹' univ = univ :=
rfl
#align set.preimage_univ Set.preimage_univ
theorem subset_preimage_univ {s : Set α} : s ⊆ f ⁻¹' univ :=
subset_univ _
#align set.subset_preimage_univ Set.subset_preimage_univ
@[simp, mfld_simps]
theorem preimage_inter {s t : Set β} : f ⁻¹' (s ∩ t) = f ⁻¹' s ∩ f ⁻¹' t :=
rfl
#align set.preimage_inter Set.preimage_inter
@[simp]
theorem preimage_union {s t : Set β} : f ⁻¹' (s ∪ t) = f ⁻¹' s ∪ f ⁻¹' t :=
rfl
#align set.preimage_union Set.preimage_union
@[simp]
theorem preimage_compl {s : Set β} : f ⁻¹' sᶜ = (f ⁻¹' s)ᶜ :=
rfl
#align set.preimage_compl Set.preimage_compl
@[simp]
theorem preimage_diff (f : α → β) (s t : Set β) : f ⁻¹' (s \ t) = f ⁻¹' s \ f ⁻¹' t :=
rfl
#align set.preimage_diff Set.preimage_diff
@[simp]
lemma preimage_symmDiff {f : α → β} (s t : Set β) : f ⁻¹' (s ∆ t) = (f ⁻¹' s) ∆ (f ⁻¹' t) :=
rfl
#align set.preimage_symm_diff Set.preimage_symmDiff
@[simp]
theorem preimage_ite (f : α → β) (s t₁ t₂ : Set β) :
f ⁻¹' s.ite t₁ t₂ = (f ⁻¹' s).ite (f ⁻¹' t₁) (f ⁻¹' t₂) :=
rfl
#align set.preimage_ite Set.preimage_ite
@[simp]
theorem preimage_setOf_eq {p : α → Prop} {f : β → α} : f ⁻¹' { a | p a } = { a | p (f a) } :=
rfl
#align set.preimage_set_of_eq Set.preimage_setOf_eq
@[simp]
theorem preimage_id_eq : preimage (id : α → α) = id :=
rfl
#align set.preimage_id_eq Set.preimage_id_eq
@[mfld_simps]
theorem preimage_id {s : Set α} : id ⁻¹' s = s :=
rfl
#align set.preimage_id Set.preimage_id
@[simp, mfld_simps]
theorem preimage_id' {s : Set α} : (fun x => x) ⁻¹' s = s :=
rfl
#align set.preimage_id' Set.preimage_id'
@[simp]
theorem preimage_const_of_mem {b : β} {s : Set β} (h : b ∈ s) : (fun _ : α => b) ⁻¹' s = univ :=
eq_univ_of_forall fun _ => h
#align set.preimage_const_of_mem Set.preimage_const_of_mem
@[simp]
theorem preimage_const_of_not_mem {b : β} {s : Set β} (h : b ∉ s) : (fun _ : α => b) ⁻¹' s = ∅ :=
eq_empty_of_subset_empty fun _ hx => h hx
#align set.preimage_const_of_not_mem Set.preimage_const_of_not_mem
theorem preimage_const (b : β) (s : Set β) [Decidable (b ∈ s)] :
(fun _ : α => b) ⁻¹' s = if b ∈ s then univ else ∅ := by
split_ifs with hb
exacts [preimage_const_of_mem hb, preimage_const_of_not_mem hb]
#align set.preimage_const Set.preimage_const
/-- If preimage of each singleton under `f : α → β` is either empty or the whole type,
then `f` is a constant. -/
lemma exists_eq_const_of_preimage_singleton [Nonempty β] {f : α → β}
(hf : ∀ b : β, f ⁻¹' {b} = ∅ ∨ f ⁻¹' {b} = univ) : ∃ b, f = const α b := by
rcases em (∃ b, f ⁻¹' {b} = univ) with ⟨b, hb⟩ | hf'
· exact ⟨b, funext fun x ↦ eq_univ_iff_forall.1 hb x⟩
· have : ∀ x b, f x ≠ b := fun x b ↦
eq_empty_iff_forall_not_mem.1 ((hf b).resolve_right fun h ↦ hf' ⟨b, h⟩) x
exact ⟨Classical.arbitrary β, funext fun x ↦ absurd rfl (this x _)⟩
theorem preimage_comp {s : Set γ} : g ∘ f ⁻¹' s = f ⁻¹' (g ⁻¹' s) :=
rfl
#align set.preimage_comp Set.preimage_comp
theorem preimage_comp_eq : preimage (g ∘ f) = preimage f ∘ preimage g :=
rfl
#align set.preimage_comp_eq Set.preimage_comp_eq
theorem preimage_iterate_eq {f : α → α} {n : ℕ} : Set.preimage f^[n] = (Set.preimage f)^[n] := by
induction' n with n ih; · simp
rw [iterate_succ, iterate_succ', preimage_comp_eq, ih]
#align set.preimage_iterate_eq Set.preimage_iterate_eq
theorem preimage_preimage {g : β → γ} {f : α → β} {s : Set γ} :
f ⁻¹' (g ⁻¹' s) = (fun x => g (f x)) ⁻¹' s :=
preimage_comp.symm
#align set.preimage_preimage Set.preimage_preimage
theorem eq_preimage_subtype_val_iff {p : α → Prop} {s : Set (Subtype p)} {t : Set α} :
s = Subtype.val ⁻¹' t ↔ ∀ (x) (h : p x), (⟨x, h⟩ : Subtype p) ∈ s ↔ x ∈ t :=
⟨fun s_eq x h => by
rw [s_eq]
simp, fun h => ext fun ⟨x, hx⟩ => by simp [h]⟩
#align set.eq_preimage_subtype_val_iff Set.eq_preimage_subtype_val_iff
theorem nonempty_of_nonempty_preimage {s : Set β} {f : α → β} (hf : (f ⁻¹' s).Nonempty) :
s.Nonempty :=
let ⟨x, hx⟩ := hf
⟨f x, hx⟩
#align set.nonempty_of_nonempty_preimage Set.nonempty_of_nonempty_preimage
@[simp] theorem preimage_singleton_true (p : α → Prop) : p ⁻¹' {True} = {a | p a} := by ext; simp
#align set.preimage_singleton_true Set.preimage_singleton_true
@[simp] theorem preimage_singleton_false (p : α → Prop) : p ⁻¹' {False} = {a | ¬p a} := by ext; simp
#align set.preimage_singleton_false Set.preimage_singleton_false
theorem preimage_subtype_coe_eq_compl {s u v : Set α} (hsuv : s ⊆ u ∪ v)
(H : s ∩ (u ∩ v) = ∅) : ((↑) : s → α) ⁻¹' u = ((↑) ⁻¹' v)ᶜ := by
ext ⟨x, x_in_s⟩
constructor
· intro x_in_u x_in_v
exact eq_empty_iff_forall_not_mem.mp H x ⟨x_in_s, ⟨x_in_u, x_in_v⟩⟩
· intro hx
exact Or.elim (hsuv x_in_s) id fun hx' => hx.elim hx'
#align set.preimage_subtype_coe_eq_compl Set.preimage_subtype_coe_eq_compl
end Preimage
/-! ### Image of a set under a function -/
section Image
variable {f : α → β} {s t : Set α}
-- Porting note: `Set.image` is already defined in `Init.Set`
#align set.image Set.image
/-- `f '' s` denotes the image of `s : Set α` under the function `f : α → β`. -/
infixl:80 " '' " => image
theorem mem_image_iff_bex {f : α → β} {s : Set α} {y : β} :
y ∈ f '' s ↔ ∃ (x : _) (_ : x ∈ s), f x = y :=
bex_def.symm
#align set.mem_image_iff_bex Set.mem_image_iff_bex
@[simp]
theorem mem_image (f : α → β) (s : Set α) (y : β) : y ∈ f '' s ↔ ∃ x ∈ s, f x = y :=
Iff.rfl
#align set.mem_image Set.mem_image
theorem image_eta (f : α → β) : f '' s = (fun x => f x) '' s :=
rfl
#align set.image_eta Set.image_eta
@[mfld_simps]
theorem mem_image_of_mem (f : α → β) {x : α} {a : Set α} (h : x ∈ a) : f x ∈ f '' a :=
⟨_, h, rfl⟩
#align set.mem_image_of_mem Set.mem_image_of_mem
theorem _root_.Function.Injective.mem_set_image {f : α → β} (hf : Injective f) {s : Set α} {a : α} :
f a ∈ f '' s ↔ a ∈ s :=
⟨fun ⟨_, hb, Eq⟩ => hf Eq ▸ hb, mem_image_of_mem f⟩
#align function.injective.mem_set_image Function.Injective.mem_set_image
theorem ball_image_iff {f : α → β} {s : Set α} {p : β → Prop} :
(∀ y ∈ f '' s, p y) ↔ ∀ x ∈ s, p (f x) := by simp
#align set.ball_image_iff Set.ball_image_iff
theorem ball_image_of_ball {f : α → β} {s : Set α} {p : β → Prop} (h : ∀ x ∈ s, p (f x)) :
∀ y ∈ f '' s, p y :=
ball_image_iff.2 h
#align set.ball_image_of_ball Set.ball_image_of_ball
theorem bex_image_iff {f : α → β} {s : Set α} {p : β → Prop} :
(∃ y ∈ f '' s, p y) ↔ ∃ x ∈ s, p (f x) := by simp
#align set.bex_image_iff Set.bex_image_iff
theorem mem_image_elim {f : α → β} {s : Set α} {C : β → Prop} (h : ∀ x : α, x ∈ s → C (f x)) :
∀ {y : β}, y ∈ f '' s → C y
| _, ⟨a, a_in, rfl⟩ => h a a_in
#align set.mem_image_elim Set.mem_image_elim
theorem mem_image_elim_on {f : α → β} {s : Set α} {C : β → Prop} {y : β} (h_y : y ∈ f '' s)
(h : ∀ x : α, x ∈ s → C (f x)) : C y :=
mem_image_elim h h_y
#align set.mem_image_elim_on Set.mem_image_elim_on
-- Porting note: used to be `safe`
@[congr]
theorem image_congr {f g : α → β} {s : Set α} (h : ∀ a ∈ s, f a = g a) : f '' s = g '' s := by
ext x
rw [mem_image, mem_image]
exact {
mp := by
rintro ⟨a, ha1, ha2⟩
exact ⟨a, ⟨ha1, (h a ha1) ▸ ha2⟩⟩,
mpr := by
rintro ⟨a, ha1, ha2⟩
exact ⟨a, ⟨ha1, (h a ha1) ▸ ha2⟩⟩
}
-- safe [ext_iff, iff_def]
#align set.image_congr Set.image_congr
/-- A common special case of `image_congr` -/
theorem image_congr' {f g : α → β} {s : Set α} (h : ∀ x : α, f x = g x) : f '' s = g '' s :=
image_congr fun x _ => h x
#align set.image_congr' Set.image_congr'
@[gcongr]
lemma image_mono (h : s ⊆ t) : f '' s ⊆ f '' t := by
rintro - ⟨a, ha, rfl⟩; exact mem_image_of_mem f (h ha)
theorem image_comp (f : β → γ) (g : α → β) (a : Set α) : f ∘ g '' a = f '' (g '' a) :=
Subset.antisymm (ball_image_of_ball fun _ ha => mem_image_of_mem _ <| mem_image_of_mem _ ha)
(ball_image_of_ball <| ball_image_of_ball fun _ ha => mem_image_of_mem _ ha)
#align set.image_comp Set.image_comp
theorem image_comp_eq {g : β → γ} : image (g ∘ f) = image g ∘ image f := by
|
ext
|
theorem image_comp_eq {g : β → γ} : image (g ∘ f) = image g ∘ image f := by
|
Mathlib.Data.Set.Image.302_0.IJFiTzmYGOCpPSd
|
theorem image_comp_eq {g : β → γ} : image (g ∘ f) = image g ∘ image f
|
Mathlib_Data_Set_Image
|
case h.h
α : Type u_1
β : Type u_2
γ : Type u_3
ι : Sort u_4
ι' : Sort u_5
f : α → β
s t : Set α
g : β → γ
x✝¹ : Set α
x✝ : γ
⊢ x✝ ∈ g ∘ f '' x✝¹ ↔ x✝ ∈ (image g ∘ image f) x✝¹
|
/-
Copyright (c) 2014 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Leonardo de Moura
-/
import Mathlib.Data.Set.Basic
#align_import data.set.image from "leanprover-community/mathlib"@"001ffdc42920050657fd45bd2b8bfbec8eaaeb29"
/-!
# Images and preimages of sets
## Main definitions
* `preimage f t : Set α` : the preimage f⁻¹(t) (written `f ⁻¹' t` in Lean) of a subset of β.
* `range f : Set β` : the image of `univ` under `f`.
Also works for `{p : Prop} (f : p → α)` (unlike `image`)
## Notation
* `f ⁻¹' t` for `Set.preimage f t`
* `f '' s` for `Set.image f s`
## Tags
set, sets, image, preimage, pre-image, range
-/
set_option autoImplicit true
universe u v
open Function Set
namespace Set
variable {α β γ : Type*} {ι ι' : Sort*}
/-! ### Inverse image -/
/-- The preimage of `s : Set β` by `f : α → β`, written `f ⁻¹' s`,
is the set of `x : α` such that `f x ∈ s`. -/
def preimage {α : Type u} {β : Type v} (f : α → β) (s : Set β) : Set α :=
{ x | f x ∈ s }
#align set.preimage Set.preimage
/-- `f ⁻¹' t` denotes the preimage of `t : Set β` under the function `f : α → β`. -/
infixl:80 " ⁻¹' " => preimage
section Preimage
variable {f : α → β} {g : β → γ}
@[simp]
theorem preimage_empty : f ⁻¹' ∅ = ∅ :=
rfl
#align set.preimage_empty Set.preimage_empty
@[simp, mfld_simps]
theorem mem_preimage {s : Set β} {a : α} : a ∈ f ⁻¹' s ↔ f a ∈ s :=
Iff.rfl
#align set.mem_preimage Set.mem_preimage
theorem preimage_congr {f g : α → β} {s : Set β} (h : ∀ x : α, f x = g x) : f ⁻¹' s = g ⁻¹' s := by
congr with x
simp [h]
#align set.preimage_congr Set.preimage_congr
@[gcongr]
theorem preimage_mono {s t : Set β} (h : s ⊆ t) : f ⁻¹' s ⊆ f ⁻¹' t := fun _ hx => h hx
#align set.preimage_mono Set.preimage_mono
@[simp, mfld_simps]
theorem preimage_univ : f ⁻¹' univ = univ :=
rfl
#align set.preimage_univ Set.preimage_univ
theorem subset_preimage_univ {s : Set α} : s ⊆ f ⁻¹' univ :=
subset_univ _
#align set.subset_preimage_univ Set.subset_preimage_univ
@[simp, mfld_simps]
theorem preimage_inter {s t : Set β} : f ⁻¹' (s ∩ t) = f ⁻¹' s ∩ f ⁻¹' t :=
rfl
#align set.preimage_inter Set.preimage_inter
@[simp]
theorem preimage_union {s t : Set β} : f ⁻¹' (s ∪ t) = f ⁻¹' s ∪ f ⁻¹' t :=
rfl
#align set.preimage_union Set.preimage_union
@[simp]
theorem preimage_compl {s : Set β} : f ⁻¹' sᶜ = (f ⁻¹' s)ᶜ :=
rfl
#align set.preimage_compl Set.preimage_compl
@[simp]
theorem preimage_diff (f : α → β) (s t : Set β) : f ⁻¹' (s \ t) = f ⁻¹' s \ f ⁻¹' t :=
rfl
#align set.preimage_diff Set.preimage_diff
@[simp]
lemma preimage_symmDiff {f : α → β} (s t : Set β) : f ⁻¹' (s ∆ t) = (f ⁻¹' s) ∆ (f ⁻¹' t) :=
rfl
#align set.preimage_symm_diff Set.preimage_symmDiff
@[simp]
theorem preimage_ite (f : α → β) (s t₁ t₂ : Set β) :
f ⁻¹' s.ite t₁ t₂ = (f ⁻¹' s).ite (f ⁻¹' t₁) (f ⁻¹' t₂) :=
rfl
#align set.preimage_ite Set.preimage_ite
@[simp]
theorem preimage_setOf_eq {p : α → Prop} {f : β → α} : f ⁻¹' { a | p a } = { a | p (f a) } :=
rfl
#align set.preimage_set_of_eq Set.preimage_setOf_eq
@[simp]
theorem preimage_id_eq : preimage (id : α → α) = id :=
rfl
#align set.preimage_id_eq Set.preimage_id_eq
@[mfld_simps]
theorem preimage_id {s : Set α} : id ⁻¹' s = s :=
rfl
#align set.preimage_id Set.preimage_id
@[simp, mfld_simps]
theorem preimage_id' {s : Set α} : (fun x => x) ⁻¹' s = s :=
rfl
#align set.preimage_id' Set.preimage_id'
@[simp]
theorem preimage_const_of_mem {b : β} {s : Set β} (h : b ∈ s) : (fun _ : α => b) ⁻¹' s = univ :=
eq_univ_of_forall fun _ => h
#align set.preimage_const_of_mem Set.preimage_const_of_mem
@[simp]
theorem preimage_const_of_not_mem {b : β} {s : Set β} (h : b ∉ s) : (fun _ : α => b) ⁻¹' s = ∅ :=
eq_empty_of_subset_empty fun _ hx => h hx
#align set.preimage_const_of_not_mem Set.preimage_const_of_not_mem
theorem preimage_const (b : β) (s : Set β) [Decidable (b ∈ s)] :
(fun _ : α => b) ⁻¹' s = if b ∈ s then univ else ∅ := by
split_ifs with hb
exacts [preimage_const_of_mem hb, preimage_const_of_not_mem hb]
#align set.preimage_const Set.preimage_const
/-- If preimage of each singleton under `f : α → β` is either empty or the whole type,
then `f` is a constant. -/
lemma exists_eq_const_of_preimage_singleton [Nonempty β] {f : α → β}
(hf : ∀ b : β, f ⁻¹' {b} = ∅ ∨ f ⁻¹' {b} = univ) : ∃ b, f = const α b := by
rcases em (∃ b, f ⁻¹' {b} = univ) with ⟨b, hb⟩ | hf'
· exact ⟨b, funext fun x ↦ eq_univ_iff_forall.1 hb x⟩
· have : ∀ x b, f x ≠ b := fun x b ↦
eq_empty_iff_forall_not_mem.1 ((hf b).resolve_right fun h ↦ hf' ⟨b, h⟩) x
exact ⟨Classical.arbitrary β, funext fun x ↦ absurd rfl (this x _)⟩
theorem preimage_comp {s : Set γ} : g ∘ f ⁻¹' s = f ⁻¹' (g ⁻¹' s) :=
rfl
#align set.preimage_comp Set.preimage_comp
theorem preimage_comp_eq : preimage (g ∘ f) = preimage f ∘ preimage g :=
rfl
#align set.preimage_comp_eq Set.preimage_comp_eq
theorem preimage_iterate_eq {f : α → α} {n : ℕ} : Set.preimage f^[n] = (Set.preimage f)^[n] := by
induction' n with n ih; · simp
rw [iterate_succ, iterate_succ', preimage_comp_eq, ih]
#align set.preimage_iterate_eq Set.preimage_iterate_eq
theorem preimage_preimage {g : β → γ} {f : α → β} {s : Set γ} :
f ⁻¹' (g ⁻¹' s) = (fun x => g (f x)) ⁻¹' s :=
preimage_comp.symm
#align set.preimage_preimage Set.preimage_preimage
theorem eq_preimage_subtype_val_iff {p : α → Prop} {s : Set (Subtype p)} {t : Set α} :
s = Subtype.val ⁻¹' t ↔ ∀ (x) (h : p x), (⟨x, h⟩ : Subtype p) ∈ s ↔ x ∈ t :=
⟨fun s_eq x h => by
rw [s_eq]
simp, fun h => ext fun ⟨x, hx⟩ => by simp [h]⟩
#align set.eq_preimage_subtype_val_iff Set.eq_preimage_subtype_val_iff
theorem nonempty_of_nonempty_preimage {s : Set β} {f : α → β} (hf : (f ⁻¹' s).Nonempty) :
s.Nonempty :=
let ⟨x, hx⟩ := hf
⟨f x, hx⟩
#align set.nonempty_of_nonempty_preimage Set.nonempty_of_nonempty_preimage
@[simp] theorem preimage_singleton_true (p : α → Prop) : p ⁻¹' {True} = {a | p a} := by ext; simp
#align set.preimage_singleton_true Set.preimage_singleton_true
@[simp] theorem preimage_singleton_false (p : α → Prop) : p ⁻¹' {False} = {a | ¬p a} := by ext; simp
#align set.preimage_singleton_false Set.preimage_singleton_false
theorem preimage_subtype_coe_eq_compl {s u v : Set α} (hsuv : s ⊆ u ∪ v)
(H : s ∩ (u ∩ v) = ∅) : ((↑) : s → α) ⁻¹' u = ((↑) ⁻¹' v)ᶜ := by
ext ⟨x, x_in_s⟩
constructor
· intro x_in_u x_in_v
exact eq_empty_iff_forall_not_mem.mp H x ⟨x_in_s, ⟨x_in_u, x_in_v⟩⟩
· intro hx
exact Or.elim (hsuv x_in_s) id fun hx' => hx.elim hx'
#align set.preimage_subtype_coe_eq_compl Set.preimage_subtype_coe_eq_compl
end Preimage
/-! ### Image of a set under a function -/
section Image
variable {f : α → β} {s t : Set α}
-- Porting note: `Set.image` is already defined in `Init.Set`
#align set.image Set.image
/-- `f '' s` denotes the image of `s : Set α` under the function `f : α → β`. -/
infixl:80 " '' " => image
theorem mem_image_iff_bex {f : α → β} {s : Set α} {y : β} :
y ∈ f '' s ↔ ∃ (x : _) (_ : x ∈ s), f x = y :=
bex_def.symm
#align set.mem_image_iff_bex Set.mem_image_iff_bex
@[simp]
theorem mem_image (f : α → β) (s : Set α) (y : β) : y ∈ f '' s ↔ ∃ x ∈ s, f x = y :=
Iff.rfl
#align set.mem_image Set.mem_image
theorem image_eta (f : α → β) : f '' s = (fun x => f x) '' s :=
rfl
#align set.image_eta Set.image_eta
@[mfld_simps]
theorem mem_image_of_mem (f : α → β) {x : α} {a : Set α} (h : x ∈ a) : f x ∈ f '' a :=
⟨_, h, rfl⟩
#align set.mem_image_of_mem Set.mem_image_of_mem
theorem _root_.Function.Injective.mem_set_image {f : α → β} (hf : Injective f) {s : Set α} {a : α} :
f a ∈ f '' s ↔ a ∈ s :=
⟨fun ⟨_, hb, Eq⟩ => hf Eq ▸ hb, mem_image_of_mem f⟩
#align function.injective.mem_set_image Function.Injective.mem_set_image
theorem ball_image_iff {f : α → β} {s : Set α} {p : β → Prop} :
(∀ y ∈ f '' s, p y) ↔ ∀ x ∈ s, p (f x) := by simp
#align set.ball_image_iff Set.ball_image_iff
theorem ball_image_of_ball {f : α → β} {s : Set α} {p : β → Prop} (h : ∀ x ∈ s, p (f x)) :
∀ y ∈ f '' s, p y :=
ball_image_iff.2 h
#align set.ball_image_of_ball Set.ball_image_of_ball
theorem bex_image_iff {f : α → β} {s : Set α} {p : β → Prop} :
(∃ y ∈ f '' s, p y) ↔ ∃ x ∈ s, p (f x) := by simp
#align set.bex_image_iff Set.bex_image_iff
theorem mem_image_elim {f : α → β} {s : Set α} {C : β → Prop} (h : ∀ x : α, x ∈ s → C (f x)) :
∀ {y : β}, y ∈ f '' s → C y
| _, ⟨a, a_in, rfl⟩ => h a a_in
#align set.mem_image_elim Set.mem_image_elim
theorem mem_image_elim_on {f : α → β} {s : Set α} {C : β → Prop} {y : β} (h_y : y ∈ f '' s)
(h : ∀ x : α, x ∈ s → C (f x)) : C y :=
mem_image_elim h h_y
#align set.mem_image_elim_on Set.mem_image_elim_on
-- Porting note: used to be `safe`
@[congr]
theorem image_congr {f g : α → β} {s : Set α} (h : ∀ a ∈ s, f a = g a) : f '' s = g '' s := by
ext x
rw [mem_image, mem_image]
exact {
mp := by
rintro ⟨a, ha1, ha2⟩
exact ⟨a, ⟨ha1, (h a ha1) ▸ ha2⟩⟩,
mpr := by
rintro ⟨a, ha1, ha2⟩
exact ⟨a, ⟨ha1, (h a ha1) ▸ ha2⟩⟩
}
-- safe [ext_iff, iff_def]
#align set.image_congr Set.image_congr
/-- A common special case of `image_congr` -/
theorem image_congr' {f g : α → β} {s : Set α} (h : ∀ x : α, f x = g x) : f '' s = g '' s :=
image_congr fun x _ => h x
#align set.image_congr' Set.image_congr'
@[gcongr]
lemma image_mono (h : s ⊆ t) : f '' s ⊆ f '' t := by
rintro - ⟨a, ha, rfl⟩; exact mem_image_of_mem f (h ha)
theorem image_comp (f : β → γ) (g : α → β) (a : Set α) : f ∘ g '' a = f '' (g '' a) :=
Subset.antisymm (ball_image_of_ball fun _ ha => mem_image_of_mem _ <| mem_image_of_mem _ ha)
(ball_image_of_ball <| ball_image_of_ball fun _ ha => mem_image_of_mem _ ha)
#align set.image_comp Set.image_comp
theorem image_comp_eq {g : β → γ} : image (g ∘ f) = image g ∘ image f := by ext;
|
simp
|
theorem image_comp_eq {g : β → γ} : image (g ∘ f) = image g ∘ image f := by ext;
|
Mathlib.Data.Set.Image.302_0.IJFiTzmYGOCpPSd
|
theorem image_comp_eq {g : β → γ} : image (g ∘ f) = image g ∘ image f
|
Mathlib_Data_Set_Image
|
α : Type u_1
β : Type u_2
γ : Type u_3
ι : Sort u_4
ι' : Sort u_5
f✝ : α → β
s t : Set α
β' : Type u_6
f : β → γ
g : α → β
f' : α → β'
g' : β' → γ
h_comm : ∀ (a : α), f (g a) = g' (f' a)
⊢ f '' (g '' s) = g' '' (f' '' s)
|
/-
Copyright (c) 2014 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Leonardo de Moura
-/
import Mathlib.Data.Set.Basic
#align_import data.set.image from "leanprover-community/mathlib"@"001ffdc42920050657fd45bd2b8bfbec8eaaeb29"
/-!
# Images and preimages of sets
## Main definitions
* `preimage f t : Set α` : the preimage f⁻¹(t) (written `f ⁻¹' t` in Lean) of a subset of β.
* `range f : Set β` : the image of `univ` under `f`.
Also works for `{p : Prop} (f : p → α)` (unlike `image`)
## Notation
* `f ⁻¹' t` for `Set.preimage f t`
* `f '' s` for `Set.image f s`
## Tags
set, sets, image, preimage, pre-image, range
-/
set_option autoImplicit true
universe u v
open Function Set
namespace Set
variable {α β γ : Type*} {ι ι' : Sort*}
/-! ### Inverse image -/
/-- The preimage of `s : Set β` by `f : α → β`, written `f ⁻¹' s`,
is the set of `x : α` such that `f x ∈ s`. -/
def preimage {α : Type u} {β : Type v} (f : α → β) (s : Set β) : Set α :=
{ x | f x ∈ s }
#align set.preimage Set.preimage
/-- `f ⁻¹' t` denotes the preimage of `t : Set β` under the function `f : α → β`. -/
infixl:80 " ⁻¹' " => preimage
section Preimage
variable {f : α → β} {g : β → γ}
@[simp]
theorem preimage_empty : f ⁻¹' ∅ = ∅ :=
rfl
#align set.preimage_empty Set.preimage_empty
@[simp, mfld_simps]
theorem mem_preimage {s : Set β} {a : α} : a ∈ f ⁻¹' s ↔ f a ∈ s :=
Iff.rfl
#align set.mem_preimage Set.mem_preimage
theorem preimage_congr {f g : α → β} {s : Set β} (h : ∀ x : α, f x = g x) : f ⁻¹' s = g ⁻¹' s := by
congr with x
simp [h]
#align set.preimage_congr Set.preimage_congr
@[gcongr]
theorem preimage_mono {s t : Set β} (h : s ⊆ t) : f ⁻¹' s ⊆ f ⁻¹' t := fun _ hx => h hx
#align set.preimage_mono Set.preimage_mono
@[simp, mfld_simps]
theorem preimage_univ : f ⁻¹' univ = univ :=
rfl
#align set.preimage_univ Set.preimage_univ
theorem subset_preimage_univ {s : Set α} : s ⊆ f ⁻¹' univ :=
subset_univ _
#align set.subset_preimage_univ Set.subset_preimage_univ
@[simp, mfld_simps]
theorem preimage_inter {s t : Set β} : f ⁻¹' (s ∩ t) = f ⁻¹' s ∩ f ⁻¹' t :=
rfl
#align set.preimage_inter Set.preimage_inter
@[simp]
theorem preimage_union {s t : Set β} : f ⁻¹' (s ∪ t) = f ⁻¹' s ∪ f ⁻¹' t :=
rfl
#align set.preimage_union Set.preimage_union
@[simp]
theorem preimage_compl {s : Set β} : f ⁻¹' sᶜ = (f ⁻¹' s)ᶜ :=
rfl
#align set.preimage_compl Set.preimage_compl
@[simp]
theorem preimage_diff (f : α → β) (s t : Set β) : f ⁻¹' (s \ t) = f ⁻¹' s \ f ⁻¹' t :=
rfl
#align set.preimage_diff Set.preimage_diff
@[simp]
lemma preimage_symmDiff {f : α → β} (s t : Set β) : f ⁻¹' (s ∆ t) = (f ⁻¹' s) ∆ (f ⁻¹' t) :=
rfl
#align set.preimage_symm_diff Set.preimage_symmDiff
@[simp]
theorem preimage_ite (f : α → β) (s t₁ t₂ : Set β) :
f ⁻¹' s.ite t₁ t₂ = (f ⁻¹' s).ite (f ⁻¹' t₁) (f ⁻¹' t₂) :=
rfl
#align set.preimage_ite Set.preimage_ite
@[simp]
theorem preimage_setOf_eq {p : α → Prop} {f : β → α} : f ⁻¹' { a | p a } = { a | p (f a) } :=
rfl
#align set.preimage_set_of_eq Set.preimage_setOf_eq
@[simp]
theorem preimage_id_eq : preimage (id : α → α) = id :=
rfl
#align set.preimage_id_eq Set.preimage_id_eq
@[mfld_simps]
theorem preimage_id {s : Set α} : id ⁻¹' s = s :=
rfl
#align set.preimage_id Set.preimage_id
@[simp, mfld_simps]
theorem preimage_id' {s : Set α} : (fun x => x) ⁻¹' s = s :=
rfl
#align set.preimage_id' Set.preimage_id'
@[simp]
theorem preimage_const_of_mem {b : β} {s : Set β} (h : b ∈ s) : (fun _ : α => b) ⁻¹' s = univ :=
eq_univ_of_forall fun _ => h
#align set.preimage_const_of_mem Set.preimage_const_of_mem
@[simp]
theorem preimage_const_of_not_mem {b : β} {s : Set β} (h : b ∉ s) : (fun _ : α => b) ⁻¹' s = ∅ :=
eq_empty_of_subset_empty fun _ hx => h hx
#align set.preimage_const_of_not_mem Set.preimage_const_of_not_mem
theorem preimage_const (b : β) (s : Set β) [Decidable (b ∈ s)] :
(fun _ : α => b) ⁻¹' s = if b ∈ s then univ else ∅ := by
split_ifs with hb
exacts [preimage_const_of_mem hb, preimage_const_of_not_mem hb]
#align set.preimage_const Set.preimage_const
/-- If preimage of each singleton under `f : α → β` is either empty or the whole type,
then `f` is a constant. -/
lemma exists_eq_const_of_preimage_singleton [Nonempty β] {f : α → β}
(hf : ∀ b : β, f ⁻¹' {b} = ∅ ∨ f ⁻¹' {b} = univ) : ∃ b, f = const α b := by
rcases em (∃ b, f ⁻¹' {b} = univ) with ⟨b, hb⟩ | hf'
· exact ⟨b, funext fun x ↦ eq_univ_iff_forall.1 hb x⟩
· have : ∀ x b, f x ≠ b := fun x b ↦
eq_empty_iff_forall_not_mem.1 ((hf b).resolve_right fun h ↦ hf' ⟨b, h⟩) x
exact ⟨Classical.arbitrary β, funext fun x ↦ absurd rfl (this x _)⟩
theorem preimage_comp {s : Set γ} : g ∘ f ⁻¹' s = f ⁻¹' (g ⁻¹' s) :=
rfl
#align set.preimage_comp Set.preimage_comp
theorem preimage_comp_eq : preimage (g ∘ f) = preimage f ∘ preimage g :=
rfl
#align set.preimage_comp_eq Set.preimage_comp_eq
theorem preimage_iterate_eq {f : α → α} {n : ℕ} : Set.preimage f^[n] = (Set.preimage f)^[n] := by
induction' n with n ih; · simp
rw [iterate_succ, iterate_succ', preimage_comp_eq, ih]
#align set.preimage_iterate_eq Set.preimage_iterate_eq
theorem preimage_preimage {g : β → γ} {f : α → β} {s : Set γ} :
f ⁻¹' (g ⁻¹' s) = (fun x => g (f x)) ⁻¹' s :=
preimage_comp.symm
#align set.preimage_preimage Set.preimage_preimage
theorem eq_preimage_subtype_val_iff {p : α → Prop} {s : Set (Subtype p)} {t : Set α} :
s = Subtype.val ⁻¹' t ↔ ∀ (x) (h : p x), (⟨x, h⟩ : Subtype p) ∈ s ↔ x ∈ t :=
⟨fun s_eq x h => by
rw [s_eq]
simp, fun h => ext fun ⟨x, hx⟩ => by simp [h]⟩
#align set.eq_preimage_subtype_val_iff Set.eq_preimage_subtype_val_iff
theorem nonempty_of_nonempty_preimage {s : Set β} {f : α → β} (hf : (f ⁻¹' s).Nonempty) :
s.Nonempty :=
let ⟨x, hx⟩ := hf
⟨f x, hx⟩
#align set.nonempty_of_nonempty_preimage Set.nonempty_of_nonempty_preimage
@[simp] theorem preimage_singleton_true (p : α → Prop) : p ⁻¹' {True} = {a | p a} := by ext; simp
#align set.preimage_singleton_true Set.preimage_singleton_true
@[simp] theorem preimage_singleton_false (p : α → Prop) : p ⁻¹' {False} = {a | ¬p a} := by ext; simp
#align set.preimage_singleton_false Set.preimage_singleton_false
theorem preimage_subtype_coe_eq_compl {s u v : Set α} (hsuv : s ⊆ u ∪ v)
(H : s ∩ (u ∩ v) = ∅) : ((↑) : s → α) ⁻¹' u = ((↑) ⁻¹' v)ᶜ := by
ext ⟨x, x_in_s⟩
constructor
· intro x_in_u x_in_v
exact eq_empty_iff_forall_not_mem.mp H x ⟨x_in_s, ⟨x_in_u, x_in_v⟩⟩
· intro hx
exact Or.elim (hsuv x_in_s) id fun hx' => hx.elim hx'
#align set.preimage_subtype_coe_eq_compl Set.preimage_subtype_coe_eq_compl
end Preimage
/-! ### Image of a set under a function -/
section Image
variable {f : α → β} {s t : Set α}
-- Porting note: `Set.image` is already defined in `Init.Set`
#align set.image Set.image
/-- `f '' s` denotes the image of `s : Set α` under the function `f : α → β`. -/
infixl:80 " '' " => image
theorem mem_image_iff_bex {f : α → β} {s : Set α} {y : β} :
y ∈ f '' s ↔ ∃ (x : _) (_ : x ∈ s), f x = y :=
bex_def.symm
#align set.mem_image_iff_bex Set.mem_image_iff_bex
@[simp]
theorem mem_image (f : α → β) (s : Set α) (y : β) : y ∈ f '' s ↔ ∃ x ∈ s, f x = y :=
Iff.rfl
#align set.mem_image Set.mem_image
theorem image_eta (f : α → β) : f '' s = (fun x => f x) '' s :=
rfl
#align set.image_eta Set.image_eta
@[mfld_simps]
theorem mem_image_of_mem (f : α → β) {x : α} {a : Set α} (h : x ∈ a) : f x ∈ f '' a :=
⟨_, h, rfl⟩
#align set.mem_image_of_mem Set.mem_image_of_mem
theorem _root_.Function.Injective.mem_set_image {f : α → β} (hf : Injective f) {s : Set α} {a : α} :
f a ∈ f '' s ↔ a ∈ s :=
⟨fun ⟨_, hb, Eq⟩ => hf Eq ▸ hb, mem_image_of_mem f⟩
#align function.injective.mem_set_image Function.Injective.mem_set_image
theorem ball_image_iff {f : α → β} {s : Set α} {p : β → Prop} :
(∀ y ∈ f '' s, p y) ↔ ∀ x ∈ s, p (f x) := by simp
#align set.ball_image_iff Set.ball_image_iff
theorem ball_image_of_ball {f : α → β} {s : Set α} {p : β → Prop} (h : ∀ x ∈ s, p (f x)) :
∀ y ∈ f '' s, p y :=
ball_image_iff.2 h
#align set.ball_image_of_ball Set.ball_image_of_ball
theorem bex_image_iff {f : α → β} {s : Set α} {p : β → Prop} :
(∃ y ∈ f '' s, p y) ↔ ∃ x ∈ s, p (f x) := by simp
#align set.bex_image_iff Set.bex_image_iff
theorem mem_image_elim {f : α → β} {s : Set α} {C : β → Prop} (h : ∀ x : α, x ∈ s → C (f x)) :
∀ {y : β}, y ∈ f '' s → C y
| _, ⟨a, a_in, rfl⟩ => h a a_in
#align set.mem_image_elim Set.mem_image_elim
theorem mem_image_elim_on {f : α → β} {s : Set α} {C : β → Prop} {y : β} (h_y : y ∈ f '' s)
(h : ∀ x : α, x ∈ s → C (f x)) : C y :=
mem_image_elim h h_y
#align set.mem_image_elim_on Set.mem_image_elim_on
-- Porting note: used to be `safe`
@[congr]
theorem image_congr {f g : α → β} {s : Set α} (h : ∀ a ∈ s, f a = g a) : f '' s = g '' s := by
ext x
rw [mem_image, mem_image]
exact {
mp := by
rintro ⟨a, ha1, ha2⟩
exact ⟨a, ⟨ha1, (h a ha1) ▸ ha2⟩⟩,
mpr := by
rintro ⟨a, ha1, ha2⟩
exact ⟨a, ⟨ha1, (h a ha1) ▸ ha2⟩⟩
}
-- safe [ext_iff, iff_def]
#align set.image_congr Set.image_congr
/-- A common special case of `image_congr` -/
theorem image_congr' {f g : α → β} {s : Set α} (h : ∀ x : α, f x = g x) : f '' s = g '' s :=
image_congr fun x _ => h x
#align set.image_congr' Set.image_congr'
@[gcongr]
lemma image_mono (h : s ⊆ t) : f '' s ⊆ f '' t := by
rintro - ⟨a, ha, rfl⟩; exact mem_image_of_mem f (h ha)
theorem image_comp (f : β → γ) (g : α → β) (a : Set α) : f ∘ g '' a = f '' (g '' a) :=
Subset.antisymm (ball_image_of_ball fun _ ha => mem_image_of_mem _ <| mem_image_of_mem _ ha)
(ball_image_of_ball <| ball_image_of_ball fun _ ha => mem_image_of_mem _ ha)
#align set.image_comp Set.image_comp
theorem image_comp_eq {g : β → γ} : image (g ∘ f) = image g ∘ image f := by ext; simp
/-- A variant of `image_comp`, useful for rewriting -/
theorem image_image (g : β → γ) (f : α → β) (s : Set α) : g '' (f '' s) = (fun x => g (f x)) '' s :=
(image_comp g f s).symm
#align set.image_image Set.image_image
theorem image_comm {β'} {f : β → γ} {g : α → β} {f' : α → β'} {g' : β' → γ}
(h_comm : ∀ a, f (g a) = g' (f' a)) : (s.image g).image f = (s.image f').image g' := by
|
simp_rw [image_image, h_comm]
|
theorem image_comm {β'} {f : β → γ} {g : α → β} {f' : α → β'} {g' : β' → γ}
(h_comm : ∀ a, f (g a) = g' (f' a)) : (s.image g).image f = (s.image f').image g' := by
|
Mathlib.Data.Set.Image.309_0.IJFiTzmYGOCpPSd
|
theorem image_comm {β'} {f : β → γ} {g : α → β} {f' : α → β'} {g' : β' → γ}
(h_comm : ∀ a, f (g a) = g' (f' a)) : (s.image g).image f = (s.image f').image g'
|
Mathlib_Data_Set_Image
|
α : Type u_1
β : Type u_2
γ : Type u_3
ι : Sort u_4
ι' : Sort u_5
f✝ : α → β
s t a b : Set α
f : α → β
h : a ⊆ b
⊢ f '' a ⊆ f '' b
|
/-
Copyright (c) 2014 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Leonardo de Moura
-/
import Mathlib.Data.Set.Basic
#align_import data.set.image from "leanprover-community/mathlib"@"001ffdc42920050657fd45bd2b8bfbec8eaaeb29"
/-!
# Images and preimages of sets
## Main definitions
* `preimage f t : Set α` : the preimage f⁻¹(t) (written `f ⁻¹' t` in Lean) of a subset of β.
* `range f : Set β` : the image of `univ` under `f`.
Also works for `{p : Prop} (f : p → α)` (unlike `image`)
## Notation
* `f ⁻¹' t` for `Set.preimage f t`
* `f '' s` for `Set.image f s`
## Tags
set, sets, image, preimage, pre-image, range
-/
set_option autoImplicit true
universe u v
open Function Set
namespace Set
variable {α β γ : Type*} {ι ι' : Sort*}
/-! ### Inverse image -/
/-- The preimage of `s : Set β` by `f : α → β`, written `f ⁻¹' s`,
is the set of `x : α` such that `f x ∈ s`. -/
def preimage {α : Type u} {β : Type v} (f : α → β) (s : Set β) : Set α :=
{ x | f x ∈ s }
#align set.preimage Set.preimage
/-- `f ⁻¹' t` denotes the preimage of `t : Set β` under the function `f : α → β`. -/
infixl:80 " ⁻¹' " => preimage
section Preimage
variable {f : α → β} {g : β → γ}
@[simp]
theorem preimage_empty : f ⁻¹' ∅ = ∅ :=
rfl
#align set.preimage_empty Set.preimage_empty
@[simp, mfld_simps]
theorem mem_preimage {s : Set β} {a : α} : a ∈ f ⁻¹' s ↔ f a ∈ s :=
Iff.rfl
#align set.mem_preimage Set.mem_preimage
theorem preimage_congr {f g : α → β} {s : Set β} (h : ∀ x : α, f x = g x) : f ⁻¹' s = g ⁻¹' s := by
congr with x
simp [h]
#align set.preimage_congr Set.preimage_congr
@[gcongr]
theorem preimage_mono {s t : Set β} (h : s ⊆ t) : f ⁻¹' s ⊆ f ⁻¹' t := fun _ hx => h hx
#align set.preimage_mono Set.preimage_mono
@[simp, mfld_simps]
theorem preimage_univ : f ⁻¹' univ = univ :=
rfl
#align set.preimage_univ Set.preimage_univ
theorem subset_preimage_univ {s : Set α} : s ⊆ f ⁻¹' univ :=
subset_univ _
#align set.subset_preimage_univ Set.subset_preimage_univ
@[simp, mfld_simps]
theorem preimage_inter {s t : Set β} : f ⁻¹' (s ∩ t) = f ⁻¹' s ∩ f ⁻¹' t :=
rfl
#align set.preimage_inter Set.preimage_inter
@[simp]
theorem preimage_union {s t : Set β} : f ⁻¹' (s ∪ t) = f ⁻¹' s ∪ f ⁻¹' t :=
rfl
#align set.preimage_union Set.preimage_union
@[simp]
theorem preimage_compl {s : Set β} : f ⁻¹' sᶜ = (f ⁻¹' s)ᶜ :=
rfl
#align set.preimage_compl Set.preimage_compl
@[simp]
theorem preimage_diff (f : α → β) (s t : Set β) : f ⁻¹' (s \ t) = f ⁻¹' s \ f ⁻¹' t :=
rfl
#align set.preimage_diff Set.preimage_diff
@[simp]
lemma preimage_symmDiff {f : α → β} (s t : Set β) : f ⁻¹' (s ∆ t) = (f ⁻¹' s) ∆ (f ⁻¹' t) :=
rfl
#align set.preimage_symm_diff Set.preimage_symmDiff
@[simp]
theorem preimage_ite (f : α → β) (s t₁ t₂ : Set β) :
f ⁻¹' s.ite t₁ t₂ = (f ⁻¹' s).ite (f ⁻¹' t₁) (f ⁻¹' t₂) :=
rfl
#align set.preimage_ite Set.preimage_ite
@[simp]
theorem preimage_setOf_eq {p : α → Prop} {f : β → α} : f ⁻¹' { a | p a } = { a | p (f a) } :=
rfl
#align set.preimage_set_of_eq Set.preimage_setOf_eq
@[simp]
theorem preimage_id_eq : preimage (id : α → α) = id :=
rfl
#align set.preimage_id_eq Set.preimage_id_eq
@[mfld_simps]
theorem preimage_id {s : Set α} : id ⁻¹' s = s :=
rfl
#align set.preimage_id Set.preimage_id
@[simp, mfld_simps]
theorem preimage_id' {s : Set α} : (fun x => x) ⁻¹' s = s :=
rfl
#align set.preimage_id' Set.preimage_id'
@[simp]
theorem preimage_const_of_mem {b : β} {s : Set β} (h : b ∈ s) : (fun _ : α => b) ⁻¹' s = univ :=
eq_univ_of_forall fun _ => h
#align set.preimage_const_of_mem Set.preimage_const_of_mem
@[simp]
theorem preimage_const_of_not_mem {b : β} {s : Set β} (h : b ∉ s) : (fun _ : α => b) ⁻¹' s = ∅ :=
eq_empty_of_subset_empty fun _ hx => h hx
#align set.preimage_const_of_not_mem Set.preimage_const_of_not_mem
theorem preimage_const (b : β) (s : Set β) [Decidable (b ∈ s)] :
(fun _ : α => b) ⁻¹' s = if b ∈ s then univ else ∅ := by
split_ifs with hb
exacts [preimage_const_of_mem hb, preimage_const_of_not_mem hb]
#align set.preimage_const Set.preimage_const
/-- If preimage of each singleton under `f : α → β` is either empty or the whole type,
then `f` is a constant. -/
lemma exists_eq_const_of_preimage_singleton [Nonempty β] {f : α → β}
(hf : ∀ b : β, f ⁻¹' {b} = ∅ ∨ f ⁻¹' {b} = univ) : ∃ b, f = const α b := by
rcases em (∃ b, f ⁻¹' {b} = univ) with ⟨b, hb⟩ | hf'
· exact ⟨b, funext fun x ↦ eq_univ_iff_forall.1 hb x⟩
· have : ∀ x b, f x ≠ b := fun x b ↦
eq_empty_iff_forall_not_mem.1 ((hf b).resolve_right fun h ↦ hf' ⟨b, h⟩) x
exact ⟨Classical.arbitrary β, funext fun x ↦ absurd rfl (this x _)⟩
theorem preimage_comp {s : Set γ} : g ∘ f ⁻¹' s = f ⁻¹' (g ⁻¹' s) :=
rfl
#align set.preimage_comp Set.preimage_comp
theorem preimage_comp_eq : preimage (g ∘ f) = preimage f ∘ preimage g :=
rfl
#align set.preimage_comp_eq Set.preimage_comp_eq
theorem preimage_iterate_eq {f : α → α} {n : ℕ} : Set.preimage f^[n] = (Set.preimage f)^[n] := by
induction' n with n ih; · simp
rw [iterate_succ, iterate_succ', preimage_comp_eq, ih]
#align set.preimage_iterate_eq Set.preimage_iterate_eq
theorem preimage_preimage {g : β → γ} {f : α → β} {s : Set γ} :
f ⁻¹' (g ⁻¹' s) = (fun x => g (f x)) ⁻¹' s :=
preimage_comp.symm
#align set.preimage_preimage Set.preimage_preimage
theorem eq_preimage_subtype_val_iff {p : α → Prop} {s : Set (Subtype p)} {t : Set α} :
s = Subtype.val ⁻¹' t ↔ ∀ (x) (h : p x), (⟨x, h⟩ : Subtype p) ∈ s ↔ x ∈ t :=
⟨fun s_eq x h => by
rw [s_eq]
simp, fun h => ext fun ⟨x, hx⟩ => by simp [h]⟩
#align set.eq_preimage_subtype_val_iff Set.eq_preimage_subtype_val_iff
theorem nonempty_of_nonempty_preimage {s : Set β} {f : α → β} (hf : (f ⁻¹' s).Nonempty) :
s.Nonempty :=
let ⟨x, hx⟩ := hf
⟨f x, hx⟩
#align set.nonempty_of_nonempty_preimage Set.nonempty_of_nonempty_preimage
@[simp] theorem preimage_singleton_true (p : α → Prop) : p ⁻¹' {True} = {a | p a} := by ext; simp
#align set.preimage_singleton_true Set.preimage_singleton_true
@[simp] theorem preimage_singleton_false (p : α → Prop) : p ⁻¹' {False} = {a | ¬p a} := by ext; simp
#align set.preimage_singleton_false Set.preimage_singleton_false
theorem preimage_subtype_coe_eq_compl {s u v : Set α} (hsuv : s ⊆ u ∪ v)
(H : s ∩ (u ∩ v) = ∅) : ((↑) : s → α) ⁻¹' u = ((↑) ⁻¹' v)ᶜ := by
ext ⟨x, x_in_s⟩
constructor
· intro x_in_u x_in_v
exact eq_empty_iff_forall_not_mem.mp H x ⟨x_in_s, ⟨x_in_u, x_in_v⟩⟩
· intro hx
exact Or.elim (hsuv x_in_s) id fun hx' => hx.elim hx'
#align set.preimage_subtype_coe_eq_compl Set.preimage_subtype_coe_eq_compl
end Preimage
/-! ### Image of a set under a function -/
section Image
variable {f : α → β} {s t : Set α}
-- Porting note: `Set.image` is already defined in `Init.Set`
#align set.image Set.image
/-- `f '' s` denotes the image of `s : Set α` under the function `f : α → β`. -/
infixl:80 " '' " => image
theorem mem_image_iff_bex {f : α → β} {s : Set α} {y : β} :
y ∈ f '' s ↔ ∃ (x : _) (_ : x ∈ s), f x = y :=
bex_def.symm
#align set.mem_image_iff_bex Set.mem_image_iff_bex
@[simp]
theorem mem_image (f : α → β) (s : Set α) (y : β) : y ∈ f '' s ↔ ∃ x ∈ s, f x = y :=
Iff.rfl
#align set.mem_image Set.mem_image
theorem image_eta (f : α → β) : f '' s = (fun x => f x) '' s :=
rfl
#align set.image_eta Set.image_eta
@[mfld_simps]
theorem mem_image_of_mem (f : α → β) {x : α} {a : Set α} (h : x ∈ a) : f x ∈ f '' a :=
⟨_, h, rfl⟩
#align set.mem_image_of_mem Set.mem_image_of_mem
theorem _root_.Function.Injective.mem_set_image {f : α → β} (hf : Injective f) {s : Set α} {a : α} :
f a ∈ f '' s ↔ a ∈ s :=
⟨fun ⟨_, hb, Eq⟩ => hf Eq ▸ hb, mem_image_of_mem f⟩
#align function.injective.mem_set_image Function.Injective.mem_set_image
theorem ball_image_iff {f : α → β} {s : Set α} {p : β → Prop} :
(∀ y ∈ f '' s, p y) ↔ ∀ x ∈ s, p (f x) := by simp
#align set.ball_image_iff Set.ball_image_iff
theorem ball_image_of_ball {f : α → β} {s : Set α} {p : β → Prop} (h : ∀ x ∈ s, p (f x)) :
∀ y ∈ f '' s, p y :=
ball_image_iff.2 h
#align set.ball_image_of_ball Set.ball_image_of_ball
theorem bex_image_iff {f : α → β} {s : Set α} {p : β → Prop} :
(∃ y ∈ f '' s, p y) ↔ ∃ x ∈ s, p (f x) := by simp
#align set.bex_image_iff Set.bex_image_iff
theorem mem_image_elim {f : α → β} {s : Set α} {C : β → Prop} (h : ∀ x : α, x ∈ s → C (f x)) :
∀ {y : β}, y ∈ f '' s → C y
| _, ⟨a, a_in, rfl⟩ => h a a_in
#align set.mem_image_elim Set.mem_image_elim
theorem mem_image_elim_on {f : α → β} {s : Set α} {C : β → Prop} {y : β} (h_y : y ∈ f '' s)
(h : ∀ x : α, x ∈ s → C (f x)) : C y :=
mem_image_elim h h_y
#align set.mem_image_elim_on Set.mem_image_elim_on
-- Porting note: used to be `safe`
@[congr]
theorem image_congr {f g : α → β} {s : Set α} (h : ∀ a ∈ s, f a = g a) : f '' s = g '' s := by
ext x
rw [mem_image, mem_image]
exact {
mp := by
rintro ⟨a, ha1, ha2⟩
exact ⟨a, ⟨ha1, (h a ha1) ▸ ha2⟩⟩,
mpr := by
rintro ⟨a, ha1, ha2⟩
exact ⟨a, ⟨ha1, (h a ha1) ▸ ha2⟩⟩
}
-- safe [ext_iff, iff_def]
#align set.image_congr Set.image_congr
/-- A common special case of `image_congr` -/
theorem image_congr' {f g : α → β} {s : Set α} (h : ∀ x : α, f x = g x) : f '' s = g '' s :=
image_congr fun x _ => h x
#align set.image_congr' Set.image_congr'
@[gcongr]
lemma image_mono (h : s ⊆ t) : f '' s ⊆ f '' t := by
rintro - ⟨a, ha, rfl⟩; exact mem_image_of_mem f (h ha)
theorem image_comp (f : β → γ) (g : α → β) (a : Set α) : f ∘ g '' a = f '' (g '' a) :=
Subset.antisymm (ball_image_of_ball fun _ ha => mem_image_of_mem _ <| mem_image_of_mem _ ha)
(ball_image_of_ball <| ball_image_of_ball fun _ ha => mem_image_of_mem _ ha)
#align set.image_comp Set.image_comp
theorem image_comp_eq {g : β → γ} : image (g ∘ f) = image g ∘ image f := by ext; simp
/-- A variant of `image_comp`, useful for rewriting -/
theorem image_image (g : β → γ) (f : α → β) (s : Set α) : g '' (f '' s) = (fun x => g (f x)) '' s :=
(image_comp g f s).symm
#align set.image_image Set.image_image
theorem image_comm {β'} {f : β → γ} {g : α → β} {f' : α → β'} {g' : β' → γ}
(h_comm : ∀ a, f (g a) = g' (f' a)) : (s.image g).image f = (s.image f').image g' := by
simp_rw [image_image, h_comm]
#align set.image_comm Set.image_comm
theorem _root_.Function.Semiconj.set_image {f : α → β} {ga : α → α} {gb : β → β}
(h : Function.Semiconj f ga gb) : Function.Semiconj (image f) (image ga) (image gb) := fun _ =>
image_comm h
#align function.semiconj.set_image Function.Semiconj.set_image
theorem _root_.Function.Commute.set_image {f g : α → α} (h : Function.Commute f g) :
Function.Commute (image f) (image g) :=
Function.Semiconj.set_image h
#align function.commute.set_image Function.Commute.set_image
/-- Image is monotone with respect to `⊆`. See `Set.monotone_image` for the statement in
terms of `≤`. -/
@[gcongr]
theorem image_subset {a b : Set α} (f : α → β) (h : a ⊆ b) : f '' a ⊆ f '' b := by
|
simp only [subset_def, mem_image]
|
/-- Image is monotone with respect to `⊆`. See `Set.monotone_image` for the statement in
terms of `≤`. -/
@[gcongr]
theorem image_subset {a b : Set α} (f : α → β) (h : a ⊆ b) : f '' a ⊆ f '' b := by
|
Mathlib.Data.Set.Image.324_0.IJFiTzmYGOCpPSd
|
/-- Image is monotone with respect to `⊆`. See `Set.monotone_image` for the statement in
terms of `≤`. -/
@[gcongr]
theorem image_subset {a b : Set α} (f : α → β) (h : a ⊆ b) : f '' a ⊆ f '' b
|
Mathlib_Data_Set_Image
|
α : Type u_1
β : Type u_2
γ : Type u_3
ι : Sort u_4
ι' : Sort u_5
f✝ : α → β
s t a b : Set α
f : α → β
h : a ⊆ b
⊢ ∀ (x : β), (∃ x_1 ∈ a, f x_1 = x) → ∃ x_1 ∈ b, f x_1 = x
|
/-
Copyright (c) 2014 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Leonardo de Moura
-/
import Mathlib.Data.Set.Basic
#align_import data.set.image from "leanprover-community/mathlib"@"001ffdc42920050657fd45bd2b8bfbec8eaaeb29"
/-!
# Images and preimages of sets
## Main definitions
* `preimage f t : Set α` : the preimage f⁻¹(t) (written `f ⁻¹' t` in Lean) of a subset of β.
* `range f : Set β` : the image of `univ` under `f`.
Also works for `{p : Prop} (f : p → α)` (unlike `image`)
## Notation
* `f ⁻¹' t` for `Set.preimage f t`
* `f '' s` for `Set.image f s`
## Tags
set, sets, image, preimage, pre-image, range
-/
set_option autoImplicit true
universe u v
open Function Set
namespace Set
variable {α β γ : Type*} {ι ι' : Sort*}
/-! ### Inverse image -/
/-- The preimage of `s : Set β` by `f : α → β`, written `f ⁻¹' s`,
is the set of `x : α` such that `f x ∈ s`. -/
def preimage {α : Type u} {β : Type v} (f : α → β) (s : Set β) : Set α :=
{ x | f x ∈ s }
#align set.preimage Set.preimage
/-- `f ⁻¹' t` denotes the preimage of `t : Set β` under the function `f : α → β`. -/
infixl:80 " ⁻¹' " => preimage
section Preimage
variable {f : α → β} {g : β → γ}
@[simp]
theorem preimage_empty : f ⁻¹' ∅ = ∅ :=
rfl
#align set.preimage_empty Set.preimage_empty
@[simp, mfld_simps]
theorem mem_preimage {s : Set β} {a : α} : a ∈ f ⁻¹' s ↔ f a ∈ s :=
Iff.rfl
#align set.mem_preimage Set.mem_preimage
theorem preimage_congr {f g : α → β} {s : Set β} (h : ∀ x : α, f x = g x) : f ⁻¹' s = g ⁻¹' s := by
congr with x
simp [h]
#align set.preimage_congr Set.preimage_congr
@[gcongr]
theorem preimage_mono {s t : Set β} (h : s ⊆ t) : f ⁻¹' s ⊆ f ⁻¹' t := fun _ hx => h hx
#align set.preimage_mono Set.preimage_mono
@[simp, mfld_simps]
theorem preimage_univ : f ⁻¹' univ = univ :=
rfl
#align set.preimage_univ Set.preimage_univ
theorem subset_preimage_univ {s : Set α} : s ⊆ f ⁻¹' univ :=
subset_univ _
#align set.subset_preimage_univ Set.subset_preimage_univ
@[simp, mfld_simps]
theorem preimage_inter {s t : Set β} : f ⁻¹' (s ∩ t) = f ⁻¹' s ∩ f ⁻¹' t :=
rfl
#align set.preimage_inter Set.preimage_inter
@[simp]
theorem preimage_union {s t : Set β} : f ⁻¹' (s ∪ t) = f ⁻¹' s ∪ f ⁻¹' t :=
rfl
#align set.preimage_union Set.preimage_union
@[simp]
theorem preimage_compl {s : Set β} : f ⁻¹' sᶜ = (f ⁻¹' s)ᶜ :=
rfl
#align set.preimage_compl Set.preimage_compl
@[simp]
theorem preimage_diff (f : α → β) (s t : Set β) : f ⁻¹' (s \ t) = f ⁻¹' s \ f ⁻¹' t :=
rfl
#align set.preimage_diff Set.preimage_diff
@[simp]
lemma preimage_symmDiff {f : α → β} (s t : Set β) : f ⁻¹' (s ∆ t) = (f ⁻¹' s) ∆ (f ⁻¹' t) :=
rfl
#align set.preimage_symm_diff Set.preimage_symmDiff
@[simp]
theorem preimage_ite (f : α → β) (s t₁ t₂ : Set β) :
f ⁻¹' s.ite t₁ t₂ = (f ⁻¹' s).ite (f ⁻¹' t₁) (f ⁻¹' t₂) :=
rfl
#align set.preimage_ite Set.preimage_ite
@[simp]
theorem preimage_setOf_eq {p : α → Prop} {f : β → α} : f ⁻¹' { a | p a } = { a | p (f a) } :=
rfl
#align set.preimage_set_of_eq Set.preimage_setOf_eq
@[simp]
theorem preimage_id_eq : preimage (id : α → α) = id :=
rfl
#align set.preimage_id_eq Set.preimage_id_eq
@[mfld_simps]
theorem preimage_id {s : Set α} : id ⁻¹' s = s :=
rfl
#align set.preimage_id Set.preimage_id
@[simp, mfld_simps]
theorem preimage_id' {s : Set α} : (fun x => x) ⁻¹' s = s :=
rfl
#align set.preimage_id' Set.preimage_id'
@[simp]
theorem preimage_const_of_mem {b : β} {s : Set β} (h : b ∈ s) : (fun _ : α => b) ⁻¹' s = univ :=
eq_univ_of_forall fun _ => h
#align set.preimage_const_of_mem Set.preimage_const_of_mem
@[simp]
theorem preimage_const_of_not_mem {b : β} {s : Set β} (h : b ∉ s) : (fun _ : α => b) ⁻¹' s = ∅ :=
eq_empty_of_subset_empty fun _ hx => h hx
#align set.preimage_const_of_not_mem Set.preimage_const_of_not_mem
theorem preimage_const (b : β) (s : Set β) [Decidable (b ∈ s)] :
(fun _ : α => b) ⁻¹' s = if b ∈ s then univ else ∅ := by
split_ifs with hb
exacts [preimage_const_of_mem hb, preimage_const_of_not_mem hb]
#align set.preimage_const Set.preimage_const
/-- If preimage of each singleton under `f : α → β` is either empty or the whole type,
then `f` is a constant. -/
lemma exists_eq_const_of_preimage_singleton [Nonempty β] {f : α → β}
(hf : ∀ b : β, f ⁻¹' {b} = ∅ ∨ f ⁻¹' {b} = univ) : ∃ b, f = const α b := by
rcases em (∃ b, f ⁻¹' {b} = univ) with ⟨b, hb⟩ | hf'
· exact ⟨b, funext fun x ↦ eq_univ_iff_forall.1 hb x⟩
· have : ∀ x b, f x ≠ b := fun x b ↦
eq_empty_iff_forall_not_mem.1 ((hf b).resolve_right fun h ↦ hf' ⟨b, h⟩) x
exact ⟨Classical.arbitrary β, funext fun x ↦ absurd rfl (this x _)⟩
theorem preimage_comp {s : Set γ} : g ∘ f ⁻¹' s = f ⁻¹' (g ⁻¹' s) :=
rfl
#align set.preimage_comp Set.preimage_comp
theorem preimage_comp_eq : preimage (g ∘ f) = preimage f ∘ preimage g :=
rfl
#align set.preimage_comp_eq Set.preimage_comp_eq
theorem preimage_iterate_eq {f : α → α} {n : ℕ} : Set.preimage f^[n] = (Set.preimage f)^[n] := by
induction' n with n ih; · simp
rw [iterate_succ, iterate_succ', preimage_comp_eq, ih]
#align set.preimage_iterate_eq Set.preimage_iterate_eq
theorem preimage_preimage {g : β → γ} {f : α → β} {s : Set γ} :
f ⁻¹' (g ⁻¹' s) = (fun x => g (f x)) ⁻¹' s :=
preimage_comp.symm
#align set.preimage_preimage Set.preimage_preimage
theorem eq_preimage_subtype_val_iff {p : α → Prop} {s : Set (Subtype p)} {t : Set α} :
s = Subtype.val ⁻¹' t ↔ ∀ (x) (h : p x), (⟨x, h⟩ : Subtype p) ∈ s ↔ x ∈ t :=
⟨fun s_eq x h => by
rw [s_eq]
simp, fun h => ext fun ⟨x, hx⟩ => by simp [h]⟩
#align set.eq_preimage_subtype_val_iff Set.eq_preimage_subtype_val_iff
theorem nonempty_of_nonempty_preimage {s : Set β} {f : α → β} (hf : (f ⁻¹' s).Nonempty) :
s.Nonempty :=
let ⟨x, hx⟩ := hf
⟨f x, hx⟩
#align set.nonempty_of_nonempty_preimage Set.nonempty_of_nonempty_preimage
@[simp] theorem preimage_singleton_true (p : α → Prop) : p ⁻¹' {True} = {a | p a} := by ext; simp
#align set.preimage_singleton_true Set.preimage_singleton_true
@[simp] theorem preimage_singleton_false (p : α → Prop) : p ⁻¹' {False} = {a | ¬p a} := by ext; simp
#align set.preimage_singleton_false Set.preimage_singleton_false
theorem preimage_subtype_coe_eq_compl {s u v : Set α} (hsuv : s ⊆ u ∪ v)
(H : s ∩ (u ∩ v) = ∅) : ((↑) : s → α) ⁻¹' u = ((↑) ⁻¹' v)ᶜ := by
ext ⟨x, x_in_s⟩
constructor
· intro x_in_u x_in_v
exact eq_empty_iff_forall_not_mem.mp H x ⟨x_in_s, ⟨x_in_u, x_in_v⟩⟩
· intro hx
exact Or.elim (hsuv x_in_s) id fun hx' => hx.elim hx'
#align set.preimage_subtype_coe_eq_compl Set.preimage_subtype_coe_eq_compl
end Preimage
/-! ### Image of a set under a function -/
section Image
variable {f : α → β} {s t : Set α}
-- Porting note: `Set.image` is already defined in `Init.Set`
#align set.image Set.image
/-- `f '' s` denotes the image of `s : Set α` under the function `f : α → β`. -/
infixl:80 " '' " => image
theorem mem_image_iff_bex {f : α → β} {s : Set α} {y : β} :
y ∈ f '' s ↔ ∃ (x : _) (_ : x ∈ s), f x = y :=
bex_def.symm
#align set.mem_image_iff_bex Set.mem_image_iff_bex
@[simp]
theorem mem_image (f : α → β) (s : Set α) (y : β) : y ∈ f '' s ↔ ∃ x ∈ s, f x = y :=
Iff.rfl
#align set.mem_image Set.mem_image
theorem image_eta (f : α → β) : f '' s = (fun x => f x) '' s :=
rfl
#align set.image_eta Set.image_eta
@[mfld_simps]
theorem mem_image_of_mem (f : α → β) {x : α} {a : Set α} (h : x ∈ a) : f x ∈ f '' a :=
⟨_, h, rfl⟩
#align set.mem_image_of_mem Set.mem_image_of_mem
theorem _root_.Function.Injective.mem_set_image {f : α → β} (hf : Injective f) {s : Set α} {a : α} :
f a ∈ f '' s ↔ a ∈ s :=
⟨fun ⟨_, hb, Eq⟩ => hf Eq ▸ hb, mem_image_of_mem f⟩
#align function.injective.mem_set_image Function.Injective.mem_set_image
theorem ball_image_iff {f : α → β} {s : Set α} {p : β → Prop} :
(∀ y ∈ f '' s, p y) ↔ ∀ x ∈ s, p (f x) := by simp
#align set.ball_image_iff Set.ball_image_iff
theorem ball_image_of_ball {f : α → β} {s : Set α} {p : β → Prop} (h : ∀ x ∈ s, p (f x)) :
∀ y ∈ f '' s, p y :=
ball_image_iff.2 h
#align set.ball_image_of_ball Set.ball_image_of_ball
theorem bex_image_iff {f : α → β} {s : Set α} {p : β → Prop} :
(∃ y ∈ f '' s, p y) ↔ ∃ x ∈ s, p (f x) := by simp
#align set.bex_image_iff Set.bex_image_iff
theorem mem_image_elim {f : α → β} {s : Set α} {C : β → Prop} (h : ∀ x : α, x ∈ s → C (f x)) :
∀ {y : β}, y ∈ f '' s → C y
| _, ⟨a, a_in, rfl⟩ => h a a_in
#align set.mem_image_elim Set.mem_image_elim
theorem mem_image_elim_on {f : α → β} {s : Set α} {C : β → Prop} {y : β} (h_y : y ∈ f '' s)
(h : ∀ x : α, x ∈ s → C (f x)) : C y :=
mem_image_elim h h_y
#align set.mem_image_elim_on Set.mem_image_elim_on
-- Porting note: used to be `safe`
@[congr]
theorem image_congr {f g : α → β} {s : Set α} (h : ∀ a ∈ s, f a = g a) : f '' s = g '' s := by
ext x
rw [mem_image, mem_image]
exact {
mp := by
rintro ⟨a, ha1, ha2⟩
exact ⟨a, ⟨ha1, (h a ha1) ▸ ha2⟩⟩,
mpr := by
rintro ⟨a, ha1, ha2⟩
exact ⟨a, ⟨ha1, (h a ha1) ▸ ha2⟩⟩
}
-- safe [ext_iff, iff_def]
#align set.image_congr Set.image_congr
/-- A common special case of `image_congr` -/
theorem image_congr' {f g : α → β} {s : Set α} (h : ∀ x : α, f x = g x) : f '' s = g '' s :=
image_congr fun x _ => h x
#align set.image_congr' Set.image_congr'
@[gcongr]
lemma image_mono (h : s ⊆ t) : f '' s ⊆ f '' t := by
rintro - ⟨a, ha, rfl⟩; exact mem_image_of_mem f (h ha)
theorem image_comp (f : β → γ) (g : α → β) (a : Set α) : f ∘ g '' a = f '' (g '' a) :=
Subset.antisymm (ball_image_of_ball fun _ ha => mem_image_of_mem _ <| mem_image_of_mem _ ha)
(ball_image_of_ball <| ball_image_of_ball fun _ ha => mem_image_of_mem _ ha)
#align set.image_comp Set.image_comp
theorem image_comp_eq {g : β → γ} : image (g ∘ f) = image g ∘ image f := by ext; simp
/-- A variant of `image_comp`, useful for rewriting -/
theorem image_image (g : β → γ) (f : α → β) (s : Set α) : g '' (f '' s) = (fun x => g (f x)) '' s :=
(image_comp g f s).symm
#align set.image_image Set.image_image
theorem image_comm {β'} {f : β → γ} {g : α → β} {f' : α → β'} {g' : β' → γ}
(h_comm : ∀ a, f (g a) = g' (f' a)) : (s.image g).image f = (s.image f').image g' := by
simp_rw [image_image, h_comm]
#align set.image_comm Set.image_comm
theorem _root_.Function.Semiconj.set_image {f : α → β} {ga : α → α} {gb : β → β}
(h : Function.Semiconj f ga gb) : Function.Semiconj (image f) (image ga) (image gb) := fun _ =>
image_comm h
#align function.semiconj.set_image Function.Semiconj.set_image
theorem _root_.Function.Commute.set_image {f g : α → α} (h : Function.Commute f g) :
Function.Commute (image f) (image g) :=
Function.Semiconj.set_image h
#align function.commute.set_image Function.Commute.set_image
/-- Image is monotone with respect to `⊆`. See `Set.monotone_image` for the statement in
terms of `≤`. -/
@[gcongr]
theorem image_subset {a b : Set α} (f : α → β) (h : a ⊆ b) : f '' a ⊆ f '' b := by
simp only [subset_def, mem_image]
|
exact fun x => fun ⟨w, h1, h2⟩ => ⟨w, h h1, h2⟩
|
/-- Image is monotone with respect to `⊆`. See `Set.monotone_image` for the statement in
terms of `≤`. -/
@[gcongr]
theorem image_subset {a b : Set α} (f : α → β) (h : a ⊆ b) : f '' a ⊆ f '' b := by
simp only [subset_def, mem_image]
|
Mathlib.Data.Set.Image.324_0.IJFiTzmYGOCpPSd
|
/-- Image is monotone with respect to `⊆`. See `Set.monotone_image` for the statement in
terms of `≤`. -/
@[gcongr]
theorem image_subset {a b : Set α} (f : α → β) (h : a ⊆ b) : f '' a ⊆ f '' b
|
Mathlib_Data_Set_Image
|
α : Type u_1
β : Type u_2
γ : Type u_3
ι : Sort u_4
ι' : Sort u_5
f✝ : α → β
s✝ t✝ : Set α
f : α → β
s t : Set α
x : β
⊢ x ∈ f '' (s ∪ t) → x ∈ f '' s ∪ f '' t
|
/-
Copyright (c) 2014 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Leonardo de Moura
-/
import Mathlib.Data.Set.Basic
#align_import data.set.image from "leanprover-community/mathlib"@"001ffdc42920050657fd45bd2b8bfbec8eaaeb29"
/-!
# Images and preimages of sets
## Main definitions
* `preimage f t : Set α` : the preimage f⁻¹(t) (written `f ⁻¹' t` in Lean) of a subset of β.
* `range f : Set β` : the image of `univ` under `f`.
Also works for `{p : Prop} (f : p → α)` (unlike `image`)
## Notation
* `f ⁻¹' t` for `Set.preimage f t`
* `f '' s` for `Set.image f s`
## Tags
set, sets, image, preimage, pre-image, range
-/
set_option autoImplicit true
universe u v
open Function Set
namespace Set
variable {α β γ : Type*} {ι ι' : Sort*}
/-! ### Inverse image -/
/-- The preimage of `s : Set β` by `f : α → β`, written `f ⁻¹' s`,
is the set of `x : α` such that `f x ∈ s`. -/
def preimage {α : Type u} {β : Type v} (f : α → β) (s : Set β) : Set α :=
{ x | f x ∈ s }
#align set.preimage Set.preimage
/-- `f ⁻¹' t` denotes the preimage of `t : Set β` under the function `f : α → β`. -/
infixl:80 " ⁻¹' " => preimage
section Preimage
variable {f : α → β} {g : β → γ}
@[simp]
theorem preimage_empty : f ⁻¹' ∅ = ∅ :=
rfl
#align set.preimage_empty Set.preimage_empty
@[simp, mfld_simps]
theorem mem_preimage {s : Set β} {a : α} : a ∈ f ⁻¹' s ↔ f a ∈ s :=
Iff.rfl
#align set.mem_preimage Set.mem_preimage
theorem preimage_congr {f g : α → β} {s : Set β} (h : ∀ x : α, f x = g x) : f ⁻¹' s = g ⁻¹' s := by
congr with x
simp [h]
#align set.preimage_congr Set.preimage_congr
@[gcongr]
theorem preimage_mono {s t : Set β} (h : s ⊆ t) : f ⁻¹' s ⊆ f ⁻¹' t := fun _ hx => h hx
#align set.preimage_mono Set.preimage_mono
@[simp, mfld_simps]
theorem preimage_univ : f ⁻¹' univ = univ :=
rfl
#align set.preimage_univ Set.preimage_univ
theorem subset_preimage_univ {s : Set α} : s ⊆ f ⁻¹' univ :=
subset_univ _
#align set.subset_preimage_univ Set.subset_preimage_univ
@[simp, mfld_simps]
theorem preimage_inter {s t : Set β} : f ⁻¹' (s ∩ t) = f ⁻¹' s ∩ f ⁻¹' t :=
rfl
#align set.preimage_inter Set.preimage_inter
@[simp]
theorem preimage_union {s t : Set β} : f ⁻¹' (s ∪ t) = f ⁻¹' s ∪ f ⁻¹' t :=
rfl
#align set.preimage_union Set.preimage_union
@[simp]
theorem preimage_compl {s : Set β} : f ⁻¹' sᶜ = (f ⁻¹' s)ᶜ :=
rfl
#align set.preimage_compl Set.preimage_compl
@[simp]
theorem preimage_diff (f : α → β) (s t : Set β) : f ⁻¹' (s \ t) = f ⁻¹' s \ f ⁻¹' t :=
rfl
#align set.preimage_diff Set.preimage_diff
@[simp]
lemma preimage_symmDiff {f : α → β} (s t : Set β) : f ⁻¹' (s ∆ t) = (f ⁻¹' s) ∆ (f ⁻¹' t) :=
rfl
#align set.preimage_symm_diff Set.preimage_symmDiff
@[simp]
theorem preimage_ite (f : α → β) (s t₁ t₂ : Set β) :
f ⁻¹' s.ite t₁ t₂ = (f ⁻¹' s).ite (f ⁻¹' t₁) (f ⁻¹' t₂) :=
rfl
#align set.preimage_ite Set.preimage_ite
@[simp]
theorem preimage_setOf_eq {p : α → Prop} {f : β → α} : f ⁻¹' { a | p a } = { a | p (f a) } :=
rfl
#align set.preimage_set_of_eq Set.preimage_setOf_eq
@[simp]
theorem preimage_id_eq : preimage (id : α → α) = id :=
rfl
#align set.preimage_id_eq Set.preimage_id_eq
@[mfld_simps]
theorem preimage_id {s : Set α} : id ⁻¹' s = s :=
rfl
#align set.preimage_id Set.preimage_id
@[simp, mfld_simps]
theorem preimage_id' {s : Set α} : (fun x => x) ⁻¹' s = s :=
rfl
#align set.preimage_id' Set.preimage_id'
@[simp]
theorem preimage_const_of_mem {b : β} {s : Set β} (h : b ∈ s) : (fun _ : α => b) ⁻¹' s = univ :=
eq_univ_of_forall fun _ => h
#align set.preimage_const_of_mem Set.preimage_const_of_mem
@[simp]
theorem preimage_const_of_not_mem {b : β} {s : Set β} (h : b ∉ s) : (fun _ : α => b) ⁻¹' s = ∅ :=
eq_empty_of_subset_empty fun _ hx => h hx
#align set.preimage_const_of_not_mem Set.preimage_const_of_not_mem
theorem preimage_const (b : β) (s : Set β) [Decidable (b ∈ s)] :
(fun _ : α => b) ⁻¹' s = if b ∈ s then univ else ∅ := by
split_ifs with hb
exacts [preimage_const_of_mem hb, preimage_const_of_not_mem hb]
#align set.preimage_const Set.preimage_const
/-- If preimage of each singleton under `f : α → β` is either empty or the whole type,
then `f` is a constant. -/
lemma exists_eq_const_of_preimage_singleton [Nonempty β] {f : α → β}
(hf : ∀ b : β, f ⁻¹' {b} = ∅ ∨ f ⁻¹' {b} = univ) : ∃ b, f = const α b := by
rcases em (∃ b, f ⁻¹' {b} = univ) with ⟨b, hb⟩ | hf'
· exact ⟨b, funext fun x ↦ eq_univ_iff_forall.1 hb x⟩
· have : ∀ x b, f x ≠ b := fun x b ↦
eq_empty_iff_forall_not_mem.1 ((hf b).resolve_right fun h ↦ hf' ⟨b, h⟩) x
exact ⟨Classical.arbitrary β, funext fun x ↦ absurd rfl (this x _)⟩
theorem preimage_comp {s : Set γ} : g ∘ f ⁻¹' s = f ⁻¹' (g ⁻¹' s) :=
rfl
#align set.preimage_comp Set.preimage_comp
theorem preimage_comp_eq : preimage (g ∘ f) = preimage f ∘ preimage g :=
rfl
#align set.preimage_comp_eq Set.preimage_comp_eq
theorem preimage_iterate_eq {f : α → α} {n : ℕ} : Set.preimage f^[n] = (Set.preimage f)^[n] := by
induction' n with n ih; · simp
rw [iterate_succ, iterate_succ', preimage_comp_eq, ih]
#align set.preimage_iterate_eq Set.preimage_iterate_eq
theorem preimage_preimage {g : β → γ} {f : α → β} {s : Set γ} :
f ⁻¹' (g ⁻¹' s) = (fun x => g (f x)) ⁻¹' s :=
preimage_comp.symm
#align set.preimage_preimage Set.preimage_preimage
theorem eq_preimage_subtype_val_iff {p : α → Prop} {s : Set (Subtype p)} {t : Set α} :
s = Subtype.val ⁻¹' t ↔ ∀ (x) (h : p x), (⟨x, h⟩ : Subtype p) ∈ s ↔ x ∈ t :=
⟨fun s_eq x h => by
rw [s_eq]
simp, fun h => ext fun ⟨x, hx⟩ => by simp [h]⟩
#align set.eq_preimage_subtype_val_iff Set.eq_preimage_subtype_val_iff
theorem nonempty_of_nonempty_preimage {s : Set β} {f : α → β} (hf : (f ⁻¹' s).Nonempty) :
s.Nonempty :=
let ⟨x, hx⟩ := hf
⟨f x, hx⟩
#align set.nonempty_of_nonempty_preimage Set.nonempty_of_nonempty_preimage
@[simp] theorem preimage_singleton_true (p : α → Prop) : p ⁻¹' {True} = {a | p a} := by ext; simp
#align set.preimage_singleton_true Set.preimage_singleton_true
@[simp] theorem preimage_singleton_false (p : α → Prop) : p ⁻¹' {False} = {a | ¬p a} := by ext; simp
#align set.preimage_singleton_false Set.preimage_singleton_false
theorem preimage_subtype_coe_eq_compl {s u v : Set α} (hsuv : s ⊆ u ∪ v)
(H : s ∩ (u ∩ v) = ∅) : ((↑) : s → α) ⁻¹' u = ((↑) ⁻¹' v)ᶜ := by
ext ⟨x, x_in_s⟩
constructor
· intro x_in_u x_in_v
exact eq_empty_iff_forall_not_mem.mp H x ⟨x_in_s, ⟨x_in_u, x_in_v⟩⟩
· intro hx
exact Or.elim (hsuv x_in_s) id fun hx' => hx.elim hx'
#align set.preimage_subtype_coe_eq_compl Set.preimage_subtype_coe_eq_compl
end Preimage
/-! ### Image of a set under a function -/
section Image
variable {f : α → β} {s t : Set α}
-- Porting note: `Set.image` is already defined in `Init.Set`
#align set.image Set.image
/-- `f '' s` denotes the image of `s : Set α` under the function `f : α → β`. -/
infixl:80 " '' " => image
theorem mem_image_iff_bex {f : α → β} {s : Set α} {y : β} :
y ∈ f '' s ↔ ∃ (x : _) (_ : x ∈ s), f x = y :=
bex_def.symm
#align set.mem_image_iff_bex Set.mem_image_iff_bex
@[simp]
theorem mem_image (f : α → β) (s : Set α) (y : β) : y ∈ f '' s ↔ ∃ x ∈ s, f x = y :=
Iff.rfl
#align set.mem_image Set.mem_image
theorem image_eta (f : α → β) : f '' s = (fun x => f x) '' s :=
rfl
#align set.image_eta Set.image_eta
@[mfld_simps]
theorem mem_image_of_mem (f : α → β) {x : α} {a : Set α} (h : x ∈ a) : f x ∈ f '' a :=
⟨_, h, rfl⟩
#align set.mem_image_of_mem Set.mem_image_of_mem
theorem _root_.Function.Injective.mem_set_image {f : α → β} (hf : Injective f) {s : Set α} {a : α} :
f a ∈ f '' s ↔ a ∈ s :=
⟨fun ⟨_, hb, Eq⟩ => hf Eq ▸ hb, mem_image_of_mem f⟩
#align function.injective.mem_set_image Function.Injective.mem_set_image
theorem ball_image_iff {f : α → β} {s : Set α} {p : β → Prop} :
(∀ y ∈ f '' s, p y) ↔ ∀ x ∈ s, p (f x) := by simp
#align set.ball_image_iff Set.ball_image_iff
theorem ball_image_of_ball {f : α → β} {s : Set α} {p : β → Prop} (h : ∀ x ∈ s, p (f x)) :
∀ y ∈ f '' s, p y :=
ball_image_iff.2 h
#align set.ball_image_of_ball Set.ball_image_of_ball
theorem bex_image_iff {f : α → β} {s : Set α} {p : β → Prop} :
(∃ y ∈ f '' s, p y) ↔ ∃ x ∈ s, p (f x) := by simp
#align set.bex_image_iff Set.bex_image_iff
theorem mem_image_elim {f : α → β} {s : Set α} {C : β → Prop} (h : ∀ x : α, x ∈ s → C (f x)) :
∀ {y : β}, y ∈ f '' s → C y
| _, ⟨a, a_in, rfl⟩ => h a a_in
#align set.mem_image_elim Set.mem_image_elim
theorem mem_image_elim_on {f : α → β} {s : Set α} {C : β → Prop} {y : β} (h_y : y ∈ f '' s)
(h : ∀ x : α, x ∈ s → C (f x)) : C y :=
mem_image_elim h h_y
#align set.mem_image_elim_on Set.mem_image_elim_on
-- Porting note: used to be `safe`
@[congr]
theorem image_congr {f g : α → β} {s : Set α} (h : ∀ a ∈ s, f a = g a) : f '' s = g '' s := by
ext x
rw [mem_image, mem_image]
exact {
mp := by
rintro ⟨a, ha1, ha2⟩
exact ⟨a, ⟨ha1, (h a ha1) ▸ ha2⟩⟩,
mpr := by
rintro ⟨a, ha1, ha2⟩
exact ⟨a, ⟨ha1, (h a ha1) ▸ ha2⟩⟩
}
-- safe [ext_iff, iff_def]
#align set.image_congr Set.image_congr
/-- A common special case of `image_congr` -/
theorem image_congr' {f g : α → β} {s : Set α} (h : ∀ x : α, f x = g x) : f '' s = g '' s :=
image_congr fun x _ => h x
#align set.image_congr' Set.image_congr'
@[gcongr]
lemma image_mono (h : s ⊆ t) : f '' s ⊆ f '' t := by
rintro - ⟨a, ha, rfl⟩; exact mem_image_of_mem f (h ha)
theorem image_comp (f : β → γ) (g : α → β) (a : Set α) : f ∘ g '' a = f '' (g '' a) :=
Subset.antisymm (ball_image_of_ball fun _ ha => mem_image_of_mem _ <| mem_image_of_mem _ ha)
(ball_image_of_ball <| ball_image_of_ball fun _ ha => mem_image_of_mem _ ha)
#align set.image_comp Set.image_comp
theorem image_comp_eq {g : β → γ} : image (g ∘ f) = image g ∘ image f := by ext; simp
/-- A variant of `image_comp`, useful for rewriting -/
theorem image_image (g : β → γ) (f : α → β) (s : Set α) : g '' (f '' s) = (fun x => g (f x)) '' s :=
(image_comp g f s).symm
#align set.image_image Set.image_image
theorem image_comm {β'} {f : β → γ} {g : α → β} {f' : α → β'} {g' : β' → γ}
(h_comm : ∀ a, f (g a) = g' (f' a)) : (s.image g).image f = (s.image f').image g' := by
simp_rw [image_image, h_comm]
#align set.image_comm Set.image_comm
theorem _root_.Function.Semiconj.set_image {f : α → β} {ga : α → α} {gb : β → β}
(h : Function.Semiconj f ga gb) : Function.Semiconj (image f) (image ga) (image gb) := fun _ =>
image_comm h
#align function.semiconj.set_image Function.Semiconj.set_image
theorem _root_.Function.Commute.set_image {f g : α → α} (h : Function.Commute f g) :
Function.Commute (image f) (image g) :=
Function.Semiconj.set_image h
#align function.commute.set_image Function.Commute.set_image
/-- Image is monotone with respect to `⊆`. See `Set.monotone_image` for the statement in
terms of `≤`. -/
@[gcongr]
theorem image_subset {a b : Set α} (f : α → β) (h : a ⊆ b) : f '' a ⊆ f '' b := by
simp only [subset_def, mem_image]
exact fun x => fun ⟨w, h1, h2⟩ => ⟨w, h h1, h2⟩
#align set.image_subset Set.image_subset
/-- `Set.image` is monotone. See `Set.image_subset` for the statement in terms of `⊆`. -/
lemma monotone_image {f : α → β} : Monotone (image f) := fun _ _ => image_subset _
#align set.monotone_image Set.monotone_image
theorem image_union (f : α → β) (s t : Set α) : f '' (s ∪ t) = f '' s ∪ f '' t :=
ext fun x =>
⟨by
|
rintro ⟨a, h | h, rfl⟩ <;> [left; right]
|
theorem image_union (f : α → β) (s t : Set α) : f '' (s ∪ t) = f '' s ∪ f '' t :=
ext fun x =>
⟨by
|
Mathlib.Data.Set.Image.336_0.IJFiTzmYGOCpPSd
|
theorem image_union (f : α → β) (s t : Set α) : f '' (s ∪ t) = f '' s ∪ f '' t
|
Mathlib_Data_Set_Image
|
α : Type u_1
β : Type u_2
γ : Type u_3
ι : Sort u_4
ι' : Sort u_5
f✝ : α → β
s✝ t✝ : Set α
f : α → β
s t : Set α
x : β
⊢ x ∈ f '' (s ∪ t) → x ∈ f '' s ∪ f '' t
|
/-
Copyright (c) 2014 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Leonardo de Moura
-/
import Mathlib.Data.Set.Basic
#align_import data.set.image from "leanprover-community/mathlib"@"001ffdc42920050657fd45bd2b8bfbec8eaaeb29"
/-!
# Images and preimages of sets
## Main definitions
* `preimage f t : Set α` : the preimage f⁻¹(t) (written `f ⁻¹' t` in Lean) of a subset of β.
* `range f : Set β` : the image of `univ` under `f`.
Also works for `{p : Prop} (f : p → α)` (unlike `image`)
## Notation
* `f ⁻¹' t` for `Set.preimage f t`
* `f '' s` for `Set.image f s`
## Tags
set, sets, image, preimage, pre-image, range
-/
set_option autoImplicit true
universe u v
open Function Set
namespace Set
variable {α β γ : Type*} {ι ι' : Sort*}
/-! ### Inverse image -/
/-- The preimage of `s : Set β` by `f : α → β`, written `f ⁻¹' s`,
is the set of `x : α` such that `f x ∈ s`. -/
def preimage {α : Type u} {β : Type v} (f : α → β) (s : Set β) : Set α :=
{ x | f x ∈ s }
#align set.preimage Set.preimage
/-- `f ⁻¹' t` denotes the preimage of `t : Set β` under the function `f : α → β`. -/
infixl:80 " ⁻¹' " => preimage
section Preimage
variable {f : α → β} {g : β → γ}
@[simp]
theorem preimage_empty : f ⁻¹' ∅ = ∅ :=
rfl
#align set.preimage_empty Set.preimage_empty
@[simp, mfld_simps]
theorem mem_preimage {s : Set β} {a : α} : a ∈ f ⁻¹' s ↔ f a ∈ s :=
Iff.rfl
#align set.mem_preimage Set.mem_preimage
theorem preimage_congr {f g : α → β} {s : Set β} (h : ∀ x : α, f x = g x) : f ⁻¹' s = g ⁻¹' s := by
congr with x
simp [h]
#align set.preimage_congr Set.preimage_congr
@[gcongr]
theorem preimage_mono {s t : Set β} (h : s ⊆ t) : f ⁻¹' s ⊆ f ⁻¹' t := fun _ hx => h hx
#align set.preimage_mono Set.preimage_mono
@[simp, mfld_simps]
theorem preimage_univ : f ⁻¹' univ = univ :=
rfl
#align set.preimage_univ Set.preimage_univ
theorem subset_preimage_univ {s : Set α} : s ⊆ f ⁻¹' univ :=
subset_univ _
#align set.subset_preimage_univ Set.subset_preimage_univ
@[simp, mfld_simps]
theorem preimage_inter {s t : Set β} : f ⁻¹' (s ∩ t) = f ⁻¹' s ∩ f ⁻¹' t :=
rfl
#align set.preimage_inter Set.preimage_inter
@[simp]
theorem preimage_union {s t : Set β} : f ⁻¹' (s ∪ t) = f ⁻¹' s ∪ f ⁻¹' t :=
rfl
#align set.preimage_union Set.preimage_union
@[simp]
theorem preimage_compl {s : Set β} : f ⁻¹' sᶜ = (f ⁻¹' s)ᶜ :=
rfl
#align set.preimage_compl Set.preimage_compl
@[simp]
theorem preimage_diff (f : α → β) (s t : Set β) : f ⁻¹' (s \ t) = f ⁻¹' s \ f ⁻¹' t :=
rfl
#align set.preimage_diff Set.preimage_diff
@[simp]
lemma preimage_symmDiff {f : α → β} (s t : Set β) : f ⁻¹' (s ∆ t) = (f ⁻¹' s) ∆ (f ⁻¹' t) :=
rfl
#align set.preimage_symm_diff Set.preimage_symmDiff
@[simp]
theorem preimage_ite (f : α → β) (s t₁ t₂ : Set β) :
f ⁻¹' s.ite t₁ t₂ = (f ⁻¹' s).ite (f ⁻¹' t₁) (f ⁻¹' t₂) :=
rfl
#align set.preimage_ite Set.preimage_ite
@[simp]
theorem preimage_setOf_eq {p : α → Prop} {f : β → α} : f ⁻¹' { a | p a } = { a | p (f a) } :=
rfl
#align set.preimage_set_of_eq Set.preimage_setOf_eq
@[simp]
theorem preimage_id_eq : preimage (id : α → α) = id :=
rfl
#align set.preimage_id_eq Set.preimage_id_eq
@[mfld_simps]
theorem preimage_id {s : Set α} : id ⁻¹' s = s :=
rfl
#align set.preimage_id Set.preimage_id
@[simp, mfld_simps]
theorem preimage_id' {s : Set α} : (fun x => x) ⁻¹' s = s :=
rfl
#align set.preimage_id' Set.preimage_id'
@[simp]
theorem preimage_const_of_mem {b : β} {s : Set β} (h : b ∈ s) : (fun _ : α => b) ⁻¹' s = univ :=
eq_univ_of_forall fun _ => h
#align set.preimage_const_of_mem Set.preimage_const_of_mem
@[simp]
theorem preimage_const_of_not_mem {b : β} {s : Set β} (h : b ∉ s) : (fun _ : α => b) ⁻¹' s = ∅ :=
eq_empty_of_subset_empty fun _ hx => h hx
#align set.preimage_const_of_not_mem Set.preimage_const_of_not_mem
theorem preimage_const (b : β) (s : Set β) [Decidable (b ∈ s)] :
(fun _ : α => b) ⁻¹' s = if b ∈ s then univ else ∅ := by
split_ifs with hb
exacts [preimage_const_of_mem hb, preimage_const_of_not_mem hb]
#align set.preimage_const Set.preimage_const
/-- If preimage of each singleton under `f : α → β` is either empty or the whole type,
then `f` is a constant. -/
lemma exists_eq_const_of_preimage_singleton [Nonempty β] {f : α → β}
(hf : ∀ b : β, f ⁻¹' {b} = ∅ ∨ f ⁻¹' {b} = univ) : ∃ b, f = const α b := by
rcases em (∃ b, f ⁻¹' {b} = univ) with ⟨b, hb⟩ | hf'
· exact ⟨b, funext fun x ↦ eq_univ_iff_forall.1 hb x⟩
· have : ∀ x b, f x ≠ b := fun x b ↦
eq_empty_iff_forall_not_mem.1 ((hf b).resolve_right fun h ↦ hf' ⟨b, h⟩) x
exact ⟨Classical.arbitrary β, funext fun x ↦ absurd rfl (this x _)⟩
theorem preimage_comp {s : Set γ} : g ∘ f ⁻¹' s = f ⁻¹' (g ⁻¹' s) :=
rfl
#align set.preimage_comp Set.preimage_comp
theorem preimage_comp_eq : preimage (g ∘ f) = preimage f ∘ preimage g :=
rfl
#align set.preimage_comp_eq Set.preimage_comp_eq
theorem preimage_iterate_eq {f : α → α} {n : ℕ} : Set.preimage f^[n] = (Set.preimage f)^[n] := by
induction' n with n ih; · simp
rw [iterate_succ, iterate_succ', preimage_comp_eq, ih]
#align set.preimage_iterate_eq Set.preimage_iterate_eq
theorem preimage_preimage {g : β → γ} {f : α → β} {s : Set γ} :
f ⁻¹' (g ⁻¹' s) = (fun x => g (f x)) ⁻¹' s :=
preimage_comp.symm
#align set.preimage_preimage Set.preimage_preimage
theorem eq_preimage_subtype_val_iff {p : α → Prop} {s : Set (Subtype p)} {t : Set α} :
s = Subtype.val ⁻¹' t ↔ ∀ (x) (h : p x), (⟨x, h⟩ : Subtype p) ∈ s ↔ x ∈ t :=
⟨fun s_eq x h => by
rw [s_eq]
simp, fun h => ext fun ⟨x, hx⟩ => by simp [h]⟩
#align set.eq_preimage_subtype_val_iff Set.eq_preimage_subtype_val_iff
theorem nonempty_of_nonempty_preimage {s : Set β} {f : α → β} (hf : (f ⁻¹' s).Nonempty) :
s.Nonempty :=
let ⟨x, hx⟩ := hf
⟨f x, hx⟩
#align set.nonempty_of_nonempty_preimage Set.nonempty_of_nonempty_preimage
@[simp] theorem preimage_singleton_true (p : α → Prop) : p ⁻¹' {True} = {a | p a} := by ext; simp
#align set.preimage_singleton_true Set.preimage_singleton_true
@[simp] theorem preimage_singleton_false (p : α → Prop) : p ⁻¹' {False} = {a | ¬p a} := by ext; simp
#align set.preimage_singleton_false Set.preimage_singleton_false
theorem preimage_subtype_coe_eq_compl {s u v : Set α} (hsuv : s ⊆ u ∪ v)
(H : s ∩ (u ∩ v) = ∅) : ((↑) : s → α) ⁻¹' u = ((↑) ⁻¹' v)ᶜ := by
ext ⟨x, x_in_s⟩
constructor
· intro x_in_u x_in_v
exact eq_empty_iff_forall_not_mem.mp H x ⟨x_in_s, ⟨x_in_u, x_in_v⟩⟩
· intro hx
exact Or.elim (hsuv x_in_s) id fun hx' => hx.elim hx'
#align set.preimage_subtype_coe_eq_compl Set.preimage_subtype_coe_eq_compl
end Preimage
/-! ### Image of a set under a function -/
section Image
variable {f : α → β} {s t : Set α}
-- Porting note: `Set.image` is already defined in `Init.Set`
#align set.image Set.image
/-- `f '' s` denotes the image of `s : Set α` under the function `f : α → β`. -/
infixl:80 " '' " => image
theorem mem_image_iff_bex {f : α → β} {s : Set α} {y : β} :
y ∈ f '' s ↔ ∃ (x : _) (_ : x ∈ s), f x = y :=
bex_def.symm
#align set.mem_image_iff_bex Set.mem_image_iff_bex
@[simp]
theorem mem_image (f : α → β) (s : Set α) (y : β) : y ∈ f '' s ↔ ∃ x ∈ s, f x = y :=
Iff.rfl
#align set.mem_image Set.mem_image
theorem image_eta (f : α → β) : f '' s = (fun x => f x) '' s :=
rfl
#align set.image_eta Set.image_eta
@[mfld_simps]
theorem mem_image_of_mem (f : α → β) {x : α} {a : Set α} (h : x ∈ a) : f x ∈ f '' a :=
⟨_, h, rfl⟩
#align set.mem_image_of_mem Set.mem_image_of_mem
theorem _root_.Function.Injective.mem_set_image {f : α → β} (hf : Injective f) {s : Set α} {a : α} :
f a ∈ f '' s ↔ a ∈ s :=
⟨fun ⟨_, hb, Eq⟩ => hf Eq ▸ hb, mem_image_of_mem f⟩
#align function.injective.mem_set_image Function.Injective.mem_set_image
theorem ball_image_iff {f : α → β} {s : Set α} {p : β → Prop} :
(∀ y ∈ f '' s, p y) ↔ ∀ x ∈ s, p (f x) := by simp
#align set.ball_image_iff Set.ball_image_iff
theorem ball_image_of_ball {f : α → β} {s : Set α} {p : β → Prop} (h : ∀ x ∈ s, p (f x)) :
∀ y ∈ f '' s, p y :=
ball_image_iff.2 h
#align set.ball_image_of_ball Set.ball_image_of_ball
theorem bex_image_iff {f : α → β} {s : Set α} {p : β → Prop} :
(∃ y ∈ f '' s, p y) ↔ ∃ x ∈ s, p (f x) := by simp
#align set.bex_image_iff Set.bex_image_iff
theorem mem_image_elim {f : α → β} {s : Set α} {C : β → Prop} (h : ∀ x : α, x ∈ s → C (f x)) :
∀ {y : β}, y ∈ f '' s → C y
| _, ⟨a, a_in, rfl⟩ => h a a_in
#align set.mem_image_elim Set.mem_image_elim
theorem mem_image_elim_on {f : α → β} {s : Set α} {C : β → Prop} {y : β} (h_y : y ∈ f '' s)
(h : ∀ x : α, x ∈ s → C (f x)) : C y :=
mem_image_elim h h_y
#align set.mem_image_elim_on Set.mem_image_elim_on
-- Porting note: used to be `safe`
@[congr]
theorem image_congr {f g : α → β} {s : Set α} (h : ∀ a ∈ s, f a = g a) : f '' s = g '' s := by
ext x
rw [mem_image, mem_image]
exact {
mp := by
rintro ⟨a, ha1, ha2⟩
exact ⟨a, ⟨ha1, (h a ha1) ▸ ha2⟩⟩,
mpr := by
rintro ⟨a, ha1, ha2⟩
exact ⟨a, ⟨ha1, (h a ha1) ▸ ha2⟩⟩
}
-- safe [ext_iff, iff_def]
#align set.image_congr Set.image_congr
/-- A common special case of `image_congr` -/
theorem image_congr' {f g : α → β} {s : Set α} (h : ∀ x : α, f x = g x) : f '' s = g '' s :=
image_congr fun x _ => h x
#align set.image_congr' Set.image_congr'
@[gcongr]
lemma image_mono (h : s ⊆ t) : f '' s ⊆ f '' t := by
rintro - ⟨a, ha, rfl⟩; exact mem_image_of_mem f (h ha)
theorem image_comp (f : β → γ) (g : α → β) (a : Set α) : f ∘ g '' a = f '' (g '' a) :=
Subset.antisymm (ball_image_of_ball fun _ ha => mem_image_of_mem _ <| mem_image_of_mem _ ha)
(ball_image_of_ball <| ball_image_of_ball fun _ ha => mem_image_of_mem _ ha)
#align set.image_comp Set.image_comp
theorem image_comp_eq {g : β → γ} : image (g ∘ f) = image g ∘ image f := by ext; simp
/-- A variant of `image_comp`, useful for rewriting -/
theorem image_image (g : β → γ) (f : α → β) (s : Set α) : g '' (f '' s) = (fun x => g (f x)) '' s :=
(image_comp g f s).symm
#align set.image_image Set.image_image
theorem image_comm {β'} {f : β → γ} {g : α → β} {f' : α → β'} {g' : β' → γ}
(h_comm : ∀ a, f (g a) = g' (f' a)) : (s.image g).image f = (s.image f').image g' := by
simp_rw [image_image, h_comm]
#align set.image_comm Set.image_comm
theorem _root_.Function.Semiconj.set_image {f : α → β} {ga : α → α} {gb : β → β}
(h : Function.Semiconj f ga gb) : Function.Semiconj (image f) (image ga) (image gb) := fun _ =>
image_comm h
#align function.semiconj.set_image Function.Semiconj.set_image
theorem _root_.Function.Commute.set_image {f g : α → α} (h : Function.Commute f g) :
Function.Commute (image f) (image g) :=
Function.Semiconj.set_image h
#align function.commute.set_image Function.Commute.set_image
/-- Image is monotone with respect to `⊆`. See `Set.monotone_image` for the statement in
terms of `≤`. -/
@[gcongr]
theorem image_subset {a b : Set α} (f : α → β) (h : a ⊆ b) : f '' a ⊆ f '' b := by
simp only [subset_def, mem_image]
exact fun x => fun ⟨w, h1, h2⟩ => ⟨w, h h1, h2⟩
#align set.image_subset Set.image_subset
/-- `Set.image` is monotone. See `Set.image_subset` for the statement in terms of `⊆`. -/
lemma monotone_image {f : α → β} : Monotone (image f) := fun _ _ => image_subset _
#align set.monotone_image Set.monotone_image
theorem image_union (f : α → β) (s t : Set α) : f '' (s ∪ t) = f '' s ∪ f '' t :=
ext fun x =>
⟨by
|
rintro ⟨a, h | h, rfl⟩
|
theorem image_union (f : α → β) (s t : Set α) : f '' (s ∪ t) = f '' s ∪ f '' t :=
ext fun x =>
⟨by
|
Mathlib.Data.Set.Image.336_0.IJFiTzmYGOCpPSd
|
theorem image_union (f : α → β) (s t : Set α) : f '' (s ∪ t) = f '' s ∪ f '' t
|
Mathlib_Data_Set_Image
|
case intro.intro.inl
α : Type u_1
β : Type u_2
γ : Type u_3
ι : Sort u_4
ι' : Sort u_5
f✝ : α → β
s✝ t✝ : Set α
f : α → β
s t : Set α
a : α
h : a ∈ s
⊢ f a ∈ f '' s ∪ f '' t
|
/-
Copyright (c) 2014 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Leonardo de Moura
-/
import Mathlib.Data.Set.Basic
#align_import data.set.image from "leanprover-community/mathlib"@"001ffdc42920050657fd45bd2b8bfbec8eaaeb29"
/-!
# Images and preimages of sets
## Main definitions
* `preimage f t : Set α` : the preimage f⁻¹(t) (written `f ⁻¹' t` in Lean) of a subset of β.
* `range f : Set β` : the image of `univ` under `f`.
Also works for `{p : Prop} (f : p → α)` (unlike `image`)
## Notation
* `f ⁻¹' t` for `Set.preimage f t`
* `f '' s` for `Set.image f s`
## Tags
set, sets, image, preimage, pre-image, range
-/
set_option autoImplicit true
universe u v
open Function Set
namespace Set
variable {α β γ : Type*} {ι ι' : Sort*}
/-! ### Inverse image -/
/-- The preimage of `s : Set β` by `f : α → β`, written `f ⁻¹' s`,
is the set of `x : α` such that `f x ∈ s`. -/
def preimage {α : Type u} {β : Type v} (f : α → β) (s : Set β) : Set α :=
{ x | f x ∈ s }
#align set.preimage Set.preimage
/-- `f ⁻¹' t` denotes the preimage of `t : Set β` under the function `f : α → β`. -/
infixl:80 " ⁻¹' " => preimage
section Preimage
variable {f : α → β} {g : β → γ}
@[simp]
theorem preimage_empty : f ⁻¹' ∅ = ∅ :=
rfl
#align set.preimage_empty Set.preimage_empty
@[simp, mfld_simps]
theorem mem_preimage {s : Set β} {a : α} : a ∈ f ⁻¹' s ↔ f a ∈ s :=
Iff.rfl
#align set.mem_preimage Set.mem_preimage
theorem preimage_congr {f g : α → β} {s : Set β} (h : ∀ x : α, f x = g x) : f ⁻¹' s = g ⁻¹' s := by
congr with x
simp [h]
#align set.preimage_congr Set.preimage_congr
@[gcongr]
theorem preimage_mono {s t : Set β} (h : s ⊆ t) : f ⁻¹' s ⊆ f ⁻¹' t := fun _ hx => h hx
#align set.preimage_mono Set.preimage_mono
@[simp, mfld_simps]
theorem preimage_univ : f ⁻¹' univ = univ :=
rfl
#align set.preimage_univ Set.preimage_univ
theorem subset_preimage_univ {s : Set α} : s ⊆ f ⁻¹' univ :=
subset_univ _
#align set.subset_preimage_univ Set.subset_preimage_univ
@[simp, mfld_simps]
theorem preimage_inter {s t : Set β} : f ⁻¹' (s ∩ t) = f ⁻¹' s ∩ f ⁻¹' t :=
rfl
#align set.preimage_inter Set.preimage_inter
@[simp]
theorem preimage_union {s t : Set β} : f ⁻¹' (s ∪ t) = f ⁻¹' s ∪ f ⁻¹' t :=
rfl
#align set.preimage_union Set.preimage_union
@[simp]
theorem preimage_compl {s : Set β} : f ⁻¹' sᶜ = (f ⁻¹' s)ᶜ :=
rfl
#align set.preimage_compl Set.preimage_compl
@[simp]
theorem preimage_diff (f : α → β) (s t : Set β) : f ⁻¹' (s \ t) = f ⁻¹' s \ f ⁻¹' t :=
rfl
#align set.preimage_diff Set.preimage_diff
@[simp]
lemma preimage_symmDiff {f : α → β} (s t : Set β) : f ⁻¹' (s ∆ t) = (f ⁻¹' s) ∆ (f ⁻¹' t) :=
rfl
#align set.preimage_symm_diff Set.preimage_symmDiff
@[simp]
theorem preimage_ite (f : α → β) (s t₁ t₂ : Set β) :
f ⁻¹' s.ite t₁ t₂ = (f ⁻¹' s).ite (f ⁻¹' t₁) (f ⁻¹' t₂) :=
rfl
#align set.preimage_ite Set.preimage_ite
@[simp]
theorem preimage_setOf_eq {p : α → Prop} {f : β → α} : f ⁻¹' { a | p a } = { a | p (f a) } :=
rfl
#align set.preimage_set_of_eq Set.preimage_setOf_eq
@[simp]
theorem preimage_id_eq : preimage (id : α → α) = id :=
rfl
#align set.preimage_id_eq Set.preimage_id_eq
@[mfld_simps]
theorem preimage_id {s : Set α} : id ⁻¹' s = s :=
rfl
#align set.preimage_id Set.preimage_id
@[simp, mfld_simps]
theorem preimage_id' {s : Set α} : (fun x => x) ⁻¹' s = s :=
rfl
#align set.preimage_id' Set.preimage_id'
@[simp]
theorem preimage_const_of_mem {b : β} {s : Set β} (h : b ∈ s) : (fun _ : α => b) ⁻¹' s = univ :=
eq_univ_of_forall fun _ => h
#align set.preimage_const_of_mem Set.preimage_const_of_mem
@[simp]
theorem preimage_const_of_not_mem {b : β} {s : Set β} (h : b ∉ s) : (fun _ : α => b) ⁻¹' s = ∅ :=
eq_empty_of_subset_empty fun _ hx => h hx
#align set.preimage_const_of_not_mem Set.preimage_const_of_not_mem
theorem preimage_const (b : β) (s : Set β) [Decidable (b ∈ s)] :
(fun _ : α => b) ⁻¹' s = if b ∈ s then univ else ∅ := by
split_ifs with hb
exacts [preimage_const_of_mem hb, preimage_const_of_not_mem hb]
#align set.preimage_const Set.preimage_const
/-- If preimage of each singleton under `f : α → β` is either empty or the whole type,
then `f` is a constant. -/
lemma exists_eq_const_of_preimage_singleton [Nonempty β] {f : α → β}
(hf : ∀ b : β, f ⁻¹' {b} = ∅ ∨ f ⁻¹' {b} = univ) : ∃ b, f = const α b := by
rcases em (∃ b, f ⁻¹' {b} = univ) with ⟨b, hb⟩ | hf'
· exact ⟨b, funext fun x ↦ eq_univ_iff_forall.1 hb x⟩
· have : ∀ x b, f x ≠ b := fun x b ↦
eq_empty_iff_forall_not_mem.1 ((hf b).resolve_right fun h ↦ hf' ⟨b, h⟩) x
exact ⟨Classical.arbitrary β, funext fun x ↦ absurd rfl (this x _)⟩
theorem preimage_comp {s : Set γ} : g ∘ f ⁻¹' s = f ⁻¹' (g ⁻¹' s) :=
rfl
#align set.preimage_comp Set.preimage_comp
theorem preimage_comp_eq : preimage (g ∘ f) = preimage f ∘ preimage g :=
rfl
#align set.preimage_comp_eq Set.preimage_comp_eq
theorem preimage_iterate_eq {f : α → α} {n : ℕ} : Set.preimage f^[n] = (Set.preimage f)^[n] := by
induction' n with n ih; · simp
rw [iterate_succ, iterate_succ', preimage_comp_eq, ih]
#align set.preimage_iterate_eq Set.preimage_iterate_eq
theorem preimage_preimage {g : β → γ} {f : α → β} {s : Set γ} :
f ⁻¹' (g ⁻¹' s) = (fun x => g (f x)) ⁻¹' s :=
preimage_comp.symm
#align set.preimage_preimage Set.preimage_preimage
theorem eq_preimage_subtype_val_iff {p : α → Prop} {s : Set (Subtype p)} {t : Set α} :
s = Subtype.val ⁻¹' t ↔ ∀ (x) (h : p x), (⟨x, h⟩ : Subtype p) ∈ s ↔ x ∈ t :=
⟨fun s_eq x h => by
rw [s_eq]
simp, fun h => ext fun ⟨x, hx⟩ => by simp [h]⟩
#align set.eq_preimage_subtype_val_iff Set.eq_preimage_subtype_val_iff
theorem nonempty_of_nonempty_preimage {s : Set β} {f : α → β} (hf : (f ⁻¹' s).Nonempty) :
s.Nonempty :=
let ⟨x, hx⟩ := hf
⟨f x, hx⟩
#align set.nonempty_of_nonempty_preimage Set.nonempty_of_nonempty_preimage
@[simp] theorem preimage_singleton_true (p : α → Prop) : p ⁻¹' {True} = {a | p a} := by ext; simp
#align set.preimage_singleton_true Set.preimage_singleton_true
@[simp] theorem preimage_singleton_false (p : α → Prop) : p ⁻¹' {False} = {a | ¬p a} := by ext; simp
#align set.preimage_singleton_false Set.preimage_singleton_false
theorem preimage_subtype_coe_eq_compl {s u v : Set α} (hsuv : s ⊆ u ∪ v)
(H : s ∩ (u ∩ v) = ∅) : ((↑) : s → α) ⁻¹' u = ((↑) ⁻¹' v)ᶜ := by
ext ⟨x, x_in_s⟩
constructor
· intro x_in_u x_in_v
exact eq_empty_iff_forall_not_mem.mp H x ⟨x_in_s, ⟨x_in_u, x_in_v⟩⟩
· intro hx
exact Or.elim (hsuv x_in_s) id fun hx' => hx.elim hx'
#align set.preimage_subtype_coe_eq_compl Set.preimage_subtype_coe_eq_compl
end Preimage
/-! ### Image of a set under a function -/
section Image
variable {f : α → β} {s t : Set α}
-- Porting note: `Set.image` is already defined in `Init.Set`
#align set.image Set.image
/-- `f '' s` denotes the image of `s : Set α` under the function `f : α → β`. -/
infixl:80 " '' " => image
theorem mem_image_iff_bex {f : α → β} {s : Set α} {y : β} :
y ∈ f '' s ↔ ∃ (x : _) (_ : x ∈ s), f x = y :=
bex_def.symm
#align set.mem_image_iff_bex Set.mem_image_iff_bex
@[simp]
theorem mem_image (f : α → β) (s : Set α) (y : β) : y ∈ f '' s ↔ ∃ x ∈ s, f x = y :=
Iff.rfl
#align set.mem_image Set.mem_image
theorem image_eta (f : α → β) : f '' s = (fun x => f x) '' s :=
rfl
#align set.image_eta Set.image_eta
@[mfld_simps]
theorem mem_image_of_mem (f : α → β) {x : α} {a : Set α} (h : x ∈ a) : f x ∈ f '' a :=
⟨_, h, rfl⟩
#align set.mem_image_of_mem Set.mem_image_of_mem
theorem _root_.Function.Injective.mem_set_image {f : α → β} (hf : Injective f) {s : Set α} {a : α} :
f a ∈ f '' s ↔ a ∈ s :=
⟨fun ⟨_, hb, Eq⟩ => hf Eq ▸ hb, mem_image_of_mem f⟩
#align function.injective.mem_set_image Function.Injective.mem_set_image
theorem ball_image_iff {f : α → β} {s : Set α} {p : β → Prop} :
(∀ y ∈ f '' s, p y) ↔ ∀ x ∈ s, p (f x) := by simp
#align set.ball_image_iff Set.ball_image_iff
theorem ball_image_of_ball {f : α → β} {s : Set α} {p : β → Prop} (h : ∀ x ∈ s, p (f x)) :
∀ y ∈ f '' s, p y :=
ball_image_iff.2 h
#align set.ball_image_of_ball Set.ball_image_of_ball
theorem bex_image_iff {f : α → β} {s : Set α} {p : β → Prop} :
(∃ y ∈ f '' s, p y) ↔ ∃ x ∈ s, p (f x) := by simp
#align set.bex_image_iff Set.bex_image_iff
theorem mem_image_elim {f : α → β} {s : Set α} {C : β → Prop} (h : ∀ x : α, x ∈ s → C (f x)) :
∀ {y : β}, y ∈ f '' s → C y
| _, ⟨a, a_in, rfl⟩ => h a a_in
#align set.mem_image_elim Set.mem_image_elim
theorem mem_image_elim_on {f : α → β} {s : Set α} {C : β → Prop} {y : β} (h_y : y ∈ f '' s)
(h : ∀ x : α, x ∈ s → C (f x)) : C y :=
mem_image_elim h h_y
#align set.mem_image_elim_on Set.mem_image_elim_on
-- Porting note: used to be `safe`
@[congr]
theorem image_congr {f g : α → β} {s : Set α} (h : ∀ a ∈ s, f a = g a) : f '' s = g '' s := by
ext x
rw [mem_image, mem_image]
exact {
mp := by
rintro ⟨a, ha1, ha2⟩
exact ⟨a, ⟨ha1, (h a ha1) ▸ ha2⟩⟩,
mpr := by
rintro ⟨a, ha1, ha2⟩
exact ⟨a, ⟨ha1, (h a ha1) ▸ ha2⟩⟩
}
-- safe [ext_iff, iff_def]
#align set.image_congr Set.image_congr
/-- A common special case of `image_congr` -/
theorem image_congr' {f g : α → β} {s : Set α} (h : ∀ x : α, f x = g x) : f '' s = g '' s :=
image_congr fun x _ => h x
#align set.image_congr' Set.image_congr'
@[gcongr]
lemma image_mono (h : s ⊆ t) : f '' s ⊆ f '' t := by
rintro - ⟨a, ha, rfl⟩; exact mem_image_of_mem f (h ha)
theorem image_comp (f : β → γ) (g : α → β) (a : Set α) : f ∘ g '' a = f '' (g '' a) :=
Subset.antisymm (ball_image_of_ball fun _ ha => mem_image_of_mem _ <| mem_image_of_mem _ ha)
(ball_image_of_ball <| ball_image_of_ball fun _ ha => mem_image_of_mem _ ha)
#align set.image_comp Set.image_comp
theorem image_comp_eq {g : β → γ} : image (g ∘ f) = image g ∘ image f := by ext; simp
/-- A variant of `image_comp`, useful for rewriting -/
theorem image_image (g : β → γ) (f : α → β) (s : Set α) : g '' (f '' s) = (fun x => g (f x)) '' s :=
(image_comp g f s).symm
#align set.image_image Set.image_image
theorem image_comm {β'} {f : β → γ} {g : α → β} {f' : α → β'} {g' : β' → γ}
(h_comm : ∀ a, f (g a) = g' (f' a)) : (s.image g).image f = (s.image f').image g' := by
simp_rw [image_image, h_comm]
#align set.image_comm Set.image_comm
theorem _root_.Function.Semiconj.set_image {f : α → β} {ga : α → α} {gb : β → β}
(h : Function.Semiconj f ga gb) : Function.Semiconj (image f) (image ga) (image gb) := fun _ =>
image_comm h
#align function.semiconj.set_image Function.Semiconj.set_image
theorem _root_.Function.Commute.set_image {f g : α → α} (h : Function.Commute f g) :
Function.Commute (image f) (image g) :=
Function.Semiconj.set_image h
#align function.commute.set_image Function.Commute.set_image
/-- Image is monotone with respect to `⊆`. See `Set.monotone_image` for the statement in
terms of `≤`. -/
@[gcongr]
theorem image_subset {a b : Set α} (f : α → β) (h : a ⊆ b) : f '' a ⊆ f '' b := by
simp only [subset_def, mem_image]
exact fun x => fun ⟨w, h1, h2⟩ => ⟨w, h h1, h2⟩
#align set.image_subset Set.image_subset
/-- `Set.image` is monotone. See `Set.image_subset` for the statement in terms of `⊆`. -/
lemma monotone_image {f : α → β} : Monotone (image f) := fun _ _ => image_subset _
#align set.monotone_image Set.monotone_image
theorem image_union (f : α → β) (s t : Set α) : f '' (s ∪ t) = f '' s ∪ f '' t :=
ext fun x =>
⟨by rintro ⟨a, h | h, rfl⟩ <;> [
|
left
|
theorem image_union (f : α → β) (s t : Set α) : f '' (s ∪ t) = f '' s ∪ f '' t :=
ext fun x =>
⟨by rintro ⟨a, h | h, rfl⟩ <;> [
|
Mathlib.Data.Set.Image.336_0.IJFiTzmYGOCpPSd
|
theorem image_union (f : α → β) (s t : Set α) : f '' (s ∪ t) = f '' s ∪ f '' t
|
Mathlib_Data_Set_Image
|
case intro.intro.inr
α : Type u_1
β : Type u_2
γ : Type u_3
ι : Sort u_4
ι' : Sort u_5
f✝ : α → β
s✝ t✝ : Set α
f : α → β
s t : Set α
a : α
h : a ∈ t
⊢ f a ∈ f '' s ∪ f '' t
|
/-
Copyright (c) 2014 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Leonardo de Moura
-/
import Mathlib.Data.Set.Basic
#align_import data.set.image from "leanprover-community/mathlib"@"001ffdc42920050657fd45bd2b8bfbec8eaaeb29"
/-!
# Images and preimages of sets
## Main definitions
* `preimage f t : Set α` : the preimage f⁻¹(t) (written `f ⁻¹' t` in Lean) of a subset of β.
* `range f : Set β` : the image of `univ` under `f`.
Also works for `{p : Prop} (f : p → α)` (unlike `image`)
## Notation
* `f ⁻¹' t` for `Set.preimage f t`
* `f '' s` for `Set.image f s`
## Tags
set, sets, image, preimage, pre-image, range
-/
set_option autoImplicit true
universe u v
open Function Set
namespace Set
variable {α β γ : Type*} {ι ι' : Sort*}
/-! ### Inverse image -/
/-- The preimage of `s : Set β` by `f : α → β`, written `f ⁻¹' s`,
is the set of `x : α` such that `f x ∈ s`. -/
def preimage {α : Type u} {β : Type v} (f : α → β) (s : Set β) : Set α :=
{ x | f x ∈ s }
#align set.preimage Set.preimage
/-- `f ⁻¹' t` denotes the preimage of `t : Set β` under the function `f : α → β`. -/
infixl:80 " ⁻¹' " => preimage
section Preimage
variable {f : α → β} {g : β → γ}
@[simp]
theorem preimage_empty : f ⁻¹' ∅ = ∅ :=
rfl
#align set.preimage_empty Set.preimage_empty
@[simp, mfld_simps]
theorem mem_preimage {s : Set β} {a : α} : a ∈ f ⁻¹' s ↔ f a ∈ s :=
Iff.rfl
#align set.mem_preimage Set.mem_preimage
theorem preimage_congr {f g : α → β} {s : Set β} (h : ∀ x : α, f x = g x) : f ⁻¹' s = g ⁻¹' s := by
congr with x
simp [h]
#align set.preimage_congr Set.preimage_congr
@[gcongr]
theorem preimage_mono {s t : Set β} (h : s ⊆ t) : f ⁻¹' s ⊆ f ⁻¹' t := fun _ hx => h hx
#align set.preimage_mono Set.preimage_mono
@[simp, mfld_simps]
theorem preimage_univ : f ⁻¹' univ = univ :=
rfl
#align set.preimage_univ Set.preimage_univ
theorem subset_preimage_univ {s : Set α} : s ⊆ f ⁻¹' univ :=
subset_univ _
#align set.subset_preimage_univ Set.subset_preimage_univ
@[simp, mfld_simps]
theorem preimage_inter {s t : Set β} : f ⁻¹' (s ∩ t) = f ⁻¹' s ∩ f ⁻¹' t :=
rfl
#align set.preimage_inter Set.preimage_inter
@[simp]
theorem preimage_union {s t : Set β} : f ⁻¹' (s ∪ t) = f ⁻¹' s ∪ f ⁻¹' t :=
rfl
#align set.preimage_union Set.preimage_union
@[simp]
theorem preimage_compl {s : Set β} : f ⁻¹' sᶜ = (f ⁻¹' s)ᶜ :=
rfl
#align set.preimage_compl Set.preimage_compl
@[simp]
theorem preimage_diff (f : α → β) (s t : Set β) : f ⁻¹' (s \ t) = f ⁻¹' s \ f ⁻¹' t :=
rfl
#align set.preimage_diff Set.preimage_diff
@[simp]
lemma preimage_symmDiff {f : α → β} (s t : Set β) : f ⁻¹' (s ∆ t) = (f ⁻¹' s) ∆ (f ⁻¹' t) :=
rfl
#align set.preimage_symm_diff Set.preimage_symmDiff
@[simp]
theorem preimage_ite (f : α → β) (s t₁ t₂ : Set β) :
f ⁻¹' s.ite t₁ t₂ = (f ⁻¹' s).ite (f ⁻¹' t₁) (f ⁻¹' t₂) :=
rfl
#align set.preimage_ite Set.preimage_ite
@[simp]
theorem preimage_setOf_eq {p : α → Prop} {f : β → α} : f ⁻¹' { a | p a } = { a | p (f a) } :=
rfl
#align set.preimage_set_of_eq Set.preimage_setOf_eq
@[simp]
theorem preimage_id_eq : preimage (id : α → α) = id :=
rfl
#align set.preimage_id_eq Set.preimage_id_eq
@[mfld_simps]
theorem preimage_id {s : Set α} : id ⁻¹' s = s :=
rfl
#align set.preimage_id Set.preimage_id
@[simp, mfld_simps]
theorem preimage_id' {s : Set α} : (fun x => x) ⁻¹' s = s :=
rfl
#align set.preimage_id' Set.preimage_id'
@[simp]
theorem preimage_const_of_mem {b : β} {s : Set β} (h : b ∈ s) : (fun _ : α => b) ⁻¹' s = univ :=
eq_univ_of_forall fun _ => h
#align set.preimage_const_of_mem Set.preimage_const_of_mem
@[simp]
theorem preimage_const_of_not_mem {b : β} {s : Set β} (h : b ∉ s) : (fun _ : α => b) ⁻¹' s = ∅ :=
eq_empty_of_subset_empty fun _ hx => h hx
#align set.preimage_const_of_not_mem Set.preimage_const_of_not_mem
theorem preimage_const (b : β) (s : Set β) [Decidable (b ∈ s)] :
(fun _ : α => b) ⁻¹' s = if b ∈ s then univ else ∅ := by
split_ifs with hb
exacts [preimage_const_of_mem hb, preimage_const_of_not_mem hb]
#align set.preimage_const Set.preimage_const
/-- If preimage of each singleton under `f : α → β` is either empty or the whole type,
then `f` is a constant. -/
lemma exists_eq_const_of_preimage_singleton [Nonempty β] {f : α → β}
(hf : ∀ b : β, f ⁻¹' {b} = ∅ ∨ f ⁻¹' {b} = univ) : ∃ b, f = const α b := by
rcases em (∃ b, f ⁻¹' {b} = univ) with ⟨b, hb⟩ | hf'
· exact ⟨b, funext fun x ↦ eq_univ_iff_forall.1 hb x⟩
· have : ∀ x b, f x ≠ b := fun x b ↦
eq_empty_iff_forall_not_mem.1 ((hf b).resolve_right fun h ↦ hf' ⟨b, h⟩) x
exact ⟨Classical.arbitrary β, funext fun x ↦ absurd rfl (this x _)⟩
theorem preimage_comp {s : Set γ} : g ∘ f ⁻¹' s = f ⁻¹' (g ⁻¹' s) :=
rfl
#align set.preimage_comp Set.preimage_comp
theorem preimage_comp_eq : preimage (g ∘ f) = preimage f ∘ preimage g :=
rfl
#align set.preimage_comp_eq Set.preimage_comp_eq
theorem preimage_iterate_eq {f : α → α} {n : ℕ} : Set.preimage f^[n] = (Set.preimage f)^[n] := by
induction' n with n ih; · simp
rw [iterate_succ, iterate_succ', preimage_comp_eq, ih]
#align set.preimage_iterate_eq Set.preimage_iterate_eq
theorem preimage_preimage {g : β → γ} {f : α → β} {s : Set γ} :
f ⁻¹' (g ⁻¹' s) = (fun x => g (f x)) ⁻¹' s :=
preimage_comp.symm
#align set.preimage_preimage Set.preimage_preimage
theorem eq_preimage_subtype_val_iff {p : α → Prop} {s : Set (Subtype p)} {t : Set α} :
s = Subtype.val ⁻¹' t ↔ ∀ (x) (h : p x), (⟨x, h⟩ : Subtype p) ∈ s ↔ x ∈ t :=
⟨fun s_eq x h => by
rw [s_eq]
simp, fun h => ext fun ⟨x, hx⟩ => by simp [h]⟩
#align set.eq_preimage_subtype_val_iff Set.eq_preimage_subtype_val_iff
theorem nonempty_of_nonempty_preimage {s : Set β} {f : α → β} (hf : (f ⁻¹' s).Nonempty) :
s.Nonempty :=
let ⟨x, hx⟩ := hf
⟨f x, hx⟩
#align set.nonempty_of_nonempty_preimage Set.nonempty_of_nonempty_preimage
@[simp] theorem preimage_singleton_true (p : α → Prop) : p ⁻¹' {True} = {a | p a} := by ext; simp
#align set.preimage_singleton_true Set.preimage_singleton_true
@[simp] theorem preimage_singleton_false (p : α → Prop) : p ⁻¹' {False} = {a | ¬p a} := by ext; simp
#align set.preimage_singleton_false Set.preimage_singleton_false
theorem preimage_subtype_coe_eq_compl {s u v : Set α} (hsuv : s ⊆ u ∪ v)
(H : s ∩ (u ∩ v) = ∅) : ((↑) : s → α) ⁻¹' u = ((↑) ⁻¹' v)ᶜ := by
ext ⟨x, x_in_s⟩
constructor
· intro x_in_u x_in_v
exact eq_empty_iff_forall_not_mem.mp H x ⟨x_in_s, ⟨x_in_u, x_in_v⟩⟩
· intro hx
exact Or.elim (hsuv x_in_s) id fun hx' => hx.elim hx'
#align set.preimage_subtype_coe_eq_compl Set.preimage_subtype_coe_eq_compl
end Preimage
/-! ### Image of a set under a function -/
section Image
variable {f : α → β} {s t : Set α}
-- Porting note: `Set.image` is already defined in `Init.Set`
#align set.image Set.image
/-- `f '' s` denotes the image of `s : Set α` under the function `f : α → β`. -/
infixl:80 " '' " => image
theorem mem_image_iff_bex {f : α → β} {s : Set α} {y : β} :
y ∈ f '' s ↔ ∃ (x : _) (_ : x ∈ s), f x = y :=
bex_def.symm
#align set.mem_image_iff_bex Set.mem_image_iff_bex
@[simp]
theorem mem_image (f : α → β) (s : Set α) (y : β) : y ∈ f '' s ↔ ∃ x ∈ s, f x = y :=
Iff.rfl
#align set.mem_image Set.mem_image
theorem image_eta (f : α → β) : f '' s = (fun x => f x) '' s :=
rfl
#align set.image_eta Set.image_eta
@[mfld_simps]
theorem mem_image_of_mem (f : α → β) {x : α} {a : Set α} (h : x ∈ a) : f x ∈ f '' a :=
⟨_, h, rfl⟩
#align set.mem_image_of_mem Set.mem_image_of_mem
theorem _root_.Function.Injective.mem_set_image {f : α → β} (hf : Injective f) {s : Set α} {a : α} :
f a ∈ f '' s ↔ a ∈ s :=
⟨fun ⟨_, hb, Eq⟩ => hf Eq ▸ hb, mem_image_of_mem f⟩
#align function.injective.mem_set_image Function.Injective.mem_set_image
theorem ball_image_iff {f : α → β} {s : Set α} {p : β → Prop} :
(∀ y ∈ f '' s, p y) ↔ ∀ x ∈ s, p (f x) := by simp
#align set.ball_image_iff Set.ball_image_iff
theorem ball_image_of_ball {f : α → β} {s : Set α} {p : β → Prop} (h : ∀ x ∈ s, p (f x)) :
∀ y ∈ f '' s, p y :=
ball_image_iff.2 h
#align set.ball_image_of_ball Set.ball_image_of_ball
theorem bex_image_iff {f : α → β} {s : Set α} {p : β → Prop} :
(∃ y ∈ f '' s, p y) ↔ ∃ x ∈ s, p (f x) := by simp
#align set.bex_image_iff Set.bex_image_iff
theorem mem_image_elim {f : α → β} {s : Set α} {C : β → Prop} (h : ∀ x : α, x ∈ s → C (f x)) :
∀ {y : β}, y ∈ f '' s → C y
| _, ⟨a, a_in, rfl⟩ => h a a_in
#align set.mem_image_elim Set.mem_image_elim
theorem mem_image_elim_on {f : α → β} {s : Set α} {C : β → Prop} {y : β} (h_y : y ∈ f '' s)
(h : ∀ x : α, x ∈ s → C (f x)) : C y :=
mem_image_elim h h_y
#align set.mem_image_elim_on Set.mem_image_elim_on
-- Porting note: used to be `safe`
@[congr]
theorem image_congr {f g : α → β} {s : Set α} (h : ∀ a ∈ s, f a = g a) : f '' s = g '' s := by
ext x
rw [mem_image, mem_image]
exact {
mp := by
rintro ⟨a, ha1, ha2⟩
exact ⟨a, ⟨ha1, (h a ha1) ▸ ha2⟩⟩,
mpr := by
rintro ⟨a, ha1, ha2⟩
exact ⟨a, ⟨ha1, (h a ha1) ▸ ha2⟩⟩
}
-- safe [ext_iff, iff_def]
#align set.image_congr Set.image_congr
/-- A common special case of `image_congr` -/
theorem image_congr' {f g : α → β} {s : Set α} (h : ∀ x : α, f x = g x) : f '' s = g '' s :=
image_congr fun x _ => h x
#align set.image_congr' Set.image_congr'
@[gcongr]
lemma image_mono (h : s ⊆ t) : f '' s ⊆ f '' t := by
rintro - ⟨a, ha, rfl⟩; exact mem_image_of_mem f (h ha)
theorem image_comp (f : β → γ) (g : α → β) (a : Set α) : f ∘ g '' a = f '' (g '' a) :=
Subset.antisymm (ball_image_of_ball fun _ ha => mem_image_of_mem _ <| mem_image_of_mem _ ha)
(ball_image_of_ball <| ball_image_of_ball fun _ ha => mem_image_of_mem _ ha)
#align set.image_comp Set.image_comp
theorem image_comp_eq {g : β → γ} : image (g ∘ f) = image g ∘ image f := by ext; simp
/-- A variant of `image_comp`, useful for rewriting -/
theorem image_image (g : β → γ) (f : α → β) (s : Set α) : g '' (f '' s) = (fun x => g (f x)) '' s :=
(image_comp g f s).symm
#align set.image_image Set.image_image
theorem image_comm {β'} {f : β → γ} {g : α → β} {f' : α → β'} {g' : β' → γ}
(h_comm : ∀ a, f (g a) = g' (f' a)) : (s.image g).image f = (s.image f').image g' := by
simp_rw [image_image, h_comm]
#align set.image_comm Set.image_comm
theorem _root_.Function.Semiconj.set_image {f : α → β} {ga : α → α} {gb : β → β}
(h : Function.Semiconj f ga gb) : Function.Semiconj (image f) (image ga) (image gb) := fun _ =>
image_comm h
#align function.semiconj.set_image Function.Semiconj.set_image
theorem _root_.Function.Commute.set_image {f g : α → α} (h : Function.Commute f g) :
Function.Commute (image f) (image g) :=
Function.Semiconj.set_image h
#align function.commute.set_image Function.Commute.set_image
/-- Image is monotone with respect to `⊆`. See `Set.monotone_image` for the statement in
terms of `≤`. -/
@[gcongr]
theorem image_subset {a b : Set α} (f : α → β) (h : a ⊆ b) : f '' a ⊆ f '' b := by
simp only [subset_def, mem_image]
exact fun x => fun ⟨w, h1, h2⟩ => ⟨w, h h1, h2⟩
#align set.image_subset Set.image_subset
/-- `Set.image` is monotone. See `Set.image_subset` for the statement in terms of `⊆`. -/
lemma monotone_image {f : α → β} : Monotone (image f) := fun _ _ => image_subset _
#align set.monotone_image Set.monotone_image
theorem image_union (f : α → β) (s t : Set α) : f '' (s ∪ t) = f '' s ∪ f '' t :=
ext fun x =>
⟨by rintro ⟨a, h | h, rfl⟩ <;> [left;
|
right
|
theorem image_union (f : α → β) (s t : Set α) : f '' (s ∪ t) = f '' s ∪ f '' t :=
ext fun x =>
⟨by rintro ⟨a, h | h, rfl⟩ <;> [left;
|
Mathlib.Data.Set.Image.336_0.IJFiTzmYGOCpPSd
|
theorem image_union (f : α → β) (s t : Set α) : f '' (s ∪ t) = f '' s ∪ f '' t
|
Mathlib_Data_Set_Image
|
case intro.intro.inl.h
α : Type u_1
β : Type u_2
γ : Type u_3
ι : Sort u_4
ι' : Sort u_5
f✝ : α → β
s✝ t✝ : Set α
f : α → β
s t : Set α
a : α
h : a ∈ s
⊢ f a ∈ f '' s
|
/-
Copyright (c) 2014 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Leonardo de Moura
-/
import Mathlib.Data.Set.Basic
#align_import data.set.image from "leanprover-community/mathlib"@"001ffdc42920050657fd45bd2b8bfbec8eaaeb29"
/-!
# Images and preimages of sets
## Main definitions
* `preimage f t : Set α` : the preimage f⁻¹(t) (written `f ⁻¹' t` in Lean) of a subset of β.
* `range f : Set β` : the image of `univ` under `f`.
Also works for `{p : Prop} (f : p → α)` (unlike `image`)
## Notation
* `f ⁻¹' t` for `Set.preimage f t`
* `f '' s` for `Set.image f s`
## Tags
set, sets, image, preimage, pre-image, range
-/
set_option autoImplicit true
universe u v
open Function Set
namespace Set
variable {α β γ : Type*} {ι ι' : Sort*}
/-! ### Inverse image -/
/-- The preimage of `s : Set β` by `f : α → β`, written `f ⁻¹' s`,
is the set of `x : α` such that `f x ∈ s`. -/
def preimage {α : Type u} {β : Type v} (f : α → β) (s : Set β) : Set α :=
{ x | f x ∈ s }
#align set.preimage Set.preimage
/-- `f ⁻¹' t` denotes the preimage of `t : Set β` under the function `f : α → β`. -/
infixl:80 " ⁻¹' " => preimage
section Preimage
variable {f : α → β} {g : β → γ}
@[simp]
theorem preimage_empty : f ⁻¹' ∅ = ∅ :=
rfl
#align set.preimage_empty Set.preimage_empty
@[simp, mfld_simps]
theorem mem_preimage {s : Set β} {a : α} : a ∈ f ⁻¹' s ↔ f a ∈ s :=
Iff.rfl
#align set.mem_preimage Set.mem_preimage
theorem preimage_congr {f g : α → β} {s : Set β} (h : ∀ x : α, f x = g x) : f ⁻¹' s = g ⁻¹' s := by
congr with x
simp [h]
#align set.preimage_congr Set.preimage_congr
@[gcongr]
theorem preimage_mono {s t : Set β} (h : s ⊆ t) : f ⁻¹' s ⊆ f ⁻¹' t := fun _ hx => h hx
#align set.preimage_mono Set.preimage_mono
@[simp, mfld_simps]
theorem preimage_univ : f ⁻¹' univ = univ :=
rfl
#align set.preimage_univ Set.preimage_univ
theorem subset_preimage_univ {s : Set α} : s ⊆ f ⁻¹' univ :=
subset_univ _
#align set.subset_preimage_univ Set.subset_preimage_univ
@[simp, mfld_simps]
theorem preimage_inter {s t : Set β} : f ⁻¹' (s ∩ t) = f ⁻¹' s ∩ f ⁻¹' t :=
rfl
#align set.preimage_inter Set.preimage_inter
@[simp]
theorem preimage_union {s t : Set β} : f ⁻¹' (s ∪ t) = f ⁻¹' s ∪ f ⁻¹' t :=
rfl
#align set.preimage_union Set.preimage_union
@[simp]
theorem preimage_compl {s : Set β} : f ⁻¹' sᶜ = (f ⁻¹' s)ᶜ :=
rfl
#align set.preimage_compl Set.preimage_compl
@[simp]
theorem preimage_diff (f : α → β) (s t : Set β) : f ⁻¹' (s \ t) = f ⁻¹' s \ f ⁻¹' t :=
rfl
#align set.preimage_diff Set.preimage_diff
@[simp]
lemma preimage_symmDiff {f : α → β} (s t : Set β) : f ⁻¹' (s ∆ t) = (f ⁻¹' s) ∆ (f ⁻¹' t) :=
rfl
#align set.preimage_symm_diff Set.preimage_symmDiff
@[simp]
theorem preimage_ite (f : α → β) (s t₁ t₂ : Set β) :
f ⁻¹' s.ite t₁ t₂ = (f ⁻¹' s).ite (f ⁻¹' t₁) (f ⁻¹' t₂) :=
rfl
#align set.preimage_ite Set.preimage_ite
@[simp]
theorem preimage_setOf_eq {p : α → Prop} {f : β → α} : f ⁻¹' { a | p a } = { a | p (f a) } :=
rfl
#align set.preimage_set_of_eq Set.preimage_setOf_eq
@[simp]
theorem preimage_id_eq : preimage (id : α → α) = id :=
rfl
#align set.preimage_id_eq Set.preimage_id_eq
@[mfld_simps]
theorem preimage_id {s : Set α} : id ⁻¹' s = s :=
rfl
#align set.preimage_id Set.preimage_id
@[simp, mfld_simps]
theorem preimage_id' {s : Set α} : (fun x => x) ⁻¹' s = s :=
rfl
#align set.preimage_id' Set.preimage_id'
@[simp]
theorem preimage_const_of_mem {b : β} {s : Set β} (h : b ∈ s) : (fun _ : α => b) ⁻¹' s = univ :=
eq_univ_of_forall fun _ => h
#align set.preimage_const_of_mem Set.preimage_const_of_mem
@[simp]
theorem preimage_const_of_not_mem {b : β} {s : Set β} (h : b ∉ s) : (fun _ : α => b) ⁻¹' s = ∅ :=
eq_empty_of_subset_empty fun _ hx => h hx
#align set.preimage_const_of_not_mem Set.preimage_const_of_not_mem
theorem preimage_const (b : β) (s : Set β) [Decidable (b ∈ s)] :
(fun _ : α => b) ⁻¹' s = if b ∈ s then univ else ∅ := by
split_ifs with hb
exacts [preimage_const_of_mem hb, preimage_const_of_not_mem hb]
#align set.preimage_const Set.preimage_const
/-- If preimage of each singleton under `f : α → β` is either empty or the whole type,
then `f` is a constant. -/
lemma exists_eq_const_of_preimage_singleton [Nonempty β] {f : α → β}
(hf : ∀ b : β, f ⁻¹' {b} = ∅ ∨ f ⁻¹' {b} = univ) : ∃ b, f = const α b := by
rcases em (∃ b, f ⁻¹' {b} = univ) with ⟨b, hb⟩ | hf'
· exact ⟨b, funext fun x ↦ eq_univ_iff_forall.1 hb x⟩
· have : ∀ x b, f x ≠ b := fun x b ↦
eq_empty_iff_forall_not_mem.1 ((hf b).resolve_right fun h ↦ hf' ⟨b, h⟩) x
exact ⟨Classical.arbitrary β, funext fun x ↦ absurd rfl (this x _)⟩
theorem preimage_comp {s : Set γ} : g ∘ f ⁻¹' s = f ⁻¹' (g ⁻¹' s) :=
rfl
#align set.preimage_comp Set.preimage_comp
theorem preimage_comp_eq : preimage (g ∘ f) = preimage f ∘ preimage g :=
rfl
#align set.preimage_comp_eq Set.preimage_comp_eq
theorem preimage_iterate_eq {f : α → α} {n : ℕ} : Set.preimage f^[n] = (Set.preimage f)^[n] := by
induction' n with n ih; · simp
rw [iterate_succ, iterate_succ', preimage_comp_eq, ih]
#align set.preimage_iterate_eq Set.preimage_iterate_eq
theorem preimage_preimage {g : β → γ} {f : α → β} {s : Set γ} :
f ⁻¹' (g ⁻¹' s) = (fun x => g (f x)) ⁻¹' s :=
preimage_comp.symm
#align set.preimage_preimage Set.preimage_preimage
theorem eq_preimage_subtype_val_iff {p : α → Prop} {s : Set (Subtype p)} {t : Set α} :
s = Subtype.val ⁻¹' t ↔ ∀ (x) (h : p x), (⟨x, h⟩ : Subtype p) ∈ s ↔ x ∈ t :=
⟨fun s_eq x h => by
rw [s_eq]
simp, fun h => ext fun ⟨x, hx⟩ => by simp [h]⟩
#align set.eq_preimage_subtype_val_iff Set.eq_preimage_subtype_val_iff
theorem nonempty_of_nonempty_preimage {s : Set β} {f : α → β} (hf : (f ⁻¹' s).Nonempty) :
s.Nonempty :=
let ⟨x, hx⟩ := hf
⟨f x, hx⟩
#align set.nonempty_of_nonempty_preimage Set.nonempty_of_nonempty_preimage
@[simp] theorem preimage_singleton_true (p : α → Prop) : p ⁻¹' {True} = {a | p a} := by ext; simp
#align set.preimage_singleton_true Set.preimage_singleton_true
@[simp] theorem preimage_singleton_false (p : α → Prop) : p ⁻¹' {False} = {a | ¬p a} := by ext; simp
#align set.preimage_singleton_false Set.preimage_singleton_false
theorem preimage_subtype_coe_eq_compl {s u v : Set α} (hsuv : s ⊆ u ∪ v)
(H : s ∩ (u ∩ v) = ∅) : ((↑) : s → α) ⁻¹' u = ((↑) ⁻¹' v)ᶜ := by
ext ⟨x, x_in_s⟩
constructor
· intro x_in_u x_in_v
exact eq_empty_iff_forall_not_mem.mp H x ⟨x_in_s, ⟨x_in_u, x_in_v⟩⟩
· intro hx
exact Or.elim (hsuv x_in_s) id fun hx' => hx.elim hx'
#align set.preimage_subtype_coe_eq_compl Set.preimage_subtype_coe_eq_compl
end Preimage
/-! ### Image of a set under a function -/
section Image
variable {f : α → β} {s t : Set α}
-- Porting note: `Set.image` is already defined in `Init.Set`
#align set.image Set.image
/-- `f '' s` denotes the image of `s : Set α` under the function `f : α → β`. -/
infixl:80 " '' " => image
theorem mem_image_iff_bex {f : α → β} {s : Set α} {y : β} :
y ∈ f '' s ↔ ∃ (x : _) (_ : x ∈ s), f x = y :=
bex_def.symm
#align set.mem_image_iff_bex Set.mem_image_iff_bex
@[simp]
theorem mem_image (f : α → β) (s : Set α) (y : β) : y ∈ f '' s ↔ ∃ x ∈ s, f x = y :=
Iff.rfl
#align set.mem_image Set.mem_image
theorem image_eta (f : α → β) : f '' s = (fun x => f x) '' s :=
rfl
#align set.image_eta Set.image_eta
@[mfld_simps]
theorem mem_image_of_mem (f : α → β) {x : α} {a : Set α} (h : x ∈ a) : f x ∈ f '' a :=
⟨_, h, rfl⟩
#align set.mem_image_of_mem Set.mem_image_of_mem
theorem _root_.Function.Injective.mem_set_image {f : α → β} (hf : Injective f) {s : Set α} {a : α} :
f a ∈ f '' s ↔ a ∈ s :=
⟨fun ⟨_, hb, Eq⟩ => hf Eq ▸ hb, mem_image_of_mem f⟩
#align function.injective.mem_set_image Function.Injective.mem_set_image
theorem ball_image_iff {f : α → β} {s : Set α} {p : β → Prop} :
(∀ y ∈ f '' s, p y) ↔ ∀ x ∈ s, p (f x) := by simp
#align set.ball_image_iff Set.ball_image_iff
theorem ball_image_of_ball {f : α → β} {s : Set α} {p : β → Prop} (h : ∀ x ∈ s, p (f x)) :
∀ y ∈ f '' s, p y :=
ball_image_iff.2 h
#align set.ball_image_of_ball Set.ball_image_of_ball
theorem bex_image_iff {f : α → β} {s : Set α} {p : β → Prop} :
(∃ y ∈ f '' s, p y) ↔ ∃ x ∈ s, p (f x) := by simp
#align set.bex_image_iff Set.bex_image_iff
theorem mem_image_elim {f : α → β} {s : Set α} {C : β → Prop} (h : ∀ x : α, x ∈ s → C (f x)) :
∀ {y : β}, y ∈ f '' s → C y
| _, ⟨a, a_in, rfl⟩ => h a a_in
#align set.mem_image_elim Set.mem_image_elim
theorem mem_image_elim_on {f : α → β} {s : Set α} {C : β → Prop} {y : β} (h_y : y ∈ f '' s)
(h : ∀ x : α, x ∈ s → C (f x)) : C y :=
mem_image_elim h h_y
#align set.mem_image_elim_on Set.mem_image_elim_on
-- Porting note: used to be `safe`
@[congr]
theorem image_congr {f g : α → β} {s : Set α} (h : ∀ a ∈ s, f a = g a) : f '' s = g '' s := by
ext x
rw [mem_image, mem_image]
exact {
mp := by
rintro ⟨a, ha1, ha2⟩
exact ⟨a, ⟨ha1, (h a ha1) ▸ ha2⟩⟩,
mpr := by
rintro ⟨a, ha1, ha2⟩
exact ⟨a, ⟨ha1, (h a ha1) ▸ ha2⟩⟩
}
-- safe [ext_iff, iff_def]
#align set.image_congr Set.image_congr
/-- A common special case of `image_congr` -/
theorem image_congr' {f g : α → β} {s : Set α} (h : ∀ x : α, f x = g x) : f '' s = g '' s :=
image_congr fun x _ => h x
#align set.image_congr' Set.image_congr'
@[gcongr]
lemma image_mono (h : s ⊆ t) : f '' s ⊆ f '' t := by
rintro - ⟨a, ha, rfl⟩; exact mem_image_of_mem f (h ha)
theorem image_comp (f : β → γ) (g : α → β) (a : Set α) : f ∘ g '' a = f '' (g '' a) :=
Subset.antisymm (ball_image_of_ball fun _ ha => mem_image_of_mem _ <| mem_image_of_mem _ ha)
(ball_image_of_ball <| ball_image_of_ball fun _ ha => mem_image_of_mem _ ha)
#align set.image_comp Set.image_comp
theorem image_comp_eq {g : β → γ} : image (g ∘ f) = image g ∘ image f := by ext; simp
/-- A variant of `image_comp`, useful for rewriting -/
theorem image_image (g : β → γ) (f : α → β) (s : Set α) : g '' (f '' s) = (fun x => g (f x)) '' s :=
(image_comp g f s).symm
#align set.image_image Set.image_image
theorem image_comm {β'} {f : β → γ} {g : α → β} {f' : α → β'} {g' : β' → γ}
(h_comm : ∀ a, f (g a) = g' (f' a)) : (s.image g).image f = (s.image f').image g' := by
simp_rw [image_image, h_comm]
#align set.image_comm Set.image_comm
theorem _root_.Function.Semiconj.set_image {f : α → β} {ga : α → α} {gb : β → β}
(h : Function.Semiconj f ga gb) : Function.Semiconj (image f) (image ga) (image gb) := fun _ =>
image_comm h
#align function.semiconj.set_image Function.Semiconj.set_image
theorem _root_.Function.Commute.set_image {f g : α → α} (h : Function.Commute f g) :
Function.Commute (image f) (image g) :=
Function.Semiconj.set_image h
#align function.commute.set_image Function.Commute.set_image
/-- Image is monotone with respect to `⊆`. See `Set.monotone_image` for the statement in
terms of `≤`. -/
@[gcongr]
theorem image_subset {a b : Set α} (f : α → β) (h : a ⊆ b) : f '' a ⊆ f '' b := by
simp only [subset_def, mem_image]
exact fun x => fun ⟨w, h1, h2⟩ => ⟨w, h h1, h2⟩
#align set.image_subset Set.image_subset
/-- `Set.image` is monotone. See `Set.image_subset` for the statement in terms of `⊆`. -/
lemma monotone_image {f : α → β} : Monotone (image f) := fun _ _ => image_subset _
#align set.monotone_image Set.monotone_image
theorem image_union (f : α → β) (s t : Set α) : f '' (s ∪ t) = f '' s ∪ f '' t :=
ext fun x =>
⟨by rintro ⟨a, h | h, rfl⟩ <;> [left; right] <;>
|
exact ⟨_, h, rfl⟩
|
theorem image_union (f : α → β) (s t : Set α) : f '' (s ∪ t) = f '' s ∪ f '' t :=
ext fun x =>
⟨by rintro ⟨a, h | h, rfl⟩ <;> [left; right] <;>
|
Mathlib.Data.Set.Image.336_0.IJFiTzmYGOCpPSd
|
theorem image_union (f : α → β) (s t : Set α) : f '' (s ∪ t) = f '' s ∪ f '' t
|
Mathlib_Data_Set_Image
|
case intro.intro.inr.h
α : Type u_1
β : Type u_2
γ : Type u_3
ι : Sort u_4
ι' : Sort u_5
f✝ : α → β
s✝ t✝ : Set α
f : α → β
s t : Set α
a : α
h : a ∈ t
⊢ f a ∈ f '' t
|
/-
Copyright (c) 2014 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Leonardo de Moura
-/
import Mathlib.Data.Set.Basic
#align_import data.set.image from "leanprover-community/mathlib"@"001ffdc42920050657fd45bd2b8bfbec8eaaeb29"
/-!
# Images and preimages of sets
## Main definitions
* `preimage f t : Set α` : the preimage f⁻¹(t) (written `f ⁻¹' t` in Lean) of a subset of β.
* `range f : Set β` : the image of `univ` under `f`.
Also works for `{p : Prop} (f : p → α)` (unlike `image`)
## Notation
* `f ⁻¹' t` for `Set.preimage f t`
* `f '' s` for `Set.image f s`
## Tags
set, sets, image, preimage, pre-image, range
-/
set_option autoImplicit true
universe u v
open Function Set
namespace Set
variable {α β γ : Type*} {ι ι' : Sort*}
/-! ### Inverse image -/
/-- The preimage of `s : Set β` by `f : α → β`, written `f ⁻¹' s`,
is the set of `x : α` such that `f x ∈ s`. -/
def preimage {α : Type u} {β : Type v} (f : α → β) (s : Set β) : Set α :=
{ x | f x ∈ s }
#align set.preimage Set.preimage
/-- `f ⁻¹' t` denotes the preimage of `t : Set β` under the function `f : α → β`. -/
infixl:80 " ⁻¹' " => preimage
section Preimage
variable {f : α → β} {g : β → γ}
@[simp]
theorem preimage_empty : f ⁻¹' ∅ = ∅ :=
rfl
#align set.preimage_empty Set.preimage_empty
@[simp, mfld_simps]
theorem mem_preimage {s : Set β} {a : α} : a ∈ f ⁻¹' s ↔ f a ∈ s :=
Iff.rfl
#align set.mem_preimage Set.mem_preimage
theorem preimage_congr {f g : α → β} {s : Set β} (h : ∀ x : α, f x = g x) : f ⁻¹' s = g ⁻¹' s := by
congr with x
simp [h]
#align set.preimage_congr Set.preimage_congr
@[gcongr]
theorem preimage_mono {s t : Set β} (h : s ⊆ t) : f ⁻¹' s ⊆ f ⁻¹' t := fun _ hx => h hx
#align set.preimage_mono Set.preimage_mono
@[simp, mfld_simps]
theorem preimage_univ : f ⁻¹' univ = univ :=
rfl
#align set.preimage_univ Set.preimage_univ
theorem subset_preimage_univ {s : Set α} : s ⊆ f ⁻¹' univ :=
subset_univ _
#align set.subset_preimage_univ Set.subset_preimage_univ
@[simp, mfld_simps]
theorem preimage_inter {s t : Set β} : f ⁻¹' (s ∩ t) = f ⁻¹' s ∩ f ⁻¹' t :=
rfl
#align set.preimage_inter Set.preimage_inter
@[simp]
theorem preimage_union {s t : Set β} : f ⁻¹' (s ∪ t) = f ⁻¹' s ∪ f ⁻¹' t :=
rfl
#align set.preimage_union Set.preimage_union
@[simp]
theorem preimage_compl {s : Set β} : f ⁻¹' sᶜ = (f ⁻¹' s)ᶜ :=
rfl
#align set.preimage_compl Set.preimage_compl
@[simp]
theorem preimage_diff (f : α → β) (s t : Set β) : f ⁻¹' (s \ t) = f ⁻¹' s \ f ⁻¹' t :=
rfl
#align set.preimage_diff Set.preimage_diff
@[simp]
lemma preimage_symmDiff {f : α → β} (s t : Set β) : f ⁻¹' (s ∆ t) = (f ⁻¹' s) ∆ (f ⁻¹' t) :=
rfl
#align set.preimage_symm_diff Set.preimage_symmDiff
@[simp]
theorem preimage_ite (f : α → β) (s t₁ t₂ : Set β) :
f ⁻¹' s.ite t₁ t₂ = (f ⁻¹' s).ite (f ⁻¹' t₁) (f ⁻¹' t₂) :=
rfl
#align set.preimage_ite Set.preimage_ite
@[simp]
theorem preimage_setOf_eq {p : α → Prop} {f : β → α} : f ⁻¹' { a | p a } = { a | p (f a) } :=
rfl
#align set.preimage_set_of_eq Set.preimage_setOf_eq
@[simp]
theorem preimage_id_eq : preimage (id : α → α) = id :=
rfl
#align set.preimage_id_eq Set.preimage_id_eq
@[mfld_simps]
theorem preimage_id {s : Set α} : id ⁻¹' s = s :=
rfl
#align set.preimage_id Set.preimage_id
@[simp, mfld_simps]
theorem preimage_id' {s : Set α} : (fun x => x) ⁻¹' s = s :=
rfl
#align set.preimage_id' Set.preimage_id'
@[simp]
theorem preimage_const_of_mem {b : β} {s : Set β} (h : b ∈ s) : (fun _ : α => b) ⁻¹' s = univ :=
eq_univ_of_forall fun _ => h
#align set.preimage_const_of_mem Set.preimage_const_of_mem
@[simp]
theorem preimage_const_of_not_mem {b : β} {s : Set β} (h : b ∉ s) : (fun _ : α => b) ⁻¹' s = ∅ :=
eq_empty_of_subset_empty fun _ hx => h hx
#align set.preimage_const_of_not_mem Set.preimage_const_of_not_mem
theorem preimage_const (b : β) (s : Set β) [Decidable (b ∈ s)] :
(fun _ : α => b) ⁻¹' s = if b ∈ s then univ else ∅ := by
split_ifs with hb
exacts [preimage_const_of_mem hb, preimage_const_of_not_mem hb]
#align set.preimage_const Set.preimage_const
/-- If preimage of each singleton under `f : α → β` is either empty or the whole type,
then `f` is a constant. -/
lemma exists_eq_const_of_preimage_singleton [Nonempty β] {f : α → β}
(hf : ∀ b : β, f ⁻¹' {b} = ∅ ∨ f ⁻¹' {b} = univ) : ∃ b, f = const α b := by
rcases em (∃ b, f ⁻¹' {b} = univ) with ⟨b, hb⟩ | hf'
· exact ⟨b, funext fun x ↦ eq_univ_iff_forall.1 hb x⟩
· have : ∀ x b, f x ≠ b := fun x b ↦
eq_empty_iff_forall_not_mem.1 ((hf b).resolve_right fun h ↦ hf' ⟨b, h⟩) x
exact ⟨Classical.arbitrary β, funext fun x ↦ absurd rfl (this x _)⟩
theorem preimage_comp {s : Set γ} : g ∘ f ⁻¹' s = f ⁻¹' (g ⁻¹' s) :=
rfl
#align set.preimage_comp Set.preimage_comp
theorem preimage_comp_eq : preimage (g ∘ f) = preimage f ∘ preimage g :=
rfl
#align set.preimage_comp_eq Set.preimage_comp_eq
theorem preimage_iterate_eq {f : α → α} {n : ℕ} : Set.preimage f^[n] = (Set.preimage f)^[n] := by
induction' n with n ih; · simp
rw [iterate_succ, iterate_succ', preimage_comp_eq, ih]
#align set.preimage_iterate_eq Set.preimage_iterate_eq
theorem preimage_preimage {g : β → γ} {f : α → β} {s : Set γ} :
f ⁻¹' (g ⁻¹' s) = (fun x => g (f x)) ⁻¹' s :=
preimage_comp.symm
#align set.preimage_preimage Set.preimage_preimage
theorem eq_preimage_subtype_val_iff {p : α → Prop} {s : Set (Subtype p)} {t : Set α} :
s = Subtype.val ⁻¹' t ↔ ∀ (x) (h : p x), (⟨x, h⟩ : Subtype p) ∈ s ↔ x ∈ t :=
⟨fun s_eq x h => by
rw [s_eq]
simp, fun h => ext fun ⟨x, hx⟩ => by simp [h]⟩
#align set.eq_preimage_subtype_val_iff Set.eq_preimage_subtype_val_iff
theorem nonempty_of_nonempty_preimage {s : Set β} {f : α → β} (hf : (f ⁻¹' s).Nonempty) :
s.Nonempty :=
let ⟨x, hx⟩ := hf
⟨f x, hx⟩
#align set.nonempty_of_nonempty_preimage Set.nonempty_of_nonempty_preimage
@[simp] theorem preimage_singleton_true (p : α → Prop) : p ⁻¹' {True} = {a | p a} := by ext; simp
#align set.preimage_singleton_true Set.preimage_singleton_true
@[simp] theorem preimage_singleton_false (p : α → Prop) : p ⁻¹' {False} = {a | ¬p a} := by ext; simp
#align set.preimage_singleton_false Set.preimage_singleton_false
theorem preimage_subtype_coe_eq_compl {s u v : Set α} (hsuv : s ⊆ u ∪ v)
(H : s ∩ (u ∩ v) = ∅) : ((↑) : s → α) ⁻¹' u = ((↑) ⁻¹' v)ᶜ := by
ext ⟨x, x_in_s⟩
constructor
· intro x_in_u x_in_v
exact eq_empty_iff_forall_not_mem.mp H x ⟨x_in_s, ⟨x_in_u, x_in_v⟩⟩
· intro hx
exact Or.elim (hsuv x_in_s) id fun hx' => hx.elim hx'
#align set.preimage_subtype_coe_eq_compl Set.preimage_subtype_coe_eq_compl
end Preimage
/-! ### Image of a set under a function -/
section Image
variable {f : α → β} {s t : Set α}
-- Porting note: `Set.image` is already defined in `Init.Set`
#align set.image Set.image
/-- `f '' s` denotes the image of `s : Set α` under the function `f : α → β`. -/
infixl:80 " '' " => image
theorem mem_image_iff_bex {f : α → β} {s : Set α} {y : β} :
y ∈ f '' s ↔ ∃ (x : _) (_ : x ∈ s), f x = y :=
bex_def.symm
#align set.mem_image_iff_bex Set.mem_image_iff_bex
@[simp]
theorem mem_image (f : α → β) (s : Set α) (y : β) : y ∈ f '' s ↔ ∃ x ∈ s, f x = y :=
Iff.rfl
#align set.mem_image Set.mem_image
theorem image_eta (f : α → β) : f '' s = (fun x => f x) '' s :=
rfl
#align set.image_eta Set.image_eta
@[mfld_simps]
theorem mem_image_of_mem (f : α → β) {x : α} {a : Set α} (h : x ∈ a) : f x ∈ f '' a :=
⟨_, h, rfl⟩
#align set.mem_image_of_mem Set.mem_image_of_mem
theorem _root_.Function.Injective.mem_set_image {f : α → β} (hf : Injective f) {s : Set α} {a : α} :
f a ∈ f '' s ↔ a ∈ s :=
⟨fun ⟨_, hb, Eq⟩ => hf Eq ▸ hb, mem_image_of_mem f⟩
#align function.injective.mem_set_image Function.Injective.mem_set_image
theorem ball_image_iff {f : α → β} {s : Set α} {p : β → Prop} :
(∀ y ∈ f '' s, p y) ↔ ∀ x ∈ s, p (f x) := by simp
#align set.ball_image_iff Set.ball_image_iff
theorem ball_image_of_ball {f : α → β} {s : Set α} {p : β → Prop} (h : ∀ x ∈ s, p (f x)) :
∀ y ∈ f '' s, p y :=
ball_image_iff.2 h
#align set.ball_image_of_ball Set.ball_image_of_ball
theorem bex_image_iff {f : α → β} {s : Set α} {p : β → Prop} :
(∃ y ∈ f '' s, p y) ↔ ∃ x ∈ s, p (f x) := by simp
#align set.bex_image_iff Set.bex_image_iff
theorem mem_image_elim {f : α → β} {s : Set α} {C : β → Prop} (h : ∀ x : α, x ∈ s → C (f x)) :
∀ {y : β}, y ∈ f '' s → C y
| _, ⟨a, a_in, rfl⟩ => h a a_in
#align set.mem_image_elim Set.mem_image_elim
theorem mem_image_elim_on {f : α → β} {s : Set α} {C : β → Prop} {y : β} (h_y : y ∈ f '' s)
(h : ∀ x : α, x ∈ s → C (f x)) : C y :=
mem_image_elim h h_y
#align set.mem_image_elim_on Set.mem_image_elim_on
-- Porting note: used to be `safe`
@[congr]
theorem image_congr {f g : α → β} {s : Set α} (h : ∀ a ∈ s, f a = g a) : f '' s = g '' s := by
ext x
rw [mem_image, mem_image]
exact {
mp := by
rintro ⟨a, ha1, ha2⟩
exact ⟨a, ⟨ha1, (h a ha1) ▸ ha2⟩⟩,
mpr := by
rintro ⟨a, ha1, ha2⟩
exact ⟨a, ⟨ha1, (h a ha1) ▸ ha2⟩⟩
}
-- safe [ext_iff, iff_def]
#align set.image_congr Set.image_congr
/-- A common special case of `image_congr` -/
theorem image_congr' {f g : α → β} {s : Set α} (h : ∀ x : α, f x = g x) : f '' s = g '' s :=
image_congr fun x _ => h x
#align set.image_congr' Set.image_congr'
@[gcongr]
lemma image_mono (h : s ⊆ t) : f '' s ⊆ f '' t := by
rintro - ⟨a, ha, rfl⟩; exact mem_image_of_mem f (h ha)
theorem image_comp (f : β → γ) (g : α → β) (a : Set α) : f ∘ g '' a = f '' (g '' a) :=
Subset.antisymm (ball_image_of_ball fun _ ha => mem_image_of_mem _ <| mem_image_of_mem _ ha)
(ball_image_of_ball <| ball_image_of_ball fun _ ha => mem_image_of_mem _ ha)
#align set.image_comp Set.image_comp
theorem image_comp_eq {g : β → γ} : image (g ∘ f) = image g ∘ image f := by ext; simp
/-- A variant of `image_comp`, useful for rewriting -/
theorem image_image (g : β → γ) (f : α → β) (s : Set α) : g '' (f '' s) = (fun x => g (f x)) '' s :=
(image_comp g f s).symm
#align set.image_image Set.image_image
theorem image_comm {β'} {f : β → γ} {g : α → β} {f' : α → β'} {g' : β' → γ}
(h_comm : ∀ a, f (g a) = g' (f' a)) : (s.image g).image f = (s.image f').image g' := by
simp_rw [image_image, h_comm]
#align set.image_comm Set.image_comm
theorem _root_.Function.Semiconj.set_image {f : α → β} {ga : α → α} {gb : β → β}
(h : Function.Semiconj f ga gb) : Function.Semiconj (image f) (image ga) (image gb) := fun _ =>
image_comm h
#align function.semiconj.set_image Function.Semiconj.set_image
theorem _root_.Function.Commute.set_image {f g : α → α} (h : Function.Commute f g) :
Function.Commute (image f) (image g) :=
Function.Semiconj.set_image h
#align function.commute.set_image Function.Commute.set_image
/-- Image is monotone with respect to `⊆`. See `Set.monotone_image` for the statement in
terms of `≤`. -/
@[gcongr]
theorem image_subset {a b : Set α} (f : α → β) (h : a ⊆ b) : f '' a ⊆ f '' b := by
simp only [subset_def, mem_image]
exact fun x => fun ⟨w, h1, h2⟩ => ⟨w, h h1, h2⟩
#align set.image_subset Set.image_subset
/-- `Set.image` is monotone. See `Set.image_subset` for the statement in terms of `⊆`. -/
lemma monotone_image {f : α → β} : Monotone (image f) := fun _ _ => image_subset _
#align set.monotone_image Set.monotone_image
theorem image_union (f : α → β) (s t : Set α) : f '' (s ∪ t) = f '' s ∪ f '' t :=
ext fun x =>
⟨by rintro ⟨a, h | h, rfl⟩ <;> [left; right] <;>
|
exact ⟨_, h, rfl⟩
|
theorem image_union (f : α → β) (s t : Set α) : f '' (s ∪ t) = f '' s ∪ f '' t :=
ext fun x =>
⟨by rintro ⟨a, h | h, rfl⟩ <;> [left; right] <;>
|
Mathlib.Data.Set.Image.336_0.IJFiTzmYGOCpPSd
|
theorem image_union (f : α → β) (s t : Set α) : f '' (s ∪ t) = f '' s ∪ f '' t
|
Mathlib_Data_Set_Image
|
α : Type u_1
β : Type u_2
γ : Type u_3
ι : Sort u_4
ι' : Sort u_5
f✝ : α → β
s✝ t✝ : Set α
f : α → β
s t : Set α
x : β
⊢ x ∈ f '' s ∪ f '' t → x ∈ f '' (s ∪ t)
|
/-
Copyright (c) 2014 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Leonardo de Moura
-/
import Mathlib.Data.Set.Basic
#align_import data.set.image from "leanprover-community/mathlib"@"001ffdc42920050657fd45bd2b8bfbec8eaaeb29"
/-!
# Images and preimages of sets
## Main definitions
* `preimage f t : Set α` : the preimage f⁻¹(t) (written `f ⁻¹' t` in Lean) of a subset of β.
* `range f : Set β` : the image of `univ` under `f`.
Also works for `{p : Prop} (f : p → α)` (unlike `image`)
## Notation
* `f ⁻¹' t` for `Set.preimage f t`
* `f '' s` for `Set.image f s`
## Tags
set, sets, image, preimage, pre-image, range
-/
set_option autoImplicit true
universe u v
open Function Set
namespace Set
variable {α β γ : Type*} {ι ι' : Sort*}
/-! ### Inverse image -/
/-- The preimage of `s : Set β` by `f : α → β`, written `f ⁻¹' s`,
is the set of `x : α` such that `f x ∈ s`. -/
def preimage {α : Type u} {β : Type v} (f : α → β) (s : Set β) : Set α :=
{ x | f x ∈ s }
#align set.preimage Set.preimage
/-- `f ⁻¹' t` denotes the preimage of `t : Set β` under the function `f : α → β`. -/
infixl:80 " ⁻¹' " => preimage
section Preimage
variable {f : α → β} {g : β → γ}
@[simp]
theorem preimage_empty : f ⁻¹' ∅ = ∅ :=
rfl
#align set.preimage_empty Set.preimage_empty
@[simp, mfld_simps]
theorem mem_preimage {s : Set β} {a : α} : a ∈ f ⁻¹' s ↔ f a ∈ s :=
Iff.rfl
#align set.mem_preimage Set.mem_preimage
theorem preimage_congr {f g : α → β} {s : Set β} (h : ∀ x : α, f x = g x) : f ⁻¹' s = g ⁻¹' s := by
congr with x
simp [h]
#align set.preimage_congr Set.preimage_congr
@[gcongr]
theorem preimage_mono {s t : Set β} (h : s ⊆ t) : f ⁻¹' s ⊆ f ⁻¹' t := fun _ hx => h hx
#align set.preimage_mono Set.preimage_mono
@[simp, mfld_simps]
theorem preimage_univ : f ⁻¹' univ = univ :=
rfl
#align set.preimage_univ Set.preimage_univ
theorem subset_preimage_univ {s : Set α} : s ⊆ f ⁻¹' univ :=
subset_univ _
#align set.subset_preimage_univ Set.subset_preimage_univ
@[simp, mfld_simps]
theorem preimage_inter {s t : Set β} : f ⁻¹' (s ∩ t) = f ⁻¹' s ∩ f ⁻¹' t :=
rfl
#align set.preimage_inter Set.preimage_inter
@[simp]
theorem preimage_union {s t : Set β} : f ⁻¹' (s ∪ t) = f ⁻¹' s ∪ f ⁻¹' t :=
rfl
#align set.preimage_union Set.preimage_union
@[simp]
theorem preimage_compl {s : Set β} : f ⁻¹' sᶜ = (f ⁻¹' s)ᶜ :=
rfl
#align set.preimage_compl Set.preimage_compl
@[simp]
theorem preimage_diff (f : α → β) (s t : Set β) : f ⁻¹' (s \ t) = f ⁻¹' s \ f ⁻¹' t :=
rfl
#align set.preimage_diff Set.preimage_diff
@[simp]
lemma preimage_symmDiff {f : α → β} (s t : Set β) : f ⁻¹' (s ∆ t) = (f ⁻¹' s) ∆ (f ⁻¹' t) :=
rfl
#align set.preimage_symm_diff Set.preimage_symmDiff
@[simp]
theorem preimage_ite (f : α → β) (s t₁ t₂ : Set β) :
f ⁻¹' s.ite t₁ t₂ = (f ⁻¹' s).ite (f ⁻¹' t₁) (f ⁻¹' t₂) :=
rfl
#align set.preimage_ite Set.preimage_ite
@[simp]
theorem preimage_setOf_eq {p : α → Prop} {f : β → α} : f ⁻¹' { a | p a } = { a | p (f a) } :=
rfl
#align set.preimage_set_of_eq Set.preimage_setOf_eq
@[simp]
theorem preimage_id_eq : preimage (id : α → α) = id :=
rfl
#align set.preimage_id_eq Set.preimage_id_eq
@[mfld_simps]
theorem preimage_id {s : Set α} : id ⁻¹' s = s :=
rfl
#align set.preimage_id Set.preimage_id
@[simp, mfld_simps]
theorem preimage_id' {s : Set α} : (fun x => x) ⁻¹' s = s :=
rfl
#align set.preimage_id' Set.preimage_id'
@[simp]
theorem preimage_const_of_mem {b : β} {s : Set β} (h : b ∈ s) : (fun _ : α => b) ⁻¹' s = univ :=
eq_univ_of_forall fun _ => h
#align set.preimage_const_of_mem Set.preimage_const_of_mem
@[simp]
theorem preimage_const_of_not_mem {b : β} {s : Set β} (h : b ∉ s) : (fun _ : α => b) ⁻¹' s = ∅ :=
eq_empty_of_subset_empty fun _ hx => h hx
#align set.preimage_const_of_not_mem Set.preimage_const_of_not_mem
theorem preimage_const (b : β) (s : Set β) [Decidable (b ∈ s)] :
(fun _ : α => b) ⁻¹' s = if b ∈ s then univ else ∅ := by
split_ifs with hb
exacts [preimage_const_of_mem hb, preimage_const_of_not_mem hb]
#align set.preimage_const Set.preimage_const
/-- If preimage of each singleton under `f : α → β` is either empty or the whole type,
then `f` is a constant. -/
lemma exists_eq_const_of_preimage_singleton [Nonempty β] {f : α → β}
(hf : ∀ b : β, f ⁻¹' {b} = ∅ ∨ f ⁻¹' {b} = univ) : ∃ b, f = const α b := by
rcases em (∃ b, f ⁻¹' {b} = univ) with ⟨b, hb⟩ | hf'
· exact ⟨b, funext fun x ↦ eq_univ_iff_forall.1 hb x⟩
· have : ∀ x b, f x ≠ b := fun x b ↦
eq_empty_iff_forall_not_mem.1 ((hf b).resolve_right fun h ↦ hf' ⟨b, h⟩) x
exact ⟨Classical.arbitrary β, funext fun x ↦ absurd rfl (this x _)⟩
theorem preimage_comp {s : Set γ} : g ∘ f ⁻¹' s = f ⁻¹' (g ⁻¹' s) :=
rfl
#align set.preimage_comp Set.preimage_comp
theorem preimage_comp_eq : preimage (g ∘ f) = preimage f ∘ preimage g :=
rfl
#align set.preimage_comp_eq Set.preimage_comp_eq
theorem preimage_iterate_eq {f : α → α} {n : ℕ} : Set.preimage f^[n] = (Set.preimage f)^[n] := by
induction' n with n ih; · simp
rw [iterate_succ, iterate_succ', preimage_comp_eq, ih]
#align set.preimage_iterate_eq Set.preimage_iterate_eq
theorem preimage_preimage {g : β → γ} {f : α → β} {s : Set γ} :
f ⁻¹' (g ⁻¹' s) = (fun x => g (f x)) ⁻¹' s :=
preimage_comp.symm
#align set.preimage_preimage Set.preimage_preimage
theorem eq_preimage_subtype_val_iff {p : α → Prop} {s : Set (Subtype p)} {t : Set α} :
s = Subtype.val ⁻¹' t ↔ ∀ (x) (h : p x), (⟨x, h⟩ : Subtype p) ∈ s ↔ x ∈ t :=
⟨fun s_eq x h => by
rw [s_eq]
simp, fun h => ext fun ⟨x, hx⟩ => by simp [h]⟩
#align set.eq_preimage_subtype_val_iff Set.eq_preimage_subtype_val_iff
theorem nonempty_of_nonempty_preimage {s : Set β} {f : α → β} (hf : (f ⁻¹' s).Nonempty) :
s.Nonempty :=
let ⟨x, hx⟩ := hf
⟨f x, hx⟩
#align set.nonempty_of_nonempty_preimage Set.nonempty_of_nonempty_preimage
@[simp] theorem preimage_singleton_true (p : α → Prop) : p ⁻¹' {True} = {a | p a} := by ext; simp
#align set.preimage_singleton_true Set.preimage_singleton_true
@[simp] theorem preimage_singleton_false (p : α → Prop) : p ⁻¹' {False} = {a | ¬p a} := by ext; simp
#align set.preimage_singleton_false Set.preimage_singleton_false
theorem preimage_subtype_coe_eq_compl {s u v : Set α} (hsuv : s ⊆ u ∪ v)
(H : s ∩ (u ∩ v) = ∅) : ((↑) : s → α) ⁻¹' u = ((↑) ⁻¹' v)ᶜ := by
ext ⟨x, x_in_s⟩
constructor
· intro x_in_u x_in_v
exact eq_empty_iff_forall_not_mem.mp H x ⟨x_in_s, ⟨x_in_u, x_in_v⟩⟩
· intro hx
exact Or.elim (hsuv x_in_s) id fun hx' => hx.elim hx'
#align set.preimage_subtype_coe_eq_compl Set.preimage_subtype_coe_eq_compl
end Preimage
/-! ### Image of a set under a function -/
section Image
variable {f : α → β} {s t : Set α}
-- Porting note: `Set.image` is already defined in `Init.Set`
#align set.image Set.image
/-- `f '' s` denotes the image of `s : Set α` under the function `f : α → β`. -/
infixl:80 " '' " => image
theorem mem_image_iff_bex {f : α → β} {s : Set α} {y : β} :
y ∈ f '' s ↔ ∃ (x : _) (_ : x ∈ s), f x = y :=
bex_def.symm
#align set.mem_image_iff_bex Set.mem_image_iff_bex
@[simp]
theorem mem_image (f : α → β) (s : Set α) (y : β) : y ∈ f '' s ↔ ∃ x ∈ s, f x = y :=
Iff.rfl
#align set.mem_image Set.mem_image
theorem image_eta (f : α → β) : f '' s = (fun x => f x) '' s :=
rfl
#align set.image_eta Set.image_eta
@[mfld_simps]
theorem mem_image_of_mem (f : α → β) {x : α} {a : Set α} (h : x ∈ a) : f x ∈ f '' a :=
⟨_, h, rfl⟩
#align set.mem_image_of_mem Set.mem_image_of_mem
theorem _root_.Function.Injective.mem_set_image {f : α → β} (hf : Injective f) {s : Set α} {a : α} :
f a ∈ f '' s ↔ a ∈ s :=
⟨fun ⟨_, hb, Eq⟩ => hf Eq ▸ hb, mem_image_of_mem f⟩
#align function.injective.mem_set_image Function.Injective.mem_set_image
theorem ball_image_iff {f : α → β} {s : Set α} {p : β → Prop} :
(∀ y ∈ f '' s, p y) ↔ ∀ x ∈ s, p (f x) := by simp
#align set.ball_image_iff Set.ball_image_iff
theorem ball_image_of_ball {f : α → β} {s : Set α} {p : β → Prop} (h : ∀ x ∈ s, p (f x)) :
∀ y ∈ f '' s, p y :=
ball_image_iff.2 h
#align set.ball_image_of_ball Set.ball_image_of_ball
theorem bex_image_iff {f : α → β} {s : Set α} {p : β → Prop} :
(∃ y ∈ f '' s, p y) ↔ ∃ x ∈ s, p (f x) := by simp
#align set.bex_image_iff Set.bex_image_iff
theorem mem_image_elim {f : α → β} {s : Set α} {C : β → Prop} (h : ∀ x : α, x ∈ s → C (f x)) :
∀ {y : β}, y ∈ f '' s → C y
| _, ⟨a, a_in, rfl⟩ => h a a_in
#align set.mem_image_elim Set.mem_image_elim
theorem mem_image_elim_on {f : α → β} {s : Set α} {C : β → Prop} {y : β} (h_y : y ∈ f '' s)
(h : ∀ x : α, x ∈ s → C (f x)) : C y :=
mem_image_elim h h_y
#align set.mem_image_elim_on Set.mem_image_elim_on
-- Porting note: used to be `safe`
@[congr]
theorem image_congr {f g : α → β} {s : Set α} (h : ∀ a ∈ s, f a = g a) : f '' s = g '' s := by
ext x
rw [mem_image, mem_image]
exact {
mp := by
rintro ⟨a, ha1, ha2⟩
exact ⟨a, ⟨ha1, (h a ha1) ▸ ha2⟩⟩,
mpr := by
rintro ⟨a, ha1, ha2⟩
exact ⟨a, ⟨ha1, (h a ha1) ▸ ha2⟩⟩
}
-- safe [ext_iff, iff_def]
#align set.image_congr Set.image_congr
/-- A common special case of `image_congr` -/
theorem image_congr' {f g : α → β} {s : Set α} (h : ∀ x : α, f x = g x) : f '' s = g '' s :=
image_congr fun x _ => h x
#align set.image_congr' Set.image_congr'
@[gcongr]
lemma image_mono (h : s ⊆ t) : f '' s ⊆ f '' t := by
rintro - ⟨a, ha, rfl⟩; exact mem_image_of_mem f (h ha)
theorem image_comp (f : β → γ) (g : α → β) (a : Set α) : f ∘ g '' a = f '' (g '' a) :=
Subset.antisymm (ball_image_of_ball fun _ ha => mem_image_of_mem _ <| mem_image_of_mem _ ha)
(ball_image_of_ball <| ball_image_of_ball fun _ ha => mem_image_of_mem _ ha)
#align set.image_comp Set.image_comp
theorem image_comp_eq {g : β → γ} : image (g ∘ f) = image g ∘ image f := by ext; simp
/-- A variant of `image_comp`, useful for rewriting -/
theorem image_image (g : β → γ) (f : α → β) (s : Set α) : g '' (f '' s) = (fun x => g (f x)) '' s :=
(image_comp g f s).symm
#align set.image_image Set.image_image
theorem image_comm {β'} {f : β → γ} {g : α → β} {f' : α → β'} {g' : β' → γ}
(h_comm : ∀ a, f (g a) = g' (f' a)) : (s.image g).image f = (s.image f').image g' := by
simp_rw [image_image, h_comm]
#align set.image_comm Set.image_comm
theorem _root_.Function.Semiconj.set_image {f : α → β} {ga : α → α} {gb : β → β}
(h : Function.Semiconj f ga gb) : Function.Semiconj (image f) (image ga) (image gb) := fun _ =>
image_comm h
#align function.semiconj.set_image Function.Semiconj.set_image
theorem _root_.Function.Commute.set_image {f g : α → α} (h : Function.Commute f g) :
Function.Commute (image f) (image g) :=
Function.Semiconj.set_image h
#align function.commute.set_image Function.Commute.set_image
/-- Image is monotone with respect to `⊆`. See `Set.monotone_image` for the statement in
terms of `≤`. -/
@[gcongr]
theorem image_subset {a b : Set α} (f : α → β) (h : a ⊆ b) : f '' a ⊆ f '' b := by
simp only [subset_def, mem_image]
exact fun x => fun ⟨w, h1, h2⟩ => ⟨w, h h1, h2⟩
#align set.image_subset Set.image_subset
/-- `Set.image` is monotone. See `Set.image_subset` for the statement in terms of `⊆`. -/
lemma monotone_image {f : α → β} : Monotone (image f) := fun _ _ => image_subset _
#align set.monotone_image Set.monotone_image
theorem image_union (f : α → β) (s t : Set α) : f '' (s ∪ t) = f '' s ∪ f '' t :=
ext fun x =>
⟨by rintro ⟨a, h | h, rfl⟩ <;> [left; right] <;> exact ⟨_, h, rfl⟩, by
|
rintro (⟨a, h, rfl⟩ | ⟨a, h, rfl⟩) <;> refine' ⟨_, _, rfl⟩ <;> [left; right]
|
theorem image_union (f : α → β) (s t : Set α) : f '' (s ∪ t) = f '' s ∪ f '' t :=
ext fun x =>
⟨by rintro ⟨a, h | h, rfl⟩ <;> [left; right] <;> exact ⟨_, h, rfl⟩, by
|
Mathlib.Data.Set.Image.336_0.IJFiTzmYGOCpPSd
|
theorem image_union (f : α → β) (s t : Set α) : f '' (s ∪ t) = f '' s ∪ f '' t
|
Mathlib_Data_Set_Image
|
α : Type u_1
β : Type u_2
γ : Type u_3
ι : Sort u_4
ι' : Sort u_5
f✝ : α → β
s✝ t✝ : Set α
f : α → β
s t : Set α
x : β
⊢ x ∈ f '' s ∪ f '' t → x ∈ f '' (s ∪ t)
|
/-
Copyright (c) 2014 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Leonardo de Moura
-/
import Mathlib.Data.Set.Basic
#align_import data.set.image from "leanprover-community/mathlib"@"001ffdc42920050657fd45bd2b8bfbec8eaaeb29"
/-!
# Images and preimages of sets
## Main definitions
* `preimage f t : Set α` : the preimage f⁻¹(t) (written `f ⁻¹' t` in Lean) of a subset of β.
* `range f : Set β` : the image of `univ` under `f`.
Also works for `{p : Prop} (f : p → α)` (unlike `image`)
## Notation
* `f ⁻¹' t` for `Set.preimage f t`
* `f '' s` for `Set.image f s`
## Tags
set, sets, image, preimage, pre-image, range
-/
set_option autoImplicit true
universe u v
open Function Set
namespace Set
variable {α β γ : Type*} {ι ι' : Sort*}
/-! ### Inverse image -/
/-- The preimage of `s : Set β` by `f : α → β`, written `f ⁻¹' s`,
is the set of `x : α` such that `f x ∈ s`. -/
def preimage {α : Type u} {β : Type v} (f : α → β) (s : Set β) : Set α :=
{ x | f x ∈ s }
#align set.preimage Set.preimage
/-- `f ⁻¹' t` denotes the preimage of `t : Set β` under the function `f : α → β`. -/
infixl:80 " ⁻¹' " => preimage
section Preimage
variable {f : α → β} {g : β → γ}
@[simp]
theorem preimage_empty : f ⁻¹' ∅ = ∅ :=
rfl
#align set.preimage_empty Set.preimage_empty
@[simp, mfld_simps]
theorem mem_preimage {s : Set β} {a : α} : a ∈ f ⁻¹' s ↔ f a ∈ s :=
Iff.rfl
#align set.mem_preimage Set.mem_preimage
theorem preimage_congr {f g : α → β} {s : Set β} (h : ∀ x : α, f x = g x) : f ⁻¹' s = g ⁻¹' s := by
congr with x
simp [h]
#align set.preimage_congr Set.preimage_congr
@[gcongr]
theorem preimage_mono {s t : Set β} (h : s ⊆ t) : f ⁻¹' s ⊆ f ⁻¹' t := fun _ hx => h hx
#align set.preimage_mono Set.preimage_mono
@[simp, mfld_simps]
theorem preimage_univ : f ⁻¹' univ = univ :=
rfl
#align set.preimage_univ Set.preimage_univ
theorem subset_preimage_univ {s : Set α} : s ⊆ f ⁻¹' univ :=
subset_univ _
#align set.subset_preimage_univ Set.subset_preimage_univ
@[simp, mfld_simps]
theorem preimage_inter {s t : Set β} : f ⁻¹' (s ∩ t) = f ⁻¹' s ∩ f ⁻¹' t :=
rfl
#align set.preimage_inter Set.preimage_inter
@[simp]
theorem preimage_union {s t : Set β} : f ⁻¹' (s ∪ t) = f ⁻¹' s ∪ f ⁻¹' t :=
rfl
#align set.preimage_union Set.preimage_union
@[simp]
theorem preimage_compl {s : Set β} : f ⁻¹' sᶜ = (f ⁻¹' s)ᶜ :=
rfl
#align set.preimage_compl Set.preimage_compl
@[simp]
theorem preimage_diff (f : α → β) (s t : Set β) : f ⁻¹' (s \ t) = f ⁻¹' s \ f ⁻¹' t :=
rfl
#align set.preimage_diff Set.preimage_diff
@[simp]
lemma preimage_symmDiff {f : α → β} (s t : Set β) : f ⁻¹' (s ∆ t) = (f ⁻¹' s) ∆ (f ⁻¹' t) :=
rfl
#align set.preimage_symm_diff Set.preimage_symmDiff
@[simp]
theorem preimage_ite (f : α → β) (s t₁ t₂ : Set β) :
f ⁻¹' s.ite t₁ t₂ = (f ⁻¹' s).ite (f ⁻¹' t₁) (f ⁻¹' t₂) :=
rfl
#align set.preimage_ite Set.preimage_ite
@[simp]
theorem preimage_setOf_eq {p : α → Prop} {f : β → α} : f ⁻¹' { a | p a } = { a | p (f a) } :=
rfl
#align set.preimage_set_of_eq Set.preimage_setOf_eq
@[simp]
theorem preimage_id_eq : preimage (id : α → α) = id :=
rfl
#align set.preimage_id_eq Set.preimage_id_eq
@[mfld_simps]
theorem preimage_id {s : Set α} : id ⁻¹' s = s :=
rfl
#align set.preimage_id Set.preimage_id
@[simp, mfld_simps]
theorem preimage_id' {s : Set α} : (fun x => x) ⁻¹' s = s :=
rfl
#align set.preimage_id' Set.preimage_id'
@[simp]
theorem preimage_const_of_mem {b : β} {s : Set β} (h : b ∈ s) : (fun _ : α => b) ⁻¹' s = univ :=
eq_univ_of_forall fun _ => h
#align set.preimage_const_of_mem Set.preimage_const_of_mem
@[simp]
theorem preimage_const_of_not_mem {b : β} {s : Set β} (h : b ∉ s) : (fun _ : α => b) ⁻¹' s = ∅ :=
eq_empty_of_subset_empty fun _ hx => h hx
#align set.preimage_const_of_not_mem Set.preimage_const_of_not_mem
theorem preimage_const (b : β) (s : Set β) [Decidable (b ∈ s)] :
(fun _ : α => b) ⁻¹' s = if b ∈ s then univ else ∅ := by
split_ifs with hb
exacts [preimage_const_of_mem hb, preimage_const_of_not_mem hb]
#align set.preimage_const Set.preimage_const
/-- If preimage of each singleton under `f : α → β` is either empty or the whole type,
then `f` is a constant. -/
lemma exists_eq_const_of_preimage_singleton [Nonempty β] {f : α → β}
(hf : ∀ b : β, f ⁻¹' {b} = ∅ ∨ f ⁻¹' {b} = univ) : ∃ b, f = const α b := by
rcases em (∃ b, f ⁻¹' {b} = univ) with ⟨b, hb⟩ | hf'
· exact ⟨b, funext fun x ↦ eq_univ_iff_forall.1 hb x⟩
· have : ∀ x b, f x ≠ b := fun x b ↦
eq_empty_iff_forall_not_mem.1 ((hf b).resolve_right fun h ↦ hf' ⟨b, h⟩) x
exact ⟨Classical.arbitrary β, funext fun x ↦ absurd rfl (this x _)⟩
theorem preimage_comp {s : Set γ} : g ∘ f ⁻¹' s = f ⁻¹' (g ⁻¹' s) :=
rfl
#align set.preimage_comp Set.preimage_comp
theorem preimage_comp_eq : preimage (g ∘ f) = preimage f ∘ preimage g :=
rfl
#align set.preimage_comp_eq Set.preimage_comp_eq
theorem preimage_iterate_eq {f : α → α} {n : ℕ} : Set.preimage f^[n] = (Set.preimage f)^[n] := by
induction' n with n ih; · simp
rw [iterate_succ, iterate_succ', preimage_comp_eq, ih]
#align set.preimage_iterate_eq Set.preimage_iterate_eq
theorem preimage_preimage {g : β → γ} {f : α → β} {s : Set γ} :
f ⁻¹' (g ⁻¹' s) = (fun x => g (f x)) ⁻¹' s :=
preimage_comp.symm
#align set.preimage_preimage Set.preimage_preimage
theorem eq_preimage_subtype_val_iff {p : α → Prop} {s : Set (Subtype p)} {t : Set α} :
s = Subtype.val ⁻¹' t ↔ ∀ (x) (h : p x), (⟨x, h⟩ : Subtype p) ∈ s ↔ x ∈ t :=
⟨fun s_eq x h => by
rw [s_eq]
simp, fun h => ext fun ⟨x, hx⟩ => by simp [h]⟩
#align set.eq_preimage_subtype_val_iff Set.eq_preimage_subtype_val_iff
theorem nonempty_of_nonempty_preimage {s : Set β} {f : α → β} (hf : (f ⁻¹' s).Nonempty) :
s.Nonempty :=
let ⟨x, hx⟩ := hf
⟨f x, hx⟩
#align set.nonempty_of_nonempty_preimage Set.nonempty_of_nonempty_preimage
@[simp] theorem preimage_singleton_true (p : α → Prop) : p ⁻¹' {True} = {a | p a} := by ext; simp
#align set.preimage_singleton_true Set.preimage_singleton_true
@[simp] theorem preimage_singleton_false (p : α → Prop) : p ⁻¹' {False} = {a | ¬p a} := by ext; simp
#align set.preimage_singleton_false Set.preimage_singleton_false
theorem preimage_subtype_coe_eq_compl {s u v : Set α} (hsuv : s ⊆ u ∪ v)
(H : s ∩ (u ∩ v) = ∅) : ((↑) : s → α) ⁻¹' u = ((↑) ⁻¹' v)ᶜ := by
ext ⟨x, x_in_s⟩
constructor
· intro x_in_u x_in_v
exact eq_empty_iff_forall_not_mem.mp H x ⟨x_in_s, ⟨x_in_u, x_in_v⟩⟩
· intro hx
exact Or.elim (hsuv x_in_s) id fun hx' => hx.elim hx'
#align set.preimage_subtype_coe_eq_compl Set.preimage_subtype_coe_eq_compl
end Preimage
/-! ### Image of a set under a function -/
section Image
variable {f : α → β} {s t : Set α}
-- Porting note: `Set.image` is already defined in `Init.Set`
#align set.image Set.image
/-- `f '' s` denotes the image of `s : Set α` under the function `f : α → β`. -/
infixl:80 " '' " => image
theorem mem_image_iff_bex {f : α → β} {s : Set α} {y : β} :
y ∈ f '' s ↔ ∃ (x : _) (_ : x ∈ s), f x = y :=
bex_def.symm
#align set.mem_image_iff_bex Set.mem_image_iff_bex
@[simp]
theorem mem_image (f : α → β) (s : Set α) (y : β) : y ∈ f '' s ↔ ∃ x ∈ s, f x = y :=
Iff.rfl
#align set.mem_image Set.mem_image
theorem image_eta (f : α → β) : f '' s = (fun x => f x) '' s :=
rfl
#align set.image_eta Set.image_eta
@[mfld_simps]
theorem mem_image_of_mem (f : α → β) {x : α} {a : Set α} (h : x ∈ a) : f x ∈ f '' a :=
⟨_, h, rfl⟩
#align set.mem_image_of_mem Set.mem_image_of_mem
theorem _root_.Function.Injective.mem_set_image {f : α → β} (hf : Injective f) {s : Set α} {a : α} :
f a ∈ f '' s ↔ a ∈ s :=
⟨fun ⟨_, hb, Eq⟩ => hf Eq ▸ hb, mem_image_of_mem f⟩
#align function.injective.mem_set_image Function.Injective.mem_set_image
theorem ball_image_iff {f : α → β} {s : Set α} {p : β → Prop} :
(∀ y ∈ f '' s, p y) ↔ ∀ x ∈ s, p (f x) := by simp
#align set.ball_image_iff Set.ball_image_iff
theorem ball_image_of_ball {f : α → β} {s : Set α} {p : β → Prop} (h : ∀ x ∈ s, p (f x)) :
∀ y ∈ f '' s, p y :=
ball_image_iff.2 h
#align set.ball_image_of_ball Set.ball_image_of_ball
theorem bex_image_iff {f : α → β} {s : Set α} {p : β → Prop} :
(∃ y ∈ f '' s, p y) ↔ ∃ x ∈ s, p (f x) := by simp
#align set.bex_image_iff Set.bex_image_iff
theorem mem_image_elim {f : α → β} {s : Set α} {C : β → Prop} (h : ∀ x : α, x ∈ s → C (f x)) :
∀ {y : β}, y ∈ f '' s → C y
| _, ⟨a, a_in, rfl⟩ => h a a_in
#align set.mem_image_elim Set.mem_image_elim
theorem mem_image_elim_on {f : α → β} {s : Set α} {C : β → Prop} {y : β} (h_y : y ∈ f '' s)
(h : ∀ x : α, x ∈ s → C (f x)) : C y :=
mem_image_elim h h_y
#align set.mem_image_elim_on Set.mem_image_elim_on
-- Porting note: used to be `safe`
@[congr]
theorem image_congr {f g : α → β} {s : Set α} (h : ∀ a ∈ s, f a = g a) : f '' s = g '' s := by
ext x
rw [mem_image, mem_image]
exact {
mp := by
rintro ⟨a, ha1, ha2⟩
exact ⟨a, ⟨ha1, (h a ha1) ▸ ha2⟩⟩,
mpr := by
rintro ⟨a, ha1, ha2⟩
exact ⟨a, ⟨ha1, (h a ha1) ▸ ha2⟩⟩
}
-- safe [ext_iff, iff_def]
#align set.image_congr Set.image_congr
/-- A common special case of `image_congr` -/
theorem image_congr' {f g : α → β} {s : Set α} (h : ∀ x : α, f x = g x) : f '' s = g '' s :=
image_congr fun x _ => h x
#align set.image_congr' Set.image_congr'
@[gcongr]
lemma image_mono (h : s ⊆ t) : f '' s ⊆ f '' t := by
rintro - ⟨a, ha, rfl⟩; exact mem_image_of_mem f (h ha)
theorem image_comp (f : β → γ) (g : α → β) (a : Set α) : f ∘ g '' a = f '' (g '' a) :=
Subset.antisymm (ball_image_of_ball fun _ ha => mem_image_of_mem _ <| mem_image_of_mem _ ha)
(ball_image_of_ball <| ball_image_of_ball fun _ ha => mem_image_of_mem _ ha)
#align set.image_comp Set.image_comp
theorem image_comp_eq {g : β → γ} : image (g ∘ f) = image g ∘ image f := by ext; simp
/-- A variant of `image_comp`, useful for rewriting -/
theorem image_image (g : β → γ) (f : α → β) (s : Set α) : g '' (f '' s) = (fun x => g (f x)) '' s :=
(image_comp g f s).symm
#align set.image_image Set.image_image
theorem image_comm {β'} {f : β → γ} {g : α → β} {f' : α → β'} {g' : β' → γ}
(h_comm : ∀ a, f (g a) = g' (f' a)) : (s.image g).image f = (s.image f').image g' := by
simp_rw [image_image, h_comm]
#align set.image_comm Set.image_comm
theorem _root_.Function.Semiconj.set_image {f : α → β} {ga : α → α} {gb : β → β}
(h : Function.Semiconj f ga gb) : Function.Semiconj (image f) (image ga) (image gb) := fun _ =>
image_comm h
#align function.semiconj.set_image Function.Semiconj.set_image
theorem _root_.Function.Commute.set_image {f g : α → α} (h : Function.Commute f g) :
Function.Commute (image f) (image g) :=
Function.Semiconj.set_image h
#align function.commute.set_image Function.Commute.set_image
/-- Image is monotone with respect to `⊆`. See `Set.monotone_image` for the statement in
terms of `≤`. -/
@[gcongr]
theorem image_subset {a b : Set α} (f : α → β) (h : a ⊆ b) : f '' a ⊆ f '' b := by
simp only [subset_def, mem_image]
exact fun x => fun ⟨w, h1, h2⟩ => ⟨w, h h1, h2⟩
#align set.image_subset Set.image_subset
/-- `Set.image` is monotone. See `Set.image_subset` for the statement in terms of `⊆`. -/
lemma monotone_image {f : α → β} : Monotone (image f) := fun _ _ => image_subset _
#align set.monotone_image Set.monotone_image
theorem image_union (f : α → β) (s t : Set α) : f '' (s ∪ t) = f '' s ∪ f '' t :=
ext fun x =>
⟨by rintro ⟨a, h | h, rfl⟩ <;> [left; right] <;> exact ⟨_, h, rfl⟩, by
|
rintro (⟨a, h, rfl⟩ | ⟨a, h, rfl⟩)
|
theorem image_union (f : α → β) (s t : Set α) : f '' (s ∪ t) = f '' s ∪ f '' t :=
ext fun x =>
⟨by rintro ⟨a, h | h, rfl⟩ <;> [left; right] <;> exact ⟨_, h, rfl⟩, by
|
Mathlib.Data.Set.Image.336_0.IJFiTzmYGOCpPSd
|
theorem image_union (f : α → β) (s t : Set α) : f '' (s ∪ t) = f '' s ∪ f '' t
|
Mathlib_Data_Set_Image
|
case inl.intro.intro
α : Type u_1
β : Type u_2
γ : Type u_3
ι : Sort u_4
ι' : Sort u_5
f✝ : α → β
s✝ t✝ : Set α
f : α → β
s t : Set α
a : α
h : a ∈ s
⊢ f a ∈ f '' (s ∪ t)
|
/-
Copyright (c) 2014 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Leonardo de Moura
-/
import Mathlib.Data.Set.Basic
#align_import data.set.image from "leanprover-community/mathlib"@"001ffdc42920050657fd45bd2b8bfbec8eaaeb29"
/-!
# Images and preimages of sets
## Main definitions
* `preimage f t : Set α` : the preimage f⁻¹(t) (written `f ⁻¹' t` in Lean) of a subset of β.
* `range f : Set β` : the image of `univ` under `f`.
Also works for `{p : Prop} (f : p → α)` (unlike `image`)
## Notation
* `f ⁻¹' t` for `Set.preimage f t`
* `f '' s` for `Set.image f s`
## Tags
set, sets, image, preimage, pre-image, range
-/
set_option autoImplicit true
universe u v
open Function Set
namespace Set
variable {α β γ : Type*} {ι ι' : Sort*}
/-! ### Inverse image -/
/-- The preimage of `s : Set β` by `f : α → β`, written `f ⁻¹' s`,
is the set of `x : α` such that `f x ∈ s`. -/
def preimage {α : Type u} {β : Type v} (f : α → β) (s : Set β) : Set α :=
{ x | f x ∈ s }
#align set.preimage Set.preimage
/-- `f ⁻¹' t` denotes the preimage of `t : Set β` under the function `f : α → β`. -/
infixl:80 " ⁻¹' " => preimage
section Preimage
variable {f : α → β} {g : β → γ}
@[simp]
theorem preimage_empty : f ⁻¹' ∅ = ∅ :=
rfl
#align set.preimage_empty Set.preimage_empty
@[simp, mfld_simps]
theorem mem_preimage {s : Set β} {a : α} : a ∈ f ⁻¹' s ↔ f a ∈ s :=
Iff.rfl
#align set.mem_preimage Set.mem_preimage
theorem preimage_congr {f g : α → β} {s : Set β} (h : ∀ x : α, f x = g x) : f ⁻¹' s = g ⁻¹' s := by
congr with x
simp [h]
#align set.preimage_congr Set.preimage_congr
@[gcongr]
theorem preimage_mono {s t : Set β} (h : s ⊆ t) : f ⁻¹' s ⊆ f ⁻¹' t := fun _ hx => h hx
#align set.preimage_mono Set.preimage_mono
@[simp, mfld_simps]
theorem preimage_univ : f ⁻¹' univ = univ :=
rfl
#align set.preimage_univ Set.preimage_univ
theorem subset_preimage_univ {s : Set α} : s ⊆ f ⁻¹' univ :=
subset_univ _
#align set.subset_preimage_univ Set.subset_preimage_univ
@[simp, mfld_simps]
theorem preimage_inter {s t : Set β} : f ⁻¹' (s ∩ t) = f ⁻¹' s ∩ f ⁻¹' t :=
rfl
#align set.preimage_inter Set.preimage_inter
@[simp]
theorem preimage_union {s t : Set β} : f ⁻¹' (s ∪ t) = f ⁻¹' s ∪ f ⁻¹' t :=
rfl
#align set.preimage_union Set.preimage_union
@[simp]
theorem preimage_compl {s : Set β} : f ⁻¹' sᶜ = (f ⁻¹' s)ᶜ :=
rfl
#align set.preimage_compl Set.preimage_compl
@[simp]
theorem preimage_diff (f : α → β) (s t : Set β) : f ⁻¹' (s \ t) = f ⁻¹' s \ f ⁻¹' t :=
rfl
#align set.preimage_diff Set.preimage_diff
@[simp]
lemma preimage_symmDiff {f : α → β} (s t : Set β) : f ⁻¹' (s ∆ t) = (f ⁻¹' s) ∆ (f ⁻¹' t) :=
rfl
#align set.preimage_symm_diff Set.preimage_symmDiff
@[simp]
theorem preimage_ite (f : α → β) (s t₁ t₂ : Set β) :
f ⁻¹' s.ite t₁ t₂ = (f ⁻¹' s).ite (f ⁻¹' t₁) (f ⁻¹' t₂) :=
rfl
#align set.preimage_ite Set.preimage_ite
@[simp]
theorem preimage_setOf_eq {p : α → Prop} {f : β → α} : f ⁻¹' { a | p a } = { a | p (f a) } :=
rfl
#align set.preimage_set_of_eq Set.preimage_setOf_eq
@[simp]
theorem preimage_id_eq : preimage (id : α → α) = id :=
rfl
#align set.preimage_id_eq Set.preimage_id_eq
@[mfld_simps]
theorem preimage_id {s : Set α} : id ⁻¹' s = s :=
rfl
#align set.preimage_id Set.preimage_id
@[simp, mfld_simps]
theorem preimage_id' {s : Set α} : (fun x => x) ⁻¹' s = s :=
rfl
#align set.preimage_id' Set.preimage_id'
@[simp]
theorem preimage_const_of_mem {b : β} {s : Set β} (h : b ∈ s) : (fun _ : α => b) ⁻¹' s = univ :=
eq_univ_of_forall fun _ => h
#align set.preimage_const_of_mem Set.preimage_const_of_mem
@[simp]
theorem preimage_const_of_not_mem {b : β} {s : Set β} (h : b ∉ s) : (fun _ : α => b) ⁻¹' s = ∅ :=
eq_empty_of_subset_empty fun _ hx => h hx
#align set.preimage_const_of_not_mem Set.preimage_const_of_not_mem
theorem preimage_const (b : β) (s : Set β) [Decidable (b ∈ s)] :
(fun _ : α => b) ⁻¹' s = if b ∈ s then univ else ∅ := by
split_ifs with hb
exacts [preimage_const_of_mem hb, preimage_const_of_not_mem hb]
#align set.preimage_const Set.preimage_const
/-- If preimage of each singleton under `f : α → β` is either empty or the whole type,
then `f` is a constant. -/
lemma exists_eq_const_of_preimage_singleton [Nonempty β] {f : α → β}
(hf : ∀ b : β, f ⁻¹' {b} = ∅ ∨ f ⁻¹' {b} = univ) : ∃ b, f = const α b := by
rcases em (∃ b, f ⁻¹' {b} = univ) with ⟨b, hb⟩ | hf'
· exact ⟨b, funext fun x ↦ eq_univ_iff_forall.1 hb x⟩
· have : ∀ x b, f x ≠ b := fun x b ↦
eq_empty_iff_forall_not_mem.1 ((hf b).resolve_right fun h ↦ hf' ⟨b, h⟩) x
exact ⟨Classical.arbitrary β, funext fun x ↦ absurd rfl (this x _)⟩
theorem preimage_comp {s : Set γ} : g ∘ f ⁻¹' s = f ⁻¹' (g ⁻¹' s) :=
rfl
#align set.preimage_comp Set.preimage_comp
theorem preimage_comp_eq : preimage (g ∘ f) = preimage f ∘ preimage g :=
rfl
#align set.preimage_comp_eq Set.preimage_comp_eq
theorem preimage_iterate_eq {f : α → α} {n : ℕ} : Set.preimage f^[n] = (Set.preimage f)^[n] := by
induction' n with n ih; · simp
rw [iterate_succ, iterate_succ', preimage_comp_eq, ih]
#align set.preimage_iterate_eq Set.preimage_iterate_eq
theorem preimage_preimage {g : β → γ} {f : α → β} {s : Set γ} :
f ⁻¹' (g ⁻¹' s) = (fun x => g (f x)) ⁻¹' s :=
preimage_comp.symm
#align set.preimage_preimage Set.preimage_preimage
theorem eq_preimage_subtype_val_iff {p : α → Prop} {s : Set (Subtype p)} {t : Set α} :
s = Subtype.val ⁻¹' t ↔ ∀ (x) (h : p x), (⟨x, h⟩ : Subtype p) ∈ s ↔ x ∈ t :=
⟨fun s_eq x h => by
rw [s_eq]
simp, fun h => ext fun ⟨x, hx⟩ => by simp [h]⟩
#align set.eq_preimage_subtype_val_iff Set.eq_preimage_subtype_val_iff
theorem nonempty_of_nonempty_preimage {s : Set β} {f : α → β} (hf : (f ⁻¹' s).Nonempty) :
s.Nonempty :=
let ⟨x, hx⟩ := hf
⟨f x, hx⟩
#align set.nonempty_of_nonempty_preimage Set.nonempty_of_nonempty_preimage
@[simp] theorem preimage_singleton_true (p : α → Prop) : p ⁻¹' {True} = {a | p a} := by ext; simp
#align set.preimage_singleton_true Set.preimage_singleton_true
@[simp] theorem preimage_singleton_false (p : α → Prop) : p ⁻¹' {False} = {a | ¬p a} := by ext; simp
#align set.preimage_singleton_false Set.preimage_singleton_false
theorem preimage_subtype_coe_eq_compl {s u v : Set α} (hsuv : s ⊆ u ∪ v)
(H : s ∩ (u ∩ v) = ∅) : ((↑) : s → α) ⁻¹' u = ((↑) ⁻¹' v)ᶜ := by
ext ⟨x, x_in_s⟩
constructor
· intro x_in_u x_in_v
exact eq_empty_iff_forall_not_mem.mp H x ⟨x_in_s, ⟨x_in_u, x_in_v⟩⟩
· intro hx
exact Or.elim (hsuv x_in_s) id fun hx' => hx.elim hx'
#align set.preimage_subtype_coe_eq_compl Set.preimage_subtype_coe_eq_compl
end Preimage
/-! ### Image of a set under a function -/
section Image
variable {f : α → β} {s t : Set α}
-- Porting note: `Set.image` is already defined in `Init.Set`
#align set.image Set.image
/-- `f '' s` denotes the image of `s : Set α` under the function `f : α → β`. -/
infixl:80 " '' " => image
theorem mem_image_iff_bex {f : α → β} {s : Set α} {y : β} :
y ∈ f '' s ↔ ∃ (x : _) (_ : x ∈ s), f x = y :=
bex_def.symm
#align set.mem_image_iff_bex Set.mem_image_iff_bex
@[simp]
theorem mem_image (f : α → β) (s : Set α) (y : β) : y ∈ f '' s ↔ ∃ x ∈ s, f x = y :=
Iff.rfl
#align set.mem_image Set.mem_image
theorem image_eta (f : α → β) : f '' s = (fun x => f x) '' s :=
rfl
#align set.image_eta Set.image_eta
@[mfld_simps]
theorem mem_image_of_mem (f : α → β) {x : α} {a : Set α} (h : x ∈ a) : f x ∈ f '' a :=
⟨_, h, rfl⟩
#align set.mem_image_of_mem Set.mem_image_of_mem
theorem _root_.Function.Injective.mem_set_image {f : α → β} (hf : Injective f) {s : Set α} {a : α} :
f a ∈ f '' s ↔ a ∈ s :=
⟨fun ⟨_, hb, Eq⟩ => hf Eq ▸ hb, mem_image_of_mem f⟩
#align function.injective.mem_set_image Function.Injective.mem_set_image
theorem ball_image_iff {f : α → β} {s : Set α} {p : β → Prop} :
(∀ y ∈ f '' s, p y) ↔ ∀ x ∈ s, p (f x) := by simp
#align set.ball_image_iff Set.ball_image_iff
theorem ball_image_of_ball {f : α → β} {s : Set α} {p : β → Prop} (h : ∀ x ∈ s, p (f x)) :
∀ y ∈ f '' s, p y :=
ball_image_iff.2 h
#align set.ball_image_of_ball Set.ball_image_of_ball
theorem bex_image_iff {f : α → β} {s : Set α} {p : β → Prop} :
(∃ y ∈ f '' s, p y) ↔ ∃ x ∈ s, p (f x) := by simp
#align set.bex_image_iff Set.bex_image_iff
theorem mem_image_elim {f : α → β} {s : Set α} {C : β → Prop} (h : ∀ x : α, x ∈ s → C (f x)) :
∀ {y : β}, y ∈ f '' s → C y
| _, ⟨a, a_in, rfl⟩ => h a a_in
#align set.mem_image_elim Set.mem_image_elim
theorem mem_image_elim_on {f : α → β} {s : Set α} {C : β → Prop} {y : β} (h_y : y ∈ f '' s)
(h : ∀ x : α, x ∈ s → C (f x)) : C y :=
mem_image_elim h h_y
#align set.mem_image_elim_on Set.mem_image_elim_on
-- Porting note: used to be `safe`
@[congr]
theorem image_congr {f g : α → β} {s : Set α} (h : ∀ a ∈ s, f a = g a) : f '' s = g '' s := by
ext x
rw [mem_image, mem_image]
exact {
mp := by
rintro ⟨a, ha1, ha2⟩
exact ⟨a, ⟨ha1, (h a ha1) ▸ ha2⟩⟩,
mpr := by
rintro ⟨a, ha1, ha2⟩
exact ⟨a, ⟨ha1, (h a ha1) ▸ ha2⟩⟩
}
-- safe [ext_iff, iff_def]
#align set.image_congr Set.image_congr
/-- A common special case of `image_congr` -/
theorem image_congr' {f g : α → β} {s : Set α} (h : ∀ x : α, f x = g x) : f '' s = g '' s :=
image_congr fun x _ => h x
#align set.image_congr' Set.image_congr'
@[gcongr]
lemma image_mono (h : s ⊆ t) : f '' s ⊆ f '' t := by
rintro - ⟨a, ha, rfl⟩; exact mem_image_of_mem f (h ha)
theorem image_comp (f : β → γ) (g : α → β) (a : Set α) : f ∘ g '' a = f '' (g '' a) :=
Subset.antisymm (ball_image_of_ball fun _ ha => mem_image_of_mem _ <| mem_image_of_mem _ ha)
(ball_image_of_ball <| ball_image_of_ball fun _ ha => mem_image_of_mem _ ha)
#align set.image_comp Set.image_comp
theorem image_comp_eq {g : β → γ} : image (g ∘ f) = image g ∘ image f := by ext; simp
/-- A variant of `image_comp`, useful for rewriting -/
theorem image_image (g : β → γ) (f : α → β) (s : Set α) : g '' (f '' s) = (fun x => g (f x)) '' s :=
(image_comp g f s).symm
#align set.image_image Set.image_image
theorem image_comm {β'} {f : β → γ} {g : α → β} {f' : α → β'} {g' : β' → γ}
(h_comm : ∀ a, f (g a) = g' (f' a)) : (s.image g).image f = (s.image f').image g' := by
simp_rw [image_image, h_comm]
#align set.image_comm Set.image_comm
theorem _root_.Function.Semiconj.set_image {f : α → β} {ga : α → α} {gb : β → β}
(h : Function.Semiconj f ga gb) : Function.Semiconj (image f) (image ga) (image gb) := fun _ =>
image_comm h
#align function.semiconj.set_image Function.Semiconj.set_image
theorem _root_.Function.Commute.set_image {f g : α → α} (h : Function.Commute f g) :
Function.Commute (image f) (image g) :=
Function.Semiconj.set_image h
#align function.commute.set_image Function.Commute.set_image
/-- Image is monotone with respect to `⊆`. See `Set.monotone_image` for the statement in
terms of `≤`. -/
@[gcongr]
theorem image_subset {a b : Set α} (f : α → β) (h : a ⊆ b) : f '' a ⊆ f '' b := by
simp only [subset_def, mem_image]
exact fun x => fun ⟨w, h1, h2⟩ => ⟨w, h h1, h2⟩
#align set.image_subset Set.image_subset
/-- `Set.image` is monotone. See `Set.image_subset` for the statement in terms of `⊆`. -/
lemma monotone_image {f : α → β} : Monotone (image f) := fun _ _ => image_subset _
#align set.monotone_image Set.monotone_image
theorem image_union (f : α → β) (s t : Set α) : f '' (s ∪ t) = f '' s ∪ f '' t :=
ext fun x =>
⟨by rintro ⟨a, h | h, rfl⟩ <;> [left; right] <;> exact ⟨_, h, rfl⟩, by
rintro (⟨a, h, rfl⟩ | ⟨a, h, rfl⟩) <;>
|
refine' ⟨_, _, rfl⟩
|
theorem image_union (f : α → β) (s t : Set α) : f '' (s ∪ t) = f '' s ∪ f '' t :=
ext fun x =>
⟨by rintro ⟨a, h | h, rfl⟩ <;> [left; right] <;> exact ⟨_, h, rfl⟩, by
rintro (⟨a, h, rfl⟩ | ⟨a, h, rfl⟩) <;>
|
Mathlib.Data.Set.Image.336_0.IJFiTzmYGOCpPSd
|
theorem image_union (f : α → β) (s t : Set α) : f '' (s ∪ t) = f '' s ∪ f '' t
|
Mathlib_Data_Set_Image
|
case inr.intro.intro
α : Type u_1
β : Type u_2
γ : Type u_3
ι : Sort u_4
ι' : Sort u_5
f✝ : α → β
s✝ t✝ : Set α
f : α → β
s t : Set α
a : α
h : a ∈ t
⊢ f a ∈ f '' (s ∪ t)
|
/-
Copyright (c) 2014 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Leonardo de Moura
-/
import Mathlib.Data.Set.Basic
#align_import data.set.image from "leanprover-community/mathlib"@"001ffdc42920050657fd45bd2b8bfbec8eaaeb29"
/-!
# Images and preimages of sets
## Main definitions
* `preimage f t : Set α` : the preimage f⁻¹(t) (written `f ⁻¹' t` in Lean) of a subset of β.
* `range f : Set β` : the image of `univ` under `f`.
Also works for `{p : Prop} (f : p → α)` (unlike `image`)
## Notation
* `f ⁻¹' t` for `Set.preimage f t`
* `f '' s` for `Set.image f s`
## Tags
set, sets, image, preimage, pre-image, range
-/
set_option autoImplicit true
universe u v
open Function Set
namespace Set
variable {α β γ : Type*} {ι ι' : Sort*}
/-! ### Inverse image -/
/-- The preimage of `s : Set β` by `f : α → β`, written `f ⁻¹' s`,
is the set of `x : α` such that `f x ∈ s`. -/
def preimage {α : Type u} {β : Type v} (f : α → β) (s : Set β) : Set α :=
{ x | f x ∈ s }
#align set.preimage Set.preimage
/-- `f ⁻¹' t` denotes the preimage of `t : Set β` under the function `f : α → β`. -/
infixl:80 " ⁻¹' " => preimage
section Preimage
variable {f : α → β} {g : β → γ}
@[simp]
theorem preimage_empty : f ⁻¹' ∅ = ∅ :=
rfl
#align set.preimage_empty Set.preimage_empty
@[simp, mfld_simps]
theorem mem_preimage {s : Set β} {a : α} : a ∈ f ⁻¹' s ↔ f a ∈ s :=
Iff.rfl
#align set.mem_preimage Set.mem_preimage
theorem preimage_congr {f g : α → β} {s : Set β} (h : ∀ x : α, f x = g x) : f ⁻¹' s = g ⁻¹' s := by
congr with x
simp [h]
#align set.preimage_congr Set.preimage_congr
@[gcongr]
theorem preimage_mono {s t : Set β} (h : s ⊆ t) : f ⁻¹' s ⊆ f ⁻¹' t := fun _ hx => h hx
#align set.preimage_mono Set.preimage_mono
@[simp, mfld_simps]
theorem preimage_univ : f ⁻¹' univ = univ :=
rfl
#align set.preimage_univ Set.preimage_univ
theorem subset_preimage_univ {s : Set α} : s ⊆ f ⁻¹' univ :=
subset_univ _
#align set.subset_preimage_univ Set.subset_preimage_univ
@[simp, mfld_simps]
theorem preimage_inter {s t : Set β} : f ⁻¹' (s ∩ t) = f ⁻¹' s ∩ f ⁻¹' t :=
rfl
#align set.preimage_inter Set.preimage_inter
@[simp]
theorem preimage_union {s t : Set β} : f ⁻¹' (s ∪ t) = f ⁻¹' s ∪ f ⁻¹' t :=
rfl
#align set.preimage_union Set.preimage_union
@[simp]
theorem preimage_compl {s : Set β} : f ⁻¹' sᶜ = (f ⁻¹' s)ᶜ :=
rfl
#align set.preimage_compl Set.preimage_compl
@[simp]
theorem preimage_diff (f : α → β) (s t : Set β) : f ⁻¹' (s \ t) = f ⁻¹' s \ f ⁻¹' t :=
rfl
#align set.preimage_diff Set.preimage_diff
@[simp]
lemma preimage_symmDiff {f : α → β} (s t : Set β) : f ⁻¹' (s ∆ t) = (f ⁻¹' s) ∆ (f ⁻¹' t) :=
rfl
#align set.preimage_symm_diff Set.preimage_symmDiff
@[simp]
theorem preimage_ite (f : α → β) (s t₁ t₂ : Set β) :
f ⁻¹' s.ite t₁ t₂ = (f ⁻¹' s).ite (f ⁻¹' t₁) (f ⁻¹' t₂) :=
rfl
#align set.preimage_ite Set.preimage_ite
@[simp]
theorem preimage_setOf_eq {p : α → Prop} {f : β → α} : f ⁻¹' { a | p a } = { a | p (f a) } :=
rfl
#align set.preimage_set_of_eq Set.preimage_setOf_eq
@[simp]
theorem preimage_id_eq : preimage (id : α → α) = id :=
rfl
#align set.preimage_id_eq Set.preimage_id_eq
@[mfld_simps]
theorem preimage_id {s : Set α} : id ⁻¹' s = s :=
rfl
#align set.preimage_id Set.preimage_id
@[simp, mfld_simps]
theorem preimage_id' {s : Set α} : (fun x => x) ⁻¹' s = s :=
rfl
#align set.preimage_id' Set.preimage_id'
@[simp]
theorem preimage_const_of_mem {b : β} {s : Set β} (h : b ∈ s) : (fun _ : α => b) ⁻¹' s = univ :=
eq_univ_of_forall fun _ => h
#align set.preimage_const_of_mem Set.preimage_const_of_mem
@[simp]
theorem preimage_const_of_not_mem {b : β} {s : Set β} (h : b ∉ s) : (fun _ : α => b) ⁻¹' s = ∅ :=
eq_empty_of_subset_empty fun _ hx => h hx
#align set.preimage_const_of_not_mem Set.preimage_const_of_not_mem
theorem preimage_const (b : β) (s : Set β) [Decidable (b ∈ s)] :
(fun _ : α => b) ⁻¹' s = if b ∈ s then univ else ∅ := by
split_ifs with hb
exacts [preimage_const_of_mem hb, preimage_const_of_not_mem hb]
#align set.preimage_const Set.preimage_const
/-- If preimage of each singleton under `f : α → β` is either empty or the whole type,
then `f` is a constant. -/
lemma exists_eq_const_of_preimage_singleton [Nonempty β] {f : α → β}
(hf : ∀ b : β, f ⁻¹' {b} = ∅ ∨ f ⁻¹' {b} = univ) : ∃ b, f = const α b := by
rcases em (∃ b, f ⁻¹' {b} = univ) with ⟨b, hb⟩ | hf'
· exact ⟨b, funext fun x ↦ eq_univ_iff_forall.1 hb x⟩
· have : ∀ x b, f x ≠ b := fun x b ↦
eq_empty_iff_forall_not_mem.1 ((hf b).resolve_right fun h ↦ hf' ⟨b, h⟩) x
exact ⟨Classical.arbitrary β, funext fun x ↦ absurd rfl (this x _)⟩
theorem preimage_comp {s : Set γ} : g ∘ f ⁻¹' s = f ⁻¹' (g ⁻¹' s) :=
rfl
#align set.preimage_comp Set.preimage_comp
theorem preimage_comp_eq : preimage (g ∘ f) = preimage f ∘ preimage g :=
rfl
#align set.preimage_comp_eq Set.preimage_comp_eq
theorem preimage_iterate_eq {f : α → α} {n : ℕ} : Set.preimage f^[n] = (Set.preimage f)^[n] := by
induction' n with n ih; · simp
rw [iterate_succ, iterate_succ', preimage_comp_eq, ih]
#align set.preimage_iterate_eq Set.preimage_iterate_eq
theorem preimage_preimage {g : β → γ} {f : α → β} {s : Set γ} :
f ⁻¹' (g ⁻¹' s) = (fun x => g (f x)) ⁻¹' s :=
preimage_comp.symm
#align set.preimage_preimage Set.preimage_preimage
theorem eq_preimage_subtype_val_iff {p : α → Prop} {s : Set (Subtype p)} {t : Set α} :
s = Subtype.val ⁻¹' t ↔ ∀ (x) (h : p x), (⟨x, h⟩ : Subtype p) ∈ s ↔ x ∈ t :=
⟨fun s_eq x h => by
rw [s_eq]
simp, fun h => ext fun ⟨x, hx⟩ => by simp [h]⟩
#align set.eq_preimage_subtype_val_iff Set.eq_preimage_subtype_val_iff
theorem nonempty_of_nonempty_preimage {s : Set β} {f : α → β} (hf : (f ⁻¹' s).Nonempty) :
s.Nonempty :=
let ⟨x, hx⟩ := hf
⟨f x, hx⟩
#align set.nonempty_of_nonempty_preimage Set.nonempty_of_nonempty_preimage
@[simp] theorem preimage_singleton_true (p : α → Prop) : p ⁻¹' {True} = {a | p a} := by ext; simp
#align set.preimage_singleton_true Set.preimage_singleton_true
@[simp] theorem preimage_singleton_false (p : α → Prop) : p ⁻¹' {False} = {a | ¬p a} := by ext; simp
#align set.preimage_singleton_false Set.preimage_singleton_false
theorem preimage_subtype_coe_eq_compl {s u v : Set α} (hsuv : s ⊆ u ∪ v)
(H : s ∩ (u ∩ v) = ∅) : ((↑) : s → α) ⁻¹' u = ((↑) ⁻¹' v)ᶜ := by
ext ⟨x, x_in_s⟩
constructor
· intro x_in_u x_in_v
exact eq_empty_iff_forall_not_mem.mp H x ⟨x_in_s, ⟨x_in_u, x_in_v⟩⟩
· intro hx
exact Or.elim (hsuv x_in_s) id fun hx' => hx.elim hx'
#align set.preimage_subtype_coe_eq_compl Set.preimage_subtype_coe_eq_compl
end Preimage
/-! ### Image of a set under a function -/
section Image
variable {f : α → β} {s t : Set α}
-- Porting note: `Set.image` is already defined in `Init.Set`
#align set.image Set.image
/-- `f '' s` denotes the image of `s : Set α` under the function `f : α → β`. -/
infixl:80 " '' " => image
theorem mem_image_iff_bex {f : α → β} {s : Set α} {y : β} :
y ∈ f '' s ↔ ∃ (x : _) (_ : x ∈ s), f x = y :=
bex_def.symm
#align set.mem_image_iff_bex Set.mem_image_iff_bex
@[simp]
theorem mem_image (f : α → β) (s : Set α) (y : β) : y ∈ f '' s ↔ ∃ x ∈ s, f x = y :=
Iff.rfl
#align set.mem_image Set.mem_image
theorem image_eta (f : α → β) : f '' s = (fun x => f x) '' s :=
rfl
#align set.image_eta Set.image_eta
@[mfld_simps]
theorem mem_image_of_mem (f : α → β) {x : α} {a : Set α} (h : x ∈ a) : f x ∈ f '' a :=
⟨_, h, rfl⟩
#align set.mem_image_of_mem Set.mem_image_of_mem
theorem _root_.Function.Injective.mem_set_image {f : α → β} (hf : Injective f) {s : Set α} {a : α} :
f a ∈ f '' s ↔ a ∈ s :=
⟨fun ⟨_, hb, Eq⟩ => hf Eq ▸ hb, mem_image_of_mem f⟩
#align function.injective.mem_set_image Function.Injective.mem_set_image
theorem ball_image_iff {f : α → β} {s : Set α} {p : β → Prop} :
(∀ y ∈ f '' s, p y) ↔ ∀ x ∈ s, p (f x) := by simp
#align set.ball_image_iff Set.ball_image_iff
theorem ball_image_of_ball {f : α → β} {s : Set α} {p : β → Prop} (h : ∀ x ∈ s, p (f x)) :
∀ y ∈ f '' s, p y :=
ball_image_iff.2 h
#align set.ball_image_of_ball Set.ball_image_of_ball
theorem bex_image_iff {f : α → β} {s : Set α} {p : β → Prop} :
(∃ y ∈ f '' s, p y) ↔ ∃ x ∈ s, p (f x) := by simp
#align set.bex_image_iff Set.bex_image_iff
theorem mem_image_elim {f : α → β} {s : Set α} {C : β → Prop} (h : ∀ x : α, x ∈ s → C (f x)) :
∀ {y : β}, y ∈ f '' s → C y
| _, ⟨a, a_in, rfl⟩ => h a a_in
#align set.mem_image_elim Set.mem_image_elim
theorem mem_image_elim_on {f : α → β} {s : Set α} {C : β → Prop} {y : β} (h_y : y ∈ f '' s)
(h : ∀ x : α, x ∈ s → C (f x)) : C y :=
mem_image_elim h h_y
#align set.mem_image_elim_on Set.mem_image_elim_on
-- Porting note: used to be `safe`
@[congr]
theorem image_congr {f g : α → β} {s : Set α} (h : ∀ a ∈ s, f a = g a) : f '' s = g '' s := by
ext x
rw [mem_image, mem_image]
exact {
mp := by
rintro ⟨a, ha1, ha2⟩
exact ⟨a, ⟨ha1, (h a ha1) ▸ ha2⟩⟩,
mpr := by
rintro ⟨a, ha1, ha2⟩
exact ⟨a, ⟨ha1, (h a ha1) ▸ ha2⟩⟩
}
-- safe [ext_iff, iff_def]
#align set.image_congr Set.image_congr
/-- A common special case of `image_congr` -/
theorem image_congr' {f g : α → β} {s : Set α} (h : ∀ x : α, f x = g x) : f '' s = g '' s :=
image_congr fun x _ => h x
#align set.image_congr' Set.image_congr'
@[gcongr]
lemma image_mono (h : s ⊆ t) : f '' s ⊆ f '' t := by
rintro - ⟨a, ha, rfl⟩; exact mem_image_of_mem f (h ha)
theorem image_comp (f : β → γ) (g : α → β) (a : Set α) : f ∘ g '' a = f '' (g '' a) :=
Subset.antisymm (ball_image_of_ball fun _ ha => mem_image_of_mem _ <| mem_image_of_mem _ ha)
(ball_image_of_ball <| ball_image_of_ball fun _ ha => mem_image_of_mem _ ha)
#align set.image_comp Set.image_comp
theorem image_comp_eq {g : β → γ} : image (g ∘ f) = image g ∘ image f := by ext; simp
/-- A variant of `image_comp`, useful for rewriting -/
theorem image_image (g : β → γ) (f : α → β) (s : Set α) : g '' (f '' s) = (fun x => g (f x)) '' s :=
(image_comp g f s).symm
#align set.image_image Set.image_image
theorem image_comm {β'} {f : β → γ} {g : α → β} {f' : α → β'} {g' : β' → γ}
(h_comm : ∀ a, f (g a) = g' (f' a)) : (s.image g).image f = (s.image f').image g' := by
simp_rw [image_image, h_comm]
#align set.image_comm Set.image_comm
theorem _root_.Function.Semiconj.set_image {f : α → β} {ga : α → α} {gb : β → β}
(h : Function.Semiconj f ga gb) : Function.Semiconj (image f) (image ga) (image gb) := fun _ =>
image_comm h
#align function.semiconj.set_image Function.Semiconj.set_image
theorem _root_.Function.Commute.set_image {f g : α → α} (h : Function.Commute f g) :
Function.Commute (image f) (image g) :=
Function.Semiconj.set_image h
#align function.commute.set_image Function.Commute.set_image
/-- Image is monotone with respect to `⊆`. See `Set.monotone_image` for the statement in
terms of `≤`. -/
@[gcongr]
theorem image_subset {a b : Set α} (f : α → β) (h : a ⊆ b) : f '' a ⊆ f '' b := by
simp only [subset_def, mem_image]
exact fun x => fun ⟨w, h1, h2⟩ => ⟨w, h h1, h2⟩
#align set.image_subset Set.image_subset
/-- `Set.image` is monotone. See `Set.image_subset` for the statement in terms of `⊆`. -/
lemma monotone_image {f : α → β} : Monotone (image f) := fun _ _ => image_subset _
#align set.monotone_image Set.monotone_image
theorem image_union (f : α → β) (s t : Set α) : f '' (s ∪ t) = f '' s ∪ f '' t :=
ext fun x =>
⟨by rintro ⟨a, h | h, rfl⟩ <;> [left; right] <;> exact ⟨_, h, rfl⟩, by
rintro (⟨a, h, rfl⟩ | ⟨a, h, rfl⟩) <;>
|
refine' ⟨_, _, rfl⟩
|
theorem image_union (f : α → β) (s t : Set α) : f '' (s ∪ t) = f '' s ∪ f '' t :=
ext fun x =>
⟨by rintro ⟨a, h | h, rfl⟩ <;> [left; right] <;> exact ⟨_, h, rfl⟩, by
rintro (⟨a, h, rfl⟩ | ⟨a, h, rfl⟩) <;>
|
Mathlib.Data.Set.Image.336_0.IJFiTzmYGOCpPSd
|
theorem image_union (f : α → β) (s t : Set α) : f '' (s ∪ t) = f '' s ∪ f '' t
|
Mathlib_Data_Set_Image
|
case inl.intro.intro
α : Type u_1
β : Type u_2
γ : Type u_3
ι : Sort u_4
ι' : Sort u_5
f✝ : α → β
s✝ t✝ : Set α
f : α → β
s t : Set α
a : α
h : a ∈ s
⊢ a ∈ s ∪ t
|
/-
Copyright (c) 2014 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Leonardo de Moura
-/
import Mathlib.Data.Set.Basic
#align_import data.set.image from "leanprover-community/mathlib"@"001ffdc42920050657fd45bd2b8bfbec8eaaeb29"
/-!
# Images and preimages of sets
## Main definitions
* `preimage f t : Set α` : the preimage f⁻¹(t) (written `f ⁻¹' t` in Lean) of a subset of β.
* `range f : Set β` : the image of `univ` under `f`.
Also works for `{p : Prop} (f : p → α)` (unlike `image`)
## Notation
* `f ⁻¹' t` for `Set.preimage f t`
* `f '' s` for `Set.image f s`
## Tags
set, sets, image, preimage, pre-image, range
-/
set_option autoImplicit true
universe u v
open Function Set
namespace Set
variable {α β γ : Type*} {ι ι' : Sort*}
/-! ### Inverse image -/
/-- The preimage of `s : Set β` by `f : α → β`, written `f ⁻¹' s`,
is the set of `x : α` such that `f x ∈ s`. -/
def preimage {α : Type u} {β : Type v} (f : α → β) (s : Set β) : Set α :=
{ x | f x ∈ s }
#align set.preimage Set.preimage
/-- `f ⁻¹' t` denotes the preimage of `t : Set β` under the function `f : α → β`. -/
infixl:80 " ⁻¹' " => preimage
section Preimage
variable {f : α → β} {g : β → γ}
@[simp]
theorem preimage_empty : f ⁻¹' ∅ = ∅ :=
rfl
#align set.preimage_empty Set.preimage_empty
@[simp, mfld_simps]
theorem mem_preimage {s : Set β} {a : α} : a ∈ f ⁻¹' s ↔ f a ∈ s :=
Iff.rfl
#align set.mem_preimage Set.mem_preimage
theorem preimage_congr {f g : α → β} {s : Set β} (h : ∀ x : α, f x = g x) : f ⁻¹' s = g ⁻¹' s := by
congr with x
simp [h]
#align set.preimage_congr Set.preimage_congr
@[gcongr]
theorem preimage_mono {s t : Set β} (h : s ⊆ t) : f ⁻¹' s ⊆ f ⁻¹' t := fun _ hx => h hx
#align set.preimage_mono Set.preimage_mono
@[simp, mfld_simps]
theorem preimage_univ : f ⁻¹' univ = univ :=
rfl
#align set.preimage_univ Set.preimage_univ
theorem subset_preimage_univ {s : Set α} : s ⊆ f ⁻¹' univ :=
subset_univ _
#align set.subset_preimage_univ Set.subset_preimage_univ
@[simp, mfld_simps]
theorem preimage_inter {s t : Set β} : f ⁻¹' (s ∩ t) = f ⁻¹' s ∩ f ⁻¹' t :=
rfl
#align set.preimage_inter Set.preimage_inter
@[simp]
theorem preimage_union {s t : Set β} : f ⁻¹' (s ∪ t) = f ⁻¹' s ∪ f ⁻¹' t :=
rfl
#align set.preimage_union Set.preimage_union
@[simp]
theorem preimage_compl {s : Set β} : f ⁻¹' sᶜ = (f ⁻¹' s)ᶜ :=
rfl
#align set.preimage_compl Set.preimage_compl
@[simp]
theorem preimage_diff (f : α → β) (s t : Set β) : f ⁻¹' (s \ t) = f ⁻¹' s \ f ⁻¹' t :=
rfl
#align set.preimage_diff Set.preimage_diff
@[simp]
lemma preimage_symmDiff {f : α → β} (s t : Set β) : f ⁻¹' (s ∆ t) = (f ⁻¹' s) ∆ (f ⁻¹' t) :=
rfl
#align set.preimage_symm_diff Set.preimage_symmDiff
@[simp]
theorem preimage_ite (f : α → β) (s t₁ t₂ : Set β) :
f ⁻¹' s.ite t₁ t₂ = (f ⁻¹' s).ite (f ⁻¹' t₁) (f ⁻¹' t₂) :=
rfl
#align set.preimage_ite Set.preimage_ite
@[simp]
theorem preimage_setOf_eq {p : α → Prop} {f : β → α} : f ⁻¹' { a | p a } = { a | p (f a) } :=
rfl
#align set.preimage_set_of_eq Set.preimage_setOf_eq
@[simp]
theorem preimage_id_eq : preimage (id : α → α) = id :=
rfl
#align set.preimage_id_eq Set.preimage_id_eq
@[mfld_simps]
theorem preimage_id {s : Set α} : id ⁻¹' s = s :=
rfl
#align set.preimage_id Set.preimage_id
@[simp, mfld_simps]
theorem preimage_id' {s : Set α} : (fun x => x) ⁻¹' s = s :=
rfl
#align set.preimage_id' Set.preimage_id'
@[simp]
theorem preimage_const_of_mem {b : β} {s : Set β} (h : b ∈ s) : (fun _ : α => b) ⁻¹' s = univ :=
eq_univ_of_forall fun _ => h
#align set.preimage_const_of_mem Set.preimage_const_of_mem
@[simp]
theorem preimage_const_of_not_mem {b : β} {s : Set β} (h : b ∉ s) : (fun _ : α => b) ⁻¹' s = ∅ :=
eq_empty_of_subset_empty fun _ hx => h hx
#align set.preimage_const_of_not_mem Set.preimage_const_of_not_mem
theorem preimage_const (b : β) (s : Set β) [Decidable (b ∈ s)] :
(fun _ : α => b) ⁻¹' s = if b ∈ s then univ else ∅ := by
split_ifs with hb
exacts [preimage_const_of_mem hb, preimage_const_of_not_mem hb]
#align set.preimage_const Set.preimage_const
/-- If preimage of each singleton under `f : α → β` is either empty or the whole type,
then `f` is a constant. -/
lemma exists_eq_const_of_preimage_singleton [Nonempty β] {f : α → β}
(hf : ∀ b : β, f ⁻¹' {b} = ∅ ∨ f ⁻¹' {b} = univ) : ∃ b, f = const α b := by
rcases em (∃ b, f ⁻¹' {b} = univ) with ⟨b, hb⟩ | hf'
· exact ⟨b, funext fun x ↦ eq_univ_iff_forall.1 hb x⟩
· have : ∀ x b, f x ≠ b := fun x b ↦
eq_empty_iff_forall_not_mem.1 ((hf b).resolve_right fun h ↦ hf' ⟨b, h⟩) x
exact ⟨Classical.arbitrary β, funext fun x ↦ absurd rfl (this x _)⟩
theorem preimage_comp {s : Set γ} : g ∘ f ⁻¹' s = f ⁻¹' (g ⁻¹' s) :=
rfl
#align set.preimage_comp Set.preimage_comp
theorem preimage_comp_eq : preimage (g ∘ f) = preimage f ∘ preimage g :=
rfl
#align set.preimage_comp_eq Set.preimage_comp_eq
theorem preimage_iterate_eq {f : α → α} {n : ℕ} : Set.preimage f^[n] = (Set.preimage f)^[n] := by
induction' n with n ih; · simp
rw [iterate_succ, iterate_succ', preimage_comp_eq, ih]
#align set.preimage_iterate_eq Set.preimage_iterate_eq
theorem preimage_preimage {g : β → γ} {f : α → β} {s : Set γ} :
f ⁻¹' (g ⁻¹' s) = (fun x => g (f x)) ⁻¹' s :=
preimage_comp.symm
#align set.preimage_preimage Set.preimage_preimage
theorem eq_preimage_subtype_val_iff {p : α → Prop} {s : Set (Subtype p)} {t : Set α} :
s = Subtype.val ⁻¹' t ↔ ∀ (x) (h : p x), (⟨x, h⟩ : Subtype p) ∈ s ↔ x ∈ t :=
⟨fun s_eq x h => by
rw [s_eq]
simp, fun h => ext fun ⟨x, hx⟩ => by simp [h]⟩
#align set.eq_preimage_subtype_val_iff Set.eq_preimage_subtype_val_iff
theorem nonempty_of_nonempty_preimage {s : Set β} {f : α → β} (hf : (f ⁻¹' s).Nonempty) :
s.Nonempty :=
let ⟨x, hx⟩ := hf
⟨f x, hx⟩
#align set.nonempty_of_nonempty_preimage Set.nonempty_of_nonempty_preimage
@[simp] theorem preimage_singleton_true (p : α → Prop) : p ⁻¹' {True} = {a | p a} := by ext; simp
#align set.preimage_singleton_true Set.preimage_singleton_true
@[simp] theorem preimage_singleton_false (p : α → Prop) : p ⁻¹' {False} = {a | ¬p a} := by ext; simp
#align set.preimage_singleton_false Set.preimage_singleton_false
theorem preimage_subtype_coe_eq_compl {s u v : Set α} (hsuv : s ⊆ u ∪ v)
(H : s ∩ (u ∩ v) = ∅) : ((↑) : s → α) ⁻¹' u = ((↑) ⁻¹' v)ᶜ := by
ext ⟨x, x_in_s⟩
constructor
· intro x_in_u x_in_v
exact eq_empty_iff_forall_not_mem.mp H x ⟨x_in_s, ⟨x_in_u, x_in_v⟩⟩
· intro hx
exact Or.elim (hsuv x_in_s) id fun hx' => hx.elim hx'
#align set.preimage_subtype_coe_eq_compl Set.preimage_subtype_coe_eq_compl
end Preimage
/-! ### Image of a set under a function -/
section Image
variable {f : α → β} {s t : Set α}
-- Porting note: `Set.image` is already defined in `Init.Set`
#align set.image Set.image
/-- `f '' s` denotes the image of `s : Set α` under the function `f : α → β`. -/
infixl:80 " '' " => image
theorem mem_image_iff_bex {f : α → β} {s : Set α} {y : β} :
y ∈ f '' s ↔ ∃ (x : _) (_ : x ∈ s), f x = y :=
bex_def.symm
#align set.mem_image_iff_bex Set.mem_image_iff_bex
@[simp]
theorem mem_image (f : α → β) (s : Set α) (y : β) : y ∈ f '' s ↔ ∃ x ∈ s, f x = y :=
Iff.rfl
#align set.mem_image Set.mem_image
theorem image_eta (f : α → β) : f '' s = (fun x => f x) '' s :=
rfl
#align set.image_eta Set.image_eta
@[mfld_simps]
theorem mem_image_of_mem (f : α → β) {x : α} {a : Set α} (h : x ∈ a) : f x ∈ f '' a :=
⟨_, h, rfl⟩
#align set.mem_image_of_mem Set.mem_image_of_mem
theorem _root_.Function.Injective.mem_set_image {f : α → β} (hf : Injective f) {s : Set α} {a : α} :
f a ∈ f '' s ↔ a ∈ s :=
⟨fun ⟨_, hb, Eq⟩ => hf Eq ▸ hb, mem_image_of_mem f⟩
#align function.injective.mem_set_image Function.Injective.mem_set_image
theorem ball_image_iff {f : α → β} {s : Set α} {p : β → Prop} :
(∀ y ∈ f '' s, p y) ↔ ∀ x ∈ s, p (f x) := by simp
#align set.ball_image_iff Set.ball_image_iff
theorem ball_image_of_ball {f : α → β} {s : Set α} {p : β → Prop} (h : ∀ x ∈ s, p (f x)) :
∀ y ∈ f '' s, p y :=
ball_image_iff.2 h
#align set.ball_image_of_ball Set.ball_image_of_ball
theorem bex_image_iff {f : α → β} {s : Set α} {p : β → Prop} :
(∃ y ∈ f '' s, p y) ↔ ∃ x ∈ s, p (f x) := by simp
#align set.bex_image_iff Set.bex_image_iff
theorem mem_image_elim {f : α → β} {s : Set α} {C : β → Prop} (h : ∀ x : α, x ∈ s → C (f x)) :
∀ {y : β}, y ∈ f '' s → C y
| _, ⟨a, a_in, rfl⟩ => h a a_in
#align set.mem_image_elim Set.mem_image_elim
theorem mem_image_elim_on {f : α → β} {s : Set α} {C : β → Prop} {y : β} (h_y : y ∈ f '' s)
(h : ∀ x : α, x ∈ s → C (f x)) : C y :=
mem_image_elim h h_y
#align set.mem_image_elim_on Set.mem_image_elim_on
-- Porting note: used to be `safe`
@[congr]
theorem image_congr {f g : α → β} {s : Set α} (h : ∀ a ∈ s, f a = g a) : f '' s = g '' s := by
ext x
rw [mem_image, mem_image]
exact {
mp := by
rintro ⟨a, ha1, ha2⟩
exact ⟨a, ⟨ha1, (h a ha1) ▸ ha2⟩⟩,
mpr := by
rintro ⟨a, ha1, ha2⟩
exact ⟨a, ⟨ha1, (h a ha1) ▸ ha2⟩⟩
}
-- safe [ext_iff, iff_def]
#align set.image_congr Set.image_congr
/-- A common special case of `image_congr` -/
theorem image_congr' {f g : α → β} {s : Set α} (h : ∀ x : α, f x = g x) : f '' s = g '' s :=
image_congr fun x _ => h x
#align set.image_congr' Set.image_congr'
@[gcongr]
lemma image_mono (h : s ⊆ t) : f '' s ⊆ f '' t := by
rintro - ⟨a, ha, rfl⟩; exact mem_image_of_mem f (h ha)
theorem image_comp (f : β → γ) (g : α → β) (a : Set α) : f ∘ g '' a = f '' (g '' a) :=
Subset.antisymm (ball_image_of_ball fun _ ha => mem_image_of_mem _ <| mem_image_of_mem _ ha)
(ball_image_of_ball <| ball_image_of_ball fun _ ha => mem_image_of_mem _ ha)
#align set.image_comp Set.image_comp
theorem image_comp_eq {g : β → γ} : image (g ∘ f) = image g ∘ image f := by ext; simp
/-- A variant of `image_comp`, useful for rewriting -/
theorem image_image (g : β → γ) (f : α → β) (s : Set α) : g '' (f '' s) = (fun x => g (f x)) '' s :=
(image_comp g f s).symm
#align set.image_image Set.image_image
theorem image_comm {β'} {f : β → γ} {g : α → β} {f' : α → β'} {g' : β' → γ}
(h_comm : ∀ a, f (g a) = g' (f' a)) : (s.image g).image f = (s.image f').image g' := by
simp_rw [image_image, h_comm]
#align set.image_comm Set.image_comm
theorem _root_.Function.Semiconj.set_image {f : α → β} {ga : α → α} {gb : β → β}
(h : Function.Semiconj f ga gb) : Function.Semiconj (image f) (image ga) (image gb) := fun _ =>
image_comm h
#align function.semiconj.set_image Function.Semiconj.set_image
theorem _root_.Function.Commute.set_image {f g : α → α} (h : Function.Commute f g) :
Function.Commute (image f) (image g) :=
Function.Semiconj.set_image h
#align function.commute.set_image Function.Commute.set_image
/-- Image is monotone with respect to `⊆`. See `Set.monotone_image` for the statement in
terms of `≤`. -/
@[gcongr]
theorem image_subset {a b : Set α} (f : α → β) (h : a ⊆ b) : f '' a ⊆ f '' b := by
simp only [subset_def, mem_image]
exact fun x => fun ⟨w, h1, h2⟩ => ⟨w, h h1, h2⟩
#align set.image_subset Set.image_subset
/-- `Set.image` is monotone. See `Set.image_subset` for the statement in terms of `⊆`. -/
lemma monotone_image {f : α → β} : Monotone (image f) := fun _ _ => image_subset _
#align set.monotone_image Set.monotone_image
theorem image_union (f : α → β) (s t : Set α) : f '' (s ∪ t) = f '' s ∪ f '' t :=
ext fun x =>
⟨by rintro ⟨a, h | h, rfl⟩ <;> [left; right] <;> exact ⟨_, h, rfl⟩, by
rintro (⟨a, h, rfl⟩ | ⟨a, h, rfl⟩) <;> refine' ⟨_, _, rfl⟩ <;> [
|
left
|
theorem image_union (f : α → β) (s t : Set α) : f '' (s ∪ t) = f '' s ∪ f '' t :=
ext fun x =>
⟨by rintro ⟨a, h | h, rfl⟩ <;> [left; right] <;> exact ⟨_, h, rfl⟩, by
rintro (⟨a, h, rfl⟩ | ⟨a, h, rfl⟩) <;> refine' ⟨_, _, rfl⟩ <;> [
|
Mathlib.Data.Set.Image.336_0.IJFiTzmYGOCpPSd
|
theorem image_union (f : α → β) (s t : Set α) : f '' (s ∪ t) = f '' s ∪ f '' t
|
Mathlib_Data_Set_Image
|
case inr.intro.intro
α : Type u_1
β : Type u_2
γ : Type u_3
ι : Sort u_4
ι' : Sort u_5
f✝ : α → β
s✝ t✝ : Set α
f : α → β
s t : Set α
a : α
h : a ∈ t
⊢ a ∈ s ∪ t
|
/-
Copyright (c) 2014 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Leonardo de Moura
-/
import Mathlib.Data.Set.Basic
#align_import data.set.image from "leanprover-community/mathlib"@"001ffdc42920050657fd45bd2b8bfbec8eaaeb29"
/-!
# Images and preimages of sets
## Main definitions
* `preimage f t : Set α` : the preimage f⁻¹(t) (written `f ⁻¹' t` in Lean) of a subset of β.
* `range f : Set β` : the image of `univ` under `f`.
Also works for `{p : Prop} (f : p → α)` (unlike `image`)
## Notation
* `f ⁻¹' t` for `Set.preimage f t`
* `f '' s` for `Set.image f s`
## Tags
set, sets, image, preimage, pre-image, range
-/
set_option autoImplicit true
universe u v
open Function Set
namespace Set
variable {α β γ : Type*} {ι ι' : Sort*}
/-! ### Inverse image -/
/-- The preimage of `s : Set β` by `f : α → β`, written `f ⁻¹' s`,
is the set of `x : α` such that `f x ∈ s`. -/
def preimage {α : Type u} {β : Type v} (f : α → β) (s : Set β) : Set α :=
{ x | f x ∈ s }
#align set.preimage Set.preimage
/-- `f ⁻¹' t` denotes the preimage of `t : Set β` under the function `f : α → β`. -/
infixl:80 " ⁻¹' " => preimage
section Preimage
variable {f : α → β} {g : β → γ}
@[simp]
theorem preimage_empty : f ⁻¹' ∅ = ∅ :=
rfl
#align set.preimage_empty Set.preimage_empty
@[simp, mfld_simps]
theorem mem_preimage {s : Set β} {a : α} : a ∈ f ⁻¹' s ↔ f a ∈ s :=
Iff.rfl
#align set.mem_preimage Set.mem_preimage
theorem preimage_congr {f g : α → β} {s : Set β} (h : ∀ x : α, f x = g x) : f ⁻¹' s = g ⁻¹' s := by
congr with x
simp [h]
#align set.preimage_congr Set.preimage_congr
@[gcongr]
theorem preimage_mono {s t : Set β} (h : s ⊆ t) : f ⁻¹' s ⊆ f ⁻¹' t := fun _ hx => h hx
#align set.preimage_mono Set.preimage_mono
@[simp, mfld_simps]
theorem preimage_univ : f ⁻¹' univ = univ :=
rfl
#align set.preimage_univ Set.preimage_univ
theorem subset_preimage_univ {s : Set α} : s ⊆ f ⁻¹' univ :=
subset_univ _
#align set.subset_preimage_univ Set.subset_preimage_univ
@[simp, mfld_simps]
theorem preimage_inter {s t : Set β} : f ⁻¹' (s ∩ t) = f ⁻¹' s ∩ f ⁻¹' t :=
rfl
#align set.preimage_inter Set.preimage_inter
@[simp]
theorem preimage_union {s t : Set β} : f ⁻¹' (s ∪ t) = f ⁻¹' s ∪ f ⁻¹' t :=
rfl
#align set.preimage_union Set.preimage_union
@[simp]
theorem preimage_compl {s : Set β} : f ⁻¹' sᶜ = (f ⁻¹' s)ᶜ :=
rfl
#align set.preimage_compl Set.preimage_compl
@[simp]
theorem preimage_diff (f : α → β) (s t : Set β) : f ⁻¹' (s \ t) = f ⁻¹' s \ f ⁻¹' t :=
rfl
#align set.preimage_diff Set.preimage_diff
@[simp]
lemma preimage_symmDiff {f : α → β} (s t : Set β) : f ⁻¹' (s ∆ t) = (f ⁻¹' s) ∆ (f ⁻¹' t) :=
rfl
#align set.preimage_symm_diff Set.preimage_symmDiff
@[simp]
theorem preimage_ite (f : α → β) (s t₁ t₂ : Set β) :
f ⁻¹' s.ite t₁ t₂ = (f ⁻¹' s).ite (f ⁻¹' t₁) (f ⁻¹' t₂) :=
rfl
#align set.preimage_ite Set.preimage_ite
@[simp]
theorem preimage_setOf_eq {p : α → Prop} {f : β → α} : f ⁻¹' { a | p a } = { a | p (f a) } :=
rfl
#align set.preimage_set_of_eq Set.preimage_setOf_eq
@[simp]
theorem preimage_id_eq : preimage (id : α → α) = id :=
rfl
#align set.preimage_id_eq Set.preimage_id_eq
@[mfld_simps]
theorem preimage_id {s : Set α} : id ⁻¹' s = s :=
rfl
#align set.preimage_id Set.preimage_id
@[simp, mfld_simps]
theorem preimage_id' {s : Set α} : (fun x => x) ⁻¹' s = s :=
rfl
#align set.preimage_id' Set.preimage_id'
@[simp]
theorem preimage_const_of_mem {b : β} {s : Set β} (h : b ∈ s) : (fun _ : α => b) ⁻¹' s = univ :=
eq_univ_of_forall fun _ => h
#align set.preimage_const_of_mem Set.preimage_const_of_mem
@[simp]
theorem preimage_const_of_not_mem {b : β} {s : Set β} (h : b ∉ s) : (fun _ : α => b) ⁻¹' s = ∅ :=
eq_empty_of_subset_empty fun _ hx => h hx
#align set.preimage_const_of_not_mem Set.preimage_const_of_not_mem
theorem preimage_const (b : β) (s : Set β) [Decidable (b ∈ s)] :
(fun _ : α => b) ⁻¹' s = if b ∈ s then univ else ∅ := by
split_ifs with hb
exacts [preimage_const_of_mem hb, preimage_const_of_not_mem hb]
#align set.preimage_const Set.preimage_const
/-- If preimage of each singleton under `f : α → β` is either empty or the whole type,
then `f` is a constant. -/
lemma exists_eq_const_of_preimage_singleton [Nonempty β] {f : α → β}
(hf : ∀ b : β, f ⁻¹' {b} = ∅ ∨ f ⁻¹' {b} = univ) : ∃ b, f = const α b := by
rcases em (∃ b, f ⁻¹' {b} = univ) with ⟨b, hb⟩ | hf'
· exact ⟨b, funext fun x ↦ eq_univ_iff_forall.1 hb x⟩
· have : ∀ x b, f x ≠ b := fun x b ↦
eq_empty_iff_forall_not_mem.1 ((hf b).resolve_right fun h ↦ hf' ⟨b, h⟩) x
exact ⟨Classical.arbitrary β, funext fun x ↦ absurd rfl (this x _)⟩
theorem preimage_comp {s : Set γ} : g ∘ f ⁻¹' s = f ⁻¹' (g ⁻¹' s) :=
rfl
#align set.preimage_comp Set.preimage_comp
theorem preimage_comp_eq : preimage (g ∘ f) = preimage f ∘ preimage g :=
rfl
#align set.preimage_comp_eq Set.preimage_comp_eq
theorem preimage_iterate_eq {f : α → α} {n : ℕ} : Set.preimage f^[n] = (Set.preimage f)^[n] := by
induction' n with n ih; · simp
rw [iterate_succ, iterate_succ', preimage_comp_eq, ih]
#align set.preimage_iterate_eq Set.preimage_iterate_eq
theorem preimage_preimage {g : β → γ} {f : α → β} {s : Set γ} :
f ⁻¹' (g ⁻¹' s) = (fun x => g (f x)) ⁻¹' s :=
preimage_comp.symm
#align set.preimage_preimage Set.preimage_preimage
theorem eq_preimage_subtype_val_iff {p : α → Prop} {s : Set (Subtype p)} {t : Set α} :
s = Subtype.val ⁻¹' t ↔ ∀ (x) (h : p x), (⟨x, h⟩ : Subtype p) ∈ s ↔ x ∈ t :=
⟨fun s_eq x h => by
rw [s_eq]
simp, fun h => ext fun ⟨x, hx⟩ => by simp [h]⟩
#align set.eq_preimage_subtype_val_iff Set.eq_preimage_subtype_val_iff
theorem nonempty_of_nonempty_preimage {s : Set β} {f : α → β} (hf : (f ⁻¹' s).Nonempty) :
s.Nonempty :=
let ⟨x, hx⟩ := hf
⟨f x, hx⟩
#align set.nonempty_of_nonempty_preimage Set.nonempty_of_nonempty_preimage
@[simp] theorem preimage_singleton_true (p : α → Prop) : p ⁻¹' {True} = {a | p a} := by ext; simp
#align set.preimage_singleton_true Set.preimage_singleton_true
@[simp] theorem preimage_singleton_false (p : α → Prop) : p ⁻¹' {False} = {a | ¬p a} := by ext; simp
#align set.preimage_singleton_false Set.preimage_singleton_false
theorem preimage_subtype_coe_eq_compl {s u v : Set α} (hsuv : s ⊆ u ∪ v)
(H : s ∩ (u ∩ v) = ∅) : ((↑) : s → α) ⁻¹' u = ((↑) ⁻¹' v)ᶜ := by
ext ⟨x, x_in_s⟩
constructor
· intro x_in_u x_in_v
exact eq_empty_iff_forall_not_mem.mp H x ⟨x_in_s, ⟨x_in_u, x_in_v⟩⟩
· intro hx
exact Or.elim (hsuv x_in_s) id fun hx' => hx.elim hx'
#align set.preimage_subtype_coe_eq_compl Set.preimage_subtype_coe_eq_compl
end Preimage
/-! ### Image of a set under a function -/
section Image
variable {f : α → β} {s t : Set α}
-- Porting note: `Set.image` is already defined in `Init.Set`
#align set.image Set.image
/-- `f '' s` denotes the image of `s : Set α` under the function `f : α → β`. -/
infixl:80 " '' " => image
theorem mem_image_iff_bex {f : α → β} {s : Set α} {y : β} :
y ∈ f '' s ↔ ∃ (x : _) (_ : x ∈ s), f x = y :=
bex_def.symm
#align set.mem_image_iff_bex Set.mem_image_iff_bex
@[simp]
theorem mem_image (f : α → β) (s : Set α) (y : β) : y ∈ f '' s ↔ ∃ x ∈ s, f x = y :=
Iff.rfl
#align set.mem_image Set.mem_image
theorem image_eta (f : α → β) : f '' s = (fun x => f x) '' s :=
rfl
#align set.image_eta Set.image_eta
@[mfld_simps]
theorem mem_image_of_mem (f : α → β) {x : α} {a : Set α} (h : x ∈ a) : f x ∈ f '' a :=
⟨_, h, rfl⟩
#align set.mem_image_of_mem Set.mem_image_of_mem
theorem _root_.Function.Injective.mem_set_image {f : α → β} (hf : Injective f) {s : Set α} {a : α} :
f a ∈ f '' s ↔ a ∈ s :=
⟨fun ⟨_, hb, Eq⟩ => hf Eq ▸ hb, mem_image_of_mem f⟩
#align function.injective.mem_set_image Function.Injective.mem_set_image
theorem ball_image_iff {f : α → β} {s : Set α} {p : β → Prop} :
(∀ y ∈ f '' s, p y) ↔ ∀ x ∈ s, p (f x) := by simp
#align set.ball_image_iff Set.ball_image_iff
theorem ball_image_of_ball {f : α → β} {s : Set α} {p : β → Prop} (h : ∀ x ∈ s, p (f x)) :
∀ y ∈ f '' s, p y :=
ball_image_iff.2 h
#align set.ball_image_of_ball Set.ball_image_of_ball
theorem bex_image_iff {f : α → β} {s : Set α} {p : β → Prop} :
(∃ y ∈ f '' s, p y) ↔ ∃ x ∈ s, p (f x) := by simp
#align set.bex_image_iff Set.bex_image_iff
theorem mem_image_elim {f : α → β} {s : Set α} {C : β → Prop} (h : ∀ x : α, x ∈ s → C (f x)) :
∀ {y : β}, y ∈ f '' s → C y
| _, ⟨a, a_in, rfl⟩ => h a a_in
#align set.mem_image_elim Set.mem_image_elim
theorem mem_image_elim_on {f : α → β} {s : Set α} {C : β → Prop} {y : β} (h_y : y ∈ f '' s)
(h : ∀ x : α, x ∈ s → C (f x)) : C y :=
mem_image_elim h h_y
#align set.mem_image_elim_on Set.mem_image_elim_on
-- Porting note: used to be `safe`
@[congr]
theorem image_congr {f g : α → β} {s : Set α} (h : ∀ a ∈ s, f a = g a) : f '' s = g '' s := by
ext x
rw [mem_image, mem_image]
exact {
mp := by
rintro ⟨a, ha1, ha2⟩
exact ⟨a, ⟨ha1, (h a ha1) ▸ ha2⟩⟩,
mpr := by
rintro ⟨a, ha1, ha2⟩
exact ⟨a, ⟨ha1, (h a ha1) ▸ ha2⟩⟩
}
-- safe [ext_iff, iff_def]
#align set.image_congr Set.image_congr
/-- A common special case of `image_congr` -/
theorem image_congr' {f g : α → β} {s : Set α} (h : ∀ x : α, f x = g x) : f '' s = g '' s :=
image_congr fun x _ => h x
#align set.image_congr' Set.image_congr'
@[gcongr]
lemma image_mono (h : s ⊆ t) : f '' s ⊆ f '' t := by
rintro - ⟨a, ha, rfl⟩; exact mem_image_of_mem f (h ha)
theorem image_comp (f : β → γ) (g : α → β) (a : Set α) : f ∘ g '' a = f '' (g '' a) :=
Subset.antisymm (ball_image_of_ball fun _ ha => mem_image_of_mem _ <| mem_image_of_mem _ ha)
(ball_image_of_ball <| ball_image_of_ball fun _ ha => mem_image_of_mem _ ha)
#align set.image_comp Set.image_comp
theorem image_comp_eq {g : β → γ} : image (g ∘ f) = image g ∘ image f := by ext; simp
/-- A variant of `image_comp`, useful for rewriting -/
theorem image_image (g : β → γ) (f : α → β) (s : Set α) : g '' (f '' s) = (fun x => g (f x)) '' s :=
(image_comp g f s).symm
#align set.image_image Set.image_image
theorem image_comm {β'} {f : β → γ} {g : α → β} {f' : α → β'} {g' : β' → γ}
(h_comm : ∀ a, f (g a) = g' (f' a)) : (s.image g).image f = (s.image f').image g' := by
simp_rw [image_image, h_comm]
#align set.image_comm Set.image_comm
theorem _root_.Function.Semiconj.set_image {f : α → β} {ga : α → α} {gb : β → β}
(h : Function.Semiconj f ga gb) : Function.Semiconj (image f) (image ga) (image gb) := fun _ =>
image_comm h
#align function.semiconj.set_image Function.Semiconj.set_image
theorem _root_.Function.Commute.set_image {f g : α → α} (h : Function.Commute f g) :
Function.Commute (image f) (image g) :=
Function.Semiconj.set_image h
#align function.commute.set_image Function.Commute.set_image
/-- Image is monotone with respect to `⊆`. See `Set.monotone_image` for the statement in
terms of `≤`. -/
@[gcongr]
theorem image_subset {a b : Set α} (f : α → β) (h : a ⊆ b) : f '' a ⊆ f '' b := by
simp only [subset_def, mem_image]
exact fun x => fun ⟨w, h1, h2⟩ => ⟨w, h h1, h2⟩
#align set.image_subset Set.image_subset
/-- `Set.image` is monotone. See `Set.image_subset` for the statement in terms of `⊆`. -/
lemma monotone_image {f : α → β} : Monotone (image f) := fun _ _ => image_subset _
#align set.monotone_image Set.monotone_image
theorem image_union (f : α → β) (s t : Set α) : f '' (s ∪ t) = f '' s ∪ f '' t :=
ext fun x =>
⟨by rintro ⟨a, h | h, rfl⟩ <;> [left; right] <;> exact ⟨_, h, rfl⟩, by
rintro (⟨a, h, rfl⟩ | ⟨a, h, rfl⟩) <;> refine' ⟨_, _, rfl⟩ <;> [left;
|
right
|
theorem image_union (f : α → β) (s t : Set α) : f '' (s ∪ t) = f '' s ∪ f '' t :=
ext fun x =>
⟨by rintro ⟨a, h | h, rfl⟩ <;> [left; right] <;> exact ⟨_, h, rfl⟩, by
rintro (⟨a, h, rfl⟩ | ⟨a, h, rfl⟩) <;> refine' ⟨_, _, rfl⟩ <;> [left;
|
Mathlib.Data.Set.Image.336_0.IJFiTzmYGOCpPSd
|
theorem image_union (f : α → β) (s t : Set α) : f '' (s ∪ t) = f '' s ∪ f '' t
|
Mathlib_Data_Set_Image
|
case inl.intro.intro.h
α : Type u_1
β : Type u_2
γ : Type u_3
ι : Sort u_4
ι' : Sort u_5
f✝ : α → β
s✝ t✝ : Set α
f : α → β
s t : Set α
a : α
h : a ∈ s
⊢ a ∈ s
|
/-
Copyright (c) 2014 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Leonardo de Moura
-/
import Mathlib.Data.Set.Basic
#align_import data.set.image from "leanprover-community/mathlib"@"001ffdc42920050657fd45bd2b8bfbec8eaaeb29"
/-!
# Images and preimages of sets
## Main definitions
* `preimage f t : Set α` : the preimage f⁻¹(t) (written `f ⁻¹' t` in Lean) of a subset of β.
* `range f : Set β` : the image of `univ` under `f`.
Also works for `{p : Prop} (f : p → α)` (unlike `image`)
## Notation
* `f ⁻¹' t` for `Set.preimage f t`
* `f '' s` for `Set.image f s`
## Tags
set, sets, image, preimage, pre-image, range
-/
set_option autoImplicit true
universe u v
open Function Set
namespace Set
variable {α β γ : Type*} {ι ι' : Sort*}
/-! ### Inverse image -/
/-- The preimage of `s : Set β` by `f : α → β`, written `f ⁻¹' s`,
is the set of `x : α` such that `f x ∈ s`. -/
def preimage {α : Type u} {β : Type v} (f : α → β) (s : Set β) : Set α :=
{ x | f x ∈ s }
#align set.preimage Set.preimage
/-- `f ⁻¹' t` denotes the preimage of `t : Set β` under the function `f : α → β`. -/
infixl:80 " ⁻¹' " => preimage
section Preimage
variable {f : α → β} {g : β → γ}
@[simp]
theorem preimage_empty : f ⁻¹' ∅ = ∅ :=
rfl
#align set.preimage_empty Set.preimage_empty
@[simp, mfld_simps]
theorem mem_preimage {s : Set β} {a : α} : a ∈ f ⁻¹' s ↔ f a ∈ s :=
Iff.rfl
#align set.mem_preimage Set.mem_preimage
theorem preimage_congr {f g : α → β} {s : Set β} (h : ∀ x : α, f x = g x) : f ⁻¹' s = g ⁻¹' s := by
congr with x
simp [h]
#align set.preimage_congr Set.preimage_congr
@[gcongr]
theorem preimage_mono {s t : Set β} (h : s ⊆ t) : f ⁻¹' s ⊆ f ⁻¹' t := fun _ hx => h hx
#align set.preimage_mono Set.preimage_mono
@[simp, mfld_simps]
theorem preimage_univ : f ⁻¹' univ = univ :=
rfl
#align set.preimage_univ Set.preimage_univ
theorem subset_preimage_univ {s : Set α} : s ⊆ f ⁻¹' univ :=
subset_univ _
#align set.subset_preimage_univ Set.subset_preimage_univ
@[simp, mfld_simps]
theorem preimage_inter {s t : Set β} : f ⁻¹' (s ∩ t) = f ⁻¹' s ∩ f ⁻¹' t :=
rfl
#align set.preimage_inter Set.preimage_inter
@[simp]
theorem preimage_union {s t : Set β} : f ⁻¹' (s ∪ t) = f ⁻¹' s ∪ f ⁻¹' t :=
rfl
#align set.preimage_union Set.preimage_union
@[simp]
theorem preimage_compl {s : Set β} : f ⁻¹' sᶜ = (f ⁻¹' s)ᶜ :=
rfl
#align set.preimage_compl Set.preimage_compl
@[simp]
theorem preimage_diff (f : α → β) (s t : Set β) : f ⁻¹' (s \ t) = f ⁻¹' s \ f ⁻¹' t :=
rfl
#align set.preimage_diff Set.preimage_diff
@[simp]
lemma preimage_symmDiff {f : α → β} (s t : Set β) : f ⁻¹' (s ∆ t) = (f ⁻¹' s) ∆ (f ⁻¹' t) :=
rfl
#align set.preimage_symm_diff Set.preimage_symmDiff
@[simp]
theorem preimage_ite (f : α → β) (s t₁ t₂ : Set β) :
f ⁻¹' s.ite t₁ t₂ = (f ⁻¹' s).ite (f ⁻¹' t₁) (f ⁻¹' t₂) :=
rfl
#align set.preimage_ite Set.preimage_ite
@[simp]
theorem preimage_setOf_eq {p : α → Prop} {f : β → α} : f ⁻¹' { a | p a } = { a | p (f a) } :=
rfl
#align set.preimage_set_of_eq Set.preimage_setOf_eq
@[simp]
theorem preimage_id_eq : preimage (id : α → α) = id :=
rfl
#align set.preimage_id_eq Set.preimage_id_eq
@[mfld_simps]
theorem preimage_id {s : Set α} : id ⁻¹' s = s :=
rfl
#align set.preimage_id Set.preimage_id
@[simp, mfld_simps]
theorem preimage_id' {s : Set α} : (fun x => x) ⁻¹' s = s :=
rfl
#align set.preimage_id' Set.preimage_id'
@[simp]
theorem preimage_const_of_mem {b : β} {s : Set β} (h : b ∈ s) : (fun _ : α => b) ⁻¹' s = univ :=
eq_univ_of_forall fun _ => h
#align set.preimage_const_of_mem Set.preimage_const_of_mem
@[simp]
theorem preimage_const_of_not_mem {b : β} {s : Set β} (h : b ∉ s) : (fun _ : α => b) ⁻¹' s = ∅ :=
eq_empty_of_subset_empty fun _ hx => h hx
#align set.preimage_const_of_not_mem Set.preimage_const_of_not_mem
theorem preimage_const (b : β) (s : Set β) [Decidable (b ∈ s)] :
(fun _ : α => b) ⁻¹' s = if b ∈ s then univ else ∅ := by
split_ifs with hb
exacts [preimage_const_of_mem hb, preimage_const_of_not_mem hb]
#align set.preimage_const Set.preimage_const
/-- If preimage of each singleton under `f : α → β` is either empty or the whole type,
then `f` is a constant. -/
lemma exists_eq_const_of_preimage_singleton [Nonempty β] {f : α → β}
(hf : ∀ b : β, f ⁻¹' {b} = ∅ ∨ f ⁻¹' {b} = univ) : ∃ b, f = const α b := by
rcases em (∃ b, f ⁻¹' {b} = univ) with ⟨b, hb⟩ | hf'
· exact ⟨b, funext fun x ↦ eq_univ_iff_forall.1 hb x⟩
· have : ∀ x b, f x ≠ b := fun x b ↦
eq_empty_iff_forall_not_mem.1 ((hf b).resolve_right fun h ↦ hf' ⟨b, h⟩) x
exact ⟨Classical.arbitrary β, funext fun x ↦ absurd rfl (this x _)⟩
theorem preimage_comp {s : Set γ} : g ∘ f ⁻¹' s = f ⁻¹' (g ⁻¹' s) :=
rfl
#align set.preimage_comp Set.preimage_comp
theorem preimage_comp_eq : preimage (g ∘ f) = preimage f ∘ preimage g :=
rfl
#align set.preimage_comp_eq Set.preimage_comp_eq
theorem preimage_iterate_eq {f : α → α} {n : ℕ} : Set.preimage f^[n] = (Set.preimage f)^[n] := by
induction' n with n ih; · simp
rw [iterate_succ, iterate_succ', preimage_comp_eq, ih]
#align set.preimage_iterate_eq Set.preimage_iterate_eq
theorem preimage_preimage {g : β → γ} {f : α → β} {s : Set γ} :
f ⁻¹' (g ⁻¹' s) = (fun x => g (f x)) ⁻¹' s :=
preimage_comp.symm
#align set.preimage_preimage Set.preimage_preimage
theorem eq_preimage_subtype_val_iff {p : α → Prop} {s : Set (Subtype p)} {t : Set α} :
s = Subtype.val ⁻¹' t ↔ ∀ (x) (h : p x), (⟨x, h⟩ : Subtype p) ∈ s ↔ x ∈ t :=
⟨fun s_eq x h => by
rw [s_eq]
simp, fun h => ext fun ⟨x, hx⟩ => by simp [h]⟩
#align set.eq_preimage_subtype_val_iff Set.eq_preimage_subtype_val_iff
theorem nonempty_of_nonempty_preimage {s : Set β} {f : α → β} (hf : (f ⁻¹' s).Nonempty) :
s.Nonempty :=
let ⟨x, hx⟩ := hf
⟨f x, hx⟩
#align set.nonempty_of_nonempty_preimage Set.nonempty_of_nonempty_preimage
@[simp] theorem preimage_singleton_true (p : α → Prop) : p ⁻¹' {True} = {a | p a} := by ext; simp
#align set.preimage_singleton_true Set.preimage_singleton_true
@[simp] theorem preimage_singleton_false (p : α → Prop) : p ⁻¹' {False} = {a | ¬p a} := by ext; simp
#align set.preimage_singleton_false Set.preimage_singleton_false
theorem preimage_subtype_coe_eq_compl {s u v : Set α} (hsuv : s ⊆ u ∪ v)
(H : s ∩ (u ∩ v) = ∅) : ((↑) : s → α) ⁻¹' u = ((↑) ⁻¹' v)ᶜ := by
ext ⟨x, x_in_s⟩
constructor
· intro x_in_u x_in_v
exact eq_empty_iff_forall_not_mem.mp H x ⟨x_in_s, ⟨x_in_u, x_in_v⟩⟩
· intro hx
exact Or.elim (hsuv x_in_s) id fun hx' => hx.elim hx'
#align set.preimage_subtype_coe_eq_compl Set.preimage_subtype_coe_eq_compl
end Preimage
/-! ### Image of a set under a function -/
section Image
variable {f : α → β} {s t : Set α}
-- Porting note: `Set.image` is already defined in `Init.Set`
#align set.image Set.image
/-- `f '' s` denotes the image of `s : Set α` under the function `f : α → β`. -/
infixl:80 " '' " => image
theorem mem_image_iff_bex {f : α → β} {s : Set α} {y : β} :
y ∈ f '' s ↔ ∃ (x : _) (_ : x ∈ s), f x = y :=
bex_def.symm
#align set.mem_image_iff_bex Set.mem_image_iff_bex
@[simp]
theorem mem_image (f : α → β) (s : Set α) (y : β) : y ∈ f '' s ↔ ∃ x ∈ s, f x = y :=
Iff.rfl
#align set.mem_image Set.mem_image
theorem image_eta (f : α → β) : f '' s = (fun x => f x) '' s :=
rfl
#align set.image_eta Set.image_eta
@[mfld_simps]
theorem mem_image_of_mem (f : α → β) {x : α} {a : Set α} (h : x ∈ a) : f x ∈ f '' a :=
⟨_, h, rfl⟩
#align set.mem_image_of_mem Set.mem_image_of_mem
theorem _root_.Function.Injective.mem_set_image {f : α → β} (hf : Injective f) {s : Set α} {a : α} :
f a ∈ f '' s ↔ a ∈ s :=
⟨fun ⟨_, hb, Eq⟩ => hf Eq ▸ hb, mem_image_of_mem f⟩
#align function.injective.mem_set_image Function.Injective.mem_set_image
theorem ball_image_iff {f : α → β} {s : Set α} {p : β → Prop} :
(∀ y ∈ f '' s, p y) ↔ ∀ x ∈ s, p (f x) := by simp
#align set.ball_image_iff Set.ball_image_iff
theorem ball_image_of_ball {f : α → β} {s : Set α} {p : β → Prop} (h : ∀ x ∈ s, p (f x)) :
∀ y ∈ f '' s, p y :=
ball_image_iff.2 h
#align set.ball_image_of_ball Set.ball_image_of_ball
theorem bex_image_iff {f : α → β} {s : Set α} {p : β → Prop} :
(∃ y ∈ f '' s, p y) ↔ ∃ x ∈ s, p (f x) := by simp
#align set.bex_image_iff Set.bex_image_iff
theorem mem_image_elim {f : α → β} {s : Set α} {C : β → Prop} (h : ∀ x : α, x ∈ s → C (f x)) :
∀ {y : β}, y ∈ f '' s → C y
| _, ⟨a, a_in, rfl⟩ => h a a_in
#align set.mem_image_elim Set.mem_image_elim
theorem mem_image_elim_on {f : α → β} {s : Set α} {C : β → Prop} {y : β} (h_y : y ∈ f '' s)
(h : ∀ x : α, x ∈ s → C (f x)) : C y :=
mem_image_elim h h_y
#align set.mem_image_elim_on Set.mem_image_elim_on
-- Porting note: used to be `safe`
@[congr]
theorem image_congr {f g : α → β} {s : Set α} (h : ∀ a ∈ s, f a = g a) : f '' s = g '' s := by
ext x
rw [mem_image, mem_image]
exact {
mp := by
rintro ⟨a, ha1, ha2⟩
exact ⟨a, ⟨ha1, (h a ha1) ▸ ha2⟩⟩,
mpr := by
rintro ⟨a, ha1, ha2⟩
exact ⟨a, ⟨ha1, (h a ha1) ▸ ha2⟩⟩
}
-- safe [ext_iff, iff_def]
#align set.image_congr Set.image_congr
/-- A common special case of `image_congr` -/
theorem image_congr' {f g : α → β} {s : Set α} (h : ∀ x : α, f x = g x) : f '' s = g '' s :=
image_congr fun x _ => h x
#align set.image_congr' Set.image_congr'
@[gcongr]
lemma image_mono (h : s ⊆ t) : f '' s ⊆ f '' t := by
rintro - ⟨a, ha, rfl⟩; exact mem_image_of_mem f (h ha)
theorem image_comp (f : β → γ) (g : α → β) (a : Set α) : f ∘ g '' a = f '' (g '' a) :=
Subset.antisymm (ball_image_of_ball fun _ ha => mem_image_of_mem _ <| mem_image_of_mem _ ha)
(ball_image_of_ball <| ball_image_of_ball fun _ ha => mem_image_of_mem _ ha)
#align set.image_comp Set.image_comp
theorem image_comp_eq {g : β → γ} : image (g ∘ f) = image g ∘ image f := by ext; simp
/-- A variant of `image_comp`, useful for rewriting -/
theorem image_image (g : β → γ) (f : α → β) (s : Set α) : g '' (f '' s) = (fun x => g (f x)) '' s :=
(image_comp g f s).symm
#align set.image_image Set.image_image
theorem image_comm {β'} {f : β → γ} {g : α → β} {f' : α → β'} {g' : β' → γ}
(h_comm : ∀ a, f (g a) = g' (f' a)) : (s.image g).image f = (s.image f').image g' := by
simp_rw [image_image, h_comm]
#align set.image_comm Set.image_comm
theorem _root_.Function.Semiconj.set_image {f : α → β} {ga : α → α} {gb : β → β}
(h : Function.Semiconj f ga gb) : Function.Semiconj (image f) (image ga) (image gb) := fun _ =>
image_comm h
#align function.semiconj.set_image Function.Semiconj.set_image
theorem _root_.Function.Commute.set_image {f g : α → α} (h : Function.Commute f g) :
Function.Commute (image f) (image g) :=
Function.Semiconj.set_image h
#align function.commute.set_image Function.Commute.set_image
/-- Image is monotone with respect to `⊆`. See `Set.monotone_image` for the statement in
terms of `≤`. -/
@[gcongr]
theorem image_subset {a b : Set α} (f : α → β) (h : a ⊆ b) : f '' a ⊆ f '' b := by
simp only [subset_def, mem_image]
exact fun x => fun ⟨w, h1, h2⟩ => ⟨w, h h1, h2⟩
#align set.image_subset Set.image_subset
/-- `Set.image` is monotone. See `Set.image_subset` for the statement in terms of `⊆`. -/
lemma monotone_image {f : α → β} : Monotone (image f) := fun _ _ => image_subset _
#align set.monotone_image Set.monotone_image
theorem image_union (f : α → β) (s t : Set α) : f '' (s ∪ t) = f '' s ∪ f '' t :=
ext fun x =>
⟨by rintro ⟨a, h | h, rfl⟩ <;> [left; right] <;> exact ⟨_, h, rfl⟩, by
rintro (⟨a, h, rfl⟩ | ⟨a, h, rfl⟩) <;> refine' ⟨_, _, rfl⟩ <;> [left; right] <;>
|
exact h
|
theorem image_union (f : α → β) (s t : Set α) : f '' (s ∪ t) = f '' s ∪ f '' t :=
ext fun x =>
⟨by rintro ⟨a, h | h, rfl⟩ <;> [left; right] <;> exact ⟨_, h, rfl⟩, by
rintro (⟨a, h, rfl⟩ | ⟨a, h, rfl⟩) <;> refine' ⟨_, _, rfl⟩ <;> [left; right] <;>
|
Mathlib.Data.Set.Image.336_0.IJFiTzmYGOCpPSd
|
theorem image_union (f : α → β) (s t : Set α) : f '' (s ∪ t) = f '' s ∪ f '' t
|
Mathlib_Data_Set_Image
|
case inr.intro.intro.h
α : Type u_1
β : Type u_2
γ : Type u_3
ι : Sort u_4
ι' : Sort u_5
f✝ : α → β
s✝ t✝ : Set α
f : α → β
s t : Set α
a : α
h : a ∈ t
⊢ a ∈ t
|
/-
Copyright (c) 2014 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Leonardo de Moura
-/
import Mathlib.Data.Set.Basic
#align_import data.set.image from "leanprover-community/mathlib"@"001ffdc42920050657fd45bd2b8bfbec8eaaeb29"
/-!
# Images and preimages of sets
## Main definitions
* `preimage f t : Set α` : the preimage f⁻¹(t) (written `f ⁻¹' t` in Lean) of a subset of β.
* `range f : Set β` : the image of `univ` under `f`.
Also works for `{p : Prop} (f : p → α)` (unlike `image`)
## Notation
* `f ⁻¹' t` for `Set.preimage f t`
* `f '' s` for `Set.image f s`
## Tags
set, sets, image, preimage, pre-image, range
-/
set_option autoImplicit true
universe u v
open Function Set
namespace Set
variable {α β γ : Type*} {ι ι' : Sort*}
/-! ### Inverse image -/
/-- The preimage of `s : Set β` by `f : α → β`, written `f ⁻¹' s`,
is the set of `x : α` such that `f x ∈ s`. -/
def preimage {α : Type u} {β : Type v} (f : α → β) (s : Set β) : Set α :=
{ x | f x ∈ s }
#align set.preimage Set.preimage
/-- `f ⁻¹' t` denotes the preimage of `t : Set β` under the function `f : α → β`. -/
infixl:80 " ⁻¹' " => preimage
section Preimage
variable {f : α → β} {g : β → γ}
@[simp]
theorem preimage_empty : f ⁻¹' ∅ = ∅ :=
rfl
#align set.preimage_empty Set.preimage_empty
@[simp, mfld_simps]
theorem mem_preimage {s : Set β} {a : α} : a ∈ f ⁻¹' s ↔ f a ∈ s :=
Iff.rfl
#align set.mem_preimage Set.mem_preimage
theorem preimage_congr {f g : α → β} {s : Set β} (h : ∀ x : α, f x = g x) : f ⁻¹' s = g ⁻¹' s := by
congr with x
simp [h]
#align set.preimage_congr Set.preimage_congr
@[gcongr]
theorem preimage_mono {s t : Set β} (h : s ⊆ t) : f ⁻¹' s ⊆ f ⁻¹' t := fun _ hx => h hx
#align set.preimage_mono Set.preimage_mono
@[simp, mfld_simps]
theorem preimage_univ : f ⁻¹' univ = univ :=
rfl
#align set.preimage_univ Set.preimage_univ
theorem subset_preimage_univ {s : Set α} : s ⊆ f ⁻¹' univ :=
subset_univ _
#align set.subset_preimage_univ Set.subset_preimage_univ
@[simp, mfld_simps]
theorem preimage_inter {s t : Set β} : f ⁻¹' (s ∩ t) = f ⁻¹' s ∩ f ⁻¹' t :=
rfl
#align set.preimage_inter Set.preimage_inter
@[simp]
theorem preimage_union {s t : Set β} : f ⁻¹' (s ∪ t) = f ⁻¹' s ∪ f ⁻¹' t :=
rfl
#align set.preimage_union Set.preimage_union
@[simp]
theorem preimage_compl {s : Set β} : f ⁻¹' sᶜ = (f ⁻¹' s)ᶜ :=
rfl
#align set.preimage_compl Set.preimage_compl
@[simp]
theorem preimage_diff (f : α → β) (s t : Set β) : f ⁻¹' (s \ t) = f ⁻¹' s \ f ⁻¹' t :=
rfl
#align set.preimage_diff Set.preimage_diff
@[simp]
lemma preimage_symmDiff {f : α → β} (s t : Set β) : f ⁻¹' (s ∆ t) = (f ⁻¹' s) ∆ (f ⁻¹' t) :=
rfl
#align set.preimage_symm_diff Set.preimage_symmDiff
@[simp]
theorem preimage_ite (f : α → β) (s t₁ t₂ : Set β) :
f ⁻¹' s.ite t₁ t₂ = (f ⁻¹' s).ite (f ⁻¹' t₁) (f ⁻¹' t₂) :=
rfl
#align set.preimage_ite Set.preimage_ite
@[simp]
theorem preimage_setOf_eq {p : α → Prop} {f : β → α} : f ⁻¹' { a | p a } = { a | p (f a) } :=
rfl
#align set.preimage_set_of_eq Set.preimage_setOf_eq
@[simp]
theorem preimage_id_eq : preimage (id : α → α) = id :=
rfl
#align set.preimage_id_eq Set.preimage_id_eq
@[mfld_simps]
theorem preimage_id {s : Set α} : id ⁻¹' s = s :=
rfl
#align set.preimage_id Set.preimage_id
@[simp, mfld_simps]
theorem preimage_id' {s : Set α} : (fun x => x) ⁻¹' s = s :=
rfl
#align set.preimage_id' Set.preimage_id'
@[simp]
theorem preimage_const_of_mem {b : β} {s : Set β} (h : b ∈ s) : (fun _ : α => b) ⁻¹' s = univ :=
eq_univ_of_forall fun _ => h
#align set.preimage_const_of_mem Set.preimage_const_of_mem
@[simp]
theorem preimage_const_of_not_mem {b : β} {s : Set β} (h : b ∉ s) : (fun _ : α => b) ⁻¹' s = ∅ :=
eq_empty_of_subset_empty fun _ hx => h hx
#align set.preimage_const_of_not_mem Set.preimage_const_of_not_mem
theorem preimage_const (b : β) (s : Set β) [Decidable (b ∈ s)] :
(fun _ : α => b) ⁻¹' s = if b ∈ s then univ else ∅ := by
split_ifs with hb
exacts [preimage_const_of_mem hb, preimage_const_of_not_mem hb]
#align set.preimage_const Set.preimage_const
/-- If preimage of each singleton under `f : α → β` is either empty or the whole type,
then `f` is a constant. -/
lemma exists_eq_const_of_preimage_singleton [Nonempty β] {f : α → β}
(hf : ∀ b : β, f ⁻¹' {b} = ∅ ∨ f ⁻¹' {b} = univ) : ∃ b, f = const α b := by
rcases em (∃ b, f ⁻¹' {b} = univ) with ⟨b, hb⟩ | hf'
· exact ⟨b, funext fun x ↦ eq_univ_iff_forall.1 hb x⟩
· have : ∀ x b, f x ≠ b := fun x b ↦
eq_empty_iff_forall_not_mem.1 ((hf b).resolve_right fun h ↦ hf' ⟨b, h⟩) x
exact ⟨Classical.arbitrary β, funext fun x ↦ absurd rfl (this x _)⟩
theorem preimage_comp {s : Set γ} : g ∘ f ⁻¹' s = f ⁻¹' (g ⁻¹' s) :=
rfl
#align set.preimage_comp Set.preimage_comp
theorem preimage_comp_eq : preimage (g ∘ f) = preimage f ∘ preimage g :=
rfl
#align set.preimage_comp_eq Set.preimage_comp_eq
theorem preimage_iterate_eq {f : α → α} {n : ℕ} : Set.preimage f^[n] = (Set.preimage f)^[n] := by
induction' n with n ih; · simp
rw [iterate_succ, iterate_succ', preimage_comp_eq, ih]
#align set.preimage_iterate_eq Set.preimage_iterate_eq
theorem preimage_preimage {g : β → γ} {f : α → β} {s : Set γ} :
f ⁻¹' (g ⁻¹' s) = (fun x => g (f x)) ⁻¹' s :=
preimage_comp.symm
#align set.preimage_preimage Set.preimage_preimage
theorem eq_preimage_subtype_val_iff {p : α → Prop} {s : Set (Subtype p)} {t : Set α} :
s = Subtype.val ⁻¹' t ↔ ∀ (x) (h : p x), (⟨x, h⟩ : Subtype p) ∈ s ↔ x ∈ t :=
⟨fun s_eq x h => by
rw [s_eq]
simp, fun h => ext fun ⟨x, hx⟩ => by simp [h]⟩
#align set.eq_preimage_subtype_val_iff Set.eq_preimage_subtype_val_iff
theorem nonempty_of_nonempty_preimage {s : Set β} {f : α → β} (hf : (f ⁻¹' s).Nonempty) :
s.Nonempty :=
let ⟨x, hx⟩ := hf
⟨f x, hx⟩
#align set.nonempty_of_nonempty_preimage Set.nonempty_of_nonempty_preimage
@[simp] theorem preimage_singleton_true (p : α → Prop) : p ⁻¹' {True} = {a | p a} := by ext; simp
#align set.preimage_singleton_true Set.preimage_singleton_true
@[simp] theorem preimage_singleton_false (p : α → Prop) : p ⁻¹' {False} = {a | ¬p a} := by ext; simp
#align set.preimage_singleton_false Set.preimage_singleton_false
theorem preimage_subtype_coe_eq_compl {s u v : Set α} (hsuv : s ⊆ u ∪ v)
(H : s ∩ (u ∩ v) = ∅) : ((↑) : s → α) ⁻¹' u = ((↑) ⁻¹' v)ᶜ := by
ext ⟨x, x_in_s⟩
constructor
· intro x_in_u x_in_v
exact eq_empty_iff_forall_not_mem.mp H x ⟨x_in_s, ⟨x_in_u, x_in_v⟩⟩
· intro hx
exact Or.elim (hsuv x_in_s) id fun hx' => hx.elim hx'
#align set.preimage_subtype_coe_eq_compl Set.preimage_subtype_coe_eq_compl
end Preimage
/-! ### Image of a set under a function -/
section Image
variable {f : α → β} {s t : Set α}
-- Porting note: `Set.image` is already defined in `Init.Set`
#align set.image Set.image
/-- `f '' s` denotes the image of `s : Set α` under the function `f : α → β`. -/
infixl:80 " '' " => image
theorem mem_image_iff_bex {f : α → β} {s : Set α} {y : β} :
y ∈ f '' s ↔ ∃ (x : _) (_ : x ∈ s), f x = y :=
bex_def.symm
#align set.mem_image_iff_bex Set.mem_image_iff_bex
@[simp]
theorem mem_image (f : α → β) (s : Set α) (y : β) : y ∈ f '' s ↔ ∃ x ∈ s, f x = y :=
Iff.rfl
#align set.mem_image Set.mem_image
theorem image_eta (f : α → β) : f '' s = (fun x => f x) '' s :=
rfl
#align set.image_eta Set.image_eta
@[mfld_simps]
theorem mem_image_of_mem (f : α → β) {x : α} {a : Set α} (h : x ∈ a) : f x ∈ f '' a :=
⟨_, h, rfl⟩
#align set.mem_image_of_mem Set.mem_image_of_mem
theorem _root_.Function.Injective.mem_set_image {f : α → β} (hf : Injective f) {s : Set α} {a : α} :
f a ∈ f '' s ↔ a ∈ s :=
⟨fun ⟨_, hb, Eq⟩ => hf Eq ▸ hb, mem_image_of_mem f⟩
#align function.injective.mem_set_image Function.Injective.mem_set_image
theorem ball_image_iff {f : α → β} {s : Set α} {p : β → Prop} :
(∀ y ∈ f '' s, p y) ↔ ∀ x ∈ s, p (f x) := by simp
#align set.ball_image_iff Set.ball_image_iff
theorem ball_image_of_ball {f : α → β} {s : Set α} {p : β → Prop} (h : ∀ x ∈ s, p (f x)) :
∀ y ∈ f '' s, p y :=
ball_image_iff.2 h
#align set.ball_image_of_ball Set.ball_image_of_ball
theorem bex_image_iff {f : α → β} {s : Set α} {p : β → Prop} :
(∃ y ∈ f '' s, p y) ↔ ∃ x ∈ s, p (f x) := by simp
#align set.bex_image_iff Set.bex_image_iff
theorem mem_image_elim {f : α → β} {s : Set α} {C : β → Prop} (h : ∀ x : α, x ∈ s → C (f x)) :
∀ {y : β}, y ∈ f '' s → C y
| _, ⟨a, a_in, rfl⟩ => h a a_in
#align set.mem_image_elim Set.mem_image_elim
theorem mem_image_elim_on {f : α → β} {s : Set α} {C : β → Prop} {y : β} (h_y : y ∈ f '' s)
(h : ∀ x : α, x ∈ s → C (f x)) : C y :=
mem_image_elim h h_y
#align set.mem_image_elim_on Set.mem_image_elim_on
-- Porting note: used to be `safe`
@[congr]
theorem image_congr {f g : α → β} {s : Set α} (h : ∀ a ∈ s, f a = g a) : f '' s = g '' s := by
ext x
rw [mem_image, mem_image]
exact {
mp := by
rintro ⟨a, ha1, ha2⟩
exact ⟨a, ⟨ha1, (h a ha1) ▸ ha2⟩⟩,
mpr := by
rintro ⟨a, ha1, ha2⟩
exact ⟨a, ⟨ha1, (h a ha1) ▸ ha2⟩⟩
}
-- safe [ext_iff, iff_def]
#align set.image_congr Set.image_congr
/-- A common special case of `image_congr` -/
theorem image_congr' {f g : α → β} {s : Set α} (h : ∀ x : α, f x = g x) : f '' s = g '' s :=
image_congr fun x _ => h x
#align set.image_congr' Set.image_congr'
@[gcongr]
lemma image_mono (h : s ⊆ t) : f '' s ⊆ f '' t := by
rintro - ⟨a, ha, rfl⟩; exact mem_image_of_mem f (h ha)
theorem image_comp (f : β → γ) (g : α → β) (a : Set α) : f ∘ g '' a = f '' (g '' a) :=
Subset.antisymm (ball_image_of_ball fun _ ha => mem_image_of_mem _ <| mem_image_of_mem _ ha)
(ball_image_of_ball <| ball_image_of_ball fun _ ha => mem_image_of_mem _ ha)
#align set.image_comp Set.image_comp
theorem image_comp_eq {g : β → γ} : image (g ∘ f) = image g ∘ image f := by ext; simp
/-- A variant of `image_comp`, useful for rewriting -/
theorem image_image (g : β → γ) (f : α → β) (s : Set α) : g '' (f '' s) = (fun x => g (f x)) '' s :=
(image_comp g f s).symm
#align set.image_image Set.image_image
theorem image_comm {β'} {f : β → γ} {g : α → β} {f' : α → β'} {g' : β' → γ}
(h_comm : ∀ a, f (g a) = g' (f' a)) : (s.image g).image f = (s.image f').image g' := by
simp_rw [image_image, h_comm]
#align set.image_comm Set.image_comm
theorem _root_.Function.Semiconj.set_image {f : α → β} {ga : α → α} {gb : β → β}
(h : Function.Semiconj f ga gb) : Function.Semiconj (image f) (image ga) (image gb) := fun _ =>
image_comm h
#align function.semiconj.set_image Function.Semiconj.set_image
theorem _root_.Function.Commute.set_image {f g : α → α} (h : Function.Commute f g) :
Function.Commute (image f) (image g) :=
Function.Semiconj.set_image h
#align function.commute.set_image Function.Commute.set_image
/-- Image is monotone with respect to `⊆`. See `Set.monotone_image` for the statement in
terms of `≤`. -/
@[gcongr]
theorem image_subset {a b : Set α} (f : α → β) (h : a ⊆ b) : f '' a ⊆ f '' b := by
simp only [subset_def, mem_image]
exact fun x => fun ⟨w, h1, h2⟩ => ⟨w, h h1, h2⟩
#align set.image_subset Set.image_subset
/-- `Set.image` is monotone. See `Set.image_subset` for the statement in terms of `⊆`. -/
lemma monotone_image {f : α → β} : Monotone (image f) := fun _ _ => image_subset _
#align set.monotone_image Set.monotone_image
theorem image_union (f : α → β) (s t : Set α) : f '' (s ∪ t) = f '' s ∪ f '' t :=
ext fun x =>
⟨by rintro ⟨a, h | h, rfl⟩ <;> [left; right] <;> exact ⟨_, h, rfl⟩, by
rintro (⟨a, h, rfl⟩ | ⟨a, h, rfl⟩) <;> refine' ⟨_, _, rfl⟩ <;> [left; right] <;>
|
exact h
|
theorem image_union (f : α → β) (s t : Set α) : f '' (s ∪ t) = f '' s ∪ f '' t :=
ext fun x =>
⟨by rintro ⟨a, h | h, rfl⟩ <;> [left; right] <;> exact ⟨_, h, rfl⟩, by
rintro (⟨a, h, rfl⟩ | ⟨a, h, rfl⟩) <;> refine' ⟨_, _, rfl⟩ <;> [left; right] <;>
|
Mathlib.Data.Set.Image.336_0.IJFiTzmYGOCpPSd
|
theorem image_union (f : α → β) (s t : Set α) : f '' (s ∪ t) = f '' s ∪ f '' t
|
Mathlib_Data_Set_Image
|
α : Type u_1
β : Type u_2
γ : Type u_3
ι : Sort u_4
ι' : Sort u_5
f✝ : α → β
s t : Set α
f : α → β
⊢ f '' ∅ = ∅
|
/-
Copyright (c) 2014 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Leonardo de Moura
-/
import Mathlib.Data.Set.Basic
#align_import data.set.image from "leanprover-community/mathlib"@"001ffdc42920050657fd45bd2b8bfbec8eaaeb29"
/-!
# Images and preimages of sets
## Main definitions
* `preimage f t : Set α` : the preimage f⁻¹(t) (written `f ⁻¹' t` in Lean) of a subset of β.
* `range f : Set β` : the image of `univ` under `f`.
Also works for `{p : Prop} (f : p → α)` (unlike `image`)
## Notation
* `f ⁻¹' t` for `Set.preimage f t`
* `f '' s` for `Set.image f s`
## Tags
set, sets, image, preimage, pre-image, range
-/
set_option autoImplicit true
universe u v
open Function Set
namespace Set
variable {α β γ : Type*} {ι ι' : Sort*}
/-! ### Inverse image -/
/-- The preimage of `s : Set β` by `f : α → β`, written `f ⁻¹' s`,
is the set of `x : α` such that `f x ∈ s`. -/
def preimage {α : Type u} {β : Type v} (f : α → β) (s : Set β) : Set α :=
{ x | f x ∈ s }
#align set.preimage Set.preimage
/-- `f ⁻¹' t` denotes the preimage of `t : Set β` under the function `f : α → β`. -/
infixl:80 " ⁻¹' " => preimage
section Preimage
variable {f : α → β} {g : β → γ}
@[simp]
theorem preimage_empty : f ⁻¹' ∅ = ∅ :=
rfl
#align set.preimage_empty Set.preimage_empty
@[simp, mfld_simps]
theorem mem_preimage {s : Set β} {a : α} : a ∈ f ⁻¹' s ↔ f a ∈ s :=
Iff.rfl
#align set.mem_preimage Set.mem_preimage
theorem preimage_congr {f g : α → β} {s : Set β} (h : ∀ x : α, f x = g x) : f ⁻¹' s = g ⁻¹' s := by
congr with x
simp [h]
#align set.preimage_congr Set.preimage_congr
@[gcongr]
theorem preimage_mono {s t : Set β} (h : s ⊆ t) : f ⁻¹' s ⊆ f ⁻¹' t := fun _ hx => h hx
#align set.preimage_mono Set.preimage_mono
@[simp, mfld_simps]
theorem preimage_univ : f ⁻¹' univ = univ :=
rfl
#align set.preimage_univ Set.preimage_univ
theorem subset_preimage_univ {s : Set α} : s ⊆ f ⁻¹' univ :=
subset_univ _
#align set.subset_preimage_univ Set.subset_preimage_univ
@[simp, mfld_simps]
theorem preimage_inter {s t : Set β} : f ⁻¹' (s ∩ t) = f ⁻¹' s ∩ f ⁻¹' t :=
rfl
#align set.preimage_inter Set.preimage_inter
@[simp]
theorem preimage_union {s t : Set β} : f ⁻¹' (s ∪ t) = f ⁻¹' s ∪ f ⁻¹' t :=
rfl
#align set.preimage_union Set.preimage_union
@[simp]
theorem preimage_compl {s : Set β} : f ⁻¹' sᶜ = (f ⁻¹' s)ᶜ :=
rfl
#align set.preimage_compl Set.preimage_compl
@[simp]
theorem preimage_diff (f : α → β) (s t : Set β) : f ⁻¹' (s \ t) = f ⁻¹' s \ f ⁻¹' t :=
rfl
#align set.preimage_diff Set.preimage_diff
@[simp]
lemma preimage_symmDiff {f : α → β} (s t : Set β) : f ⁻¹' (s ∆ t) = (f ⁻¹' s) ∆ (f ⁻¹' t) :=
rfl
#align set.preimage_symm_diff Set.preimage_symmDiff
@[simp]
theorem preimage_ite (f : α → β) (s t₁ t₂ : Set β) :
f ⁻¹' s.ite t₁ t₂ = (f ⁻¹' s).ite (f ⁻¹' t₁) (f ⁻¹' t₂) :=
rfl
#align set.preimage_ite Set.preimage_ite
@[simp]
theorem preimage_setOf_eq {p : α → Prop} {f : β → α} : f ⁻¹' { a | p a } = { a | p (f a) } :=
rfl
#align set.preimage_set_of_eq Set.preimage_setOf_eq
@[simp]
theorem preimage_id_eq : preimage (id : α → α) = id :=
rfl
#align set.preimage_id_eq Set.preimage_id_eq
@[mfld_simps]
theorem preimage_id {s : Set α} : id ⁻¹' s = s :=
rfl
#align set.preimage_id Set.preimage_id
@[simp, mfld_simps]
theorem preimage_id' {s : Set α} : (fun x => x) ⁻¹' s = s :=
rfl
#align set.preimage_id' Set.preimage_id'
@[simp]
theorem preimage_const_of_mem {b : β} {s : Set β} (h : b ∈ s) : (fun _ : α => b) ⁻¹' s = univ :=
eq_univ_of_forall fun _ => h
#align set.preimage_const_of_mem Set.preimage_const_of_mem
@[simp]
theorem preimage_const_of_not_mem {b : β} {s : Set β} (h : b ∉ s) : (fun _ : α => b) ⁻¹' s = ∅ :=
eq_empty_of_subset_empty fun _ hx => h hx
#align set.preimage_const_of_not_mem Set.preimage_const_of_not_mem
theorem preimage_const (b : β) (s : Set β) [Decidable (b ∈ s)] :
(fun _ : α => b) ⁻¹' s = if b ∈ s then univ else ∅ := by
split_ifs with hb
exacts [preimage_const_of_mem hb, preimage_const_of_not_mem hb]
#align set.preimage_const Set.preimage_const
/-- If preimage of each singleton under `f : α → β` is either empty or the whole type,
then `f` is a constant. -/
lemma exists_eq_const_of_preimage_singleton [Nonempty β] {f : α → β}
(hf : ∀ b : β, f ⁻¹' {b} = ∅ ∨ f ⁻¹' {b} = univ) : ∃ b, f = const α b := by
rcases em (∃ b, f ⁻¹' {b} = univ) with ⟨b, hb⟩ | hf'
· exact ⟨b, funext fun x ↦ eq_univ_iff_forall.1 hb x⟩
· have : ∀ x b, f x ≠ b := fun x b ↦
eq_empty_iff_forall_not_mem.1 ((hf b).resolve_right fun h ↦ hf' ⟨b, h⟩) x
exact ⟨Classical.arbitrary β, funext fun x ↦ absurd rfl (this x _)⟩
theorem preimage_comp {s : Set γ} : g ∘ f ⁻¹' s = f ⁻¹' (g ⁻¹' s) :=
rfl
#align set.preimage_comp Set.preimage_comp
theorem preimage_comp_eq : preimage (g ∘ f) = preimage f ∘ preimage g :=
rfl
#align set.preimage_comp_eq Set.preimage_comp_eq
theorem preimage_iterate_eq {f : α → α} {n : ℕ} : Set.preimage f^[n] = (Set.preimage f)^[n] := by
induction' n with n ih; · simp
rw [iterate_succ, iterate_succ', preimage_comp_eq, ih]
#align set.preimage_iterate_eq Set.preimage_iterate_eq
theorem preimage_preimage {g : β → γ} {f : α → β} {s : Set γ} :
f ⁻¹' (g ⁻¹' s) = (fun x => g (f x)) ⁻¹' s :=
preimage_comp.symm
#align set.preimage_preimage Set.preimage_preimage
theorem eq_preimage_subtype_val_iff {p : α → Prop} {s : Set (Subtype p)} {t : Set α} :
s = Subtype.val ⁻¹' t ↔ ∀ (x) (h : p x), (⟨x, h⟩ : Subtype p) ∈ s ↔ x ∈ t :=
⟨fun s_eq x h => by
rw [s_eq]
simp, fun h => ext fun ⟨x, hx⟩ => by simp [h]⟩
#align set.eq_preimage_subtype_val_iff Set.eq_preimage_subtype_val_iff
theorem nonempty_of_nonempty_preimage {s : Set β} {f : α → β} (hf : (f ⁻¹' s).Nonempty) :
s.Nonempty :=
let ⟨x, hx⟩ := hf
⟨f x, hx⟩
#align set.nonempty_of_nonempty_preimage Set.nonempty_of_nonempty_preimage
@[simp] theorem preimage_singleton_true (p : α → Prop) : p ⁻¹' {True} = {a | p a} := by ext; simp
#align set.preimage_singleton_true Set.preimage_singleton_true
@[simp] theorem preimage_singleton_false (p : α → Prop) : p ⁻¹' {False} = {a | ¬p a} := by ext; simp
#align set.preimage_singleton_false Set.preimage_singleton_false
theorem preimage_subtype_coe_eq_compl {s u v : Set α} (hsuv : s ⊆ u ∪ v)
(H : s ∩ (u ∩ v) = ∅) : ((↑) : s → α) ⁻¹' u = ((↑) ⁻¹' v)ᶜ := by
ext ⟨x, x_in_s⟩
constructor
· intro x_in_u x_in_v
exact eq_empty_iff_forall_not_mem.mp H x ⟨x_in_s, ⟨x_in_u, x_in_v⟩⟩
· intro hx
exact Or.elim (hsuv x_in_s) id fun hx' => hx.elim hx'
#align set.preimage_subtype_coe_eq_compl Set.preimage_subtype_coe_eq_compl
end Preimage
/-! ### Image of a set under a function -/
section Image
variable {f : α → β} {s t : Set α}
-- Porting note: `Set.image` is already defined in `Init.Set`
#align set.image Set.image
/-- `f '' s` denotes the image of `s : Set α` under the function `f : α → β`. -/
infixl:80 " '' " => image
theorem mem_image_iff_bex {f : α → β} {s : Set α} {y : β} :
y ∈ f '' s ↔ ∃ (x : _) (_ : x ∈ s), f x = y :=
bex_def.symm
#align set.mem_image_iff_bex Set.mem_image_iff_bex
@[simp]
theorem mem_image (f : α → β) (s : Set α) (y : β) : y ∈ f '' s ↔ ∃ x ∈ s, f x = y :=
Iff.rfl
#align set.mem_image Set.mem_image
theorem image_eta (f : α → β) : f '' s = (fun x => f x) '' s :=
rfl
#align set.image_eta Set.image_eta
@[mfld_simps]
theorem mem_image_of_mem (f : α → β) {x : α} {a : Set α} (h : x ∈ a) : f x ∈ f '' a :=
⟨_, h, rfl⟩
#align set.mem_image_of_mem Set.mem_image_of_mem
theorem _root_.Function.Injective.mem_set_image {f : α → β} (hf : Injective f) {s : Set α} {a : α} :
f a ∈ f '' s ↔ a ∈ s :=
⟨fun ⟨_, hb, Eq⟩ => hf Eq ▸ hb, mem_image_of_mem f⟩
#align function.injective.mem_set_image Function.Injective.mem_set_image
theorem ball_image_iff {f : α → β} {s : Set α} {p : β → Prop} :
(∀ y ∈ f '' s, p y) ↔ ∀ x ∈ s, p (f x) := by simp
#align set.ball_image_iff Set.ball_image_iff
theorem ball_image_of_ball {f : α → β} {s : Set α} {p : β → Prop} (h : ∀ x ∈ s, p (f x)) :
∀ y ∈ f '' s, p y :=
ball_image_iff.2 h
#align set.ball_image_of_ball Set.ball_image_of_ball
theorem bex_image_iff {f : α → β} {s : Set α} {p : β → Prop} :
(∃ y ∈ f '' s, p y) ↔ ∃ x ∈ s, p (f x) := by simp
#align set.bex_image_iff Set.bex_image_iff
theorem mem_image_elim {f : α → β} {s : Set α} {C : β → Prop} (h : ∀ x : α, x ∈ s → C (f x)) :
∀ {y : β}, y ∈ f '' s → C y
| _, ⟨a, a_in, rfl⟩ => h a a_in
#align set.mem_image_elim Set.mem_image_elim
theorem mem_image_elim_on {f : α → β} {s : Set α} {C : β → Prop} {y : β} (h_y : y ∈ f '' s)
(h : ∀ x : α, x ∈ s → C (f x)) : C y :=
mem_image_elim h h_y
#align set.mem_image_elim_on Set.mem_image_elim_on
-- Porting note: used to be `safe`
@[congr]
theorem image_congr {f g : α → β} {s : Set α} (h : ∀ a ∈ s, f a = g a) : f '' s = g '' s := by
ext x
rw [mem_image, mem_image]
exact {
mp := by
rintro ⟨a, ha1, ha2⟩
exact ⟨a, ⟨ha1, (h a ha1) ▸ ha2⟩⟩,
mpr := by
rintro ⟨a, ha1, ha2⟩
exact ⟨a, ⟨ha1, (h a ha1) ▸ ha2⟩⟩
}
-- safe [ext_iff, iff_def]
#align set.image_congr Set.image_congr
/-- A common special case of `image_congr` -/
theorem image_congr' {f g : α → β} {s : Set α} (h : ∀ x : α, f x = g x) : f '' s = g '' s :=
image_congr fun x _ => h x
#align set.image_congr' Set.image_congr'
@[gcongr]
lemma image_mono (h : s ⊆ t) : f '' s ⊆ f '' t := by
rintro - ⟨a, ha, rfl⟩; exact mem_image_of_mem f (h ha)
theorem image_comp (f : β → γ) (g : α → β) (a : Set α) : f ∘ g '' a = f '' (g '' a) :=
Subset.antisymm (ball_image_of_ball fun _ ha => mem_image_of_mem _ <| mem_image_of_mem _ ha)
(ball_image_of_ball <| ball_image_of_ball fun _ ha => mem_image_of_mem _ ha)
#align set.image_comp Set.image_comp
theorem image_comp_eq {g : β → γ} : image (g ∘ f) = image g ∘ image f := by ext; simp
/-- A variant of `image_comp`, useful for rewriting -/
theorem image_image (g : β → γ) (f : α → β) (s : Set α) : g '' (f '' s) = (fun x => g (f x)) '' s :=
(image_comp g f s).symm
#align set.image_image Set.image_image
theorem image_comm {β'} {f : β → γ} {g : α → β} {f' : α → β'} {g' : β' → γ}
(h_comm : ∀ a, f (g a) = g' (f' a)) : (s.image g).image f = (s.image f').image g' := by
simp_rw [image_image, h_comm]
#align set.image_comm Set.image_comm
theorem _root_.Function.Semiconj.set_image {f : α → β} {ga : α → α} {gb : β → β}
(h : Function.Semiconj f ga gb) : Function.Semiconj (image f) (image ga) (image gb) := fun _ =>
image_comm h
#align function.semiconj.set_image Function.Semiconj.set_image
theorem _root_.Function.Commute.set_image {f g : α → α} (h : Function.Commute f g) :
Function.Commute (image f) (image g) :=
Function.Semiconj.set_image h
#align function.commute.set_image Function.Commute.set_image
/-- Image is monotone with respect to `⊆`. See `Set.monotone_image` for the statement in
terms of `≤`. -/
@[gcongr]
theorem image_subset {a b : Set α} (f : α → β) (h : a ⊆ b) : f '' a ⊆ f '' b := by
simp only [subset_def, mem_image]
exact fun x => fun ⟨w, h1, h2⟩ => ⟨w, h h1, h2⟩
#align set.image_subset Set.image_subset
/-- `Set.image` is monotone. See `Set.image_subset` for the statement in terms of `⊆`. -/
lemma monotone_image {f : α → β} : Monotone (image f) := fun _ _ => image_subset _
#align set.monotone_image Set.monotone_image
theorem image_union (f : α → β) (s t : Set α) : f '' (s ∪ t) = f '' s ∪ f '' t :=
ext fun x =>
⟨by rintro ⟨a, h | h, rfl⟩ <;> [left; right] <;> exact ⟨_, h, rfl⟩, by
rintro (⟨a, h, rfl⟩ | ⟨a, h, rfl⟩) <;> refine' ⟨_, _, rfl⟩ <;> [left; right] <;> exact h⟩
#align set.image_union Set.image_union
@[simp]
theorem image_empty (f : α → β) : f '' ∅ = ∅ := by
|
ext
|
@[simp]
theorem image_empty (f : α → β) : f '' ∅ = ∅ := by
|
Mathlib.Data.Set.Image.342_0.IJFiTzmYGOCpPSd
|
@[simp]
theorem image_empty (f : α → β) : f '' ∅ = ∅
|
Mathlib_Data_Set_Image
|
case h
α : Type u_1
β : Type u_2
γ : Type u_3
ι : Sort u_4
ι' : Sort u_5
f✝ : α → β
s t : Set α
f : α → β
x✝ : β
⊢ x✝ ∈ f '' ∅ ↔ x✝ ∈ ∅
|
/-
Copyright (c) 2014 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Leonardo de Moura
-/
import Mathlib.Data.Set.Basic
#align_import data.set.image from "leanprover-community/mathlib"@"001ffdc42920050657fd45bd2b8bfbec8eaaeb29"
/-!
# Images and preimages of sets
## Main definitions
* `preimage f t : Set α` : the preimage f⁻¹(t) (written `f ⁻¹' t` in Lean) of a subset of β.
* `range f : Set β` : the image of `univ` under `f`.
Also works for `{p : Prop} (f : p → α)` (unlike `image`)
## Notation
* `f ⁻¹' t` for `Set.preimage f t`
* `f '' s` for `Set.image f s`
## Tags
set, sets, image, preimage, pre-image, range
-/
set_option autoImplicit true
universe u v
open Function Set
namespace Set
variable {α β γ : Type*} {ι ι' : Sort*}
/-! ### Inverse image -/
/-- The preimage of `s : Set β` by `f : α → β`, written `f ⁻¹' s`,
is the set of `x : α` such that `f x ∈ s`. -/
def preimage {α : Type u} {β : Type v} (f : α → β) (s : Set β) : Set α :=
{ x | f x ∈ s }
#align set.preimage Set.preimage
/-- `f ⁻¹' t` denotes the preimage of `t : Set β` under the function `f : α → β`. -/
infixl:80 " ⁻¹' " => preimage
section Preimage
variable {f : α → β} {g : β → γ}
@[simp]
theorem preimage_empty : f ⁻¹' ∅ = ∅ :=
rfl
#align set.preimage_empty Set.preimage_empty
@[simp, mfld_simps]
theorem mem_preimage {s : Set β} {a : α} : a ∈ f ⁻¹' s ↔ f a ∈ s :=
Iff.rfl
#align set.mem_preimage Set.mem_preimage
theorem preimage_congr {f g : α → β} {s : Set β} (h : ∀ x : α, f x = g x) : f ⁻¹' s = g ⁻¹' s := by
congr with x
simp [h]
#align set.preimage_congr Set.preimage_congr
@[gcongr]
theorem preimage_mono {s t : Set β} (h : s ⊆ t) : f ⁻¹' s ⊆ f ⁻¹' t := fun _ hx => h hx
#align set.preimage_mono Set.preimage_mono
@[simp, mfld_simps]
theorem preimage_univ : f ⁻¹' univ = univ :=
rfl
#align set.preimage_univ Set.preimage_univ
theorem subset_preimage_univ {s : Set α} : s ⊆ f ⁻¹' univ :=
subset_univ _
#align set.subset_preimage_univ Set.subset_preimage_univ
@[simp, mfld_simps]
theorem preimage_inter {s t : Set β} : f ⁻¹' (s ∩ t) = f ⁻¹' s ∩ f ⁻¹' t :=
rfl
#align set.preimage_inter Set.preimage_inter
@[simp]
theorem preimage_union {s t : Set β} : f ⁻¹' (s ∪ t) = f ⁻¹' s ∪ f ⁻¹' t :=
rfl
#align set.preimage_union Set.preimage_union
@[simp]
theorem preimage_compl {s : Set β} : f ⁻¹' sᶜ = (f ⁻¹' s)ᶜ :=
rfl
#align set.preimage_compl Set.preimage_compl
@[simp]
theorem preimage_diff (f : α → β) (s t : Set β) : f ⁻¹' (s \ t) = f ⁻¹' s \ f ⁻¹' t :=
rfl
#align set.preimage_diff Set.preimage_diff
@[simp]
lemma preimage_symmDiff {f : α → β} (s t : Set β) : f ⁻¹' (s ∆ t) = (f ⁻¹' s) ∆ (f ⁻¹' t) :=
rfl
#align set.preimage_symm_diff Set.preimage_symmDiff
@[simp]
theorem preimage_ite (f : α → β) (s t₁ t₂ : Set β) :
f ⁻¹' s.ite t₁ t₂ = (f ⁻¹' s).ite (f ⁻¹' t₁) (f ⁻¹' t₂) :=
rfl
#align set.preimage_ite Set.preimage_ite
@[simp]
theorem preimage_setOf_eq {p : α → Prop} {f : β → α} : f ⁻¹' { a | p a } = { a | p (f a) } :=
rfl
#align set.preimage_set_of_eq Set.preimage_setOf_eq
@[simp]
theorem preimage_id_eq : preimage (id : α → α) = id :=
rfl
#align set.preimage_id_eq Set.preimage_id_eq
@[mfld_simps]
theorem preimage_id {s : Set α} : id ⁻¹' s = s :=
rfl
#align set.preimage_id Set.preimage_id
@[simp, mfld_simps]
theorem preimage_id' {s : Set α} : (fun x => x) ⁻¹' s = s :=
rfl
#align set.preimage_id' Set.preimage_id'
@[simp]
theorem preimage_const_of_mem {b : β} {s : Set β} (h : b ∈ s) : (fun _ : α => b) ⁻¹' s = univ :=
eq_univ_of_forall fun _ => h
#align set.preimage_const_of_mem Set.preimage_const_of_mem
@[simp]
theorem preimage_const_of_not_mem {b : β} {s : Set β} (h : b ∉ s) : (fun _ : α => b) ⁻¹' s = ∅ :=
eq_empty_of_subset_empty fun _ hx => h hx
#align set.preimage_const_of_not_mem Set.preimage_const_of_not_mem
theorem preimage_const (b : β) (s : Set β) [Decidable (b ∈ s)] :
(fun _ : α => b) ⁻¹' s = if b ∈ s then univ else ∅ := by
split_ifs with hb
exacts [preimage_const_of_mem hb, preimage_const_of_not_mem hb]
#align set.preimage_const Set.preimage_const
/-- If preimage of each singleton under `f : α → β` is either empty or the whole type,
then `f` is a constant. -/
lemma exists_eq_const_of_preimage_singleton [Nonempty β] {f : α → β}
(hf : ∀ b : β, f ⁻¹' {b} = ∅ ∨ f ⁻¹' {b} = univ) : ∃ b, f = const α b := by
rcases em (∃ b, f ⁻¹' {b} = univ) with ⟨b, hb⟩ | hf'
· exact ⟨b, funext fun x ↦ eq_univ_iff_forall.1 hb x⟩
· have : ∀ x b, f x ≠ b := fun x b ↦
eq_empty_iff_forall_not_mem.1 ((hf b).resolve_right fun h ↦ hf' ⟨b, h⟩) x
exact ⟨Classical.arbitrary β, funext fun x ↦ absurd rfl (this x _)⟩
theorem preimage_comp {s : Set γ} : g ∘ f ⁻¹' s = f ⁻¹' (g ⁻¹' s) :=
rfl
#align set.preimage_comp Set.preimage_comp
theorem preimage_comp_eq : preimage (g ∘ f) = preimage f ∘ preimage g :=
rfl
#align set.preimage_comp_eq Set.preimage_comp_eq
theorem preimage_iterate_eq {f : α → α} {n : ℕ} : Set.preimage f^[n] = (Set.preimage f)^[n] := by
induction' n with n ih; · simp
rw [iterate_succ, iterate_succ', preimage_comp_eq, ih]
#align set.preimage_iterate_eq Set.preimage_iterate_eq
theorem preimage_preimage {g : β → γ} {f : α → β} {s : Set γ} :
f ⁻¹' (g ⁻¹' s) = (fun x => g (f x)) ⁻¹' s :=
preimage_comp.symm
#align set.preimage_preimage Set.preimage_preimage
theorem eq_preimage_subtype_val_iff {p : α → Prop} {s : Set (Subtype p)} {t : Set α} :
s = Subtype.val ⁻¹' t ↔ ∀ (x) (h : p x), (⟨x, h⟩ : Subtype p) ∈ s ↔ x ∈ t :=
⟨fun s_eq x h => by
rw [s_eq]
simp, fun h => ext fun ⟨x, hx⟩ => by simp [h]⟩
#align set.eq_preimage_subtype_val_iff Set.eq_preimage_subtype_val_iff
theorem nonempty_of_nonempty_preimage {s : Set β} {f : α → β} (hf : (f ⁻¹' s).Nonempty) :
s.Nonempty :=
let ⟨x, hx⟩ := hf
⟨f x, hx⟩
#align set.nonempty_of_nonempty_preimage Set.nonempty_of_nonempty_preimage
@[simp] theorem preimage_singleton_true (p : α → Prop) : p ⁻¹' {True} = {a | p a} := by ext; simp
#align set.preimage_singleton_true Set.preimage_singleton_true
@[simp] theorem preimage_singleton_false (p : α → Prop) : p ⁻¹' {False} = {a | ¬p a} := by ext; simp
#align set.preimage_singleton_false Set.preimage_singleton_false
theorem preimage_subtype_coe_eq_compl {s u v : Set α} (hsuv : s ⊆ u ∪ v)
(H : s ∩ (u ∩ v) = ∅) : ((↑) : s → α) ⁻¹' u = ((↑) ⁻¹' v)ᶜ := by
ext ⟨x, x_in_s⟩
constructor
· intro x_in_u x_in_v
exact eq_empty_iff_forall_not_mem.mp H x ⟨x_in_s, ⟨x_in_u, x_in_v⟩⟩
· intro hx
exact Or.elim (hsuv x_in_s) id fun hx' => hx.elim hx'
#align set.preimage_subtype_coe_eq_compl Set.preimage_subtype_coe_eq_compl
end Preimage
/-! ### Image of a set under a function -/
section Image
variable {f : α → β} {s t : Set α}
-- Porting note: `Set.image` is already defined in `Init.Set`
#align set.image Set.image
/-- `f '' s` denotes the image of `s : Set α` under the function `f : α → β`. -/
infixl:80 " '' " => image
theorem mem_image_iff_bex {f : α → β} {s : Set α} {y : β} :
y ∈ f '' s ↔ ∃ (x : _) (_ : x ∈ s), f x = y :=
bex_def.symm
#align set.mem_image_iff_bex Set.mem_image_iff_bex
@[simp]
theorem mem_image (f : α → β) (s : Set α) (y : β) : y ∈ f '' s ↔ ∃ x ∈ s, f x = y :=
Iff.rfl
#align set.mem_image Set.mem_image
theorem image_eta (f : α → β) : f '' s = (fun x => f x) '' s :=
rfl
#align set.image_eta Set.image_eta
@[mfld_simps]
theorem mem_image_of_mem (f : α → β) {x : α} {a : Set α} (h : x ∈ a) : f x ∈ f '' a :=
⟨_, h, rfl⟩
#align set.mem_image_of_mem Set.mem_image_of_mem
theorem _root_.Function.Injective.mem_set_image {f : α → β} (hf : Injective f) {s : Set α} {a : α} :
f a ∈ f '' s ↔ a ∈ s :=
⟨fun ⟨_, hb, Eq⟩ => hf Eq ▸ hb, mem_image_of_mem f⟩
#align function.injective.mem_set_image Function.Injective.mem_set_image
theorem ball_image_iff {f : α → β} {s : Set α} {p : β → Prop} :
(∀ y ∈ f '' s, p y) ↔ ∀ x ∈ s, p (f x) := by simp
#align set.ball_image_iff Set.ball_image_iff
theorem ball_image_of_ball {f : α → β} {s : Set α} {p : β → Prop} (h : ∀ x ∈ s, p (f x)) :
∀ y ∈ f '' s, p y :=
ball_image_iff.2 h
#align set.ball_image_of_ball Set.ball_image_of_ball
theorem bex_image_iff {f : α → β} {s : Set α} {p : β → Prop} :
(∃ y ∈ f '' s, p y) ↔ ∃ x ∈ s, p (f x) := by simp
#align set.bex_image_iff Set.bex_image_iff
theorem mem_image_elim {f : α → β} {s : Set α} {C : β → Prop} (h : ∀ x : α, x ∈ s → C (f x)) :
∀ {y : β}, y ∈ f '' s → C y
| _, ⟨a, a_in, rfl⟩ => h a a_in
#align set.mem_image_elim Set.mem_image_elim
theorem mem_image_elim_on {f : α → β} {s : Set α} {C : β → Prop} {y : β} (h_y : y ∈ f '' s)
(h : ∀ x : α, x ∈ s → C (f x)) : C y :=
mem_image_elim h h_y
#align set.mem_image_elim_on Set.mem_image_elim_on
-- Porting note: used to be `safe`
@[congr]
theorem image_congr {f g : α → β} {s : Set α} (h : ∀ a ∈ s, f a = g a) : f '' s = g '' s := by
ext x
rw [mem_image, mem_image]
exact {
mp := by
rintro ⟨a, ha1, ha2⟩
exact ⟨a, ⟨ha1, (h a ha1) ▸ ha2⟩⟩,
mpr := by
rintro ⟨a, ha1, ha2⟩
exact ⟨a, ⟨ha1, (h a ha1) ▸ ha2⟩⟩
}
-- safe [ext_iff, iff_def]
#align set.image_congr Set.image_congr
/-- A common special case of `image_congr` -/
theorem image_congr' {f g : α → β} {s : Set α} (h : ∀ x : α, f x = g x) : f '' s = g '' s :=
image_congr fun x _ => h x
#align set.image_congr' Set.image_congr'
@[gcongr]
lemma image_mono (h : s ⊆ t) : f '' s ⊆ f '' t := by
rintro - ⟨a, ha, rfl⟩; exact mem_image_of_mem f (h ha)
theorem image_comp (f : β → γ) (g : α → β) (a : Set α) : f ∘ g '' a = f '' (g '' a) :=
Subset.antisymm (ball_image_of_ball fun _ ha => mem_image_of_mem _ <| mem_image_of_mem _ ha)
(ball_image_of_ball <| ball_image_of_ball fun _ ha => mem_image_of_mem _ ha)
#align set.image_comp Set.image_comp
theorem image_comp_eq {g : β → γ} : image (g ∘ f) = image g ∘ image f := by ext; simp
/-- A variant of `image_comp`, useful for rewriting -/
theorem image_image (g : β → γ) (f : α → β) (s : Set α) : g '' (f '' s) = (fun x => g (f x)) '' s :=
(image_comp g f s).symm
#align set.image_image Set.image_image
theorem image_comm {β'} {f : β → γ} {g : α → β} {f' : α → β'} {g' : β' → γ}
(h_comm : ∀ a, f (g a) = g' (f' a)) : (s.image g).image f = (s.image f').image g' := by
simp_rw [image_image, h_comm]
#align set.image_comm Set.image_comm
theorem _root_.Function.Semiconj.set_image {f : α → β} {ga : α → α} {gb : β → β}
(h : Function.Semiconj f ga gb) : Function.Semiconj (image f) (image ga) (image gb) := fun _ =>
image_comm h
#align function.semiconj.set_image Function.Semiconj.set_image
theorem _root_.Function.Commute.set_image {f g : α → α} (h : Function.Commute f g) :
Function.Commute (image f) (image g) :=
Function.Semiconj.set_image h
#align function.commute.set_image Function.Commute.set_image
/-- Image is monotone with respect to `⊆`. See `Set.monotone_image` for the statement in
terms of `≤`. -/
@[gcongr]
theorem image_subset {a b : Set α} (f : α → β) (h : a ⊆ b) : f '' a ⊆ f '' b := by
simp only [subset_def, mem_image]
exact fun x => fun ⟨w, h1, h2⟩ => ⟨w, h h1, h2⟩
#align set.image_subset Set.image_subset
/-- `Set.image` is monotone. See `Set.image_subset` for the statement in terms of `⊆`. -/
lemma monotone_image {f : α → β} : Monotone (image f) := fun _ _ => image_subset _
#align set.monotone_image Set.monotone_image
theorem image_union (f : α → β) (s t : Set α) : f '' (s ∪ t) = f '' s ∪ f '' t :=
ext fun x =>
⟨by rintro ⟨a, h | h, rfl⟩ <;> [left; right] <;> exact ⟨_, h, rfl⟩, by
rintro (⟨a, h, rfl⟩ | ⟨a, h, rfl⟩) <;> refine' ⟨_, _, rfl⟩ <;> [left; right] <;> exact h⟩
#align set.image_union Set.image_union
@[simp]
theorem image_empty (f : α → β) : f '' ∅ = ∅ := by
ext
|
simp
|
@[simp]
theorem image_empty (f : α → β) : f '' ∅ = ∅ := by
ext
|
Mathlib.Data.Set.Image.342_0.IJFiTzmYGOCpPSd
|
@[simp]
theorem image_empty (f : α → β) : f '' ∅ = ∅
|
Mathlib_Data_Set_Image
|
α : Type u_1
β : Type u_2
γ : Type u_3
ι : Sort u_4
ι' : Sort u_5
f✝ : α → β
s✝ t✝ : Set α
f : α → β
s t : Set α
h : ∀ x ∈ t, ∀ y ∈ s, f x = f y → x = y
b : β
x✝ : b ∈ f '' s ∩ f '' t
a₁ : α
ha₁ : a₁ ∈ s
h₁ : f a₁ = b
a₂ : α
ha₂ : a₂ ∈ t
h₂ : f a₂ = b
⊢ f a₂ = f a₁
|
/-
Copyright (c) 2014 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Leonardo de Moura
-/
import Mathlib.Data.Set.Basic
#align_import data.set.image from "leanprover-community/mathlib"@"001ffdc42920050657fd45bd2b8bfbec8eaaeb29"
/-!
# Images and preimages of sets
## Main definitions
* `preimage f t : Set α` : the preimage f⁻¹(t) (written `f ⁻¹' t` in Lean) of a subset of β.
* `range f : Set β` : the image of `univ` under `f`.
Also works for `{p : Prop} (f : p → α)` (unlike `image`)
## Notation
* `f ⁻¹' t` for `Set.preimage f t`
* `f '' s` for `Set.image f s`
## Tags
set, sets, image, preimage, pre-image, range
-/
set_option autoImplicit true
universe u v
open Function Set
namespace Set
variable {α β γ : Type*} {ι ι' : Sort*}
/-! ### Inverse image -/
/-- The preimage of `s : Set β` by `f : α → β`, written `f ⁻¹' s`,
is the set of `x : α` such that `f x ∈ s`. -/
def preimage {α : Type u} {β : Type v} (f : α → β) (s : Set β) : Set α :=
{ x | f x ∈ s }
#align set.preimage Set.preimage
/-- `f ⁻¹' t` denotes the preimage of `t : Set β` under the function `f : α → β`. -/
infixl:80 " ⁻¹' " => preimage
section Preimage
variable {f : α → β} {g : β → γ}
@[simp]
theorem preimage_empty : f ⁻¹' ∅ = ∅ :=
rfl
#align set.preimage_empty Set.preimage_empty
@[simp, mfld_simps]
theorem mem_preimage {s : Set β} {a : α} : a ∈ f ⁻¹' s ↔ f a ∈ s :=
Iff.rfl
#align set.mem_preimage Set.mem_preimage
theorem preimage_congr {f g : α → β} {s : Set β} (h : ∀ x : α, f x = g x) : f ⁻¹' s = g ⁻¹' s := by
congr with x
simp [h]
#align set.preimage_congr Set.preimage_congr
@[gcongr]
theorem preimage_mono {s t : Set β} (h : s ⊆ t) : f ⁻¹' s ⊆ f ⁻¹' t := fun _ hx => h hx
#align set.preimage_mono Set.preimage_mono
@[simp, mfld_simps]
theorem preimage_univ : f ⁻¹' univ = univ :=
rfl
#align set.preimage_univ Set.preimage_univ
theorem subset_preimage_univ {s : Set α} : s ⊆ f ⁻¹' univ :=
subset_univ _
#align set.subset_preimage_univ Set.subset_preimage_univ
@[simp, mfld_simps]
theorem preimage_inter {s t : Set β} : f ⁻¹' (s ∩ t) = f ⁻¹' s ∩ f ⁻¹' t :=
rfl
#align set.preimage_inter Set.preimage_inter
@[simp]
theorem preimage_union {s t : Set β} : f ⁻¹' (s ∪ t) = f ⁻¹' s ∪ f ⁻¹' t :=
rfl
#align set.preimage_union Set.preimage_union
@[simp]
theorem preimage_compl {s : Set β} : f ⁻¹' sᶜ = (f ⁻¹' s)ᶜ :=
rfl
#align set.preimage_compl Set.preimage_compl
@[simp]
theorem preimage_diff (f : α → β) (s t : Set β) : f ⁻¹' (s \ t) = f ⁻¹' s \ f ⁻¹' t :=
rfl
#align set.preimage_diff Set.preimage_diff
@[simp]
lemma preimage_symmDiff {f : α → β} (s t : Set β) : f ⁻¹' (s ∆ t) = (f ⁻¹' s) ∆ (f ⁻¹' t) :=
rfl
#align set.preimage_symm_diff Set.preimage_symmDiff
@[simp]
theorem preimage_ite (f : α → β) (s t₁ t₂ : Set β) :
f ⁻¹' s.ite t₁ t₂ = (f ⁻¹' s).ite (f ⁻¹' t₁) (f ⁻¹' t₂) :=
rfl
#align set.preimage_ite Set.preimage_ite
@[simp]
theorem preimage_setOf_eq {p : α → Prop} {f : β → α} : f ⁻¹' { a | p a } = { a | p (f a) } :=
rfl
#align set.preimage_set_of_eq Set.preimage_setOf_eq
@[simp]
theorem preimage_id_eq : preimage (id : α → α) = id :=
rfl
#align set.preimage_id_eq Set.preimage_id_eq
@[mfld_simps]
theorem preimage_id {s : Set α} : id ⁻¹' s = s :=
rfl
#align set.preimage_id Set.preimage_id
@[simp, mfld_simps]
theorem preimage_id' {s : Set α} : (fun x => x) ⁻¹' s = s :=
rfl
#align set.preimage_id' Set.preimage_id'
@[simp]
theorem preimage_const_of_mem {b : β} {s : Set β} (h : b ∈ s) : (fun _ : α => b) ⁻¹' s = univ :=
eq_univ_of_forall fun _ => h
#align set.preimage_const_of_mem Set.preimage_const_of_mem
@[simp]
theorem preimage_const_of_not_mem {b : β} {s : Set β} (h : b ∉ s) : (fun _ : α => b) ⁻¹' s = ∅ :=
eq_empty_of_subset_empty fun _ hx => h hx
#align set.preimage_const_of_not_mem Set.preimage_const_of_not_mem
theorem preimage_const (b : β) (s : Set β) [Decidable (b ∈ s)] :
(fun _ : α => b) ⁻¹' s = if b ∈ s then univ else ∅ := by
split_ifs with hb
exacts [preimage_const_of_mem hb, preimage_const_of_not_mem hb]
#align set.preimage_const Set.preimage_const
/-- If preimage of each singleton under `f : α → β` is either empty or the whole type,
then `f` is a constant. -/
lemma exists_eq_const_of_preimage_singleton [Nonempty β] {f : α → β}
(hf : ∀ b : β, f ⁻¹' {b} = ∅ ∨ f ⁻¹' {b} = univ) : ∃ b, f = const α b := by
rcases em (∃ b, f ⁻¹' {b} = univ) with ⟨b, hb⟩ | hf'
· exact ⟨b, funext fun x ↦ eq_univ_iff_forall.1 hb x⟩
· have : ∀ x b, f x ≠ b := fun x b ↦
eq_empty_iff_forall_not_mem.1 ((hf b).resolve_right fun h ↦ hf' ⟨b, h⟩) x
exact ⟨Classical.arbitrary β, funext fun x ↦ absurd rfl (this x _)⟩
theorem preimage_comp {s : Set γ} : g ∘ f ⁻¹' s = f ⁻¹' (g ⁻¹' s) :=
rfl
#align set.preimage_comp Set.preimage_comp
theorem preimage_comp_eq : preimage (g ∘ f) = preimage f ∘ preimage g :=
rfl
#align set.preimage_comp_eq Set.preimage_comp_eq
theorem preimage_iterate_eq {f : α → α} {n : ℕ} : Set.preimage f^[n] = (Set.preimage f)^[n] := by
induction' n with n ih; · simp
rw [iterate_succ, iterate_succ', preimage_comp_eq, ih]
#align set.preimage_iterate_eq Set.preimage_iterate_eq
theorem preimage_preimage {g : β → γ} {f : α → β} {s : Set γ} :
f ⁻¹' (g ⁻¹' s) = (fun x => g (f x)) ⁻¹' s :=
preimage_comp.symm
#align set.preimage_preimage Set.preimage_preimage
theorem eq_preimage_subtype_val_iff {p : α → Prop} {s : Set (Subtype p)} {t : Set α} :
s = Subtype.val ⁻¹' t ↔ ∀ (x) (h : p x), (⟨x, h⟩ : Subtype p) ∈ s ↔ x ∈ t :=
⟨fun s_eq x h => by
rw [s_eq]
simp, fun h => ext fun ⟨x, hx⟩ => by simp [h]⟩
#align set.eq_preimage_subtype_val_iff Set.eq_preimage_subtype_val_iff
theorem nonempty_of_nonempty_preimage {s : Set β} {f : α → β} (hf : (f ⁻¹' s).Nonempty) :
s.Nonempty :=
let ⟨x, hx⟩ := hf
⟨f x, hx⟩
#align set.nonempty_of_nonempty_preimage Set.nonempty_of_nonempty_preimage
@[simp] theorem preimage_singleton_true (p : α → Prop) : p ⁻¹' {True} = {a | p a} := by ext; simp
#align set.preimage_singleton_true Set.preimage_singleton_true
@[simp] theorem preimage_singleton_false (p : α → Prop) : p ⁻¹' {False} = {a | ¬p a} := by ext; simp
#align set.preimage_singleton_false Set.preimage_singleton_false
theorem preimage_subtype_coe_eq_compl {s u v : Set α} (hsuv : s ⊆ u ∪ v)
(H : s ∩ (u ∩ v) = ∅) : ((↑) : s → α) ⁻¹' u = ((↑) ⁻¹' v)ᶜ := by
ext ⟨x, x_in_s⟩
constructor
· intro x_in_u x_in_v
exact eq_empty_iff_forall_not_mem.mp H x ⟨x_in_s, ⟨x_in_u, x_in_v⟩⟩
· intro hx
exact Or.elim (hsuv x_in_s) id fun hx' => hx.elim hx'
#align set.preimage_subtype_coe_eq_compl Set.preimage_subtype_coe_eq_compl
end Preimage
/-! ### Image of a set under a function -/
section Image
variable {f : α → β} {s t : Set α}
-- Porting note: `Set.image` is already defined in `Init.Set`
#align set.image Set.image
/-- `f '' s` denotes the image of `s : Set α` under the function `f : α → β`. -/
infixl:80 " '' " => image
theorem mem_image_iff_bex {f : α → β} {s : Set α} {y : β} :
y ∈ f '' s ↔ ∃ (x : _) (_ : x ∈ s), f x = y :=
bex_def.symm
#align set.mem_image_iff_bex Set.mem_image_iff_bex
@[simp]
theorem mem_image (f : α → β) (s : Set α) (y : β) : y ∈ f '' s ↔ ∃ x ∈ s, f x = y :=
Iff.rfl
#align set.mem_image Set.mem_image
theorem image_eta (f : α → β) : f '' s = (fun x => f x) '' s :=
rfl
#align set.image_eta Set.image_eta
@[mfld_simps]
theorem mem_image_of_mem (f : α → β) {x : α} {a : Set α} (h : x ∈ a) : f x ∈ f '' a :=
⟨_, h, rfl⟩
#align set.mem_image_of_mem Set.mem_image_of_mem
theorem _root_.Function.Injective.mem_set_image {f : α → β} (hf : Injective f) {s : Set α} {a : α} :
f a ∈ f '' s ↔ a ∈ s :=
⟨fun ⟨_, hb, Eq⟩ => hf Eq ▸ hb, mem_image_of_mem f⟩
#align function.injective.mem_set_image Function.Injective.mem_set_image
theorem ball_image_iff {f : α → β} {s : Set α} {p : β → Prop} :
(∀ y ∈ f '' s, p y) ↔ ∀ x ∈ s, p (f x) := by simp
#align set.ball_image_iff Set.ball_image_iff
theorem ball_image_of_ball {f : α → β} {s : Set α} {p : β → Prop} (h : ∀ x ∈ s, p (f x)) :
∀ y ∈ f '' s, p y :=
ball_image_iff.2 h
#align set.ball_image_of_ball Set.ball_image_of_ball
theorem bex_image_iff {f : α → β} {s : Set α} {p : β → Prop} :
(∃ y ∈ f '' s, p y) ↔ ∃ x ∈ s, p (f x) := by simp
#align set.bex_image_iff Set.bex_image_iff
theorem mem_image_elim {f : α → β} {s : Set α} {C : β → Prop} (h : ∀ x : α, x ∈ s → C (f x)) :
∀ {y : β}, y ∈ f '' s → C y
| _, ⟨a, a_in, rfl⟩ => h a a_in
#align set.mem_image_elim Set.mem_image_elim
theorem mem_image_elim_on {f : α → β} {s : Set α} {C : β → Prop} {y : β} (h_y : y ∈ f '' s)
(h : ∀ x : α, x ∈ s → C (f x)) : C y :=
mem_image_elim h h_y
#align set.mem_image_elim_on Set.mem_image_elim_on
-- Porting note: used to be `safe`
@[congr]
theorem image_congr {f g : α → β} {s : Set α} (h : ∀ a ∈ s, f a = g a) : f '' s = g '' s := by
ext x
rw [mem_image, mem_image]
exact {
mp := by
rintro ⟨a, ha1, ha2⟩
exact ⟨a, ⟨ha1, (h a ha1) ▸ ha2⟩⟩,
mpr := by
rintro ⟨a, ha1, ha2⟩
exact ⟨a, ⟨ha1, (h a ha1) ▸ ha2⟩⟩
}
-- safe [ext_iff, iff_def]
#align set.image_congr Set.image_congr
/-- A common special case of `image_congr` -/
theorem image_congr' {f g : α → β} {s : Set α} (h : ∀ x : α, f x = g x) : f '' s = g '' s :=
image_congr fun x _ => h x
#align set.image_congr' Set.image_congr'
@[gcongr]
lemma image_mono (h : s ⊆ t) : f '' s ⊆ f '' t := by
rintro - ⟨a, ha, rfl⟩; exact mem_image_of_mem f (h ha)
theorem image_comp (f : β → γ) (g : α → β) (a : Set α) : f ∘ g '' a = f '' (g '' a) :=
Subset.antisymm (ball_image_of_ball fun _ ha => mem_image_of_mem _ <| mem_image_of_mem _ ha)
(ball_image_of_ball <| ball_image_of_ball fun _ ha => mem_image_of_mem _ ha)
#align set.image_comp Set.image_comp
theorem image_comp_eq {g : β → γ} : image (g ∘ f) = image g ∘ image f := by ext; simp
/-- A variant of `image_comp`, useful for rewriting -/
theorem image_image (g : β → γ) (f : α → β) (s : Set α) : g '' (f '' s) = (fun x => g (f x)) '' s :=
(image_comp g f s).symm
#align set.image_image Set.image_image
theorem image_comm {β'} {f : β → γ} {g : α → β} {f' : α → β'} {g' : β' → γ}
(h_comm : ∀ a, f (g a) = g' (f' a)) : (s.image g).image f = (s.image f').image g' := by
simp_rw [image_image, h_comm]
#align set.image_comm Set.image_comm
theorem _root_.Function.Semiconj.set_image {f : α → β} {ga : α → α} {gb : β → β}
(h : Function.Semiconj f ga gb) : Function.Semiconj (image f) (image ga) (image gb) := fun _ =>
image_comm h
#align function.semiconj.set_image Function.Semiconj.set_image
theorem _root_.Function.Commute.set_image {f g : α → α} (h : Function.Commute f g) :
Function.Commute (image f) (image g) :=
Function.Semiconj.set_image h
#align function.commute.set_image Function.Commute.set_image
/-- Image is monotone with respect to `⊆`. See `Set.monotone_image` for the statement in
terms of `≤`. -/
@[gcongr]
theorem image_subset {a b : Set α} (f : α → β) (h : a ⊆ b) : f '' a ⊆ f '' b := by
simp only [subset_def, mem_image]
exact fun x => fun ⟨w, h1, h2⟩ => ⟨w, h h1, h2⟩
#align set.image_subset Set.image_subset
/-- `Set.image` is monotone. See `Set.image_subset` for the statement in terms of `⊆`. -/
lemma monotone_image {f : α → β} : Monotone (image f) := fun _ _ => image_subset _
#align set.monotone_image Set.monotone_image
theorem image_union (f : α → β) (s t : Set α) : f '' (s ∪ t) = f '' s ∪ f '' t :=
ext fun x =>
⟨by rintro ⟨a, h | h, rfl⟩ <;> [left; right] <;> exact ⟨_, h, rfl⟩, by
rintro (⟨a, h, rfl⟩ | ⟨a, h, rfl⟩) <;> refine' ⟨_, _, rfl⟩ <;> [left; right] <;> exact h⟩
#align set.image_union Set.image_union
@[simp]
theorem image_empty (f : α → β) : f '' ∅ = ∅ := by
ext
simp
#align set.image_empty Set.image_empty
theorem image_inter_subset (f : α → β) (s t : Set α) : f '' (s ∩ t) ⊆ f '' s ∩ f '' t :=
subset_inter (image_subset _ <| inter_subset_left _ _) (image_subset _ <| inter_subset_right _ _)
#align set.image_inter_subset Set.image_inter_subset
theorem image_inter_on {f : α → β} {s t : Set α} (h : ∀ x ∈ t, ∀ y ∈ s, f x = f y → x = y) :
f '' (s ∩ t) = f '' s ∩ f '' t :=
(image_inter_subset _ _ _).antisymm
fun b ⟨⟨a₁, ha₁, h₁⟩, ⟨a₂, ha₂, h₂⟩⟩ ↦
have : a₂ = a₁ := h _ ha₂ _ ha₁ (by
|
simp [*]
|
theorem image_inter_on {f : α → β} {s t : Set α} (h : ∀ x ∈ t, ∀ y ∈ s, f x = f y → x = y) :
f '' (s ∩ t) = f '' s ∩ f '' t :=
(image_inter_subset _ _ _).antisymm
fun b ⟨⟨a₁, ha₁, h₁⟩, ⟨a₂, ha₂, h₂⟩⟩ ↦
have : a₂ = a₁ := h _ ha₂ _ ha₁ (by
|
Mathlib.Data.Set.Image.352_0.IJFiTzmYGOCpPSd
|
theorem image_inter_on {f : α → β} {s t : Set α} (h : ∀ x ∈ t, ∀ y ∈ s, f x = f y → x = y) :
f '' (s ∩ t) = f '' s ∩ f '' t
|
Mathlib_Data_Set_Image
|
α : Type u_1
β : Type u_2
γ : Type u_3
ι✝ : Sort u_4
ι' : Sort u_5
f✝ : α → β
s t : Set α
ι : Type u_6
f : ι → β
H : Surjective f
⊢ ∀ (x : β), x ∈ f '' univ
|
/-
Copyright (c) 2014 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Leonardo de Moura
-/
import Mathlib.Data.Set.Basic
#align_import data.set.image from "leanprover-community/mathlib"@"001ffdc42920050657fd45bd2b8bfbec8eaaeb29"
/-!
# Images and preimages of sets
## Main definitions
* `preimage f t : Set α` : the preimage f⁻¹(t) (written `f ⁻¹' t` in Lean) of a subset of β.
* `range f : Set β` : the image of `univ` under `f`.
Also works for `{p : Prop} (f : p → α)` (unlike `image`)
## Notation
* `f ⁻¹' t` for `Set.preimage f t`
* `f '' s` for `Set.image f s`
## Tags
set, sets, image, preimage, pre-image, range
-/
set_option autoImplicit true
universe u v
open Function Set
namespace Set
variable {α β γ : Type*} {ι ι' : Sort*}
/-! ### Inverse image -/
/-- The preimage of `s : Set β` by `f : α → β`, written `f ⁻¹' s`,
is the set of `x : α` such that `f x ∈ s`. -/
def preimage {α : Type u} {β : Type v} (f : α → β) (s : Set β) : Set α :=
{ x | f x ∈ s }
#align set.preimage Set.preimage
/-- `f ⁻¹' t` denotes the preimage of `t : Set β` under the function `f : α → β`. -/
infixl:80 " ⁻¹' " => preimage
section Preimage
variable {f : α → β} {g : β → γ}
@[simp]
theorem preimage_empty : f ⁻¹' ∅ = ∅ :=
rfl
#align set.preimage_empty Set.preimage_empty
@[simp, mfld_simps]
theorem mem_preimage {s : Set β} {a : α} : a ∈ f ⁻¹' s ↔ f a ∈ s :=
Iff.rfl
#align set.mem_preimage Set.mem_preimage
theorem preimage_congr {f g : α → β} {s : Set β} (h : ∀ x : α, f x = g x) : f ⁻¹' s = g ⁻¹' s := by
congr with x
simp [h]
#align set.preimage_congr Set.preimage_congr
@[gcongr]
theorem preimage_mono {s t : Set β} (h : s ⊆ t) : f ⁻¹' s ⊆ f ⁻¹' t := fun _ hx => h hx
#align set.preimage_mono Set.preimage_mono
@[simp, mfld_simps]
theorem preimage_univ : f ⁻¹' univ = univ :=
rfl
#align set.preimage_univ Set.preimage_univ
theorem subset_preimage_univ {s : Set α} : s ⊆ f ⁻¹' univ :=
subset_univ _
#align set.subset_preimage_univ Set.subset_preimage_univ
@[simp, mfld_simps]
theorem preimage_inter {s t : Set β} : f ⁻¹' (s ∩ t) = f ⁻¹' s ∩ f ⁻¹' t :=
rfl
#align set.preimage_inter Set.preimage_inter
@[simp]
theorem preimage_union {s t : Set β} : f ⁻¹' (s ∪ t) = f ⁻¹' s ∪ f ⁻¹' t :=
rfl
#align set.preimage_union Set.preimage_union
@[simp]
theorem preimage_compl {s : Set β} : f ⁻¹' sᶜ = (f ⁻¹' s)ᶜ :=
rfl
#align set.preimage_compl Set.preimage_compl
@[simp]
theorem preimage_diff (f : α → β) (s t : Set β) : f ⁻¹' (s \ t) = f ⁻¹' s \ f ⁻¹' t :=
rfl
#align set.preimage_diff Set.preimage_diff
@[simp]
lemma preimage_symmDiff {f : α → β} (s t : Set β) : f ⁻¹' (s ∆ t) = (f ⁻¹' s) ∆ (f ⁻¹' t) :=
rfl
#align set.preimage_symm_diff Set.preimage_symmDiff
@[simp]
theorem preimage_ite (f : α → β) (s t₁ t₂ : Set β) :
f ⁻¹' s.ite t₁ t₂ = (f ⁻¹' s).ite (f ⁻¹' t₁) (f ⁻¹' t₂) :=
rfl
#align set.preimage_ite Set.preimage_ite
@[simp]
theorem preimage_setOf_eq {p : α → Prop} {f : β → α} : f ⁻¹' { a | p a } = { a | p (f a) } :=
rfl
#align set.preimage_set_of_eq Set.preimage_setOf_eq
@[simp]
theorem preimage_id_eq : preimage (id : α → α) = id :=
rfl
#align set.preimage_id_eq Set.preimage_id_eq
@[mfld_simps]
theorem preimage_id {s : Set α} : id ⁻¹' s = s :=
rfl
#align set.preimage_id Set.preimage_id
@[simp, mfld_simps]
theorem preimage_id' {s : Set α} : (fun x => x) ⁻¹' s = s :=
rfl
#align set.preimage_id' Set.preimage_id'
@[simp]
theorem preimage_const_of_mem {b : β} {s : Set β} (h : b ∈ s) : (fun _ : α => b) ⁻¹' s = univ :=
eq_univ_of_forall fun _ => h
#align set.preimage_const_of_mem Set.preimage_const_of_mem
@[simp]
theorem preimage_const_of_not_mem {b : β} {s : Set β} (h : b ∉ s) : (fun _ : α => b) ⁻¹' s = ∅ :=
eq_empty_of_subset_empty fun _ hx => h hx
#align set.preimage_const_of_not_mem Set.preimage_const_of_not_mem
theorem preimage_const (b : β) (s : Set β) [Decidable (b ∈ s)] :
(fun _ : α => b) ⁻¹' s = if b ∈ s then univ else ∅ := by
split_ifs with hb
exacts [preimage_const_of_mem hb, preimage_const_of_not_mem hb]
#align set.preimage_const Set.preimage_const
/-- If preimage of each singleton under `f : α → β` is either empty or the whole type,
then `f` is a constant. -/
lemma exists_eq_const_of_preimage_singleton [Nonempty β] {f : α → β}
(hf : ∀ b : β, f ⁻¹' {b} = ∅ ∨ f ⁻¹' {b} = univ) : ∃ b, f = const α b := by
rcases em (∃ b, f ⁻¹' {b} = univ) with ⟨b, hb⟩ | hf'
· exact ⟨b, funext fun x ↦ eq_univ_iff_forall.1 hb x⟩
· have : ∀ x b, f x ≠ b := fun x b ↦
eq_empty_iff_forall_not_mem.1 ((hf b).resolve_right fun h ↦ hf' ⟨b, h⟩) x
exact ⟨Classical.arbitrary β, funext fun x ↦ absurd rfl (this x _)⟩
theorem preimage_comp {s : Set γ} : g ∘ f ⁻¹' s = f ⁻¹' (g ⁻¹' s) :=
rfl
#align set.preimage_comp Set.preimage_comp
theorem preimage_comp_eq : preimage (g ∘ f) = preimage f ∘ preimage g :=
rfl
#align set.preimage_comp_eq Set.preimage_comp_eq
theorem preimage_iterate_eq {f : α → α} {n : ℕ} : Set.preimage f^[n] = (Set.preimage f)^[n] := by
induction' n with n ih; · simp
rw [iterate_succ, iterate_succ', preimage_comp_eq, ih]
#align set.preimage_iterate_eq Set.preimage_iterate_eq
theorem preimage_preimage {g : β → γ} {f : α → β} {s : Set γ} :
f ⁻¹' (g ⁻¹' s) = (fun x => g (f x)) ⁻¹' s :=
preimage_comp.symm
#align set.preimage_preimage Set.preimage_preimage
theorem eq_preimage_subtype_val_iff {p : α → Prop} {s : Set (Subtype p)} {t : Set α} :
s = Subtype.val ⁻¹' t ↔ ∀ (x) (h : p x), (⟨x, h⟩ : Subtype p) ∈ s ↔ x ∈ t :=
⟨fun s_eq x h => by
rw [s_eq]
simp, fun h => ext fun ⟨x, hx⟩ => by simp [h]⟩
#align set.eq_preimage_subtype_val_iff Set.eq_preimage_subtype_val_iff
theorem nonempty_of_nonempty_preimage {s : Set β} {f : α → β} (hf : (f ⁻¹' s).Nonempty) :
s.Nonempty :=
let ⟨x, hx⟩ := hf
⟨f x, hx⟩
#align set.nonempty_of_nonempty_preimage Set.nonempty_of_nonempty_preimage
@[simp] theorem preimage_singleton_true (p : α → Prop) : p ⁻¹' {True} = {a | p a} := by ext; simp
#align set.preimage_singleton_true Set.preimage_singleton_true
@[simp] theorem preimage_singleton_false (p : α → Prop) : p ⁻¹' {False} = {a | ¬p a} := by ext; simp
#align set.preimage_singleton_false Set.preimage_singleton_false
theorem preimage_subtype_coe_eq_compl {s u v : Set α} (hsuv : s ⊆ u ∪ v)
(H : s ∩ (u ∩ v) = ∅) : ((↑) : s → α) ⁻¹' u = ((↑) ⁻¹' v)ᶜ := by
ext ⟨x, x_in_s⟩
constructor
· intro x_in_u x_in_v
exact eq_empty_iff_forall_not_mem.mp H x ⟨x_in_s, ⟨x_in_u, x_in_v⟩⟩
· intro hx
exact Or.elim (hsuv x_in_s) id fun hx' => hx.elim hx'
#align set.preimage_subtype_coe_eq_compl Set.preimage_subtype_coe_eq_compl
end Preimage
/-! ### Image of a set under a function -/
section Image
variable {f : α → β} {s t : Set α}
-- Porting note: `Set.image` is already defined in `Init.Set`
#align set.image Set.image
/-- `f '' s` denotes the image of `s : Set α` under the function `f : α → β`. -/
infixl:80 " '' " => image
theorem mem_image_iff_bex {f : α → β} {s : Set α} {y : β} :
y ∈ f '' s ↔ ∃ (x : _) (_ : x ∈ s), f x = y :=
bex_def.symm
#align set.mem_image_iff_bex Set.mem_image_iff_bex
@[simp]
theorem mem_image (f : α → β) (s : Set α) (y : β) : y ∈ f '' s ↔ ∃ x ∈ s, f x = y :=
Iff.rfl
#align set.mem_image Set.mem_image
theorem image_eta (f : α → β) : f '' s = (fun x => f x) '' s :=
rfl
#align set.image_eta Set.image_eta
@[mfld_simps]
theorem mem_image_of_mem (f : α → β) {x : α} {a : Set α} (h : x ∈ a) : f x ∈ f '' a :=
⟨_, h, rfl⟩
#align set.mem_image_of_mem Set.mem_image_of_mem
theorem _root_.Function.Injective.mem_set_image {f : α → β} (hf : Injective f) {s : Set α} {a : α} :
f a ∈ f '' s ↔ a ∈ s :=
⟨fun ⟨_, hb, Eq⟩ => hf Eq ▸ hb, mem_image_of_mem f⟩
#align function.injective.mem_set_image Function.Injective.mem_set_image
theorem ball_image_iff {f : α → β} {s : Set α} {p : β → Prop} :
(∀ y ∈ f '' s, p y) ↔ ∀ x ∈ s, p (f x) := by simp
#align set.ball_image_iff Set.ball_image_iff
theorem ball_image_of_ball {f : α → β} {s : Set α} {p : β → Prop} (h : ∀ x ∈ s, p (f x)) :
∀ y ∈ f '' s, p y :=
ball_image_iff.2 h
#align set.ball_image_of_ball Set.ball_image_of_ball
theorem bex_image_iff {f : α → β} {s : Set α} {p : β → Prop} :
(∃ y ∈ f '' s, p y) ↔ ∃ x ∈ s, p (f x) := by simp
#align set.bex_image_iff Set.bex_image_iff
theorem mem_image_elim {f : α → β} {s : Set α} {C : β → Prop} (h : ∀ x : α, x ∈ s → C (f x)) :
∀ {y : β}, y ∈ f '' s → C y
| _, ⟨a, a_in, rfl⟩ => h a a_in
#align set.mem_image_elim Set.mem_image_elim
theorem mem_image_elim_on {f : α → β} {s : Set α} {C : β → Prop} {y : β} (h_y : y ∈ f '' s)
(h : ∀ x : α, x ∈ s → C (f x)) : C y :=
mem_image_elim h h_y
#align set.mem_image_elim_on Set.mem_image_elim_on
-- Porting note: used to be `safe`
@[congr]
theorem image_congr {f g : α → β} {s : Set α} (h : ∀ a ∈ s, f a = g a) : f '' s = g '' s := by
ext x
rw [mem_image, mem_image]
exact {
mp := by
rintro ⟨a, ha1, ha2⟩
exact ⟨a, ⟨ha1, (h a ha1) ▸ ha2⟩⟩,
mpr := by
rintro ⟨a, ha1, ha2⟩
exact ⟨a, ⟨ha1, (h a ha1) ▸ ha2⟩⟩
}
-- safe [ext_iff, iff_def]
#align set.image_congr Set.image_congr
/-- A common special case of `image_congr` -/
theorem image_congr' {f g : α → β} {s : Set α} (h : ∀ x : α, f x = g x) : f '' s = g '' s :=
image_congr fun x _ => h x
#align set.image_congr' Set.image_congr'
@[gcongr]
lemma image_mono (h : s ⊆ t) : f '' s ⊆ f '' t := by
rintro - ⟨a, ha, rfl⟩; exact mem_image_of_mem f (h ha)
theorem image_comp (f : β → γ) (g : α → β) (a : Set α) : f ∘ g '' a = f '' (g '' a) :=
Subset.antisymm (ball_image_of_ball fun _ ha => mem_image_of_mem _ <| mem_image_of_mem _ ha)
(ball_image_of_ball <| ball_image_of_ball fun _ ha => mem_image_of_mem _ ha)
#align set.image_comp Set.image_comp
theorem image_comp_eq {g : β → γ} : image (g ∘ f) = image g ∘ image f := by ext; simp
/-- A variant of `image_comp`, useful for rewriting -/
theorem image_image (g : β → γ) (f : α → β) (s : Set α) : g '' (f '' s) = (fun x => g (f x)) '' s :=
(image_comp g f s).symm
#align set.image_image Set.image_image
theorem image_comm {β'} {f : β → γ} {g : α → β} {f' : α → β'} {g' : β' → γ}
(h_comm : ∀ a, f (g a) = g' (f' a)) : (s.image g).image f = (s.image f').image g' := by
simp_rw [image_image, h_comm]
#align set.image_comm Set.image_comm
theorem _root_.Function.Semiconj.set_image {f : α → β} {ga : α → α} {gb : β → β}
(h : Function.Semiconj f ga gb) : Function.Semiconj (image f) (image ga) (image gb) := fun _ =>
image_comm h
#align function.semiconj.set_image Function.Semiconj.set_image
theorem _root_.Function.Commute.set_image {f g : α → α} (h : Function.Commute f g) :
Function.Commute (image f) (image g) :=
Function.Semiconj.set_image h
#align function.commute.set_image Function.Commute.set_image
/-- Image is monotone with respect to `⊆`. See `Set.monotone_image` for the statement in
terms of `≤`. -/
@[gcongr]
theorem image_subset {a b : Set α} (f : α → β) (h : a ⊆ b) : f '' a ⊆ f '' b := by
simp only [subset_def, mem_image]
exact fun x => fun ⟨w, h1, h2⟩ => ⟨w, h h1, h2⟩
#align set.image_subset Set.image_subset
/-- `Set.image` is monotone. See `Set.image_subset` for the statement in terms of `⊆`. -/
lemma monotone_image {f : α → β} : Monotone (image f) := fun _ _ => image_subset _
#align set.monotone_image Set.monotone_image
theorem image_union (f : α → β) (s t : Set α) : f '' (s ∪ t) = f '' s ∪ f '' t :=
ext fun x =>
⟨by rintro ⟨a, h | h, rfl⟩ <;> [left; right] <;> exact ⟨_, h, rfl⟩, by
rintro (⟨a, h, rfl⟩ | ⟨a, h, rfl⟩) <;> refine' ⟨_, _, rfl⟩ <;> [left; right] <;> exact h⟩
#align set.image_union Set.image_union
@[simp]
theorem image_empty (f : α → β) : f '' ∅ = ∅ := by
ext
simp
#align set.image_empty Set.image_empty
theorem image_inter_subset (f : α → β) (s t : Set α) : f '' (s ∩ t) ⊆ f '' s ∩ f '' t :=
subset_inter (image_subset _ <| inter_subset_left _ _) (image_subset _ <| inter_subset_right _ _)
#align set.image_inter_subset Set.image_inter_subset
theorem image_inter_on {f : α → β} {s t : Set α} (h : ∀ x ∈ t, ∀ y ∈ s, f x = f y → x = y) :
f '' (s ∩ t) = f '' s ∩ f '' t :=
(image_inter_subset _ _ _).antisymm
fun b ⟨⟨a₁, ha₁, h₁⟩, ⟨a₂, ha₂, h₂⟩⟩ ↦
have : a₂ = a₁ := h _ ha₂ _ ha₁ (by simp [*])
⟨a₁, ⟨ha₁, this ▸ ha₂⟩, h₁⟩
#align set.image_inter_on Set.image_inter_on
theorem image_inter {f : α → β} {s t : Set α} (H : Injective f) : f '' (s ∩ t) = f '' s ∩ f '' t :=
image_inter_on fun _ _ _ _ h => H h
#align set.image_inter Set.image_inter
theorem image_univ_of_surjective {ι : Type*} {f : ι → β} (H : Surjective f) : f '' univ = univ :=
eq_univ_of_forall <| by
|
simpa [image]
|
theorem image_univ_of_surjective {ι : Type*} {f : ι → β} (H : Surjective f) : f '' univ = univ :=
eq_univ_of_forall <| by
|
Mathlib.Data.Set.Image.364_0.IJFiTzmYGOCpPSd
|
theorem image_univ_of_surjective {ι : Type*} {f : ι → β} (H : Surjective f) : f '' univ = univ
|
Mathlib_Data_Set_Image
|
α : Type u_1
β : Type u_2
γ : Type u_3
ι : Sort u_4
ι' : Sort u_5
f✝ : α → β
s t : Set α
f : α → β
a : α
⊢ f '' {a} = {f a}
|
/-
Copyright (c) 2014 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Leonardo de Moura
-/
import Mathlib.Data.Set.Basic
#align_import data.set.image from "leanprover-community/mathlib"@"001ffdc42920050657fd45bd2b8bfbec8eaaeb29"
/-!
# Images and preimages of sets
## Main definitions
* `preimage f t : Set α` : the preimage f⁻¹(t) (written `f ⁻¹' t` in Lean) of a subset of β.
* `range f : Set β` : the image of `univ` under `f`.
Also works for `{p : Prop} (f : p → α)` (unlike `image`)
## Notation
* `f ⁻¹' t` for `Set.preimage f t`
* `f '' s` for `Set.image f s`
## Tags
set, sets, image, preimage, pre-image, range
-/
set_option autoImplicit true
universe u v
open Function Set
namespace Set
variable {α β γ : Type*} {ι ι' : Sort*}
/-! ### Inverse image -/
/-- The preimage of `s : Set β` by `f : α → β`, written `f ⁻¹' s`,
is the set of `x : α` such that `f x ∈ s`. -/
def preimage {α : Type u} {β : Type v} (f : α → β) (s : Set β) : Set α :=
{ x | f x ∈ s }
#align set.preimage Set.preimage
/-- `f ⁻¹' t` denotes the preimage of `t : Set β` under the function `f : α → β`. -/
infixl:80 " ⁻¹' " => preimage
section Preimage
variable {f : α → β} {g : β → γ}
@[simp]
theorem preimage_empty : f ⁻¹' ∅ = ∅ :=
rfl
#align set.preimage_empty Set.preimage_empty
@[simp, mfld_simps]
theorem mem_preimage {s : Set β} {a : α} : a ∈ f ⁻¹' s ↔ f a ∈ s :=
Iff.rfl
#align set.mem_preimage Set.mem_preimage
theorem preimage_congr {f g : α → β} {s : Set β} (h : ∀ x : α, f x = g x) : f ⁻¹' s = g ⁻¹' s := by
congr with x
simp [h]
#align set.preimage_congr Set.preimage_congr
@[gcongr]
theorem preimage_mono {s t : Set β} (h : s ⊆ t) : f ⁻¹' s ⊆ f ⁻¹' t := fun _ hx => h hx
#align set.preimage_mono Set.preimage_mono
@[simp, mfld_simps]
theorem preimage_univ : f ⁻¹' univ = univ :=
rfl
#align set.preimage_univ Set.preimage_univ
theorem subset_preimage_univ {s : Set α} : s ⊆ f ⁻¹' univ :=
subset_univ _
#align set.subset_preimage_univ Set.subset_preimage_univ
@[simp, mfld_simps]
theorem preimage_inter {s t : Set β} : f ⁻¹' (s ∩ t) = f ⁻¹' s ∩ f ⁻¹' t :=
rfl
#align set.preimage_inter Set.preimage_inter
@[simp]
theorem preimage_union {s t : Set β} : f ⁻¹' (s ∪ t) = f ⁻¹' s ∪ f ⁻¹' t :=
rfl
#align set.preimage_union Set.preimage_union
@[simp]
theorem preimage_compl {s : Set β} : f ⁻¹' sᶜ = (f ⁻¹' s)ᶜ :=
rfl
#align set.preimage_compl Set.preimage_compl
@[simp]
theorem preimage_diff (f : α → β) (s t : Set β) : f ⁻¹' (s \ t) = f ⁻¹' s \ f ⁻¹' t :=
rfl
#align set.preimage_diff Set.preimage_diff
@[simp]
lemma preimage_symmDiff {f : α → β} (s t : Set β) : f ⁻¹' (s ∆ t) = (f ⁻¹' s) ∆ (f ⁻¹' t) :=
rfl
#align set.preimage_symm_diff Set.preimage_symmDiff
@[simp]
theorem preimage_ite (f : α → β) (s t₁ t₂ : Set β) :
f ⁻¹' s.ite t₁ t₂ = (f ⁻¹' s).ite (f ⁻¹' t₁) (f ⁻¹' t₂) :=
rfl
#align set.preimage_ite Set.preimage_ite
@[simp]
theorem preimage_setOf_eq {p : α → Prop} {f : β → α} : f ⁻¹' { a | p a } = { a | p (f a) } :=
rfl
#align set.preimage_set_of_eq Set.preimage_setOf_eq
@[simp]
theorem preimage_id_eq : preimage (id : α → α) = id :=
rfl
#align set.preimage_id_eq Set.preimage_id_eq
@[mfld_simps]
theorem preimage_id {s : Set α} : id ⁻¹' s = s :=
rfl
#align set.preimage_id Set.preimage_id
@[simp, mfld_simps]
theorem preimage_id' {s : Set α} : (fun x => x) ⁻¹' s = s :=
rfl
#align set.preimage_id' Set.preimage_id'
@[simp]
theorem preimage_const_of_mem {b : β} {s : Set β} (h : b ∈ s) : (fun _ : α => b) ⁻¹' s = univ :=
eq_univ_of_forall fun _ => h
#align set.preimage_const_of_mem Set.preimage_const_of_mem
@[simp]
theorem preimage_const_of_not_mem {b : β} {s : Set β} (h : b ∉ s) : (fun _ : α => b) ⁻¹' s = ∅ :=
eq_empty_of_subset_empty fun _ hx => h hx
#align set.preimage_const_of_not_mem Set.preimage_const_of_not_mem
theorem preimage_const (b : β) (s : Set β) [Decidable (b ∈ s)] :
(fun _ : α => b) ⁻¹' s = if b ∈ s then univ else ∅ := by
split_ifs with hb
exacts [preimage_const_of_mem hb, preimage_const_of_not_mem hb]
#align set.preimage_const Set.preimage_const
/-- If preimage of each singleton under `f : α → β` is either empty or the whole type,
then `f` is a constant. -/
lemma exists_eq_const_of_preimage_singleton [Nonempty β] {f : α → β}
(hf : ∀ b : β, f ⁻¹' {b} = ∅ ∨ f ⁻¹' {b} = univ) : ∃ b, f = const α b := by
rcases em (∃ b, f ⁻¹' {b} = univ) with ⟨b, hb⟩ | hf'
· exact ⟨b, funext fun x ↦ eq_univ_iff_forall.1 hb x⟩
· have : ∀ x b, f x ≠ b := fun x b ↦
eq_empty_iff_forall_not_mem.1 ((hf b).resolve_right fun h ↦ hf' ⟨b, h⟩) x
exact ⟨Classical.arbitrary β, funext fun x ↦ absurd rfl (this x _)⟩
theorem preimage_comp {s : Set γ} : g ∘ f ⁻¹' s = f ⁻¹' (g ⁻¹' s) :=
rfl
#align set.preimage_comp Set.preimage_comp
theorem preimage_comp_eq : preimage (g ∘ f) = preimage f ∘ preimage g :=
rfl
#align set.preimage_comp_eq Set.preimage_comp_eq
theorem preimage_iterate_eq {f : α → α} {n : ℕ} : Set.preimage f^[n] = (Set.preimage f)^[n] := by
induction' n with n ih; · simp
rw [iterate_succ, iterate_succ', preimage_comp_eq, ih]
#align set.preimage_iterate_eq Set.preimage_iterate_eq
theorem preimage_preimage {g : β → γ} {f : α → β} {s : Set γ} :
f ⁻¹' (g ⁻¹' s) = (fun x => g (f x)) ⁻¹' s :=
preimage_comp.symm
#align set.preimage_preimage Set.preimage_preimage
theorem eq_preimage_subtype_val_iff {p : α → Prop} {s : Set (Subtype p)} {t : Set α} :
s = Subtype.val ⁻¹' t ↔ ∀ (x) (h : p x), (⟨x, h⟩ : Subtype p) ∈ s ↔ x ∈ t :=
⟨fun s_eq x h => by
rw [s_eq]
simp, fun h => ext fun ⟨x, hx⟩ => by simp [h]⟩
#align set.eq_preimage_subtype_val_iff Set.eq_preimage_subtype_val_iff
theorem nonempty_of_nonempty_preimage {s : Set β} {f : α → β} (hf : (f ⁻¹' s).Nonempty) :
s.Nonempty :=
let ⟨x, hx⟩ := hf
⟨f x, hx⟩
#align set.nonempty_of_nonempty_preimage Set.nonempty_of_nonempty_preimage
@[simp] theorem preimage_singleton_true (p : α → Prop) : p ⁻¹' {True} = {a | p a} := by ext; simp
#align set.preimage_singleton_true Set.preimage_singleton_true
@[simp] theorem preimage_singleton_false (p : α → Prop) : p ⁻¹' {False} = {a | ¬p a} := by ext; simp
#align set.preimage_singleton_false Set.preimage_singleton_false
theorem preimage_subtype_coe_eq_compl {s u v : Set α} (hsuv : s ⊆ u ∪ v)
(H : s ∩ (u ∩ v) = ∅) : ((↑) : s → α) ⁻¹' u = ((↑) ⁻¹' v)ᶜ := by
ext ⟨x, x_in_s⟩
constructor
· intro x_in_u x_in_v
exact eq_empty_iff_forall_not_mem.mp H x ⟨x_in_s, ⟨x_in_u, x_in_v⟩⟩
· intro hx
exact Or.elim (hsuv x_in_s) id fun hx' => hx.elim hx'
#align set.preimage_subtype_coe_eq_compl Set.preimage_subtype_coe_eq_compl
end Preimage
/-! ### Image of a set under a function -/
section Image
variable {f : α → β} {s t : Set α}
-- Porting note: `Set.image` is already defined in `Init.Set`
#align set.image Set.image
/-- `f '' s` denotes the image of `s : Set α` under the function `f : α → β`. -/
infixl:80 " '' " => image
theorem mem_image_iff_bex {f : α → β} {s : Set α} {y : β} :
y ∈ f '' s ↔ ∃ (x : _) (_ : x ∈ s), f x = y :=
bex_def.symm
#align set.mem_image_iff_bex Set.mem_image_iff_bex
@[simp]
theorem mem_image (f : α → β) (s : Set α) (y : β) : y ∈ f '' s ↔ ∃ x ∈ s, f x = y :=
Iff.rfl
#align set.mem_image Set.mem_image
theorem image_eta (f : α → β) : f '' s = (fun x => f x) '' s :=
rfl
#align set.image_eta Set.image_eta
@[mfld_simps]
theorem mem_image_of_mem (f : α → β) {x : α} {a : Set α} (h : x ∈ a) : f x ∈ f '' a :=
⟨_, h, rfl⟩
#align set.mem_image_of_mem Set.mem_image_of_mem
theorem _root_.Function.Injective.mem_set_image {f : α → β} (hf : Injective f) {s : Set α} {a : α} :
f a ∈ f '' s ↔ a ∈ s :=
⟨fun ⟨_, hb, Eq⟩ => hf Eq ▸ hb, mem_image_of_mem f⟩
#align function.injective.mem_set_image Function.Injective.mem_set_image
theorem ball_image_iff {f : α → β} {s : Set α} {p : β → Prop} :
(∀ y ∈ f '' s, p y) ↔ ∀ x ∈ s, p (f x) := by simp
#align set.ball_image_iff Set.ball_image_iff
theorem ball_image_of_ball {f : α → β} {s : Set α} {p : β → Prop} (h : ∀ x ∈ s, p (f x)) :
∀ y ∈ f '' s, p y :=
ball_image_iff.2 h
#align set.ball_image_of_ball Set.ball_image_of_ball
theorem bex_image_iff {f : α → β} {s : Set α} {p : β → Prop} :
(∃ y ∈ f '' s, p y) ↔ ∃ x ∈ s, p (f x) := by simp
#align set.bex_image_iff Set.bex_image_iff
theorem mem_image_elim {f : α → β} {s : Set α} {C : β → Prop} (h : ∀ x : α, x ∈ s → C (f x)) :
∀ {y : β}, y ∈ f '' s → C y
| _, ⟨a, a_in, rfl⟩ => h a a_in
#align set.mem_image_elim Set.mem_image_elim
theorem mem_image_elim_on {f : α → β} {s : Set α} {C : β → Prop} {y : β} (h_y : y ∈ f '' s)
(h : ∀ x : α, x ∈ s → C (f x)) : C y :=
mem_image_elim h h_y
#align set.mem_image_elim_on Set.mem_image_elim_on
-- Porting note: used to be `safe`
@[congr]
theorem image_congr {f g : α → β} {s : Set α} (h : ∀ a ∈ s, f a = g a) : f '' s = g '' s := by
ext x
rw [mem_image, mem_image]
exact {
mp := by
rintro ⟨a, ha1, ha2⟩
exact ⟨a, ⟨ha1, (h a ha1) ▸ ha2⟩⟩,
mpr := by
rintro ⟨a, ha1, ha2⟩
exact ⟨a, ⟨ha1, (h a ha1) ▸ ha2⟩⟩
}
-- safe [ext_iff, iff_def]
#align set.image_congr Set.image_congr
/-- A common special case of `image_congr` -/
theorem image_congr' {f g : α → β} {s : Set α} (h : ∀ x : α, f x = g x) : f '' s = g '' s :=
image_congr fun x _ => h x
#align set.image_congr' Set.image_congr'
@[gcongr]
lemma image_mono (h : s ⊆ t) : f '' s ⊆ f '' t := by
rintro - ⟨a, ha, rfl⟩; exact mem_image_of_mem f (h ha)
theorem image_comp (f : β → γ) (g : α → β) (a : Set α) : f ∘ g '' a = f '' (g '' a) :=
Subset.antisymm (ball_image_of_ball fun _ ha => mem_image_of_mem _ <| mem_image_of_mem _ ha)
(ball_image_of_ball <| ball_image_of_ball fun _ ha => mem_image_of_mem _ ha)
#align set.image_comp Set.image_comp
theorem image_comp_eq {g : β → γ} : image (g ∘ f) = image g ∘ image f := by ext; simp
/-- A variant of `image_comp`, useful for rewriting -/
theorem image_image (g : β → γ) (f : α → β) (s : Set α) : g '' (f '' s) = (fun x => g (f x)) '' s :=
(image_comp g f s).symm
#align set.image_image Set.image_image
theorem image_comm {β'} {f : β → γ} {g : α → β} {f' : α → β'} {g' : β' → γ}
(h_comm : ∀ a, f (g a) = g' (f' a)) : (s.image g).image f = (s.image f').image g' := by
simp_rw [image_image, h_comm]
#align set.image_comm Set.image_comm
theorem _root_.Function.Semiconj.set_image {f : α → β} {ga : α → α} {gb : β → β}
(h : Function.Semiconj f ga gb) : Function.Semiconj (image f) (image ga) (image gb) := fun _ =>
image_comm h
#align function.semiconj.set_image Function.Semiconj.set_image
theorem _root_.Function.Commute.set_image {f g : α → α} (h : Function.Commute f g) :
Function.Commute (image f) (image g) :=
Function.Semiconj.set_image h
#align function.commute.set_image Function.Commute.set_image
/-- Image is monotone with respect to `⊆`. See `Set.monotone_image` for the statement in
terms of `≤`. -/
@[gcongr]
theorem image_subset {a b : Set α} (f : α → β) (h : a ⊆ b) : f '' a ⊆ f '' b := by
simp only [subset_def, mem_image]
exact fun x => fun ⟨w, h1, h2⟩ => ⟨w, h h1, h2⟩
#align set.image_subset Set.image_subset
/-- `Set.image` is monotone. See `Set.image_subset` for the statement in terms of `⊆`. -/
lemma monotone_image {f : α → β} : Monotone (image f) := fun _ _ => image_subset _
#align set.monotone_image Set.monotone_image
theorem image_union (f : α → β) (s t : Set α) : f '' (s ∪ t) = f '' s ∪ f '' t :=
ext fun x =>
⟨by rintro ⟨a, h | h, rfl⟩ <;> [left; right] <;> exact ⟨_, h, rfl⟩, by
rintro (⟨a, h, rfl⟩ | ⟨a, h, rfl⟩) <;> refine' ⟨_, _, rfl⟩ <;> [left; right] <;> exact h⟩
#align set.image_union Set.image_union
@[simp]
theorem image_empty (f : α → β) : f '' ∅ = ∅ := by
ext
simp
#align set.image_empty Set.image_empty
theorem image_inter_subset (f : α → β) (s t : Set α) : f '' (s ∩ t) ⊆ f '' s ∩ f '' t :=
subset_inter (image_subset _ <| inter_subset_left _ _) (image_subset _ <| inter_subset_right _ _)
#align set.image_inter_subset Set.image_inter_subset
theorem image_inter_on {f : α → β} {s t : Set α} (h : ∀ x ∈ t, ∀ y ∈ s, f x = f y → x = y) :
f '' (s ∩ t) = f '' s ∩ f '' t :=
(image_inter_subset _ _ _).antisymm
fun b ⟨⟨a₁, ha₁, h₁⟩, ⟨a₂, ha₂, h₂⟩⟩ ↦
have : a₂ = a₁ := h _ ha₂ _ ha₁ (by simp [*])
⟨a₁, ⟨ha₁, this ▸ ha₂⟩, h₁⟩
#align set.image_inter_on Set.image_inter_on
theorem image_inter {f : α → β} {s t : Set α} (H : Injective f) : f '' (s ∩ t) = f '' s ∩ f '' t :=
image_inter_on fun _ _ _ _ h => H h
#align set.image_inter Set.image_inter
theorem image_univ_of_surjective {ι : Type*} {f : ι → β} (H : Surjective f) : f '' univ = univ :=
eq_univ_of_forall <| by simpa [image]
#align set.image_univ_of_surjective Set.image_univ_of_surjective
@[simp]
theorem image_singleton {f : α → β} {a : α} : f '' {a} = {f a} := by
|
ext
|
@[simp]
theorem image_singleton {f : α → β} {a : α} : f '' {a} = {f a} := by
|
Mathlib.Data.Set.Image.368_0.IJFiTzmYGOCpPSd
|
@[simp]
theorem image_singleton {f : α → β} {a : α} : f '' {a} = {f a}
|
Mathlib_Data_Set_Image
|
case h
α : Type u_1
β : Type u_2
γ : Type u_3
ι : Sort u_4
ι' : Sort u_5
f✝ : α → β
s t : Set α
f : α → β
a : α
x✝ : β
⊢ x✝ ∈ f '' {a} ↔ x✝ ∈ {f a}
|
/-
Copyright (c) 2014 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Leonardo de Moura
-/
import Mathlib.Data.Set.Basic
#align_import data.set.image from "leanprover-community/mathlib"@"001ffdc42920050657fd45bd2b8bfbec8eaaeb29"
/-!
# Images and preimages of sets
## Main definitions
* `preimage f t : Set α` : the preimage f⁻¹(t) (written `f ⁻¹' t` in Lean) of a subset of β.
* `range f : Set β` : the image of `univ` under `f`.
Also works for `{p : Prop} (f : p → α)` (unlike `image`)
## Notation
* `f ⁻¹' t` for `Set.preimage f t`
* `f '' s` for `Set.image f s`
## Tags
set, sets, image, preimage, pre-image, range
-/
set_option autoImplicit true
universe u v
open Function Set
namespace Set
variable {α β γ : Type*} {ι ι' : Sort*}
/-! ### Inverse image -/
/-- The preimage of `s : Set β` by `f : α → β`, written `f ⁻¹' s`,
is the set of `x : α` such that `f x ∈ s`. -/
def preimage {α : Type u} {β : Type v} (f : α → β) (s : Set β) : Set α :=
{ x | f x ∈ s }
#align set.preimage Set.preimage
/-- `f ⁻¹' t` denotes the preimage of `t : Set β` under the function `f : α → β`. -/
infixl:80 " ⁻¹' " => preimage
section Preimage
variable {f : α → β} {g : β → γ}
@[simp]
theorem preimage_empty : f ⁻¹' ∅ = ∅ :=
rfl
#align set.preimage_empty Set.preimage_empty
@[simp, mfld_simps]
theorem mem_preimage {s : Set β} {a : α} : a ∈ f ⁻¹' s ↔ f a ∈ s :=
Iff.rfl
#align set.mem_preimage Set.mem_preimage
theorem preimage_congr {f g : α → β} {s : Set β} (h : ∀ x : α, f x = g x) : f ⁻¹' s = g ⁻¹' s := by
congr with x
simp [h]
#align set.preimage_congr Set.preimage_congr
@[gcongr]
theorem preimage_mono {s t : Set β} (h : s ⊆ t) : f ⁻¹' s ⊆ f ⁻¹' t := fun _ hx => h hx
#align set.preimage_mono Set.preimage_mono
@[simp, mfld_simps]
theorem preimage_univ : f ⁻¹' univ = univ :=
rfl
#align set.preimage_univ Set.preimage_univ
theorem subset_preimage_univ {s : Set α} : s ⊆ f ⁻¹' univ :=
subset_univ _
#align set.subset_preimage_univ Set.subset_preimage_univ
@[simp, mfld_simps]
theorem preimage_inter {s t : Set β} : f ⁻¹' (s ∩ t) = f ⁻¹' s ∩ f ⁻¹' t :=
rfl
#align set.preimage_inter Set.preimage_inter
@[simp]
theorem preimage_union {s t : Set β} : f ⁻¹' (s ∪ t) = f ⁻¹' s ∪ f ⁻¹' t :=
rfl
#align set.preimage_union Set.preimage_union
@[simp]
theorem preimage_compl {s : Set β} : f ⁻¹' sᶜ = (f ⁻¹' s)ᶜ :=
rfl
#align set.preimage_compl Set.preimage_compl
@[simp]
theorem preimage_diff (f : α → β) (s t : Set β) : f ⁻¹' (s \ t) = f ⁻¹' s \ f ⁻¹' t :=
rfl
#align set.preimage_diff Set.preimage_diff
@[simp]
lemma preimage_symmDiff {f : α → β} (s t : Set β) : f ⁻¹' (s ∆ t) = (f ⁻¹' s) ∆ (f ⁻¹' t) :=
rfl
#align set.preimage_symm_diff Set.preimage_symmDiff
@[simp]
theorem preimage_ite (f : α → β) (s t₁ t₂ : Set β) :
f ⁻¹' s.ite t₁ t₂ = (f ⁻¹' s).ite (f ⁻¹' t₁) (f ⁻¹' t₂) :=
rfl
#align set.preimage_ite Set.preimage_ite
@[simp]
theorem preimage_setOf_eq {p : α → Prop} {f : β → α} : f ⁻¹' { a | p a } = { a | p (f a) } :=
rfl
#align set.preimage_set_of_eq Set.preimage_setOf_eq
@[simp]
theorem preimage_id_eq : preimage (id : α → α) = id :=
rfl
#align set.preimage_id_eq Set.preimage_id_eq
@[mfld_simps]
theorem preimage_id {s : Set α} : id ⁻¹' s = s :=
rfl
#align set.preimage_id Set.preimage_id
@[simp, mfld_simps]
theorem preimage_id' {s : Set α} : (fun x => x) ⁻¹' s = s :=
rfl
#align set.preimage_id' Set.preimage_id'
@[simp]
theorem preimage_const_of_mem {b : β} {s : Set β} (h : b ∈ s) : (fun _ : α => b) ⁻¹' s = univ :=
eq_univ_of_forall fun _ => h
#align set.preimage_const_of_mem Set.preimage_const_of_mem
@[simp]
theorem preimage_const_of_not_mem {b : β} {s : Set β} (h : b ∉ s) : (fun _ : α => b) ⁻¹' s = ∅ :=
eq_empty_of_subset_empty fun _ hx => h hx
#align set.preimage_const_of_not_mem Set.preimage_const_of_not_mem
theorem preimage_const (b : β) (s : Set β) [Decidable (b ∈ s)] :
(fun _ : α => b) ⁻¹' s = if b ∈ s then univ else ∅ := by
split_ifs with hb
exacts [preimage_const_of_mem hb, preimage_const_of_not_mem hb]
#align set.preimage_const Set.preimage_const
/-- If preimage of each singleton under `f : α → β` is either empty or the whole type,
then `f` is a constant. -/
lemma exists_eq_const_of_preimage_singleton [Nonempty β] {f : α → β}
(hf : ∀ b : β, f ⁻¹' {b} = ∅ ∨ f ⁻¹' {b} = univ) : ∃ b, f = const α b := by
rcases em (∃ b, f ⁻¹' {b} = univ) with ⟨b, hb⟩ | hf'
· exact ⟨b, funext fun x ↦ eq_univ_iff_forall.1 hb x⟩
· have : ∀ x b, f x ≠ b := fun x b ↦
eq_empty_iff_forall_not_mem.1 ((hf b).resolve_right fun h ↦ hf' ⟨b, h⟩) x
exact ⟨Classical.arbitrary β, funext fun x ↦ absurd rfl (this x _)⟩
theorem preimage_comp {s : Set γ} : g ∘ f ⁻¹' s = f ⁻¹' (g ⁻¹' s) :=
rfl
#align set.preimage_comp Set.preimage_comp
theorem preimage_comp_eq : preimage (g ∘ f) = preimage f ∘ preimage g :=
rfl
#align set.preimage_comp_eq Set.preimage_comp_eq
theorem preimage_iterate_eq {f : α → α} {n : ℕ} : Set.preimage f^[n] = (Set.preimage f)^[n] := by
induction' n with n ih; · simp
rw [iterate_succ, iterate_succ', preimage_comp_eq, ih]
#align set.preimage_iterate_eq Set.preimage_iterate_eq
theorem preimage_preimage {g : β → γ} {f : α → β} {s : Set γ} :
f ⁻¹' (g ⁻¹' s) = (fun x => g (f x)) ⁻¹' s :=
preimage_comp.symm
#align set.preimage_preimage Set.preimage_preimage
theorem eq_preimage_subtype_val_iff {p : α → Prop} {s : Set (Subtype p)} {t : Set α} :
s = Subtype.val ⁻¹' t ↔ ∀ (x) (h : p x), (⟨x, h⟩ : Subtype p) ∈ s ↔ x ∈ t :=
⟨fun s_eq x h => by
rw [s_eq]
simp, fun h => ext fun ⟨x, hx⟩ => by simp [h]⟩
#align set.eq_preimage_subtype_val_iff Set.eq_preimage_subtype_val_iff
theorem nonempty_of_nonempty_preimage {s : Set β} {f : α → β} (hf : (f ⁻¹' s).Nonempty) :
s.Nonempty :=
let ⟨x, hx⟩ := hf
⟨f x, hx⟩
#align set.nonempty_of_nonempty_preimage Set.nonempty_of_nonempty_preimage
@[simp] theorem preimage_singleton_true (p : α → Prop) : p ⁻¹' {True} = {a | p a} := by ext; simp
#align set.preimage_singleton_true Set.preimage_singleton_true
@[simp] theorem preimage_singleton_false (p : α → Prop) : p ⁻¹' {False} = {a | ¬p a} := by ext; simp
#align set.preimage_singleton_false Set.preimage_singleton_false
theorem preimage_subtype_coe_eq_compl {s u v : Set α} (hsuv : s ⊆ u ∪ v)
(H : s ∩ (u ∩ v) = ∅) : ((↑) : s → α) ⁻¹' u = ((↑) ⁻¹' v)ᶜ := by
ext ⟨x, x_in_s⟩
constructor
· intro x_in_u x_in_v
exact eq_empty_iff_forall_not_mem.mp H x ⟨x_in_s, ⟨x_in_u, x_in_v⟩⟩
· intro hx
exact Or.elim (hsuv x_in_s) id fun hx' => hx.elim hx'
#align set.preimage_subtype_coe_eq_compl Set.preimage_subtype_coe_eq_compl
end Preimage
/-! ### Image of a set under a function -/
section Image
variable {f : α → β} {s t : Set α}
-- Porting note: `Set.image` is already defined in `Init.Set`
#align set.image Set.image
/-- `f '' s` denotes the image of `s : Set α` under the function `f : α → β`. -/
infixl:80 " '' " => image
theorem mem_image_iff_bex {f : α → β} {s : Set α} {y : β} :
y ∈ f '' s ↔ ∃ (x : _) (_ : x ∈ s), f x = y :=
bex_def.symm
#align set.mem_image_iff_bex Set.mem_image_iff_bex
@[simp]
theorem mem_image (f : α → β) (s : Set α) (y : β) : y ∈ f '' s ↔ ∃ x ∈ s, f x = y :=
Iff.rfl
#align set.mem_image Set.mem_image
theorem image_eta (f : α → β) : f '' s = (fun x => f x) '' s :=
rfl
#align set.image_eta Set.image_eta
@[mfld_simps]
theorem mem_image_of_mem (f : α → β) {x : α} {a : Set α} (h : x ∈ a) : f x ∈ f '' a :=
⟨_, h, rfl⟩
#align set.mem_image_of_mem Set.mem_image_of_mem
theorem _root_.Function.Injective.mem_set_image {f : α → β} (hf : Injective f) {s : Set α} {a : α} :
f a ∈ f '' s ↔ a ∈ s :=
⟨fun ⟨_, hb, Eq⟩ => hf Eq ▸ hb, mem_image_of_mem f⟩
#align function.injective.mem_set_image Function.Injective.mem_set_image
theorem ball_image_iff {f : α → β} {s : Set α} {p : β → Prop} :
(∀ y ∈ f '' s, p y) ↔ ∀ x ∈ s, p (f x) := by simp
#align set.ball_image_iff Set.ball_image_iff
theorem ball_image_of_ball {f : α → β} {s : Set α} {p : β → Prop} (h : ∀ x ∈ s, p (f x)) :
∀ y ∈ f '' s, p y :=
ball_image_iff.2 h
#align set.ball_image_of_ball Set.ball_image_of_ball
theorem bex_image_iff {f : α → β} {s : Set α} {p : β → Prop} :
(∃ y ∈ f '' s, p y) ↔ ∃ x ∈ s, p (f x) := by simp
#align set.bex_image_iff Set.bex_image_iff
theorem mem_image_elim {f : α → β} {s : Set α} {C : β → Prop} (h : ∀ x : α, x ∈ s → C (f x)) :
∀ {y : β}, y ∈ f '' s → C y
| _, ⟨a, a_in, rfl⟩ => h a a_in
#align set.mem_image_elim Set.mem_image_elim
theorem mem_image_elim_on {f : α → β} {s : Set α} {C : β → Prop} {y : β} (h_y : y ∈ f '' s)
(h : ∀ x : α, x ∈ s → C (f x)) : C y :=
mem_image_elim h h_y
#align set.mem_image_elim_on Set.mem_image_elim_on
-- Porting note: used to be `safe`
@[congr]
theorem image_congr {f g : α → β} {s : Set α} (h : ∀ a ∈ s, f a = g a) : f '' s = g '' s := by
ext x
rw [mem_image, mem_image]
exact {
mp := by
rintro ⟨a, ha1, ha2⟩
exact ⟨a, ⟨ha1, (h a ha1) ▸ ha2⟩⟩,
mpr := by
rintro ⟨a, ha1, ha2⟩
exact ⟨a, ⟨ha1, (h a ha1) ▸ ha2⟩⟩
}
-- safe [ext_iff, iff_def]
#align set.image_congr Set.image_congr
/-- A common special case of `image_congr` -/
theorem image_congr' {f g : α → β} {s : Set α} (h : ∀ x : α, f x = g x) : f '' s = g '' s :=
image_congr fun x _ => h x
#align set.image_congr' Set.image_congr'
@[gcongr]
lemma image_mono (h : s ⊆ t) : f '' s ⊆ f '' t := by
rintro - ⟨a, ha, rfl⟩; exact mem_image_of_mem f (h ha)
theorem image_comp (f : β → γ) (g : α → β) (a : Set α) : f ∘ g '' a = f '' (g '' a) :=
Subset.antisymm (ball_image_of_ball fun _ ha => mem_image_of_mem _ <| mem_image_of_mem _ ha)
(ball_image_of_ball <| ball_image_of_ball fun _ ha => mem_image_of_mem _ ha)
#align set.image_comp Set.image_comp
theorem image_comp_eq {g : β → γ} : image (g ∘ f) = image g ∘ image f := by ext; simp
/-- A variant of `image_comp`, useful for rewriting -/
theorem image_image (g : β → γ) (f : α → β) (s : Set α) : g '' (f '' s) = (fun x => g (f x)) '' s :=
(image_comp g f s).symm
#align set.image_image Set.image_image
theorem image_comm {β'} {f : β → γ} {g : α → β} {f' : α → β'} {g' : β' → γ}
(h_comm : ∀ a, f (g a) = g' (f' a)) : (s.image g).image f = (s.image f').image g' := by
simp_rw [image_image, h_comm]
#align set.image_comm Set.image_comm
theorem _root_.Function.Semiconj.set_image {f : α → β} {ga : α → α} {gb : β → β}
(h : Function.Semiconj f ga gb) : Function.Semiconj (image f) (image ga) (image gb) := fun _ =>
image_comm h
#align function.semiconj.set_image Function.Semiconj.set_image
theorem _root_.Function.Commute.set_image {f g : α → α} (h : Function.Commute f g) :
Function.Commute (image f) (image g) :=
Function.Semiconj.set_image h
#align function.commute.set_image Function.Commute.set_image
/-- Image is monotone with respect to `⊆`. See `Set.monotone_image` for the statement in
terms of `≤`. -/
@[gcongr]
theorem image_subset {a b : Set α} (f : α → β) (h : a ⊆ b) : f '' a ⊆ f '' b := by
simp only [subset_def, mem_image]
exact fun x => fun ⟨w, h1, h2⟩ => ⟨w, h h1, h2⟩
#align set.image_subset Set.image_subset
/-- `Set.image` is monotone. See `Set.image_subset` for the statement in terms of `⊆`. -/
lemma monotone_image {f : α → β} : Monotone (image f) := fun _ _ => image_subset _
#align set.monotone_image Set.monotone_image
theorem image_union (f : α → β) (s t : Set α) : f '' (s ∪ t) = f '' s ∪ f '' t :=
ext fun x =>
⟨by rintro ⟨a, h | h, rfl⟩ <;> [left; right] <;> exact ⟨_, h, rfl⟩, by
rintro (⟨a, h, rfl⟩ | ⟨a, h, rfl⟩) <;> refine' ⟨_, _, rfl⟩ <;> [left; right] <;> exact h⟩
#align set.image_union Set.image_union
@[simp]
theorem image_empty (f : α → β) : f '' ∅ = ∅ := by
ext
simp
#align set.image_empty Set.image_empty
theorem image_inter_subset (f : α → β) (s t : Set α) : f '' (s ∩ t) ⊆ f '' s ∩ f '' t :=
subset_inter (image_subset _ <| inter_subset_left _ _) (image_subset _ <| inter_subset_right _ _)
#align set.image_inter_subset Set.image_inter_subset
theorem image_inter_on {f : α → β} {s t : Set α} (h : ∀ x ∈ t, ∀ y ∈ s, f x = f y → x = y) :
f '' (s ∩ t) = f '' s ∩ f '' t :=
(image_inter_subset _ _ _).antisymm
fun b ⟨⟨a₁, ha₁, h₁⟩, ⟨a₂, ha₂, h₂⟩⟩ ↦
have : a₂ = a₁ := h _ ha₂ _ ha₁ (by simp [*])
⟨a₁, ⟨ha₁, this ▸ ha₂⟩, h₁⟩
#align set.image_inter_on Set.image_inter_on
theorem image_inter {f : α → β} {s t : Set α} (H : Injective f) : f '' (s ∩ t) = f '' s ∩ f '' t :=
image_inter_on fun _ _ _ _ h => H h
#align set.image_inter Set.image_inter
theorem image_univ_of_surjective {ι : Type*} {f : ι → β} (H : Surjective f) : f '' univ = univ :=
eq_univ_of_forall <| by simpa [image]
#align set.image_univ_of_surjective Set.image_univ_of_surjective
@[simp]
theorem image_singleton {f : α → β} {a : α} : f '' {a} = {f a} := by
ext
|
simp [image, eq_comm]
|
@[simp]
theorem image_singleton {f : α → β} {a : α} : f '' {a} = {f a} := by
ext
|
Mathlib.Data.Set.Image.368_0.IJFiTzmYGOCpPSd
|
@[simp]
theorem image_singleton {f : α → β} {a : α} : f '' {a} = {f a}
|
Mathlib_Data_Set_Image
|
α✝ : Type u_1
β✝ : Type u_2
γ : Type u_3
ι : Sort u_4
ι' : Sort u_5
f✝ : α✝ → β✝
s✝ t : Set α✝
α : Type u_6
β : Type u_7
f : α → β
s : Set α
⊢ f '' s = ∅ ↔ s = ∅
|
/-
Copyright (c) 2014 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Leonardo de Moura
-/
import Mathlib.Data.Set.Basic
#align_import data.set.image from "leanprover-community/mathlib"@"001ffdc42920050657fd45bd2b8bfbec8eaaeb29"
/-!
# Images and preimages of sets
## Main definitions
* `preimage f t : Set α` : the preimage f⁻¹(t) (written `f ⁻¹' t` in Lean) of a subset of β.
* `range f : Set β` : the image of `univ` under `f`.
Also works for `{p : Prop} (f : p → α)` (unlike `image`)
## Notation
* `f ⁻¹' t` for `Set.preimage f t`
* `f '' s` for `Set.image f s`
## Tags
set, sets, image, preimage, pre-image, range
-/
set_option autoImplicit true
universe u v
open Function Set
namespace Set
variable {α β γ : Type*} {ι ι' : Sort*}
/-! ### Inverse image -/
/-- The preimage of `s : Set β` by `f : α → β`, written `f ⁻¹' s`,
is the set of `x : α` such that `f x ∈ s`. -/
def preimage {α : Type u} {β : Type v} (f : α → β) (s : Set β) : Set α :=
{ x | f x ∈ s }
#align set.preimage Set.preimage
/-- `f ⁻¹' t` denotes the preimage of `t : Set β` under the function `f : α → β`. -/
infixl:80 " ⁻¹' " => preimage
section Preimage
variable {f : α → β} {g : β → γ}
@[simp]
theorem preimage_empty : f ⁻¹' ∅ = ∅ :=
rfl
#align set.preimage_empty Set.preimage_empty
@[simp, mfld_simps]
theorem mem_preimage {s : Set β} {a : α} : a ∈ f ⁻¹' s ↔ f a ∈ s :=
Iff.rfl
#align set.mem_preimage Set.mem_preimage
theorem preimage_congr {f g : α → β} {s : Set β} (h : ∀ x : α, f x = g x) : f ⁻¹' s = g ⁻¹' s := by
congr with x
simp [h]
#align set.preimage_congr Set.preimage_congr
@[gcongr]
theorem preimage_mono {s t : Set β} (h : s ⊆ t) : f ⁻¹' s ⊆ f ⁻¹' t := fun _ hx => h hx
#align set.preimage_mono Set.preimage_mono
@[simp, mfld_simps]
theorem preimage_univ : f ⁻¹' univ = univ :=
rfl
#align set.preimage_univ Set.preimage_univ
theorem subset_preimage_univ {s : Set α} : s ⊆ f ⁻¹' univ :=
subset_univ _
#align set.subset_preimage_univ Set.subset_preimage_univ
@[simp, mfld_simps]
theorem preimage_inter {s t : Set β} : f ⁻¹' (s ∩ t) = f ⁻¹' s ∩ f ⁻¹' t :=
rfl
#align set.preimage_inter Set.preimage_inter
@[simp]
theorem preimage_union {s t : Set β} : f ⁻¹' (s ∪ t) = f ⁻¹' s ∪ f ⁻¹' t :=
rfl
#align set.preimage_union Set.preimage_union
@[simp]
theorem preimage_compl {s : Set β} : f ⁻¹' sᶜ = (f ⁻¹' s)ᶜ :=
rfl
#align set.preimage_compl Set.preimage_compl
@[simp]
theorem preimage_diff (f : α → β) (s t : Set β) : f ⁻¹' (s \ t) = f ⁻¹' s \ f ⁻¹' t :=
rfl
#align set.preimage_diff Set.preimage_diff
@[simp]
lemma preimage_symmDiff {f : α → β} (s t : Set β) : f ⁻¹' (s ∆ t) = (f ⁻¹' s) ∆ (f ⁻¹' t) :=
rfl
#align set.preimage_symm_diff Set.preimage_symmDiff
@[simp]
theorem preimage_ite (f : α → β) (s t₁ t₂ : Set β) :
f ⁻¹' s.ite t₁ t₂ = (f ⁻¹' s).ite (f ⁻¹' t₁) (f ⁻¹' t₂) :=
rfl
#align set.preimage_ite Set.preimage_ite
@[simp]
theorem preimage_setOf_eq {p : α → Prop} {f : β → α} : f ⁻¹' { a | p a } = { a | p (f a) } :=
rfl
#align set.preimage_set_of_eq Set.preimage_setOf_eq
@[simp]
theorem preimage_id_eq : preimage (id : α → α) = id :=
rfl
#align set.preimage_id_eq Set.preimage_id_eq
@[mfld_simps]
theorem preimage_id {s : Set α} : id ⁻¹' s = s :=
rfl
#align set.preimage_id Set.preimage_id
@[simp, mfld_simps]
theorem preimage_id' {s : Set α} : (fun x => x) ⁻¹' s = s :=
rfl
#align set.preimage_id' Set.preimage_id'
@[simp]
theorem preimage_const_of_mem {b : β} {s : Set β} (h : b ∈ s) : (fun _ : α => b) ⁻¹' s = univ :=
eq_univ_of_forall fun _ => h
#align set.preimage_const_of_mem Set.preimage_const_of_mem
@[simp]
theorem preimage_const_of_not_mem {b : β} {s : Set β} (h : b ∉ s) : (fun _ : α => b) ⁻¹' s = ∅ :=
eq_empty_of_subset_empty fun _ hx => h hx
#align set.preimage_const_of_not_mem Set.preimage_const_of_not_mem
theorem preimage_const (b : β) (s : Set β) [Decidable (b ∈ s)] :
(fun _ : α => b) ⁻¹' s = if b ∈ s then univ else ∅ := by
split_ifs with hb
exacts [preimage_const_of_mem hb, preimage_const_of_not_mem hb]
#align set.preimage_const Set.preimage_const
/-- If preimage of each singleton under `f : α → β` is either empty or the whole type,
then `f` is a constant. -/
lemma exists_eq_const_of_preimage_singleton [Nonempty β] {f : α → β}
(hf : ∀ b : β, f ⁻¹' {b} = ∅ ∨ f ⁻¹' {b} = univ) : ∃ b, f = const α b := by
rcases em (∃ b, f ⁻¹' {b} = univ) with ⟨b, hb⟩ | hf'
· exact ⟨b, funext fun x ↦ eq_univ_iff_forall.1 hb x⟩
· have : ∀ x b, f x ≠ b := fun x b ↦
eq_empty_iff_forall_not_mem.1 ((hf b).resolve_right fun h ↦ hf' ⟨b, h⟩) x
exact ⟨Classical.arbitrary β, funext fun x ↦ absurd rfl (this x _)⟩
theorem preimage_comp {s : Set γ} : g ∘ f ⁻¹' s = f ⁻¹' (g ⁻¹' s) :=
rfl
#align set.preimage_comp Set.preimage_comp
theorem preimage_comp_eq : preimage (g ∘ f) = preimage f ∘ preimage g :=
rfl
#align set.preimage_comp_eq Set.preimage_comp_eq
theorem preimage_iterate_eq {f : α → α} {n : ℕ} : Set.preimage f^[n] = (Set.preimage f)^[n] := by
induction' n with n ih; · simp
rw [iterate_succ, iterate_succ', preimage_comp_eq, ih]
#align set.preimage_iterate_eq Set.preimage_iterate_eq
theorem preimage_preimage {g : β → γ} {f : α → β} {s : Set γ} :
f ⁻¹' (g ⁻¹' s) = (fun x => g (f x)) ⁻¹' s :=
preimage_comp.symm
#align set.preimage_preimage Set.preimage_preimage
theorem eq_preimage_subtype_val_iff {p : α → Prop} {s : Set (Subtype p)} {t : Set α} :
s = Subtype.val ⁻¹' t ↔ ∀ (x) (h : p x), (⟨x, h⟩ : Subtype p) ∈ s ↔ x ∈ t :=
⟨fun s_eq x h => by
rw [s_eq]
simp, fun h => ext fun ⟨x, hx⟩ => by simp [h]⟩
#align set.eq_preimage_subtype_val_iff Set.eq_preimage_subtype_val_iff
theorem nonempty_of_nonempty_preimage {s : Set β} {f : α → β} (hf : (f ⁻¹' s).Nonempty) :
s.Nonempty :=
let ⟨x, hx⟩ := hf
⟨f x, hx⟩
#align set.nonempty_of_nonempty_preimage Set.nonempty_of_nonempty_preimage
@[simp] theorem preimage_singleton_true (p : α → Prop) : p ⁻¹' {True} = {a | p a} := by ext; simp
#align set.preimage_singleton_true Set.preimage_singleton_true
@[simp] theorem preimage_singleton_false (p : α → Prop) : p ⁻¹' {False} = {a | ¬p a} := by ext; simp
#align set.preimage_singleton_false Set.preimage_singleton_false
theorem preimage_subtype_coe_eq_compl {s u v : Set α} (hsuv : s ⊆ u ∪ v)
(H : s ∩ (u ∩ v) = ∅) : ((↑) : s → α) ⁻¹' u = ((↑) ⁻¹' v)ᶜ := by
ext ⟨x, x_in_s⟩
constructor
· intro x_in_u x_in_v
exact eq_empty_iff_forall_not_mem.mp H x ⟨x_in_s, ⟨x_in_u, x_in_v⟩⟩
· intro hx
exact Or.elim (hsuv x_in_s) id fun hx' => hx.elim hx'
#align set.preimage_subtype_coe_eq_compl Set.preimage_subtype_coe_eq_compl
end Preimage
/-! ### Image of a set under a function -/
section Image
variable {f : α → β} {s t : Set α}
-- Porting note: `Set.image` is already defined in `Init.Set`
#align set.image Set.image
/-- `f '' s` denotes the image of `s : Set α` under the function `f : α → β`. -/
infixl:80 " '' " => image
theorem mem_image_iff_bex {f : α → β} {s : Set α} {y : β} :
y ∈ f '' s ↔ ∃ (x : _) (_ : x ∈ s), f x = y :=
bex_def.symm
#align set.mem_image_iff_bex Set.mem_image_iff_bex
@[simp]
theorem mem_image (f : α → β) (s : Set α) (y : β) : y ∈ f '' s ↔ ∃ x ∈ s, f x = y :=
Iff.rfl
#align set.mem_image Set.mem_image
theorem image_eta (f : α → β) : f '' s = (fun x => f x) '' s :=
rfl
#align set.image_eta Set.image_eta
@[mfld_simps]
theorem mem_image_of_mem (f : α → β) {x : α} {a : Set α} (h : x ∈ a) : f x ∈ f '' a :=
⟨_, h, rfl⟩
#align set.mem_image_of_mem Set.mem_image_of_mem
theorem _root_.Function.Injective.mem_set_image {f : α → β} (hf : Injective f) {s : Set α} {a : α} :
f a ∈ f '' s ↔ a ∈ s :=
⟨fun ⟨_, hb, Eq⟩ => hf Eq ▸ hb, mem_image_of_mem f⟩
#align function.injective.mem_set_image Function.Injective.mem_set_image
theorem ball_image_iff {f : α → β} {s : Set α} {p : β → Prop} :
(∀ y ∈ f '' s, p y) ↔ ∀ x ∈ s, p (f x) := by simp
#align set.ball_image_iff Set.ball_image_iff
theorem ball_image_of_ball {f : α → β} {s : Set α} {p : β → Prop} (h : ∀ x ∈ s, p (f x)) :
∀ y ∈ f '' s, p y :=
ball_image_iff.2 h
#align set.ball_image_of_ball Set.ball_image_of_ball
theorem bex_image_iff {f : α → β} {s : Set α} {p : β → Prop} :
(∃ y ∈ f '' s, p y) ↔ ∃ x ∈ s, p (f x) := by simp
#align set.bex_image_iff Set.bex_image_iff
theorem mem_image_elim {f : α → β} {s : Set α} {C : β → Prop} (h : ∀ x : α, x ∈ s → C (f x)) :
∀ {y : β}, y ∈ f '' s → C y
| _, ⟨a, a_in, rfl⟩ => h a a_in
#align set.mem_image_elim Set.mem_image_elim
theorem mem_image_elim_on {f : α → β} {s : Set α} {C : β → Prop} {y : β} (h_y : y ∈ f '' s)
(h : ∀ x : α, x ∈ s → C (f x)) : C y :=
mem_image_elim h h_y
#align set.mem_image_elim_on Set.mem_image_elim_on
-- Porting note: used to be `safe`
@[congr]
theorem image_congr {f g : α → β} {s : Set α} (h : ∀ a ∈ s, f a = g a) : f '' s = g '' s := by
ext x
rw [mem_image, mem_image]
exact {
mp := by
rintro ⟨a, ha1, ha2⟩
exact ⟨a, ⟨ha1, (h a ha1) ▸ ha2⟩⟩,
mpr := by
rintro ⟨a, ha1, ha2⟩
exact ⟨a, ⟨ha1, (h a ha1) ▸ ha2⟩⟩
}
-- safe [ext_iff, iff_def]
#align set.image_congr Set.image_congr
/-- A common special case of `image_congr` -/
theorem image_congr' {f g : α → β} {s : Set α} (h : ∀ x : α, f x = g x) : f '' s = g '' s :=
image_congr fun x _ => h x
#align set.image_congr' Set.image_congr'
@[gcongr]
lemma image_mono (h : s ⊆ t) : f '' s ⊆ f '' t := by
rintro - ⟨a, ha, rfl⟩; exact mem_image_of_mem f (h ha)
theorem image_comp (f : β → γ) (g : α → β) (a : Set α) : f ∘ g '' a = f '' (g '' a) :=
Subset.antisymm (ball_image_of_ball fun _ ha => mem_image_of_mem _ <| mem_image_of_mem _ ha)
(ball_image_of_ball <| ball_image_of_ball fun _ ha => mem_image_of_mem _ ha)
#align set.image_comp Set.image_comp
theorem image_comp_eq {g : β → γ} : image (g ∘ f) = image g ∘ image f := by ext; simp
/-- A variant of `image_comp`, useful for rewriting -/
theorem image_image (g : β → γ) (f : α → β) (s : Set α) : g '' (f '' s) = (fun x => g (f x)) '' s :=
(image_comp g f s).symm
#align set.image_image Set.image_image
theorem image_comm {β'} {f : β → γ} {g : α → β} {f' : α → β'} {g' : β' → γ}
(h_comm : ∀ a, f (g a) = g' (f' a)) : (s.image g).image f = (s.image f').image g' := by
simp_rw [image_image, h_comm]
#align set.image_comm Set.image_comm
theorem _root_.Function.Semiconj.set_image {f : α → β} {ga : α → α} {gb : β → β}
(h : Function.Semiconj f ga gb) : Function.Semiconj (image f) (image ga) (image gb) := fun _ =>
image_comm h
#align function.semiconj.set_image Function.Semiconj.set_image
theorem _root_.Function.Commute.set_image {f g : α → α} (h : Function.Commute f g) :
Function.Commute (image f) (image g) :=
Function.Semiconj.set_image h
#align function.commute.set_image Function.Commute.set_image
/-- Image is monotone with respect to `⊆`. See `Set.monotone_image` for the statement in
terms of `≤`. -/
@[gcongr]
theorem image_subset {a b : Set α} (f : α → β) (h : a ⊆ b) : f '' a ⊆ f '' b := by
simp only [subset_def, mem_image]
exact fun x => fun ⟨w, h1, h2⟩ => ⟨w, h h1, h2⟩
#align set.image_subset Set.image_subset
/-- `Set.image` is monotone. See `Set.image_subset` for the statement in terms of `⊆`. -/
lemma monotone_image {f : α → β} : Monotone (image f) := fun _ _ => image_subset _
#align set.monotone_image Set.monotone_image
theorem image_union (f : α → β) (s t : Set α) : f '' (s ∪ t) = f '' s ∪ f '' t :=
ext fun x =>
⟨by rintro ⟨a, h | h, rfl⟩ <;> [left; right] <;> exact ⟨_, h, rfl⟩, by
rintro (⟨a, h, rfl⟩ | ⟨a, h, rfl⟩) <;> refine' ⟨_, _, rfl⟩ <;> [left; right] <;> exact h⟩
#align set.image_union Set.image_union
@[simp]
theorem image_empty (f : α → β) : f '' ∅ = ∅ := by
ext
simp
#align set.image_empty Set.image_empty
theorem image_inter_subset (f : α → β) (s t : Set α) : f '' (s ∩ t) ⊆ f '' s ∩ f '' t :=
subset_inter (image_subset _ <| inter_subset_left _ _) (image_subset _ <| inter_subset_right _ _)
#align set.image_inter_subset Set.image_inter_subset
theorem image_inter_on {f : α → β} {s t : Set α} (h : ∀ x ∈ t, ∀ y ∈ s, f x = f y → x = y) :
f '' (s ∩ t) = f '' s ∩ f '' t :=
(image_inter_subset _ _ _).antisymm
fun b ⟨⟨a₁, ha₁, h₁⟩, ⟨a₂, ha₂, h₂⟩⟩ ↦
have : a₂ = a₁ := h _ ha₂ _ ha₁ (by simp [*])
⟨a₁, ⟨ha₁, this ▸ ha₂⟩, h₁⟩
#align set.image_inter_on Set.image_inter_on
theorem image_inter {f : α → β} {s t : Set α} (H : Injective f) : f '' (s ∩ t) = f '' s ∩ f '' t :=
image_inter_on fun _ _ _ _ h => H h
#align set.image_inter Set.image_inter
theorem image_univ_of_surjective {ι : Type*} {f : ι → β} (H : Surjective f) : f '' univ = univ :=
eq_univ_of_forall <| by simpa [image]
#align set.image_univ_of_surjective Set.image_univ_of_surjective
@[simp]
theorem image_singleton {f : α → β} {a : α} : f '' {a} = {f a} := by
ext
simp [image, eq_comm]
#align set.image_singleton Set.image_singleton
@[simp]
theorem Nonempty.image_const {s : Set α} (hs : s.Nonempty) (a : β) : (fun _ => a) '' s = {a} :=
ext fun _ =>
⟨fun ⟨_, _, h⟩ => h ▸ mem_singleton _, fun h =>
(eq_of_mem_singleton h).symm ▸ hs.imp fun _ hy => ⟨hy, rfl⟩⟩
#align set.nonempty.image_const Set.Nonempty.image_const
@[simp, mfld_simps]
theorem image_eq_empty {α β} {f : α → β} {s : Set α} : f '' s = ∅ ↔ s = ∅ := by
|
simp only [eq_empty_iff_forall_not_mem]
|
@[simp, mfld_simps]
theorem image_eq_empty {α β} {f : α → β} {s : Set α} : f '' s = ∅ ↔ s = ∅ := by
|
Mathlib.Data.Set.Image.381_0.IJFiTzmYGOCpPSd
|
@[simp, mfld_simps]
theorem image_eq_empty {α β} {f : α → β} {s : Set α} : f '' s = ∅ ↔ s = ∅
|
Mathlib_Data_Set_Image
|
α✝ : Type u_1
β✝ : Type u_2
γ : Type u_3
ι : Sort u_4
ι' : Sort u_5
f✝ : α✝ → β✝
s✝ t : Set α✝
α : Type u_6
β : Type u_7
f : α → β
s : Set α
⊢ (∀ (x : β), x ∉ f '' s) ↔ ∀ (x : α), x ∉ s
|
/-
Copyright (c) 2014 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Leonardo de Moura
-/
import Mathlib.Data.Set.Basic
#align_import data.set.image from "leanprover-community/mathlib"@"001ffdc42920050657fd45bd2b8bfbec8eaaeb29"
/-!
# Images and preimages of sets
## Main definitions
* `preimage f t : Set α` : the preimage f⁻¹(t) (written `f ⁻¹' t` in Lean) of a subset of β.
* `range f : Set β` : the image of `univ` under `f`.
Also works for `{p : Prop} (f : p → α)` (unlike `image`)
## Notation
* `f ⁻¹' t` for `Set.preimage f t`
* `f '' s` for `Set.image f s`
## Tags
set, sets, image, preimage, pre-image, range
-/
set_option autoImplicit true
universe u v
open Function Set
namespace Set
variable {α β γ : Type*} {ι ι' : Sort*}
/-! ### Inverse image -/
/-- The preimage of `s : Set β` by `f : α → β`, written `f ⁻¹' s`,
is the set of `x : α` such that `f x ∈ s`. -/
def preimage {α : Type u} {β : Type v} (f : α → β) (s : Set β) : Set α :=
{ x | f x ∈ s }
#align set.preimage Set.preimage
/-- `f ⁻¹' t` denotes the preimage of `t : Set β` under the function `f : α → β`. -/
infixl:80 " ⁻¹' " => preimage
section Preimage
variable {f : α → β} {g : β → γ}
@[simp]
theorem preimage_empty : f ⁻¹' ∅ = ∅ :=
rfl
#align set.preimage_empty Set.preimage_empty
@[simp, mfld_simps]
theorem mem_preimage {s : Set β} {a : α} : a ∈ f ⁻¹' s ↔ f a ∈ s :=
Iff.rfl
#align set.mem_preimage Set.mem_preimage
theorem preimage_congr {f g : α → β} {s : Set β} (h : ∀ x : α, f x = g x) : f ⁻¹' s = g ⁻¹' s := by
congr with x
simp [h]
#align set.preimage_congr Set.preimage_congr
@[gcongr]
theorem preimage_mono {s t : Set β} (h : s ⊆ t) : f ⁻¹' s ⊆ f ⁻¹' t := fun _ hx => h hx
#align set.preimage_mono Set.preimage_mono
@[simp, mfld_simps]
theorem preimage_univ : f ⁻¹' univ = univ :=
rfl
#align set.preimage_univ Set.preimage_univ
theorem subset_preimage_univ {s : Set α} : s ⊆ f ⁻¹' univ :=
subset_univ _
#align set.subset_preimage_univ Set.subset_preimage_univ
@[simp, mfld_simps]
theorem preimage_inter {s t : Set β} : f ⁻¹' (s ∩ t) = f ⁻¹' s ∩ f ⁻¹' t :=
rfl
#align set.preimage_inter Set.preimage_inter
@[simp]
theorem preimage_union {s t : Set β} : f ⁻¹' (s ∪ t) = f ⁻¹' s ∪ f ⁻¹' t :=
rfl
#align set.preimage_union Set.preimage_union
@[simp]
theorem preimage_compl {s : Set β} : f ⁻¹' sᶜ = (f ⁻¹' s)ᶜ :=
rfl
#align set.preimage_compl Set.preimage_compl
@[simp]
theorem preimage_diff (f : α → β) (s t : Set β) : f ⁻¹' (s \ t) = f ⁻¹' s \ f ⁻¹' t :=
rfl
#align set.preimage_diff Set.preimage_diff
@[simp]
lemma preimage_symmDiff {f : α → β} (s t : Set β) : f ⁻¹' (s ∆ t) = (f ⁻¹' s) ∆ (f ⁻¹' t) :=
rfl
#align set.preimage_symm_diff Set.preimage_symmDiff
@[simp]
theorem preimage_ite (f : α → β) (s t₁ t₂ : Set β) :
f ⁻¹' s.ite t₁ t₂ = (f ⁻¹' s).ite (f ⁻¹' t₁) (f ⁻¹' t₂) :=
rfl
#align set.preimage_ite Set.preimage_ite
@[simp]
theorem preimage_setOf_eq {p : α → Prop} {f : β → α} : f ⁻¹' { a | p a } = { a | p (f a) } :=
rfl
#align set.preimage_set_of_eq Set.preimage_setOf_eq
@[simp]
theorem preimage_id_eq : preimage (id : α → α) = id :=
rfl
#align set.preimage_id_eq Set.preimage_id_eq
@[mfld_simps]
theorem preimage_id {s : Set α} : id ⁻¹' s = s :=
rfl
#align set.preimage_id Set.preimage_id
@[simp, mfld_simps]
theorem preimage_id' {s : Set α} : (fun x => x) ⁻¹' s = s :=
rfl
#align set.preimage_id' Set.preimage_id'
@[simp]
theorem preimage_const_of_mem {b : β} {s : Set β} (h : b ∈ s) : (fun _ : α => b) ⁻¹' s = univ :=
eq_univ_of_forall fun _ => h
#align set.preimage_const_of_mem Set.preimage_const_of_mem
@[simp]
theorem preimage_const_of_not_mem {b : β} {s : Set β} (h : b ∉ s) : (fun _ : α => b) ⁻¹' s = ∅ :=
eq_empty_of_subset_empty fun _ hx => h hx
#align set.preimage_const_of_not_mem Set.preimage_const_of_not_mem
theorem preimage_const (b : β) (s : Set β) [Decidable (b ∈ s)] :
(fun _ : α => b) ⁻¹' s = if b ∈ s then univ else ∅ := by
split_ifs with hb
exacts [preimage_const_of_mem hb, preimage_const_of_not_mem hb]
#align set.preimage_const Set.preimage_const
/-- If preimage of each singleton under `f : α → β` is either empty or the whole type,
then `f` is a constant. -/
lemma exists_eq_const_of_preimage_singleton [Nonempty β] {f : α → β}
(hf : ∀ b : β, f ⁻¹' {b} = ∅ ∨ f ⁻¹' {b} = univ) : ∃ b, f = const α b := by
rcases em (∃ b, f ⁻¹' {b} = univ) with ⟨b, hb⟩ | hf'
· exact ⟨b, funext fun x ↦ eq_univ_iff_forall.1 hb x⟩
· have : ∀ x b, f x ≠ b := fun x b ↦
eq_empty_iff_forall_not_mem.1 ((hf b).resolve_right fun h ↦ hf' ⟨b, h⟩) x
exact ⟨Classical.arbitrary β, funext fun x ↦ absurd rfl (this x _)⟩
theorem preimage_comp {s : Set γ} : g ∘ f ⁻¹' s = f ⁻¹' (g ⁻¹' s) :=
rfl
#align set.preimage_comp Set.preimage_comp
theorem preimage_comp_eq : preimage (g ∘ f) = preimage f ∘ preimage g :=
rfl
#align set.preimage_comp_eq Set.preimage_comp_eq
theorem preimage_iterate_eq {f : α → α} {n : ℕ} : Set.preimage f^[n] = (Set.preimage f)^[n] := by
induction' n with n ih; · simp
rw [iterate_succ, iterate_succ', preimage_comp_eq, ih]
#align set.preimage_iterate_eq Set.preimage_iterate_eq
theorem preimage_preimage {g : β → γ} {f : α → β} {s : Set γ} :
f ⁻¹' (g ⁻¹' s) = (fun x => g (f x)) ⁻¹' s :=
preimage_comp.symm
#align set.preimage_preimage Set.preimage_preimage
theorem eq_preimage_subtype_val_iff {p : α → Prop} {s : Set (Subtype p)} {t : Set α} :
s = Subtype.val ⁻¹' t ↔ ∀ (x) (h : p x), (⟨x, h⟩ : Subtype p) ∈ s ↔ x ∈ t :=
⟨fun s_eq x h => by
rw [s_eq]
simp, fun h => ext fun ⟨x, hx⟩ => by simp [h]⟩
#align set.eq_preimage_subtype_val_iff Set.eq_preimage_subtype_val_iff
theorem nonempty_of_nonempty_preimage {s : Set β} {f : α → β} (hf : (f ⁻¹' s).Nonempty) :
s.Nonempty :=
let ⟨x, hx⟩ := hf
⟨f x, hx⟩
#align set.nonempty_of_nonempty_preimage Set.nonempty_of_nonempty_preimage
@[simp] theorem preimage_singleton_true (p : α → Prop) : p ⁻¹' {True} = {a | p a} := by ext; simp
#align set.preimage_singleton_true Set.preimage_singleton_true
@[simp] theorem preimage_singleton_false (p : α → Prop) : p ⁻¹' {False} = {a | ¬p a} := by ext; simp
#align set.preimage_singleton_false Set.preimage_singleton_false
theorem preimage_subtype_coe_eq_compl {s u v : Set α} (hsuv : s ⊆ u ∪ v)
(H : s ∩ (u ∩ v) = ∅) : ((↑) : s → α) ⁻¹' u = ((↑) ⁻¹' v)ᶜ := by
ext ⟨x, x_in_s⟩
constructor
· intro x_in_u x_in_v
exact eq_empty_iff_forall_not_mem.mp H x ⟨x_in_s, ⟨x_in_u, x_in_v⟩⟩
· intro hx
exact Or.elim (hsuv x_in_s) id fun hx' => hx.elim hx'
#align set.preimage_subtype_coe_eq_compl Set.preimage_subtype_coe_eq_compl
end Preimage
/-! ### Image of a set under a function -/
section Image
variable {f : α → β} {s t : Set α}
-- Porting note: `Set.image` is already defined in `Init.Set`
#align set.image Set.image
/-- `f '' s` denotes the image of `s : Set α` under the function `f : α → β`. -/
infixl:80 " '' " => image
theorem mem_image_iff_bex {f : α → β} {s : Set α} {y : β} :
y ∈ f '' s ↔ ∃ (x : _) (_ : x ∈ s), f x = y :=
bex_def.symm
#align set.mem_image_iff_bex Set.mem_image_iff_bex
@[simp]
theorem mem_image (f : α → β) (s : Set α) (y : β) : y ∈ f '' s ↔ ∃ x ∈ s, f x = y :=
Iff.rfl
#align set.mem_image Set.mem_image
theorem image_eta (f : α → β) : f '' s = (fun x => f x) '' s :=
rfl
#align set.image_eta Set.image_eta
@[mfld_simps]
theorem mem_image_of_mem (f : α → β) {x : α} {a : Set α} (h : x ∈ a) : f x ∈ f '' a :=
⟨_, h, rfl⟩
#align set.mem_image_of_mem Set.mem_image_of_mem
theorem _root_.Function.Injective.mem_set_image {f : α → β} (hf : Injective f) {s : Set α} {a : α} :
f a ∈ f '' s ↔ a ∈ s :=
⟨fun ⟨_, hb, Eq⟩ => hf Eq ▸ hb, mem_image_of_mem f⟩
#align function.injective.mem_set_image Function.Injective.mem_set_image
theorem ball_image_iff {f : α → β} {s : Set α} {p : β → Prop} :
(∀ y ∈ f '' s, p y) ↔ ∀ x ∈ s, p (f x) := by simp
#align set.ball_image_iff Set.ball_image_iff
theorem ball_image_of_ball {f : α → β} {s : Set α} {p : β → Prop} (h : ∀ x ∈ s, p (f x)) :
∀ y ∈ f '' s, p y :=
ball_image_iff.2 h
#align set.ball_image_of_ball Set.ball_image_of_ball
theorem bex_image_iff {f : α → β} {s : Set α} {p : β → Prop} :
(∃ y ∈ f '' s, p y) ↔ ∃ x ∈ s, p (f x) := by simp
#align set.bex_image_iff Set.bex_image_iff
theorem mem_image_elim {f : α → β} {s : Set α} {C : β → Prop} (h : ∀ x : α, x ∈ s → C (f x)) :
∀ {y : β}, y ∈ f '' s → C y
| _, ⟨a, a_in, rfl⟩ => h a a_in
#align set.mem_image_elim Set.mem_image_elim
theorem mem_image_elim_on {f : α → β} {s : Set α} {C : β → Prop} {y : β} (h_y : y ∈ f '' s)
(h : ∀ x : α, x ∈ s → C (f x)) : C y :=
mem_image_elim h h_y
#align set.mem_image_elim_on Set.mem_image_elim_on
-- Porting note: used to be `safe`
@[congr]
theorem image_congr {f g : α → β} {s : Set α} (h : ∀ a ∈ s, f a = g a) : f '' s = g '' s := by
ext x
rw [mem_image, mem_image]
exact {
mp := by
rintro ⟨a, ha1, ha2⟩
exact ⟨a, ⟨ha1, (h a ha1) ▸ ha2⟩⟩,
mpr := by
rintro ⟨a, ha1, ha2⟩
exact ⟨a, ⟨ha1, (h a ha1) ▸ ha2⟩⟩
}
-- safe [ext_iff, iff_def]
#align set.image_congr Set.image_congr
/-- A common special case of `image_congr` -/
theorem image_congr' {f g : α → β} {s : Set α} (h : ∀ x : α, f x = g x) : f '' s = g '' s :=
image_congr fun x _ => h x
#align set.image_congr' Set.image_congr'
@[gcongr]
lemma image_mono (h : s ⊆ t) : f '' s ⊆ f '' t := by
rintro - ⟨a, ha, rfl⟩; exact mem_image_of_mem f (h ha)
theorem image_comp (f : β → γ) (g : α → β) (a : Set α) : f ∘ g '' a = f '' (g '' a) :=
Subset.antisymm (ball_image_of_ball fun _ ha => mem_image_of_mem _ <| mem_image_of_mem _ ha)
(ball_image_of_ball <| ball_image_of_ball fun _ ha => mem_image_of_mem _ ha)
#align set.image_comp Set.image_comp
theorem image_comp_eq {g : β → γ} : image (g ∘ f) = image g ∘ image f := by ext; simp
/-- A variant of `image_comp`, useful for rewriting -/
theorem image_image (g : β → γ) (f : α → β) (s : Set α) : g '' (f '' s) = (fun x => g (f x)) '' s :=
(image_comp g f s).symm
#align set.image_image Set.image_image
theorem image_comm {β'} {f : β → γ} {g : α → β} {f' : α → β'} {g' : β' → γ}
(h_comm : ∀ a, f (g a) = g' (f' a)) : (s.image g).image f = (s.image f').image g' := by
simp_rw [image_image, h_comm]
#align set.image_comm Set.image_comm
theorem _root_.Function.Semiconj.set_image {f : α → β} {ga : α → α} {gb : β → β}
(h : Function.Semiconj f ga gb) : Function.Semiconj (image f) (image ga) (image gb) := fun _ =>
image_comm h
#align function.semiconj.set_image Function.Semiconj.set_image
theorem _root_.Function.Commute.set_image {f g : α → α} (h : Function.Commute f g) :
Function.Commute (image f) (image g) :=
Function.Semiconj.set_image h
#align function.commute.set_image Function.Commute.set_image
/-- Image is monotone with respect to `⊆`. See `Set.monotone_image` for the statement in
terms of `≤`. -/
@[gcongr]
theorem image_subset {a b : Set α} (f : α → β) (h : a ⊆ b) : f '' a ⊆ f '' b := by
simp only [subset_def, mem_image]
exact fun x => fun ⟨w, h1, h2⟩ => ⟨w, h h1, h2⟩
#align set.image_subset Set.image_subset
/-- `Set.image` is monotone. See `Set.image_subset` for the statement in terms of `⊆`. -/
lemma monotone_image {f : α → β} : Monotone (image f) := fun _ _ => image_subset _
#align set.monotone_image Set.monotone_image
theorem image_union (f : α → β) (s t : Set α) : f '' (s ∪ t) = f '' s ∪ f '' t :=
ext fun x =>
⟨by rintro ⟨a, h | h, rfl⟩ <;> [left; right] <;> exact ⟨_, h, rfl⟩, by
rintro (⟨a, h, rfl⟩ | ⟨a, h, rfl⟩) <;> refine' ⟨_, _, rfl⟩ <;> [left; right] <;> exact h⟩
#align set.image_union Set.image_union
@[simp]
theorem image_empty (f : α → β) : f '' ∅ = ∅ := by
ext
simp
#align set.image_empty Set.image_empty
theorem image_inter_subset (f : α → β) (s t : Set α) : f '' (s ∩ t) ⊆ f '' s ∩ f '' t :=
subset_inter (image_subset _ <| inter_subset_left _ _) (image_subset _ <| inter_subset_right _ _)
#align set.image_inter_subset Set.image_inter_subset
theorem image_inter_on {f : α → β} {s t : Set α} (h : ∀ x ∈ t, ∀ y ∈ s, f x = f y → x = y) :
f '' (s ∩ t) = f '' s ∩ f '' t :=
(image_inter_subset _ _ _).antisymm
fun b ⟨⟨a₁, ha₁, h₁⟩, ⟨a₂, ha₂, h₂⟩⟩ ↦
have : a₂ = a₁ := h _ ha₂ _ ha₁ (by simp [*])
⟨a₁, ⟨ha₁, this ▸ ha₂⟩, h₁⟩
#align set.image_inter_on Set.image_inter_on
theorem image_inter {f : α → β} {s t : Set α} (H : Injective f) : f '' (s ∩ t) = f '' s ∩ f '' t :=
image_inter_on fun _ _ _ _ h => H h
#align set.image_inter Set.image_inter
theorem image_univ_of_surjective {ι : Type*} {f : ι → β} (H : Surjective f) : f '' univ = univ :=
eq_univ_of_forall <| by simpa [image]
#align set.image_univ_of_surjective Set.image_univ_of_surjective
@[simp]
theorem image_singleton {f : α → β} {a : α} : f '' {a} = {f a} := by
ext
simp [image, eq_comm]
#align set.image_singleton Set.image_singleton
@[simp]
theorem Nonempty.image_const {s : Set α} (hs : s.Nonempty) (a : β) : (fun _ => a) '' s = {a} :=
ext fun _ =>
⟨fun ⟨_, _, h⟩ => h ▸ mem_singleton _, fun h =>
(eq_of_mem_singleton h).symm ▸ hs.imp fun _ hy => ⟨hy, rfl⟩⟩
#align set.nonempty.image_const Set.Nonempty.image_const
@[simp, mfld_simps]
theorem image_eq_empty {α β} {f : α → β} {s : Set α} : f '' s = ∅ ↔ s = ∅ := by
simp only [eq_empty_iff_forall_not_mem]
|
exact ⟨fun H a ha => H _ ⟨_, ha, rfl⟩, fun H b ⟨_, ha, _⟩ => H _ ha⟩
|
@[simp, mfld_simps]
theorem image_eq_empty {α β} {f : α → β} {s : Set α} : f '' s = ∅ ↔ s = ∅ := by
simp only [eq_empty_iff_forall_not_mem]
|
Mathlib.Data.Set.Image.381_0.IJFiTzmYGOCpPSd
|
@[simp, mfld_simps]
theorem image_eq_empty {α β} {f : α → β} {s : Set α} : f '' s = ∅ ↔ s = ∅
|
Mathlib_Data_Set_Image
|
α : Type u_1
β : Type u_2
γ : Type u_3
ι : Sort u_4
ι' : Sort u_5
f : α → β
s t✝ : Set α
inst✝ : BooleanAlgebra α
t : α
S : Set α
⊢ t ∈ compl '' S ↔ tᶜ ∈ S
|
/-
Copyright (c) 2014 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Leonardo de Moura
-/
import Mathlib.Data.Set.Basic
#align_import data.set.image from "leanprover-community/mathlib"@"001ffdc42920050657fd45bd2b8bfbec8eaaeb29"
/-!
# Images and preimages of sets
## Main definitions
* `preimage f t : Set α` : the preimage f⁻¹(t) (written `f ⁻¹' t` in Lean) of a subset of β.
* `range f : Set β` : the image of `univ` under `f`.
Also works for `{p : Prop} (f : p → α)` (unlike `image`)
## Notation
* `f ⁻¹' t` for `Set.preimage f t`
* `f '' s` for `Set.image f s`
## Tags
set, sets, image, preimage, pre-image, range
-/
set_option autoImplicit true
universe u v
open Function Set
namespace Set
variable {α β γ : Type*} {ι ι' : Sort*}
/-! ### Inverse image -/
/-- The preimage of `s : Set β` by `f : α → β`, written `f ⁻¹' s`,
is the set of `x : α` such that `f x ∈ s`. -/
def preimage {α : Type u} {β : Type v} (f : α → β) (s : Set β) : Set α :=
{ x | f x ∈ s }
#align set.preimage Set.preimage
/-- `f ⁻¹' t` denotes the preimage of `t : Set β` under the function `f : α → β`. -/
infixl:80 " ⁻¹' " => preimage
section Preimage
variable {f : α → β} {g : β → γ}
@[simp]
theorem preimage_empty : f ⁻¹' ∅ = ∅ :=
rfl
#align set.preimage_empty Set.preimage_empty
@[simp, mfld_simps]
theorem mem_preimage {s : Set β} {a : α} : a ∈ f ⁻¹' s ↔ f a ∈ s :=
Iff.rfl
#align set.mem_preimage Set.mem_preimage
theorem preimage_congr {f g : α → β} {s : Set β} (h : ∀ x : α, f x = g x) : f ⁻¹' s = g ⁻¹' s := by
congr with x
simp [h]
#align set.preimage_congr Set.preimage_congr
@[gcongr]
theorem preimage_mono {s t : Set β} (h : s ⊆ t) : f ⁻¹' s ⊆ f ⁻¹' t := fun _ hx => h hx
#align set.preimage_mono Set.preimage_mono
@[simp, mfld_simps]
theorem preimage_univ : f ⁻¹' univ = univ :=
rfl
#align set.preimage_univ Set.preimage_univ
theorem subset_preimage_univ {s : Set α} : s ⊆ f ⁻¹' univ :=
subset_univ _
#align set.subset_preimage_univ Set.subset_preimage_univ
@[simp, mfld_simps]
theorem preimage_inter {s t : Set β} : f ⁻¹' (s ∩ t) = f ⁻¹' s ∩ f ⁻¹' t :=
rfl
#align set.preimage_inter Set.preimage_inter
@[simp]
theorem preimage_union {s t : Set β} : f ⁻¹' (s ∪ t) = f ⁻¹' s ∪ f ⁻¹' t :=
rfl
#align set.preimage_union Set.preimage_union
@[simp]
theorem preimage_compl {s : Set β} : f ⁻¹' sᶜ = (f ⁻¹' s)ᶜ :=
rfl
#align set.preimage_compl Set.preimage_compl
@[simp]
theorem preimage_diff (f : α → β) (s t : Set β) : f ⁻¹' (s \ t) = f ⁻¹' s \ f ⁻¹' t :=
rfl
#align set.preimage_diff Set.preimage_diff
@[simp]
lemma preimage_symmDiff {f : α → β} (s t : Set β) : f ⁻¹' (s ∆ t) = (f ⁻¹' s) ∆ (f ⁻¹' t) :=
rfl
#align set.preimage_symm_diff Set.preimage_symmDiff
@[simp]
theorem preimage_ite (f : α → β) (s t₁ t₂ : Set β) :
f ⁻¹' s.ite t₁ t₂ = (f ⁻¹' s).ite (f ⁻¹' t₁) (f ⁻¹' t₂) :=
rfl
#align set.preimage_ite Set.preimage_ite
@[simp]
theorem preimage_setOf_eq {p : α → Prop} {f : β → α} : f ⁻¹' { a | p a } = { a | p (f a) } :=
rfl
#align set.preimage_set_of_eq Set.preimage_setOf_eq
@[simp]
theorem preimage_id_eq : preimage (id : α → α) = id :=
rfl
#align set.preimage_id_eq Set.preimage_id_eq
@[mfld_simps]
theorem preimage_id {s : Set α} : id ⁻¹' s = s :=
rfl
#align set.preimage_id Set.preimage_id
@[simp, mfld_simps]
theorem preimage_id' {s : Set α} : (fun x => x) ⁻¹' s = s :=
rfl
#align set.preimage_id' Set.preimage_id'
@[simp]
theorem preimage_const_of_mem {b : β} {s : Set β} (h : b ∈ s) : (fun _ : α => b) ⁻¹' s = univ :=
eq_univ_of_forall fun _ => h
#align set.preimage_const_of_mem Set.preimage_const_of_mem
@[simp]
theorem preimage_const_of_not_mem {b : β} {s : Set β} (h : b ∉ s) : (fun _ : α => b) ⁻¹' s = ∅ :=
eq_empty_of_subset_empty fun _ hx => h hx
#align set.preimage_const_of_not_mem Set.preimage_const_of_not_mem
theorem preimage_const (b : β) (s : Set β) [Decidable (b ∈ s)] :
(fun _ : α => b) ⁻¹' s = if b ∈ s then univ else ∅ := by
split_ifs with hb
exacts [preimage_const_of_mem hb, preimage_const_of_not_mem hb]
#align set.preimage_const Set.preimage_const
/-- If preimage of each singleton under `f : α → β` is either empty or the whole type,
then `f` is a constant. -/
lemma exists_eq_const_of_preimage_singleton [Nonempty β] {f : α → β}
(hf : ∀ b : β, f ⁻¹' {b} = ∅ ∨ f ⁻¹' {b} = univ) : ∃ b, f = const α b := by
rcases em (∃ b, f ⁻¹' {b} = univ) with ⟨b, hb⟩ | hf'
· exact ⟨b, funext fun x ↦ eq_univ_iff_forall.1 hb x⟩
· have : ∀ x b, f x ≠ b := fun x b ↦
eq_empty_iff_forall_not_mem.1 ((hf b).resolve_right fun h ↦ hf' ⟨b, h⟩) x
exact ⟨Classical.arbitrary β, funext fun x ↦ absurd rfl (this x _)⟩
theorem preimage_comp {s : Set γ} : g ∘ f ⁻¹' s = f ⁻¹' (g ⁻¹' s) :=
rfl
#align set.preimage_comp Set.preimage_comp
theorem preimage_comp_eq : preimage (g ∘ f) = preimage f ∘ preimage g :=
rfl
#align set.preimage_comp_eq Set.preimage_comp_eq
theorem preimage_iterate_eq {f : α → α} {n : ℕ} : Set.preimage f^[n] = (Set.preimage f)^[n] := by
induction' n with n ih; · simp
rw [iterate_succ, iterate_succ', preimage_comp_eq, ih]
#align set.preimage_iterate_eq Set.preimage_iterate_eq
theorem preimage_preimage {g : β → γ} {f : α → β} {s : Set γ} :
f ⁻¹' (g ⁻¹' s) = (fun x => g (f x)) ⁻¹' s :=
preimage_comp.symm
#align set.preimage_preimage Set.preimage_preimage
theorem eq_preimage_subtype_val_iff {p : α → Prop} {s : Set (Subtype p)} {t : Set α} :
s = Subtype.val ⁻¹' t ↔ ∀ (x) (h : p x), (⟨x, h⟩ : Subtype p) ∈ s ↔ x ∈ t :=
⟨fun s_eq x h => by
rw [s_eq]
simp, fun h => ext fun ⟨x, hx⟩ => by simp [h]⟩
#align set.eq_preimage_subtype_val_iff Set.eq_preimage_subtype_val_iff
theorem nonempty_of_nonempty_preimage {s : Set β} {f : α → β} (hf : (f ⁻¹' s).Nonempty) :
s.Nonempty :=
let ⟨x, hx⟩ := hf
⟨f x, hx⟩
#align set.nonempty_of_nonempty_preimage Set.nonempty_of_nonempty_preimage
@[simp] theorem preimage_singleton_true (p : α → Prop) : p ⁻¹' {True} = {a | p a} := by ext; simp
#align set.preimage_singleton_true Set.preimage_singleton_true
@[simp] theorem preimage_singleton_false (p : α → Prop) : p ⁻¹' {False} = {a | ¬p a} := by ext; simp
#align set.preimage_singleton_false Set.preimage_singleton_false
theorem preimage_subtype_coe_eq_compl {s u v : Set α} (hsuv : s ⊆ u ∪ v)
(H : s ∩ (u ∩ v) = ∅) : ((↑) : s → α) ⁻¹' u = ((↑) ⁻¹' v)ᶜ := by
ext ⟨x, x_in_s⟩
constructor
· intro x_in_u x_in_v
exact eq_empty_iff_forall_not_mem.mp H x ⟨x_in_s, ⟨x_in_u, x_in_v⟩⟩
· intro hx
exact Or.elim (hsuv x_in_s) id fun hx' => hx.elim hx'
#align set.preimage_subtype_coe_eq_compl Set.preimage_subtype_coe_eq_compl
end Preimage
/-! ### Image of a set under a function -/
section Image
variable {f : α → β} {s t : Set α}
-- Porting note: `Set.image` is already defined in `Init.Set`
#align set.image Set.image
/-- `f '' s` denotes the image of `s : Set α` under the function `f : α → β`. -/
infixl:80 " '' " => image
theorem mem_image_iff_bex {f : α → β} {s : Set α} {y : β} :
y ∈ f '' s ↔ ∃ (x : _) (_ : x ∈ s), f x = y :=
bex_def.symm
#align set.mem_image_iff_bex Set.mem_image_iff_bex
@[simp]
theorem mem_image (f : α → β) (s : Set α) (y : β) : y ∈ f '' s ↔ ∃ x ∈ s, f x = y :=
Iff.rfl
#align set.mem_image Set.mem_image
theorem image_eta (f : α → β) : f '' s = (fun x => f x) '' s :=
rfl
#align set.image_eta Set.image_eta
@[mfld_simps]
theorem mem_image_of_mem (f : α → β) {x : α} {a : Set α} (h : x ∈ a) : f x ∈ f '' a :=
⟨_, h, rfl⟩
#align set.mem_image_of_mem Set.mem_image_of_mem
theorem _root_.Function.Injective.mem_set_image {f : α → β} (hf : Injective f) {s : Set α} {a : α} :
f a ∈ f '' s ↔ a ∈ s :=
⟨fun ⟨_, hb, Eq⟩ => hf Eq ▸ hb, mem_image_of_mem f⟩
#align function.injective.mem_set_image Function.Injective.mem_set_image
theorem ball_image_iff {f : α → β} {s : Set α} {p : β → Prop} :
(∀ y ∈ f '' s, p y) ↔ ∀ x ∈ s, p (f x) := by simp
#align set.ball_image_iff Set.ball_image_iff
theorem ball_image_of_ball {f : α → β} {s : Set α} {p : β → Prop} (h : ∀ x ∈ s, p (f x)) :
∀ y ∈ f '' s, p y :=
ball_image_iff.2 h
#align set.ball_image_of_ball Set.ball_image_of_ball
theorem bex_image_iff {f : α → β} {s : Set α} {p : β → Prop} :
(∃ y ∈ f '' s, p y) ↔ ∃ x ∈ s, p (f x) := by simp
#align set.bex_image_iff Set.bex_image_iff
theorem mem_image_elim {f : α → β} {s : Set α} {C : β → Prop} (h : ∀ x : α, x ∈ s → C (f x)) :
∀ {y : β}, y ∈ f '' s → C y
| _, ⟨a, a_in, rfl⟩ => h a a_in
#align set.mem_image_elim Set.mem_image_elim
theorem mem_image_elim_on {f : α → β} {s : Set α} {C : β → Prop} {y : β} (h_y : y ∈ f '' s)
(h : ∀ x : α, x ∈ s → C (f x)) : C y :=
mem_image_elim h h_y
#align set.mem_image_elim_on Set.mem_image_elim_on
-- Porting note: used to be `safe`
@[congr]
theorem image_congr {f g : α → β} {s : Set α} (h : ∀ a ∈ s, f a = g a) : f '' s = g '' s := by
ext x
rw [mem_image, mem_image]
exact {
mp := by
rintro ⟨a, ha1, ha2⟩
exact ⟨a, ⟨ha1, (h a ha1) ▸ ha2⟩⟩,
mpr := by
rintro ⟨a, ha1, ha2⟩
exact ⟨a, ⟨ha1, (h a ha1) ▸ ha2⟩⟩
}
-- safe [ext_iff, iff_def]
#align set.image_congr Set.image_congr
/-- A common special case of `image_congr` -/
theorem image_congr' {f g : α → β} {s : Set α} (h : ∀ x : α, f x = g x) : f '' s = g '' s :=
image_congr fun x _ => h x
#align set.image_congr' Set.image_congr'
@[gcongr]
lemma image_mono (h : s ⊆ t) : f '' s ⊆ f '' t := by
rintro - ⟨a, ha, rfl⟩; exact mem_image_of_mem f (h ha)
theorem image_comp (f : β → γ) (g : α → β) (a : Set α) : f ∘ g '' a = f '' (g '' a) :=
Subset.antisymm (ball_image_of_ball fun _ ha => mem_image_of_mem _ <| mem_image_of_mem _ ha)
(ball_image_of_ball <| ball_image_of_ball fun _ ha => mem_image_of_mem _ ha)
#align set.image_comp Set.image_comp
theorem image_comp_eq {g : β → γ} : image (g ∘ f) = image g ∘ image f := by ext; simp
/-- A variant of `image_comp`, useful for rewriting -/
theorem image_image (g : β → γ) (f : α → β) (s : Set α) : g '' (f '' s) = (fun x => g (f x)) '' s :=
(image_comp g f s).symm
#align set.image_image Set.image_image
theorem image_comm {β'} {f : β → γ} {g : α → β} {f' : α → β'} {g' : β' → γ}
(h_comm : ∀ a, f (g a) = g' (f' a)) : (s.image g).image f = (s.image f').image g' := by
simp_rw [image_image, h_comm]
#align set.image_comm Set.image_comm
theorem _root_.Function.Semiconj.set_image {f : α → β} {ga : α → α} {gb : β → β}
(h : Function.Semiconj f ga gb) : Function.Semiconj (image f) (image ga) (image gb) := fun _ =>
image_comm h
#align function.semiconj.set_image Function.Semiconj.set_image
theorem _root_.Function.Commute.set_image {f g : α → α} (h : Function.Commute f g) :
Function.Commute (image f) (image g) :=
Function.Semiconj.set_image h
#align function.commute.set_image Function.Commute.set_image
/-- Image is monotone with respect to `⊆`. See `Set.monotone_image` for the statement in
terms of `≤`. -/
@[gcongr]
theorem image_subset {a b : Set α} (f : α → β) (h : a ⊆ b) : f '' a ⊆ f '' b := by
simp only [subset_def, mem_image]
exact fun x => fun ⟨w, h1, h2⟩ => ⟨w, h h1, h2⟩
#align set.image_subset Set.image_subset
/-- `Set.image` is monotone. See `Set.image_subset` for the statement in terms of `⊆`. -/
lemma monotone_image {f : α → β} : Monotone (image f) := fun _ _ => image_subset _
#align set.monotone_image Set.monotone_image
theorem image_union (f : α → β) (s t : Set α) : f '' (s ∪ t) = f '' s ∪ f '' t :=
ext fun x =>
⟨by rintro ⟨a, h | h, rfl⟩ <;> [left; right] <;> exact ⟨_, h, rfl⟩, by
rintro (⟨a, h, rfl⟩ | ⟨a, h, rfl⟩) <;> refine' ⟨_, _, rfl⟩ <;> [left; right] <;> exact h⟩
#align set.image_union Set.image_union
@[simp]
theorem image_empty (f : α → β) : f '' ∅ = ∅ := by
ext
simp
#align set.image_empty Set.image_empty
theorem image_inter_subset (f : α → β) (s t : Set α) : f '' (s ∩ t) ⊆ f '' s ∩ f '' t :=
subset_inter (image_subset _ <| inter_subset_left _ _) (image_subset _ <| inter_subset_right _ _)
#align set.image_inter_subset Set.image_inter_subset
theorem image_inter_on {f : α → β} {s t : Set α} (h : ∀ x ∈ t, ∀ y ∈ s, f x = f y → x = y) :
f '' (s ∩ t) = f '' s ∩ f '' t :=
(image_inter_subset _ _ _).antisymm
fun b ⟨⟨a₁, ha₁, h₁⟩, ⟨a₂, ha₂, h₂⟩⟩ ↦
have : a₂ = a₁ := h _ ha₂ _ ha₁ (by simp [*])
⟨a₁, ⟨ha₁, this ▸ ha₂⟩, h₁⟩
#align set.image_inter_on Set.image_inter_on
theorem image_inter {f : α → β} {s t : Set α} (H : Injective f) : f '' (s ∩ t) = f '' s ∩ f '' t :=
image_inter_on fun _ _ _ _ h => H h
#align set.image_inter Set.image_inter
theorem image_univ_of_surjective {ι : Type*} {f : ι → β} (H : Surjective f) : f '' univ = univ :=
eq_univ_of_forall <| by simpa [image]
#align set.image_univ_of_surjective Set.image_univ_of_surjective
@[simp]
theorem image_singleton {f : α → β} {a : α} : f '' {a} = {f a} := by
ext
simp [image, eq_comm]
#align set.image_singleton Set.image_singleton
@[simp]
theorem Nonempty.image_const {s : Set α} (hs : s.Nonempty) (a : β) : (fun _ => a) '' s = {a} :=
ext fun _ =>
⟨fun ⟨_, _, h⟩ => h ▸ mem_singleton _, fun h =>
(eq_of_mem_singleton h).symm ▸ hs.imp fun _ hy => ⟨hy, rfl⟩⟩
#align set.nonempty.image_const Set.Nonempty.image_const
@[simp, mfld_simps]
theorem image_eq_empty {α β} {f : α → β} {s : Set α} : f '' s = ∅ ↔ s = ∅ := by
simp only [eq_empty_iff_forall_not_mem]
exact ⟨fun H a ha => H _ ⟨_, ha, rfl⟩, fun H b ⟨_, ha, _⟩ => H _ ha⟩
#align set.image_eq_empty Set.image_eq_empty
-- Porting note: `compl` is already defined in `Init.Set`
theorem preimage_compl_eq_image_compl [BooleanAlgebra α] (S : Set α) :
HasCompl.compl ⁻¹' S = HasCompl.compl '' S :=
Set.ext fun x =>
⟨fun h => ⟨xᶜ, h, compl_compl x⟩, fun h =>
Exists.elim h fun _ hy => (compl_eq_comm.mp hy.2).symm.subst hy.1⟩
#align set.preimage_compl_eq_image_compl Set.preimage_compl_eq_image_compl
theorem mem_compl_image [BooleanAlgebra α] (t : α) (S : Set α) :
t ∈ HasCompl.compl '' S ↔ tᶜ ∈ S := by
|
simp [← preimage_compl_eq_image_compl]
|
theorem mem_compl_image [BooleanAlgebra α] (t : α) (S : Set α) :
t ∈ HasCompl.compl '' S ↔ tᶜ ∈ S := by
|
Mathlib.Data.Set.Image.395_0.IJFiTzmYGOCpPSd
|
theorem mem_compl_image [BooleanAlgebra α] (t : α) (S : Set α) :
t ∈ HasCompl.compl '' S ↔ tᶜ ∈ S
|
Mathlib_Data_Set_Image
|
α : Type u_1
β : Type u_2
γ : Type u_3
ι : Sort u_4
ι' : Sort u_5
f : α → β
s t : Set α
⊢ image id = id
|
/-
Copyright (c) 2014 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Leonardo de Moura
-/
import Mathlib.Data.Set.Basic
#align_import data.set.image from "leanprover-community/mathlib"@"001ffdc42920050657fd45bd2b8bfbec8eaaeb29"
/-!
# Images and preimages of sets
## Main definitions
* `preimage f t : Set α` : the preimage f⁻¹(t) (written `f ⁻¹' t` in Lean) of a subset of β.
* `range f : Set β` : the image of `univ` under `f`.
Also works for `{p : Prop} (f : p → α)` (unlike `image`)
## Notation
* `f ⁻¹' t` for `Set.preimage f t`
* `f '' s` for `Set.image f s`
## Tags
set, sets, image, preimage, pre-image, range
-/
set_option autoImplicit true
universe u v
open Function Set
namespace Set
variable {α β γ : Type*} {ι ι' : Sort*}
/-! ### Inverse image -/
/-- The preimage of `s : Set β` by `f : α → β`, written `f ⁻¹' s`,
is the set of `x : α` such that `f x ∈ s`. -/
def preimage {α : Type u} {β : Type v} (f : α → β) (s : Set β) : Set α :=
{ x | f x ∈ s }
#align set.preimage Set.preimage
/-- `f ⁻¹' t` denotes the preimage of `t : Set β` under the function `f : α → β`. -/
infixl:80 " ⁻¹' " => preimage
section Preimage
variable {f : α → β} {g : β → γ}
@[simp]
theorem preimage_empty : f ⁻¹' ∅ = ∅ :=
rfl
#align set.preimage_empty Set.preimage_empty
@[simp, mfld_simps]
theorem mem_preimage {s : Set β} {a : α} : a ∈ f ⁻¹' s ↔ f a ∈ s :=
Iff.rfl
#align set.mem_preimage Set.mem_preimage
theorem preimage_congr {f g : α → β} {s : Set β} (h : ∀ x : α, f x = g x) : f ⁻¹' s = g ⁻¹' s := by
congr with x
simp [h]
#align set.preimage_congr Set.preimage_congr
@[gcongr]
theorem preimage_mono {s t : Set β} (h : s ⊆ t) : f ⁻¹' s ⊆ f ⁻¹' t := fun _ hx => h hx
#align set.preimage_mono Set.preimage_mono
@[simp, mfld_simps]
theorem preimage_univ : f ⁻¹' univ = univ :=
rfl
#align set.preimage_univ Set.preimage_univ
theorem subset_preimage_univ {s : Set α} : s ⊆ f ⁻¹' univ :=
subset_univ _
#align set.subset_preimage_univ Set.subset_preimage_univ
@[simp, mfld_simps]
theorem preimage_inter {s t : Set β} : f ⁻¹' (s ∩ t) = f ⁻¹' s ∩ f ⁻¹' t :=
rfl
#align set.preimage_inter Set.preimage_inter
@[simp]
theorem preimage_union {s t : Set β} : f ⁻¹' (s ∪ t) = f ⁻¹' s ∪ f ⁻¹' t :=
rfl
#align set.preimage_union Set.preimage_union
@[simp]
theorem preimage_compl {s : Set β} : f ⁻¹' sᶜ = (f ⁻¹' s)ᶜ :=
rfl
#align set.preimage_compl Set.preimage_compl
@[simp]
theorem preimage_diff (f : α → β) (s t : Set β) : f ⁻¹' (s \ t) = f ⁻¹' s \ f ⁻¹' t :=
rfl
#align set.preimage_diff Set.preimage_diff
@[simp]
lemma preimage_symmDiff {f : α → β} (s t : Set β) : f ⁻¹' (s ∆ t) = (f ⁻¹' s) ∆ (f ⁻¹' t) :=
rfl
#align set.preimage_symm_diff Set.preimage_symmDiff
@[simp]
theorem preimage_ite (f : α → β) (s t₁ t₂ : Set β) :
f ⁻¹' s.ite t₁ t₂ = (f ⁻¹' s).ite (f ⁻¹' t₁) (f ⁻¹' t₂) :=
rfl
#align set.preimage_ite Set.preimage_ite
@[simp]
theorem preimage_setOf_eq {p : α → Prop} {f : β → α} : f ⁻¹' { a | p a } = { a | p (f a) } :=
rfl
#align set.preimage_set_of_eq Set.preimage_setOf_eq
@[simp]
theorem preimage_id_eq : preimage (id : α → α) = id :=
rfl
#align set.preimage_id_eq Set.preimage_id_eq
@[mfld_simps]
theorem preimage_id {s : Set α} : id ⁻¹' s = s :=
rfl
#align set.preimage_id Set.preimage_id
@[simp, mfld_simps]
theorem preimage_id' {s : Set α} : (fun x => x) ⁻¹' s = s :=
rfl
#align set.preimage_id' Set.preimage_id'
@[simp]
theorem preimage_const_of_mem {b : β} {s : Set β} (h : b ∈ s) : (fun _ : α => b) ⁻¹' s = univ :=
eq_univ_of_forall fun _ => h
#align set.preimage_const_of_mem Set.preimage_const_of_mem
@[simp]
theorem preimage_const_of_not_mem {b : β} {s : Set β} (h : b ∉ s) : (fun _ : α => b) ⁻¹' s = ∅ :=
eq_empty_of_subset_empty fun _ hx => h hx
#align set.preimage_const_of_not_mem Set.preimage_const_of_not_mem
theorem preimage_const (b : β) (s : Set β) [Decidable (b ∈ s)] :
(fun _ : α => b) ⁻¹' s = if b ∈ s then univ else ∅ := by
split_ifs with hb
exacts [preimage_const_of_mem hb, preimage_const_of_not_mem hb]
#align set.preimage_const Set.preimage_const
/-- If preimage of each singleton under `f : α → β` is either empty or the whole type,
then `f` is a constant. -/
lemma exists_eq_const_of_preimage_singleton [Nonempty β] {f : α → β}
(hf : ∀ b : β, f ⁻¹' {b} = ∅ ∨ f ⁻¹' {b} = univ) : ∃ b, f = const α b := by
rcases em (∃ b, f ⁻¹' {b} = univ) with ⟨b, hb⟩ | hf'
· exact ⟨b, funext fun x ↦ eq_univ_iff_forall.1 hb x⟩
· have : ∀ x b, f x ≠ b := fun x b ↦
eq_empty_iff_forall_not_mem.1 ((hf b).resolve_right fun h ↦ hf' ⟨b, h⟩) x
exact ⟨Classical.arbitrary β, funext fun x ↦ absurd rfl (this x _)⟩
theorem preimage_comp {s : Set γ} : g ∘ f ⁻¹' s = f ⁻¹' (g ⁻¹' s) :=
rfl
#align set.preimage_comp Set.preimage_comp
theorem preimage_comp_eq : preimage (g ∘ f) = preimage f ∘ preimage g :=
rfl
#align set.preimage_comp_eq Set.preimage_comp_eq
theorem preimage_iterate_eq {f : α → α} {n : ℕ} : Set.preimage f^[n] = (Set.preimage f)^[n] := by
induction' n with n ih; · simp
rw [iterate_succ, iterate_succ', preimage_comp_eq, ih]
#align set.preimage_iterate_eq Set.preimage_iterate_eq
theorem preimage_preimage {g : β → γ} {f : α → β} {s : Set γ} :
f ⁻¹' (g ⁻¹' s) = (fun x => g (f x)) ⁻¹' s :=
preimage_comp.symm
#align set.preimage_preimage Set.preimage_preimage
theorem eq_preimage_subtype_val_iff {p : α → Prop} {s : Set (Subtype p)} {t : Set α} :
s = Subtype.val ⁻¹' t ↔ ∀ (x) (h : p x), (⟨x, h⟩ : Subtype p) ∈ s ↔ x ∈ t :=
⟨fun s_eq x h => by
rw [s_eq]
simp, fun h => ext fun ⟨x, hx⟩ => by simp [h]⟩
#align set.eq_preimage_subtype_val_iff Set.eq_preimage_subtype_val_iff
theorem nonempty_of_nonempty_preimage {s : Set β} {f : α → β} (hf : (f ⁻¹' s).Nonempty) :
s.Nonempty :=
let ⟨x, hx⟩ := hf
⟨f x, hx⟩
#align set.nonempty_of_nonempty_preimage Set.nonempty_of_nonempty_preimage
@[simp] theorem preimage_singleton_true (p : α → Prop) : p ⁻¹' {True} = {a | p a} := by ext; simp
#align set.preimage_singleton_true Set.preimage_singleton_true
@[simp] theorem preimage_singleton_false (p : α → Prop) : p ⁻¹' {False} = {a | ¬p a} := by ext; simp
#align set.preimage_singleton_false Set.preimage_singleton_false
theorem preimage_subtype_coe_eq_compl {s u v : Set α} (hsuv : s ⊆ u ∪ v)
(H : s ∩ (u ∩ v) = ∅) : ((↑) : s → α) ⁻¹' u = ((↑) ⁻¹' v)ᶜ := by
ext ⟨x, x_in_s⟩
constructor
· intro x_in_u x_in_v
exact eq_empty_iff_forall_not_mem.mp H x ⟨x_in_s, ⟨x_in_u, x_in_v⟩⟩
· intro hx
exact Or.elim (hsuv x_in_s) id fun hx' => hx.elim hx'
#align set.preimage_subtype_coe_eq_compl Set.preimage_subtype_coe_eq_compl
end Preimage
/-! ### Image of a set under a function -/
section Image
variable {f : α → β} {s t : Set α}
-- Porting note: `Set.image` is already defined in `Init.Set`
#align set.image Set.image
/-- `f '' s` denotes the image of `s : Set α` under the function `f : α → β`. -/
infixl:80 " '' " => image
theorem mem_image_iff_bex {f : α → β} {s : Set α} {y : β} :
y ∈ f '' s ↔ ∃ (x : _) (_ : x ∈ s), f x = y :=
bex_def.symm
#align set.mem_image_iff_bex Set.mem_image_iff_bex
@[simp]
theorem mem_image (f : α → β) (s : Set α) (y : β) : y ∈ f '' s ↔ ∃ x ∈ s, f x = y :=
Iff.rfl
#align set.mem_image Set.mem_image
theorem image_eta (f : α → β) : f '' s = (fun x => f x) '' s :=
rfl
#align set.image_eta Set.image_eta
@[mfld_simps]
theorem mem_image_of_mem (f : α → β) {x : α} {a : Set α} (h : x ∈ a) : f x ∈ f '' a :=
⟨_, h, rfl⟩
#align set.mem_image_of_mem Set.mem_image_of_mem
theorem _root_.Function.Injective.mem_set_image {f : α → β} (hf : Injective f) {s : Set α} {a : α} :
f a ∈ f '' s ↔ a ∈ s :=
⟨fun ⟨_, hb, Eq⟩ => hf Eq ▸ hb, mem_image_of_mem f⟩
#align function.injective.mem_set_image Function.Injective.mem_set_image
theorem ball_image_iff {f : α → β} {s : Set α} {p : β → Prop} :
(∀ y ∈ f '' s, p y) ↔ ∀ x ∈ s, p (f x) := by simp
#align set.ball_image_iff Set.ball_image_iff
theorem ball_image_of_ball {f : α → β} {s : Set α} {p : β → Prop} (h : ∀ x ∈ s, p (f x)) :
∀ y ∈ f '' s, p y :=
ball_image_iff.2 h
#align set.ball_image_of_ball Set.ball_image_of_ball
theorem bex_image_iff {f : α → β} {s : Set α} {p : β → Prop} :
(∃ y ∈ f '' s, p y) ↔ ∃ x ∈ s, p (f x) := by simp
#align set.bex_image_iff Set.bex_image_iff
theorem mem_image_elim {f : α → β} {s : Set α} {C : β → Prop} (h : ∀ x : α, x ∈ s → C (f x)) :
∀ {y : β}, y ∈ f '' s → C y
| _, ⟨a, a_in, rfl⟩ => h a a_in
#align set.mem_image_elim Set.mem_image_elim
theorem mem_image_elim_on {f : α → β} {s : Set α} {C : β → Prop} {y : β} (h_y : y ∈ f '' s)
(h : ∀ x : α, x ∈ s → C (f x)) : C y :=
mem_image_elim h h_y
#align set.mem_image_elim_on Set.mem_image_elim_on
-- Porting note: used to be `safe`
@[congr]
theorem image_congr {f g : α → β} {s : Set α} (h : ∀ a ∈ s, f a = g a) : f '' s = g '' s := by
ext x
rw [mem_image, mem_image]
exact {
mp := by
rintro ⟨a, ha1, ha2⟩
exact ⟨a, ⟨ha1, (h a ha1) ▸ ha2⟩⟩,
mpr := by
rintro ⟨a, ha1, ha2⟩
exact ⟨a, ⟨ha1, (h a ha1) ▸ ha2⟩⟩
}
-- safe [ext_iff, iff_def]
#align set.image_congr Set.image_congr
/-- A common special case of `image_congr` -/
theorem image_congr' {f g : α → β} {s : Set α} (h : ∀ x : α, f x = g x) : f '' s = g '' s :=
image_congr fun x _ => h x
#align set.image_congr' Set.image_congr'
@[gcongr]
lemma image_mono (h : s ⊆ t) : f '' s ⊆ f '' t := by
rintro - ⟨a, ha, rfl⟩; exact mem_image_of_mem f (h ha)
theorem image_comp (f : β → γ) (g : α → β) (a : Set α) : f ∘ g '' a = f '' (g '' a) :=
Subset.antisymm (ball_image_of_ball fun _ ha => mem_image_of_mem _ <| mem_image_of_mem _ ha)
(ball_image_of_ball <| ball_image_of_ball fun _ ha => mem_image_of_mem _ ha)
#align set.image_comp Set.image_comp
theorem image_comp_eq {g : β → γ} : image (g ∘ f) = image g ∘ image f := by ext; simp
/-- A variant of `image_comp`, useful for rewriting -/
theorem image_image (g : β → γ) (f : α → β) (s : Set α) : g '' (f '' s) = (fun x => g (f x)) '' s :=
(image_comp g f s).symm
#align set.image_image Set.image_image
theorem image_comm {β'} {f : β → γ} {g : α → β} {f' : α → β'} {g' : β' → γ}
(h_comm : ∀ a, f (g a) = g' (f' a)) : (s.image g).image f = (s.image f').image g' := by
simp_rw [image_image, h_comm]
#align set.image_comm Set.image_comm
theorem _root_.Function.Semiconj.set_image {f : α → β} {ga : α → α} {gb : β → β}
(h : Function.Semiconj f ga gb) : Function.Semiconj (image f) (image ga) (image gb) := fun _ =>
image_comm h
#align function.semiconj.set_image Function.Semiconj.set_image
theorem _root_.Function.Commute.set_image {f g : α → α} (h : Function.Commute f g) :
Function.Commute (image f) (image g) :=
Function.Semiconj.set_image h
#align function.commute.set_image Function.Commute.set_image
/-- Image is monotone with respect to `⊆`. See `Set.monotone_image` for the statement in
terms of `≤`. -/
@[gcongr]
theorem image_subset {a b : Set α} (f : α → β) (h : a ⊆ b) : f '' a ⊆ f '' b := by
simp only [subset_def, mem_image]
exact fun x => fun ⟨w, h1, h2⟩ => ⟨w, h h1, h2⟩
#align set.image_subset Set.image_subset
/-- `Set.image` is monotone. See `Set.image_subset` for the statement in terms of `⊆`. -/
lemma monotone_image {f : α → β} : Monotone (image f) := fun _ _ => image_subset _
#align set.monotone_image Set.monotone_image
theorem image_union (f : α → β) (s t : Set α) : f '' (s ∪ t) = f '' s ∪ f '' t :=
ext fun x =>
⟨by rintro ⟨a, h | h, rfl⟩ <;> [left; right] <;> exact ⟨_, h, rfl⟩, by
rintro (⟨a, h, rfl⟩ | ⟨a, h, rfl⟩) <;> refine' ⟨_, _, rfl⟩ <;> [left; right] <;> exact h⟩
#align set.image_union Set.image_union
@[simp]
theorem image_empty (f : α → β) : f '' ∅ = ∅ := by
ext
simp
#align set.image_empty Set.image_empty
theorem image_inter_subset (f : α → β) (s t : Set α) : f '' (s ∩ t) ⊆ f '' s ∩ f '' t :=
subset_inter (image_subset _ <| inter_subset_left _ _) (image_subset _ <| inter_subset_right _ _)
#align set.image_inter_subset Set.image_inter_subset
theorem image_inter_on {f : α → β} {s t : Set α} (h : ∀ x ∈ t, ∀ y ∈ s, f x = f y → x = y) :
f '' (s ∩ t) = f '' s ∩ f '' t :=
(image_inter_subset _ _ _).antisymm
fun b ⟨⟨a₁, ha₁, h₁⟩, ⟨a₂, ha₂, h₂⟩⟩ ↦
have : a₂ = a₁ := h _ ha₂ _ ha₁ (by simp [*])
⟨a₁, ⟨ha₁, this ▸ ha₂⟩, h₁⟩
#align set.image_inter_on Set.image_inter_on
theorem image_inter {f : α → β} {s t : Set α} (H : Injective f) : f '' (s ∩ t) = f '' s ∩ f '' t :=
image_inter_on fun _ _ _ _ h => H h
#align set.image_inter Set.image_inter
theorem image_univ_of_surjective {ι : Type*} {f : ι → β} (H : Surjective f) : f '' univ = univ :=
eq_univ_of_forall <| by simpa [image]
#align set.image_univ_of_surjective Set.image_univ_of_surjective
@[simp]
theorem image_singleton {f : α → β} {a : α} : f '' {a} = {f a} := by
ext
simp [image, eq_comm]
#align set.image_singleton Set.image_singleton
@[simp]
theorem Nonempty.image_const {s : Set α} (hs : s.Nonempty) (a : β) : (fun _ => a) '' s = {a} :=
ext fun _ =>
⟨fun ⟨_, _, h⟩ => h ▸ mem_singleton _, fun h =>
(eq_of_mem_singleton h).symm ▸ hs.imp fun _ hy => ⟨hy, rfl⟩⟩
#align set.nonempty.image_const Set.Nonempty.image_const
@[simp, mfld_simps]
theorem image_eq_empty {α β} {f : α → β} {s : Set α} : f '' s = ∅ ↔ s = ∅ := by
simp only [eq_empty_iff_forall_not_mem]
exact ⟨fun H a ha => H _ ⟨_, ha, rfl⟩, fun H b ⟨_, ha, _⟩ => H _ ha⟩
#align set.image_eq_empty Set.image_eq_empty
-- Porting note: `compl` is already defined in `Init.Set`
theorem preimage_compl_eq_image_compl [BooleanAlgebra α] (S : Set α) :
HasCompl.compl ⁻¹' S = HasCompl.compl '' S :=
Set.ext fun x =>
⟨fun h => ⟨xᶜ, h, compl_compl x⟩, fun h =>
Exists.elim h fun _ hy => (compl_eq_comm.mp hy.2).symm.subst hy.1⟩
#align set.preimage_compl_eq_image_compl Set.preimage_compl_eq_image_compl
theorem mem_compl_image [BooleanAlgebra α] (t : α) (S : Set α) :
t ∈ HasCompl.compl '' S ↔ tᶜ ∈ S := by
simp [← preimage_compl_eq_image_compl]
#align set.mem_compl_image Set.mem_compl_image
@[simp]
theorem image_id_eq : image (id : α → α) = id := by
|
ext
|
@[simp]
theorem image_id_eq : image (id : α → α) = id := by
|
Mathlib.Data.Set.Image.400_0.IJFiTzmYGOCpPSd
|
@[simp]
theorem image_id_eq : image (id : α → α) = id
|
Mathlib_Data_Set_Image
|
case h.h
α : Type u_1
β : Type u_2
γ : Type u_3
ι : Sort u_4
ι' : Sort u_5
f : α → β
s t x✝¹ : Set α
x✝ : α
⊢ x✝ ∈ id '' x✝¹ ↔ x✝ ∈ id x✝¹
|
/-
Copyright (c) 2014 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Leonardo de Moura
-/
import Mathlib.Data.Set.Basic
#align_import data.set.image from "leanprover-community/mathlib"@"001ffdc42920050657fd45bd2b8bfbec8eaaeb29"
/-!
# Images and preimages of sets
## Main definitions
* `preimage f t : Set α` : the preimage f⁻¹(t) (written `f ⁻¹' t` in Lean) of a subset of β.
* `range f : Set β` : the image of `univ` under `f`.
Also works for `{p : Prop} (f : p → α)` (unlike `image`)
## Notation
* `f ⁻¹' t` for `Set.preimage f t`
* `f '' s` for `Set.image f s`
## Tags
set, sets, image, preimage, pre-image, range
-/
set_option autoImplicit true
universe u v
open Function Set
namespace Set
variable {α β γ : Type*} {ι ι' : Sort*}
/-! ### Inverse image -/
/-- The preimage of `s : Set β` by `f : α → β`, written `f ⁻¹' s`,
is the set of `x : α` such that `f x ∈ s`. -/
def preimage {α : Type u} {β : Type v} (f : α → β) (s : Set β) : Set α :=
{ x | f x ∈ s }
#align set.preimage Set.preimage
/-- `f ⁻¹' t` denotes the preimage of `t : Set β` under the function `f : α → β`. -/
infixl:80 " ⁻¹' " => preimage
section Preimage
variable {f : α → β} {g : β → γ}
@[simp]
theorem preimage_empty : f ⁻¹' ∅ = ∅ :=
rfl
#align set.preimage_empty Set.preimage_empty
@[simp, mfld_simps]
theorem mem_preimage {s : Set β} {a : α} : a ∈ f ⁻¹' s ↔ f a ∈ s :=
Iff.rfl
#align set.mem_preimage Set.mem_preimage
theorem preimage_congr {f g : α → β} {s : Set β} (h : ∀ x : α, f x = g x) : f ⁻¹' s = g ⁻¹' s := by
congr with x
simp [h]
#align set.preimage_congr Set.preimage_congr
@[gcongr]
theorem preimage_mono {s t : Set β} (h : s ⊆ t) : f ⁻¹' s ⊆ f ⁻¹' t := fun _ hx => h hx
#align set.preimage_mono Set.preimage_mono
@[simp, mfld_simps]
theorem preimage_univ : f ⁻¹' univ = univ :=
rfl
#align set.preimage_univ Set.preimage_univ
theorem subset_preimage_univ {s : Set α} : s ⊆ f ⁻¹' univ :=
subset_univ _
#align set.subset_preimage_univ Set.subset_preimage_univ
@[simp, mfld_simps]
theorem preimage_inter {s t : Set β} : f ⁻¹' (s ∩ t) = f ⁻¹' s ∩ f ⁻¹' t :=
rfl
#align set.preimage_inter Set.preimage_inter
@[simp]
theorem preimage_union {s t : Set β} : f ⁻¹' (s ∪ t) = f ⁻¹' s ∪ f ⁻¹' t :=
rfl
#align set.preimage_union Set.preimage_union
@[simp]
theorem preimage_compl {s : Set β} : f ⁻¹' sᶜ = (f ⁻¹' s)ᶜ :=
rfl
#align set.preimage_compl Set.preimage_compl
@[simp]
theorem preimage_diff (f : α → β) (s t : Set β) : f ⁻¹' (s \ t) = f ⁻¹' s \ f ⁻¹' t :=
rfl
#align set.preimage_diff Set.preimage_diff
@[simp]
lemma preimage_symmDiff {f : α → β} (s t : Set β) : f ⁻¹' (s ∆ t) = (f ⁻¹' s) ∆ (f ⁻¹' t) :=
rfl
#align set.preimage_symm_diff Set.preimage_symmDiff
@[simp]
theorem preimage_ite (f : α → β) (s t₁ t₂ : Set β) :
f ⁻¹' s.ite t₁ t₂ = (f ⁻¹' s).ite (f ⁻¹' t₁) (f ⁻¹' t₂) :=
rfl
#align set.preimage_ite Set.preimage_ite
@[simp]
theorem preimage_setOf_eq {p : α → Prop} {f : β → α} : f ⁻¹' { a | p a } = { a | p (f a) } :=
rfl
#align set.preimage_set_of_eq Set.preimage_setOf_eq
@[simp]
theorem preimage_id_eq : preimage (id : α → α) = id :=
rfl
#align set.preimage_id_eq Set.preimage_id_eq
@[mfld_simps]
theorem preimage_id {s : Set α} : id ⁻¹' s = s :=
rfl
#align set.preimage_id Set.preimage_id
@[simp, mfld_simps]
theorem preimage_id' {s : Set α} : (fun x => x) ⁻¹' s = s :=
rfl
#align set.preimage_id' Set.preimage_id'
@[simp]
theorem preimage_const_of_mem {b : β} {s : Set β} (h : b ∈ s) : (fun _ : α => b) ⁻¹' s = univ :=
eq_univ_of_forall fun _ => h
#align set.preimage_const_of_mem Set.preimage_const_of_mem
@[simp]
theorem preimage_const_of_not_mem {b : β} {s : Set β} (h : b ∉ s) : (fun _ : α => b) ⁻¹' s = ∅ :=
eq_empty_of_subset_empty fun _ hx => h hx
#align set.preimage_const_of_not_mem Set.preimage_const_of_not_mem
theorem preimage_const (b : β) (s : Set β) [Decidable (b ∈ s)] :
(fun _ : α => b) ⁻¹' s = if b ∈ s then univ else ∅ := by
split_ifs with hb
exacts [preimage_const_of_mem hb, preimage_const_of_not_mem hb]
#align set.preimage_const Set.preimage_const
/-- If preimage of each singleton under `f : α → β` is either empty or the whole type,
then `f` is a constant. -/
lemma exists_eq_const_of_preimage_singleton [Nonempty β] {f : α → β}
(hf : ∀ b : β, f ⁻¹' {b} = ∅ ∨ f ⁻¹' {b} = univ) : ∃ b, f = const α b := by
rcases em (∃ b, f ⁻¹' {b} = univ) with ⟨b, hb⟩ | hf'
· exact ⟨b, funext fun x ↦ eq_univ_iff_forall.1 hb x⟩
· have : ∀ x b, f x ≠ b := fun x b ↦
eq_empty_iff_forall_not_mem.1 ((hf b).resolve_right fun h ↦ hf' ⟨b, h⟩) x
exact ⟨Classical.arbitrary β, funext fun x ↦ absurd rfl (this x _)⟩
theorem preimage_comp {s : Set γ} : g ∘ f ⁻¹' s = f ⁻¹' (g ⁻¹' s) :=
rfl
#align set.preimage_comp Set.preimage_comp
theorem preimage_comp_eq : preimage (g ∘ f) = preimage f ∘ preimage g :=
rfl
#align set.preimage_comp_eq Set.preimage_comp_eq
theorem preimage_iterate_eq {f : α → α} {n : ℕ} : Set.preimage f^[n] = (Set.preimage f)^[n] := by
induction' n with n ih; · simp
rw [iterate_succ, iterate_succ', preimage_comp_eq, ih]
#align set.preimage_iterate_eq Set.preimage_iterate_eq
theorem preimage_preimage {g : β → γ} {f : α → β} {s : Set γ} :
f ⁻¹' (g ⁻¹' s) = (fun x => g (f x)) ⁻¹' s :=
preimage_comp.symm
#align set.preimage_preimage Set.preimage_preimage
theorem eq_preimage_subtype_val_iff {p : α → Prop} {s : Set (Subtype p)} {t : Set α} :
s = Subtype.val ⁻¹' t ↔ ∀ (x) (h : p x), (⟨x, h⟩ : Subtype p) ∈ s ↔ x ∈ t :=
⟨fun s_eq x h => by
rw [s_eq]
simp, fun h => ext fun ⟨x, hx⟩ => by simp [h]⟩
#align set.eq_preimage_subtype_val_iff Set.eq_preimage_subtype_val_iff
theorem nonempty_of_nonempty_preimage {s : Set β} {f : α → β} (hf : (f ⁻¹' s).Nonempty) :
s.Nonempty :=
let ⟨x, hx⟩ := hf
⟨f x, hx⟩
#align set.nonempty_of_nonempty_preimage Set.nonempty_of_nonempty_preimage
@[simp] theorem preimage_singleton_true (p : α → Prop) : p ⁻¹' {True} = {a | p a} := by ext; simp
#align set.preimage_singleton_true Set.preimage_singleton_true
@[simp] theorem preimage_singleton_false (p : α → Prop) : p ⁻¹' {False} = {a | ¬p a} := by ext; simp
#align set.preimage_singleton_false Set.preimage_singleton_false
theorem preimage_subtype_coe_eq_compl {s u v : Set α} (hsuv : s ⊆ u ∪ v)
(H : s ∩ (u ∩ v) = ∅) : ((↑) : s → α) ⁻¹' u = ((↑) ⁻¹' v)ᶜ := by
ext ⟨x, x_in_s⟩
constructor
· intro x_in_u x_in_v
exact eq_empty_iff_forall_not_mem.mp H x ⟨x_in_s, ⟨x_in_u, x_in_v⟩⟩
· intro hx
exact Or.elim (hsuv x_in_s) id fun hx' => hx.elim hx'
#align set.preimage_subtype_coe_eq_compl Set.preimage_subtype_coe_eq_compl
end Preimage
/-! ### Image of a set under a function -/
section Image
variable {f : α → β} {s t : Set α}
-- Porting note: `Set.image` is already defined in `Init.Set`
#align set.image Set.image
/-- `f '' s` denotes the image of `s : Set α` under the function `f : α → β`. -/
infixl:80 " '' " => image
theorem mem_image_iff_bex {f : α → β} {s : Set α} {y : β} :
y ∈ f '' s ↔ ∃ (x : _) (_ : x ∈ s), f x = y :=
bex_def.symm
#align set.mem_image_iff_bex Set.mem_image_iff_bex
@[simp]
theorem mem_image (f : α → β) (s : Set α) (y : β) : y ∈ f '' s ↔ ∃ x ∈ s, f x = y :=
Iff.rfl
#align set.mem_image Set.mem_image
theorem image_eta (f : α → β) : f '' s = (fun x => f x) '' s :=
rfl
#align set.image_eta Set.image_eta
@[mfld_simps]
theorem mem_image_of_mem (f : α → β) {x : α} {a : Set α} (h : x ∈ a) : f x ∈ f '' a :=
⟨_, h, rfl⟩
#align set.mem_image_of_mem Set.mem_image_of_mem
theorem _root_.Function.Injective.mem_set_image {f : α → β} (hf : Injective f) {s : Set α} {a : α} :
f a ∈ f '' s ↔ a ∈ s :=
⟨fun ⟨_, hb, Eq⟩ => hf Eq ▸ hb, mem_image_of_mem f⟩
#align function.injective.mem_set_image Function.Injective.mem_set_image
theorem ball_image_iff {f : α → β} {s : Set α} {p : β → Prop} :
(∀ y ∈ f '' s, p y) ↔ ∀ x ∈ s, p (f x) := by simp
#align set.ball_image_iff Set.ball_image_iff
theorem ball_image_of_ball {f : α → β} {s : Set α} {p : β → Prop} (h : ∀ x ∈ s, p (f x)) :
∀ y ∈ f '' s, p y :=
ball_image_iff.2 h
#align set.ball_image_of_ball Set.ball_image_of_ball
theorem bex_image_iff {f : α → β} {s : Set α} {p : β → Prop} :
(∃ y ∈ f '' s, p y) ↔ ∃ x ∈ s, p (f x) := by simp
#align set.bex_image_iff Set.bex_image_iff
theorem mem_image_elim {f : α → β} {s : Set α} {C : β → Prop} (h : ∀ x : α, x ∈ s → C (f x)) :
∀ {y : β}, y ∈ f '' s → C y
| _, ⟨a, a_in, rfl⟩ => h a a_in
#align set.mem_image_elim Set.mem_image_elim
theorem mem_image_elim_on {f : α → β} {s : Set α} {C : β → Prop} {y : β} (h_y : y ∈ f '' s)
(h : ∀ x : α, x ∈ s → C (f x)) : C y :=
mem_image_elim h h_y
#align set.mem_image_elim_on Set.mem_image_elim_on
-- Porting note: used to be `safe`
@[congr]
theorem image_congr {f g : α → β} {s : Set α} (h : ∀ a ∈ s, f a = g a) : f '' s = g '' s := by
ext x
rw [mem_image, mem_image]
exact {
mp := by
rintro ⟨a, ha1, ha2⟩
exact ⟨a, ⟨ha1, (h a ha1) ▸ ha2⟩⟩,
mpr := by
rintro ⟨a, ha1, ha2⟩
exact ⟨a, ⟨ha1, (h a ha1) ▸ ha2⟩⟩
}
-- safe [ext_iff, iff_def]
#align set.image_congr Set.image_congr
/-- A common special case of `image_congr` -/
theorem image_congr' {f g : α → β} {s : Set α} (h : ∀ x : α, f x = g x) : f '' s = g '' s :=
image_congr fun x _ => h x
#align set.image_congr' Set.image_congr'
@[gcongr]
lemma image_mono (h : s ⊆ t) : f '' s ⊆ f '' t := by
rintro - ⟨a, ha, rfl⟩; exact mem_image_of_mem f (h ha)
theorem image_comp (f : β → γ) (g : α → β) (a : Set α) : f ∘ g '' a = f '' (g '' a) :=
Subset.antisymm (ball_image_of_ball fun _ ha => mem_image_of_mem _ <| mem_image_of_mem _ ha)
(ball_image_of_ball <| ball_image_of_ball fun _ ha => mem_image_of_mem _ ha)
#align set.image_comp Set.image_comp
theorem image_comp_eq {g : β → γ} : image (g ∘ f) = image g ∘ image f := by ext; simp
/-- A variant of `image_comp`, useful for rewriting -/
theorem image_image (g : β → γ) (f : α → β) (s : Set α) : g '' (f '' s) = (fun x => g (f x)) '' s :=
(image_comp g f s).symm
#align set.image_image Set.image_image
theorem image_comm {β'} {f : β → γ} {g : α → β} {f' : α → β'} {g' : β' → γ}
(h_comm : ∀ a, f (g a) = g' (f' a)) : (s.image g).image f = (s.image f').image g' := by
simp_rw [image_image, h_comm]
#align set.image_comm Set.image_comm
theorem _root_.Function.Semiconj.set_image {f : α → β} {ga : α → α} {gb : β → β}
(h : Function.Semiconj f ga gb) : Function.Semiconj (image f) (image ga) (image gb) := fun _ =>
image_comm h
#align function.semiconj.set_image Function.Semiconj.set_image
theorem _root_.Function.Commute.set_image {f g : α → α} (h : Function.Commute f g) :
Function.Commute (image f) (image g) :=
Function.Semiconj.set_image h
#align function.commute.set_image Function.Commute.set_image
/-- Image is monotone with respect to `⊆`. See `Set.monotone_image` for the statement in
terms of `≤`. -/
@[gcongr]
theorem image_subset {a b : Set α} (f : α → β) (h : a ⊆ b) : f '' a ⊆ f '' b := by
simp only [subset_def, mem_image]
exact fun x => fun ⟨w, h1, h2⟩ => ⟨w, h h1, h2⟩
#align set.image_subset Set.image_subset
/-- `Set.image` is monotone. See `Set.image_subset` for the statement in terms of `⊆`. -/
lemma monotone_image {f : α → β} : Monotone (image f) := fun _ _ => image_subset _
#align set.monotone_image Set.monotone_image
theorem image_union (f : α → β) (s t : Set α) : f '' (s ∪ t) = f '' s ∪ f '' t :=
ext fun x =>
⟨by rintro ⟨a, h | h, rfl⟩ <;> [left; right] <;> exact ⟨_, h, rfl⟩, by
rintro (⟨a, h, rfl⟩ | ⟨a, h, rfl⟩) <;> refine' ⟨_, _, rfl⟩ <;> [left; right] <;> exact h⟩
#align set.image_union Set.image_union
@[simp]
theorem image_empty (f : α → β) : f '' ∅ = ∅ := by
ext
simp
#align set.image_empty Set.image_empty
theorem image_inter_subset (f : α → β) (s t : Set α) : f '' (s ∩ t) ⊆ f '' s ∩ f '' t :=
subset_inter (image_subset _ <| inter_subset_left _ _) (image_subset _ <| inter_subset_right _ _)
#align set.image_inter_subset Set.image_inter_subset
theorem image_inter_on {f : α → β} {s t : Set α} (h : ∀ x ∈ t, ∀ y ∈ s, f x = f y → x = y) :
f '' (s ∩ t) = f '' s ∩ f '' t :=
(image_inter_subset _ _ _).antisymm
fun b ⟨⟨a₁, ha₁, h₁⟩, ⟨a₂, ha₂, h₂⟩⟩ ↦
have : a₂ = a₁ := h _ ha₂ _ ha₁ (by simp [*])
⟨a₁, ⟨ha₁, this ▸ ha₂⟩, h₁⟩
#align set.image_inter_on Set.image_inter_on
theorem image_inter {f : α → β} {s t : Set α} (H : Injective f) : f '' (s ∩ t) = f '' s ∩ f '' t :=
image_inter_on fun _ _ _ _ h => H h
#align set.image_inter Set.image_inter
theorem image_univ_of_surjective {ι : Type*} {f : ι → β} (H : Surjective f) : f '' univ = univ :=
eq_univ_of_forall <| by simpa [image]
#align set.image_univ_of_surjective Set.image_univ_of_surjective
@[simp]
theorem image_singleton {f : α → β} {a : α} : f '' {a} = {f a} := by
ext
simp [image, eq_comm]
#align set.image_singleton Set.image_singleton
@[simp]
theorem Nonempty.image_const {s : Set α} (hs : s.Nonempty) (a : β) : (fun _ => a) '' s = {a} :=
ext fun _ =>
⟨fun ⟨_, _, h⟩ => h ▸ mem_singleton _, fun h =>
(eq_of_mem_singleton h).symm ▸ hs.imp fun _ hy => ⟨hy, rfl⟩⟩
#align set.nonempty.image_const Set.Nonempty.image_const
@[simp, mfld_simps]
theorem image_eq_empty {α β} {f : α → β} {s : Set α} : f '' s = ∅ ↔ s = ∅ := by
simp only [eq_empty_iff_forall_not_mem]
exact ⟨fun H a ha => H _ ⟨_, ha, rfl⟩, fun H b ⟨_, ha, _⟩ => H _ ha⟩
#align set.image_eq_empty Set.image_eq_empty
-- Porting note: `compl` is already defined in `Init.Set`
theorem preimage_compl_eq_image_compl [BooleanAlgebra α] (S : Set α) :
HasCompl.compl ⁻¹' S = HasCompl.compl '' S :=
Set.ext fun x =>
⟨fun h => ⟨xᶜ, h, compl_compl x⟩, fun h =>
Exists.elim h fun _ hy => (compl_eq_comm.mp hy.2).symm.subst hy.1⟩
#align set.preimage_compl_eq_image_compl Set.preimage_compl_eq_image_compl
theorem mem_compl_image [BooleanAlgebra α] (t : α) (S : Set α) :
t ∈ HasCompl.compl '' S ↔ tᶜ ∈ S := by
simp [← preimage_compl_eq_image_compl]
#align set.mem_compl_image Set.mem_compl_image
@[simp]
theorem image_id_eq : image (id : α → α) = id := by ext;
|
simp
|
@[simp]
theorem image_id_eq : image (id : α → α) = id := by ext;
|
Mathlib.Data.Set.Image.400_0.IJFiTzmYGOCpPSd
|
@[simp]
theorem image_id_eq : image (id : α → α) = id
|
Mathlib_Data_Set_Image
|
α : Type u_1
β : Type u_2
γ : Type u_3
ι : Sort u_4
ι' : Sort u_5
f : α → β
s✝ t s : Set α
⊢ (fun x => x) '' s = s
|
/-
Copyright (c) 2014 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Leonardo de Moura
-/
import Mathlib.Data.Set.Basic
#align_import data.set.image from "leanprover-community/mathlib"@"001ffdc42920050657fd45bd2b8bfbec8eaaeb29"
/-!
# Images and preimages of sets
## Main definitions
* `preimage f t : Set α` : the preimage f⁻¹(t) (written `f ⁻¹' t` in Lean) of a subset of β.
* `range f : Set β` : the image of `univ` under `f`.
Also works for `{p : Prop} (f : p → α)` (unlike `image`)
## Notation
* `f ⁻¹' t` for `Set.preimage f t`
* `f '' s` for `Set.image f s`
## Tags
set, sets, image, preimage, pre-image, range
-/
set_option autoImplicit true
universe u v
open Function Set
namespace Set
variable {α β γ : Type*} {ι ι' : Sort*}
/-! ### Inverse image -/
/-- The preimage of `s : Set β` by `f : α → β`, written `f ⁻¹' s`,
is the set of `x : α` such that `f x ∈ s`. -/
def preimage {α : Type u} {β : Type v} (f : α → β) (s : Set β) : Set α :=
{ x | f x ∈ s }
#align set.preimage Set.preimage
/-- `f ⁻¹' t` denotes the preimage of `t : Set β` under the function `f : α → β`. -/
infixl:80 " ⁻¹' " => preimage
section Preimage
variable {f : α → β} {g : β → γ}
@[simp]
theorem preimage_empty : f ⁻¹' ∅ = ∅ :=
rfl
#align set.preimage_empty Set.preimage_empty
@[simp, mfld_simps]
theorem mem_preimage {s : Set β} {a : α} : a ∈ f ⁻¹' s ↔ f a ∈ s :=
Iff.rfl
#align set.mem_preimage Set.mem_preimage
theorem preimage_congr {f g : α → β} {s : Set β} (h : ∀ x : α, f x = g x) : f ⁻¹' s = g ⁻¹' s := by
congr with x
simp [h]
#align set.preimage_congr Set.preimage_congr
@[gcongr]
theorem preimage_mono {s t : Set β} (h : s ⊆ t) : f ⁻¹' s ⊆ f ⁻¹' t := fun _ hx => h hx
#align set.preimage_mono Set.preimage_mono
@[simp, mfld_simps]
theorem preimage_univ : f ⁻¹' univ = univ :=
rfl
#align set.preimage_univ Set.preimage_univ
theorem subset_preimage_univ {s : Set α} : s ⊆ f ⁻¹' univ :=
subset_univ _
#align set.subset_preimage_univ Set.subset_preimage_univ
@[simp, mfld_simps]
theorem preimage_inter {s t : Set β} : f ⁻¹' (s ∩ t) = f ⁻¹' s ∩ f ⁻¹' t :=
rfl
#align set.preimage_inter Set.preimage_inter
@[simp]
theorem preimage_union {s t : Set β} : f ⁻¹' (s ∪ t) = f ⁻¹' s ∪ f ⁻¹' t :=
rfl
#align set.preimage_union Set.preimage_union
@[simp]
theorem preimage_compl {s : Set β} : f ⁻¹' sᶜ = (f ⁻¹' s)ᶜ :=
rfl
#align set.preimage_compl Set.preimage_compl
@[simp]
theorem preimage_diff (f : α → β) (s t : Set β) : f ⁻¹' (s \ t) = f ⁻¹' s \ f ⁻¹' t :=
rfl
#align set.preimage_diff Set.preimage_diff
@[simp]
lemma preimage_symmDiff {f : α → β} (s t : Set β) : f ⁻¹' (s ∆ t) = (f ⁻¹' s) ∆ (f ⁻¹' t) :=
rfl
#align set.preimage_symm_diff Set.preimage_symmDiff
@[simp]
theorem preimage_ite (f : α → β) (s t₁ t₂ : Set β) :
f ⁻¹' s.ite t₁ t₂ = (f ⁻¹' s).ite (f ⁻¹' t₁) (f ⁻¹' t₂) :=
rfl
#align set.preimage_ite Set.preimage_ite
@[simp]
theorem preimage_setOf_eq {p : α → Prop} {f : β → α} : f ⁻¹' { a | p a } = { a | p (f a) } :=
rfl
#align set.preimage_set_of_eq Set.preimage_setOf_eq
@[simp]
theorem preimage_id_eq : preimage (id : α → α) = id :=
rfl
#align set.preimage_id_eq Set.preimage_id_eq
@[mfld_simps]
theorem preimage_id {s : Set α} : id ⁻¹' s = s :=
rfl
#align set.preimage_id Set.preimage_id
@[simp, mfld_simps]
theorem preimage_id' {s : Set α} : (fun x => x) ⁻¹' s = s :=
rfl
#align set.preimage_id' Set.preimage_id'
@[simp]
theorem preimage_const_of_mem {b : β} {s : Set β} (h : b ∈ s) : (fun _ : α => b) ⁻¹' s = univ :=
eq_univ_of_forall fun _ => h
#align set.preimage_const_of_mem Set.preimage_const_of_mem
@[simp]
theorem preimage_const_of_not_mem {b : β} {s : Set β} (h : b ∉ s) : (fun _ : α => b) ⁻¹' s = ∅ :=
eq_empty_of_subset_empty fun _ hx => h hx
#align set.preimage_const_of_not_mem Set.preimage_const_of_not_mem
theorem preimage_const (b : β) (s : Set β) [Decidable (b ∈ s)] :
(fun _ : α => b) ⁻¹' s = if b ∈ s then univ else ∅ := by
split_ifs with hb
exacts [preimage_const_of_mem hb, preimage_const_of_not_mem hb]
#align set.preimage_const Set.preimage_const
/-- If preimage of each singleton under `f : α → β` is either empty or the whole type,
then `f` is a constant. -/
lemma exists_eq_const_of_preimage_singleton [Nonempty β] {f : α → β}
(hf : ∀ b : β, f ⁻¹' {b} = ∅ ∨ f ⁻¹' {b} = univ) : ∃ b, f = const α b := by
rcases em (∃ b, f ⁻¹' {b} = univ) with ⟨b, hb⟩ | hf'
· exact ⟨b, funext fun x ↦ eq_univ_iff_forall.1 hb x⟩
· have : ∀ x b, f x ≠ b := fun x b ↦
eq_empty_iff_forall_not_mem.1 ((hf b).resolve_right fun h ↦ hf' ⟨b, h⟩) x
exact ⟨Classical.arbitrary β, funext fun x ↦ absurd rfl (this x _)⟩
theorem preimage_comp {s : Set γ} : g ∘ f ⁻¹' s = f ⁻¹' (g ⁻¹' s) :=
rfl
#align set.preimage_comp Set.preimage_comp
theorem preimage_comp_eq : preimage (g ∘ f) = preimage f ∘ preimage g :=
rfl
#align set.preimage_comp_eq Set.preimage_comp_eq
theorem preimage_iterate_eq {f : α → α} {n : ℕ} : Set.preimage f^[n] = (Set.preimage f)^[n] := by
induction' n with n ih; · simp
rw [iterate_succ, iterate_succ', preimage_comp_eq, ih]
#align set.preimage_iterate_eq Set.preimage_iterate_eq
theorem preimage_preimage {g : β → γ} {f : α → β} {s : Set γ} :
f ⁻¹' (g ⁻¹' s) = (fun x => g (f x)) ⁻¹' s :=
preimage_comp.symm
#align set.preimage_preimage Set.preimage_preimage
theorem eq_preimage_subtype_val_iff {p : α → Prop} {s : Set (Subtype p)} {t : Set α} :
s = Subtype.val ⁻¹' t ↔ ∀ (x) (h : p x), (⟨x, h⟩ : Subtype p) ∈ s ↔ x ∈ t :=
⟨fun s_eq x h => by
rw [s_eq]
simp, fun h => ext fun ⟨x, hx⟩ => by simp [h]⟩
#align set.eq_preimage_subtype_val_iff Set.eq_preimage_subtype_val_iff
theorem nonempty_of_nonempty_preimage {s : Set β} {f : α → β} (hf : (f ⁻¹' s).Nonempty) :
s.Nonempty :=
let ⟨x, hx⟩ := hf
⟨f x, hx⟩
#align set.nonempty_of_nonempty_preimage Set.nonempty_of_nonempty_preimage
@[simp] theorem preimage_singleton_true (p : α → Prop) : p ⁻¹' {True} = {a | p a} := by ext; simp
#align set.preimage_singleton_true Set.preimage_singleton_true
@[simp] theorem preimage_singleton_false (p : α → Prop) : p ⁻¹' {False} = {a | ¬p a} := by ext; simp
#align set.preimage_singleton_false Set.preimage_singleton_false
theorem preimage_subtype_coe_eq_compl {s u v : Set α} (hsuv : s ⊆ u ∪ v)
(H : s ∩ (u ∩ v) = ∅) : ((↑) : s → α) ⁻¹' u = ((↑) ⁻¹' v)ᶜ := by
ext ⟨x, x_in_s⟩
constructor
· intro x_in_u x_in_v
exact eq_empty_iff_forall_not_mem.mp H x ⟨x_in_s, ⟨x_in_u, x_in_v⟩⟩
· intro hx
exact Or.elim (hsuv x_in_s) id fun hx' => hx.elim hx'
#align set.preimage_subtype_coe_eq_compl Set.preimage_subtype_coe_eq_compl
end Preimage
/-! ### Image of a set under a function -/
section Image
variable {f : α → β} {s t : Set α}
-- Porting note: `Set.image` is already defined in `Init.Set`
#align set.image Set.image
/-- `f '' s` denotes the image of `s : Set α` under the function `f : α → β`. -/
infixl:80 " '' " => image
theorem mem_image_iff_bex {f : α → β} {s : Set α} {y : β} :
y ∈ f '' s ↔ ∃ (x : _) (_ : x ∈ s), f x = y :=
bex_def.symm
#align set.mem_image_iff_bex Set.mem_image_iff_bex
@[simp]
theorem mem_image (f : α → β) (s : Set α) (y : β) : y ∈ f '' s ↔ ∃ x ∈ s, f x = y :=
Iff.rfl
#align set.mem_image Set.mem_image
theorem image_eta (f : α → β) : f '' s = (fun x => f x) '' s :=
rfl
#align set.image_eta Set.image_eta
@[mfld_simps]
theorem mem_image_of_mem (f : α → β) {x : α} {a : Set α} (h : x ∈ a) : f x ∈ f '' a :=
⟨_, h, rfl⟩
#align set.mem_image_of_mem Set.mem_image_of_mem
theorem _root_.Function.Injective.mem_set_image {f : α → β} (hf : Injective f) {s : Set α} {a : α} :
f a ∈ f '' s ↔ a ∈ s :=
⟨fun ⟨_, hb, Eq⟩ => hf Eq ▸ hb, mem_image_of_mem f⟩
#align function.injective.mem_set_image Function.Injective.mem_set_image
theorem ball_image_iff {f : α → β} {s : Set α} {p : β → Prop} :
(∀ y ∈ f '' s, p y) ↔ ∀ x ∈ s, p (f x) := by simp
#align set.ball_image_iff Set.ball_image_iff
theorem ball_image_of_ball {f : α → β} {s : Set α} {p : β → Prop} (h : ∀ x ∈ s, p (f x)) :
∀ y ∈ f '' s, p y :=
ball_image_iff.2 h
#align set.ball_image_of_ball Set.ball_image_of_ball
theorem bex_image_iff {f : α → β} {s : Set α} {p : β → Prop} :
(∃ y ∈ f '' s, p y) ↔ ∃ x ∈ s, p (f x) := by simp
#align set.bex_image_iff Set.bex_image_iff
theorem mem_image_elim {f : α → β} {s : Set α} {C : β → Prop} (h : ∀ x : α, x ∈ s → C (f x)) :
∀ {y : β}, y ∈ f '' s → C y
| _, ⟨a, a_in, rfl⟩ => h a a_in
#align set.mem_image_elim Set.mem_image_elim
theorem mem_image_elim_on {f : α → β} {s : Set α} {C : β → Prop} {y : β} (h_y : y ∈ f '' s)
(h : ∀ x : α, x ∈ s → C (f x)) : C y :=
mem_image_elim h h_y
#align set.mem_image_elim_on Set.mem_image_elim_on
-- Porting note: used to be `safe`
@[congr]
theorem image_congr {f g : α → β} {s : Set α} (h : ∀ a ∈ s, f a = g a) : f '' s = g '' s := by
ext x
rw [mem_image, mem_image]
exact {
mp := by
rintro ⟨a, ha1, ha2⟩
exact ⟨a, ⟨ha1, (h a ha1) ▸ ha2⟩⟩,
mpr := by
rintro ⟨a, ha1, ha2⟩
exact ⟨a, ⟨ha1, (h a ha1) ▸ ha2⟩⟩
}
-- safe [ext_iff, iff_def]
#align set.image_congr Set.image_congr
/-- A common special case of `image_congr` -/
theorem image_congr' {f g : α → β} {s : Set α} (h : ∀ x : α, f x = g x) : f '' s = g '' s :=
image_congr fun x _ => h x
#align set.image_congr' Set.image_congr'
@[gcongr]
lemma image_mono (h : s ⊆ t) : f '' s ⊆ f '' t := by
rintro - ⟨a, ha, rfl⟩; exact mem_image_of_mem f (h ha)
theorem image_comp (f : β → γ) (g : α → β) (a : Set α) : f ∘ g '' a = f '' (g '' a) :=
Subset.antisymm (ball_image_of_ball fun _ ha => mem_image_of_mem _ <| mem_image_of_mem _ ha)
(ball_image_of_ball <| ball_image_of_ball fun _ ha => mem_image_of_mem _ ha)
#align set.image_comp Set.image_comp
theorem image_comp_eq {g : β → γ} : image (g ∘ f) = image g ∘ image f := by ext; simp
/-- A variant of `image_comp`, useful for rewriting -/
theorem image_image (g : β → γ) (f : α → β) (s : Set α) : g '' (f '' s) = (fun x => g (f x)) '' s :=
(image_comp g f s).symm
#align set.image_image Set.image_image
theorem image_comm {β'} {f : β → γ} {g : α → β} {f' : α → β'} {g' : β' → γ}
(h_comm : ∀ a, f (g a) = g' (f' a)) : (s.image g).image f = (s.image f').image g' := by
simp_rw [image_image, h_comm]
#align set.image_comm Set.image_comm
theorem _root_.Function.Semiconj.set_image {f : α → β} {ga : α → α} {gb : β → β}
(h : Function.Semiconj f ga gb) : Function.Semiconj (image f) (image ga) (image gb) := fun _ =>
image_comm h
#align function.semiconj.set_image Function.Semiconj.set_image
theorem _root_.Function.Commute.set_image {f g : α → α} (h : Function.Commute f g) :
Function.Commute (image f) (image g) :=
Function.Semiconj.set_image h
#align function.commute.set_image Function.Commute.set_image
/-- Image is monotone with respect to `⊆`. See `Set.monotone_image` for the statement in
terms of `≤`. -/
@[gcongr]
theorem image_subset {a b : Set α} (f : α → β) (h : a ⊆ b) : f '' a ⊆ f '' b := by
simp only [subset_def, mem_image]
exact fun x => fun ⟨w, h1, h2⟩ => ⟨w, h h1, h2⟩
#align set.image_subset Set.image_subset
/-- `Set.image` is monotone. See `Set.image_subset` for the statement in terms of `⊆`. -/
lemma monotone_image {f : α → β} : Monotone (image f) := fun _ _ => image_subset _
#align set.monotone_image Set.monotone_image
theorem image_union (f : α → β) (s t : Set α) : f '' (s ∪ t) = f '' s ∪ f '' t :=
ext fun x =>
⟨by rintro ⟨a, h | h, rfl⟩ <;> [left; right] <;> exact ⟨_, h, rfl⟩, by
rintro (⟨a, h, rfl⟩ | ⟨a, h, rfl⟩) <;> refine' ⟨_, _, rfl⟩ <;> [left; right] <;> exact h⟩
#align set.image_union Set.image_union
@[simp]
theorem image_empty (f : α → β) : f '' ∅ = ∅ := by
ext
simp
#align set.image_empty Set.image_empty
theorem image_inter_subset (f : α → β) (s t : Set α) : f '' (s ∩ t) ⊆ f '' s ∩ f '' t :=
subset_inter (image_subset _ <| inter_subset_left _ _) (image_subset _ <| inter_subset_right _ _)
#align set.image_inter_subset Set.image_inter_subset
theorem image_inter_on {f : α → β} {s t : Set α} (h : ∀ x ∈ t, ∀ y ∈ s, f x = f y → x = y) :
f '' (s ∩ t) = f '' s ∩ f '' t :=
(image_inter_subset _ _ _).antisymm
fun b ⟨⟨a₁, ha₁, h₁⟩, ⟨a₂, ha₂, h₂⟩⟩ ↦
have : a₂ = a₁ := h _ ha₂ _ ha₁ (by simp [*])
⟨a₁, ⟨ha₁, this ▸ ha₂⟩, h₁⟩
#align set.image_inter_on Set.image_inter_on
theorem image_inter {f : α → β} {s t : Set α} (H : Injective f) : f '' (s ∩ t) = f '' s ∩ f '' t :=
image_inter_on fun _ _ _ _ h => H h
#align set.image_inter Set.image_inter
theorem image_univ_of_surjective {ι : Type*} {f : ι → β} (H : Surjective f) : f '' univ = univ :=
eq_univ_of_forall <| by simpa [image]
#align set.image_univ_of_surjective Set.image_univ_of_surjective
@[simp]
theorem image_singleton {f : α → β} {a : α} : f '' {a} = {f a} := by
ext
simp [image, eq_comm]
#align set.image_singleton Set.image_singleton
@[simp]
theorem Nonempty.image_const {s : Set α} (hs : s.Nonempty) (a : β) : (fun _ => a) '' s = {a} :=
ext fun _ =>
⟨fun ⟨_, _, h⟩ => h ▸ mem_singleton _, fun h =>
(eq_of_mem_singleton h).symm ▸ hs.imp fun _ hy => ⟨hy, rfl⟩⟩
#align set.nonempty.image_const Set.Nonempty.image_const
@[simp, mfld_simps]
theorem image_eq_empty {α β} {f : α → β} {s : Set α} : f '' s = ∅ ↔ s = ∅ := by
simp only [eq_empty_iff_forall_not_mem]
exact ⟨fun H a ha => H _ ⟨_, ha, rfl⟩, fun H b ⟨_, ha, _⟩ => H _ ha⟩
#align set.image_eq_empty Set.image_eq_empty
-- Porting note: `compl` is already defined in `Init.Set`
theorem preimage_compl_eq_image_compl [BooleanAlgebra α] (S : Set α) :
HasCompl.compl ⁻¹' S = HasCompl.compl '' S :=
Set.ext fun x =>
⟨fun h => ⟨xᶜ, h, compl_compl x⟩, fun h =>
Exists.elim h fun _ hy => (compl_eq_comm.mp hy.2).symm.subst hy.1⟩
#align set.preimage_compl_eq_image_compl Set.preimage_compl_eq_image_compl
theorem mem_compl_image [BooleanAlgebra α] (t : α) (S : Set α) :
t ∈ HasCompl.compl '' S ↔ tᶜ ∈ S := by
simp [← preimage_compl_eq_image_compl]
#align set.mem_compl_image Set.mem_compl_image
@[simp]
theorem image_id_eq : image (id : α → α) = id := by ext; simp
/-- A variant of `image_id` -/
@[simp]
theorem image_id' (s : Set α) : (fun x => x) '' s = s := by
|
ext
|
/-- A variant of `image_id` -/
@[simp]
theorem image_id' (s : Set α) : (fun x => x) '' s = s := by
|
Mathlib.Data.Set.Image.403_0.IJFiTzmYGOCpPSd
|
/-- A variant of `image_id` -/
@[simp]
theorem image_id' (s : Set α) : (fun x => x) '' s = s
|
Mathlib_Data_Set_Image
|
case h
α : Type u_1
β : Type u_2
γ : Type u_3
ι : Sort u_4
ι' : Sort u_5
f : α → β
s✝ t s : Set α
x✝ : α
⊢ x✝ ∈ (fun x => x) '' s ↔ x✝ ∈ s
|
/-
Copyright (c) 2014 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Leonardo de Moura
-/
import Mathlib.Data.Set.Basic
#align_import data.set.image from "leanprover-community/mathlib"@"001ffdc42920050657fd45bd2b8bfbec8eaaeb29"
/-!
# Images and preimages of sets
## Main definitions
* `preimage f t : Set α` : the preimage f⁻¹(t) (written `f ⁻¹' t` in Lean) of a subset of β.
* `range f : Set β` : the image of `univ` under `f`.
Also works for `{p : Prop} (f : p → α)` (unlike `image`)
## Notation
* `f ⁻¹' t` for `Set.preimage f t`
* `f '' s` for `Set.image f s`
## Tags
set, sets, image, preimage, pre-image, range
-/
set_option autoImplicit true
universe u v
open Function Set
namespace Set
variable {α β γ : Type*} {ι ι' : Sort*}
/-! ### Inverse image -/
/-- The preimage of `s : Set β` by `f : α → β`, written `f ⁻¹' s`,
is the set of `x : α` such that `f x ∈ s`. -/
def preimage {α : Type u} {β : Type v} (f : α → β) (s : Set β) : Set α :=
{ x | f x ∈ s }
#align set.preimage Set.preimage
/-- `f ⁻¹' t` denotes the preimage of `t : Set β` under the function `f : α → β`. -/
infixl:80 " ⁻¹' " => preimage
section Preimage
variable {f : α → β} {g : β → γ}
@[simp]
theorem preimage_empty : f ⁻¹' ∅ = ∅ :=
rfl
#align set.preimage_empty Set.preimage_empty
@[simp, mfld_simps]
theorem mem_preimage {s : Set β} {a : α} : a ∈ f ⁻¹' s ↔ f a ∈ s :=
Iff.rfl
#align set.mem_preimage Set.mem_preimage
theorem preimage_congr {f g : α → β} {s : Set β} (h : ∀ x : α, f x = g x) : f ⁻¹' s = g ⁻¹' s := by
congr with x
simp [h]
#align set.preimage_congr Set.preimage_congr
@[gcongr]
theorem preimage_mono {s t : Set β} (h : s ⊆ t) : f ⁻¹' s ⊆ f ⁻¹' t := fun _ hx => h hx
#align set.preimage_mono Set.preimage_mono
@[simp, mfld_simps]
theorem preimage_univ : f ⁻¹' univ = univ :=
rfl
#align set.preimage_univ Set.preimage_univ
theorem subset_preimage_univ {s : Set α} : s ⊆ f ⁻¹' univ :=
subset_univ _
#align set.subset_preimage_univ Set.subset_preimage_univ
@[simp, mfld_simps]
theorem preimage_inter {s t : Set β} : f ⁻¹' (s ∩ t) = f ⁻¹' s ∩ f ⁻¹' t :=
rfl
#align set.preimage_inter Set.preimage_inter
@[simp]
theorem preimage_union {s t : Set β} : f ⁻¹' (s ∪ t) = f ⁻¹' s ∪ f ⁻¹' t :=
rfl
#align set.preimage_union Set.preimage_union
@[simp]
theorem preimage_compl {s : Set β} : f ⁻¹' sᶜ = (f ⁻¹' s)ᶜ :=
rfl
#align set.preimage_compl Set.preimage_compl
@[simp]
theorem preimage_diff (f : α → β) (s t : Set β) : f ⁻¹' (s \ t) = f ⁻¹' s \ f ⁻¹' t :=
rfl
#align set.preimage_diff Set.preimage_diff
@[simp]
lemma preimage_symmDiff {f : α → β} (s t : Set β) : f ⁻¹' (s ∆ t) = (f ⁻¹' s) ∆ (f ⁻¹' t) :=
rfl
#align set.preimage_symm_diff Set.preimage_symmDiff
@[simp]
theorem preimage_ite (f : α → β) (s t₁ t₂ : Set β) :
f ⁻¹' s.ite t₁ t₂ = (f ⁻¹' s).ite (f ⁻¹' t₁) (f ⁻¹' t₂) :=
rfl
#align set.preimage_ite Set.preimage_ite
@[simp]
theorem preimage_setOf_eq {p : α → Prop} {f : β → α} : f ⁻¹' { a | p a } = { a | p (f a) } :=
rfl
#align set.preimage_set_of_eq Set.preimage_setOf_eq
@[simp]
theorem preimage_id_eq : preimage (id : α → α) = id :=
rfl
#align set.preimage_id_eq Set.preimage_id_eq
@[mfld_simps]
theorem preimage_id {s : Set α} : id ⁻¹' s = s :=
rfl
#align set.preimage_id Set.preimage_id
@[simp, mfld_simps]
theorem preimage_id' {s : Set α} : (fun x => x) ⁻¹' s = s :=
rfl
#align set.preimage_id' Set.preimage_id'
@[simp]
theorem preimage_const_of_mem {b : β} {s : Set β} (h : b ∈ s) : (fun _ : α => b) ⁻¹' s = univ :=
eq_univ_of_forall fun _ => h
#align set.preimage_const_of_mem Set.preimage_const_of_mem
@[simp]
theorem preimage_const_of_not_mem {b : β} {s : Set β} (h : b ∉ s) : (fun _ : α => b) ⁻¹' s = ∅ :=
eq_empty_of_subset_empty fun _ hx => h hx
#align set.preimage_const_of_not_mem Set.preimage_const_of_not_mem
theorem preimage_const (b : β) (s : Set β) [Decidable (b ∈ s)] :
(fun _ : α => b) ⁻¹' s = if b ∈ s then univ else ∅ := by
split_ifs with hb
exacts [preimage_const_of_mem hb, preimage_const_of_not_mem hb]
#align set.preimage_const Set.preimage_const
/-- If preimage of each singleton under `f : α → β` is either empty or the whole type,
then `f` is a constant. -/
lemma exists_eq_const_of_preimage_singleton [Nonempty β] {f : α → β}
(hf : ∀ b : β, f ⁻¹' {b} = ∅ ∨ f ⁻¹' {b} = univ) : ∃ b, f = const α b := by
rcases em (∃ b, f ⁻¹' {b} = univ) with ⟨b, hb⟩ | hf'
· exact ⟨b, funext fun x ↦ eq_univ_iff_forall.1 hb x⟩
· have : ∀ x b, f x ≠ b := fun x b ↦
eq_empty_iff_forall_not_mem.1 ((hf b).resolve_right fun h ↦ hf' ⟨b, h⟩) x
exact ⟨Classical.arbitrary β, funext fun x ↦ absurd rfl (this x _)⟩
theorem preimage_comp {s : Set γ} : g ∘ f ⁻¹' s = f ⁻¹' (g ⁻¹' s) :=
rfl
#align set.preimage_comp Set.preimage_comp
theorem preimage_comp_eq : preimage (g ∘ f) = preimage f ∘ preimage g :=
rfl
#align set.preimage_comp_eq Set.preimage_comp_eq
theorem preimage_iterate_eq {f : α → α} {n : ℕ} : Set.preimage f^[n] = (Set.preimage f)^[n] := by
induction' n with n ih; · simp
rw [iterate_succ, iterate_succ', preimage_comp_eq, ih]
#align set.preimage_iterate_eq Set.preimage_iterate_eq
theorem preimage_preimage {g : β → γ} {f : α → β} {s : Set γ} :
f ⁻¹' (g ⁻¹' s) = (fun x => g (f x)) ⁻¹' s :=
preimage_comp.symm
#align set.preimage_preimage Set.preimage_preimage
theorem eq_preimage_subtype_val_iff {p : α → Prop} {s : Set (Subtype p)} {t : Set α} :
s = Subtype.val ⁻¹' t ↔ ∀ (x) (h : p x), (⟨x, h⟩ : Subtype p) ∈ s ↔ x ∈ t :=
⟨fun s_eq x h => by
rw [s_eq]
simp, fun h => ext fun ⟨x, hx⟩ => by simp [h]⟩
#align set.eq_preimage_subtype_val_iff Set.eq_preimage_subtype_val_iff
theorem nonempty_of_nonempty_preimage {s : Set β} {f : α → β} (hf : (f ⁻¹' s).Nonempty) :
s.Nonempty :=
let ⟨x, hx⟩ := hf
⟨f x, hx⟩
#align set.nonempty_of_nonempty_preimage Set.nonempty_of_nonempty_preimage
@[simp] theorem preimage_singleton_true (p : α → Prop) : p ⁻¹' {True} = {a | p a} := by ext; simp
#align set.preimage_singleton_true Set.preimage_singleton_true
@[simp] theorem preimage_singleton_false (p : α → Prop) : p ⁻¹' {False} = {a | ¬p a} := by ext; simp
#align set.preimage_singleton_false Set.preimage_singleton_false
theorem preimage_subtype_coe_eq_compl {s u v : Set α} (hsuv : s ⊆ u ∪ v)
(H : s ∩ (u ∩ v) = ∅) : ((↑) : s → α) ⁻¹' u = ((↑) ⁻¹' v)ᶜ := by
ext ⟨x, x_in_s⟩
constructor
· intro x_in_u x_in_v
exact eq_empty_iff_forall_not_mem.mp H x ⟨x_in_s, ⟨x_in_u, x_in_v⟩⟩
· intro hx
exact Or.elim (hsuv x_in_s) id fun hx' => hx.elim hx'
#align set.preimage_subtype_coe_eq_compl Set.preimage_subtype_coe_eq_compl
end Preimage
/-! ### Image of a set under a function -/
section Image
variable {f : α → β} {s t : Set α}
-- Porting note: `Set.image` is already defined in `Init.Set`
#align set.image Set.image
/-- `f '' s` denotes the image of `s : Set α` under the function `f : α → β`. -/
infixl:80 " '' " => image
theorem mem_image_iff_bex {f : α → β} {s : Set α} {y : β} :
y ∈ f '' s ↔ ∃ (x : _) (_ : x ∈ s), f x = y :=
bex_def.symm
#align set.mem_image_iff_bex Set.mem_image_iff_bex
@[simp]
theorem mem_image (f : α → β) (s : Set α) (y : β) : y ∈ f '' s ↔ ∃ x ∈ s, f x = y :=
Iff.rfl
#align set.mem_image Set.mem_image
theorem image_eta (f : α → β) : f '' s = (fun x => f x) '' s :=
rfl
#align set.image_eta Set.image_eta
@[mfld_simps]
theorem mem_image_of_mem (f : α → β) {x : α} {a : Set α} (h : x ∈ a) : f x ∈ f '' a :=
⟨_, h, rfl⟩
#align set.mem_image_of_mem Set.mem_image_of_mem
theorem _root_.Function.Injective.mem_set_image {f : α → β} (hf : Injective f) {s : Set α} {a : α} :
f a ∈ f '' s ↔ a ∈ s :=
⟨fun ⟨_, hb, Eq⟩ => hf Eq ▸ hb, mem_image_of_mem f⟩
#align function.injective.mem_set_image Function.Injective.mem_set_image
theorem ball_image_iff {f : α → β} {s : Set α} {p : β → Prop} :
(∀ y ∈ f '' s, p y) ↔ ∀ x ∈ s, p (f x) := by simp
#align set.ball_image_iff Set.ball_image_iff
theorem ball_image_of_ball {f : α → β} {s : Set α} {p : β → Prop} (h : ∀ x ∈ s, p (f x)) :
∀ y ∈ f '' s, p y :=
ball_image_iff.2 h
#align set.ball_image_of_ball Set.ball_image_of_ball
theorem bex_image_iff {f : α → β} {s : Set α} {p : β → Prop} :
(∃ y ∈ f '' s, p y) ↔ ∃ x ∈ s, p (f x) := by simp
#align set.bex_image_iff Set.bex_image_iff
theorem mem_image_elim {f : α → β} {s : Set α} {C : β → Prop} (h : ∀ x : α, x ∈ s → C (f x)) :
∀ {y : β}, y ∈ f '' s → C y
| _, ⟨a, a_in, rfl⟩ => h a a_in
#align set.mem_image_elim Set.mem_image_elim
theorem mem_image_elim_on {f : α → β} {s : Set α} {C : β → Prop} {y : β} (h_y : y ∈ f '' s)
(h : ∀ x : α, x ∈ s → C (f x)) : C y :=
mem_image_elim h h_y
#align set.mem_image_elim_on Set.mem_image_elim_on
-- Porting note: used to be `safe`
@[congr]
theorem image_congr {f g : α → β} {s : Set α} (h : ∀ a ∈ s, f a = g a) : f '' s = g '' s := by
ext x
rw [mem_image, mem_image]
exact {
mp := by
rintro ⟨a, ha1, ha2⟩
exact ⟨a, ⟨ha1, (h a ha1) ▸ ha2⟩⟩,
mpr := by
rintro ⟨a, ha1, ha2⟩
exact ⟨a, ⟨ha1, (h a ha1) ▸ ha2⟩⟩
}
-- safe [ext_iff, iff_def]
#align set.image_congr Set.image_congr
/-- A common special case of `image_congr` -/
theorem image_congr' {f g : α → β} {s : Set α} (h : ∀ x : α, f x = g x) : f '' s = g '' s :=
image_congr fun x _ => h x
#align set.image_congr' Set.image_congr'
@[gcongr]
lemma image_mono (h : s ⊆ t) : f '' s ⊆ f '' t := by
rintro - ⟨a, ha, rfl⟩; exact mem_image_of_mem f (h ha)
theorem image_comp (f : β → γ) (g : α → β) (a : Set α) : f ∘ g '' a = f '' (g '' a) :=
Subset.antisymm (ball_image_of_ball fun _ ha => mem_image_of_mem _ <| mem_image_of_mem _ ha)
(ball_image_of_ball <| ball_image_of_ball fun _ ha => mem_image_of_mem _ ha)
#align set.image_comp Set.image_comp
theorem image_comp_eq {g : β → γ} : image (g ∘ f) = image g ∘ image f := by ext; simp
/-- A variant of `image_comp`, useful for rewriting -/
theorem image_image (g : β → γ) (f : α → β) (s : Set α) : g '' (f '' s) = (fun x => g (f x)) '' s :=
(image_comp g f s).symm
#align set.image_image Set.image_image
theorem image_comm {β'} {f : β → γ} {g : α → β} {f' : α → β'} {g' : β' → γ}
(h_comm : ∀ a, f (g a) = g' (f' a)) : (s.image g).image f = (s.image f').image g' := by
simp_rw [image_image, h_comm]
#align set.image_comm Set.image_comm
theorem _root_.Function.Semiconj.set_image {f : α → β} {ga : α → α} {gb : β → β}
(h : Function.Semiconj f ga gb) : Function.Semiconj (image f) (image ga) (image gb) := fun _ =>
image_comm h
#align function.semiconj.set_image Function.Semiconj.set_image
theorem _root_.Function.Commute.set_image {f g : α → α} (h : Function.Commute f g) :
Function.Commute (image f) (image g) :=
Function.Semiconj.set_image h
#align function.commute.set_image Function.Commute.set_image
/-- Image is monotone with respect to `⊆`. See `Set.monotone_image` for the statement in
terms of `≤`. -/
@[gcongr]
theorem image_subset {a b : Set α} (f : α → β) (h : a ⊆ b) : f '' a ⊆ f '' b := by
simp only [subset_def, mem_image]
exact fun x => fun ⟨w, h1, h2⟩ => ⟨w, h h1, h2⟩
#align set.image_subset Set.image_subset
/-- `Set.image` is monotone. See `Set.image_subset` for the statement in terms of `⊆`. -/
lemma monotone_image {f : α → β} : Monotone (image f) := fun _ _ => image_subset _
#align set.monotone_image Set.monotone_image
theorem image_union (f : α → β) (s t : Set α) : f '' (s ∪ t) = f '' s ∪ f '' t :=
ext fun x =>
⟨by rintro ⟨a, h | h, rfl⟩ <;> [left; right] <;> exact ⟨_, h, rfl⟩, by
rintro (⟨a, h, rfl⟩ | ⟨a, h, rfl⟩) <;> refine' ⟨_, _, rfl⟩ <;> [left; right] <;> exact h⟩
#align set.image_union Set.image_union
@[simp]
theorem image_empty (f : α → β) : f '' ∅ = ∅ := by
ext
simp
#align set.image_empty Set.image_empty
theorem image_inter_subset (f : α → β) (s t : Set α) : f '' (s ∩ t) ⊆ f '' s ∩ f '' t :=
subset_inter (image_subset _ <| inter_subset_left _ _) (image_subset _ <| inter_subset_right _ _)
#align set.image_inter_subset Set.image_inter_subset
theorem image_inter_on {f : α → β} {s t : Set α} (h : ∀ x ∈ t, ∀ y ∈ s, f x = f y → x = y) :
f '' (s ∩ t) = f '' s ∩ f '' t :=
(image_inter_subset _ _ _).antisymm
fun b ⟨⟨a₁, ha₁, h₁⟩, ⟨a₂, ha₂, h₂⟩⟩ ↦
have : a₂ = a₁ := h _ ha₂ _ ha₁ (by simp [*])
⟨a₁, ⟨ha₁, this ▸ ha₂⟩, h₁⟩
#align set.image_inter_on Set.image_inter_on
theorem image_inter {f : α → β} {s t : Set α} (H : Injective f) : f '' (s ∩ t) = f '' s ∩ f '' t :=
image_inter_on fun _ _ _ _ h => H h
#align set.image_inter Set.image_inter
theorem image_univ_of_surjective {ι : Type*} {f : ι → β} (H : Surjective f) : f '' univ = univ :=
eq_univ_of_forall <| by simpa [image]
#align set.image_univ_of_surjective Set.image_univ_of_surjective
@[simp]
theorem image_singleton {f : α → β} {a : α} : f '' {a} = {f a} := by
ext
simp [image, eq_comm]
#align set.image_singleton Set.image_singleton
@[simp]
theorem Nonempty.image_const {s : Set α} (hs : s.Nonempty) (a : β) : (fun _ => a) '' s = {a} :=
ext fun _ =>
⟨fun ⟨_, _, h⟩ => h ▸ mem_singleton _, fun h =>
(eq_of_mem_singleton h).symm ▸ hs.imp fun _ hy => ⟨hy, rfl⟩⟩
#align set.nonempty.image_const Set.Nonempty.image_const
@[simp, mfld_simps]
theorem image_eq_empty {α β} {f : α → β} {s : Set α} : f '' s = ∅ ↔ s = ∅ := by
simp only [eq_empty_iff_forall_not_mem]
exact ⟨fun H a ha => H _ ⟨_, ha, rfl⟩, fun H b ⟨_, ha, _⟩ => H _ ha⟩
#align set.image_eq_empty Set.image_eq_empty
-- Porting note: `compl` is already defined in `Init.Set`
theorem preimage_compl_eq_image_compl [BooleanAlgebra α] (S : Set α) :
HasCompl.compl ⁻¹' S = HasCompl.compl '' S :=
Set.ext fun x =>
⟨fun h => ⟨xᶜ, h, compl_compl x⟩, fun h =>
Exists.elim h fun _ hy => (compl_eq_comm.mp hy.2).symm.subst hy.1⟩
#align set.preimage_compl_eq_image_compl Set.preimage_compl_eq_image_compl
theorem mem_compl_image [BooleanAlgebra α] (t : α) (S : Set α) :
t ∈ HasCompl.compl '' S ↔ tᶜ ∈ S := by
simp [← preimage_compl_eq_image_compl]
#align set.mem_compl_image Set.mem_compl_image
@[simp]
theorem image_id_eq : image (id : α → α) = id := by ext; simp
/-- A variant of `image_id` -/
@[simp]
theorem image_id' (s : Set α) : (fun x => x) '' s = s := by
ext
|
simp
|
/-- A variant of `image_id` -/
@[simp]
theorem image_id' (s : Set α) : (fun x => x) '' s = s := by
ext
|
Mathlib.Data.Set.Image.403_0.IJFiTzmYGOCpPSd
|
/-- A variant of `image_id` -/
@[simp]
theorem image_id' (s : Set α) : (fun x => x) '' s = s
|
Mathlib_Data_Set_Image
|
α : Type u_1
β : Type u_2
γ : Type u_3
ι : Sort u_4
ι' : Sort u_5
f : α → β
s✝ t s : Set α
⊢ id '' s = s
|
/-
Copyright (c) 2014 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Leonardo de Moura
-/
import Mathlib.Data.Set.Basic
#align_import data.set.image from "leanprover-community/mathlib"@"001ffdc42920050657fd45bd2b8bfbec8eaaeb29"
/-!
# Images and preimages of sets
## Main definitions
* `preimage f t : Set α` : the preimage f⁻¹(t) (written `f ⁻¹' t` in Lean) of a subset of β.
* `range f : Set β` : the image of `univ` under `f`.
Also works for `{p : Prop} (f : p → α)` (unlike `image`)
## Notation
* `f ⁻¹' t` for `Set.preimage f t`
* `f '' s` for `Set.image f s`
## Tags
set, sets, image, preimage, pre-image, range
-/
set_option autoImplicit true
universe u v
open Function Set
namespace Set
variable {α β γ : Type*} {ι ι' : Sort*}
/-! ### Inverse image -/
/-- The preimage of `s : Set β` by `f : α → β`, written `f ⁻¹' s`,
is the set of `x : α` such that `f x ∈ s`. -/
def preimage {α : Type u} {β : Type v} (f : α → β) (s : Set β) : Set α :=
{ x | f x ∈ s }
#align set.preimage Set.preimage
/-- `f ⁻¹' t` denotes the preimage of `t : Set β` under the function `f : α → β`. -/
infixl:80 " ⁻¹' " => preimage
section Preimage
variable {f : α → β} {g : β → γ}
@[simp]
theorem preimage_empty : f ⁻¹' ∅ = ∅ :=
rfl
#align set.preimage_empty Set.preimage_empty
@[simp, mfld_simps]
theorem mem_preimage {s : Set β} {a : α} : a ∈ f ⁻¹' s ↔ f a ∈ s :=
Iff.rfl
#align set.mem_preimage Set.mem_preimage
theorem preimage_congr {f g : α → β} {s : Set β} (h : ∀ x : α, f x = g x) : f ⁻¹' s = g ⁻¹' s := by
congr with x
simp [h]
#align set.preimage_congr Set.preimage_congr
@[gcongr]
theorem preimage_mono {s t : Set β} (h : s ⊆ t) : f ⁻¹' s ⊆ f ⁻¹' t := fun _ hx => h hx
#align set.preimage_mono Set.preimage_mono
@[simp, mfld_simps]
theorem preimage_univ : f ⁻¹' univ = univ :=
rfl
#align set.preimage_univ Set.preimage_univ
theorem subset_preimage_univ {s : Set α} : s ⊆ f ⁻¹' univ :=
subset_univ _
#align set.subset_preimage_univ Set.subset_preimage_univ
@[simp, mfld_simps]
theorem preimage_inter {s t : Set β} : f ⁻¹' (s ∩ t) = f ⁻¹' s ∩ f ⁻¹' t :=
rfl
#align set.preimage_inter Set.preimage_inter
@[simp]
theorem preimage_union {s t : Set β} : f ⁻¹' (s ∪ t) = f ⁻¹' s ∪ f ⁻¹' t :=
rfl
#align set.preimage_union Set.preimage_union
@[simp]
theorem preimage_compl {s : Set β} : f ⁻¹' sᶜ = (f ⁻¹' s)ᶜ :=
rfl
#align set.preimage_compl Set.preimage_compl
@[simp]
theorem preimage_diff (f : α → β) (s t : Set β) : f ⁻¹' (s \ t) = f ⁻¹' s \ f ⁻¹' t :=
rfl
#align set.preimage_diff Set.preimage_diff
@[simp]
lemma preimage_symmDiff {f : α → β} (s t : Set β) : f ⁻¹' (s ∆ t) = (f ⁻¹' s) ∆ (f ⁻¹' t) :=
rfl
#align set.preimage_symm_diff Set.preimage_symmDiff
@[simp]
theorem preimage_ite (f : α → β) (s t₁ t₂ : Set β) :
f ⁻¹' s.ite t₁ t₂ = (f ⁻¹' s).ite (f ⁻¹' t₁) (f ⁻¹' t₂) :=
rfl
#align set.preimage_ite Set.preimage_ite
@[simp]
theorem preimage_setOf_eq {p : α → Prop} {f : β → α} : f ⁻¹' { a | p a } = { a | p (f a) } :=
rfl
#align set.preimage_set_of_eq Set.preimage_setOf_eq
@[simp]
theorem preimage_id_eq : preimage (id : α → α) = id :=
rfl
#align set.preimage_id_eq Set.preimage_id_eq
@[mfld_simps]
theorem preimage_id {s : Set α} : id ⁻¹' s = s :=
rfl
#align set.preimage_id Set.preimage_id
@[simp, mfld_simps]
theorem preimage_id' {s : Set α} : (fun x => x) ⁻¹' s = s :=
rfl
#align set.preimage_id' Set.preimage_id'
@[simp]
theorem preimage_const_of_mem {b : β} {s : Set β} (h : b ∈ s) : (fun _ : α => b) ⁻¹' s = univ :=
eq_univ_of_forall fun _ => h
#align set.preimage_const_of_mem Set.preimage_const_of_mem
@[simp]
theorem preimage_const_of_not_mem {b : β} {s : Set β} (h : b ∉ s) : (fun _ : α => b) ⁻¹' s = ∅ :=
eq_empty_of_subset_empty fun _ hx => h hx
#align set.preimage_const_of_not_mem Set.preimage_const_of_not_mem
theorem preimage_const (b : β) (s : Set β) [Decidable (b ∈ s)] :
(fun _ : α => b) ⁻¹' s = if b ∈ s then univ else ∅ := by
split_ifs with hb
exacts [preimage_const_of_mem hb, preimage_const_of_not_mem hb]
#align set.preimage_const Set.preimage_const
/-- If preimage of each singleton under `f : α → β` is either empty or the whole type,
then `f` is a constant. -/
lemma exists_eq_const_of_preimage_singleton [Nonempty β] {f : α → β}
(hf : ∀ b : β, f ⁻¹' {b} = ∅ ∨ f ⁻¹' {b} = univ) : ∃ b, f = const α b := by
rcases em (∃ b, f ⁻¹' {b} = univ) with ⟨b, hb⟩ | hf'
· exact ⟨b, funext fun x ↦ eq_univ_iff_forall.1 hb x⟩
· have : ∀ x b, f x ≠ b := fun x b ↦
eq_empty_iff_forall_not_mem.1 ((hf b).resolve_right fun h ↦ hf' ⟨b, h⟩) x
exact ⟨Classical.arbitrary β, funext fun x ↦ absurd rfl (this x _)⟩
theorem preimage_comp {s : Set γ} : g ∘ f ⁻¹' s = f ⁻¹' (g ⁻¹' s) :=
rfl
#align set.preimage_comp Set.preimage_comp
theorem preimage_comp_eq : preimage (g ∘ f) = preimage f ∘ preimage g :=
rfl
#align set.preimage_comp_eq Set.preimage_comp_eq
theorem preimage_iterate_eq {f : α → α} {n : ℕ} : Set.preimage f^[n] = (Set.preimage f)^[n] := by
induction' n with n ih; · simp
rw [iterate_succ, iterate_succ', preimage_comp_eq, ih]
#align set.preimage_iterate_eq Set.preimage_iterate_eq
theorem preimage_preimage {g : β → γ} {f : α → β} {s : Set γ} :
f ⁻¹' (g ⁻¹' s) = (fun x => g (f x)) ⁻¹' s :=
preimage_comp.symm
#align set.preimage_preimage Set.preimage_preimage
theorem eq_preimage_subtype_val_iff {p : α → Prop} {s : Set (Subtype p)} {t : Set α} :
s = Subtype.val ⁻¹' t ↔ ∀ (x) (h : p x), (⟨x, h⟩ : Subtype p) ∈ s ↔ x ∈ t :=
⟨fun s_eq x h => by
rw [s_eq]
simp, fun h => ext fun ⟨x, hx⟩ => by simp [h]⟩
#align set.eq_preimage_subtype_val_iff Set.eq_preimage_subtype_val_iff
theorem nonempty_of_nonempty_preimage {s : Set β} {f : α → β} (hf : (f ⁻¹' s).Nonempty) :
s.Nonempty :=
let ⟨x, hx⟩ := hf
⟨f x, hx⟩
#align set.nonempty_of_nonempty_preimage Set.nonempty_of_nonempty_preimage
@[simp] theorem preimage_singleton_true (p : α → Prop) : p ⁻¹' {True} = {a | p a} := by ext; simp
#align set.preimage_singleton_true Set.preimage_singleton_true
@[simp] theorem preimage_singleton_false (p : α → Prop) : p ⁻¹' {False} = {a | ¬p a} := by ext; simp
#align set.preimage_singleton_false Set.preimage_singleton_false
theorem preimage_subtype_coe_eq_compl {s u v : Set α} (hsuv : s ⊆ u ∪ v)
(H : s ∩ (u ∩ v) = ∅) : ((↑) : s → α) ⁻¹' u = ((↑) ⁻¹' v)ᶜ := by
ext ⟨x, x_in_s⟩
constructor
· intro x_in_u x_in_v
exact eq_empty_iff_forall_not_mem.mp H x ⟨x_in_s, ⟨x_in_u, x_in_v⟩⟩
· intro hx
exact Or.elim (hsuv x_in_s) id fun hx' => hx.elim hx'
#align set.preimage_subtype_coe_eq_compl Set.preimage_subtype_coe_eq_compl
end Preimage
/-! ### Image of a set under a function -/
section Image
variable {f : α → β} {s t : Set α}
-- Porting note: `Set.image` is already defined in `Init.Set`
#align set.image Set.image
/-- `f '' s` denotes the image of `s : Set α` under the function `f : α → β`. -/
infixl:80 " '' " => image
theorem mem_image_iff_bex {f : α → β} {s : Set α} {y : β} :
y ∈ f '' s ↔ ∃ (x : _) (_ : x ∈ s), f x = y :=
bex_def.symm
#align set.mem_image_iff_bex Set.mem_image_iff_bex
@[simp]
theorem mem_image (f : α → β) (s : Set α) (y : β) : y ∈ f '' s ↔ ∃ x ∈ s, f x = y :=
Iff.rfl
#align set.mem_image Set.mem_image
theorem image_eta (f : α → β) : f '' s = (fun x => f x) '' s :=
rfl
#align set.image_eta Set.image_eta
@[mfld_simps]
theorem mem_image_of_mem (f : α → β) {x : α} {a : Set α} (h : x ∈ a) : f x ∈ f '' a :=
⟨_, h, rfl⟩
#align set.mem_image_of_mem Set.mem_image_of_mem
theorem _root_.Function.Injective.mem_set_image {f : α → β} (hf : Injective f) {s : Set α} {a : α} :
f a ∈ f '' s ↔ a ∈ s :=
⟨fun ⟨_, hb, Eq⟩ => hf Eq ▸ hb, mem_image_of_mem f⟩
#align function.injective.mem_set_image Function.Injective.mem_set_image
theorem ball_image_iff {f : α → β} {s : Set α} {p : β → Prop} :
(∀ y ∈ f '' s, p y) ↔ ∀ x ∈ s, p (f x) := by simp
#align set.ball_image_iff Set.ball_image_iff
theorem ball_image_of_ball {f : α → β} {s : Set α} {p : β → Prop} (h : ∀ x ∈ s, p (f x)) :
∀ y ∈ f '' s, p y :=
ball_image_iff.2 h
#align set.ball_image_of_ball Set.ball_image_of_ball
theorem bex_image_iff {f : α → β} {s : Set α} {p : β → Prop} :
(∃ y ∈ f '' s, p y) ↔ ∃ x ∈ s, p (f x) := by simp
#align set.bex_image_iff Set.bex_image_iff
theorem mem_image_elim {f : α → β} {s : Set α} {C : β → Prop} (h : ∀ x : α, x ∈ s → C (f x)) :
∀ {y : β}, y ∈ f '' s → C y
| _, ⟨a, a_in, rfl⟩ => h a a_in
#align set.mem_image_elim Set.mem_image_elim
theorem mem_image_elim_on {f : α → β} {s : Set α} {C : β → Prop} {y : β} (h_y : y ∈ f '' s)
(h : ∀ x : α, x ∈ s → C (f x)) : C y :=
mem_image_elim h h_y
#align set.mem_image_elim_on Set.mem_image_elim_on
-- Porting note: used to be `safe`
@[congr]
theorem image_congr {f g : α → β} {s : Set α} (h : ∀ a ∈ s, f a = g a) : f '' s = g '' s := by
ext x
rw [mem_image, mem_image]
exact {
mp := by
rintro ⟨a, ha1, ha2⟩
exact ⟨a, ⟨ha1, (h a ha1) ▸ ha2⟩⟩,
mpr := by
rintro ⟨a, ha1, ha2⟩
exact ⟨a, ⟨ha1, (h a ha1) ▸ ha2⟩⟩
}
-- safe [ext_iff, iff_def]
#align set.image_congr Set.image_congr
/-- A common special case of `image_congr` -/
theorem image_congr' {f g : α → β} {s : Set α} (h : ∀ x : α, f x = g x) : f '' s = g '' s :=
image_congr fun x _ => h x
#align set.image_congr' Set.image_congr'
@[gcongr]
lemma image_mono (h : s ⊆ t) : f '' s ⊆ f '' t := by
rintro - ⟨a, ha, rfl⟩; exact mem_image_of_mem f (h ha)
theorem image_comp (f : β → γ) (g : α → β) (a : Set α) : f ∘ g '' a = f '' (g '' a) :=
Subset.antisymm (ball_image_of_ball fun _ ha => mem_image_of_mem _ <| mem_image_of_mem _ ha)
(ball_image_of_ball <| ball_image_of_ball fun _ ha => mem_image_of_mem _ ha)
#align set.image_comp Set.image_comp
theorem image_comp_eq {g : β → γ} : image (g ∘ f) = image g ∘ image f := by ext; simp
/-- A variant of `image_comp`, useful for rewriting -/
theorem image_image (g : β → γ) (f : α → β) (s : Set α) : g '' (f '' s) = (fun x => g (f x)) '' s :=
(image_comp g f s).symm
#align set.image_image Set.image_image
theorem image_comm {β'} {f : β → γ} {g : α → β} {f' : α → β'} {g' : β' → γ}
(h_comm : ∀ a, f (g a) = g' (f' a)) : (s.image g).image f = (s.image f').image g' := by
simp_rw [image_image, h_comm]
#align set.image_comm Set.image_comm
theorem _root_.Function.Semiconj.set_image {f : α → β} {ga : α → α} {gb : β → β}
(h : Function.Semiconj f ga gb) : Function.Semiconj (image f) (image ga) (image gb) := fun _ =>
image_comm h
#align function.semiconj.set_image Function.Semiconj.set_image
theorem _root_.Function.Commute.set_image {f g : α → α} (h : Function.Commute f g) :
Function.Commute (image f) (image g) :=
Function.Semiconj.set_image h
#align function.commute.set_image Function.Commute.set_image
/-- Image is monotone with respect to `⊆`. See `Set.monotone_image` for the statement in
terms of `≤`. -/
@[gcongr]
theorem image_subset {a b : Set α} (f : α → β) (h : a ⊆ b) : f '' a ⊆ f '' b := by
simp only [subset_def, mem_image]
exact fun x => fun ⟨w, h1, h2⟩ => ⟨w, h h1, h2⟩
#align set.image_subset Set.image_subset
/-- `Set.image` is monotone. See `Set.image_subset` for the statement in terms of `⊆`. -/
lemma monotone_image {f : α → β} : Monotone (image f) := fun _ _ => image_subset _
#align set.monotone_image Set.monotone_image
theorem image_union (f : α → β) (s t : Set α) : f '' (s ∪ t) = f '' s ∪ f '' t :=
ext fun x =>
⟨by rintro ⟨a, h | h, rfl⟩ <;> [left; right] <;> exact ⟨_, h, rfl⟩, by
rintro (⟨a, h, rfl⟩ | ⟨a, h, rfl⟩) <;> refine' ⟨_, _, rfl⟩ <;> [left; right] <;> exact h⟩
#align set.image_union Set.image_union
@[simp]
theorem image_empty (f : α → β) : f '' ∅ = ∅ := by
ext
simp
#align set.image_empty Set.image_empty
theorem image_inter_subset (f : α → β) (s t : Set α) : f '' (s ∩ t) ⊆ f '' s ∩ f '' t :=
subset_inter (image_subset _ <| inter_subset_left _ _) (image_subset _ <| inter_subset_right _ _)
#align set.image_inter_subset Set.image_inter_subset
theorem image_inter_on {f : α → β} {s t : Set α} (h : ∀ x ∈ t, ∀ y ∈ s, f x = f y → x = y) :
f '' (s ∩ t) = f '' s ∩ f '' t :=
(image_inter_subset _ _ _).antisymm
fun b ⟨⟨a₁, ha₁, h₁⟩, ⟨a₂, ha₂, h₂⟩⟩ ↦
have : a₂ = a₁ := h _ ha₂ _ ha₁ (by simp [*])
⟨a₁, ⟨ha₁, this ▸ ha₂⟩, h₁⟩
#align set.image_inter_on Set.image_inter_on
theorem image_inter {f : α → β} {s t : Set α} (H : Injective f) : f '' (s ∩ t) = f '' s ∩ f '' t :=
image_inter_on fun _ _ _ _ h => H h
#align set.image_inter Set.image_inter
theorem image_univ_of_surjective {ι : Type*} {f : ι → β} (H : Surjective f) : f '' univ = univ :=
eq_univ_of_forall <| by simpa [image]
#align set.image_univ_of_surjective Set.image_univ_of_surjective
@[simp]
theorem image_singleton {f : α → β} {a : α} : f '' {a} = {f a} := by
ext
simp [image, eq_comm]
#align set.image_singleton Set.image_singleton
@[simp]
theorem Nonempty.image_const {s : Set α} (hs : s.Nonempty) (a : β) : (fun _ => a) '' s = {a} :=
ext fun _ =>
⟨fun ⟨_, _, h⟩ => h ▸ mem_singleton _, fun h =>
(eq_of_mem_singleton h).symm ▸ hs.imp fun _ hy => ⟨hy, rfl⟩⟩
#align set.nonempty.image_const Set.Nonempty.image_const
@[simp, mfld_simps]
theorem image_eq_empty {α β} {f : α → β} {s : Set α} : f '' s = ∅ ↔ s = ∅ := by
simp only [eq_empty_iff_forall_not_mem]
exact ⟨fun H a ha => H _ ⟨_, ha, rfl⟩, fun H b ⟨_, ha, _⟩ => H _ ha⟩
#align set.image_eq_empty Set.image_eq_empty
-- Porting note: `compl` is already defined in `Init.Set`
theorem preimage_compl_eq_image_compl [BooleanAlgebra α] (S : Set α) :
HasCompl.compl ⁻¹' S = HasCompl.compl '' S :=
Set.ext fun x =>
⟨fun h => ⟨xᶜ, h, compl_compl x⟩, fun h =>
Exists.elim h fun _ hy => (compl_eq_comm.mp hy.2).symm.subst hy.1⟩
#align set.preimage_compl_eq_image_compl Set.preimage_compl_eq_image_compl
theorem mem_compl_image [BooleanAlgebra α] (t : α) (S : Set α) :
t ∈ HasCompl.compl '' S ↔ tᶜ ∈ S := by
simp [← preimage_compl_eq_image_compl]
#align set.mem_compl_image Set.mem_compl_image
@[simp]
theorem image_id_eq : image (id : α → α) = id := by ext; simp
/-- A variant of `image_id` -/
@[simp]
theorem image_id' (s : Set α) : (fun x => x) '' s = s := by
ext
simp
#align set.image_id' Set.image_id'
theorem image_id (s : Set α) : id '' s = s := by
|
simp
|
theorem image_id (s : Set α) : id '' s = s := by
|
Mathlib.Data.Set.Image.410_0.IJFiTzmYGOCpPSd
|
theorem image_id (s : Set α) : id '' s = s
|
Mathlib_Data_Set_Image
|
α : Type u_1
β : Type u_2
γ : Type u_3
ι : Sort u_4
ι' : Sort u_5
f✝ : α → β
s t : Set α
f : α → α
n : ℕ
⊢ image f^[n] = (image f)^[n]
|
/-
Copyright (c) 2014 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Leonardo de Moura
-/
import Mathlib.Data.Set.Basic
#align_import data.set.image from "leanprover-community/mathlib"@"001ffdc42920050657fd45bd2b8bfbec8eaaeb29"
/-!
# Images and preimages of sets
## Main definitions
* `preimage f t : Set α` : the preimage f⁻¹(t) (written `f ⁻¹' t` in Lean) of a subset of β.
* `range f : Set β` : the image of `univ` under `f`.
Also works for `{p : Prop} (f : p → α)` (unlike `image`)
## Notation
* `f ⁻¹' t` for `Set.preimage f t`
* `f '' s` for `Set.image f s`
## Tags
set, sets, image, preimage, pre-image, range
-/
set_option autoImplicit true
universe u v
open Function Set
namespace Set
variable {α β γ : Type*} {ι ι' : Sort*}
/-! ### Inverse image -/
/-- The preimage of `s : Set β` by `f : α → β`, written `f ⁻¹' s`,
is the set of `x : α` such that `f x ∈ s`. -/
def preimage {α : Type u} {β : Type v} (f : α → β) (s : Set β) : Set α :=
{ x | f x ∈ s }
#align set.preimage Set.preimage
/-- `f ⁻¹' t` denotes the preimage of `t : Set β` under the function `f : α → β`. -/
infixl:80 " ⁻¹' " => preimage
section Preimage
variable {f : α → β} {g : β → γ}
@[simp]
theorem preimage_empty : f ⁻¹' ∅ = ∅ :=
rfl
#align set.preimage_empty Set.preimage_empty
@[simp, mfld_simps]
theorem mem_preimage {s : Set β} {a : α} : a ∈ f ⁻¹' s ↔ f a ∈ s :=
Iff.rfl
#align set.mem_preimage Set.mem_preimage
theorem preimage_congr {f g : α → β} {s : Set β} (h : ∀ x : α, f x = g x) : f ⁻¹' s = g ⁻¹' s := by
congr with x
simp [h]
#align set.preimage_congr Set.preimage_congr
@[gcongr]
theorem preimage_mono {s t : Set β} (h : s ⊆ t) : f ⁻¹' s ⊆ f ⁻¹' t := fun _ hx => h hx
#align set.preimage_mono Set.preimage_mono
@[simp, mfld_simps]
theorem preimage_univ : f ⁻¹' univ = univ :=
rfl
#align set.preimage_univ Set.preimage_univ
theorem subset_preimage_univ {s : Set α} : s ⊆ f ⁻¹' univ :=
subset_univ _
#align set.subset_preimage_univ Set.subset_preimage_univ
@[simp, mfld_simps]
theorem preimage_inter {s t : Set β} : f ⁻¹' (s ∩ t) = f ⁻¹' s ∩ f ⁻¹' t :=
rfl
#align set.preimage_inter Set.preimage_inter
@[simp]
theorem preimage_union {s t : Set β} : f ⁻¹' (s ∪ t) = f ⁻¹' s ∪ f ⁻¹' t :=
rfl
#align set.preimage_union Set.preimage_union
@[simp]
theorem preimage_compl {s : Set β} : f ⁻¹' sᶜ = (f ⁻¹' s)ᶜ :=
rfl
#align set.preimage_compl Set.preimage_compl
@[simp]
theorem preimage_diff (f : α → β) (s t : Set β) : f ⁻¹' (s \ t) = f ⁻¹' s \ f ⁻¹' t :=
rfl
#align set.preimage_diff Set.preimage_diff
@[simp]
lemma preimage_symmDiff {f : α → β} (s t : Set β) : f ⁻¹' (s ∆ t) = (f ⁻¹' s) ∆ (f ⁻¹' t) :=
rfl
#align set.preimage_symm_diff Set.preimage_symmDiff
@[simp]
theorem preimage_ite (f : α → β) (s t₁ t₂ : Set β) :
f ⁻¹' s.ite t₁ t₂ = (f ⁻¹' s).ite (f ⁻¹' t₁) (f ⁻¹' t₂) :=
rfl
#align set.preimage_ite Set.preimage_ite
@[simp]
theorem preimage_setOf_eq {p : α → Prop} {f : β → α} : f ⁻¹' { a | p a } = { a | p (f a) } :=
rfl
#align set.preimage_set_of_eq Set.preimage_setOf_eq
@[simp]
theorem preimage_id_eq : preimage (id : α → α) = id :=
rfl
#align set.preimage_id_eq Set.preimage_id_eq
@[mfld_simps]
theorem preimage_id {s : Set α} : id ⁻¹' s = s :=
rfl
#align set.preimage_id Set.preimage_id
@[simp, mfld_simps]
theorem preimage_id' {s : Set α} : (fun x => x) ⁻¹' s = s :=
rfl
#align set.preimage_id' Set.preimage_id'
@[simp]
theorem preimage_const_of_mem {b : β} {s : Set β} (h : b ∈ s) : (fun _ : α => b) ⁻¹' s = univ :=
eq_univ_of_forall fun _ => h
#align set.preimage_const_of_mem Set.preimage_const_of_mem
@[simp]
theorem preimage_const_of_not_mem {b : β} {s : Set β} (h : b ∉ s) : (fun _ : α => b) ⁻¹' s = ∅ :=
eq_empty_of_subset_empty fun _ hx => h hx
#align set.preimage_const_of_not_mem Set.preimage_const_of_not_mem
theorem preimage_const (b : β) (s : Set β) [Decidable (b ∈ s)] :
(fun _ : α => b) ⁻¹' s = if b ∈ s then univ else ∅ := by
split_ifs with hb
exacts [preimage_const_of_mem hb, preimage_const_of_not_mem hb]
#align set.preimage_const Set.preimage_const
/-- If preimage of each singleton under `f : α → β` is either empty or the whole type,
then `f` is a constant. -/
lemma exists_eq_const_of_preimage_singleton [Nonempty β] {f : α → β}
(hf : ∀ b : β, f ⁻¹' {b} = ∅ ∨ f ⁻¹' {b} = univ) : ∃ b, f = const α b := by
rcases em (∃ b, f ⁻¹' {b} = univ) with ⟨b, hb⟩ | hf'
· exact ⟨b, funext fun x ↦ eq_univ_iff_forall.1 hb x⟩
· have : ∀ x b, f x ≠ b := fun x b ↦
eq_empty_iff_forall_not_mem.1 ((hf b).resolve_right fun h ↦ hf' ⟨b, h⟩) x
exact ⟨Classical.arbitrary β, funext fun x ↦ absurd rfl (this x _)⟩
theorem preimage_comp {s : Set γ} : g ∘ f ⁻¹' s = f ⁻¹' (g ⁻¹' s) :=
rfl
#align set.preimage_comp Set.preimage_comp
theorem preimage_comp_eq : preimage (g ∘ f) = preimage f ∘ preimage g :=
rfl
#align set.preimage_comp_eq Set.preimage_comp_eq
theorem preimage_iterate_eq {f : α → α} {n : ℕ} : Set.preimage f^[n] = (Set.preimage f)^[n] := by
induction' n with n ih; · simp
rw [iterate_succ, iterate_succ', preimage_comp_eq, ih]
#align set.preimage_iterate_eq Set.preimage_iterate_eq
theorem preimage_preimage {g : β → γ} {f : α → β} {s : Set γ} :
f ⁻¹' (g ⁻¹' s) = (fun x => g (f x)) ⁻¹' s :=
preimage_comp.symm
#align set.preimage_preimage Set.preimage_preimage
theorem eq_preimage_subtype_val_iff {p : α → Prop} {s : Set (Subtype p)} {t : Set α} :
s = Subtype.val ⁻¹' t ↔ ∀ (x) (h : p x), (⟨x, h⟩ : Subtype p) ∈ s ↔ x ∈ t :=
⟨fun s_eq x h => by
rw [s_eq]
simp, fun h => ext fun ⟨x, hx⟩ => by simp [h]⟩
#align set.eq_preimage_subtype_val_iff Set.eq_preimage_subtype_val_iff
theorem nonempty_of_nonempty_preimage {s : Set β} {f : α → β} (hf : (f ⁻¹' s).Nonempty) :
s.Nonempty :=
let ⟨x, hx⟩ := hf
⟨f x, hx⟩
#align set.nonempty_of_nonempty_preimage Set.nonempty_of_nonempty_preimage
@[simp] theorem preimage_singleton_true (p : α → Prop) : p ⁻¹' {True} = {a | p a} := by ext; simp
#align set.preimage_singleton_true Set.preimage_singleton_true
@[simp] theorem preimage_singleton_false (p : α → Prop) : p ⁻¹' {False} = {a | ¬p a} := by ext; simp
#align set.preimage_singleton_false Set.preimage_singleton_false
theorem preimage_subtype_coe_eq_compl {s u v : Set α} (hsuv : s ⊆ u ∪ v)
(H : s ∩ (u ∩ v) = ∅) : ((↑) : s → α) ⁻¹' u = ((↑) ⁻¹' v)ᶜ := by
ext ⟨x, x_in_s⟩
constructor
· intro x_in_u x_in_v
exact eq_empty_iff_forall_not_mem.mp H x ⟨x_in_s, ⟨x_in_u, x_in_v⟩⟩
· intro hx
exact Or.elim (hsuv x_in_s) id fun hx' => hx.elim hx'
#align set.preimage_subtype_coe_eq_compl Set.preimage_subtype_coe_eq_compl
end Preimage
/-! ### Image of a set under a function -/
section Image
variable {f : α → β} {s t : Set α}
-- Porting note: `Set.image` is already defined in `Init.Set`
#align set.image Set.image
/-- `f '' s` denotes the image of `s : Set α` under the function `f : α → β`. -/
infixl:80 " '' " => image
theorem mem_image_iff_bex {f : α → β} {s : Set α} {y : β} :
y ∈ f '' s ↔ ∃ (x : _) (_ : x ∈ s), f x = y :=
bex_def.symm
#align set.mem_image_iff_bex Set.mem_image_iff_bex
@[simp]
theorem mem_image (f : α → β) (s : Set α) (y : β) : y ∈ f '' s ↔ ∃ x ∈ s, f x = y :=
Iff.rfl
#align set.mem_image Set.mem_image
theorem image_eta (f : α → β) : f '' s = (fun x => f x) '' s :=
rfl
#align set.image_eta Set.image_eta
@[mfld_simps]
theorem mem_image_of_mem (f : α → β) {x : α} {a : Set α} (h : x ∈ a) : f x ∈ f '' a :=
⟨_, h, rfl⟩
#align set.mem_image_of_mem Set.mem_image_of_mem
theorem _root_.Function.Injective.mem_set_image {f : α → β} (hf : Injective f) {s : Set α} {a : α} :
f a ∈ f '' s ↔ a ∈ s :=
⟨fun ⟨_, hb, Eq⟩ => hf Eq ▸ hb, mem_image_of_mem f⟩
#align function.injective.mem_set_image Function.Injective.mem_set_image
theorem ball_image_iff {f : α → β} {s : Set α} {p : β → Prop} :
(∀ y ∈ f '' s, p y) ↔ ∀ x ∈ s, p (f x) := by simp
#align set.ball_image_iff Set.ball_image_iff
theorem ball_image_of_ball {f : α → β} {s : Set α} {p : β → Prop} (h : ∀ x ∈ s, p (f x)) :
∀ y ∈ f '' s, p y :=
ball_image_iff.2 h
#align set.ball_image_of_ball Set.ball_image_of_ball
theorem bex_image_iff {f : α → β} {s : Set α} {p : β → Prop} :
(∃ y ∈ f '' s, p y) ↔ ∃ x ∈ s, p (f x) := by simp
#align set.bex_image_iff Set.bex_image_iff
theorem mem_image_elim {f : α → β} {s : Set α} {C : β → Prop} (h : ∀ x : α, x ∈ s → C (f x)) :
∀ {y : β}, y ∈ f '' s → C y
| _, ⟨a, a_in, rfl⟩ => h a a_in
#align set.mem_image_elim Set.mem_image_elim
theorem mem_image_elim_on {f : α → β} {s : Set α} {C : β → Prop} {y : β} (h_y : y ∈ f '' s)
(h : ∀ x : α, x ∈ s → C (f x)) : C y :=
mem_image_elim h h_y
#align set.mem_image_elim_on Set.mem_image_elim_on
-- Porting note: used to be `safe`
@[congr]
theorem image_congr {f g : α → β} {s : Set α} (h : ∀ a ∈ s, f a = g a) : f '' s = g '' s := by
ext x
rw [mem_image, mem_image]
exact {
mp := by
rintro ⟨a, ha1, ha2⟩
exact ⟨a, ⟨ha1, (h a ha1) ▸ ha2⟩⟩,
mpr := by
rintro ⟨a, ha1, ha2⟩
exact ⟨a, ⟨ha1, (h a ha1) ▸ ha2⟩⟩
}
-- safe [ext_iff, iff_def]
#align set.image_congr Set.image_congr
/-- A common special case of `image_congr` -/
theorem image_congr' {f g : α → β} {s : Set α} (h : ∀ x : α, f x = g x) : f '' s = g '' s :=
image_congr fun x _ => h x
#align set.image_congr' Set.image_congr'
@[gcongr]
lemma image_mono (h : s ⊆ t) : f '' s ⊆ f '' t := by
rintro - ⟨a, ha, rfl⟩; exact mem_image_of_mem f (h ha)
theorem image_comp (f : β → γ) (g : α → β) (a : Set α) : f ∘ g '' a = f '' (g '' a) :=
Subset.antisymm (ball_image_of_ball fun _ ha => mem_image_of_mem _ <| mem_image_of_mem _ ha)
(ball_image_of_ball <| ball_image_of_ball fun _ ha => mem_image_of_mem _ ha)
#align set.image_comp Set.image_comp
theorem image_comp_eq {g : β → γ} : image (g ∘ f) = image g ∘ image f := by ext; simp
/-- A variant of `image_comp`, useful for rewriting -/
theorem image_image (g : β → γ) (f : α → β) (s : Set α) : g '' (f '' s) = (fun x => g (f x)) '' s :=
(image_comp g f s).symm
#align set.image_image Set.image_image
theorem image_comm {β'} {f : β → γ} {g : α → β} {f' : α → β'} {g' : β' → γ}
(h_comm : ∀ a, f (g a) = g' (f' a)) : (s.image g).image f = (s.image f').image g' := by
simp_rw [image_image, h_comm]
#align set.image_comm Set.image_comm
theorem _root_.Function.Semiconj.set_image {f : α → β} {ga : α → α} {gb : β → β}
(h : Function.Semiconj f ga gb) : Function.Semiconj (image f) (image ga) (image gb) := fun _ =>
image_comm h
#align function.semiconj.set_image Function.Semiconj.set_image
theorem _root_.Function.Commute.set_image {f g : α → α} (h : Function.Commute f g) :
Function.Commute (image f) (image g) :=
Function.Semiconj.set_image h
#align function.commute.set_image Function.Commute.set_image
/-- Image is monotone with respect to `⊆`. See `Set.monotone_image` for the statement in
terms of `≤`. -/
@[gcongr]
theorem image_subset {a b : Set α} (f : α → β) (h : a ⊆ b) : f '' a ⊆ f '' b := by
simp only [subset_def, mem_image]
exact fun x => fun ⟨w, h1, h2⟩ => ⟨w, h h1, h2⟩
#align set.image_subset Set.image_subset
/-- `Set.image` is monotone. See `Set.image_subset` for the statement in terms of `⊆`. -/
lemma monotone_image {f : α → β} : Monotone (image f) := fun _ _ => image_subset _
#align set.monotone_image Set.monotone_image
theorem image_union (f : α → β) (s t : Set α) : f '' (s ∪ t) = f '' s ∪ f '' t :=
ext fun x =>
⟨by rintro ⟨a, h | h, rfl⟩ <;> [left; right] <;> exact ⟨_, h, rfl⟩, by
rintro (⟨a, h, rfl⟩ | ⟨a, h, rfl⟩) <;> refine' ⟨_, _, rfl⟩ <;> [left; right] <;> exact h⟩
#align set.image_union Set.image_union
@[simp]
theorem image_empty (f : α → β) : f '' ∅ = ∅ := by
ext
simp
#align set.image_empty Set.image_empty
theorem image_inter_subset (f : α → β) (s t : Set α) : f '' (s ∩ t) ⊆ f '' s ∩ f '' t :=
subset_inter (image_subset _ <| inter_subset_left _ _) (image_subset _ <| inter_subset_right _ _)
#align set.image_inter_subset Set.image_inter_subset
theorem image_inter_on {f : α → β} {s t : Set α} (h : ∀ x ∈ t, ∀ y ∈ s, f x = f y → x = y) :
f '' (s ∩ t) = f '' s ∩ f '' t :=
(image_inter_subset _ _ _).antisymm
fun b ⟨⟨a₁, ha₁, h₁⟩, ⟨a₂, ha₂, h₂⟩⟩ ↦
have : a₂ = a₁ := h _ ha₂ _ ha₁ (by simp [*])
⟨a₁, ⟨ha₁, this ▸ ha₂⟩, h₁⟩
#align set.image_inter_on Set.image_inter_on
theorem image_inter {f : α → β} {s t : Set α} (H : Injective f) : f '' (s ∩ t) = f '' s ∩ f '' t :=
image_inter_on fun _ _ _ _ h => H h
#align set.image_inter Set.image_inter
theorem image_univ_of_surjective {ι : Type*} {f : ι → β} (H : Surjective f) : f '' univ = univ :=
eq_univ_of_forall <| by simpa [image]
#align set.image_univ_of_surjective Set.image_univ_of_surjective
@[simp]
theorem image_singleton {f : α → β} {a : α} : f '' {a} = {f a} := by
ext
simp [image, eq_comm]
#align set.image_singleton Set.image_singleton
@[simp]
theorem Nonempty.image_const {s : Set α} (hs : s.Nonempty) (a : β) : (fun _ => a) '' s = {a} :=
ext fun _ =>
⟨fun ⟨_, _, h⟩ => h ▸ mem_singleton _, fun h =>
(eq_of_mem_singleton h).symm ▸ hs.imp fun _ hy => ⟨hy, rfl⟩⟩
#align set.nonempty.image_const Set.Nonempty.image_const
@[simp, mfld_simps]
theorem image_eq_empty {α β} {f : α → β} {s : Set α} : f '' s = ∅ ↔ s = ∅ := by
simp only [eq_empty_iff_forall_not_mem]
exact ⟨fun H a ha => H _ ⟨_, ha, rfl⟩, fun H b ⟨_, ha, _⟩ => H _ ha⟩
#align set.image_eq_empty Set.image_eq_empty
-- Porting note: `compl` is already defined in `Init.Set`
theorem preimage_compl_eq_image_compl [BooleanAlgebra α] (S : Set α) :
HasCompl.compl ⁻¹' S = HasCompl.compl '' S :=
Set.ext fun x =>
⟨fun h => ⟨xᶜ, h, compl_compl x⟩, fun h =>
Exists.elim h fun _ hy => (compl_eq_comm.mp hy.2).symm.subst hy.1⟩
#align set.preimage_compl_eq_image_compl Set.preimage_compl_eq_image_compl
theorem mem_compl_image [BooleanAlgebra α] (t : α) (S : Set α) :
t ∈ HasCompl.compl '' S ↔ tᶜ ∈ S := by
simp [← preimage_compl_eq_image_compl]
#align set.mem_compl_image Set.mem_compl_image
@[simp]
theorem image_id_eq : image (id : α → α) = id := by ext; simp
/-- A variant of `image_id` -/
@[simp]
theorem image_id' (s : Set α) : (fun x => x) '' s = s := by
ext
simp
#align set.image_id' Set.image_id'
theorem image_id (s : Set α) : id '' s = s := by simp
#align set.image_id Set.image_id
lemma image_iterate_eq {f : α → α} {n : ℕ} : image (f^[n]) = (image f)^[n] := by
|
induction' n with n ih
|
lemma image_iterate_eq {f : α → α} {n : ℕ} : image (f^[n]) = (image f)^[n] := by
|
Mathlib.Data.Set.Image.413_0.IJFiTzmYGOCpPSd
|
lemma image_iterate_eq {f : α → α} {n : ℕ} : image (f^[n]) = (image f)^[n]
|
Mathlib_Data_Set_Image
|
case zero
α : Type u_1
β : Type u_2
γ : Type u_3
ι : Sort u_4
ι' : Sort u_5
f✝ : α → β
s t : Set α
f : α → α
⊢ image f^[Nat.zero] = (image f)^[Nat.zero]
|
/-
Copyright (c) 2014 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Leonardo de Moura
-/
import Mathlib.Data.Set.Basic
#align_import data.set.image from "leanprover-community/mathlib"@"001ffdc42920050657fd45bd2b8bfbec8eaaeb29"
/-!
# Images and preimages of sets
## Main definitions
* `preimage f t : Set α` : the preimage f⁻¹(t) (written `f ⁻¹' t` in Lean) of a subset of β.
* `range f : Set β` : the image of `univ` under `f`.
Also works for `{p : Prop} (f : p → α)` (unlike `image`)
## Notation
* `f ⁻¹' t` for `Set.preimage f t`
* `f '' s` for `Set.image f s`
## Tags
set, sets, image, preimage, pre-image, range
-/
set_option autoImplicit true
universe u v
open Function Set
namespace Set
variable {α β γ : Type*} {ι ι' : Sort*}
/-! ### Inverse image -/
/-- The preimage of `s : Set β` by `f : α → β`, written `f ⁻¹' s`,
is the set of `x : α` such that `f x ∈ s`. -/
def preimage {α : Type u} {β : Type v} (f : α → β) (s : Set β) : Set α :=
{ x | f x ∈ s }
#align set.preimage Set.preimage
/-- `f ⁻¹' t` denotes the preimage of `t : Set β` under the function `f : α → β`. -/
infixl:80 " ⁻¹' " => preimage
section Preimage
variable {f : α → β} {g : β → γ}
@[simp]
theorem preimage_empty : f ⁻¹' ∅ = ∅ :=
rfl
#align set.preimage_empty Set.preimage_empty
@[simp, mfld_simps]
theorem mem_preimage {s : Set β} {a : α} : a ∈ f ⁻¹' s ↔ f a ∈ s :=
Iff.rfl
#align set.mem_preimage Set.mem_preimage
theorem preimage_congr {f g : α → β} {s : Set β} (h : ∀ x : α, f x = g x) : f ⁻¹' s = g ⁻¹' s := by
congr with x
simp [h]
#align set.preimage_congr Set.preimage_congr
@[gcongr]
theorem preimage_mono {s t : Set β} (h : s ⊆ t) : f ⁻¹' s ⊆ f ⁻¹' t := fun _ hx => h hx
#align set.preimage_mono Set.preimage_mono
@[simp, mfld_simps]
theorem preimage_univ : f ⁻¹' univ = univ :=
rfl
#align set.preimage_univ Set.preimage_univ
theorem subset_preimage_univ {s : Set α} : s ⊆ f ⁻¹' univ :=
subset_univ _
#align set.subset_preimage_univ Set.subset_preimage_univ
@[simp, mfld_simps]
theorem preimage_inter {s t : Set β} : f ⁻¹' (s ∩ t) = f ⁻¹' s ∩ f ⁻¹' t :=
rfl
#align set.preimage_inter Set.preimage_inter
@[simp]
theorem preimage_union {s t : Set β} : f ⁻¹' (s ∪ t) = f ⁻¹' s ∪ f ⁻¹' t :=
rfl
#align set.preimage_union Set.preimage_union
@[simp]
theorem preimage_compl {s : Set β} : f ⁻¹' sᶜ = (f ⁻¹' s)ᶜ :=
rfl
#align set.preimage_compl Set.preimage_compl
@[simp]
theorem preimage_diff (f : α → β) (s t : Set β) : f ⁻¹' (s \ t) = f ⁻¹' s \ f ⁻¹' t :=
rfl
#align set.preimage_diff Set.preimage_diff
@[simp]
lemma preimage_symmDiff {f : α → β} (s t : Set β) : f ⁻¹' (s ∆ t) = (f ⁻¹' s) ∆ (f ⁻¹' t) :=
rfl
#align set.preimage_symm_diff Set.preimage_symmDiff
@[simp]
theorem preimage_ite (f : α → β) (s t₁ t₂ : Set β) :
f ⁻¹' s.ite t₁ t₂ = (f ⁻¹' s).ite (f ⁻¹' t₁) (f ⁻¹' t₂) :=
rfl
#align set.preimage_ite Set.preimage_ite
@[simp]
theorem preimage_setOf_eq {p : α → Prop} {f : β → α} : f ⁻¹' { a | p a } = { a | p (f a) } :=
rfl
#align set.preimage_set_of_eq Set.preimage_setOf_eq
@[simp]
theorem preimage_id_eq : preimage (id : α → α) = id :=
rfl
#align set.preimage_id_eq Set.preimage_id_eq
@[mfld_simps]
theorem preimage_id {s : Set α} : id ⁻¹' s = s :=
rfl
#align set.preimage_id Set.preimage_id
@[simp, mfld_simps]
theorem preimage_id' {s : Set α} : (fun x => x) ⁻¹' s = s :=
rfl
#align set.preimage_id' Set.preimage_id'
@[simp]
theorem preimage_const_of_mem {b : β} {s : Set β} (h : b ∈ s) : (fun _ : α => b) ⁻¹' s = univ :=
eq_univ_of_forall fun _ => h
#align set.preimage_const_of_mem Set.preimage_const_of_mem
@[simp]
theorem preimage_const_of_not_mem {b : β} {s : Set β} (h : b ∉ s) : (fun _ : α => b) ⁻¹' s = ∅ :=
eq_empty_of_subset_empty fun _ hx => h hx
#align set.preimage_const_of_not_mem Set.preimage_const_of_not_mem
theorem preimage_const (b : β) (s : Set β) [Decidable (b ∈ s)] :
(fun _ : α => b) ⁻¹' s = if b ∈ s then univ else ∅ := by
split_ifs with hb
exacts [preimage_const_of_mem hb, preimage_const_of_not_mem hb]
#align set.preimage_const Set.preimage_const
/-- If preimage of each singleton under `f : α → β` is either empty or the whole type,
then `f` is a constant. -/
lemma exists_eq_const_of_preimage_singleton [Nonempty β] {f : α → β}
(hf : ∀ b : β, f ⁻¹' {b} = ∅ ∨ f ⁻¹' {b} = univ) : ∃ b, f = const α b := by
rcases em (∃ b, f ⁻¹' {b} = univ) with ⟨b, hb⟩ | hf'
· exact ⟨b, funext fun x ↦ eq_univ_iff_forall.1 hb x⟩
· have : ∀ x b, f x ≠ b := fun x b ↦
eq_empty_iff_forall_not_mem.1 ((hf b).resolve_right fun h ↦ hf' ⟨b, h⟩) x
exact ⟨Classical.arbitrary β, funext fun x ↦ absurd rfl (this x _)⟩
theorem preimage_comp {s : Set γ} : g ∘ f ⁻¹' s = f ⁻¹' (g ⁻¹' s) :=
rfl
#align set.preimage_comp Set.preimage_comp
theorem preimage_comp_eq : preimage (g ∘ f) = preimage f ∘ preimage g :=
rfl
#align set.preimage_comp_eq Set.preimage_comp_eq
theorem preimage_iterate_eq {f : α → α} {n : ℕ} : Set.preimage f^[n] = (Set.preimage f)^[n] := by
induction' n with n ih; · simp
rw [iterate_succ, iterate_succ', preimage_comp_eq, ih]
#align set.preimage_iterate_eq Set.preimage_iterate_eq
theorem preimage_preimage {g : β → γ} {f : α → β} {s : Set γ} :
f ⁻¹' (g ⁻¹' s) = (fun x => g (f x)) ⁻¹' s :=
preimage_comp.symm
#align set.preimage_preimage Set.preimage_preimage
theorem eq_preimage_subtype_val_iff {p : α → Prop} {s : Set (Subtype p)} {t : Set α} :
s = Subtype.val ⁻¹' t ↔ ∀ (x) (h : p x), (⟨x, h⟩ : Subtype p) ∈ s ↔ x ∈ t :=
⟨fun s_eq x h => by
rw [s_eq]
simp, fun h => ext fun ⟨x, hx⟩ => by simp [h]⟩
#align set.eq_preimage_subtype_val_iff Set.eq_preimage_subtype_val_iff
theorem nonempty_of_nonempty_preimage {s : Set β} {f : α → β} (hf : (f ⁻¹' s).Nonempty) :
s.Nonempty :=
let ⟨x, hx⟩ := hf
⟨f x, hx⟩
#align set.nonempty_of_nonempty_preimage Set.nonempty_of_nonempty_preimage
@[simp] theorem preimage_singleton_true (p : α → Prop) : p ⁻¹' {True} = {a | p a} := by ext; simp
#align set.preimage_singleton_true Set.preimage_singleton_true
@[simp] theorem preimage_singleton_false (p : α → Prop) : p ⁻¹' {False} = {a | ¬p a} := by ext; simp
#align set.preimage_singleton_false Set.preimage_singleton_false
theorem preimage_subtype_coe_eq_compl {s u v : Set α} (hsuv : s ⊆ u ∪ v)
(H : s ∩ (u ∩ v) = ∅) : ((↑) : s → α) ⁻¹' u = ((↑) ⁻¹' v)ᶜ := by
ext ⟨x, x_in_s⟩
constructor
· intro x_in_u x_in_v
exact eq_empty_iff_forall_not_mem.mp H x ⟨x_in_s, ⟨x_in_u, x_in_v⟩⟩
· intro hx
exact Or.elim (hsuv x_in_s) id fun hx' => hx.elim hx'
#align set.preimage_subtype_coe_eq_compl Set.preimage_subtype_coe_eq_compl
end Preimage
/-! ### Image of a set under a function -/
section Image
variable {f : α → β} {s t : Set α}
-- Porting note: `Set.image` is already defined in `Init.Set`
#align set.image Set.image
/-- `f '' s` denotes the image of `s : Set α` under the function `f : α → β`. -/
infixl:80 " '' " => image
theorem mem_image_iff_bex {f : α → β} {s : Set α} {y : β} :
y ∈ f '' s ↔ ∃ (x : _) (_ : x ∈ s), f x = y :=
bex_def.symm
#align set.mem_image_iff_bex Set.mem_image_iff_bex
@[simp]
theorem mem_image (f : α → β) (s : Set α) (y : β) : y ∈ f '' s ↔ ∃ x ∈ s, f x = y :=
Iff.rfl
#align set.mem_image Set.mem_image
theorem image_eta (f : α → β) : f '' s = (fun x => f x) '' s :=
rfl
#align set.image_eta Set.image_eta
@[mfld_simps]
theorem mem_image_of_mem (f : α → β) {x : α} {a : Set α} (h : x ∈ a) : f x ∈ f '' a :=
⟨_, h, rfl⟩
#align set.mem_image_of_mem Set.mem_image_of_mem
theorem _root_.Function.Injective.mem_set_image {f : α → β} (hf : Injective f) {s : Set α} {a : α} :
f a ∈ f '' s ↔ a ∈ s :=
⟨fun ⟨_, hb, Eq⟩ => hf Eq ▸ hb, mem_image_of_mem f⟩
#align function.injective.mem_set_image Function.Injective.mem_set_image
theorem ball_image_iff {f : α → β} {s : Set α} {p : β → Prop} :
(∀ y ∈ f '' s, p y) ↔ ∀ x ∈ s, p (f x) := by simp
#align set.ball_image_iff Set.ball_image_iff
theorem ball_image_of_ball {f : α → β} {s : Set α} {p : β → Prop} (h : ∀ x ∈ s, p (f x)) :
∀ y ∈ f '' s, p y :=
ball_image_iff.2 h
#align set.ball_image_of_ball Set.ball_image_of_ball
theorem bex_image_iff {f : α → β} {s : Set α} {p : β → Prop} :
(∃ y ∈ f '' s, p y) ↔ ∃ x ∈ s, p (f x) := by simp
#align set.bex_image_iff Set.bex_image_iff
theorem mem_image_elim {f : α → β} {s : Set α} {C : β → Prop} (h : ∀ x : α, x ∈ s → C (f x)) :
∀ {y : β}, y ∈ f '' s → C y
| _, ⟨a, a_in, rfl⟩ => h a a_in
#align set.mem_image_elim Set.mem_image_elim
theorem mem_image_elim_on {f : α → β} {s : Set α} {C : β → Prop} {y : β} (h_y : y ∈ f '' s)
(h : ∀ x : α, x ∈ s → C (f x)) : C y :=
mem_image_elim h h_y
#align set.mem_image_elim_on Set.mem_image_elim_on
-- Porting note: used to be `safe`
@[congr]
theorem image_congr {f g : α → β} {s : Set α} (h : ∀ a ∈ s, f a = g a) : f '' s = g '' s := by
ext x
rw [mem_image, mem_image]
exact {
mp := by
rintro ⟨a, ha1, ha2⟩
exact ⟨a, ⟨ha1, (h a ha1) ▸ ha2⟩⟩,
mpr := by
rintro ⟨a, ha1, ha2⟩
exact ⟨a, ⟨ha1, (h a ha1) ▸ ha2⟩⟩
}
-- safe [ext_iff, iff_def]
#align set.image_congr Set.image_congr
/-- A common special case of `image_congr` -/
theorem image_congr' {f g : α → β} {s : Set α} (h : ∀ x : α, f x = g x) : f '' s = g '' s :=
image_congr fun x _ => h x
#align set.image_congr' Set.image_congr'
@[gcongr]
lemma image_mono (h : s ⊆ t) : f '' s ⊆ f '' t := by
rintro - ⟨a, ha, rfl⟩; exact mem_image_of_mem f (h ha)
theorem image_comp (f : β → γ) (g : α → β) (a : Set α) : f ∘ g '' a = f '' (g '' a) :=
Subset.antisymm (ball_image_of_ball fun _ ha => mem_image_of_mem _ <| mem_image_of_mem _ ha)
(ball_image_of_ball <| ball_image_of_ball fun _ ha => mem_image_of_mem _ ha)
#align set.image_comp Set.image_comp
theorem image_comp_eq {g : β → γ} : image (g ∘ f) = image g ∘ image f := by ext; simp
/-- A variant of `image_comp`, useful for rewriting -/
theorem image_image (g : β → γ) (f : α → β) (s : Set α) : g '' (f '' s) = (fun x => g (f x)) '' s :=
(image_comp g f s).symm
#align set.image_image Set.image_image
theorem image_comm {β'} {f : β → γ} {g : α → β} {f' : α → β'} {g' : β' → γ}
(h_comm : ∀ a, f (g a) = g' (f' a)) : (s.image g).image f = (s.image f').image g' := by
simp_rw [image_image, h_comm]
#align set.image_comm Set.image_comm
theorem _root_.Function.Semiconj.set_image {f : α → β} {ga : α → α} {gb : β → β}
(h : Function.Semiconj f ga gb) : Function.Semiconj (image f) (image ga) (image gb) := fun _ =>
image_comm h
#align function.semiconj.set_image Function.Semiconj.set_image
theorem _root_.Function.Commute.set_image {f g : α → α} (h : Function.Commute f g) :
Function.Commute (image f) (image g) :=
Function.Semiconj.set_image h
#align function.commute.set_image Function.Commute.set_image
/-- Image is monotone with respect to `⊆`. See `Set.monotone_image` for the statement in
terms of `≤`. -/
@[gcongr]
theorem image_subset {a b : Set α} (f : α → β) (h : a ⊆ b) : f '' a ⊆ f '' b := by
simp only [subset_def, mem_image]
exact fun x => fun ⟨w, h1, h2⟩ => ⟨w, h h1, h2⟩
#align set.image_subset Set.image_subset
/-- `Set.image` is monotone. See `Set.image_subset` for the statement in terms of `⊆`. -/
lemma monotone_image {f : α → β} : Monotone (image f) := fun _ _ => image_subset _
#align set.monotone_image Set.monotone_image
theorem image_union (f : α → β) (s t : Set α) : f '' (s ∪ t) = f '' s ∪ f '' t :=
ext fun x =>
⟨by rintro ⟨a, h | h, rfl⟩ <;> [left; right] <;> exact ⟨_, h, rfl⟩, by
rintro (⟨a, h, rfl⟩ | ⟨a, h, rfl⟩) <;> refine' ⟨_, _, rfl⟩ <;> [left; right] <;> exact h⟩
#align set.image_union Set.image_union
@[simp]
theorem image_empty (f : α → β) : f '' ∅ = ∅ := by
ext
simp
#align set.image_empty Set.image_empty
theorem image_inter_subset (f : α → β) (s t : Set α) : f '' (s ∩ t) ⊆ f '' s ∩ f '' t :=
subset_inter (image_subset _ <| inter_subset_left _ _) (image_subset _ <| inter_subset_right _ _)
#align set.image_inter_subset Set.image_inter_subset
theorem image_inter_on {f : α → β} {s t : Set α} (h : ∀ x ∈ t, ∀ y ∈ s, f x = f y → x = y) :
f '' (s ∩ t) = f '' s ∩ f '' t :=
(image_inter_subset _ _ _).antisymm
fun b ⟨⟨a₁, ha₁, h₁⟩, ⟨a₂, ha₂, h₂⟩⟩ ↦
have : a₂ = a₁ := h _ ha₂ _ ha₁ (by simp [*])
⟨a₁, ⟨ha₁, this ▸ ha₂⟩, h₁⟩
#align set.image_inter_on Set.image_inter_on
theorem image_inter {f : α → β} {s t : Set α} (H : Injective f) : f '' (s ∩ t) = f '' s ∩ f '' t :=
image_inter_on fun _ _ _ _ h => H h
#align set.image_inter Set.image_inter
theorem image_univ_of_surjective {ι : Type*} {f : ι → β} (H : Surjective f) : f '' univ = univ :=
eq_univ_of_forall <| by simpa [image]
#align set.image_univ_of_surjective Set.image_univ_of_surjective
@[simp]
theorem image_singleton {f : α → β} {a : α} : f '' {a} = {f a} := by
ext
simp [image, eq_comm]
#align set.image_singleton Set.image_singleton
@[simp]
theorem Nonempty.image_const {s : Set α} (hs : s.Nonempty) (a : β) : (fun _ => a) '' s = {a} :=
ext fun _ =>
⟨fun ⟨_, _, h⟩ => h ▸ mem_singleton _, fun h =>
(eq_of_mem_singleton h).symm ▸ hs.imp fun _ hy => ⟨hy, rfl⟩⟩
#align set.nonempty.image_const Set.Nonempty.image_const
@[simp, mfld_simps]
theorem image_eq_empty {α β} {f : α → β} {s : Set α} : f '' s = ∅ ↔ s = ∅ := by
simp only [eq_empty_iff_forall_not_mem]
exact ⟨fun H a ha => H _ ⟨_, ha, rfl⟩, fun H b ⟨_, ha, _⟩ => H _ ha⟩
#align set.image_eq_empty Set.image_eq_empty
-- Porting note: `compl` is already defined in `Init.Set`
theorem preimage_compl_eq_image_compl [BooleanAlgebra α] (S : Set α) :
HasCompl.compl ⁻¹' S = HasCompl.compl '' S :=
Set.ext fun x =>
⟨fun h => ⟨xᶜ, h, compl_compl x⟩, fun h =>
Exists.elim h fun _ hy => (compl_eq_comm.mp hy.2).symm.subst hy.1⟩
#align set.preimage_compl_eq_image_compl Set.preimage_compl_eq_image_compl
theorem mem_compl_image [BooleanAlgebra α] (t : α) (S : Set α) :
t ∈ HasCompl.compl '' S ↔ tᶜ ∈ S := by
simp [← preimage_compl_eq_image_compl]
#align set.mem_compl_image Set.mem_compl_image
@[simp]
theorem image_id_eq : image (id : α → α) = id := by ext; simp
/-- A variant of `image_id` -/
@[simp]
theorem image_id' (s : Set α) : (fun x => x) '' s = s := by
ext
simp
#align set.image_id' Set.image_id'
theorem image_id (s : Set α) : id '' s = s := by simp
#align set.image_id Set.image_id
lemma image_iterate_eq {f : α → α} {n : ℕ} : image (f^[n]) = (image f)^[n] := by
induction' n with n ih; ·
|
simp
|
lemma image_iterate_eq {f : α → α} {n : ℕ} : image (f^[n]) = (image f)^[n] := by
induction' n with n ih; ·
|
Mathlib.Data.Set.Image.413_0.IJFiTzmYGOCpPSd
|
lemma image_iterate_eq {f : α → α} {n : ℕ} : image (f^[n]) = (image f)^[n]
|
Mathlib_Data_Set_Image
|
case succ
α : Type u_1
β : Type u_2
γ : Type u_3
ι : Sort u_4
ι' : Sort u_5
f✝ : α → β
s t : Set α
f : α → α
n : ℕ
ih : image f^[n] = (image f)^[n]
⊢ image f^[Nat.succ n] = (image f)^[Nat.succ n]
|
/-
Copyright (c) 2014 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Leonardo de Moura
-/
import Mathlib.Data.Set.Basic
#align_import data.set.image from "leanprover-community/mathlib"@"001ffdc42920050657fd45bd2b8bfbec8eaaeb29"
/-!
# Images and preimages of sets
## Main definitions
* `preimage f t : Set α` : the preimage f⁻¹(t) (written `f ⁻¹' t` in Lean) of a subset of β.
* `range f : Set β` : the image of `univ` under `f`.
Also works for `{p : Prop} (f : p → α)` (unlike `image`)
## Notation
* `f ⁻¹' t` for `Set.preimage f t`
* `f '' s` for `Set.image f s`
## Tags
set, sets, image, preimage, pre-image, range
-/
set_option autoImplicit true
universe u v
open Function Set
namespace Set
variable {α β γ : Type*} {ι ι' : Sort*}
/-! ### Inverse image -/
/-- The preimage of `s : Set β` by `f : α → β`, written `f ⁻¹' s`,
is the set of `x : α` such that `f x ∈ s`. -/
def preimage {α : Type u} {β : Type v} (f : α → β) (s : Set β) : Set α :=
{ x | f x ∈ s }
#align set.preimage Set.preimage
/-- `f ⁻¹' t` denotes the preimage of `t : Set β` under the function `f : α → β`. -/
infixl:80 " ⁻¹' " => preimage
section Preimage
variable {f : α → β} {g : β → γ}
@[simp]
theorem preimage_empty : f ⁻¹' ∅ = ∅ :=
rfl
#align set.preimage_empty Set.preimage_empty
@[simp, mfld_simps]
theorem mem_preimage {s : Set β} {a : α} : a ∈ f ⁻¹' s ↔ f a ∈ s :=
Iff.rfl
#align set.mem_preimage Set.mem_preimage
theorem preimage_congr {f g : α → β} {s : Set β} (h : ∀ x : α, f x = g x) : f ⁻¹' s = g ⁻¹' s := by
congr with x
simp [h]
#align set.preimage_congr Set.preimage_congr
@[gcongr]
theorem preimage_mono {s t : Set β} (h : s ⊆ t) : f ⁻¹' s ⊆ f ⁻¹' t := fun _ hx => h hx
#align set.preimage_mono Set.preimage_mono
@[simp, mfld_simps]
theorem preimage_univ : f ⁻¹' univ = univ :=
rfl
#align set.preimage_univ Set.preimage_univ
theorem subset_preimage_univ {s : Set α} : s ⊆ f ⁻¹' univ :=
subset_univ _
#align set.subset_preimage_univ Set.subset_preimage_univ
@[simp, mfld_simps]
theorem preimage_inter {s t : Set β} : f ⁻¹' (s ∩ t) = f ⁻¹' s ∩ f ⁻¹' t :=
rfl
#align set.preimage_inter Set.preimage_inter
@[simp]
theorem preimage_union {s t : Set β} : f ⁻¹' (s ∪ t) = f ⁻¹' s ∪ f ⁻¹' t :=
rfl
#align set.preimage_union Set.preimage_union
@[simp]
theorem preimage_compl {s : Set β} : f ⁻¹' sᶜ = (f ⁻¹' s)ᶜ :=
rfl
#align set.preimage_compl Set.preimage_compl
@[simp]
theorem preimage_diff (f : α → β) (s t : Set β) : f ⁻¹' (s \ t) = f ⁻¹' s \ f ⁻¹' t :=
rfl
#align set.preimage_diff Set.preimage_diff
@[simp]
lemma preimage_symmDiff {f : α → β} (s t : Set β) : f ⁻¹' (s ∆ t) = (f ⁻¹' s) ∆ (f ⁻¹' t) :=
rfl
#align set.preimage_symm_diff Set.preimage_symmDiff
@[simp]
theorem preimage_ite (f : α → β) (s t₁ t₂ : Set β) :
f ⁻¹' s.ite t₁ t₂ = (f ⁻¹' s).ite (f ⁻¹' t₁) (f ⁻¹' t₂) :=
rfl
#align set.preimage_ite Set.preimage_ite
@[simp]
theorem preimage_setOf_eq {p : α → Prop} {f : β → α} : f ⁻¹' { a | p a } = { a | p (f a) } :=
rfl
#align set.preimage_set_of_eq Set.preimage_setOf_eq
@[simp]
theorem preimage_id_eq : preimage (id : α → α) = id :=
rfl
#align set.preimage_id_eq Set.preimage_id_eq
@[mfld_simps]
theorem preimage_id {s : Set α} : id ⁻¹' s = s :=
rfl
#align set.preimage_id Set.preimage_id
@[simp, mfld_simps]
theorem preimage_id' {s : Set α} : (fun x => x) ⁻¹' s = s :=
rfl
#align set.preimage_id' Set.preimage_id'
@[simp]
theorem preimage_const_of_mem {b : β} {s : Set β} (h : b ∈ s) : (fun _ : α => b) ⁻¹' s = univ :=
eq_univ_of_forall fun _ => h
#align set.preimage_const_of_mem Set.preimage_const_of_mem
@[simp]
theorem preimage_const_of_not_mem {b : β} {s : Set β} (h : b ∉ s) : (fun _ : α => b) ⁻¹' s = ∅ :=
eq_empty_of_subset_empty fun _ hx => h hx
#align set.preimage_const_of_not_mem Set.preimage_const_of_not_mem
theorem preimage_const (b : β) (s : Set β) [Decidable (b ∈ s)] :
(fun _ : α => b) ⁻¹' s = if b ∈ s then univ else ∅ := by
split_ifs with hb
exacts [preimage_const_of_mem hb, preimage_const_of_not_mem hb]
#align set.preimage_const Set.preimage_const
/-- If preimage of each singleton under `f : α → β` is either empty or the whole type,
then `f` is a constant. -/
lemma exists_eq_const_of_preimage_singleton [Nonempty β] {f : α → β}
(hf : ∀ b : β, f ⁻¹' {b} = ∅ ∨ f ⁻¹' {b} = univ) : ∃ b, f = const α b := by
rcases em (∃ b, f ⁻¹' {b} = univ) with ⟨b, hb⟩ | hf'
· exact ⟨b, funext fun x ↦ eq_univ_iff_forall.1 hb x⟩
· have : ∀ x b, f x ≠ b := fun x b ↦
eq_empty_iff_forall_not_mem.1 ((hf b).resolve_right fun h ↦ hf' ⟨b, h⟩) x
exact ⟨Classical.arbitrary β, funext fun x ↦ absurd rfl (this x _)⟩
theorem preimage_comp {s : Set γ} : g ∘ f ⁻¹' s = f ⁻¹' (g ⁻¹' s) :=
rfl
#align set.preimage_comp Set.preimage_comp
theorem preimage_comp_eq : preimage (g ∘ f) = preimage f ∘ preimage g :=
rfl
#align set.preimage_comp_eq Set.preimage_comp_eq
theorem preimage_iterate_eq {f : α → α} {n : ℕ} : Set.preimage f^[n] = (Set.preimage f)^[n] := by
induction' n with n ih; · simp
rw [iterate_succ, iterate_succ', preimage_comp_eq, ih]
#align set.preimage_iterate_eq Set.preimage_iterate_eq
theorem preimage_preimage {g : β → γ} {f : α → β} {s : Set γ} :
f ⁻¹' (g ⁻¹' s) = (fun x => g (f x)) ⁻¹' s :=
preimage_comp.symm
#align set.preimage_preimage Set.preimage_preimage
theorem eq_preimage_subtype_val_iff {p : α → Prop} {s : Set (Subtype p)} {t : Set α} :
s = Subtype.val ⁻¹' t ↔ ∀ (x) (h : p x), (⟨x, h⟩ : Subtype p) ∈ s ↔ x ∈ t :=
⟨fun s_eq x h => by
rw [s_eq]
simp, fun h => ext fun ⟨x, hx⟩ => by simp [h]⟩
#align set.eq_preimage_subtype_val_iff Set.eq_preimage_subtype_val_iff
theorem nonempty_of_nonempty_preimage {s : Set β} {f : α → β} (hf : (f ⁻¹' s).Nonempty) :
s.Nonempty :=
let ⟨x, hx⟩ := hf
⟨f x, hx⟩
#align set.nonempty_of_nonempty_preimage Set.nonempty_of_nonempty_preimage
@[simp] theorem preimage_singleton_true (p : α → Prop) : p ⁻¹' {True} = {a | p a} := by ext; simp
#align set.preimage_singleton_true Set.preimage_singleton_true
@[simp] theorem preimage_singleton_false (p : α → Prop) : p ⁻¹' {False} = {a | ¬p a} := by ext; simp
#align set.preimage_singleton_false Set.preimage_singleton_false
theorem preimage_subtype_coe_eq_compl {s u v : Set α} (hsuv : s ⊆ u ∪ v)
(H : s ∩ (u ∩ v) = ∅) : ((↑) : s → α) ⁻¹' u = ((↑) ⁻¹' v)ᶜ := by
ext ⟨x, x_in_s⟩
constructor
· intro x_in_u x_in_v
exact eq_empty_iff_forall_not_mem.mp H x ⟨x_in_s, ⟨x_in_u, x_in_v⟩⟩
· intro hx
exact Or.elim (hsuv x_in_s) id fun hx' => hx.elim hx'
#align set.preimage_subtype_coe_eq_compl Set.preimage_subtype_coe_eq_compl
end Preimage
/-! ### Image of a set under a function -/
section Image
variable {f : α → β} {s t : Set α}
-- Porting note: `Set.image` is already defined in `Init.Set`
#align set.image Set.image
/-- `f '' s` denotes the image of `s : Set α` under the function `f : α → β`. -/
infixl:80 " '' " => image
theorem mem_image_iff_bex {f : α → β} {s : Set α} {y : β} :
y ∈ f '' s ↔ ∃ (x : _) (_ : x ∈ s), f x = y :=
bex_def.symm
#align set.mem_image_iff_bex Set.mem_image_iff_bex
@[simp]
theorem mem_image (f : α → β) (s : Set α) (y : β) : y ∈ f '' s ↔ ∃ x ∈ s, f x = y :=
Iff.rfl
#align set.mem_image Set.mem_image
theorem image_eta (f : α → β) : f '' s = (fun x => f x) '' s :=
rfl
#align set.image_eta Set.image_eta
@[mfld_simps]
theorem mem_image_of_mem (f : α → β) {x : α} {a : Set α} (h : x ∈ a) : f x ∈ f '' a :=
⟨_, h, rfl⟩
#align set.mem_image_of_mem Set.mem_image_of_mem
theorem _root_.Function.Injective.mem_set_image {f : α → β} (hf : Injective f) {s : Set α} {a : α} :
f a ∈ f '' s ↔ a ∈ s :=
⟨fun ⟨_, hb, Eq⟩ => hf Eq ▸ hb, mem_image_of_mem f⟩
#align function.injective.mem_set_image Function.Injective.mem_set_image
theorem ball_image_iff {f : α → β} {s : Set α} {p : β → Prop} :
(∀ y ∈ f '' s, p y) ↔ ∀ x ∈ s, p (f x) := by simp
#align set.ball_image_iff Set.ball_image_iff
theorem ball_image_of_ball {f : α → β} {s : Set α} {p : β → Prop} (h : ∀ x ∈ s, p (f x)) :
∀ y ∈ f '' s, p y :=
ball_image_iff.2 h
#align set.ball_image_of_ball Set.ball_image_of_ball
theorem bex_image_iff {f : α → β} {s : Set α} {p : β → Prop} :
(∃ y ∈ f '' s, p y) ↔ ∃ x ∈ s, p (f x) := by simp
#align set.bex_image_iff Set.bex_image_iff
theorem mem_image_elim {f : α → β} {s : Set α} {C : β → Prop} (h : ∀ x : α, x ∈ s → C (f x)) :
∀ {y : β}, y ∈ f '' s → C y
| _, ⟨a, a_in, rfl⟩ => h a a_in
#align set.mem_image_elim Set.mem_image_elim
theorem mem_image_elim_on {f : α → β} {s : Set α} {C : β → Prop} {y : β} (h_y : y ∈ f '' s)
(h : ∀ x : α, x ∈ s → C (f x)) : C y :=
mem_image_elim h h_y
#align set.mem_image_elim_on Set.mem_image_elim_on
-- Porting note: used to be `safe`
@[congr]
theorem image_congr {f g : α → β} {s : Set α} (h : ∀ a ∈ s, f a = g a) : f '' s = g '' s := by
ext x
rw [mem_image, mem_image]
exact {
mp := by
rintro ⟨a, ha1, ha2⟩
exact ⟨a, ⟨ha1, (h a ha1) ▸ ha2⟩⟩,
mpr := by
rintro ⟨a, ha1, ha2⟩
exact ⟨a, ⟨ha1, (h a ha1) ▸ ha2⟩⟩
}
-- safe [ext_iff, iff_def]
#align set.image_congr Set.image_congr
/-- A common special case of `image_congr` -/
theorem image_congr' {f g : α → β} {s : Set α} (h : ∀ x : α, f x = g x) : f '' s = g '' s :=
image_congr fun x _ => h x
#align set.image_congr' Set.image_congr'
@[gcongr]
lemma image_mono (h : s ⊆ t) : f '' s ⊆ f '' t := by
rintro - ⟨a, ha, rfl⟩; exact mem_image_of_mem f (h ha)
theorem image_comp (f : β → γ) (g : α → β) (a : Set α) : f ∘ g '' a = f '' (g '' a) :=
Subset.antisymm (ball_image_of_ball fun _ ha => mem_image_of_mem _ <| mem_image_of_mem _ ha)
(ball_image_of_ball <| ball_image_of_ball fun _ ha => mem_image_of_mem _ ha)
#align set.image_comp Set.image_comp
theorem image_comp_eq {g : β → γ} : image (g ∘ f) = image g ∘ image f := by ext; simp
/-- A variant of `image_comp`, useful for rewriting -/
theorem image_image (g : β → γ) (f : α → β) (s : Set α) : g '' (f '' s) = (fun x => g (f x)) '' s :=
(image_comp g f s).symm
#align set.image_image Set.image_image
theorem image_comm {β'} {f : β → γ} {g : α → β} {f' : α → β'} {g' : β' → γ}
(h_comm : ∀ a, f (g a) = g' (f' a)) : (s.image g).image f = (s.image f').image g' := by
simp_rw [image_image, h_comm]
#align set.image_comm Set.image_comm
theorem _root_.Function.Semiconj.set_image {f : α → β} {ga : α → α} {gb : β → β}
(h : Function.Semiconj f ga gb) : Function.Semiconj (image f) (image ga) (image gb) := fun _ =>
image_comm h
#align function.semiconj.set_image Function.Semiconj.set_image
theorem _root_.Function.Commute.set_image {f g : α → α} (h : Function.Commute f g) :
Function.Commute (image f) (image g) :=
Function.Semiconj.set_image h
#align function.commute.set_image Function.Commute.set_image
/-- Image is monotone with respect to `⊆`. See `Set.monotone_image` for the statement in
terms of `≤`. -/
@[gcongr]
theorem image_subset {a b : Set α} (f : α → β) (h : a ⊆ b) : f '' a ⊆ f '' b := by
simp only [subset_def, mem_image]
exact fun x => fun ⟨w, h1, h2⟩ => ⟨w, h h1, h2⟩
#align set.image_subset Set.image_subset
/-- `Set.image` is monotone. See `Set.image_subset` for the statement in terms of `⊆`. -/
lemma monotone_image {f : α → β} : Monotone (image f) := fun _ _ => image_subset _
#align set.monotone_image Set.monotone_image
theorem image_union (f : α → β) (s t : Set α) : f '' (s ∪ t) = f '' s ∪ f '' t :=
ext fun x =>
⟨by rintro ⟨a, h | h, rfl⟩ <;> [left; right] <;> exact ⟨_, h, rfl⟩, by
rintro (⟨a, h, rfl⟩ | ⟨a, h, rfl⟩) <;> refine' ⟨_, _, rfl⟩ <;> [left; right] <;> exact h⟩
#align set.image_union Set.image_union
@[simp]
theorem image_empty (f : α → β) : f '' ∅ = ∅ := by
ext
simp
#align set.image_empty Set.image_empty
theorem image_inter_subset (f : α → β) (s t : Set α) : f '' (s ∩ t) ⊆ f '' s ∩ f '' t :=
subset_inter (image_subset _ <| inter_subset_left _ _) (image_subset _ <| inter_subset_right _ _)
#align set.image_inter_subset Set.image_inter_subset
theorem image_inter_on {f : α → β} {s t : Set α} (h : ∀ x ∈ t, ∀ y ∈ s, f x = f y → x = y) :
f '' (s ∩ t) = f '' s ∩ f '' t :=
(image_inter_subset _ _ _).antisymm
fun b ⟨⟨a₁, ha₁, h₁⟩, ⟨a₂, ha₂, h₂⟩⟩ ↦
have : a₂ = a₁ := h _ ha₂ _ ha₁ (by simp [*])
⟨a₁, ⟨ha₁, this ▸ ha₂⟩, h₁⟩
#align set.image_inter_on Set.image_inter_on
theorem image_inter {f : α → β} {s t : Set α} (H : Injective f) : f '' (s ∩ t) = f '' s ∩ f '' t :=
image_inter_on fun _ _ _ _ h => H h
#align set.image_inter Set.image_inter
theorem image_univ_of_surjective {ι : Type*} {f : ι → β} (H : Surjective f) : f '' univ = univ :=
eq_univ_of_forall <| by simpa [image]
#align set.image_univ_of_surjective Set.image_univ_of_surjective
@[simp]
theorem image_singleton {f : α → β} {a : α} : f '' {a} = {f a} := by
ext
simp [image, eq_comm]
#align set.image_singleton Set.image_singleton
@[simp]
theorem Nonempty.image_const {s : Set α} (hs : s.Nonempty) (a : β) : (fun _ => a) '' s = {a} :=
ext fun _ =>
⟨fun ⟨_, _, h⟩ => h ▸ mem_singleton _, fun h =>
(eq_of_mem_singleton h).symm ▸ hs.imp fun _ hy => ⟨hy, rfl⟩⟩
#align set.nonempty.image_const Set.Nonempty.image_const
@[simp, mfld_simps]
theorem image_eq_empty {α β} {f : α → β} {s : Set α} : f '' s = ∅ ↔ s = ∅ := by
simp only [eq_empty_iff_forall_not_mem]
exact ⟨fun H a ha => H _ ⟨_, ha, rfl⟩, fun H b ⟨_, ha, _⟩ => H _ ha⟩
#align set.image_eq_empty Set.image_eq_empty
-- Porting note: `compl` is already defined in `Init.Set`
theorem preimage_compl_eq_image_compl [BooleanAlgebra α] (S : Set α) :
HasCompl.compl ⁻¹' S = HasCompl.compl '' S :=
Set.ext fun x =>
⟨fun h => ⟨xᶜ, h, compl_compl x⟩, fun h =>
Exists.elim h fun _ hy => (compl_eq_comm.mp hy.2).symm.subst hy.1⟩
#align set.preimage_compl_eq_image_compl Set.preimage_compl_eq_image_compl
theorem mem_compl_image [BooleanAlgebra α] (t : α) (S : Set α) :
t ∈ HasCompl.compl '' S ↔ tᶜ ∈ S := by
simp [← preimage_compl_eq_image_compl]
#align set.mem_compl_image Set.mem_compl_image
@[simp]
theorem image_id_eq : image (id : α → α) = id := by ext; simp
/-- A variant of `image_id` -/
@[simp]
theorem image_id' (s : Set α) : (fun x => x) '' s = s := by
ext
simp
#align set.image_id' Set.image_id'
theorem image_id (s : Set α) : id '' s = s := by simp
#align set.image_id Set.image_id
lemma image_iterate_eq {f : α → α} {n : ℕ} : image (f^[n]) = (image f)^[n] := by
induction' n with n ih; · simp
|
rw [iterate_succ', iterate_succ',← ih, image_comp_eq]
|
lemma image_iterate_eq {f : α → α} {n : ℕ} : image (f^[n]) = (image f)^[n] := by
induction' n with n ih; · simp
|
Mathlib.Data.Set.Image.413_0.IJFiTzmYGOCpPSd
|
lemma image_iterate_eq {f : α → α} {n : ℕ} : image (f^[n]) = (image f)^[n]
|
Mathlib_Data_Set_Image
|
α : Type u_1
β : Type u_2
γ : Type u_3
ι : Sort u_4
ι' : Sort u_5
f : α → β
s t : Set α
inst✝ : BooleanAlgebra α
S : Set α
⊢ compl '' (compl '' S) = S
|
/-
Copyright (c) 2014 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Leonardo de Moura
-/
import Mathlib.Data.Set.Basic
#align_import data.set.image from "leanprover-community/mathlib"@"001ffdc42920050657fd45bd2b8bfbec8eaaeb29"
/-!
# Images and preimages of sets
## Main definitions
* `preimage f t : Set α` : the preimage f⁻¹(t) (written `f ⁻¹' t` in Lean) of a subset of β.
* `range f : Set β` : the image of `univ` under `f`.
Also works for `{p : Prop} (f : p → α)` (unlike `image`)
## Notation
* `f ⁻¹' t` for `Set.preimage f t`
* `f '' s` for `Set.image f s`
## Tags
set, sets, image, preimage, pre-image, range
-/
set_option autoImplicit true
universe u v
open Function Set
namespace Set
variable {α β γ : Type*} {ι ι' : Sort*}
/-! ### Inverse image -/
/-- The preimage of `s : Set β` by `f : α → β`, written `f ⁻¹' s`,
is the set of `x : α` such that `f x ∈ s`. -/
def preimage {α : Type u} {β : Type v} (f : α → β) (s : Set β) : Set α :=
{ x | f x ∈ s }
#align set.preimage Set.preimage
/-- `f ⁻¹' t` denotes the preimage of `t : Set β` under the function `f : α → β`. -/
infixl:80 " ⁻¹' " => preimage
section Preimage
variable {f : α → β} {g : β → γ}
@[simp]
theorem preimage_empty : f ⁻¹' ∅ = ∅ :=
rfl
#align set.preimage_empty Set.preimage_empty
@[simp, mfld_simps]
theorem mem_preimage {s : Set β} {a : α} : a ∈ f ⁻¹' s ↔ f a ∈ s :=
Iff.rfl
#align set.mem_preimage Set.mem_preimage
theorem preimage_congr {f g : α → β} {s : Set β} (h : ∀ x : α, f x = g x) : f ⁻¹' s = g ⁻¹' s := by
congr with x
simp [h]
#align set.preimage_congr Set.preimage_congr
@[gcongr]
theorem preimage_mono {s t : Set β} (h : s ⊆ t) : f ⁻¹' s ⊆ f ⁻¹' t := fun _ hx => h hx
#align set.preimage_mono Set.preimage_mono
@[simp, mfld_simps]
theorem preimage_univ : f ⁻¹' univ = univ :=
rfl
#align set.preimage_univ Set.preimage_univ
theorem subset_preimage_univ {s : Set α} : s ⊆ f ⁻¹' univ :=
subset_univ _
#align set.subset_preimage_univ Set.subset_preimage_univ
@[simp, mfld_simps]
theorem preimage_inter {s t : Set β} : f ⁻¹' (s ∩ t) = f ⁻¹' s ∩ f ⁻¹' t :=
rfl
#align set.preimage_inter Set.preimage_inter
@[simp]
theorem preimage_union {s t : Set β} : f ⁻¹' (s ∪ t) = f ⁻¹' s ∪ f ⁻¹' t :=
rfl
#align set.preimage_union Set.preimage_union
@[simp]
theorem preimage_compl {s : Set β} : f ⁻¹' sᶜ = (f ⁻¹' s)ᶜ :=
rfl
#align set.preimage_compl Set.preimage_compl
@[simp]
theorem preimage_diff (f : α → β) (s t : Set β) : f ⁻¹' (s \ t) = f ⁻¹' s \ f ⁻¹' t :=
rfl
#align set.preimage_diff Set.preimage_diff
@[simp]
lemma preimage_symmDiff {f : α → β} (s t : Set β) : f ⁻¹' (s ∆ t) = (f ⁻¹' s) ∆ (f ⁻¹' t) :=
rfl
#align set.preimage_symm_diff Set.preimage_symmDiff
@[simp]
theorem preimage_ite (f : α → β) (s t₁ t₂ : Set β) :
f ⁻¹' s.ite t₁ t₂ = (f ⁻¹' s).ite (f ⁻¹' t₁) (f ⁻¹' t₂) :=
rfl
#align set.preimage_ite Set.preimage_ite
@[simp]
theorem preimage_setOf_eq {p : α → Prop} {f : β → α} : f ⁻¹' { a | p a } = { a | p (f a) } :=
rfl
#align set.preimage_set_of_eq Set.preimage_setOf_eq
@[simp]
theorem preimage_id_eq : preimage (id : α → α) = id :=
rfl
#align set.preimage_id_eq Set.preimage_id_eq
@[mfld_simps]
theorem preimage_id {s : Set α} : id ⁻¹' s = s :=
rfl
#align set.preimage_id Set.preimage_id
@[simp, mfld_simps]
theorem preimage_id' {s : Set α} : (fun x => x) ⁻¹' s = s :=
rfl
#align set.preimage_id' Set.preimage_id'
@[simp]
theorem preimage_const_of_mem {b : β} {s : Set β} (h : b ∈ s) : (fun _ : α => b) ⁻¹' s = univ :=
eq_univ_of_forall fun _ => h
#align set.preimage_const_of_mem Set.preimage_const_of_mem
@[simp]
theorem preimage_const_of_not_mem {b : β} {s : Set β} (h : b ∉ s) : (fun _ : α => b) ⁻¹' s = ∅ :=
eq_empty_of_subset_empty fun _ hx => h hx
#align set.preimage_const_of_not_mem Set.preimage_const_of_not_mem
theorem preimage_const (b : β) (s : Set β) [Decidable (b ∈ s)] :
(fun _ : α => b) ⁻¹' s = if b ∈ s then univ else ∅ := by
split_ifs with hb
exacts [preimage_const_of_mem hb, preimage_const_of_not_mem hb]
#align set.preimage_const Set.preimage_const
/-- If preimage of each singleton under `f : α → β` is either empty or the whole type,
then `f` is a constant. -/
lemma exists_eq_const_of_preimage_singleton [Nonempty β] {f : α → β}
(hf : ∀ b : β, f ⁻¹' {b} = ∅ ∨ f ⁻¹' {b} = univ) : ∃ b, f = const α b := by
rcases em (∃ b, f ⁻¹' {b} = univ) with ⟨b, hb⟩ | hf'
· exact ⟨b, funext fun x ↦ eq_univ_iff_forall.1 hb x⟩
· have : ∀ x b, f x ≠ b := fun x b ↦
eq_empty_iff_forall_not_mem.1 ((hf b).resolve_right fun h ↦ hf' ⟨b, h⟩) x
exact ⟨Classical.arbitrary β, funext fun x ↦ absurd rfl (this x _)⟩
theorem preimage_comp {s : Set γ} : g ∘ f ⁻¹' s = f ⁻¹' (g ⁻¹' s) :=
rfl
#align set.preimage_comp Set.preimage_comp
theorem preimage_comp_eq : preimage (g ∘ f) = preimage f ∘ preimage g :=
rfl
#align set.preimage_comp_eq Set.preimage_comp_eq
theorem preimage_iterate_eq {f : α → α} {n : ℕ} : Set.preimage f^[n] = (Set.preimage f)^[n] := by
induction' n with n ih; · simp
rw [iterate_succ, iterate_succ', preimage_comp_eq, ih]
#align set.preimage_iterate_eq Set.preimage_iterate_eq
theorem preimage_preimage {g : β → γ} {f : α → β} {s : Set γ} :
f ⁻¹' (g ⁻¹' s) = (fun x => g (f x)) ⁻¹' s :=
preimage_comp.symm
#align set.preimage_preimage Set.preimage_preimage
theorem eq_preimage_subtype_val_iff {p : α → Prop} {s : Set (Subtype p)} {t : Set α} :
s = Subtype.val ⁻¹' t ↔ ∀ (x) (h : p x), (⟨x, h⟩ : Subtype p) ∈ s ↔ x ∈ t :=
⟨fun s_eq x h => by
rw [s_eq]
simp, fun h => ext fun ⟨x, hx⟩ => by simp [h]⟩
#align set.eq_preimage_subtype_val_iff Set.eq_preimage_subtype_val_iff
theorem nonempty_of_nonempty_preimage {s : Set β} {f : α → β} (hf : (f ⁻¹' s).Nonempty) :
s.Nonempty :=
let ⟨x, hx⟩ := hf
⟨f x, hx⟩
#align set.nonempty_of_nonempty_preimage Set.nonempty_of_nonempty_preimage
@[simp] theorem preimage_singleton_true (p : α → Prop) : p ⁻¹' {True} = {a | p a} := by ext; simp
#align set.preimage_singleton_true Set.preimage_singleton_true
@[simp] theorem preimage_singleton_false (p : α → Prop) : p ⁻¹' {False} = {a | ¬p a} := by ext; simp
#align set.preimage_singleton_false Set.preimage_singleton_false
theorem preimage_subtype_coe_eq_compl {s u v : Set α} (hsuv : s ⊆ u ∪ v)
(H : s ∩ (u ∩ v) = ∅) : ((↑) : s → α) ⁻¹' u = ((↑) ⁻¹' v)ᶜ := by
ext ⟨x, x_in_s⟩
constructor
· intro x_in_u x_in_v
exact eq_empty_iff_forall_not_mem.mp H x ⟨x_in_s, ⟨x_in_u, x_in_v⟩⟩
· intro hx
exact Or.elim (hsuv x_in_s) id fun hx' => hx.elim hx'
#align set.preimage_subtype_coe_eq_compl Set.preimage_subtype_coe_eq_compl
end Preimage
/-! ### Image of a set under a function -/
section Image
variable {f : α → β} {s t : Set α}
-- Porting note: `Set.image` is already defined in `Init.Set`
#align set.image Set.image
/-- `f '' s` denotes the image of `s : Set α` under the function `f : α → β`. -/
infixl:80 " '' " => image
theorem mem_image_iff_bex {f : α → β} {s : Set α} {y : β} :
y ∈ f '' s ↔ ∃ (x : _) (_ : x ∈ s), f x = y :=
bex_def.symm
#align set.mem_image_iff_bex Set.mem_image_iff_bex
@[simp]
theorem mem_image (f : α → β) (s : Set α) (y : β) : y ∈ f '' s ↔ ∃ x ∈ s, f x = y :=
Iff.rfl
#align set.mem_image Set.mem_image
theorem image_eta (f : α → β) : f '' s = (fun x => f x) '' s :=
rfl
#align set.image_eta Set.image_eta
@[mfld_simps]
theorem mem_image_of_mem (f : α → β) {x : α} {a : Set α} (h : x ∈ a) : f x ∈ f '' a :=
⟨_, h, rfl⟩
#align set.mem_image_of_mem Set.mem_image_of_mem
theorem _root_.Function.Injective.mem_set_image {f : α → β} (hf : Injective f) {s : Set α} {a : α} :
f a ∈ f '' s ↔ a ∈ s :=
⟨fun ⟨_, hb, Eq⟩ => hf Eq ▸ hb, mem_image_of_mem f⟩
#align function.injective.mem_set_image Function.Injective.mem_set_image
theorem ball_image_iff {f : α → β} {s : Set α} {p : β → Prop} :
(∀ y ∈ f '' s, p y) ↔ ∀ x ∈ s, p (f x) := by simp
#align set.ball_image_iff Set.ball_image_iff
theorem ball_image_of_ball {f : α → β} {s : Set α} {p : β → Prop} (h : ∀ x ∈ s, p (f x)) :
∀ y ∈ f '' s, p y :=
ball_image_iff.2 h
#align set.ball_image_of_ball Set.ball_image_of_ball
theorem bex_image_iff {f : α → β} {s : Set α} {p : β → Prop} :
(∃ y ∈ f '' s, p y) ↔ ∃ x ∈ s, p (f x) := by simp
#align set.bex_image_iff Set.bex_image_iff
theorem mem_image_elim {f : α → β} {s : Set α} {C : β → Prop} (h : ∀ x : α, x ∈ s → C (f x)) :
∀ {y : β}, y ∈ f '' s → C y
| _, ⟨a, a_in, rfl⟩ => h a a_in
#align set.mem_image_elim Set.mem_image_elim
theorem mem_image_elim_on {f : α → β} {s : Set α} {C : β → Prop} {y : β} (h_y : y ∈ f '' s)
(h : ∀ x : α, x ∈ s → C (f x)) : C y :=
mem_image_elim h h_y
#align set.mem_image_elim_on Set.mem_image_elim_on
-- Porting note: used to be `safe`
@[congr]
theorem image_congr {f g : α → β} {s : Set α} (h : ∀ a ∈ s, f a = g a) : f '' s = g '' s := by
ext x
rw [mem_image, mem_image]
exact {
mp := by
rintro ⟨a, ha1, ha2⟩
exact ⟨a, ⟨ha1, (h a ha1) ▸ ha2⟩⟩,
mpr := by
rintro ⟨a, ha1, ha2⟩
exact ⟨a, ⟨ha1, (h a ha1) ▸ ha2⟩⟩
}
-- safe [ext_iff, iff_def]
#align set.image_congr Set.image_congr
/-- A common special case of `image_congr` -/
theorem image_congr' {f g : α → β} {s : Set α} (h : ∀ x : α, f x = g x) : f '' s = g '' s :=
image_congr fun x _ => h x
#align set.image_congr' Set.image_congr'
@[gcongr]
lemma image_mono (h : s ⊆ t) : f '' s ⊆ f '' t := by
rintro - ⟨a, ha, rfl⟩; exact mem_image_of_mem f (h ha)
theorem image_comp (f : β → γ) (g : α → β) (a : Set α) : f ∘ g '' a = f '' (g '' a) :=
Subset.antisymm (ball_image_of_ball fun _ ha => mem_image_of_mem _ <| mem_image_of_mem _ ha)
(ball_image_of_ball <| ball_image_of_ball fun _ ha => mem_image_of_mem _ ha)
#align set.image_comp Set.image_comp
theorem image_comp_eq {g : β → γ} : image (g ∘ f) = image g ∘ image f := by ext; simp
/-- A variant of `image_comp`, useful for rewriting -/
theorem image_image (g : β → γ) (f : α → β) (s : Set α) : g '' (f '' s) = (fun x => g (f x)) '' s :=
(image_comp g f s).symm
#align set.image_image Set.image_image
theorem image_comm {β'} {f : β → γ} {g : α → β} {f' : α → β'} {g' : β' → γ}
(h_comm : ∀ a, f (g a) = g' (f' a)) : (s.image g).image f = (s.image f').image g' := by
simp_rw [image_image, h_comm]
#align set.image_comm Set.image_comm
theorem _root_.Function.Semiconj.set_image {f : α → β} {ga : α → α} {gb : β → β}
(h : Function.Semiconj f ga gb) : Function.Semiconj (image f) (image ga) (image gb) := fun _ =>
image_comm h
#align function.semiconj.set_image Function.Semiconj.set_image
theorem _root_.Function.Commute.set_image {f g : α → α} (h : Function.Commute f g) :
Function.Commute (image f) (image g) :=
Function.Semiconj.set_image h
#align function.commute.set_image Function.Commute.set_image
/-- Image is monotone with respect to `⊆`. See `Set.monotone_image` for the statement in
terms of `≤`. -/
@[gcongr]
theorem image_subset {a b : Set α} (f : α → β) (h : a ⊆ b) : f '' a ⊆ f '' b := by
simp only [subset_def, mem_image]
exact fun x => fun ⟨w, h1, h2⟩ => ⟨w, h h1, h2⟩
#align set.image_subset Set.image_subset
/-- `Set.image` is monotone. See `Set.image_subset` for the statement in terms of `⊆`. -/
lemma monotone_image {f : α → β} : Monotone (image f) := fun _ _ => image_subset _
#align set.monotone_image Set.monotone_image
theorem image_union (f : α → β) (s t : Set α) : f '' (s ∪ t) = f '' s ∪ f '' t :=
ext fun x =>
⟨by rintro ⟨a, h | h, rfl⟩ <;> [left; right] <;> exact ⟨_, h, rfl⟩, by
rintro (⟨a, h, rfl⟩ | ⟨a, h, rfl⟩) <;> refine' ⟨_, _, rfl⟩ <;> [left; right] <;> exact h⟩
#align set.image_union Set.image_union
@[simp]
theorem image_empty (f : α → β) : f '' ∅ = ∅ := by
ext
simp
#align set.image_empty Set.image_empty
theorem image_inter_subset (f : α → β) (s t : Set α) : f '' (s ∩ t) ⊆ f '' s ∩ f '' t :=
subset_inter (image_subset _ <| inter_subset_left _ _) (image_subset _ <| inter_subset_right _ _)
#align set.image_inter_subset Set.image_inter_subset
theorem image_inter_on {f : α → β} {s t : Set α} (h : ∀ x ∈ t, ∀ y ∈ s, f x = f y → x = y) :
f '' (s ∩ t) = f '' s ∩ f '' t :=
(image_inter_subset _ _ _).antisymm
fun b ⟨⟨a₁, ha₁, h₁⟩, ⟨a₂, ha₂, h₂⟩⟩ ↦
have : a₂ = a₁ := h _ ha₂ _ ha₁ (by simp [*])
⟨a₁, ⟨ha₁, this ▸ ha₂⟩, h₁⟩
#align set.image_inter_on Set.image_inter_on
theorem image_inter {f : α → β} {s t : Set α} (H : Injective f) : f '' (s ∩ t) = f '' s ∩ f '' t :=
image_inter_on fun _ _ _ _ h => H h
#align set.image_inter Set.image_inter
theorem image_univ_of_surjective {ι : Type*} {f : ι → β} (H : Surjective f) : f '' univ = univ :=
eq_univ_of_forall <| by simpa [image]
#align set.image_univ_of_surjective Set.image_univ_of_surjective
@[simp]
theorem image_singleton {f : α → β} {a : α} : f '' {a} = {f a} := by
ext
simp [image, eq_comm]
#align set.image_singleton Set.image_singleton
@[simp]
theorem Nonempty.image_const {s : Set α} (hs : s.Nonempty) (a : β) : (fun _ => a) '' s = {a} :=
ext fun _ =>
⟨fun ⟨_, _, h⟩ => h ▸ mem_singleton _, fun h =>
(eq_of_mem_singleton h).symm ▸ hs.imp fun _ hy => ⟨hy, rfl⟩⟩
#align set.nonempty.image_const Set.Nonempty.image_const
@[simp, mfld_simps]
theorem image_eq_empty {α β} {f : α → β} {s : Set α} : f '' s = ∅ ↔ s = ∅ := by
simp only [eq_empty_iff_forall_not_mem]
exact ⟨fun H a ha => H _ ⟨_, ha, rfl⟩, fun H b ⟨_, ha, _⟩ => H _ ha⟩
#align set.image_eq_empty Set.image_eq_empty
-- Porting note: `compl` is already defined in `Init.Set`
theorem preimage_compl_eq_image_compl [BooleanAlgebra α] (S : Set α) :
HasCompl.compl ⁻¹' S = HasCompl.compl '' S :=
Set.ext fun x =>
⟨fun h => ⟨xᶜ, h, compl_compl x⟩, fun h =>
Exists.elim h fun _ hy => (compl_eq_comm.mp hy.2).symm.subst hy.1⟩
#align set.preimage_compl_eq_image_compl Set.preimage_compl_eq_image_compl
theorem mem_compl_image [BooleanAlgebra α] (t : α) (S : Set α) :
t ∈ HasCompl.compl '' S ↔ tᶜ ∈ S := by
simp [← preimage_compl_eq_image_compl]
#align set.mem_compl_image Set.mem_compl_image
@[simp]
theorem image_id_eq : image (id : α → α) = id := by ext; simp
/-- A variant of `image_id` -/
@[simp]
theorem image_id' (s : Set α) : (fun x => x) '' s = s := by
ext
simp
#align set.image_id' Set.image_id'
theorem image_id (s : Set α) : id '' s = s := by simp
#align set.image_id Set.image_id
lemma image_iterate_eq {f : α → α} {n : ℕ} : image (f^[n]) = (image f)^[n] := by
induction' n with n ih; · simp
rw [iterate_succ', iterate_succ',← ih, image_comp_eq]
theorem compl_compl_image [BooleanAlgebra α] (S : Set α) :
HasCompl.compl '' (HasCompl.compl '' S) = S := by
|
rw [← image_comp, compl_comp_compl, image_id]
|
theorem compl_compl_image [BooleanAlgebra α] (S : Set α) :
HasCompl.compl '' (HasCompl.compl '' S) = S := by
|
Mathlib.Data.Set.Image.417_0.IJFiTzmYGOCpPSd
|
theorem compl_compl_image [BooleanAlgebra α] (S : Set α) :
HasCompl.compl '' (HasCompl.compl '' S) = S
|
Mathlib_Data_Set_Image
|
α : Type u_1
β : Type u_2
γ : Type u_3
ι : Sort u_4
ι' : Sort u_5
f✝ : α → β
s✝ t : Set α
f : α → β
a : α
s : Set α
⊢ f '' insert a s = insert (f a) (f '' s)
|
/-
Copyright (c) 2014 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Leonardo de Moura
-/
import Mathlib.Data.Set.Basic
#align_import data.set.image from "leanprover-community/mathlib"@"001ffdc42920050657fd45bd2b8bfbec8eaaeb29"
/-!
# Images and preimages of sets
## Main definitions
* `preimage f t : Set α` : the preimage f⁻¹(t) (written `f ⁻¹' t` in Lean) of a subset of β.
* `range f : Set β` : the image of `univ` under `f`.
Also works for `{p : Prop} (f : p → α)` (unlike `image`)
## Notation
* `f ⁻¹' t` for `Set.preimage f t`
* `f '' s` for `Set.image f s`
## Tags
set, sets, image, preimage, pre-image, range
-/
set_option autoImplicit true
universe u v
open Function Set
namespace Set
variable {α β γ : Type*} {ι ι' : Sort*}
/-! ### Inverse image -/
/-- The preimage of `s : Set β` by `f : α → β`, written `f ⁻¹' s`,
is the set of `x : α` such that `f x ∈ s`. -/
def preimage {α : Type u} {β : Type v} (f : α → β) (s : Set β) : Set α :=
{ x | f x ∈ s }
#align set.preimage Set.preimage
/-- `f ⁻¹' t` denotes the preimage of `t : Set β` under the function `f : α → β`. -/
infixl:80 " ⁻¹' " => preimage
section Preimage
variable {f : α → β} {g : β → γ}
@[simp]
theorem preimage_empty : f ⁻¹' ∅ = ∅ :=
rfl
#align set.preimage_empty Set.preimage_empty
@[simp, mfld_simps]
theorem mem_preimage {s : Set β} {a : α} : a ∈ f ⁻¹' s ↔ f a ∈ s :=
Iff.rfl
#align set.mem_preimage Set.mem_preimage
theorem preimage_congr {f g : α → β} {s : Set β} (h : ∀ x : α, f x = g x) : f ⁻¹' s = g ⁻¹' s := by
congr with x
simp [h]
#align set.preimage_congr Set.preimage_congr
@[gcongr]
theorem preimage_mono {s t : Set β} (h : s ⊆ t) : f ⁻¹' s ⊆ f ⁻¹' t := fun _ hx => h hx
#align set.preimage_mono Set.preimage_mono
@[simp, mfld_simps]
theorem preimage_univ : f ⁻¹' univ = univ :=
rfl
#align set.preimage_univ Set.preimage_univ
theorem subset_preimage_univ {s : Set α} : s ⊆ f ⁻¹' univ :=
subset_univ _
#align set.subset_preimage_univ Set.subset_preimage_univ
@[simp, mfld_simps]
theorem preimage_inter {s t : Set β} : f ⁻¹' (s ∩ t) = f ⁻¹' s ∩ f ⁻¹' t :=
rfl
#align set.preimage_inter Set.preimage_inter
@[simp]
theorem preimage_union {s t : Set β} : f ⁻¹' (s ∪ t) = f ⁻¹' s ∪ f ⁻¹' t :=
rfl
#align set.preimage_union Set.preimage_union
@[simp]
theorem preimage_compl {s : Set β} : f ⁻¹' sᶜ = (f ⁻¹' s)ᶜ :=
rfl
#align set.preimage_compl Set.preimage_compl
@[simp]
theorem preimage_diff (f : α → β) (s t : Set β) : f ⁻¹' (s \ t) = f ⁻¹' s \ f ⁻¹' t :=
rfl
#align set.preimage_diff Set.preimage_diff
@[simp]
lemma preimage_symmDiff {f : α → β} (s t : Set β) : f ⁻¹' (s ∆ t) = (f ⁻¹' s) ∆ (f ⁻¹' t) :=
rfl
#align set.preimage_symm_diff Set.preimage_symmDiff
@[simp]
theorem preimage_ite (f : α → β) (s t₁ t₂ : Set β) :
f ⁻¹' s.ite t₁ t₂ = (f ⁻¹' s).ite (f ⁻¹' t₁) (f ⁻¹' t₂) :=
rfl
#align set.preimage_ite Set.preimage_ite
@[simp]
theorem preimage_setOf_eq {p : α → Prop} {f : β → α} : f ⁻¹' { a | p a } = { a | p (f a) } :=
rfl
#align set.preimage_set_of_eq Set.preimage_setOf_eq
@[simp]
theorem preimage_id_eq : preimage (id : α → α) = id :=
rfl
#align set.preimage_id_eq Set.preimage_id_eq
@[mfld_simps]
theorem preimage_id {s : Set α} : id ⁻¹' s = s :=
rfl
#align set.preimage_id Set.preimage_id
@[simp, mfld_simps]
theorem preimage_id' {s : Set α} : (fun x => x) ⁻¹' s = s :=
rfl
#align set.preimage_id' Set.preimage_id'
@[simp]
theorem preimage_const_of_mem {b : β} {s : Set β} (h : b ∈ s) : (fun _ : α => b) ⁻¹' s = univ :=
eq_univ_of_forall fun _ => h
#align set.preimage_const_of_mem Set.preimage_const_of_mem
@[simp]
theorem preimage_const_of_not_mem {b : β} {s : Set β} (h : b ∉ s) : (fun _ : α => b) ⁻¹' s = ∅ :=
eq_empty_of_subset_empty fun _ hx => h hx
#align set.preimage_const_of_not_mem Set.preimage_const_of_not_mem
theorem preimage_const (b : β) (s : Set β) [Decidable (b ∈ s)] :
(fun _ : α => b) ⁻¹' s = if b ∈ s then univ else ∅ := by
split_ifs with hb
exacts [preimage_const_of_mem hb, preimage_const_of_not_mem hb]
#align set.preimage_const Set.preimage_const
/-- If preimage of each singleton under `f : α → β` is either empty or the whole type,
then `f` is a constant. -/
lemma exists_eq_const_of_preimage_singleton [Nonempty β] {f : α → β}
(hf : ∀ b : β, f ⁻¹' {b} = ∅ ∨ f ⁻¹' {b} = univ) : ∃ b, f = const α b := by
rcases em (∃ b, f ⁻¹' {b} = univ) with ⟨b, hb⟩ | hf'
· exact ⟨b, funext fun x ↦ eq_univ_iff_forall.1 hb x⟩
· have : ∀ x b, f x ≠ b := fun x b ↦
eq_empty_iff_forall_not_mem.1 ((hf b).resolve_right fun h ↦ hf' ⟨b, h⟩) x
exact ⟨Classical.arbitrary β, funext fun x ↦ absurd rfl (this x _)⟩
theorem preimage_comp {s : Set γ} : g ∘ f ⁻¹' s = f ⁻¹' (g ⁻¹' s) :=
rfl
#align set.preimage_comp Set.preimage_comp
theorem preimage_comp_eq : preimage (g ∘ f) = preimage f ∘ preimage g :=
rfl
#align set.preimage_comp_eq Set.preimage_comp_eq
theorem preimage_iterate_eq {f : α → α} {n : ℕ} : Set.preimage f^[n] = (Set.preimage f)^[n] := by
induction' n with n ih; · simp
rw [iterate_succ, iterate_succ', preimage_comp_eq, ih]
#align set.preimage_iterate_eq Set.preimage_iterate_eq
theorem preimage_preimage {g : β → γ} {f : α → β} {s : Set γ} :
f ⁻¹' (g ⁻¹' s) = (fun x => g (f x)) ⁻¹' s :=
preimage_comp.symm
#align set.preimage_preimage Set.preimage_preimage
theorem eq_preimage_subtype_val_iff {p : α → Prop} {s : Set (Subtype p)} {t : Set α} :
s = Subtype.val ⁻¹' t ↔ ∀ (x) (h : p x), (⟨x, h⟩ : Subtype p) ∈ s ↔ x ∈ t :=
⟨fun s_eq x h => by
rw [s_eq]
simp, fun h => ext fun ⟨x, hx⟩ => by simp [h]⟩
#align set.eq_preimage_subtype_val_iff Set.eq_preimage_subtype_val_iff
theorem nonempty_of_nonempty_preimage {s : Set β} {f : α → β} (hf : (f ⁻¹' s).Nonempty) :
s.Nonempty :=
let ⟨x, hx⟩ := hf
⟨f x, hx⟩
#align set.nonempty_of_nonempty_preimage Set.nonempty_of_nonempty_preimage
@[simp] theorem preimage_singleton_true (p : α → Prop) : p ⁻¹' {True} = {a | p a} := by ext; simp
#align set.preimage_singleton_true Set.preimage_singleton_true
@[simp] theorem preimage_singleton_false (p : α → Prop) : p ⁻¹' {False} = {a | ¬p a} := by ext; simp
#align set.preimage_singleton_false Set.preimage_singleton_false
theorem preimage_subtype_coe_eq_compl {s u v : Set α} (hsuv : s ⊆ u ∪ v)
(H : s ∩ (u ∩ v) = ∅) : ((↑) : s → α) ⁻¹' u = ((↑) ⁻¹' v)ᶜ := by
ext ⟨x, x_in_s⟩
constructor
· intro x_in_u x_in_v
exact eq_empty_iff_forall_not_mem.mp H x ⟨x_in_s, ⟨x_in_u, x_in_v⟩⟩
· intro hx
exact Or.elim (hsuv x_in_s) id fun hx' => hx.elim hx'
#align set.preimage_subtype_coe_eq_compl Set.preimage_subtype_coe_eq_compl
end Preimage
/-! ### Image of a set under a function -/
section Image
variable {f : α → β} {s t : Set α}
-- Porting note: `Set.image` is already defined in `Init.Set`
#align set.image Set.image
/-- `f '' s` denotes the image of `s : Set α` under the function `f : α → β`. -/
infixl:80 " '' " => image
theorem mem_image_iff_bex {f : α → β} {s : Set α} {y : β} :
y ∈ f '' s ↔ ∃ (x : _) (_ : x ∈ s), f x = y :=
bex_def.symm
#align set.mem_image_iff_bex Set.mem_image_iff_bex
@[simp]
theorem mem_image (f : α → β) (s : Set α) (y : β) : y ∈ f '' s ↔ ∃ x ∈ s, f x = y :=
Iff.rfl
#align set.mem_image Set.mem_image
theorem image_eta (f : α → β) : f '' s = (fun x => f x) '' s :=
rfl
#align set.image_eta Set.image_eta
@[mfld_simps]
theorem mem_image_of_mem (f : α → β) {x : α} {a : Set α} (h : x ∈ a) : f x ∈ f '' a :=
⟨_, h, rfl⟩
#align set.mem_image_of_mem Set.mem_image_of_mem
theorem _root_.Function.Injective.mem_set_image {f : α → β} (hf : Injective f) {s : Set α} {a : α} :
f a ∈ f '' s ↔ a ∈ s :=
⟨fun ⟨_, hb, Eq⟩ => hf Eq ▸ hb, mem_image_of_mem f⟩
#align function.injective.mem_set_image Function.Injective.mem_set_image
theorem ball_image_iff {f : α → β} {s : Set α} {p : β → Prop} :
(∀ y ∈ f '' s, p y) ↔ ∀ x ∈ s, p (f x) := by simp
#align set.ball_image_iff Set.ball_image_iff
theorem ball_image_of_ball {f : α → β} {s : Set α} {p : β → Prop} (h : ∀ x ∈ s, p (f x)) :
∀ y ∈ f '' s, p y :=
ball_image_iff.2 h
#align set.ball_image_of_ball Set.ball_image_of_ball
theorem bex_image_iff {f : α → β} {s : Set α} {p : β → Prop} :
(∃ y ∈ f '' s, p y) ↔ ∃ x ∈ s, p (f x) := by simp
#align set.bex_image_iff Set.bex_image_iff
theorem mem_image_elim {f : α → β} {s : Set α} {C : β → Prop} (h : ∀ x : α, x ∈ s → C (f x)) :
∀ {y : β}, y ∈ f '' s → C y
| _, ⟨a, a_in, rfl⟩ => h a a_in
#align set.mem_image_elim Set.mem_image_elim
theorem mem_image_elim_on {f : α → β} {s : Set α} {C : β → Prop} {y : β} (h_y : y ∈ f '' s)
(h : ∀ x : α, x ∈ s → C (f x)) : C y :=
mem_image_elim h h_y
#align set.mem_image_elim_on Set.mem_image_elim_on
-- Porting note: used to be `safe`
@[congr]
theorem image_congr {f g : α → β} {s : Set α} (h : ∀ a ∈ s, f a = g a) : f '' s = g '' s := by
ext x
rw [mem_image, mem_image]
exact {
mp := by
rintro ⟨a, ha1, ha2⟩
exact ⟨a, ⟨ha1, (h a ha1) ▸ ha2⟩⟩,
mpr := by
rintro ⟨a, ha1, ha2⟩
exact ⟨a, ⟨ha1, (h a ha1) ▸ ha2⟩⟩
}
-- safe [ext_iff, iff_def]
#align set.image_congr Set.image_congr
/-- A common special case of `image_congr` -/
theorem image_congr' {f g : α → β} {s : Set α} (h : ∀ x : α, f x = g x) : f '' s = g '' s :=
image_congr fun x _ => h x
#align set.image_congr' Set.image_congr'
@[gcongr]
lemma image_mono (h : s ⊆ t) : f '' s ⊆ f '' t := by
rintro - ⟨a, ha, rfl⟩; exact mem_image_of_mem f (h ha)
theorem image_comp (f : β → γ) (g : α → β) (a : Set α) : f ∘ g '' a = f '' (g '' a) :=
Subset.antisymm (ball_image_of_ball fun _ ha => mem_image_of_mem _ <| mem_image_of_mem _ ha)
(ball_image_of_ball <| ball_image_of_ball fun _ ha => mem_image_of_mem _ ha)
#align set.image_comp Set.image_comp
theorem image_comp_eq {g : β → γ} : image (g ∘ f) = image g ∘ image f := by ext; simp
/-- A variant of `image_comp`, useful for rewriting -/
theorem image_image (g : β → γ) (f : α → β) (s : Set α) : g '' (f '' s) = (fun x => g (f x)) '' s :=
(image_comp g f s).symm
#align set.image_image Set.image_image
theorem image_comm {β'} {f : β → γ} {g : α → β} {f' : α → β'} {g' : β' → γ}
(h_comm : ∀ a, f (g a) = g' (f' a)) : (s.image g).image f = (s.image f').image g' := by
simp_rw [image_image, h_comm]
#align set.image_comm Set.image_comm
theorem _root_.Function.Semiconj.set_image {f : α → β} {ga : α → α} {gb : β → β}
(h : Function.Semiconj f ga gb) : Function.Semiconj (image f) (image ga) (image gb) := fun _ =>
image_comm h
#align function.semiconj.set_image Function.Semiconj.set_image
theorem _root_.Function.Commute.set_image {f g : α → α} (h : Function.Commute f g) :
Function.Commute (image f) (image g) :=
Function.Semiconj.set_image h
#align function.commute.set_image Function.Commute.set_image
/-- Image is monotone with respect to `⊆`. See `Set.monotone_image` for the statement in
terms of `≤`. -/
@[gcongr]
theorem image_subset {a b : Set α} (f : α → β) (h : a ⊆ b) : f '' a ⊆ f '' b := by
simp only [subset_def, mem_image]
exact fun x => fun ⟨w, h1, h2⟩ => ⟨w, h h1, h2⟩
#align set.image_subset Set.image_subset
/-- `Set.image` is monotone. See `Set.image_subset` for the statement in terms of `⊆`. -/
lemma monotone_image {f : α → β} : Monotone (image f) := fun _ _ => image_subset _
#align set.monotone_image Set.monotone_image
theorem image_union (f : α → β) (s t : Set α) : f '' (s ∪ t) = f '' s ∪ f '' t :=
ext fun x =>
⟨by rintro ⟨a, h | h, rfl⟩ <;> [left; right] <;> exact ⟨_, h, rfl⟩, by
rintro (⟨a, h, rfl⟩ | ⟨a, h, rfl⟩) <;> refine' ⟨_, _, rfl⟩ <;> [left; right] <;> exact h⟩
#align set.image_union Set.image_union
@[simp]
theorem image_empty (f : α → β) : f '' ∅ = ∅ := by
ext
simp
#align set.image_empty Set.image_empty
theorem image_inter_subset (f : α → β) (s t : Set α) : f '' (s ∩ t) ⊆ f '' s ∩ f '' t :=
subset_inter (image_subset _ <| inter_subset_left _ _) (image_subset _ <| inter_subset_right _ _)
#align set.image_inter_subset Set.image_inter_subset
theorem image_inter_on {f : α → β} {s t : Set α} (h : ∀ x ∈ t, ∀ y ∈ s, f x = f y → x = y) :
f '' (s ∩ t) = f '' s ∩ f '' t :=
(image_inter_subset _ _ _).antisymm
fun b ⟨⟨a₁, ha₁, h₁⟩, ⟨a₂, ha₂, h₂⟩⟩ ↦
have : a₂ = a₁ := h _ ha₂ _ ha₁ (by simp [*])
⟨a₁, ⟨ha₁, this ▸ ha₂⟩, h₁⟩
#align set.image_inter_on Set.image_inter_on
theorem image_inter {f : α → β} {s t : Set α} (H : Injective f) : f '' (s ∩ t) = f '' s ∩ f '' t :=
image_inter_on fun _ _ _ _ h => H h
#align set.image_inter Set.image_inter
theorem image_univ_of_surjective {ι : Type*} {f : ι → β} (H : Surjective f) : f '' univ = univ :=
eq_univ_of_forall <| by simpa [image]
#align set.image_univ_of_surjective Set.image_univ_of_surjective
@[simp]
theorem image_singleton {f : α → β} {a : α} : f '' {a} = {f a} := by
ext
simp [image, eq_comm]
#align set.image_singleton Set.image_singleton
@[simp]
theorem Nonempty.image_const {s : Set α} (hs : s.Nonempty) (a : β) : (fun _ => a) '' s = {a} :=
ext fun _ =>
⟨fun ⟨_, _, h⟩ => h ▸ mem_singleton _, fun h =>
(eq_of_mem_singleton h).symm ▸ hs.imp fun _ hy => ⟨hy, rfl⟩⟩
#align set.nonempty.image_const Set.Nonempty.image_const
@[simp, mfld_simps]
theorem image_eq_empty {α β} {f : α → β} {s : Set α} : f '' s = ∅ ↔ s = ∅ := by
simp only [eq_empty_iff_forall_not_mem]
exact ⟨fun H a ha => H _ ⟨_, ha, rfl⟩, fun H b ⟨_, ha, _⟩ => H _ ha⟩
#align set.image_eq_empty Set.image_eq_empty
-- Porting note: `compl` is already defined in `Init.Set`
theorem preimage_compl_eq_image_compl [BooleanAlgebra α] (S : Set α) :
HasCompl.compl ⁻¹' S = HasCompl.compl '' S :=
Set.ext fun x =>
⟨fun h => ⟨xᶜ, h, compl_compl x⟩, fun h =>
Exists.elim h fun _ hy => (compl_eq_comm.mp hy.2).symm.subst hy.1⟩
#align set.preimage_compl_eq_image_compl Set.preimage_compl_eq_image_compl
theorem mem_compl_image [BooleanAlgebra α] (t : α) (S : Set α) :
t ∈ HasCompl.compl '' S ↔ tᶜ ∈ S := by
simp [← preimage_compl_eq_image_compl]
#align set.mem_compl_image Set.mem_compl_image
@[simp]
theorem image_id_eq : image (id : α → α) = id := by ext; simp
/-- A variant of `image_id` -/
@[simp]
theorem image_id' (s : Set α) : (fun x => x) '' s = s := by
ext
simp
#align set.image_id' Set.image_id'
theorem image_id (s : Set α) : id '' s = s := by simp
#align set.image_id Set.image_id
lemma image_iterate_eq {f : α → α} {n : ℕ} : image (f^[n]) = (image f)^[n] := by
induction' n with n ih; · simp
rw [iterate_succ', iterate_succ',← ih, image_comp_eq]
theorem compl_compl_image [BooleanAlgebra α] (S : Set α) :
HasCompl.compl '' (HasCompl.compl '' S) = S := by
rw [← image_comp, compl_comp_compl, image_id]
#align set.compl_compl_image Set.compl_compl_image
theorem image_insert_eq {f : α → β} {a : α} {s : Set α} :
f '' insert a s = insert (f a) (f '' s) := by
|
ext
|
theorem image_insert_eq {f : α → β} {a : α} {s : Set α} :
f '' insert a s = insert (f a) (f '' s) := by
|
Mathlib.Data.Set.Image.422_0.IJFiTzmYGOCpPSd
|
theorem image_insert_eq {f : α → β} {a : α} {s : Set α} :
f '' insert a s = insert (f a) (f '' s)
|
Mathlib_Data_Set_Image
|
case h
α : Type u_1
β : Type u_2
γ : Type u_3
ι : Sort u_4
ι' : Sort u_5
f✝ : α → β
s✝ t : Set α
f : α → β
a : α
s : Set α
x✝ : β
⊢ x✝ ∈ f '' insert a s ↔ x✝ ∈ insert (f a) (f '' s)
|
/-
Copyright (c) 2014 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Leonardo de Moura
-/
import Mathlib.Data.Set.Basic
#align_import data.set.image from "leanprover-community/mathlib"@"001ffdc42920050657fd45bd2b8bfbec8eaaeb29"
/-!
# Images and preimages of sets
## Main definitions
* `preimage f t : Set α` : the preimage f⁻¹(t) (written `f ⁻¹' t` in Lean) of a subset of β.
* `range f : Set β` : the image of `univ` under `f`.
Also works for `{p : Prop} (f : p → α)` (unlike `image`)
## Notation
* `f ⁻¹' t` for `Set.preimage f t`
* `f '' s` for `Set.image f s`
## Tags
set, sets, image, preimage, pre-image, range
-/
set_option autoImplicit true
universe u v
open Function Set
namespace Set
variable {α β γ : Type*} {ι ι' : Sort*}
/-! ### Inverse image -/
/-- The preimage of `s : Set β` by `f : α → β`, written `f ⁻¹' s`,
is the set of `x : α` such that `f x ∈ s`. -/
def preimage {α : Type u} {β : Type v} (f : α → β) (s : Set β) : Set α :=
{ x | f x ∈ s }
#align set.preimage Set.preimage
/-- `f ⁻¹' t` denotes the preimage of `t : Set β` under the function `f : α → β`. -/
infixl:80 " ⁻¹' " => preimage
section Preimage
variable {f : α → β} {g : β → γ}
@[simp]
theorem preimage_empty : f ⁻¹' ∅ = ∅ :=
rfl
#align set.preimage_empty Set.preimage_empty
@[simp, mfld_simps]
theorem mem_preimage {s : Set β} {a : α} : a ∈ f ⁻¹' s ↔ f a ∈ s :=
Iff.rfl
#align set.mem_preimage Set.mem_preimage
theorem preimage_congr {f g : α → β} {s : Set β} (h : ∀ x : α, f x = g x) : f ⁻¹' s = g ⁻¹' s := by
congr with x
simp [h]
#align set.preimage_congr Set.preimage_congr
@[gcongr]
theorem preimage_mono {s t : Set β} (h : s ⊆ t) : f ⁻¹' s ⊆ f ⁻¹' t := fun _ hx => h hx
#align set.preimage_mono Set.preimage_mono
@[simp, mfld_simps]
theorem preimage_univ : f ⁻¹' univ = univ :=
rfl
#align set.preimage_univ Set.preimage_univ
theorem subset_preimage_univ {s : Set α} : s ⊆ f ⁻¹' univ :=
subset_univ _
#align set.subset_preimage_univ Set.subset_preimage_univ
@[simp, mfld_simps]
theorem preimage_inter {s t : Set β} : f ⁻¹' (s ∩ t) = f ⁻¹' s ∩ f ⁻¹' t :=
rfl
#align set.preimage_inter Set.preimage_inter
@[simp]
theorem preimage_union {s t : Set β} : f ⁻¹' (s ∪ t) = f ⁻¹' s ∪ f ⁻¹' t :=
rfl
#align set.preimage_union Set.preimage_union
@[simp]
theorem preimage_compl {s : Set β} : f ⁻¹' sᶜ = (f ⁻¹' s)ᶜ :=
rfl
#align set.preimage_compl Set.preimage_compl
@[simp]
theorem preimage_diff (f : α → β) (s t : Set β) : f ⁻¹' (s \ t) = f ⁻¹' s \ f ⁻¹' t :=
rfl
#align set.preimage_diff Set.preimage_diff
@[simp]
lemma preimage_symmDiff {f : α → β} (s t : Set β) : f ⁻¹' (s ∆ t) = (f ⁻¹' s) ∆ (f ⁻¹' t) :=
rfl
#align set.preimage_symm_diff Set.preimage_symmDiff
@[simp]
theorem preimage_ite (f : α → β) (s t₁ t₂ : Set β) :
f ⁻¹' s.ite t₁ t₂ = (f ⁻¹' s).ite (f ⁻¹' t₁) (f ⁻¹' t₂) :=
rfl
#align set.preimage_ite Set.preimage_ite
@[simp]
theorem preimage_setOf_eq {p : α → Prop} {f : β → α} : f ⁻¹' { a | p a } = { a | p (f a) } :=
rfl
#align set.preimage_set_of_eq Set.preimage_setOf_eq
@[simp]
theorem preimage_id_eq : preimage (id : α → α) = id :=
rfl
#align set.preimage_id_eq Set.preimage_id_eq
@[mfld_simps]
theorem preimage_id {s : Set α} : id ⁻¹' s = s :=
rfl
#align set.preimage_id Set.preimage_id
@[simp, mfld_simps]
theorem preimage_id' {s : Set α} : (fun x => x) ⁻¹' s = s :=
rfl
#align set.preimage_id' Set.preimage_id'
@[simp]
theorem preimage_const_of_mem {b : β} {s : Set β} (h : b ∈ s) : (fun _ : α => b) ⁻¹' s = univ :=
eq_univ_of_forall fun _ => h
#align set.preimage_const_of_mem Set.preimage_const_of_mem
@[simp]
theorem preimage_const_of_not_mem {b : β} {s : Set β} (h : b ∉ s) : (fun _ : α => b) ⁻¹' s = ∅ :=
eq_empty_of_subset_empty fun _ hx => h hx
#align set.preimage_const_of_not_mem Set.preimage_const_of_not_mem
theorem preimage_const (b : β) (s : Set β) [Decidable (b ∈ s)] :
(fun _ : α => b) ⁻¹' s = if b ∈ s then univ else ∅ := by
split_ifs with hb
exacts [preimage_const_of_mem hb, preimage_const_of_not_mem hb]
#align set.preimage_const Set.preimage_const
/-- If preimage of each singleton under `f : α → β` is either empty or the whole type,
then `f` is a constant. -/
lemma exists_eq_const_of_preimage_singleton [Nonempty β] {f : α → β}
(hf : ∀ b : β, f ⁻¹' {b} = ∅ ∨ f ⁻¹' {b} = univ) : ∃ b, f = const α b := by
rcases em (∃ b, f ⁻¹' {b} = univ) with ⟨b, hb⟩ | hf'
· exact ⟨b, funext fun x ↦ eq_univ_iff_forall.1 hb x⟩
· have : ∀ x b, f x ≠ b := fun x b ↦
eq_empty_iff_forall_not_mem.1 ((hf b).resolve_right fun h ↦ hf' ⟨b, h⟩) x
exact ⟨Classical.arbitrary β, funext fun x ↦ absurd rfl (this x _)⟩
theorem preimage_comp {s : Set γ} : g ∘ f ⁻¹' s = f ⁻¹' (g ⁻¹' s) :=
rfl
#align set.preimage_comp Set.preimage_comp
theorem preimage_comp_eq : preimage (g ∘ f) = preimage f ∘ preimage g :=
rfl
#align set.preimage_comp_eq Set.preimage_comp_eq
theorem preimage_iterate_eq {f : α → α} {n : ℕ} : Set.preimage f^[n] = (Set.preimage f)^[n] := by
induction' n with n ih; · simp
rw [iterate_succ, iterate_succ', preimage_comp_eq, ih]
#align set.preimage_iterate_eq Set.preimage_iterate_eq
theorem preimage_preimage {g : β → γ} {f : α → β} {s : Set γ} :
f ⁻¹' (g ⁻¹' s) = (fun x => g (f x)) ⁻¹' s :=
preimage_comp.symm
#align set.preimage_preimage Set.preimage_preimage
theorem eq_preimage_subtype_val_iff {p : α → Prop} {s : Set (Subtype p)} {t : Set α} :
s = Subtype.val ⁻¹' t ↔ ∀ (x) (h : p x), (⟨x, h⟩ : Subtype p) ∈ s ↔ x ∈ t :=
⟨fun s_eq x h => by
rw [s_eq]
simp, fun h => ext fun ⟨x, hx⟩ => by simp [h]⟩
#align set.eq_preimage_subtype_val_iff Set.eq_preimage_subtype_val_iff
theorem nonempty_of_nonempty_preimage {s : Set β} {f : α → β} (hf : (f ⁻¹' s).Nonempty) :
s.Nonempty :=
let ⟨x, hx⟩ := hf
⟨f x, hx⟩
#align set.nonempty_of_nonempty_preimage Set.nonempty_of_nonempty_preimage
@[simp] theorem preimage_singleton_true (p : α → Prop) : p ⁻¹' {True} = {a | p a} := by ext; simp
#align set.preimage_singleton_true Set.preimage_singleton_true
@[simp] theorem preimage_singleton_false (p : α → Prop) : p ⁻¹' {False} = {a | ¬p a} := by ext; simp
#align set.preimage_singleton_false Set.preimage_singleton_false
theorem preimage_subtype_coe_eq_compl {s u v : Set α} (hsuv : s ⊆ u ∪ v)
(H : s ∩ (u ∩ v) = ∅) : ((↑) : s → α) ⁻¹' u = ((↑) ⁻¹' v)ᶜ := by
ext ⟨x, x_in_s⟩
constructor
· intro x_in_u x_in_v
exact eq_empty_iff_forall_not_mem.mp H x ⟨x_in_s, ⟨x_in_u, x_in_v⟩⟩
· intro hx
exact Or.elim (hsuv x_in_s) id fun hx' => hx.elim hx'
#align set.preimage_subtype_coe_eq_compl Set.preimage_subtype_coe_eq_compl
end Preimage
/-! ### Image of a set under a function -/
section Image
variable {f : α → β} {s t : Set α}
-- Porting note: `Set.image` is already defined in `Init.Set`
#align set.image Set.image
/-- `f '' s` denotes the image of `s : Set α` under the function `f : α → β`. -/
infixl:80 " '' " => image
theorem mem_image_iff_bex {f : α → β} {s : Set α} {y : β} :
y ∈ f '' s ↔ ∃ (x : _) (_ : x ∈ s), f x = y :=
bex_def.symm
#align set.mem_image_iff_bex Set.mem_image_iff_bex
@[simp]
theorem mem_image (f : α → β) (s : Set α) (y : β) : y ∈ f '' s ↔ ∃ x ∈ s, f x = y :=
Iff.rfl
#align set.mem_image Set.mem_image
theorem image_eta (f : α → β) : f '' s = (fun x => f x) '' s :=
rfl
#align set.image_eta Set.image_eta
@[mfld_simps]
theorem mem_image_of_mem (f : α → β) {x : α} {a : Set α} (h : x ∈ a) : f x ∈ f '' a :=
⟨_, h, rfl⟩
#align set.mem_image_of_mem Set.mem_image_of_mem
theorem _root_.Function.Injective.mem_set_image {f : α → β} (hf : Injective f) {s : Set α} {a : α} :
f a ∈ f '' s ↔ a ∈ s :=
⟨fun ⟨_, hb, Eq⟩ => hf Eq ▸ hb, mem_image_of_mem f⟩
#align function.injective.mem_set_image Function.Injective.mem_set_image
theorem ball_image_iff {f : α → β} {s : Set α} {p : β → Prop} :
(∀ y ∈ f '' s, p y) ↔ ∀ x ∈ s, p (f x) := by simp
#align set.ball_image_iff Set.ball_image_iff
theorem ball_image_of_ball {f : α → β} {s : Set α} {p : β → Prop} (h : ∀ x ∈ s, p (f x)) :
∀ y ∈ f '' s, p y :=
ball_image_iff.2 h
#align set.ball_image_of_ball Set.ball_image_of_ball
theorem bex_image_iff {f : α → β} {s : Set α} {p : β → Prop} :
(∃ y ∈ f '' s, p y) ↔ ∃ x ∈ s, p (f x) := by simp
#align set.bex_image_iff Set.bex_image_iff
theorem mem_image_elim {f : α → β} {s : Set α} {C : β → Prop} (h : ∀ x : α, x ∈ s → C (f x)) :
∀ {y : β}, y ∈ f '' s → C y
| _, ⟨a, a_in, rfl⟩ => h a a_in
#align set.mem_image_elim Set.mem_image_elim
theorem mem_image_elim_on {f : α → β} {s : Set α} {C : β → Prop} {y : β} (h_y : y ∈ f '' s)
(h : ∀ x : α, x ∈ s → C (f x)) : C y :=
mem_image_elim h h_y
#align set.mem_image_elim_on Set.mem_image_elim_on
-- Porting note: used to be `safe`
@[congr]
theorem image_congr {f g : α → β} {s : Set α} (h : ∀ a ∈ s, f a = g a) : f '' s = g '' s := by
ext x
rw [mem_image, mem_image]
exact {
mp := by
rintro ⟨a, ha1, ha2⟩
exact ⟨a, ⟨ha1, (h a ha1) ▸ ha2⟩⟩,
mpr := by
rintro ⟨a, ha1, ha2⟩
exact ⟨a, ⟨ha1, (h a ha1) ▸ ha2⟩⟩
}
-- safe [ext_iff, iff_def]
#align set.image_congr Set.image_congr
/-- A common special case of `image_congr` -/
theorem image_congr' {f g : α → β} {s : Set α} (h : ∀ x : α, f x = g x) : f '' s = g '' s :=
image_congr fun x _ => h x
#align set.image_congr' Set.image_congr'
@[gcongr]
lemma image_mono (h : s ⊆ t) : f '' s ⊆ f '' t := by
rintro - ⟨a, ha, rfl⟩; exact mem_image_of_mem f (h ha)
theorem image_comp (f : β → γ) (g : α → β) (a : Set α) : f ∘ g '' a = f '' (g '' a) :=
Subset.antisymm (ball_image_of_ball fun _ ha => mem_image_of_mem _ <| mem_image_of_mem _ ha)
(ball_image_of_ball <| ball_image_of_ball fun _ ha => mem_image_of_mem _ ha)
#align set.image_comp Set.image_comp
theorem image_comp_eq {g : β → γ} : image (g ∘ f) = image g ∘ image f := by ext; simp
/-- A variant of `image_comp`, useful for rewriting -/
theorem image_image (g : β → γ) (f : α → β) (s : Set α) : g '' (f '' s) = (fun x => g (f x)) '' s :=
(image_comp g f s).symm
#align set.image_image Set.image_image
theorem image_comm {β'} {f : β → γ} {g : α → β} {f' : α → β'} {g' : β' → γ}
(h_comm : ∀ a, f (g a) = g' (f' a)) : (s.image g).image f = (s.image f').image g' := by
simp_rw [image_image, h_comm]
#align set.image_comm Set.image_comm
theorem _root_.Function.Semiconj.set_image {f : α → β} {ga : α → α} {gb : β → β}
(h : Function.Semiconj f ga gb) : Function.Semiconj (image f) (image ga) (image gb) := fun _ =>
image_comm h
#align function.semiconj.set_image Function.Semiconj.set_image
theorem _root_.Function.Commute.set_image {f g : α → α} (h : Function.Commute f g) :
Function.Commute (image f) (image g) :=
Function.Semiconj.set_image h
#align function.commute.set_image Function.Commute.set_image
/-- Image is monotone with respect to `⊆`. See `Set.monotone_image` for the statement in
terms of `≤`. -/
@[gcongr]
theorem image_subset {a b : Set α} (f : α → β) (h : a ⊆ b) : f '' a ⊆ f '' b := by
simp only [subset_def, mem_image]
exact fun x => fun ⟨w, h1, h2⟩ => ⟨w, h h1, h2⟩
#align set.image_subset Set.image_subset
/-- `Set.image` is monotone. See `Set.image_subset` for the statement in terms of `⊆`. -/
lemma monotone_image {f : α → β} : Monotone (image f) := fun _ _ => image_subset _
#align set.monotone_image Set.monotone_image
theorem image_union (f : α → β) (s t : Set α) : f '' (s ∪ t) = f '' s ∪ f '' t :=
ext fun x =>
⟨by rintro ⟨a, h | h, rfl⟩ <;> [left; right] <;> exact ⟨_, h, rfl⟩, by
rintro (⟨a, h, rfl⟩ | ⟨a, h, rfl⟩) <;> refine' ⟨_, _, rfl⟩ <;> [left; right] <;> exact h⟩
#align set.image_union Set.image_union
@[simp]
theorem image_empty (f : α → β) : f '' ∅ = ∅ := by
ext
simp
#align set.image_empty Set.image_empty
theorem image_inter_subset (f : α → β) (s t : Set α) : f '' (s ∩ t) ⊆ f '' s ∩ f '' t :=
subset_inter (image_subset _ <| inter_subset_left _ _) (image_subset _ <| inter_subset_right _ _)
#align set.image_inter_subset Set.image_inter_subset
theorem image_inter_on {f : α → β} {s t : Set α} (h : ∀ x ∈ t, ∀ y ∈ s, f x = f y → x = y) :
f '' (s ∩ t) = f '' s ∩ f '' t :=
(image_inter_subset _ _ _).antisymm
fun b ⟨⟨a₁, ha₁, h₁⟩, ⟨a₂, ha₂, h₂⟩⟩ ↦
have : a₂ = a₁ := h _ ha₂ _ ha₁ (by simp [*])
⟨a₁, ⟨ha₁, this ▸ ha₂⟩, h₁⟩
#align set.image_inter_on Set.image_inter_on
theorem image_inter {f : α → β} {s t : Set α} (H : Injective f) : f '' (s ∩ t) = f '' s ∩ f '' t :=
image_inter_on fun _ _ _ _ h => H h
#align set.image_inter Set.image_inter
theorem image_univ_of_surjective {ι : Type*} {f : ι → β} (H : Surjective f) : f '' univ = univ :=
eq_univ_of_forall <| by simpa [image]
#align set.image_univ_of_surjective Set.image_univ_of_surjective
@[simp]
theorem image_singleton {f : α → β} {a : α} : f '' {a} = {f a} := by
ext
simp [image, eq_comm]
#align set.image_singleton Set.image_singleton
@[simp]
theorem Nonempty.image_const {s : Set α} (hs : s.Nonempty) (a : β) : (fun _ => a) '' s = {a} :=
ext fun _ =>
⟨fun ⟨_, _, h⟩ => h ▸ mem_singleton _, fun h =>
(eq_of_mem_singleton h).symm ▸ hs.imp fun _ hy => ⟨hy, rfl⟩⟩
#align set.nonempty.image_const Set.Nonempty.image_const
@[simp, mfld_simps]
theorem image_eq_empty {α β} {f : α → β} {s : Set α} : f '' s = ∅ ↔ s = ∅ := by
simp only [eq_empty_iff_forall_not_mem]
exact ⟨fun H a ha => H _ ⟨_, ha, rfl⟩, fun H b ⟨_, ha, _⟩ => H _ ha⟩
#align set.image_eq_empty Set.image_eq_empty
-- Porting note: `compl` is already defined in `Init.Set`
theorem preimage_compl_eq_image_compl [BooleanAlgebra α] (S : Set α) :
HasCompl.compl ⁻¹' S = HasCompl.compl '' S :=
Set.ext fun x =>
⟨fun h => ⟨xᶜ, h, compl_compl x⟩, fun h =>
Exists.elim h fun _ hy => (compl_eq_comm.mp hy.2).symm.subst hy.1⟩
#align set.preimage_compl_eq_image_compl Set.preimage_compl_eq_image_compl
theorem mem_compl_image [BooleanAlgebra α] (t : α) (S : Set α) :
t ∈ HasCompl.compl '' S ↔ tᶜ ∈ S := by
simp [← preimage_compl_eq_image_compl]
#align set.mem_compl_image Set.mem_compl_image
@[simp]
theorem image_id_eq : image (id : α → α) = id := by ext; simp
/-- A variant of `image_id` -/
@[simp]
theorem image_id' (s : Set α) : (fun x => x) '' s = s := by
ext
simp
#align set.image_id' Set.image_id'
theorem image_id (s : Set α) : id '' s = s := by simp
#align set.image_id Set.image_id
lemma image_iterate_eq {f : α → α} {n : ℕ} : image (f^[n]) = (image f)^[n] := by
induction' n with n ih; · simp
rw [iterate_succ', iterate_succ',← ih, image_comp_eq]
theorem compl_compl_image [BooleanAlgebra α] (S : Set α) :
HasCompl.compl '' (HasCompl.compl '' S) = S := by
rw [← image_comp, compl_comp_compl, image_id]
#align set.compl_compl_image Set.compl_compl_image
theorem image_insert_eq {f : α → β} {a : α} {s : Set α} :
f '' insert a s = insert (f a) (f '' s) := by
ext
|
simp [and_or_left, exists_or, eq_comm, or_comm, and_comm]
|
theorem image_insert_eq {f : α → β} {a : α} {s : Set α} :
f '' insert a s = insert (f a) (f '' s) := by
ext
|
Mathlib.Data.Set.Image.422_0.IJFiTzmYGOCpPSd
|
theorem image_insert_eq {f : α → β} {a : α} {s : Set α} :
f '' insert a s = insert (f a) (f '' s)
|
Mathlib_Data_Set_Image
|
α : Type u_1
β : Type u_2
γ : Type u_3
ι : Sort u_4
ι' : Sort u_5
f✝ : α → β
s t : Set α
f : α → β
a b : α
⊢ f '' {a, b} = {f a, f b}
|
/-
Copyright (c) 2014 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Leonardo de Moura
-/
import Mathlib.Data.Set.Basic
#align_import data.set.image from "leanprover-community/mathlib"@"001ffdc42920050657fd45bd2b8bfbec8eaaeb29"
/-!
# Images and preimages of sets
## Main definitions
* `preimage f t : Set α` : the preimage f⁻¹(t) (written `f ⁻¹' t` in Lean) of a subset of β.
* `range f : Set β` : the image of `univ` under `f`.
Also works for `{p : Prop} (f : p → α)` (unlike `image`)
## Notation
* `f ⁻¹' t` for `Set.preimage f t`
* `f '' s` for `Set.image f s`
## Tags
set, sets, image, preimage, pre-image, range
-/
set_option autoImplicit true
universe u v
open Function Set
namespace Set
variable {α β γ : Type*} {ι ι' : Sort*}
/-! ### Inverse image -/
/-- The preimage of `s : Set β` by `f : α → β`, written `f ⁻¹' s`,
is the set of `x : α` such that `f x ∈ s`. -/
def preimage {α : Type u} {β : Type v} (f : α → β) (s : Set β) : Set α :=
{ x | f x ∈ s }
#align set.preimage Set.preimage
/-- `f ⁻¹' t` denotes the preimage of `t : Set β` under the function `f : α → β`. -/
infixl:80 " ⁻¹' " => preimage
section Preimage
variable {f : α → β} {g : β → γ}
@[simp]
theorem preimage_empty : f ⁻¹' ∅ = ∅ :=
rfl
#align set.preimage_empty Set.preimage_empty
@[simp, mfld_simps]
theorem mem_preimage {s : Set β} {a : α} : a ∈ f ⁻¹' s ↔ f a ∈ s :=
Iff.rfl
#align set.mem_preimage Set.mem_preimage
theorem preimage_congr {f g : α → β} {s : Set β} (h : ∀ x : α, f x = g x) : f ⁻¹' s = g ⁻¹' s := by
congr with x
simp [h]
#align set.preimage_congr Set.preimage_congr
@[gcongr]
theorem preimage_mono {s t : Set β} (h : s ⊆ t) : f ⁻¹' s ⊆ f ⁻¹' t := fun _ hx => h hx
#align set.preimage_mono Set.preimage_mono
@[simp, mfld_simps]
theorem preimage_univ : f ⁻¹' univ = univ :=
rfl
#align set.preimage_univ Set.preimage_univ
theorem subset_preimage_univ {s : Set α} : s ⊆ f ⁻¹' univ :=
subset_univ _
#align set.subset_preimage_univ Set.subset_preimage_univ
@[simp, mfld_simps]
theorem preimage_inter {s t : Set β} : f ⁻¹' (s ∩ t) = f ⁻¹' s ∩ f ⁻¹' t :=
rfl
#align set.preimage_inter Set.preimage_inter
@[simp]
theorem preimage_union {s t : Set β} : f ⁻¹' (s ∪ t) = f ⁻¹' s ∪ f ⁻¹' t :=
rfl
#align set.preimage_union Set.preimage_union
@[simp]
theorem preimage_compl {s : Set β} : f ⁻¹' sᶜ = (f ⁻¹' s)ᶜ :=
rfl
#align set.preimage_compl Set.preimage_compl
@[simp]
theorem preimage_diff (f : α → β) (s t : Set β) : f ⁻¹' (s \ t) = f ⁻¹' s \ f ⁻¹' t :=
rfl
#align set.preimage_diff Set.preimage_diff
@[simp]
lemma preimage_symmDiff {f : α → β} (s t : Set β) : f ⁻¹' (s ∆ t) = (f ⁻¹' s) ∆ (f ⁻¹' t) :=
rfl
#align set.preimage_symm_diff Set.preimage_symmDiff
@[simp]
theorem preimage_ite (f : α → β) (s t₁ t₂ : Set β) :
f ⁻¹' s.ite t₁ t₂ = (f ⁻¹' s).ite (f ⁻¹' t₁) (f ⁻¹' t₂) :=
rfl
#align set.preimage_ite Set.preimage_ite
@[simp]
theorem preimage_setOf_eq {p : α → Prop} {f : β → α} : f ⁻¹' { a | p a } = { a | p (f a) } :=
rfl
#align set.preimage_set_of_eq Set.preimage_setOf_eq
@[simp]
theorem preimage_id_eq : preimage (id : α → α) = id :=
rfl
#align set.preimage_id_eq Set.preimage_id_eq
@[mfld_simps]
theorem preimage_id {s : Set α} : id ⁻¹' s = s :=
rfl
#align set.preimage_id Set.preimage_id
@[simp, mfld_simps]
theorem preimage_id' {s : Set α} : (fun x => x) ⁻¹' s = s :=
rfl
#align set.preimage_id' Set.preimage_id'
@[simp]
theorem preimage_const_of_mem {b : β} {s : Set β} (h : b ∈ s) : (fun _ : α => b) ⁻¹' s = univ :=
eq_univ_of_forall fun _ => h
#align set.preimage_const_of_mem Set.preimage_const_of_mem
@[simp]
theorem preimage_const_of_not_mem {b : β} {s : Set β} (h : b ∉ s) : (fun _ : α => b) ⁻¹' s = ∅ :=
eq_empty_of_subset_empty fun _ hx => h hx
#align set.preimage_const_of_not_mem Set.preimage_const_of_not_mem
theorem preimage_const (b : β) (s : Set β) [Decidable (b ∈ s)] :
(fun _ : α => b) ⁻¹' s = if b ∈ s then univ else ∅ := by
split_ifs with hb
exacts [preimage_const_of_mem hb, preimage_const_of_not_mem hb]
#align set.preimage_const Set.preimage_const
/-- If preimage of each singleton under `f : α → β` is either empty or the whole type,
then `f` is a constant. -/
lemma exists_eq_const_of_preimage_singleton [Nonempty β] {f : α → β}
(hf : ∀ b : β, f ⁻¹' {b} = ∅ ∨ f ⁻¹' {b} = univ) : ∃ b, f = const α b := by
rcases em (∃ b, f ⁻¹' {b} = univ) with ⟨b, hb⟩ | hf'
· exact ⟨b, funext fun x ↦ eq_univ_iff_forall.1 hb x⟩
· have : ∀ x b, f x ≠ b := fun x b ↦
eq_empty_iff_forall_not_mem.1 ((hf b).resolve_right fun h ↦ hf' ⟨b, h⟩) x
exact ⟨Classical.arbitrary β, funext fun x ↦ absurd rfl (this x _)⟩
theorem preimage_comp {s : Set γ} : g ∘ f ⁻¹' s = f ⁻¹' (g ⁻¹' s) :=
rfl
#align set.preimage_comp Set.preimage_comp
theorem preimage_comp_eq : preimage (g ∘ f) = preimage f ∘ preimage g :=
rfl
#align set.preimage_comp_eq Set.preimage_comp_eq
theorem preimage_iterate_eq {f : α → α} {n : ℕ} : Set.preimage f^[n] = (Set.preimage f)^[n] := by
induction' n with n ih; · simp
rw [iterate_succ, iterate_succ', preimage_comp_eq, ih]
#align set.preimage_iterate_eq Set.preimage_iterate_eq
theorem preimage_preimage {g : β → γ} {f : α → β} {s : Set γ} :
f ⁻¹' (g ⁻¹' s) = (fun x => g (f x)) ⁻¹' s :=
preimage_comp.symm
#align set.preimage_preimage Set.preimage_preimage
theorem eq_preimage_subtype_val_iff {p : α → Prop} {s : Set (Subtype p)} {t : Set α} :
s = Subtype.val ⁻¹' t ↔ ∀ (x) (h : p x), (⟨x, h⟩ : Subtype p) ∈ s ↔ x ∈ t :=
⟨fun s_eq x h => by
rw [s_eq]
simp, fun h => ext fun ⟨x, hx⟩ => by simp [h]⟩
#align set.eq_preimage_subtype_val_iff Set.eq_preimage_subtype_val_iff
theorem nonempty_of_nonempty_preimage {s : Set β} {f : α → β} (hf : (f ⁻¹' s).Nonempty) :
s.Nonempty :=
let ⟨x, hx⟩ := hf
⟨f x, hx⟩
#align set.nonempty_of_nonempty_preimage Set.nonempty_of_nonempty_preimage
@[simp] theorem preimage_singleton_true (p : α → Prop) : p ⁻¹' {True} = {a | p a} := by ext; simp
#align set.preimage_singleton_true Set.preimage_singleton_true
@[simp] theorem preimage_singleton_false (p : α → Prop) : p ⁻¹' {False} = {a | ¬p a} := by ext; simp
#align set.preimage_singleton_false Set.preimage_singleton_false
theorem preimage_subtype_coe_eq_compl {s u v : Set α} (hsuv : s ⊆ u ∪ v)
(H : s ∩ (u ∩ v) = ∅) : ((↑) : s → α) ⁻¹' u = ((↑) ⁻¹' v)ᶜ := by
ext ⟨x, x_in_s⟩
constructor
· intro x_in_u x_in_v
exact eq_empty_iff_forall_not_mem.mp H x ⟨x_in_s, ⟨x_in_u, x_in_v⟩⟩
· intro hx
exact Or.elim (hsuv x_in_s) id fun hx' => hx.elim hx'
#align set.preimage_subtype_coe_eq_compl Set.preimage_subtype_coe_eq_compl
end Preimage
/-! ### Image of a set under a function -/
section Image
variable {f : α → β} {s t : Set α}
-- Porting note: `Set.image` is already defined in `Init.Set`
#align set.image Set.image
/-- `f '' s` denotes the image of `s : Set α` under the function `f : α → β`. -/
infixl:80 " '' " => image
theorem mem_image_iff_bex {f : α → β} {s : Set α} {y : β} :
y ∈ f '' s ↔ ∃ (x : _) (_ : x ∈ s), f x = y :=
bex_def.symm
#align set.mem_image_iff_bex Set.mem_image_iff_bex
@[simp]
theorem mem_image (f : α → β) (s : Set α) (y : β) : y ∈ f '' s ↔ ∃ x ∈ s, f x = y :=
Iff.rfl
#align set.mem_image Set.mem_image
theorem image_eta (f : α → β) : f '' s = (fun x => f x) '' s :=
rfl
#align set.image_eta Set.image_eta
@[mfld_simps]
theorem mem_image_of_mem (f : α → β) {x : α} {a : Set α} (h : x ∈ a) : f x ∈ f '' a :=
⟨_, h, rfl⟩
#align set.mem_image_of_mem Set.mem_image_of_mem
theorem _root_.Function.Injective.mem_set_image {f : α → β} (hf : Injective f) {s : Set α} {a : α} :
f a ∈ f '' s ↔ a ∈ s :=
⟨fun ⟨_, hb, Eq⟩ => hf Eq ▸ hb, mem_image_of_mem f⟩
#align function.injective.mem_set_image Function.Injective.mem_set_image
theorem ball_image_iff {f : α → β} {s : Set α} {p : β → Prop} :
(∀ y ∈ f '' s, p y) ↔ ∀ x ∈ s, p (f x) := by simp
#align set.ball_image_iff Set.ball_image_iff
theorem ball_image_of_ball {f : α → β} {s : Set α} {p : β → Prop} (h : ∀ x ∈ s, p (f x)) :
∀ y ∈ f '' s, p y :=
ball_image_iff.2 h
#align set.ball_image_of_ball Set.ball_image_of_ball
theorem bex_image_iff {f : α → β} {s : Set α} {p : β → Prop} :
(∃ y ∈ f '' s, p y) ↔ ∃ x ∈ s, p (f x) := by simp
#align set.bex_image_iff Set.bex_image_iff
theorem mem_image_elim {f : α → β} {s : Set α} {C : β → Prop} (h : ∀ x : α, x ∈ s → C (f x)) :
∀ {y : β}, y ∈ f '' s → C y
| _, ⟨a, a_in, rfl⟩ => h a a_in
#align set.mem_image_elim Set.mem_image_elim
theorem mem_image_elim_on {f : α → β} {s : Set α} {C : β → Prop} {y : β} (h_y : y ∈ f '' s)
(h : ∀ x : α, x ∈ s → C (f x)) : C y :=
mem_image_elim h h_y
#align set.mem_image_elim_on Set.mem_image_elim_on
-- Porting note: used to be `safe`
@[congr]
theorem image_congr {f g : α → β} {s : Set α} (h : ∀ a ∈ s, f a = g a) : f '' s = g '' s := by
ext x
rw [mem_image, mem_image]
exact {
mp := by
rintro ⟨a, ha1, ha2⟩
exact ⟨a, ⟨ha1, (h a ha1) ▸ ha2⟩⟩,
mpr := by
rintro ⟨a, ha1, ha2⟩
exact ⟨a, ⟨ha1, (h a ha1) ▸ ha2⟩⟩
}
-- safe [ext_iff, iff_def]
#align set.image_congr Set.image_congr
/-- A common special case of `image_congr` -/
theorem image_congr' {f g : α → β} {s : Set α} (h : ∀ x : α, f x = g x) : f '' s = g '' s :=
image_congr fun x _ => h x
#align set.image_congr' Set.image_congr'
@[gcongr]
lemma image_mono (h : s ⊆ t) : f '' s ⊆ f '' t := by
rintro - ⟨a, ha, rfl⟩; exact mem_image_of_mem f (h ha)
theorem image_comp (f : β → γ) (g : α → β) (a : Set α) : f ∘ g '' a = f '' (g '' a) :=
Subset.antisymm (ball_image_of_ball fun _ ha => mem_image_of_mem _ <| mem_image_of_mem _ ha)
(ball_image_of_ball <| ball_image_of_ball fun _ ha => mem_image_of_mem _ ha)
#align set.image_comp Set.image_comp
theorem image_comp_eq {g : β → γ} : image (g ∘ f) = image g ∘ image f := by ext; simp
/-- A variant of `image_comp`, useful for rewriting -/
theorem image_image (g : β → γ) (f : α → β) (s : Set α) : g '' (f '' s) = (fun x => g (f x)) '' s :=
(image_comp g f s).symm
#align set.image_image Set.image_image
theorem image_comm {β'} {f : β → γ} {g : α → β} {f' : α → β'} {g' : β' → γ}
(h_comm : ∀ a, f (g a) = g' (f' a)) : (s.image g).image f = (s.image f').image g' := by
simp_rw [image_image, h_comm]
#align set.image_comm Set.image_comm
theorem _root_.Function.Semiconj.set_image {f : α → β} {ga : α → α} {gb : β → β}
(h : Function.Semiconj f ga gb) : Function.Semiconj (image f) (image ga) (image gb) := fun _ =>
image_comm h
#align function.semiconj.set_image Function.Semiconj.set_image
theorem _root_.Function.Commute.set_image {f g : α → α} (h : Function.Commute f g) :
Function.Commute (image f) (image g) :=
Function.Semiconj.set_image h
#align function.commute.set_image Function.Commute.set_image
/-- Image is monotone with respect to `⊆`. See `Set.monotone_image` for the statement in
terms of `≤`. -/
@[gcongr]
theorem image_subset {a b : Set α} (f : α → β) (h : a ⊆ b) : f '' a ⊆ f '' b := by
simp only [subset_def, mem_image]
exact fun x => fun ⟨w, h1, h2⟩ => ⟨w, h h1, h2⟩
#align set.image_subset Set.image_subset
/-- `Set.image` is monotone. See `Set.image_subset` for the statement in terms of `⊆`. -/
lemma monotone_image {f : α → β} : Monotone (image f) := fun _ _ => image_subset _
#align set.monotone_image Set.monotone_image
theorem image_union (f : α → β) (s t : Set α) : f '' (s ∪ t) = f '' s ∪ f '' t :=
ext fun x =>
⟨by rintro ⟨a, h | h, rfl⟩ <;> [left; right] <;> exact ⟨_, h, rfl⟩, by
rintro (⟨a, h, rfl⟩ | ⟨a, h, rfl⟩) <;> refine' ⟨_, _, rfl⟩ <;> [left; right] <;> exact h⟩
#align set.image_union Set.image_union
@[simp]
theorem image_empty (f : α → β) : f '' ∅ = ∅ := by
ext
simp
#align set.image_empty Set.image_empty
theorem image_inter_subset (f : α → β) (s t : Set α) : f '' (s ∩ t) ⊆ f '' s ∩ f '' t :=
subset_inter (image_subset _ <| inter_subset_left _ _) (image_subset _ <| inter_subset_right _ _)
#align set.image_inter_subset Set.image_inter_subset
theorem image_inter_on {f : α → β} {s t : Set α} (h : ∀ x ∈ t, ∀ y ∈ s, f x = f y → x = y) :
f '' (s ∩ t) = f '' s ∩ f '' t :=
(image_inter_subset _ _ _).antisymm
fun b ⟨⟨a₁, ha₁, h₁⟩, ⟨a₂, ha₂, h₂⟩⟩ ↦
have : a₂ = a₁ := h _ ha₂ _ ha₁ (by simp [*])
⟨a₁, ⟨ha₁, this ▸ ha₂⟩, h₁⟩
#align set.image_inter_on Set.image_inter_on
theorem image_inter {f : α → β} {s t : Set α} (H : Injective f) : f '' (s ∩ t) = f '' s ∩ f '' t :=
image_inter_on fun _ _ _ _ h => H h
#align set.image_inter Set.image_inter
theorem image_univ_of_surjective {ι : Type*} {f : ι → β} (H : Surjective f) : f '' univ = univ :=
eq_univ_of_forall <| by simpa [image]
#align set.image_univ_of_surjective Set.image_univ_of_surjective
@[simp]
theorem image_singleton {f : α → β} {a : α} : f '' {a} = {f a} := by
ext
simp [image, eq_comm]
#align set.image_singleton Set.image_singleton
@[simp]
theorem Nonempty.image_const {s : Set α} (hs : s.Nonempty) (a : β) : (fun _ => a) '' s = {a} :=
ext fun _ =>
⟨fun ⟨_, _, h⟩ => h ▸ mem_singleton _, fun h =>
(eq_of_mem_singleton h).symm ▸ hs.imp fun _ hy => ⟨hy, rfl⟩⟩
#align set.nonempty.image_const Set.Nonempty.image_const
@[simp, mfld_simps]
theorem image_eq_empty {α β} {f : α → β} {s : Set α} : f '' s = ∅ ↔ s = ∅ := by
simp only [eq_empty_iff_forall_not_mem]
exact ⟨fun H a ha => H _ ⟨_, ha, rfl⟩, fun H b ⟨_, ha, _⟩ => H _ ha⟩
#align set.image_eq_empty Set.image_eq_empty
-- Porting note: `compl` is already defined in `Init.Set`
theorem preimage_compl_eq_image_compl [BooleanAlgebra α] (S : Set α) :
HasCompl.compl ⁻¹' S = HasCompl.compl '' S :=
Set.ext fun x =>
⟨fun h => ⟨xᶜ, h, compl_compl x⟩, fun h =>
Exists.elim h fun _ hy => (compl_eq_comm.mp hy.2).symm.subst hy.1⟩
#align set.preimage_compl_eq_image_compl Set.preimage_compl_eq_image_compl
theorem mem_compl_image [BooleanAlgebra α] (t : α) (S : Set α) :
t ∈ HasCompl.compl '' S ↔ tᶜ ∈ S := by
simp [← preimage_compl_eq_image_compl]
#align set.mem_compl_image Set.mem_compl_image
@[simp]
theorem image_id_eq : image (id : α → α) = id := by ext; simp
/-- A variant of `image_id` -/
@[simp]
theorem image_id' (s : Set α) : (fun x => x) '' s = s := by
ext
simp
#align set.image_id' Set.image_id'
theorem image_id (s : Set α) : id '' s = s := by simp
#align set.image_id Set.image_id
lemma image_iterate_eq {f : α → α} {n : ℕ} : image (f^[n]) = (image f)^[n] := by
induction' n with n ih; · simp
rw [iterate_succ', iterate_succ',← ih, image_comp_eq]
theorem compl_compl_image [BooleanAlgebra α] (S : Set α) :
HasCompl.compl '' (HasCompl.compl '' S) = S := by
rw [← image_comp, compl_comp_compl, image_id]
#align set.compl_compl_image Set.compl_compl_image
theorem image_insert_eq {f : α → β} {a : α} {s : Set α} :
f '' insert a s = insert (f a) (f '' s) := by
ext
simp [and_or_left, exists_or, eq_comm, or_comm, and_comm]
#align set.image_insert_eq Set.image_insert_eq
theorem image_pair (f : α → β) (a b : α) : f '' {a, b} = {f a, f b} := by
|
simp only [image_insert_eq, image_singleton]
|
theorem image_pair (f : α → β) (a b : α) : f '' {a, b} = {f a, f b} := by
|
Mathlib.Data.Set.Image.428_0.IJFiTzmYGOCpPSd
|
theorem image_pair (f : α → β) (a b : α) : f '' {a, b} = {f a, f b}
|
Mathlib_Data_Set_Image
|
α : Type u_1
β : Type u_2
γ : Type u_3
ι : Sort u_4
ι' : Sort u_5
f✝ : α → β
s✝ t : Set α
f : α → β
g : β → α
b : β
s : Set α
h₁ : LeftInverse g f
h₂ : Function.RightInverse g f
⊢ b ∈ f '' s ↔ g b ∈ s
|
/-
Copyright (c) 2014 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Leonardo de Moura
-/
import Mathlib.Data.Set.Basic
#align_import data.set.image from "leanprover-community/mathlib"@"001ffdc42920050657fd45bd2b8bfbec8eaaeb29"
/-!
# Images and preimages of sets
## Main definitions
* `preimage f t : Set α` : the preimage f⁻¹(t) (written `f ⁻¹' t` in Lean) of a subset of β.
* `range f : Set β` : the image of `univ` under `f`.
Also works for `{p : Prop} (f : p → α)` (unlike `image`)
## Notation
* `f ⁻¹' t` for `Set.preimage f t`
* `f '' s` for `Set.image f s`
## Tags
set, sets, image, preimage, pre-image, range
-/
set_option autoImplicit true
universe u v
open Function Set
namespace Set
variable {α β γ : Type*} {ι ι' : Sort*}
/-! ### Inverse image -/
/-- The preimage of `s : Set β` by `f : α → β`, written `f ⁻¹' s`,
is the set of `x : α` such that `f x ∈ s`. -/
def preimage {α : Type u} {β : Type v} (f : α → β) (s : Set β) : Set α :=
{ x | f x ∈ s }
#align set.preimage Set.preimage
/-- `f ⁻¹' t` denotes the preimage of `t : Set β` under the function `f : α → β`. -/
infixl:80 " ⁻¹' " => preimage
section Preimage
variable {f : α → β} {g : β → γ}
@[simp]
theorem preimage_empty : f ⁻¹' ∅ = ∅ :=
rfl
#align set.preimage_empty Set.preimage_empty
@[simp, mfld_simps]
theorem mem_preimage {s : Set β} {a : α} : a ∈ f ⁻¹' s ↔ f a ∈ s :=
Iff.rfl
#align set.mem_preimage Set.mem_preimage
theorem preimage_congr {f g : α → β} {s : Set β} (h : ∀ x : α, f x = g x) : f ⁻¹' s = g ⁻¹' s := by
congr with x
simp [h]
#align set.preimage_congr Set.preimage_congr
@[gcongr]
theorem preimage_mono {s t : Set β} (h : s ⊆ t) : f ⁻¹' s ⊆ f ⁻¹' t := fun _ hx => h hx
#align set.preimage_mono Set.preimage_mono
@[simp, mfld_simps]
theorem preimage_univ : f ⁻¹' univ = univ :=
rfl
#align set.preimage_univ Set.preimage_univ
theorem subset_preimage_univ {s : Set α} : s ⊆ f ⁻¹' univ :=
subset_univ _
#align set.subset_preimage_univ Set.subset_preimage_univ
@[simp, mfld_simps]
theorem preimage_inter {s t : Set β} : f ⁻¹' (s ∩ t) = f ⁻¹' s ∩ f ⁻¹' t :=
rfl
#align set.preimage_inter Set.preimage_inter
@[simp]
theorem preimage_union {s t : Set β} : f ⁻¹' (s ∪ t) = f ⁻¹' s ∪ f ⁻¹' t :=
rfl
#align set.preimage_union Set.preimage_union
@[simp]
theorem preimage_compl {s : Set β} : f ⁻¹' sᶜ = (f ⁻¹' s)ᶜ :=
rfl
#align set.preimage_compl Set.preimage_compl
@[simp]
theorem preimage_diff (f : α → β) (s t : Set β) : f ⁻¹' (s \ t) = f ⁻¹' s \ f ⁻¹' t :=
rfl
#align set.preimage_diff Set.preimage_diff
@[simp]
lemma preimage_symmDiff {f : α → β} (s t : Set β) : f ⁻¹' (s ∆ t) = (f ⁻¹' s) ∆ (f ⁻¹' t) :=
rfl
#align set.preimage_symm_diff Set.preimage_symmDiff
@[simp]
theorem preimage_ite (f : α → β) (s t₁ t₂ : Set β) :
f ⁻¹' s.ite t₁ t₂ = (f ⁻¹' s).ite (f ⁻¹' t₁) (f ⁻¹' t₂) :=
rfl
#align set.preimage_ite Set.preimage_ite
@[simp]
theorem preimage_setOf_eq {p : α → Prop} {f : β → α} : f ⁻¹' { a | p a } = { a | p (f a) } :=
rfl
#align set.preimage_set_of_eq Set.preimage_setOf_eq
@[simp]
theorem preimage_id_eq : preimage (id : α → α) = id :=
rfl
#align set.preimage_id_eq Set.preimage_id_eq
@[mfld_simps]
theorem preimage_id {s : Set α} : id ⁻¹' s = s :=
rfl
#align set.preimage_id Set.preimage_id
@[simp, mfld_simps]
theorem preimage_id' {s : Set α} : (fun x => x) ⁻¹' s = s :=
rfl
#align set.preimage_id' Set.preimage_id'
@[simp]
theorem preimage_const_of_mem {b : β} {s : Set β} (h : b ∈ s) : (fun _ : α => b) ⁻¹' s = univ :=
eq_univ_of_forall fun _ => h
#align set.preimage_const_of_mem Set.preimage_const_of_mem
@[simp]
theorem preimage_const_of_not_mem {b : β} {s : Set β} (h : b ∉ s) : (fun _ : α => b) ⁻¹' s = ∅ :=
eq_empty_of_subset_empty fun _ hx => h hx
#align set.preimage_const_of_not_mem Set.preimage_const_of_not_mem
theorem preimage_const (b : β) (s : Set β) [Decidable (b ∈ s)] :
(fun _ : α => b) ⁻¹' s = if b ∈ s then univ else ∅ := by
split_ifs with hb
exacts [preimage_const_of_mem hb, preimage_const_of_not_mem hb]
#align set.preimage_const Set.preimage_const
/-- If preimage of each singleton under `f : α → β` is either empty or the whole type,
then `f` is a constant. -/
lemma exists_eq_const_of_preimage_singleton [Nonempty β] {f : α → β}
(hf : ∀ b : β, f ⁻¹' {b} = ∅ ∨ f ⁻¹' {b} = univ) : ∃ b, f = const α b := by
rcases em (∃ b, f ⁻¹' {b} = univ) with ⟨b, hb⟩ | hf'
· exact ⟨b, funext fun x ↦ eq_univ_iff_forall.1 hb x⟩
· have : ∀ x b, f x ≠ b := fun x b ↦
eq_empty_iff_forall_not_mem.1 ((hf b).resolve_right fun h ↦ hf' ⟨b, h⟩) x
exact ⟨Classical.arbitrary β, funext fun x ↦ absurd rfl (this x _)⟩
theorem preimage_comp {s : Set γ} : g ∘ f ⁻¹' s = f ⁻¹' (g ⁻¹' s) :=
rfl
#align set.preimage_comp Set.preimage_comp
theorem preimage_comp_eq : preimage (g ∘ f) = preimage f ∘ preimage g :=
rfl
#align set.preimage_comp_eq Set.preimage_comp_eq
theorem preimage_iterate_eq {f : α → α} {n : ℕ} : Set.preimage f^[n] = (Set.preimage f)^[n] := by
induction' n with n ih; · simp
rw [iterate_succ, iterate_succ', preimage_comp_eq, ih]
#align set.preimage_iterate_eq Set.preimage_iterate_eq
theorem preimage_preimage {g : β → γ} {f : α → β} {s : Set γ} :
f ⁻¹' (g ⁻¹' s) = (fun x => g (f x)) ⁻¹' s :=
preimage_comp.symm
#align set.preimage_preimage Set.preimage_preimage
theorem eq_preimage_subtype_val_iff {p : α → Prop} {s : Set (Subtype p)} {t : Set α} :
s = Subtype.val ⁻¹' t ↔ ∀ (x) (h : p x), (⟨x, h⟩ : Subtype p) ∈ s ↔ x ∈ t :=
⟨fun s_eq x h => by
rw [s_eq]
simp, fun h => ext fun ⟨x, hx⟩ => by simp [h]⟩
#align set.eq_preimage_subtype_val_iff Set.eq_preimage_subtype_val_iff
theorem nonempty_of_nonempty_preimage {s : Set β} {f : α → β} (hf : (f ⁻¹' s).Nonempty) :
s.Nonempty :=
let ⟨x, hx⟩ := hf
⟨f x, hx⟩
#align set.nonempty_of_nonempty_preimage Set.nonempty_of_nonempty_preimage
@[simp] theorem preimage_singleton_true (p : α → Prop) : p ⁻¹' {True} = {a | p a} := by ext; simp
#align set.preimage_singleton_true Set.preimage_singleton_true
@[simp] theorem preimage_singleton_false (p : α → Prop) : p ⁻¹' {False} = {a | ¬p a} := by ext; simp
#align set.preimage_singleton_false Set.preimage_singleton_false
theorem preimage_subtype_coe_eq_compl {s u v : Set α} (hsuv : s ⊆ u ∪ v)
(H : s ∩ (u ∩ v) = ∅) : ((↑) : s → α) ⁻¹' u = ((↑) ⁻¹' v)ᶜ := by
ext ⟨x, x_in_s⟩
constructor
· intro x_in_u x_in_v
exact eq_empty_iff_forall_not_mem.mp H x ⟨x_in_s, ⟨x_in_u, x_in_v⟩⟩
· intro hx
exact Or.elim (hsuv x_in_s) id fun hx' => hx.elim hx'
#align set.preimage_subtype_coe_eq_compl Set.preimage_subtype_coe_eq_compl
end Preimage
/-! ### Image of a set under a function -/
section Image
variable {f : α → β} {s t : Set α}
-- Porting note: `Set.image` is already defined in `Init.Set`
#align set.image Set.image
/-- `f '' s` denotes the image of `s : Set α` under the function `f : α → β`. -/
infixl:80 " '' " => image
theorem mem_image_iff_bex {f : α → β} {s : Set α} {y : β} :
y ∈ f '' s ↔ ∃ (x : _) (_ : x ∈ s), f x = y :=
bex_def.symm
#align set.mem_image_iff_bex Set.mem_image_iff_bex
@[simp]
theorem mem_image (f : α → β) (s : Set α) (y : β) : y ∈ f '' s ↔ ∃ x ∈ s, f x = y :=
Iff.rfl
#align set.mem_image Set.mem_image
theorem image_eta (f : α → β) : f '' s = (fun x => f x) '' s :=
rfl
#align set.image_eta Set.image_eta
@[mfld_simps]
theorem mem_image_of_mem (f : α → β) {x : α} {a : Set α} (h : x ∈ a) : f x ∈ f '' a :=
⟨_, h, rfl⟩
#align set.mem_image_of_mem Set.mem_image_of_mem
theorem _root_.Function.Injective.mem_set_image {f : α → β} (hf : Injective f) {s : Set α} {a : α} :
f a ∈ f '' s ↔ a ∈ s :=
⟨fun ⟨_, hb, Eq⟩ => hf Eq ▸ hb, mem_image_of_mem f⟩
#align function.injective.mem_set_image Function.Injective.mem_set_image
theorem ball_image_iff {f : α → β} {s : Set α} {p : β → Prop} :
(∀ y ∈ f '' s, p y) ↔ ∀ x ∈ s, p (f x) := by simp
#align set.ball_image_iff Set.ball_image_iff
theorem ball_image_of_ball {f : α → β} {s : Set α} {p : β → Prop} (h : ∀ x ∈ s, p (f x)) :
∀ y ∈ f '' s, p y :=
ball_image_iff.2 h
#align set.ball_image_of_ball Set.ball_image_of_ball
theorem bex_image_iff {f : α → β} {s : Set α} {p : β → Prop} :
(∃ y ∈ f '' s, p y) ↔ ∃ x ∈ s, p (f x) := by simp
#align set.bex_image_iff Set.bex_image_iff
theorem mem_image_elim {f : α → β} {s : Set α} {C : β → Prop} (h : ∀ x : α, x ∈ s → C (f x)) :
∀ {y : β}, y ∈ f '' s → C y
| _, ⟨a, a_in, rfl⟩ => h a a_in
#align set.mem_image_elim Set.mem_image_elim
theorem mem_image_elim_on {f : α → β} {s : Set α} {C : β → Prop} {y : β} (h_y : y ∈ f '' s)
(h : ∀ x : α, x ∈ s → C (f x)) : C y :=
mem_image_elim h h_y
#align set.mem_image_elim_on Set.mem_image_elim_on
-- Porting note: used to be `safe`
@[congr]
theorem image_congr {f g : α → β} {s : Set α} (h : ∀ a ∈ s, f a = g a) : f '' s = g '' s := by
ext x
rw [mem_image, mem_image]
exact {
mp := by
rintro ⟨a, ha1, ha2⟩
exact ⟨a, ⟨ha1, (h a ha1) ▸ ha2⟩⟩,
mpr := by
rintro ⟨a, ha1, ha2⟩
exact ⟨a, ⟨ha1, (h a ha1) ▸ ha2⟩⟩
}
-- safe [ext_iff, iff_def]
#align set.image_congr Set.image_congr
/-- A common special case of `image_congr` -/
theorem image_congr' {f g : α → β} {s : Set α} (h : ∀ x : α, f x = g x) : f '' s = g '' s :=
image_congr fun x _ => h x
#align set.image_congr' Set.image_congr'
@[gcongr]
lemma image_mono (h : s ⊆ t) : f '' s ⊆ f '' t := by
rintro - ⟨a, ha, rfl⟩; exact mem_image_of_mem f (h ha)
theorem image_comp (f : β → γ) (g : α → β) (a : Set α) : f ∘ g '' a = f '' (g '' a) :=
Subset.antisymm (ball_image_of_ball fun _ ha => mem_image_of_mem _ <| mem_image_of_mem _ ha)
(ball_image_of_ball <| ball_image_of_ball fun _ ha => mem_image_of_mem _ ha)
#align set.image_comp Set.image_comp
theorem image_comp_eq {g : β → γ} : image (g ∘ f) = image g ∘ image f := by ext; simp
/-- A variant of `image_comp`, useful for rewriting -/
theorem image_image (g : β → γ) (f : α → β) (s : Set α) : g '' (f '' s) = (fun x => g (f x)) '' s :=
(image_comp g f s).symm
#align set.image_image Set.image_image
theorem image_comm {β'} {f : β → γ} {g : α → β} {f' : α → β'} {g' : β' → γ}
(h_comm : ∀ a, f (g a) = g' (f' a)) : (s.image g).image f = (s.image f').image g' := by
simp_rw [image_image, h_comm]
#align set.image_comm Set.image_comm
theorem _root_.Function.Semiconj.set_image {f : α → β} {ga : α → α} {gb : β → β}
(h : Function.Semiconj f ga gb) : Function.Semiconj (image f) (image ga) (image gb) := fun _ =>
image_comm h
#align function.semiconj.set_image Function.Semiconj.set_image
theorem _root_.Function.Commute.set_image {f g : α → α} (h : Function.Commute f g) :
Function.Commute (image f) (image g) :=
Function.Semiconj.set_image h
#align function.commute.set_image Function.Commute.set_image
/-- Image is monotone with respect to `⊆`. See `Set.monotone_image` for the statement in
terms of `≤`. -/
@[gcongr]
theorem image_subset {a b : Set α} (f : α → β) (h : a ⊆ b) : f '' a ⊆ f '' b := by
simp only [subset_def, mem_image]
exact fun x => fun ⟨w, h1, h2⟩ => ⟨w, h h1, h2⟩
#align set.image_subset Set.image_subset
/-- `Set.image` is monotone. See `Set.image_subset` for the statement in terms of `⊆`. -/
lemma monotone_image {f : α → β} : Monotone (image f) := fun _ _ => image_subset _
#align set.monotone_image Set.monotone_image
theorem image_union (f : α → β) (s t : Set α) : f '' (s ∪ t) = f '' s ∪ f '' t :=
ext fun x =>
⟨by rintro ⟨a, h | h, rfl⟩ <;> [left; right] <;> exact ⟨_, h, rfl⟩, by
rintro (⟨a, h, rfl⟩ | ⟨a, h, rfl⟩) <;> refine' ⟨_, _, rfl⟩ <;> [left; right] <;> exact h⟩
#align set.image_union Set.image_union
@[simp]
theorem image_empty (f : α → β) : f '' ∅ = ∅ := by
ext
simp
#align set.image_empty Set.image_empty
theorem image_inter_subset (f : α → β) (s t : Set α) : f '' (s ∩ t) ⊆ f '' s ∩ f '' t :=
subset_inter (image_subset _ <| inter_subset_left _ _) (image_subset _ <| inter_subset_right _ _)
#align set.image_inter_subset Set.image_inter_subset
theorem image_inter_on {f : α → β} {s t : Set α} (h : ∀ x ∈ t, ∀ y ∈ s, f x = f y → x = y) :
f '' (s ∩ t) = f '' s ∩ f '' t :=
(image_inter_subset _ _ _).antisymm
fun b ⟨⟨a₁, ha₁, h₁⟩, ⟨a₂, ha₂, h₂⟩⟩ ↦
have : a₂ = a₁ := h _ ha₂ _ ha₁ (by simp [*])
⟨a₁, ⟨ha₁, this ▸ ha₂⟩, h₁⟩
#align set.image_inter_on Set.image_inter_on
theorem image_inter {f : α → β} {s t : Set α} (H : Injective f) : f '' (s ∩ t) = f '' s ∩ f '' t :=
image_inter_on fun _ _ _ _ h => H h
#align set.image_inter Set.image_inter
theorem image_univ_of_surjective {ι : Type*} {f : ι → β} (H : Surjective f) : f '' univ = univ :=
eq_univ_of_forall <| by simpa [image]
#align set.image_univ_of_surjective Set.image_univ_of_surjective
@[simp]
theorem image_singleton {f : α → β} {a : α} : f '' {a} = {f a} := by
ext
simp [image, eq_comm]
#align set.image_singleton Set.image_singleton
@[simp]
theorem Nonempty.image_const {s : Set α} (hs : s.Nonempty) (a : β) : (fun _ => a) '' s = {a} :=
ext fun _ =>
⟨fun ⟨_, _, h⟩ => h ▸ mem_singleton _, fun h =>
(eq_of_mem_singleton h).symm ▸ hs.imp fun _ hy => ⟨hy, rfl⟩⟩
#align set.nonempty.image_const Set.Nonempty.image_const
@[simp, mfld_simps]
theorem image_eq_empty {α β} {f : α → β} {s : Set α} : f '' s = ∅ ↔ s = ∅ := by
simp only [eq_empty_iff_forall_not_mem]
exact ⟨fun H a ha => H _ ⟨_, ha, rfl⟩, fun H b ⟨_, ha, _⟩ => H _ ha⟩
#align set.image_eq_empty Set.image_eq_empty
-- Porting note: `compl` is already defined in `Init.Set`
theorem preimage_compl_eq_image_compl [BooleanAlgebra α] (S : Set α) :
HasCompl.compl ⁻¹' S = HasCompl.compl '' S :=
Set.ext fun x =>
⟨fun h => ⟨xᶜ, h, compl_compl x⟩, fun h =>
Exists.elim h fun _ hy => (compl_eq_comm.mp hy.2).symm.subst hy.1⟩
#align set.preimage_compl_eq_image_compl Set.preimage_compl_eq_image_compl
theorem mem_compl_image [BooleanAlgebra α] (t : α) (S : Set α) :
t ∈ HasCompl.compl '' S ↔ tᶜ ∈ S := by
simp [← preimage_compl_eq_image_compl]
#align set.mem_compl_image Set.mem_compl_image
@[simp]
theorem image_id_eq : image (id : α → α) = id := by ext; simp
/-- A variant of `image_id` -/
@[simp]
theorem image_id' (s : Set α) : (fun x => x) '' s = s := by
ext
simp
#align set.image_id' Set.image_id'
theorem image_id (s : Set α) : id '' s = s := by simp
#align set.image_id Set.image_id
lemma image_iterate_eq {f : α → α} {n : ℕ} : image (f^[n]) = (image f)^[n] := by
induction' n with n ih; · simp
rw [iterate_succ', iterate_succ',← ih, image_comp_eq]
theorem compl_compl_image [BooleanAlgebra α] (S : Set α) :
HasCompl.compl '' (HasCompl.compl '' S) = S := by
rw [← image_comp, compl_comp_compl, image_id]
#align set.compl_compl_image Set.compl_compl_image
theorem image_insert_eq {f : α → β} {a : α} {s : Set α} :
f '' insert a s = insert (f a) (f '' s) := by
ext
simp [and_or_left, exists_or, eq_comm, or_comm, and_comm]
#align set.image_insert_eq Set.image_insert_eq
theorem image_pair (f : α → β) (a b : α) : f '' {a, b} = {f a, f b} := by
simp only [image_insert_eq, image_singleton]
#align set.image_pair Set.image_pair
theorem image_subset_preimage_of_inverse {f : α → β} {g : β → α} (I : LeftInverse g f) (s : Set α) :
f '' s ⊆ g ⁻¹' s := fun _ ⟨a, h, e⟩ => e ▸ ((I a).symm ▸ h : g (f a) ∈ s)
#align set.image_subset_preimage_of_inverse Set.image_subset_preimage_of_inverse
theorem preimage_subset_image_of_inverse {f : α → β} {g : β → α} (I : LeftInverse g f) (s : Set β) :
f ⁻¹' s ⊆ g '' s := fun b h => ⟨f b, h, I b⟩
#align set.preimage_subset_image_of_inverse Set.preimage_subset_image_of_inverse
theorem image_eq_preimage_of_inverse {f : α → β} {g : β → α} (h₁ : LeftInverse g f)
(h₂ : RightInverse g f) : image f = preimage g :=
funext fun s =>
Subset.antisymm (image_subset_preimage_of_inverse h₁ s) (preimage_subset_image_of_inverse h₂ s)
#align set.image_eq_preimage_of_inverse Set.image_eq_preimage_of_inverse
theorem mem_image_iff_of_inverse {f : α → β} {g : β → α} {b : β} {s : Set α} (h₁ : LeftInverse g f)
(h₂ : RightInverse g f) : b ∈ f '' s ↔ g b ∈ s := by
|
rw [image_eq_preimage_of_inverse h₁ h₂]
|
theorem mem_image_iff_of_inverse {f : α → β} {g : β → α} {b : β} {s : Set α} (h₁ : LeftInverse g f)
(h₂ : RightInverse g f) : b ∈ f '' s ↔ g b ∈ s := by
|
Mathlib.Data.Set.Image.446_0.IJFiTzmYGOCpPSd
|
theorem mem_image_iff_of_inverse {f : α → β} {g : β → α} {b : β} {s : Set α} (h₁ : LeftInverse g f)
(h₂ : RightInverse g f) : b ∈ f '' s ↔ g b ∈ s
|
Mathlib_Data_Set_Image
|
α : Type u_1
β : Type u_2
γ : Type u_3
ι : Sort u_4
ι' : Sort u_5
f✝ : α → β
s✝ t : Set α
f : α → β
g : β → α
b : β
s : Set α
h₁ : LeftInverse g f
h₂ : Function.RightInverse g f
⊢ b ∈ g ⁻¹' s ↔ g b ∈ s
|
/-
Copyright (c) 2014 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Leonardo de Moura
-/
import Mathlib.Data.Set.Basic
#align_import data.set.image from "leanprover-community/mathlib"@"001ffdc42920050657fd45bd2b8bfbec8eaaeb29"
/-!
# Images and preimages of sets
## Main definitions
* `preimage f t : Set α` : the preimage f⁻¹(t) (written `f ⁻¹' t` in Lean) of a subset of β.
* `range f : Set β` : the image of `univ` under `f`.
Also works for `{p : Prop} (f : p → α)` (unlike `image`)
## Notation
* `f ⁻¹' t` for `Set.preimage f t`
* `f '' s` for `Set.image f s`
## Tags
set, sets, image, preimage, pre-image, range
-/
set_option autoImplicit true
universe u v
open Function Set
namespace Set
variable {α β γ : Type*} {ι ι' : Sort*}
/-! ### Inverse image -/
/-- The preimage of `s : Set β` by `f : α → β`, written `f ⁻¹' s`,
is the set of `x : α` such that `f x ∈ s`. -/
def preimage {α : Type u} {β : Type v} (f : α → β) (s : Set β) : Set α :=
{ x | f x ∈ s }
#align set.preimage Set.preimage
/-- `f ⁻¹' t` denotes the preimage of `t : Set β` under the function `f : α → β`. -/
infixl:80 " ⁻¹' " => preimage
section Preimage
variable {f : α → β} {g : β → γ}
@[simp]
theorem preimage_empty : f ⁻¹' ∅ = ∅ :=
rfl
#align set.preimage_empty Set.preimage_empty
@[simp, mfld_simps]
theorem mem_preimage {s : Set β} {a : α} : a ∈ f ⁻¹' s ↔ f a ∈ s :=
Iff.rfl
#align set.mem_preimage Set.mem_preimage
theorem preimage_congr {f g : α → β} {s : Set β} (h : ∀ x : α, f x = g x) : f ⁻¹' s = g ⁻¹' s := by
congr with x
simp [h]
#align set.preimage_congr Set.preimage_congr
@[gcongr]
theorem preimage_mono {s t : Set β} (h : s ⊆ t) : f ⁻¹' s ⊆ f ⁻¹' t := fun _ hx => h hx
#align set.preimage_mono Set.preimage_mono
@[simp, mfld_simps]
theorem preimage_univ : f ⁻¹' univ = univ :=
rfl
#align set.preimage_univ Set.preimage_univ
theorem subset_preimage_univ {s : Set α} : s ⊆ f ⁻¹' univ :=
subset_univ _
#align set.subset_preimage_univ Set.subset_preimage_univ
@[simp, mfld_simps]
theorem preimage_inter {s t : Set β} : f ⁻¹' (s ∩ t) = f ⁻¹' s ∩ f ⁻¹' t :=
rfl
#align set.preimage_inter Set.preimage_inter
@[simp]
theorem preimage_union {s t : Set β} : f ⁻¹' (s ∪ t) = f ⁻¹' s ∪ f ⁻¹' t :=
rfl
#align set.preimage_union Set.preimage_union
@[simp]
theorem preimage_compl {s : Set β} : f ⁻¹' sᶜ = (f ⁻¹' s)ᶜ :=
rfl
#align set.preimage_compl Set.preimage_compl
@[simp]
theorem preimage_diff (f : α → β) (s t : Set β) : f ⁻¹' (s \ t) = f ⁻¹' s \ f ⁻¹' t :=
rfl
#align set.preimage_diff Set.preimage_diff
@[simp]
lemma preimage_symmDiff {f : α → β} (s t : Set β) : f ⁻¹' (s ∆ t) = (f ⁻¹' s) ∆ (f ⁻¹' t) :=
rfl
#align set.preimage_symm_diff Set.preimage_symmDiff
@[simp]
theorem preimage_ite (f : α → β) (s t₁ t₂ : Set β) :
f ⁻¹' s.ite t₁ t₂ = (f ⁻¹' s).ite (f ⁻¹' t₁) (f ⁻¹' t₂) :=
rfl
#align set.preimage_ite Set.preimage_ite
@[simp]
theorem preimage_setOf_eq {p : α → Prop} {f : β → α} : f ⁻¹' { a | p a } = { a | p (f a) } :=
rfl
#align set.preimage_set_of_eq Set.preimage_setOf_eq
@[simp]
theorem preimage_id_eq : preimage (id : α → α) = id :=
rfl
#align set.preimage_id_eq Set.preimage_id_eq
@[mfld_simps]
theorem preimage_id {s : Set α} : id ⁻¹' s = s :=
rfl
#align set.preimage_id Set.preimage_id
@[simp, mfld_simps]
theorem preimage_id' {s : Set α} : (fun x => x) ⁻¹' s = s :=
rfl
#align set.preimage_id' Set.preimage_id'
@[simp]
theorem preimage_const_of_mem {b : β} {s : Set β} (h : b ∈ s) : (fun _ : α => b) ⁻¹' s = univ :=
eq_univ_of_forall fun _ => h
#align set.preimage_const_of_mem Set.preimage_const_of_mem
@[simp]
theorem preimage_const_of_not_mem {b : β} {s : Set β} (h : b ∉ s) : (fun _ : α => b) ⁻¹' s = ∅ :=
eq_empty_of_subset_empty fun _ hx => h hx
#align set.preimage_const_of_not_mem Set.preimage_const_of_not_mem
theorem preimage_const (b : β) (s : Set β) [Decidable (b ∈ s)] :
(fun _ : α => b) ⁻¹' s = if b ∈ s then univ else ∅ := by
split_ifs with hb
exacts [preimage_const_of_mem hb, preimage_const_of_not_mem hb]
#align set.preimage_const Set.preimage_const
/-- If preimage of each singleton under `f : α → β` is either empty or the whole type,
then `f` is a constant. -/
lemma exists_eq_const_of_preimage_singleton [Nonempty β] {f : α → β}
(hf : ∀ b : β, f ⁻¹' {b} = ∅ ∨ f ⁻¹' {b} = univ) : ∃ b, f = const α b := by
rcases em (∃ b, f ⁻¹' {b} = univ) with ⟨b, hb⟩ | hf'
· exact ⟨b, funext fun x ↦ eq_univ_iff_forall.1 hb x⟩
· have : ∀ x b, f x ≠ b := fun x b ↦
eq_empty_iff_forall_not_mem.1 ((hf b).resolve_right fun h ↦ hf' ⟨b, h⟩) x
exact ⟨Classical.arbitrary β, funext fun x ↦ absurd rfl (this x _)⟩
theorem preimage_comp {s : Set γ} : g ∘ f ⁻¹' s = f ⁻¹' (g ⁻¹' s) :=
rfl
#align set.preimage_comp Set.preimage_comp
theorem preimage_comp_eq : preimage (g ∘ f) = preimage f ∘ preimage g :=
rfl
#align set.preimage_comp_eq Set.preimage_comp_eq
theorem preimage_iterate_eq {f : α → α} {n : ℕ} : Set.preimage f^[n] = (Set.preimage f)^[n] := by
induction' n with n ih; · simp
rw [iterate_succ, iterate_succ', preimage_comp_eq, ih]
#align set.preimage_iterate_eq Set.preimage_iterate_eq
theorem preimage_preimage {g : β → γ} {f : α → β} {s : Set γ} :
f ⁻¹' (g ⁻¹' s) = (fun x => g (f x)) ⁻¹' s :=
preimage_comp.symm
#align set.preimage_preimage Set.preimage_preimage
theorem eq_preimage_subtype_val_iff {p : α → Prop} {s : Set (Subtype p)} {t : Set α} :
s = Subtype.val ⁻¹' t ↔ ∀ (x) (h : p x), (⟨x, h⟩ : Subtype p) ∈ s ↔ x ∈ t :=
⟨fun s_eq x h => by
rw [s_eq]
simp, fun h => ext fun ⟨x, hx⟩ => by simp [h]⟩
#align set.eq_preimage_subtype_val_iff Set.eq_preimage_subtype_val_iff
theorem nonempty_of_nonempty_preimage {s : Set β} {f : α → β} (hf : (f ⁻¹' s).Nonempty) :
s.Nonempty :=
let ⟨x, hx⟩ := hf
⟨f x, hx⟩
#align set.nonempty_of_nonempty_preimage Set.nonempty_of_nonempty_preimage
@[simp] theorem preimage_singleton_true (p : α → Prop) : p ⁻¹' {True} = {a | p a} := by ext; simp
#align set.preimage_singleton_true Set.preimage_singleton_true
@[simp] theorem preimage_singleton_false (p : α → Prop) : p ⁻¹' {False} = {a | ¬p a} := by ext; simp
#align set.preimage_singleton_false Set.preimage_singleton_false
theorem preimage_subtype_coe_eq_compl {s u v : Set α} (hsuv : s ⊆ u ∪ v)
(H : s ∩ (u ∩ v) = ∅) : ((↑) : s → α) ⁻¹' u = ((↑) ⁻¹' v)ᶜ := by
ext ⟨x, x_in_s⟩
constructor
· intro x_in_u x_in_v
exact eq_empty_iff_forall_not_mem.mp H x ⟨x_in_s, ⟨x_in_u, x_in_v⟩⟩
· intro hx
exact Or.elim (hsuv x_in_s) id fun hx' => hx.elim hx'
#align set.preimage_subtype_coe_eq_compl Set.preimage_subtype_coe_eq_compl
end Preimage
/-! ### Image of a set under a function -/
section Image
variable {f : α → β} {s t : Set α}
-- Porting note: `Set.image` is already defined in `Init.Set`
#align set.image Set.image
/-- `f '' s` denotes the image of `s : Set α` under the function `f : α → β`. -/
infixl:80 " '' " => image
theorem mem_image_iff_bex {f : α → β} {s : Set α} {y : β} :
y ∈ f '' s ↔ ∃ (x : _) (_ : x ∈ s), f x = y :=
bex_def.symm
#align set.mem_image_iff_bex Set.mem_image_iff_bex
@[simp]
theorem mem_image (f : α → β) (s : Set α) (y : β) : y ∈ f '' s ↔ ∃ x ∈ s, f x = y :=
Iff.rfl
#align set.mem_image Set.mem_image
theorem image_eta (f : α → β) : f '' s = (fun x => f x) '' s :=
rfl
#align set.image_eta Set.image_eta
@[mfld_simps]
theorem mem_image_of_mem (f : α → β) {x : α} {a : Set α} (h : x ∈ a) : f x ∈ f '' a :=
⟨_, h, rfl⟩
#align set.mem_image_of_mem Set.mem_image_of_mem
theorem _root_.Function.Injective.mem_set_image {f : α → β} (hf : Injective f) {s : Set α} {a : α} :
f a ∈ f '' s ↔ a ∈ s :=
⟨fun ⟨_, hb, Eq⟩ => hf Eq ▸ hb, mem_image_of_mem f⟩
#align function.injective.mem_set_image Function.Injective.mem_set_image
theorem ball_image_iff {f : α → β} {s : Set α} {p : β → Prop} :
(∀ y ∈ f '' s, p y) ↔ ∀ x ∈ s, p (f x) := by simp
#align set.ball_image_iff Set.ball_image_iff
theorem ball_image_of_ball {f : α → β} {s : Set α} {p : β → Prop} (h : ∀ x ∈ s, p (f x)) :
∀ y ∈ f '' s, p y :=
ball_image_iff.2 h
#align set.ball_image_of_ball Set.ball_image_of_ball
theorem bex_image_iff {f : α → β} {s : Set α} {p : β → Prop} :
(∃ y ∈ f '' s, p y) ↔ ∃ x ∈ s, p (f x) := by simp
#align set.bex_image_iff Set.bex_image_iff
theorem mem_image_elim {f : α → β} {s : Set α} {C : β → Prop} (h : ∀ x : α, x ∈ s → C (f x)) :
∀ {y : β}, y ∈ f '' s → C y
| _, ⟨a, a_in, rfl⟩ => h a a_in
#align set.mem_image_elim Set.mem_image_elim
theorem mem_image_elim_on {f : α → β} {s : Set α} {C : β → Prop} {y : β} (h_y : y ∈ f '' s)
(h : ∀ x : α, x ∈ s → C (f x)) : C y :=
mem_image_elim h h_y
#align set.mem_image_elim_on Set.mem_image_elim_on
-- Porting note: used to be `safe`
@[congr]
theorem image_congr {f g : α → β} {s : Set α} (h : ∀ a ∈ s, f a = g a) : f '' s = g '' s := by
ext x
rw [mem_image, mem_image]
exact {
mp := by
rintro ⟨a, ha1, ha2⟩
exact ⟨a, ⟨ha1, (h a ha1) ▸ ha2⟩⟩,
mpr := by
rintro ⟨a, ha1, ha2⟩
exact ⟨a, ⟨ha1, (h a ha1) ▸ ha2⟩⟩
}
-- safe [ext_iff, iff_def]
#align set.image_congr Set.image_congr
/-- A common special case of `image_congr` -/
theorem image_congr' {f g : α → β} {s : Set α} (h : ∀ x : α, f x = g x) : f '' s = g '' s :=
image_congr fun x _ => h x
#align set.image_congr' Set.image_congr'
@[gcongr]
lemma image_mono (h : s ⊆ t) : f '' s ⊆ f '' t := by
rintro - ⟨a, ha, rfl⟩; exact mem_image_of_mem f (h ha)
theorem image_comp (f : β → γ) (g : α → β) (a : Set α) : f ∘ g '' a = f '' (g '' a) :=
Subset.antisymm (ball_image_of_ball fun _ ha => mem_image_of_mem _ <| mem_image_of_mem _ ha)
(ball_image_of_ball <| ball_image_of_ball fun _ ha => mem_image_of_mem _ ha)
#align set.image_comp Set.image_comp
theorem image_comp_eq {g : β → γ} : image (g ∘ f) = image g ∘ image f := by ext; simp
/-- A variant of `image_comp`, useful for rewriting -/
theorem image_image (g : β → γ) (f : α → β) (s : Set α) : g '' (f '' s) = (fun x => g (f x)) '' s :=
(image_comp g f s).symm
#align set.image_image Set.image_image
theorem image_comm {β'} {f : β → γ} {g : α → β} {f' : α → β'} {g' : β' → γ}
(h_comm : ∀ a, f (g a) = g' (f' a)) : (s.image g).image f = (s.image f').image g' := by
simp_rw [image_image, h_comm]
#align set.image_comm Set.image_comm
theorem _root_.Function.Semiconj.set_image {f : α → β} {ga : α → α} {gb : β → β}
(h : Function.Semiconj f ga gb) : Function.Semiconj (image f) (image ga) (image gb) := fun _ =>
image_comm h
#align function.semiconj.set_image Function.Semiconj.set_image
theorem _root_.Function.Commute.set_image {f g : α → α} (h : Function.Commute f g) :
Function.Commute (image f) (image g) :=
Function.Semiconj.set_image h
#align function.commute.set_image Function.Commute.set_image
/-- Image is monotone with respect to `⊆`. See `Set.monotone_image` for the statement in
terms of `≤`. -/
@[gcongr]
theorem image_subset {a b : Set α} (f : α → β) (h : a ⊆ b) : f '' a ⊆ f '' b := by
simp only [subset_def, mem_image]
exact fun x => fun ⟨w, h1, h2⟩ => ⟨w, h h1, h2⟩
#align set.image_subset Set.image_subset
/-- `Set.image` is monotone. See `Set.image_subset` for the statement in terms of `⊆`. -/
lemma monotone_image {f : α → β} : Monotone (image f) := fun _ _ => image_subset _
#align set.monotone_image Set.monotone_image
theorem image_union (f : α → β) (s t : Set α) : f '' (s ∪ t) = f '' s ∪ f '' t :=
ext fun x =>
⟨by rintro ⟨a, h | h, rfl⟩ <;> [left; right] <;> exact ⟨_, h, rfl⟩, by
rintro (⟨a, h, rfl⟩ | ⟨a, h, rfl⟩) <;> refine' ⟨_, _, rfl⟩ <;> [left; right] <;> exact h⟩
#align set.image_union Set.image_union
@[simp]
theorem image_empty (f : α → β) : f '' ∅ = ∅ := by
ext
simp
#align set.image_empty Set.image_empty
theorem image_inter_subset (f : α → β) (s t : Set α) : f '' (s ∩ t) ⊆ f '' s ∩ f '' t :=
subset_inter (image_subset _ <| inter_subset_left _ _) (image_subset _ <| inter_subset_right _ _)
#align set.image_inter_subset Set.image_inter_subset
theorem image_inter_on {f : α → β} {s t : Set α} (h : ∀ x ∈ t, ∀ y ∈ s, f x = f y → x = y) :
f '' (s ∩ t) = f '' s ∩ f '' t :=
(image_inter_subset _ _ _).antisymm
fun b ⟨⟨a₁, ha₁, h₁⟩, ⟨a₂, ha₂, h₂⟩⟩ ↦
have : a₂ = a₁ := h _ ha₂ _ ha₁ (by simp [*])
⟨a₁, ⟨ha₁, this ▸ ha₂⟩, h₁⟩
#align set.image_inter_on Set.image_inter_on
theorem image_inter {f : α → β} {s t : Set α} (H : Injective f) : f '' (s ∩ t) = f '' s ∩ f '' t :=
image_inter_on fun _ _ _ _ h => H h
#align set.image_inter Set.image_inter
theorem image_univ_of_surjective {ι : Type*} {f : ι → β} (H : Surjective f) : f '' univ = univ :=
eq_univ_of_forall <| by simpa [image]
#align set.image_univ_of_surjective Set.image_univ_of_surjective
@[simp]
theorem image_singleton {f : α → β} {a : α} : f '' {a} = {f a} := by
ext
simp [image, eq_comm]
#align set.image_singleton Set.image_singleton
@[simp]
theorem Nonempty.image_const {s : Set α} (hs : s.Nonempty) (a : β) : (fun _ => a) '' s = {a} :=
ext fun _ =>
⟨fun ⟨_, _, h⟩ => h ▸ mem_singleton _, fun h =>
(eq_of_mem_singleton h).symm ▸ hs.imp fun _ hy => ⟨hy, rfl⟩⟩
#align set.nonempty.image_const Set.Nonempty.image_const
@[simp, mfld_simps]
theorem image_eq_empty {α β} {f : α → β} {s : Set α} : f '' s = ∅ ↔ s = ∅ := by
simp only [eq_empty_iff_forall_not_mem]
exact ⟨fun H a ha => H _ ⟨_, ha, rfl⟩, fun H b ⟨_, ha, _⟩ => H _ ha⟩
#align set.image_eq_empty Set.image_eq_empty
-- Porting note: `compl` is already defined in `Init.Set`
theorem preimage_compl_eq_image_compl [BooleanAlgebra α] (S : Set α) :
HasCompl.compl ⁻¹' S = HasCompl.compl '' S :=
Set.ext fun x =>
⟨fun h => ⟨xᶜ, h, compl_compl x⟩, fun h =>
Exists.elim h fun _ hy => (compl_eq_comm.mp hy.2).symm.subst hy.1⟩
#align set.preimage_compl_eq_image_compl Set.preimage_compl_eq_image_compl
theorem mem_compl_image [BooleanAlgebra α] (t : α) (S : Set α) :
t ∈ HasCompl.compl '' S ↔ tᶜ ∈ S := by
simp [← preimage_compl_eq_image_compl]
#align set.mem_compl_image Set.mem_compl_image
@[simp]
theorem image_id_eq : image (id : α → α) = id := by ext; simp
/-- A variant of `image_id` -/
@[simp]
theorem image_id' (s : Set α) : (fun x => x) '' s = s := by
ext
simp
#align set.image_id' Set.image_id'
theorem image_id (s : Set α) : id '' s = s := by simp
#align set.image_id Set.image_id
lemma image_iterate_eq {f : α → α} {n : ℕ} : image (f^[n]) = (image f)^[n] := by
induction' n with n ih; · simp
rw [iterate_succ', iterate_succ',← ih, image_comp_eq]
theorem compl_compl_image [BooleanAlgebra α] (S : Set α) :
HasCompl.compl '' (HasCompl.compl '' S) = S := by
rw [← image_comp, compl_comp_compl, image_id]
#align set.compl_compl_image Set.compl_compl_image
theorem image_insert_eq {f : α → β} {a : α} {s : Set α} :
f '' insert a s = insert (f a) (f '' s) := by
ext
simp [and_or_left, exists_or, eq_comm, or_comm, and_comm]
#align set.image_insert_eq Set.image_insert_eq
theorem image_pair (f : α → β) (a b : α) : f '' {a, b} = {f a, f b} := by
simp only [image_insert_eq, image_singleton]
#align set.image_pair Set.image_pair
theorem image_subset_preimage_of_inverse {f : α → β} {g : β → α} (I : LeftInverse g f) (s : Set α) :
f '' s ⊆ g ⁻¹' s := fun _ ⟨a, h, e⟩ => e ▸ ((I a).symm ▸ h : g (f a) ∈ s)
#align set.image_subset_preimage_of_inverse Set.image_subset_preimage_of_inverse
theorem preimage_subset_image_of_inverse {f : α → β} {g : β → α} (I : LeftInverse g f) (s : Set β) :
f ⁻¹' s ⊆ g '' s := fun b h => ⟨f b, h, I b⟩
#align set.preimage_subset_image_of_inverse Set.preimage_subset_image_of_inverse
theorem image_eq_preimage_of_inverse {f : α → β} {g : β → α} (h₁ : LeftInverse g f)
(h₂ : RightInverse g f) : image f = preimage g :=
funext fun s =>
Subset.antisymm (image_subset_preimage_of_inverse h₁ s) (preimage_subset_image_of_inverse h₂ s)
#align set.image_eq_preimage_of_inverse Set.image_eq_preimage_of_inverse
theorem mem_image_iff_of_inverse {f : α → β} {g : β → α} {b : β} {s : Set α} (h₁ : LeftInverse g f)
(h₂ : RightInverse g f) : b ∈ f '' s ↔ g b ∈ s := by
rw [image_eq_preimage_of_inverse h₁ h₂];
|
rfl
|
theorem mem_image_iff_of_inverse {f : α → β} {g : β → α} {b : β} {s : Set α} (h₁ : LeftInverse g f)
(h₂ : RightInverse g f) : b ∈ f '' s ↔ g b ∈ s := by
rw [image_eq_preimage_of_inverse h₁ h₂];
|
Mathlib.Data.Set.Image.446_0.IJFiTzmYGOCpPSd
|
theorem mem_image_iff_of_inverse {f : α → β} {g : β → α} {b : β} {s : Set α} (h₁ : LeftInverse g f)
(h₂ : RightInverse g f) : b ∈ f '' s ↔ g b ∈ s
|
Mathlib_Data_Set_Image
|
α : Type u_1
β : Type u_2
γ : Type u_3
ι : Sort u_4
ι' : Sort u_5
f✝ : α → β
s✝ t : Set α
f : α → β
s : Set α
H : Injective f
⊢ Disjoint (f '' s) (f '' sᶜ)
|
/-
Copyright (c) 2014 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Leonardo de Moura
-/
import Mathlib.Data.Set.Basic
#align_import data.set.image from "leanprover-community/mathlib"@"001ffdc42920050657fd45bd2b8bfbec8eaaeb29"
/-!
# Images and preimages of sets
## Main definitions
* `preimage f t : Set α` : the preimage f⁻¹(t) (written `f ⁻¹' t` in Lean) of a subset of β.
* `range f : Set β` : the image of `univ` under `f`.
Also works for `{p : Prop} (f : p → α)` (unlike `image`)
## Notation
* `f ⁻¹' t` for `Set.preimage f t`
* `f '' s` for `Set.image f s`
## Tags
set, sets, image, preimage, pre-image, range
-/
set_option autoImplicit true
universe u v
open Function Set
namespace Set
variable {α β γ : Type*} {ι ι' : Sort*}
/-! ### Inverse image -/
/-- The preimage of `s : Set β` by `f : α → β`, written `f ⁻¹' s`,
is the set of `x : α` such that `f x ∈ s`. -/
def preimage {α : Type u} {β : Type v} (f : α → β) (s : Set β) : Set α :=
{ x | f x ∈ s }
#align set.preimage Set.preimage
/-- `f ⁻¹' t` denotes the preimage of `t : Set β` under the function `f : α → β`. -/
infixl:80 " ⁻¹' " => preimage
section Preimage
variable {f : α → β} {g : β → γ}
@[simp]
theorem preimage_empty : f ⁻¹' ∅ = ∅ :=
rfl
#align set.preimage_empty Set.preimage_empty
@[simp, mfld_simps]
theorem mem_preimage {s : Set β} {a : α} : a ∈ f ⁻¹' s ↔ f a ∈ s :=
Iff.rfl
#align set.mem_preimage Set.mem_preimage
theorem preimage_congr {f g : α → β} {s : Set β} (h : ∀ x : α, f x = g x) : f ⁻¹' s = g ⁻¹' s := by
congr with x
simp [h]
#align set.preimage_congr Set.preimage_congr
@[gcongr]
theorem preimage_mono {s t : Set β} (h : s ⊆ t) : f ⁻¹' s ⊆ f ⁻¹' t := fun _ hx => h hx
#align set.preimage_mono Set.preimage_mono
@[simp, mfld_simps]
theorem preimage_univ : f ⁻¹' univ = univ :=
rfl
#align set.preimage_univ Set.preimage_univ
theorem subset_preimage_univ {s : Set α} : s ⊆ f ⁻¹' univ :=
subset_univ _
#align set.subset_preimage_univ Set.subset_preimage_univ
@[simp, mfld_simps]
theorem preimage_inter {s t : Set β} : f ⁻¹' (s ∩ t) = f ⁻¹' s ∩ f ⁻¹' t :=
rfl
#align set.preimage_inter Set.preimage_inter
@[simp]
theorem preimage_union {s t : Set β} : f ⁻¹' (s ∪ t) = f ⁻¹' s ∪ f ⁻¹' t :=
rfl
#align set.preimage_union Set.preimage_union
@[simp]
theorem preimage_compl {s : Set β} : f ⁻¹' sᶜ = (f ⁻¹' s)ᶜ :=
rfl
#align set.preimage_compl Set.preimage_compl
@[simp]
theorem preimage_diff (f : α → β) (s t : Set β) : f ⁻¹' (s \ t) = f ⁻¹' s \ f ⁻¹' t :=
rfl
#align set.preimage_diff Set.preimage_diff
@[simp]
lemma preimage_symmDiff {f : α → β} (s t : Set β) : f ⁻¹' (s ∆ t) = (f ⁻¹' s) ∆ (f ⁻¹' t) :=
rfl
#align set.preimage_symm_diff Set.preimage_symmDiff
@[simp]
theorem preimage_ite (f : α → β) (s t₁ t₂ : Set β) :
f ⁻¹' s.ite t₁ t₂ = (f ⁻¹' s).ite (f ⁻¹' t₁) (f ⁻¹' t₂) :=
rfl
#align set.preimage_ite Set.preimage_ite
@[simp]
theorem preimage_setOf_eq {p : α → Prop} {f : β → α} : f ⁻¹' { a | p a } = { a | p (f a) } :=
rfl
#align set.preimage_set_of_eq Set.preimage_setOf_eq
@[simp]
theorem preimage_id_eq : preimage (id : α → α) = id :=
rfl
#align set.preimage_id_eq Set.preimage_id_eq
@[mfld_simps]
theorem preimage_id {s : Set α} : id ⁻¹' s = s :=
rfl
#align set.preimage_id Set.preimage_id
@[simp, mfld_simps]
theorem preimage_id' {s : Set α} : (fun x => x) ⁻¹' s = s :=
rfl
#align set.preimage_id' Set.preimage_id'
@[simp]
theorem preimage_const_of_mem {b : β} {s : Set β} (h : b ∈ s) : (fun _ : α => b) ⁻¹' s = univ :=
eq_univ_of_forall fun _ => h
#align set.preimage_const_of_mem Set.preimage_const_of_mem
@[simp]
theorem preimage_const_of_not_mem {b : β} {s : Set β} (h : b ∉ s) : (fun _ : α => b) ⁻¹' s = ∅ :=
eq_empty_of_subset_empty fun _ hx => h hx
#align set.preimage_const_of_not_mem Set.preimage_const_of_not_mem
theorem preimage_const (b : β) (s : Set β) [Decidable (b ∈ s)] :
(fun _ : α => b) ⁻¹' s = if b ∈ s then univ else ∅ := by
split_ifs with hb
exacts [preimage_const_of_mem hb, preimage_const_of_not_mem hb]
#align set.preimage_const Set.preimage_const
/-- If preimage of each singleton under `f : α → β` is either empty or the whole type,
then `f` is a constant. -/
lemma exists_eq_const_of_preimage_singleton [Nonempty β] {f : α → β}
(hf : ∀ b : β, f ⁻¹' {b} = ∅ ∨ f ⁻¹' {b} = univ) : ∃ b, f = const α b := by
rcases em (∃ b, f ⁻¹' {b} = univ) with ⟨b, hb⟩ | hf'
· exact ⟨b, funext fun x ↦ eq_univ_iff_forall.1 hb x⟩
· have : ∀ x b, f x ≠ b := fun x b ↦
eq_empty_iff_forall_not_mem.1 ((hf b).resolve_right fun h ↦ hf' ⟨b, h⟩) x
exact ⟨Classical.arbitrary β, funext fun x ↦ absurd rfl (this x _)⟩
theorem preimage_comp {s : Set γ} : g ∘ f ⁻¹' s = f ⁻¹' (g ⁻¹' s) :=
rfl
#align set.preimage_comp Set.preimage_comp
theorem preimage_comp_eq : preimage (g ∘ f) = preimage f ∘ preimage g :=
rfl
#align set.preimage_comp_eq Set.preimage_comp_eq
theorem preimage_iterate_eq {f : α → α} {n : ℕ} : Set.preimage f^[n] = (Set.preimage f)^[n] := by
induction' n with n ih; · simp
rw [iterate_succ, iterate_succ', preimage_comp_eq, ih]
#align set.preimage_iterate_eq Set.preimage_iterate_eq
theorem preimage_preimage {g : β → γ} {f : α → β} {s : Set γ} :
f ⁻¹' (g ⁻¹' s) = (fun x => g (f x)) ⁻¹' s :=
preimage_comp.symm
#align set.preimage_preimage Set.preimage_preimage
theorem eq_preimage_subtype_val_iff {p : α → Prop} {s : Set (Subtype p)} {t : Set α} :
s = Subtype.val ⁻¹' t ↔ ∀ (x) (h : p x), (⟨x, h⟩ : Subtype p) ∈ s ↔ x ∈ t :=
⟨fun s_eq x h => by
rw [s_eq]
simp, fun h => ext fun ⟨x, hx⟩ => by simp [h]⟩
#align set.eq_preimage_subtype_val_iff Set.eq_preimage_subtype_val_iff
theorem nonempty_of_nonempty_preimage {s : Set β} {f : α → β} (hf : (f ⁻¹' s).Nonempty) :
s.Nonempty :=
let ⟨x, hx⟩ := hf
⟨f x, hx⟩
#align set.nonempty_of_nonempty_preimage Set.nonempty_of_nonempty_preimage
@[simp] theorem preimage_singleton_true (p : α → Prop) : p ⁻¹' {True} = {a | p a} := by ext; simp
#align set.preimage_singleton_true Set.preimage_singleton_true
@[simp] theorem preimage_singleton_false (p : α → Prop) : p ⁻¹' {False} = {a | ¬p a} := by ext; simp
#align set.preimage_singleton_false Set.preimage_singleton_false
theorem preimage_subtype_coe_eq_compl {s u v : Set α} (hsuv : s ⊆ u ∪ v)
(H : s ∩ (u ∩ v) = ∅) : ((↑) : s → α) ⁻¹' u = ((↑) ⁻¹' v)ᶜ := by
ext ⟨x, x_in_s⟩
constructor
· intro x_in_u x_in_v
exact eq_empty_iff_forall_not_mem.mp H x ⟨x_in_s, ⟨x_in_u, x_in_v⟩⟩
· intro hx
exact Or.elim (hsuv x_in_s) id fun hx' => hx.elim hx'
#align set.preimage_subtype_coe_eq_compl Set.preimage_subtype_coe_eq_compl
end Preimage
/-! ### Image of a set under a function -/
section Image
variable {f : α → β} {s t : Set α}
-- Porting note: `Set.image` is already defined in `Init.Set`
#align set.image Set.image
/-- `f '' s` denotes the image of `s : Set α` under the function `f : α → β`. -/
infixl:80 " '' " => image
theorem mem_image_iff_bex {f : α → β} {s : Set α} {y : β} :
y ∈ f '' s ↔ ∃ (x : _) (_ : x ∈ s), f x = y :=
bex_def.symm
#align set.mem_image_iff_bex Set.mem_image_iff_bex
@[simp]
theorem mem_image (f : α → β) (s : Set α) (y : β) : y ∈ f '' s ↔ ∃ x ∈ s, f x = y :=
Iff.rfl
#align set.mem_image Set.mem_image
theorem image_eta (f : α → β) : f '' s = (fun x => f x) '' s :=
rfl
#align set.image_eta Set.image_eta
@[mfld_simps]
theorem mem_image_of_mem (f : α → β) {x : α} {a : Set α} (h : x ∈ a) : f x ∈ f '' a :=
⟨_, h, rfl⟩
#align set.mem_image_of_mem Set.mem_image_of_mem
theorem _root_.Function.Injective.mem_set_image {f : α → β} (hf : Injective f) {s : Set α} {a : α} :
f a ∈ f '' s ↔ a ∈ s :=
⟨fun ⟨_, hb, Eq⟩ => hf Eq ▸ hb, mem_image_of_mem f⟩
#align function.injective.mem_set_image Function.Injective.mem_set_image
theorem ball_image_iff {f : α → β} {s : Set α} {p : β → Prop} :
(∀ y ∈ f '' s, p y) ↔ ∀ x ∈ s, p (f x) := by simp
#align set.ball_image_iff Set.ball_image_iff
theorem ball_image_of_ball {f : α → β} {s : Set α} {p : β → Prop} (h : ∀ x ∈ s, p (f x)) :
∀ y ∈ f '' s, p y :=
ball_image_iff.2 h
#align set.ball_image_of_ball Set.ball_image_of_ball
theorem bex_image_iff {f : α → β} {s : Set α} {p : β → Prop} :
(∃ y ∈ f '' s, p y) ↔ ∃ x ∈ s, p (f x) := by simp
#align set.bex_image_iff Set.bex_image_iff
theorem mem_image_elim {f : α → β} {s : Set α} {C : β → Prop} (h : ∀ x : α, x ∈ s → C (f x)) :
∀ {y : β}, y ∈ f '' s → C y
| _, ⟨a, a_in, rfl⟩ => h a a_in
#align set.mem_image_elim Set.mem_image_elim
theorem mem_image_elim_on {f : α → β} {s : Set α} {C : β → Prop} {y : β} (h_y : y ∈ f '' s)
(h : ∀ x : α, x ∈ s → C (f x)) : C y :=
mem_image_elim h h_y
#align set.mem_image_elim_on Set.mem_image_elim_on
-- Porting note: used to be `safe`
@[congr]
theorem image_congr {f g : α → β} {s : Set α} (h : ∀ a ∈ s, f a = g a) : f '' s = g '' s := by
ext x
rw [mem_image, mem_image]
exact {
mp := by
rintro ⟨a, ha1, ha2⟩
exact ⟨a, ⟨ha1, (h a ha1) ▸ ha2⟩⟩,
mpr := by
rintro ⟨a, ha1, ha2⟩
exact ⟨a, ⟨ha1, (h a ha1) ▸ ha2⟩⟩
}
-- safe [ext_iff, iff_def]
#align set.image_congr Set.image_congr
/-- A common special case of `image_congr` -/
theorem image_congr' {f g : α → β} {s : Set α} (h : ∀ x : α, f x = g x) : f '' s = g '' s :=
image_congr fun x _ => h x
#align set.image_congr' Set.image_congr'
@[gcongr]
lemma image_mono (h : s ⊆ t) : f '' s ⊆ f '' t := by
rintro - ⟨a, ha, rfl⟩; exact mem_image_of_mem f (h ha)
theorem image_comp (f : β → γ) (g : α → β) (a : Set α) : f ∘ g '' a = f '' (g '' a) :=
Subset.antisymm (ball_image_of_ball fun _ ha => mem_image_of_mem _ <| mem_image_of_mem _ ha)
(ball_image_of_ball <| ball_image_of_ball fun _ ha => mem_image_of_mem _ ha)
#align set.image_comp Set.image_comp
theorem image_comp_eq {g : β → γ} : image (g ∘ f) = image g ∘ image f := by ext; simp
/-- A variant of `image_comp`, useful for rewriting -/
theorem image_image (g : β → γ) (f : α → β) (s : Set α) : g '' (f '' s) = (fun x => g (f x)) '' s :=
(image_comp g f s).symm
#align set.image_image Set.image_image
theorem image_comm {β'} {f : β → γ} {g : α → β} {f' : α → β'} {g' : β' → γ}
(h_comm : ∀ a, f (g a) = g' (f' a)) : (s.image g).image f = (s.image f').image g' := by
simp_rw [image_image, h_comm]
#align set.image_comm Set.image_comm
theorem _root_.Function.Semiconj.set_image {f : α → β} {ga : α → α} {gb : β → β}
(h : Function.Semiconj f ga gb) : Function.Semiconj (image f) (image ga) (image gb) := fun _ =>
image_comm h
#align function.semiconj.set_image Function.Semiconj.set_image
theorem _root_.Function.Commute.set_image {f g : α → α} (h : Function.Commute f g) :
Function.Commute (image f) (image g) :=
Function.Semiconj.set_image h
#align function.commute.set_image Function.Commute.set_image
/-- Image is monotone with respect to `⊆`. See `Set.monotone_image` for the statement in
terms of `≤`. -/
@[gcongr]
theorem image_subset {a b : Set α} (f : α → β) (h : a ⊆ b) : f '' a ⊆ f '' b := by
simp only [subset_def, mem_image]
exact fun x => fun ⟨w, h1, h2⟩ => ⟨w, h h1, h2⟩
#align set.image_subset Set.image_subset
/-- `Set.image` is monotone. See `Set.image_subset` for the statement in terms of `⊆`. -/
lemma monotone_image {f : α → β} : Monotone (image f) := fun _ _ => image_subset _
#align set.monotone_image Set.monotone_image
theorem image_union (f : α → β) (s t : Set α) : f '' (s ∪ t) = f '' s ∪ f '' t :=
ext fun x =>
⟨by rintro ⟨a, h | h, rfl⟩ <;> [left; right] <;> exact ⟨_, h, rfl⟩, by
rintro (⟨a, h, rfl⟩ | ⟨a, h, rfl⟩) <;> refine' ⟨_, _, rfl⟩ <;> [left; right] <;> exact h⟩
#align set.image_union Set.image_union
@[simp]
theorem image_empty (f : α → β) : f '' ∅ = ∅ := by
ext
simp
#align set.image_empty Set.image_empty
theorem image_inter_subset (f : α → β) (s t : Set α) : f '' (s ∩ t) ⊆ f '' s ∩ f '' t :=
subset_inter (image_subset _ <| inter_subset_left _ _) (image_subset _ <| inter_subset_right _ _)
#align set.image_inter_subset Set.image_inter_subset
theorem image_inter_on {f : α → β} {s t : Set α} (h : ∀ x ∈ t, ∀ y ∈ s, f x = f y → x = y) :
f '' (s ∩ t) = f '' s ∩ f '' t :=
(image_inter_subset _ _ _).antisymm
fun b ⟨⟨a₁, ha₁, h₁⟩, ⟨a₂, ha₂, h₂⟩⟩ ↦
have : a₂ = a₁ := h _ ha₂ _ ha₁ (by simp [*])
⟨a₁, ⟨ha₁, this ▸ ha₂⟩, h₁⟩
#align set.image_inter_on Set.image_inter_on
theorem image_inter {f : α → β} {s t : Set α} (H : Injective f) : f '' (s ∩ t) = f '' s ∩ f '' t :=
image_inter_on fun _ _ _ _ h => H h
#align set.image_inter Set.image_inter
theorem image_univ_of_surjective {ι : Type*} {f : ι → β} (H : Surjective f) : f '' univ = univ :=
eq_univ_of_forall <| by simpa [image]
#align set.image_univ_of_surjective Set.image_univ_of_surjective
@[simp]
theorem image_singleton {f : α → β} {a : α} : f '' {a} = {f a} := by
ext
simp [image, eq_comm]
#align set.image_singleton Set.image_singleton
@[simp]
theorem Nonempty.image_const {s : Set α} (hs : s.Nonempty) (a : β) : (fun _ => a) '' s = {a} :=
ext fun _ =>
⟨fun ⟨_, _, h⟩ => h ▸ mem_singleton _, fun h =>
(eq_of_mem_singleton h).symm ▸ hs.imp fun _ hy => ⟨hy, rfl⟩⟩
#align set.nonempty.image_const Set.Nonempty.image_const
@[simp, mfld_simps]
theorem image_eq_empty {α β} {f : α → β} {s : Set α} : f '' s = ∅ ↔ s = ∅ := by
simp only [eq_empty_iff_forall_not_mem]
exact ⟨fun H a ha => H _ ⟨_, ha, rfl⟩, fun H b ⟨_, ha, _⟩ => H _ ha⟩
#align set.image_eq_empty Set.image_eq_empty
-- Porting note: `compl` is already defined in `Init.Set`
theorem preimage_compl_eq_image_compl [BooleanAlgebra α] (S : Set α) :
HasCompl.compl ⁻¹' S = HasCompl.compl '' S :=
Set.ext fun x =>
⟨fun h => ⟨xᶜ, h, compl_compl x⟩, fun h =>
Exists.elim h fun _ hy => (compl_eq_comm.mp hy.2).symm.subst hy.1⟩
#align set.preimage_compl_eq_image_compl Set.preimage_compl_eq_image_compl
theorem mem_compl_image [BooleanAlgebra α] (t : α) (S : Set α) :
t ∈ HasCompl.compl '' S ↔ tᶜ ∈ S := by
simp [← preimage_compl_eq_image_compl]
#align set.mem_compl_image Set.mem_compl_image
@[simp]
theorem image_id_eq : image (id : α → α) = id := by ext; simp
/-- A variant of `image_id` -/
@[simp]
theorem image_id' (s : Set α) : (fun x => x) '' s = s := by
ext
simp
#align set.image_id' Set.image_id'
theorem image_id (s : Set α) : id '' s = s := by simp
#align set.image_id Set.image_id
lemma image_iterate_eq {f : α → α} {n : ℕ} : image (f^[n]) = (image f)^[n] := by
induction' n with n ih; · simp
rw [iterate_succ', iterate_succ',← ih, image_comp_eq]
theorem compl_compl_image [BooleanAlgebra α] (S : Set α) :
HasCompl.compl '' (HasCompl.compl '' S) = S := by
rw [← image_comp, compl_comp_compl, image_id]
#align set.compl_compl_image Set.compl_compl_image
theorem image_insert_eq {f : α → β} {a : α} {s : Set α} :
f '' insert a s = insert (f a) (f '' s) := by
ext
simp [and_or_left, exists_or, eq_comm, or_comm, and_comm]
#align set.image_insert_eq Set.image_insert_eq
theorem image_pair (f : α → β) (a b : α) : f '' {a, b} = {f a, f b} := by
simp only [image_insert_eq, image_singleton]
#align set.image_pair Set.image_pair
theorem image_subset_preimage_of_inverse {f : α → β} {g : β → α} (I : LeftInverse g f) (s : Set α) :
f '' s ⊆ g ⁻¹' s := fun _ ⟨a, h, e⟩ => e ▸ ((I a).symm ▸ h : g (f a) ∈ s)
#align set.image_subset_preimage_of_inverse Set.image_subset_preimage_of_inverse
theorem preimage_subset_image_of_inverse {f : α → β} {g : β → α} (I : LeftInverse g f) (s : Set β) :
f ⁻¹' s ⊆ g '' s := fun b h => ⟨f b, h, I b⟩
#align set.preimage_subset_image_of_inverse Set.preimage_subset_image_of_inverse
theorem image_eq_preimage_of_inverse {f : α → β} {g : β → α} (h₁ : LeftInverse g f)
(h₂ : RightInverse g f) : image f = preimage g :=
funext fun s =>
Subset.antisymm (image_subset_preimage_of_inverse h₁ s) (preimage_subset_image_of_inverse h₂ s)
#align set.image_eq_preimage_of_inverse Set.image_eq_preimage_of_inverse
theorem mem_image_iff_of_inverse {f : α → β} {g : β → α} {b : β} {s : Set α} (h₁ : LeftInverse g f)
(h₂ : RightInverse g f) : b ∈ f '' s ↔ g b ∈ s := by
rw [image_eq_preimage_of_inverse h₁ h₂]; rfl
#align set.mem_image_iff_of_inverse Set.mem_image_iff_of_inverse
theorem image_compl_subset {f : α → β} {s : Set α} (H : Injective f) : f '' sᶜ ⊆ (f '' s)ᶜ :=
Disjoint.subset_compl_left <| by
|
simp [disjoint_iff_inf_le, ← image_inter H]
|
theorem image_compl_subset {f : α → β} {s : Set α} (H : Injective f) : f '' sᶜ ⊆ (f '' s)ᶜ :=
Disjoint.subset_compl_left <| by
|
Mathlib.Data.Set.Image.451_0.IJFiTzmYGOCpPSd
|
theorem image_compl_subset {f : α → β} {s : Set α} (H : Injective f) : f '' sᶜ ⊆ (f '' s)ᶜ
|
Mathlib_Data_Set_Image
|
α : Type u_1
β : Type u_2
γ : Type u_3
ι : Sort u_4
ι' : Sort u_5
f✝ : α → β
s✝ t : Set α
f : α → β
s : Set α
H : Surjective f
⊢ f '' s ∪ f '' sᶜ = univ
|
/-
Copyright (c) 2014 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Leonardo de Moura
-/
import Mathlib.Data.Set.Basic
#align_import data.set.image from "leanprover-community/mathlib"@"001ffdc42920050657fd45bd2b8bfbec8eaaeb29"
/-!
# Images and preimages of sets
## Main definitions
* `preimage f t : Set α` : the preimage f⁻¹(t) (written `f ⁻¹' t` in Lean) of a subset of β.
* `range f : Set β` : the image of `univ` under `f`.
Also works for `{p : Prop} (f : p → α)` (unlike `image`)
## Notation
* `f ⁻¹' t` for `Set.preimage f t`
* `f '' s` for `Set.image f s`
## Tags
set, sets, image, preimage, pre-image, range
-/
set_option autoImplicit true
universe u v
open Function Set
namespace Set
variable {α β γ : Type*} {ι ι' : Sort*}
/-! ### Inverse image -/
/-- The preimage of `s : Set β` by `f : α → β`, written `f ⁻¹' s`,
is the set of `x : α` such that `f x ∈ s`. -/
def preimage {α : Type u} {β : Type v} (f : α → β) (s : Set β) : Set α :=
{ x | f x ∈ s }
#align set.preimage Set.preimage
/-- `f ⁻¹' t` denotes the preimage of `t : Set β` under the function `f : α → β`. -/
infixl:80 " ⁻¹' " => preimage
section Preimage
variable {f : α → β} {g : β → γ}
@[simp]
theorem preimage_empty : f ⁻¹' ∅ = ∅ :=
rfl
#align set.preimage_empty Set.preimage_empty
@[simp, mfld_simps]
theorem mem_preimage {s : Set β} {a : α} : a ∈ f ⁻¹' s ↔ f a ∈ s :=
Iff.rfl
#align set.mem_preimage Set.mem_preimage
theorem preimage_congr {f g : α → β} {s : Set β} (h : ∀ x : α, f x = g x) : f ⁻¹' s = g ⁻¹' s := by
congr with x
simp [h]
#align set.preimage_congr Set.preimage_congr
@[gcongr]
theorem preimage_mono {s t : Set β} (h : s ⊆ t) : f ⁻¹' s ⊆ f ⁻¹' t := fun _ hx => h hx
#align set.preimage_mono Set.preimage_mono
@[simp, mfld_simps]
theorem preimage_univ : f ⁻¹' univ = univ :=
rfl
#align set.preimage_univ Set.preimage_univ
theorem subset_preimage_univ {s : Set α} : s ⊆ f ⁻¹' univ :=
subset_univ _
#align set.subset_preimage_univ Set.subset_preimage_univ
@[simp, mfld_simps]
theorem preimage_inter {s t : Set β} : f ⁻¹' (s ∩ t) = f ⁻¹' s ∩ f ⁻¹' t :=
rfl
#align set.preimage_inter Set.preimage_inter
@[simp]
theorem preimage_union {s t : Set β} : f ⁻¹' (s ∪ t) = f ⁻¹' s ∪ f ⁻¹' t :=
rfl
#align set.preimage_union Set.preimage_union
@[simp]
theorem preimage_compl {s : Set β} : f ⁻¹' sᶜ = (f ⁻¹' s)ᶜ :=
rfl
#align set.preimage_compl Set.preimage_compl
@[simp]
theorem preimage_diff (f : α → β) (s t : Set β) : f ⁻¹' (s \ t) = f ⁻¹' s \ f ⁻¹' t :=
rfl
#align set.preimage_diff Set.preimage_diff
@[simp]
lemma preimage_symmDiff {f : α → β} (s t : Set β) : f ⁻¹' (s ∆ t) = (f ⁻¹' s) ∆ (f ⁻¹' t) :=
rfl
#align set.preimage_symm_diff Set.preimage_symmDiff
@[simp]
theorem preimage_ite (f : α → β) (s t₁ t₂ : Set β) :
f ⁻¹' s.ite t₁ t₂ = (f ⁻¹' s).ite (f ⁻¹' t₁) (f ⁻¹' t₂) :=
rfl
#align set.preimage_ite Set.preimage_ite
@[simp]
theorem preimage_setOf_eq {p : α → Prop} {f : β → α} : f ⁻¹' { a | p a } = { a | p (f a) } :=
rfl
#align set.preimage_set_of_eq Set.preimage_setOf_eq
@[simp]
theorem preimage_id_eq : preimage (id : α → α) = id :=
rfl
#align set.preimage_id_eq Set.preimage_id_eq
@[mfld_simps]
theorem preimage_id {s : Set α} : id ⁻¹' s = s :=
rfl
#align set.preimage_id Set.preimage_id
@[simp, mfld_simps]
theorem preimage_id' {s : Set α} : (fun x => x) ⁻¹' s = s :=
rfl
#align set.preimage_id' Set.preimage_id'
@[simp]
theorem preimage_const_of_mem {b : β} {s : Set β} (h : b ∈ s) : (fun _ : α => b) ⁻¹' s = univ :=
eq_univ_of_forall fun _ => h
#align set.preimage_const_of_mem Set.preimage_const_of_mem
@[simp]
theorem preimage_const_of_not_mem {b : β} {s : Set β} (h : b ∉ s) : (fun _ : α => b) ⁻¹' s = ∅ :=
eq_empty_of_subset_empty fun _ hx => h hx
#align set.preimage_const_of_not_mem Set.preimage_const_of_not_mem
theorem preimage_const (b : β) (s : Set β) [Decidable (b ∈ s)] :
(fun _ : α => b) ⁻¹' s = if b ∈ s then univ else ∅ := by
split_ifs with hb
exacts [preimage_const_of_mem hb, preimage_const_of_not_mem hb]
#align set.preimage_const Set.preimage_const
/-- If preimage of each singleton under `f : α → β` is either empty or the whole type,
then `f` is a constant. -/
lemma exists_eq_const_of_preimage_singleton [Nonempty β] {f : α → β}
(hf : ∀ b : β, f ⁻¹' {b} = ∅ ∨ f ⁻¹' {b} = univ) : ∃ b, f = const α b := by
rcases em (∃ b, f ⁻¹' {b} = univ) with ⟨b, hb⟩ | hf'
· exact ⟨b, funext fun x ↦ eq_univ_iff_forall.1 hb x⟩
· have : ∀ x b, f x ≠ b := fun x b ↦
eq_empty_iff_forall_not_mem.1 ((hf b).resolve_right fun h ↦ hf' ⟨b, h⟩) x
exact ⟨Classical.arbitrary β, funext fun x ↦ absurd rfl (this x _)⟩
theorem preimage_comp {s : Set γ} : g ∘ f ⁻¹' s = f ⁻¹' (g ⁻¹' s) :=
rfl
#align set.preimage_comp Set.preimage_comp
theorem preimage_comp_eq : preimage (g ∘ f) = preimage f ∘ preimage g :=
rfl
#align set.preimage_comp_eq Set.preimage_comp_eq
theorem preimage_iterate_eq {f : α → α} {n : ℕ} : Set.preimage f^[n] = (Set.preimage f)^[n] := by
induction' n with n ih; · simp
rw [iterate_succ, iterate_succ', preimage_comp_eq, ih]
#align set.preimage_iterate_eq Set.preimage_iterate_eq
theorem preimage_preimage {g : β → γ} {f : α → β} {s : Set γ} :
f ⁻¹' (g ⁻¹' s) = (fun x => g (f x)) ⁻¹' s :=
preimage_comp.symm
#align set.preimage_preimage Set.preimage_preimage
theorem eq_preimage_subtype_val_iff {p : α → Prop} {s : Set (Subtype p)} {t : Set α} :
s = Subtype.val ⁻¹' t ↔ ∀ (x) (h : p x), (⟨x, h⟩ : Subtype p) ∈ s ↔ x ∈ t :=
⟨fun s_eq x h => by
rw [s_eq]
simp, fun h => ext fun ⟨x, hx⟩ => by simp [h]⟩
#align set.eq_preimage_subtype_val_iff Set.eq_preimage_subtype_val_iff
theorem nonempty_of_nonempty_preimage {s : Set β} {f : α → β} (hf : (f ⁻¹' s).Nonempty) :
s.Nonempty :=
let ⟨x, hx⟩ := hf
⟨f x, hx⟩
#align set.nonempty_of_nonempty_preimage Set.nonempty_of_nonempty_preimage
@[simp] theorem preimage_singleton_true (p : α → Prop) : p ⁻¹' {True} = {a | p a} := by ext; simp
#align set.preimage_singleton_true Set.preimage_singleton_true
@[simp] theorem preimage_singleton_false (p : α → Prop) : p ⁻¹' {False} = {a | ¬p a} := by ext; simp
#align set.preimage_singleton_false Set.preimage_singleton_false
theorem preimage_subtype_coe_eq_compl {s u v : Set α} (hsuv : s ⊆ u ∪ v)
(H : s ∩ (u ∩ v) = ∅) : ((↑) : s → α) ⁻¹' u = ((↑) ⁻¹' v)ᶜ := by
ext ⟨x, x_in_s⟩
constructor
· intro x_in_u x_in_v
exact eq_empty_iff_forall_not_mem.mp H x ⟨x_in_s, ⟨x_in_u, x_in_v⟩⟩
· intro hx
exact Or.elim (hsuv x_in_s) id fun hx' => hx.elim hx'
#align set.preimage_subtype_coe_eq_compl Set.preimage_subtype_coe_eq_compl
end Preimage
/-! ### Image of a set under a function -/
section Image
variable {f : α → β} {s t : Set α}
-- Porting note: `Set.image` is already defined in `Init.Set`
#align set.image Set.image
/-- `f '' s` denotes the image of `s : Set α` under the function `f : α → β`. -/
infixl:80 " '' " => image
theorem mem_image_iff_bex {f : α → β} {s : Set α} {y : β} :
y ∈ f '' s ↔ ∃ (x : _) (_ : x ∈ s), f x = y :=
bex_def.symm
#align set.mem_image_iff_bex Set.mem_image_iff_bex
@[simp]
theorem mem_image (f : α → β) (s : Set α) (y : β) : y ∈ f '' s ↔ ∃ x ∈ s, f x = y :=
Iff.rfl
#align set.mem_image Set.mem_image
theorem image_eta (f : α → β) : f '' s = (fun x => f x) '' s :=
rfl
#align set.image_eta Set.image_eta
@[mfld_simps]
theorem mem_image_of_mem (f : α → β) {x : α} {a : Set α} (h : x ∈ a) : f x ∈ f '' a :=
⟨_, h, rfl⟩
#align set.mem_image_of_mem Set.mem_image_of_mem
theorem _root_.Function.Injective.mem_set_image {f : α → β} (hf : Injective f) {s : Set α} {a : α} :
f a ∈ f '' s ↔ a ∈ s :=
⟨fun ⟨_, hb, Eq⟩ => hf Eq ▸ hb, mem_image_of_mem f⟩
#align function.injective.mem_set_image Function.Injective.mem_set_image
theorem ball_image_iff {f : α → β} {s : Set α} {p : β → Prop} :
(∀ y ∈ f '' s, p y) ↔ ∀ x ∈ s, p (f x) := by simp
#align set.ball_image_iff Set.ball_image_iff
theorem ball_image_of_ball {f : α → β} {s : Set α} {p : β → Prop} (h : ∀ x ∈ s, p (f x)) :
∀ y ∈ f '' s, p y :=
ball_image_iff.2 h
#align set.ball_image_of_ball Set.ball_image_of_ball
theorem bex_image_iff {f : α → β} {s : Set α} {p : β → Prop} :
(∃ y ∈ f '' s, p y) ↔ ∃ x ∈ s, p (f x) := by simp
#align set.bex_image_iff Set.bex_image_iff
theorem mem_image_elim {f : α → β} {s : Set α} {C : β → Prop} (h : ∀ x : α, x ∈ s → C (f x)) :
∀ {y : β}, y ∈ f '' s → C y
| _, ⟨a, a_in, rfl⟩ => h a a_in
#align set.mem_image_elim Set.mem_image_elim
theorem mem_image_elim_on {f : α → β} {s : Set α} {C : β → Prop} {y : β} (h_y : y ∈ f '' s)
(h : ∀ x : α, x ∈ s → C (f x)) : C y :=
mem_image_elim h h_y
#align set.mem_image_elim_on Set.mem_image_elim_on
-- Porting note: used to be `safe`
@[congr]
theorem image_congr {f g : α → β} {s : Set α} (h : ∀ a ∈ s, f a = g a) : f '' s = g '' s := by
ext x
rw [mem_image, mem_image]
exact {
mp := by
rintro ⟨a, ha1, ha2⟩
exact ⟨a, ⟨ha1, (h a ha1) ▸ ha2⟩⟩,
mpr := by
rintro ⟨a, ha1, ha2⟩
exact ⟨a, ⟨ha1, (h a ha1) ▸ ha2⟩⟩
}
-- safe [ext_iff, iff_def]
#align set.image_congr Set.image_congr
/-- A common special case of `image_congr` -/
theorem image_congr' {f g : α → β} {s : Set α} (h : ∀ x : α, f x = g x) : f '' s = g '' s :=
image_congr fun x _ => h x
#align set.image_congr' Set.image_congr'
@[gcongr]
lemma image_mono (h : s ⊆ t) : f '' s ⊆ f '' t := by
rintro - ⟨a, ha, rfl⟩; exact mem_image_of_mem f (h ha)
theorem image_comp (f : β → γ) (g : α → β) (a : Set α) : f ∘ g '' a = f '' (g '' a) :=
Subset.antisymm (ball_image_of_ball fun _ ha => mem_image_of_mem _ <| mem_image_of_mem _ ha)
(ball_image_of_ball <| ball_image_of_ball fun _ ha => mem_image_of_mem _ ha)
#align set.image_comp Set.image_comp
theorem image_comp_eq {g : β → γ} : image (g ∘ f) = image g ∘ image f := by ext; simp
/-- A variant of `image_comp`, useful for rewriting -/
theorem image_image (g : β → γ) (f : α → β) (s : Set α) : g '' (f '' s) = (fun x => g (f x)) '' s :=
(image_comp g f s).symm
#align set.image_image Set.image_image
theorem image_comm {β'} {f : β → γ} {g : α → β} {f' : α → β'} {g' : β' → γ}
(h_comm : ∀ a, f (g a) = g' (f' a)) : (s.image g).image f = (s.image f').image g' := by
simp_rw [image_image, h_comm]
#align set.image_comm Set.image_comm
theorem _root_.Function.Semiconj.set_image {f : α → β} {ga : α → α} {gb : β → β}
(h : Function.Semiconj f ga gb) : Function.Semiconj (image f) (image ga) (image gb) := fun _ =>
image_comm h
#align function.semiconj.set_image Function.Semiconj.set_image
theorem _root_.Function.Commute.set_image {f g : α → α} (h : Function.Commute f g) :
Function.Commute (image f) (image g) :=
Function.Semiconj.set_image h
#align function.commute.set_image Function.Commute.set_image
/-- Image is monotone with respect to `⊆`. See `Set.monotone_image` for the statement in
terms of `≤`. -/
@[gcongr]
theorem image_subset {a b : Set α} (f : α → β) (h : a ⊆ b) : f '' a ⊆ f '' b := by
simp only [subset_def, mem_image]
exact fun x => fun ⟨w, h1, h2⟩ => ⟨w, h h1, h2⟩
#align set.image_subset Set.image_subset
/-- `Set.image` is monotone. See `Set.image_subset` for the statement in terms of `⊆`. -/
lemma monotone_image {f : α → β} : Monotone (image f) := fun _ _ => image_subset _
#align set.monotone_image Set.monotone_image
theorem image_union (f : α → β) (s t : Set α) : f '' (s ∪ t) = f '' s ∪ f '' t :=
ext fun x =>
⟨by rintro ⟨a, h | h, rfl⟩ <;> [left; right] <;> exact ⟨_, h, rfl⟩, by
rintro (⟨a, h, rfl⟩ | ⟨a, h, rfl⟩) <;> refine' ⟨_, _, rfl⟩ <;> [left; right] <;> exact h⟩
#align set.image_union Set.image_union
@[simp]
theorem image_empty (f : α → β) : f '' ∅ = ∅ := by
ext
simp
#align set.image_empty Set.image_empty
theorem image_inter_subset (f : α → β) (s t : Set α) : f '' (s ∩ t) ⊆ f '' s ∩ f '' t :=
subset_inter (image_subset _ <| inter_subset_left _ _) (image_subset _ <| inter_subset_right _ _)
#align set.image_inter_subset Set.image_inter_subset
theorem image_inter_on {f : α → β} {s t : Set α} (h : ∀ x ∈ t, ∀ y ∈ s, f x = f y → x = y) :
f '' (s ∩ t) = f '' s ∩ f '' t :=
(image_inter_subset _ _ _).antisymm
fun b ⟨⟨a₁, ha₁, h₁⟩, ⟨a₂, ha₂, h₂⟩⟩ ↦
have : a₂ = a₁ := h _ ha₂ _ ha₁ (by simp [*])
⟨a₁, ⟨ha₁, this ▸ ha₂⟩, h₁⟩
#align set.image_inter_on Set.image_inter_on
theorem image_inter {f : α → β} {s t : Set α} (H : Injective f) : f '' (s ∩ t) = f '' s ∩ f '' t :=
image_inter_on fun _ _ _ _ h => H h
#align set.image_inter Set.image_inter
theorem image_univ_of_surjective {ι : Type*} {f : ι → β} (H : Surjective f) : f '' univ = univ :=
eq_univ_of_forall <| by simpa [image]
#align set.image_univ_of_surjective Set.image_univ_of_surjective
@[simp]
theorem image_singleton {f : α → β} {a : α} : f '' {a} = {f a} := by
ext
simp [image, eq_comm]
#align set.image_singleton Set.image_singleton
@[simp]
theorem Nonempty.image_const {s : Set α} (hs : s.Nonempty) (a : β) : (fun _ => a) '' s = {a} :=
ext fun _ =>
⟨fun ⟨_, _, h⟩ => h ▸ mem_singleton _, fun h =>
(eq_of_mem_singleton h).symm ▸ hs.imp fun _ hy => ⟨hy, rfl⟩⟩
#align set.nonempty.image_const Set.Nonempty.image_const
@[simp, mfld_simps]
theorem image_eq_empty {α β} {f : α → β} {s : Set α} : f '' s = ∅ ↔ s = ∅ := by
simp only [eq_empty_iff_forall_not_mem]
exact ⟨fun H a ha => H _ ⟨_, ha, rfl⟩, fun H b ⟨_, ha, _⟩ => H _ ha⟩
#align set.image_eq_empty Set.image_eq_empty
-- Porting note: `compl` is already defined in `Init.Set`
theorem preimage_compl_eq_image_compl [BooleanAlgebra α] (S : Set α) :
HasCompl.compl ⁻¹' S = HasCompl.compl '' S :=
Set.ext fun x =>
⟨fun h => ⟨xᶜ, h, compl_compl x⟩, fun h =>
Exists.elim h fun _ hy => (compl_eq_comm.mp hy.2).symm.subst hy.1⟩
#align set.preimage_compl_eq_image_compl Set.preimage_compl_eq_image_compl
theorem mem_compl_image [BooleanAlgebra α] (t : α) (S : Set α) :
t ∈ HasCompl.compl '' S ↔ tᶜ ∈ S := by
simp [← preimage_compl_eq_image_compl]
#align set.mem_compl_image Set.mem_compl_image
@[simp]
theorem image_id_eq : image (id : α → α) = id := by ext; simp
/-- A variant of `image_id` -/
@[simp]
theorem image_id' (s : Set α) : (fun x => x) '' s = s := by
ext
simp
#align set.image_id' Set.image_id'
theorem image_id (s : Set α) : id '' s = s := by simp
#align set.image_id Set.image_id
lemma image_iterate_eq {f : α → α} {n : ℕ} : image (f^[n]) = (image f)^[n] := by
induction' n with n ih; · simp
rw [iterate_succ', iterate_succ',← ih, image_comp_eq]
theorem compl_compl_image [BooleanAlgebra α] (S : Set α) :
HasCompl.compl '' (HasCompl.compl '' S) = S := by
rw [← image_comp, compl_comp_compl, image_id]
#align set.compl_compl_image Set.compl_compl_image
theorem image_insert_eq {f : α → β} {a : α} {s : Set α} :
f '' insert a s = insert (f a) (f '' s) := by
ext
simp [and_or_left, exists_or, eq_comm, or_comm, and_comm]
#align set.image_insert_eq Set.image_insert_eq
theorem image_pair (f : α → β) (a b : α) : f '' {a, b} = {f a, f b} := by
simp only [image_insert_eq, image_singleton]
#align set.image_pair Set.image_pair
theorem image_subset_preimage_of_inverse {f : α → β} {g : β → α} (I : LeftInverse g f) (s : Set α) :
f '' s ⊆ g ⁻¹' s := fun _ ⟨a, h, e⟩ => e ▸ ((I a).symm ▸ h : g (f a) ∈ s)
#align set.image_subset_preimage_of_inverse Set.image_subset_preimage_of_inverse
theorem preimage_subset_image_of_inverse {f : α → β} {g : β → α} (I : LeftInverse g f) (s : Set β) :
f ⁻¹' s ⊆ g '' s := fun b h => ⟨f b, h, I b⟩
#align set.preimage_subset_image_of_inverse Set.preimage_subset_image_of_inverse
theorem image_eq_preimage_of_inverse {f : α → β} {g : β → α} (h₁ : LeftInverse g f)
(h₂ : RightInverse g f) : image f = preimage g :=
funext fun s =>
Subset.antisymm (image_subset_preimage_of_inverse h₁ s) (preimage_subset_image_of_inverse h₂ s)
#align set.image_eq_preimage_of_inverse Set.image_eq_preimage_of_inverse
theorem mem_image_iff_of_inverse {f : α → β} {g : β → α} {b : β} {s : Set α} (h₁ : LeftInverse g f)
(h₂ : RightInverse g f) : b ∈ f '' s ↔ g b ∈ s := by
rw [image_eq_preimage_of_inverse h₁ h₂]; rfl
#align set.mem_image_iff_of_inverse Set.mem_image_iff_of_inverse
theorem image_compl_subset {f : α → β} {s : Set α} (H : Injective f) : f '' sᶜ ⊆ (f '' s)ᶜ :=
Disjoint.subset_compl_left <| by simp [disjoint_iff_inf_le, ← image_inter H]
#align set.image_compl_subset Set.image_compl_subset
theorem subset_image_compl {f : α → β} {s : Set α} (H : Surjective f) : (f '' s)ᶜ ⊆ f '' sᶜ :=
compl_subset_iff_union.2 <| by
|
rw [← image_union]
|
theorem subset_image_compl {f : α → β} {s : Set α} (H : Surjective f) : (f '' s)ᶜ ⊆ f '' sᶜ :=
compl_subset_iff_union.2 <| by
|
Mathlib.Data.Set.Image.455_0.IJFiTzmYGOCpPSd
|
theorem subset_image_compl {f : α → β} {s : Set α} (H : Surjective f) : (f '' s)ᶜ ⊆ f '' sᶜ
|
Mathlib_Data_Set_Image
|
α : Type u_1
β : Type u_2
γ : Type u_3
ι : Sort u_4
ι' : Sort u_5
f✝ : α → β
s✝ t : Set α
f : α → β
s : Set α
H : Surjective f
⊢ f '' (s ∪ sᶜ) = univ
|
/-
Copyright (c) 2014 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Leonardo de Moura
-/
import Mathlib.Data.Set.Basic
#align_import data.set.image from "leanprover-community/mathlib"@"001ffdc42920050657fd45bd2b8bfbec8eaaeb29"
/-!
# Images and preimages of sets
## Main definitions
* `preimage f t : Set α` : the preimage f⁻¹(t) (written `f ⁻¹' t` in Lean) of a subset of β.
* `range f : Set β` : the image of `univ` under `f`.
Also works for `{p : Prop} (f : p → α)` (unlike `image`)
## Notation
* `f ⁻¹' t` for `Set.preimage f t`
* `f '' s` for `Set.image f s`
## Tags
set, sets, image, preimage, pre-image, range
-/
set_option autoImplicit true
universe u v
open Function Set
namespace Set
variable {α β γ : Type*} {ι ι' : Sort*}
/-! ### Inverse image -/
/-- The preimage of `s : Set β` by `f : α → β`, written `f ⁻¹' s`,
is the set of `x : α` such that `f x ∈ s`. -/
def preimage {α : Type u} {β : Type v} (f : α → β) (s : Set β) : Set α :=
{ x | f x ∈ s }
#align set.preimage Set.preimage
/-- `f ⁻¹' t` denotes the preimage of `t : Set β` under the function `f : α → β`. -/
infixl:80 " ⁻¹' " => preimage
section Preimage
variable {f : α → β} {g : β → γ}
@[simp]
theorem preimage_empty : f ⁻¹' ∅ = ∅ :=
rfl
#align set.preimage_empty Set.preimage_empty
@[simp, mfld_simps]
theorem mem_preimage {s : Set β} {a : α} : a ∈ f ⁻¹' s ↔ f a ∈ s :=
Iff.rfl
#align set.mem_preimage Set.mem_preimage
theorem preimage_congr {f g : α → β} {s : Set β} (h : ∀ x : α, f x = g x) : f ⁻¹' s = g ⁻¹' s := by
congr with x
simp [h]
#align set.preimage_congr Set.preimage_congr
@[gcongr]
theorem preimage_mono {s t : Set β} (h : s ⊆ t) : f ⁻¹' s ⊆ f ⁻¹' t := fun _ hx => h hx
#align set.preimage_mono Set.preimage_mono
@[simp, mfld_simps]
theorem preimage_univ : f ⁻¹' univ = univ :=
rfl
#align set.preimage_univ Set.preimage_univ
theorem subset_preimage_univ {s : Set α} : s ⊆ f ⁻¹' univ :=
subset_univ _
#align set.subset_preimage_univ Set.subset_preimage_univ
@[simp, mfld_simps]
theorem preimage_inter {s t : Set β} : f ⁻¹' (s ∩ t) = f ⁻¹' s ∩ f ⁻¹' t :=
rfl
#align set.preimage_inter Set.preimage_inter
@[simp]
theorem preimage_union {s t : Set β} : f ⁻¹' (s ∪ t) = f ⁻¹' s ∪ f ⁻¹' t :=
rfl
#align set.preimage_union Set.preimage_union
@[simp]
theorem preimage_compl {s : Set β} : f ⁻¹' sᶜ = (f ⁻¹' s)ᶜ :=
rfl
#align set.preimage_compl Set.preimage_compl
@[simp]
theorem preimage_diff (f : α → β) (s t : Set β) : f ⁻¹' (s \ t) = f ⁻¹' s \ f ⁻¹' t :=
rfl
#align set.preimage_diff Set.preimage_diff
@[simp]
lemma preimage_symmDiff {f : α → β} (s t : Set β) : f ⁻¹' (s ∆ t) = (f ⁻¹' s) ∆ (f ⁻¹' t) :=
rfl
#align set.preimage_symm_diff Set.preimage_symmDiff
@[simp]
theorem preimage_ite (f : α → β) (s t₁ t₂ : Set β) :
f ⁻¹' s.ite t₁ t₂ = (f ⁻¹' s).ite (f ⁻¹' t₁) (f ⁻¹' t₂) :=
rfl
#align set.preimage_ite Set.preimage_ite
@[simp]
theorem preimage_setOf_eq {p : α → Prop} {f : β → α} : f ⁻¹' { a | p a } = { a | p (f a) } :=
rfl
#align set.preimage_set_of_eq Set.preimage_setOf_eq
@[simp]
theorem preimage_id_eq : preimage (id : α → α) = id :=
rfl
#align set.preimage_id_eq Set.preimage_id_eq
@[mfld_simps]
theorem preimage_id {s : Set α} : id ⁻¹' s = s :=
rfl
#align set.preimage_id Set.preimage_id
@[simp, mfld_simps]
theorem preimage_id' {s : Set α} : (fun x => x) ⁻¹' s = s :=
rfl
#align set.preimage_id' Set.preimage_id'
@[simp]
theorem preimage_const_of_mem {b : β} {s : Set β} (h : b ∈ s) : (fun _ : α => b) ⁻¹' s = univ :=
eq_univ_of_forall fun _ => h
#align set.preimage_const_of_mem Set.preimage_const_of_mem
@[simp]
theorem preimage_const_of_not_mem {b : β} {s : Set β} (h : b ∉ s) : (fun _ : α => b) ⁻¹' s = ∅ :=
eq_empty_of_subset_empty fun _ hx => h hx
#align set.preimage_const_of_not_mem Set.preimage_const_of_not_mem
theorem preimage_const (b : β) (s : Set β) [Decidable (b ∈ s)] :
(fun _ : α => b) ⁻¹' s = if b ∈ s then univ else ∅ := by
split_ifs with hb
exacts [preimage_const_of_mem hb, preimage_const_of_not_mem hb]
#align set.preimage_const Set.preimage_const
/-- If preimage of each singleton under `f : α → β` is either empty or the whole type,
then `f` is a constant. -/
lemma exists_eq_const_of_preimage_singleton [Nonempty β] {f : α → β}
(hf : ∀ b : β, f ⁻¹' {b} = ∅ ∨ f ⁻¹' {b} = univ) : ∃ b, f = const α b := by
rcases em (∃ b, f ⁻¹' {b} = univ) with ⟨b, hb⟩ | hf'
· exact ⟨b, funext fun x ↦ eq_univ_iff_forall.1 hb x⟩
· have : ∀ x b, f x ≠ b := fun x b ↦
eq_empty_iff_forall_not_mem.1 ((hf b).resolve_right fun h ↦ hf' ⟨b, h⟩) x
exact ⟨Classical.arbitrary β, funext fun x ↦ absurd rfl (this x _)⟩
theorem preimage_comp {s : Set γ} : g ∘ f ⁻¹' s = f ⁻¹' (g ⁻¹' s) :=
rfl
#align set.preimage_comp Set.preimage_comp
theorem preimage_comp_eq : preimage (g ∘ f) = preimage f ∘ preimage g :=
rfl
#align set.preimage_comp_eq Set.preimage_comp_eq
theorem preimage_iterate_eq {f : α → α} {n : ℕ} : Set.preimage f^[n] = (Set.preimage f)^[n] := by
induction' n with n ih; · simp
rw [iterate_succ, iterate_succ', preimage_comp_eq, ih]
#align set.preimage_iterate_eq Set.preimage_iterate_eq
theorem preimage_preimage {g : β → γ} {f : α → β} {s : Set γ} :
f ⁻¹' (g ⁻¹' s) = (fun x => g (f x)) ⁻¹' s :=
preimage_comp.symm
#align set.preimage_preimage Set.preimage_preimage
theorem eq_preimage_subtype_val_iff {p : α → Prop} {s : Set (Subtype p)} {t : Set α} :
s = Subtype.val ⁻¹' t ↔ ∀ (x) (h : p x), (⟨x, h⟩ : Subtype p) ∈ s ↔ x ∈ t :=
⟨fun s_eq x h => by
rw [s_eq]
simp, fun h => ext fun ⟨x, hx⟩ => by simp [h]⟩
#align set.eq_preimage_subtype_val_iff Set.eq_preimage_subtype_val_iff
theorem nonempty_of_nonempty_preimage {s : Set β} {f : α → β} (hf : (f ⁻¹' s).Nonempty) :
s.Nonempty :=
let ⟨x, hx⟩ := hf
⟨f x, hx⟩
#align set.nonempty_of_nonempty_preimage Set.nonempty_of_nonempty_preimage
@[simp] theorem preimage_singleton_true (p : α → Prop) : p ⁻¹' {True} = {a | p a} := by ext; simp
#align set.preimage_singleton_true Set.preimage_singleton_true
@[simp] theorem preimage_singleton_false (p : α → Prop) : p ⁻¹' {False} = {a | ¬p a} := by ext; simp
#align set.preimage_singleton_false Set.preimage_singleton_false
theorem preimage_subtype_coe_eq_compl {s u v : Set α} (hsuv : s ⊆ u ∪ v)
(H : s ∩ (u ∩ v) = ∅) : ((↑) : s → α) ⁻¹' u = ((↑) ⁻¹' v)ᶜ := by
ext ⟨x, x_in_s⟩
constructor
· intro x_in_u x_in_v
exact eq_empty_iff_forall_not_mem.mp H x ⟨x_in_s, ⟨x_in_u, x_in_v⟩⟩
· intro hx
exact Or.elim (hsuv x_in_s) id fun hx' => hx.elim hx'
#align set.preimage_subtype_coe_eq_compl Set.preimage_subtype_coe_eq_compl
end Preimage
/-! ### Image of a set under a function -/
section Image
variable {f : α → β} {s t : Set α}
-- Porting note: `Set.image` is already defined in `Init.Set`
#align set.image Set.image
/-- `f '' s` denotes the image of `s : Set α` under the function `f : α → β`. -/
infixl:80 " '' " => image
theorem mem_image_iff_bex {f : α → β} {s : Set α} {y : β} :
y ∈ f '' s ↔ ∃ (x : _) (_ : x ∈ s), f x = y :=
bex_def.symm
#align set.mem_image_iff_bex Set.mem_image_iff_bex
@[simp]
theorem mem_image (f : α → β) (s : Set α) (y : β) : y ∈ f '' s ↔ ∃ x ∈ s, f x = y :=
Iff.rfl
#align set.mem_image Set.mem_image
theorem image_eta (f : α → β) : f '' s = (fun x => f x) '' s :=
rfl
#align set.image_eta Set.image_eta
@[mfld_simps]
theorem mem_image_of_mem (f : α → β) {x : α} {a : Set α} (h : x ∈ a) : f x ∈ f '' a :=
⟨_, h, rfl⟩
#align set.mem_image_of_mem Set.mem_image_of_mem
theorem _root_.Function.Injective.mem_set_image {f : α → β} (hf : Injective f) {s : Set α} {a : α} :
f a ∈ f '' s ↔ a ∈ s :=
⟨fun ⟨_, hb, Eq⟩ => hf Eq ▸ hb, mem_image_of_mem f⟩
#align function.injective.mem_set_image Function.Injective.mem_set_image
theorem ball_image_iff {f : α → β} {s : Set α} {p : β → Prop} :
(∀ y ∈ f '' s, p y) ↔ ∀ x ∈ s, p (f x) := by simp
#align set.ball_image_iff Set.ball_image_iff
theorem ball_image_of_ball {f : α → β} {s : Set α} {p : β → Prop} (h : ∀ x ∈ s, p (f x)) :
∀ y ∈ f '' s, p y :=
ball_image_iff.2 h
#align set.ball_image_of_ball Set.ball_image_of_ball
theorem bex_image_iff {f : α → β} {s : Set α} {p : β → Prop} :
(∃ y ∈ f '' s, p y) ↔ ∃ x ∈ s, p (f x) := by simp
#align set.bex_image_iff Set.bex_image_iff
theorem mem_image_elim {f : α → β} {s : Set α} {C : β → Prop} (h : ∀ x : α, x ∈ s → C (f x)) :
∀ {y : β}, y ∈ f '' s → C y
| _, ⟨a, a_in, rfl⟩ => h a a_in
#align set.mem_image_elim Set.mem_image_elim
theorem mem_image_elim_on {f : α → β} {s : Set α} {C : β → Prop} {y : β} (h_y : y ∈ f '' s)
(h : ∀ x : α, x ∈ s → C (f x)) : C y :=
mem_image_elim h h_y
#align set.mem_image_elim_on Set.mem_image_elim_on
-- Porting note: used to be `safe`
@[congr]
theorem image_congr {f g : α → β} {s : Set α} (h : ∀ a ∈ s, f a = g a) : f '' s = g '' s := by
ext x
rw [mem_image, mem_image]
exact {
mp := by
rintro ⟨a, ha1, ha2⟩
exact ⟨a, ⟨ha1, (h a ha1) ▸ ha2⟩⟩,
mpr := by
rintro ⟨a, ha1, ha2⟩
exact ⟨a, ⟨ha1, (h a ha1) ▸ ha2⟩⟩
}
-- safe [ext_iff, iff_def]
#align set.image_congr Set.image_congr
/-- A common special case of `image_congr` -/
theorem image_congr' {f g : α → β} {s : Set α} (h : ∀ x : α, f x = g x) : f '' s = g '' s :=
image_congr fun x _ => h x
#align set.image_congr' Set.image_congr'
@[gcongr]
lemma image_mono (h : s ⊆ t) : f '' s ⊆ f '' t := by
rintro - ⟨a, ha, rfl⟩; exact mem_image_of_mem f (h ha)
theorem image_comp (f : β → γ) (g : α → β) (a : Set α) : f ∘ g '' a = f '' (g '' a) :=
Subset.antisymm (ball_image_of_ball fun _ ha => mem_image_of_mem _ <| mem_image_of_mem _ ha)
(ball_image_of_ball <| ball_image_of_ball fun _ ha => mem_image_of_mem _ ha)
#align set.image_comp Set.image_comp
theorem image_comp_eq {g : β → γ} : image (g ∘ f) = image g ∘ image f := by ext; simp
/-- A variant of `image_comp`, useful for rewriting -/
theorem image_image (g : β → γ) (f : α → β) (s : Set α) : g '' (f '' s) = (fun x => g (f x)) '' s :=
(image_comp g f s).symm
#align set.image_image Set.image_image
theorem image_comm {β'} {f : β → γ} {g : α → β} {f' : α → β'} {g' : β' → γ}
(h_comm : ∀ a, f (g a) = g' (f' a)) : (s.image g).image f = (s.image f').image g' := by
simp_rw [image_image, h_comm]
#align set.image_comm Set.image_comm
theorem _root_.Function.Semiconj.set_image {f : α → β} {ga : α → α} {gb : β → β}
(h : Function.Semiconj f ga gb) : Function.Semiconj (image f) (image ga) (image gb) := fun _ =>
image_comm h
#align function.semiconj.set_image Function.Semiconj.set_image
theorem _root_.Function.Commute.set_image {f g : α → α} (h : Function.Commute f g) :
Function.Commute (image f) (image g) :=
Function.Semiconj.set_image h
#align function.commute.set_image Function.Commute.set_image
/-- Image is monotone with respect to `⊆`. See `Set.monotone_image` for the statement in
terms of `≤`. -/
@[gcongr]
theorem image_subset {a b : Set α} (f : α → β) (h : a ⊆ b) : f '' a ⊆ f '' b := by
simp only [subset_def, mem_image]
exact fun x => fun ⟨w, h1, h2⟩ => ⟨w, h h1, h2⟩
#align set.image_subset Set.image_subset
/-- `Set.image` is monotone. See `Set.image_subset` for the statement in terms of `⊆`. -/
lemma monotone_image {f : α → β} : Monotone (image f) := fun _ _ => image_subset _
#align set.monotone_image Set.monotone_image
theorem image_union (f : α → β) (s t : Set α) : f '' (s ∪ t) = f '' s ∪ f '' t :=
ext fun x =>
⟨by rintro ⟨a, h | h, rfl⟩ <;> [left; right] <;> exact ⟨_, h, rfl⟩, by
rintro (⟨a, h, rfl⟩ | ⟨a, h, rfl⟩) <;> refine' ⟨_, _, rfl⟩ <;> [left; right] <;> exact h⟩
#align set.image_union Set.image_union
@[simp]
theorem image_empty (f : α → β) : f '' ∅ = ∅ := by
ext
simp
#align set.image_empty Set.image_empty
theorem image_inter_subset (f : α → β) (s t : Set α) : f '' (s ∩ t) ⊆ f '' s ∩ f '' t :=
subset_inter (image_subset _ <| inter_subset_left _ _) (image_subset _ <| inter_subset_right _ _)
#align set.image_inter_subset Set.image_inter_subset
theorem image_inter_on {f : α → β} {s t : Set α} (h : ∀ x ∈ t, ∀ y ∈ s, f x = f y → x = y) :
f '' (s ∩ t) = f '' s ∩ f '' t :=
(image_inter_subset _ _ _).antisymm
fun b ⟨⟨a₁, ha₁, h₁⟩, ⟨a₂, ha₂, h₂⟩⟩ ↦
have : a₂ = a₁ := h _ ha₂ _ ha₁ (by simp [*])
⟨a₁, ⟨ha₁, this ▸ ha₂⟩, h₁⟩
#align set.image_inter_on Set.image_inter_on
theorem image_inter {f : α → β} {s t : Set α} (H : Injective f) : f '' (s ∩ t) = f '' s ∩ f '' t :=
image_inter_on fun _ _ _ _ h => H h
#align set.image_inter Set.image_inter
theorem image_univ_of_surjective {ι : Type*} {f : ι → β} (H : Surjective f) : f '' univ = univ :=
eq_univ_of_forall <| by simpa [image]
#align set.image_univ_of_surjective Set.image_univ_of_surjective
@[simp]
theorem image_singleton {f : α → β} {a : α} : f '' {a} = {f a} := by
ext
simp [image, eq_comm]
#align set.image_singleton Set.image_singleton
@[simp]
theorem Nonempty.image_const {s : Set α} (hs : s.Nonempty) (a : β) : (fun _ => a) '' s = {a} :=
ext fun _ =>
⟨fun ⟨_, _, h⟩ => h ▸ mem_singleton _, fun h =>
(eq_of_mem_singleton h).symm ▸ hs.imp fun _ hy => ⟨hy, rfl⟩⟩
#align set.nonempty.image_const Set.Nonempty.image_const
@[simp, mfld_simps]
theorem image_eq_empty {α β} {f : α → β} {s : Set α} : f '' s = ∅ ↔ s = ∅ := by
simp only [eq_empty_iff_forall_not_mem]
exact ⟨fun H a ha => H _ ⟨_, ha, rfl⟩, fun H b ⟨_, ha, _⟩ => H _ ha⟩
#align set.image_eq_empty Set.image_eq_empty
-- Porting note: `compl` is already defined in `Init.Set`
theorem preimage_compl_eq_image_compl [BooleanAlgebra α] (S : Set α) :
HasCompl.compl ⁻¹' S = HasCompl.compl '' S :=
Set.ext fun x =>
⟨fun h => ⟨xᶜ, h, compl_compl x⟩, fun h =>
Exists.elim h fun _ hy => (compl_eq_comm.mp hy.2).symm.subst hy.1⟩
#align set.preimage_compl_eq_image_compl Set.preimage_compl_eq_image_compl
theorem mem_compl_image [BooleanAlgebra α] (t : α) (S : Set α) :
t ∈ HasCompl.compl '' S ↔ tᶜ ∈ S := by
simp [← preimage_compl_eq_image_compl]
#align set.mem_compl_image Set.mem_compl_image
@[simp]
theorem image_id_eq : image (id : α → α) = id := by ext; simp
/-- A variant of `image_id` -/
@[simp]
theorem image_id' (s : Set α) : (fun x => x) '' s = s := by
ext
simp
#align set.image_id' Set.image_id'
theorem image_id (s : Set α) : id '' s = s := by simp
#align set.image_id Set.image_id
lemma image_iterate_eq {f : α → α} {n : ℕ} : image (f^[n]) = (image f)^[n] := by
induction' n with n ih; · simp
rw [iterate_succ', iterate_succ',← ih, image_comp_eq]
theorem compl_compl_image [BooleanAlgebra α] (S : Set α) :
HasCompl.compl '' (HasCompl.compl '' S) = S := by
rw [← image_comp, compl_comp_compl, image_id]
#align set.compl_compl_image Set.compl_compl_image
theorem image_insert_eq {f : α → β} {a : α} {s : Set α} :
f '' insert a s = insert (f a) (f '' s) := by
ext
simp [and_or_left, exists_or, eq_comm, or_comm, and_comm]
#align set.image_insert_eq Set.image_insert_eq
theorem image_pair (f : α → β) (a b : α) : f '' {a, b} = {f a, f b} := by
simp only [image_insert_eq, image_singleton]
#align set.image_pair Set.image_pair
theorem image_subset_preimage_of_inverse {f : α → β} {g : β → α} (I : LeftInverse g f) (s : Set α) :
f '' s ⊆ g ⁻¹' s := fun _ ⟨a, h, e⟩ => e ▸ ((I a).symm ▸ h : g (f a) ∈ s)
#align set.image_subset_preimage_of_inverse Set.image_subset_preimage_of_inverse
theorem preimage_subset_image_of_inverse {f : α → β} {g : β → α} (I : LeftInverse g f) (s : Set β) :
f ⁻¹' s ⊆ g '' s := fun b h => ⟨f b, h, I b⟩
#align set.preimage_subset_image_of_inverse Set.preimage_subset_image_of_inverse
theorem image_eq_preimage_of_inverse {f : α → β} {g : β → α} (h₁ : LeftInverse g f)
(h₂ : RightInverse g f) : image f = preimage g :=
funext fun s =>
Subset.antisymm (image_subset_preimage_of_inverse h₁ s) (preimage_subset_image_of_inverse h₂ s)
#align set.image_eq_preimage_of_inverse Set.image_eq_preimage_of_inverse
theorem mem_image_iff_of_inverse {f : α → β} {g : β → α} {b : β} {s : Set α} (h₁ : LeftInverse g f)
(h₂ : RightInverse g f) : b ∈ f '' s ↔ g b ∈ s := by
rw [image_eq_preimage_of_inverse h₁ h₂]; rfl
#align set.mem_image_iff_of_inverse Set.mem_image_iff_of_inverse
theorem image_compl_subset {f : α → β} {s : Set α} (H : Injective f) : f '' sᶜ ⊆ (f '' s)ᶜ :=
Disjoint.subset_compl_left <| by simp [disjoint_iff_inf_le, ← image_inter H]
#align set.image_compl_subset Set.image_compl_subset
theorem subset_image_compl {f : α → β} {s : Set α} (H : Surjective f) : (f '' s)ᶜ ⊆ f '' sᶜ :=
compl_subset_iff_union.2 <| by
rw [← image_union]
|
simp [image_univ_of_surjective H]
|
theorem subset_image_compl {f : α → β} {s : Set α} (H : Surjective f) : (f '' s)ᶜ ⊆ f '' sᶜ :=
compl_subset_iff_union.2 <| by
rw [← image_union]
|
Mathlib.Data.Set.Image.455_0.IJFiTzmYGOCpPSd
|
theorem subset_image_compl {f : α → β} {s : Set α} (H : Surjective f) : (f '' s)ᶜ ⊆ f '' sᶜ
|
Mathlib_Data_Set_Image
|
α : Type u_1
β : Type u_2
γ : Type u_3
ι : Sort u_4
ι' : Sort u_5
f✝ : α → β
s✝ t✝ : Set α
f : α → β
s t : Set α
⊢ f '' s \ f '' t ⊆ f '' (s \ t)
|
/-
Copyright (c) 2014 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Leonardo de Moura
-/
import Mathlib.Data.Set.Basic
#align_import data.set.image from "leanprover-community/mathlib"@"001ffdc42920050657fd45bd2b8bfbec8eaaeb29"
/-!
# Images and preimages of sets
## Main definitions
* `preimage f t : Set α` : the preimage f⁻¹(t) (written `f ⁻¹' t` in Lean) of a subset of β.
* `range f : Set β` : the image of `univ` under `f`.
Also works for `{p : Prop} (f : p → α)` (unlike `image`)
## Notation
* `f ⁻¹' t` for `Set.preimage f t`
* `f '' s` for `Set.image f s`
## Tags
set, sets, image, preimage, pre-image, range
-/
set_option autoImplicit true
universe u v
open Function Set
namespace Set
variable {α β γ : Type*} {ι ι' : Sort*}
/-! ### Inverse image -/
/-- The preimage of `s : Set β` by `f : α → β`, written `f ⁻¹' s`,
is the set of `x : α` such that `f x ∈ s`. -/
def preimage {α : Type u} {β : Type v} (f : α → β) (s : Set β) : Set α :=
{ x | f x ∈ s }
#align set.preimage Set.preimage
/-- `f ⁻¹' t` denotes the preimage of `t : Set β` under the function `f : α → β`. -/
infixl:80 " ⁻¹' " => preimage
section Preimage
variable {f : α → β} {g : β → γ}
@[simp]
theorem preimage_empty : f ⁻¹' ∅ = ∅ :=
rfl
#align set.preimage_empty Set.preimage_empty
@[simp, mfld_simps]
theorem mem_preimage {s : Set β} {a : α} : a ∈ f ⁻¹' s ↔ f a ∈ s :=
Iff.rfl
#align set.mem_preimage Set.mem_preimage
theorem preimage_congr {f g : α → β} {s : Set β} (h : ∀ x : α, f x = g x) : f ⁻¹' s = g ⁻¹' s := by
congr with x
simp [h]
#align set.preimage_congr Set.preimage_congr
@[gcongr]
theorem preimage_mono {s t : Set β} (h : s ⊆ t) : f ⁻¹' s ⊆ f ⁻¹' t := fun _ hx => h hx
#align set.preimage_mono Set.preimage_mono
@[simp, mfld_simps]
theorem preimage_univ : f ⁻¹' univ = univ :=
rfl
#align set.preimage_univ Set.preimage_univ
theorem subset_preimage_univ {s : Set α} : s ⊆ f ⁻¹' univ :=
subset_univ _
#align set.subset_preimage_univ Set.subset_preimage_univ
@[simp, mfld_simps]
theorem preimage_inter {s t : Set β} : f ⁻¹' (s ∩ t) = f ⁻¹' s ∩ f ⁻¹' t :=
rfl
#align set.preimage_inter Set.preimage_inter
@[simp]
theorem preimage_union {s t : Set β} : f ⁻¹' (s ∪ t) = f ⁻¹' s ∪ f ⁻¹' t :=
rfl
#align set.preimage_union Set.preimage_union
@[simp]
theorem preimage_compl {s : Set β} : f ⁻¹' sᶜ = (f ⁻¹' s)ᶜ :=
rfl
#align set.preimage_compl Set.preimage_compl
@[simp]
theorem preimage_diff (f : α → β) (s t : Set β) : f ⁻¹' (s \ t) = f ⁻¹' s \ f ⁻¹' t :=
rfl
#align set.preimage_diff Set.preimage_diff
@[simp]
lemma preimage_symmDiff {f : α → β} (s t : Set β) : f ⁻¹' (s ∆ t) = (f ⁻¹' s) ∆ (f ⁻¹' t) :=
rfl
#align set.preimage_symm_diff Set.preimage_symmDiff
@[simp]
theorem preimage_ite (f : α → β) (s t₁ t₂ : Set β) :
f ⁻¹' s.ite t₁ t₂ = (f ⁻¹' s).ite (f ⁻¹' t₁) (f ⁻¹' t₂) :=
rfl
#align set.preimage_ite Set.preimage_ite
@[simp]
theorem preimage_setOf_eq {p : α → Prop} {f : β → α} : f ⁻¹' { a | p a } = { a | p (f a) } :=
rfl
#align set.preimage_set_of_eq Set.preimage_setOf_eq
@[simp]
theorem preimage_id_eq : preimage (id : α → α) = id :=
rfl
#align set.preimage_id_eq Set.preimage_id_eq
@[mfld_simps]
theorem preimage_id {s : Set α} : id ⁻¹' s = s :=
rfl
#align set.preimage_id Set.preimage_id
@[simp, mfld_simps]
theorem preimage_id' {s : Set α} : (fun x => x) ⁻¹' s = s :=
rfl
#align set.preimage_id' Set.preimage_id'
@[simp]
theorem preimage_const_of_mem {b : β} {s : Set β} (h : b ∈ s) : (fun _ : α => b) ⁻¹' s = univ :=
eq_univ_of_forall fun _ => h
#align set.preimage_const_of_mem Set.preimage_const_of_mem
@[simp]
theorem preimage_const_of_not_mem {b : β} {s : Set β} (h : b ∉ s) : (fun _ : α => b) ⁻¹' s = ∅ :=
eq_empty_of_subset_empty fun _ hx => h hx
#align set.preimage_const_of_not_mem Set.preimage_const_of_not_mem
theorem preimage_const (b : β) (s : Set β) [Decidable (b ∈ s)] :
(fun _ : α => b) ⁻¹' s = if b ∈ s then univ else ∅ := by
split_ifs with hb
exacts [preimage_const_of_mem hb, preimage_const_of_not_mem hb]
#align set.preimage_const Set.preimage_const
/-- If preimage of each singleton under `f : α → β` is either empty or the whole type,
then `f` is a constant. -/
lemma exists_eq_const_of_preimage_singleton [Nonempty β] {f : α → β}
(hf : ∀ b : β, f ⁻¹' {b} = ∅ ∨ f ⁻¹' {b} = univ) : ∃ b, f = const α b := by
rcases em (∃ b, f ⁻¹' {b} = univ) with ⟨b, hb⟩ | hf'
· exact ⟨b, funext fun x ↦ eq_univ_iff_forall.1 hb x⟩
· have : ∀ x b, f x ≠ b := fun x b ↦
eq_empty_iff_forall_not_mem.1 ((hf b).resolve_right fun h ↦ hf' ⟨b, h⟩) x
exact ⟨Classical.arbitrary β, funext fun x ↦ absurd rfl (this x _)⟩
theorem preimage_comp {s : Set γ} : g ∘ f ⁻¹' s = f ⁻¹' (g ⁻¹' s) :=
rfl
#align set.preimage_comp Set.preimage_comp
theorem preimage_comp_eq : preimage (g ∘ f) = preimage f ∘ preimage g :=
rfl
#align set.preimage_comp_eq Set.preimage_comp_eq
theorem preimage_iterate_eq {f : α → α} {n : ℕ} : Set.preimage f^[n] = (Set.preimage f)^[n] := by
induction' n with n ih; · simp
rw [iterate_succ, iterate_succ', preimage_comp_eq, ih]
#align set.preimage_iterate_eq Set.preimage_iterate_eq
theorem preimage_preimage {g : β → γ} {f : α → β} {s : Set γ} :
f ⁻¹' (g ⁻¹' s) = (fun x => g (f x)) ⁻¹' s :=
preimage_comp.symm
#align set.preimage_preimage Set.preimage_preimage
theorem eq_preimage_subtype_val_iff {p : α → Prop} {s : Set (Subtype p)} {t : Set α} :
s = Subtype.val ⁻¹' t ↔ ∀ (x) (h : p x), (⟨x, h⟩ : Subtype p) ∈ s ↔ x ∈ t :=
⟨fun s_eq x h => by
rw [s_eq]
simp, fun h => ext fun ⟨x, hx⟩ => by simp [h]⟩
#align set.eq_preimage_subtype_val_iff Set.eq_preimage_subtype_val_iff
theorem nonempty_of_nonempty_preimage {s : Set β} {f : α → β} (hf : (f ⁻¹' s).Nonempty) :
s.Nonempty :=
let ⟨x, hx⟩ := hf
⟨f x, hx⟩
#align set.nonempty_of_nonempty_preimage Set.nonempty_of_nonempty_preimage
@[simp] theorem preimage_singleton_true (p : α → Prop) : p ⁻¹' {True} = {a | p a} := by ext; simp
#align set.preimage_singleton_true Set.preimage_singleton_true
@[simp] theorem preimage_singleton_false (p : α → Prop) : p ⁻¹' {False} = {a | ¬p a} := by ext; simp
#align set.preimage_singleton_false Set.preimage_singleton_false
theorem preimage_subtype_coe_eq_compl {s u v : Set α} (hsuv : s ⊆ u ∪ v)
(H : s ∩ (u ∩ v) = ∅) : ((↑) : s → α) ⁻¹' u = ((↑) ⁻¹' v)ᶜ := by
ext ⟨x, x_in_s⟩
constructor
· intro x_in_u x_in_v
exact eq_empty_iff_forall_not_mem.mp H x ⟨x_in_s, ⟨x_in_u, x_in_v⟩⟩
· intro hx
exact Or.elim (hsuv x_in_s) id fun hx' => hx.elim hx'
#align set.preimage_subtype_coe_eq_compl Set.preimage_subtype_coe_eq_compl
end Preimage
/-! ### Image of a set under a function -/
section Image
variable {f : α → β} {s t : Set α}
-- Porting note: `Set.image` is already defined in `Init.Set`
#align set.image Set.image
/-- `f '' s` denotes the image of `s : Set α` under the function `f : α → β`. -/
infixl:80 " '' " => image
theorem mem_image_iff_bex {f : α → β} {s : Set α} {y : β} :
y ∈ f '' s ↔ ∃ (x : _) (_ : x ∈ s), f x = y :=
bex_def.symm
#align set.mem_image_iff_bex Set.mem_image_iff_bex
@[simp]
theorem mem_image (f : α → β) (s : Set α) (y : β) : y ∈ f '' s ↔ ∃ x ∈ s, f x = y :=
Iff.rfl
#align set.mem_image Set.mem_image
theorem image_eta (f : α → β) : f '' s = (fun x => f x) '' s :=
rfl
#align set.image_eta Set.image_eta
@[mfld_simps]
theorem mem_image_of_mem (f : α → β) {x : α} {a : Set α} (h : x ∈ a) : f x ∈ f '' a :=
⟨_, h, rfl⟩
#align set.mem_image_of_mem Set.mem_image_of_mem
theorem _root_.Function.Injective.mem_set_image {f : α → β} (hf : Injective f) {s : Set α} {a : α} :
f a ∈ f '' s ↔ a ∈ s :=
⟨fun ⟨_, hb, Eq⟩ => hf Eq ▸ hb, mem_image_of_mem f⟩
#align function.injective.mem_set_image Function.Injective.mem_set_image
theorem ball_image_iff {f : α → β} {s : Set α} {p : β → Prop} :
(∀ y ∈ f '' s, p y) ↔ ∀ x ∈ s, p (f x) := by simp
#align set.ball_image_iff Set.ball_image_iff
theorem ball_image_of_ball {f : α → β} {s : Set α} {p : β → Prop} (h : ∀ x ∈ s, p (f x)) :
∀ y ∈ f '' s, p y :=
ball_image_iff.2 h
#align set.ball_image_of_ball Set.ball_image_of_ball
theorem bex_image_iff {f : α → β} {s : Set α} {p : β → Prop} :
(∃ y ∈ f '' s, p y) ↔ ∃ x ∈ s, p (f x) := by simp
#align set.bex_image_iff Set.bex_image_iff
theorem mem_image_elim {f : α → β} {s : Set α} {C : β → Prop} (h : ∀ x : α, x ∈ s → C (f x)) :
∀ {y : β}, y ∈ f '' s → C y
| _, ⟨a, a_in, rfl⟩ => h a a_in
#align set.mem_image_elim Set.mem_image_elim
theorem mem_image_elim_on {f : α → β} {s : Set α} {C : β → Prop} {y : β} (h_y : y ∈ f '' s)
(h : ∀ x : α, x ∈ s → C (f x)) : C y :=
mem_image_elim h h_y
#align set.mem_image_elim_on Set.mem_image_elim_on
-- Porting note: used to be `safe`
@[congr]
theorem image_congr {f g : α → β} {s : Set α} (h : ∀ a ∈ s, f a = g a) : f '' s = g '' s := by
ext x
rw [mem_image, mem_image]
exact {
mp := by
rintro ⟨a, ha1, ha2⟩
exact ⟨a, ⟨ha1, (h a ha1) ▸ ha2⟩⟩,
mpr := by
rintro ⟨a, ha1, ha2⟩
exact ⟨a, ⟨ha1, (h a ha1) ▸ ha2⟩⟩
}
-- safe [ext_iff, iff_def]
#align set.image_congr Set.image_congr
/-- A common special case of `image_congr` -/
theorem image_congr' {f g : α → β} {s : Set α} (h : ∀ x : α, f x = g x) : f '' s = g '' s :=
image_congr fun x _ => h x
#align set.image_congr' Set.image_congr'
@[gcongr]
lemma image_mono (h : s ⊆ t) : f '' s ⊆ f '' t := by
rintro - ⟨a, ha, rfl⟩; exact mem_image_of_mem f (h ha)
theorem image_comp (f : β → γ) (g : α → β) (a : Set α) : f ∘ g '' a = f '' (g '' a) :=
Subset.antisymm (ball_image_of_ball fun _ ha => mem_image_of_mem _ <| mem_image_of_mem _ ha)
(ball_image_of_ball <| ball_image_of_ball fun _ ha => mem_image_of_mem _ ha)
#align set.image_comp Set.image_comp
theorem image_comp_eq {g : β → γ} : image (g ∘ f) = image g ∘ image f := by ext; simp
/-- A variant of `image_comp`, useful for rewriting -/
theorem image_image (g : β → γ) (f : α → β) (s : Set α) : g '' (f '' s) = (fun x => g (f x)) '' s :=
(image_comp g f s).symm
#align set.image_image Set.image_image
theorem image_comm {β'} {f : β → γ} {g : α → β} {f' : α → β'} {g' : β' → γ}
(h_comm : ∀ a, f (g a) = g' (f' a)) : (s.image g).image f = (s.image f').image g' := by
simp_rw [image_image, h_comm]
#align set.image_comm Set.image_comm
theorem _root_.Function.Semiconj.set_image {f : α → β} {ga : α → α} {gb : β → β}
(h : Function.Semiconj f ga gb) : Function.Semiconj (image f) (image ga) (image gb) := fun _ =>
image_comm h
#align function.semiconj.set_image Function.Semiconj.set_image
theorem _root_.Function.Commute.set_image {f g : α → α} (h : Function.Commute f g) :
Function.Commute (image f) (image g) :=
Function.Semiconj.set_image h
#align function.commute.set_image Function.Commute.set_image
/-- Image is monotone with respect to `⊆`. See `Set.monotone_image` for the statement in
terms of `≤`. -/
@[gcongr]
theorem image_subset {a b : Set α} (f : α → β) (h : a ⊆ b) : f '' a ⊆ f '' b := by
simp only [subset_def, mem_image]
exact fun x => fun ⟨w, h1, h2⟩ => ⟨w, h h1, h2⟩
#align set.image_subset Set.image_subset
/-- `Set.image` is monotone. See `Set.image_subset` for the statement in terms of `⊆`. -/
lemma monotone_image {f : α → β} : Monotone (image f) := fun _ _ => image_subset _
#align set.monotone_image Set.monotone_image
theorem image_union (f : α → β) (s t : Set α) : f '' (s ∪ t) = f '' s ∪ f '' t :=
ext fun x =>
⟨by rintro ⟨a, h | h, rfl⟩ <;> [left; right] <;> exact ⟨_, h, rfl⟩, by
rintro (⟨a, h, rfl⟩ | ⟨a, h, rfl⟩) <;> refine' ⟨_, _, rfl⟩ <;> [left; right] <;> exact h⟩
#align set.image_union Set.image_union
@[simp]
theorem image_empty (f : α → β) : f '' ∅ = ∅ := by
ext
simp
#align set.image_empty Set.image_empty
theorem image_inter_subset (f : α → β) (s t : Set α) : f '' (s ∩ t) ⊆ f '' s ∩ f '' t :=
subset_inter (image_subset _ <| inter_subset_left _ _) (image_subset _ <| inter_subset_right _ _)
#align set.image_inter_subset Set.image_inter_subset
theorem image_inter_on {f : α → β} {s t : Set α} (h : ∀ x ∈ t, ∀ y ∈ s, f x = f y → x = y) :
f '' (s ∩ t) = f '' s ∩ f '' t :=
(image_inter_subset _ _ _).antisymm
fun b ⟨⟨a₁, ha₁, h₁⟩, ⟨a₂, ha₂, h₂⟩⟩ ↦
have : a₂ = a₁ := h _ ha₂ _ ha₁ (by simp [*])
⟨a₁, ⟨ha₁, this ▸ ha₂⟩, h₁⟩
#align set.image_inter_on Set.image_inter_on
theorem image_inter {f : α → β} {s t : Set α} (H : Injective f) : f '' (s ∩ t) = f '' s ∩ f '' t :=
image_inter_on fun _ _ _ _ h => H h
#align set.image_inter Set.image_inter
theorem image_univ_of_surjective {ι : Type*} {f : ι → β} (H : Surjective f) : f '' univ = univ :=
eq_univ_of_forall <| by simpa [image]
#align set.image_univ_of_surjective Set.image_univ_of_surjective
@[simp]
theorem image_singleton {f : α → β} {a : α} : f '' {a} = {f a} := by
ext
simp [image, eq_comm]
#align set.image_singleton Set.image_singleton
@[simp]
theorem Nonempty.image_const {s : Set α} (hs : s.Nonempty) (a : β) : (fun _ => a) '' s = {a} :=
ext fun _ =>
⟨fun ⟨_, _, h⟩ => h ▸ mem_singleton _, fun h =>
(eq_of_mem_singleton h).symm ▸ hs.imp fun _ hy => ⟨hy, rfl⟩⟩
#align set.nonempty.image_const Set.Nonempty.image_const
@[simp, mfld_simps]
theorem image_eq_empty {α β} {f : α → β} {s : Set α} : f '' s = ∅ ↔ s = ∅ := by
simp only [eq_empty_iff_forall_not_mem]
exact ⟨fun H a ha => H _ ⟨_, ha, rfl⟩, fun H b ⟨_, ha, _⟩ => H _ ha⟩
#align set.image_eq_empty Set.image_eq_empty
-- Porting note: `compl` is already defined in `Init.Set`
theorem preimage_compl_eq_image_compl [BooleanAlgebra α] (S : Set α) :
HasCompl.compl ⁻¹' S = HasCompl.compl '' S :=
Set.ext fun x =>
⟨fun h => ⟨xᶜ, h, compl_compl x⟩, fun h =>
Exists.elim h fun _ hy => (compl_eq_comm.mp hy.2).symm.subst hy.1⟩
#align set.preimage_compl_eq_image_compl Set.preimage_compl_eq_image_compl
theorem mem_compl_image [BooleanAlgebra α] (t : α) (S : Set α) :
t ∈ HasCompl.compl '' S ↔ tᶜ ∈ S := by
simp [← preimage_compl_eq_image_compl]
#align set.mem_compl_image Set.mem_compl_image
@[simp]
theorem image_id_eq : image (id : α → α) = id := by ext; simp
/-- A variant of `image_id` -/
@[simp]
theorem image_id' (s : Set α) : (fun x => x) '' s = s := by
ext
simp
#align set.image_id' Set.image_id'
theorem image_id (s : Set α) : id '' s = s := by simp
#align set.image_id Set.image_id
lemma image_iterate_eq {f : α → α} {n : ℕ} : image (f^[n]) = (image f)^[n] := by
induction' n with n ih; · simp
rw [iterate_succ', iterate_succ',← ih, image_comp_eq]
theorem compl_compl_image [BooleanAlgebra α] (S : Set α) :
HasCompl.compl '' (HasCompl.compl '' S) = S := by
rw [← image_comp, compl_comp_compl, image_id]
#align set.compl_compl_image Set.compl_compl_image
theorem image_insert_eq {f : α → β} {a : α} {s : Set α} :
f '' insert a s = insert (f a) (f '' s) := by
ext
simp [and_or_left, exists_or, eq_comm, or_comm, and_comm]
#align set.image_insert_eq Set.image_insert_eq
theorem image_pair (f : α → β) (a b : α) : f '' {a, b} = {f a, f b} := by
simp only [image_insert_eq, image_singleton]
#align set.image_pair Set.image_pair
theorem image_subset_preimage_of_inverse {f : α → β} {g : β → α} (I : LeftInverse g f) (s : Set α) :
f '' s ⊆ g ⁻¹' s := fun _ ⟨a, h, e⟩ => e ▸ ((I a).symm ▸ h : g (f a) ∈ s)
#align set.image_subset_preimage_of_inverse Set.image_subset_preimage_of_inverse
theorem preimage_subset_image_of_inverse {f : α → β} {g : β → α} (I : LeftInverse g f) (s : Set β) :
f ⁻¹' s ⊆ g '' s := fun b h => ⟨f b, h, I b⟩
#align set.preimage_subset_image_of_inverse Set.preimage_subset_image_of_inverse
theorem image_eq_preimage_of_inverse {f : α → β} {g : β → α} (h₁ : LeftInverse g f)
(h₂ : RightInverse g f) : image f = preimage g :=
funext fun s =>
Subset.antisymm (image_subset_preimage_of_inverse h₁ s) (preimage_subset_image_of_inverse h₂ s)
#align set.image_eq_preimage_of_inverse Set.image_eq_preimage_of_inverse
theorem mem_image_iff_of_inverse {f : α → β} {g : β → α} {b : β} {s : Set α} (h₁ : LeftInverse g f)
(h₂ : RightInverse g f) : b ∈ f '' s ↔ g b ∈ s := by
rw [image_eq_preimage_of_inverse h₁ h₂]; rfl
#align set.mem_image_iff_of_inverse Set.mem_image_iff_of_inverse
theorem image_compl_subset {f : α → β} {s : Set α} (H : Injective f) : f '' sᶜ ⊆ (f '' s)ᶜ :=
Disjoint.subset_compl_left <| by simp [disjoint_iff_inf_le, ← image_inter H]
#align set.image_compl_subset Set.image_compl_subset
theorem subset_image_compl {f : α → β} {s : Set α} (H : Surjective f) : (f '' s)ᶜ ⊆ f '' sᶜ :=
compl_subset_iff_union.2 <| by
rw [← image_union]
simp [image_univ_of_surjective H]
#align set.subset_image_compl Set.subset_image_compl
theorem image_compl_eq {f : α → β} {s : Set α} (H : Bijective f) : f '' sᶜ = (f '' s)ᶜ :=
Subset.antisymm (image_compl_subset H.1) (subset_image_compl H.2)
#align set.image_compl_eq Set.image_compl_eq
theorem subset_image_diff (f : α → β) (s t : Set α) : f '' s \ f '' t ⊆ f '' (s \ t) := by
|
rw [diff_subset_iff, ← image_union, union_diff_self]
|
theorem subset_image_diff (f : α → β) (s t : Set α) : f '' s \ f '' t ⊆ f '' (s \ t) := by
|
Mathlib.Data.Set.Image.465_0.IJFiTzmYGOCpPSd
|
theorem subset_image_diff (f : α → β) (s t : Set α) : f '' s \ f '' t ⊆ f '' (s \ t)
|
Mathlib_Data_Set_Image
|
α : Type u_1
β : Type u_2
γ : Type u_3
ι : Sort u_4
ι' : Sort u_5
f✝ : α → β
s✝ t✝ : Set α
f : α → β
s t : Set α
⊢ f '' s ⊆ f '' (t ∪ s)
|
/-
Copyright (c) 2014 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Leonardo de Moura
-/
import Mathlib.Data.Set.Basic
#align_import data.set.image from "leanprover-community/mathlib"@"001ffdc42920050657fd45bd2b8bfbec8eaaeb29"
/-!
# Images and preimages of sets
## Main definitions
* `preimage f t : Set α` : the preimage f⁻¹(t) (written `f ⁻¹' t` in Lean) of a subset of β.
* `range f : Set β` : the image of `univ` under `f`.
Also works for `{p : Prop} (f : p → α)` (unlike `image`)
## Notation
* `f ⁻¹' t` for `Set.preimage f t`
* `f '' s` for `Set.image f s`
## Tags
set, sets, image, preimage, pre-image, range
-/
set_option autoImplicit true
universe u v
open Function Set
namespace Set
variable {α β γ : Type*} {ι ι' : Sort*}
/-! ### Inverse image -/
/-- The preimage of `s : Set β` by `f : α → β`, written `f ⁻¹' s`,
is the set of `x : α` such that `f x ∈ s`. -/
def preimage {α : Type u} {β : Type v} (f : α → β) (s : Set β) : Set α :=
{ x | f x ∈ s }
#align set.preimage Set.preimage
/-- `f ⁻¹' t` denotes the preimage of `t : Set β` under the function `f : α → β`. -/
infixl:80 " ⁻¹' " => preimage
section Preimage
variable {f : α → β} {g : β → γ}
@[simp]
theorem preimage_empty : f ⁻¹' ∅ = ∅ :=
rfl
#align set.preimage_empty Set.preimage_empty
@[simp, mfld_simps]
theorem mem_preimage {s : Set β} {a : α} : a ∈ f ⁻¹' s ↔ f a ∈ s :=
Iff.rfl
#align set.mem_preimage Set.mem_preimage
theorem preimage_congr {f g : α → β} {s : Set β} (h : ∀ x : α, f x = g x) : f ⁻¹' s = g ⁻¹' s := by
congr with x
simp [h]
#align set.preimage_congr Set.preimage_congr
@[gcongr]
theorem preimage_mono {s t : Set β} (h : s ⊆ t) : f ⁻¹' s ⊆ f ⁻¹' t := fun _ hx => h hx
#align set.preimage_mono Set.preimage_mono
@[simp, mfld_simps]
theorem preimage_univ : f ⁻¹' univ = univ :=
rfl
#align set.preimage_univ Set.preimage_univ
theorem subset_preimage_univ {s : Set α} : s ⊆ f ⁻¹' univ :=
subset_univ _
#align set.subset_preimage_univ Set.subset_preimage_univ
@[simp, mfld_simps]
theorem preimage_inter {s t : Set β} : f ⁻¹' (s ∩ t) = f ⁻¹' s ∩ f ⁻¹' t :=
rfl
#align set.preimage_inter Set.preimage_inter
@[simp]
theorem preimage_union {s t : Set β} : f ⁻¹' (s ∪ t) = f ⁻¹' s ∪ f ⁻¹' t :=
rfl
#align set.preimage_union Set.preimage_union
@[simp]
theorem preimage_compl {s : Set β} : f ⁻¹' sᶜ = (f ⁻¹' s)ᶜ :=
rfl
#align set.preimage_compl Set.preimage_compl
@[simp]
theorem preimage_diff (f : α → β) (s t : Set β) : f ⁻¹' (s \ t) = f ⁻¹' s \ f ⁻¹' t :=
rfl
#align set.preimage_diff Set.preimage_diff
@[simp]
lemma preimage_symmDiff {f : α → β} (s t : Set β) : f ⁻¹' (s ∆ t) = (f ⁻¹' s) ∆ (f ⁻¹' t) :=
rfl
#align set.preimage_symm_diff Set.preimage_symmDiff
@[simp]
theorem preimage_ite (f : α → β) (s t₁ t₂ : Set β) :
f ⁻¹' s.ite t₁ t₂ = (f ⁻¹' s).ite (f ⁻¹' t₁) (f ⁻¹' t₂) :=
rfl
#align set.preimage_ite Set.preimage_ite
@[simp]
theorem preimage_setOf_eq {p : α → Prop} {f : β → α} : f ⁻¹' { a | p a } = { a | p (f a) } :=
rfl
#align set.preimage_set_of_eq Set.preimage_setOf_eq
@[simp]
theorem preimage_id_eq : preimage (id : α → α) = id :=
rfl
#align set.preimage_id_eq Set.preimage_id_eq
@[mfld_simps]
theorem preimage_id {s : Set α} : id ⁻¹' s = s :=
rfl
#align set.preimage_id Set.preimage_id
@[simp, mfld_simps]
theorem preimage_id' {s : Set α} : (fun x => x) ⁻¹' s = s :=
rfl
#align set.preimage_id' Set.preimage_id'
@[simp]
theorem preimage_const_of_mem {b : β} {s : Set β} (h : b ∈ s) : (fun _ : α => b) ⁻¹' s = univ :=
eq_univ_of_forall fun _ => h
#align set.preimage_const_of_mem Set.preimage_const_of_mem
@[simp]
theorem preimage_const_of_not_mem {b : β} {s : Set β} (h : b ∉ s) : (fun _ : α => b) ⁻¹' s = ∅ :=
eq_empty_of_subset_empty fun _ hx => h hx
#align set.preimage_const_of_not_mem Set.preimage_const_of_not_mem
theorem preimage_const (b : β) (s : Set β) [Decidable (b ∈ s)] :
(fun _ : α => b) ⁻¹' s = if b ∈ s then univ else ∅ := by
split_ifs with hb
exacts [preimage_const_of_mem hb, preimage_const_of_not_mem hb]
#align set.preimage_const Set.preimage_const
/-- If preimage of each singleton under `f : α → β` is either empty or the whole type,
then `f` is a constant. -/
lemma exists_eq_const_of_preimage_singleton [Nonempty β] {f : α → β}
(hf : ∀ b : β, f ⁻¹' {b} = ∅ ∨ f ⁻¹' {b} = univ) : ∃ b, f = const α b := by
rcases em (∃ b, f ⁻¹' {b} = univ) with ⟨b, hb⟩ | hf'
· exact ⟨b, funext fun x ↦ eq_univ_iff_forall.1 hb x⟩
· have : ∀ x b, f x ≠ b := fun x b ↦
eq_empty_iff_forall_not_mem.1 ((hf b).resolve_right fun h ↦ hf' ⟨b, h⟩) x
exact ⟨Classical.arbitrary β, funext fun x ↦ absurd rfl (this x _)⟩
theorem preimage_comp {s : Set γ} : g ∘ f ⁻¹' s = f ⁻¹' (g ⁻¹' s) :=
rfl
#align set.preimage_comp Set.preimage_comp
theorem preimage_comp_eq : preimage (g ∘ f) = preimage f ∘ preimage g :=
rfl
#align set.preimage_comp_eq Set.preimage_comp_eq
theorem preimage_iterate_eq {f : α → α} {n : ℕ} : Set.preimage f^[n] = (Set.preimage f)^[n] := by
induction' n with n ih; · simp
rw [iterate_succ, iterate_succ', preimage_comp_eq, ih]
#align set.preimage_iterate_eq Set.preimage_iterate_eq
theorem preimage_preimage {g : β → γ} {f : α → β} {s : Set γ} :
f ⁻¹' (g ⁻¹' s) = (fun x => g (f x)) ⁻¹' s :=
preimage_comp.symm
#align set.preimage_preimage Set.preimage_preimage
theorem eq_preimage_subtype_val_iff {p : α → Prop} {s : Set (Subtype p)} {t : Set α} :
s = Subtype.val ⁻¹' t ↔ ∀ (x) (h : p x), (⟨x, h⟩ : Subtype p) ∈ s ↔ x ∈ t :=
⟨fun s_eq x h => by
rw [s_eq]
simp, fun h => ext fun ⟨x, hx⟩ => by simp [h]⟩
#align set.eq_preimage_subtype_val_iff Set.eq_preimage_subtype_val_iff
theorem nonempty_of_nonempty_preimage {s : Set β} {f : α → β} (hf : (f ⁻¹' s).Nonempty) :
s.Nonempty :=
let ⟨x, hx⟩ := hf
⟨f x, hx⟩
#align set.nonempty_of_nonempty_preimage Set.nonempty_of_nonempty_preimage
@[simp] theorem preimage_singleton_true (p : α → Prop) : p ⁻¹' {True} = {a | p a} := by ext; simp
#align set.preimage_singleton_true Set.preimage_singleton_true
@[simp] theorem preimage_singleton_false (p : α → Prop) : p ⁻¹' {False} = {a | ¬p a} := by ext; simp
#align set.preimage_singleton_false Set.preimage_singleton_false
theorem preimage_subtype_coe_eq_compl {s u v : Set α} (hsuv : s ⊆ u ∪ v)
(H : s ∩ (u ∩ v) = ∅) : ((↑) : s → α) ⁻¹' u = ((↑) ⁻¹' v)ᶜ := by
ext ⟨x, x_in_s⟩
constructor
· intro x_in_u x_in_v
exact eq_empty_iff_forall_not_mem.mp H x ⟨x_in_s, ⟨x_in_u, x_in_v⟩⟩
· intro hx
exact Or.elim (hsuv x_in_s) id fun hx' => hx.elim hx'
#align set.preimage_subtype_coe_eq_compl Set.preimage_subtype_coe_eq_compl
end Preimage
/-! ### Image of a set under a function -/
section Image
variable {f : α → β} {s t : Set α}
-- Porting note: `Set.image` is already defined in `Init.Set`
#align set.image Set.image
/-- `f '' s` denotes the image of `s : Set α` under the function `f : α → β`. -/
infixl:80 " '' " => image
theorem mem_image_iff_bex {f : α → β} {s : Set α} {y : β} :
y ∈ f '' s ↔ ∃ (x : _) (_ : x ∈ s), f x = y :=
bex_def.symm
#align set.mem_image_iff_bex Set.mem_image_iff_bex
@[simp]
theorem mem_image (f : α → β) (s : Set α) (y : β) : y ∈ f '' s ↔ ∃ x ∈ s, f x = y :=
Iff.rfl
#align set.mem_image Set.mem_image
theorem image_eta (f : α → β) : f '' s = (fun x => f x) '' s :=
rfl
#align set.image_eta Set.image_eta
@[mfld_simps]
theorem mem_image_of_mem (f : α → β) {x : α} {a : Set α} (h : x ∈ a) : f x ∈ f '' a :=
⟨_, h, rfl⟩
#align set.mem_image_of_mem Set.mem_image_of_mem
theorem _root_.Function.Injective.mem_set_image {f : α → β} (hf : Injective f) {s : Set α} {a : α} :
f a ∈ f '' s ↔ a ∈ s :=
⟨fun ⟨_, hb, Eq⟩ => hf Eq ▸ hb, mem_image_of_mem f⟩
#align function.injective.mem_set_image Function.Injective.mem_set_image
theorem ball_image_iff {f : α → β} {s : Set α} {p : β → Prop} :
(∀ y ∈ f '' s, p y) ↔ ∀ x ∈ s, p (f x) := by simp
#align set.ball_image_iff Set.ball_image_iff
theorem ball_image_of_ball {f : α → β} {s : Set α} {p : β → Prop} (h : ∀ x ∈ s, p (f x)) :
∀ y ∈ f '' s, p y :=
ball_image_iff.2 h
#align set.ball_image_of_ball Set.ball_image_of_ball
theorem bex_image_iff {f : α → β} {s : Set α} {p : β → Prop} :
(∃ y ∈ f '' s, p y) ↔ ∃ x ∈ s, p (f x) := by simp
#align set.bex_image_iff Set.bex_image_iff
theorem mem_image_elim {f : α → β} {s : Set α} {C : β → Prop} (h : ∀ x : α, x ∈ s → C (f x)) :
∀ {y : β}, y ∈ f '' s → C y
| _, ⟨a, a_in, rfl⟩ => h a a_in
#align set.mem_image_elim Set.mem_image_elim
theorem mem_image_elim_on {f : α → β} {s : Set α} {C : β → Prop} {y : β} (h_y : y ∈ f '' s)
(h : ∀ x : α, x ∈ s → C (f x)) : C y :=
mem_image_elim h h_y
#align set.mem_image_elim_on Set.mem_image_elim_on
-- Porting note: used to be `safe`
@[congr]
theorem image_congr {f g : α → β} {s : Set α} (h : ∀ a ∈ s, f a = g a) : f '' s = g '' s := by
ext x
rw [mem_image, mem_image]
exact {
mp := by
rintro ⟨a, ha1, ha2⟩
exact ⟨a, ⟨ha1, (h a ha1) ▸ ha2⟩⟩,
mpr := by
rintro ⟨a, ha1, ha2⟩
exact ⟨a, ⟨ha1, (h a ha1) ▸ ha2⟩⟩
}
-- safe [ext_iff, iff_def]
#align set.image_congr Set.image_congr
/-- A common special case of `image_congr` -/
theorem image_congr' {f g : α → β} {s : Set α} (h : ∀ x : α, f x = g x) : f '' s = g '' s :=
image_congr fun x _ => h x
#align set.image_congr' Set.image_congr'
@[gcongr]
lemma image_mono (h : s ⊆ t) : f '' s ⊆ f '' t := by
rintro - ⟨a, ha, rfl⟩; exact mem_image_of_mem f (h ha)
theorem image_comp (f : β → γ) (g : α → β) (a : Set α) : f ∘ g '' a = f '' (g '' a) :=
Subset.antisymm (ball_image_of_ball fun _ ha => mem_image_of_mem _ <| mem_image_of_mem _ ha)
(ball_image_of_ball <| ball_image_of_ball fun _ ha => mem_image_of_mem _ ha)
#align set.image_comp Set.image_comp
theorem image_comp_eq {g : β → γ} : image (g ∘ f) = image g ∘ image f := by ext; simp
/-- A variant of `image_comp`, useful for rewriting -/
theorem image_image (g : β → γ) (f : α → β) (s : Set α) : g '' (f '' s) = (fun x => g (f x)) '' s :=
(image_comp g f s).symm
#align set.image_image Set.image_image
theorem image_comm {β'} {f : β → γ} {g : α → β} {f' : α → β'} {g' : β' → γ}
(h_comm : ∀ a, f (g a) = g' (f' a)) : (s.image g).image f = (s.image f').image g' := by
simp_rw [image_image, h_comm]
#align set.image_comm Set.image_comm
theorem _root_.Function.Semiconj.set_image {f : α → β} {ga : α → α} {gb : β → β}
(h : Function.Semiconj f ga gb) : Function.Semiconj (image f) (image ga) (image gb) := fun _ =>
image_comm h
#align function.semiconj.set_image Function.Semiconj.set_image
theorem _root_.Function.Commute.set_image {f g : α → α} (h : Function.Commute f g) :
Function.Commute (image f) (image g) :=
Function.Semiconj.set_image h
#align function.commute.set_image Function.Commute.set_image
/-- Image is monotone with respect to `⊆`. See `Set.monotone_image` for the statement in
terms of `≤`. -/
@[gcongr]
theorem image_subset {a b : Set α} (f : α → β) (h : a ⊆ b) : f '' a ⊆ f '' b := by
simp only [subset_def, mem_image]
exact fun x => fun ⟨w, h1, h2⟩ => ⟨w, h h1, h2⟩
#align set.image_subset Set.image_subset
/-- `Set.image` is monotone. See `Set.image_subset` for the statement in terms of `⊆`. -/
lemma monotone_image {f : α → β} : Monotone (image f) := fun _ _ => image_subset _
#align set.monotone_image Set.monotone_image
theorem image_union (f : α → β) (s t : Set α) : f '' (s ∪ t) = f '' s ∪ f '' t :=
ext fun x =>
⟨by rintro ⟨a, h | h, rfl⟩ <;> [left; right] <;> exact ⟨_, h, rfl⟩, by
rintro (⟨a, h, rfl⟩ | ⟨a, h, rfl⟩) <;> refine' ⟨_, _, rfl⟩ <;> [left; right] <;> exact h⟩
#align set.image_union Set.image_union
@[simp]
theorem image_empty (f : α → β) : f '' ∅ = ∅ := by
ext
simp
#align set.image_empty Set.image_empty
theorem image_inter_subset (f : α → β) (s t : Set α) : f '' (s ∩ t) ⊆ f '' s ∩ f '' t :=
subset_inter (image_subset _ <| inter_subset_left _ _) (image_subset _ <| inter_subset_right _ _)
#align set.image_inter_subset Set.image_inter_subset
theorem image_inter_on {f : α → β} {s t : Set α} (h : ∀ x ∈ t, ∀ y ∈ s, f x = f y → x = y) :
f '' (s ∩ t) = f '' s ∩ f '' t :=
(image_inter_subset _ _ _).antisymm
fun b ⟨⟨a₁, ha₁, h₁⟩, ⟨a₂, ha₂, h₂⟩⟩ ↦
have : a₂ = a₁ := h _ ha₂ _ ha₁ (by simp [*])
⟨a₁, ⟨ha₁, this ▸ ha₂⟩, h₁⟩
#align set.image_inter_on Set.image_inter_on
theorem image_inter {f : α → β} {s t : Set α} (H : Injective f) : f '' (s ∩ t) = f '' s ∩ f '' t :=
image_inter_on fun _ _ _ _ h => H h
#align set.image_inter Set.image_inter
theorem image_univ_of_surjective {ι : Type*} {f : ι → β} (H : Surjective f) : f '' univ = univ :=
eq_univ_of_forall <| by simpa [image]
#align set.image_univ_of_surjective Set.image_univ_of_surjective
@[simp]
theorem image_singleton {f : α → β} {a : α} : f '' {a} = {f a} := by
ext
simp [image, eq_comm]
#align set.image_singleton Set.image_singleton
@[simp]
theorem Nonempty.image_const {s : Set α} (hs : s.Nonempty) (a : β) : (fun _ => a) '' s = {a} :=
ext fun _ =>
⟨fun ⟨_, _, h⟩ => h ▸ mem_singleton _, fun h =>
(eq_of_mem_singleton h).symm ▸ hs.imp fun _ hy => ⟨hy, rfl⟩⟩
#align set.nonempty.image_const Set.Nonempty.image_const
@[simp, mfld_simps]
theorem image_eq_empty {α β} {f : α → β} {s : Set α} : f '' s = ∅ ↔ s = ∅ := by
simp only [eq_empty_iff_forall_not_mem]
exact ⟨fun H a ha => H _ ⟨_, ha, rfl⟩, fun H b ⟨_, ha, _⟩ => H _ ha⟩
#align set.image_eq_empty Set.image_eq_empty
-- Porting note: `compl` is already defined in `Init.Set`
theorem preimage_compl_eq_image_compl [BooleanAlgebra α] (S : Set α) :
HasCompl.compl ⁻¹' S = HasCompl.compl '' S :=
Set.ext fun x =>
⟨fun h => ⟨xᶜ, h, compl_compl x⟩, fun h =>
Exists.elim h fun _ hy => (compl_eq_comm.mp hy.2).symm.subst hy.1⟩
#align set.preimage_compl_eq_image_compl Set.preimage_compl_eq_image_compl
theorem mem_compl_image [BooleanAlgebra α] (t : α) (S : Set α) :
t ∈ HasCompl.compl '' S ↔ tᶜ ∈ S := by
simp [← preimage_compl_eq_image_compl]
#align set.mem_compl_image Set.mem_compl_image
@[simp]
theorem image_id_eq : image (id : α → α) = id := by ext; simp
/-- A variant of `image_id` -/
@[simp]
theorem image_id' (s : Set α) : (fun x => x) '' s = s := by
ext
simp
#align set.image_id' Set.image_id'
theorem image_id (s : Set α) : id '' s = s := by simp
#align set.image_id Set.image_id
lemma image_iterate_eq {f : α → α} {n : ℕ} : image (f^[n]) = (image f)^[n] := by
induction' n with n ih; · simp
rw [iterate_succ', iterate_succ',← ih, image_comp_eq]
theorem compl_compl_image [BooleanAlgebra α] (S : Set α) :
HasCompl.compl '' (HasCompl.compl '' S) = S := by
rw [← image_comp, compl_comp_compl, image_id]
#align set.compl_compl_image Set.compl_compl_image
theorem image_insert_eq {f : α → β} {a : α} {s : Set α} :
f '' insert a s = insert (f a) (f '' s) := by
ext
simp [and_or_left, exists_or, eq_comm, or_comm, and_comm]
#align set.image_insert_eq Set.image_insert_eq
theorem image_pair (f : α → β) (a b : α) : f '' {a, b} = {f a, f b} := by
simp only [image_insert_eq, image_singleton]
#align set.image_pair Set.image_pair
theorem image_subset_preimage_of_inverse {f : α → β} {g : β → α} (I : LeftInverse g f) (s : Set α) :
f '' s ⊆ g ⁻¹' s := fun _ ⟨a, h, e⟩ => e ▸ ((I a).symm ▸ h : g (f a) ∈ s)
#align set.image_subset_preimage_of_inverse Set.image_subset_preimage_of_inverse
theorem preimage_subset_image_of_inverse {f : α → β} {g : β → α} (I : LeftInverse g f) (s : Set β) :
f ⁻¹' s ⊆ g '' s := fun b h => ⟨f b, h, I b⟩
#align set.preimage_subset_image_of_inverse Set.preimage_subset_image_of_inverse
theorem image_eq_preimage_of_inverse {f : α → β} {g : β → α} (h₁ : LeftInverse g f)
(h₂ : RightInverse g f) : image f = preimage g :=
funext fun s =>
Subset.antisymm (image_subset_preimage_of_inverse h₁ s) (preimage_subset_image_of_inverse h₂ s)
#align set.image_eq_preimage_of_inverse Set.image_eq_preimage_of_inverse
theorem mem_image_iff_of_inverse {f : α → β} {g : β → α} {b : β} {s : Set α} (h₁ : LeftInverse g f)
(h₂ : RightInverse g f) : b ∈ f '' s ↔ g b ∈ s := by
rw [image_eq_preimage_of_inverse h₁ h₂]; rfl
#align set.mem_image_iff_of_inverse Set.mem_image_iff_of_inverse
theorem image_compl_subset {f : α → β} {s : Set α} (H : Injective f) : f '' sᶜ ⊆ (f '' s)ᶜ :=
Disjoint.subset_compl_left <| by simp [disjoint_iff_inf_le, ← image_inter H]
#align set.image_compl_subset Set.image_compl_subset
theorem subset_image_compl {f : α → β} {s : Set α} (H : Surjective f) : (f '' s)ᶜ ⊆ f '' sᶜ :=
compl_subset_iff_union.2 <| by
rw [← image_union]
simp [image_univ_of_surjective H]
#align set.subset_image_compl Set.subset_image_compl
theorem image_compl_eq {f : α → β} {s : Set α} (H : Bijective f) : f '' sᶜ = (f '' s)ᶜ :=
Subset.antisymm (image_compl_subset H.1) (subset_image_compl H.2)
#align set.image_compl_eq Set.image_compl_eq
theorem subset_image_diff (f : α → β) (s t : Set α) : f '' s \ f '' t ⊆ f '' (s \ t) := by
rw [diff_subset_iff, ← image_union, union_diff_self]
|
exact image_subset f (subset_union_right t s)
|
theorem subset_image_diff (f : α → β) (s t : Set α) : f '' s \ f '' t ⊆ f '' (s \ t) := by
rw [diff_subset_iff, ← image_union, union_diff_self]
|
Mathlib.Data.Set.Image.465_0.IJFiTzmYGOCpPSd
|
theorem subset_image_diff (f : α → β) (s t : Set α) : f '' s \ f '' t ⊆ f '' (s \ t)
|
Mathlib_Data_Set_Image
|
α : Type u_1
β : Type u_2
γ : Type u_3
ι : Sort u_4
ι' : Sort u_5
f : α → β
s✝ t✝ : Set α
hf : Injective f
s t : Set α
⊢ f '' s ∆ t = (f '' s) ∆ (f '' t)
|
/-
Copyright (c) 2014 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Leonardo de Moura
-/
import Mathlib.Data.Set.Basic
#align_import data.set.image from "leanprover-community/mathlib"@"001ffdc42920050657fd45bd2b8bfbec8eaaeb29"
/-!
# Images and preimages of sets
## Main definitions
* `preimage f t : Set α` : the preimage f⁻¹(t) (written `f ⁻¹' t` in Lean) of a subset of β.
* `range f : Set β` : the image of `univ` under `f`.
Also works for `{p : Prop} (f : p → α)` (unlike `image`)
## Notation
* `f ⁻¹' t` for `Set.preimage f t`
* `f '' s` for `Set.image f s`
## Tags
set, sets, image, preimage, pre-image, range
-/
set_option autoImplicit true
universe u v
open Function Set
namespace Set
variable {α β γ : Type*} {ι ι' : Sort*}
/-! ### Inverse image -/
/-- The preimage of `s : Set β` by `f : α → β`, written `f ⁻¹' s`,
is the set of `x : α` such that `f x ∈ s`. -/
def preimage {α : Type u} {β : Type v} (f : α → β) (s : Set β) : Set α :=
{ x | f x ∈ s }
#align set.preimage Set.preimage
/-- `f ⁻¹' t` denotes the preimage of `t : Set β` under the function `f : α → β`. -/
infixl:80 " ⁻¹' " => preimage
section Preimage
variable {f : α → β} {g : β → γ}
@[simp]
theorem preimage_empty : f ⁻¹' ∅ = ∅ :=
rfl
#align set.preimage_empty Set.preimage_empty
@[simp, mfld_simps]
theorem mem_preimage {s : Set β} {a : α} : a ∈ f ⁻¹' s ↔ f a ∈ s :=
Iff.rfl
#align set.mem_preimage Set.mem_preimage
theorem preimage_congr {f g : α → β} {s : Set β} (h : ∀ x : α, f x = g x) : f ⁻¹' s = g ⁻¹' s := by
congr with x
simp [h]
#align set.preimage_congr Set.preimage_congr
@[gcongr]
theorem preimage_mono {s t : Set β} (h : s ⊆ t) : f ⁻¹' s ⊆ f ⁻¹' t := fun _ hx => h hx
#align set.preimage_mono Set.preimage_mono
@[simp, mfld_simps]
theorem preimage_univ : f ⁻¹' univ = univ :=
rfl
#align set.preimage_univ Set.preimage_univ
theorem subset_preimage_univ {s : Set α} : s ⊆ f ⁻¹' univ :=
subset_univ _
#align set.subset_preimage_univ Set.subset_preimage_univ
@[simp, mfld_simps]
theorem preimage_inter {s t : Set β} : f ⁻¹' (s ∩ t) = f ⁻¹' s ∩ f ⁻¹' t :=
rfl
#align set.preimage_inter Set.preimage_inter
@[simp]
theorem preimage_union {s t : Set β} : f ⁻¹' (s ∪ t) = f ⁻¹' s ∪ f ⁻¹' t :=
rfl
#align set.preimage_union Set.preimage_union
@[simp]
theorem preimage_compl {s : Set β} : f ⁻¹' sᶜ = (f ⁻¹' s)ᶜ :=
rfl
#align set.preimage_compl Set.preimage_compl
@[simp]
theorem preimage_diff (f : α → β) (s t : Set β) : f ⁻¹' (s \ t) = f ⁻¹' s \ f ⁻¹' t :=
rfl
#align set.preimage_diff Set.preimage_diff
@[simp]
lemma preimage_symmDiff {f : α → β} (s t : Set β) : f ⁻¹' (s ∆ t) = (f ⁻¹' s) ∆ (f ⁻¹' t) :=
rfl
#align set.preimage_symm_diff Set.preimage_symmDiff
@[simp]
theorem preimage_ite (f : α → β) (s t₁ t₂ : Set β) :
f ⁻¹' s.ite t₁ t₂ = (f ⁻¹' s).ite (f ⁻¹' t₁) (f ⁻¹' t₂) :=
rfl
#align set.preimage_ite Set.preimage_ite
@[simp]
theorem preimage_setOf_eq {p : α → Prop} {f : β → α} : f ⁻¹' { a | p a } = { a | p (f a) } :=
rfl
#align set.preimage_set_of_eq Set.preimage_setOf_eq
@[simp]
theorem preimage_id_eq : preimage (id : α → α) = id :=
rfl
#align set.preimage_id_eq Set.preimage_id_eq
@[mfld_simps]
theorem preimage_id {s : Set α} : id ⁻¹' s = s :=
rfl
#align set.preimage_id Set.preimage_id
@[simp, mfld_simps]
theorem preimage_id' {s : Set α} : (fun x => x) ⁻¹' s = s :=
rfl
#align set.preimage_id' Set.preimage_id'
@[simp]
theorem preimage_const_of_mem {b : β} {s : Set β} (h : b ∈ s) : (fun _ : α => b) ⁻¹' s = univ :=
eq_univ_of_forall fun _ => h
#align set.preimage_const_of_mem Set.preimage_const_of_mem
@[simp]
theorem preimage_const_of_not_mem {b : β} {s : Set β} (h : b ∉ s) : (fun _ : α => b) ⁻¹' s = ∅ :=
eq_empty_of_subset_empty fun _ hx => h hx
#align set.preimage_const_of_not_mem Set.preimage_const_of_not_mem
theorem preimage_const (b : β) (s : Set β) [Decidable (b ∈ s)] :
(fun _ : α => b) ⁻¹' s = if b ∈ s then univ else ∅ := by
split_ifs with hb
exacts [preimage_const_of_mem hb, preimage_const_of_not_mem hb]
#align set.preimage_const Set.preimage_const
/-- If preimage of each singleton under `f : α → β` is either empty or the whole type,
then `f` is a constant. -/
lemma exists_eq_const_of_preimage_singleton [Nonempty β] {f : α → β}
(hf : ∀ b : β, f ⁻¹' {b} = ∅ ∨ f ⁻¹' {b} = univ) : ∃ b, f = const α b := by
rcases em (∃ b, f ⁻¹' {b} = univ) with ⟨b, hb⟩ | hf'
· exact ⟨b, funext fun x ↦ eq_univ_iff_forall.1 hb x⟩
· have : ∀ x b, f x ≠ b := fun x b ↦
eq_empty_iff_forall_not_mem.1 ((hf b).resolve_right fun h ↦ hf' ⟨b, h⟩) x
exact ⟨Classical.arbitrary β, funext fun x ↦ absurd rfl (this x _)⟩
theorem preimage_comp {s : Set γ} : g ∘ f ⁻¹' s = f ⁻¹' (g ⁻¹' s) :=
rfl
#align set.preimage_comp Set.preimage_comp
theorem preimage_comp_eq : preimage (g ∘ f) = preimage f ∘ preimage g :=
rfl
#align set.preimage_comp_eq Set.preimage_comp_eq
theorem preimage_iterate_eq {f : α → α} {n : ℕ} : Set.preimage f^[n] = (Set.preimage f)^[n] := by
induction' n with n ih; · simp
rw [iterate_succ, iterate_succ', preimage_comp_eq, ih]
#align set.preimage_iterate_eq Set.preimage_iterate_eq
theorem preimage_preimage {g : β → γ} {f : α → β} {s : Set γ} :
f ⁻¹' (g ⁻¹' s) = (fun x => g (f x)) ⁻¹' s :=
preimage_comp.symm
#align set.preimage_preimage Set.preimage_preimage
theorem eq_preimage_subtype_val_iff {p : α → Prop} {s : Set (Subtype p)} {t : Set α} :
s = Subtype.val ⁻¹' t ↔ ∀ (x) (h : p x), (⟨x, h⟩ : Subtype p) ∈ s ↔ x ∈ t :=
⟨fun s_eq x h => by
rw [s_eq]
simp, fun h => ext fun ⟨x, hx⟩ => by simp [h]⟩
#align set.eq_preimage_subtype_val_iff Set.eq_preimage_subtype_val_iff
theorem nonempty_of_nonempty_preimage {s : Set β} {f : α → β} (hf : (f ⁻¹' s).Nonempty) :
s.Nonempty :=
let ⟨x, hx⟩ := hf
⟨f x, hx⟩
#align set.nonempty_of_nonempty_preimage Set.nonempty_of_nonempty_preimage
@[simp] theorem preimage_singleton_true (p : α → Prop) : p ⁻¹' {True} = {a | p a} := by ext; simp
#align set.preimage_singleton_true Set.preimage_singleton_true
@[simp] theorem preimage_singleton_false (p : α → Prop) : p ⁻¹' {False} = {a | ¬p a} := by ext; simp
#align set.preimage_singleton_false Set.preimage_singleton_false
theorem preimage_subtype_coe_eq_compl {s u v : Set α} (hsuv : s ⊆ u ∪ v)
(H : s ∩ (u ∩ v) = ∅) : ((↑) : s → α) ⁻¹' u = ((↑) ⁻¹' v)ᶜ := by
ext ⟨x, x_in_s⟩
constructor
· intro x_in_u x_in_v
exact eq_empty_iff_forall_not_mem.mp H x ⟨x_in_s, ⟨x_in_u, x_in_v⟩⟩
· intro hx
exact Or.elim (hsuv x_in_s) id fun hx' => hx.elim hx'
#align set.preimage_subtype_coe_eq_compl Set.preimage_subtype_coe_eq_compl
end Preimage
/-! ### Image of a set under a function -/
section Image
variable {f : α → β} {s t : Set α}
-- Porting note: `Set.image` is already defined in `Init.Set`
#align set.image Set.image
/-- `f '' s` denotes the image of `s : Set α` under the function `f : α → β`. -/
infixl:80 " '' " => image
theorem mem_image_iff_bex {f : α → β} {s : Set α} {y : β} :
y ∈ f '' s ↔ ∃ (x : _) (_ : x ∈ s), f x = y :=
bex_def.symm
#align set.mem_image_iff_bex Set.mem_image_iff_bex
@[simp]
theorem mem_image (f : α → β) (s : Set α) (y : β) : y ∈ f '' s ↔ ∃ x ∈ s, f x = y :=
Iff.rfl
#align set.mem_image Set.mem_image
theorem image_eta (f : α → β) : f '' s = (fun x => f x) '' s :=
rfl
#align set.image_eta Set.image_eta
@[mfld_simps]
theorem mem_image_of_mem (f : α → β) {x : α} {a : Set α} (h : x ∈ a) : f x ∈ f '' a :=
⟨_, h, rfl⟩
#align set.mem_image_of_mem Set.mem_image_of_mem
theorem _root_.Function.Injective.mem_set_image {f : α → β} (hf : Injective f) {s : Set α} {a : α} :
f a ∈ f '' s ↔ a ∈ s :=
⟨fun ⟨_, hb, Eq⟩ => hf Eq ▸ hb, mem_image_of_mem f⟩
#align function.injective.mem_set_image Function.Injective.mem_set_image
theorem ball_image_iff {f : α → β} {s : Set α} {p : β → Prop} :
(∀ y ∈ f '' s, p y) ↔ ∀ x ∈ s, p (f x) := by simp
#align set.ball_image_iff Set.ball_image_iff
theorem ball_image_of_ball {f : α → β} {s : Set α} {p : β → Prop} (h : ∀ x ∈ s, p (f x)) :
∀ y ∈ f '' s, p y :=
ball_image_iff.2 h
#align set.ball_image_of_ball Set.ball_image_of_ball
theorem bex_image_iff {f : α → β} {s : Set α} {p : β → Prop} :
(∃ y ∈ f '' s, p y) ↔ ∃ x ∈ s, p (f x) := by simp
#align set.bex_image_iff Set.bex_image_iff
theorem mem_image_elim {f : α → β} {s : Set α} {C : β → Prop} (h : ∀ x : α, x ∈ s → C (f x)) :
∀ {y : β}, y ∈ f '' s → C y
| _, ⟨a, a_in, rfl⟩ => h a a_in
#align set.mem_image_elim Set.mem_image_elim
theorem mem_image_elim_on {f : α → β} {s : Set α} {C : β → Prop} {y : β} (h_y : y ∈ f '' s)
(h : ∀ x : α, x ∈ s → C (f x)) : C y :=
mem_image_elim h h_y
#align set.mem_image_elim_on Set.mem_image_elim_on
-- Porting note: used to be `safe`
@[congr]
theorem image_congr {f g : α → β} {s : Set α} (h : ∀ a ∈ s, f a = g a) : f '' s = g '' s := by
ext x
rw [mem_image, mem_image]
exact {
mp := by
rintro ⟨a, ha1, ha2⟩
exact ⟨a, ⟨ha1, (h a ha1) ▸ ha2⟩⟩,
mpr := by
rintro ⟨a, ha1, ha2⟩
exact ⟨a, ⟨ha1, (h a ha1) ▸ ha2⟩⟩
}
-- safe [ext_iff, iff_def]
#align set.image_congr Set.image_congr
/-- A common special case of `image_congr` -/
theorem image_congr' {f g : α → β} {s : Set α} (h : ∀ x : α, f x = g x) : f '' s = g '' s :=
image_congr fun x _ => h x
#align set.image_congr' Set.image_congr'
@[gcongr]
lemma image_mono (h : s ⊆ t) : f '' s ⊆ f '' t := by
rintro - ⟨a, ha, rfl⟩; exact mem_image_of_mem f (h ha)
theorem image_comp (f : β → γ) (g : α → β) (a : Set α) : f ∘ g '' a = f '' (g '' a) :=
Subset.antisymm (ball_image_of_ball fun _ ha => mem_image_of_mem _ <| mem_image_of_mem _ ha)
(ball_image_of_ball <| ball_image_of_ball fun _ ha => mem_image_of_mem _ ha)
#align set.image_comp Set.image_comp
theorem image_comp_eq {g : β → γ} : image (g ∘ f) = image g ∘ image f := by ext; simp
/-- A variant of `image_comp`, useful for rewriting -/
theorem image_image (g : β → γ) (f : α → β) (s : Set α) : g '' (f '' s) = (fun x => g (f x)) '' s :=
(image_comp g f s).symm
#align set.image_image Set.image_image
theorem image_comm {β'} {f : β → γ} {g : α → β} {f' : α → β'} {g' : β' → γ}
(h_comm : ∀ a, f (g a) = g' (f' a)) : (s.image g).image f = (s.image f').image g' := by
simp_rw [image_image, h_comm]
#align set.image_comm Set.image_comm
theorem _root_.Function.Semiconj.set_image {f : α → β} {ga : α → α} {gb : β → β}
(h : Function.Semiconj f ga gb) : Function.Semiconj (image f) (image ga) (image gb) := fun _ =>
image_comm h
#align function.semiconj.set_image Function.Semiconj.set_image
theorem _root_.Function.Commute.set_image {f g : α → α} (h : Function.Commute f g) :
Function.Commute (image f) (image g) :=
Function.Semiconj.set_image h
#align function.commute.set_image Function.Commute.set_image
/-- Image is monotone with respect to `⊆`. See `Set.monotone_image` for the statement in
terms of `≤`. -/
@[gcongr]
theorem image_subset {a b : Set α} (f : α → β) (h : a ⊆ b) : f '' a ⊆ f '' b := by
simp only [subset_def, mem_image]
exact fun x => fun ⟨w, h1, h2⟩ => ⟨w, h h1, h2⟩
#align set.image_subset Set.image_subset
/-- `Set.image` is monotone. See `Set.image_subset` for the statement in terms of `⊆`. -/
lemma monotone_image {f : α → β} : Monotone (image f) := fun _ _ => image_subset _
#align set.monotone_image Set.monotone_image
theorem image_union (f : α → β) (s t : Set α) : f '' (s ∪ t) = f '' s ∪ f '' t :=
ext fun x =>
⟨by rintro ⟨a, h | h, rfl⟩ <;> [left; right] <;> exact ⟨_, h, rfl⟩, by
rintro (⟨a, h, rfl⟩ | ⟨a, h, rfl⟩) <;> refine' ⟨_, _, rfl⟩ <;> [left; right] <;> exact h⟩
#align set.image_union Set.image_union
@[simp]
theorem image_empty (f : α → β) : f '' ∅ = ∅ := by
ext
simp
#align set.image_empty Set.image_empty
theorem image_inter_subset (f : α → β) (s t : Set α) : f '' (s ∩ t) ⊆ f '' s ∩ f '' t :=
subset_inter (image_subset _ <| inter_subset_left _ _) (image_subset _ <| inter_subset_right _ _)
#align set.image_inter_subset Set.image_inter_subset
theorem image_inter_on {f : α → β} {s t : Set α} (h : ∀ x ∈ t, ∀ y ∈ s, f x = f y → x = y) :
f '' (s ∩ t) = f '' s ∩ f '' t :=
(image_inter_subset _ _ _).antisymm
fun b ⟨⟨a₁, ha₁, h₁⟩, ⟨a₂, ha₂, h₂⟩⟩ ↦
have : a₂ = a₁ := h _ ha₂ _ ha₁ (by simp [*])
⟨a₁, ⟨ha₁, this ▸ ha₂⟩, h₁⟩
#align set.image_inter_on Set.image_inter_on
theorem image_inter {f : α → β} {s t : Set α} (H : Injective f) : f '' (s ∩ t) = f '' s ∩ f '' t :=
image_inter_on fun _ _ _ _ h => H h
#align set.image_inter Set.image_inter
theorem image_univ_of_surjective {ι : Type*} {f : ι → β} (H : Surjective f) : f '' univ = univ :=
eq_univ_of_forall <| by simpa [image]
#align set.image_univ_of_surjective Set.image_univ_of_surjective
@[simp]
theorem image_singleton {f : α → β} {a : α} : f '' {a} = {f a} := by
ext
simp [image, eq_comm]
#align set.image_singleton Set.image_singleton
@[simp]
theorem Nonempty.image_const {s : Set α} (hs : s.Nonempty) (a : β) : (fun _ => a) '' s = {a} :=
ext fun _ =>
⟨fun ⟨_, _, h⟩ => h ▸ mem_singleton _, fun h =>
(eq_of_mem_singleton h).symm ▸ hs.imp fun _ hy => ⟨hy, rfl⟩⟩
#align set.nonempty.image_const Set.Nonempty.image_const
@[simp, mfld_simps]
theorem image_eq_empty {α β} {f : α → β} {s : Set α} : f '' s = ∅ ↔ s = ∅ := by
simp only [eq_empty_iff_forall_not_mem]
exact ⟨fun H a ha => H _ ⟨_, ha, rfl⟩, fun H b ⟨_, ha, _⟩ => H _ ha⟩
#align set.image_eq_empty Set.image_eq_empty
-- Porting note: `compl` is already defined in `Init.Set`
theorem preimage_compl_eq_image_compl [BooleanAlgebra α] (S : Set α) :
HasCompl.compl ⁻¹' S = HasCompl.compl '' S :=
Set.ext fun x =>
⟨fun h => ⟨xᶜ, h, compl_compl x⟩, fun h =>
Exists.elim h fun _ hy => (compl_eq_comm.mp hy.2).symm.subst hy.1⟩
#align set.preimage_compl_eq_image_compl Set.preimage_compl_eq_image_compl
theorem mem_compl_image [BooleanAlgebra α] (t : α) (S : Set α) :
t ∈ HasCompl.compl '' S ↔ tᶜ ∈ S := by
simp [← preimage_compl_eq_image_compl]
#align set.mem_compl_image Set.mem_compl_image
@[simp]
theorem image_id_eq : image (id : α → α) = id := by ext; simp
/-- A variant of `image_id` -/
@[simp]
theorem image_id' (s : Set α) : (fun x => x) '' s = s := by
ext
simp
#align set.image_id' Set.image_id'
theorem image_id (s : Set α) : id '' s = s := by simp
#align set.image_id Set.image_id
lemma image_iterate_eq {f : α → α} {n : ℕ} : image (f^[n]) = (image f)^[n] := by
induction' n with n ih; · simp
rw [iterate_succ', iterate_succ',← ih, image_comp_eq]
theorem compl_compl_image [BooleanAlgebra α] (S : Set α) :
HasCompl.compl '' (HasCompl.compl '' S) = S := by
rw [← image_comp, compl_comp_compl, image_id]
#align set.compl_compl_image Set.compl_compl_image
theorem image_insert_eq {f : α → β} {a : α} {s : Set α} :
f '' insert a s = insert (f a) (f '' s) := by
ext
simp [and_or_left, exists_or, eq_comm, or_comm, and_comm]
#align set.image_insert_eq Set.image_insert_eq
theorem image_pair (f : α → β) (a b : α) : f '' {a, b} = {f a, f b} := by
simp only [image_insert_eq, image_singleton]
#align set.image_pair Set.image_pair
theorem image_subset_preimage_of_inverse {f : α → β} {g : β → α} (I : LeftInverse g f) (s : Set α) :
f '' s ⊆ g ⁻¹' s := fun _ ⟨a, h, e⟩ => e ▸ ((I a).symm ▸ h : g (f a) ∈ s)
#align set.image_subset_preimage_of_inverse Set.image_subset_preimage_of_inverse
theorem preimage_subset_image_of_inverse {f : α → β} {g : β → α} (I : LeftInverse g f) (s : Set β) :
f ⁻¹' s ⊆ g '' s := fun b h => ⟨f b, h, I b⟩
#align set.preimage_subset_image_of_inverse Set.preimage_subset_image_of_inverse
theorem image_eq_preimage_of_inverse {f : α → β} {g : β → α} (h₁ : LeftInverse g f)
(h₂ : RightInverse g f) : image f = preimage g :=
funext fun s =>
Subset.antisymm (image_subset_preimage_of_inverse h₁ s) (preimage_subset_image_of_inverse h₂ s)
#align set.image_eq_preimage_of_inverse Set.image_eq_preimage_of_inverse
theorem mem_image_iff_of_inverse {f : α → β} {g : β → α} {b : β} {s : Set α} (h₁ : LeftInverse g f)
(h₂ : RightInverse g f) : b ∈ f '' s ↔ g b ∈ s := by
rw [image_eq_preimage_of_inverse h₁ h₂]; rfl
#align set.mem_image_iff_of_inverse Set.mem_image_iff_of_inverse
theorem image_compl_subset {f : α → β} {s : Set α} (H : Injective f) : f '' sᶜ ⊆ (f '' s)ᶜ :=
Disjoint.subset_compl_left <| by simp [disjoint_iff_inf_le, ← image_inter H]
#align set.image_compl_subset Set.image_compl_subset
theorem subset_image_compl {f : α → β} {s : Set α} (H : Surjective f) : (f '' s)ᶜ ⊆ f '' sᶜ :=
compl_subset_iff_union.2 <| by
rw [← image_union]
simp [image_univ_of_surjective H]
#align set.subset_image_compl Set.subset_image_compl
theorem image_compl_eq {f : α → β} {s : Set α} (H : Bijective f) : f '' sᶜ = (f '' s)ᶜ :=
Subset.antisymm (image_compl_subset H.1) (subset_image_compl H.2)
#align set.image_compl_eq Set.image_compl_eq
theorem subset_image_diff (f : α → β) (s t : Set α) : f '' s \ f '' t ⊆ f '' (s \ t) := by
rw [diff_subset_iff, ← image_union, union_diff_self]
exact image_subset f (subset_union_right t s)
#align set.subset_image_diff Set.subset_image_diff
theorem subset_image_symmDiff : (f '' s) ∆ (f '' t) ⊆ f '' s ∆ t :=
(union_subset_union (subset_image_diff _ _ _) <| subset_image_diff _ _ _).trans
(superset_of_eq (image_union _ _ _))
#align set.subset_image_symm_diff Set.subset_image_symmDiff
theorem image_diff {f : α → β} (hf : Injective f) (s t : Set α) : f '' (s \ t) = f '' s \ f '' t :=
Subset.antisymm
(Subset.trans (image_inter_subset _ _ _) <| inter_subset_inter_right _ <| image_compl_subset hf)
(subset_image_diff f s t)
#align set.image_diff Set.image_diff
theorem image_symmDiff (hf : Injective f) (s t : Set α) : f '' s ∆ t = (f '' s) ∆ (f '' t) := by
|
simp_rw [Set.symmDiff_def, image_union, image_diff hf]
|
theorem image_symmDiff (hf : Injective f) (s t : Set α) : f '' s ∆ t = (f '' s) ∆ (f '' t) := by
|
Mathlib.Data.Set.Image.481_0.IJFiTzmYGOCpPSd
|
theorem image_symmDiff (hf : Injective f) (s t : Set α) : f '' s ∆ t = (f '' s) ∆ (f '' t)
|
Mathlib_Data_Set_Image
|
α : Type u_1
β : Type u_2
γ : Type u_3
ι : Sort u_4
ι' : Sort u_5
f✝ : α → β
s t : Set α
f : β → α
hf : Surjective f
eq : f ⁻¹' s = f ⁻¹' t
⊢ s = t
|
/-
Copyright (c) 2014 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Leonardo de Moura
-/
import Mathlib.Data.Set.Basic
#align_import data.set.image from "leanprover-community/mathlib"@"001ffdc42920050657fd45bd2b8bfbec8eaaeb29"
/-!
# Images and preimages of sets
## Main definitions
* `preimage f t : Set α` : the preimage f⁻¹(t) (written `f ⁻¹' t` in Lean) of a subset of β.
* `range f : Set β` : the image of `univ` under `f`.
Also works for `{p : Prop} (f : p → α)` (unlike `image`)
## Notation
* `f ⁻¹' t` for `Set.preimage f t`
* `f '' s` for `Set.image f s`
## Tags
set, sets, image, preimage, pre-image, range
-/
set_option autoImplicit true
universe u v
open Function Set
namespace Set
variable {α β γ : Type*} {ι ι' : Sort*}
/-! ### Inverse image -/
/-- The preimage of `s : Set β` by `f : α → β`, written `f ⁻¹' s`,
is the set of `x : α` such that `f x ∈ s`. -/
def preimage {α : Type u} {β : Type v} (f : α → β) (s : Set β) : Set α :=
{ x | f x ∈ s }
#align set.preimage Set.preimage
/-- `f ⁻¹' t` denotes the preimage of `t : Set β` under the function `f : α → β`. -/
infixl:80 " ⁻¹' " => preimage
section Preimage
variable {f : α → β} {g : β → γ}
@[simp]
theorem preimage_empty : f ⁻¹' ∅ = ∅ :=
rfl
#align set.preimage_empty Set.preimage_empty
@[simp, mfld_simps]
theorem mem_preimage {s : Set β} {a : α} : a ∈ f ⁻¹' s ↔ f a ∈ s :=
Iff.rfl
#align set.mem_preimage Set.mem_preimage
theorem preimage_congr {f g : α → β} {s : Set β} (h : ∀ x : α, f x = g x) : f ⁻¹' s = g ⁻¹' s := by
congr with x
simp [h]
#align set.preimage_congr Set.preimage_congr
@[gcongr]
theorem preimage_mono {s t : Set β} (h : s ⊆ t) : f ⁻¹' s ⊆ f ⁻¹' t := fun _ hx => h hx
#align set.preimage_mono Set.preimage_mono
@[simp, mfld_simps]
theorem preimage_univ : f ⁻¹' univ = univ :=
rfl
#align set.preimage_univ Set.preimage_univ
theorem subset_preimage_univ {s : Set α} : s ⊆ f ⁻¹' univ :=
subset_univ _
#align set.subset_preimage_univ Set.subset_preimage_univ
@[simp, mfld_simps]
theorem preimage_inter {s t : Set β} : f ⁻¹' (s ∩ t) = f ⁻¹' s ∩ f ⁻¹' t :=
rfl
#align set.preimage_inter Set.preimage_inter
@[simp]
theorem preimage_union {s t : Set β} : f ⁻¹' (s ∪ t) = f ⁻¹' s ∪ f ⁻¹' t :=
rfl
#align set.preimage_union Set.preimage_union
@[simp]
theorem preimage_compl {s : Set β} : f ⁻¹' sᶜ = (f ⁻¹' s)ᶜ :=
rfl
#align set.preimage_compl Set.preimage_compl
@[simp]
theorem preimage_diff (f : α → β) (s t : Set β) : f ⁻¹' (s \ t) = f ⁻¹' s \ f ⁻¹' t :=
rfl
#align set.preimage_diff Set.preimage_diff
@[simp]
lemma preimage_symmDiff {f : α → β} (s t : Set β) : f ⁻¹' (s ∆ t) = (f ⁻¹' s) ∆ (f ⁻¹' t) :=
rfl
#align set.preimage_symm_diff Set.preimage_symmDiff
@[simp]
theorem preimage_ite (f : α → β) (s t₁ t₂ : Set β) :
f ⁻¹' s.ite t₁ t₂ = (f ⁻¹' s).ite (f ⁻¹' t₁) (f ⁻¹' t₂) :=
rfl
#align set.preimage_ite Set.preimage_ite
@[simp]
theorem preimage_setOf_eq {p : α → Prop} {f : β → α} : f ⁻¹' { a | p a } = { a | p (f a) } :=
rfl
#align set.preimage_set_of_eq Set.preimage_setOf_eq
@[simp]
theorem preimage_id_eq : preimage (id : α → α) = id :=
rfl
#align set.preimage_id_eq Set.preimage_id_eq
@[mfld_simps]
theorem preimage_id {s : Set α} : id ⁻¹' s = s :=
rfl
#align set.preimage_id Set.preimage_id
@[simp, mfld_simps]
theorem preimage_id' {s : Set α} : (fun x => x) ⁻¹' s = s :=
rfl
#align set.preimage_id' Set.preimage_id'
@[simp]
theorem preimage_const_of_mem {b : β} {s : Set β} (h : b ∈ s) : (fun _ : α => b) ⁻¹' s = univ :=
eq_univ_of_forall fun _ => h
#align set.preimage_const_of_mem Set.preimage_const_of_mem
@[simp]
theorem preimage_const_of_not_mem {b : β} {s : Set β} (h : b ∉ s) : (fun _ : α => b) ⁻¹' s = ∅ :=
eq_empty_of_subset_empty fun _ hx => h hx
#align set.preimage_const_of_not_mem Set.preimage_const_of_not_mem
theorem preimage_const (b : β) (s : Set β) [Decidable (b ∈ s)] :
(fun _ : α => b) ⁻¹' s = if b ∈ s then univ else ∅ := by
split_ifs with hb
exacts [preimage_const_of_mem hb, preimage_const_of_not_mem hb]
#align set.preimage_const Set.preimage_const
/-- If preimage of each singleton under `f : α → β` is either empty or the whole type,
then `f` is a constant. -/
lemma exists_eq_const_of_preimage_singleton [Nonempty β] {f : α → β}
(hf : ∀ b : β, f ⁻¹' {b} = ∅ ∨ f ⁻¹' {b} = univ) : ∃ b, f = const α b := by
rcases em (∃ b, f ⁻¹' {b} = univ) with ⟨b, hb⟩ | hf'
· exact ⟨b, funext fun x ↦ eq_univ_iff_forall.1 hb x⟩
· have : ∀ x b, f x ≠ b := fun x b ↦
eq_empty_iff_forall_not_mem.1 ((hf b).resolve_right fun h ↦ hf' ⟨b, h⟩) x
exact ⟨Classical.arbitrary β, funext fun x ↦ absurd rfl (this x _)⟩
theorem preimage_comp {s : Set γ} : g ∘ f ⁻¹' s = f ⁻¹' (g ⁻¹' s) :=
rfl
#align set.preimage_comp Set.preimage_comp
theorem preimage_comp_eq : preimage (g ∘ f) = preimage f ∘ preimage g :=
rfl
#align set.preimage_comp_eq Set.preimage_comp_eq
theorem preimage_iterate_eq {f : α → α} {n : ℕ} : Set.preimage f^[n] = (Set.preimage f)^[n] := by
induction' n with n ih; · simp
rw [iterate_succ, iterate_succ', preimage_comp_eq, ih]
#align set.preimage_iterate_eq Set.preimage_iterate_eq
theorem preimage_preimage {g : β → γ} {f : α → β} {s : Set γ} :
f ⁻¹' (g ⁻¹' s) = (fun x => g (f x)) ⁻¹' s :=
preimage_comp.symm
#align set.preimage_preimage Set.preimage_preimage
theorem eq_preimage_subtype_val_iff {p : α → Prop} {s : Set (Subtype p)} {t : Set α} :
s = Subtype.val ⁻¹' t ↔ ∀ (x) (h : p x), (⟨x, h⟩ : Subtype p) ∈ s ↔ x ∈ t :=
⟨fun s_eq x h => by
rw [s_eq]
simp, fun h => ext fun ⟨x, hx⟩ => by simp [h]⟩
#align set.eq_preimage_subtype_val_iff Set.eq_preimage_subtype_val_iff
theorem nonempty_of_nonempty_preimage {s : Set β} {f : α → β} (hf : (f ⁻¹' s).Nonempty) :
s.Nonempty :=
let ⟨x, hx⟩ := hf
⟨f x, hx⟩
#align set.nonempty_of_nonempty_preimage Set.nonempty_of_nonempty_preimage
@[simp] theorem preimage_singleton_true (p : α → Prop) : p ⁻¹' {True} = {a | p a} := by ext; simp
#align set.preimage_singleton_true Set.preimage_singleton_true
@[simp] theorem preimage_singleton_false (p : α → Prop) : p ⁻¹' {False} = {a | ¬p a} := by ext; simp
#align set.preimage_singleton_false Set.preimage_singleton_false
theorem preimage_subtype_coe_eq_compl {s u v : Set α} (hsuv : s ⊆ u ∪ v)
(H : s ∩ (u ∩ v) = ∅) : ((↑) : s → α) ⁻¹' u = ((↑) ⁻¹' v)ᶜ := by
ext ⟨x, x_in_s⟩
constructor
· intro x_in_u x_in_v
exact eq_empty_iff_forall_not_mem.mp H x ⟨x_in_s, ⟨x_in_u, x_in_v⟩⟩
· intro hx
exact Or.elim (hsuv x_in_s) id fun hx' => hx.elim hx'
#align set.preimage_subtype_coe_eq_compl Set.preimage_subtype_coe_eq_compl
end Preimage
/-! ### Image of a set under a function -/
section Image
variable {f : α → β} {s t : Set α}
-- Porting note: `Set.image` is already defined in `Init.Set`
#align set.image Set.image
/-- `f '' s` denotes the image of `s : Set α` under the function `f : α → β`. -/
infixl:80 " '' " => image
theorem mem_image_iff_bex {f : α → β} {s : Set α} {y : β} :
y ∈ f '' s ↔ ∃ (x : _) (_ : x ∈ s), f x = y :=
bex_def.symm
#align set.mem_image_iff_bex Set.mem_image_iff_bex
@[simp]
theorem mem_image (f : α → β) (s : Set α) (y : β) : y ∈ f '' s ↔ ∃ x ∈ s, f x = y :=
Iff.rfl
#align set.mem_image Set.mem_image
theorem image_eta (f : α → β) : f '' s = (fun x => f x) '' s :=
rfl
#align set.image_eta Set.image_eta
@[mfld_simps]
theorem mem_image_of_mem (f : α → β) {x : α} {a : Set α} (h : x ∈ a) : f x ∈ f '' a :=
⟨_, h, rfl⟩
#align set.mem_image_of_mem Set.mem_image_of_mem
theorem _root_.Function.Injective.mem_set_image {f : α → β} (hf : Injective f) {s : Set α} {a : α} :
f a ∈ f '' s ↔ a ∈ s :=
⟨fun ⟨_, hb, Eq⟩ => hf Eq ▸ hb, mem_image_of_mem f⟩
#align function.injective.mem_set_image Function.Injective.mem_set_image
theorem ball_image_iff {f : α → β} {s : Set α} {p : β → Prop} :
(∀ y ∈ f '' s, p y) ↔ ∀ x ∈ s, p (f x) := by simp
#align set.ball_image_iff Set.ball_image_iff
theorem ball_image_of_ball {f : α → β} {s : Set α} {p : β → Prop} (h : ∀ x ∈ s, p (f x)) :
∀ y ∈ f '' s, p y :=
ball_image_iff.2 h
#align set.ball_image_of_ball Set.ball_image_of_ball
theorem bex_image_iff {f : α → β} {s : Set α} {p : β → Prop} :
(∃ y ∈ f '' s, p y) ↔ ∃ x ∈ s, p (f x) := by simp
#align set.bex_image_iff Set.bex_image_iff
theorem mem_image_elim {f : α → β} {s : Set α} {C : β → Prop} (h : ∀ x : α, x ∈ s → C (f x)) :
∀ {y : β}, y ∈ f '' s → C y
| _, ⟨a, a_in, rfl⟩ => h a a_in
#align set.mem_image_elim Set.mem_image_elim
theorem mem_image_elim_on {f : α → β} {s : Set α} {C : β → Prop} {y : β} (h_y : y ∈ f '' s)
(h : ∀ x : α, x ∈ s → C (f x)) : C y :=
mem_image_elim h h_y
#align set.mem_image_elim_on Set.mem_image_elim_on
-- Porting note: used to be `safe`
@[congr]
theorem image_congr {f g : α → β} {s : Set α} (h : ∀ a ∈ s, f a = g a) : f '' s = g '' s := by
ext x
rw [mem_image, mem_image]
exact {
mp := by
rintro ⟨a, ha1, ha2⟩
exact ⟨a, ⟨ha1, (h a ha1) ▸ ha2⟩⟩,
mpr := by
rintro ⟨a, ha1, ha2⟩
exact ⟨a, ⟨ha1, (h a ha1) ▸ ha2⟩⟩
}
-- safe [ext_iff, iff_def]
#align set.image_congr Set.image_congr
/-- A common special case of `image_congr` -/
theorem image_congr' {f g : α → β} {s : Set α} (h : ∀ x : α, f x = g x) : f '' s = g '' s :=
image_congr fun x _ => h x
#align set.image_congr' Set.image_congr'
@[gcongr]
lemma image_mono (h : s ⊆ t) : f '' s ⊆ f '' t := by
rintro - ⟨a, ha, rfl⟩; exact mem_image_of_mem f (h ha)
theorem image_comp (f : β → γ) (g : α → β) (a : Set α) : f ∘ g '' a = f '' (g '' a) :=
Subset.antisymm (ball_image_of_ball fun _ ha => mem_image_of_mem _ <| mem_image_of_mem _ ha)
(ball_image_of_ball <| ball_image_of_ball fun _ ha => mem_image_of_mem _ ha)
#align set.image_comp Set.image_comp
theorem image_comp_eq {g : β → γ} : image (g ∘ f) = image g ∘ image f := by ext; simp
/-- A variant of `image_comp`, useful for rewriting -/
theorem image_image (g : β → γ) (f : α → β) (s : Set α) : g '' (f '' s) = (fun x => g (f x)) '' s :=
(image_comp g f s).symm
#align set.image_image Set.image_image
theorem image_comm {β'} {f : β → γ} {g : α → β} {f' : α → β'} {g' : β' → γ}
(h_comm : ∀ a, f (g a) = g' (f' a)) : (s.image g).image f = (s.image f').image g' := by
simp_rw [image_image, h_comm]
#align set.image_comm Set.image_comm
theorem _root_.Function.Semiconj.set_image {f : α → β} {ga : α → α} {gb : β → β}
(h : Function.Semiconj f ga gb) : Function.Semiconj (image f) (image ga) (image gb) := fun _ =>
image_comm h
#align function.semiconj.set_image Function.Semiconj.set_image
theorem _root_.Function.Commute.set_image {f g : α → α} (h : Function.Commute f g) :
Function.Commute (image f) (image g) :=
Function.Semiconj.set_image h
#align function.commute.set_image Function.Commute.set_image
/-- Image is monotone with respect to `⊆`. See `Set.monotone_image` for the statement in
terms of `≤`. -/
@[gcongr]
theorem image_subset {a b : Set α} (f : α → β) (h : a ⊆ b) : f '' a ⊆ f '' b := by
simp only [subset_def, mem_image]
exact fun x => fun ⟨w, h1, h2⟩ => ⟨w, h h1, h2⟩
#align set.image_subset Set.image_subset
/-- `Set.image` is monotone. See `Set.image_subset` for the statement in terms of `⊆`. -/
lemma monotone_image {f : α → β} : Monotone (image f) := fun _ _ => image_subset _
#align set.monotone_image Set.monotone_image
theorem image_union (f : α → β) (s t : Set α) : f '' (s ∪ t) = f '' s ∪ f '' t :=
ext fun x =>
⟨by rintro ⟨a, h | h, rfl⟩ <;> [left; right] <;> exact ⟨_, h, rfl⟩, by
rintro (⟨a, h, rfl⟩ | ⟨a, h, rfl⟩) <;> refine' ⟨_, _, rfl⟩ <;> [left; right] <;> exact h⟩
#align set.image_union Set.image_union
@[simp]
theorem image_empty (f : α → β) : f '' ∅ = ∅ := by
ext
simp
#align set.image_empty Set.image_empty
theorem image_inter_subset (f : α → β) (s t : Set α) : f '' (s ∩ t) ⊆ f '' s ∩ f '' t :=
subset_inter (image_subset _ <| inter_subset_left _ _) (image_subset _ <| inter_subset_right _ _)
#align set.image_inter_subset Set.image_inter_subset
theorem image_inter_on {f : α → β} {s t : Set α} (h : ∀ x ∈ t, ∀ y ∈ s, f x = f y → x = y) :
f '' (s ∩ t) = f '' s ∩ f '' t :=
(image_inter_subset _ _ _).antisymm
fun b ⟨⟨a₁, ha₁, h₁⟩, ⟨a₂, ha₂, h₂⟩⟩ ↦
have : a₂ = a₁ := h _ ha₂ _ ha₁ (by simp [*])
⟨a₁, ⟨ha₁, this ▸ ha₂⟩, h₁⟩
#align set.image_inter_on Set.image_inter_on
theorem image_inter {f : α → β} {s t : Set α} (H : Injective f) : f '' (s ∩ t) = f '' s ∩ f '' t :=
image_inter_on fun _ _ _ _ h => H h
#align set.image_inter Set.image_inter
theorem image_univ_of_surjective {ι : Type*} {f : ι → β} (H : Surjective f) : f '' univ = univ :=
eq_univ_of_forall <| by simpa [image]
#align set.image_univ_of_surjective Set.image_univ_of_surjective
@[simp]
theorem image_singleton {f : α → β} {a : α} : f '' {a} = {f a} := by
ext
simp [image, eq_comm]
#align set.image_singleton Set.image_singleton
@[simp]
theorem Nonempty.image_const {s : Set α} (hs : s.Nonempty) (a : β) : (fun _ => a) '' s = {a} :=
ext fun _ =>
⟨fun ⟨_, _, h⟩ => h ▸ mem_singleton _, fun h =>
(eq_of_mem_singleton h).symm ▸ hs.imp fun _ hy => ⟨hy, rfl⟩⟩
#align set.nonempty.image_const Set.Nonempty.image_const
@[simp, mfld_simps]
theorem image_eq_empty {α β} {f : α → β} {s : Set α} : f '' s = ∅ ↔ s = ∅ := by
simp only [eq_empty_iff_forall_not_mem]
exact ⟨fun H a ha => H _ ⟨_, ha, rfl⟩, fun H b ⟨_, ha, _⟩ => H _ ha⟩
#align set.image_eq_empty Set.image_eq_empty
-- Porting note: `compl` is already defined in `Init.Set`
theorem preimage_compl_eq_image_compl [BooleanAlgebra α] (S : Set α) :
HasCompl.compl ⁻¹' S = HasCompl.compl '' S :=
Set.ext fun x =>
⟨fun h => ⟨xᶜ, h, compl_compl x⟩, fun h =>
Exists.elim h fun _ hy => (compl_eq_comm.mp hy.2).symm.subst hy.1⟩
#align set.preimage_compl_eq_image_compl Set.preimage_compl_eq_image_compl
theorem mem_compl_image [BooleanAlgebra α] (t : α) (S : Set α) :
t ∈ HasCompl.compl '' S ↔ tᶜ ∈ S := by
simp [← preimage_compl_eq_image_compl]
#align set.mem_compl_image Set.mem_compl_image
@[simp]
theorem image_id_eq : image (id : α → α) = id := by ext; simp
/-- A variant of `image_id` -/
@[simp]
theorem image_id' (s : Set α) : (fun x => x) '' s = s := by
ext
simp
#align set.image_id' Set.image_id'
theorem image_id (s : Set α) : id '' s = s := by simp
#align set.image_id Set.image_id
lemma image_iterate_eq {f : α → α} {n : ℕ} : image (f^[n]) = (image f)^[n] := by
induction' n with n ih; · simp
rw [iterate_succ', iterate_succ',← ih, image_comp_eq]
theorem compl_compl_image [BooleanAlgebra α] (S : Set α) :
HasCompl.compl '' (HasCompl.compl '' S) = S := by
rw [← image_comp, compl_comp_compl, image_id]
#align set.compl_compl_image Set.compl_compl_image
theorem image_insert_eq {f : α → β} {a : α} {s : Set α} :
f '' insert a s = insert (f a) (f '' s) := by
ext
simp [and_or_left, exists_or, eq_comm, or_comm, and_comm]
#align set.image_insert_eq Set.image_insert_eq
theorem image_pair (f : α → β) (a b : α) : f '' {a, b} = {f a, f b} := by
simp only [image_insert_eq, image_singleton]
#align set.image_pair Set.image_pair
theorem image_subset_preimage_of_inverse {f : α → β} {g : β → α} (I : LeftInverse g f) (s : Set α) :
f '' s ⊆ g ⁻¹' s := fun _ ⟨a, h, e⟩ => e ▸ ((I a).symm ▸ h : g (f a) ∈ s)
#align set.image_subset_preimage_of_inverse Set.image_subset_preimage_of_inverse
theorem preimage_subset_image_of_inverse {f : α → β} {g : β → α} (I : LeftInverse g f) (s : Set β) :
f ⁻¹' s ⊆ g '' s := fun b h => ⟨f b, h, I b⟩
#align set.preimage_subset_image_of_inverse Set.preimage_subset_image_of_inverse
theorem image_eq_preimage_of_inverse {f : α → β} {g : β → α} (h₁ : LeftInverse g f)
(h₂ : RightInverse g f) : image f = preimage g :=
funext fun s =>
Subset.antisymm (image_subset_preimage_of_inverse h₁ s) (preimage_subset_image_of_inverse h₂ s)
#align set.image_eq_preimage_of_inverse Set.image_eq_preimage_of_inverse
theorem mem_image_iff_of_inverse {f : α → β} {g : β → α} {b : β} {s : Set α} (h₁ : LeftInverse g f)
(h₂ : RightInverse g f) : b ∈ f '' s ↔ g b ∈ s := by
rw [image_eq_preimage_of_inverse h₁ h₂]; rfl
#align set.mem_image_iff_of_inverse Set.mem_image_iff_of_inverse
theorem image_compl_subset {f : α → β} {s : Set α} (H : Injective f) : f '' sᶜ ⊆ (f '' s)ᶜ :=
Disjoint.subset_compl_left <| by simp [disjoint_iff_inf_le, ← image_inter H]
#align set.image_compl_subset Set.image_compl_subset
theorem subset_image_compl {f : α → β} {s : Set α} (H : Surjective f) : (f '' s)ᶜ ⊆ f '' sᶜ :=
compl_subset_iff_union.2 <| by
rw [← image_union]
simp [image_univ_of_surjective H]
#align set.subset_image_compl Set.subset_image_compl
theorem image_compl_eq {f : α → β} {s : Set α} (H : Bijective f) : f '' sᶜ = (f '' s)ᶜ :=
Subset.antisymm (image_compl_subset H.1) (subset_image_compl H.2)
#align set.image_compl_eq Set.image_compl_eq
theorem subset_image_diff (f : α → β) (s t : Set α) : f '' s \ f '' t ⊆ f '' (s \ t) := by
rw [diff_subset_iff, ← image_union, union_diff_self]
exact image_subset f (subset_union_right t s)
#align set.subset_image_diff Set.subset_image_diff
theorem subset_image_symmDiff : (f '' s) ∆ (f '' t) ⊆ f '' s ∆ t :=
(union_subset_union (subset_image_diff _ _ _) <| subset_image_diff _ _ _).trans
(superset_of_eq (image_union _ _ _))
#align set.subset_image_symm_diff Set.subset_image_symmDiff
theorem image_diff {f : α → β} (hf : Injective f) (s t : Set α) : f '' (s \ t) = f '' s \ f '' t :=
Subset.antisymm
(Subset.trans (image_inter_subset _ _ _) <| inter_subset_inter_right _ <| image_compl_subset hf)
(subset_image_diff f s t)
#align set.image_diff Set.image_diff
theorem image_symmDiff (hf : Injective f) (s t : Set α) : f '' s ∆ t = (f '' s) ∆ (f '' t) := by
simp_rw [Set.symmDiff_def, image_union, image_diff hf]
#align set.image_symm_diff Set.image_symmDiff
theorem Nonempty.image (f : α → β) {s : Set α} : s.Nonempty → (f '' s).Nonempty
| ⟨x, hx⟩ => ⟨f x, mem_image_of_mem f hx⟩
#align set.nonempty.image Set.Nonempty.image
theorem Nonempty.of_image {f : α → β} {s : Set α} : (f '' s).Nonempty → s.Nonempty
| ⟨_, x, hx, _⟩ => ⟨x, hx⟩
#align set.nonempty.of_image Set.Nonempty.of_image
@[simp]
theorem nonempty_image_iff {f : α → β} {s : Set α} : (f '' s).Nonempty ↔ s.Nonempty :=
⟨Nonempty.of_image, fun h => h.image f⟩
#align set.nonempty_image_iff Set.nonempty_image_iff
theorem Nonempty.preimage {s : Set β} (hs : s.Nonempty) {f : α → β} (hf : Surjective f) :
(f ⁻¹' s).Nonempty :=
let ⟨y, hy⟩ := hs
let ⟨x, hx⟩ := hf y
⟨x, mem_preimage.2 <| hx.symm ▸ hy⟩
#align set.nonempty.preimage Set.Nonempty.preimage
instance (f : α → β) (s : Set α) [Nonempty s] : Nonempty (f '' s) :=
(Set.Nonempty.image f nonempty_of_nonempty_subtype).to_subtype
/-- image and preimage are a Galois connection -/
@[simp]
theorem image_subset_iff {s : Set α} {t : Set β} {f : α → β} : f '' s ⊆ t ↔ s ⊆ f ⁻¹' t :=
ball_image_iff
#align set.image_subset_iff Set.image_subset_iff
theorem image_preimage_subset (f : α → β) (s : Set β) : f '' (f ⁻¹' s) ⊆ s :=
image_subset_iff.2 Subset.rfl
#align set.image_preimage_subset Set.image_preimage_subset
theorem subset_preimage_image (f : α → β) (s : Set α) : s ⊆ f ⁻¹' (f '' s) := fun _ =>
mem_image_of_mem f
#align set.subset_preimage_image Set.subset_preimage_image
@[simp]
theorem preimage_image_eq {f : α → β} (s : Set α) (h : Injective f) : f ⁻¹' (f '' s) = s :=
Subset.antisymm (fun _ ⟨_, hy, e⟩ => h e ▸ hy) (subset_preimage_image f s)
#align set.preimage_image_eq Set.preimage_image_eq
@[simp]
theorem image_preimage_eq {f : α → β} (s : Set β) (h : Surjective f) : f '' (f ⁻¹' s) = s :=
Subset.antisymm (image_preimage_subset f s) fun x hx =>
let ⟨y, e⟩ := h x
⟨y, (e.symm ▸ hx : f y ∈ s), e⟩
#align set.image_preimage_eq Set.image_preimage_eq
@[simp]
theorem preimage_eq_preimage {f : β → α} (hf : Surjective f) : f ⁻¹' s = f ⁻¹' t ↔ s = t :=
Iff.intro
fun eq => by
|
rw [← image_preimage_eq s hf, ← image_preimage_eq t hf, eq]
|
@[simp]
theorem preimage_eq_preimage {f : β → α} (hf : Surjective f) : f ⁻¹' s = f ⁻¹' t ↔ s = t :=
Iff.intro
fun eq => by
|
Mathlib.Data.Set.Image.534_0.IJFiTzmYGOCpPSd
|
@[simp]
theorem preimage_eq_preimage {f : β → α} (hf : Surjective f) : f ⁻¹' s = f ⁻¹' t ↔ s = t
|
Mathlib_Data_Set_Image
|
α : Type u_1
β : Type u_2
γ : Type u_3
ι : Sort u_4
ι' : Sort u_5
f✝ : α → β
s✝ t✝ : Set α
f : α → β
s : Set α
t : Set β
⊢ f '' (s ∩ f ⁻¹' t) = f '' s ∩ t
|
/-
Copyright (c) 2014 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Leonardo de Moura
-/
import Mathlib.Data.Set.Basic
#align_import data.set.image from "leanprover-community/mathlib"@"001ffdc42920050657fd45bd2b8bfbec8eaaeb29"
/-!
# Images and preimages of sets
## Main definitions
* `preimage f t : Set α` : the preimage f⁻¹(t) (written `f ⁻¹' t` in Lean) of a subset of β.
* `range f : Set β` : the image of `univ` under `f`.
Also works for `{p : Prop} (f : p → α)` (unlike `image`)
## Notation
* `f ⁻¹' t` for `Set.preimage f t`
* `f '' s` for `Set.image f s`
## Tags
set, sets, image, preimage, pre-image, range
-/
set_option autoImplicit true
universe u v
open Function Set
namespace Set
variable {α β γ : Type*} {ι ι' : Sort*}
/-! ### Inverse image -/
/-- The preimage of `s : Set β` by `f : α → β`, written `f ⁻¹' s`,
is the set of `x : α` such that `f x ∈ s`. -/
def preimage {α : Type u} {β : Type v} (f : α → β) (s : Set β) : Set α :=
{ x | f x ∈ s }
#align set.preimage Set.preimage
/-- `f ⁻¹' t` denotes the preimage of `t : Set β` under the function `f : α → β`. -/
infixl:80 " ⁻¹' " => preimage
section Preimage
variable {f : α → β} {g : β → γ}
@[simp]
theorem preimage_empty : f ⁻¹' ∅ = ∅ :=
rfl
#align set.preimage_empty Set.preimage_empty
@[simp, mfld_simps]
theorem mem_preimage {s : Set β} {a : α} : a ∈ f ⁻¹' s ↔ f a ∈ s :=
Iff.rfl
#align set.mem_preimage Set.mem_preimage
theorem preimage_congr {f g : α → β} {s : Set β} (h : ∀ x : α, f x = g x) : f ⁻¹' s = g ⁻¹' s := by
congr with x
simp [h]
#align set.preimage_congr Set.preimage_congr
@[gcongr]
theorem preimage_mono {s t : Set β} (h : s ⊆ t) : f ⁻¹' s ⊆ f ⁻¹' t := fun _ hx => h hx
#align set.preimage_mono Set.preimage_mono
@[simp, mfld_simps]
theorem preimage_univ : f ⁻¹' univ = univ :=
rfl
#align set.preimage_univ Set.preimage_univ
theorem subset_preimage_univ {s : Set α} : s ⊆ f ⁻¹' univ :=
subset_univ _
#align set.subset_preimage_univ Set.subset_preimage_univ
@[simp, mfld_simps]
theorem preimage_inter {s t : Set β} : f ⁻¹' (s ∩ t) = f ⁻¹' s ∩ f ⁻¹' t :=
rfl
#align set.preimage_inter Set.preimage_inter
@[simp]
theorem preimage_union {s t : Set β} : f ⁻¹' (s ∪ t) = f ⁻¹' s ∪ f ⁻¹' t :=
rfl
#align set.preimage_union Set.preimage_union
@[simp]
theorem preimage_compl {s : Set β} : f ⁻¹' sᶜ = (f ⁻¹' s)ᶜ :=
rfl
#align set.preimage_compl Set.preimage_compl
@[simp]
theorem preimage_diff (f : α → β) (s t : Set β) : f ⁻¹' (s \ t) = f ⁻¹' s \ f ⁻¹' t :=
rfl
#align set.preimage_diff Set.preimage_diff
@[simp]
lemma preimage_symmDiff {f : α → β} (s t : Set β) : f ⁻¹' (s ∆ t) = (f ⁻¹' s) ∆ (f ⁻¹' t) :=
rfl
#align set.preimage_symm_diff Set.preimage_symmDiff
@[simp]
theorem preimage_ite (f : α → β) (s t₁ t₂ : Set β) :
f ⁻¹' s.ite t₁ t₂ = (f ⁻¹' s).ite (f ⁻¹' t₁) (f ⁻¹' t₂) :=
rfl
#align set.preimage_ite Set.preimage_ite
@[simp]
theorem preimage_setOf_eq {p : α → Prop} {f : β → α} : f ⁻¹' { a | p a } = { a | p (f a) } :=
rfl
#align set.preimage_set_of_eq Set.preimage_setOf_eq
@[simp]
theorem preimage_id_eq : preimage (id : α → α) = id :=
rfl
#align set.preimage_id_eq Set.preimage_id_eq
@[mfld_simps]
theorem preimage_id {s : Set α} : id ⁻¹' s = s :=
rfl
#align set.preimage_id Set.preimage_id
@[simp, mfld_simps]
theorem preimage_id' {s : Set α} : (fun x => x) ⁻¹' s = s :=
rfl
#align set.preimage_id' Set.preimage_id'
@[simp]
theorem preimage_const_of_mem {b : β} {s : Set β} (h : b ∈ s) : (fun _ : α => b) ⁻¹' s = univ :=
eq_univ_of_forall fun _ => h
#align set.preimage_const_of_mem Set.preimage_const_of_mem
@[simp]
theorem preimage_const_of_not_mem {b : β} {s : Set β} (h : b ∉ s) : (fun _ : α => b) ⁻¹' s = ∅ :=
eq_empty_of_subset_empty fun _ hx => h hx
#align set.preimage_const_of_not_mem Set.preimage_const_of_not_mem
theorem preimage_const (b : β) (s : Set β) [Decidable (b ∈ s)] :
(fun _ : α => b) ⁻¹' s = if b ∈ s then univ else ∅ := by
split_ifs with hb
exacts [preimage_const_of_mem hb, preimage_const_of_not_mem hb]
#align set.preimage_const Set.preimage_const
/-- If preimage of each singleton under `f : α → β` is either empty or the whole type,
then `f` is a constant. -/
lemma exists_eq_const_of_preimage_singleton [Nonempty β] {f : α → β}
(hf : ∀ b : β, f ⁻¹' {b} = ∅ ∨ f ⁻¹' {b} = univ) : ∃ b, f = const α b := by
rcases em (∃ b, f ⁻¹' {b} = univ) with ⟨b, hb⟩ | hf'
· exact ⟨b, funext fun x ↦ eq_univ_iff_forall.1 hb x⟩
· have : ∀ x b, f x ≠ b := fun x b ↦
eq_empty_iff_forall_not_mem.1 ((hf b).resolve_right fun h ↦ hf' ⟨b, h⟩) x
exact ⟨Classical.arbitrary β, funext fun x ↦ absurd rfl (this x _)⟩
theorem preimage_comp {s : Set γ} : g ∘ f ⁻¹' s = f ⁻¹' (g ⁻¹' s) :=
rfl
#align set.preimage_comp Set.preimage_comp
theorem preimage_comp_eq : preimage (g ∘ f) = preimage f ∘ preimage g :=
rfl
#align set.preimage_comp_eq Set.preimage_comp_eq
theorem preimage_iterate_eq {f : α → α} {n : ℕ} : Set.preimage f^[n] = (Set.preimage f)^[n] := by
induction' n with n ih; · simp
rw [iterate_succ, iterate_succ', preimage_comp_eq, ih]
#align set.preimage_iterate_eq Set.preimage_iterate_eq
theorem preimage_preimage {g : β → γ} {f : α → β} {s : Set γ} :
f ⁻¹' (g ⁻¹' s) = (fun x => g (f x)) ⁻¹' s :=
preimage_comp.symm
#align set.preimage_preimage Set.preimage_preimage
theorem eq_preimage_subtype_val_iff {p : α → Prop} {s : Set (Subtype p)} {t : Set α} :
s = Subtype.val ⁻¹' t ↔ ∀ (x) (h : p x), (⟨x, h⟩ : Subtype p) ∈ s ↔ x ∈ t :=
⟨fun s_eq x h => by
rw [s_eq]
simp, fun h => ext fun ⟨x, hx⟩ => by simp [h]⟩
#align set.eq_preimage_subtype_val_iff Set.eq_preimage_subtype_val_iff
theorem nonempty_of_nonempty_preimage {s : Set β} {f : α → β} (hf : (f ⁻¹' s).Nonempty) :
s.Nonempty :=
let ⟨x, hx⟩ := hf
⟨f x, hx⟩
#align set.nonempty_of_nonempty_preimage Set.nonempty_of_nonempty_preimage
@[simp] theorem preimage_singleton_true (p : α → Prop) : p ⁻¹' {True} = {a | p a} := by ext; simp
#align set.preimage_singleton_true Set.preimage_singleton_true
@[simp] theorem preimage_singleton_false (p : α → Prop) : p ⁻¹' {False} = {a | ¬p a} := by ext; simp
#align set.preimage_singleton_false Set.preimage_singleton_false
theorem preimage_subtype_coe_eq_compl {s u v : Set α} (hsuv : s ⊆ u ∪ v)
(H : s ∩ (u ∩ v) = ∅) : ((↑) : s → α) ⁻¹' u = ((↑) ⁻¹' v)ᶜ := by
ext ⟨x, x_in_s⟩
constructor
· intro x_in_u x_in_v
exact eq_empty_iff_forall_not_mem.mp H x ⟨x_in_s, ⟨x_in_u, x_in_v⟩⟩
· intro hx
exact Or.elim (hsuv x_in_s) id fun hx' => hx.elim hx'
#align set.preimage_subtype_coe_eq_compl Set.preimage_subtype_coe_eq_compl
end Preimage
/-! ### Image of a set under a function -/
section Image
variable {f : α → β} {s t : Set α}
-- Porting note: `Set.image` is already defined in `Init.Set`
#align set.image Set.image
/-- `f '' s` denotes the image of `s : Set α` under the function `f : α → β`. -/
infixl:80 " '' " => image
theorem mem_image_iff_bex {f : α → β} {s : Set α} {y : β} :
y ∈ f '' s ↔ ∃ (x : _) (_ : x ∈ s), f x = y :=
bex_def.symm
#align set.mem_image_iff_bex Set.mem_image_iff_bex
@[simp]
theorem mem_image (f : α → β) (s : Set α) (y : β) : y ∈ f '' s ↔ ∃ x ∈ s, f x = y :=
Iff.rfl
#align set.mem_image Set.mem_image
theorem image_eta (f : α → β) : f '' s = (fun x => f x) '' s :=
rfl
#align set.image_eta Set.image_eta
@[mfld_simps]
theorem mem_image_of_mem (f : α → β) {x : α} {a : Set α} (h : x ∈ a) : f x ∈ f '' a :=
⟨_, h, rfl⟩
#align set.mem_image_of_mem Set.mem_image_of_mem
theorem _root_.Function.Injective.mem_set_image {f : α → β} (hf : Injective f) {s : Set α} {a : α} :
f a ∈ f '' s ↔ a ∈ s :=
⟨fun ⟨_, hb, Eq⟩ => hf Eq ▸ hb, mem_image_of_mem f⟩
#align function.injective.mem_set_image Function.Injective.mem_set_image
theorem ball_image_iff {f : α → β} {s : Set α} {p : β → Prop} :
(∀ y ∈ f '' s, p y) ↔ ∀ x ∈ s, p (f x) := by simp
#align set.ball_image_iff Set.ball_image_iff
theorem ball_image_of_ball {f : α → β} {s : Set α} {p : β → Prop} (h : ∀ x ∈ s, p (f x)) :
∀ y ∈ f '' s, p y :=
ball_image_iff.2 h
#align set.ball_image_of_ball Set.ball_image_of_ball
theorem bex_image_iff {f : α → β} {s : Set α} {p : β → Prop} :
(∃ y ∈ f '' s, p y) ↔ ∃ x ∈ s, p (f x) := by simp
#align set.bex_image_iff Set.bex_image_iff
theorem mem_image_elim {f : α → β} {s : Set α} {C : β → Prop} (h : ∀ x : α, x ∈ s → C (f x)) :
∀ {y : β}, y ∈ f '' s → C y
| _, ⟨a, a_in, rfl⟩ => h a a_in
#align set.mem_image_elim Set.mem_image_elim
theorem mem_image_elim_on {f : α → β} {s : Set α} {C : β → Prop} {y : β} (h_y : y ∈ f '' s)
(h : ∀ x : α, x ∈ s → C (f x)) : C y :=
mem_image_elim h h_y
#align set.mem_image_elim_on Set.mem_image_elim_on
-- Porting note: used to be `safe`
@[congr]
theorem image_congr {f g : α → β} {s : Set α} (h : ∀ a ∈ s, f a = g a) : f '' s = g '' s := by
ext x
rw [mem_image, mem_image]
exact {
mp := by
rintro ⟨a, ha1, ha2⟩
exact ⟨a, ⟨ha1, (h a ha1) ▸ ha2⟩⟩,
mpr := by
rintro ⟨a, ha1, ha2⟩
exact ⟨a, ⟨ha1, (h a ha1) ▸ ha2⟩⟩
}
-- safe [ext_iff, iff_def]
#align set.image_congr Set.image_congr
/-- A common special case of `image_congr` -/
theorem image_congr' {f g : α → β} {s : Set α} (h : ∀ x : α, f x = g x) : f '' s = g '' s :=
image_congr fun x _ => h x
#align set.image_congr' Set.image_congr'
@[gcongr]
lemma image_mono (h : s ⊆ t) : f '' s ⊆ f '' t := by
rintro - ⟨a, ha, rfl⟩; exact mem_image_of_mem f (h ha)
theorem image_comp (f : β → γ) (g : α → β) (a : Set α) : f ∘ g '' a = f '' (g '' a) :=
Subset.antisymm (ball_image_of_ball fun _ ha => mem_image_of_mem _ <| mem_image_of_mem _ ha)
(ball_image_of_ball <| ball_image_of_ball fun _ ha => mem_image_of_mem _ ha)
#align set.image_comp Set.image_comp
theorem image_comp_eq {g : β → γ} : image (g ∘ f) = image g ∘ image f := by ext; simp
/-- A variant of `image_comp`, useful for rewriting -/
theorem image_image (g : β → γ) (f : α → β) (s : Set α) : g '' (f '' s) = (fun x => g (f x)) '' s :=
(image_comp g f s).symm
#align set.image_image Set.image_image
theorem image_comm {β'} {f : β → γ} {g : α → β} {f' : α → β'} {g' : β' → γ}
(h_comm : ∀ a, f (g a) = g' (f' a)) : (s.image g).image f = (s.image f').image g' := by
simp_rw [image_image, h_comm]
#align set.image_comm Set.image_comm
theorem _root_.Function.Semiconj.set_image {f : α → β} {ga : α → α} {gb : β → β}
(h : Function.Semiconj f ga gb) : Function.Semiconj (image f) (image ga) (image gb) := fun _ =>
image_comm h
#align function.semiconj.set_image Function.Semiconj.set_image
theorem _root_.Function.Commute.set_image {f g : α → α} (h : Function.Commute f g) :
Function.Commute (image f) (image g) :=
Function.Semiconj.set_image h
#align function.commute.set_image Function.Commute.set_image
/-- Image is monotone with respect to `⊆`. See `Set.monotone_image` for the statement in
terms of `≤`. -/
@[gcongr]
theorem image_subset {a b : Set α} (f : α → β) (h : a ⊆ b) : f '' a ⊆ f '' b := by
simp only [subset_def, mem_image]
exact fun x => fun ⟨w, h1, h2⟩ => ⟨w, h h1, h2⟩
#align set.image_subset Set.image_subset
/-- `Set.image` is monotone. See `Set.image_subset` for the statement in terms of `⊆`. -/
lemma monotone_image {f : α → β} : Monotone (image f) := fun _ _ => image_subset _
#align set.monotone_image Set.monotone_image
theorem image_union (f : α → β) (s t : Set α) : f '' (s ∪ t) = f '' s ∪ f '' t :=
ext fun x =>
⟨by rintro ⟨a, h | h, rfl⟩ <;> [left; right] <;> exact ⟨_, h, rfl⟩, by
rintro (⟨a, h, rfl⟩ | ⟨a, h, rfl⟩) <;> refine' ⟨_, _, rfl⟩ <;> [left; right] <;> exact h⟩
#align set.image_union Set.image_union
@[simp]
theorem image_empty (f : α → β) : f '' ∅ = ∅ := by
ext
simp
#align set.image_empty Set.image_empty
theorem image_inter_subset (f : α → β) (s t : Set α) : f '' (s ∩ t) ⊆ f '' s ∩ f '' t :=
subset_inter (image_subset _ <| inter_subset_left _ _) (image_subset _ <| inter_subset_right _ _)
#align set.image_inter_subset Set.image_inter_subset
theorem image_inter_on {f : α → β} {s t : Set α} (h : ∀ x ∈ t, ∀ y ∈ s, f x = f y → x = y) :
f '' (s ∩ t) = f '' s ∩ f '' t :=
(image_inter_subset _ _ _).antisymm
fun b ⟨⟨a₁, ha₁, h₁⟩, ⟨a₂, ha₂, h₂⟩⟩ ↦
have : a₂ = a₁ := h _ ha₂ _ ha₁ (by simp [*])
⟨a₁, ⟨ha₁, this ▸ ha₂⟩, h₁⟩
#align set.image_inter_on Set.image_inter_on
theorem image_inter {f : α → β} {s t : Set α} (H : Injective f) : f '' (s ∩ t) = f '' s ∩ f '' t :=
image_inter_on fun _ _ _ _ h => H h
#align set.image_inter Set.image_inter
theorem image_univ_of_surjective {ι : Type*} {f : ι → β} (H : Surjective f) : f '' univ = univ :=
eq_univ_of_forall <| by simpa [image]
#align set.image_univ_of_surjective Set.image_univ_of_surjective
@[simp]
theorem image_singleton {f : α → β} {a : α} : f '' {a} = {f a} := by
ext
simp [image, eq_comm]
#align set.image_singleton Set.image_singleton
@[simp]
theorem Nonempty.image_const {s : Set α} (hs : s.Nonempty) (a : β) : (fun _ => a) '' s = {a} :=
ext fun _ =>
⟨fun ⟨_, _, h⟩ => h ▸ mem_singleton _, fun h =>
(eq_of_mem_singleton h).symm ▸ hs.imp fun _ hy => ⟨hy, rfl⟩⟩
#align set.nonempty.image_const Set.Nonempty.image_const
@[simp, mfld_simps]
theorem image_eq_empty {α β} {f : α → β} {s : Set α} : f '' s = ∅ ↔ s = ∅ := by
simp only [eq_empty_iff_forall_not_mem]
exact ⟨fun H a ha => H _ ⟨_, ha, rfl⟩, fun H b ⟨_, ha, _⟩ => H _ ha⟩
#align set.image_eq_empty Set.image_eq_empty
-- Porting note: `compl` is already defined in `Init.Set`
theorem preimage_compl_eq_image_compl [BooleanAlgebra α] (S : Set α) :
HasCompl.compl ⁻¹' S = HasCompl.compl '' S :=
Set.ext fun x =>
⟨fun h => ⟨xᶜ, h, compl_compl x⟩, fun h =>
Exists.elim h fun _ hy => (compl_eq_comm.mp hy.2).symm.subst hy.1⟩
#align set.preimage_compl_eq_image_compl Set.preimage_compl_eq_image_compl
theorem mem_compl_image [BooleanAlgebra α] (t : α) (S : Set α) :
t ∈ HasCompl.compl '' S ↔ tᶜ ∈ S := by
simp [← preimage_compl_eq_image_compl]
#align set.mem_compl_image Set.mem_compl_image
@[simp]
theorem image_id_eq : image (id : α → α) = id := by ext; simp
/-- A variant of `image_id` -/
@[simp]
theorem image_id' (s : Set α) : (fun x => x) '' s = s := by
ext
simp
#align set.image_id' Set.image_id'
theorem image_id (s : Set α) : id '' s = s := by simp
#align set.image_id Set.image_id
lemma image_iterate_eq {f : α → α} {n : ℕ} : image (f^[n]) = (image f)^[n] := by
induction' n with n ih; · simp
rw [iterate_succ', iterate_succ',← ih, image_comp_eq]
theorem compl_compl_image [BooleanAlgebra α] (S : Set α) :
HasCompl.compl '' (HasCompl.compl '' S) = S := by
rw [← image_comp, compl_comp_compl, image_id]
#align set.compl_compl_image Set.compl_compl_image
theorem image_insert_eq {f : α → β} {a : α} {s : Set α} :
f '' insert a s = insert (f a) (f '' s) := by
ext
simp [and_or_left, exists_or, eq_comm, or_comm, and_comm]
#align set.image_insert_eq Set.image_insert_eq
theorem image_pair (f : α → β) (a b : α) : f '' {a, b} = {f a, f b} := by
simp only [image_insert_eq, image_singleton]
#align set.image_pair Set.image_pair
theorem image_subset_preimage_of_inverse {f : α → β} {g : β → α} (I : LeftInverse g f) (s : Set α) :
f '' s ⊆ g ⁻¹' s := fun _ ⟨a, h, e⟩ => e ▸ ((I a).symm ▸ h : g (f a) ∈ s)
#align set.image_subset_preimage_of_inverse Set.image_subset_preimage_of_inverse
theorem preimage_subset_image_of_inverse {f : α → β} {g : β → α} (I : LeftInverse g f) (s : Set β) :
f ⁻¹' s ⊆ g '' s := fun b h => ⟨f b, h, I b⟩
#align set.preimage_subset_image_of_inverse Set.preimage_subset_image_of_inverse
theorem image_eq_preimage_of_inverse {f : α → β} {g : β → α} (h₁ : LeftInverse g f)
(h₂ : RightInverse g f) : image f = preimage g :=
funext fun s =>
Subset.antisymm (image_subset_preimage_of_inverse h₁ s) (preimage_subset_image_of_inverse h₂ s)
#align set.image_eq_preimage_of_inverse Set.image_eq_preimage_of_inverse
theorem mem_image_iff_of_inverse {f : α → β} {g : β → α} {b : β} {s : Set α} (h₁ : LeftInverse g f)
(h₂ : RightInverse g f) : b ∈ f '' s ↔ g b ∈ s := by
rw [image_eq_preimage_of_inverse h₁ h₂]; rfl
#align set.mem_image_iff_of_inverse Set.mem_image_iff_of_inverse
theorem image_compl_subset {f : α → β} {s : Set α} (H : Injective f) : f '' sᶜ ⊆ (f '' s)ᶜ :=
Disjoint.subset_compl_left <| by simp [disjoint_iff_inf_le, ← image_inter H]
#align set.image_compl_subset Set.image_compl_subset
theorem subset_image_compl {f : α → β} {s : Set α} (H : Surjective f) : (f '' s)ᶜ ⊆ f '' sᶜ :=
compl_subset_iff_union.2 <| by
rw [← image_union]
simp [image_univ_of_surjective H]
#align set.subset_image_compl Set.subset_image_compl
theorem image_compl_eq {f : α → β} {s : Set α} (H : Bijective f) : f '' sᶜ = (f '' s)ᶜ :=
Subset.antisymm (image_compl_subset H.1) (subset_image_compl H.2)
#align set.image_compl_eq Set.image_compl_eq
theorem subset_image_diff (f : α → β) (s t : Set α) : f '' s \ f '' t ⊆ f '' (s \ t) := by
rw [diff_subset_iff, ← image_union, union_diff_self]
exact image_subset f (subset_union_right t s)
#align set.subset_image_diff Set.subset_image_diff
theorem subset_image_symmDiff : (f '' s) ∆ (f '' t) ⊆ f '' s ∆ t :=
(union_subset_union (subset_image_diff _ _ _) <| subset_image_diff _ _ _).trans
(superset_of_eq (image_union _ _ _))
#align set.subset_image_symm_diff Set.subset_image_symmDiff
theorem image_diff {f : α → β} (hf : Injective f) (s t : Set α) : f '' (s \ t) = f '' s \ f '' t :=
Subset.antisymm
(Subset.trans (image_inter_subset _ _ _) <| inter_subset_inter_right _ <| image_compl_subset hf)
(subset_image_diff f s t)
#align set.image_diff Set.image_diff
theorem image_symmDiff (hf : Injective f) (s t : Set α) : f '' s ∆ t = (f '' s) ∆ (f '' t) := by
simp_rw [Set.symmDiff_def, image_union, image_diff hf]
#align set.image_symm_diff Set.image_symmDiff
theorem Nonempty.image (f : α → β) {s : Set α} : s.Nonempty → (f '' s).Nonempty
| ⟨x, hx⟩ => ⟨f x, mem_image_of_mem f hx⟩
#align set.nonempty.image Set.Nonempty.image
theorem Nonempty.of_image {f : α → β} {s : Set α} : (f '' s).Nonempty → s.Nonempty
| ⟨_, x, hx, _⟩ => ⟨x, hx⟩
#align set.nonempty.of_image Set.Nonempty.of_image
@[simp]
theorem nonempty_image_iff {f : α → β} {s : Set α} : (f '' s).Nonempty ↔ s.Nonempty :=
⟨Nonempty.of_image, fun h => h.image f⟩
#align set.nonempty_image_iff Set.nonempty_image_iff
theorem Nonempty.preimage {s : Set β} (hs : s.Nonempty) {f : α → β} (hf : Surjective f) :
(f ⁻¹' s).Nonempty :=
let ⟨y, hy⟩ := hs
let ⟨x, hx⟩ := hf y
⟨x, mem_preimage.2 <| hx.symm ▸ hy⟩
#align set.nonempty.preimage Set.Nonempty.preimage
instance (f : α → β) (s : Set α) [Nonempty s] : Nonempty (f '' s) :=
(Set.Nonempty.image f nonempty_of_nonempty_subtype).to_subtype
/-- image and preimage are a Galois connection -/
@[simp]
theorem image_subset_iff {s : Set α} {t : Set β} {f : α → β} : f '' s ⊆ t ↔ s ⊆ f ⁻¹' t :=
ball_image_iff
#align set.image_subset_iff Set.image_subset_iff
theorem image_preimage_subset (f : α → β) (s : Set β) : f '' (f ⁻¹' s) ⊆ s :=
image_subset_iff.2 Subset.rfl
#align set.image_preimage_subset Set.image_preimage_subset
theorem subset_preimage_image (f : α → β) (s : Set α) : s ⊆ f ⁻¹' (f '' s) := fun _ =>
mem_image_of_mem f
#align set.subset_preimage_image Set.subset_preimage_image
@[simp]
theorem preimage_image_eq {f : α → β} (s : Set α) (h : Injective f) : f ⁻¹' (f '' s) = s :=
Subset.antisymm (fun _ ⟨_, hy, e⟩ => h e ▸ hy) (subset_preimage_image f s)
#align set.preimage_image_eq Set.preimage_image_eq
@[simp]
theorem image_preimage_eq {f : α → β} (s : Set β) (h : Surjective f) : f '' (f ⁻¹' s) = s :=
Subset.antisymm (image_preimage_subset f s) fun x hx =>
let ⟨y, e⟩ := h x
⟨y, (e.symm ▸ hx : f y ∈ s), e⟩
#align set.image_preimage_eq Set.image_preimage_eq
@[simp]
theorem preimage_eq_preimage {f : β → α} (hf : Surjective f) : f ⁻¹' s = f ⁻¹' t ↔ s = t :=
Iff.intro
fun eq => by rw [← image_preimage_eq s hf, ← image_preimage_eq t hf, eq]
fun eq => eq ▸ rfl
#align set.preimage_eq_preimage Set.preimage_eq_preimage
theorem image_inter_preimage (f : α → β) (s : Set α) (t : Set β) :
f '' (s ∩ f ⁻¹' t) = f '' s ∩ t := by
|
apply Subset.antisymm
|
theorem image_inter_preimage (f : α → β) (s : Set α) (t : Set β) :
f '' (s ∩ f ⁻¹' t) = f '' s ∩ t := by
|
Mathlib.Data.Set.Image.541_0.IJFiTzmYGOCpPSd
|
theorem image_inter_preimage (f : α → β) (s : Set α) (t : Set β) :
f '' (s ∩ f ⁻¹' t) = f '' s ∩ t
|
Mathlib_Data_Set_Image
|
case h₁
α : Type u_1
β : Type u_2
γ : Type u_3
ι : Sort u_4
ι' : Sort u_5
f✝ : α → β
s✝ t✝ : Set α
f : α → β
s : Set α
t : Set β
⊢ f '' (s ∩ f ⁻¹' t) ⊆ f '' s ∩ t
|
/-
Copyright (c) 2014 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Leonardo de Moura
-/
import Mathlib.Data.Set.Basic
#align_import data.set.image from "leanprover-community/mathlib"@"001ffdc42920050657fd45bd2b8bfbec8eaaeb29"
/-!
# Images and preimages of sets
## Main definitions
* `preimage f t : Set α` : the preimage f⁻¹(t) (written `f ⁻¹' t` in Lean) of a subset of β.
* `range f : Set β` : the image of `univ` under `f`.
Also works for `{p : Prop} (f : p → α)` (unlike `image`)
## Notation
* `f ⁻¹' t` for `Set.preimage f t`
* `f '' s` for `Set.image f s`
## Tags
set, sets, image, preimage, pre-image, range
-/
set_option autoImplicit true
universe u v
open Function Set
namespace Set
variable {α β γ : Type*} {ι ι' : Sort*}
/-! ### Inverse image -/
/-- The preimage of `s : Set β` by `f : α → β`, written `f ⁻¹' s`,
is the set of `x : α` such that `f x ∈ s`. -/
def preimage {α : Type u} {β : Type v} (f : α → β) (s : Set β) : Set α :=
{ x | f x ∈ s }
#align set.preimage Set.preimage
/-- `f ⁻¹' t` denotes the preimage of `t : Set β` under the function `f : α → β`. -/
infixl:80 " ⁻¹' " => preimage
section Preimage
variable {f : α → β} {g : β → γ}
@[simp]
theorem preimage_empty : f ⁻¹' ∅ = ∅ :=
rfl
#align set.preimage_empty Set.preimage_empty
@[simp, mfld_simps]
theorem mem_preimage {s : Set β} {a : α} : a ∈ f ⁻¹' s ↔ f a ∈ s :=
Iff.rfl
#align set.mem_preimage Set.mem_preimage
theorem preimage_congr {f g : α → β} {s : Set β} (h : ∀ x : α, f x = g x) : f ⁻¹' s = g ⁻¹' s := by
congr with x
simp [h]
#align set.preimage_congr Set.preimage_congr
@[gcongr]
theorem preimage_mono {s t : Set β} (h : s ⊆ t) : f ⁻¹' s ⊆ f ⁻¹' t := fun _ hx => h hx
#align set.preimage_mono Set.preimage_mono
@[simp, mfld_simps]
theorem preimage_univ : f ⁻¹' univ = univ :=
rfl
#align set.preimage_univ Set.preimage_univ
theorem subset_preimage_univ {s : Set α} : s ⊆ f ⁻¹' univ :=
subset_univ _
#align set.subset_preimage_univ Set.subset_preimage_univ
@[simp, mfld_simps]
theorem preimage_inter {s t : Set β} : f ⁻¹' (s ∩ t) = f ⁻¹' s ∩ f ⁻¹' t :=
rfl
#align set.preimage_inter Set.preimage_inter
@[simp]
theorem preimage_union {s t : Set β} : f ⁻¹' (s ∪ t) = f ⁻¹' s ∪ f ⁻¹' t :=
rfl
#align set.preimage_union Set.preimage_union
@[simp]
theorem preimage_compl {s : Set β} : f ⁻¹' sᶜ = (f ⁻¹' s)ᶜ :=
rfl
#align set.preimage_compl Set.preimage_compl
@[simp]
theorem preimage_diff (f : α → β) (s t : Set β) : f ⁻¹' (s \ t) = f ⁻¹' s \ f ⁻¹' t :=
rfl
#align set.preimage_diff Set.preimage_diff
@[simp]
lemma preimage_symmDiff {f : α → β} (s t : Set β) : f ⁻¹' (s ∆ t) = (f ⁻¹' s) ∆ (f ⁻¹' t) :=
rfl
#align set.preimage_symm_diff Set.preimage_symmDiff
@[simp]
theorem preimage_ite (f : α → β) (s t₁ t₂ : Set β) :
f ⁻¹' s.ite t₁ t₂ = (f ⁻¹' s).ite (f ⁻¹' t₁) (f ⁻¹' t₂) :=
rfl
#align set.preimage_ite Set.preimage_ite
@[simp]
theorem preimage_setOf_eq {p : α → Prop} {f : β → α} : f ⁻¹' { a | p a } = { a | p (f a) } :=
rfl
#align set.preimage_set_of_eq Set.preimage_setOf_eq
@[simp]
theorem preimage_id_eq : preimage (id : α → α) = id :=
rfl
#align set.preimage_id_eq Set.preimage_id_eq
@[mfld_simps]
theorem preimage_id {s : Set α} : id ⁻¹' s = s :=
rfl
#align set.preimage_id Set.preimage_id
@[simp, mfld_simps]
theorem preimage_id' {s : Set α} : (fun x => x) ⁻¹' s = s :=
rfl
#align set.preimage_id' Set.preimage_id'
@[simp]
theorem preimage_const_of_mem {b : β} {s : Set β} (h : b ∈ s) : (fun _ : α => b) ⁻¹' s = univ :=
eq_univ_of_forall fun _ => h
#align set.preimage_const_of_mem Set.preimage_const_of_mem
@[simp]
theorem preimage_const_of_not_mem {b : β} {s : Set β} (h : b ∉ s) : (fun _ : α => b) ⁻¹' s = ∅ :=
eq_empty_of_subset_empty fun _ hx => h hx
#align set.preimage_const_of_not_mem Set.preimage_const_of_not_mem
theorem preimage_const (b : β) (s : Set β) [Decidable (b ∈ s)] :
(fun _ : α => b) ⁻¹' s = if b ∈ s then univ else ∅ := by
split_ifs with hb
exacts [preimage_const_of_mem hb, preimage_const_of_not_mem hb]
#align set.preimage_const Set.preimage_const
/-- If preimage of each singleton under `f : α → β` is either empty or the whole type,
then `f` is a constant. -/
lemma exists_eq_const_of_preimage_singleton [Nonempty β] {f : α → β}
(hf : ∀ b : β, f ⁻¹' {b} = ∅ ∨ f ⁻¹' {b} = univ) : ∃ b, f = const α b := by
rcases em (∃ b, f ⁻¹' {b} = univ) with ⟨b, hb⟩ | hf'
· exact ⟨b, funext fun x ↦ eq_univ_iff_forall.1 hb x⟩
· have : ∀ x b, f x ≠ b := fun x b ↦
eq_empty_iff_forall_not_mem.1 ((hf b).resolve_right fun h ↦ hf' ⟨b, h⟩) x
exact ⟨Classical.arbitrary β, funext fun x ↦ absurd rfl (this x _)⟩
theorem preimage_comp {s : Set γ} : g ∘ f ⁻¹' s = f ⁻¹' (g ⁻¹' s) :=
rfl
#align set.preimage_comp Set.preimage_comp
theorem preimage_comp_eq : preimage (g ∘ f) = preimage f ∘ preimage g :=
rfl
#align set.preimage_comp_eq Set.preimage_comp_eq
theorem preimage_iterate_eq {f : α → α} {n : ℕ} : Set.preimage f^[n] = (Set.preimage f)^[n] := by
induction' n with n ih; · simp
rw [iterate_succ, iterate_succ', preimage_comp_eq, ih]
#align set.preimage_iterate_eq Set.preimage_iterate_eq
theorem preimage_preimage {g : β → γ} {f : α → β} {s : Set γ} :
f ⁻¹' (g ⁻¹' s) = (fun x => g (f x)) ⁻¹' s :=
preimage_comp.symm
#align set.preimage_preimage Set.preimage_preimage
theorem eq_preimage_subtype_val_iff {p : α → Prop} {s : Set (Subtype p)} {t : Set α} :
s = Subtype.val ⁻¹' t ↔ ∀ (x) (h : p x), (⟨x, h⟩ : Subtype p) ∈ s ↔ x ∈ t :=
⟨fun s_eq x h => by
rw [s_eq]
simp, fun h => ext fun ⟨x, hx⟩ => by simp [h]⟩
#align set.eq_preimage_subtype_val_iff Set.eq_preimage_subtype_val_iff
theorem nonempty_of_nonempty_preimage {s : Set β} {f : α → β} (hf : (f ⁻¹' s).Nonempty) :
s.Nonempty :=
let ⟨x, hx⟩ := hf
⟨f x, hx⟩
#align set.nonempty_of_nonempty_preimage Set.nonempty_of_nonempty_preimage
@[simp] theorem preimage_singleton_true (p : α → Prop) : p ⁻¹' {True} = {a | p a} := by ext; simp
#align set.preimage_singleton_true Set.preimage_singleton_true
@[simp] theorem preimage_singleton_false (p : α → Prop) : p ⁻¹' {False} = {a | ¬p a} := by ext; simp
#align set.preimage_singleton_false Set.preimage_singleton_false
theorem preimage_subtype_coe_eq_compl {s u v : Set α} (hsuv : s ⊆ u ∪ v)
(H : s ∩ (u ∩ v) = ∅) : ((↑) : s → α) ⁻¹' u = ((↑) ⁻¹' v)ᶜ := by
ext ⟨x, x_in_s⟩
constructor
· intro x_in_u x_in_v
exact eq_empty_iff_forall_not_mem.mp H x ⟨x_in_s, ⟨x_in_u, x_in_v⟩⟩
· intro hx
exact Or.elim (hsuv x_in_s) id fun hx' => hx.elim hx'
#align set.preimage_subtype_coe_eq_compl Set.preimage_subtype_coe_eq_compl
end Preimage
/-! ### Image of a set under a function -/
section Image
variable {f : α → β} {s t : Set α}
-- Porting note: `Set.image` is already defined in `Init.Set`
#align set.image Set.image
/-- `f '' s` denotes the image of `s : Set α` under the function `f : α → β`. -/
infixl:80 " '' " => image
theorem mem_image_iff_bex {f : α → β} {s : Set α} {y : β} :
y ∈ f '' s ↔ ∃ (x : _) (_ : x ∈ s), f x = y :=
bex_def.symm
#align set.mem_image_iff_bex Set.mem_image_iff_bex
@[simp]
theorem mem_image (f : α → β) (s : Set α) (y : β) : y ∈ f '' s ↔ ∃ x ∈ s, f x = y :=
Iff.rfl
#align set.mem_image Set.mem_image
theorem image_eta (f : α → β) : f '' s = (fun x => f x) '' s :=
rfl
#align set.image_eta Set.image_eta
@[mfld_simps]
theorem mem_image_of_mem (f : α → β) {x : α} {a : Set α} (h : x ∈ a) : f x ∈ f '' a :=
⟨_, h, rfl⟩
#align set.mem_image_of_mem Set.mem_image_of_mem
theorem _root_.Function.Injective.mem_set_image {f : α → β} (hf : Injective f) {s : Set α} {a : α} :
f a ∈ f '' s ↔ a ∈ s :=
⟨fun ⟨_, hb, Eq⟩ => hf Eq ▸ hb, mem_image_of_mem f⟩
#align function.injective.mem_set_image Function.Injective.mem_set_image
theorem ball_image_iff {f : α → β} {s : Set α} {p : β → Prop} :
(∀ y ∈ f '' s, p y) ↔ ∀ x ∈ s, p (f x) := by simp
#align set.ball_image_iff Set.ball_image_iff
theorem ball_image_of_ball {f : α → β} {s : Set α} {p : β → Prop} (h : ∀ x ∈ s, p (f x)) :
∀ y ∈ f '' s, p y :=
ball_image_iff.2 h
#align set.ball_image_of_ball Set.ball_image_of_ball
theorem bex_image_iff {f : α → β} {s : Set α} {p : β → Prop} :
(∃ y ∈ f '' s, p y) ↔ ∃ x ∈ s, p (f x) := by simp
#align set.bex_image_iff Set.bex_image_iff
theorem mem_image_elim {f : α → β} {s : Set α} {C : β → Prop} (h : ∀ x : α, x ∈ s → C (f x)) :
∀ {y : β}, y ∈ f '' s → C y
| _, ⟨a, a_in, rfl⟩ => h a a_in
#align set.mem_image_elim Set.mem_image_elim
theorem mem_image_elim_on {f : α → β} {s : Set α} {C : β → Prop} {y : β} (h_y : y ∈ f '' s)
(h : ∀ x : α, x ∈ s → C (f x)) : C y :=
mem_image_elim h h_y
#align set.mem_image_elim_on Set.mem_image_elim_on
-- Porting note: used to be `safe`
@[congr]
theorem image_congr {f g : α → β} {s : Set α} (h : ∀ a ∈ s, f a = g a) : f '' s = g '' s := by
ext x
rw [mem_image, mem_image]
exact {
mp := by
rintro ⟨a, ha1, ha2⟩
exact ⟨a, ⟨ha1, (h a ha1) ▸ ha2⟩⟩,
mpr := by
rintro ⟨a, ha1, ha2⟩
exact ⟨a, ⟨ha1, (h a ha1) ▸ ha2⟩⟩
}
-- safe [ext_iff, iff_def]
#align set.image_congr Set.image_congr
/-- A common special case of `image_congr` -/
theorem image_congr' {f g : α → β} {s : Set α} (h : ∀ x : α, f x = g x) : f '' s = g '' s :=
image_congr fun x _ => h x
#align set.image_congr' Set.image_congr'
@[gcongr]
lemma image_mono (h : s ⊆ t) : f '' s ⊆ f '' t := by
rintro - ⟨a, ha, rfl⟩; exact mem_image_of_mem f (h ha)
theorem image_comp (f : β → γ) (g : α → β) (a : Set α) : f ∘ g '' a = f '' (g '' a) :=
Subset.antisymm (ball_image_of_ball fun _ ha => mem_image_of_mem _ <| mem_image_of_mem _ ha)
(ball_image_of_ball <| ball_image_of_ball fun _ ha => mem_image_of_mem _ ha)
#align set.image_comp Set.image_comp
theorem image_comp_eq {g : β → γ} : image (g ∘ f) = image g ∘ image f := by ext; simp
/-- A variant of `image_comp`, useful for rewriting -/
theorem image_image (g : β → γ) (f : α → β) (s : Set α) : g '' (f '' s) = (fun x => g (f x)) '' s :=
(image_comp g f s).symm
#align set.image_image Set.image_image
theorem image_comm {β'} {f : β → γ} {g : α → β} {f' : α → β'} {g' : β' → γ}
(h_comm : ∀ a, f (g a) = g' (f' a)) : (s.image g).image f = (s.image f').image g' := by
simp_rw [image_image, h_comm]
#align set.image_comm Set.image_comm
theorem _root_.Function.Semiconj.set_image {f : α → β} {ga : α → α} {gb : β → β}
(h : Function.Semiconj f ga gb) : Function.Semiconj (image f) (image ga) (image gb) := fun _ =>
image_comm h
#align function.semiconj.set_image Function.Semiconj.set_image
theorem _root_.Function.Commute.set_image {f g : α → α} (h : Function.Commute f g) :
Function.Commute (image f) (image g) :=
Function.Semiconj.set_image h
#align function.commute.set_image Function.Commute.set_image
/-- Image is monotone with respect to `⊆`. See `Set.monotone_image` for the statement in
terms of `≤`. -/
@[gcongr]
theorem image_subset {a b : Set α} (f : α → β) (h : a ⊆ b) : f '' a ⊆ f '' b := by
simp only [subset_def, mem_image]
exact fun x => fun ⟨w, h1, h2⟩ => ⟨w, h h1, h2⟩
#align set.image_subset Set.image_subset
/-- `Set.image` is monotone. See `Set.image_subset` for the statement in terms of `⊆`. -/
lemma monotone_image {f : α → β} : Monotone (image f) := fun _ _ => image_subset _
#align set.monotone_image Set.monotone_image
theorem image_union (f : α → β) (s t : Set α) : f '' (s ∪ t) = f '' s ∪ f '' t :=
ext fun x =>
⟨by rintro ⟨a, h | h, rfl⟩ <;> [left; right] <;> exact ⟨_, h, rfl⟩, by
rintro (⟨a, h, rfl⟩ | ⟨a, h, rfl⟩) <;> refine' ⟨_, _, rfl⟩ <;> [left; right] <;> exact h⟩
#align set.image_union Set.image_union
@[simp]
theorem image_empty (f : α → β) : f '' ∅ = ∅ := by
ext
simp
#align set.image_empty Set.image_empty
theorem image_inter_subset (f : α → β) (s t : Set α) : f '' (s ∩ t) ⊆ f '' s ∩ f '' t :=
subset_inter (image_subset _ <| inter_subset_left _ _) (image_subset _ <| inter_subset_right _ _)
#align set.image_inter_subset Set.image_inter_subset
theorem image_inter_on {f : α → β} {s t : Set α} (h : ∀ x ∈ t, ∀ y ∈ s, f x = f y → x = y) :
f '' (s ∩ t) = f '' s ∩ f '' t :=
(image_inter_subset _ _ _).antisymm
fun b ⟨⟨a₁, ha₁, h₁⟩, ⟨a₂, ha₂, h₂⟩⟩ ↦
have : a₂ = a₁ := h _ ha₂ _ ha₁ (by simp [*])
⟨a₁, ⟨ha₁, this ▸ ha₂⟩, h₁⟩
#align set.image_inter_on Set.image_inter_on
theorem image_inter {f : α → β} {s t : Set α} (H : Injective f) : f '' (s ∩ t) = f '' s ∩ f '' t :=
image_inter_on fun _ _ _ _ h => H h
#align set.image_inter Set.image_inter
theorem image_univ_of_surjective {ι : Type*} {f : ι → β} (H : Surjective f) : f '' univ = univ :=
eq_univ_of_forall <| by simpa [image]
#align set.image_univ_of_surjective Set.image_univ_of_surjective
@[simp]
theorem image_singleton {f : α → β} {a : α} : f '' {a} = {f a} := by
ext
simp [image, eq_comm]
#align set.image_singleton Set.image_singleton
@[simp]
theorem Nonempty.image_const {s : Set α} (hs : s.Nonempty) (a : β) : (fun _ => a) '' s = {a} :=
ext fun _ =>
⟨fun ⟨_, _, h⟩ => h ▸ mem_singleton _, fun h =>
(eq_of_mem_singleton h).symm ▸ hs.imp fun _ hy => ⟨hy, rfl⟩⟩
#align set.nonempty.image_const Set.Nonempty.image_const
@[simp, mfld_simps]
theorem image_eq_empty {α β} {f : α → β} {s : Set α} : f '' s = ∅ ↔ s = ∅ := by
simp only [eq_empty_iff_forall_not_mem]
exact ⟨fun H a ha => H _ ⟨_, ha, rfl⟩, fun H b ⟨_, ha, _⟩ => H _ ha⟩
#align set.image_eq_empty Set.image_eq_empty
-- Porting note: `compl` is already defined in `Init.Set`
theorem preimage_compl_eq_image_compl [BooleanAlgebra α] (S : Set α) :
HasCompl.compl ⁻¹' S = HasCompl.compl '' S :=
Set.ext fun x =>
⟨fun h => ⟨xᶜ, h, compl_compl x⟩, fun h =>
Exists.elim h fun _ hy => (compl_eq_comm.mp hy.2).symm.subst hy.1⟩
#align set.preimage_compl_eq_image_compl Set.preimage_compl_eq_image_compl
theorem mem_compl_image [BooleanAlgebra α] (t : α) (S : Set α) :
t ∈ HasCompl.compl '' S ↔ tᶜ ∈ S := by
simp [← preimage_compl_eq_image_compl]
#align set.mem_compl_image Set.mem_compl_image
@[simp]
theorem image_id_eq : image (id : α → α) = id := by ext; simp
/-- A variant of `image_id` -/
@[simp]
theorem image_id' (s : Set α) : (fun x => x) '' s = s := by
ext
simp
#align set.image_id' Set.image_id'
theorem image_id (s : Set α) : id '' s = s := by simp
#align set.image_id Set.image_id
lemma image_iterate_eq {f : α → α} {n : ℕ} : image (f^[n]) = (image f)^[n] := by
induction' n with n ih; · simp
rw [iterate_succ', iterate_succ',← ih, image_comp_eq]
theorem compl_compl_image [BooleanAlgebra α] (S : Set α) :
HasCompl.compl '' (HasCompl.compl '' S) = S := by
rw [← image_comp, compl_comp_compl, image_id]
#align set.compl_compl_image Set.compl_compl_image
theorem image_insert_eq {f : α → β} {a : α} {s : Set α} :
f '' insert a s = insert (f a) (f '' s) := by
ext
simp [and_or_left, exists_or, eq_comm, or_comm, and_comm]
#align set.image_insert_eq Set.image_insert_eq
theorem image_pair (f : α → β) (a b : α) : f '' {a, b} = {f a, f b} := by
simp only [image_insert_eq, image_singleton]
#align set.image_pair Set.image_pair
theorem image_subset_preimage_of_inverse {f : α → β} {g : β → α} (I : LeftInverse g f) (s : Set α) :
f '' s ⊆ g ⁻¹' s := fun _ ⟨a, h, e⟩ => e ▸ ((I a).symm ▸ h : g (f a) ∈ s)
#align set.image_subset_preimage_of_inverse Set.image_subset_preimage_of_inverse
theorem preimage_subset_image_of_inverse {f : α → β} {g : β → α} (I : LeftInverse g f) (s : Set β) :
f ⁻¹' s ⊆ g '' s := fun b h => ⟨f b, h, I b⟩
#align set.preimage_subset_image_of_inverse Set.preimage_subset_image_of_inverse
theorem image_eq_preimage_of_inverse {f : α → β} {g : β → α} (h₁ : LeftInverse g f)
(h₂ : RightInverse g f) : image f = preimage g :=
funext fun s =>
Subset.antisymm (image_subset_preimage_of_inverse h₁ s) (preimage_subset_image_of_inverse h₂ s)
#align set.image_eq_preimage_of_inverse Set.image_eq_preimage_of_inverse
theorem mem_image_iff_of_inverse {f : α → β} {g : β → α} {b : β} {s : Set α} (h₁ : LeftInverse g f)
(h₂ : RightInverse g f) : b ∈ f '' s ↔ g b ∈ s := by
rw [image_eq_preimage_of_inverse h₁ h₂]; rfl
#align set.mem_image_iff_of_inverse Set.mem_image_iff_of_inverse
theorem image_compl_subset {f : α → β} {s : Set α} (H : Injective f) : f '' sᶜ ⊆ (f '' s)ᶜ :=
Disjoint.subset_compl_left <| by simp [disjoint_iff_inf_le, ← image_inter H]
#align set.image_compl_subset Set.image_compl_subset
theorem subset_image_compl {f : α → β} {s : Set α} (H : Surjective f) : (f '' s)ᶜ ⊆ f '' sᶜ :=
compl_subset_iff_union.2 <| by
rw [← image_union]
simp [image_univ_of_surjective H]
#align set.subset_image_compl Set.subset_image_compl
theorem image_compl_eq {f : α → β} {s : Set α} (H : Bijective f) : f '' sᶜ = (f '' s)ᶜ :=
Subset.antisymm (image_compl_subset H.1) (subset_image_compl H.2)
#align set.image_compl_eq Set.image_compl_eq
theorem subset_image_diff (f : α → β) (s t : Set α) : f '' s \ f '' t ⊆ f '' (s \ t) := by
rw [diff_subset_iff, ← image_union, union_diff_self]
exact image_subset f (subset_union_right t s)
#align set.subset_image_diff Set.subset_image_diff
theorem subset_image_symmDiff : (f '' s) ∆ (f '' t) ⊆ f '' s ∆ t :=
(union_subset_union (subset_image_diff _ _ _) <| subset_image_diff _ _ _).trans
(superset_of_eq (image_union _ _ _))
#align set.subset_image_symm_diff Set.subset_image_symmDiff
theorem image_diff {f : α → β} (hf : Injective f) (s t : Set α) : f '' (s \ t) = f '' s \ f '' t :=
Subset.antisymm
(Subset.trans (image_inter_subset _ _ _) <| inter_subset_inter_right _ <| image_compl_subset hf)
(subset_image_diff f s t)
#align set.image_diff Set.image_diff
theorem image_symmDiff (hf : Injective f) (s t : Set α) : f '' s ∆ t = (f '' s) ∆ (f '' t) := by
simp_rw [Set.symmDiff_def, image_union, image_diff hf]
#align set.image_symm_diff Set.image_symmDiff
theorem Nonempty.image (f : α → β) {s : Set α} : s.Nonempty → (f '' s).Nonempty
| ⟨x, hx⟩ => ⟨f x, mem_image_of_mem f hx⟩
#align set.nonempty.image Set.Nonempty.image
theorem Nonempty.of_image {f : α → β} {s : Set α} : (f '' s).Nonempty → s.Nonempty
| ⟨_, x, hx, _⟩ => ⟨x, hx⟩
#align set.nonempty.of_image Set.Nonempty.of_image
@[simp]
theorem nonempty_image_iff {f : α → β} {s : Set α} : (f '' s).Nonempty ↔ s.Nonempty :=
⟨Nonempty.of_image, fun h => h.image f⟩
#align set.nonempty_image_iff Set.nonempty_image_iff
theorem Nonempty.preimage {s : Set β} (hs : s.Nonempty) {f : α → β} (hf : Surjective f) :
(f ⁻¹' s).Nonempty :=
let ⟨y, hy⟩ := hs
let ⟨x, hx⟩ := hf y
⟨x, mem_preimage.2 <| hx.symm ▸ hy⟩
#align set.nonempty.preimage Set.Nonempty.preimage
instance (f : α → β) (s : Set α) [Nonempty s] : Nonempty (f '' s) :=
(Set.Nonempty.image f nonempty_of_nonempty_subtype).to_subtype
/-- image and preimage are a Galois connection -/
@[simp]
theorem image_subset_iff {s : Set α} {t : Set β} {f : α → β} : f '' s ⊆ t ↔ s ⊆ f ⁻¹' t :=
ball_image_iff
#align set.image_subset_iff Set.image_subset_iff
theorem image_preimage_subset (f : α → β) (s : Set β) : f '' (f ⁻¹' s) ⊆ s :=
image_subset_iff.2 Subset.rfl
#align set.image_preimage_subset Set.image_preimage_subset
theorem subset_preimage_image (f : α → β) (s : Set α) : s ⊆ f ⁻¹' (f '' s) := fun _ =>
mem_image_of_mem f
#align set.subset_preimage_image Set.subset_preimage_image
@[simp]
theorem preimage_image_eq {f : α → β} (s : Set α) (h : Injective f) : f ⁻¹' (f '' s) = s :=
Subset.antisymm (fun _ ⟨_, hy, e⟩ => h e ▸ hy) (subset_preimage_image f s)
#align set.preimage_image_eq Set.preimage_image_eq
@[simp]
theorem image_preimage_eq {f : α → β} (s : Set β) (h : Surjective f) : f '' (f ⁻¹' s) = s :=
Subset.antisymm (image_preimage_subset f s) fun x hx =>
let ⟨y, e⟩ := h x
⟨y, (e.symm ▸ hx : f y ∈ s), e⟩
#align set.image_preimage_eq Set.image_preimage_eq
@[simp]
theorem preimage_eq_preimage {f : β → α} (hf : Surjective f) : f ⁻¹' s = f ⁻¹' t ↔ s = t :=
Iff.intro
fun eq => by rw [← image_preimage_eq s hf, ← image_preimage_eq t hf, eq]
fun eq => eq ▸ rfl
#align set.preimage_eq_preimage Set.preimage_eq_preimage
theorem image_inter_preimage (f : α → β) (s : Set α) (t : Set β) :
f '' (s ∩ f ⁻¹' t) = f '' s ∩ t := by
apply Subset.antisymm
·
|
calc
f '' (s ∩ f ⁻¹' t) ⊆ f '' s ∩ f '' (f ⁻¹' t) := image_inter_subset _ _ _
_ ⊆ f '' s ∩ t := inter_subset_inter_right _ (image_preimage_subset f t)
|
theorem image_inter_preimage (f : α → β) (s : Set α) (t : Set β) :
f '' (s ∩ f ⁻¹' t) = f '' s ∩ t := by
apply Subset.antisymm
·
|
Mathlib.Data.Set.Image.541_0.IJFiTzmYGOCpPSd
|
theorem image_inter_preimage (f : α → β) (s : Set α) (t : Set β) :
f '' (s ∩ f ⁻¹' t) = f '' s ∩ t
|
Mathlib_Data_Set_Image
|
case h₂
α : Type u_1
β : Type u_2
γ : Type u_3
ι : Sort u_4
ι' : Sort u_5
f✝ : α → β
s✝ t✝ : Set α
f : α → β
s : Set α
t : Set β
⊢ f '' s ∩ t ⊆ f '' (s ∩ f ⁻¹' t)
|
/-
Copyright (c) 2014 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Leonardo de Moura
-/
import Mathlib.Data.Set.Basic
#align_import data.set.image from "leanprover-community/mathlib"@"001ffdc42920050657fd45bd2b8bfbec8eaaeb29"
/-!
# Images and preimages of sets
## Main definitions
* `preimage f t : Set α` : the preimage f⁻¹(t) (written `f ⁻¹' t` in Lean) of a subset of β.
* `range f : Set β` : the image of `univ` under `f`.
Also works for `{p : Prop} (f : p → α)` (unlike `image`)
## Notation
* `f ⁻¹' t` for `Set.preimage f t`
* `f '' s` for `Set.image f s`
## Tags
set, sets, image, preimage, pre-image, range
-/
set_option autoImplicit true
universe u v
open Function Set
namespace Set
variable {α β γ : Type*} {ι ι' : Sort*}
/-! ### Inverse image -/
/-- The preimage of `s : Set β` by `f : α → β`, written `f ⁻¹' s`,
is the set of `x : α` such that `f x ∈ s`. -/
def preimage {α : Type u} {β : Type v} (f : α → β) (s : Set β) : Set α :=
{ x | f x ∈ s }
#align set.preimage Set.preimage
/-- `f ⁻¹' t` denotes the preimage of `t : Set β` under the function `f : α → β`. -/
infixl:80 " ⁻¹' " => preimage
section Preimage
variable {f : α → β} {g : β → γ}
@[simp]
theorem preimage_empty : f ⁻¹' ∅ = ∅ :=
rfl
#align set.preimage_empty Set.preimage_empty
@[simp, mfld_simps]
theorem mem_preimage {s : Set β} {a : α} : a ∈ f ⁻¹' s ↔ f a ∈ s :=
Iff.rfl
#align set.mem_preimage Set.mem_preimage
theorem preimage_congr {f g : α → β} {s : Set β} (h : ∀ x : α, f x = g x) : f ⁻¹' s = g ⁻¹' s := by
congr with x
simp [h]
#align set.preimage_congr Set.preimage_congr
@[gcongr]
theorem preimage_mono {s t : Set β} (h : s ⊆ t) : f ⁻¹' s ⊆ f ⁻¹' t := fun _ hx => h hx
#align set.preimage_mono Set.preimage_mono
@[simp, mfld_simps]
theorem preimage_univ : f ⁻¹' univ = univ :=
rfl
#align set.preimage_univ Set.preimage_univ
theorem subset_preimage_univ {s : Set α} : s ⊆ f ⁻¹' univ :=
subset_univ _
#align set.subset_preimage_univ Set.subset_preimage_univ
@[simp, mfld_simps]
theorem preimage_inter {s t : Set β} : f ⁻¹' (s ∩ t) = f ⁻¹' s ∩ f ⁻¹' t :=
rfl
#align set.preimage_inter Set.preimage_inter
@[simp]
theorem preimage_union {s t : Set β} : f ⁻¹' (s ∪ t) = f ⁻¹' s ∪ f ⁻¹' t :=
rfl
#align set.preimage_union Set.preimage_union
@[simp]
theorem preimage_compl {s : Set β} : f ⁻¹' sᶜ = (f ⁻¹' s)ᶜ :=
rfl
#align set.preimage_compl Set.preimage_compl
@[simp]
theorem preimage_diff (f : α → β) (s t : Set β) : f ⁻¹' (s \ t) = f ⁻¹' s \ f ⁻¹' t :=
rfl
#align set.preimage_diff Set.preimage_diff
@[simp]
lemma preimage_symmDiff {f : α → β} (s t : Set β) : f ⁻¹' (s ∆ t) = (f ⁻¹' s) ∆ (f ⁻¹' t) :=
rfl
#align set.preimage_symm_diff Set.preimage_symmDiff
@[simp]
theorem preimage_ite (f : α → β) (s t₁ t₂ : Set β) :
f ⁻¹' s.ite t₁ t₂ = (f ⁻¹' s).ite (f ⁻¹' t₁) (f ⁻¹' t₂) :=
rfl
#align set.preimage_ite Set.preimage_ite
@[simp]
theorem preimage_setOf_eq {p : α → Prop} {f : β → α} : f ⁻¹' { a | p a } = { a | p (f a) } :=
rfl
#align set.preimage_set_of_eq Set.preimage_setOf_eq
@[simp]
theorem preimage_id_eq : preimage (id : α → α) = id :=
rfl
#align set.preimage_id_eq Set.preimage_id_eq
@[mfld_simps]
theorem preimage_id {s : Set α} : id ⁻¹' s = s :=
rfl
#align set.preimage_id Set.preimage_id
@[simp, mfld_simps]
theorem preimage_id' {s : Set α} : (fun x => x) ⁻¹' s = s :=
rfl
#align set.preimage_id' Set.preimage_id'
@[simp]
theorem preimage_const_of_mem {b : β} {s : Set β} (h : b ∈ s) : (fun _ : α => b) ⁻¹' s = univ :=
eq_univ_of_forall fun _ => h
#align set.preimage_const_of_mem Set.preimage_const_of_mem
@[simp]
theorem preimage_const_of_not_mem {b : β} {s : Set β} (h : b ∉ s) : (fun _ : α => b) ⁻¹' s = ∅ :=
eq_empty_of_subset_empty fun _ hx => h hx
#align set.preimage_const_of_not_mem Set.preimage_const_of_not_mem
theorem preimage_const (b : β) (s : Set β) [Decidable (b ∈ s)] :
(fun _ : α => b) ⁻¹' s = if b ∈ s then univ else ∅ := by
split_ifs with hb
exacts [preimage_const_of_mem hb, preimage_const_of_not_mem hb]
#align set.preimage_const Set.preimage_const
/-- If preimage of each singleton under `f : α → β` is either empty or the whole type,
then `f` is a constant. -/
lemma exists_eq_const_of_preimage_singleton [Nonempty β] {f : α → β}
(hf : ∀ b : β, f ⁻¹' {b} = ∅ ∨ f ⁻¹' {b} = univ) : ∃ b, f = const α b := by
rcases em (∃ b, f ⁻¹' {b} = univ) with ⟨b, hb⟩ | hf'
· exact ⟨b, funext fun x ↦ eq_univ_iff_forall.1 hb x⟩
· have : ∀ x b, f x ≠ b := fun x b ↦
eq_empty_iff_forall_not_mem.1 ((hf b).resolve_right fun h ↦ hf' ⟨b, h⟩) x
exact ⟨Classical.arbitrary β, funext fun x ↦ absurd rfl (this x _)⟩
theorem preimage_comp {s : Set γ} : g ∘ f ⁻¹' s = f ⁻¹' (g ⁻¹' s) :=
rfl
#align set.preimage_comp Set.preimage_comp
theorem preimage_comp_eq : preimage (g ∘ f) = preimage f ∘ preimage g :=
rfl
#align set.preimage_comp_eq Set.preimage_comp_eq
theorem preimage_iterate_eq {f : α → α} {n : ℕ} : Set.preimage f^[n] = (Set.preimage f)^[n] := by
induction' n with n ih; · simp
rw [iterate_succ, iterate_succ', preimage_comp_eq, ih]
#align set.preimage_iterate_eq Set.preimage_iterate_eq
theorem preimage_preimage {g : β → γ} {f : α → β} {s : Set γ} :
f ⁻¹' (g ⁻¹' s) = (fun x => g (f x)) ⁻¹' s :=
preimage_comp.symm
#align set.preimage_preimage Set.preimage_preimage
theorem eq_preimage_subtype_val_iff {p : α → Prop} {s : Set (Subtype p)} {t : Set α} :
s = Subtype.val ⁻¹' t ↔ ∀ (x) (h : p x), (⟨x, h⟩ : Subtype p) ∈ s ↔ x ∈ t :=
⟨fun s_eq x h => by
rw [s_eq]
simp, fun h => ext fun ⟨x, hx⟩ => by simp [h]⟩
#align set.eq_preimage_subtype_val_iff Set.eq_preimage_subtype_val_iff
theorem nonempty_of_nonempty_preimage {s : Set β} {f : α → β} (hf : (f ⁻¹' s).Nonempty) :
s.Nonempty :=
let ⟨x, hx⟩ := hf
⟨f x, hx⟩
#align set.nonempty_of_nonempty_preimage Set.nonempty_of_nonempty_preimage
@[simp] theorem preimage_singleton_true (p : α → Prop) : p ⁻¹' {True} = {a | p a} := by ext; simp
#align set.preimage_singleton_true Set.preimage_singleton_true
@[simp] theorem preimage_singleton_false (p : α → Prop) : p ⁻¹' {False} = {a | ¬p a} := by ext; simp
#align set.preimage_singleton_false Set.preimage_singleton_false
theorem preimage_subtype_coe_eq_compl {s u v : Set α} (hsuv : s ⊆ u ∪ v)
(H : s ∩ (u ∩ v) = ∅) : ((↑) : s → α) ⁻¹' u = ((↑) ⁻¹' v)ᶜ := by
ext ⟨x, x_in_s⟩
constructor
· intro x_in_u x_in_v
exact eq_empty_iff_forall_not_mem.mp H x ⟨x_in_s, ⟨x_in_u, x_in_v⟩⟩
· intro hx
exact Or.elim (hsuv x_in_s) id fun hx' => hx.elim hx'
#align set.preimage_subtype_coe_eq_compl Set.preimage_subtype_coe_eq_compl
end Preimage
/-! ### Image of a set under a function -/
section Image
variable {f : α → β} {s t : Set α}
-- Porting note: `Set.image` is already defined in `Init.Set`
#align set.image Set.image
/-- `f '' s` denotes the image of `s : Set α` under the function `f : α → β`. -/
infixl:80 " '' " => image
theorem mem_image_iff_bex {f : α → β} {s : Set α} {y : β} :
y ∈ f '' s ↔ ∃ (x : _) (_ : x ∈ s), f x = y :=
bex_def.symm
#align set.mem_image_iff_bex Set.mem_image_iff_bex
@[simp]
theorem mem_image (f : α → β) (s : Set α) (y : β) : y ∈ f '' s ↔ ∃ x ∈ s, f x = y :=
Iff.rfl
#align set.mem_image Set.mem_image
theorem image_eta (f : α → β) : f '' s = (fun x => f x) '' s :=
rfl
#align set.image_eta Set.image_eta
@[mfld_simps]
theorem mem_image_of_mem (f : α → β) {x : α} {a : Set α} (h : x ∈ a) : f x ∈ f '' a :=
⟨_, h, rfl⟩
#align set.mem_image_of_mem Set.mem_image_of_mem
theorem _root_.Function.Injective.mem_set_image {f : α → β} (hf : Injective f) {s : Set α} {a : α} :
f a ∈ f '' s ↔ a ∈ s :=
⟨fun ⟨_, hb, Eq⟩ => hf Eq ▸ hb, mem_image_of_mem f⟩
#align function.injective.mem_set_image Function.Injective.mem_set_image
theorem ball_image_iff {f : α → β} {s : Set α} {p : β → Prop} :
(∀ y ∈ f '' s, p y) ↔ ∀ x ∈ s, p (f x) := by simp
#align set.ball_image_iff Set.ball_image_iff
theorem ball_image_of_ball {f : α → β} {s : Set α} {p : β → Prop} (h : ∀ x ∈ s, p (f x)) :
∀ y ∈ f '' s, p y :=
ball_image_iff.2 h
#align set.ball_image_of_ball Set.ball_image_of_ball
theorem bex_image_iff {f : α → β} {s : Set α} {p : β → Prop} :
(∃ y ∈ f '' s, p y) ↔ ∃ x ∈ s, p (f x) := by simp
#align set.bex_image_iff Set.bex_image_iff
theorem mem_image_elim {f : α → β} {s : Set α} {C : β → Prop} (h : ∀ x : α, x ∈ s → C (f x)) :
∀ {y : β}, y ∈ f '' s → C y
| _, ⟨a, a_in, rfl⟩ => h a a_in
#align set.mem_image_elim Set.mem_image_elim
theorem mem_image_elim_on {f : α → β} {s : Set α} {C : β → Prop} {y : β} (h_y : y ∈ f '' s)
(h : ∀ x : α, x ∈ s → C (f x)) : C y :=
mem_image_elim h h_y
#align set.mem_image_elim_on Set.mem_image_elim_on
-- Porting note: used to be `safe`
@[congr]
theorem image_congr {f g : α → β} {s : Set α} (h : ∀ a ∈ s, f a = g a) : f '' s = g '' s := by
ext x
rw [mem_image, mem_image]
exact {
mp := by
rintro ⟨a, ha1, ha2⟩
exact ⟨a, ⟨ha1, (h a ha1) ▸ ha2⟩⟩,
mpr := by
rintro ⟨a, ha1, ha2⟩
exact ⟨a, ⟨ha1, (h a ha1) ▸ ha2⟩⟩
}
-- safe [ext_iff, iff_def]
#align set.image_congr Set.image_congr
/-- A common special case of `image_congr` -/
theorem image_congr' {f g : α → β} {s : Set α} (h : ∀ x : α, f x = g x) : f '' s = g '' s :=
image_congr fun x _ => h x
#align set.image_congr' Set.image_congr'
@[gcongr]
lemma image_mono (h : s ⊆ t) : f '' s ⊆ f '' t := by
rintro - ⟨a, ha, rfl⟩; exact mem_image_of_mem f (h ha)
theorem image_comp (f : β → γ) (g : α → β) (a : Set α) : f ∘ g '' a = f '' (g '' a) :=
Subset.antisymm (ball_image_of_ball fun _ ha => mem_image_of_mem _ <| mem_image_of_mem _ ha)
(ball_image_of_ball <| ball_image_of_ball fun _ ha => mem_image_of_mem _ ha)
#align set.image_comp Set.image_comp
theorem image_comp_eq {g : β → γ} : image (g ∘ f) = image g ∘ image f := by ext; simp
/-- A variant of `image_comp`, useful for rewriting -/
theorem image_image (g : β → γ) (f : α → β) (s : Set α) : g '' (f '' s) = (fun x => g (f x)) '' s :=
(image_comp g f s).symm
#align set.image_image Set.image_image
theorem image_comm {β'} {f : β → γ} {g : α → β} {f' : α → β'} {g' : β' → γ}
(h_comm : ∀ a, f (g a) = g' (f' a)) : (s.image g).image f = (s.image f').image g' := by
simp_rw [image_image, h_comm]
#align set.image_comm Set.image_comm
theorem _root_.Function.Semiconj.set_image {f : α → β} {ga : α → α} {gb : β → β}
(h : Function.Semiconj f ga gb) : Function.Semiconj (image f) (image ga) (image gb) := fun _ =>
image_comm h
#align function.semiconj.set_image Function.Semiconj.set_image
theorem _root_.Function.Commute.set_image {f g : α → α} (h : Function.Commute f g) :
Function.Commute (image f) (image g) :=
Function.Semiconj.set_image h
#align function.commute.set_image Function.Commute.set_image
/-- Image is monotone with respect to `⊆`. See `Set.monotone_image` for the statement in
terms of `≤`. -/
@[gcongr]
theorem image_subset {a b : Set α} (f : α → β) (h : a ⊆ b) : f '' a ⊆ f '' b := by
simp only [subset_def, mem_image]
exact fun x => fun ⟨w, h1, h2⟩ => ⟨w, h h1, h2⟩
#align set.image_subset Set.image_subset
/-- `Set.image` is monotone. See `Set.image_subset` for the statement in terms of `⊆`. -/
lemma monotone_image {f : α → β} : Monotone (image f) := fun _ _ => image_subset _
#align set.monotone_image Set.monotone_image
theorem image_union (f : α → β) (s t : Set α) : f '' (s ∪ t) = f '' s ∪ f '' t :=
ext fun x =>
⟨by rintro ⟨a, h | h, rfl⟩ <;> [left; right] <;> exact ⟨_, h, rfl⟩, by
rintro (⟨a, h, rfl⟩ | ⟨a, h, rfl⟩) <;> refine' ⟨_, _, rfl⟩ <;> [left; right] <;> exact h⟩
#align set.image_union Set.image_union
@[simp]
theorem image_empty (f : α → β) : f '' ∅ = ∅ := by
ext
simp
#align set.image_empty Set.image_empty
theorem image_inter_subset (f : α → β) (s t : Set α) : f '' (s ∩ t) ⊆ f '' s ∩ f '' t :=
subset_inter (image_subset _ <| inter_subset_left _ _) (image_subset _ <| inter_subset_right _ _)
#align set.image_inter_subset Set.image_inter_subset
theorem image_inter_on {f : α → β} {s t : Set α} (h : ∀ x ∈ t, ∀ y ∈ s, f x = f y → x = y) :
f '' (s ∩ t) = f '' s ∩ f '' t :=
(image_inter_subset _ _ _).antisymm
fun b ⟨⟨a₁, ha₁, h₁⟩, ⟨a₂, ha₂, h₂⟩⟩ ↦
have : a₂ = a₁ := h _ ha₂ _ ha₁ (by simp [*])
⟨a₁, ⟨ha₁, this ▸ ha₂⟩, h₁⟩
#align set.image_inter_on Set.image_inter_on
theorem image_inter {f : α → β} {s t : Set α} (H : Injective f) : f '' (s ∩ t) = f '' s ∩ f '' t :=
image_inter_on fun _ _ _ _ h => H h
#align set.image_inter Set.image_inter
theorem image_univ_of_surjective {ι : Type*} {f : ι → β} (H : Surjective f) : f '' univ = univ :=
eq_univ_of_forall <| by simpa [image]
#align set.image_univ_of_surjective Set.image_univ_of_surjective
@[simp]
theorem image_singleton {f : α → β} {a : α} : f '' {a} = {f a} := by
ext
simp [image, eq_comm]
#align set.image_singleton Set.image_singleton
@[simp]
theorem Nonempty.image_const {s : Set α} (hs : s.Nonempty) (a : β) : (fun _ => a) '' s = {a} :=
ext fun _ =>
⟨fun ⟨_, _, h⟩ => h ▸ mem_singleton _, fun h =>
(eq_of_mem_singleton h).symm ▸ hs.imp fun _ hy => ⟨hy, rfl⟩⟩
#align set.nonempty.image_const Set.Nonempty.image_const
@[simp, mfld_simps]
theorem image_eq_empty {α β} {f : α → β} {s : Set α} : f '' s = ∅ ↔ s = ∅ := by
simp only [eq_empty_iff_forall_not_mem]
exact ⟨fun H a ha => H _ ⟨_, ha, rfl⟩, fun H b ⟨_, ha, _⟩ => H _ ha⟩
#align set.image_eq_empty Set.image_eq_empty
-- Porting note: `compl` is already defined in `Init.Set`
theorem preimage_compl_eq_image_compl [BooleanAlgebra α] (S : Set α) :
HasCompl.compl ⁻¹' S = HasCompl.compl '' S :=
Set.ext fun x =>
⟨fun h => ⟨xᶜ, h, compl_compl x⟩, fun h =>
Exists.elim h fun _ hy => (compl_eq_comm.mp hy.2).symm.subst hy.1⟩
#align set.preimage_compl_eq_image_compl Set.preimage_compl_eq_image_compl
theorem mem_compl_image [BooleanAlgebra α] (t : α) (S : Set α) :
t ∈ HasCompl.compl '' S ↔ tᶜ ∈ S := by
simp [← preimage_compl_eq_image_compl]
#align set.mem_compl_image Set.mem_compl_image
@[simp]
theorem image_id_eq : image (id : α → α) = id := by ext; simp
/-- A variant of `image_id` -/
@[simp]
theorem image_id' (s : Set α) : (fun x => x) '' s = s := by
ext
simp
#align set.image_id' Set.image_id'
theorem image_id (s : Set α) : id '' s = s := by simp
#align set.image_id Set.image_id
lemma image_iterate_eq {f : α → α} {n : ℕ} : image (f^[n]) = (image f)^[n] := by
induction' n with n ih; · simp
rw [iterate_succ', iterate_succ',← ih, image_comp_eq]
theorem compl_compl_image [BooleanAlgebra α] (S : Set α) :
HasCompl.compl '' (HasCompl.compl '' S) = S := by
rw [← image_comp, compl_comp_compl, image_id]
#align set.compl_compl_image Set.compl_compl_image
theorem image_insert_eq {f : α → β} {a : α} {s : Set α} :
f '' insert a s = insert (f a) (f '' s) := by
ext
simp [and_or_left, exists_or, eq_comm, or_comm, and_comm]
#align set.image_insert_eq Set.image_insert_eq
theorem image_pair (f : α → β) (a b : α) : f '' {a, b} = {f a, f b} := by
simp only [image_insert_eq, image_singleton]
#align set.image_pair Set.image_pair
theorem image_subset_preimage_of_inverse {f : α → β} {g : β → α} (I : LeftInverse g f) (s : Set α) :
f '' s ⊆ g ⁻¹' s := fun _ ⟨a, h, e⟩ => e ▸ ((I a).symm ▸ h : g (f a) ∈ s)
#align set.image_subset_preimage_of_inverse Set.image_subset_preimage_of_inverse
theorem preimage_subset_image_of_inverse {f : α → β} {g : β → α} (I : LeftInverse g f) (s : Set β) :
f ⁻¹' s ⊆ g '' s := fun b h => ⟨f b, h, I b⟩
#align set.preimage_subset_image_of_inverse Set.preimage_subset_image_of_inverse
theorem image_eq_preimage_of_inverse {f : α → β} {g : β → α} (h₁ : LeftInverse g f)
(h₂ : RightInverse g f) : image f = preimage g :=
funext fun s =>
Subset.antisymm (image_subset_preimage_of_inverse h₁ s) (preimage_subset_image_of_inverse h₂ s)
#align set.image_eq_preimage_of_inverse Set.image_eq_preimage_of_inverse
theorem mem_image_iff_of_inverse {f : α → β} {g : β → α} {b : β} {s : Set α} (h₁ : LeftInverse g f)
(h₂ : RightInverse g f) : b ∈ f '' s ↔ g b ∈ s := by
rw [image_eq_preimage_of_inverse h₁ h₂]; rfl
#align set.mem_image_iff_of_inverse Set.mem_image_iff_of_inverse
theorem image_compl_subset {f : α → β} {s : Set α} (H : Injective f) : f '' sᶜ ⊆ (f '' s)ᶜ :=
Disjoint.subset_compl_left <| by simp [disjoint_iff_inf_le, ← image_inter H]
#align set.image_compl_subset Set.image_compl_subset
theorem subset_image_compl {f : α → β} {s : Set α} (H : Surjective f) : (f '' s)ᶜ ⊆ f '' sᶜ :=
compl_subset_iff_union.2 <| by
rw [← image_union]
simp [image_univ_of_surjective H]
#align set.subset_image_compl Set.subset_image_compl
theorem image_compl_eq {f : α → β} {s : Set α} (H : Bijective f) : f '' sᶜ = (f '' s)ᶜ :=
Subset.antisymm (image_compl_subset H.1) (subset_image_compl H.2)
#align set.image_compl_eq Set.image_compl_eq
theorem subset_image_diff (f : α → β) (s t : Set α) : f '' s \ f '' t ⊆ f '' (s \ t) := by
rw [diff_subset_iff, ← image_union, union_diff_self]
exact image_subset f (subset_union_right t s)
#align set.subset_image_diff Set.subset_image_diff
theorem subset_image_symmDiff : (f '' s) ∆ (f '' t) ⊆ f '' s ∆ t :=
(union_subset_union (subset_image_diff _ _ _) <| subset_image_diff _ _ _).trans
(superset_of_eq (image_union _ _ _))
#align set.subset_image_symm_diff Set.subset_image_symmDiff
theorem image_diff {f : α → β} (hf : Injective f) (s t : Set α) : f '' (s \ t) = f '' s \ f '' t :=
Subset.antisymm
(Subset.trans (image_inter_subset _ _ _) <| inter_subset_inter_right _ <| image_compl_subset hf)
(subset_image_diff f s t)
#align set.image_diff Set.image_diff
theorem image_symmDiff (hf : Injective f) (s t : Set α) : f '' s ∆ t = (f '' s) ∆ (f '' t) := by
simp_rw [Set.symmDiff_def, image_union, image_diff hf]
#align set.image_symm_diff Set.image_symmDiff
theorem Nonempty.image (f : α → β) {s : Set α} : s.Nonempty → (f '' s).Nonempty
| ⟨x, hx⟩ => ⟨f x, mem_image_of_mem f hx⟩
#align set.nonempty.image Set.Nonempty.image
theorem Nonempty.of_image {f : α → β} {s : Set α} : (f '' s).Nonempty → s.Nonempty
| ⟨_, x, hx, _⟩ => ⟨x, hx⟩
#align set.nonempty.of_image Set.Nonempty.of_image
@[simp]
theorem nonempty_image_iff {f : α → β} {s : Set α} : (f '' s).Nonempty ↔ s.Nonempty :=
⟨Nonempty.of_image, fun h => h.image f⟩
#align set.nonempty_image_iff Set.nonempty_image_iff
theorem Nonempty.preimage {s : Set β} (hs : s.Nonempty) {f : α → β} (hf : Surjective f) :
(f ⁻¹' s).Nonempty :=
let ⟨y, hy⟩ := hs
let ⟨x, hx⟩ := hf y
⟨x, mem_preimage.2 <| hx.symm ▸ hy⟩
#align set.nonempty.preimage Set.Nonempty.preimage
instance (f : α → β) (s : Set α) [Nonempty s] : Nonempty (f '' s) :=
(Set.Nonempty.image f nonempty_of_nonempty_subtype).to_subtype
/-- image and preimage are a Galois connection -/
@[simp]
theorem image_subset_iff {s : Set α} {t : Set β} {f : α → β} : f '' s ⊆ t ↔ s ⊆ f ⁻¹' t :=
ball_image_iff
#align set.image_subset_iff Set.image_subset_iff
theorem image_preimage_subset (f : α → β) (s : Set β) : f '' (f ⁻¹' s) ⊆ s :=
image_subset_iff.2 Subset.rfl
#align set.image_preimage_subset Set.image_preimage_subset
theorem subset_preimage_image (f : α → β) (s : Set α) : s ⊆ f ⁻¹' (f '' s) := fun _ =>
mem_image_of_mem f
#align set.subset_preimage_image Set.subset_preimage_image
@[simp]
theorem preimage_image_eq {f : α → β} (s : Set α) (h : Injective f) : f ⁻¹' (f '' s) = s :=
Subset.antisymm (fun _ ⟨_, hy, e⟩ => h e ▸ hy) (subset_preimage_image f s)
#align set.preimage_image_eq Set.preimage_image_eq
@[simp]
theorem image_preimage_eq {f : α → β} (s : Set β) (h : Surjective f) : f '' (f ⁻¹' s) = s :=
Subset.antisymm (image_preimage_subset f s) fun x hx =>
let ⟨y, e⟩ := h x
⟨y, (e.symm ▸ hx : f y ∈ s), e⟩
#align set.image_preimage_eq Set.image_preimage_eq
@[simp]
theorem preimage_eq_preimage {f : β → α} (hf : Surjective f) : f ⁻¹' s = f ⁻¹' t ↔ s = t :=
Iff.intro
fun eq => by rw [← image_preimage_eq s hf, ← image_preimage_eq t hf, eq]
fun eq => eq ▸ rfl
#align set.preimage_eq_preimage Set.preimage_eq_preimage
theorem image_inter_preimage (f : α → β) (s : Set α) (t : Set β) :
f '' (s ∩ f ⁻¹' t) = f '' s ∩ t := by
apply Subset.antisymm
· calc
f '' (s ∩ f ⁻¹' t) ⊆ f '' s ∩ f '' (f ⁻¹' t) := image_inter_subset _ _ _
_ ⊆ f '' s ∩ t := inter_subset_inter_right _ (image_preimage_subset f t)
·
|
rintro _ ⟨⟨x, h', rfl⟩, h⟩
|
theorem image_inter_preimage (f : α → β) (s : Set α) (t : Set β) :
f '' (s ∩ f ⁻¹' t) = f '' s ∩ t := by
apply Subset.antisymm
· calc
f '' (s ∩ f ⁻¹' t) ⊆ f '' s ∩ f '' (f ⁻¹' t) := image_inter_subset _ _ _
_ ⊆ f '' s ∩ t := inter_subset_inter_right _ (image_preimage_subset f t)
·
|
Mathlib.Data.Set.Image.541_0.IJFiTzmYGOCpPSd
|
theorem image_inter_preimage (f : α → β) (s : Set α) (t : Set β) :
f '' (s ∩ f ⁻¹' t) = f '' s ∩ t
|
Mathlib_Data_Set_Image
|
case h₂.intro.intro.intro
α : Type u_1
β : Type u_2
γ : Type u_3
ι : Sort u_4
ι' : Sort u_5
f✝ : α → β
s✝ t✝ : Set α
f : α → β
s : Set α
t : Set β
x : α
h' : x ∈ s
h : f x ∈ t
⊢ f x ∈ f '' (s ∩ f ⁻¹' t)
|
/-
Copyright (c) 2014 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Leonardo de Moura
-/
import Mathlib.Data.Set.Basic
#align_import data.set.image from "leanprover-community/mathlib"@"001ffdc42920050657fd45bd2b8bfbec8eaaeb29"
/-!
# Images and preimages of sets
## Main definitions
* `preimage f t : Set α` : the preimage f⁻¹(t) (written `f ⁻¹' t` in Lean) of a subset of β.
* `range f : Set β` : the image of `univ` under `f`.
Also works for `{p : Prop} (f : p → α)` (unlike `image`)
## Notation
* `f ⁻¹' t` for `Set.preimage f t`
* `f '' s` for `Set.image f s`
## Tags
set, sets, image, preimage, pre-image, range
-/
set_option autoImplicit true
universe u v
open Function Set
namespace Set
variable {α β γ : Type*} {ι ι' : Sort*}
/-! ### Inverse image -/
/-- The preimage of `s : Set β` by `f : α → β`, written `f ⁻¹' s`,
is the set of `x : α` such that `f x ∈ s`. -/
def preimage {α : Type u} {β : Type v} (f : α → β) (s : Set β) : Set α :=
{ x | f x ∈ s }
#align set.preimage Set.preimage
/-- `f ⁻¹' t` denotes the preimage of `t : Set β` under the function `f : α → β`. -/
infixl:80 " ⁻¹' " => preimage
section Preimage
variable {f : α → β} {g : β → γ}
@[simp]
theorem preimage_empty : f ⁻¹' ∅ = ∅ :=
rfl
#align set.preimage_empty Set.preimage_empty
@[simp, mfld_simps]
theorem mem_preimage {s : Set β} {a : α} : a ∈ f ⁻¹' s ↔ f a ∈ s :=
Iff.rfl
#align set.mem_preimage Set.mem_preimage
theorem preimage_congr {f g : α → β} {s : Set β} (h : ∀ x : α, f x = g x) : f ⁻¹' s = g ⁻¹' s := by
congr with x
simp [h]
#align set.preimage_congr Set.preimage_congr
@[gcongr]
theorem preimage_mono {s t : Set β} (h : s ⊆ t) : f ⁻¹' s ⊆ f ⁻¹' t := fun _ hx => h hx
#align set.preimage_mono Set.preimage_mono
@[simp, mfld_simps]
theorem preimage_univ : f ⁻¹' univ = univ :=
rfl
#align set.preimage_univ Set.preimage_univ
theorem subset_preimage_univ {s : Set α} : s ⊆ f ⁻¹' univ :=
subset_univ _
#align set.subset_preimage_univ Set.subset_preimage_univ
@[simp, mfld_simps]
theorem preimage_inter {s t : Set β} : f ⁻¹' (s ∩ t) = f ⁻¹' s ∩ f ⁻¹' t :=
rfl
#align set.preimage_inter Set.preimage_inter
@[simp]
theorem preimage_union {s t : Set β} : f ⁻¹' (s ∪ t) = f ⁻¹' s ∪ f ⁻¹' t :=
rfl
#align set.preimage_union Set.preimage_union
@[simp]
theorem preimage_compl {s : Set β} : f ⁻¹' sᶜ = (f ⁻¹' s)ᶜ :=
rfl
#align set.preimage_compl Set.preimage_compl
@[simp]
theorem preimage_diff (f : α → β) (s t : Set β) : f ⁻¹' (s \ t) = f ⁻¹' s \ f ⁻¹' t :=
rfl
#align set.preimage_diff Set.preimage_diff
@[simp]
lemma preimage_symmDiff {f : α → β} (s t : Set β) : f ⁻¹' (s ∆ t) = (f ⁻¹' s) ∆ (f ⁻¹' t) :=
rfl
#align set.preimage_symm_diff Set.preimage_symmDiff
@[simp]
theorem preimage_ite (f : α → β) (s t₁ t₂ : Set β) :
f ⁻¹' s.ite t₁ t₂ = (f ⁻¹' s).ite (f ⁻¹' t₁) (f ⁻¹' t₂) :=
rfl
#align set.preimage_ite Set.preimage_ite
@[simp]
theorem preimage_setOf_eq {p : α → Prop} {f : β → α} : f ⁻¹' { a | p a } = { a | p (f a) } :=
rfl
#align set.preimage_set_of_eq Set.preimage_setOf_eq
@[simp]
theorem preimage_id_eq : preimage (id : α → α) = id :=
rfl
#align set.preimage_id_eq Set.preimage_id_eq
@[mfld_simps]
theorem preimage_id {s : Set α} : id ⁻¹' s = s :=
rfl
#align set.preimage_id Set.preimage_id
@[simp, mfld_simps]
theorem preimage_id' {s : Set α} : (fun x => x) ⁻¹' s = s :=
rfl
#align set.preimage_id' Set.preimage_id'
@[simp]
theorem preimage_const_of_mem {b : β} {s : Set β} (h : b ∈ s) : (fun _ : α => b) ⁻¹' s = univ :=
eq_univ_of_forall fun _ => h
#align set.preimage_const_of_mem Set.preimage_const_of_mem
@[simp]
theorem preimage_const_of_not_mem {b : β} {s : Set β} (h : b ∉ s) : (fun _ : α => b) ⁻¹' s = ∅ :=
eq_empty_of_subset_empty fun _ hx => h hx
#align set.preimage_const_of_not_mem Set.preimage_const_of_not_mem
theorem preimage_const (b : β) (s : Set β) [Decidable (b ∈ s)] :
(fun _ : α => b) ⁻¹' s = if b ∈ s then univ else ∅ := by
split_ifs with hb
exacts [preimage_const_of_mem hb, preimage_const_of_not_mem hb]
#align set.preimage_const Set.preimage_const
/-- If preimage of each singleton under `f : α → β` is either empty or the whole type,
then `f` is a constant. -/
lemma exists_eq_const_of_preimage_singleton [Nonempty β] {f : α → β}
(hf : ∀ b : β, f ⁻¹' {b} = ∅ ∨ f ⁻¹' {b} = univ) : ∃ b, f = const α b := by
rcases em (∃ b, f ⁻¹' {b} = univ) with ⟨b, hb⟩ | hf'
· exact ⟨b, funext fun x ↦ eq_univ_iff_forall.1 hb x⟩
· have : ∀ x b, f x ≠ b := fun x b ↦
eq_empty_iff_forall_not_mem.1 ((hf b).resolve_right fun h ↦ hf' ⟨b, h⟩) x
exact ⟨Classical.arbitrary β, funext fun x ↦ absurd rfl (this x _)⟩
theorem preimage_comp {s : Set γ} : g ∘ f ⁻¹' s = f ⁻¹' (g ⁻¹' s) :=
rfl
#align set.preimage_comp Set.preimage_comp
theorem preimage_comp_eq : preimage (g ∘ f) = preimage f ∘ preimage g :=
rfl
#align set.preimage_comp_eq Set.preimage_comp_eq
theorem preimage_iterate_eq {f : α → α} {n : ℕ} : Set.preimage f^[n] = (Set.preimage f)^[n] := by
induction' n with n ih; · simp
rw [iterate_succ, iterate_succ', preimage_comp_eq, ih]
#align set.preimage_iterate_eq Set.preimage_iterate_eq
theorem preimage_preimage {g : β → γ} {f : α → β} {s : Set γ} :
f ⁻¹' (g ⁻¹' s) = (fun x => g (f x)) ⁻¹' s :=
preimage_comp.symm
#align set.preimage_preimage Set.preimage_preimage
theorem eq_preimage_subtype_val_iff {p : α → Prop} {s : Set (Subtype p)} {t : Set α} :
s = Subtype.val ⁻¹' t ↔ ∀ (x) (h : p x), (⟨x, h⟩ : Subtype p) ∈ s ↔ x ∈ t :=
⟨fun s_eq x h => by
rw [s_eq]
simp, fun h => ext fun ⟨x, hx⟩ => by simp [h]⟩
#align set.eq_preimage_subtype_val_iff Set.eq_preimage_subtype_val_iff
theorem nonempty_of_nonempty_preimage {s : Set β} {f : α → β} (hf : (f ⁻¹' s).Nonempty) :
s.Nonempty :=
let ⟨x, hx⟩ := hf
⟨f x, hx⟩
#align set.nonempty_of_nonempty_preimage Set.nonempty_of_nonempty_preimage
@[simp] theorem preimage_singleton_true (p : α → Prop) : p ⁻¹' {True} = {a | p a} := by ext; simp
#align set.preimage_singleton_true Set.preimage_singleton_true
@[simp] theorem preimage_singleton_false (p : α → Prop) : p ⁻¹' {False} = {a | ¬p a} := by ext; simp
#align set.preimage_singleton_false Set.preimage_singleton_false
theorem preimage_subtype_coe_eq_compl {s u v : Set α} (hsuv : s ⊆ u ∪ v)
(H : s ∩ (u ∩ v) = ∅) : ((↑) : s → α) ⁻¹' u = ((↑) ⁻¹' v)ᶜ := by
ext ⟨x, x_in_s⟩
constructor
· intro x_in_u x_in_v
exact eq_empty_iff_forall_not_mem.mp H x ⟨x_in_s, ⟨x_in_u, x_in_v⟩⟩
· intro hx
exact Or.elim (hsuv x_in_s) id fun hx' => hx.elim hx'
#align set.preimage_subtype_coe_eq_compl Set.preimage_subtype_coe_eq_compl
end Preimage
/-! ### Image of a set under a function -/
section Image
variable {f : α → β} {s t : Set α}
-- Porting note: `Set.image` is already defined in `Init.Set`
#align set.image Set.image
/-- `f '' s` denotes the image of `s : Set α` under the function `f : α → β`. -/
infixl:80 " '' " => image
theorem mem_image_iff_bex {f : α → β} {s : Set α} {y : β} :
y ∈ f '' s ↔ ∃ (x : _) (_ : x ∈ s), f x = y :=
bex_def.symm
#align set.mem_image_iff_bex Set.mem_image_iff_bex
@[simp]
theorem mem_image (f : α → β) (s : Set α) (y : β) : y ∈ f '' s ↔ ∃ x ∈ s, f x = y :=
Iff.rfl
#align set.mem_image Set.mem_image
theorem image_eta (f : α → β) : f '' s = (fun x => f x) '' s :=
rfl
#align set.image_eta Set.image_eta
@[mfld_simps]
theorem mem_image_of_mem (f : α → β) {x : α} {a : Set α} (h : x ∈ a) : f x ∈ f '' a :=
⟨_, h, rfl⟩
#align set.mem_image_of_mem Set.mem_image_of_mem
theorem _root_.Function.Injective.mem_set_image {f : α → β} (hf : Injective f) {s : Set α} {a : α} :
f a ∈ f '' s ↔ a ∈ s :=
⟨fun ⟨_, hb, Eq⟩ => hf Eq ▸ hb, mem_image_of_mem f⟩
#align function.injective.mem_set_image Function.Injective.mem_set_image
theorem ball_image_iff {f : α → β} {s : Set α} {p : β → Prop} :
(∀ y ∈ f '' s, p y) ↔ ∀ x ∈ s, p (f x) := by simp
#align set.ball_image_iff Set.ball_image_iff
theorem ball_image_of_ball {f : α → β} {s : Set α} {p : β → Prop} (h : ∀ x ∈ s, p (f x)) :
∀ y ∈ f '' s, p y :=
ball_image_iff.2 h
#align set.ball_image_of_ball Set.ball_image_of_ball
theorem bex_image_iff {f : α → β} {s : Set α} {p : β → Prop} :
(∃ y ∈ f '' s, p y) ↔ ∃ x ∈ s, p (f x) := by simp
#align set.bex_image_iff Set.bex_image_iff
theorem mem_image_elim {f : α → β} {s : Set α} {C : β → Prop} (h : ∀ x : α, x ∈ s → C (f x)) :
∀ {y : β}, y ∈ f '' s → C y
| _, ⟨a, a_in, rfl⟩ => h a a_in
#align set.mem_image_elim Set.mem_image_elim
theorem mem_image_elim_on {f : α → β} {s : Set α} {C : β → Prop} {y : β} (h_y : y ∈ f '' s)
(h : ∀ x : α, x ∈ s → C (f x)) : C y :=
mem_image_elim h h_y
#align set.mem_image_elim_on Set.mem_image_elim_on
-- Porting note: used to be `safe`
@[congr]
theorem image_congr {f g : α → β} {s : Set α} (h : ∀ a ∈ s, f a = g a) : f '' s = g '' s := by
ext x
rw [mem_image, mem_image]
exact {
mp := by
rintro ⟨a, ha1, ha2⟩
exact ⟨a, ⟨ha1, (h a ha1) ▸ ha2⟩⟩,
mpr := by
rintro ⟨a, ha1, ha2⟩
exact ⟨a, ⟨ha1, (h a ha1) ▸ ha2⟩⟩
}
-- safe [ext_iff, iff_def]
#align set.image_congr Set.image_congr
/-- A common special case of `image_congr` -/
theorem image_congr' {f g : α → β} {s : Set α} (h : ∀ x : α, f x = g x) : f '' s = g '' s :=
image_congr fun x _ => h x
#align set.image_congr' Set.image_congr'
@[gcongr]
lemma image_mono (h : s ⊆ t) : f '' s ⊆ f '' t := by
rintro - ⟨a, ha, rfl⟩; exact mem_image_of_mem f (h ha)
theorem image_comp (f : β → γ) (g : α → β) (a : Set α) : f ∘ g '' a = f '' (g '' a) :=
Subset.antisymm (ball_image_of_ball fun _ ha => mem_image_of_mem _ <| mem_image_of_mem _ ha)
(ball_image_of_ball <| ball_image_of_ball fun _ ha => mem_image_of_mem _ ha)
#align set.image_comp Set.image_comp
theorem image_comp_eq {g : β → γ} : image (g ∘ f) = image g ∘ image f := by ext; simp
/-- A variant of `image_comp`, useful for rewriting -/
theorem image_image (g : β → γ) (f : α → β) (s : Set α) : g '' (f '' s) = (fun x => g (f x)) '' s :=
(image_comp g f s).symm
#align set.image_image Set.image_image
theorem image_comm {β'} {f : β → γ} {g : α → β} {f' : α → β'} {g' : β' → γ}
(h_comm : ∀ a, f (g a) = g' (f' a)) : (s.image g).image f = (s.image f').image g' := by
simp_rw [image_image, h_comm]
#align set.image_comm Set.image_comm
theorem _root_.Function.Semiconj.set_image {f : α → β} {ga : α → α} {gb : β → β}
(h : Function.Semiconj f ga gb) : Function.Semiconj (image f) (image ga) (image gb) := fun _ =>
image_comm h
#align function.semiconj.set_image Function.Semiconj.set_image
theorem _root_.Function.Commute.set_image {f g : α → α} (h : Function.Commute f g) :
Function.Commute (image f) (image g) :=
Function.Semiconj.set_image h
#align function.commute.set_image Function.Commute.set_image
/-- Image is monotone with respect to `⊆`. See `Set.monotone_image` for the statement in
terms of `≤`. -/
@[gcongr]
theorem image_subset {a b : Set α} (f : α → β) (h : a ⊆ b) : f '' a ⊆ f '' b := by
simp only [subset_def, mem_image]
exact fun x => fun ⟨w, h1, h2⟩ => ⟨w, h h1, h2⟩
#align set.image_subset Set.image_subset
/-- `Set.image` is monotone. See `Set.image_subset` for the statement in terms of `⊆`. -/
lemma monotone_image {f : α → β} : Monotone (image f) := fun _ _ => image_subset _
#align set.monotone_image Set.monotone_image
theorem image_union (f : α → β) (s t : Set α) : f '' (s ∪ t) = f '' s ∪ f '' t :=
ext fun x =>
⟨by rintro ⟨a, h | h, rfl⟩ <;> [left; right] <;> exact ⟨_, h, rfl⟩, by
rintro (⟨a, h, rfl⟩ | ⟨a, h, rfl⟩) <;> refine' ⟨_, _, rfl⟩ <;> [left; right] <;> exact h⟩
#align set.image_union Set.image_union
@[simp]
theorem image_empty (f : α → β) : f '' ∅ = ∅ := by
ext
simp
#align set.image_empty Set.image_empty
theorem image_inter_subset (f : α → β) (s t : Set α) : f '' (s ∩ t) ⊆ f '' s ∩ f '' t :=
subset_inter (image_subset _ <| inter_subset_left _ _) (image_subset _ <| inter_subset_right _ _)
#align set.image_inter_subset Set.image_inter_subset
theorem image_inter_on {f : α → β} {s t : Set α} (h : ∀ x ∈ t, ∀ y ∈ s, f x = f y → x = y) :
f '' (s ∩ t) = f '' s ∩ f '' t :=
(image_inter_subset _ _ _).antisymm
fun b ⟨⟨a₁, ha₁, h₁⟩, ⟨a₂, ha₂, h₂⟩⟩ ↦
have : a₂ = a₁ := h _ ha₂ _ ha₁ (by simp [*])
⟨a₁, ⟨ha₁, this ▸ ha₂⟩, h₁⟩
#align set.image_inter_on Set.image_inter_on
theorem image_inter {f : α → β} {s t : Set α} (H : Injective f) : f '' (s ∩ t) = f '' s ∩ f '' t :=
image_inter_on fun _ _ _ _ h => H h
#align set.image_inter Set.image_inter
theorem image_univ_of_surjective {ι : Type*} {f : ι → β} (H : Surjective f) : f '' univ = univ :=
eq_univ_of_forall <| by simpa [image]
#align set.image_univ_of_surjective Set.image_univ_of_surjective
@[simp]
theorem image_singleton {f : α → β} {a : α} : f '' {a} = {f a} := by
ext
simp [image, eq_comm]
#align set.image_singleton Set.image_singleton
@[simp]
theorem Nonempty.image_const {s : Set α} (hs : s.Nonempty) (a : β) : (fun _ => a) '' s = {a} :=
ext fun _ =>
⟨fun ⟨_, _, h⟩ => h ▸ mem_singleton _, fun h =>
(eq_of_mem_singleton h).symm ▸ hs.imp fun _ hy => ⟨hy, rfl⟩⟩
#align set.nonempty.image_const Set.Nonempty.image_const
@[simp, mfld_simps]
theorem image_eq_empty {α β} {f : α → β} {s : Set α} : f '' s = ∅ ↔ s = ∅ := by
simp only [eq_empty_iff_forall_not_mem]
exact ⟨fun H a ha => H _ ⟨_, ha, rfl⟩, fun H b ⟨_, ha, _⟩ => H _ ha⟩
#align set.image_eq_empty Set.image_eq_empty
-- Porting note: `compl` is already defined in `Init.Set`
theorem preimage_compl_eq_image_compl [BooleanAlgebra α] (S : Set α) :
HasCompl.compl ⁻¹' S = HasCompl.compl '' S :=
Set.ext fun x =>
⟨fun h => ⟨xᶜ, h, compl_compl x⟩, fun h =>
Exists.elim h fun _ hy => (compl_eq_comm.mp hy.2).symm.subst hy.1⟩
#align set.preimage_compl_eq_image_compl Set.preimage_compl_eq_image_compl
theorem mem_compl_image [BooleanAlgebra α] (t : α) (S : Set α) :
t ∈ HasCompl.compl '' S ↔ tᶜ ∈ S := by
simp [← preimage_compl_eq_image_compl]
#align set.mem_compl_image Set.mem_compl_image
@[simp]
theorem image_id_eq : image (id : α → α) = id := by ext; simp
/-- A variant of `image_id` -/
@[simp]
theorem image_id' (s : Set α) : (fun x => x) '' s = s := by
ext
simp
#align set.image_id' Set.image_id'
theorem image_id (s : Set α) : id '' s = s := by simp
#align set.image_id Set.image_id
lemma image_iterate_eq {f : α → α} {n : ℕ} : image (f^[n]) = (image f)^[n] := by
induction' n with n ih; · simp
rw [iterate_succ', iterate_succ',← ih, image_comp_eq]
theorem compl_compl_image [BooleanAlgebra α] (S : Set α) :
HasCompl.compl '' (HasCompl.compl '' S) = S := by
rw [← image_comp, compl_comp_compl, image_id]
#align set.compl_compl_image Set.compl_compl_image
theorem image_insert_eq {f : α → β} {a : α} {s : Set α} :
f '' insert a s = insert (f a) (f '' s) := by
ext
simp [and_or_left, exists_or, eq_comm, or_comm, and_comm]
#align set.image_insert_eq Set.image_insert_eq
theorem image_pair (f : α → β) (a b : α) : f '' {a, b} = {f a, f b} := by
simp only [image_insert_eq, image_singleton]
#align set.image_pair Set.image_pair
theorem image_subset_preimage_of_inverse {f : α → β} {g : β → α} (I : LeftInverse g f) (s : Set α) :
f '' s ⊆ g ⁻¹' s := fun _ ⟨a, h, e⟩ => e ▸ ((I a).symm ▸ h : g (f a) ∈ s)
#align set.image_subset_preimage_of_inverse Set.image_subset_preimage_of_inverse
theorem preimage_subset_image_of_inverse {f : α → β} {g : β → α} (I : LeftInverse g f) (s : Set β) :
f ⁻¹' s ⊆ g '' s := fun b h => ⟨f b, h, I b⟩
#align set.preimage_subset_image_of_inverse Set.preimage_subset_image_of_inverse
theorem image_eq_preimage_of_inverse {f : α → β} {g : β → α} (h₁ : LeftInverse g f)
(h₂ : RightInverse g f) : image f = preimage g :=
funext fun s =>
Subset.antisymm (image_subset_preimage_of_inverse h₁ s) (preimage_subset_image_of_inverse h₂ s)
#align set.image_eq_preimage_of_inverse Set.image_eq_preimage_of_inverse
theorem mem_image_iff_of_inverse {f : α → β} {g : β → α} {b : β} {s : Set α} (h₁ : LeftInverse g f)
(h₂ : RightInverse g f) : b ∈ f '' s ↔ g b ∈ s := by
rw [image_eq_preimage_of_inverse h₁ h₂]; rfl
#align set.mem_image_iff_of_inverse Set.mem_image_iff_of_inverse
theorem image_compl_subset {f : α → β} {s : Set α} (H : Injective f) : f '' sᶜ ⊆ (f '' s)ᶜ :=
Disjoint.subset_compl_left <| by simp [disjoint_iff_inf_le, ← image_inter H]
#align set.image_compl_subset Set.image_compl_subset
theorem subset_image_compl {f : α → β} {s : Set α} (H : Surjective f) : (f '' s)ᶜ ⊆ f '' sᶜ :=
compl_subset_iff_union.2 <| by
rw [← image_union]
simp [image_univ_of_surjective H]
#align set.subset_image_compl Set.subset_image_compl
theorem image_compl_eq {f : α → β} {s : Set α} (H : Bijective f) : f '' sᶜ = (f '' s)ᶜ :=
Subset.antisymm (image_compl_subset H.1) (subset_image_compl H.2)
#align set.image_compl_eq Set.image_compl_eq
theorem subset_image_diff (f : α → β) (s t : Set α) : f '' s \ f '' t ⊆ f '' (s \ t) := by
rw [diff_subset_iff, ← image_union, union_diff_self]
exact image_subset f (subset_union_right t s)
#align set.subset_image_diff Set.subset_image_diff
theorem subset_image_symmDiff : (f '' s) ∆ (f '' t) ⊆ f '' s ∆ t :=
(union_subset_union (subset_image_diff _ _ _) <| subset_image_diff _ _ _).trans
(superset_of_eq (image_union _ _ _))
#align set.subset_image_symm_diff Set.subset_image_symmDiff
theorem image_diff {f : α → β} (hf : Injective f) (s t : Set α) : f '' (s \ t) = f '' s \ f '' t :=
Subset.antisymm
(Subset.trans (image_inter_subset _ _ _) <| inter_subset_inter_right _ <| image_compl_subset hf)
(subset_image_diff f s t)
#align set.image_diff Set.image_diff
theorem image_symmDiff (hf : Injective f) (s t : Set α) : f '' s ∆ t = (f '' s) ∆ (f '' t) := by
simp_rw [Set.symmDiff_def, image_union, image_diff hf]
#align set.image_symm_diff Set.image_symmDiff
theorem Nonempty.image (f : α → β) {s : Set α} : s.Nonempty → (f '' s).Nonempty
| ⟨x, hx⟩ => ⟨f x, mem_image_of_mem f hx⟩
#align set.nonempty.image Set.Nonempty.image
theorem Nonempty.of_image {f : α → β} {s : Set α} : (f '' s).Nonempty → s.Nonempty
| ⟨_, x, hx, _⟩ => ⟨x, hx⟩
#align set.nonempty.of_image Set.Nonempty.of_image
@[simp]
theorem nonempty_image_iff {f : α → β} {s : Set α} : (f '' s).Nonempty ↔ s.Nonempty :=
⟨Nonempty.of_image, fun h => h.image f⟩
#align set.nonempty_image_iff Set.nonempty_image_iff
theorem Nonempty.preimage {s : Set β} (hs : s.Nonempty) {f : α → β} (hf : Surjective f) :
(f ⁻¹' s).Nonempty :=
let ⟨y, hy⟩ := hs
let ⟨x, hx⟩ := hf y
⟨x, mem_preimage.2 <| hx.symm ▸ hy⟩
#align set.nonempty.preimage Set.Nonempty.preimage
instance (f : α → β) (s : Set α) [Nonempty s] : Nonempty (f '' s) :=
(Set.Nonempty.image f nonempty_of_nonempty_subtype).to_subtype
/-- image and preimage are a Galois connection -/
@[simp]
theorem image_subset_iff {s : Set α} {t : Set β} {f : α → β} : f '' s ⊆ t ↔ s ⊆ f ⁻¹' t :=
ball_image_iff
#align set.image_subset_iff Set.image_subset_iff
theorem image_preimage_subset (f : α → β) (s : Set β) : f '' (f ⁻¹' s) ⊆ s :=
image_subset_iff.2 Subset.rfl
#align set.image_preimage_subset Set.image_preimage_subset
theorem subset_preimage_image (f : α → β) (s : Set α) : s ⊆ f ⁻¹' (f '' s) := fun _ =>
mem_image_of_mem f
#align set.subset_preimage_image Set.subset_preimage_image
@[simp]
theorem preimage_image_eq {f : α → β} (s : Set α) (h : Injective f) : f ⁻¹' (f '' s) = s :=
Subset.antisymm (fun _ ⟨_, hy, e⟩ => h e ▸ hy) (subset_preimage_image f s)
#align set.preimage_image_eq Set.preimage_image_eq
@[simp]
theorem image_preimage_eq {f : α → β} (s : Set β) (h : Surjective f) : f '' (f ⁻¹' s) = s :=
Subset.antisymm (image_preimage_subset f s) fun x hx =>
let ⟨y, e⟩ := h x
⟨y, (e.symm ▸ hx : f y ∈ s), e⟩
#align set.image_preimage_eq Set.image_preimage_eq
@[simp]
theorem preimage_eq_preimage {f : β → α} (hf : Surjective f) : f ⁻¹' s = f ⁻¹' t ↔ s = t :=
Iff.intro
fun eq => by rw [← image_preimage_eq s hf, ← image_preimage_eq t hf, eq]
fun eq => eq ▸ rfl
#align set.preimage_eq_preimage Set.preimage_eq_preimage
theorem image_inter_preimage (f : α → β) (s : Set α) (t : Set β) :
f '' (s ∩ f ⁻¹' t) = f '' s ∩ t := by
apply Subset.antisymm
· calc
f '' (s ∩ f ⁻¹' t) ⊆ f '' s ∩ f '' (f ⁻¹' t) := image_inter_subset _ _ _
_ ⊆ f '' s ∩ t := inter_subset_inter_right _ (image_preimage_subset f t)
· rintro _ ⟨⟨x, h', rfl⟩, h⟩
|
exact ⟨x, ⟨h', h⟩, rfl⟩
|
theorem image_inter_preimage (f : α → β) (s : Set α) (t : Set β) :
f '' (s ∩ f ⁻¹' t) = f '' s ∩ t := by
apply Subset.antisymm
· calc
f '' (s ∩ f ⁻¹' t) ⊆ f '' s ∩ f '' (f ⁻¹' t) := image_inter_subset _ _ _
_ ⊆ f '' s ∩ t := inter_subset_inter_right _ (image_preimage_subset f t)
· rintro _ ⟨⟨x, h', rfl⟩, h⟩
|
Mathlib.Data.Set.Image.541_0.IJFiTzmYGOCpPSd
|
theorem image_inter_preimage (f : α → β) (s : Set α) (t : Set β) :
f '' (s ∩ f ⁻¹' t) = f '' s ∩ t
|
Mathlib_Data_Set_Image
|
α : Type u_1
β : Type u_2
γ : Type u_3
ι : Sort u_4
ι' : Sort u_5
f✝ : α → β
s✝ t✝ : Set α
f : α → β
s : Set α
t : Set β
⊢ f '' (f ⁻¹' t ∩ s) = t ∩ f '' s
|
/-
Copyright (c) 2014 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Leonardo de Moura
-/
import Mathlib.Data.Set.Basic
#align_import data.set.image from "leanprover-community/mathlib"@"001ffdc42920050657fd45bd2b8bfbec8eaaeb29"
/-!
# Images and preimages of sets
## Main definitions
* `preimage f t : Set α` : the preimage f⁻¹(t) (written `f ⁻¹' t` in Lean) of a subset of β.
* `range f : Set β` : the image of `univ` under `f`.
Also works for `{p : Prop} (f : p → α)` (unlike `image`)
## Notation
* `f ⁻¹' t` for `Set.preimage f t`
* `f '' s` for `Set.image f s`
## Tags
set, sets, image, preimage, pre-image, range
-/
set_option autoImplicit true
universe u v
open Function Set
namespace Set
variable {α β γ : Type*} {ι ι' : Sort*}
/-! ### Inverse image -/
/-- The preimage of `s : Set β` by `f : α → β`, written `f ⁻¹' s`,
is the set of `x : α` such that `f x ∈ s`. -/
def preimage {α : Type u} {β : Type v} (f : α → β) (s : Set β) : Set α :=
{ x | f x ∈ s }
#align set.preimage Set.preimage
/-- `f ⁻¹' t` denotes the preimage of `t : Set β` under the function `f : α → β`. -/
infixl:80 " ⁻¹' " => preimage
section Preimage
variable {f : α → β} {g : β → γ}
@[simp]
theorem preimage_empty : f ⁻¹' ∅ = ∅ :=
rfl
#align set.preimage_empty Set.preimage_empty
@[simp, mfld_simps]
theorem mem_preimage {s : Set β} {a : α} : a ∈ f ⁻¹' s ↔ f a ∈ s :=
Iff.rfl
#align set.mem_preimage Set.mem_preimage
theorem preimage_congr {f g : α → β} {s : Set β} (h : ∀ x : α, f x = g x) : f ⁻¹' s = g ⁻¹' s := by
congr with x
simp [h]
#align set.preimage_congr Set.preimage_congr
@[gcongr]
theorem preimage_mono {s t : Set β} (h : s ⊆ t) : f ⁻¹' s ⊆ f ⁻¹' t := fun _ hx => h hx
#align set.preimage_mono Set.preimage_mono
@[simp, mfld_simps]
theorem preimage_univ : f ⁻¹' univ = univ :=
rfl
#align set.preimage_univ Set.preimage_univ
theorem subset_preimage_univ {s : Set α} : s ⊆ f ⁻¹' univ :=
subset_univ _
#align set.subset_preimage_univ Set.subset_preimage_univ
@[simp, mfld_simps]
theorem preimage_inter {s t : Set β} : f ⁻¹' (s ∩ t) = f ⁻¹' s ∩ f ⁻¹' t :=
rfl
#align set.preimage_inter Set.preimage_inter
@[simp]
theorem preimage_union {s t : Set β} : f ⁻¹' (s ∪ t) = f ⁻¹' s ∪ f ⁻¹' t :=
rfl
#align set.preimage_union Set.preimage_union
@[simp]
theorem preimage_compl {s : Set β} : f ⁻¹' sᶜ = (f ⁻¹' s)ᶜ :=
rfl
#align set.preimage_compl Set.preimage_compl
@[simp]
theorem preimage_diff (f : α → β) (s t : Set β) : f ⁻¹' (s \ t) = f ⁻¹' s \ f ⁻¹' t :=
rfl
#align set.preimage_diff Set.preimage_diff
@[simp]
lemma preimage_symmDiff {f : α → β} (s t : Set β) : f ⁻¹' (s ∆ t) = (f ⁻¹' s) ∆ (f ⁻¹' t) :=
rfl
#align set.preimage_symm_diff Set.preimage_symmDiff
@[simp]
theorem preimage_ite (f : α → β) (s t₁ t₂ : Set β) :
f ⁻¹' s.ite t₁ t₂ = (f ⁻¹' s).ite (f ⁻¹' t₁) (f ⁻¹' t₂) :=
rfl
#align set.preimage_ite Set.preimage_ite
@[simp]
theorem preimage_setOf_eq {p : α → Prop} {f : β → α} : f ⁻¹' { a | p a } = { a | p (f a) } :=
rfl
#align set.preimage_set_of_eq Set.preimage_setOf_eq
@[simp]
theorem preimage_id_eq : preimage (id : α → α) = id :=
rfl
#align set.preimage_id_eq Set.preimage_id_eq
@[mfld_simps]
theorem preimage_id {s : Set α} : id ⁻¹' s = s :=
rfl
#align set.preimage_id Set.preimage_id
@[simp, mfld_simps]
theorem preimage_id' {s : Set α} : (fun x => x) ⁻¹' s = s :=
rfl
#align set.preimage_id' Set.preimage_id'
@[simp]
theorem preimage_const_of_mem {b : β} {s : Set β} (h : b ∈ s) : (fun _ : α => b) ⁻¹' s = univ :=
eq_univ_of_forall fun _ => h
#align set.preimage_const_of_mem Set.preimage_const_of_mem
@[simp]
theorem preimage_const_of_not_mem {b : β} {s : Set β} (h : b ∉ s) : (fun _ : α => b) ⁻¹' s = ∅ :=
eq_empty_of_subset_empty fun _ hx => h hx
#align set.preimage_const_of_not_mem Set.preimage_const_of_not_mem
theorem preimage_const (b : β) (s : Set β) [Decidable (b ∈ s)] :
(fun _ : α => b) ⁻¹' s = if b ∈ s then univ else ∅ := by
split_ifs with hb
exacts [preimage_const_of_mem hb, preimage_const_of_not_mem hb]
#align set.preimage_const Set.preimage_const
/-- If preimage of each singleton under `f : α → β` is either empty or the whole type,
then `f` is a constant. -/
lemma exists_eq_const_of_preimage_singleton [Nonempty β] {f : α → β}
(hf : ∀ b : β, f ⁻¹' {b} = ∅ ∨ f ⁻¹' {b} = univ) : ∃ b, f = const α b := by
rcases em (∃ b, f ⁻¹' {b} = univ) with ⟨b, hb⟩ | hf'
· exact ⟨b, funext fun x ↦ eq_univ_iff_forall.1 hb x⟩
· have : ∀ x b, f x ≠ b := fun x b ↦
eq_empty_iff_forall_not_mem.1 ((hf b).resolve_right fun h ↦ hf' ⟨b, h⟩) x
exact ⟨Classical.arbitrary β, funext fun x ↦ absurd rfl (this x _)⟩
theorem preimage_comp {s : Set γ} : g ∘ f ⁻¹' s = f ⁻¹' (g ⁻¹' s) :=
rfl
#align set.preimage_comp Set.preimage_comp
theorem preimage_comp_eq : preimage (g ∘ f) = preimage f ∘ preimage g :=
rfl
#align set.preimage_comp_eq Set.preimage_comp_eq
theorem preimage_iterate_eq {f : α → α} {n : ℕ} : Set.preimage f^[n] = (Set.preimage f)^[n] := by
induction' n with n ih; · simp
rw [iterate_succ, iterate_succ', preimage_comp_eq, ih]
#align set.preimage_iterate_eq Set.preimage_iterate_eq
theorem preimage_preimage {g : β → γ} {f : α → β} {s : Set γ} :
f ⁻¹' (g ⁻¹' s) = (fun x => g (f x)) ⁻¹' s :=
preimage_comp.symm
#align set.preimage_preimage Set.preimage_preimage
theorem eq_preimage_subtype_val_iff {p : α → Prop} {s : Set (Subtype p)} {t : Set α} :
s = Subtype.val ⁻¹' t ↔ ∀ (x) (h : p x), (⟨x, h⟩ : Subtype p) ∈ s ↔ x ∈ t :=
⟨fun s_eq x h => by
rw [s_eq]
simp, fun h => ext fun ⟨x, hx⟩ => by simp [h]⟩
#align set.eq_preimage_subtype_val_iff Set.eq_preimage_subtype_val_iff
theorem nonempty_of_nonempty_preimage {s : Set β} {f : α → β} (hf : (f ⁻¹' s).Nonempty) :
s.Nonempty :=
let ⟨x, hx⟩ := hf
⟨f x, hx⟩
#align set.nonempty_of_nonempty_preimage Set.nonempty_of_nonempty_preimage
@[simp] theorem preimage_singleton_true (p : α → Prop) : p ⁻¹' {True} = {a | p a} := by ext; simp
#align set.preimage_singleton_true Set.preimage_singleton_true
@[simp] theorem preimage_singleton_false (p : α → Prop) : p ⁻¹' {False} = {a | ¬p a} := by ext; simp
#align set.preimage_singleton_false Set.preimage_singleton_false
theorem preimage_subtype_coe_eq_compl {s u v : Set α} (hsuv : s ⊆ u ∪ v)
(H : s ∩ (u ∩ v) = ∅) : ((↑) : s → α) ⁻¹' u = ((↑) ⁻¹' v)ᶜ := by
ext ⟨x, x_in_s⟩
constructor
· intro x_in_u x_in_v
exact eq_empty_iff_forall_not_mem.mp H x ⟨x_in_s, ⟨x_in_u, x_in_v⟩⟩
· intro hx
exact Or.elim (hsuv x_in_s) id fun hx' => hx.elim hx'
#align set.preimage_subtype_coe_eq_compl Set.preimage_subtype_coe_eq_compl
end Preimage
/-! ### Image of a set under a function -/
section Image
variable {f : α → β} {s t : Set α}
-- Porting note: `Set.image` is already defined in `Init.Set`
#align set.image Set.image
/-- `f '' s` denotes the image of `s : Set α` under the function `f : α → β`. -/
infixl:80 " '' " => image
theorem mem_image_iff_bex {f : α → β} {s : Set α} {y : β} :
y ∈ f '' s ↔ ∃ (x : _) (_ : x ∈ s), f x = y :=
bex_def.symm
#align set.mem_image_iff_bex Set.mem_image_iff_bex
@[simp]
theorem mem_image (f : α → β) (s : Set α) (y : β) : y ∈ f '' s ↔ ∃ x ∈ s, f x = y :=
Iff.rfl
#align set.mem_image Set.mem_image
theorem image_eta (f : α → β) : f '' s = (fun x => f x) '' s :=
rfl
#align set.image_eta Set.image_eta
@[mfld_simps]
theorem mem_image_of_mem (f : α → β) {x : α} {a : Set α} (h : x ∈ a) : f x ∈ f '' a :=
⟨_, h, rfl⟩
#align set.mem_image_of_mem Set.mem_image_of_mem
theorem _root_.Function.Injective.mem_set_image {f : α → β} (hf : Injective f) {s : Set α} {a : α} :
f a ∈ f '' s ↔ a ∈ s :=
⟨fun ⟨_, hb, Eq⟩ => hf Eq ▸ hb, mem_image_of_mem f⟩
#align function.injective.mem_set_image Function.Injective.mem_set_image
theorem ball_image_iff {f : α → β} {s : Set α} {p : β → Prop} :
(∀ y ∈ f '' s, p y) ↔ ∀ x ∈ s, p (f x) := by simp
#align set.ball_image_iff Set.ball_image_iff
theorem ball_image_of_ball {f : α → β} {s : Set α} {p : β → Prop} (h : ∀ x ∈ s, p (f x)) :
∀ y ∈ f '' s, p y :=
ball_image_iff.2 h
#align set.ball_image_of_ball Set.ball_image_of_ball
theorem bex_image_iff {f : α → β} {s : Set α} {p : β → Prop} :
(∃ y ∈ f '' s, p y) ↔ ∃ x ∈ s, p (f x) := by simp
#align set.bex_image_iff Set.bex_image_iff
theorem mem_image_elim {f : α → β} {s : Set α} {C : β → Prop} (h : ∀ x : α, x ∈ s → C (f x)) :
∀ {y : β}, y ∈ f '' s → C y
| _, ⟨a, a_in, rfl⟩ => h a a_in
#align set.mem_image_elim Set.mem_image_elim
theorem mem_image_elim_on {f : α → β} {s : Set α} {C : β → Prop} {y : β} (h_y : y ∈ f '' s)
(h : ∀ x : α, x ∈ s → C (f x)) : C y :=
mem_image_elim h h_y
#align set.mem_image_elim_on Set.mem_image_elim_on
-- Porting note: used to be `safe`
@[congr]
theorem image_congr {f g : α → β} {s : Set α} (h : ∀ a ∈ s, f a = g a) : f '' s = g '' s := by
ext x
rw [mem_image, mem_image]
exact {
mp := by
rintro ⟨a, ha1, ha2⟩
exact ⟨a, ⟨ha1, (h a ha1) ▸ ha2⟩⟩,
mpr := by
rintro ⟨a, ha1, ha2⟩
exact ⟨a, ⟨ha1, (h a ha1) ▸ ha2⟩⟩
}
-- safe [ext_iff, iff_def]
#align set.image_congr Set.image_congr
/-- A common special case of `image_congr` -/
theorem image_congr' {f g : α → β} {s : Set α} (h : ∀ x : α, f x = g x) : f '' s = g '' s :=
image_congr fun x _ => h x
#align set.image_congr' Set.image_congr'
@[gcongr]
lemma image_mono (h : s ⊆ t) : f '' s ⊆ f '' t := by
rintro - ⟨a, ha, rfl⟩; exact mem_image_of_mem f (h ha)
theorem image_comp (f : β → γ) (g : α → β) (a : Set α) : f ∘ g '' a = f '' (g '' a) :=
Subset.antisymm (ball_image_of_ball fun _ ha => mem_image_of_mem _ <| mem_image_of_mem _ ha)
(ball_image_of_ball <| ball_image_of_ball fun _ ha => mem_image_of_mem _ ha)
#align set.image_comp Set.image_comp
theorem image_comp_eq {g : β → γ} : image (g ∘ f) = image g ∘ image f := by ext; simp
/-- A variant of `image_comp`, useful for rewriting -/
theorem image_image (g : β → γ) (f : α → β) (s : Set α) : g '' (f '' s) = (fun x => g (f x)) '' s :=
(image_comp g f s).symm
#align set.image_image Set.image_image
theorem image_comm {β'} {f : β → γ} {g : α → β} {f' : α → β'} {g' : β' → γ}
(h_comm : ∀ a, f (g a) = g' (f' a)) : (s.image g).image f = (s.image f').image g' := by
simp_rw [image_image, h_comm]
#align set.image_comm Set.image_comm
theorem _root_.Function.Semiconj.set_image {f : α → β} {ga : α → α} {gb : β → β}
(h : Function.Semiconj f ga gb) : Function.Semiconj (image f) (image ga) (image gb) := fun _ =>
image_comm h
#align function.semiconj.set_image Function.Semiconj.set_image
theorem _root_.Function.Commute.set_image {f g : α → α} (h : Function.Commute f g) :
Function.Commute (image f) (image g) :=
Function.Semiconj.set_image h
#align function.commute.set_image Function.Commute.set_image
/-- Image is monotone with respect to `⊆`. See `Set.monotone_image` for the statement in
terms of `≤`. -/
@[gcongr]
theorem image_subset {a b : Set α} (f : α → β) (h : a ⊆ b) : f '' a ⊆ f '' b := by
simp only [subset_def, mem_image]
exact fun x => fun ⟨w, h1, h2⟩ => ⟨w, h h1, h2⟩
#align set.image_subset Set.image_subset
/-- `Set.image` is monotone. See `Set.image_subset` for the statement in terms of `⊆`. -/
lemma monotone_image {f : α → β} : Monotone (image f) := fun _ _ => image_subset _
#align set.monotone_image Set.monotone_image
theorem image_union (f : α → β) (s t : Set α) : f '' (s ∪ t) = f '' s ∪ f '' t :=
ext fun x =>
⟨by rintro ⟨a, h | h, rfl⟩ <;> [left; right] <;> exact ⟨_, h, rfl⟩, by
rintro (⟨a, h, rfl⟩ | ⟨a, h, rfl⟩) <;> refine' ⟨_, _, rfl⟩ <;> [left; right] <;> exact h⟩
#align set.image_union Set.image_union
@[simp]
theorem image_empty (f : α → β) : f '' ∅ = ∅ := by
ext
simp
#align set.image_empty Set.image_empty
theorem image_inter_subset (f : α → β) (s t : Set α) : f '' (s ∩ t) ⊆ f '' s ∩ f '' t :=
subset_inter (image_subset _ <| inter_subset_left _ _) (image_subset _ <| inter_subset_right _ _)
#align set.image_inter_subset Set.image_inter_subset
theorem image_inter_on {f : α → β} {s t : Set α} (h : ∀ x ∈ t, ∀ y ∈ s, f x = f y → x = y) :
f '' (s ∩ t) = f '' s ∩ f '' t :=
(image_inter_subset _ _ _).antisymm
fun b ⟨⟨a₁, ha₁, h₁⟩, ⟨a₂, ha₂, h₂⟩⟩ ↦
have : a₂ = a₁ := h _ ha₂ _ ha₁ (by simp [*])
⟨a₁, ⟨ha₁, this ▸ ha₂⟩, h₁⟩
#align set.image_inter_on Set.image_inter_on
theorem image_inter {f : α → β} {s t : Set α} (H : Injective f) : f '' (s ∩ t) = f '' s ∩ f '' t :=
image_inter_on fun _ _ _ _ h => H h
#align set.image_inter Set.image_inter
theorem image_univ_of_surjective {ι : Type*} {f : ι → β} (H : Surjective f) : f '' univ = univ :=
eq_univ_of_forall <| by simpa [image]
#align set.image_univ_of_surjective Set.image_univ_of_surjective
@[simp]
theorem image_singleton {f : α → β} {a : α} : f '' {a} = {f a} := by
ext
simp [image, eq_comm]
#align set.image_singleton Set.image_singleton
@[simp]
theorem Nonempty.image_const {s : Set α} (hs : s.Nonempty) (a : β) : (fun _ => a) '' s = {a} :=
ext fun _ =>
⟨fun ⟨_, _, h⟩ => h ▸ mem_singleton _, fun h =>
(eq_of_mem_singleton h).symm ▸ hs.imp fun _ hy => ⟨hy, rfl⟩⟩
#align set.nonempty.image_const Set.Nonempty.image_const
@[simp, mfld_simps]
theorem image_eq_empty {α β} {f : α → β} {s : Set α} : f '' s = ∅ ↔ s = ∅ := by
simp only [eq_empty_iff_forall_not_mem]
exact ⟨fun H a ha => H _ ⟨_, ha, rfl⟩, fun H b ⟨_, ha, _⟩ => H _ ha⟩
#align set.image_eq_empty Set.image_eq_empty
-- Porting note: `compl` is already defined in `Init.Set`
theorem preimage_compl_eq_image_compl [BooleanAlgebra α] (S : Set α) :
HasCompl.compl ⁻¹' S = HasCompl.compl '' S :=
Set.ext fun x =>
⟨fun h => ⟨xᶜ, h, compl_compl x⟩, fun h =>
Exists.elim h fun _ hy => (compl_eq_comm.mp hy.2).symm.subst hy.1⟩
#align set.preimage_compl_eq_image_compl Set.preimage_compl_eq_image_compl
theorem mem_compl_image [BooleanAlgebra α] (t : α) (S : Set α) :
t ∈ HasCompl.compl '' S ↔ tᶜ ∈ S := by
simp [← preimage_compl_eq_image_compl]
#align set.mem_compl_image Set.mem_compl_image
@[simp]
theorem image_id_eq : image (id : α → α) = id := by ext; simp
/-- A variant of `image_id` -/
@[simp]
theorem image_id' (s : Set α) : (fun x => x) '' s = s := by
ext
simp
#align set.image_id' Set.image_id'
theorem image_id (s : Set α) : id '' s = s := by simp
#align set.image_id Set.image_id
lemma image_iterate_eq {f : α → α} {n : ℕ} : image (f^[n]) = (image f)^[n] := by
induction' n with n ih; · simp
rw [iterate_succ', iterate_succ',← ih, image_comp_eq]
theorem compl_compl_image [BooleanAlgebra α] (S : Set α) :
HasCompl.compl '' (HasCompl.compl '' S) = S := by
rw [← image_comp, compl_comp_compl, image_id]
#align set.compl_compl_image Set.compl_compl_image
theorem image_insert_eq {f : α → β} {a : α} {s : Set α} :
f '' insert a s = insert (f a) (f '' s) := by
ext
simp [and_or_left, exists_or, eq_comm, or_comm, and_comm]
#align set.image_insert_eq Set.image_insert_eq
theorem image_pair (f : α → β) (a b : α) : f '' {a, b} = {f a, f b} := by
simp only [image_insert_eq, image_singleton]
#align set.image_pair Set.image_pair
theorem image_subset_preimage_of_inverse {f : α → β} {g : β → α} (I : LeftInverse g f) (s : Set α) :
f '' s ⊆ g ⁻¹' s := fun _ ⟨a, h, e⟩ => e ▸ ((I a).symm ▸ h : g (f a) ∈ s)
#align set.image_subset_preimage_of_inverse Set.image_subset_preimage_of_inverse
theorem preimage_subset_image_of_inverse {f : α → β} {g : β → α} (I : LeftInverse g f) (s : Set β) :
f ⁻¹' s ⊆ g '' s := fun b h => ⟨f b, h, I b⟩
#align set.preimage_subset_image_of_inverse Set.preimage_subset_image_of_inverse
theorem image_eq_preimage_of_inverse {f : α → β} {g : β → α} (h₁ : LeftInverse g f)
(h₂ : RightInverse g f) : image f = preimage g :=
funext fun s =>
Subset.antisymm (image_subset_preimage_of_inverse h₁ s) (preimage_subset_image_of_inverse h₂ s)
#align set.image_eq_preimage_of_inverse Set.image_eq_preimage_of_inverse
theorem mem_image_iff_of_inverse {f : α → β} {g : β → α} {b : β} {s : Set α} (h₁ : LeftInverse g f)
(h₂ : RightInverse g f) : b ∈ f '' s ↔ g b ∈ s := by
rw [image_eq_preimage_of_inverse h₁ h₂]; rfl
#align set.mem_image_iff_of_inverse Set.mem_image_iff_of_inverse
theorem image_compl_subset {f : α → β} {s : Set α} (H : Injective f) : f '' sᶜ ⊆ (f '' s)ᶜ :=
Disjoint.subset_compl_left <| by simp [disjoint_iff_inf_le, ← image_inter H]
#align set.image_compl_subset Set.image_compl_subset
theorem subset_image_compl {f : α → β} {s : Set α} (H : Surjective f) : (f '' s)ᶜ ⊆ f '' sᶜ :=
compl_subset_iff_union.2 <| by
rw [← image_union]
simp [image_univ_of_surjective H]
#align set.subset_image_compl Set.subset_image_compl
theorem image_compl_eq {f : α → β} {s : Set α} (H : Bijective f) : f '' sᶜ = (f '' s)ᶜ :=
Subset.antisymm (image_compl_subset H.1) (subset_image_compl H.2)
#align set.image_compl_eq Set.image_compl_eq
theorem subset_image_diff (f : α → β) (s t : Set α) : f '' s \ f '' t ⊆ f '' (s \ t) := by
rw [diff_subset_iff, ← image_union, union_diff_self]
exact image_subset f (subset_union_right t s)
#align set.subset_image_diff Set.subset_image_diff
theorem subset_image_symmDiff : (f '' s) ∆ (f '' t) ⊆ f '' s ∆ t :=
(union_subset_union (subset_image_diff _ _ _) <| subset_image_diff _ _ _).trans
(superset_of_eq (image_union _ _ _))
#align set.subset_image_symm_diff Set.subset_image_symmDiff
theorem image_diff {f : α → β} (hf : Injective f) (s t : Set α) : f '' (s \ t) = f '' s \ f '' t :=
Subset.antisymm
(Subset.trans (image_inter_subset _ _ _) <| inter_subset_inter_right _ <| image_compl_subset hf)
(subset_image_diff f s t)
#align set.image_diff Set.image_diff
theorem image_symmDiff (hf : Injective f) (s t : Set α) : f '' s ∆ t = (f '' s) ∆ (f '' t) := by
simp_rw [Set.symmDiff_def, image_union, image_diff hf]
#align set.image_symm_diff Set.image_symmDiff
theorem Nonempty.image (f : α → β) {s : Set α} : s.Nonempty → (f '' s).Nonempty
| ⟨x, hx⟩ => ⟨f x, mem_image_of_mem f hx⟩
#align set.nonempty.image Set.Nonempty.image
theorem Nonempty.of_image {f : α → β} {s : Set α} : (f '' s).Nonempty → s.Nonempty
| ⟨_, x, hx, _⟩ => ⟨x, hx⟩
#align set.nonempty.of_image Set.Nonempty.of_image
@[simp]
theorem nonempty_image_iff {f : α → β} {s : Set α} : (f '' s).Nonempty ↔ s.Nonempty :=
⟨Nonempty.of_image, fun h => h.image f⟩
#align set.nonempty_image_iff Set.nonempty_image_iff
theorem Nonempty.preimage {s : Set β} (hs : s.Nonempty) {f : α → β} (hf : Surjective f) :
(f ⁻¹' s).Nonempty :=
let ⟨y, hy⟩ := hs
let ⟨x, hx⟩ := hf y
⟨x, mem_preimage.2 <| hx.symm ▸ hy⟩
#align set.nonempty.preimage Set.Nonempty.preimage
instance (f : α → β) (s : Set α) [Nonempty s] : Nonempty (f '' s) :=
(Set.Nonempty.image f nonempty_of_nonempty_subtype).to_subtype
/-- image and preimage are a Galois connection -/
@[simp]
theorem image_subset_iff {s : Set α} {t : Set β} {f : α → β} : f '' s ⊆ t ↔ s ⊆ f ⁻¹' t :=
ball_image_iff
#align set.image_subset_iff Set.image_subset_iff
theorem image_preimage_subset (f : α → β) (s : Set β) : f '' (f ⁻¹' s) ⊆ s :=
image_subset_iff.2 Subset.rfl
#align set.image_preimage_subset Set.image_preimage_subset
theorem subset_preimage_image (f : α → β) (s : Set α) : s ⊆ f ⁻¹' (f '' s) := fun _ =>
mem_image_of_mem f
#align set.subset_preimage_image Set.subset_preimage_image
@[simp]
theorem preimage_image_eq {f : α → β} (s : Set α) (h : Injective f) : f ⁻¹' (f '' s) = s :=
Subset.antisymm (fun _ ⟨_, hy, e⟩ => h e ▸ hy) (subset_preimage_image f s)
#align set.preimage_image_eq Set.preimage_image_eq
@[simp]
theorem image_preimage_eq {f : α → β} (s : Set β) (h : Surjective f) : f '' (f ⁻¹' s) = s :=
Subset.antisymm (image_preimage_subset f s) fun x hx =>
let ⟨y, e⟩ := h x
⟨y, (e.symm ▸ hx : f y ∈ s), e⟩
#align set.image_preimage_eq Set.image_preimage_eq
@[simp]
theorem preimage_eq_preimage {f : β → α} (hf : Surjective f) : f ⁻¹' s = f ⁻¹' t ↔ s = t :=
Iff.intro
fun eq => by rw [← image_preimage_eq s hf, ← image_preimage_eq t hf, eq]
fun eq => eq ▸ rfl
#align set.preimage_eq_preimage Set.preimage_eq_preimage
theorem image_inter_preimage (f : α → β) (s : Set α) (t : Set β) :
f '' (s ∩ f ⁻¹' t) = f '' s ∩ t := by
apply Subset.antisymm
· calc
f '' (s ∩ f ⁻¹' t) ⊆ f '' s ∩ f '' (f ⁻¹' t) := image_inter_subset _ _ _
_ ⊆ f '' s ∩ t := inter_subset_inter_right _ (image_preimage_subset f t)
· rintro _ ⟨⟨x, h', rfl⟩, h⟩
exact ⟨x, ⟨h', h⟩, rfl⟩
#align set.image_inter_preimage Set.image_inter_preimage
theorem image_preimage_inter (f : α → β) (s : Set α) (t : Set β) :
f '' (f ⁻¹' t ∩ s) = t ∩ f '' s := by
|
simp only [inter_comm, image_inter_preimage]
|
theorem image_preimage_inter (f : α → β) (s : Set α) (t : Set β) :
f '' (f ⁻¹' t ∩ s) = t ∩ f '' s := by
|
Mathlib.Data.Set.Image.551_0.IJFiTzmYGOCpPSd
|
theorem image_preimage_inter (f : α → β) (s : Set α) (t : Set β) :
f '' (f ⁻¹' t ∩ s) = t ∩ f '' s
|
Mathlib_Data_Set_Image
|
α : Type u_1
β : Type u_2
γ : Type u_3
ι : Sort u_4
ι' : Sort u_5
f✝ : α → β
s✝ t✝ : Set α
f : α → β
s : Set α
t : Set β
⊢ Set.Nonempty (f '' s ∩ t) ↔ Set.Nonempty (s ∩ f ⁻¹' t)
|
/-
Copyright (c) 2014 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Leonardo de Moura
-/
import Mathlib.Data.Set.Basic
#align_import data.set.image from "leanprover-community/mathlib"@"001ffdc42920050657fd45bd2b8bfbec8eaaeb29"
/-!
# Images and preimages of sets
## Main definitions
* `preimage f t : Set α` : the preimage f⁻¹(t) (written `f ⁻¹' t` in Lean) of a subset of β.
* `range f : Set β` : the image of `univ` under `f`.
Also works for `{p : Prop} (f : p → α)` (unlike `image`)
## Notation
* `f ⁻¹' t` for `Set.preimage f t`
* `f '' s` for `Set.image f s`
## Tags
set, sets, image, preimage, pre-image, range
-/
set_option autoImplicit true
universe u v
open Function Set
namespace Set
variable {α β γ : Type*} {ι ι' : Sort*}
/-! ### Inverse image -/
/-- The preimage of `s : Set β` by `f : α → β`, written `f ⁻¹' s`,
is the set of `x : α` such that `f x ∈ s`. -/
def preimage {α : Type u} {β : Type v} (f : α → β) (s : Set β) : Set α :=
{ x | f x ∈ s }
#align set.preimage Set.preimage
/-- `f ⁻¹' t` denotes the preimage of `t : Set β` under the function `f : α → β`. -/
infixl:80 " ⁻¹' " => preimage
section Preimage
variable {f : α → β} {g : β → γ}
@[simp]
theorem preimage_empty : f ⁻¹' ∅ = ∅ :=
rfl
#align set.preimage_empty Set.preimage_empty
@[simp, mfld_simps]
theorem mem_preimage {s : Set β} {a : α} : a ∈ f ⁻¹' s ↔ f a ∈ s :=
Iff.rfl
#align set.mem_preimage Set.mem_preimage
theorem preimage_congr {f g : α → β} {s : Set β} (h : ∀ x : α, f x = g x) : f ⁻¹' s = g ⁻¹' s := by
congr with x
simp [h]
#align set.preimage_congr Set.preimage_congr
@[gcongr]
theorem preimage_mono {s t : Set β} (h : s ⊆ t) : f ⁻¹' s ⊆ f ⁻¹' t := fun _ hx => h hx
#align set.preimage_mono Set.preimage_mono
@[simp, mfld_simps]
theorem preimage_univ : f ⁻¹' univ = univ :=
rfl
#align set.preimage_univ Set.preimage_univ
theorem subset_preimage_univ {s : Set α} : s ⊆ f ⁻¹' univ :=
subset_univ _
#align set.subset_preimage_univ Set.subset_preimage_univ
@[simp, mfld_simps]
theorem preimage_inter {s t : Set β} : f ⁻¹' (s ∩ t) = f ⁻¹' s ∩ f ⁻¹' t :=
rfl
#align set.preimage_inter Set.preimage_inter
@[simp]
theorem preimage_union {s t : Set β} : f ⁻¹' (s ∪ t) = f ⁻¹' s ∪ f ⁻¹' t :=
rfl
#align set.preimage_union Set.preimage_union
@[simp]
theorem preimage_compl {s : Set β} : f ⁻¹' sᶜ = (f ⁻¹' s)ᶜ :=
rfl
#align set.preimage_compl Set.preimage_compl
@[simp]
theorem preimage_diff (f : α → β) (s t : Set β) : f ⁻¹' (s \ t) = f ⁻¹' s \ f ⁻¹' t :=
rfl
#align set.preimage_diff Set.preimage_diff
@[simp]
lemma preimage_symmDiff {f : α → β} (s t : Set β) : f ⁻¹' (s ∆ t) = (f ⁻¹' s) ∆ (f ⁻¹' t) :=
rfl
#align set.preimage_symm_diff Set.preimage_symmDiff
@[simp]
theorem preimage_ite (f : α → β) (s t₁ t₂ : Set β) :
f ⁻¹' s.ite t₁ t₂ = (f ⁻¹' s).ite (f ⁻¹' t₁) (f ⁻¹' t₂) :=
rfl
#align set.preimage_ite Set.preimage_ite
@[simp]
theorem preimage_setOf_eq {p : α → Prop} {f : β → α} : f ⁻¹' { a | p a } = { a | p (f a) } :=
rfl
#align set.preimage_set_of_eq Set.preimage_setOf_eq
@[simp]
theorem preimage_id_eq : preimage (id : α → α) = id :=
rfl
#align set.preimage_id_eq Set.preimage_id_eq
@[mfld_simps]
theorem preimage_id {s : Set α} : id ⁻¹' s = s :=
rfl
#align set.preimage_id Set.preimage_id
@[simp, mfld_simps]
theorem preimage_id' {s : Set α} : (fun x => x) ⁻¹' s = s :=
rfl
#align set.preimage_id' Set.preimage_id'
@[simp]
theorem preimage_const_of_mem {b : β} {s : Set β} (h : b ∈ s) : (fun _ : α => b) ⁻¹' s = univ :=
eq_univ_of_forall fun _ => h
#align set.preimage_const_of_mem Set.preimage_const_of_mem
@[simp]
theorem preimage_const_of_not_mem {b : β} {s : Set β} (h : b ∉ s) : (fun _ : α => b) ⁻¹' s = ∅ :=
eq_empty_of_subset_empty fun _ hx => h hx
#align set.preimage_const_of_not_mem Set.preimage_const_of_not_mem
theorem preimage_const (b : β) (s : Set β) [Decidable (b ∈ s)] :
(fun _ : α => b) ⁻¹' s = if b ∈ s then univ else ∅ := by
split_ifs with hb
exacts [preimage_const_of_mem hb, preimage_const_of_not_mem hb]
#align set.preimage_const Set.preimage_const
/-- If preimage of each singleton under `f : α → β` is either empty or the whole type,
then `f` is a constant. -/
lemma exists_eq_const_of_preimage_singleton [Nonempty β] {f : α → β}
(hf : ∀ b : β, f ⁻¹' {b} = ∅ ∨ f ⁻¹' {b} = univ) : ∃ b, f = const α b := by
rcases em (∃ b, f ⁻¹' {b} = univ) with ⟨b, hb⟩ | hf'
· exact ⟨b, funext fun x ↦ eq_univ_iff_forall.1 hb x⟩
· have : ∀ x b, f x ≠ b := fun x b ↦
eq_empty_iff_forall_not_mem.1 ((hf b).resolve_right fun h ↦ hf' ⟨b, h⟩) x
exact ⟨Classical.arbitrary β, funext fun x ↦ absurd rfl (this x _)⟩
theorem preimage_comp {s : Set γ} : g ∘ f ⁻¹' s = f ⁻¹' (g ⁻¹' s) :=
rfl
#align set.preimage_comp Set.preimage_comp
theorem preimage_comp_eq : preimage (g ∘ f) = preimage f ∘ preimage g :=
rfl
#align set.preimage_comp_eq Set.preimage_comp_eq
theorem preimage_iterate_eq {f : α → α} {n : ℕ} : Set.preimage f^[n] = (Set.preimage f)^[n] := by
induction' n with n ih; · simp
rw [iterate_succ, iterate_succ', preimage_comp_eq, ih]
#align set.preimage_iterate_eq Set.preimage_iterate_eq
theorem preimage_preimage {g : β → γ} {f : α → β} {s : Set γ} :
f ⁻¹' (g ⁻¹' s) = (fun x => g (f x)) ⁻¹' s :=
preimage_comp.symm
#align set.preimage_preimage Set.preimage_preimage
theorem eq_preimage_subtype_val_iff {p : α → Prop} {s : Set (Subtype p)} {t : Set α} :
s = Subtype.val ⁻¹' t ↔ ∀ (x) (h : p x), (⟨x, h⟩ : Subtype p) ∈ s ↔ x ∈ t :=
⟨fun s_eq x h => by
rw [s_eq]
simp, fun h => ext fun ⟨x, hx⟩ => by simp [h]⟩
#align set.eq_preimage_subtype_val_iff Set.eq_preimage_subtype_val_iff
theorem nonempty_of_nonempty_preimage {s : Set β} {f : α → β} (hf : (f ⁻¹' s).Nonempty) :
s.Nonempty :=
let ⟨x, hx⟩ := hf
⟨f x, hx⟩
#align set.nonempty_of_nonempty_preimage Set.nonempty_of_nonempty_preimage
@[simp] theorem preimage_singleton_true (p : α → Prop) : p ⁻¹' {True} = {a | p a} := by ext; simp
#align set.preimage_singleton_true Set.preimage_singleton_true
@[simp] theorem preimage_singleton_false (p : α → Prop) : p ⁻¹' {False} = {a | ¬p a} := by ext; simp
#align set.preimage_singleton_false Set.preimage_singleton_false
theorem preimage_subtype_coe_eq_compl {s u v : Set α} (hsuv : s ⊆ u ∪ v)
(H : s ∩ (u ∩ v) = ∅) : ((↑) : s → α) ⁻¹' u = ((↑) ⁻¹' v)ᶜ := by
ext ⟨x, x_in_s⟩
constructor
· intro x_in_u x_in_v
exact eq_empty_iff_forall_not_mem.mp H x ⟨x_in_s, ⟨x_in_u, x_in_v⟩⟩
· intro hx
exact Or.elim (hsuv x_in_s) id fun hx' => hx.elim hx'
#align set.preimage_subtype_coe_eq_compl Set.preimage_subtype_coe_eq_compl
end Preimage
/-! ### Image of a set under a function -/
section Image
variable {f : α → β} {s t : Set α}
-- Porting note: `Set.image` is already defined in `Init.Set`
#align set.image Set.image
/-- `f '' s` denotes the image of `s : Set α` under the function `f : α → β`. -/
infixl:80 " '' " => image
theorem mem_image_iff_bex {f : α → β} {s : Set α} {y : β} :
y ∈ f '' s ↔ ∃ (x : _) (_ : x ∈ s), f x = y :=
bex_def.symm
#align set.mem_image_iff_bex Set.mem_image_iff_bex
@[simp]
theorem mem_image (f : α → β) (s : Set α) (y : β) : y ∈ f '' s ↔ ∃ x ∈ s, f x = y :=
Iff.rfl
#align set.mem_image Set.mem_image
theorem image_eta (f : α → β) : f '' s = (fun x => f x) '' s :=
rfl
#align set.image_eta Set.image_eta
@[mfld_simps]
theorem mem_image_of_mem (f : α → β) {x : α} {a : Set α} (h : x ∈ a) : f x ∈ f '' a :=
⟨_, h, rfl⟩
#align set.mem_image_of_mem Set.mem_image_of_mem
theorem _root_.Function.Injective.mem_set_image {f : α → β} (hf : Injective f) {s : Set α} {a : α} :
f a ∈ f '' s ↔ a ∈ s :=
⟨fun ⟨_, hb, Eq⟩ => hf Eq ▸ hb, mem_image_of_mem f⟩
#align function.injective.mem_set_image Function.Injective.mem_set_image
theorem ball_image_iff {f : α → β} {s : Set α} {p : β → Prop} :
(∀ y ∈ f '' s, p y) ↔ ∀ x ∈ s, p (f x) := by simp
#align set.ball_image_iff Set.ball_image_iff
theorem ball_image_of_ball {f : α → β} {s : Set α} {p : β → Prop} (h : ∀ x ∈ s, p (f x)) :
∀ y ∈ f '' s, p y :=
ball_image_iff.2 h
#align set.ball_image_of_ball Set.ball_image_of_ball
theorem bex_image_iff {f : α → β} {s : Set α} {p : β → Prop} :
(∃ y ∈ f '' s, p y) ↔ ∃ x ∈ s, p (f x) := by simp
#align set.bex_image_iff Set.bex_image_iff
theorem mem_image_elim {f : α → β} {s : Set α} {C : β → Prop} (h : ∀ x : α, x ∈ s → C (f x)) :
∀ {y : β}, y ∈ f '' s → C y
| _, ⟨a, a_in, rfl⟩ => h a a_in
#align set.mem_image_elim Set.mem_image_elim
theorem mem_image_elim_on {f : α → β} {s : Set α} {C : β → Prop} {y : β} (h_y : y ∈ f '' s)
(h : ∀ x : α, x ∈ s → C (f x)) : C y :=
mem_image_elim h h_y
#align set.mem_image_elim_on Set.mem_image_elim_on
-- Porting note: used to be `safe`
@[congr]
theorem image_congr {f g : α → β} {s : Set α} (h : ∀ a ∈ s, f a = g a) : f '' s = g '' s := by
ext x
rw [mem_image, mem_image]
exact {
mp := by
rintro ⟨a, ha1, ha2⟩
exact ⟨a, ⟨ha1, (h a ha1) ▸ ha2⟩⟩,
mpr := by
rintro ⟨a, ha1, ha2⟩
exact ⟨a, ⟨ha1, (h a ha1) ▸ ha2⟩⟩
}
-- safe [ext_iff, iff_def]
#align set.image_congr Set.image_congr
/-- A common special case of `image_congr` -/
theorem image_congr' {f g : α → β} {s : Set α} (h : ∀ x : α, f x = g x) : f '' s = g '' s :=
image_congr fun x _ => h x
#align set.image_congr' Set.image_congr'
@[gcongr]
lemma image_mono (h : s ⊆ t) : f '' s ⊆ f '' t := by
rintro - ⟨a, ha, rfl⟩; exact mem_image_of_mem f (h ha)
theorem image_comp (f : β → γ) (g : α → β) (a : Set α) : f ∘ g '' a = f '' (g '' a) :=
Subset.antisymm (ball_image_of_ball fun _ ha => mem_image_of_mem _ <| mem_image_of_mem _ ha)
(ball_image_of_ball <| ball_image_of_ball fun _ ha => mem_image_of_mem _ ha)
#align set.image_comp Set.image_comp
theorem image_comp_eq {g : β → γ} : image (g ∘ f) = image g ∘ image f := by ext; simp
/-- A variant of `image_comp`, useful for rewriting -/
theorem image_image (g : β → γ) (f : α → β) (s : Set α) : g '' (f '' s) = (fun x => g (f x)) '' s :=
(image_comp g f s).symm
#align set.image_image Set.image_image
theorem image_comm {β'} {f : β → γ} {g : α → β} {f' : α → β'} {g' : β' → γ}
(h_comm : ∀ a, f (g a) = g' (f' a)) : (s.image g).image f = (s.image f').image g' := by
simp_rw [image_image, h_comm]
#align set.image_comm Set.image_comm
theorem _root_.Function.Semiconj.set_image {f : α → β} {ga : α → α} {gb : β → β}
(h : Function.Semiconj f ga gb) : Function.Semiconj (image f) (image ga) (image gb) := fun _ =>
image_comm h
#align function.semiconj.set_image Function.Semiconj.set_image
theorem _root_.Function.Commute.set_image {f g : α → α} (h : Function.Commute f g) :
Function.Commute (image f) (image g) :=
Function.Semiconj.set_image h
#align function.commute.set_image Function.Commute.set_image
/-- Image is monotone with respect to `⊆`. See `Set.monotone_image` for the statement in
terms of `≤`. -/
@[gcongr]
theorem image_subset {a b : Set α} (f : α → β) (h : a ⊆ b) : f '' a ⊆ f '' b := by
simp only [subset_def, mem_image]
exact fun x => fun ⟨w, h1, h2⟩ => ⟨w, h h1, h2⟩
#align set.image_subset Set.image_subset
/-- `Set.image` is monotone. See `Set.image_subset` for the statement in terms of `⊆`. -/
lemma monotone_image {f : α → β} : Monotone (image f) := fun _ _ => image_subset _
#align set.monotone_image Set.monotone_image
theorem image_union (f : α → β) (s t : Set α) : f '' (s ∪ t) = f '' s ∪ f '' t :=
ext fun x =>
⟨by rintro ⟨a, h | h, rfl⟩ <;> [left; right] <;> exact ⟨_, h, rfl⟩, by
rintro (⟨a, h, rfl⟩ | ⟨a, h, rfl⟩) <;> refine' ⟨_, _, rfl⟩ <;> [left; right] <;> exact h⟩
#align set.image_union Set.image_union
@[simp]
theorem image_empty (f : α → β) : f '' ∅ = ∅ := by
ext
simp
#align set.image_empty Set.image_empty
theorem image_inter_subset (f : α → β) (s t : Set α) : f '' (s ∩ t) ⊆ f '' s ∩ f '' t :=
subset_inter (image_subset _ <| inter_subset_left _ _) (image_subset _ <| inter_subset_right _ _)
#align set.image_inter_subset Set.image_inter_subset
theorem image_inter_on {f : α → β} {s t : Set α} (h : ∀ x ∈ t, ∀ y ∈ s, f x = f y → x = y) :
f '' (s ∩ t) = f '' s ∩ f '' t :=
(image_inter_subset _ _ _).antisymm
fun b ⟨⟨a₁, ha₁, h₁⟩, ⟨a₂, ha₂, h₂⟩⟩ ↦
have : a₂ = a₁ := h _ ha₂ _ ha₁ (by simp [*])
⟨a₁, ⟨ha₁, this ▸ ha₂⟩, h₁⟩
#align set.image_inter_on Set.image_inter_on
theorem image_inter {f : α → β} {s t : Set α} (H : Injective f) : f '' (s ∩ t) = f '' s ∩ f '' t :=
image_inter_on fun _ _ _ _ h => H h
#align set.image_inter Set.image_inter
theorem image_univ_of_surjective {ι : Type*} {f : ι → β} (H : Surjective f) : f '' univ = univ :=
eq_univ_of_forall <| by simpa [image]
#align set.image_univ_of_surjective Set.image_univ_of_surjective
@[simp]
theorem image_singleton {f : α → β} {a : α} : f '' {a} = {f a} := by
ext
simp [image, eq_comm]
#align set.image_singleton Set.image_singleton
@[simp]
theorem Nonempty.image_const {s : Set α} (hs : s.Nonempty) (a : β) : (fun _ => a) '' s = {a} :=
ext fun _ =>
⟨fun ⟨_, _, h⟩ => h ▸ mem_singleton _, fun h =>
(eq_of_mem_singleton h).symm ▸ hs.imp fun _ hy => ⟨hy, rfl⟩⟩
#align set.nonempty.image_const Set.Nonempty.image_const
@[simp, mfld_simps]
theorem image_eq_empty {α β} {f : α → β} {s : Set α} : f '' s = ∅ ↔ s = ∅ := by
simp only [eq_empty_iff_forall_not_mem]
exact ⟨fun H a ha => H _ ⟨_, ha, rfl⟩, fun H b ⟨_, ha, _⟩ => H _ ha⟩
#align set.image_eq_empty Set.image_eq_empty
-- Porting note: `compl` is already defined in `Init.Set`
theorem preimage_compl_eq_image_compl [BooleanAlgebra α] (S : Set α) :
HasCompl.compl ⁻¹' S = HasCompl.compl '' S :=
Set.ext fun x =>
⟨fun h => ⟨xᶜ, h, compl_compl x⟩, fun h =>
Exists.elim h fun _ hy => (compl_eq_comm.mp hy.2).symm.subst hy.1⟩
#align set.preimage_compl_eq_image_compl Set.preimage_compl_eq_image_compl
theorem mem_compl_image [BooleanAlgebra α] (t : α) (S : Set α) :
t ∈ HasCompl.compl '' S ↔ tᶜ ∈ S := by
simp [← preimage_compl_eq_image_compl]
#align set.mem_compl_image Set.mem_compl_image
@[simp]
theorem image_id_eq : image (id : α → α) = id := by ext; simp
/-- A variant of `image_id` -/
@[simp]
theorem image_id' (s : Set α) : (fun x => x) '' s = s := by
ext
simp
#align set.image_id' Set.image_id'
theorem image_id (s : Set α) : id '' s = s := by simp
#align set.image_id Set.image_id
lemma image_iterate_eq {f : α → α} {n : ℕ} : image (f^[n]) = (image f)^[n] := by
induction' n with n ih; · simp
rw [iterate_succ', iterate_succ',← ih, image_comp_eq]
theorem compl_compl_image [BooleanAlgebra α] (S : Set α) :
HasCompl.compl '' (HasCompl.compl '' S) = S := by
rw [← image_comp, compl_comp_compl, image_id]
#align set.compl_compl_image Set.compl_compl_image
theorem image_insert_eq {f : α → β} {a : α} {s : Set α} :
f '' insert a s = insert (f a) (f '' s) := by
ext
simp [and_or_left, exists_or, eq_comm, or_comm, and_comm]
#align set.image_insert_eq Set.image_insert_eq
theorem image_pair (f : α → β) (a b : α) : f '' {a, b} = {f a, f b} := by
simp only [image_insert_eq, image_singleton]
#align set.image_pair Set.image_pair
theorem image_subset_preimage_of_inverse {f : α → β} {g : β → α} (I : LeftInverse g f) (s : Set α) :
f '' s ⊆ g ⁻¹' s := fun _ ⟨a, h, e⟩ => e ▸ ((I a).symm ▸ h : g (f a) ∈ s)
#align set.image_subset_preimage_of_inverse Set.image_subset_preimage_of_inverse
theorem preimage_subset_image_of_inverse {f : α → β} {g : β → α} (I : LeftInverse g f) (s : Set β) :
f ⁻¹' s ⊆ g '' s := fun b h => ⟨f b, h, I b⟩
#align set.preimage_subset_image_of_inverse Set.preimage_subset_image_of_inverse
theorem image_eq_preimage_of_inverse {f : α → β} {g : β → α} (h₁ : LeftInverse g f)
(h₂ : RightInverse g f) : image f = preimage g :=
funext fun s =>
Subset.antisymm (image_subset_preimage_of_inverse h₁ s) (preimage_subset_image_of_inverse h₂ s)
#align set.image_eq_preimage_of_inverse Set.image_eq_preimage_of_inverse
theorem mem_image_iff_of_inverse {f : α → β} {g : β → α} {b : β} {s : Set α} (h₁ : LeftInverse g f)
(h₂ : RightInverse g f) : b ∈ f '' s ↔ g b ∈ s := by
rw [image_eq_preimage_of_inverse h₁ h₂]; rfl
#align set.mem_image_iff_of_inverse Set.mem_image_iff_of_inverse
theorem image_compl_subset {f : α → β} {s : Set α} (H : Injective f) : f '' sᶜ ⊆ (f '' s)ᶜ :=
Disjoint.subset_compl_left <| by simp [disjoint_iff_inf_le, ← image_inter H]
#align set.image_compl_subset Set.image_compl_subset
theorem subset_image_compl {f : α → β} {s : Set α} (H : Surjective f) : (f '' s)ᶜ ⊆ f '' sᶜ :=
compl_subset_iff_union.2 <| by
rw [← image_union]
simp [image_univ_of_surjective H]
#align set.subset_image_compl Set.subset_image_compl
theorem image_compl_eq {f : α → β} {s : Set α} (H : Bijective f) : f '' sᶜ = (f '' s)ᶜ :=
Subset.antisymm (image_compl_subset H.1) (subset_image_compl H.2)
#align set.image_compl_eq Set.image_compl_eq
theorem subset_image_diff (f : α → β) (s t : Set α) : f '' s \ f '' t ⊆ f '' (s \ t) := by
rw [diff_subset_iff, ← image_union, union_diff_self]
exact image_subset f (subset_union_right t s)
#align set.subset_image_diff Set.subset_image_diff
theorem subset_image_symmDiff : (f '' s) ∆ (f '' t) ⊆ f '' s ∆ t :=
(union_subset_union (subset_image_diff _ _ _) <| subset_image_diff _ _ _).trans
(superset_of_eq (image_union _ _ _))
#align set.subset_image_symm_diff Set.subset_image_symmDiff
theorem image_diff {f : α → β} (hf : Injective f) (s t : Set α) : f '' (s \ t) = f '' s \ f '' t :=
Subset.antisymm
(Subset.trans (image_inter_subset _ _ _) <| inter_subset_inter_right _ <| image_compl_subset hf)
(subset_image_diff f s t)
#align set.image_diff Set.image_diff
theorem image_symmDiff (hf : Injective f) (s t : Set α) : f '' s ∆ t = (f '' s) ∆ (f '' t) := by
simp_rw [Set.symmDiff_def, image_union, image_diff hf]
#align set.image_symm_diff Set.image_symmDiff
theorem Nonempty.image (f : α → β) {s : Set α} : s.Nonempty → (f '' s).Nonempty
| ⟨x, hx⟩ => ⟨f x, mem_image_of_mem f hx⟩
#align set.nonempty.image Set.Nonempty.image
theorem Nonempty.of_image {f : α → β} {s : Set α} : (f '' s).Nonempty → s.Nonempty
| ⟨_, x, hx, _⟩ => ⟨x, hx⟩
#align set.nonempty.of_image Set.Nonempty.of_image
@[simp]
theorem nonempty_image_iff {f : α → β} {s : Set α} : (f '' s).Nonempty ↔ s.Nonempty :=
⟨Nonempty.of_image, fun h => h.image f⟩
#align set.nonempty_image_iff Set.nonempty_image_iff
theorem Nonempty.preimage {s : Set β} (hs : s.Nonempty) {f : α → β} (hf : Surjective f) :
(f ⁻¹' s).Nonempty :=
let ⟨y, hy⟩ := hs
let ⟨x, hx⟩ := hf y
⟨x, mem_preimage.2 <| hx.symm ▸ hy⟩
#align set.nonempty.preimage Set.Nonempty.preimage
instance (f : α → β) (s : Set α) [Nonempty s] : Nonempty (f '' s) :=
(Set.Nonempty.image f nonempty_of_nonempty_subtype).to_subtype
/-- image and preimage are a Galois connection -/
@[simp]
theorem image_subset_iff {s : Set α} {t : Set β} {f : α → β} : f '' s ⊆ t ↔ s ⊆ f ⁻¹' t :=
ball_image_iff
#align set.image_subset_iff Set.image_subset_iff
theorem image_preimage_subset (f : α → β) (s : Set β) : f '' (f ⁻¹' s) ⊆ s :=
image_subset_iff.2 Subset.rfl
#align set.image_preimage_subset Set.image_preimage_subset
theorem subset_preimage_image (f : α → β) (s : Set α) : s ⊆ f ⁻¹' (f '' s) := fun _ =>
mem_image_of_mem f
#align set.subset_preimage_image Set.subset_preimage_image
@[simp]
theorem preimage_image_eq {f : α → β} (s : Set α) (h : Injective f) : f ⁻¹' (f '' s) = s :=
Subset.antisymm (fun _ ⟨_, hy, e⟩ => h e ▸ hy) (subset_preimage_image f s)
#align set.preimage_image_eq Set.preimage_image_eq
@[simp]
theorem image_preimage_eq {f : α → β} (s : Set β) (h : Surjective f) : f '' (f ⁻¹' s) = s :=
Subset.antisymm (image_preimage_subset f s) fun x hx =>
let ⟨y, e⟩ := h x
⟨y, (e.symm ▸ hx : f y ∈ s), e⟩
#align set.image_preimage_eq Set.image_preimage_eq
@[simp]
theorem preimage_eq_preimage {f : β → α} (hf : Surjective f) : f ⁻¹' s = f ⁻¹' t ↔ s = t :=
Iff.intro
fun eq => by rw [← image_preimage_eq s hf, ← image_preimage_eq t hf, eq]
fun eq => eq ▸ rfl
#align set.preimage_eq_preimage Set.preimage_eq_preimage
theorem image_inter_preimage (f : α → β) (s : Set α) (t : Set β) :
f '' (s ∩ f ⁻¹' t) = f '' s ∩ t := by
apply Subset.antisymm
· calc
f '' (s ∩ f ⁻¹' t) ⊆ f '' s ∩ f '' (f ⁻¹' t) := image_inter_subset _ _ _
_ ⊆ f '' s ∩ t := inter_subset_inter_right _ (image_preimage_subset f t)
· rintro _ ⟨⟨x, h', rfl⟩, h⟩
exact ⟨x, ⟨h', h⟩, rfl⟩
#align set.image_inter_preimage Set.image_inter_preimage
theorem image_preimage_inter (f : α → β) (s : Set α) (t : Set β) :
f '' (f ⁻¹' t ∩ s) = t ∩ f '' s := by simp only [inter_comm, image_inter_preimage]
#align set.image_preimage_inter Set.image_preimage_inter
@[simp]
theorem image_inter_nonempty_iff {f : α → β} {s : Set α} {t : Set β} :
(f '' s ∩ t).Nonempty ↔ (s ∩ f ⁻¹' t).Nonempty := by
|
rw [← image_inter_preimage, nonempty_image_iff]
|
@[simp]
theorem image_inter_nonempty_iff {f : α → β} {s : Set α} {t : Set β} :
(f '' s ∩ t).Nonempty ↔ (s ∩ f ⁻¹' t).Nonempty := by
|
Mathlib.Data.Set.Image.555_0.IJFiTzmYGOCpPSd
|
@[simp]
theorem image_inter_nonempty_iff {f : α → β} {s : Set α} {t : Set β} :
(f '' s ∩ t).Nonempty ↔ (s ∩ f ⁻¹' t).Nonempty
|
Mathlib_Data_Set_Image
|
α : Type u_1
β : Type u_2
γ : Type u_3
ι : Sort u_4
ι' : Sort u_5
f✝ : α → β
s✝ t✝ : Set α
f : α → β
s : Set α
t : Set β
⊢ f '' (s \ f ⁻¹' t) = f '' s \ t
|
/-
Copyright (c) 2014 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Leonardo de Moura
-/
import Mathlib.Data.Set.Basic
#align_import data.set.image from "leanprover-community/mathlib"@"001ffdc42920050657fd45bd2b8bfbec8eaaeb29"
/-!
# Images and preimages of sets
## Main definitions
* `preimage f t : Set α` : the preimage f⁻¹(t) (written `f ⁻¹' t` in Lean) of a subset of β.
* `range f : Set β` : the image of `univ` under `f`.
Also works for `{p : Prop} (f : p → α)` (unlike `image`)
## Notation
* `f ⁻¹' t` for `Set.preimage f t`
* `f '' s` for `Set.image f s`
## Tags
set, sets, image, preimage, pre-image, range
-/
set_option autoImplicit true
universe u v
open Function Set
namespace Set
variable {α β γ : Type*} {ι ι' : Sort*}
/-! ### Inverse image -/
/-- The preimage of `s : Set β` by `f : α → β`, written `f ⁻¹' s`,
is the set of `x : α` such that `f x ∈ s`. -/
def preimage {α : Type u} {β : Type v} (f : α → β) (s : Set β) : Set α :=
{ x | f x ∈ s }
#align set.preimage Set.preimage
/-- `f ⁻¹' t` denotes the preimage of `t : Set β` under the function `f : α → β`. -/
infixl:80 " ⁻¹' " => preimage
section Preimage
variable {f : α → β} {g : β → γ}
@[simp]
theorem preimage_empty : f ⁻¹' ∅ = ∅ :=
rfl
#align set.preimage_empty Set.preimage_empty
@[simp, mfld_simps]
theorem mem_preimage {s : Set β} {a : α} : a ∈ f ⁻¹' s ↔ f a ∈ s :=
Iff.rfl
#align set.mem_preimage Set.mem_preimage
theorem preimage_congr {f g : α → β} {s : Set β} (h : ∀ x : α, f x = g x) : f ⁻¹' s = g ⁻¹' s := by
congr with x
simp [h]
#align set.preimage_congr Set.preimage_congr
@[gcongr]
theorem preimage_mono {s t : Set β} (h : s ⊆ t) : f ⁻¹' s ⊆ f ⁻¹' t := fun _ hx => h hx
#align set.preimage_mono Set.preimage_mono
@[simp, mfld_simps]
theorem preimage_univ : f ⁻¹' univ = univ :=
rfl
#align set.preimage_univ Set.preimage_univ
theorem subset_preimage_univ {s : Set α} : s ⊆ f ⁻¹' univ :=
subset_univ _
#align set.subset_preimage_univ Set.subset_preimage_univ
@[simp, mfld_simps]
theorem preimage_inter {s t : Set β} : f ⁻¹' (s ∩ t) = f ⁻¹' s ∩ f ⁻¹' t :=
rfl
#align set.preimage_inter Set.preimage_inter
@[simp]
theorem preimage_union {s t : Set β} : f ⁻¹' (s ∪ t) = f ⁻¹' s ∪ f ⁻¹' t :=
rfl
#align set.preimage_union Set.preimage_union
@[simp]
theorem preimage_compl {s : Set β} : f ⁻¹' sᶜ = (f ⁻¹' s)ᶜ :=
rfl
#align set.preimage_compl Set.preimage_compl
@[simp]
theorem preimage_diff (f : α → β) (s t : Set β) : f ⁻¹' (s \ t) = f ⁻¹' s \ f ⁻¹' t :=
rfl
#align set.preimage_diff Set.preimage_diff
@[simp]
lemma preimage_symmDiff {f : α → β} (s t : Set β) : f ⁻¹' (s ∆ t) = (f ⁻¹' s) ∆ (f ⁻¹' t) :=
rfl
#align set.preimage_symm_diff Set.preimage_symmDiff
@[simp]
theorem preimage_ite (f : α → β) (s t₁ t₂ : Set β) :
f ⁻¹' s.ite t₁ t₂ = (f ⁻¹' s).ite (f ⁻¹' t₁) (f ⁻¹' t₂) :=
rfl
#align set.preimage_ite Set.preimage_ite
@[simp]
theorem preimage_setOf_eq {p : α → Prop} {f : β → α} : f ⁻¹' { a | p a } = { a | p (f a) } :=
rfl
#align set.preimage_set_of_eq Set.preimage_setOf_eq
@[simp]
theorem preimage_id_eq : preimage (id : α → α) = id :=
rfl
#align set.preimage_id_eq Set.preimage_id_eq
@[mfld_simps]
theorem preimage_id {s : Set α} : id ⁻¹' s = s :=
rfl
#align set.preimage_id Set.preimage_id
@[simp, mfld_simps]
theorem preimage_id' {s : Set α} : (fun x => x) ⁻¹' s = s :=
rfl
#align set.preimage_id' Set.preimage_id'
@[simp]
theorem preimage_const_of_mem {b : β} {s : Set β} (h : b ∈ s) : (fun _ : α => b) ⁻¹' s = univ :=
eq_univ_of_forall fun _ => h
#align set.preimage_const_of_mem Set.preimage_const_of_mem
@[simp]
theorem preimage_const_of_not_mem {b : β} {s : Set β} (h : b ∉ s) : (fun _ : α => b) ⁻¹' s = ∅ :=
eq_empty_of_subset_empty fun _ hx => h hx
#align set.preimage_const_of_not_mem Set.preimage_const_of_not_mem
theorem preimage_const (b : β) (s : Set β) [Decidable (b ∈ s)] :
(fun _ : α => b) ⁻¹' s = if b ∈ s then univ else ∅ := by
split_ifs with hb
exacts [preimage_const_of_mem hb, preimage_const_of_not_mem hb]
#align set.preimage_const Set.preimage_const
/-- If preimage of each singleton under `f : α → β` is either empty or the whole type,
then `f` is a constant. -/
lemma exists_eq_const_of_preimage_singleton [Nonempty β] {f : α → β}
(hf : ∀ b : β, f ⁻¹' {b} = ∅ ∨ f ⁻¹' {b} = univ) : ∃ b, f = const α b := by
rcases em (∃ b, f ⁻¹' {b} = univ) with ⟨b, hb⟩ | hf'
· exact ⟨b, funext fun x ↦ eq_univ_iff_forall.1 hb x⟩
· have : ∀ x b, f x ≠ b := fun x b ↦
eq_empty_iff_forall_not_mem.1 ((hf b).resolve_right fun h ↦ hf' ⟨b, h⟩) x
exact ⟨Classical.arbitrary β, funext fun x ↦ absurd rfl (this x _)⟩
theorem preimage_comp {s : Set γ} : g ∘ f ⁻¹' s = f ⁻¹' (g ⁻¹' s) :=
rfl
#align set.preimage_comp Set.preimage_comp
theorem preimage_comp_eq : preimage (g ∘ f) = preimage f ∘ preimage g :=
rfl
#align set.preimage_comp_eq Set.preimage_comp_eq
theorem preimage_iterate_eq {f : α → α} {n : ℕ} : Set.preimage f^[n] = (Set.preimage f)^[n] := by
induction' n with n ih; · simp
rw [iterate_succ, iterate_succ', preimage_comp_eq, ih]
#align set.preimage_iterate_eq Set.preimage_iterate_eq
theorem preimage_preimage {g : β → γ} {f : α → β} {s : Set γ} :
f ⁻¹' (g ⁻¹' s) = (fun x => g (f x)) ⁻¹' s :=
preimage_comp.symm
#align set.preimage_preimage Set.preimage_preimage
theorem eq_preimage_subtype_val_iff {p : α → Prop} {s : Set (Subtype p)} {t : Set α} :
s = Subtype.val ⁻¹' t ↔ ∀ (x) (h : p x), (⟨x, h⟩ : Subtype p) ∈ s ↔ x ∈ t :=
⟨fun s_eq x h => by
rw [s_eq]
simp, fun h => ext fun ⟨x, hx⟩ => by simp [h]⟩
#align set.eq_preimage_subtype_val_iff Set.eq_preimage_subtype_val_iff
theorem nonempty_of_nonempty_preimage {s : Set β} {f : α → β} (hf : (f ⁻¹' s).Nonempty) :
s.Nonempty :=
let ⟨x, hx⟩ := hf
⟨f x, hx⟩
#align set.nonempty_of_nonempty_preimage Set.nonempty_of_nonempty_preimage
@[simp] theorem preimage_singleton_true (p : α → Prop) : p ⁻¹' {True} = {a | p a} := by ext; simp
#align set.preimage_singleton_true Set.preimage_singleton_true
@[simp] theorem preimage_singleton_false (p : α → Prop) : p ⁻¹' {False} = {a | ¬p a} := by ext; simp
#align set.preimage_singleton_false Set.preimage_singleton_false
theorem preimage_subtype_coe_eq_compl {s u v : Set α} (hsuv : s ⊆ u ∪ v)
(H : s ∩ (u ∩ v) = ∅) : ((↑) : s → α) ⁻¹' u = ((↑) ⁻¹' v)ᶜ := by
ext ⟨x, x_in_s⟩
constructor
· intro x_in_u x_in_v
exact eq_empty_iff_forall_not_mem.mp H x ⟨x_in_s, ⟨x_in_u, x_in_v⟩⟩
· intro hx
exact Or.elim (hsuv x_in_s) id fun hx' => hx.elim hx'
#align set.preimage_subtype_coe_eq_compl Set.preimage_subtype_coe_eq_compl
end Preimage
/-! ### Image of a set under a function -/
section Image
variable {f : α → β} {s t : Set α}
-- Porting note: `Set.image` is already defined in `Init.Set`
#align set.image Set.image
/-- `f '' s` denotes the image of `s : Set α` under the function `f : α → β`. -/
infixl:80 " '' " => image
theorem mem_image_iff_bex {f : α → β} {s : Set α} {y : β} :
y ∈ f '' s ↔ ∃ (x : _) (_ : x ∈ s), f x = y :=
bex_def.symm
#align set.mem_image_iff_bex Set.mem_image_iff_bex
@[simp]
theorem mem_image (f : α → β) (s : Set α) (y : β) : y ∈ f '' s ↔ ∃ x ∈ s, f x = y :=
Iff.rfl
#align set.mem_image Set.mem_image
theorem image_eta (f : α → β) : f '' s = (fun x => f x) '' s :=
rfl
#align set.image_eta Set.image_eta
@[mfld_simps]
theorem mem_image_of_mem (f : α → β) {x : α} {a : Set α} (h : x ∈ a) : f x ∈ f '' a :=
⟨_, h, rfl⟩
#align set.mem_image_of_mem Set.mem_image_of_mem
theorem _root_.Function.Injective.mem_set_image {f : α → β} (hf : Injective f) {s : Set α} {a : α} :
f a ∈ f '' s ↔ a ∈ s :=
⟨fun ⟨_, hb, Eq⟩ => hf Eq ▸ hb, mem_image_of_mem f⟩
#align function.injective.mem_set_image Function.Injective.mem_set_image
theorem ball_image_iff {f : α → β} {s : Set α} {p : β → Prop} :
(∀ y ∈ f '' s, p y) ↔ ∀ x ∈ s, p (f x) := by simp
#align set.ball_image_iff Set.ball_image_iff
theorem ball_image_of_ball {f : α → β} {s : Set α} {p : β → Prop} (h : ∀ x ∈ s, p (f x)) :
∀ y ∈ f '' s, p y :=
ball_image_iff.2 h
#align set.ball_image_of_ball Set.ball_image_of_ball
theorem bex_image_iff {f : α → β} {s : Set α} {p : β → Prop} :
(∃ y ∈ f '' s, p y) ↔ ∃ x ∈ s, p (f x) := by simp
#align set.bex_image_iff Set.bex_image_iff
theorem mem_image_elim {f : α → β} {s : Set α} {C : β → Prop} (h : ∀ x : α, x ∈ s → C (f x)) :
∀ {y : β}, y ∈ f '' s → C y
| _, ⟨a, a_in, rfl⟩ => h a a_in
#align set.mem_image_elim Set.mem_image_elim
theorem mem_image_elim_on {f : α → β} {s : Set α} {C : β → Prop} {y : β} (h_y : y ∈ f '' s)
(h : ∀ x : α, x ∈ s → C (f x)) : C y :=
mem_image_elim h h_y
#align set.mem_image_elim_on Set.mem_image_elim_on
-- Porting note: used to be `safe`
@[congr]
theorem image_congr {f g : α → β} {s : Set α} (h : ∀ a ∈ s, f a = g a) : f '' s = g '' s := by
ext x
rw [mem_image, mem_image]
exact {
mp := by
rintro ⟨a, ha1, ha2⟩
exact ⟨a, ⟨ha1, (h a ha1) ▸ ha2⟩⟩,
mpr := by
rintro ⟨a, ha1, ha2⟩
exact ⟨a, ⟨ha1, (h a ha1) ▸ ha2⟩⟩
}
-- safe [ext_iff, iff_def]
#align set.image_congr Set.image_congr
/-- A common special case of `image_congr` -/
theorem image_congr' {f g : α → β} {s : Set α} (h : ∀ x : α, f x = g x) : f '' s = g '' s :=
image_congr fun x _ => h x
#align set.image_congr' Set.image_congr'
@[gcongr]
lemma image_mono (h : s ⊆ t) : f '' s ⊆ f '' t := by
rintro - ⟨a, ha, rfl⟩; exact mem_image_of_mem f (h ha)
theorem image_comp (f : β → γ) (g : α → β) (a : Set α) : f ∘ g '' a = f '' (g '' a) :=
Subset.antisymm (ball_image_of_ball fun _ ha => mem_image_of_mem _ <| mem_image_of_mem _ ha)
(ball_image_of_ball <| ball_image_of_ball fun _ ha => mem_image_of_mem _ ha)
#align set.image_comp Set.image_comp
theorem image_comp_eq {g : β → γ} : image (g ∘ f) = image g ∘ image f := by ext; simp
/-- A variant of `image_comp`, useful for rewriting -/
theorem image_image (g : β → γ) (f : α → β) (s : Set α) : g '' (f '' s) = (fun x => g (f x)) '' s :=
(image_comp g f s).symm
#align set.image_image Set.image_image
theorem image_comm {β'} {f : β → γ} {g : α → β} {f' : α → β'} {g' : β' → γ}
(h_comm : ∀ a, f (g a) = g' (f' a)) : (s.image g).image f = (s.image f').image g' := by
simp_rw [image_image, h_comm]
#align set.image_comm Set.image_comm
theorem _root_.Function.Semiconj.set_image {f : α → β} {ga : α → α} {gb : β → β}
(h : Function.Semiconj f ga gb) : Function.Semiconj (image f) (image ga) (image gb) := fun _ =>
image_comm h
#align function.semiconj.set_image Function.Semiconj.set_image
theorem _root_.Function.Commute.set_image {f g : α → α} (h : Function.Commute f g) :
Function.Commute (image f) (image g) :=
Function.Semiconj.set_image h
#align function.commute.set_image Function.Commute.set_image
/-- Image is monotone with respect to `⊆`. See `Set.monotone_image` for the statement in
terms of `≤`. -/
@[gcongr]
theorem image_subset {a b : Set α} (f : α → β) (h : a ⊆ b) : f '' a ⊆ f '' b := by
simp only [subset_def, mem_image]
exact fun x => fun ⟨w, h1, h2⟩ => ⟨w, h h1, h2⟩
#align set.image_subset Set.image_subset
/-- `Set.image` is monotone. See `Set.image_subset` for the statement in terms of `⊆`. -/
lemma monotone_image {f : α → β} : Monotone (image f) := fun _ _ => image_subset _
#align set.monotone_image Set.monotone_image
theorem image_union (f : α → β) (s t : Set α) : f '' (s ∪ t) = f '' s ∪ f '' t :=
ext fun x =>
⟨by rintro ⟨a, h | h, rfl⟩ <;> [left; right] <;> exact ⟨_, h, rfl⟩, by
rintro (⟨a, h, rfl⟩ | ⟨a, h, rfl⟩) <;> refine' ⟨_, _, rfl⟩ <;> [left; right] <;> exact h⟩
#align set.image_union Set.image_union
@[simp]
theorem image_empty (f : α → β) : f '' ∅ = ∅ := by
ext
simp
#align set.image_empty Set.image_empty
theorem image_inter_subset (f : α → β) (s t : Set α) : f '' (s ∩ t) ⊆ f '' s ∩ f '' t :=
subset_inter (image_subset _ <| inter_subset_left _ _) (image_subset _ <| inter_subset_right _ _)
#align set.image_inter_subset Set.image_inter_subset
theorem image_inter_on {f : α → β} {s t : Set α} (h : ∀ x ∈ t, ∀ y ∈ s, f x = f y → x = y) :
f '' (s ∩ t) = f '' s ∩ f '' t :=
(image_inter_subset _ _ _).antisymm
fun b ⟨⟨a₁, ha₁, h₁⟩, ⟨a₂, ha₂, h₂⟩⟩ ↦
have : a₂ = a₁ := h _ ha₂ _ ha₁ (by simp [*])
⟨a₁, ⟨ha₁, this ▸ ha₂⟩, h₁⟩
#align set.image_inter_on Set.image_inter_on
theorem image_inter {f : α → β} {s t : Set α} (H : Injective f) : f '' (s ∩ t) = f '' s ∩ f '' t :=
image_inter_on fun _ _ _ _ h => H h
#align set.image_inter Set.image_inter
theorem image_univ_of_surjective {ι : Type*} {f : ι → β} (H : Surjective f) : f '' univ = univ :=
eq_univ_of_forall <| by simpa [image]
#align set.image_univ_of_surjective Set.image_univ_of_surjective
@[simp]
theorem image_singleton {f : α → β} {a : α} : f '' {a} = {f a} := by
ext
simp [image, eq_comm]
#align set.image_singleton Set.image_singleton
@[simp]
theorem Nonempty.image_const {s : Set α} (hs : s.Nonempty) (a : β) : (fun _ => a) '' s = {a} :=
ext fun _ =>
⟨fun ⟨_, _, h⟩ => h ▸ mem_singleton _, fun h =>
(eq_of_mem_singleton h).symm ▸ hs.imp fun _ hy => ⟨hy, rfl⟩⟩
#align set.nonempty.image_const Set.Nonempty.image_const
@[simp, mfld_simps]
theorem image_eq_empty {α β} {f : α → β} {s : Set α} : f '' s = ∅ ↔ s = ∅ := by
simp only [eq_empty_iff_forall_not_mem]
exact ⟨fun H a ha => H _ ⟨_, ha, rfl⟩, fun H b ⟨_, ha, _⟩ => H _ ha⟩
#align set.image_eq_empty Set.image_eq_empty
-- Porting note: `compl` is already defined in `Init.Set`
theorem preimage_compl_eq_image_compl [BooleanAlgebra α] (S : Set α) :
HasCompl.compl ⁻¹' S = HasCompl.compl '' S :=
Set.ext fun x =>
⟨fun h => ⟨xᶜ, h, compl_compl x⟩, fun h =>
Exists.elim h fun _ hy => (compl_eq_comm.mp hy.2).symm.subst hy.1⟩
#align set.preimage_compl_eq_image_compl Set.preimage_compl_eq_image_compl
theorem mem_compl_image [BooleanAlgebra α] (t : α) (S : Set α) :
t ∈ HasCompl.compl '' S ↔ tᶜ ∈ S := by
simp [← preimage_compl_eq_image_compl]
#align set.mem_compl_image Set.mem_compl_image
@[simp]
theorem image_id_eq : image (id : α → α) = id := by ext; simp
/-- A variant of `image_id` -/
@[simp]
theorem image_id' (s : Set α) : (fun x => x) '' s = s := by
ext
simp
#align set.image_id' Set.image_id'
theorem image_id (s : Set α) : id '' s = s := by simp
#align set.image_id Set.image_id
lemma image_iterate_eq {f : α → α} {n : ℕ} : image (f^[n]) = (image f)^[n] := by
induction' n with n ih; · simp
rw [iterate_succ', iterate_succ',← ih, image_comp_eq]
theorem compl_compl_image [BooleanAlgebra α] (S : Set α) :
HasCompl.compl '' (HasCompl.compl '' S) = S := by
rw [← image_comp, compl_comp_compl, image_id]
#align set.compl_compl_image Set.compl_compl_image
theorem image_insert_eq {f : α → β} {a : α} {s : Set α} :
f '' insert a s = insert (f a) (f '' s) := by
ext
simp [and_or_left, exists_or, eq_comm, or_comm, and_comm]
#align set.image_insert_eq Set.image_insert_eq
theorem image_pair (f : α → β) (a b : α) : f '' {a, b} = {f a, f b} := by
simp only [image_insert_eq, image_singleton]
#align set.image_pair Set.image_pair
theorem image_subset_preimage_of_inverse {f : α → β} {g : β → α} (I : LeftInverse g f) (s : Set α) :
f '' s ⊆ g ⁻¹' s := fun _ ⟨a, h, e⟩ => e ▸ ((I a).symm ▸ h : g (f a) ∈ s)
#align set.image_subset_preimage_of_inverse Set.image_subset_preimage_of_inverse
theorem preimage_subset_image_of_inverse {f : α → β} {g : β → α} (I : LeftInverse g f) (s : Set β) :
f ⁻¹' s ⊆ g '' s := fun b h => ⟨f b, h, I b⟩
#align set.preimage_subset_image_of_inverse Set.preimage_subset_image_of_inverse
theorem image_eq_preimage_of_inverse {f : α → β} {g : β → α} (h₁ : LeftInverse g f)
(h₂ : RightInverse g f) : image f = preimage g :=
funext fun s =>
Subset.antisymm (image_subset_preimage_of_inverse h₁ s) (preimage_subset_image_of_inverse h₂ s)
#align set.image_eq_preimage_of_inverse Set.image_eq_preimage_of_inverse
theorem mem_image_iff_of_inverse {f : α → β} {g : β → α} {b : β} {s : Set α} (h₁ : LeftInverse g f)
(h₂ : RightInverse g f) : b ∈ f '' s ↔ g b ∈ s := by
rw [image_eq_preimage_of_inverse h₁ h₂]; rfl
#align set.mem_image_iff_of_inverse Set.mem_image_iff_of_inverse
theorem image_compl_subset {f : α → β} {s : Set α} (H : Injective f) : f '' sᶜ ⊆ (f '' s)ᶜ :=
Disjoint.subset_compl_left <| by simp [disjoint_iff_inf_le, ← image_inter H]
#align set.image_compl_subset Set.image_compl_subset
theorem subset_image_compl {f : α → β} {s : Set α} (H : Surjective f) : (f '' s)ᶜ ⊆ f '' sᶜ :=
compl_subset_iff_union.2 <| by
rw [← image_union]
simp [image_univ_of_surjective H]
#align set.subset_image_compl Set.subset_image_compl
theorem image_compl_eq {f : α → β} {s : Set α} (H : Bijective f) : f '' sᶜ = (f '' s)ᶜ :=
Subset.antisymm (image_compl_subset H.1) (subset_image_compl H.2)
#align set.image_compl_eq Set.image_compl_eq
theorem subset_image_diff (f : α → β) (s t : Set α) : f '' s \ f '' t ⊆ f '' (s \ t) := by
rw [diff_subset_iff, ← image_union, union_diff_self]
exact image_subset f (subset_union_right t s)
#align set.subset_image_diff Set.subset_image_diff
theorem subset_image_symmDiff : (f '' s) ∆ (f '' t) ⊆ f '' s ∆ t :=
(union_subset_union (subset_image_diff _ _ _) <| subset_image_diff _ _ _).trans
(superset_of_eq (image_union _ _ _))
#align set.subset_image_symm_diff Set.subset_image_symmDiff
theorem image_diff {f : α → β} (hf : Injective f) (s t : Set α) : f '' (s \ t) = f '' s \ f '' t :=
Subset.antisymm
(Subset.trans (image_inter_subset _ _ _) <| inter_subset_inter_right _ <| image_compl_subset hf)
(subset_image_diff f s t)
#align set.image_diff Set.image_diff
theorem image_symmDiff (hf : Injective f) (s t : Set α) : f '' s ∆ t = (f '' s) ∆ (f '' t) := by
simp_rw [Set.symmDiff_def, image_union, image_diff hf]
#align set.image_symm_diff Set.image_symmDiff
theorem Nonempty.image (f : α → β) {s : Set α} : s.Nonempty → (f '' s).Nonempty
| ⟨x, hx⟩ => ⟨f x, mem_image_of_mem f hx⟩
#align set.nonempty.image Set.Nonempty.image
theorem Nonempty.of_image {f : α → β} {s : Set α} : (f '' s).Nonempty → s.Nonempty
| ⟨_, x, hx, _⟩ => ⟨x, hx⟩
#align set.nonempty.of_image Set.Nonempty.of_image
@[simp]
theorem nonempty_image_iff {f : α → β} {s : Set α} : (f '' s).Nonempty ↔ s.Nonempty :=
⟨Nonempty.of_image, fun h => h.image f⟩
#align set.nonempty_image_iff Set.nonempty_image_iff
theorem Nonempty.preimage {s : Set β} (hs : s.Nonempty) {f : α → β} (hf : Surjective f) :
(f ⁻¹' s).Nonempty :=
let ⟨y, hy⟩ := hs
let ⟨x, hx⟩ := hf y
⟨x, mem_preimage.2 <| hx.symm ▸ hy⟩
#align set.nonempty.preimage Set.Nonempty.preimage
instance (f : α → β) (s : Set α) [Nonempty s] : Nonempty (f '' s) :=
(Set.Nonempty.image f nonempty_of_nonempty_subtype).to_subtype
/-- image and preimage are a Galois connection -/
@[simp]
theorem image_subset_iff {s : Set α} {t : Set β} {f : α → β} : f '' s ⊆ t ↔ s ⊆ f ⁻¹' t :=
ball_image_iff
#align set.image_subset_iff Set.image_subset_iff
theorem image_preimage_subset (f : α → β) (s : Set β) : f '' (f ⁻¹' s) ⊆ s :=
image_subset_iff.2 Subset.rfl
#align set.image_preimage_subset Set.image_preimage_subset
theorem subset_preimage_image (f : α → β) (s : Set α) : s ⊆ f ⁻¹' (f '' s) := fun _ =>
mem_image_of_mem f
#align set.subset_preimage_image Set.subset_preimage_image
@[simp]
theorem preimage_image_eq {f : α → β} (s : Set α) (h : Injective f) : f ⁻¹' (f '' s) = s :=
Subset.antisymm (fun _ ⟨_, hy, e⟩ => h e ▸ hy) (subset_preimage_image f s)
#align set.preimage_image_eq Set.preimage_image_eq
@[simp]
theorem image_preimage_eq {f : α → β} (s : Set β) (h : Surjective f) : f '' (f ⁻¹' s) = s :=
Subset.antisymm (image_preimage_subset f s) fun x hx =>
let ⟨y, e⟩ := h x
⟨y, (e.symm ▸ hx : f y ∈ s), e⟩
#align set.image_preimage_eq Set.image_preimage_eq
@[simp]
theorem preimage_eq_preimage {f : β → α} (hf : Surjective f) : f ⁻¹' s = f ⁻¹' t ↔ s = t :=
Iff.intro
fun eq => by rw [← image_preimage_eq s hf, ← image_preimage_eq t hf, eq]
fun eq => eq ▸ rfl
#align set.preimage_eq_preimage Set.preimage_eq_preimage
theorem image_inter_preimage (f : α → β) (s : Set α) (t : Set β) :
f '' (s ∩ f ⁻¹' t) = f '' s ∩ t := by
apply Subset.antisymm
· calc
f '' (s ∩ f ⁻¹' t) ⊆ f '' s ∩ f '' (f ⁻¹' t) := image_inter_subset _ _ _
_ ⊆ f '' s ∩ t := inter_subset_inter_right _ (image_preimage_subset f t)
· rintro _ ⟨⟨x, h', rfl⟩, h⟩
exact ⟨x, ⟨h', h⟩, rfl⟩
#align set.image_inter_preimage Set.image_inter_preimage
theorem image_preimage_inter (f : α → β) (s : Set α) (t : Set β) :
f '' (f ⁻¹' t ∩ s) = t ∩ f '' s := by simp only [inter_comm, image_inter_preimage]
#align set.image_preimage_inter Set.image_preimage_inter
@[simp]
theorem image_inter_nonempty_iff {f : α → β} {s : Set α} {t : Set β} :
(f '' s ∩ t).Nonempty ↔ (s ∩ f ⁻¹' t).Nonempty := by
rw [← image_inter_preimage, nonempty_image_iff]
#align set.image_inter_nonempty_iff Set.image_inter_nonempty_iff
theorem image_diff_preimage {f : α → β} {s : Set α} {t : Set β} : f '' (s \ f ⁻¹' t) = f '' s \ t :=
by
|
simp_rw [diff_eq, ← preimage_compl, image_inter_preimage]
|
theorem image_diff_preimage {f : α → β} {s : Set α} {t : Set β} : f '' (s \ f ⁻¹' t) = f '' s \ t :=
by
|
Mathlib.Data.Set.Image.561_0.IJFiTzmYGOCpPSd
|
theorem image_diff_preimage {f : α → β} {s : Set α} {t : Set β} : f '' (s \ f ⁻¹' t) = f '' s \ t
|
Mathlib_Data_Set_Image
|
α : Type u_1
β : Type u_2
γ : Type u_3
ι : Sort u_4
ι' : Sort u_5
f✝ : α → β
s t : Set α
f : α → β
hf : Injective f
eq : f '' s = f '' t
⊢ s = t
|
/-
Copyright (c) 2014 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Leonardo de Moura
-/
import Mathlib.Data.Set.Basic
#align_import data.set.image from "leanprover-community/mathlib"@"001ffdc42920050657fd45bd2b8bfbec8eaaeb29"
/-!
# Images and preimages of sets
## Main definitions
* `preimage f t : Set α` : the preimage f⁻¹(t) (written `f ⁻¹' t` in Lean) of a subset of β.
* `range f : Set β` : the image of `univ` under `f`.
Also works for `{p : Prop} (f : p → α)` (unlike `image`)
## Notation
* `f ⁻¹' t` for `Set.preimage f t`
* `f '' s` for `Set.image f s`
## Tags
set, sets, image, preimage, pre-image, range
-/
set_option autoImplicit true
universe u v
open Function Set
namespace Set
variable {α β γ : Type*} {ι ι' : Sort*}
/-! ### Inverse image -/
/-- The preimage of `s : Set β` by `f : α → β`, written `f ⁻¹' s`,
is the set of `x : α` such that `f x ∈ s`. -/
def preimage {α : Type u} {β : Type v} (f : α → β) (s : Set β) : Set α :=
{ x | f x ∈ s }
#align set.preimage Set.preimage
/-- `f ⁻¹' t` denotes the preimage of `t : Set β` under the function `f : α → β`. -/
infixl:80 " ⁻¹' " => preimage
section Preimage
variable {f : α → β} {g : β → γ}
@[simp]
theorem preimage_empty : f ⁻¹' ∅ = ∅ :=
rfl
#align set.preimage_empty Set.preimage_empty
@[simp, mfld_simps]
theorem mem_preimage {s : Set β} {a : α} : a ∈ f ⁻¹' s ↔ f a ∈ s :=
Iff.rfl
#align set.mem_preimage Set.mem_preimage
theorem preimage_congr {f g : α → β} {s : Set β} (h : ∀ x : α, f x = g x) : f ⁻¹' s = g ⁻¹' s := by
congr with x
simp [h]
#align set.preimage_congr Set.preimage_congr
@[gcongr]
theorem preimage_mono {s t : Set β} (h : s ⊆ t) : f ⁻¹' s ⊆ f ⁻¹' t := fun _ hx => h hx
#align set.preimage_mono Set.preimage_mono
@[simp, mfld_simps]
theorem preimage_univ : f ⁻¹' univ = univ :=
rfl
#align set.preimage_univ Set.preimage_univ
theorem subset_preimage_univ {s : Set α} : s ⊆ f ⁻¹' univ :=
subset_univ _
#align set.subset_preimage_univ Set.subset_preimage_univ
@[simp, mfld_simps]
theorem preimage_inter {s t : Set β} : f ⁻¹' (s ∩ t) = f ⁻¹' s ∩ f ⁻¹' t :=
rfl
#align set.preimage_inter Set.preimage_inter
@[simp]
theorem preimage_union {s t : Set β} : f ⁻¹' (s ∪ t) = f ⁻¹' s ∪ f ⁻¹' t :=
rfl
#align set.preimage_union Set.preimage_union
@[simp]
theorem preimage_compl {s : Set β} : f ⁻¹' sᶜ = (f ⁻¹' s)ᶜ :=
rfl
#align set.preimage_compl Set.preimage_compl
@[simp]
theorem preimage_diff (f : α → β) (s t : Set β) : f ⁻¹' (s \ t) = f ⁻¹' s \ f ⁻¹' t :=
rfl
#align set.preimage_diff Set.preimage_diff
@[simp]
lemma preimage_symmDiff {f : α → β} (s t : Set β) : f ⁻¹' (s ∆ t) = (f ⁻¹' s) ∆ (f ⁻¹' t) :=
rfl
#align set.preimage_symm_diff Set.preimage_symmDiff
@[simp]
theorem preimage_ite (f : α → β) (s t₁ t₂ : Set β) :
f ⁻¹' s.ite t₁ t₂ = (f ⁻¹' s).ite (f ⁻¹' t₁) (f ⁻¹' t₂) :=
rfl
#align set.preimage_ite Set.preimage_ite
@[simp]
theorem preimage_setOf_eq {p : α → Prop} {f : β → α} : f ⁻¹' { a | p a } = { a | p (f a) } :=
rfl
#align set.preimage_set_of_eq Set.preimage_setOf_eq
@[simp]
theorem preimage_id_eq : preimage (id : α → α) = id :=
rfl
#align set.preimage_id_eq Set.preimage_id_eq
@[mfld_simps]
theorem preimage_id {s : Set α} : id ⁻¹' s = s :=
rfl
#align set.preimage_id Set.preimage_id
@[simp, mfld_simps]
theorem preimage_id' {s : Set α} : (fun x => x) ⁻¹' s = s :=
rfl
#align set.preimage_id' Set.preimage_id'
@[simp]
theorem preimage_const_of_mem {b : β} {s : Set β} (h : b ∈ s) : (fun _ : α => b) ⁻¹' s = univ :=
eq_univ_of_forall fun _ => h
#align set.preimage_const_of_mem Set.preimage_const_of_mem
@[simp]
theorem preimage_const_of_not_mem {b : β} {s : Set β} (h : b ∉ s) : (fun _ : α => b) ⁻¹' s = ∅ :=
eq_empty_of_subset_empty fun _ hx => h hx
#align set.preimage_const_of_not_mem Set.preimage_const_of_not_mem
theorem preimage_const (b : β) (s : Set β) [Decidable (b ∈ s)] :
(fun _ : α => b) ⁻¹' s = if b ∈ s then univ else ∅ := by
split_ifs with hb
exacts [preimage_const_of_mem hb, preimage_const_of_not_mem hb]
#align set.preimage_const Set.preimage_const
/-- If preimage of each singleton under `f : α → β` is either empty or the whole type,
then `f` is a constant. -/
lemma exists_eq_const_of_preimage_singleton [Nonempty β] {f : α → β}
(hf : ∀ b : β, f ⁻¹' {b} = ∅ ∨ f ⁻¹' {b} = univ) : ∃ b, f = const α b := by
rcases em (∃ b, f ⁻¹' {b} = univ) with ⟨b, hb⟩ | hf'
· exact ⟨b, funext fun x ↦ eq_univ_iff_forall.1 hb x⟩
· have : ∀ x b, f x ≠ b := fun x b ↦
eq_empty_iff_forall_not_mem.1 ((hf b).resolve_right fun h ↦ hf' ⟨b, h⟩) x
exact ⟨Classical.arbitrary β, funext fun x ↦ absurd rfl (this x _)⟩
theorem preimage_comp {s : Set γ} : g ∘ f ⁻¹' s = f ⁻¹' (g ⁻¹' s) :=
rfl
#align set.preimage_comp Set.preimage_comp
theorem preimage_comp_eq : preimage (g ∘ f) = preimage f ∘ preimage g :=
rfl
#align set.preimage_comp_eq Set.preimage_comp_eq
theorem preimage_iterate_eq {f : α → α} {n : ℕ} : Set.preimage f^[n] = (Set.preimage f)^[n] := by
induction' n with n ih; · simp
rw [iterate_succ, iterate_succ', preimage_comp_eq, ih]
#align set.preimage_iterate_eq Set.preimage_iterate_eq
theorem preimage_preimage {g : β → γ} {f : α → β} {s : Set γ} :
f ⁻¹' (g ⁻¹' s) = (fun x => g (f x)) ⁻¹' s :=
preimage_comp.symm
#align set.preimage_preimage Set.preimage_preimage
theorem eq_preimage_subtype_val_iff {p : α → Prop} {s : Set (Subtype p)} {t : Set α} :
s = Subtype.val ⁻¹' t ↔ ∀ (x) (h : p x), (⟨x, h⟩ : Subtype p) ∈ s ↔ x ∈ t :=
⟨fun s_eq x h => by
rw [s_eq]
simp, fun h => ext fun ⟨x, hx⟩ => by simp [h]⟩
#align set.eq_preimage_subtype_val_iff Set.eq_preimage_subtype_val_iff
theorem nonempty_of_nonempty_preimage {s : Set β} {f : α → β} (hf : (f ⁻¹' s).Nonempty) :
s.Nonempty :=
let ⟨x, hx⟩ := hf
⟨f x, hx⟩
#align set.nonempty_of_nonempty_preimage Set.nonempty_of_nonempty_preimage
@[simp] theorem preimage_singleton_true (p : α → Prop) : p ⁻¹' {True} = {a | p a} := by ext; simp
#align set.preimage_singleton_true Set.preimage_singleton_true
@[simp] theorem preimage_singleton_false (p : α → Prop) : p ⁻¹' {False} = {a | ¬p a} := by ext; simp
#align set.preimage_singleton_false Set.preimage_singleton_false
theorem preimage_subtype_coe_eq_compl {s u v : Set α} (hsuv : s ⊆ u ∪ v)
(H : s ∩ (u ∩ v) = ∅) : ((↑) : s → α) ⁻¹' u = ((↑) ⁻¹' v)ᶜ := by
ext ⟨x, x_in_s⟩
constructor
· intro x_in_u x_in_v
exact eq_empty_iff_forall_not_mem.mp H x ⟨x_in_s, ⟨x_in_u, x_in_v⟩⟩
· intro hx
exact Or.elim (hsuv x_in_s) id fun hx' => hx.elim hx'
#align set.preimage_subtype_coe_eq_compl Set.preimage_subtype_coe_eq_compl
end Preimage
/-! ### Image of a set under a function -/
section Image
variable {f : α → β} {s t : Set α}
-- Porting note: `Set.image` is already defined in `Init.Set`
#align set.image Set.image
/-- `f '' s` denotes the image of `s : Set α` under the function `f : α → β`. -/
infixl:80 " '' " => image
theorem mem_image_iff_bex {f : α → β} {s : Set α} {y : β} :
y ∈ f '' s ↔ ∃ (x : _) (_ : x ∈ s), f x = y :=
bex_def.symm
#align set.mem_image_iff_bex Set.mem_image_iff_bex
@[simp]
theorem mem_image (f : α → β) (s : Set α) (y : β) : y ∈ f '' s ↔ ∃ x ∈ s, f x = y :=
Iff.rfl
#align set.mem_image Set.mem_image
theorem image_eta (f : α → β) : f '' s = (fun x => f x) '' s :=
rfl
#align set.image_eta Set.image_eta
@[mfld_simps]
theorem mem_image_of_mem (f : α → β) {x : α} {a : Set α} (h : x ∈ a) : f x ∈ f '' a :=
⟨_, h, rfl⟩
#align set.mem_image_of_mem Set.mem_image_of_mem
theorem _root_.Function.Injective.mem_set_image {f : α → β} (hf : Injective f) {s : Set α} {a : α} :
f a ∈ f '' s ↔ a ∈ s :=
⟨fun ⟨_, hb, Eq⟩ => hf Eq ▸ hb, mem_image_of_mem f⟩
#align function.injective.mem_set_image Function.Injective.mem_set_image
theorem ball_image_iff {f : α → β} {s : Set α} {p : β → Prop} :
(∀ y ∈ f '' s, p y) ↔ ∀ x ∈ s, p (f x) := by simp
#align set.ball_image_iff Set.ball_image_iff
theorem ball_image_of_ball {f : α → β} {s : Set α} {p : β → Prop} (h : ∀ x ∈ s, p (f x)) :
∀ y ∈ f '' s, p y :=
ball_image_iff.2 h
#align set.ball_image_of_ball Set.ball_image_of_ball
theorem bex_image_iff {f : α → β} {s : Set α} {p : β → Prop} :
(∃ y ∈ f '' s, p y) ↔ ∃ x ∈ s, p (f x) := by simp
#align set.bex_image_iff Set.bex_image_iff
theorem mem_image_elim {f : α → β} {s : Set α} {C : β → Prop} (h : ∀ x : α, x ∈ s → C (f x)) :
∀ {y : β}, y ∈ f '' s → C y
| _, ⟨a, a_in, rfl⟩ => h a a_in
#align set.mem_image_elim Set.mem_image_elim
theorem mem_image_elim_on {f : α → β} {s : Set α} {C : β → Prop} {y : β} (h_y : y ∈ f '' s)
(h : ∀ x : α, x ∈ s → C (f x)) : C y :=
mem_image_elim h h_y
#align set.mem_image_elim_on Set.mem_image_elim_on
-- Porting note: used to be `safe`
@[congr]
theorem image_congr {f g : α → β} {s : Set α} (h : ∀ a ∈ s, f a = g a) : f '' s = g '' s := by
ext x
rw [mem_image, mem_image]
exact {
mp := by
rintro ⟨a, ha1, ha2⟩
exact ⟨a, ⟨ha1, (h a ha1) ▸ ha2⟩⟩,
mpr := by
rintro ⟨a, ha1, ha2⟩
exact ⟨a, ⟨ha1, (h a ha1) ▸ ha2⟩⟩
}
-- safe [ext_iff, iff_def]
#align set.image_congr Set.image_congr
/-- A common special case of `image_congr` -/
theorem image_congr' {f g : α → β} {s : Set α} (h : ∀ x : α, f x = g x) : f '' s = g '' s :=
image_congr fun x _ => h x
#align set.image_congr' Set.image_congr'
@[gcongr]
lemma image_mono (h : s ⊆ t) : f '' s ⊆ f '' t := by
rintro - ⟨a, ha, rfl⟩; exact mem_image_of_mem f (h ha)
theorem image_comp (f : β → γ) (g : α → β) (a : Set α) : f ∘ g '' a = f '' (g '' a) :=
Subset.antisymm (ball_image_of_ball fun _ ha => mem_image_of_mem _ <| mem_image_of_mem _ ha)
(ball_image_of_ball <| ball_image_of_ball fun _ ha => mem_image_of_mem _ ha)
#align set.image_comp Set.image_comp
theorem image_comp_eq {g : β → γ} : image (g ∘ f) = image g ∘ image f := by ext; simp
/-- A variant of `image_comp`, useful for rewriting -/
theorem image_image (g : β → γ) (f : α → β) (s : Set α) : g '' (f '' s) = (fun x => g (f x)) '' s :=
(image_comp g f s).symm
#align set.image_image Set.image_image
theorem image_comm {β'} {f : β → γ} {g : α → β} {f' : α → β'} {g' : β' → γ}
(h_comm : ∀ a, f (g a) = g' (f' a)) : (s.image g).image f = (s.image f').image g' := by
simp_rw [image_image, h_comm]
#align set.image_comm Set.image_comm
theorem _root_.Function.Semiconj.set_image {f : α → β} {ga : α → α} {gb : β → β}
(h : Function.Semiconj f ga gb) : Function.Semiconj (image f) (image ga) (image gb) := fun _ =>
image_comm h
#align function.semiconj.set_image Function.Semiconj.set_image
theorem _root_.Function.Commute.set_image {f g : α → α} (h : Function.Commute f g) :
Function.Commute (image f) (image g) :=
Function.Semiconj.set_image h
#align function.commute.set_image Function.Commute.set_image
/-- Image is monotone with respect to `⊆`. See `Set.monotone_image` for the statement in
terms of `≤`. -/
@[gcongr]
theorem image_subset {a b : Set α} (f : α → β) (h : a ⊆ b) : f '' a ⊆ f '' b := by
simp only [subset_def, mem_image]
exact fun x => fun ⟨w, h1, h2⟩ => ⟨w, h h1, h2⟩
#align set.image_subset Set.image_subset
/-- `Set.image` is monotone. See `Set.image_subset` for the statement in terms of `⊆`. -/
lemma monotone_image {f : α → β} : Monotone (image f) := fun _ _ => image_subset _
#align set.monotone_image Set.monotone_image
theorem image_union (f : α → β) (s t : Set α) : f '' (s ∪ t) = f '' s ∪ f '' t :=
ext fun x =>
⟨by rintro ⟨a, h | h, rfl⟩ <;> [left; right] <;> exact ⟨_, h, rfl⟩, by
rintro (⟨a, h, rfl⟩ | ⟨a, h, rfl⟩) <;> refine' ⟨_, _, rfl⟩ <;> [left; right] <;> exact h⟩
#align set.image_union Set.image_union
@[simp]
theorem image_empty (f : α → β) : f '' ∅ = ∅ := by
ext
simp
#align set.image_empty Set.image_empty
theorem image_inter_subset (f : α → β) (s t : Set α) : f '' (s ∩ t) ⊆ f '' s ∩ f '' t :=
subset_inter (image_subset _ <| inter_subset_left _ _) (image_subset _ <| inter_subset_right _ _)
#align set.image_inter_subset Set.image_inter_subset
theorem image_inter_on {f : α → β} {s t : Set α} (h : ∀ x ∈ t, ∀ y ∈ s, f x = f y → x = y) :
f '' (s ∩ t) = f '' s ∩ f '' t :=
(image_inter_subset _ _ _).antisymm
fun b ⟨⟨a₁, ha₁, h₁⟩, ⟨a₂, ha₂, h₂⟩⟩ ↦
have : a₂ = a₁ := h _ ha₂ _ ha₁ (by simp [*])
⟨a₁, ⟨ha₁, this ▸ ha₂⟩, h₁⟩
#align set.image_inter_on Set.image_inter_on
theorem image_inter {f : α → β} {s t : Set α} (H : Injective f) : f '' (s ∩ t) = f '' s ∩ f '' t :=
image_inter_on fun _ _ _ _ h => H h
#align set.image_inter Set.image_inter
theorem image_univ_of_surjective {ι : Type*} {f : ι → β} (H : Surjective f) : f '' univ = univ :=
eq_univ_of_forall <| by simpa [image]
#align set.image_univ_of_surjective Set.image_univ_of_surjective
@[simp]
theorem image_singleton {f : α → β} {a : α} : f '' {a} = {f a} := by
ext
simp [image, eq_comm]
#align set.image_singleton Set.image_singleton
@[simp]
theorem Nonempty.image_const {s : Set α} (hs : s.Nonempty) (a : β) : (fun _ => a) '' s = {a} :=
ext fun _ =>
⟨fun ⟨_, _, h⟩ => h ▸ mem_singleton _, fun h =>
(eq_of_mem_singleton h).symm ▸ hs.imp fun _ hy => ⟨hy, rfl⟩⟩
#align set.nonempty.image_const Set.Nonempty.image_const
@[simp, mfld_simps]
theorem image_eq_empty {α β} {f : α → β} {s : Set α} : f '' s = ∅ ↔ s = ∅ := by
simp only [eq_empty_iff_forall_not_mem]
exact ⟨fun H a ha => H _ ⟨_, ha, rfl⟩, fun H b ⟨_, ha, _⟩ => H _ ha⟩
#align set.image_eq_empty Set.image_eq_empty
-- Porting note: `compl` is already defined in `Init.Set`
theorem preimage_compl_eq_image_compl [BooleanAlgebra α] (S : Set α) :
HasCompl.compl ⁻¹' S = HasCompl.compl '' S :=
Set.ext fun x =>
⟨fun h => ⟨xᶜ, h, compl_compl x⟩, fun h =>
Exists.elim h fun _ hy => (compl_eq_comm.mp hy.2).symm.subst hy.1⟩
#align set.preimage_compl_eq_image_compl Set.preimage_compl_eq_image_compl
theorem mem_compl_image [BooleanAlgebra α] (t : α) (S : Set α) :
t ∈ HasCompl.compl '' S ↔ tᶜ ∈ S := by
simp [← preimage_compl_eq_image_compl]
#align set.mem_compl_image Set.mem_compl_image
@[simp]
theorem image_id_eq : image (id : α → α) = id := by ext; simp
/-- A variant of `image_id` -/
@[simp]
theorem image_id' (s : Set α) : (fun x => x) '' s = s := by
ext
simp
#align set.image_id' Set.image_id'
theorem image_id (s : Set α) : id '' s = s := by simp
#align set.image_id Set.image_id
lemma image_iterate_eq {f : α → α} {n : ℕ} : image (f^[n]) = (image f)^[n] := by
induction' n with n ih; · simp
rw [iterate_succ', iterate_succ',← ih, image_comp_eq]
theorem compl_compl_image [BooleanAlgebra α] (S : Set α) :
HasCompl.compl '' (HasCompl.compl '' S) = S := by
rw [← image_comp, compl_comp_compl, image_id]
#align set.compl_compl_image Set.compl_compl_image
theorem image_insert_eq {f : α → β} {a : α} {s : Set α} :
f '' insert a s = insert (f a) (f '' s) := by
ext
simp [and_or_left, exists_or, eq_comm, or_comm, and_comm]
#align set.image_insert_eq Set.image_insert_eq
theorem image_pair (f : α → β) (a b : α) : f '' {a, b} = {f a, f b} := by
simp only [image_insert_eq, image_singleton]
#align set.image_pair Set.image_pair
theorem image_subset_preimage_of_inverse {f : α → β} {g : β → α} (I : LeftInverse g f) (s : Set α) :
f '' s ⊆ g ⁻¹' s := fun _ ⟨a, h, e⟩ => e ▸ ((I a).symm ▸ h : g (f a) ∈ s)
#align set.image_subset_preimage_of_inverse Set.image_subset_preimage_of_inverse
theorem preimage_subset_image_of_inverse {f : α → β} {g : β → α} (I : LeftInverse g f) (s : Set β) :
f ⁻¹' s ⊆ g '' s := fun b h => ⟨f b, h, I b⟩
#align set.preimage_subset_image_of_inverse Set.preimage_subset_image_of_inverse
theorem image_eq_preimage_of_inverse {f : α → β} {g : β → α} (h₁ : LeftInverse g f)
(h₂ : RightInverse g f) : image f = preimage g :=
funext fun s =>
Subset.antisymm (image_subset_preimage_of_inverse h₁ s) (preimage_subset_image_of_inverse h₂ s)
#align set.image_eq_preimage_of_inverse Set.image_eq_preimage_of_inverse
theorem mem_image_iff_of_inverse {f : α → β} {g : β → α} {b : β} {s : Set α} (h₁ : LeftInverse g f)
(h₂ : RightInverse g f) : b ∈ f '' s ↔ g b ∈ s := by
rw [image_eq_preimage_of_inverse h₁ h₂]; rfl
#align set.mem_image_iff_of_inverse Set.mem_image_iff_of_inverse
theorem image_compl_subset {f : α → β} {s : Set α} (H : Injective f) : f '' sᶜ ⊆ (f '' s)ᶜ :=
Disjoint.subset_compl_left <| by simp [disjoint_iff_inf_le, ← image_inter H]
#align set.image_compl_subset Set.image_compl_subset
theorem subset_image_compl {f : α → β} {s : Set α} (H : Surjective f) : (f '' s)ᶜ ⊆ f '' sᶜ :=
compl_subset_iff_union.2 <| by
rw [← image_union]
simp [image_univ_of_surjective H]
#align set.subset_image_compl Set.subset_image_compl
theorem image_compl_eq {f : α → β} {s : Set α} (H : Bijective f) : f '' sᶜ = (f '' s)ᶜ :=
Subset.antisymm (image_compl_subset H.1) (subset_image_compl H.2)
#align set.image_compl_eq Set.image_compl_eq
theorem subset_image_diff (f : α → β) (s t : Set α) : f '' s \ f '' t ⊆ f '' (s \ t) := by
rw [diff_subset_iff, ← image_union, union_diff_self]
exact image_subset f (subset_union_right t s)
#align set.subset_image_diff Set.subset_image_diff
theorem subset_image_symmDiff : (f '' s) ∆ (f '' t) ⊆ f '' s ∆ t :=
(union_subset_union (subset_image_diff _ _ _) <| subset_image_diff _ _ _).trans
(superset_of_eq (image_union _ _ _))
#align set.subset_image_symm_diff Set.subset_image_symmDiff
theorem image_diff {f : α → β} (hf : Injective f) (s t : Set α) : f '' (s \ t) = f '' s \ f '' t :=
Subset.antisymm
(Subset.trans (image_inter_subset _ _ _) <| inter_subset_inter_right _ <| image_compl_subset hf)
(subset_image_diff f s t)
#align set.image_diff Set.image_diff
theorem image_symmDiff (hf : Injective f) (s t : Set α) : f '' s ∆ t = (f '' s) ∆ (f '' t) := by
simp_rw [Set.symmDiff_def, image_union, image_diff hf]
#align set.image_symm_diff Set.image_symmDiff
theorem Nonempty.image (f : α → β) {s : Set α} : s.Nonempty → (f '' s).Nonempty
| ⟨x, hx⟩ => ⟨f x, mem_image_of_mem f hx⟩
#align set.nonempty.image Set.Nonempty.image
theorem Nonempty.of_image {f : α → β} {s : Set α} : (f '' s).Nonempty → s.Nonempty
| ⟨_, x, hx, _⟩ => ⟨x, hx⟩
#align set.nonempty.of_image Set.Nonempty.of_image
@[simp]
theorem nonempty_image_iff {f : α → β} {s : Set α} : (f '' s).Nonempty ↔ s.Nonempty :=
⟨Nonempty.of_image, fun h => h.image f⟩
#align set.nonempty_image_iff Set.nonempty_image_iff
theorem Nonempty.preimage {s : Set β} (hs : s.Nonempty) {f : α → β} (hf : Surjective f) :
(f ⁻¹' s).Nonempty :=
let ⟨y, hy⟩ := hs
let ⟨x, hx⟩ := hf y
⟨x, mem_preimage.2 <| hx.symm ▸ hy⟩
#align set.nonempty.preimage Set.Nonempty.preimage
instance (f : α → β) (s : Set α) [Nonempty s] : Nonempty (f '' s) :=
(Set.Nonempty.image f nonempty_of_nonempty_subtype).to_subtype
/-- image and preimage are a Galois connection -/
@[simp]
theorem image_subset_iff {s : Set α} {t : Set β} {f : α → β} : f '' s ⊆ t ↔ s ⊆ f ⁻¹' t :=
ball_image_iff
#align set.image_subset_iff Set.image_subset_iff
theorem image_preimage_subset (f : α → β) (s : Set β) : f '' (f ⁻¹' s) ⊆ s :=
image_subset_iff.2 Subset.rfl
#align set.image_preimage_subset Set.image_preimage_subset
theorem subset_preimage_image (f : α → β) (s : Set α) : s ⊆ f ⁻¹' (f '' s) := fun _ =>
mem_image_of_mem f
#align set.subset_preimage_image Set.subset_preimage_image
@[simp]
theorem preimage_image_eq {f : α → β} (s : Set α) (h : Injective f) : f ⁻¹' (f '' s) = s :=
Subset.antisymm (fun _ ⟨_, hy, e⟩ => h e ▸ hy) (subset_preimage_image f s)
#align set.preimage_image_eq Set.preimage_image_eq
@[simp]
theorem image_preimage_eq {f : α → β} (s : Set β) (h : Surjective f) : f '' (f ⁻¹' s) = s :=
Subset.antisymm (image_preimage_subset f s) fun x hx =>
let ⟨y, e⟩ := h x
⟨y, (e.symm ▸ hx : f y ∈ s), e⟩
#align set.image_preimage_eq Set.image_preimage_eq
@[simp]
theorem preimage_eq_preimage {f : β → α} (hf : Surjective f) : f ⁻¹' s = f ⁻¹' t ↔ s = t :=
Iff.intro
fun eq => by rw [← image_preimage_eq s hf, ← image_preimage_eq t hf, eq]
fun eq => eq ▸ rfl
#align set.preimage_eq_preimage Set.preimage_eq_preimage
theorem image_inter_preimage (f : α → β) (s : Set α) (t : Set β) :
f '' (s ∩ f ⁻¹' t) = f '' s ∩ t := by
apply Subset.antisymm
· calc
f '' (s ∩ f ⁻¹' t) ⊆ f '' s ∩ f '' (f ⁻¹' t) := image_inter_subset _ _ _
_ ⊆ f '' s ∩ t := inter_subset_inter_right _ (image_preimage_subset f t)
· rintro _ ⟨⟨x, h', rfl⟩, h⟩
exact ⟨x, ⟨h', h⟩, rfl⟩
#align set.image_inter_preimage Set.image_inter_preimage
theorem image_preimage_inter (f : α → β) (s : Set α) (t : Set β) :
f '' (f ⁻¹' t ∩ s) = t ∩ f '' s := by simp only [inter_comm, image_inter_preimage]
#align set.image_preimage_inter Set.image_preimage_inter
@[simp]
theorem image_inter_nonempty_iff {f : α → β} {s : Set α} {t : Set β} :
(f '' s ∩ t).Nonempty ↔ (s ∩ f ⁻¹' t).Nonempty := by
rw [← image_inter_preimage, nonempty_image_iff]
#align set.image_inter_nonempty_iff Set.image_inter_nonempty_iff
theorem image_diff_preimage {f : α → β} {s : Set α} {t : Set β} : f '' (s \ f ⁻¹' t) = f '' s \ t :=
by simp_rw [diff_eq, ← preimage_compl, image_inter_preimage]
#align set.image_diff_preimage Set.image_diff_preimage
theorem compl_image : image (compl : Set α → Set α) = preimage compl :=
image_eq_preimage_of_inverse compl_compl compl_compl
#align set.compl_image Set.compl_image
theorem compl_image_set_of {p : Set α → Prop} : compl '' { s | p s } = { s | p sᶜ } :=
congr_fun compl_image p
#align set.compl_image_set_of Set.compl_image_set_of
theorem inter_preimage_subset (s : Set α) (t : Set β) (f : α → β) :
s ∩ f ⁻¹' t ⊆ f ⁻¹' (f '' s ∩ t) := fun _ h => ⟨mem_image_of_mem _ h.left, h.right⟩
#align set.inter_preimage_subset Set.inter_preimage_subset
theorem union_preimage_subset (s : Set α) (t : Set β) (f : α → β) :
s ∪ f ⁻¹' t ⊆ f ⁻¹' (f '' s ∪ t) := fun _ h =>
Or.elim h (fun l => Or.inl <| mem_image_of_mem _ l) fun r => Or.inr r
#align set.union_preimage_subset Set.union_preimage_subset
theorem subset_image_union (f : α → β) (s : Set α) (t : Set β) : f '' (s ∪ f ⁻¹' t) ⊆ f '' s ∪ t :=
image_subset_iff.2 (union_preimage_subset _ _ _)
#align set.subset_image_union Set.subset_image_union
theorem preimage_subset_iff {A : Set α} {B : Set β} {f : α → β} :
f ⁻¹' B ⊆ A ↔ ∀ a : α, f a ∈ B → a ∈ A :=
Iff.rfl
#align set.preimage_subset_iff Set.preimage_subset_iff
theorem image_eq_image {f : α → β} (hf : Injective f) : f '' s = f '' t ↔ s = t :=
Iff.symm <|
(Iff.intro fun eq => eq ▸ rfl) fun eq => by
|
rw [← preimage_image_eq s hf, ← preimage_image_eq t hf, eq]
|
theorem image_eq_image {f : α → β} (hf : Injective f) : f '' s = f '' t ↔ s = t :=
Iff.symm <|
(Iff.intro fun eq => eq ▸ rfl) fun eq => by
|
Mathlib.Data.Set.Image.591_0.IJFiTzmYGOCpPSd
|
theorem image_eq_image {f : α → β} (hf : Injective f) : f '' s = f '' t ↔ s = t
|
Mathlib_Data_Set_Image
|
α : Type u_1
β : Type u_2
γ : Type u_3
ι : Sort u_4
ι' : Sort u_5
f✝ : α → β
s t : Set α
f : α → β
hf : Injective f
⊢ f '' s ⊆ f '' t ↔ s ⊆ t
|
/-
Copyright (c) 2014 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Leonardo de Moura
-/
import Mathlib.Data.Set.Basic
#align_import data.set.image from "leanprover-community/mathlib"@"001ffdc42920050657fd45bd2b8bfbec8eaaeb29"
/-!
# Images and preimages of sets
## Main definitions
* `preimage f t : Set α` : the preimage f⁻¹(t) (written `f ⁻¹' t` in Lean) of a subset of β.
* `range f : Set β` : the image of `univ` under `f`.
Also works for `{p : Prop} (f : p → α)` (unlike `image`)
## Notation
* `f ⁻¹' t` for `Set.preimage f t`
* `f '' s` for `Set.image f s`
## Tags
set, sets, image, preimage, pre-image, range
-/
set_option autoImplicit true
universe u v
open Function Set
namespace Set
variable {α β γ : Type*} {ι ι' : Sort*}
/-! ### Inverse image -/
/-- The preimage of `s : Set β` by `f : α → β`, written `f ⁻¹' s`,
is the set of `x : α` such that `f x ∈ s`. -/
def preimage {α : Type u} {β : Type v} (f : α → β) (s : Set β) : Set α :=
{ x | f x ∈ s }
#align set.preimage Set.preimage
/-- `f ⁻¹' t` denotes the preimage of `t : Set β` under the function `f : α → β`. -/
infixl:80 " ⁻¹' " => preimage
section Preimage
variable {f : α → β} {g : β → γ}
@[simp]
theorem preimage_empty : f ⁻¹' ∅ = ∅ :=
rfl
#align set.preimage_empty Set.preimage_empty
@[simp, mfld_simps]
theorem mem_preimage {s : Set β} {a : α} : a ∈ f ⁻¹' s ↔ f a ∈ s :=
Iff.rfl
#align set.mem_preimage Set.mem_preimage
theorem preimage_congr {f g : α → β} {s : Set β} (h : ∀ x : α, f x = g x) : f ⁻¹' s = g ⁻¹' s := by
congr with x
simp [h]
#align set.preimage_congr Set.preimage_congr
@[gcongr]
theorem preimage_mono {s t : Set β} (h : s ⊆ t) : f ⁻¹' s ⊆ f ⁻¹' t := fun _ hx => h hx
#align set.preimage_mono Set.preimage_mono
@[simp, mfld_simps]
theorem preimage_univ : f ⁻¹' univ = univ :=
rfl
#align set.preimage_univ Set.preimage_univ
theorem subset_preimage_univ {s : Set α} : s ⊆ f ⁻¹' univ :=
subset_univ _
#align set.subset_preimage_univ Set.subset_preimage_univ
@[simp, mfld_simps]
theorem preimage_inter {s t : Set β} : f ⁻¹' (s ∩ t) = f ⁻¹' s ∩ f ⁻¹' t :=
rfl
#align set.preimage_inter Set.preimage_inter
@[simp]
theorem preimage_union {s t : Set β} : f ⁻¹' (s ∪ t) = f ⁻¹' s ∪ f ⁻¹' t :=
rfl
#align set.preimage_union Set.preimage_union
@[simp]
theorem preimage_compl {s : Set β} : f ⁻¹' sᶜ = (f ⁻¹' s)ᶜ :=
rfl
#align set.preimage_compl Set.preimage_compl
@[simp]
theorem preimage_diff (f : α → β) (s t : Set β) : f ⁻¹' (s \ t) = f ⁻¹' s \ f ⁻¹' t :=
rfl
#align set.preimage_diff Set.preimage_diff
@[simp]
lemma preimage_symmDiff {f : α → β} (s t : Set β) : f ⁻¹' (s ∆ t) = (f ⁻¹' s) ∆ (f ⁻¹' t) :=
rfl
#align set.preimage_symm_diff Set.preimage_symmDiff
@[simp]
theorem preimage_ite (f : α → β) (s t₁ t₂ : Set β) :
f ⁻¹' s.ite t₁ t₂ = (f ⁻¹' s).ite (f ⁻¹' t₁) (f ⁻¹' t₂) :=
rfl
#align set.preimage_ite Set.preimage_ite
@[simp]
theorem preimage_setOf_eq {p : α → Prop} {f : β → α} : f ⁻¹' { a | p a } = { a | p (f a) } :=
rfl
#align set.preimage_set_of_eq Set.preimage_setOf_eq
@[simp]
theorem preimage_id_eq : preimage (id : α → α) = id :=
rfl
#align set.preimage_id_eq Set.preimage_id_eq
@[mfld_simps]
theorem preimage_id {s : Set α} : id ⁻¹' s = s :=
rfl
#align set.preimage_id Set.preimage_id
@[simp, mfld_simps]
theorem preimage_id' {s : Set α} : (fun x => x) ⁻¹' s = s :=
rfl
#align set.preimage_id' Set.preimage_id'
@[simp]
theorem preimage_const_of_mem {b : β} {s : Set β} (h : b ∈ s) : (fun _ : α => b) ⁻¹' s = univ :=
eq_univ_of_forall fun _ => h
#align set.preimage_const_of_mem Set.preimage_const_of_mem
@[simp]
theorem preimage_const_of_not_mem {b : β} {s : Set β} (h : b ∉ s) : (fun _ : α => b) ⁻¹' s = ∅ :=
eq_empty_of_subset_empty fun _ hx => h hx
#align set.preimage_const_of_not_mem Set.preimage_const_of_not_mem
theorem preimage_const (b : β) (s : Set β) [Decidable (b ∈ s)] :
(fun _ : α => b) ⁻¹' s = if b ∈ s then univ else ∅ := by
split_ifs with hb
exacts [preimage_const_of_mem hb, preimage_const_of_not_mem hb]
#align set.preimage_const Set.preimage_const
/-- If preimage of each singleton under `f : α → β` is either empty or the whole type,
then `f` is a constant. -/
lemma exists_eq_const_of_preimage_singleton [Nonempty β] {f : α → β}
(hf : ∀ b : β, f ⁻¹' {b} = ∅ ∨ f ⁻¹' {b} = univ) : ∃ b, f = const α b := by
rcases em (∃ b, f ⁻¹' {b} = univ) with ⟨b, hb⟩ | hf'
· exact ⟨b, funext fun x ↦ eq_univ_iff_forall.1 hb x⟩
· have : ∀ x b, f x ≠ b := fun x b ↦
eq_empty_iff_forall_not_mem.1 ((hf b).resolve_right fun h ↦ hf' ⟨b, h⟩) x
exact ⟨Classical.arbitrary β, funext fun x ↦ absurd rfl (this x _)⟩
theorem preimage_comp {s : Set γ} : g ∘ f ⁻¹' s = f ⁻¹' (g ⁻¹' s) :=
rfl
#align set.preimage_comp Set.preimage_comp
theorem preimage_comp_eq : preimage (g ∘ f) = preimage f ∘ preimage g :=
rfl
#align set.preimage_comp_eq Set.preimage_comp_eq
theorem preimage_iterate_eq {f : α → α} {n : ℕ} : Set.preimage f^[n] = (Set.preimage f)^[n] := by
induction' n with n ih; · simp
rw [iterate_succ, iterate_succ', preimage_comp_eq, ih]
#align set.preimage_iterate_eq Set.preimage_iterate_eq
theorem preimage_preimage {g : β → γ} {f : α → β} {s : Set γ} :
f ⁻¹' (g ⁻¹' s) = (fun x => g (f x)) ⁻¹' s :=
preimage_comp.symm
#align set.preimage_preimage Set.preimage_preimage
theorem eq_preimage_subtype_val_iff {p : α → Prop} {s : Set (Subtype p)} {t : Set α} :
s = Subtype.val ⁻¹' t ↔ ∀ (x) (h : p x), (⟨x, h⟩ : Subtype p) ∈ s ↔ x ∈ t :=
⟨fun s_eq x h => by
rw [s_eq]
simp, fun h => ext fun ⟨x, hx⟩ => by simp [h]⟩
#align set.eq_preimage_subtype_val_iff Set.eq_preimage_subtype_val_iff
theorem nonempty_of_nonempty_preimage {s : Set β} {f : α → β} (hf : (f ⁻¹' s).Nonempty) :
s.Nonempty :=
let ⟨x, hx⟩ := hf
⟨f x, hx⟩
#align set.nonempty_of_nonempty_preimage Set.nonempty_of_nonempty_preimage
@[simp] theorem preimage_singleton_true (p : α → Prop) : p ⁻¹' {True} = {a | p a} := by ext; simp
#align set.preimage_singleton_true Set.preimage_singleton_true
@[simp] theorem preimage_singleton_false (p : α → Prop) : p ⁻¹' {False} = {a | ¬p a} := by ext; simp
#align set.preimage_singleton_false Set.preimage_singleton_false
theorem preimage_subtype_coe_eq_compl {s u v : Set α} (hsuv : s ⊆ u ∪ v)
(H : s ∩ (u ∩ v) = ∅) : ((↑) : s → α) ⁻¹' u = ((↑) ⁻¹' v)ᶜ := by
ext ⟨x, x_in_s⟩
constructor
· intro x_in_u x_in_v
exact eq_empty_iff_forall_not_mem.mp H x ⟨x_in_s, ⟨x_in_u, x_in_v⟩⟩
· intro hx
exact Or.elim (hsuv x_in_s) id fun hx' => hx.elim hx'
#align set.preimage_subtype_coe_eq_compl Set.preimage_subtype_coe_eq_compl
end Preimage
/-! ### Image of a set under a function -/
section Image
variable {f : α → β} {s t : Set α}
-- Porting note: `Set.image` is already defined in `Init.Set`
#align set.image Set.image
/-- `f '' s` denotes the image of `s : Set α` under the function `f : α → β`. -/
infixl:80 " '' " => image
theorem mem_image_iff_bex {f : α → β} {s : Set α} {y : β} :
y ∈ f '' s ↔ ∃ (x : _) (_ : x ∈ s), f x = y :=
bex_def.symm
#align set.mem_image_iff_bex Set.mem_image_iff_bex
@[simp]
theorem mem_image (f : α → β) (s : Set α) (y : β) : y ∈ f '' s ↔ ∃ x ∈ s, f x = y :=
Iff.rfl
#align set.mem_image Set.mem_image
theorem image_eta (f : α → β) : f '' s = (fun x => f x) '' s :=
rfl
#align set.image_eta Set.image_eta
@[mfld_simps]
theorem mem_image_of_mem (f : α → β) {x : α} {a : Set α} (h : x ∈ a) : f x ∈ f '' a :=
⟨_, h, rfl⟩
#align set.mem_image_of_mem Set.mem_image_of_mem
theorem _root_.Function.Injective.mem_set_image {f : α → β} (hf : Injective f) {s : Set α} {a : α} :
f a ∈ f '' s ↔ a ∈ s :=
⟨fun ⟨_, hb, Eq⟩ => hf Eq ▸ hb, mem_image_of_mem f⟩
#align function.injective.mem_set_image Function.Injective.mem_set_image
theorem ball_image_iff {f : α → β} {s : Set α} {p : β → Prop} :
(∀ y ∈ f '' s, p y) ↔ ∀ x ∈ s, p (f x) := by simp
#align set.ball_image_iff Set.ball_image_iff
theorem ball_image_of_ball {f : α → β} {s : Set α} {p : β → Prop} (h : ∀ x ∈ s, p (f x)) :
∀ y ∈ f '' s, p y :=
ball_image_iff.2 h
#align set.ball_image_of_ball Set.ball_image_of_ball
theorem bex_image_iff {f : α → β} {s : Set α} {p : β → Prop} :
(∃ y ∈ f '' s, p y) ↔ ∃ x ∈ s, p (f x) := by simp
#align set.bex_image_iff Set.bex_image_iff
theorem mem_image_elim {f : α → β} {s : Set α} {C : β → Prop} (h : ∀ x : α, x ∈ s → C (f x)) :
∀ {y : β}, y ∈ f '' s → C y
| _, ⟨a, a_in, rfl⟩ => h a a_in
#align set.mem_image_elim Set.mem_image_elim
theorem mem_image_elim_on {f : α → β} {s : Set α} {C : β → Prop} {y : β} (h_y : y ∈ f '' s)
(h : ∀ x : α, x ∈ s → C (f x)) : C y :=
mem_image_elim h h_y
#align set.mem_image_elim_on Set.mem_image_elim_on
-- Porting note: used to be `safe`
@[congr]
theorem image_congr {f g : α → β} {s : Set α} (h : ∀ a ∈ s, f a = g a) : f '' s = g '' s := by
ext x
rw [mem_image, mem_image]
exact {
mp := by
rintro ⟨a, ha1, ha2⟩
exact ⟨a, ⟨ha1, (h a ha1) ▸ ha2⟩⟩,
mpr := by
rintro ⟨a, ha1, ha2⟩
exact ⟨a, ⟨ha1, (h a ha1) ▸ ha2⟩⟩
}
-- safe [ext_iff, iff_def]
#align set.image_congr Set.image_congr
/-- A common special case of `image_congr` -/
theorem image_congr' {f g : α → β} {s : Set α} (h : ∀ x : α, f x = g x) : f '' s = g '' s :=
image_congr fun x _ => h x
#align set.image_congr' Set.image_congr'
@[gcongr]
lemma image_mono (h : s ⊆ t) : f '' s ⊆ f '' t := by
rintro - ⟨a, ha, rfl⟩; exact mem_image_of_mem f (h ha)
theorem image_comp (f : β → γ) (g : α → β) (a : Set α) : f ∘ g '' a = f '' (g '' a) :=
Subset.antisymm (ball_image_of_ball fun _ ha => mem_image_of_mem _ <| mem_image_of_mem _ ha)
(ball_image_of_ball <| ball_image_of_ball fun _ ha => mem_image_of_mem _ ha)
#align set.image_comp Set.image_comp
theorem image_comp_eq {g : β → γ} : image (g ∘ f) = image g ∘ image f := by ext; simp
/-- A variant of `image_comp`, useful for rewriting -/
theorem image_image (g : β → γ) (f : α → β) (s : Set α) : g '' (f '' s) = (fun x => g (f x)) '' s :=
(image_comp g f s).symm
#align set.image_image Set.image_image
theorem image_comm {β'} {f : β → γ} {g : α → β} {f' : α → β'} {g' : β' → γ}
(h_comm : ∀ a, f (g a) = g' (f' a)) : (s.image g).image f = (s.image f').image g' := by
simp_rw [image_image, h_comm]
#align set.image_comm Set.image_comm
theorem _root_.Function.Semiconj.set_image {f : α → β} {ga : α → α} {gb : β → β}
(h : Function.Semiconj f ga gb) : Function.Semiconj (image f) (image ga) (image gb) := fun _ =>
image_comm h
#align function.semiconj.set_image Function.Semiconj.set_image
theorem _root_.Function.Commute.set_image {f g : α → α} (h : Function.Commute f g) :
Function.Commute (image f) (image g) :=
Function.Semiconj.set_image h
#align function.commute.set_image Function.Commute.set_image
/-- Image is monotone with respect to `⊆`. See `Set.monotone_image` for the statement in
terms of `≤`. -/
@[gcongr]
theorem image_subset {a b : Set α} (f : α → β) (h : a ⊆ b) : f '' a ⊆ f '' b := by
simp only [subset_def, mem_image]
exact fun x => fun ⟨w, h1, h2⟩ => ⟨w, h h1, h2⟩
#align set.image_subset Set.image_subset
/-- `Set.image` is monotone. See `Set.image_subset` for the statement in terms of `⊆`. -/
lemma monotone_image {f : α → β} : Monotone (image f) := fun _ _ => image_subset _
#align set.monotone_image Set.monotone_image
theorem image_union (f : α → β) (s t : Set α) : f '' (s ∪ t) = f '' s ∪ f '' t :=
ext fun x =>
⟨by rintro ⟨a, h | h, rfl⟩ <;> [left; right] <;> exact ⟨_, h, rfl⟩, by
rintro (⟨a, h, rfl⟩ | ⟨a, h, rfl⟩) <;> refine' ⟨_, _, rfl⟩ <;> [left; right] <;> exact h⟩
#align set.image_union Set.image_union
@[simp]
theorem image_empty (f : α → β) : f '' ∅ = ∅ := by
ext
simp
#align set.image_empty Set.image_empty
theorem image_inter_subset (f : α → β) (s t : Set α) : f '' (s ∩ t) ⊆ f '' s ∩ f '' t :=
subset_inter (image_subset _ <| inter_subset_left _ _) (image_subset _ <| inter_subset_right _ _)
#align set.image_inter_subset Set.image_inter_subset
theorem image_inter_on {f : α → β} {s t : Set α} (h : ∀ x ∈ t, ∀ y ∈ s, f x = f y → x = y) :
f '' (s ∩ t) = f '' s ∩ f '' t :=
(image_inter_subset _ _ _).antisymm
fun b ⟨⟨a₁, ha₁, h₁⟩, ⟨a₂, ha₂, h₂⟩⟩ ↦
have : a₂ = a₁ := h _ ha₂ _ ha₁ (by simp [*])
⟨a₁, ⟨ha₁, this ▸ ha₂⟩, h₁⟩
#align set.image_inter_on Set.image_inter_on
theorem image_inter {f : α → β} {s t : Set α} (H : Injective f) : f '' (s ∩ t) = f '' s ∩ f '' t :=
image_inter_on fun _ _ _ _ h => H h
#align set.image_inter Set.image_inter
theorem image_univ_of_surjective {ι : Type*} {f : ι → β} (H : Surjective f) : f '' univ = univ :=
eq_univ_of_forall <| by simpa [image]
#align set.image_univ_of_surjective Set.image_univ_of_surjective
@[simp]
theorem image_singleton {f : α → β} {a : α} : f '' {a} = {f a} := by
ext
simp [image, eq_comm]
#align set.image_singleton Set.image_singleton
@[simp]
theorem Nonempty.image_const {s : Set α} (hs : s.Nonempty) (a : β) : (fun _ => a) '' s = {a} :=
ext fun _ =>
⟨fun ⟨_, _, h⟩ => h ▸ mem_singleton _, fun h =>
(eq_of_mem_singleton h).symm ▸ hs.imp fun _ hy => ⟨hy, rfl⟩⟩
#align set.nonempty.image_const Set.Nonempty.image_const
@[simp, mfld_simps]
theorem image_eq_empty {α β} {f : α → β} {s : Set α} : f '' s = ∅ ↔ s = ∅ := by
simp only [eq_empty_iff_forall_not_mem]
exact ⟨fun H a ha => H _ ⟨_, ha, rfl⟩, fun H b ⟨_, ha, _⟩ => H _ ha⟩
#align set.image_eq_empty Set.image_eq_empty
-- Porting note: `compl` is already defined in `Init.Set`
theorem preimage_compl_eq_image_compl [BooleanAlgebra α] (S : Set α) :
HasCompl.compl ⁻¹' S = HasCompl.compl '' S :=
Set.ext fun x =>
⟨fun h => ⟨xᶜ, h, compl_compl x⟩, fun h =>
Exists.elim h fun _ hy => (compl_eq_comm.mp hy.2).symm.subst hy.1⟩
#align set.preimage_compl_eq_image_compl Set.preimage_compl_eq_image_compl
theorem mem_compl_image [BooleanAlgebra α] (t : α) (S : Set α) :
t ∈ HasCompl.compl '' S ↔ tᶜ ∈ S := by
simp [← preimage_compl_eq_image_compl]
#align set.mem_compl_image Set.mem_compl_image
@[simp]
theorem image_id_eq : image (id : α → α) = id := by ext; simp
/-- A variant of `image_id` -/
@[simp]
theorem image_id' (s : Set α) : (fun x => x) '' s = s := by
ext
simp
#align set.image_id' Set.image_id'
theorem image_id (s : Set α) : id '' s = s := by simp
#align set.image_id Set.image_id
lemma image_iterate_eq {f : α → α} {n : ℕ} : image (f^[n]) = (image f)^[n] := by
induction' n with n ih; · simp
rw [iterate_succ', iterate_succ',← ih, image_comp_eq]
theorem compl_compl_image [BooleanAlgebra α] (S : Set α) :
HasCompl.compl '' (HasCompl.compl '' S) = S := by
rw [← image_comp, compl_comp_compl, image_id]
#align set.compl_compl_image Set.compl_compl_image
theorem image_insert_eq {f : α → β} {a : α} {s : Set α} :
f '' insert a s = insert (f a) (f '' s) := by
ext
simp [and_or_left, exists_or, eq_comm, or_comm, and_comm]
#align set.image_insert_eq Set.image_insert_eq
theorem image_pair (f : α → β) (a b : α) : f '' {a, b} = {f a, f b} := by
simp only [image_insert_eq, image_singleton]
#align set.image_pair Set.image_pair
theorem image_subset_preimage_of_inverse {f : α → β} {g : β → α} (I : LeftInverse g f) (s : Set α) :
f '' s ⊆ g ⁻¹' s := fun _ ⟨a, h, e⟩ => e ▸ ((I a).symm ▸ h : g (f a) ∈ s)
#align set.image_subset_preimage_of_inverse Set.image_subset_preimage_of_inverse
theorem preimage_subset_image_of_inverse {f : α → β} {g : β → α} (I : LeftInverse g f) (s : Set β) :
f ⁻¹' s ⊆ g '' s := fun b h => ⟨f b, h, I b⟩
#align set.preimage_subset_image_of_inverse Set.preimage_subset_image_of_inverse
theorem image_eq_preimage_of_inverse {f : α → β} {g : β → α} (h₁ : LeftInverse g f)
(h₂ : RightInverse g f) : image f = preimage g :=
funext fun s =>
Subset.antisymm (image_subset_preimage_of_inverse h₁ s) (preimage_subset_image_of_inverse h₂ s)
#align set.image_eq_preimage_of_inverse Set.image_eq_preimage_of_inverse
theorem mem_image_iff_of_inverse {f : α → β} {g : β → α} {b : β} {s : Set α} (h₁ : LeftInverse g f)
(h₂ : RightInverse g f) : b ∈ f '' s ↔ g b ∈ s := by
rw [image_eq_preimage_of_inverse h₁ h₂]; rfl
#align set.mem_image_iff_of_inverse Set.mem_image_iff_of_inverse
theorem image_compl_subset {f : α → β} {s : Set α} (H : Injective f) : f '' sᶜ ⊆ (f '' s)ᶜ :=
Disjoint.subset_compl_left <| by simp [disjoint_iff_inf_le, ← image_inter H]
#align set.image_compl_subset Set.image_compl_subset
theorem subset_image_compl {f : α → β} {s : Set α} (H : Surjective f) : (f '' s)ᶜ ⊆ f '' sᶜ :=
compl_subset_iff_union.2 <| by
rw [← image_union]
simp [image_univ_of_surjective H]
#align set.subset_image_compl Set.subset_image_compl
theorem image_compl_eq {f : α → β} {s : Set α} (H : Bijective f) : f '' sᶜ = (f '' s)ᶜ :=
Subset.antisymm (image_compl_subset H.1) (subset_image_compl H.2)
#align set.image_compl_eq Set.image_compl_eq
theorem subset_image_diff (f : α → β) (s t : Set α) : f '' s \ f '' t ⊆ f '' (s \ t) := by
rw [diff_subset_iff, ← image_union, union_diff_self]
exact image_subset f (subset_union_right t s)
#align set.subset_image_diff Set.subset_image_diff
theorem subset_image_symmDiff : (f '' s) ∆ (f '' t) ⊆ f '' s ∆ t :=
(union_subset_union (subset_image_diff _ _ _) <| subset_image_diff _ _ _).trans
(superset_of_eq (image_union _ _ _))
#align set.subset_image_symm_diff Set.subset_image_symmDiff
theorem image_diff {f : α → β} (hf : Injective f) (s t : Set α) : f '' (s \ t) = f '' s \ f '' t :=
Subset.antisymm
(Subset.trans (image_inter_subset _ _ _) <| inter_subset_inter_right _ <| image_compl_subset hf)
(subset_image_diff f s t)
#align set.image_diff Set.image_diff
theorem image_symmDiff (hf : Injective f) (s t : Set α) : f '' s ∆ t = (f '' s) ∆ (f '' t) := by
simp_rw [Set.symmDiff_def, image_union, image_diff hf]
#align set.image_symm_diff Set.image_symmDiff
theorem Nonempty.image (f : α → β) {s : Set α} : s.Nonempty → (f '' s).Nonempty
| ⟨x, hx⟩ => ⟨f x, mem_image_of_mem f hx⟩
#align set.nonempty.image Set.Nonempty.image
theorem Nonempty.of_image {f : α → β} {s : Set α} : (f '' s).Nonempty → s.Nonempty
| ⟨_, x, hx, _⟩ => ⟨x, hx⟩
#align set.nonempty.of_image Set.Nonempty.of_image
@[simp]
theorem nonempty_image_iff {f : α → β} {s : Set α} : (f '' s).Nonempty ↔ s.Nonempty :=
⟨Nonempty.of_image, fun h => h.image f⟩
#align set.nonempty_image_iff Set.nonempty_image_iff
theorem Nonempty.preimage {s : Set β} (hs : s.Nonempty) {f : α → β} (hf : Surjective f) :
(f ⁻¹' s).Nonempty :=
let ⟨y, hy⟩ := hs
let ⟨x, hx⟩ := hf y
⟨x, mem_preimage.2 <| hx.symm ▸ hy⟩
#align set.nonempty.preimage Set.Nonempty.preimage
instance (f : α → β) (s : Set α) [Nonempty s] : Nonempty (f '' s) :=
(Set.Nonempty.image f nonempty_of_nonempty_subtype).to_subtype
/-- image and preimage are a Galois connection -/
@[simp]
theorem image_subset_iff {s : Set α} {t : Set β} {f : α → β} : f '' s ⊆ t ↔ s ⊆ f ⁻¹' t :=
ball_image_iff
#align set.image_subset_iff Set.image_subset_iff
theorem image_preimage_subset (f : α → β) (s : Set β) : f '' (f ⁻¹' s) ⊆ s :=
image_subset_iff.2 Subset.rfl
#align set.image_preimage_subset Set.image_preimage_subset
theorem subset_preimage_image (f : α → β) (s : Set α) : s ⊆ f ⁻¹' (f '' s) := fun _ =>
mem_image_of_mem f
#align set.subset_preimage_image Set.subset_preimage_image
@[simp]
theorem preimage_image_eq {f : α → β} (s : Set α) (h : Injective f) : f ⁻¹' (f '' s) = s :=
Subset.antisymm (fun _ ⟨_, hy, e⟩ => h e ▸ hy) (subset_preimage_image f s)
#align set.preimage_image_eq Set.preimage_image_eq
@[simp]
theorem image_preimage_eq {f : α → β} (s : Set β) (h : Surjective f) : f '' (f ⁻¹' s) = s :=
Subset.antisymm (image_preimage_subset f s) fun x hx =>
let ⟨y, e⟩ := h x
⟨y, (e.symm ▸ hx : f y ∈ s), e⟩
#align set.image_preimage_eq Set.image_preimage_eq
@[simp]
theorem preimage_eq_preimage {f : β → α} (hf : Surjective f) : f ⁻¹' s = f ⁻¹' t ↔ s = t :=
Iff.intro
fun eq => by rw [← image_preimage_eq s hf, ← image_preimage_eq t hf, eq]
fun eq => eq ▸ rfl
#align set.preimage_eq_preimage Set.preimage_eq_preimage
theorem image_inter_preimage (f : α → β) (s : Set α) (t : Set β) :
f '' (s ∩ f ⁻¹' t) = f '' s ∩ t := by
apply Subset.antisymm
· calc
f '' (s ∩ f ⁻¹' t) ⊆ f '' s ∩ f '' (f ⁻¹' t) := image_inter_subset _ _ _
_ ⊆ f '' s ∩ t := inter_subset_inter_right _ (image_preimage_subset f t)
· rintro _ ⟨⟨x, h', rfl⟩, h⟩
exact ⟨x, ⟨h', h⟩, rfl⟩
#align set.image_inter_preimage Set.image_inter_preimage
theorem image_preimage_inter (f : α → β) (s : Set α) (t : Set β) :
f '' (f ⁻¹' t ∩ s) = t ∩ f '' s := by simp only [inter_comm, image_inter_preimage]
#align set.image_preimage_inter Set.image_preimage_inter
@[simp]
theorem image_inter_nonempty_iff {f : α → β} {s : Set α} {t : Set β} :
(f '' s ∩ t).Nonempty ↔ (s ∩ f ⁻¹' t).Nonempty := by
rw [← image_inter_preimage, nonempty_image_iff]
#align set.image_inter_nonempty_iff Set.image_inter_nonempty_iff
theorem image_diff_preimage {f : α → β} {s : Set α} {t : Set β} : f '' (s \ f ⁻¹' t) = f '' s \ t :=
by simp_rw [diff_eq, ← preimage_compl, image_inter_preimage]
#align set.image_diff_preimage Set.image_diff_preimage
theorem compl_image : image (compl : Set α → Set α) = preimage compl :=
image_eq_preimage_of_inverse compl_compl compl_compl
#align set.compl_image Set.compl_image
theorem compl_image_set_of {p : Set α → Prop} : compl '' { s | p s } = { s | p sᶜ } :=
congr_fun compl_image p
#align set.compl_image_set_of Set.compl_image_set_of
theorem inter_preimage_subset (s : Set α) (t : Set β) (f : α → β) :
s ∩ f ⁻¹' t ⊆ f ⁻¹' (f '' s ∩ t) := fun _ h => ⟨mem_image_of_mem _ h.left, h.right⟩
#align set.inter_preimage_subset Set.inter_preimage_subset
theorem union_preimage_subset (s : Set α) (t : Set β) (f : α → β) :
s ∪ f ⁻¹' t ⊆ f ⁻¹' (f '' s ∪ t) := fun _ h =>
Or.elim h (fun l => Or.inl <| mem_image_of_mem _ l) fun r => Or.inr r
#align set.union_preimage_subset Set.union_preimage_subset
theorem subset_image_union (f : α → β) (s : Set α) (t : Set β) : f '' (s ∪ f ⁻¹' t) ⊆ f '' s ∪ t :=
image_subset_iff.2 (union_preimage_subset _ _ _)
#align set.subset_image_union Set.subset_image_union
theorem preimage_subset_iff {A : Set α} {B : Set β} {f : α → β} :
f ⁻¹' B ⊆ A ↔ ∀ a : α, f a ∈ B → a ∈ A :=
Iff.rfl
#align set.preimage_subset_iff Set.preimage_subset_iff
theorem image_eq_image {f : α → β} (hf : Injective f) : f '' s = f '' t ↔ s = t :=
Iff.symm <|
(Iff.intro fun eq => eq ▸ rfl) fun eq => by
rw [← preimage_image_eq s hf, ← preimage_image_eq t hf, eq]
#align set.image_eq_image Set.image_eq_image
theorem image_subset_image_iff {f : α → β} (hf : Injective f) : f '' s ⊆ f '' t ↔ s ⊆ t := by
|
refine' Iff.symm <| (Iff.intro (image_subset f)) fun h => _
|
theorem image_subset_image_iff {f : α → β} (hf : Injective f) : f '' s ⊆ f '' t ↔ s ⊆ t := by
|
Mathlib.Data.Set.Image.597_0.IJFiTzmYGOCpPSd
|
theorem image_subset_image_iff {f : α → β} (hf : Injective f) : f '' s ⊆ f '' t ↔ s ⊆ t
|
Mathlib_Data_Set_Image
|
α : Type u_1
β : Type u_2
γ : Type u_3
ι : Sort u_4
ι' : Sort u_5
f✝ : α → β
s t : Set α
f : α → β
hf : Injective f
h : f '' s ⊆ f '' t
⊢ s ⊆ t
|
/-
Copyright (c) 2014 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Leonardo de Moura
-/
import Mathlib.Data.Set.Basic
#align_import data.set.image from "leanprover-community/mathlib"@"001ffdc42920050657fd45bd2b8bfbec8eaaeb29"
/-!
# Images and preimages of sets
## Main definitions
* `preimage f t : Set α` : the preimage f⁻¹(t) (written `f ⁻¹' t` in Lean) of a subset of β.
* `range f : Set β` : the image of `univ` under `f`.
Also works for `{p : Prop} (f : p → α)` (unlike `image`)
## Notation
* `f ⁻¹' t` for `Set.preimage f t`
* `f '' s` for `Set.image f s`
## Tags
set, sets, image, preimage, pre-image, range
-/
set_option autoImplicit true
universe u v
open Function Set
namespace Set
variable {α β γ : Type*} {ι ι' : Sort*}
/-! ### Inverse image -/
/-- The preimage of `s : Set β` by `f : α → β`, written `f ⁻¹' s`,
is the set of `x : α` such that `f x ∈ s`. -/
def preimage {α : Type u} {β : Type v} (f : α → β) (s : Set β) : Set α :=
{ x | f x ∈ s }
#align set.preimage Set.preimage
/-- `f ⁻¹' t` denotes the preimage of `t : Set β` under the function `f : α → β`. -/
infixl:80 " ⁻¹' " => preimage
section Preimage
variable {f : α → β} {g : β → γ}
@[simp]
theorem preimage_empty : f ⁻¹' ∅ = ∅ :=
rfl
#align set.preimage_empty Set.preimage_empty
@[simp, mfld_simps]
theorem mem_preimage {s : Set β} {a : α} : a ∈ f ⁻¹' s ↔ f a ∈ s :=
Iff.rfl
#align set.mem_preimage Set.mem_preimage
theorem preimage_congr {f g : α → β} {s : Set β} (h : ∀ x : α, f x = g x) : f ⁻¹' s = g ⁻¹' s := by
congr with x
simp [h]
#align set.preimage_congr Set.preimage_congr
@[gcongr]
theorem preimage_mono {s t : Set β} (h : s ⊆ t) : f ⁻¹' s ⊆ f ⁻¹' t := fun _ hx => h hx
#align set.preimage_mono Set.preimage_mono
@[simp, mfld_simps]
theorem preimage_univ : f ⁻¹' univ = univ :=
rfl
#align set.preimage_univ Set.preimage_univ
theorem subset_preimage_univ {s : Set α} : s ⊆ f ⁻¹' univ :=
subset_univ _
#align set.subset_preimage_univ Set.subset_preimage_univ
@[simp, mfld_simps]
theorem preimage_inter {s t : Set β} : f ⁻¹' (s ∩ t) = f ⁻¹' s ∩ f ⁻¹' t :=
rfl
#align set.preimage_inter Set.preimage_inter
@[simp]
theorem preimage_union {s t : Set β} : f ⁻¹' (s ∪ t) = f ⁻¹' s ∪ f ⁻¹' t :=
rfl
#align set.preimage_union Set.preimage_union
@[simp]
theorem preimage_compl {s : Set β} : f ⁻¹' sᶜ = (f ⁻¹' s)ᶜ :=
rfl
#align set.preimage_compl Set.preimage_compl
@[simp]
theorem preimage_diff (f : α → β) (s t : Set β) : f ⁻¹' (s \ t) = f ⁻¹' s \ f ⁻¹' t :=
rfl
#align set.preimage_diff Set.preimage_diff
@[simp]
lemma preimage_symmDiff {f : α → β} (s t : Set β) : f ⁻¹' (s ∆ t) = (f ⁻¹' s) ∆ (f ⁻¹' t) :=
rfl
#align set.preimage_symm_diff Set.preimage_symmDiff
@[simp]
theorem preimage_ite (f : α → β) (s t₁ t₂ : Set β) :
f ⁻¹' s.ite t₁ t₂ = (f ⁻¹' s).ite (f ⁻¹' t₁) (f ⁻¹' t₂) :=
rfl
#align set.preimage_ite Set.preimage_ite
@[simp]
theorem preimage_setOf_eq {p : α → Prop} {f : β → α} : f ⁻¹' { a | p a } = { a | p (f a) } :=
rfl
#align set.preimage_set_of_eq Set.preimage_setOf_eq
@[simp]
theorem preimage_id_eq : preimage (id : α → α) = id :=
rfl
#align set.preimage_id_eq Set.preimage_id_eq
@[mfld_simps]
theorem preimage_id {s : Set α} : id ⁻¹' s = s :=
rfl
#align set.preimage_id Set.preimage_id
@[simp, mfld_simps]
theorem preimage_id' {s : Set α} : (fun x => x) ⁻¹' s = s :=
rfl
#align set.preimage_id' Set.preimage_id'
@[simp]
theorem preimage_const_of_mem {b : β} {s : Set β} (h : b ∈ s) : (fun _ : α => b) ⁻¹' s = univ :=
eq_univ_of_forall fun _ => h
#align set.preimage_const_of_mem Set.preimage_const_of_mem
@[simp]
theorem preimage_const_of_not_mem {b : β} {s : Set β} (h : b ∉ s) : (fun _ : α => b) ⁻¹' s = ∅ :=
eq_empty_of_subset_empty fun _ hx => h hx
#align set.preimage_const_of_not_mem Set.preimage_const_of_not_mem
theorem preimage_const (b : β) (s : Set β) [Decidable (b ∈ s)] :
(fun _ : α => b) ⁻¹' s = if b ∈ s then univ else ∅ := by
split_ifs with hb
exacts [preimage_const_of_mem hb, preimage_const_of_not_mem hb]
#align set.preimage_const Set.preimage_const
/-- If preimage of each singleton under `f : α → β` is either empty or the whole type,
then `f` is a constant. -/
lemma exists_eq_const_of_preimage_singleton [Nonempty β] {f : α → β}
(hf : ∀ b : β, f ⁻¹' {b} = ∅ ∨ f ⁻¹' {b} = univ) : ∃ b, f = const α b := by
rcases em (∃ b, f ⁻¹' {b} = univ) with ⟨b, hb⟩ | hf'
· exact ⟨b, funext fun x ↦ eq_univ_iff_forall.1 hb x⟩
· have : ∀ x b, f x ≠ b := fun x b ↦
eq_empty_iff_forall_not_mem.1 ((hf b).resolve_right fun h ↦ hf' ⟨b, h⟩) x
exact ⟨Classical.arbitrary β, funext fun x ↦ absurd rfl (this x _)⟩
theorem preimage_comp {s : Set γ} : g ∘ f ⁻¹' s = f ⁻¹' (g ⁻¹' s) :=
rfl
#align set.preimage_comp Set.preimage_comp
theorem preimage_comp_eq : preimage (g ∘ f) = preimage f ∘ preimage g :=
rfl
#align set.preimage_comp_eq Set.preimage_comp_eq
theorem preimage_iterate_eq {f : α → α} {n : ℕ} : Set.preimage f^[n] = (Set.preimage f)^[n] := by
induction' n with n ih; · simp
rw [iterate_succ, iterate_succ', preimage_comp_eq, ih]
#align set.preimage_iterate_eq Set.preimage_iterate_eq
theorem preimage_preimage {g : β → γ} {f : α → β} {s : Set γ} :
f ⁻¹' (g ⁻¹' s) = (fun x => g (f x)) ⁻¹' s :=
preimage_comp.symm
#align set.preimage_preimage Set.preimage_preimage
theorem eq_preimage_subtype_val_iff {p : α → Prop} {s : Set (Subtype p)} {t : Set α} :
s = Subtype.val ⁻¹' t ↔ ∀ (x) (h : p x), (⟨x, h⟩ : Subtype p) ∈ s ↔ x ∈ t :=
⟨fun s_eq x h => by
rw [s_eq]
simp, fun h => ext fun ⟨x, hx⟩ => by simp [h]⟩
#align set.eq_preimage_subtype_val_iff Set.eq_preimage_subtype_val_iff
theorem nonempty_of_nonempty_preimage {s : Set β} {f : α → β} (hf : (f ⁻¹' s).Nonempty) :
s.Nonempty :=
let ⟨x, hx⟩ := hf
⟨f x, hx⟩
#align set.nonempty_of_nonempty_preimage Set.nonempty_of_nonempty_preimage
@[simp] theorem preimage_singleton_true (p : α → Prop) : p ⁻¹' {True} = {a | p a} := by ext; simp
#align set.preimage_singleton_true Set.preimage_singleton_true
@[simp] theorem preimage_singleton_false (p : α → Prop) : p ⁻¹' {False} = {a | ¬p a} := by ext; simp
#align set.preimage_singleton_false Set.preimage_singleton_false
theorem preimage_subtype_coe_eq_compl {s u v : Set α} (hsuv : s ⊆ u ∪ v)
(H : s ∩ (u ∩ v) = ∅) : ((↑) : s → α) ⁻¹' u = ((↑) ⁻¹' v)ᶜ := by
ext ⟨x, x_in_s⟩
constructor
· intro x_in_u x_in_v
exact eq_empty_iff_forall_not_mem.mp H x ⟨x_in_s, ⟨x_in_u, x_in_v⟩⟩
· intro hx
exact Or.elim (hsuv x_in_s) id fun hx' => hx.elim hx'
#align set.preimage_subtype_coe_eq_compl Set.preimage_subtype_coe_eq_compl
end Preimage
/-! ### Image of a set under a function -/
section Image
variable {f : α → β} {s t : Set α}
-- Porting note: `Set.image` is already defined in `Init.Set`
#align set.image Set.image
/-- `f '' s` denotes the image of `s : Set α` under the function `f : α → β`. -/
infixl:80 " '' " => image
theorem mem_image_iff_bex {f : α → β} {s : Set α} {y : β} :
y ∈ f '' s ↔ ∃ (x : _) (_ : x ∈ s), f x = y :=
bex_def.symm
#align set.mem_image_iff_bex Set.mem_image_iff_bex
@[simp]
theorem mem_image (f : α → β) (s : Set α) (y : β) : y ∈ f '' s ↔ ∃ x ∈ s, f x = y :=
Iff.rfl
#align set.mem_image Set.mem_image
theorem image_eta (f : α → β) : f '' s = (fun x => f x) '' s :=
rfl
#align set.image_eta Set.image_eta
@[mfld_simps]
theorem mem_image_of_mem (f : α → β) {x : α} {a : Set α} (h : x ∈ a) : f x ∈ f '' a :=
⟨_, h, rfl⟩
#align set.mem_image_of_mem Set.mem_image_of_mem
theorem _root_.Function.Injective.mem_set_image {f : α → β} (hf : Injective f) {s : Set α} {a : α} :
f a ∈ f '' s ↔ a ∈ s :=
⟨fun ⟨_, hb, Eq⟩ => hf Eq ▸ hb, mem_image_of_mem f⟩
#align function.injective.mem_set_image Function.Injective.mem_set_image
theorem ball_image_iff {f : α → β} {s : Set α} {p : β → Prop} :
(∀ y ∈ f '' s, p y) ↔ ∀ x ∈ s, p (f x) := by simp
#align set.ball_image_iff Set.ball_image_iff
theorem ball_image_of_ball {f : α → β} {s : Set α} {p : β → Prop} (h : ∀ x ∈ s, p (f x)) :
∀ y ∈ f '' s, p y :=
ball_image_iff.2 h
#align set.ball_image_of_ball Set.ball_image_of_ball
theorem bex_image_iff {f : α → β} {s : Set α} {p : β → Prop} :
(∃ y ∈ f '' s, p y) ↔ ∃ x ∈ s, p (f x) := by simp
#align set.bex_image_iff Set.bex_image_iff
theorem mem_image_elim {f : α → β} {s : Set α} {C : β → Prop} (h : ∀ x : α, x ∈ s → C (f x)) :
∀ {y : β}, y ∈ f '' s → C y
| _, ⟨a, a_in, rfl⟩ => h a a_in
#align set.mem_image_elim Set.mem_image_elim
theorem mem_image_elim_on {f : α → β} {s : Set α} {C : β → Prop} {y : β} (h_y : y ∈ f '' s)
(h : ∀ x : α, x ∈ s → C (f x)) : C y :=
mem_image_elim h h_y
#align set.mem_image_elim_on Set.mem_image_elim_on
-- Porting note: used to be `safe`
@[congr]
theorem image_congr {f g : α → β} {s : Set α} (h : ∀ a ∈ s, f a = g a) : f '' s = g '' s := by
ext x
rw [mem_image, mem_image]
exact {
mp := by
rintro ⟨a, ha1, ha2⟩
exact ⟨a, ⟨ha1, (h a ha1) ▸ ha2⟩⟩,
mpr := by
rintro ⟨a, ha1, ha2⟩
exact ⟨a, ⟨ha1, (h a ha1) ▸ ha2⟩⟩
}
-- safe [ext_iff, iff_def]
#align set.image_congr Set.image_congr
/-- A common special case of `image_congr` -/
theorem image_congr' {f g : α → β} {s : Set α} (h : ∀ x : α, f x = g x) : f '' s = g '' s :=
image_congr fun x _ => h x
#align set.image_congr' Set.image_congr'
@[gcongr]
lemma image_mono (h : s ⊆ t) : f '' s ⊆ f '' t := by
rintro - ⟨a, ha, rfl⟩; exact mem_image_of_mem f (h ha)
theorem image_comp (f : β → γ) (g : α → β) (a : Set α) : f ∘ g '' a = f '' (g '' a) :=
Subset.antisymm (ball_image_of_ball fun _ ha => mem_image_of_mem _ <| mem_image_of_mem _ ha)
(ball_image_of_ball <| ball_image_of_ball fun _ ha => mem_image_of_mem _ ha)
#align set.image_comp Set.image_comp
theorem image_comp_eq {g : β → γ} : image (g ∘ f) = image g ∘ image f := by ext; simp
/-- A variant of `image_comp`, useful for rewriting -/
theorem image_image (g : β → γ) (f : α → β) (s : Set α) : g '' (f '' s) = (fun x => g (f x)) '' s :=
(image_comp g f s).symm
#align set.image_image Set.image_image
theorem image_comm {β'} {f : β → γ} {g : α → β} {f' : α → β'} {g' : β' → γ}
(h_comm : ∀ a, f (g a) = g' (f' a)) : (s.image g).image f = (s.image f').image g' := by
simp_rw [image_image, h_comm]
#align set.image_comm Set.image_comm
theorem _root_.Function.Semiconj.set_image {f : α → β} {ga : α → α} {gb : β → β}
(h : Function.Semiconj f ga gb) : Function.Semiconj (image f) (image ga) (image gb) := fun _ =>
image_comm h
#align function.semiconj.set_image Function.Semiconj.set_image
theorem _root_.Function.Commute.set_image {f g : α → α} (h : Function.Commute f g) :
Function.Commute (image f) (image g) :=
Function.Semiconj.set_image h
#align function.commute.set_image Function.Commute.set_image
/-- Image is monotone with respect to `⊆`. See `Set.monotone_image` for the statement in
terms of `≤`. -/
@[gcongr]
theorem image_subset {a b : Set α} (f : α → β) (h : a ⊆ b) : f '' a ⊆ f '' b := by
simp only [subset_def, mem_image]
exact fun x => fun ⟨w, h1, h2⟩ => ⟨w, h h1, h2⟩
#align set.image_subset Set.image_subset
/-- `Set.image` is monotone. See `Set.image_subset` for the statement in terms of `⊆`. -/
lemma monotone_image {f : α → β} : Monotone (image f) := fun _ _ => image_subset _
#align set.monotone_image Set.monotone_image
theorem image_union (f : α → β) (s t : Set α) : f '' (s ∪ t) = f '' s ∪ f '' t :=
ext fun x =>
⟨by rintro ⟨a, h | h, rfl⟩ <;> [left; right] <;> exact ⟨_, h, rfl⟩, by
rintro (⟨a, h, rfl⟩ | ⟨a, h, rfl⟩) <;> refine' ⟨_, _, rfl⟩ <;> [left; right] <;> exact h⟩
#align set.image_union Set.image_union
@[simp]
theorem image_empty (f : α → β) : f '' ∅ = ∅ := by
ext
simp
#align set.image_empty Set.image_empty
theorem image_inter_subset (f : α → β) (s t : Set α) : f '' (s ∩ t) ⊆ f '' s ∩ f '' t :=
subset_inter (image_subset _ <| inter_subset_left _ _) (image_subset _ <| inter_subset_right _ _)
#align set.image_inter_subset Set.image_inter_subset
theorem image_inter_on {f : α → β} {s t : Set α} (h : ∀ x ∈ t, ∀ y ∈ s, f x = f y → x = y) :
f '' (s ∩ t) = f '' s ∩ f '' t :=
(image_inter_subset _ _ _).antisymm
fun b ⟨⟨a₁, ha₁, h₁⟩, ⟨a₂, ha₂, h₂⟩⟩ ↦
have : a₂ = a₁ := h _ ha₂ _ ha₁ (by simp [*])
⟨a₁, ⟨ha₁, this ▸ ha₂⟩, h₁⟩
#align set.image_inter_on Set.image_inter_on
theorem image_inter {f : α → β} {s t : Set α} (H : Injective f) : f '' (s ∩ t) = f '' s ∩ f '' t :=
image_inter_on fun _ _ _ _ h => H h
#align set.image_inter Set.image_inter
theorem image_univ_of_surjective {ι : Type*} {f : ι → β} (H : Surjective f) : f '' univ = univ :=
eq_univ_of_forall <| by simpa [image]
#align set.image_univ_of_surjective Set.image_univ_of_surjective
@[simp]
theorem image_singleton {f : α → β} {a : α} : f '' {a} = {f a} := by
ext
simp [image, eq_comm]
#align set.image_singleton Set.image_singleton
@[simp]
theorem Nonempty.image_const {s : Set α} (hs : s.Nonempty) (a : β) : (fun _ => a) '' s = {a} :=
ext fun _ =>
⟨fun ⟨_, _, h⟩ => h ▸ mem_singleton _, fun h =>
(eq_of_mem_singleton h).symm ▸ hs.imp fun _ hy => ⟨hy, rfl⟩⟩
#align set.nonempty.image_const Set.Nonempty.image_const
@[simp, mfld_simps]
theorem image_eq_empty {α β} {f : α → β} {s : Set α} : f '' s = ∅ ↔ s = ∅ := by
simp only [eq_empty_iff_forall_not_mem]
exact ⟨fun H a ha => H _ ⟨_, ha, rfl⟩, fun H b ⟨_, ha, _⟩ => H _ ha⟩
#align set.image_eq_empty Set.image_eq_empty
-- Porting note: `compl` is already defined in `Init.Set`
theorem preimage_compl_eq_image_compl [BooleanAlgebra α] (S : Set α) :
HasCompl.compl ⁻¹' S = HasCompl.compl '' S :=
Set.ext fun x =>
⟨fun h => ⟨xᶜ, h, compl_compl x⟩, fun h =>
Exists.elim h fun _ hy => (compl_eq_comm.mp hy.2).symm.subst hy.1⟩
#align set.preimage_compl_eq_image_compl Set.preimage_compl_eq_image_compl
theorem mem_compl_image [BooleanAlgebra α] (t : α) (S : Set α) :
t ∈ HasCompl.compl '' S ↔ tᶜ ∈ S := by
simp [← preimage_compl_eq_image_compl]
#align set.mem_compl_image Set.mem_compl_image
@[simp]
theorem image_id_eq : image (id : α → α) = id := by ext; simp
/-- A variant of `image_id` -/
@[simp]
theorem image_id' (s : Set α) : (fun x => x) '' s = s := by
ext
simp
#align set.image_id' Set.image_id'
theorem image_id (s : Set α) : id '' s = s := by simp
#align set.image_id Set.image_id
lemma image_iterate_eq {f : α → α} {n : ℕ} : image (f^[n]) = (image f)^[n] := by
induction' n with n ih; · simp
rw [iterate_succ', iterate_succ',← ih, image_comp_eq]
theorem compl_compl_image [BooleanAlgebra α] (S : Set α) :
HasCompl.compl '' (HasCompl.compl '' S) = S := by
rw [← image_comp, compl_comp_compl, image_id]
#align set.compl_compl_image Set.compl_compl_image
theorem image_insert_eq {f : α → β} {a : α} {s : Set α} :
f '' insert a s = insert (f a) (f '' s) := by
ext
simp [and_or_left, exists_or, eq_comm, or_comm, and_comm]
#align set.image_insert_eq Set.image_insert_eq
theorem image_pair (f : α → β) (a b : α) : f '' {a, b} = {f a, f b} := by
simp only [image_insert_eq, image_singleton]
#align set.image_pair Set.image_pair
theorem image_subset_preimage_of_inverse {f : α → β} {g : β → α} (I : LeftInverse g f) (s : Set α) :
f '' s ⊆ g ⁻¹' s := fun _ ⟨a, h, e⟩ => e ▸ ((I a).symm ▸ h : g (f a) ∈ s)
#align set.image_subset_preimage_of_inverse Set.image_subset_preimage_of_inverse
theorem preimage_subset_image_of_inverse {f : α → β} {g : β → α} (I : LeftInverse g f) (s : Set β) :
f ⁻¹' s ⊆ g '' s := fun b h => ⟨f b, h, I b⟩
#align set.preimage_subset_image_of_inverse Set.preimage_subset_image_of_inverse
theorem image_eq_preimage_of_inverse {f : α → β} {g : β → α} (h₁ : LeftInverse g f)
(h₂ : RightInverse g f) : image f = preimage g :=
funext fun s =>
Subset.antisymm (image_subset_preimage_of_inverse h₁ s) (preimage_subset_image_of_inverse h₂ s)
#align set.image_eq_preimage_of_inverse Set.image_eq_preimage_of_inverse
theorem mem_image_iff_of_inverse {f : α → β} {g : β → α} {b : β} {s : Set α} (h₁ : LeftInverse g f)
(h₂ : RightInverse g f) : b ∈ f '' s ↔ g b ∈ s := by
rw [image_eq_preimage_of_inverse h₁ h₂]; rfl
#align set.mem_image_iff_of_inverse Set.mem_image_iff_of_inverse
theorem image_compl_subset {f : α → β} {s : Set α} (H : Injective f) : f '' sᶜ ⊆ (f '' s)ᶜ :=
Disjoint.subset_compl_left <| by simp [disjoint_iff_inf_le, ← image_inter H]
#align set.image_compl_subset Set.image_compl_subset
theorem subset_image_compl {f : α → β} {s : Set α} (H : Surjective f) : (f '' s)ᶜ ⊆ f '' sᶜ :=
compl_subset_iff_union.2 <| by
rw [← image_union]
simp [image_univ_of_surjective H]
#align set.subset_image_compl Set.subset_image_compl
theorem image_compl_eq {f : α → β} {s : Set α} (H : Bijective f) : f '' sᶜ = (f '' s)ᶜ :=
Subset.antisymm (image_compl_subset H.1) (subset_image_compl H.2)
#align set.image_compl_eq Set.image_compl_eq
theorem subset_image_diff (f : α → β) (s t : Set α) : f '' s \ f '' t ⊆ f '' (s \ t) := by
rw [diff_subset_iff, ← image_union, union_diff_self]
exact image_subset f (subset_union_right t s)
#align set.subset_image_diff Set.subset_image_diff
theorem subset_image_symmDiff : (f '' s) ∆ (f '' t) ⊆ f '' s ∆ t :=
(union_subset_union (subset_image_diff _ _ _) <| subset_image_diff _ _ _).trans
(superset_of_eq (image_union _ _ _))
#align set.subset_image_symm_diff Set.subset_image_symmDiff
theorem image_diff {f : α → β} (hf : Injective f) (s t : Set α) : f '' (s \ t) = f '' s \ f '' t :=
Subset.antisymm
(Subset.trans (image_inter_subset _ _ _) <| inter_subset_inter_right _ <| image_compl_subset hf)
(subset_image_diff f s t)
#align set.image_diff Set.image_diff
theorem image_symmDiff (hf : Injective f) (s t : Set α) : f '' s ∆ t = (f '' s) ∆ (f '' t) := by
simp_rw [Set.symmDiff_def, image_union, image_diff hf]
#align set.image_symm_diff Set.image_symmDiff
theorem Nonempty.image (f : α → β) {s : Set α} : s.Nonempty → (f '' s).Nonempty
| ⟨x, hx⟩ => ⟨f x, mem_image_of_mem f hx⟩
#align set.nonempty.image Set.Nonempty.image
theorem Nonempty.of_image {f : α → β} {s : Set α} : (f '' s).Nonempty → s.Nonempty
| ⟨_, x, hx, _⟩ => ⟨x, hx⟩
#align set.nonempty.of_image Set.Nonempty.of_image
@[simp]
theorem nonempty_image_iff {f : α → β} {s : Set α} : (f '' s).Nonempty ↔ s.Nonempty :=
⟨Nonempty.of_image, fun h => h.image f⟩
#align set.nonempty_image_iff Set.nonempty_image_iff
theorem Nonempty.preimage {s : Set β} (hs : s.Nonempty) {f : α → β} (hf : Surjective f) :
(f ⁻¹' s).Nonempty :=
let ⟨y, hy⟩ := hs
let ⟨x, hx⟩ := hf y
⟨x, mem_preimage.2 <| hx.symm ▸ hy⟩
#align set.nonempty.preimage Set.Nonempty.preimage
instance (f : α → β) (s : Set α) [Nonempty s] : Nonempty (f '' s) :=
(Set.Nonempty.image f nonempty_of_nonempty_subtype).to_subtype
/-- image and preimage are a Galois connection -/
@[simp]
theorem image_subset_iff {s : Set α} {t : Set β} {f : α → β} : f '' s ⊆ t ↔ s ⊆ f ⁻¹' t :=
ball_image_iff
#align set.image_subset_iff Set.image_subset_iff
theorem image_preimage_subset (f : α → β) (s : Set β) : f '' (f ⁻¹' s) ⊆ s :=
image_subset_iff.2 Subset.rfl
#align set.image_preimage_subset Set.image_preimage_subset
theorem subset_preimage_image (f : α → β) (s : Set α) : s ⊆ f ⁻¹' (f '' s) := fun _ =>
mem_image_of_mem f
#align set.subset_preimage_image Set.subset_preimage_image
@[simp]
theorem preimage_image_eq {f : α → β} (s : Set α) (h : Injective f) : f ⁻¹' (f '' s) = s :=
Subset.antisymm (fun _ ⟨_, hy, e⟩ => h e ▸ hy) (subset_preimage_image f s)
#align set.preimage_image_eq Set.preimage_image_eq
@[simp]
theorem image_preimage_eq {f : α → β} (s : Set β) (h : Surjective f) : f '' (f ⁻¹' s) = s :=
Subset.antisymm (image_preimage_subset f s) fun x hx =>
let ⟨y, e⟩ := h x
⟨y, (e.symm ▸ hx : f y ∈ s), e⟩
#align set.image_preimage_eq Set.image_preimage_eq
@[simp]
theorem preimage_eq_preimage {f : β → α} (hf : Surjective f) : f ⁻¹' s = f ⁻¹' t ↔ s = t :=
Iff.intro
fun eq => by rw [← image_preimage_eq s hf, ← image_preimage_eq t hf, eq]
fun eq => eq ▸ rfl
#align set.preimage_eq_preimage Set.preimage_eq_preimage
theorem image_inter_preimage (f : α → β) (s : Set α) (t : Set β) :
f '' (s ∩ f ⁻¹' t) = f '' s ∩ t := by
apply Subset.antisymm
· calc
f '' (s ∩ f ⁻¹' t) ⊆ f '' s ∩ f '' (f ⁻¹' t) := image_inter_subset _ _ _
_ ⊆ f '' s ∩ t := inter_subset_inter_right _ (image_preimage_subset f t)
· rintro _ ⟨⟨x, h', rfl⟩, h⟩
exact ⟨x, ⟨h', h⟩, rfl⟩
#align set.image_inter_preimage Set.image_inter_preimage
theorem image_preimage_inter (f : α → β) (s : Set α) (t : Set β) :
f '' (f ⁻¹' t ∩ s) = t ∩ f '' s := by simp only [inter_comm, image_inter_preimage]
#align set.image_preimage_inter Set.image_preimage_inter
@[simp]
theorem image_inter_nonempty_iff {f : α → β} {s : Set α} {t : Set β} :
(f '' s ∩ t).Nonempty ↔ (s ∩ f ⁻¹' t).Nonempty := by
rw [← image_inter_preimage, nonempty_image_iff]
#align set.image_inter_nonempty_iff Set.image_inter_nonempty_iff
theorem image_diff_preimage {f : α → β} {s : Set α} {t : Set β} : f '' (s \ f ⁻¹' t) = f '' s \ t :=
by simp_rw [diff_eq, ← preimage_compl, image_inter_preimage]
#align set.image_diff_preimage Set.image_diff_preimage
theorem compl_image : image (compl : Set α → Set α) = preimage compl :=
image_eq_preimage_of_inverse compl_compl compl_compl
#align set.compl_image Set.compl_image
theorem compl_image_set_of {p : Set α → Prop} : compl '' { s | p s } = { s | p sᶜ } :=
congr_fun compl_image p
#align set.compl_image_set_of Set.compl_image_set_of
theorem inter_preimage_subset (s : Set α) (t : Set β) (f : α → β) :
s ∩ f ⁻¹' t ⊆ f ⁻¹' (f '' s ∩ t) := fun _ h => ⟨mem_image_of_mem _ h.left, h.right⟩
#align set.inter_preimage_subset Set.inter_preimage_subset
theorem union_preimage_subset (s : Set α) (t : Set β) (f : α → β) :
s ∪ f ⁻¹' t ⊆ f ⁻¹' (f '' s ∪ t) := fun _ h =>
Or.elim h (fun l => Or.inl <| mem_image_of_mem _ l) fun r => Or.inr r
#align set.union_preimage_subset Set.union_preimage_subset
theorem subset_image_union (f : α → β) (s : Set α) (t : Set β) : f '' (s ∪ f ⁻¹' t) ⊆ f '' s ∪ t :=
image_subset_iff.2 (union_preimage_subset _ _ _)
#align set.subset_image_union Set.subset_image_union
theorem preimage_subset_iff {A : Set α} {B : Set β} {f : α → β} :
f ⁻¹' B ⊆ A ↔ ∀ a : α, f a ∈ B → a ∈ A :=
Iff.rfl
#align set.preimage_subset_iff Set.preimage_subset_iff
theorem image_eq_image {f : α → β} (hf : Injective f) : f '' s = f '' t ↔ s = t :=
Iff.symm <|
(Iff.intro fun eq => eq ▸ rfl) fun eq => by
rw [← preimage_image_eq s hf, ← preimage_image_eq t hf, eq]
#align set.image_eq_image Set.image_eq_image
theorem image_subset_image_iff {f : α → β} (hf : Injective f) : f '' s ⊆ f '' t ↔ s ⊆ t := by
refine' Iff.symm <| (Iff.intro (image_subset f)) fun h => _
|
rw [← preimage_image_eq s hf, ← preimage_image_eq t hf]
|
theorem image_subset_image_iff {f : α → β} (hf : Injective f) : f '' s ⊆ f '' t ↔ s ⊆ t := by
refine' Iff.symm <| (Iff.intro (image_subset f)) fun h => _
|
Mathlib.Data.Set.Image.597_0.IJFiTzmYGOCpPSd
|
theorem image_subset_image_iff {f : α → β} (hf : Injective f) : f '' s ⊆ f '' t ↔ s ⊆ t
|
Mathlib_Data_Set_Image
|
α : Type u_1
β : Type u_2
γ : Type u_3
ι : Sort u_4
ι' : Sort u_5
f✝ : α → β
s t : Set α
f : α → β
hf : Injective f
h : f '' s ⊆ f '' t
⊢ f ⁻¹' (f '' s) ⊆ f ⁻¹' (f '' t)
|
/-
Copyright (c) 2014 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Leonardo de Moura
-/
import Mathlib.Data.Set.Basic
#align_import data.set.image from "leanprover-community/mathlib"@"001ffdc42920050657fd45bd2b8bfbec8eaaeb29"
/-!
# Images and preimages of sets
## Main definitions
* `preimage f t : Set α` : the preimage f⁻¹(t) (written `f ⁻¹' t` in Lean) of a subset of β.
* `range f : Set β` : the image of `univ` under `f`.
Also works for `{p : Prop} (f : p → α)` (unlike `image`)
## Notation
* `f ⁻¹' t` for `Set.preimage f t`
* `f '' s` for `Set.image f s`
## Tags
set, sets, image, preimage, pre-image, range
-/
set_option autoImplicit true
universe u v
open Function Set
namespace Set
variable {α β γ : Type*} {ι ι' : Sort*}
/-! ### Inverse image -/
/-- The preimage of `s : Set β` by `f : α → β`, written `f ⁻¹' s`,
is the set of `x : α` such that `f x ∈ s`. -/
def preimage {α : Type u} {β : Type v} (f : α → β) (s : Set β) : Set α :=
{ x | f x ∈ s }
#align set.preimage Set.preimage
/-- `f ⁻¹' t` denotes the preimage of `t : Set β` under the function `f : α → β`. -/
infixl:80 " ⁻¹' " => preimage
section Preimage
variable {f : α → β} {g : β → γ}
@[simp]
theorem preimage_empty : f ⁻¹' ∅ = ∅ :=
rfl
#align set.preimage_empty Set.preimage_empty
@[simp, mfld_simps]
theorem mem_preimage {s : Set β} {a : α} : a ∈ f ⁻¹' s ↔ f a ∈ s :=
Iff.rfl
#align set.mem_preimage Set.mem_preimage
theorem preimage_congr {f g : α → β} {s : Set β} (h : ∀ x : α, f x = g x) : f ⁻¹' s = g ⁻¹' s := by
congr with x
simp [h]
#align set.preimage_congr Set.preimage_congr
@[gcongr]
theorem preimage_mono {s t : Set β} (h : s ⊆ t) : f ⁻¹' s ⊆ f ⁻¹' t := fun _ hx => h hx
#align set.preimage_mono Set.preimage_mono
@[simp, mfld_simps]
theorem preimage_univ : f ⁻¹' univ = univ :=
rfl
#align set.preimage_univ Set.preimage_univ
theorem subset_preimage_univ {s : Set α} : s ⊆ f ⁻¹' univ :=
subset_univ _
#align set.subset_preimage_univ Set.subset_preimage_univ
@[simp, mfld_simps]
theorem preimage_inter {s t : Set β} : f ⁻¹' (s ∩ t) = f ⁻¹' s ∩ f ⁻¹' t :=
rfl
#align set.preimage_inter Set.preimage_inter
@[simp]
theorem preimage_union {s t : Set β} : f ⁻¹' (s ∪ t) = f ⁻¹' s ∪ f ⁻¹' t :=
rfl
#align set.preimage_union Set.preimage_union
@[simp]
theorem preimage_compl {s : Set β} : f ⁻¹' sᶜ = (f ⁻¹' s)ᶜ :=
rfl
#align set.preimage_compl Set.preimage_compl
@[simp]
theorem preimage_diff (f : α → β) (s t : Set β) : f ⁻¹' (s \ t) = f ⁻¹' s \ f ⁻¹' t :=
rfl
#align set.preimage_diff Set.preimage_diff
@[simp]
lemma preimage_symmDiff {f : α → β} (s t : Set β) : f ⁻¹' (s ∆ t) = (f ⁻¹' s) ∆ (f ⁻¹' t) :=
rfl
#align set.preimage_symm_diff Set.preimage_symmDiff
@[simp]
theorem preimage_ite (f : α → β) (s t₁ t₂ : Set β) :
f ⁻¹' s.ite t₁ t₂ = (f ⁻¹' s).ite (f ⁻¹' t₁) (f ⁻¹' t₂) :=
rfl
#align set.preimage_ite Set.preimage_ite
@[simp]
theorem preimage_setOf_eq {p : α → Prop} {f : β → α} : f ⁻¹' { a | p a } = { a | p (f a) } :=
rfl
#align set.preimage_set_of_eq Set.preimage_setOf_eq
@[simp]
theorem preimage_id_eq : preimage (id : α → α) = id :=
rfl
#align set.preimage_id_eq Set.preimage_id_eq
@[mfld_simps]
theorem preimage_id {s : Set α} : id ⁻¹' s = s :=
rfl
#align set.preimage_id Set.preimage_id
@[simp, mfld_simps]
theorem preimage_id' {s : Set α} : (fun x => x) ⁻¹' s = s :=
rfl
#align set.preimage_id' Set.preimage_id'
@[simp]
theorem preimage_const_of_mem {b : β} {s : Set β} (h : b ∈ s) : (fun _ : α => b) ⁻¹' s = univ :=
eq_univ_of_forall fun _ => h
#align set.preimage_const_of_mem Set.preimage_const_of_mem
@[simp]
theorem preimage_const_of_not_mem {b : β} {s : Set β} (h : b ∉ s) : (fun _ : α => b) ⁻¹' s = ∅ :=
eq_empty_of_subset_empty fun _ hx => h hx
#align set.preimage_const_of_not_mem Set.preimage_const_of_not_mem
theorem preimage_const (b : β) (s : Set β) [Decidable (b ∈ s)] :
(fun _ : α => b) ⁻¹' s = if b ∈ s then univ else ∅ := by
split_ifs with hb
exacts [preimage_const_of_mem hb, preimage_const_of_not_mem hb]
#align set.preimage_const Set.preimage_const
/-- If preimage of each singleton under `f : α → β` is either empty or the whole type,
then `f` is a constant. -/
lemma exists_eq_const_of_preimage_singleton [Nonempty β] {f : α → β}
(hf : ∀ b : β, f ⁻¹' {b} = ∅ ∨ f ⁻¹' {b} = univ) : ∃ b, f = const α b := by
rcases em (∃ b, f ⁻¹' {b} = univ) with ⟨b, hb⟩ | hf'
· exact ⟨b, funext fun x ↦ eq_univ_iff_forall.1 hb x⟩
· have : ∀ x b, f x ≠ b := fun x b ↦
eq_empty_iff_forall_not_mem.1 ((hf b).resolve_right fun h ↦ hf' ⟨b, h⟩) x
exact ⟨Classical.arbitrary β, funext fun x ↦ absurd rfl (this x _)⟩
theorem preimage_comp {s : Set γ} : g ∘ f ⁻¹' s = f ⁻¹' (g ⁻¹' s) :=
rfl
#align set.preimage_comp Set.preimage_comp
theorem preimage_comp_eq : preimage (g ∘ f) = preimage f ∘ preimage g :=
rfl
#align set.preimage_comp_eq Set.preimage_comp_eq
theorem preimage_iterate_eq {f : α → α} {n : ℕ} : Set.preimage f^[n] = (Set.preimage f)^[n] := by
induction' n with n ih; · simp
rw [iterate_succ, iterate_succ', preimage_comp_eq, ih]
#align set.preimage_iterate_eq Set.preimage_iterate_eq
theorem preimage_preimage {g : β → γ} {f : α → β} {s : Set γ} :
f ⁻¹' (g ⁻¹' s) = (fun x => g (f x)) ⁻¹' s :=
preimage_comp.symm
#align set.preimage_preimage Set.preimage_preimage
theorem eq_preimage_subtype_val_iff {p : α → Prop} {s : Set (Subtype p)} {t : Set α} :
s = Subtype.val ⁻¹' t ↔ ∀ (x) (h : p x), (⟨x, h⟩ : Subtype p) ∈ s ↔ x ∈ t :=
⟨fun s_eq x h => by
rw [s_eq]
simp, fun h => ext fun ⟨x, hx⟩ => by simp [h]⟩
#align set.eq_preimage_subtype_val_iff Set.eq_preimage_subtype_val_iff
theorem nonempty_of_nonempty_preimage {s : Set β} {f : α → β} (hf : (f ⁻¹' s).Nonempty) :
s.Nonempty :=
let ⟨x, hx⟩ := hf
⟨f x, hx⟩
#align set.nonempty_of_nonempty_preimage Set.nonempty_of_nonempty_preimage
@[simp] theorem preimage_singleton_true (p : α → Prop) : p ⁻¹' {True} = {a | p a} := by ext; simp
#align set.preimage_singleton_true Set.preimage_singleton_true
@[simp] theorem preimage_singleton_false (p : α → Prop) : p ⁻¹' {False} = {a | ¬p a} := by ext; simp
#align set.preimage_singleton_false Set.preimage_singleton_false
theorem preimage_subtype_coe_eq_compl {s u v : Set α} (hsuv : s ⊆ u ∪ v)
(H : s ∩ (u ∩ v) = ∅) : ((↑) : s → α) ⁻¹' u = ((↑) ⁻¹' v)ᶜ := by
ext ⟨x, x_in_s⟩
constructor
· intro x_in_u x_in_v
exact eq_empty_iff_forall_not_mem.mp H x ⟨x_in_s, ⟨x_in_u, x_in_v⟩⟩
· intro hx
exact Or.elim (hsuv x_in_s) id fun hx' => hx.elim hx'
#align set.preimage_subtype_coe_eq_compl Set.preimage_subtype_coe_eq_compl
end Preimage
/-! ### Image of a set under a function -/
section Image
variable {f : α → β} {s t : Set α}
-- Porting note: `Set.image` is already defined in `Init.Set`
#align set.image Set.image
/-- `f '' s` denotes the image of `s : Set α` under the function `f : α → β`. -/
infixl:80 " '' " => image
theorem mem_image_iff_bex {f : α → β} {s : Set α} {y : β} :
y ∈ f '' s ↔ ∃ (x : _) (_ : x ∈ s), f x = y :=
bex_def.symm
#align set.mem_image_iff_bex Set.mem_image_iff_bex
@[simp]
theorem mem_image (f : α → β) (s : Set α) (y : β) : y ∈ f '' s ↔ ∃ x ∈ s, f x = y :=
Iff.rfl
#align set.mem_image Set.mem_image
theorem image_eta (f : α → β) : f '' s = (fun x => f x) '' s :=
rfl
#align set.image_eta Set.image_eta
@[mfld_simps]
theorem mem_image_of_mem (f : α → β) {x : α} {a : Set α} (h : x ∈ a) : f x ∈ f '' a :=
⟨_, h, rfl⟩
#align set.mem_image_of_mem Set.mem_image_of_mem
theorem _root_.Function.Injective.mem_set_image {f : α → β} (hf : Injective f) {s : Set α} {a : α} :
f a ∈ f '' s ↔ a ∈ s :=
⟨fun ⟨_, hb, Eq⟩ => hf Eq ▸ hb, mem_image_of_mem f⟩
#align function.injective.mem_set_image Function.Injective.mem_set_image
theorem ball_image_iff {f : α → β} {s : Set α} {p : β → Prop} :
(∀ y ∈ f '' s, p y) ↔ ∀ x ∈ s, p (f x) := by simp
#align set.ball_image_iff Set.ball_image_iff
theorem ball_image_of_ball {f : α → β} {s : Set α} {p : β → Prop} (h : ∀ x ∈ s, p (f x)) :
∀ y ∈ f '' s, p y :=
ball_image_iff.2 h
#align set.ball_image_of_ball Set.ball_image_of_ball
theorem bex_image_iff {f : α → β} {s : Set α} {p : β → Prop} :
(∃ y ∈ f '' s, p y) ↔ ∃ x ∈ s, p (f x) := by simp
#align set.bex_image_iff Set.bex_image_iff
theorem mem_image_elim {f : α → β} {s : Set α} {C : β → Prop} (h : ∀ x : α, x ∈ s → C (f x)) :
∀ {y : β}, y ∈ f '' s → C y
| _, ⟨a, a_in, rfl⟩ => h a a_in
#align set.mem_image_elim Set.mem_image_elim
theorem mem_image_elim_on {f : α → β} {s : Set α} {C : β → Prop} {y : β} (h_y : y ∈ f '' s)
(h : ∀ x : α, x ∈ s → C (f x)) : C y :=
mem_image_elim h h_y
#align set.mem_image_elim_on Set.mem_image_elim_on
-- Porting note: used to be `safe`
@[congr]
theorem image_congr {f g : α → β} {s : Set α} (h : ∀ a ∈ s, f a = g a) : f '' s = g '' s := by
ext x
rw [mem_image, mem_image]
exact {
mp := by
rintro ⟨a, ha1, ha2⟩
exact ⟨a, ⟨ha1, (h a ha1) ▸ ha2⟩⟩,
mpr := by
rintro ⟨a, ha1, ha2⟩
exact ⟨a, ⟨ha1, (h a ha1) ▸ ha2⟩⟩
}
-- safe [ext_iff, iff_def]
#align set.image_congr Set.image_congr
/-- A common special case of `image_congr` -/
theorem image_congr' {f g : α → β} {s : Set α} (h : ∀ x : α, f x = g x) : f '' s = g '' s :=
image_congr fun x _ => h x
#align set.image_congr' Set.image_congr'
@[gcongr]
lemma image_mono (h : s ⊆ t) : f '' s ⊆ f '' t := by
rintro - ⟨a, ha, rfl⟩; exact mem_image_of_mem f (h ha)
theorem image_comp (f : β → γ) (g : α → β) (a : Set α) : f ∘ g '' a = f '' (g '' a) :=
Subset.antisymm (ball_image_of_ball fun _ ha => mem_image_of_mem _ <| mem_image_of_mem _ ha)
(ball_image_of_ball <| ball_image_of_ball fun _ ha => mem_image_of_mem _ ha)
#align set.image_comp Set.image_comp
theorem image_comp_eq {g : β → γ} : image (g ∘ f) = image g ∘ image f := by ext; simp
/-- A variant of `image_comp`, useful for rewriting -/
theorem image_image (g : β → γ) (f : α → β) (s : Set α) : g '' (f '' s) = (fun x => g (f x)) '' s :=
(image_comp g f s).symm
#align set.image_image Set.image_image
theorem image_comm {β'} {f : β → γ} {g : α → β} {f' : α → β'} {g' : β' → γ}
(h_comm : ∀ a, f (g a) = g' (f' a)) : (s.image g).image f = (s.image f').image g' := by
simp_rw [image_image, h_comm]
#align set.image_comm Set.image_comm
theorem _root_.Function.Semiconj.set_image {f : α → β} {ga : α → α} {gb : β → β}
(h : Function.Semiconj f ga gb) : Function.Semiconj (image f) (image ga) (image gb) := fun _ =>
image_comm h
#align function.semiconj.set_image Function.Semiconj.set_image
theorem _root_.Function.Commute.set_image {f g : α → α} (h : Function.Commute f g) :
Function.Commute (image f) (image g) :=
Function.Semiconj.set_image h
#align function.commute.set_image Function.Commute.set_image
/-- Image is monotone with respect to `⊆`. See `Set.monotone_image` for the statement in
terms of `≤`. -/
@[gcongr]
theorem image_subset {a b : Set α} (f : α → β) (h : a ⊆ b) : f '' a ⊆ f '' b := by
simp only [subset_def, mem_image]
exact fun x => fun ⟨w, h1, h2⟩ => ⟨w, h h1, h2⟩
#align set.image_subset Set.image_subset
/-- `Set.image` is monotone. See `Set.image_subset` for the statement in terms of `⊆`. -/
lemma monotone_image {f : α → β} : Monotone (image f) := fun _ _ => image_subset _
#align set.monotone_image Set.monotone_image
theorem image_union (f : α → β) (s t : Set α) : f '' (s ∪ t) = f '' s ∪ f '' t :=
ext fun x =>
⟨by rintro ⟨a, h | h, rfl⟩ <;> [left; right] <;> exact ⟨_, h, rfl⟩, by
rintro (⟨a, h, rfl⟩ | ⟨a, h, rfl⟩) <;> refine' ⟨_, _, rfl⟩ <;> [left; right] <;> exact h⟩
#align set.image_union Set.image_union
@[simp]
theorem image_empty (f : α → β) : f '' ∅ = ∅ := by
ext
simp
#align set.image_empty Set.image_empty
theorem image_inter_subset (f : α → β) (s t : Set α) : f '' (s ∩ t) ⊆ f '' s ∩ f '' t :=
subset_inter (image_subset _ <| inter_subset_left _ _) (image_subset _ <| inter_subset_right _ _)
#align set.image_inter_subset Set.image_inter_subset
theorem image_inter_on {f : α → β} {s t : Set α} (h : ∀ x ∈ t, ∀ y ∈ s, f x = f y → x = y) :
f '' (s ∩ t) = f '' s ∩ f '' t :=
(image_inter_subset _ _ _).antisymm
fun b ⟨⟨a₁, ha₁, h₁⟩, ⟨a₂, ha₂, h₂⟩⟩ ↦
have : a₂ = a₁ := h _ ha₂ _ ha₁ (by simp [*])
⟨a₁, ⟨ha₁, this ▸ ha₂⟩, h₁⟩
#align set.image_inter_on Set.image_inter_on
theorem image_inter {f : α → β} {s t : Set α} (H : Injective f) : f '' (s ∩ t) = f '' s ∩ f '' t :=
image_inter_on fun _ _ _ _ h => H h
#align set.image_inter Set.image_inter
theorem image_univ_of_surjective {ι : Type*} {f : ι → β} (H : Surjective f) : f '' univ = univ :=
eq_univ_of_forall <| by simpa [image]
#align set.image_univ_of_surjective Set.image_univ_of_surjective
@[simp]
theorem image_singleton {f : α → β} {a : α} : f '' {a} = {f a} := by
ext
simp [image, eq_comm]
#align set.image_singleton Set.image_singleton
@[simp]
theorem Nonempty.image_const {s : Set α} (hs : s.Nonempty) (a : β) : (fun _ => a) '' s = {a} :=
ext fun _ =>
⟨fun ⟨_, _, h⟩ => h ▸ mem_singleton _, fun h =>
(eq_of_mem_singleton h).symm ▸ hs.imp fun _ hy => ⟨hy, rfl⟩⟩
#align set.nonempty.image_const Set.Nonempty.image_const
@[simp, mfld_simps]
theorem image_eq_empty {α β} {f : α → β} {s : Set α} : f '' s = ∅ ↔ s = ∅ := by
simp only [eq_empty_iff_forall_not_mem]
exact ⟨fun H a ha => H _ ⟨_, ha, rfl⟩, fun H b ⟨_, ha, _⟩ => H _ ha⟩
#align set.image_eq_empty Set.image_eq_empty
-- Porting note: `compl` is already defined in `Init.Set`
theorem preimage_compl_eq_image_compl [BooleanAlgebra α] (S : Set α) :
HasCompl.compl ⁻¹' S = HasCompl.compl '' S :=
Set.ext fun x =>
⟨fun h => ⟨xᶜ, h, compl_compl x⟩, fun h =>
Exists.elim h fun _ hy => (compl_eq_comm.mp hy.2).symm.subst hy.1⟩
#align set.preimage_compl_eq_image_compl Set.preimage_compl_eq_image_compl
theorem mem_compl_image [BooleanAlgebra α] (t : α) (S : Set α) :
t ∈ HasCompl.compl '' S ↔ tᶜ ∈ S := by
simp [← preimage_compl_eq_image_compl]
#align set.mem_compl_image Set.mem_compl_image
@[simp]
theorem image_id_eq : image (id : α → α) = id := by ext; simp
/-- A variant of `image_id` -/
@[simp]
theorem image_id' (s : Set α) : (fun x => x) '' s = s := by
ext
simp
#align set.image_id' Set.image_id'
theorem image_id (s : Set α) : id '' s = s := by simp
#align set.image_id Set.image_id
lemma image_iterate_eq {f : α → α} {n : ℕ} : image (f^[n]) = (image f)^[n] := by
induction' n with n ih; · simp
rw [iterate_succ', iterate_succ',← ih, image_comp_eq]
theorem compl_compl_image [BooleanAlgebra α] (S : Set α) :
HasCompl.compl '' (HasCompl.compl '' S) = S := by
rw [← image_comp, compl_comp_compl, image_id]
#align set.compl_compl_image Set.compl_compl_image
theorem image_insert_eq {f : α → β} {a : α} {s : Set α} :
f '' insert a s = insert (f a) (f '' s) := by
ext
simp [and_or_left, exists_or, eq_comm, or_comm, and_comm]
#align set.image_insert_eq Set.image_insert_eq
theorem image_pair (f : α → β) (a b : α) : f '' {a, b} = {f a, f b} := by
simp only [image_insert_eq, image_singleton]
#align set.image_pair Set.image_pair
theorem image_subset_preimage_of_inverse {f : α → β} {g : β → α} (I : LeftInverse g f) (s : Set α) :
f '' s ⊆ g ⁻¹' s := fun _ ⟨a, h, e⟩ => e ▸ ((I a).symm ▸ h : g (f a) ∈ s)
#align set.image_subset_preimage_of_inverse Set.image_subset_preimage_of_inverse
theorem preimage_subset_image_of_inverse {f : α → β} {g : β → α} (I : LeftInverse g f) (s : Set β) :
f ⁻¹' s ⊆ g '' s := fun b h => ⟨f b, h, I b⟩
#align set.preimage_subset_image_of_inverse Set.preimage_subset_image_of_inverse
theorem image_eq_preimage_of_inverse {f : α → β} {g : β → α} (h₁ : LeftInverse g f)
(h₂ : RightInverse g f) : image f = preimage g :=
funext fun s =>
Subset.antisymm (image_subset_preimage_of_inverse h₁ s) (preimage_subset_image_of_inverse h₂ s)
#align set.image_eq_preimage_of_inverse Set.image_eq_preimage_of_inverse
theorem mem_image_iff_of_inverse {f : α → β} {g : β → α} {b : β} {s : Set α} (h₁ : LeftInverse g f)
(h₂ : RightInverse g f) : b ∈ f '' s ↔ g b ∈ s := by
rw [image_eq_preimage_of_inverse h₁ h₂]; rfl
#align set.mem_image_iff_of_inverse Set.mem_image_iff_of_inverse
theorem image_compl_subset {f : α → β} {s : Set α} (H : Injective f) : f '' sᶜ ⊆ (f '' s)ᶜ :=
Disjoint.subset_compl_left <| by simp [disjoint_iff_inf_le, ← image_inter H]
#align set.image_compl_subset Set.image_compl_subset
theorem subset_image_compl {f : α → β} {s : Set α} (H : Surjective f) : (f '' s)ᶜ ⊆ f '' sᶜ :=
compl_subset_iff_union.2 <| by
rw [← image_union]
simp [image_univ_of_surjective H]
#align set.subset_image_compl Set.subset_image_compl
theorem image_compl_eq {f : α → β} {s : Set α} (H : Bijective f) : f '' sᶜ = (f '' s)ᶜ :=
Subset.antisymm (image_compl_subset H.1) (subset_image_compl H.2)
#align set.image_compl_eq Set.image_compl_eq
theorem subset_image_diff (f : α → β) (s t : Set α) : f '' s \ f '' t ⊆ f '' (s \ t) := by
rw [diff_subset_iff, ← image_union, union_diff_self]
exact image_subset f (subset_union_right t s)
#align set.subset_image_diff Set.subset_image_diff
theorem subset_image_symmDiff : (f '' s) ∆ (f '' t) ⊆ f '' s ∆ t :=
(union_subset_union (subset_image_diff _ _ _) <| subset_image_diff _ _ _).trans
(superset_of_eq (image_union _ _ _))
#align set.subset_image_symm_diff Set.subset_image_symmDiff
theorem image_diff {f : α → β} (hf : Injective f) (s t : Set α) : f '' (s \ t) = f '' s \ f '' t :=
Subset.antisymm
(Subset.trans (image_inter_subset _ _ _) <| inter_subset_inter_right _ <| image_compl_subset hf)
(subset_image_diff f s t)
#align set.image_diff Set.image_diff
theorem image_symmDiff (hf : Injective f) (s t : Set α) : f '' s ∆ t = (f '' s) ∆ (f '' t) := by
simp_rw [Set.symmDiff_def, image_union, image_diff hf]
#align set.image_symm_diff Set.image_symmDiff
theorem Nonempty.image (f : α → β) {s : Set α} : s.Nonempty → (f '' s).Nonempty
| ⟨x, hx⟩ => ⟨f x, mem_image_of_mem f hx⟩
#align set.nonempty.image Set.Nonempty.image
theorem Nonempty.of_image {f : α → β} {s : Set α} : (f '' s).Nonempty → s.Nonempty
| ⟨_, x, hx, _⟩ => ⟨x, hx⟩
#align set.nonempty.of_image Set.Nonempty.of_image
@[simp]
theorem nonempty_image_iff {f : α → β} {s : Set α} : (f '' s).Nonempty ↔ s.Nonempty :=
⟨Nonempty.of_image, fun h => h.image f⟩
#align set.nonempty_image_iff Set.nonempty_image_iff
theorem Nonempty.preimage {s : Set β} (hs : s.Nonempty) {f : α → β} (hf : Surjective f) :
(f ⁻¹' s).Nonempty :=
let ⟨y, hy⟩ := hs
let ⟨x, hx⟩ := hf y
⟨x, mem_preimage.2 <| hx.symm ▸ hy⟩
#align set.nonempty.preimage Set.Nonempty.preimage
instance (f : α → β) (s : Set α) [Nonempty s] : Nonempty (f '' s) :=
(Set.Nonempty.image f nonempty_of_nonempty_subtype).to_subtype
/-- image and preimage are a Galois connection -/
@[simp]
theorem image_subset_iff {s : Set α} {t : Set β} {f : α → β} : f '' s ⊆ t ↔ s ⊆ f ⁻¹' t :=
ball_image_iff
#align set.image_subset_iff Set.image_subset_iff
theorem image_preimage_subset (f : α → β) (s : Set β) : f '' (f ⁻¹' s) ⊆ s :=
image_subset_iff.2 Subset.rfl
#align set.image_preimage_subset Set.image_preimage_subset
theorem subset_preimage_image (f : α → β) (s : Set α) : s ⊆ f ⁻¹' (f '' s) := fun _ =>
mem_image_of_mem f
#align set.subset_preimage_image Set.subset_preimage_image
@[simp]
theorem preimage_image_eq {f : α → β} (s : Set α) (h : Injective f) : f ⁻¹' (f '' s) = s :=
Subset.antisymm (fun _ ⟨_, hy, e⟩ => h e ▸ hy) (subset_preimage_image f s)
#align set.preimage_image_eq Set.preimage_image_eq
@[simp]
theorem image_preimage_eq {f : α → β} (s : Set β) (h : Surjective f) : f '' (f ⁻¹' s) = s :=
Subset.antisymm (image_preimage_subset f s) fun x hx =>
let ⟨y, e⟩ := h x
⟨y, (e.symm ▸ hx : f y ∈ s), e⟩
#align set.image_preimage_eq Set.image_preimage_eq
@[simp]
theorem preimage_eq_preimage {f : β → α} (hf : Surjective f) : f ⁻¹' s = f ⁻¹' t ↔ s = t :=
Iff.intro
fun eq => by rw [← image_preimage_eq s hf, ← image_preimage_eq t hf, eq]
fun eq => eq ▸ rfl
#align set.preimage_eq_preimage Set.preimage_eq_preimage
theorem image_inter_preimage (f : α → β) (s : Set α) (t : Set β) :
f '' (s ∩ f ⁻¹' t) = f '' s ∩ t := by
apply Subset.antisymm
· calc
f '' (s ∩ f ⁻¹' t) ⊆ f '' s ∩ f '' (f ⁻¹' t) := image_inter_subset _ _ _
_ ⊆ f '' s ∩ t := inter_subset_inter_right _ (image_preimage_subset f t)
· rintro _ ⟨⟨x, h', rfl⟩, h⟩
exact ⟨x, ⟨h', h⟩, rfl⟩
#align set.image_inter_preimage Set.image_inter_preimage
theorem image_preimage_inter (f : α → β) (s : Set α) (t : Set β) :
f '' (f ⁻¹' t ∩ s) = t ∩ f '' s := by simp only [inter_comm, image_inter_preimage]
#align set.image_preimage_inter Set.image_preimage_inter
@[simp]
theorem image_inter_nonempty_iff {f : α → β} {s : Set α} {t : Set β} :
(f '' s ∩ t).Nonempty ↔ (s ∩ f ⁻¹' t).Nonempty := by
rw [← image_inter_preimage, nonempty_image_iff]
#align set.image_inter_nonempty_iff Set.image_inter_nonempty_iff
theorem image_diff_preimage {f : α → β} {s : Set α} {t : Set β} : f '' (s \ f ⁻¹' t) = f '' s \ t :=
by simp_rw [diff_eq, ← preimage_compl, image_inter_preimage]
#align set.image_diff_preimage Set.image_diff_preimage
theorem compl_image : image (compl : Set α → Set α) = preimage compl :=
image_eq_preimage_of_inverse compl_compl compl_compl
#align set.compl_image Set.compl_image
theorem compl_image_set_of {p : Set α → Prop} : compl '' { s | p s } = { s | p sᶜ } :=
congr_fun compl_image p
#align set.compl_image_set_of Set.compl_image_set_of
theorem inter_preimage_subset (s : Set α) (t : Set β) (f : α → β) :
s ∩ f ⁻¹' t ⊆ f ⁻¹' (f '' s ∩ t) := fun _ h => ⟨mem_image_of_mem _ h.left, h.right⟩
#align set.inter_preimage_subset Set.inter_preimage_subset
theorem union_preimage_subset (s : Set α) (t : Set β) (f : α → β) :
s ∪ f ⁻¹' t ⊆ f ⁻¹' (f '' s ∪ t) := fun _ h =>
Or.elim h (fun l => Or.inl <| mem_image_of_mem _ l) fun r => Or.inr r
#align set.union_preimage_subset Set.union_preimage_subset
theorem subset_image_union (f : α → β) (s : Set α) (t : Set β) : f '' (s ∪ f ⁻¹' t) ⊆ f '' s ∪ t :=
image_subset_iff.2 (union_preimage_subset _ _ _)
#align set.subset_image_union Set.subset_image_union
theorem preimage_subset_iff {A : Set α} {B : Set β} {f : α → β} :
f ⁻¹' B ⊆ A ↔ ∀ a : α, f a ∈ B → a ∈ A :=
Iff.rfl
#align set.preimage_subset_iff Set.preimage_subset_iff
theorem image_eq_image {f : α → β} (hf : Injective f) : f '' s = f '' t ↔ s = t :=
Iff.symm <|
(Iff.intro fun eq => eq ▸ rfl) fun eq => by
rw [← preimage_image_eq s hf, ← preimage_image_eq t hf, eq]
#align set.image_eq_image Set.image_eq_image
theorem image_subset_image_iff {f : α → β} (hf : Injective f) : f '' s ⊆ f '' t ↔ s ⊆ t := by
refine' Iff.symm <| (Iff.intro (image_subset f)) fun h => _
rw [← preimage_image_eq s hf, ← preimage_image_eq t hf]
|
exact preimage_mono h
|
theorem image_subset_image_iff {f : α → β} (hf : Injective f) : f '' s ⊆ f '' t ↔ s ⊆ t := by
refine' Iff.symm <| (Iff.intro (image_subset f)) fun h => _
rw [← preimage_image_eq s hf, ← preimage_image_eq t hf]
|
Mathlib.Data.Set.Image.597_0.IJFiTzmYGOCpPSd
|
theorem image_subset_image_iff {f : α → β} (hf : Injective f) : f '' s ⊆ f '' t ↔ s ⊆ t
|
Mathlib_Data_Set_Image
|
α : Type u_1
β : Type u_2
γ : Type u_3
ι : Sort u_4
ι' : Sort u_5
f : α → β
s✝ t s : Set α
σ : Equiv.Perm α
hs : {a | σ a ≠ a} ⊆ s
⊢ ⇑σ '' s = s
|
/-
Copyright (c) 2014 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Leonardo de Moura
-/
import Mathlib.Data.Set.Basic
#align_import data.set.image from "leanprover-community/mathlib"@"001ffdc42920050657fd45bd2b8bfbec8eaaeb29"
/-!
# Images and preimages of sets
## Main definitions
* `preimage f t : Set α` : the preimage f⁻¹(t) (written `f ⁻¹' t` in Lean) of a subset of β.
* `range f : Set β` : the image of `univ` under `f`.
Also works for `{p : Prop} (f : p → α)` (unlike `image`)
## Notation
* `f ⁻¹' t` for `Set.preimage f t`
* `f '' s` for `Set.image f s`
## Tags
set, sets, image, preimage, pre-image, range
-/
set_option autoImplicit true
universe u v
open Function Set
namespace Set
variable {α β γ : Type*} {ι ι' : Sort*}
/-! ### Inverse image -/
/-- The preimage of `s : Set β` by `f : α → β`, written `f ⁻¹' s`,
is the set of `x : α` such that `f x ∈ s`. -/
def preimage {α : Type u} {β : Type v} (f : α → β) (s : Set β) : Set α :=
{ x | f x ∈ s }
#align set.preimage Set.preimage
/-- `f ⁻¹' t` denotes the preimage of `t : Set β` under the function `f : α → β`. -/
infixl:80 " ⁻¹' " => preimage
section Preimage
variable {f : α → β} {g : β → γ}
@[simp]
theorem preimage_empty : f ⁻¹' ∅ = ∅ :=
rfl
#align set.preimage_empty Set.preimage_empty
@[simp, mfld_simps]
theorem mem_preimage {s : Set β} {a : α} : a ∈ f ⁻¹' s ↔ f a ∈ s :=
Iff.rfl
#align set.mem_preimage Set.mem_preimage
theorem preimage_congr {f g : α → β} {s : Set β} (h : ∀ x : α, f x = g x) : f ⁻¹' s = g ⁻¹' s := by
congr with x
simp [h]
#align set.preimage_congr Set.preimage_congr
@[gcongr]
theorem preimage_mono {s t : Set β} (h : s ⊆ t) : f ⁻¹' s ⊆ f ⁻¹' t := fun _ hx => h hx
#align set.preimage_mono Set.preimage_mono
@[simp, mfld_simps]
theorem preimage_univ : f ⁻¹' univ = univ :=
rfl
#align set.preimage_univ Set.preimage_univ
theorem subset_preimage_univ {s : Set α} : s ⊆ f ⁻¹' univ :=
subset_univ _
#align set.subset_preimage_univ Set.subset_preimage_univ
@[simp, mfld_simps]
theorem preimage_inter {s t : Set β} : f ⁻¹' (s ∩ t) = f ⁻¹' s ∩ f ⁻¹' t :=
rfl
#align set.preimage_inter Set.preimage_inter
@[simp]
theorem preimage_union {s t : Set β} : f ⁻¹' (s ∪ t) = f ⁻¹' s ∪ f ⁻¹' t :=
rfl
#align set.preimage_union Set.preimage_union
@[simp]
theorem preimage_compl {s : Set β} : f ⁻¹' sᶜ = (f ⁻¹' s)ᶜ :=
rfl
#align set.preimage_compl Set.preimage_compl
@[simp]
theorem preimage_diff (f : α → β) (s t : Set β) : f ⁻¹' (s \ t) = f ⁻¹' s \ f ⁻¹' t :=
rfl
#align set.preimage_diff Set.preimage_diff
@[simp]
lemma preimage_symmDiff {f : α → β} (s t : Set β) : f ⁻¹' (s ∆ t) = (f ⁻¹' s) ∆ (f ⁻¹' t) :=
rfl
#align set.preimage_symm_diff Set.preimage_symmDiff
@[simp]
theorem preimage_ite (f : α → β) (s t₁ t₂ : Set β) :
f ⁻¹' s.ite t₁ t₂ = (f ⁻¹' s).ite (f ⁻¹' t₁) (f ⁻¹' t₂) :=
rfl
#align set.preimage_ite Set.preimage_ite
@[simp]
theorem preimage_setOf_eq {p : α → Prop} {f : β → α} : f ⁻¹' { a | p a } = { a | p (f a) } :=
rfl
#align set.preimage_set_of_eq Set.preimage_setOf_eq
@[simp]
theorem preimage_id_eq : preimage (id : α → α) = id :=
rfl
#align set.preimage_id_eq Set.preimage_id_eq
@[mfld_simps]
theorem preimage_id {s : Set α} : id ⁻¹' s = s :=
rfl
#align set.preimage_id Set.preimage_id
@[simp, mfld_simps]
theorem preimage_id' {s : Set α} : (fun x => x) ⁻¹' s = s :=
rfl
#align set.preimage_id' Set.preimage_id'
@[simp]
theorem preimage_const_of_mem {b : β} {s : Set β} (h : b ∈ s) : (fun _ : α => b) ⁻¹' s = univ :=
eq_univ_of_forall fun _ => h
#align set.preimage_const_of_mem Set.preimage_const_of_mem
@[simp]
theorem preimage_const_of_not_mem {b : β} {s : Set β} (h : b ∉ s) : (fun _ : α => b) ⁻¹' s = ∅ :=
eq_empty_of_subset_empty fun _ hx => h hx
#align set.preimage_const_of_not_mem Set.preimage_const_of_not_mem
theorem preimage_const (b : β) (s : Set β) [Decidable (b ∈ s)] :
(fun _ : α => b) ⁻¹' s = if b ∈ s then univ else ∅ := by
split_ifs with hb
exacts [preimage_const_of_mem hb, preimage_const_of_not_mem hb]
#align set.preimage_const Set.preimage_const
/-- If preimage of each singleton under `f : α → β` is either empty or the whole type,
then `f` is a constant. -/
lemma exists_eq_const_of_preimage_singleton [Nonempty β] {f : α → β}
(hf : ∀ b : β, f ⁻¹' {b} = ∅ ∨ f ⁻¹' {b} = univ) : ∃ b, f = const α b := by
rcases em (∃ b, f ⁻¹' {b} = univ) with ⟨b, hb⟩ | hf'
· exact ⟨b, funext fun x ↦ eq_univ_iff_forall.1 hb x⟩
· have : ∀ x b, f x ≠ b := fun x b ↦
eq_empty_iff_forall_not_mem.1 ((hf b).resolve_right fun h ↦ hf' ⟨b, h⟩) x
exact ⟨Classical.arbitrary β, funext fun x ↦ absurd rfl (this x _)⟩
theorem preimage_comp {s : Set γ} : g ∘ f ⁻¹' s = f ⁻¹' (g ⁻¹' s) :=
rfl
#align set.preimage_comp Set.preimage_comp
theorem preimage_comp_eq : preimage (g ∘ f) = preimage f ∘ preimage g :=
rfl
#align set.preimage_comp_eq Set.preimage_comp_eq
theorem preimage_iterate_eq {f : α → α} {n : ℕ} : Set.preimage f^[n] = (Set.preimage f)^[n] := by
induction' n with n ih; · simp
rw [iterate_succ, iterate_succ', preimage_comp_eq, ih]
#align set.preimage_iterate_eq Set.preimage_iterate_eq
theorem preimage_preimage {g : β → γ} {f : α → β} {s : Set γ} :
f ⁻¹' (g ⁻¹' s) = (fun x => g (f x)) ⁻¹' s :=
preimage_comp.symm
#align set.preimage_preimage Set.preimage_preimage
theorem eq_preimage_subtype_val_iff {p : α → Prop} {s : Set (Subtype p)} {t : Set α} :
s = Subtype.val ⁻¹' t ↔ ∀ (x) (h : p x), (⟨x, h⟩ : Subtype p) ∈ s ↔ x ∈ t :=
⟨fun s_eq x h => by
rw [s_eq]
simp, fun h => ext fun ⟨x, hx⟩ => by simp [h]⟩
#align set.eq_preimage_subtype_val_iff Set.eq_preimage_subtype_val_iff
theorem nonempty_of_nonempty_preimage {s : Set β} {f : α → β} (hf : (f ⁻¹' s).Nonempty) :
s.Nonempty :=
let ⟨x, hx⟩ := hf
⟨f x, hx⟩
#align set.nonempty_of_nonempty_preimage Set.nonempty_of_nonempty_preimage
@[simp] theorem preimage_singleton_true (p : α → Prop) : p ⁻¹' {True} = {a | p a} := by ext; simp
#align set.preimage_singleton_true Set.preimage_singleton_true
@[simp] theorem preimage_singleton_false (p : α → Prop) : p ⁻¹' {False} = {a | ¬p a} := by ext; simp
#align set.preimage_singleton_false Set.preimage_singleton_false
theorem preimage_subtype_coe_eq_compl {s u v : Set α} (hsuv : s ⊆ u ∪ v)
(H : s ∩ (u ∩ v) = ∅) : ((↑) : s → α) ⁻¹' u = ((↑) ⁻¹' v)ᶜ := by
ext ⟨x, x_in_s⟩
constructor
· intro x_in_u x_in_v
exact eq_empty_iff_forall_not_mem.mp H x ⟨x_in_s, ⟨x_in_u, x_in_v⟩⟩
· intro hx
exact Or.elim (hsuv x_in_s) id fun hx' => hx.elim hx'
#align set.preimage_subtype_coe_eq_compl Set.preimage_subtype_coe_eq_compl
end Preimage
/-! ### Image of a set under a function -/
section Image
variable {f : α → β} {s t : Set α}
-- Porting note: `Set.image` is already defined in `Init.Set`
#align set.image Set.image
/-- `f '' s` denotes the image of `s : Set α` under the function `f : α → β`. -/
infixl:80 " '' " => image
theorem mem_image_iff_bex {f : α → β} {s : Set α} {y : β} :
y ∈ f '' s ↔ ∃ (x : _) (_ : x ∈ s), f x = y :=
bex_def.symm
#align set.mem_image_iff_bex Set.mem_image_iff_bex
@[simp]
theorem mem_image (f : α → β) (s : Set α) (y : β) : y ∈ f '' s ↔ ∃ x ∈ s, f x = y :=
Iff.rfl
#align set.mem_image Set.mem_image
theorem image_eta (f : α → β) : f '' s = (fun x => f x) '' s :=
rfl
#align set.image_eta Set.image_eta
@[mfld_simps]
theorem mem_image_of_mem (f : α → β) {x : α} {a : Set α} (h : x ∈ a) : f x ∈ f '' a :=
⟨_, h, rfl⟩
#align set.mem_image_of_mem Set.mem_image_of_mem
theorem _root_.Function.Injective.mem_set_image {f : α → β} (hf : Injective f) {s : Set α} {a : α} :
f a ∈ f '' s ↔ a ∈ s :=
⟨fun ⟨_, hb, Eq⟩ => hf Eq ▸ hb, mem_image_of_mem f⟩
#align function.injective.mem_set_image Function.Injective.mem_set_image
theorem ball_image_iff {f : α → β} {s : Set α} {p : β → Prop} :
(∀ y ∈ f '' s, p y) ↔ ∀ x ∈ s, p (f x) := by simp
#align set.ball_image_iff Set.ball_image_iff
theorem ball_image_of_ball {f : α → β} {s : Set α} {p : β → Prop} (h : ∀ x ∈ s, p (f x)) :
∀ y ∈ f '' s, p y :=
ball_image_iff.2 h
#align set.ball_image_of_ball Set.ball_image_of_ball
theorem bex_image_iff {f : α → β} {s : Set α} {p : β → Prop} :
(∃ y ∈ f '' s, p y) ↔ ∃ x ∈ s, p (f x) := by simp
#align set.bex_image_iff Set.bex_image_iff
theorem mem_image_elim {f : α → β} {s : Set α} {C : β → Prop} (h : ∀ x : α, x ∈ s → C (f x)) :
∀ {y : β}, y ∈ f '' s → C y
| _, ⟨a, a_in, rfl⟩ => h a a_in
#align set.mem_image_elim Set.mem_image_elim
theorem mem_image_elim_on {f : α → β} {s : Set α} {C : β → Prop} {y : β} (h_y : y ∈ f '' s)
(h : ∀ x : α, x ∈ s → C (f x)) : C y :=
mem_image_elim h h_y
#align set.mem_image_elim_on Set.mem_image_elim_on
-- Porting note: used to be `safe`
@[congr]
theorem image_congr {f g : α → β} {s : Set α} (h : ∀ a ∈ s, f a = g a) : f '' s = g '' s := by
ext x
rw [mem_image, mem_image]
exact {
mp := by
rintro ⟨a, ha1, ha2⟩
exact ⟨a, ⟨ha1, (h a ha1) ▸ ha2⟩⟩,
mpr := by
rintro ⟨a, ha1, ha2⟩
exact ⟨a, ⟨ha1, (h a ha1) ▸ ha2⟩⟩
}
-- safe [ext_iff, iff_def]
#align set.image_congr Set.image_congr
/-- A common special case of `image_congr` -/
theorem image_congr' {f g : α → β} {s : Set α} (h : ∀ x : α, f x = g x) : f '' s = g '' s :=
image_congr fun x _ => h x
#align set.image_congr' Set.image_congr'
@[gcongr]
lemma image_mono (h : s ⊆ t) : f '' s ⊆ f '' t := by
rintro - ⟨a, ha, rfl⟩; exact mem_image_of_mem f (h ha)
theorem image_comp (f : β → γ) (g : α → β) (a : Set α) : f ∘ g '' a = f '' (g '' a) :=
Subset.antisymm (ball_image_of_ball fun _ ha => mem_image_of_mem _ <| mem_image_of_mem _ ha)
(ball_image_of_ball <| ball_image_of_ball fun _ ha => mem_image_of_mem _ ha)
#align set.image_comp Set.image_comp
theorem image_comp_eq {g : β → γ} : image (g ∘ f) = image g ∘ image f := by ext; simp
/-- A variant of `image_comp`, useful for rewriting -/
theorem image_image (g : β → γ) (f : α → β) (s : Set α) : g '' (f '' s) = (fun x => g (f x)) '' s :=
(image_comp g f s).symm
#align set.image_image Set.image_image
theorem image_comm {β'} {f : β → γ} {g : α → β} {f' : α → β'} {g' : β' → γ}
(h_comm : ∀ a, f (g a) = g' (f' a)) : (s.image g).image f = (s.image f').image g' := by
simp_rw [image_image, h_comm]
#align set.image_comm Set.image_comm
theorem _root_.Function.Semiconj.set_image {f : α → β} {ga : α → α} {gb : β → β}
(h : Function.Semiconj f ga gb) : Function.Semiconj (image f) (image ga) (image gb) := fun _ =>
image_comm h
#align function.semiconj.set_image Function.Semiconj.set_image
theorem _root_.Function.Commute.set_image {f g : α → α} (h : Function.Commute f g) :
Function.Commute (image f) (image g) :=
Function.Semiconj.set_image h
#align function.commute.set_image Function.Commute.set_image
/-- Image is monotone with respect to `⊆`. See `Set.monotone_image` for the statement in
terms of `≤`. -/
@[gcongr]
theorem image_subset {a b : Set α} (f : α → β) (h : a ⊆ b) : f '' a ⊆ f '' b := by
simp only [subset_def, mem_image]
exact fun x => fun ⟨w, h1, h2⟩ => ⟨w, h h1, h2⟩
#align set.image_subset Set.image_subset
/-- `Set.image` is monotone. See `Set.image_subset` for the statement in terms of `⊆`. -/
lemma monotone_image {f : α → β} : Monotone (image f) := fun _ _ => image_subset _
#align set.monotone_image Set.monotone_image
theorem image_union (f : α → β) (s t : Set α) : f '' (s ∪ t) = f '' s ∪ f '' t :=
ext fun x =>
⟨by rintro ⟨a, h | h, rfl⟩ <;> [left; right] <;> exact ⟨_, h, rfl⟩, by
rintro (⟨a, h, rfl⟩ | ⟨a, h, rfl⟩) <;> refine' ⟨_, _, rfl⟩ <;> [left; right] <;> exact h⟩
#align set.image_union Set.image_union
@[simp]
theorem image_empty (f : α → β) : f '' ∅ = ∅ := by
ext
simp
#align set.image_empty Set.image_empty
theorem image_inter_subset (f : α → β) (s t : Set α) : f '' (s ∩ t) ⊆ f '' s ∩ f '' t :=
subset_inter (image_subset _ <| inter_subset_left _ _) (image_subset _ <| inter_subset_right _ _)
#align set.image_inter_subset Set.image_inter_subset
theorem image_inter_on {f : α → β} {s t : Set α} (h : ∀ x ∈ t, ∀ y ∈ s, f x = f y → x = y) :
f '' (s ∩ t) = f '' s ∩ f '' t :=
(image_inter_subset _ _ _).antisymm
fun b ⟨⟨a₁, ha₁, h₁⟩, ⟨a₂, ha₂, h₂⟩⟩ ↦
have : a₂ = a₁ := h _ ha₂ _ ha₁ (by simp [*])
⟨a₁, ⟨ha₁, this ▸ ha₂⟩, h₁⟩
#align set.image_inter_on Set.image_inter_on
theorem image_inter {f : α → β} {s t : Set α} (H : Injective f) : f '' (s ∩ t) = f '' s ∩ f '' t :=
image_inter_on fun _ _ _ _ h => H h
#align set.image_inter Set.image_inter
theorem image_univ_of_surjective {ι : Type*} {f : ι → β} (H : Surjective f) : f '' univ = univ :=
eq_univ_of_forall <| by simpa [image]
#align set.image_univ_of_surjective Set.image_univ_of_surjective
@[simp]
theorem image_singleton {f : α → β} {a : α} : f '' {a} = {f a} := by
ext
simp [image, eq_comm]
#align set.image_singleton Set.image_singleton
@[simp]
theorem Nonempty.image_const {s : Set α} (hs : s.Nonempty) (a : β) : (fun _ => a) '' s = {a} :=
ext fun _ =>
⟨fun ⟨_, _, h⟩ => h ▸ mem_singleton _, fun h =>
(eq_of_mem_singleton h).symm ▸ hs.imp fun _ hy => ⟨hy, rfl⟩⟩
#align set.nonempty.image_const Set.Nonempty.image_const
@[simp, mfld_simps]
theorem image_eq_empty {α β} {f : α → β} {s : Set α} : f '' s = ∅ ↔ s = ∅ := by
simp only [eq_empty_iff_forall_not_mem]
exact ⟨fun H a ha => H _ ⟨_, ha, rfl⟩, fun H b ⟨_, ha, _⟩ => H _ ha⟩
#align set.image_eq_empty Set.image_eq_empty
-- Porting note: `compl` is already defined in `Init.Set`
theorem preimage_compl_eq_image_compl [BooleanAlgebra α] (S : Set α) :
HasCompl.compl ⁻¹' S = HasCompl.compl '' S :=
Set.ext fun x =>
⟨fun h => ⟨xᶜ, h, compl_compl x⟩, fun h =>
Exists.elim h fun _ hy => (compl_eq_comm.mp hy.2).symm.subst hy.1⟩
#align set.preimage_compl_eq_image_compl Set.preimage_compl_eq_image_compl
theorem mem_compl_image [BooleanAlgebra α] (t : α) (S : Set α) :
t ∈ HasCompl.compl '' S ↔ tᶜ ∈ S := by
simp [← preimage_compl_eq_image_compl]
#align set.mem_compl_image Set.mem_compl_image
@[simp]
theorem image_id_eq : image (id : α → α) = id := by ext; simp
/-- A variant of `image_id` -/
@[simp]
theorem image_id' (s : Set α) : (fun x => x) '' s = s := by
ext
simp
#align set.image_id' Set.image_id'
theorem image_id (s : Set α) : id '' s = s := by simp
#align set.image_id Set.image_id
lemma image_iterate_eq {f : α → α} {n : ℕ} : image (f^[n]) = (image f)^[n] := by
induction' n with n ih; · simp
rw [iterate_succ', iterate_succ',← ih, image_comp_eq]
theorem compl_compl_image [BooleanAlgebra α] (S : Set α) :
HasCompl.compl '' (HasCompl.compl '' S) = S := by
rw [← image_comp, compl_comp_compl, image_id]
#align set.compl_compl_image Set.compl_compl_image
theorem image_insert_eq {f : α → β} {a : α} {s : Set α} :
f '' insert a s = insert (f a) (f '' s) := by
ext
simp [and_or_left, exists_or, eq_comm, or_comm, and_comm]
#align set.image_insert_eq Set.image_insert_eq
theorem image_pair (f : α → β) (a b : α) : f '' {a, b} = {f a, f b} := by
simp only [image_insert_eq, image_singleton]
#align set.image_pair Set.image_pair
theorem image_subset_preimage_of_inverse {f : α → β} {g : β → α} (I : LeftInverse g f) (s : Set α) :
f '' s ⊆ g ⁻¹' s := fun _ ⟨a, h, e⟩ => e ▸ ((I a).symm ▸ h : g (f a) ∈ s)
#align set.image_subset_preimage_of_inverse Set.image_subset_preimage_of_inverse
theorem preimage_subset_image_of_inverse {f : α → β} {g : β → α} (I : LeftInverse g f) (s : Set β) :
f ⁻¹' s ⊆ g '' s := fun b h => ⟨f b, h, I b⟩
#align set.preimage_subset_image_of_inverse Set.preimage_subset_image_of_inverse
theorem image_eq_preimage_of_inverse {f : α → β} {g : β → α} (h₁ : LeftInverse g f)
(h₂ : RightInverse g f) : image f = preimage g :=
funext fun s =>
Subset.antisymm (image_subset_preimage_of_inverse h₁ s) (preimage_subset_image_of_inverse h₂ s)
#align set.image_eq_preimage_of_inverse Set.image_eq_preimage_of_inverse
theorem mem_image_iff_of_inverse {f : α → β} {g : β → α} {b : β} {s : Set α} (h₁ : LeftInverse g f)
(h₂ : RightInverse g f) : b ∈ f '' s ↔ g b ∈ s := by
rw [image_eq_preimage_of_inverse h₁ h₂]; rfl
#align set.mem_image_iff_of_inverse Set.mem_image_iff_of_inverse
theorem image_compl_subset {f : α → β} {s : Set α} (H : Injective f) : f '' sᶜ ⊆ (f '' s)ᶜ :=
Disjoint.subset_compl_left <| by simp [disjoint_iff_inf_le, ← image_inter H]
#align set.image_compl_subset Set.image_compl_subset
theorem subset_image_compl {f : α → β} {s : Set α} (H : Surjective f) : (f '' s)ᶜ ⊆ f '' sᶜ :=
compl_subset_iff_union.2 <| by
rw [← image_union]
simp [image_univ_of_surjective H]
#align set.subset_image_compl Set.subset_image_compl
theorem image_compl_eq {f : α → β} {s : Set α} (H : Bijective f) : f '' sᶜ = (f '' s)ᶜ :=
Subset.antisymm (image_compl_subset H.1) (subset_image_compl H.2)
#align set.image_compl_eq Set.image_compl_eq
theorem subset_image_diff (f : α → β) (s t : Set α) : f '' s \ f '' t ⊆ f '' (s \ t) := by
rw [diff_subset_iff, ← image_union, union_diff_self]
exact image_subset f (subset_union_right t s)
#align set.subset_image_diff Set.subset_image_diff
theorem subset_image_symmDiff : (f '' s) ∆ (f '' t) ⊆ f '' s ∆ t :=
(union_subset_union (subset_image_diff _ _ _) <| subset_image_diff _ _ _).trans
(superset_of_eq (image_union _ _ _))
#align set.subset_image_symm_diff Set.subset_image_symmDiff
theorem image_diff {f : α → β} (hf : Injective f) (s t : Set α) : f '' (s \ t) = f '' s \ f '' t :=
Subset.antisymm
(Subset.trans (image_inter_subset _ _ _) <| inter_subset_inter_right _ <| image_compl_subset hf)
(subset_image_diff f s t)
#align set.image_diff Set.image_diff
theorem image_symmDiff (hf : Injective f) (s t : Set α) : f '' s ∆ t = (f '' s) ∆ (f '' t) := by
simp_rw [Set.symmDiff_def, image_union, image_diff hf]
#align set.image_symm_diff Set.image_symmDiff
theorem Nonempty.image (f : α → β) {s : Set α} : s.Nonempty → (f '' s).Nonempty
| ⟨x, hx⟩ => ⟨f x, mem_image_of_mem f hx⟩
#align set.nonempty.image Set.Nonempty.image
theorem Nonempty.of_image {f : α → β} {s : Set α} : (f '' s).Nonempty → s.Nonempty
| ⟨_, x, hx, _⟩ => ⟨x, hx⟩
#align set.nonempty.of_image Set.Nonempty.of_image
@[simp]
theorem nonempty_image_iff {f : α → β} {s : Set α} : (f '' s).Nonempty ↔ s.Nonempty :=
⟨Nonempty.of_image, fun h => h.image f⟩
#align set.nonempty_image_iff Set.nonempty_image_iff
theorem Nonempty.preimage {s : Set β} (hs : s.Nonempty) {f : α → β} (hf : Surjective f) :
(f ⁻¹' s).Nonempty :=
let ⟨y, hy⟩ := hs
let ⟨x, hx⟩ := hf y
⟨x, mem_preimage.2 <| hx.symm ▸ hy⟩
#align set.nonempty.preimage Set.Nonempty.preimage
instance (f : α → β) (s : Set α) [Nonempty s] : Nonempty (f '' s) :=
(Set.Nonempty.image f nonempty_of_nonempty_subtype).to_subtype
/-- image and preimage are a Galois connection -/
@[simp]
theorem image_subset_iff {s : Set α} {t : Set β} {f : α → β} : f '' s ⊆ t ↔ s ⊆ f ⁻¹' t :=
ball_image_iff
#align set.image_subset_iff Set.image_subset_iff
theorem image_preimage_subset (f : α → β) (s : Set β) : f '' (f ⁻¹' s) ⊆ s :=
image_subset_iff.2 Subset.rfl
#align set.image_preimage_subset Set.image_preimage_subset
theorem subset_preimage_image (f : α → β) (s : Set α) : s ⊆ f ⁻¹' (f '' s) := fun _ =>
mem_image_of_mem f
#align set.subset_preimage_image Set.subset_preimage_image
@[simp]
theorem preimage_image_eq {f : α → β} (s : Set α) (h : Injective f) : f ⁻¹' (f '' s) = s :=
Subset.antisymm (fun _ ⟨_, hy, e⟩ => h e ▸ hy) (subset_preimage_image f s)
#align set.preimage_image_eq Set.preimage_image_eq
@[simp]
theorem image_preimage_eq {f : α → β} (s : Set β) (h : Surjective f) : f '' (f ⁻¹' s) = s :=
Subset.antisymm (image_preimage_subset f s) fun x hx =>
let ⟨y, e⟩ := h x
⟨y, (e.symm ▸ hx : f y ∈ s), e⟩
#align set.image_preimage_eq Set.image_preimage_eq
@[simp]
theorem preimage_eq_preimage {f : β → α} (hf : Surjective f) : f ⁻¹' s = f ⁻¹' t ↔ s = t :=
Iff.intro
fun eq => by rw [← image_preimage_eq s hf, ← image_preimage_eq t hf, eq]
fun eq => eq ▸ rfl
#align set.preimage_eq_preimage Set.preimage_eq_preimage
theorem image_inter_preimage (f : α → β) (s : Set α) (t : Set β) :
f '' (s ∩ f ⁻¹' t) = f '' s ∩ t := by
apply Subset.antisymm
· calc
f '' (s ∩ f ⁻¹' t) ⊆ f '' s ∩ f '' (f ⁻¹' t) := image_inter_subset _ _ _
_ ⊆ f '' s ∩ t := inter_subset_inter_right _ (image_preimage_subset f t)
· rintro _ ⟨⟨x, h', rfl⟩, h⟩
exact ⟨x, ⟨h', h⟩, rfl⟩
#align set.image_inter_preimage Set.image_inter_preimage
theorem image_preimage_inter (f : α → β) (s : Set α) (t : Set β) :
f '' (f ⁻¹' t ∩ s) = t ∩ f '' s := by simp only [inter_comm, image_inter_preimage]
#align set.image_preimage_inter Set.image_preimage_inter
@[simp]
theorem image_inter_nonempty_iff {f : α → β} {s : Set α} {t : Set β} :
(f '' s ∩ t).Nonempty ↔ (s ∩ f ⁻¹' t).Nonempty := by
rw [← image_inter_preimage, nonempty_image_iff]
#align set.image_inter_nonempty_iff Set.image_inter_nonempty_iff
theorem image_diff_preimage {f : α → β} {s : Set α} {t : Set β} : f '' (s \ f ⁻¹' t) = f '' s \ t :=
by simp_rw [diff_eq, ← preimage_compl, image_inter_preimage]
#align set.image_diff_preimage Set.image_diff_preimage
theorem compl_image : image (compl : Set α → Set α) = preimage compl :=
image_eq_preimage_of_inverse compl_compl compl_compl
#align set.compl_image Set.compl_image
theorem compl_image_set_of {p : Set α → Prop} : compl '' { s | p s } = { s | p sᶜ } :=
congr_fun compl_image p
#align set.compl_image_set_of Set.compl_image_set_of
theorem inter_preimage_subset (s : Set α) (t : Set β) (f : α → β) :
s ∩ f ⁻¹' t ⊆ f ⁻¹' (f '' s ∩ t) := fun _ h => ⟨mem_image_of_mem _ h.left, h.right⟩
#align set.inter_preimage_subset Set.inter_preimage_subset
theorem union_preimage_subset (s : Set α) (t : Set β) (f : α → β) :
s ∪ f ⁻¹' t ⊆ f ⁻¹' (f '' s ∪ t) := fun _ h =>
Or.elim h (fun l => Or.inl <| mem_image_of_mem _ l) fun r => Or.inr r
#align set.union_preimage_subset Set.union_preimage_subset
theorem subset_image_union (f : α → β) (s : Set α) (t : Set β) : f '' (s ∪ f ⁻¹' t) ⊆ f '' s ∪ t :=
image_subset_iff.2 (union_preimage_subset _ _ _)
#align set.subset_image_union Set.subset_image_union
theorem preimage_subset_iff {A : Set α} {B : Set β} {f : α → β} :
f ⁻¹' B ⊆ A ↔ ∀ a : α, f a ∈ B → a ∈ A :=
Iff.rfl
#align set.preimage_subset_iff Set.preimage_subset_iff
theorem image_eq_image {f : α → β} (hf : Injective f) : f '' s = f '' t ↔ s = t :=
Iff.symm <|
(Iff.intro fun eq => eq ▸ rfl) fun eq => by
rw [← preimage_image_eq s hf, ← preimage_image_eq t hf, eq]
#align set.image_eq_image Set.image_eq_image
theorem image_subset_image_iff {f : α → β} (hf : Injective f) : f '' s ⊆ f '' t ↔ s ⊆ t := by
refine' Iff.symm <| (Iff.intro (image_subset f)) fun h => _
rw [← preimage_image_eq s hf, ← preimage_image_eq t hf]
exact preimage_mono h
#align set.image_subset_image_iff Set.image_subset_image_iff
theorem prod_quotient_preimage_eq_image [s : Setoid α] (g : Quotient s → β) {h : α → β}
(Hh : h = g ∘ Quotient.mk'') (r : Set (β × β)) :
{ x : Quotient s × Quotient s | (g x.1, g x.2) ∈ r } =
(fun a : α × α => (⟦a.1⟧, ⟦a.2⟧)) '' ((fun a : α × α => (h a.1, h a.2)) ⁻¹' r) :=
Hh.symm ▸
Set.ext fun ⟨a₁, a₂⟩ =>
⟨Quot.induction_on₂ a₁ a₂ fun a₁ a₂ h => ⟨(a₁, a₂), h, rfl⟩, fun ⟨⟨b₁, b₂⟩, h₁, h₂⟩ =>
show (g a₁, g a₂) ∈ r from
have h₃ : ⟦b₁⟧ = a₁ ∧ ⟦b₂⟧ = a₂ := Prod.ext_iff.1 h₂
h₃.1 ▸ h₃.2 ▸ h₁⟩
#align set.prod_quotient_preimage_eq_image Set.prod_quotient_preimage_eq_image
theorem exists_image_iff (f : α → β) (x : Set α) (P : β → Prop) :
(∃ a : f '' x, P a) ↔ ∃ a : x, P (f a) :=
⟨fun ⟨a, h⟩ => ⟨⟨_, a.prop.choose_spec.1⟩, a.prop.choose_spec.2.symm ▸ h⟩, fun ⟨a, h⟩ =>
⟨⟨_, _, a.prop, rfl⟩, h⟩⟩
#align set.exists_image_iff Set.exists_image_iff
/-- Restriction of `f` to `s` factors through `s.imageFactorization f : s → f '' s`. -/
def imageFactorization (f : α → β) (s : Set α) : s → f '' s := fun p =>
⟨f p.1, mem_image_of_mem f p.2⟩
#align set.image_factorization Set.imageFactorization
theorem imageFactorization_eq {f : α → β} {s : Set α} :
Subtype.val ∘ imageFactorization f s = f ∘ Subtype.val :=
funext fun _ => rfl
#align set.image_factorization_eq Set.imageFactorization_eq
theorem surjective_onto_image {f : α → β} {s : Set α} : Surjective (imageFactorization f s) :=
fun ⟨_, ⟨a, ha, rfl⟩⟩ => ⟨⟨a, ha⟩, rfl⟩
#align set.surjective_onto_image Set.surjective_onto_image
/-- If the only elements outside `s` are those left fixed by `σ`, then mapping by `σ` has no effect.
-/
theorem image_perm {s : Set α} {σ : Equiv.Perm α} (hs : { a : α | σ a ≠ a } ⊆ s) : σ '' s = s := by
|
ext i
|
/-- If the only elements outside `s` are those left fixed by `σ`, then mapping by `σ` has no effect.
-/
theorem image_perm {s : Set α} {σ : Equiv.Perm α} (hs : { a : α | σ a ≠ a } ⊆ s) : σ '' s = s := by
|
Mathlib.Data.Set.Image.635_0.IJFiTzmYGOCpPSd
|
/-- If the only elements outside `s` are those left fixed by `σ`, then mapping by `σ` has no effect.
-/
theorem image_perm {s : Set α} {σ : Equiv.Perm α} (hs : { a : α | σ a ≠ a } ⊆ s) : σ '' s = s
|
Mathlib_Data_Set_Image
|
case h
α : Type u_1
β : Type u_2
γ : Type u_3
ι : Sort u_4
ι' : Sort u_5
f : α → β
s✝ t s : Set α
σ : Equiv.Perm α
hs : {a | σ a ≠ a} ⊆ s
i : α
⊢ i ∈ ⇑σ '' s ↔ i ∈ s
|
/-
Copyright (c) 2014 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Leonardo de Moura
-/
import Mathlib.Data.Set.Basic
#align_import data.set.image from "leanprover-community/mathlib"@"001ffdc42920050657fd45bd2b8bfbec8eaaeb29"
/-!
# Images and preimages of sets
## Main definitions
* `preimage f t : Set α` : the preimage f⁻¹(t) (written `f ⁻¹' t` in Lean) of a subset of β.
* `range f : Set β` : the image of `univ` under `f`.
Also works for `{p : Prop} (f : p → α)` (unlike `image`)
## Notation
* `f ⁻¹' t` for `Set.preimage f t`
* `f '' s` for `Set.image f s`
## Tags
set, sets, image, preimage, pre-image, range
-/
set_option autoImplicit true
universe u v
open Function Set
namespace Set
variable {α β γ : Type*} {ι ι' : Sort*}
/-! ### Inverse image -/
/-- The preimage of `s : Set β` by `f : α → β`, written `f ⁻¹' s`,
is the set of `x : α` such that `f x ∈ s`. -/
def preimage {α : Type u} {β : Type v} (f : α → β) (s : Set β) : Set α :=
{ x | f x ∈ s }
#align set.preimage Set.preimage
/-- `f ⁻¹' t` denotes the preimage of `t : Set β` under the function `f : α → β`. -/
infixl:80 " ⁻¹' " => preimage
section Preimage
variable {f : α → β} {g : β → γ}
@[simp]
theorem preimage_empty : f ⁻¹' ∅ = ∅ :=
rfl
#align set.preimage_empty Set.preimage_empty
@[simp, mfld_simps]
theorem mem_preimage {s : Set β} {a : α} : a ∈ f ⁻¹' s ↔ f a ∈ s :=
Iff.rfl
#align set.mem_preimage Set.mem_preimage
theorem preimage_congr {f g : α → β} {s : Set β} (h : ∀ x : α, f x = g x) : f ⁻¹' s = g ⁻¹' s := by
congr with x
simp [h]
#align set.preimage_congr Set.preimage_congr
@[gcongr]
theorem preimage_mono {s t : Set β} (h : s ⊆ t) : f ⁻¹' s ⊆ f ⁻¹' t := fun _ hx => h hx
#align set.preimage_mono Set.preimage_mono
@[simp, mfld_simps]
theorem preimage_univ : f ⁻¹' univ = univ :=
rfl
#align set.preimage_univ Set.preimage_univ
theorem subset_preimage_univ {s : Set α} : s ⊆ f ⁻¹' univ :=
subset_univ _
#align set.subset_preimage_univ Set.subset_preimage_univ
@[simp, mfld_simps]
theorem preimage_inter {s t : Set β} : f ⁻¹' (s ∩ t) = f ⁻¹' s ∩ f ⁻¹' t :=
rfl
#align set.preimage_inter Set.preimage_inter
@[simp]
theorem preimage_union {s t : Set β} : f ⁻¹' (s ∪ t) = f ⁻¹' s ∪ f ⁻¹' t :=
rfl
#align set.preimage_union Set.preimage_union
@[simp]
theorem preimage_compl {s : Set β} : f ⁻¹' sᶜ = (f ⁻¹' s)ᶜ :=
rfl
#align set.preimage_compl Set.preimage_compl
@[simp]
theorem preimage_diff (f : α → β) (s t : Set β) : f ⁻¹' (s \ t) = f ⁻¹' s \ f ⁻¹' t :=
rfl
#align set.preimage_diff Set.preimage_diff
@[simp]
lemma preimage_symmDiff {f : α → β} (s t : Set β) : f ⁻¹' (s ∆ t) = (f ⁻¹' s) ∆ (f ⁻¹' t) :=
rfl
#align set.preimage_symm_diff Set.preimage_symmDiff
@[simp]
theorem preimage_ite (f : α → β) (s t₁ t₂ : Set β) :
f ⁻¹' s.ite t₁ t₂ = (f ⁻¹' s).ite (f ⁻¹' t₁) (f ⁻¹' t₂) :=
rfl
#align set.preimage_ite Set.preimage_ite
@[simp]
theorem preimage_setOf_eq {p : α → Prop} {f : β → α} : f ⁻¹' { a | p a } = { a | p (f a) } :=
rfl
#align set.preimage_set_of_eq Set.preimage_setOf_eq
@[simp]
theorem preimage_id_eq : preimage (id : α → α) = id :=
rfl
#align set.preimage_id_eq Set.preimage_id_eq
@[mfld_simps]
theorem preimage_id {s : Set α} : id ⁻¹' s = s :=
rfl
#align set.preimage_id Set.preimage_id
@[simp, mfld_simps]
theorem preimage_id' {s : Set α} : (fun x => x) ⁻¹' s = s :=
rfl
#align set.preimage_id' Set.preimage_id'
@[simp]
theorem preimage_const_of_mem {b : β} {s : Set β} (h : b ∈ s) : (fun _ : α => b) ⁻¹' s = univ :=
eq_univ_of_forall fun _ => h
#align set.preimage_const_of_mem Set.preimage_const_of_mem
@[simp]
theorem preimage_const_of_not_mem {b : β} {s : Set β} (h : b ∉ s) : (fun _ : α => b) ⁻¹' s = ∅ :=
eq_empty_of_subset_empty fun _ hx => h hx
#align set.preimage_const_of_not_mem Set.preimage_const_of_not_mem
theorem preimage_const (b : β) (s : Set β) [Decidable (b ∈ s)] :
(fun _ : α => b) ⁻¹' s = if b ∈ s then univ else ∅ := by
split_ifs with hb
exacts [preimage_const_of_mem hb, preimage_const_of_not_mem hb]
#align set.preimage_const Set.preimage_const
/-- If preimage of each singleton under `f : α → β` is either empty or the whole type,
then `f` is a constant. -/
lemma exists_eq_const_of_preimage_singleton [Nonempty β] {f : α → β}
(hf : ∀ b : β, f ⁻¹' {b} = ∅ ∨ f ⁻¹' {b} = univ) : ∃ b, f = const α b := by
rcases em (∃ b, f ⁻¹' {b} = univ) with ⟨b, hb⟩ | hf'
· exact ⟨b, funext fun x ↦ eq_univ_iff_forall.1 hb x⟩
· have : ∀ x b, f x ≠ b := fun x b ↦
eq_empty_iff_forall_not_mem.1 ((hf b).resolve_right fun h ↦ hf' ⟨b, h⟩) x
exact ⟨Classical.arbitrary β, funext fun x ↦ absurd rfl (this x _)⟩
theorem preimage_comp {s : Set γ} : g ∘ f ⁻¹' s = f ⁻¹' (g ⁻¹' s) :=
rfl
#align set.preimage_comp Set.preimage_comp
theorem preimage_comp_eq : preimage (g ∘ f) = preimage f ∘ preimage g :=
rfl
#align set.preimage_comp_eq Set.preimage_comp_eq
theorem preimage_iterate_eq {f : α → α} {n : ℕ} : Set.preimage f^[n] = (Set.preimage f)^[n] := by
induction' n with n ih; · simp
rw [iterate_succ, iterate_succ', preimage_comp_eq, ih]
#align set.preimage_iterate_eq Set.preimage_iterate_eq
theorem preimage_preimage {g : β → γ} {f : α → β} {s : Set γ} :
f ⁻¹' (g ⁻¹' s) = (fun x => g (f x)) ⁻¹' s :=
preimage_comp.symm
#align set.preimage_preimage Set.preimage_preimage
theorem eq_preimage_subtype_val_iff {p : α → Prop} {s : Set (Subtype p)} {t : Set α} :
s = Subtype.val ⁻¹' t ↔ ∀ (x) (h : p x), (⟨x, h⟩ : Subtype p) ∈ s ↔ x ∈ t :=
⟨fun s_eq x h => by
rw [s_eq]
simp, fun h => ext fun ⟨x, hx⟩ => by simp [h]⟩
#align set.eq_preimage_subtype_val_iff Set.eq_preimage_subtype_val_iff
theorem nonempty_of_nonempty_preimage {s : Set β} {f : α → β} (hf : (f ⁻¹' s).Nonempty) :
s.Nonempty :=
let ⟨x, hx⟩ := hf
⟨f x, hx⟩
#align set.nonempty_of_nonempty_preimage Set.nonempty_of_nonempty_preimage
@[simp] theorem preimage_singleton_true (p : α → Prop) : p ⁻¹' {True} = {a | p a} := by ext; simp
#align set.preimage_singleton_true Set.preimage_singleton_true
@[simp] theorem preimage_singleton_false (p : α → Prop) : p ⁻¹' {False} = {a | ¬p a} := by ext; simp
#align set.preimage_singleton_false Set.preimage_singleton_false
theorem preimage_subtype_coe_eq_compl {s u v : Set α} (hsuv : s ⊆ u ∪ v)
(H : s ∩ (u ∩ v) = ∅) : ((↑) : s → α) ⁻¹' u = ((↑) ⁻¹' v)ᶜ := by
ext ⟨x, x_in_s⟩
constructor
· intro x_in_u x_in_v
exact eq_empty_iff_forall_not_mem.mp H x ⟨x_in_s, ⟨x_in_u, x_in_v⟩⟩
· intro hx
exact Or.elim (hsuv x_in_s) id fun hx' => hx.elim hx'
#align set.preimage_subtype_coe_eq_compl Set.preimage_subtype_coe_eq_compl
end Preimage
/-! ### Image of a set under a function -/
section Image
variable {f : α → β} {s t : Set α}
-- Porting note: `Set.image` is already defined in `Init.Set`
#align set.image Set.image
/-- `f '' s` denotes the image of `s : Set α` under the function `f : α → β`. -/
infixl:80 " '' " => image
theorem mem_image_iff_bex {f : α → β} {s : Set α} {y : β} :
y ∈ f '' s ↔ ∃ (x : _) (_ : x ∈ s), f x = y :=
bex_def.symm
#align set.mem_image_iff_bex Set.mem_image_iff_bex
@[simp]
theorem mem_image (f : α → β) (s : Set α) (y : β) : y ∈ f '' s ↔ ∃ x ∈ s, f x = y :=
Iff.rfl
#align set.mem_image Set.mem_image
theorem image_eta (f : α → β) : f '' s = (fun x => f x) '' s :=
rfl
#align set.image_eta Set.image_eta
@[mfld_simps]
theorem mem_image_of_mem (f : α → β) {x : α} {a : Set α} (h : x ∈ a) : f x ∈ f '' a :=
⟨_, h, rfl⟩
#align set.mem_image_of_mem Set.mem_image_of_mem
theorem _root_.Function.Injective.mem_set_image {f : α → β} (hf : Injective f) {s : Set α} {a : α} :
f a ∈ f '' s ↔ a ∈ s :=
⟨fun ⟨_, hb, Eq⟩ => hf Eq ▸ hb, mem_image_of_mem f⟩
#align function.injective.mem_set_image Function.Injective.mem_set_image
theorem ball_image_iff {f : α → β} {s : Set α} {p : β → Prop} :
(∀ y ∈ f '' s, p y) ↔ ∀ x ∈ s, p (f x) := by simp
#align set.ball_image_iff Set.ball_image_iff
theorem ball_image_of_ball {f : α → β} {s : Set α} {p : β → Prop} (h : ∀ x ∈ s, p (f x)) :
∀ y ∈ f '' s, p y :=
ball_image_iff.2 h
#align set.ball_image_of_ball Set.ball_image_of_ball
theorem bex_image_iff {f : α → β} {s : Set α} {p : β → Prop} :
(∃ y ∈ f '' s, p y) ↔ ∃ x ∈ s, p (f x) := by simp
#align set.bex_image_iff Set.bex_image_iff
theorem mem_image_elim {f : α → β} {s : Set α} {C : β → Prop} (h : ∀ x : α, x ∈ s → C (f x)) :
∀ {y : β}, y ∈ f '' s → C y
| _, ⟨a, a_in, rfl⟩ => h a a_in
#align set.mem_image_elim Set.mem_image_elim
theorem mem_image_elim_on {f : α → β} {s : Set α} {C : β → Prop} {y : β} (h_y : y ∈ f '' s)
(h : ∀ x : α, x ∈ s → C (f x)) : C y :=
mem_image_elim h h_y
#align set.mem_image_elim_on Set.mem_image_elim_on
-- Porting note: used to be `safe`
@[congr]
theorem image_congr {f g : α → β} {s : Set α} (h : ∀ a ∈ s, f a = g a) : f '' s = g '' s := by
ext x
rw [mem_image, mem_image]
exact {
mp := by
rintro ⟨a, ha1, ha2⟩
exact ⟨a, ⟨ha1, (h a ha1) ▸ ha2⟩⟩,
mpr := by
rintro ⟨a, ha1, ha2⟩
exact ⟨a, ⟨ha1, (h a ha1) ▸ ha2⟩⟩
}
-- safe [ext_iff, iff_def]
#align set.image_congr Set.image_congr
/-- A common special case of `image_congr` -/
theorem image_congr' {f g : α → β} {s : Set α} (h : ∀ x : α, f x = g x) : f '' s = g '' s :=
image_congr fun x _ => h x
#align set.image_congr' Set.image_congr'
@[gcongr]
lemma image_mono (h : s ⊆ t) : f '' s ⊆ f '' t := by
rintro - ⟨a, ha, rfl⟩; exact mem_image_of_mem f (h ha)
theorem image_comp (f : β → γ) (g : α → β) (a : Set α) : f ∘ g '' a = f '' (g '' a) :=
Subset.antisymm (ball_image_of_ball fun _ ha => mem_image_of_mem _ <| mem_image_of_mem _ ha)
(ball_image_of_ball <| ball_image_of_ball fun _ ha => mem_image_of_mem _ ha)
#align set.image_comp Set.image_comp
theorem image_comp_eq {g : β → γ} : image (g ∘ f) = image g ∘ image f := by ext; simp
/-- A variant of `image_comp`, useful for rewriting -/
theorem image_image (g : β → γ) (f : α → β) (s : Set α) : g '' (f '' s) = (fun x => g (f x)) '' s :=
(image_comp g f s).symm
#align set.image_image Set.image_image
theorem image_comm {β'} {f : β → γ} {g : α → β} {f' : α → β'} {g' : β' → γ}
(h_comm : ∀ a, f (g a) = g' (f' a)) : (s.image g).image f = (s.image f').image g' := by
simp_rw [image_image, h_comm]
#align set.image_comm Set.image_comm
theorem _root_.Function.Semiconj.set_image {f : α → β} {ga : α → α} {gb : β → β}
(h : Function.Semiconj f ga gb) : Function.Semiconj (image f) (image ga) (image gb) := fun _ =>
image_comm h
#align function.semiconj.set_image Function.Semiconj.set_image
theorem _root_.Function.Commute.set_image {f g : α → α} (h : Function.Commute f g) :
Function.Commute (image f) (image g) :=
Function.Semiconj.set_image h
#align function.commute.set_image Function.Commute.set_image
/-- Image is monotone with respect to `⊆`. See `Set.monotone_image` for the statement in
terms of `≤`. -/
@[gcongr]
theorem image_subset {a b : Set α} (f : α → β) (h : a ⊆ b) : f '' a ⊆ f '' b := by
simp only [subset_def, mem_image]
exact fun x => fun ⟨w, h1, h2⟩ => ⟨w, h h1, h2⟩
#align set.image_subset Set.image_subset
/-- `Set.image` is monotone. See `Set.image_subset` for the statement in terms of `⊆`. -/
lemma monotone_image {f : α → β} : Monotone (image f) := fun _ _ => image_subset _
#align set.monotone_image Set.monotone_image
theorem image_union (f : α → β) (s t : Set α) : f '' (s ∪ t) = f '' s ∪ f '' t :=
ext fun x =>
⟨by rintro ⟨a, h | h, rfl⟩ <;> [left; right] <;> exact ⟨_, h, rfl⟩, by
rintro (⟨a, h, rfl⟩ | ⟨a, h, rfl⟩) <;> refine' ⟨_, _, rfl⟩ <;> [left; right] <;> exact h⟩
#align set.image_union Set.image_union
@[simp]
theorem image_empty (f : α → β) : f '' ∅ = ∅ := by
ext
simp
#align set.image_empty Set.image_empty
theorem image_inter_subset (f : α → β) (s t : Set α) : f '' (s ∩ t) ⊆ f '' s ∩ f '' t :=
subset_inter (image_subset _ <| inter_subset_left _ _) (image_subset _ <| inter_subset_right _ _)
#align set.image_inter_subset Set.image_inter_subset
theorem image_inter_on {f : α → β} {s t : Set α} (h : ∀ x ∈ t, ∀ y ∈ s, f x = f y → x = y) :
f '' (s ∩ t) = f '' s ∩ f '' t :=
(image_inter_subset _ _ _).antisymm
fun b ⟨⟨a₁, ha₁, h₁⟩, ⟨a₂, ha₂, h₂⟩⟩ ↦
have : a₂ = a₁ := h _ ha₂ _ ha₁ (by simp [*])
⟨a₁, ⟨ha₁, this ▸ ha₂⟩, h₁⟩
#align set.image_inter_on Set.image_inter_on
theorem image_inter {f : α → β} {s t : Set α} (H : Injective f) : f '' (s ∩ t) = f '' s ∩ f '' t :=
image_inter_on fun _ _ _ _ h => H h
#align set.image_inter Set.image_inter
theorem image_univ_of_surjective {ι : Type*} {f : ι → β} (H : Surjective f) : f '' univ = univ :=
eq_univ_of_forall <| by simpa [image]
#align set.image_univ_of_surjective Set.image_univ_of_surjective
@[simp]
theorem image_singleton {f : α → β} {a : α} : f '' {a} = {f a} := by
ext
simp [image, eq_comm]
#align set.image_singleton Set.image_singleton
@[simp]
theorem Nonempty.image_const {s : Set α} (hs : s.Nonempty) (a : β) : (fun _ => a) '' s = {a} :=
ext fun _ =>
⟨fun ⟨_, _, h⟩ => h ▸ mem_singleton _, fun h =>
(eq_of_mem_singleton h).symm ▸ hs.imp fun _ hy => ⟨hy, rfl⟩⟩
#align set.nonempty.image_const Set.Nonempty.image_const
@[simp, mfld_simps]
theorem image_eq_empty {α β} {f : α → β} {s : Set α} : f '' s = ∅ ↔ s = ∅ := by
simp only [eq_empty_iff_forall_not_mem]
exact ⟨fun H a ha => H _ ⟨_, ha, rfl⟩, fun H b ⟨_, ha, _⟩ => H _ ha⟩
#align set.image_eq_empty Set.image_eq_empty
-- Porting note: `compl` is already defined in `Init.Set`
theorem preimage_compl_eq_image_compl [BooleanAlgebra α] (S : Set α) :
HasCompl.compl ⁻¹' S = HasCompl.compl '' S :=
Set.ext fun x =>
⟨fun h => ⟨xᶜ, h, compl_compl x⟩, fun h =>
Exists.elim h fun _ hy => (compl_eq_comm.mp hy.2).symm.subst hy.1⟩
#align set.preimage_compl_eq_image_compl Set.preimage_compl_eq_image_compl
theorem mem_compl_image [BooleanAlgebra α] (t : α) (S : Set α) :
t ∈ HasCompl.compl '' S ↔ tᶜ ∈ S := by
simp [← preimage_compl_eq_image_compl]
#align set.mem_compl_image Set.mem_compl_image
@[simp]
theorem image_id_eq : image (id : α → α) = id := by ext; simp
/-- A variant of `image_id` -/
@[simp]
theorem image_id' (s : Set α) : (fun x => x) '' s = s := by
ext
simp
#align set.image_id' Set.image_id'
theorem image_id (s : Set α) : id '' s = s := by simp
#align set.image_id Set.image_id
lemma image_iterate_eq {f : α → α} {n : ℕ} : image (f^[n]) = (image f)^[n] := by
induction' n with n ih; · simp
rw [iterate_succ', iterate_succ',← ih, image_comp_eq]
theorem compl_compl_image [BooleanAlgebra α] (S : Set α) :
HasCompl.compl '' (HasCompl.compl '' S) = S := by
rw [← image_comp, compl_comp_compl, image_id]
#align set.compl_compl_image Set.compl_compl_image
theorem image_insert_eq {f : α → β} {a : α} {s : Set α} :
f '' insert a s = insert (f a) (f '' s) := by
ext
simp [and_or_left, exists_or, eq_comm, or_comm, and_comm]
#align set.image_insert_eq Set.image_insert_eq
theorem image_pair (f : α → β) (a b : α) : f '' {a, b} = {f a, f b} := by
simp only [image_insert_eq, image_singleton]
#align set.image_pair Set.image_pair
theorem image_subset_preimage_of_inverse {f : α → β} {g : β → α} (I : LeftInverse g f) (s : Set α) :
f '' s ⊆ g ⁻¹' s := fun _ ⟨a, h, e⟩ => e ▸ ((I a).symm ▸ h : g (f a) ∈ s)
#align set.image_subset_preimage_of_inverse Set.image_subset_preimage_of_inverse
theorem preimage_subset_image_of_inverse {f : α → β} {g : β → α} (I : LeftInverse g f) (s : Set β) :
f ⁻¹' s ⊆ g '' s := fun b h => ⟨f b, h, I b⟩
#align set.preimage_subset_image_of_inverse Set.preimage_subset_image_of_inverse
theorem image_eq_preimage_of_inverse {f : α → β} {g : β → α} (h₁ : LeftInverse g f)
(h₂ : RightInverse g f) : image f = preimage g :=
funext fun s =>
Subset.antisymm (image_subset_preimage_of_inverse h₁ s) (preimage_subset_image_of_inverse h₂ s)
#align set.image_eq_preimage_of_inverse Set.image_eq_preimage_of_inverse
theorem mem_image_iff_of_inverse {f : α → β} {g : β → α} {b : β} {s : Set α} (h₁ : LeftInverse g f)
(h₂ : RightInverse g f) : b ∈ f '' s ↔ g b ∈ s := by
rw [image_eq_preimage_of_inverse h₁ h₂]; rfl
#align set.mem_image_iff_of_inverse Set.mem_image_iff_of_inverse
theorem image_compl_subset {f : α → β} {s : Set α} (H : Injective f) : f '' sᶜ ⊆ (f '' s)ᶜ :=
Disjoint.subset_compl_left <| by simp [disjoint_iff_inf_le, ← image_inter H]
#align set.image_compl_subset Set.image_compl_subset
theorem subset_image_compl {f : α → β} {s : Set α} (H : Surjective f) : (f '' s)ᶜ ⊆ f '' sᶜ :=
compl_subset_iff_union.2 <| by
rw [← image_union]
simp [image_univ_of_surjective H]
#align set.subset_image_compl Set.subset_image_compl
theorem image_compl_eq {f : α → β} {s : Set α} (H : Bijective f) : f '' sᶜ = (f '' s)ᶜ :=
Subset.antisymm (image_compl_subset H.1) (subset_image_compl H.2)
#align set.image_compl_eq Set.image_compl_eq
theorem subset_image_diff (f : α → β) (s t : Set α) : f '' s \ f '' t ⊆ f '' (s \ t) := by
rw [diff_subset_iff, ← image_union, union_diff_self]
exact image_subset f (subset_union_right t s)
#align set.subset_image_diff Set.subset_image_diff
theorem subset_image_symmDiff : (f '' s) ∆ (f '' t) ⊆ f '' s ∆ t :=
(union_subset_union (subset_image_diff _ _ _) <| subset_image_diff _ _ _).trans
(superset_of_eq (image_union _ _ _))
#align set.subset_image_symm_diff Set.subset_image_symmDiff
theorem image_diff {f : α → β} (hf : Injective f) (s t : Set α) : f '' (s \ t) = f '' s \ f '' t :=
Subset.antisymm
(Subset.trans (image_inter_subset _ _ _) <| inter_subset_inter_right _ <| image_compl_subset hf)
(subset_image_diff f s t)
#align set.image_diff Set.image_diff
theorem image_symmDiff (hf : Injective f) (s t : Set α) : f '' s ∆ t = (f '' s) ∆ (f '' t) := by
simp_rw [Set.symmDiff_def, image_union, image_diff hf]
#align set.image_symm_diff Set.image_symmDiff
theorem Nonempty.image (f : α → β) {s : Set α} : s.Nonempty → (f '' s).Nonempty
| ⟨x, hx⟩ => ⟨f x, mem_image_of_mem f hx⟩
#align set.nonempty.image Set.Nonempty.image
theorem Nonempty.of_image {f : α → β} {s : Set α} : (f '' s).Nonempty → s.Nonempty
| ⟨_, x, hx, _⟩ => ⟨x, hx⟩
#align set.nonempty.of_image Set.Nonempty.of_image
@[simp]
theorem nonempty_image_iff {f : α → β} {s : Set α} : (f '' s).Nonempty ↔ s.Nonempty :=
⟨Nonempty.of_image, fun h => h.image f⟩
#align set.nonempty_image_iff Set.nonempty_image_iff
theorem Nonempty.preimage {s : Set β} (hs : s.Nonempty) {f : α → β} (hf : Surjective f) :
(f ⁻¹' s).Nonempty :=
let ⟨y, hy⟩ := hs
let ⟨x, hx⟩ := hf y
⟨x, mem_preimage.2 <| hx.symm ▸ hy⟩
#align set.nonempty.preimage Set.Nonempty.preimage
instance (f : α → β) (s : Set α) [Nonempty s] : Nonempty (f '' s) :=
(Set.Nonempty.image f nonempty_of_nonempty_subtype).to_subtype
/-- image and preimage are a Galois connection -/
@[simp]
theorem image_subset_iff {s : Set α} {t : Set β} {f : α → β} : f '' s ⊆ t ↔ s ⊆ f ⁻¹' t :=
ball_image_iff
#align set.image_subset_iff Set.image_subset_iff
theorem image_preimage_subset (f : α → β) (s : Set β) : f '' (f ⁻¹' s) ⊆ s :=
image_subset_iff.2 Subset.rfl
#align set.image_preimage_subset Set.image_preimage_subset
theorem subset_preimage_image (f : α → β) (s : Set α) : s ⊆ f ⁻¹' (f '' s) := fun _ =>
mem_image_of_mem f
#align set.subset_preimage_image Set.subset_preimage_image
@[simp]
theorem preimage_image_eq {f : α → β} (s : Set α) (h : Injective f) : f ⁻¹' (f '' s) = s :=
Subset.antisymm (fun _ ⟨_, hy, e⟩ => h e ▸ hy) (subset_preimage_image f s)
#align set.preimage_image_eq Set.preimage_image_eq
@[simp]
theorem image_preimage_eq {f : α → β} (s : Set β) (h : Surjective f) : f '' (f ⁻¹' s) = s :=
Subset.antisymm (image_preimage_subset f s) fun x hx =>
let ⟨y, e⟩ := h x
⟨y, (e.symm ▸ hx : f y ∈ s), e⟩
#align set.image_preimage_eq Set.image_preimage_eq
@[simp]
theorem preimage_eq_preimage {f : β → α} (hf : Surjective f) : f ⁻¹' s = f ⁻¹' t ↔ s = t :=
Iff.intro
fun eq => by rw [← image_preimage_eq s hf, ← image_preimage_eq t hf, eq]
fun eq => eq ▸ rfl
#align set.preimage_eq_preimage Set.preimage_eq_preimage
theorem image_inter_preimage (f : α → β) (s : Set α) (t : Set β) :
f '' (s ∩ f ⁻¹' t) = f '' s ∩ t := by
apply Subset.antisymm
· calc
f '' (s ∩ f ⁻¹' t) ⊆ f '' s ∩ f '' (f ⁻¹' t) := image_inter_subset _ _ _
_ ⊆ f '' s ∩ t := inter_subset_inter_right _ (image_preimage_subset f t)
· rintro _ ⟨⟨x, h', rfl⟩, h⟩
exact ⟨x, ⟨h', h⟩, rfl⟩
#align set.image_inter_preimage Set.image_inter_preimage
theorem image_preimage_inter (f : α → β) (s : Set α) (t : Set β) :
f '' (f ⁻¹' t ∩ s) = t ∩ f '' s := by simp only [inter_comm, image_inter_preimage]
#align set.image_preimage_inter Set.image_preimage_inter
@[simp]
theorem image_inter_nonempty_iff {f : α → β} {s : Set α} {t : Set β} :
(f '' s ∩ t).Nonempty ↔ (s ∩ f ⁻¹' t).Nonempty := by
rw [← image_inter_preimage, nonempty_image_iff]
#align set.image_inter_nonempty_iff Set.image_inter_nonempty_iff
theorem image_diff_preimage {f : α → β} {s : Set α} {t : Set β} : f '' (s \ f ⁻¹' t) = f '' s \ t :=
by simp_rw [diff_eq, ← preimage_compl, image_inter_preimage]
#align set.image_diff_preimage Set.image_diff_preimage
theorem compl_image : image (compl : Set α → Set α) = preimage compl :=
image_eq_preimage_of_inverse compl_compl compl_compl
#align set.compl_image Set.compl_image
theorem compl_image_set_of {p : Set α → Prop} : compl '' { s | p s } = { s | p sᶜ } :=
congr_fun compl_image p
#align set.compl_image_set_of Set.compl_image_set_of
theorem inter_preimage_subset (s : Set α) (t : Set β) (f : α → β) :
s ∩ f ⁻¹' t ⊆ f ⁻¹' (f '' s ∩ t) := fun _ h => ⟨mem_image_of_mem _ h.left, h.right⟩
#align set.inter_preimage_subset Set.inter_preimage_subset
theorem union_preimage_subset (s : Set α) (t : Set β) (f : α → β) :
s ∪ f ⁻¹' t ⊆ f ⁻¹' (f '' s ∪ t) := fun _ h =>
Or.elim h (fun l => Or.inl <| mem_image_of_mem _ l) fun r => Or.inr r
#align set.union_preimage_subset Set.union_preimage_subset
theorem subset_image_union (f : α → β) (s : Set α) (t : Set β) : f '' (s ∪ f ⁻¹' t) ⊆ f '' s ∪ t :=
image_subset_iff.2 (union_preimage_subset _ _ _)
#align set.subset_image_union Set.subset_image_union
theorem preimage_subset_iff {A : Set α} {B : Set β} {f : α → β} :
f ⁻¹' B ⊆ A ↔ ∀ a : α, f a ∈ B → a ∈ A :=
Iff.rfl
#align set.preimage_subset_iff Set.preimage_subset_iff
theorem image_eq_image {f : α → β} (hf : Injective f) : f '' s = f '' t ↔ s = t :=
Iff.symm <|
(Iff.intro fun eq => eq ▸ rfl) fun eq => by
rw [← preimage_image_eq s hf, ← preimage_image_eq t hf, eq]
#align set.image_eq_image Set.image_eq_image
theorem image_subset_image_iff {f : α → β} (hf : Injective f) : f '' s ⊆ f '' t ↔ s ⊆ t := by
refine' Iff.symm <| (Iff.intro (image_subset f)) fun h => _
rw [← preimage_image_eq s hf, ← preimage_image_eq t hf]
exact preimage_mono h
#align set.image_subset_image_iff Set.image_subset_image_iff
theorem prod_quotient_preimage_eq_image [s : Setoid α] (g : Quotient s → β) {h : α → β}
(Hh : h = g ∘ Quotient.mk'') (r : Set (β × β)) :
{ x : Quotient s × Quotient s | (g x.1, g x.2) ∈ r } =
(fun a : α × α => (⟦a.1⟧, ⟦a.2⟧)) '' ((fun a : α × α => (h a.1, h a.2)) ⁻¹' r) :=
Hh.symm ▸
Set.ext fun ⟨a₁, a₂⟩ =>
⟨Quot.induction_on₂ a₁ a₂ fun a₁ a₂ h => ⟨(a₁, a₂), h, rfl⟩, fun ⟨⟨b₁, b₂⟩, h₁, h₂⟩ =>
show (g a₁, g a₂) ∈ r from
have h₃ : ⟦b₁⟧ = a₁ ∧ ⟦b₂⟧ = a₂ := Prod.ext_iff.1 h₂
h₃.1 ▸ h₃.2 ▸ h₁⟩
#align set.prod_quotient_preimage_eq_image Set.prod_quotient_preimage_eq_image
theorem exists_image_iff (f : α → β) (x : Set α) (P : β → Prop) :
(∃ a : f '' x, P a) ↔ ∃ a : x, P (f a) :=
⟨fun ⟨a, h⟩ => ⟨⟨_, a.prop.choose_spec.1⟩, a.prop.choose_spec.2.symm ▸ h⟩, fun ⟨a, h⟩ =>
⟨⟨_, _, a.prop, rfl⟩, h⟩⟩
#align set.exists_image_iff Set.exists_image_iff
/-- Restriction of `f` to `s` factors through `s.imageFactorization f : s → f '' s`. -/
def imageFactorization (f : α → β) (s : Set α) : s → f '' s := fun p =>
⟨f p.1, mem_image_of_mem f p.2⟩
#align set.image_factorization Set.imageFactorization
theorem imageFactorization_eq {f : α → β} {s : Set α} :
Subtype.val ∘ imageFactorization f s = f ∘ Subtype.val :=
funext fun _ => rfl
#align set.image_factorization_eq Set.imageFactorization_eq
theorem surjective_onto_image {f : α → β} {s : Set α} : Surjective (imageFactorization f s) :=
fun ⟨_, ⟨a, ha, rfl⟩⟩ => ⟨⟨a, ha⟩, rfl⟩
#align set.surjective_onto_image Set.surjective_onto_image
/-- If the only elements outside `s` are those left fixed by `σ`, then mapping by `σ` has no effect.
-/
theorem image_perm {s : Set α} {σ : Equiv.Perm α} (hs : { a : α | σ a ≠ a } ⊆ s) : σ '' s = s := by
ext i
|
obtain hi | hi := eq_or_ne (σ i) i
|
/-- If the only elements outside `s` are those left fixed by `σ`, then mapping by `σ` has no effect.
-/
theorem image_perm {s : Set α} {σ : Equiv.Perm α} (hs : { a : α | σ a ≠ a } ⊆ s) : σ '' s = s := by
ext i
|
Mathlib.Data.Set.Image.635_0.IJFiTzmYGOCpPSd
|
/-- If the only elements outside `s` are those left fixed by `σ`, then mapping by `σ` has no effect.
-/
theorem image_perm {s : Set α} {σ : Equiv.Perm α} (hs : { a : α | σ a ≠ a } ⊆ s) : σ '' s = s
|
Mathlib_Data_Set_Image
|
case h.inl
α : Type u_1
β : Type u_2
γ : Type u_3
ι : Sort u_4
ι' : Sort u_5
f : α → β
s✝ t s : Set α
σ : Equiv.Perm α
hs : {a | σ a ≠ a} ⊆ s
i : α
hi : σ i = i
⊢ i ∈ ⇑σ '' s ↔ i ∈ s
|
/-
Copyright (c) 2014 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Leonardo de Moura
-/
import Mathlib.Data.Set.Basic
#align_import data.set.image from "leanprover-community/mathlib"@"001ffdc42920050657fd45bd2b8bfbec8eaaeb29"
/-!
# Images and preimages of sets
## Main definitions
* `preimage f t : Set α` : the preimage f⁻¹(t) (written `f ⁻¹' t` in Lean) of a subset of β.
* `range f : Set β` : the image of `univ` under `f`.
Also works for `{p : Prop} (f : p → α)` (unlike `image`)
## Notation
* `f ⁻¹' t` for `Set.preimage f t`
* `f '' s` for `Set.image f s`
## Tags
set, sets, image, preimage, pre-image, range
-/
set_option autoImplicit true
universe u v
open Function Set
namespace Set
variable {α β γ : Type*} {ι ι' : Sort*}
/-! ### Inverse image -/
/-- The preimage of `s : Set β` by `f : α → β`, written `f ⁻¹' s`,
is the set of `x : α` such that `f x ∈ s`. -/
def preimage {α : Type u} {β : Type v} (f : α → β) (s : Set β) : Set α :=
{ x | f x ∈ s }
#align set.preimage Set.preimage
/-- `f ⁻¹' t` denotes the preimage of `t : Set β` under the function `f : α → β`. -/
infixl:80 " ⁻¹' " => preimage
section Preimage
variable {f : α → β} {g : β → γ}
@[simp]
theorem preimage_empty : f ⁻¹' ∅ = ∅ :=
rfl
#align set.preimage_empty Set.preimage_empty
@[simp, mfld_simps]
theorem mem_preimage {s : Set β} {a : α} : a ∈ f ⁻¹' s ↔ f a ∈ s :=
Iff.rfl
#align set.mem_preimage Set.mem_preimage
theorem preimage_congr {f g : α → β} {s : Set β} (h : ∀ x : α, f x = g x) : f ⁻¹' s = g ⁻¹' s := by
congr with x
simp [h]
#align set.preimage_congr Set.preimage_congr
@[gcongr]
theorem preimage_mono {s t : Set β} (h : s ⊆ t) : f ⁻¹' s ⊆ f ⁻¹' t := fun _ hx => h hx
#align set.preimage_mono Set.preimage_mono
@[simp, mfld_simps]
theorem preimage_univ : f ⁻¹' univ = univ :=
rfl
#align set.preimage_univ Set.preimage_univ
theorem subset_preimage_univ {s : Set α} : s ⊆ f ⁻¹' univ :=
subset_univ _
#align set.subset_preimage_univ Set.subset_preimage_univ
@[simp, mfld_simps]
theorem preimage_inter {s t : Set β} : f ⁻¹' (s ∩ t) = f ⁻¹' s ∩ f ⁻¹' t :=
rfl
#align set.preimage_inter Set.preimage_inter
@[simp]
theorem preimage_union {s t : Set β} : f ⁻¹' (s ∪ t) = f ⁻¹' s ∪ f ⁻¹' t :=
rfl
#align set.preimage_union Set.preimage_union
@[simp]
theorem preimage_compl {s : Set β} : f ⁻¹' sᶜ = (f ⁻¹' s)ᶜ :=
rfl
#align set.preimage_compl Set.preimage_compl
@[simp]
theorem preimage_diff (f : α → β) (s t : Set β) : f ⁻¹' (s \ t) = f ⁻¹' s \ f ⁻¹' t :=
rfl
#align set.preimage_diff Set.preimage_diff
@[simp]
lemma preimage_symmDiff {f : α → β} (s t : Set β) : f ⁻¹' (s ∆ t) = (f ⁻¹' s) ∆ (f ⁻¹' t) :=
rfl
#align set.preimage_symm_diff Set.preimage_symmDiff
@[simp]
theorem preimage_ite (f : α → β) (s t₁ t₂ : Set β) :
f ⁻¹' s.ite t₁ t₂ = (f ⁻¹' s).ite (f ⁻¹' t₁) (f ⁻¹' t₂) :=
rfl
#align set.preimage_ite Set.preimage_ite
@[simp]
theorem preimage_setOf_eq {p : α → Prop} {f : β → α} : f ⁻¹' { a | p a } = { a | p (f a) } :=
rfl
#align set.preimage_set_of_eq Set.preimage_setOf_eq
@[simp]
theorem preimage_id_eq : preimage (id : α → α) = id :=
rfl
#align set.preimage_id_eq Set.preimage_id_eq
@[mfld_simps]
theorem preimage_id {s : Set α} : id ⁻¹' s = s :=
rfl
#align set.preimage_id Set.preimage_id
@[simp, mfld_simps]
theorem preimage_id' {s : Set α} : (fun x => x) ⁻¹' s = s :=
rfl
#align set.preimage_id' Set.preimage_id'
@[simp]
theorem preimage_const_of_mem {b : β} {s : Set β} (h : b ∈ s) : (fun _ : α => b) ⁻¹' s = univ :=
eq_univ_of_forall fun _ => h
#align set.preimage_const_of_mem Set.preimage_const_of_mem
@[simp]
theorem preimage_const_of_not_mem {b : β} {s : Set β} (h : b ∉ s) : (fun _ : α => b) ⁻¹' s = ∅ :=
eq_empty_of_subset_empty fun _ hx => h hx
#align set.preimage_const_of_not_mem Set.preimage_const_of_not_mem
theorem preimage_const (b : β) (s : Set β) [Decidable (b ∈ s)] :
(fun _ : α => b) ⁻¹' s = if b ∈ s then univ else ∅ := by
split_ifs with hb
exacts [preimage_const_of_mem hb, preimage_const_of_not_mem hb]
#align set.preimage_const Set.preimage_const
/-- If preimage of each singleton under `f : α → β` is either empty or the whole type,
then `f` is a constant. -/
lemma exists_eq_const_of_preimage_singleton [Nonempty β] {f : α → β}
(hf : ∀ b : β, f ⁻¹' {b} = ∅ ∨ f ⁻¹' {b} = univ) : ∃ b, f = const α b := by
rcases em (∃ b, f ⁻¹' {b} = univ) with ⟨b, hb⟩ | hf'
· exact ⟨b, funext fun x ↦ eq_univ_iff_forall.1 hb x⟩
· have : ∀ x b, f x ≠ b := fun x b ↦
eq_empty_iff_forall_not_mem.1 ((hf b).resolve_right fun h ↦ hf' ⟨b, h⟩) x
exact ⟨Classical.arbitrary β, funext fun x ↦ absurd rfl (this x _)⟩
theorem preimage_comp {s : Set γ} : g ∘ f ⁻¹' s = f ⁻¹' (g ⁻¹' s) :=
rfl
#align set.preimage_comp Set.preimage_comp
theorem preimage_comp_eq : preimage (g ∘ f) = preimage f ∘ preimage g :=
rfl
#align set.preimage_comp_eq Set.preimage_comp_eq
theorem preimage_iterate_eq {f : α → α} {n : ℕ} : Set.preimage f^[n] = (Set.preimage f)^[n] := by
induction' n with n ih; · simp
rw [iterate_succ, iterate_succ', preimage_comp_eq, ih]
#align set.preimage_iterate_eq Set.preimage_iterate_eq
theorem preimage_preimage {g : β → γ} {f : α → β} {s : Set γ} :
f ⁻¹' (g ⁻¹' s) = (fun x => g (f x)) ⁻¹' s :=
preimage_comp.symm
#align set.preimage_preimage Set.preimage_preimage
theorem eq_preimage_subtype_val_iff {p : α → Prop} {s : Set (Subtype p)} {t : Set α} :
s = Subtype.val ⁻¹' t ↔ ∀ (x) (h : p x), (⟨x, h⟩ : Subtype p) ∈ s ↔ x ∈ t :=
⟨fun s_eq x h => by
rw [s_eq]
simp, fun h => ext fun ⟨x, hx⟩ => by simp [h]⟩
#align set.eq_preimage_subtype_val_iff Set.eq_preimage_subtype_val_iff
theorem nonempty_of_nonempty_preimage {s : Set β} {f : α → β} (hf : (f ⁻¹' s).Nonempty) :
s.Nonempty :=
let ⟨x, hx⟩ := hf
⟨f x, hx⟩
#align set.nonempty_of_nonempty_preimage Set.nonempty_of_nonempty_preimage
@[simp] theorem preimage_singleton_true (p : α → Prop) : p ⁻¹' {True} = {a | p a} := by ext; simp
#align set.preimage_singleton_true Set.preimage_singleton_true
@[simp] theorem preimage_singleton_false (p : α → Prop) : p ⁻¹' {False} = {a | ¬p a} := by ext; simp
#align set.preimage_singleton_false Set.preimage_singleton_false
theorem preimage_subtype_coe_eq_compl {s u v : Set α} (hsuv : s ⊆ u ∪ v)
(H : s ∩ (u ∩ v) = ∅) : ((↑) : s → α) ⁻¹' u = ((↑) ⁻¹' v)ᶜ := by
ext ⟨x, x_in_s⟩
constructor
· intro x_in_u x_in_v
exact eq_empty_iff_forall_not_mem.mp H x ⟨x_in_s, ⟨x_in_u, x_in_v⟩⟩
· intro hx
exact Or.elim (hsuv x_in_s) id fun hx' => hx.elim hx'
#align set.preimage_subtype_coe_eq_compl Set.preimage_subtype_coe_eq_compl
end Preimage
/-! ### Image of a set under a function -/
section Image
variable {f : α → β} {s t : Set α}
-- Porting note: `Set.image` is already defined in `Init.Set`
#align set.image Set.image
/-- `f '' s` denotes the image of `s : Set α` under the function `f : α → β`. -/
infixl:80 " '' " => image
theorem mem_image_iff_bex {f : α → β} {s : Set α} {y : β} :
y ∈ f '' s ↔ ∃ (x : _) (_ : x ∈ s), f x = y :=
bex_def.symm
#align set.mem_image_iff_bex Set.mem_image_iff_bex
@[simp]
theorem mem_image (f : α → β) (s : Set α) (y : β) : y ∈ f '' s ↔ ∃ x ∈ s, f x = y :=
Iff.rfl
#align set.mem_image Set.mem_image
theorem image_eta (f : α → β) : f '' s = (fun x => f x) '' s :=
rfl
#align set.image_eta Set.image_eta
@[mfld_simps]
theorem mem_image_of_mem (f : α → β) {x : α} {a : Set α} (h : x ∈ a) : f x ∈ f '' a :=
⟨_, h, rfl⟩
#align set.mem_image_of_mem Set.mem_image_of_mem
theorem _root_.Function.Injective.mem_set_image {f : α → β} (hf : Injective f) {s : Set α} {a : α} :
f a ∈ f '' s ↔ a ∈ s :=
⟨fun ⟨_, hb, Eq⟩ => hf Eq ▸ hb, mem_image_of_mem f⟩
#align function.injective.mem_set_image Function.Injective.mem_set_image
theorem ball_image_iff {f : α → β} {s : Set α} {p : β → Prop} :
(∀ y ∈ f '' s, p y) ↔ ∀ x ∈ s, p (f x) := by simp
#align set.ball_image_iff Set.ball_image_iff
theorem ball_image_of_ball {f : α → β} {s : Set α} {p : β → Prop} (h : ∀ x ∈ s, p (f x)) :
∀ y ∈ f '' s, p y :=
ball_image_iff.2 h
#align set.ball_image_of_ball Set.ball_image_of_ball
theorem bex_image_iff {f : α → β} {s : Set α} {p : β → Prop} :
(∃ y ∈ f '' s, p y) ↔ ∃ x ∈ s, p (f x) := by simp
#align set.bex_image_iff Set.bex_image_iff
theorem mem_image_elim {f : α → β} {s : Set α} {C : β → Prop} (h : ∀ x : α, x ∈ s → C (f x)) :
∀ {y : β}, y ∈ f '' s → C y
| _, ⟨a, a_in, rfl⟩ => h a a_in
#align set.mem_image_elim Set.mem_image_elim
theorem mem_image_elim_on {f : α → β} {s : Set α} {C : β → Prop} {y : β} (h_y : y ∈ f '' s)
(h : ∀ x : α, x ∈ s → C (f x)) : C y :=
mem_image_elim h h_y
#align set.mem_image_elim_on Set.mem_image_elim_on
-- Porting note: used to be `safe`
@[congr]
theorem image_congr {f g : α → β} {s : Set α} (h : ∀ a ∈ s, f a = g a) : f '' s = g '' s := by
ext x
rw [mem_image, mem_image]
exact {
mp := by
rintro ⟨a, ha1, ha2⟩
exact ⟨a, ⟨ha1, (h a ha1) ▸ ha2⟩⟩,
mpr := by
rintro ⟨a, ha1, ha2⟩
exact ⟨a, ⟨ha1, (h a ha1) ▸ ha2⟩⟩
}
-- safe [ext_iff, iff_def]
#align set.image_congr Set.image_congr
/-- A common special case of `image_congr` -/
theorem image_congr' {f g : α → β} {s : Set α} (h : ∀ x : α, f x = g x) : f '' s = g '' s :=
image_congr fun x _ => h x
#align set.image_congr' Set.image_congr'
@[gcongr]
lemma image_mono (h : s ⊆ t) : f '' s ⊆ f '' t := by
rintro - ⟨a, ha, rfl⟩; exact mem_image_of_mem f (h ha)
theorem image_comp (f : β → γ) (g : α → β) (a : Set α) : f ∘ g '' a = f '' (g '' a) :=
Subset.antisymm (ball_image_of_ball fun _ ha => mem_image_of_mem _ <| mem_image_of_mem _ ha)
(ball_image_of_ball <| ball_image_of_ball fun _ ha => mem_image_of_mem _ ha)
#align set.image_comp Set.image_comp
theorem image_comp_eq {g : β → γ} : image (g ∘ f) = image g ∘ image f := by ext; simp
/-- A variant of `image_comp`, useful for rewriting -/
theorem image_image (g : β → γ) (f : α → β) (s : Set α) : g '' (f '' s) = (fun x => g (f x)) '' s :=
(image_comp g f s).symm
#align set.image_image Set.image_image
theorem image_comm {β'} {f : β → γ} {g : α → β} {f' : α → β'} {g' : β' → γ}
(h_comm : ∀ a, f (g a) = g' (f' a)) : (s.image g).image f = (s.image f').image g' := by
simp_rw [image_image, h_comm]
#align set.image_comm Set.image_comm
theorem _root_.Function.Semiconj.set_image {f : α → β} {ga : α → α} {gb : β → β}
(h : Function.Semiconj f ga gb) : Function.Semiconj (image f) (image ga) (image gb) := fun _ =>
image_comm h
#align function.semiconj.set_image Function.Semiconj.set_image
theorem _root_.Function.Commute.set_image {f g : α → α} (h : Function.Commute f g) :
Function.Commute (image f) (image g) :=
Function.Semiconj.set_image h
#align function.commute.set_image Function.Commute.set_image
/-- Image is monotone with respect to `⊆`. See `Set.monotone_image` for the statement in
terms of `≤`. -/
@[gcongr]
theorem image_subset {a b : Set α} (f : α → β) (h : a ⊆ b) : f '' a ⊆ f '' b := by
simp only [subset_def, mem_image]
exact fun x => fun ⟨w, h1, h2⟩ => ⟨w, h h1, h2⟩
#align set.image_subset Set.image_subset
/-- `Set.image` is monotone. See `Set.image_subset` for the statement in terms of `⊆`. -/
lemma monotone_image {f : α → β} : Monotone (image f) := fun _ _ => image_subset _
#align set.monotone_image Set.monotone_image
theorem image_union (f : α → β) (s t : Set α) : f '' (s ∪ t) = f '' s ∪ f '' t :=
ext fun x =>
⟨by rintro ⟨a, h | h, rfl⟩ <;> [left; right] <;> exact ⟨_, h, rfl⟩, by
rintro (⟨a, h, rfl⟩ | ⟨a, h, rfl⟩) <;> refine' ⟨_, _, rfl⟩ <;> [left; right] <;> exact h⟩
#align set.image_union Set.image_union
@[simp]
theorem image_empty (f : α → β) : f '' ∅ = ∅ := by
ext
simp
#align set.image_empty Set.image_empty
theorem image_inter_subset (f : α → β) (s t : Set α) : f '' (s ∩ t) ⊆ f '' s ∩ f '' t :=
subset_inter (image_subset _ <| inter_subset_left _ _) (image_subset _ <| inter_subset_right _ _)
#align set.image_inter_subset Set.image_inter_subset
theorem image_inter_on {f : α → β} {s t : Set α} (h : ∀ x ∈ t, ∀ y ∈ s, f x = f y → x = y) :
f '' (s ∩ t) = f '' s ∩ f '' t :=
(image_inter_subset _ _ _).antisymm
fun b ⟨⟨a₁, ha₁, h₁⟩, ⟨a₂, ha₂, h₂⟩⟩ ↦
have : a₂ = a₁ := h _ ha₂ _ ha₁ (by simp [*])
⟨a₁, ⟨ha₁, this ▸ ha₂⟩, h₁⟩
#align set.image_inter_on Set.image_inter_on
theorem image_inter {f : α → β} {s t : Set α} (H : Injective f) : f '' (s ∩ t) = f '' s ∩ f '' t :=
image_inter_on fun _ _ _ _ h => H h
#align set.image_inter Set.image_inter
theorem image_univ_of_surjective {ι : Type*} {f : ι → β} (H : Surjective f) : f '' univ = univ :=
eq_univ_of_forall <| by simpa [image]
#align set.image_univ_of_surjective Set.image_univ_of_surjective
@[simp]
theorem image_singleton {f : α → β} {a : α} : f '' {a} = {f a} := by
ext
simp [image, eq_comm]
#align set.image_singleton Set.image_singleton
@[simp]
theorem Nonempty.image_const {s : Set α} (hs : s.Nonempty) (a : β) : (fun _ => a) '' s = {a} :=
ext fun _ =>
⟨fun ⟨_, _, h⟩ => h ▸ mem_singleton _, fun h =>
(eq_of_mem_singleton h).symm ▸ hs.imp fun _ hy => ⟨hy, rfl⟩⟩
#align set.nonempty.image_const Set.Nonempty.image_const
@[simp, mfld_simps]
theorem image_eq_empty {α β} {f : α → β} {s : Set α} : f '' s = ∅ ↔ s = ∅ := by
simp only [eq_empty_iff_forall_not_mem]
exact ⟨fun H a ha => H _ ⟨_, ha, rfl⟩, fun H b ⟨_, ha, _⟩ => H _ ha⟩
#align set.image_eq_empty Set.image_eq_empty
-- Porting note: `compl` is already defined in `Init.Set`
theorem preimage_compl_eq_image_compl [BooleanAlgebra α] (S : Set α) :
HasCompl.compl ⁻¹' S = HasCompl.compl '' S :=
Set.ext fun x =>
⟨fun h => ⟨xᶜ, h, compl_compl x⟩, fun h =>
Exists.elim h fun _ hy => (compl_eq_comm.mp hy.2).symm.subst hy.1⟩
#align set.preimage_compl_eq_image_compl Set.preimage_compl_eq_image_compl
theorem mem_compl_image [BooleanAlgebra α] (t : α) (S : Set α) :
t ∈ HasCompl.compl '' S ↔ tᶜ ∈ S := by
simp [← preimage_compl_eq_image_compl]
#align set.mem_compl_image Set.mem_compl_image
@[simp]
theorem image_id_eq : image (id : α → α) = id := by ext; simp
/-- A variant of `image_id` -/
@[simp]
theorem image_id' (s : Set α) : (fun x => x) '' s = s := by
ext
simp
#align set.image_id' Set.image_id'
theorem image_id (s : Set α) : id '' s = s := by simp
#align set.image_id Set.image_id
lemma image_iterate_eq {f : α → α} {n : ℕ} : image (f^[n]) = (image f)^[n] := by
induction' n with n ih; · simp
rw [iterate_succ', iterate_succ',← ih, image_comp_eq]
theorem compl_compl_image [BooleanAlgebra α] (S : Set α) :
HasCompl.compl '' (HasCompl.compl '' S) = S := by
rw [← image_comp, compl_comp_compl, image_id]
#align set.compl_compl_image Set.compl_compl_image
theorem image_insert_eq {f : α → β} {a : α} {s : Set α} :
f '' insert a s = insert (f a) (f '' s) := by
ext
simp [and_or_left, exists_or, eq_comm, or_comm, and_comm]
#align set.image_insert_eq Set.image_insert_eq
theorem image_pair (f : α → β) (a b : α) : f '' {a, b} = {f a, f b} := by
simp only [image_insert_eq, image_singleton]
#align set.image_pair Set.image_pair
theorem image_subset_preimage_of_inverse {f : α → β} {g : β → α} (I : LeftInverse g f) (s : Set α) :
f '' s ⊆ g ⁻¹' s := fun _ ⟨a, h, e⟩ => e ▸ ((I a).symm ▸ h : g (f a) ∈ s)
#align set.image_subset_preimage_of_inverse Set.image_subset_preimage_of_inverse
theorem preimage_subset_image_of_inverse {f : α → β} {g : β → α} (I : LeftInverse g f) (s : Set β) :
f ⁻¹' s ⊆ g '' s := fun b h => ⟨f b, h, I b⟩
#align set.preimage_subset_image_of_inverse Set.preimage_subset_image_of_inverse
theorem image_eq_preimage_of_inverse {f : α → β} {g : β → α} (h₁ : LeftInverse g f)
(h₂ : RightInverse g f) : image f = preimage g :=
funext fun s =>
Subset.antisymm (image_subset_preimage_of_inverse h₁ s) (preimage_subset_image_of_inverse h₂ s)
#align set.image_eq_preimage_of_inverse Set.image_eq_preimage_of_inverse
theorem mem_image_iff_of_inverse {f : α → β} {g : β → α} {b : β} {s : Set α} (h₁ : LeftInverse g f)
(h₂ : RightInverse g f) : b ∈ f '' s ↔ g b ∈ s := by
rw [image_eq_preimage_of_inverse h₁ h₂]; rfl
#align set.mem_image_iff_of_inverse Set.mem_image_iff_of_inverse
theorem image_compl_subset {f : α → β} {s : Set α} (H : Injective f) : f '' sᶜ ⊆ (f '' s)ᶜ :=
Disjoint.subset_compl_left <| by simp [disjoint_iff_inf_le, ← image_inter H]
#align set.image_compl_subset Set.image_compl_subset
theorem subset_image_compl {f : α → β} {s : Set α} (H : Surjective f) : (f '' s)ᶜ ⊆ f '' sᶜ :=
compl_subset_iff_union.2 <| by
rw [← image_union]
simp [image_univ_of_surjective H]
#align set.subset_image_compl Set.subset_image_compl
theorem image_compl_eq {f : α → β} {s : Set α} (H : Bijective f) : f '' sᶜ = (f '' s)ᶜ :=
Subset.antisymm (image_compl_subset H.1) (subset_image_compl H.2)
#align set.image_compl_eq Set.image_compl_eq
theorem subset_image_diff (f : α → β) (s t : Set α) : f '' s \ f '' t ⊆ f '' (s \ t) := by
rw [diff_subset_iff, ← image_union, union_diff_self]
exact image_subset f (subset_union_right t s)
#align set.subset_image_diff Set.subset_image_diff
theorem subset_image_symmDiff : (f '' s) ∆ (f '' t) ⊆ f '' s ∆ t :=
(union_subset_union (subset_image_diff _ _ _) <| subset_image_diff _ _ _).trans
(superset_of_eq (image_union _ _ _))
#align set.subset_image_symm_diff Set.subset_image_symmDiff
theorem image_diff {f : α → β} (hf : Injective f) (s t : Set α) : f '' (s \ t) = f '' s \ f '' t :=
Subset.antisymm
(Subset.trans (image_inter_subset _ _ _) <| inter_subset_inter_right _ <| image_compl_subset hf)
(subset_image_diff f s t)
#align set.image_diff Set.image_diff
theorem image_symmDiff (hf : Injective f) (s t : Set α) : f '' s ∆ t = (f '' s) ∆ (f '' t) := by
simp_rw [Set.symmDiff_def, image_union, image_diff hf]
#align set.image_symm_diff Set.image_symmDiff
theorem Nonempty.image (f : α → β) {s : Set α} : s.Nonempty → (f '' s).Nonempty
| ⟨x, hx⟩ => ⟨f x, mem_image_of_mem f hx⟩
#align set.nonempty.image Set.Nonempty.image
theorem Nonempty.of_image {f : α → β} {s : Set α} : (f '' s).Nonempty → s.Nonempty
| ⟨_, x, hx, _⟩ => ⟨x, hx⟩
#align set.nonempty.of_image Set.Nonempty.of_image
@[simp]
theorem nonempty_image_iff {f : α → β} {s : Set α} : (f '' s).Nonempty ↔ s.Nonempty :=
⟨Nonempty.of_image, fun h => h.image f⟩
#align set.nonempty_image_iff Set.nonempty_image_iff
theorem Nonempty.preimage {s : Set β} (hs : s.Nonempty) {f : α → β} (hf : Surjective f) :
(f ⁻¹' s).Nonempty :=
let ⟨y, hy⟩ := hs
let ⟨x, hx⟩ := hf y
⟨x, mem_preimage.2 <| hx.symm ▸ hy⟩
#align set.nonempty.preimage Set.Nonempty.preimage
instance (f : α → β) (s : Set α) [Nonempty s] : Nonempty (f '' s) :=
(Set.Nonempty.image f nonempty_of_nonempty_subtype).to_subtype
/-- image and preimage are a Galois connection -/
@[simp]
theorem image_subset_iff {s : Set α} {t : Set β} {f : α → β} : f '' s ⊆ t ↔ s ⊆ f ⁻¹' t :=
ball_image_iff
#align set.image_subset_iff Set.image_subset_iff
theorem image_preimage_subset (f : α → β) (s : Set β) : f '' (f ⁻¹' s) ⊆ s :=
image_subset_iff.2 Subset.rfl
#align set.image_preimage_subset Set.image_preimage_subset
theorem subset_preimage_image (f : α → β) (s : Set α) : s ⊆ f ⁻¹' (f '' s) := fun _ =>
mem_image_of_mem f
#align set.subset_preimage_image Set.subset_preimage_image
@[simp]
theorem preimage_image_eq {f : α → β} (s : Set α) (h : Injective f) : f ⁻¹' (f '' s) = s :=
Subset.antisymm (fun _ ⟨_, hy, e⟩ => h e ▸ hy) (subset_preimage_image f s)
#align set.preimage_image_eq Set.preimage_image_eq
@[simp]
theorem image_preimage_eq {f : α → β} (s : Set β) (h : Surjective f) : f '' (f ⁻¹' s) = s :=
Subset.antisymm (image_preimage_subset f s) fun x hx =>
let ⟨y, e⟩ := h x
⟨y, (e.symm ▸ hx : f y ∈ s), e⟩
#align set.image_preimage_eq Set.image_preimage_eq
@[simp]
theorem preimage_eq_preimage {f : β → α} (hf : Surjective f) : f ⁻¹' s = f ⁻¹' t ↔ s = t :=
Iff.intro
fun eq => by rw [← image_preimage_eq s hf, ← image_preimage_eq t hf, eq]
fun eq => eq ▸ rfl
#align set.preimage_eq_preimage Set.preimage_eq_preimage
theorem image_inter_preimage (f : α → β) (s : Set α) (t : Set β) :
f '' (s ∩ f ⁻¹' t) = f '' s ∩ t := by
apply Subset.antisymm
· calc
f '' (s ∩ f ⁻¹' t) ⊆ f '' s ∩ f '' (f ⁻¹' t) := image_inter_subset _ _ _
_ ⊆ f '' s ∩ t := inter_subset_inter_right _ (image_preimage_subset f t)
· rintro _ ⟨⟨x, h', rfl⟩, h⟩
exact ⟨x, ⟨h', h⟩, rfl⟩
#align set.image_inter_preimage Set.image_inter_preimage
theorem image_preimage_inter (f : α → β) (s : Set α) (t : Set β) :
f '' (f ⁻¹' t ∩ s) = t ∩ f '' s := by simp only [inter_comm, image_inter_preimage]
#align set.image_preimage_inter Set.image_preimage_inter
@[simp]
theorem image_inter_nonempty_iff {f : α → β} {s : Set α} {t : Set β} :
(f '' s ∩ t).Nonempty ↔ (s ∩ f ⁻¹' t).Nonempty := by
rw [← image_inter_preimage, nonempty_image_iff]
#align set.image_inter_nonempty_iff Set.image_inter_nonempty_iff
theorem image_diff_preimage {f : α → β} {s : Set α} {t : Set β} : f '' (s \ f ⁻¹' t) = f '' s \ t :=
by simp_rw [diff_eq, ← preimage_compl, image_inter_preimage]
#align set.image_diff_preimage Set.image_diff_preimage
theorem compl_image : image (compl : Set α → Set α) = preimage compl :=
image_eq_preimage_of_inverse compl_compl compl_compl
#align set.compl_image Set.compl_image
theorem compl_image_set_of {p : Set α → Prop} : compl '' { s | p s } = { s | p sᶜ } :=
congr_fun compl_image p
#align set.compl_image_set_of Set.compl_image_set_of
theorem inter_preimage_subset (s : Set α) (t : Set β) (f : α → β) :
s ∩ f ⁻¹' t ⊆ f ⁻¹' (f '' s ∩ t) := fun _ h => ⟨mem_image_of_mem _ h.left, h.right⟩
#align set.inter_preimage_subset Set.inter_preimage_subset
theorem union_preimage_subset (s : Set α) (t : Set β) (f : α → β) :
s ∪ f ⁻¹' t ⊆ f ⁻¹' (f '' s ∪ t) := fun _ h =>
Or.elim h (fun l => Or.inl <| mem_image_of_mem _ l) fun r => Or.inr r
#align set.union_preimage_subset Set.union_preimage_subset
theorem subset_image_union (f : α → β) (s : Set α) (t : Set β) : f '' (s ∪ f ⁻¹' t) ⊆ f '' s ∪ t :=
image_subset_iff.2 (union_preimage_subset _ _ _)
#align set.subset_image_union Set.subset_image_union
theorem preimage_subset_iff {A : Set α} {B : Set β} {f : α → β} :
f ⁻¹' B ⊆ A ↔ ∀ a : α, f a ∈ B → a ∈ A :=
Iff.rfl
#align set.preimage_subset_iff Set.preimage_subset_iff
theorem image_eq_image {f : α → β} (hf : Injective f) : f '' s = f '' t ↔ s = t :=
Iff.symm <|
(Iff.intro fun eq => eq ▸ rfl) fun eq => by
rw [← preimage_image_eq s hf, ← preimage_image_eq t hf, eq]
#align set.image_eq_image Set.image_eq_image
theorem image_subset_image_iff {f : α → β} (hf : Injective f) : f '' s ⊆ f '' t ↔ s ⊆ t := by
refine' Iff.symm <| (Iff.intro (image_subset f)) fun h => _
rw [← preimage_image_eq s hf, ← preimage_image_eq t hf]
exact preimage_mono h
#align set.image_subset_image_iff Set.image_subset_image_iff
theorem prod_quotient_preimage_eq_image [s : Setoid α] (g : Quotient s → β) {h : α → β}
(Hh : h = g ∘ Quotient.mk'') (r : Set (β × β)) :
{ x : Quotient s × Quotient s | (g x.1, g x.2) ∈ r } =
(fun a : α × α => (⟦a.1⟧, ⟦a.2⟧)) '' ((fun a : α × α => (h a.1, h a.2)) ⁻¹' r) :=
Hh.symm ▸
Set.ext fun ⟨a₁, a₂⟩ =>
⟨Quot.induction_on₂ a₁ a₂ fun a₁ a₂ h => ⟨(a₁, a₂), h, rfl⟩, fun ⟨⟨b₁, b₂⟩, h₁, h₂⟩ =>
show (g a₁, g a₂) ∈ r from
have h₃ : ⟦b₁⟧ = a₁ ∧ ⟦b₂⟧ = a₂ := Prod.ext_iff.1 h₂
h₃.1 ▸ h₃.2 ▸ h₁⟩
#align set.prod_quotient_preimage_eq_image Set.prod_quotient_preimage_eq_image
theorem exists_image_iff (f : α → β) (x : Set α) (P : β → Prop) :
(∃ a : f '' x, P a) ↔ ∃ a : x, P (f a) :=
⟨fun ⟨a, h⟩ => ⟨⟨_, a.prop.choose_spec.1⟩, a.prop.choose_spec.2.symm ▸ h⟩, fun ⟨a, h⟩ =>
⟨⟨_, _, a.prop, rfl⟩, h⟩⟩
#align set.exists_image_iff Set.exists_image_iff
/-- Restriction of `f` to `s` factors through `s.imageFactorization f : s → f '' s`. -/
def imageFactorization (f : α → β) (s : Set α) : s → f '' s := fun p =>
⟨f p.1, mem_image_of_mem f p.2⟩
#align set.image_factorization Set.imageFactorization
theorem imageFactorization_eq {f : α → β} {s : Set α} :
Subtype.val ∘ imageFactorization f s = f ∘ Subtype.val :=
funext fun _ => rfl
#align set.image_factorization_eq Set.imageFactorization_eq
theorem surjective_onto_image {f : α → β} {s : Set α} : Surjective (imageFactorization f s) :=
fun ⟨_, ⟨a, ha, rfl⟩⟩ => ⟨⟨a, ha⟩, rfl⟩
#align set.surjective_onto_image Set.surjective_onto_image
/-- If the only elements outside `s` are those left fixed by `σ`, then mapping by `σ` has no effect.
-/
theorem image_perm {s : Set α} {σ : Equiv.Perm α} (hs : { a : α | σ a ≠ a } ⊆ s) : σ '' s = s := by
ext i
obtain hi | hi := eq_or_ne (σ i) i
·
|
refine' ⟨_, fun h => ⟨i, h, hi⟩⟩
|
/-- If the only elements outside `s` are those left fixed by `σ`, then mapping by `σ` has no effect.
-/
theorem image_perm {s : Set α} {σ : Equiv.Perm α} (hs : { a : α | σ a ≠ a } ⊆ s) : σ '' s = s := by
ext i
obtain hi | hi := eq_or_ne (σ i) i
·
|
Mathlib.Data.Set.Image.635_0.IJFiTzmYGOCpPSd
|
/-- If the only elements outside `s` are those left fixed by `σ`, then mapping by `σ` has no effect.
-/
theorem image_perm {s : Set α} {σ : Equiv.Perm α} (hs : { a : α | σ a ≠ a } ⊆ s) : σ '' s = s
|
Mathlib_Data_Set_Image
|
case h.inl
α : Type u_1
β : Type u_2
γ : Type u_3
ι : Sort u_4
ι' : Sort u_5
f : α → β
s✝ t s : Set α
σ : Equiv.Perm α
hs : {a | σ a ≠ a} ⊆ s
i : α
hi : σ i = i
⊢ i ∈ ⇑σ '' s → i ∈ s
|
/-
Copyright (c) 2014 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Leonardo de Moura
-/
import Mathlib.Data.Set.Basic
#align_import data.set.image from "leanprover-community/mathlib"@"001ffdc42920050657fd45bd2b8bfbec8eaaeb29"
/-!
# Images and preimages of sets
## Main definitions
* `preimage f t : Set α` : the preimage f⁻¹(t) (written `f ⁻¹' t` in Lean) of a subset of β.
* `range f : Set β` : the image of `univ` under `f`.
Also works for `{p : Prop} (f : p → α)` (unlike `image`)
## Notation
* `f ⁻¹' t` for `Set.preimage f t`
* `f '' s` for `Set.image f s`
## Tags
set, sets, image, preimage, pre-image, range
-/
set_option autoImplicit true
universe u v
open Function Set
namespace Set
variable {α β γ : Type*} {ι ι' : Sort*}
/-! ### Inverse image -/
/-- The preimage of `s : Set β` by `f : α → β`, written `f ⁻¹' s`,
is the set of `x : α` such that `f x ∈ s`. -/
def preimage {α : Type u} {β : Type v} (f : α → β) (s : Set β) : Set α :=
{ x | f x ∈ s }
#align set.preimage Set.preimage
/-- `f ⁻¹' t` denotes the preimage of `t : Set β` under the function `f : α → β`. -/
infixl:80 " ⁻¹' " => preimage
section Preimage
variable {f : α → β} {g : β → γ}
@[simp]
theorem preimage_empty : f ⁻¹' ∅ = ∅ :=
rfl
#align set.preimage_empty Set.preimage_empty
@[simp, mfld_simps]
theorem mem_preimage {s : Set β} {a : α} : a ∈ f ⁻¹' s ↔ f a ∈ s :=
Iff.rfl
#align set.mem_preimage Set.mem_preimage
theorem preimage_congr {f g : α → β} {s : Set β} (h : ∀ x : α, f x = g x) : f ⁻¹' s = g ⁻¹' s := by
congr with x
simp [h]
#align set.preimage_congr Set.preimage_congr
@[gcongr]
theorem preimage_mono {s t : Set β} (h : s ⊆ t) : f ⁻¹' s ⊆ f ⁻¹' t := fun _ hx => h hx
#align set.preimage_mono Set.preimage_mono
@[simp, mfld_simps]
theorem preimage_univ : f ⁻¹' univ = univ :=
rfl
#align set.preimage_univ Set.preimage_univ
theorem subset_preimage_univ {s : Set α} : s ⊆ f ⁻¹' univ :=
subset_univ _
#align set.subset_preimage_univ Set.subset_preimage_univ
@[simp, mfld_simps]
theorem preimage_inter {s t : Set β} : f ⁻¹' (s ∩ t) = f ⁻¹' s ∩ f ⁻¹' t :=
rfl
#align set.preimage_inter Set.preimage_inter
@[simp]
theorem preimage_union {s t : Set β} : f ⁻¹' (s ∪ t) = f ⁻¹' s ∪ f ⁻¹' t :=
rfl
#align set.preimage_union Set.preimage_union
@[simp]
theorem preimage_compl {s : Set β} : f ⁻¹' sᶜ = (f ⁻¹' s)ᶜ :=
rfl
#align set.preimage_compl Set.preimage_compl
@[simp]
theorem preimage_diff (f : α → β) (s t : Set β) : f ⁻¹' (s \ t) = f ⁻¹' s \ f ⁻¹' t :=
rfl
#align set.preimage_diff Set.preimage_diff
@[simp]
lemma preimage_symmDiff {f : α → β} (s t : Set β) : f ⁻¹' (s ∆ t) = (f ⁻¹' s) ∆ (f ⁻¹' t) :=
rfl
#align set.preimage_symm_diff Set.preimage_symmDiff
@[simp]
theorem preimage_ite (f : α → β) (s t₁ t₂ : Set β) :
f ⁻¹' s.ite t₁ t₂ = (f ⁻¹' s).ite (f ⁻¹' t₁) (f ⁻¹' t₂) :=
rfl
#align set.preimage_ite Set.preimage_ite
@[simp]
theorem preimage_setOf_eq {p : α → Prop} {f : β → α} : f ⁻¹' { a | p a } = { a | p (f a) } :=
rfl
#align set.preimage_set_of_eq Set.preimage_setOf_eq
@[simp]
theorem preimage_id_eq : preimage (id : α → α) = id :=
rfl
#align set.preimage_id_eq Set.preimage_id_eq
@[mfld_simps]
theorem preimage_id {s : Set α} : id ⁻¹' s = s :=
rfl
#align set.preimage_id Set.preimage_id
@[simp, mfld_simps]
theorem preimage_id' {s : Set α} : (fun x => x) ⁻¹' s = s :=
rfl
#align set.preimage_id' Set.preimage_id'
@[simp]
theorem preimage_const_of_mem {b : β} {s : Set β} (h : b ∈ s) : (fun _ : α => b) ⁻¹' s = univ :=
eq_univ_of_forall fun _ => h
#align set.preimage_const_of_mem Set.preimage_const_of_mem
@[simp]
theorem preimage_const_of_not_mem {b : β} {s : Set β} (h : b ∉ s) : (fun _ : α => b) ⁻¹' s = ∅ :=
eq_empty_of_subset_empty fun _ hx => h hx
#align set.preimage_const_of_not_mem Set.preimage_const_of_not_mem
theorem preimage_const (b : β) (s : Set β) [Decidable (b ∈ s)] :
(fun _ : α => b) ⁻¹' s = if b ∈ s then univ else ∅ := by
split_ifs with hb
exacts [preimage_const_of_mem hb, preimage_const_of_not_mem hb]
#align set.preimage_const Set.preimage_const
/-- If preimage of each singleton under `f : α → β` is either empty or the whole type,
then `f` is a constant. -/
lemma exists_eq_const_of_preimage_singleton [Nonempty β] {f : α → β}
(hf : ∀ b : β, f ⁻¹' {b} = ∅ ∨ f ⁻¹' {b} = univ) : ∃ b, f = const α b := by
rcases em (∃ b, f ⁻¹' {b} = univ) with ⟨b, hb⟩ | hf'
· exact ⟨b, funext fun x ↦ eq_univ_iff_forall.1 hb x⟩
· have : ∀ x b, f x ≠ b := fun x b ↦
eq_empty_iff_forall_not_mem.1 ((hf b).resolve_right fun h ↦ hf' ⟨b, h⟩) x
exact ⟨Classical.arbitrary β, funext fun x ↦ absurd rfl (this x _)⟩
theorem preimage_comp {s : Set γ} : g ∘ f ⁻¹' s = f ⁻¹' (g ⁻¹' s) :=
rfl
#align set.preimage_comp Set.preimage_comp
theorem preimage_comp_eq : preimage (g ∘ f) = preimage f ∘ preimage g :=
rfl
#align set.preimage_comp_eq Set.preimage_comp_eq
theorem preimage_iterate_eq {f : α → α} {n : ℕ} : Set.preimage f^[n] = (Set.preimage f)^[n] := by
induction' n with n ih; · simp
rw [iterate_succ, iterate_succ', preimage_comp_eq, ih]
#align set.preimage_iterate_eq Set.preimage_iterate_eq
theorem preimage_preimage {g : β → γ} {f : α → β} {s : Set γ} :
f ⁻¹' (g ⁻¹' s) = (fun x => g (f x)) ⁻¹' s :=
preimage_comp.symm
#align set.preimage_preimage Set.preimage_preimage
theorem eq_preimage_subtype_val_iff {p : α → Prop} {s : Set (Subtype p)} {t : Set α} :
s = Subtype.val ⁻¹' t ↔ ∀ (x) (h : p x), (⟨x, h⟩ : Subtype p) ∈ s ↔ x ∈ t :=
⟨fun s_eq x h => by
rw [s_eq]
simp, fun h => ext fun ⟨x, hx⟩ => by simp [h]⟩
#align set.eq_preimage_subtype_val_iff Set.eq_preimage_subtype_val_iff
theorem nonempty_of_nonempty_preimage {s : Set β} {f : α → β} (hf : (f ⁻¹' s).Nonempty) :
s.Nonempty :=
let ⟨x, hx⟩ := hf
⟨f x, hx⟩
#align set.nonempty_of_nonempty_preimage Set.nonempty_of_nonempty_preimage
@[simp] theorem preimage_singleton_true (p : α → Prop) : p ⁻¹' {True} = {a | p a} := by ext; simp
#align set.preimage_singleton_true Set.preimage_singleton_true
@[simp] theorem preimage_singleton_false (p : α → Prop) : p ⁻¹' {False} = {a | ¬p a} := by ext; simp
#align set.preimage_singleton_false Set.preimage_singleton_false
theorem preimage_subtype_coe_eq_compl {s u v : Set α} (hsuv : s ⊆ u ∪ v)
(H : s ∩ (u ∩ v) = ∅) : ((↑) : s → α) ⁻¹' u = ((↑) ⁻¹' v)ᶜ := by
ext ⟨x, x_in_s⟩
constructor
· intro x_in_u x_in_v
exact eq_empty_iff_forall_not_mem.mp H x ⟨x_in_s, ⟨x_in_u, x_in_v⟩⟩
· intro hx
exact Or.elim (hsuv x_in_s) id fun hx' => hx.elim hx'
#align set.preimage_subtype_coe_eq_compl Set.preimage_subtype_coe_eq_compl
end Preimage
/-! ### Image of a set under a function -/
section Image
variable {f : α → β} {s t : Set α}
-- Porting note: `Set.image` is already defined in `Init.Set`
#align set.image Set.image
/-- `f '' s` denotes the image of `s : Set α` under the function `f : α → β`. -/
infixl:80 " '' " => image
theorem mem_image_iff_bex {f : α → β} {s : Set α} {y : β} :
y ∈ f '' s ↔ ∃ (x : _) (_ : x ∈ s), f x = y :=
bex_def.symm
#align set.mem_image_iff_bex Set.mem_image_iff_bex
@[simp]
theorem mem_image (f : α → β) (s : Set α) (y : β) : y ∈ f '' s ↔ ∃ x ∈ s, f x = y :=
Iff.rfl
#align set.mem_image Set.mem_image
theorem image_eta (f : α → β) : f '' s = (fun x => f x) '' s :=
rfl
#align set.image_eta Set.image_eta
@[mfld_simps]
theorem mem_image_of_mem (f : α → β) {x : α} {a : Set α} (h : x ∈ a) : f x ∈ f '' a :=
⟨_, h, rfl⟩
#align set.mem_image_of_mem Set.mem_image_of_mem
theorem _root_.Function.Injective.mem_set_image {f : α → β} (hf : Injective f) {s : Set α} {a : α} :
f a ∈ f '' s ↔ a ∈ s :=
⟨fun ⟨_, hb, Eq⟩ => hf Eq ▸ hb, mem_image_of_mem f⟩
#align function.injective.mem_set_image Function.Injective.mem_set_image
theorem ball_image_iff {f : α → β} {s : Set α} {p : β → Prop} :
(∀ y ∈ f '' s, p y) ↔ ∀ x ∈ s, p (f x) := by simp
#align set.ball_image_iff Set.ball_image_iff
theorem ball_image_of_ball {f : α → β} {s : Set α} {p : β → Prop} (h : ∀ x ∈ s, p (f x)) :
∀ y ∈ f '' s, p y :=
ball_image_iff.2 h
#align set.ball_image_of_ball Set.ball_image_of_ball
theorem bex_image_iff {f : α → β} {s : Set α} {p : β → Prop} :
(∃ y ∈ f '' s, p y) ↔ ∃ x ∈ s, p (f x) := by simp
#align set.bex_image_iff Set.bex_image_iff
theorem mem_image_elim {f : α → β} {s : Set α} {C : β → Prop} (h : ∀ x : α, x ∈ s → C (f x)) :
∀ {y : β}, y ∈ f '' s → C y
| _, ⟨a, a_in, rfl⟩ => h a a_in
#align set.mem_image_elim Set.mem_image_elim
theorem mem_image_elim_on {f : α → β} {s : Set α} {C : β → Prop} {y : β} (h_y : y ∈ f '' s)
(h : ∀ x : α, x ∈ s → C (f x)) : C y :=
mem_image_elim h h_y
#align set.mem_image_elim_on Set.mem_image_elim_on
-- Porting note: used to be `safe`
@[congr]
theorem image_congr {f g : α → β} {s : Set α} (h : ∀ a ∈ s, f a = g a) : f '' s = g '' s := by
ext x
rw [mem_image, mem_image]
exact {
mp := by
rintro ⟨a, ha1, ha2⟩
exact ⟨a, ⟨ha1, (h a ha1) ▸ ha2⟩⟩,
mpr := by
rintro ⟨a, ha1, ha2⟩
exact ⟨a, ⟨ha1, (h a ha1) ▸ ha2⟩⟩
}
-- safe [ext_iff, iff_def]
#align set.image_congr Set.image_congr
/-- A common special case of `image_congr` -/
theorem image_congr' {f g : α → β} {s : Set α} (h : ∀ x : α, f x = g x) : f '' s = g '' s :=
image_congr fun x _ => h x
#align set.image_congr' Set.image_congr'
@[gcongr]
lemma image_mono (h : s ⊆ t) : f '' s ⊆ f '' t := by
rintro - ⟨a, ha, rfl⟩; exact mem_image_of_mem f (h ha)
theorem image_comp (f : β → γ) (g : α → β) (a : Set α) : f ∘ g '' a = f '' (g '' a) :=
Subset.antisymm (ball_image_of_ball fun _ ha => mem_image_of_mem _ <| mem_image_of_mem _ ha)
(ball_image_of_ball <| ball_image_of_ball fun _ ha => mem_image_of_mem _ ha)
#align set.image_comp Set.image_comp
theorem image_comp_eq {g : β → γ} : image (g ∘ f) = image g ∘ image f := by ext; simp
/-- A variant of `image_comp`, useful for rewriting -/
theorem image_image (g : β → γ) (f : α → β) (s : Set α) : g '' (f '' s) = (fun x => g (f x)) '' s :=
(image_comp g f s).symm
#align set.image_image Set.image_image
theorem image_comm {β'} {f : β → γ} {g : α → β} {f' : α → β'} {g' : β' → γ}
(h_comm : ∀ a, f (g a) = g' (f' a)) : (s.image g).image f = (s.image f').image g' := by
simp_rw [image_image, h_comm]
#align set.image_comm Set.image_comm
theorem _root_.Function.Semiconj.set_image {f : α → β} {ga : α → α} {gb : β → β}
(h : Function.Semiconj f ga gb) : Function.Semiconj (image f) (image ga) (image gb) := fun _ =>
image_comm h
#align function.semiconj.set_image Function.Semiconj.set_image
theorem _root_.Function.Commute.set_image {f g : α → α} (h : Function.Commute f g) :
Function.Commute (image f) (image g) :=
Function.Semiconj.set_image h
#align function.commute.set_image Function.Commute.set_image
/-- Image is monotone with respect to `⊆`. See `Set.monotone_image` for the statement in
terms of `≤`. -/
@[gcongr]
theorem image_subset {a b : Set α} (f : α → β) (h : a ⊆ b) : f '' a ⊆ f '' b := by
simp only [subset_def, mem_image]
exact fun x => fun ⟨w, h1, h2⟩ => ⟨w, h h1, h2⟩
#align set.image_subset Set.image_subset
/-- `Set.image` is monotone. See `Set.image_subset` for the statement in terms of `⊆`. -/
lemma monotone_image {f : α → β} : Monotone (image f) := fun _ _ => image_subset _
#align set.monotone_image Set.monotone_image
theorem image_union (f : α → β) (s t : Set α) : f '' (s ∪ t) = f '' s ∪ f '' t :=
ext fun x =>
⟨by rintro ⟨a, h | h, rfl⟩ <;> [left; right] <;> exact ⟨_, h, rfl⟩, by
rintro (⟨a, h, rfl⟩ | ⟨a, h, rfl⟩) <;> refine' ⟨_, _, rfl⟩ <;> [left; right] <;> exact h⟩
#align set.image_union Set.image_union
@[simp]
theorem image_empty (f : α → β) : f '' ∅ = ∅ := by
ext
simp
#align set.image_empty Set.image_empty
theorem image_inter_subset (f : α → β) (s t : Set α) : f '' (s ∩ t) ⊆ f '' s ∩ f '' t :=
subset_inter (image_subset _ <| inter_subset_left _ _) (image_subset _ <| inter_subset_right _ _)
#align set.image_inter_subset Set.image_inter_subset
theorem image_inter_on {f : α → β} {s t : Set α} (h : ∀ x ∈ t, ∀ y ∈ s, f x = f y → x = y) :
f '' (s ∩ t) = f '' s ∩ f '' t :=
(image_inter_subset _ _ _).antisymm
fun b ⟨⟨a₁, ha₁, h₁⟩, ⟨a₂, ha₂, h₂⟩⟩ ↦
have : a₂ = a₁ := h _ ha₂ _ ha₁ (by simp [*])
⟨a₁, ⟨ha₁, this ▸ ha₂⟩, h₁⟩
#align set.image_inter_on Set.image_inter_on
theorem image_inter {f : α → β} {s t : Set α} (H : Injective f) : f '' (s ∩ t) = f '' s ∩ f '' t :=
image_inter_on fun _ _ _ _ h => H h
#align set.image_inter Set.image_inter
theorem image_univ_of_surjective {ι : Type*} {f : ι → β} (H : Surjective f) : f '' univ = univ :=
eq_univ_of_forall <| by simpa [image]
#align set.image_univ_of_surjective Set.image_univ_of_surjective
@[simp]
theorem image_singleton {f : α → β} {a : α} : f '' {a} = {f a} := by
ext
simp [image, eq_comm]
#align set.image_singleton Set.image_singleton
@[simp]
theorem Nonempty.image_const {s : Set α} (hs : s.Nonempty) (a : β) : (fun _ => a) '' s = {a} :=
ext fun _ =>
⟨fun ⟨_, _, h⟩ => h ▸ mem_singleton _, fun h =>
(eq_of_mem_singleton h).symm ▸ hs.imp fun _ hy => ⟨hy, rfl⟩⟩
#align set.nonempty.image_const Set.Nonempty.image_const
@[simp, mfld_simps]
theorem image_eq_empty {α β} {f : α → β} {s : Set α} : f '' s = ∅ ↔ s = ∅ := by
simp only [eq_empty_iff_forall_not_mem]
exact ⟨fun H a ha => H _ ⟨_, ha, rfl⟩, fun H b ⟨_, ha, _⟩ => H _ ha⟩
#align set.image_eq_empty Set.image_eq_empty
-- Porting note: `compl` is already defined in `Init.Set`
theorem preimage_compl_eq_image_compl [BooleanAlgebra α] (S : Set α) :
HasCompl.compl ⁻¹' S = HasCompl.compl '' S :=
Set.ext fun x =>
⟨fun h => ⟨xᶜ, h, compl_compl x⟩, fun h =>
Exists.elim h fun _ hy => (compl_eq_comm.mp hy.2).symm.subst hy.1⟩
#align set.preimage_compl_eq_image_compl Set.preimage_compl_eq_image_compl
theorem mem_compl_image [BooleanAlgebra α] (t : α) (S : Set α) :
t ∈ HasCompl.compl '' S ↔ tᶜ ∈ S := by
simp [← preimage_compl_eq_image_compl]
#align set.mem_compl_image Set.mem_compl_image
@[simp]
theorem image_id_eq : image (id : α → α) = id := by ext; simp
/-- A variant of `image_id` -/
@[simp]
theorem image_id' (s : Set α) : (fun x => x) '' s = s := by
ext
simp
#align set.image_id' Set.image_id'
theorem image_id (s : Set α) : id '' s = s := by simp
#align set.image_id Set.image_id
lemma image_iterate_eq {f : α → α} {n : ℕ} : image (f^[n]) = (image f)^[n] := by
induction' n with n ih; · simp
rw [iterate_succ', iterate_succ',← ih, image_comp_eq]
theorem compl_compl_image [BooleanAlgebra α] (S : Set α) :
HasCompl.compl '' (HasCompl.compl '' S) = S := by
rw [← image_comp, compl_comp_compl, image_id]
#align set.compl_compl_image Set.compl_compl_image
theorem image_insert_eq {f : α → β} {a : α} {s : Set α} :
f '' insert a s = insert (f a) (f '' s) := by
ext
simp [and_or_left, exists_or, eq_comm, or_comm, and_comm]
#align set.image_insert_eq Set.image_insert_eq
theorem image_pair (f : α → β) (a b : α) : f '' {a, b} = {f a, f b} := by
simp only [image_insert_eq, image_singleton]
#align set.image_pair Set.image_pair
theorem image_subset_preimage_of_inverse {f : α → β} {g : β → α} (I : LeftInverse g f) (s : Set α) :
f '' s ⊆ g ⁻¹' s := fun _ ⟨a, h, e⟩ => e ▸ ((I a).symm ▸ h : g (f a) ∈ s)
#align set.image_subset_preimage_of_inverse Set.image_subset_preimage_of_inverse
theorem preimage_subset_image_of_inverse {f : α → β} {g : β → α} (I : LeftInverse g f) (s : Set β) :
f ⁻¹' s ⊆ g '' s := fun b h => ⟨f b, h, I b⟩
#align set.preimage_subset_image_of_inverse Set.preimage_subset_image_of_inverse
theorem image_eq_preimage_of_inverse {f : α → β} {g : β → α} (h₁ : LeftInverse g f)
(h₂ : RightInverse g f) : image f = preimage g :=
funext fun s =>
Subset.antisymm (image_subset_preimage_of_inverse h₁ s) (preimage_subset_image_of_inverse h₂ s)
#align set.image_eq_preimage_of_inverse Set.image_eq_preimage_of_inverse
theorem mem_image_iff_of_inverse {f : α → β} {g : β → α} {b : β} {s : Set α} (h₁ : LeftInverse g f)
(h₂ : RightInverse g f) : b ∈ f '' s ↔ g b ∈ s := by
rw [image_eq_preimage_of_inverse h₁ h₂]; rfl
#align set.mem_image_iff_of_inverse Set.mem_image_iff_of_inverse
theorem image_compl_subset {f : α → β} {s : Set α} (H : Injective f) : f '' sᶜ ⊆ (f '' s)ᶜ :=
Disjoint.subset_compl_left <| by simp [disjoint_iff_inf_le, ← image_inter H]
#align set.image_compl_subset Set.image_compl_subset
theorem subset_image_compl {f : α → β} {s : Set α} (H : Surjective f) : (f '' s)ᶜ ⊆ f '' sᶜ :=
compl_subset_iff_union.2 <| by
rw [← image_union]
simp [image_univ_of_surjective H]
#align set.subset_image_compl Set.subset_image_compl
theorem image_compl_eq {f : α → β} {s : Set α} (H : Bijective f) : f '' sᶜ = (f '' s)ᶜ :=
Subset.antisymm (image_compl_subset H.1) (subset_image_compl H.2)
#align set.image_compl_eq Set.image_compl_eq
theorem subset_image_diff (f : α → β) (s t : Set α) : f '' s \ f '' t ⊆ f '' (s \ t) := by
rw [diff_subset_iff, ← image_union, union_diff_self]
exact image_subset f (subset_union_right t s)
#align set.subset_image_diff Set.subset_image_diff
theorem subset_image_symmDiff : (f '' s) ∆ (f '' t) ⊆ f '' s ∆ t :=
(union_subset_union (subset_image_diff _ _ _) <| subset_image_diff _ _ _).trans
(superset_of_eq (image_union _ _ _))
#align set.subset_image_symm_diff Set.subset_image_symmDiff
theorem image_diff {f : α → β} (hf : Injective f) (s t : Set α) : f '' (s \ t) = f '' s \ f '' t :=
Subset.antisymm
(Subset.trans (image_inter_subset _ _ _) <| inter_subset_inter_right _ <| image_compl_subset hf)
(subset_image_diff f s t)
#align set.image_diff Set.image_diff
theorem image_symmDiff (hf : Injective f) (s t : Set α) : f '' s ∆ t = (f '' s) ∆ (f '' t) := by
simp_rw [Set.symmDiff_def, image_union, image_diff hf]
#align set.image_symm_diff Set.image_symmDiff
theorem Nonempty.image (f : α → β) {s : Set α} : s.Nonempty → (f '' s).Nonempty
| ⟨x, hx⟩ => ⟨f x, mem_image_of_mem f hx⟩
#align set.nonempty.image Set.Nonempty.image
theorem Nonempty.of_image {f : α → β} {s : Set α} : (f '' s).Nonempty → s.Nonempty
| ⟨_, x, hx, _⟩ => ⟨x, hx⟩
#align set.nonempty.of_image Set.Nonempty.of_image
@[simp]
theorem nonempty_image_iff {f : α → β} {s : Set α} : (f '' s).Nonempty ↔ s.Nonempty :=
⟨Nonempty.of_image, fun h => h.image f⟩
#align set.nonempty_image_iff Set.nonempty_image_iff
theorem Nonempty.preimage {s : Set β} (hs : s.Nonempty) {f : α → β} (hf : Surjective f) :
(f ⁻¹' s).Nonempty :=
let ⟨y, hy⟩ := hs
let ⟨x, hx⟩ := hf y
⟨x, mem_preimage.2 <| hx.symm ▸ hy⟩
#align set.nonempty.preimage Set.Nonempty.preimage
instance (f : α → β) (s : Set α) [Nonempty s] : Nonempty (f '' s) :=
(Set.Nonempty.image f nonempty_of_nonempty_subtype).to_subtype
/-- image and preimage are a Galois connection -/
@[simp]
theorem image_subset_iff {s : Set α} {t : Set β} {f : α → β} : f '' s ⊆ t ↔ s ⊆ f ⁻¹' t :=
ball_image_iff
#align set.image_subset_iff Set.image_subset_iff
theorem image_preimage_subset (f : α → β) (s : Set β) : f '' (f ⁻¹' s) ⊆ s :=
image_subset_iff.2 Subset.rfl
#align set.image_preimage_subset Set.image_preimage_subset
theorem subset_preimage_image (f : α → β) (s : Set α) : s ⊆ f ⁻¹' (f '' s) := fun _ =>
mem_image_of_mem f
#align set.subset_preimage_image Set.subset_preimage_image
@[simp]
theorem preimage_image_eq {f : α → β} (s : Set α) (h : Injective f) : f ⁻¹' (f '' s) = s :=
Subset.antisymm (fun _ ⟨_, hy, e⟩ => h e ▸ hy) (subset_preimage_image f s)
#align set.preimage_image_eq Set.preimage_image_eq
@[simp]
theorem image_preimage_eq {f : α → β} (s : Set β) (h : Surjective f) : f '' (f ⁻¹' s) = s :=
Subset.antisymm (image_preimage_subset f s) fun x hx =>
let ⟨y, e⟩ := h x
⟨y, (e.symm ▸ hx : f y ∈ s), e⟩
#align set.image_preimage_eq Set.image_preimage_eq
@[simp]
theorem preimage_eq_preimage {f : β → α} (hf : Surjective f) : f ⁻¹' s = f ⁻¹' t ↔ s = t :=
Iff.intro
fun eq => by rw [← image_preimage_eq s hf, ← image_preimage_eq t hf, eq]
fun eq => eq ▸ rfl
#align set.preimage_eq_preimage Set.preimage_eq_preimage
theorem image_inter_preimage (f : α → β) (s : Set α) (t : Set β) :
f '' (s ∩ f ⁻¹' t) = f '' s ∩ t := by
apply Subset.antisymm
· calc
f '' (s ∩ f ⁻¹' t) ⊆ f '' s ∩ f '' (f ⁻¹' t) := image_inter_subset _ _ _
_ ⊆ f '' s ∩ t := inter_subset_inter_right _ (image_preimage_subset f t)
· rintro _ ⟨⟨x, h', rfl⟩, h⟩
exact ⟨x, ⟨h', h⟩, rfl⟩
#align set.image_inter_preimage Set.image_inter_preimage
theorem image_preimage_inter (f : α → β) (s : Set α) (t : Set β) :
f '' (f ⁻¹' t ∩ s) = t ∩ f '' s := by simp only [inter_comm, image_inter_preimage]
#align set.image_preimage_inter Set.image_preimage_inter
@[simp]
theorem image_inter_nonempty_iff {f : α → β} {s : Set α} {t : Set β} :
(f '' s ∩ t).Nonempty ↔ (s ∩ f ⁻¹' t).Nonempty := by
rw [← image_inter_preimage, nonempty_image_iff]
#align set.image_inter_nonempty_iff Set.image_inter_nonempty_iff
theorem image_diff_preimage {f : α → β} {s : Set α} {t : Set β} : f '' (s \ f ⁻¹' t) = f '' s \ t :=
by simp_rw [diff_eq, ← preimage_compl, image_inter_preimage]
#align set.image_diff_preimage Set.image_diff_preimage
theorem compl_image : image (compl : Set α → Set α) = preimage compl :=
image_eq_preimage_of_inverse compl_compl compl_compl
#align set.compl_image Set.compl_image
theorem compl_image_set_of {p : Set α → Prop} : compl '' { s | p s } = { s | p sᶜ } :=
congr_fun compl_image p
#align set.compl_image_set_of Set.compl_image_set_of
theorem inter_preimage_subset (s : Set α) (t : Set β) (f : α → β) :
s ∩ f ⁻¹' t ⊆ f ⁻¹' (f '' s ∩ t) := fun _ h => ⟨mem_image_of_mem _ h.left, h.right⟩
#align set.inter_preimage_subset Set.inter_preimage_subset
theorem union_preimage_subset (s : Set α) (t : Set β) (f : α → β) :
s ∪ f ⁻¹' t ⊆ f ⁻¹' (f '' s ∪ t) := fun _ h =>
Or.elim h (fun l => Or.inl <| mem_image_of_mem _ l) fun r => Or.inr r
#align set.union_preimage_subset Set.union_preimage_subset
theorem subset_image_union (f : α → β) (s : Set α) (t : Set β) : f '' (s ∪ f ⁻¹' t) ⊆ f '' s ∪ t :=
image_subset_iff.2 (union_preimage_subset _ _ _)
#align set.subset_image_union Set.subset_image_union
theorem preimage_subset_iff {A : Set α} {B : Set β} {f : α → β} :
f ⁻¹' B ⊆ A ↔ ∀ a : α, f a ∈ B → a ∈ A :=
Iff.rfl
#align set.preimage_subset_iff Set.preimage_subset_iff
theorem image_eq_image {f : α → β} (hf : Injective f) : f '' s = f '' t ↔ s = t :=
Iff.symm <|
(Iff.intro fun eq => eq ▸ rfl) fun eq => by
rw [← preimage_image_eq s hf, ← preimage_image_eq t hf, eq]
#align set.image_eq_image Set.image_eq_image
theorem image_subset_image_iff {f : α → β} (hf : Injective f) : f '' s ⊆ f '' t ↔ s ⊆ t := by
refine' Iff.symm <| (Iff.intro (image_subset f)) fun h => _
rw [← preimage_image_eq s hf, ← preimage_image_eq t hf]
exact preimage_mono h
#align set.image_subset_image_iff Set.image_subset_image_iff
theorem prod_quotient_preimage_eq_image [s : Setoid α] (g : Quotient s → β) {h : α → β}
(Hh : h = g ∘ Quotient.mk'') (r : Set (β × β)) :
{ x : Quotient s × Quotient s | (g x.1, g x.2) ∈ r } =
(fun a : α × α => (⟦a.1⟧, ⟦a.2⟧)) '' ((fun a : α × α => (h a.1, h a.2)) ⁻¹' r) :=
Hh.symm ▸
Set.ext fun ⟨a₁, a₂⟩ =>
⟨Quot.induction_on₂ a₁ a₂ fun a₁ a₂ h => ⟨(a₁, a₂), h, rfl⟩, fun ⟨⟨b₁, b₂⟩, h₁, h₂⟩ =>
show (g a₁, g a₂) ∈ r from
have h₃ : ⟦b₁⟧ = a₁ ∧ ⟦b₂⟧ = a₂ := Prod.ext_iff.1 h₂
h₃.1 ▸ h₃.2 ▸ h₁⟩
#align set.prod_quotient_preimage_eq_image Set.prod_quotient_preimage_eq_image
theorem exists_image_iff (f : α → β) (x : Set α) (P : β → Prop) :
(∃ a : f '' x, P a) ↔ ∃ a : x, P (f a) :=
⟨fun ⟨a, h⟩ => ⟨⟨_, a.prop.choose_spec.1⟩, a.prop.choose_spec.2.symm ▸ h⟩, fun ⟨a, h⟩ =>
⟨⟨_, _, a.prop, rfl⟩, h⟩⟩
#align set.exists_image_iff Set.exists_image_iff
/-- Restriction of `f` to `s` factors through `s.imageFactorization f : s → f '' s`. -/
def imageFactorization (f : α → β) (s : Set α) : s → f '' s := fun p =>
⟨f p.1, mem_image_of_mem f p.2⟩
#align set.image_factorization Set.imageFactorization
theorem imageFactorization_eq {f : α → β} {s : Set α} :
Subtype.val ∘ imageFactorization f s = f ∘ Subtype.val :=
funext fun _ => rfl
#align set.image_factorization_eq Set.imageFactorization_eq
theorem surjective_onto_image {f : α → β} {s : Set α} : Surjective (imageFactorization f s) :=
fun ⟨_, ⟨a, ha, rfl⟩⟩ => ⟨⟨a, ha⟩, rfl⟩
#align set.surjective_onto_image Set.surjective_onto_image
/-- If the only elements outside `s` are those left fixed by `σ`, then mapping by `σ` has no effect.
-/
theorem image_perm {s : Set α} {σ : Equiv.Perm α} (hs : { a : α | σ a ≠ a } ⊆ s) : σ '' s = s := by
ext i
obtain hi | hi := eq_or_ne (σ i) i
· refine' ⟨_, fun h => ⟨i, h, hi⟩⟩
|
rintro ⟨j, hj, h⟩
|
/-- If the only elements outside `s` are those left fixed by `σ`, then mapping by `σ` has no effect.
-/
theorem image_perm {s : Set α} {σ : Equiv.Perm α} (hs : { a : α | σ a ≠ a } ⊆ s) : σ '' s = s := by
ext i
obtain hi | hi := eq_or_ne (σ i) i
· refine' ⟨_, fun h => ⟨i, h, hi⟩⟩
|
Mathlib.Data.Set.Image.635_0.IJFiTzmYGOCpPSd
|
/-- If the only elements outside `s` are those left fixed by `σ`, then mapping by `σ` has no effect.
-/
theorem image_perm {s : Set α} {σ : Equiv.Perm α} (hs : { a : α | σ a ≠ a } ⊆ s) : σ '' s = s
|
Mathlib_Data_Set_Image
|
case h.inl.intro.intro
α : Type u_1
β : Type u_2
γ : Type u_3
ι : Sort u_4
ι' : Sort u_5
f : α → β
s✝ t s : Set α
σ : Equiv.Perm α
hs : {a | σ a ≠ a} ⊆ s
i : α
hi : σ i = i
j : α
hj : j ∈ s
h : σ j = i
⊢ i ∈ s
|
/-
Copyright (c) 2014 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Leonardo de Moura
-/
import Mathlib.Data.Set.Basic
#align_import data.set.image from "leanprover-community/mathlib"@"001ffdc42920050657fd45bd2b8bfbec8eaaeb29"
/-!
# Images and preimages of sets
## Main definitions
* `preimage f t : Set α` : the preimage f⁻¹(t) (written `f ⁻¹' t` in Lean) of a subset of β.
* `range f : Set β` : the image of `univ` under `f`.
Also works for `{p : Prop} (f : p → α)` (unlike `image`)
## Notation
* `f ⁻¹' t` for `Set.preimage f t`
* `f '' s` for `Set.image f s`
## Tags
set, sets, image, preimage, pre-image, range
-/
set_option autoImplicit true
universe u v
open Function Set
namespace Set
variable {α β γ : Type*} {ι ι' : Sort*}
/-! ### Inverse image -/
/-- The preimage of `s : Set β` by `f : α → β`, written `f ⁻¹' s`,
is the set of `x : α` such that `f x ∈ s`. -/
def preimage {α : Type u} {β : Type v} (f : α → β) (s : Set β) : Set α :=
{ x | f x ∈ s }
#align set.preimage Set.preimage
/-- `f ⁻¹' t` denotes the preimage of `t : Set β` under the function `f : α → β`. -/
infixl:80 " ⁻¹' " => preimage
section Preimage
variable {f : α → β} {g : β → γ}
@[simp]
theorem preimage_empty : f ⁻¹' ∅ = ∅ :=
rfl
#align set.preimage_empty Set.preimage_empty
@[simp, mfld_simps]
theorem mem_preimage {s : Set β} {a : α} : a ∈ f ⁻¹' s ↔ f a ∈ s :=
Iff.rfl
#align set.mem_preimage Set.mem_preimage
theorem preimage_congr {f g : α → β} {s : Set β} (h : ∀ x : α, f x = g x) : f ⁻¹' s = g ⁻¹' s := by
congr with x
simp [h]
#align set.preimage_congr Set.preimage_congr
@[gcongr]
theorem preimage_mono {s t : Set β} (h : s ⊆ t) : f ⁻¹' s ⊆ f ⁻¹' t := fun _ hx => h hx
#align set.preimage_mono Set.preimage_mono
@[simp, mfld_simps]
theorem preimage_univ : f ⁻¹' univ = univ :=
rfl
#align set.preimage_univ Set.preimage_univ
theorem subset_preimage_univ {s : Set α} : s ⊆ f ⁻¹' univ :=
subset_univ _
#align set.subset_preimage_univ Set.subset_preimage_univ
@[simp, mfld_simps]
theorem preimage_inter {s t : Set β} : f ⁻¹' (s ∩ t) = f ⁻¹' s ∩ f ⁻¹' t :=
rfl
#align set.preimage_inter Set.preimage_inter
@[simp]
theorem preimage_union {s t : Set β} : f ⁻¹' (s ∪ t) = f ⁻¹' s ∪ f ⁻¹' t :=
rfl
#align set.preimage_union Set.preimage_union
@[simp]
theorem preimage_compl {s : Set β} : f ⁻¹' sᶜ = (f ⁻¹' s)ᶜ :=
rfl
#align set.preimage_compl Set.preimage_compl
@[simp]
theorem preimage_diff (f : α → β) (s t : Set β) : f ⁻¹' (s \ t) = f ⁻¹' s \ f ⁻¹' t :=
rfl
#align set.preimage_diff Set.preimage_diff
@[simp]
lemma preimage_symmDiff {f : α → β} (s t : Set β) : f ⁻¹' (s ∆ t) = (f ⁻¹' s) ∆ (f ⁻¹' t) :=
rfl
#align set.preimage_symm_diff Set.preimage_symmDiff
@[simp]
theorem preimage_ite (f : α → β) (s t₁ t₂ : Set β) :
f ⁻¹' s.ite t₁ t₂ = (f ⁻¹' s).ite (f ⁻¹' t₁) (f ⁻¹' t₂) :=
rfl
#align set.preimage_ite Set.preimage_ite
@[simp]
theorem preimage_setOf_eq {p : α → Prop} {f : β → α} : f ⁻¹' { a | p a } = { a | p (f a) } :=
rfl
#align set.preimage_set_of_eq Set.preimage_setOf_eq
@[simp]
theorem preimage_id_eq : preimage (id : α → α) = id :=
rfl
#align set.preimage_id_eq Set.preimage_id_eq
@[mfld_simps]
theorem preimage_id {s : Set α} : id ⁻¹' s = s :=
rfl
#align set.preimage_id Set.preimage_id
@[simp, mfld_simps]
theorem preimage_id' {s : Set α} : (fun x => x) ⁻¹' s = s :=
rfl
#align set.preimage_id' Set.preimage_id'
@[simp]
theorem preimage_const_of_mem {b : β} {s : Set β} (h : b ∈ s) : (fun _ : α => b) ⁻¹' s = univ :=
eq_univ_of_forall fun _ => h
#align set.preimage_const_of_mem Set.preimage_const_of_mem
@[simp]
theorem preimage_const_of_not_mem {b : β} {s : Set β} (h : b ∉ s) : (fun _ : α => b) ⁻¹' s = ∅ :=
eq_empty_of_subset_empty fun _ hx => h hx
#align set.preimage_const_of_not_mem Set.preimage_const_of_not_mem
theorem preimage_const (b : β) (s : Set β) [Decidable (b ∈ s)] :
(fun _ : α => b) ⁻¹' s = if b ∈ s then univ else ∅ := by
split_ifs with hb
exacts [preimage_const_of_mem hb, preimage_const_of_not_mem hb]
#align set.preimage_const Set.preimage_const
/-- If preimage of each singleton under `f : α → β` is either empty or the whole type,
then `f` is a constant. -/
lemma exists_eq_const_of_preimage_singleton [Nonempty β] {f : α → β}
(hf : ∀ b : β, f ⁻¹' {b} = ∅ ∨ f ⁻¹' {b} = univ) : ∃ b, f = const α b := by
rcases em (∃ b, f ⁻¹' {b} = univ) with ⟨b, hb⟩ | hf'
· exact ⟨b, funext fun x ↦ eq_univ_iff_forall.1 hb x⟩
· have : ∀ x b, f x ≠ b := fun x b ↦
eq_empty_iff_forall_not_mem.1 ((hf b).resolve_right fun h ↦ hf' ⟨b, h⟩) x
exact ⟨Classical.arbitrary β, funext fun x ↦ absurd rfl (this x _)⟩
theorem preimage_comp {s : Set γ} : g ∘ f ⁻¹' s = f ⁻¹' (g ⁻¹' s) :=
rfl
#align set.preimage_comp Set.preimage_comp
theorem preimage_comp_eq : preimage (g ∘ f) = preimage f ∘ preimage g :=
rfl
#align set.preimage_comp_eq Set.preimage_comp_eq
theorem preimage_iterate_eq {f : α → α} {n : ℕ} : Set.preimage f^[n] = (Set.preimage f)^[n] := by
induction' n with n ih; · simp
rw [iterate_succ, iterate_succ', preimage_comp_eq, ih]
#align set.preimage_iterate_eq Set.preimage_iterate_eq
theorem preimage_preimage {g : β → γ} {f : α → β} {s : Set γ} :
f ⁻¹' (g ⁻¹' s) = (fun x => g (f x)) ⁻¹' s :=
preimage_comp.symm
#align set.preimage_preimage Set.preimage_preimage
theorem eq_preimage_subtype_val_iff {p : α → Prop} {s : Set (Subtype p)} {t : Set α} :
s = Subtype.val ⁻¹' t ↔ ∀ (x) (h : p x), (⟨x, h⟩ : Subtype p) ∈ s ↔ x ∈ t :=
⟨fun s_eq x h => by
rw [s_eq]
simp, fun h => ext fun ⟨x, hx⟩ => by simp [h]⟩
#align set.eq_preimage_subtype_val_iff Set.eq_preimage_subtype_val_iff
theorem nonempty_of_nonempty_preimage {s : Set β} {f : α → β} (hf : (f ⁻¹' s).Nonempty) :
s.Nonempty :=
let ⟨x, hx⟩ := hf
⟨f x, hx⟩
#align set.nonempty_of_nonempty_preimage Set.nonempty_of_nonempty_preimage
@[simp] theorem preimage_singleton_true (p : α → Prop) : p ⁻¹' {True} = {a | p a} := by ext; simp
#align set.preimage_singleton_true Set.preimage_singleton_true
@[simp] theorem preimage_singleton_false (p : α → Prop) : p ⁻¹' {False} = {a | ¬p a} := by ext; simp
#align set.preimage_singleton_false Set.preimage_singleton_false
theorem preimage_subtype_coe_eq_compl {s u v : Set α} (hsuv : s ⊆ u ∪ v)
(H : s ∩ (u ∩ v) = ∅) : ((↑) : s → α) ⁻¹' u = ((↑) ⁻¹' v)ᶜ := by
ext ⟨x, x_in_s⟩
constructor
· intro x_in_u x_in_v
exact eq_empty_iff_forall_not_mem.mp H x ⟨x_in_s, ⟨x_in_u, x_in_v⟩⟩
· intro hx
exact Or.elim (hsuv x_in_s) id fun hx' => hx.elim hx'
#align set.preimage_subtype_coe_eq_compl Set.preimage_subtype_coe_eq_compl
end Preimage
/-! ### Image of a set under a function -/
section Image
variable {f : α → β} {s t : Set α}
-- Porting note: `Set.image` is already defined in `Init.Set`
#align set.image Set.image
/-- `f '' s` denotes the image of `s : Set α` under the function `f : α → β`. -/
infixl:80 " '' " => image
theorem mem_image_iff_bex {f : α → β} {s : Set α} {y : β} :
y ∈ f '' s ↔ ∃ (x : _) (_ : x ∈ s), f x = y :=
bex_def.symm
#align set.mem_image_iff_bex Set.mem_image_iff_bex
@[simp]
theorem mem_image (f : α → β) (s : Set α) (y : β) : y ∈ f '' s ↔ ∃ x ∈ s, f x = y :=
Iff.rfl
#align set.mem_image Set.mem_image
theorem image_eta (f : α → β) : f '' s = (fun x => f x) '' s :=
rfl
#align set.image_eta Set.image_eta
@[mfld_simps]
theorem mem_image_of_mem (f : α → β) {x : α} {a : Set α} (h : x ∈ a) : f x ∈ f '' a :=
⟨_, h, rfl⟩
#align set.mem_image_of_mem Set.mem_image_of_mem
theorem _root_.Function.Injective.mem_set_image {f : α → β} (hf : Injective f) {s : Set α} {a : α} :
f a ∈ f '' s ↔ a ∈ s :=
⟨fun ⟨_, hb, Eq⟩ => hf Eq ▸ hb, mem_image_of_mem f⟩
#align function.injective.mem_set_image Function.Injective.mem_set_image
theorem ball_image_iff {f : α → β} {s : Set α} {p : β → Prop} :
(∀ y ∈ f '' s, p y) ↔ ∀ x ∈ s, p (f x) := by simp
#align set.ball_image_iff Set.ball_image_iff
theorem ball_image_of_ball {f : α → β} {s : Set α} {p : β → Prop} (h : ∀ x ∈ s, p (f x)) :
∀ y ∈ f '' s, p y :=
ball_image_iff.2 h
#align set.ball_image_of_ball Set.ball_image_of_ball
theorem bex_image_iff {f : α → β} {s : Set α} {p : β → Prop} :
(∃ y ∈ f '' s, p y) ↔ ∃ x ∈ s, p (f x) := by simp
#align set.bex_image_iff Set.bex_image_iff
theorem mem_image_elim {f : α → β} {s : Set α} {C : β → Prop} (h : ∀ x : α, x ∈ s → C (f x)) :
∀ {y : β}, y ∈ f '' s → C y
| _, ⟨a, a_in, rfl⟩ => h a a_in
#align set.mem_image_elim Set.mem_image_elim
theorem mem_image_elim_on {f : α → β} {s : Set α} {C : β → Prop} {y : β} (h_y : y ∈ f '' s)
(h : ∀ x : α, x ∈ s → C (f x)) : C y :=
mem_image_elim h h_y
#align set.mem_image_elim_on Set.mem_image_elim_on
-- Porting note: used to be `safe`
@[congr]
theorem image_congr {f g : α → β} {s : Set α} (h : ∀ a ∈ s, f a = g a) : f '' s = g '' s := by
ext x
rw [mem_image, mem_image]
exact {
mp := by
rintro ⟨a, ha1, ha2⟩
exact ⟨a, ⟨ha1, (h a ha1) ▸ ha2⟩⟩,
mpr := by
rintro ⟨a, ha1, ha2⟩
exact ⟨a, ⟨ha1, (h a ha1) ▸ ha2⟩⟩
}
-- safe [ext_iff, iff_def]
#align set.image_congr Set.image_congr
/-- A common special case of `image_congr` -/
theorem image_congr' {f g : α → β} {s : Set α} (h : ∀ x : α, f x = g x) : f '' s = g '' s :=
image_congr fun x _ => h x
#align set.image_congr' Set.image_congr'
@[gcongr]
lemma image_mono (h : s ⊆ t) : f '' s ⊆ f '' t := by
rintro - ⟨a, ha, rfl⟩; exact mem_image_of_mem f (h ha)
theorem image_comp (f : β → γ) (g : α → β) (a : Set α) : f ∘ g '' a = f '' (g '' a) :=
Subset.antisymm (ball_image_of_ball fun _ ha => mem_image_of_mem _ <| mem_image_of_mem _ ha)
(ball_image_of_ball <| ball_image_of_ball fun _ ha => mem_image_of_mem _ ha)
#align set.image_comp Set.image_comp
theorem image_comp_eq {g : β → γ} : image (g ∘ f) = image g ∘ image f := by ext; simp
/-- A variant of `image_comp`, useful for rewriting -/
theorem image_image (g : β → γ) (f : α → β) (s : Set α) : g '' (f '' s) = (fun x => g (f x)) '' s :=
(image_comp g f s).symm
#align set.image_image Set.image_image
theorem image_comm {β'} {f : β → γ} {g : α → β} {f' : α → β'} {g' : β' → γ}
(h_comm : ∀ a, f (g a) = g' (f' a)) : (s.image g).image f = (s.image f').image g' := by
simp_rw [image_image, h_comm]
#align set.image_comm Set.image_comm
theorem _root_.Function.Semiconj.set_image {f : α → β} {ga : α → α} {gb : β → β}
(h : Function.Semiconj f ga gb) : Function.Semiconj (image f) (image ga) (image gb) := fun _ =>
image_comm h
#align function.semiconj.set_image Function.Semiconj.set_image
theorem _root_.Function.Commute.set_image {f g : α → α} (h : Function.Commute f g) :
Function.Commute (image f) (image g) :=
Function.Semiconj.set_image h
#align function.commute.set_image Function.Commute.set_image
/-- Image is monotone with respect to `⊆`. See `Set.monotone_image` for the statement in
terms of `≤`. -/
@[gcongr]
theorem image_subset {a b : Set α} (f : α → β) (h : a ⊆ b) : f '' a ⊆ f '' b := by
simp only [subset_def, mem_image]
exact fun x => fun ⟨w, h1, h2⟩ => ⟨w, h h1, h2⟩
#align set.image_subset Set.image_subset
/-- `Set.image` is monotone. See `Set.image_subset` for the statement in terms of `⊆`. -/
lemma monotone_image {f : α → β} : Monotone (image f) := fun _ _ => image_subset _
#align set.monotone_image Set.monotone_image
theorem image_union (f : α → β) (s t : Set α) : f '' (s ∪ t) = f '' s ∪ f '' t :=
ext fun x =>
⟨by rintro ⟨a, h | h, rfl⟩ <;> [left; right] <;> exact ⟨_, h, rfl⟩, by
rintro (⟨a, h, rfl⟩ | ⟨a, h, rfl⟩) <;> refine' ⟨_, _, rfl⟩ <;> [left; right] <;> exact h⟩
#align set.image_union Set.image_union
@[simp]
theorem image_empty (f : α → β) : f '' ∅ = ∅ := by
ext
simp
#align set.image_empty Set.image_empty
theorem image_inter_subset (f : α → β) (s t : Set α) : f '' (s ∩ t) ⊆ f '' s ∩ f '' t :=
subset_inter (image_subset _ <| inter_subset_left _ _) (image_subset _ <| inter_subset_right _ _)
#align set.image_inter_subset Set.image_inter_subset
theorem image_inter_on {f : α → β} {s t : Set α} (h : ∀ x ∈ t, ∀ y ∈ s, f x = f y → x = y) :
f '' (s ∩ t) = f '' s ∩ f '' t :=
(image_inter_subset _ _ _).antisymm
fun b ⟨⟨a₁, ha₁, h₁⟩, ⟨a₂, ha₂, h₂⟩⟩ ↦
have : a₂ = a₁ := h _ ha₂ _ ha₁ (by simp [*])
⟨a₁, ⟨ha₁, this ▸ ha₂⟩, h₁⟩
#align set.image_inter_on Set.image_inter_on
theorem image_inter {f : α → β} {s t : Set α} (H : Injective f) : f '' (s ∩ t) = f '' s ∩ f '' t :=
image_inter_on fun _ _ _ _ h => H h
#align set.image_inter Set.image_inter
theorem image_univ_of_surjective {ι : Type*} {f : ι → β} (H : Surjective f) : f '' univ = univ :=
eq_univ_of_forall <| by simpa [image]
#align set.image_univ_of_surjective Set.image_univ_of_surjective
@[simp]
theorem image_singleton {f : α → β} {a : α} : f '' {a} = {f a} := by
ext
simp [image, eq_comm]
#align set.image_singleton Set.image_singleton
@[simp]
theorem Nonempty.image_const {s : Set α} (hs : s.Nonempty) (a : β) : (fun _ => a) '' s = {a} :=
ext fun _ =>
⟨fun ⟨_, _, h⟩ => h ▸ mem_singleton _, fun h =>
(eq_of_mem_singleton h).symm ▸ hs.imp fun _ hy => ⟨hy, rfl⟩⟩
#align set.nonempty.image_const Set.Nonempty.image_const
@[simp, mfld_simps]
theorem image_eq_empty {α β} {f : α → β} {s : Set α} : f '' s = ∅ ↔ s = ∅ := by
simp only [eq_empty_iff_forall_not_mem]
exact ⟨fun H a ha => H _ ⟨_, ha, rfl⟩, fun H b ⟨_, ha, _⟩ => H _ ha⟩
#align set.image_eq_empty Set.image_eq_empty
-- Porting note: `compl` is already defined in `Init.Set`
theorem preimage_compl_eq_image_compl [BooleanAlgebra α] (S : Set α) :
HasCompl.compl ⁻¹' S = HasCompl.compl '' S :=
Set.ext fun x =>
⟨fun h => ⟨xᶜ, h, compl_compl x⟩, fun h =>
Exists.elim h fun _ hy => (compl_eq_comm.mp hy.2).symm.subst hy.1⟩
#align set.preimage_compl_eq_image_compl Set.preimage_compl_eq_image_compl
theorem mem_compl_image [BooleanAlgebra α] (t : α) (S : Set α) :
t ∈ HasCompl.compl '' S ↔ tᶜ ∈ S := by
simp [← preimage_compl_eq_image_compl]
#align set.mem_compl_image Set.mem_compl_image
@[simp]
theorem image_id_eq : image (id : α → α) = id := by ext; simp
/-- A variant of `image_id` -/
@[simp]
theorem image_id' (s : Set α) : (fun x => x) '' s = s := by
ext
simp
#align set.image_id' Set.image_id'
theorem image_id (s : Set α) : id '' s = s := by simp
#align set.image_id Set.image_id
lemma image_iterate_eq {f : α → α} {n : ℕ} : image (f^[n]) = (image f)^[n] := by
induction' n with n ih; · simp
rw [iterate_succ', iterate_succ',← ih, image_comp_eq]
theorem compl_compl_image [BooleanAlgebra α] (S : Set α) :
HasCompl.compl '' (HasCompl.compl '' S) = S := by
rw [← image_comp, compl_comp_compl, image_id]
#align set.compl_compl_image Set.compl_compl_image
theorem image_insert_eq {f : α → β} {a : α} {s : Set α} :
f '' insert a s = insert (f a) (f '' s) := by
ext
simp [and_or_left, exists_or, eq_comm, or_comm, and_comm]
#align set.image_insert_eq Set.image_insert_eq
theorem image_pair (f : α → β) (a b : α) : f '' {a, b} = {f a, f b} := by
simp only [image_insert_eq, image_singleton]
#align set.image_pair Set.image_pair
theorem image_subset_preimage_of_inverse {f : α → β} {g : β → α} (I : LeftInverse g f) (s : Set α) :
f '' s ⊆ g ⁻¹' s := fun _ ⟨a, h, e⟩ => e ▸ ((I a).symm ▸ h : g (f a) ∈ s)
#align set.image_subset_preimage_of_inverse Set.image_subset_preimage_of_inverse
theorem preimage_subset_image_of_inverse {f : α → β} {g : β → α} (I : LeftInverse g f) (s : Set β) :
f ⁻¹' s ⊆ g '' s := fun b h => ⟨f b, h, I b⟩
#align set.preimage_subset_image_of_inverse Set.preimage_subset_image_of_inverse
theorem image_eq_preimage_of_inverse {f : α → β} {g : β → α} (h₁ : LeftInverse g f)
(h₂ : RightInverse g f) : image f = preimage g :=
funext fun s =>
Subset.antisymm (image_subset_preimage_of_inverse h₁ s) (preimage_subset_image_of_inverse h₂ s)
#align set.image_eq_preimage_of_inverse Set.image_eq_preimage_of_inverse
theorem mem_image_iff_of_inverse {f : α → β} {g : β → α} {b : β} {s : Set α} (h₁ : LeftInverse g f)
(h₂ : RightInverse g f) : b ∈ f '' s ↔ g b ∈ s := by
rw [image_eq_preimage_of_inverse h₁ h₂]; rfl
#align set.mem_image_iff_of_inverse Set.mem_image_iff_of_inverse
theorem image_compl_subset {f : α → β} {s : Set α} (H : Injective f) : f '' sᶜ ⊆ (f '' s)ᶜ :=
Disjoint.subset_compl_left <| by simp [disjoint_iff_inf_le, ← image_inter H]
#align set.image_compl_subset Set.image_compl_subset
theorem subset_image_compl {f : α → β} {s : Set α} (H : Surjective f) : (f '' s)ᶜ ⊆ f '' sᶜ :=
compl_subset_iff_union.2 <| by
rw [← image_union]
simp [image_univ_of_surjective H]
#align set.subset_image_compl Set.subset_image_compl
theorem image_compl_eq {f : α → β} {s : Set α} (H : Bijective f) : f '' sᶜ = (f '' s)ᶜ :=
Subset.antisymm (image_compl_subset H.1) (subset_image_compl H.2)
#align set.image_compl_eq Set.image_compl_eq
theorem subset_image_diff (f : α → β) (s t : Set α) : f '' s \ f '' t ⊆ f '' (s \ t) := by
rw [diff_subset_iff, ← image_union, union_diff_self]
exact image_subset f (subset_union_right t s)
#align set.subset_image_diff Set.subset_image_diff
theorem subset_image_symmDiff : (f '' s) ∆ (f '' t) ⊆ f '' s ∆ t :=
(union_subset_union (subset_image_diff _ _ _) <| subset_image_diff _ _ _).trans
(superset_of_eq (image_union _ _ _))
#align set.subset_image_symm_diff Set.subset_image_symmDiff
theorem image_diff {f : α → β} (hf : Injective f) (s t : Set α) : f '' (s \ t) = f '' s \ f '' t :=
Subset.antisymm
(Subset.trans (image_inter_subset _ _ _) <| inter_subset_inter_right _ <| image_compl_subset hf)
(subset_image_diff f s t)
#align set.image_diff Set.image_diff
theorem image_symmDiff (hf : Injective f) (s t : Set α) : f '' s ∆ t = (f '' s) ∆ (f '' t) := by
simp_rw [Set.symmDiff_def, image_union, image_diff hf]
#align set.image_symm_diff Set.image_symmDiff
theorem Nonempty.image (f : α → β) {s : Set α} : s.Nonempty → (f '' s).Nonempty
| ⟨x, hx⟩ => ⟨f x, mem_image_of_mem f hx⟩
#align set.nonempty.image Set.Nonempty.image
theorem Nonempty.of_image {f : α → β} {s : Set α} : (f '' s).Nonempty → s.Nonempty
| ⟨_, x, hx, _⟩ => ⟨x, hx⟩
#align set.nonempty.of_image Set.Nonempty.of_image
@[simp]
theorem nonempty_image_iff {f : α → β} {s : Set α} : (f '' s).Nonempty ↔ s.Nonempty :=
⟨Nonempty.of_image, fun h => h.image f⟩
#align set.nonempty_image_iff Set.nonempty_image_iff
theorem Nonempty.preimage {s : Set β} (hs : s.Nonempty) {f : α → β} (hf : Surjective f) :
(f ⁻¹' s).Nonempty :=
let ⟨y, hy⟩ := hs
let ⟨x, hx⟩ := hf y
⟨x, mem_preimage.2 <| hx.symm ▸ hy⟩
#align set.nonempty.preimage Set.Nonempty.preimage
instance (f : α → β) (s : Set α) [Nonempty s] : Nonempty (f '' s) :=
(Set.Nonempty.image f nonempty_of_nonempty_subtype).to_subtype
/-- image and preimage are a Galois connection -/
@[simp]
theorem image_subset_iff {s : Set α} {t : Set β} {f : α → β} : f '' s ⊆ t ↔ s ⊆ f ⁻¹' t :=
ball_image_iff
#align set.image_subset_iff Set.image_subset_iff
theorem image_preimage_subset (f : α → β) (s : Set β) : f '' (f ⁻¹' s) ⊆ s :=
image_subset_iff.2 Subset.rfl
#align set.image_preimage_subset Set.image_preimage_subset
theorem subset_preimage_image (f : α → β) (s : Set α) : s ⊆ f ⁻¹' (f '' s) := fun _ =>
mem_image_of_mem f
#align set.subset_preimage_image Set.subset_preimage_image
@[simp]
theorem preimage_image_eq {f : α → β} (s : Set α) (h : Injective f) : f ⁻¹' (f '' s) = s :=
Subset.antisymm (fun _ ⟨_, hy, e⟩ => h e ▸ hy) (subset_preimage_image f s)
#align set.preimage_image_eq Set.preimage_image_eq
@[simp]
theorem image_preimage_eq {f : α → β} (s : Set β) (h : Surjective f) : f '' (f ⁻¹' s) = s :=
Subset.antisymm (image_preimage_subset f s) fun x hx =>
let ⟨y, e⟩ := h x
⟨y, (e.symm ▸ hx : f y ∈ s), e⟩
#align set.image_preimage_eq Set.image_preimage_eq
@[simp]
theorem preimage_eq_preimage {f : β → α} (hf : Surjective f) : f ⁻¹' s = f ⁻¹' t ↔ s = t :=
Iff.intro
fun eq => by rw [← image_preimage_eq s hf, ← image_preimage_eq t hf, eq]
fun eq => eq ▸ rfl
#align set.preimage_eq_preimage Set.preimage_eq_preimage
theorem image_inter_preimage (f : α → β) (s : Set α) (t : Set β) :
f '' (s ∩ f ⁻¹' t) = f '' s ∩ t := by
apply Subset.antisymm
· calc
f '' (s ∩ f ⁻¹' t) ⊆ f '' s ∩ f '' (f ⁻¹' t) := image_inter_subset _ _ _
_ ⊆ f '' s ∩ t := inter_subset_inter_right _ (image_preimage_subset f t)
· rintro _ ⟨⟨x, h', rfl⟩, h⟩
exact ⟨x, ⟨h', h⟩, rfl⟩
#align set.image_inter_preimage Set.image_inter_preimage
theorem image_preimage_inter (f : α → β) (s : Set α) (t : Set β) :
f '' (f ⁻¹' t ∩ s) = t ∩ f '' s := by simp only [inter_comm, image_inter_preimage]
#align set.image_preimage_inter Set.image_preimage_inter
@[simp]
theorem image_inter_nonempty_iff {f : α → β} {s : Set α} {t : Set β} :
(f '' s ∩ t).Nonempty ↔ (s ∩ f ⁻¹' t).Nonempty := by
rw [← image_inter_preimage, nonempty_image_iff]
#align set.image_inter_nonempty_iff Set.image_inter_nonempty_iff
theorem image_diff_preimage {f : α → β} {s : Set α} {t : Set β} : f '' (s \ f ⁻¹' t) = f '' s \ t :=
by simp_rw [diff_eq, ← preimage_compl, image_inter_preimage]
#align set.image_diff_preimage Set.image_diff_preimage
theorem compl_image : image (compl : Set α → Set α) = preimage compl :=
image_eq_preimage_of_inverse compl_compl compl_compl
#align set.compl_image Set.compl_image
theorem compl_image_set_of {p : Set α → Prop} : compl '' { s | p s } = { s | p sᶜ } :=
congr_fun compl_image p
#align set.compl_image_set_of Set.compl_image_set_of
theorem inter_preimage_subset (s : Set α) (t : Set β) (f : α → β) :
s ∩ f ⁻¹' t ⊆ f ⁻¹' (f '' s ∩ t) := fun _ h => ⟨mem_image_of_mem _ h.left, h.right⟩
#align set.inter_preimage_subset Set.inter_preimage_subset
theorem union_preimage_subset (s : Set α) (t : Set β) (f : α → β) :
s ∪ f ⁻¹' t ⊆ f ⁻¹' (f '' s ∪ t) := fun _ h =>
Or.elim h (fun l => Or.inl <| mem_image_of_mem _ l) fun r => Or.inr r
#align set.union_preimage_subset Set.union_preimage_subset
theorem subset_image_union (f : α → β) (s : Set α) (t : Set β) : f '' (s ∪ f ⁻¹' t) ⊆ f '' s ∪ t :=
image_subset_iff.2 (union_preimage_subset _ _ _)
#align set.subset_image_union Set.subset_image_union
theorem preimage_subset_iff {A : Set α} {B : Set β} {f : α → β} :
f ⁻¹' B ⊆ A ↔ ∀ a : α, f a ∈ B → a ∈ A :=
Iff.rfl
#align set.preimage_subset_iff Set.preimage_subset_iff
theorem image_eq_image {f : α → β} (hf : Injective f) : f '' s = f '' t ↔ s = t :=
Iff.symm <|
(Iff.intro fun eq => eq ▸ rfl) fun eq => by
rw [← preimage_image_eq s hf, ← preimage_image_eq t hf, eq]
#align set.image_eq_image Set.image_eq_image
theorem image_subset_image_iff {f : α → β} (hf : Injective f) : f '' s ⊆ f '' t ↔ s ⊆ t := by
refine' Iff.symm <| (Iff.intro (image_subset f)) fun h => _
rw [← preimage_image_eq s hf, ← preimage_image_eq t hf]
exact preimage_mono h
#align set.image_subset_image_iff Set.image_subset_image_iff
theorem prod_quotient_preimage_eq_image [s : Setoid α] (g : Quotient s → β) {h : α → β}
(Hh : h = g ∘ Quotient.mk'') (r : Set (β × β)) :
{ x : Quotient s × Quotient s | (g x.1, g x.2) ∈ r } =
(fun a : α × α => (⟦a.1⟧, ⟦a.2⟧)) '' ((fun a : α × α => (h a.1, h a.2)) ⁻¹' r) :=
Hh.symm ▸
Set.ext fun ⟨a₁, a₂⟩ =>
⟨Quot.induction_on₂ a₁ a₂ fun a₁ a₂ h => ⟨(a₁, a₂), h, rfl⟩, fun ⟨⟨b₁, b₂⟩, h₁, h₂⟩ =>
show (g a₁, g a₂) ∈ r from
have h₃ : ⟦b₁⟧ = a₁ ∧ ⟦b₂⟧ = a₂ := Prod.ext_iff.1 h₂
h₃.1 ▸ h₃.2 ▸ h₁⟩
#align set.prod_quotient_preimage_eq_image Set.prod_quotient_preimage_eq_image
theorem exists_image_iff (f : α → β) (x : Set α) (P : β → Prop) :
(∃ a : f '' x, P a) ↔ ∃ a : x, P (f a) :=
⟨fun ⟨a, h⟩ => ⟨⟨_, a.prop.choose_spec.1⟩, a.prop.choose_spec.2.symm ▸ h⟩, fun ⟨a, h⟩ =>
⟨⟨_, _, a.prop, rfl⟩, h⟩⟩
#align set.exists_image_iff Set.exists_image_iff
/-- Restriction of `f` to `s` factors through `s.imageFactorization f : s → f '' s`. -/
def imageFactorization (f : α → β) (s : Set α) : s → f '' s := fun p =>
⟨f p.1, mem_image_of_mem f p.2⟩
#align set.image_factorization Set.imageFactorization
theorem imageFactorization_eq {f : α → β} {s : Set α} :
Subtype.val ∘ imageFactorization f s = f ∘ Subtype.val :=
funext fun _ => rfl
#align set.image_factorization_eq Set.imageFactorization_eq
theorem surjective_onto_image {f : α → β} {s : Set α} : Surjective (imageFactorization f s) :=
fun ⟨_, ⟨a, ha, rfl⟩⟩ => ⟨⟨a, ha⟩, rfl⟩
#align set.surjective_onto_image Set.surjective_onto_image
/-- If the only elements outside `s` are those left fixed by `σ`, then mapping by `σ` has no effect.
-/
theorem image_perm {s : Set α} {σ : Equiv.Perm α} (hs : { a : α | σ a ≠ a } ⊆ s) : σ '' s = s := by
ext i
obtain hi | hi := eq_or_ne (σ i) i
· refine' ⟨_, fun h => ⟨i, h, hi⟩⟩
rintro ⟨j, hj, h⟩
|
rwa [σ.injective (hi.trans h.symm)]
|
/-- If the only elements outside `s` are those left fixed by `σ`, then mapping by `σ` has no effect.
-/
theorem image_perm {s : Set α} {σ : Equiv.Perm α} (hs : { a : α | σ a ≠ a } ⊆ s) : σ '' s = s := by
ext i
obtain hi | hi := eq_or_ne (σ i) i
· refine' ⟨_, fun h => ⟨i, h, hi⟩⟩
rintro ⟨j, hj, h⟩
|
Mathlib.Data.Set.Image.635_0.IJFiTzmYGOCpPSd
|
/-- If the only elements outside `s` are those left fixed by `σ`, then mapping by `σ` has no effect.
-/
theorem image_perm {s : Set α} {σ : Equiv.Perm α} (hs : { a : α | σ a ≠ a } ⊆ s) : σ '' s = s
|
Mathlib_Data_Set_Image
|
case h.inr
α : Type u_1
β : Type u_2
γ : Type u_3
ι : Sort u_4
ι' : Sort u_5
f : α → β
s✝ t s : Set α
σ : Equiv.Perm α
hs : {a | σ a ≠ a} ⊆ s
i : α
hi : σ i ≠ i
⊢ i ∈ ⇑σ '' s ↔ i ∈ s
|
/-
Copyright (c) 2014 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Leonardo de Moura
-/
import Mathlib.Data.Set.Basic
#align_import data.set.image from "leanprover-community/mathlib"@"001ffdc42920050657fd45bd2b8bfbec8eaaeb29"
/-!
# Images and preimages of sets
## Main definitions
* `preimage f t : Set α` : the preimage f⁻¹(t) (written `f ⁻¹' t` in Lean) of a subset of β.
* `range f : Set β` : the image of `univ` under `f`.
Also works for `{p : Prop} (f : p → α)` (unlike `image`)
## Notation
* `f ⁻¹' t` for `Set.preimage f t`
* `f '' s` for `Set.image f s`
## Tags
set, sets, image, preimage, pre-image, range
-/
set_option autoImplicit true
universe u v
open Function Set
namespace Set
variable {α β γ : Type*} {ι ι' : Sort*}
/-! ### Inverse image -/
/-- The preimage of `s : Set β` by `f : α → β`, written `f ⁻¹' s`,
is the set of `x : α` such that `f x ∈ s`. -/
def preimage {α : Type u} {β : Type v} (f : α → β) (s : Set β) : Set α :=
{ x | f x ∈ s }
#align set.preimage Set.preimage
/-- `f ⁻¹' t` denotes the preimage of `t : Set β` under the function `f : α → β`. -/
infixl:80 " ⁻¹' " => preimage
section Preimage
variable {f : α → β} {g : β → γ}
@[simp]
theorem preimage_empty : f ⁻¹' ∅ = ∅ :=
rfl
#align set.preimage_empty Set.preimage_empty
@[simp, mfld_simps]
theorem mem_preimage {s : Set β} {a : α} : a ∈ f ⁻¹' s ↔ f a ∈ s :=
Iff.rfl
#align set.mem_preimage Set.mem_preimage
theorem preimage_congr {f g : α → β} {s : Set β} (h : ∀ x : α, f x = g x) : f ⁻¹' s = g ⁻¹' s := by
congr with x
simp [h]
#align set.preimage_congr Set.preimage_congr
@[gcongr]
theorem preimage_mono {s t : Set β} (h : s ⊆ t) : f ⁻¹' s ⊆ f ⁻¹' t := fun _ hx => h hx
#align set.preimage_mono Set.preimage_mono
@[simp, mfld_simps]
theorem preimage_univ : f ⁻¹' univ = univ :=
rfl
#align set.preimage_univ Set.preimage_univ
theorem subset_preimage_univ {s : Set α} : s ⊆ f ⁻¹' univ :=
subset_univ _
#align set.subset_preimage_univ Set.subset_preimage_univ
@[simp, mfld_simps]
theorem preimage_inter {s t : Set β} : f ⁻¹' (s ∩ t) = f ⁻¹' s ∩ f ⁻¹' t :=
rfl
#align set.preimage_inter Set.preimage_inter
@[simp]
theorem preimage_union {s t : Set β} : f ⁻¹' (s ∪ t) = f ⁻¹' s ∪ f ⁻¹' t :=
rfl
#align set.preimage_union Set.preimage_union
@[simp]
theorem preimage_compl {s : Set β} : f ⁻¹' sᶜ = (f ⁻¹' s)ᶜ :=
rfl
#align set.preimage_compl Set.preimage_compl
@[simp]
theorem preimage_diff (f : α → β) (s t : Set β) : f ⁻¹' (s \ t) = f ⁻¹' s \ f ⁻¹' t :=
rfl
#align set.preimage_diff Set.preimage_diff
@[simp]
lemma preimage_symmDiff {f : α → β} (s t : Set β) : f ⁻¹' (s ∆ t) = (f ⁻¹' s) ∆ (f ⁻¹' t) :=
rfl
#align set.preimage_symm_diff Set.preimage_symmDiff
@[simp]
theorem preimage_ite (f : α → β) (s t₁ t₂ : Set β) :
f ⁻¹' s.ite t₁ t₂ = (f ⁻¹' s).ite (f ⁻¹' t₁) (f ⁻¹' t₂) :=
rfl
#align set.preimage_ite Set.preimage_ite
@[simp]
theorem preimage_setOf_eq {p : α → Prop} {f : β → α} : f ⁻¹' { a | p a } = { a | p (f a) } :=
rfl
#align set.preimage_set_of_eq Set.preimage_setOf_eq
@[simp]
theorem preimage_id_eq : preimage (id : α → α) = id :=
rfl
#align set.preimage_id_eq Set.preimage_id_eq
@[mfld_simps]
theorem preimage_id {s : Set α} : id ⁻¹' s = s :=
rfl
#align set.preimage_id Set.preimage_id
@[simp, mfld_simps]
theorem preimage_id' {s : Set α} : (fun x => x) ⁻¹' s = s :=
rfl
#align set.preimage_id' Set.preimage_id'
@[simp]
theorem preimage_const_of_mem {b : β} {s : Set β} (h : b ∈ s) : (fun _ : α => b) ⁻¹' s = univ :=
eq_univ_of_forall fun _ => h
#align set.preimage_const_of_mem Set.preimage_const_of_mem
@[simp]
theorem preimage_const_of_not_mem {b : β} {s : Set β} (h : b ∉ s) : (fun _ : α => b) ⁻¹' s = ∅ :=
eq_empty_of_subset_empty fun _ hx => h hx
#align set.preimage_const_of_not_mem Set.preimage_const_of_not_mem
theorem preimage_const (b : β) (s : Set β) [Decidable (b ∈ s)] :
(fun _ : α => b) ⁻¹' s = if b ∈ s then univ else ∅ := by
split_ifs with hb
exacts [preimage_const_of_mem hb, preimage_const_of_not_mem hb]
#align set.preimage_const Set.preimage_const
/-- If preimage of each singleton under `f : α → β` is either empty or the whole type,
then `f` is a constant. -/
lemma exists_eq_const_of_preimage_singleton [Nonempty β] {f : α → β}
(hf : ∀ b : β, f ⁻¹' {b} = ∅ ∨ f ⁻¹' {b} = univ) : ∃ b, f = const α b := by
rcases em (∃ b, f ⁻¹' {b} = univ) with ⟨b, hb⟩ | hf'
· exact ⟨b, funext fun x ↦ eq_univ_iff_forall.1 hb x⟩
· have : ∀ x b, f x ≠ b := fun x b ↦
eq_empty_iff_forall_not_mem.1 ((hf b).resolve_right fun h ↦ hf' ⟨b, h⟩) x
exact ⟨Classical.arbitrary β, funext fun x ↦ absurd rfl (this x _)⟩
theorem preimage_comp {s : Set γ} : g ∘ f ⁻¹' s = f ⁻¹' (g ⁻¹' s) :=
rfl
#align set.preimage_comp Set.preimage_comp
theorem preimage_comp_eq : preimage (g ∘ f) = preimage f ∘ preimage g :=
rfl
#align set.preimage_comp_eq Set.preimage_comp_eq
theorem preimage_iterate_eq {f : α → α} {n : ℕ} : Set.preimage f^[n] = (Set.preimage f)^[n] := by
induction' n with n ih; · simp
rw [iterate_succ, iterate_succ', preimage_comp_eq, ih]
#align set.preimage_iterate_eq Set.preimage_iterate_eq
theorem preimage_preimage {g : β → γ} {f : α → β} {s : Set γ} :
f ⁻¹' (g ⁻¹' s) = (fun x => g (f x)) ⁻¹' s :=
preimage_comp.symm
#align set.preimage_preimage Set.preimage_preimage
theorem eq_preimage_subtype_val_iff {p : α → Prop} {s : Set (Subtype p)} {t : Set α} :
s = Subtype.val ⁻¹' t ↔ ∀ (x) (h : p x), (⟨x, h⟩ : Subtype p) ∈ s ↔ x ∈ t :=
⟨fun s_eq x h => by
rw [s_eq]
simp, fun h => ext fun ⟨x, hx⟩ => by simp [h]⟩
#align set.eq_preimage_subtype_val_iff Set.eq_preimage_subtype_val_iff
theorem nonempty_of_nonempty_preimage {s : Set β} {f : α → β} (hf : (f ⁻¹' s).Nonempty) :
s.Nonempty :=
let ⟨x, hx⟩ := hf
⟨f x, hx⟩
#align set.nonempty_of_nonempty_preimage Set.nonempty_of_nonempty_preimage
@[simp] theorem preimage_singleton_true (p : α → Prop) : p ⁻¹' {True} = {a | p a} := by ext; simp
#align set.preimage_singleton_true Set.preimage_singleton_true
@[simp] theorem preimage_singleton_false (p : α → Prop) : p ⁻¹' {False} = {a | ¬p a} := by ext; simp
#align set.preimage_singleton_false Set.preimage_singleton_false
theorem preimage_subtype_coe_eq_compl {s u v : Set α} (hsuv : s ⊆ u ∪ v)
(H : s ∩ (u ∩ v) = ∅) : ((↑) : s → α) ⁻¹' u = ((↑) ⁻¹' v)ᶜ := by
ext ⟨x, x_in_s⟩
constructor
· intro x_in_u x_in_v
exact eq_empty_iff_forall_not_mem.mp H x ⟨x_in_s, ⟨x_in_u, x_in_v⟩⟩
· intro hx
exact Or.elim (hsuv x_in_s) id fun hx' => hx.elim hx'
#align set.preimage_subtype_coe_eq_compl Set.preimage_subtype_coe_eq_compl
end Preimage
/-! ### Image of a set under a function -/
section Image
variable {f : α → β} {s t : Set α}
-- Porting note: `Set.image` is already defined in `Init.Set`
#align set.image Set.image
/-- `f '' s` denotes the image of `s : Set α` under the function `f : α → β`. -/
infixl:80 " '' " => image
theorem mem_image_iff_bex {f : α → β} {s : Set α} {y : β} :
y ∈ f '' s ↔ ∃ (x : _) (_ : x ∈ s), f x = y :=
bex_def.symm
#align set.mem_image_iff_bex Set.mem_image_iff_bex
@[simp]
theorem mem_image (f : α → β) (s : Set α) (y : β) : y ∈ f '' s ↔ ∃ x ∈ s, f x = y :=
Iff.rfl
#align set.mem_image Set.mem_image
theorem image_eta (f : α → β) : f '' s = (fun x => f x) '' s :=
rfl
#align set.image_eta Set.image_eta
@[mfld_simps]
theorem mem_image_of_mem (f : α → β) {x : α} {a : Set α} (h : x ∈ a) : f x ∈ f '' a :=
⟨_, h, rfl⟩
#align set.mem_image_of_mem Set.mem_image_of_mem
theorem _root_.Function.Injective.mem_set_image {f : α → β} (hf : Injective f) {s : Set α} {a : α} :
f a ∈ f '' s ↔ a ∈ s :=
⟨fun ⟨_, hb, Eq⟩ => hf Eq ▸ hb, mem_image_of_mem f⟩
#align function.injective.mem_set_image Function.Injective.mem_set_image
theorem ball_image_iff {f : α → β} {s : Set α} {p : β → Prop} :
(∀ y ∈ f '' s, p y) ↔ ∀ x ∈ s, p (f x) := by simp
#align set.ball_image_iff Set.ball_image_iff
theorem ball_image_of_ball {f : α → β} {s : Set α} {p : β → Prop} (h : ∀ x ∈ s, p (f x)) :
∀ y ∈ f '' s, p y :=
ball_image_iff.2 h
#align set.ball_image_of_ball Set.ball_image_of_ball
theorem bex_image_iff {f : α → β} {s : Set α} {p : β → Prop} :
(∃ y ∈ f '' s, p y) ↔ ∃ x ∈ s, p (f x) := by simp
#align set.bex_image_iff Set.bex_image_iff
theorem mem_image_elim {f : α → β} {s : Set α} {C : β → Prop} (h : ∀ x : α, x ∈ s → C (f x)) :
∀ {y : β}, y ∈ f '' s → C y
| _, ⟨a, a_in, rfl⟩ => h a a_in
#align set.mem_image_elim Set.mem_image_elim
theorem mem_image_elim_on {f : α → β} {s : Set α} {C : β → Prop} {y : β} (h_y : y ∈ f '' s)
(h : ∀ x : α, x ∈ s → C (f x)) : C y :=
mem_image_elim h h_y
#align set.mem_image_elim_on Set.mem_image_elim_on
-- Porting note: used to be `safe`
@[congr]
theorem image_congr {f g : α → β} {s : Set α} (h : ∀ a ∈ s, f a = g a) : f '' s = g '' s := by
ext x
rw [mem_image, mem_image]
exact {
mp := by
rintro ⟨a, ha1, ha2⟩
exact ⟨a, ⟨ha1, (h a ha1) ▸ ha2⟩⟩,
mpr := by
rintro ⟨a, ha1, ha2⟩
exact ⟨a, ⟨ha1, (h a ha1) ▸ ha2⟩⟩
}
-- safe [ext_iff, iff_def]
#align set.image_congr Set.image_congr
/-- A common special case of `image_congr` -/
theorem image_congr' {f g : α → β} {s : Set α} (h : ∀ x : α, f x = g x) : f '' s = g '' s :=
image_congr fun x _ => h x
#align set.image_congr' Set.image_congr'
@[gcongr]
lemma image_mono (h : s ⊆ t) : f '' s ⊆ f '' t := by
rintro - ⟨a, ha, rfl⟩; exact mem_image_of_mem f (h ha)
theorem image_comp (f : β → γ) (g : α → β) (a : Set α) : f ∘ g '' a = f '' (g '' a) :=
Subset.antisymm (ball_image_of_ball fun _ ha => mem_image_of_mem _ <| mem_image_of_mem _ ha)
(ball_image_of_ball <| ball_image_of_ball fun _ ha => mem_image_of_mem _ ha)
#align set.image_comp Set.image_comp
theorem image_comp_eq {g : β → γ} : image (g ∘ f) = image g ∘ image f := by ext; simp
/-- A variant of `image_comp`, useful for rewriting -/
theorem image_image (g : β → γ) (f : α → β) (s : Set α) : g '' (f '' s) = (fun x => g (f x)) '' s :=
(image_comp g f s).symm
#align set.image_image Set.image_image
theorem image_comm {β'} {f : β → γ} {g : α → β} {f' : α → β'} {g' : β' → γ}
(h_comm : ∀ a, f (g a) = g' (f' a)) : (s.image g).image f = (s.image f').image g' := by
simp_rw [image_image, h_comm]
#align set.image_comm Set.image_comm
theorem _root_.Function.Semiconj.set_image {f : α → β} {ga : α → α} {gb : β → β}
(h : Function.Semiconj f ga gb) : Function.Semiconj (image f) (image ga) (image gb) := fun _ =>
image_comm h
#align function.semiconj.set_image Function.Semiconj.set_image
theorem _root_.Function.Commute.set_image {f g : α → α} (h : Function.Commute f g) :
Function.Commute (image f) (image g) :=
Function.Semiconj.set_image h
#align function.commute.set_image Function.Commute.set_image
/-- Image is monotone with respect to `⊆`. See `Set.monotone_image` for the statement in
terms of `≤`. -/
@[gcongr]
theorem image_subset {a b : Set α} (f : α → β) (h : a ⊆ b) : f '' a ⊆ f '' b := by
simp only [subset_def, mem_image]
exact fun x => fun ⟨w, h1, h2⟩ => ⟨w, h h1, h2⟩
#align set.image_subset Set.image_subset
/-- `Set.image` is monotone. See `Set.image_subset` for the statement in terms of `⊆`. -/
lemma monotone_image {f : α → β} : Monotone (image f) := fun _ _ => image_subset _
#align set.monotone_image Set.monotone_image
theorem image_union (f : α → β) (s t : Set α) : f '' (s ∪ t) = f '' s ∪ f '' t :=
ext fun x =>
⟨by rintro ⟨a, h | h, rfl⟩ <;> [left; right] <;> exact ⟨_, h, rfl⟩, by
rintro (⟨a, h, rfl⟩ | ⟨a, h, rfl⟩) <;> refine' ⟨_, _, rfl⟩ <;> [left; right] <;> exact h⟩
#align set.image_union Set.image_union
@[simp]
theorem image_empty (f : α → β) : f '' ∅ = ∅ := by
ext
simp
#align set.image_empty Set.image_empty
theorem image_inter_subset (f : α → β) (s t : Set α) : f '' (s ∩ t) ⊆ f '' s ∩ f '' t :=
subset_inter (image_subset _ <| inter_subset_left _ _) (image_subset _ <| inter_subset_right _ _)
#align set.image_inter_subset Set.image_inter_subset
theorem image_inter_on {f : α → β} {s t : Set α} (h : ∀ x ∈ t, ∀ y ∈ s, f x = f y → x = y) :
f '' (s ∩ t) = f '' s ∩ f '' t :=
(image_inter_subset _ _ _).antisymm
fun b ⟨⟨a₁, ha₁, h₁⟩, ⟨a₂, ha₂, h₂⟩⟩ ↦
have : a₂ = a₁ := h _ ha₂ _ ha₁ (by simp [*])
⟨a₁, ⟨ha₁, this ▸ ha₂⟩, h₁⟩
#align set.image_inter_on Set.image_inter_on
theorem image_inter {f : α → β} {s t : Set α} (H : Injective f) : f '' (s ∩ t) = f '' s ∩ f '' t :=
image_inter_on fun _ _ _ _ h => H h
#align set.image_inter Set.image_inter
theorem image_univ_of_surjective {ι : Type*} {f : ι → β} (H : Surjective f) : f '' univ = univ :=
eq_univ_of_forall <| by simpa [image]
#align set.image_univ_of_surjective Set.image_univ_of_surjective
@[simp]
theorem image_singleton {f : α → β} {a : α} : f '' {a} = {f a} := by
ext
simp [image, eq_comm]
#align set.image_singleton Set.image_singleton
@[simp]
theorem Nonempty.image_const {s : Set α} (hs : s.Nonempty) (a : β) : (fun _ => a) '' s = {a} :=
ext fun _ =>
⟨fun ⟨_, _, h⟩ => h ▸ mem_singleton _, fun h =>
(eq_of_mem_singleton h).symm ▸ hs.imp fun _ hy => ⟨hy, rfl⟩⟩
#align set.nonempty.image_const Set.Nonempty.image_const
@[simp, mfld_simps]
theorem image_eq_empty {α β} {f : α → β} {s : Set α} : f '' s = ∅ ↔ s = ∅ := by
simp only [eq_empty_iff_forall_not_mem]
exact ⟨fun H a ha => H _ ⟨_, ha, rfl⟩, fun H b ⟨_, ha, _⟩ => H _ ha⟩
#align set.image_eq_empty Set.image_eq_empty
-- Porting note: `compl` is already defined in `Init.Set`
theorem preimage_compl_eq_image_compl [BooleanAlgebra α] (S : Set α) :
HasCompl.compl ⁻¹' S = HasCompl.compl '' S :=
Set.ext fun x =>
⟨fun h => ⟨xᶜ, h, compl_compl x⟩, fun h =>
Exists.elim h fun _ hy => (compl_eq_comm.mp hy.2).symm.subst hy.1⟩
#align set.preimage_compl_eq_image_compl Set.preimage_compl_eq_image_compl
theorem mem_compl_image [BooleanAlgebra α] (t : α) (S : Set α) :
t ∈ HasCompl.compl '' S ↔ tᶜ ∈ S := by
simp [← preimage_compl_eq_image_compl]
#align set.mem_compl_image Set.mem_compl_image
@[simp]
theorem image_id_eq : image (id : α → α) = id := by ext; simp
/-- A variant of `image_id` -/
@[simp]
theorem image_id' (s : Set α) : (fun x => x) '' s = s := by
ext
simp
#align set.image_id' Set.image_id'
theorem image_id (s : Set α) : id '' s = s := by simp
#align set.image_id Set.image_id
lemma image_iterate_eq {f : α → α} {n : ℕ} : image (f^[n]) = (image f)^[n] := by
induction' n with n ih; · simp
rw [iterate_succ', iterate_succ',← ih, image_comp_eq]
theorem compl_compl_image [BooleanAlgebra α] (S : Set α) :
HasCompl.compl '' (HasCompl.compl '' S) = S := by
rw [← image_comp, compl_comp_compl, image_id]
#align set.compl_compl_image Set.compl_compl_image
theorem image_insert_eq {f : α → β} {a : α} {s : Set α} :
f '' insert a s = insert (f a) (f '' s) := by
ext
simp [and_or_left, exists_or, eq_comm, or_comm, and_comm]
#align set.image_insert_eq Set.image_insert_eq
theorem image_pair (f : α → β) (a b : α) : f '' {a, b} = {f a, f b} := by
simp only [image_insert_eq, image_singleton]
#align set.image_pair Set.image_pair
theorem image_subset_preimage_of_inverse {f : α → β} {g : β → α} (I : LeftInverse g f) (s : Set α) :
f '' s ⊆ g ⁻¹' s := fun _ ⟨a, h, e⟩ => e ▸ ((I a).symm ▸ h : g (f a) ∈ s)
#align set.image_subset_preimage_of_inverse Set.image_subset_preimage_of_inverse
theorem preimage_subset_image_of_inverse {f : α → β} {g : β → α} (I : LeftInverse g f) (s : Set β) :
f ⁻¹' s ⊆ g '' s := fun b h => ⟨f b, h, I b⟩
#align set.preimage_subset_image_of_inverse Set.preimage_subset_image_of_inverse
theorem image_eq_preimage_of_inverse {f : α → β} {g : β → α} (h₁ : LeftInverse g f)
(h₂ : RightInverse g f) : image f = preimage g :=
funext fun s =>
Subset.antisymm (image_subset_preimage_of_inverse h₁ s) (preimage_subset_image_of_inverse h₂ s)
#align set.image_eq_preimage_of_inverse Set.image_eq_preimage_of_inverse
theorem mem_image_iff_of_inverse {f : α → β} {g : β → α} {b : β} {s : Set α} (h₁ : LeftInverse g f)
(h₂ : RightInverse g f) : b ∈ f '' s ↔ g b ∈ s := by
rw [image_eq_preimage_of_inverse h₁ h₂]; rfl
#align set.mem_image_iff_of_inverse Set.mem_image_iff_of_inverse
theorem image_compl_subset {f : α → β} {s : Set α} (H : Injective f) : f '' sᶜ ⊆ (f '' s)ᶜ :=
Disjoint.subset_compl_left <| by simp [disjoint_iff_inf_le, ← image_inter H]
#align set.image_compl_subset Set.image_compl_subset
theorem subset_image_compl {f : α → β} {s : Set α} (H : Surjective f) : (f '' s)ᶜ ⊆ f '' sᶜ :=
compl_subset_iff_union.2 <| by
rw [← image_union]
simp [image_univ_of_surjective H]
#align set.subset_image_compl Set.subset_image_compl
theorem image_compl_eq {f : α → β} {s : Set α} (H : Bijective f) : f '' sᶜ = (f '' s)ᶜ :=
Subset.antisymm (image_compl_subset H.1) (subset_image_compl H.2)
#align set.image_compl_eq Set.image_compl_eq
theorem subset_image_diff (f : α → β) (s t : Set α) : f '' s \ f '' t ⊆ f '' (s \ t) := by
rw [diff_subset_iff, ← image_union, union_diff_self]
exact image_subset f (subset_union_right t s)
#align set.subset_image_diff Set.subset_image_diff
theorem subset_image_symmDiff : (f '' s) ∆ (f '' t) ⊆ f '' s ∆ t :=
(union_subset_union (subset_image_diff _ _ _) <| subset_image_diff _ _ _).trans
(superset_of_eq (image_union _ _ _))
#align set.subset_image_symm_diff Set.subset_image_symmDiff
theorem image_diff {f : α → β} (hf : Injective f) (s t : Set α) : f '' (s \ t) = f '' s \ f '' t :=
Subset.antisymm
(Subset.trans (image_inter_subset _ _ _) <| inter_subset_inter_right _ <| image_compl_subset hf)
(subset_image_diff f s t)
#align set.image_diff Set.image_diff
theorem image_symmDiff (hf : Injective f) (s t : Set α) : f '' s ∆ t = (f '' s) ∆ (f '' t) := by
simp_rw [Set.symmDiff_def, image_union, image_diff hf]
#align set.image_symm_diff Set.image_symmDiff
theorem Nonempty.image (f : α → β) {s : Set α} : s.Nonempty → (f '' s).Nonempty
| ⟨x, hx⟩ => ⟨f x, mem_image_of_mem f hx⟩
#align set.nonempty.image Set.Nonempty.image
theorem Nonempty.of_image {f : α → β} {s : Set α} : (f '' s).Nonempty → s.Nonempty
| ⟨_, x, hx, _⟩ => ⟨x, hx⟩
#align set.nonempty.of_image Set.Nonempty.of_image
@[simp]
theorem nonempty_image_iff {f : α → β} {s : Set α} : (f '' s).Nonempty ↔ s.Nonempty :=
⟨Nonempty.of_image, fun h => h.image f⟩
#align set.nonempty_image_iff Set.nonempty_image_iff
theorem Nonempty.preimage {s : Set β} (hs : s.Nonempty) {f : α → β} (hf : Surjective f) :
(f ⁻¹' s).Nonempty :=
let ⟨y, hy⟩ := hs
let ⟨x, hx⟩ := hf y
⟨x, mem_preimage.2 <| hx.symm ▸ hy⟩
#align set.nonempty.preimage Set.Nonempty.preimage
instance (f : α → β) (s : Set α) [Nonempty s] : Nonempty (f '' s) :=
(Set.Nonempty.image f nonempty_of_nonempty_subtype).to_subtype
/-- image and preimage are a Galois connection -/
@[simp]
theorem image_subset_iff {s : Set α} {t : Set β} {f : α → β} : f '' s ⊆ t ↔ s ⊆ f ⁻¹' t :=
ball_image_iff
#align set.image_subset_iff Set.image_subset_iff
theorem image_preimage_subset (f : α → β) (s : Set β) : f '' (f ⁻¹' s) ⊆ s :=
image_subset_iff.2 Subset.rfl
#align set.image_preimage_subset Set.image_preimage_subset
theorem subset_preimage_image (f : α → β) (s : Set α) : s ⊆ f ⁻¹' (f '' s) := fun _ =>
mem_image_of_mem f
#align set.subset_preimage_image Set.subset_preimage_image
@[simp]
theorem preimage_image_eq {f : α → β} (s : Set α) (h : Injective f) : f ⁻¹' (f '' s) = s :=
Subset.antisymm (fun _ ⟨_, hy, e⟩ => h e ▸ hy) (subset_preimage_image f s)
#align set.preimage_image_eq Set.preimage_image_eq
@[simp]
theorem image_preimage_eq {f : α → β} (s : Set β) (h : Surjective f) : f '' (f ⁻¹' s) = s :=
Subset.antisymm (image_preimage_subset f s) fun x hx =>
let ⟨y, e⟩ := h x
⟨y, (e.symm ▸ hx : f y ∈ s), e⟩
#align set.image_preimage_eq Set.image_preimage_eq
@[simp]
theorem preimage_eq_preimage {f : β → α} (hf : Surjective f) : f ⁻¹' s = f ⁻¹' t ↔ s = t :=
Iff.intro
fun eq => by rw [← image_preimage_eq s hf, ← image_preimage_eq t hf, eq]
fun eq => eq ▸ rfl
#align set.preimage_eq_preimage Set.preimage_eq_preimage
theorem image_inter_preimage (f : α → β) (s : Set α) (t : Set β) :
f '' (s ∩ f ⁻¹' t) = f '' s ∩ t := by
apply Subset.antisymm
· calc
f '' (s ∩ f ⁻¹' t) ⊆ f '' s ∩ f '' (f ⁻¹' t) := image_inter_subset _ _ _
_ ⊆ f '' s ∩ t := inter_subset_inter_right _ (image_preimage_subset f t)
· rintro _ ⟨⟨x, h', rfl⟩, h⟩
exact ⟨x, ⟨h', h⟩, rfl⟩
#align set.image_inter_preimage Set.image_inter_preimage
theorem image_preimage_inter (f : α → β) (s : Set α) (t : Set β) :
f '' (f ⁻¹' t ∩ s) = t ∩ f '' s := by simp only [inter_comm, image_inter_preimage]
#align set.image_preimage_inter Set.image_preimage_inter
@[simp]
theorem image_inter_nonempty_iff {f : α → β} {s : Set α} {t : Set β} :
(f '' s ∩ t).Nonempty ↔ (s ∩ f ⁻¹' t).Nonempty := by
rw [← image_inter_preimage, nonempty_image_iff]
#align set.image_inter_nonempty_iff Set.image_inter_nonempty_iff
theorem image_diff_preimage {f : α → β} {s : Set α} {t : Set β} : f '' (s \ f ⁻¹' t) = f '' s \ t :=
by simp_rw [diff_eq, ← preimage_compl, image_inter_preimage]
#align set.image_diff_preimage Set.image_diff_preimage
theorem compl_image : image (compl : Set α → Set α) = preimage compl :=
image_eq_preimage_of_inverse compl_compl compl_compl
#align set.compl_image Set.compl_image
theorem compl_image_set_of {p : Set α → Prop} : compl '' { s | p s } = { s | p sᶜ } :=
congr_fun compl_image p
#align set.compl_image_set_of Set.compl_image_set_of
theorem inter_preimage_subset (s : Set α) (t : Set β) (f : α → β) :
s ∩ f ⁻¹' t ⊆ f ⁻¹' (f '' s ∩ t) := fun _ h => ⟨mem_image_of_mem _ h.left, h.right⟩
#align set.inter_preimage_subset Set.inter_preimage_subset
theorem union_preimage_subset (s : Set α) (t : Set β) (f : α → β) :
s ∪ f ⁻¹' t ⊆ f ⁻¹' (f '' s ∪ t) := fun _ h =>
Or.elim h (fun l => Or.inl <| mem_image_of_mem _ l) fun r => Or.inr r
#align set.union_preimage_subset Set.union_preimage_subset
theorem subset_image_union (f : α → β) (s : Set α) (t : Set β) : f '' (s ∪ f ⁻¹' t) ⊆ f '' s ∪ t :=
image_subset_iff.2 (union_preimage_subset _ _ _)
#align set.subset_image_union Set.subset_image_union
theorem preimage_subset_iff {A : Set α} {B : Set β} {f : α → β} :
f ⁻¹' B ⊆ A ↔ ∀ a : α, f a ∈ B → a ∈ A :=
Iff.rfl
#align set.preimage_subset_iff Set.preimage_subset_iff
theorem image_eq_image {f : α → β} (hf : Injective f) : f '' s = f '' t ↔ s = t :=
Iff.symm <|
(Iff.intro fun eq => eq ▸ rfl) fun eq => by
rw [← preimage_image_eq s hf, ← preimage_image_eq t hf, eq]
#align set.image_eq_image Set.image_eq_image
theorem image_subset_image_iff {f : α → β} (hf : Injective f) : f '' s ⊆ f '' t ↔ s ⊆ t := by
refine' Iff.symm <| (Iff.intro (image_subset f)) fun h => _
rw [← preimage_image_eq s hf, ← preimage_image_eq t hf]
exact preimage_mono h
#align set.image_subset_image_iff Set.image_subset_image_iff
theorem prod_quotient_preimage_eq_image [s : Setoid α] (g : Quotient s → β) {h : α → β}
(Hh : h = g ∘ Quotient.mk'') (r : Set (β × β)) :
{ x : Quotient s × Quotient s | (g x.1, g x.2) ∈ r } =
(fun a : α × α => (⟦a.1⟧, ⟦a.2⟧)) '' ((fun a : α × α => (h a.1, h a.2)) ⁻¹' r) :=
Hh.symm ▸
Set.ext fun ⟨a₁, a₂⟩ =>
⟨Quot.induction_on₂ a₁ a₂ fun a₁ a₂ h => ⟨(a₁, a₂), h, rfl⟩, fun ⟨⟨b₁, b₂⟩, h₁, h₂⟩ =>
show (g a₁, g a₂) ∈ r from
have h₃ : ⟦b₁⟧ = a₁ ∧ ⟦b₂⟧ = a₂ := Prod.ext_iff.1 h₂
h₃.1 ▸ h₃.2 ▸ h₁⟩
#align set.prod_quotient_preimage_eq_image Set.prod_quotient_preimage_eq_image
theorem exists_image_iff (f : α → β) (x : Set α) (P : β → Prop) :
(∃ a : f '' x, P a) ↔ ∃ a : x, P (f a) :=
⟨fun ⟨a, h⟩ => ⟨⟨_, a.prop.choose_spec.1⟩, a.prop.choose_spec.2.symm ▸ h⟩, fun ⟨a, h⟩ =>
⟨⟨_, _, a.prop, rfl⟩, h⟩⟩
#align set.exists_image_iff Set.exists_image_iff
/-- Restriction of `f` to `s` factors through `s.imageFactorization f : s → f '' s`. -/
def imageFactorization (f : α → β) (s : Set α) : s → f '' s := fun p =>
⟨f p.1, mem_image_of_mem f p.2⟩
#align set.image_factorization Set.imageFactorization
theorem imageFactorization_eq {f : α → β} {s : Set α} :
Subtype.val ∘ imageFactorization f s = f ∘ Subtype.val :=
funext fun _ => rfl
#align set.image_factorization_eq Set.imageFactorization_eq
theorem surjective_onto_image {f : α → β} {s : Set α} : Surjective (imageFactorization f s) :=
fun ⟨_, ⟨a, ha, rfl⟩⟩ => ⟨⟨a, ha⟩, rfl⟩
#align set.surjective_onto_image Set.surjective_onto_image
/-- If the only elements outside `s` are those left fixed by `σ`, then mapping by `σ` has no effect.
-/
theorem image_perm {s : Set α} {σ : Equiv.Perm α} (hs : { a : α | σ a ≠ a } ⊆ s) : σ '' s = s := by
ext i
obtain hi | hi := eq_or_ne (σ i) i
· refine' ⟨_, fun h => ⟨i, h, hi⟩⟩
rintro ⟨j, hj, h⟩
rwa [σ.injective (hi.trans h.symm)]
·
|
refine' iff_of_true ⟨σ.symm i, hs fun h => hi _, σ.apply_symm_apply _⟩ (hs hi)
|
/-- If the only elements outside `s` are those left fixed by `σ`, then mapping by `σ` has no effect.
-/
theorem image_perm {s : Set α} {σ : Equiv.Perm α} (hs : { a : α | σ a ≠ a } ⊆ s) : σ '' s = s := by
ext i
obtain hi | hi := eq_or_ne (σ i) i
· refine' ⟨_, fun h => ⟨i, h, hi⟩⟩
rintro ⟨j, hj, h⟩
rwa [σ.injective (hi.trans h.symm)]
·
|
Mathlib.Data.Set.Image.635_0.IJFiTzmYGOCpPSd
|
/-- If the only elements outside `s` are those left fixed by `σ`, then mapping by `σ` has no effect.
-/
theorem image_perm {s : Set α} {σ : Equiv.Perm α} (hs : { a : α | σ a ≠ a } ⊆ s) : σ '' s = s
|
Mathlib_Data_Set_Image
|
case h.inr
α : Type u_1
β : Type u_2
γ : Type u_3
ι : Sort u_4
ι' : Sort u_5
f : α → β
s✝ t s : Set α
σ : Equiv.Perm α
hs : {a | σ a ≠ a} ⊆ s
i : α
hi : σ i ≠ i
h : σ (σ.symm i) = σ.symm i
⊢ σ i = i
|
/-
Copyright (c) 2014 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Leonardo de Moura
-/
import Mathlib.Data.Set.Basic
#align_import data.set.image from "leanprover-community/mathlib"@"001ffdc42920050657fd45bd2b8bfbec8eaaeb29"
/-!
# Images and preimages of sets
## Main definitions
* `preimage f t : Set α` : the preimage f⁻¹(t) (written `f ⁻¹' t` in Lean) of a subset of β.
* `range f : Set β` : the image of `univ` under `f`.
Also works for `{p : Prop} (f : p → α)` (unlike `image`)
## Notation
* `f ⁻¹' t` for `Set.preimage f t`
* `f '' s` for `Set.image f s`
## Tags
set, sets, image, preimage, pre-image, range
-/
set_option autoImplicit true
universe u v
open Function Set
namespace Set
variable {α β γ : Type*} {ι ι' : Sort*}
/-! ### Inverse image -/
/-- The preimage of `s : Set β` by `f : α → β`, written `f ⁻¹' s`,
is the set of `x : α` such that `f x ∈ s`. -/
def preimage {α : Type u} {β : Type v} (f : α → β) (s : Set β) : Set α :=
{ x | f x ∈ s }
#align set.preimage Set.preimage
/-- `f ⁻¹' t` denotes the preimage of `t : Set β` under the function `f : α → β`. -/
infixl:80 " ⁻¹' " => preimage
section Preimage
variable {f : α → β} {g : β → γ}
@[simp]
theorem preimage_empty : f ⁻¹' ∅ = ∅ :=
rfl
#align set.preimage_empty Set.preimage_empty
@[simp, mfld_simps]
theorem mem_preimage {s : Set β} {a : α} : a ∈ f ⁻¹' s ↔ f a ∈ s :=
Iff.rfl
#align set.mem_preimage Set.mem_preimage
theorem preimage_congr {f g : α → β} {s : Set β} (h : ∀ x : α, f x = g x) : f ⁻¹' s = g ⁻¹' s := by
congr with x
simp [h]
#align set.preimage_congr Set.preimage_congr
@[gcongr]
theorem preimage_mono {s t : Set β} (h : s ⊆ t) : f ⁻¹' s ⊆ f ⁻¹' t := fun _ hx => h hx
#align set.preimage_mono Set.preimage_mono
@[simp, mfld_simps]
theorem preimage_univ : f ⁻¹' univ = univ :=
rfl
#align set.preimage_univ Set.preimage_univ
theorem subset_preimage_univ {s : Set α} : s ⊆ f ⁻¹' univ :=
subset_univ _
#align set.subset_preimage_univ Set.subset_preimage_univ
@[simp, mfld_simps]
theorem preimage_inter {s t : Set β} : f ⁻¹' (s ∩ t) = f ⁻¹' s ∩ f ⁻¹' t :=
rfl
#align set.preimage_inter Set.preimage_inter
@[simp]
theorem preimage_union {s t : Set β} : f ⁻¹' (s ∪ t) = f ⁻¹' s ∪ f ⁻¹' t :=
rfl
#align set.preimage_union Set.preimage_union
@[simp]
theorem preimage_compl {s : Set β} : f ⁻¹' sᶜ = (f ⁻¹' s)ᶜ :=
rfl
#align set.preimage_compl Set.preimage_compl
@[simp]
theorem preimage_diff (f : α → β) (s t : Set β) : f ⁻¹' (s \ t) = f ⁻¹' s \ f ⁻¹' t :=
rfl
#align set.preimage_diff Set.preimage_diff
@[simp]
lemma preimage_symmDiff {f : α → β} (s t : Set β) : f ⁻¹' (s ∆ t) = (f ⁻¹' s) ∆ (f ⁻¹' t) :=
rfl
#align set.preimage_symm_diff Set.preimage_symmDiff
@[simp]
theorem preimage_ite (f : α → β) (s t₁ t₂ : Set β) :
f ⁻¹' s.ite t₁ t₂ = (f ⁻¹' s).ite (f ⁻¹' t₁) (f ⁻¹' t₂) :=
rfl
#align set.preimage_ite Set.preimage_ite
@[simp]
theorem preimage_setOf_eq {p : α → Prop} {f : β → α} : f ⁻¹' { a | p a } = { a | p (f a) } :=
rfl
#align set.preimage_set_of_eq Set.preimage_setOf_eq
@[simp]
theorem preimage_id_eq : preimage (id : α → α) = id :=
rfl
#align set.preimage_id_eq Set.preimage_id_eq
@[mfld_simps]
theorem preimage_id {s : Set α} : id ⁻¹' s = s :=
rfl
#align set.preimage_id Set.preimage_id
@[simp, mfld_simps]
theorem preimage_id' {s : Set α} : (fun x => x) ⁻¹' s = s :=
rfl
#align set.preimage_id' Set.preimage_id'
@[simp]
theorem preimage_const_of_mem {b : β} {s : Set β} (h : b ∈ s) : (fun _ : α => b) ⁻¹' s = univ :=
eq_univ_of_forall fun _ => h
#align set.preimage_const_of_mem Set.preimage_const_of_mem
@[simp]
theorem preimage_const_of_not_mem {b : β} {s : Set β} (h : b ∉ s) : (fun _ : α => b) ⁻¹' s = ∅ :=
eq_empty_of_subset_empty fun _ hx => h hx
#align set.preimage_const_of_not_mem Set.preimage_const_of_not_mem
theorem preimage_const (b : β) (s : Set β) [Decidable (b ∈ s)] :
(fun _ : α => b) ⁻¹' s = if b ∈ s then univ else ∅ := by
split_ifs with hb
exacts [preimage_const_of_mem hb, preimage_const_of_not_mem hb]
#align set.preimage_const Set.preimage_const
/-- If preimage of each singleton under `f : α → β` is either empty or the whole type,
then `f` is a constant. -/
lemma exists_eq_const_of_preimage_singleton [Nonempty β] {f : α → β}
(hf : ∀ b : β, f ⁻¹' {b} = ∅ ∨ f ⁻¹' {b} = univ) : ∃ b, f = const α b := by
rcases em (∃ b, f ⁻¹' {b} = univ) with ⟨b, hb⟩ | hf'
· exact ⟨b, funext fun x ↦ eq_univ_iff_forall.1 hb x⟩
· have : ∀ x b, f x ≠ b := fun x b ↦
eq_empty_iff_forall_not_mem.1 ((hf b).resolve_right fun h ↦ hf' ⟨b, h⟩) x
exact ⟨Classical.arbitrary β, funext fun x ↦ absurd rfl (this x _)⟩
theorem preimage_comp {s : Set γ} : g ∘ f ⁻¹' s = f ⁻¹' (g ⁻¹' s) :=
rfl
#align set.preimage_comp Set.preimage_comp
theorem preimage_comp_eq : preimage (g ∘ f) = preimage f ∘ preimage g :=
rfl
#align set.preimage_comp_eq Set.preimage_comp_eq
theorem preimage_iterate_eq {f : α → α} {n : ℕ} : Set.preimage f^[n] = (Set.preimage f)^[n] := by
induction' n with n ih; · simp
rw [iterate_succ, iterate_succ', preimage_comp_eq, ih]
#align set.preimage_iterate_eq Set.preimage_iterate_eq
theorem preimage_preimage {g : β → γ} {f : α → β} {s : Set γ} :
f ⁻¹' (g ⁻¹' s) = (fun x => g (f x)) ⁻¹' s :=
preimage_comp.symm
#align set.preimage_preimage Set.preimage_preimage
theorem eq_preimage_subtype_val_iff {p : α → Prop} {s : Set (Subtype p)} {t : Set α} :
s = Subtype.val ⁻¹' t ↔ ∀ (x) (h : p x), (⟨x, h⟩ : Subtype p) ∈ s ↔ x ∈ t :=
⟨fun s_eq x h => by
rw [s_eq]
simp, fun h => ext fun ⟨x, hx⟩ => by simp [h]⟩
#align set.eq_preimage_subtype_val_iff Set.eq_preimage_subtype_val_iff
theorem nonempty_of_nonempty_preimage {s : Set β} {f : α → β} (hf : (f ⁻¹' s).Nonempty) :
s.Nonempty :=
let ⟨x, hx⟩ := hf
⟨f x, hx⟩
#align set.nonempty_of_nonempty_preimage Set.nonempty_of_nonempty_preimage
@[simp] theorem preimage_singleton_true (p : α → Prop) : p ⁻¹' {True} = {a | p a} := by ext; simp
#align set.preimage_singleton_true Set.preimage_singleton_true
@[simp] theorem preimage_singleton_false (p : α → Prop) : p ⁻¹' {False} = {a | ¬p a} := by ext; simp
#align set.preimage_singleton_false Set.preimage_singleton_false
theorem preimage_subtype_coe_eq_compl {s u v : Set α} (hsuv : s ⊆ u ∪ v)
(H : s ∩ (u ∩ v) = ∅) : ((↑) : s → α) ⁻¹' u = ((↑) ⁻¹' v)ᶜ := by
ext ⟨x, x_in_s⟩
constructor
· intro x_in_u x_in_v
exact eq_empty_iff_forall_not_mem.mp H x ⟨x_in_s, ⟨x_in_u, x_in_v⟩⟩
· intro hx
exact Or.elim (hsuv x_in_s) id fun hx' => hx.elim hx'
#align set.preimage_subtype_coe_eq_compl Set.preimage_subtype_coe_eq_compl
end Preimage
/-! ### Image of a set under a function -/
section Image
variable {f : α → β} {s t : Set α}
-- Porting note: `Set.image` is already defined in `Init.Set`
#align set.image Set.image
/-- `f '' s` denotes the image of `s : Set α` under the function `f : α → β`. -/
infixl:80 " '' " => image
theorem mem_image_iff_bex {f : α → β} {s : Set α} {y : β} :
y ∈ f '' s ↔ ∃ (x : _) (_ : x ∈ s), f x = y :=
bex_def.symm
#align set.mem_image_iff_bex Set.mem_image_iff_bex
@[simp]
theorem mem_image (f : α → β) (s : Set α) (y : β) : y ∈ f '' s ↔ ∃ x ∈ s, f x = y :=
Iff.rfl
#align set.mem_image Set.mem_image
theorem image_eta (f : α → β) : f '' s = (fun x => f x) '' s :=
rfl
#align set.image_eta Set.image_eta
@[mfld_simps]
theorem mem_image_of_mem (f : α → β) {x : α} {a : Set α} (h : x ∈ a) : f x ∈ f '' a :=
⟨_, h, rfl⟩
#align set.mem_image_of_mem Set.mem_image_of_mem
theorem _root_.Function.Injective.mem_set_image {f : α → β} (hf : Injective f) {s : Set α} {a : α} :
f a ∈ f '' s ↔ a ∈ s :=
⟨fun ⟨_, hb, Eq⟩ => hf Eq ▸ hb, mem_image_of_mem f⟩
#align function.injective.mem_set_image Function.Injective.mem_set_image
theorem ball_image_iff {f : α → β} {s : Set α} {p : β → Prop} :
(∀ y ∈ f '' s, p y) ↔ ∀ x ∈ s, p (f x) := by simp
#align set.ball_image_iff Set.ball_image_iff
theorem ball_image_of_ball {f : α → β} {s : Set α} {p : β → Prop} (h : ∀ x ∈ s, p (f x)) :
∀ y ∈ f '' s, p y :=
ball_image_iff.2 h
#align set.ball_image_of_ball Set.ball_image_of_ball
theorem bex_image_iff {f : α → β} {s : Set α} {p : β → Prop} :
(∃ y ∈ f '' s, p y) ↔ ∃ x ∈ s, p (f x) := by simp
#align set.bex_image_iff Set.bex_image_iff
theorem mem_image_elim {f : α → β} {s : Set α} {C : β → Prop} (h : ∀ x : α, x ∈ s → C (f x)) :
∀ {y : β}, y ∈ f '' s → C y
| _, ⟨a, a_in, rfl⟩ => h a a_in
#align set.mem_image_elim Set.mem_image_elim
theorem mem_image_elim_on {f : α → β} {s : Set α} {C : β → Prop} {y : β} (h_y : y ∈ f '' s)
(h : ∀ x : α, x ∈ s → C (f x)) : C y :=
mem_image_elim h h_y
#align set.mem_image_elim_on Set.mem_image_elim_on
-- Porting note: used to be `safe`
@[congr]
theorem image_congr {f g : α → β} {s : Set α} (h : ∀ a ∈ s, f a = g a) : f '' s = g '' s := by
ext x
rw [mem_image, mem_image]
exact {
mp := by
rintro ⟨a, ha1, ha2⟩
exact ⟨a, ⟨ha1, (h a ha1) ▸ ha2⟩⟩,
mpr := by
rintro ⟨a, ha1, ha2⟩
exact ⟨a, ⟨ha1, (h a ha1) ▸ ha2⟩⟩
}
-- safe [ext_iff, iff_def]
#align set.image_congr Set.image_congr
/-- A common special case of `image_congr` -/
theorem image_congr' {f g : α → β} {s : Set α} (h : ∀ x : α, f x = g x) : f '' s = g '' s :=
image_congr fun x _ => h x
#align set.image_congr' Set.image_congr'
@[gcongr]
lemma image_mono (h : s ⊆ t) : f '' s ⊆ f '' t := by
rintro - ⟨a, ha, rfl⟩; exact mem_image_of_mem f (h ha)
theorem image_comp (f : β → γ) (g : α → β) (a : Set α) : f ∘ g '' a = f '' (g '' a) :=
Subset.antisymm (ball_image_of_ball fun _ ha => mem_image_of_mem _ <| mem_image_of_mem _ ha)
(ball_image_of_ball <| ball_image_of_ball fun _ ha => mem_image_of_mem _ ha)
#align set.image_comp Set.image_comp
theorem image_comp_eq {g : β → γ} : image (g ∘ f) = image g ∘ image f := by ext; simp
/-- A variant of `image_comp`, useful for rewriting -/
theorem image_image (g : β → γ) (f : α → β) (s : Set α) : g '' (f '' s) = (fun x => g (f x)) '' s :=
(image_comp g f s).symm
#align set.image_image Set.image_image
theorem image_comm {β'} {f : β → γ} {g : α → β} {f' : α → β'} {g' : β' → γ}
(h_comm : ∀ a, f (g a) = g' (f' a)) : (s.image g).image f = (s.image f').image g' := by
simp_rw [image_image, h_comm]
#align set.image_comm Set.image_comm
theorem _root_.Function.Semiconj.set_image {f : α → β} {ga : α → α} {gb : β → β}
(h : Function.Semiconj f ga gb) : Function.Semiconj (image f) (image ga) (image gb) := fun _ =>
image_comm h
#align function.semiconj.set_image Function.Semiconj.set_image
theorem _root_.Function.Commute.set_image {f g : α → α} (h : Function.Commute f g) :
Function.Commute (image f) (image g) :=
Function.Semiconj.set_image h
#align function.commute.set_image Function.Commute.set_image
/-- Image is monotone with respect to `⊆`. See `Set.monotone_image` for the statement in
terms of `≤`. -/
@[gcongr]
theorem image_subset {a b : Set α} (f : α → β) (h : a ⊆ b) : f '' a ⊆ f '' b := by
simp only [subset_def, mem_image]
exact fun x => fun ⟨w, h1, h2⟩ => ⟨w, h h1, h2⟩
#align set.image_subset Set.image_subset
/-- `Set.image` is monotone. See `Set.image_subset` for the statement in terms of `⊆`. -/
lemma monotone_image {f : α → β} : Monotone (image f) := fun _ _ => image_subset _
#align set.monotone_image Set.monotone_image
theorem image_union (f : α → β) (s t : Set α) : f '' (s ∪ t) = f '' s ∪ f '' t :=
ext fun x =>
⟨by rintro ⟨a, h | h, rfl⟩ <;> [left; right] <;> exact ⟨_, h, rfl⟩, by
rintro (⟨a, h, rfl⟩ | ⟨a, h, rfl⟩) <;> refine' ⟨_, _, rfl⟩ <;> [left; right] <;> exact h⟩
#align set.image_union Set.image_union
@[simp]
theorem image_empty (f : α → β) : f '' ∅ = ∅ := by
ext
simp
#align set.image_empty Set.image_empty
theorem image_inter_subset (f : α → β) (s t : Set α) : f '' (s ∩ t) ⊆ f '' s ∩ f '' t :=
subset_inter (image_subset _ <| inter_subset_left _ _) (image_subset _ <| inter_subset_right _ _)
#align set.image_inter_subset Set.image_inter_subset
theorem image_inter_on {f : α → β} {s t : Set α} (h : ∀ x ∈ t, ∀ y ∈ s, f x = f y → x = y) :
f '' (s ∩ t) = f '' s ∩ f '' t :=
(image_inter_subset _ _ _).antisymm
fun b ⟨⟨a₁, ha₁, h₁⟩, ⟨a₂, ha₂, h₂⟩⟩ ↦
have : a₂ = a₁ := h _ ha₂ _ ha₁ (by simp [*])
⟨a₁, ⟨ha₁, this ▸ ha₂⟩, h₁⟩
#align set.image_inter_on Set.image_inter_on
theorem image_inter {f : α → β} {s t : Set α} (H : Injective f) : f '' (s ∩ t) = f '' s ∩ f '' t :=
image_inter_on fun _ _ _ _ h => H h
#align set.image_inter Set.image_inter
theorem image_univ_of_surjective {ι : Type*} {f : ι → β} (H : Surjective f) : f '' univ = univ :=
eq_univ_of_forall <| by simpa [image]
#align set.image_univ_of_surjective Set.image_univ_of_surjective
@[simp]
theorem image_singleton {f : α → β} {a : α} : f '' {a} = {f a} := by
ext
simp [image, eq_comm]
#align set.image_singleton Set.image_singleton
@[simp]
theorem Nonempty.image_const {s : Set α} (hs : s.Nonempty) (a : β) : (fun _ => a) '' s = {a} :=
ext fun _ =>
⟨fun ⟨_, _, h⟩ => h ▸ mem_singleton _, fun h =>
(eq_of_mem_singleton h).symm ▸ hs.imp fun _ hy => ⟨hy, rfl⟩⟩
#align set.nonempty.image_const Set.Nonempty.image_const
@[simp, mfld_simps]
theorem image_eq_empty {α β} {f : α → β} {s : Set α} : f '' s = ∅ ↔ s = ∅ := by
simp only [eq_empty_iff_forall_not_mem]
exact ⟨fun H a ha => H _ ⟨_, ha, rfl⟩, fun H b ⟨_, ha, _⟩ => H _ ha⟩
#align set.image_eq_empty Set.image_eq_empty
-- Porting note: `compl` is already defined in `Init.Set`
theorem preimage_compl_eq_image_compl [BooleanAlgebra α] (S : Set α) :
HasCompl.compl ⁻¹' S = HasCompl.compl '' S :=
Set.ext fun x =>
⟨fun h => ⟨xᶜ, h, compl_compl x⟩, fun h =>
Exists.elim h fun _ hy => (compl_eq_comm.mp hy.2).symm.subst hy.1⟩
#align set.preimage_compl_eq_image_compl Set.preimage_compl_eq_image_compl
theorem mem_compl_image [BooleanAlgebra α] (t : α) (S : Set α) :
t ∈ HasCompl.compl '' S ↔ tᶜ ∈ S := by
simp [← preimage_compl_eq_image_compl]
#align set.mem_compl_image Set.mem_compl_image
@[simp]
theorem image_id_eq : image (id : α → α) = id := by ext; simp
/-- A variant of `image_id` -/
@[simp]
theorem image_id' (s : Set α) : (fun x => x) '' s = s := by
ext
simp
#align set.image_id' Set.image_id'
theorem image_id (s : Set α) : id '' s = s := by simp
#align set.image_id Set.image_id
lemma image_iterate_eq {f : α → α} {n : ℕ} : image (f^[n]) = (image f)^[n] := by
induction' n with n ih; · simp
rw [iterate_succ', iterate_succ',← ih, image_comp_eq]
theorem compl_compl_image [BooleanAlgebra α] (S : Set α) :
HasCompl.compl '' (HasCompl.compl '' S) = S := by
rw [← image_comp, compl_comp_compl, image_id]
#align set.compl_compl_image Set.compl_compl_image
theorem image_insert_eq {f : α → β} {a : α} {s : Set α} :
f '' insert a s = insert (f a) (f '' s) := by
ext
simp [and_or_left, exists_or, eq_comm, or_comm, and_comm]
#align set.image_insert_eq Set.image_insert_eq
theorem image_pair (f : α → β) (a b : α) : f '' {a, b} = {f a, f b} := by
simp only [image_insert_eq, image_singleton]
#align set.image_pair Set.image_pair
theorem image_subset_preimage_of_inverse {f : α → β} {g : β → α} (I : LeftInverse g f) (s : Set α) :
f '' s ⊆ g ⁻¹' s := fun _ ⟨a, h, e⟩ => e ▸ ((I a).symm ▸ h : g (f a) ∈ s)
#align set.image_subset_preimage_of_inverse Set.image_subset_preimage_of_inverse
theorem preimage_subset_image_of_inverse {f : α → β} {g : β → α} (I : LeftInverse g f) (s : Set β) :
f ⁻¹' s ⊆ g '' s := fun b h => ⟨f b, h, I b⟩
#align set.preimage_subset_image_of_inverse Set.preimage_subset_image_of_inverse
theorem image_eq_preimage_of_inverse {f : α → β} {g : β → α} (h₁ : LeftInverse g f)
(h₂ : RightInverse g f) : image f = preimage g :=
funext fun s =>
Subset.antisymm (image_subset_preimage_of_inverse h₁ s) (preimage_subset_image_of_inverse h₂ s)
#align set.image_eq_preimage_of_inverse Set.image_eq_preimage_of_inverse
theorem mem_image_iff_of_inverse {f : α → β} {g : β → α} {b : β} {s : Set α} (h₁ : LeftInverse g f)
(h₂ : RightInverse g f) : b ∈ f '' s ↔ g b ∈ s := by
rw [image_eq_preimage_of_inverse h₁ h₂]; rfl
#align set.mem_image_iff_of_inverse Set.mem_image_iff_of_inverse
theorem image_compl_subset {f : α → β} {s : Set α} (H : Injective f) : f '' sᶜ ⊆ (f '' s)ᶜ :=
Disjoint.subset_compl_left <| by simp [disjoint_iff_inf_le, ← image_inter H]
#align set.image_compl_subset Set.image_compl_subset
theorem subset_image_compl {f : α → β} {s : Set α} (H : Surjective f) : (f '' s)ᶜ ⊆ f '' sᶜ :=
compl_subset_iff_union.2 <| by
rw [← image_union]
simp [image_univ_of_surjective H]
#align set.subset_image_compl Set.subset_image_compl
theorem image_compl_eq {f : α → β} {s : Set α} (H : Bijective f) : f '' sᶜ = (f '' s)ᶜ :=
Subset.antisymm (image_compl_subset H.1) (subset_image_compl H.2)
#align set.image_compl_eq Set.image_compl_eq
theorem subset_image_diff (f : α → β) (s t : Set α) : f '' s \ f '' t ⊆ f '' (s \ t) := by
rw [diff_subset_iff, ← image_union, union_diff_self]
exact image_subset f (subset_union_right t s)
#align set.subset_image_diff Set.subset_image_diff
theorem subset_image_symmDiff : (f '' s) ∆ (f '' t) ⊆ f '' s ∆ t :=
(union_subset_union (subset_image_diff _ _ _) <| subset_image_diff _ _ _).trans
(superset_of_eq (image_union _ _ _))
#align set.subset_image_symm_diff Set.subset_image_symmDiff
theorem image_diff {f : α → β} (hf : Injective f) (s t : Set α) : f '' (s \ t) = f '' s \ f '' t :=
Subset.antisymm
(Subset.trans (image_inter_subset _ _ _) <| inter_subset_inter_right _ <| image_compl_subset hf)
(subset_image_diff f s t)
#align set.image_diff Set.image_diff
theorem image_symmDiff (hf : Injective f) (s t : Set α) : f '' s ∆ t = (f '' s) ∆ (f '' t) := by
simp_rw [Set.symmDiff_def, image_union, image_diff hf]
#align set.image_symm_diff Set.image_symmDiff
theorem Nonempty.image (f : α → β) {s : Set α} : s.Nonempty → (f '' s).Nonempty
| ⟨x, hx⟩ => ⟨f x, mem_image_of_mem f hx⟩
#align set.nonempty.image Set.Nonempty.image
theorem Nonempty.of_image {f : α → β} {s : Set α} : (f '' s).Nonempty → s.Nonempty
| ⟨_, x, hx, _⟩ => ⟨x, hx⟩
#align set.nonempty.of_image Set.Nonempty.of_image
@[simp]
theorem nonempty_image_iff {f : α → β} {s : Set α} : (f '' s).Nonempty ↔ s.Nonempty :=
⟨Nonempty.of_image, fun h => h.image f⟩
#align set.nonempty_image_iff Set.nonempty_image_iff
theorem Nonempty.preimage {s : Set β} (hs : s.Nonempty) {f : α → β} (hf : Surjective f) :
(f ⁻¹' s).Nonempty :=
let ⟨y, hy⟩ := hs
let ⟨x, hx⟩ := hf y
⟨x, mem_preimage.2 <| hx.symm ▸ hy⟩
#align set.nonempty.preimage Set.Nonempty.preimage
instance (f : α → β) (s : Set α) [Nonempty s] : Nonempty (f '' s) :=
(Set.Nonempty.image f nonempty_of_nonempty_subtype).to_subtype
/-- image and preimage are a Galois connection -/
@[simp]
theorem image_subset_iff {s : Set α} {t : Set β} {f : α → β} : f '' s ⊆ t ↔ s ⊆ f ⁻¹' t :=
ball_image_iff
#align set.image_subset_iff Set.image_subset_iff
theorem image_preimage_subset (f : α → β) (s : Set β) : f '' (f ⁻¹' s) ⊆ s :=
image_subset_iff.2 Subset.rfl
#align set.image_preimage_subset Set.image_preimage_subset
theorem subset_preimage_image (f : α → β) (s : Set α) : s ⊆ f ⁻¹' (f '' s) := fun _ =>
mem_image_of_mem f
#align set.subset_preimage_image Set.subset_preimage_image
@[simp]
theorem preimage_image_eq {f : α → β} (s : Set α) (h : Injective f) : f ⁻¹' (f '' s) = s :=
Subset.antisymm (fun _ ⟨_, hy, e⟩ => h e ▸ hy) (subset_preimage_image f s)
#align set.preimage_image_eq Set.preimage_image_eq
@[simp]
theorem image_preimage_eq {f : α → β} (s : Set β) (h : Surjective f) : f '' (f ⁻¹' s) = s :=
Subset.antisymm (image_preimage_subset f s) fun x hx =>
let ⟨y, e⟩ := h x
⟨y, (e.symm ▸ hx : f y ∈ s), e⟩
#align set.image_preimage_eq Set.image_preimage_eq
@[simp]
theorem preimage_eq_preimage {f : β → α} (hf : Surjective f) : f ⁻¹' s = f ⁻¹' t ↔ s = t :=
Iff.intro
fun eq => by rw [← image_preimage_eq s hf, ← image_preimage_eq t hf, eq]
fun eq => eq ▸ rfl
#align set.preimage_eq_preimage Set.preimage_eq_preimage
theorem image_inter_preimage (f : α → β) (s : Set α) (t : Set β) :
f '' (s ∩ f ⁻¹' t) = f '' s ∩ t := by
apply Subset.antisymm
· calc
f '' (s ∩ f ⁻¹' t) ⊆ f '' s ∩ f '' (f ⁻¹' t) := image_inter_subset _ _ _
_ ⊆ f '' s ∩ t := inter_subset_inter_right _ (image_preimage_subset f t)
· rintro _ ⟨⟨x, h', rfl⟩, h⟩
exact ⟨x, ⟨h', h⟩, rfl⟩
#align set.image_inter_preimage Set.image_inter_preimage
theorem image_preimage_inter (f : α → β) (s : Set α) (t : Set β) :
f '' (f ⁻¹' t ∩ s) = t ∩ f '' s := by simp only [inter_comm, image_inter_preimage]
#align set.image_preimage_inter Set.image_preimage_inter
@[simp]
theorem image_inter_nonempty_iff {f : α → β} {s : Set α} {t : Set β} :
(f '' s ∩ t).Nonempty ↔ (s ∩ f ⁻¹' t).Nonempty := by
rw [← image_inter_preimage, nonempty_image_iff]
#align set.image_inter_nonempty_iff Set.image_inter_nonempty_iff
theorem image_diff_preimage {f : α → β} {s : Set α} {t : Set β} : f '' (s \ f ⁻¹' t) = f '' s \ t :=
by simp_rw [diff_eq, ← preimage_compl, image_inter_preimage]
#align set.image_diff_preimage Set.image_diff_preimage
theorem compl_image : image (compl : Set α → Set α) = preimage compl :=
image_eq_preimage_of_inverse compl_compl compl_compl
#align set.compl_image Set.compl_image
theorem compl_image_set_of {p : Set α → Prop} : compl '' { s | p s } = { s | p sᶜ } :=
congr_fun compl_image p
#align set.compl_image_set_of Set.compl_image_set_of
theorem inter_preimage_subset (s : Set α) (t : Set β) (f : α → β) :
s ∩ f ⁻¹' t ⊆ f ⁻¹' (f '' s ∩ t) := fun _ h => ⟨mem_image_of_mem _ h.left, h.right⟩
#align set.inter_preimage_subset Set.inter_preimage_subset
theorem union_preimage_subset (s : Set α) (t : Set β) (f : α → β) :
s ∪ f ⁻¹' t ⊆ f ⁻¹' (f '' s ∪ t) := fun _ h =>
Or.elim h (fun l => Or.inl <| mem_image_of_mem _ l) fun r => Or.inr r
#align set.union_preimage_subset Set.union_preimage_subset
theorem subset_image_union (f : α → β) (s : Set α) (t : Set β) : f '' (s ∪ f ⁻¹' t) ⊆ f '' s ∪ t :=
image_subset_iff.2 (union_preimage_subset _ _ _)
#align set.subset_image_union Set.subset_image_union
theorem preimage_subset_iff {A : Set α} {B : Set β} {f : α → β} :
f ⁻¹' B ⊆ A ↔ ∀ a : α, f a ∈ B → a ∈ A :=
Iff.rfl
#align set.preimage_subset_iff Set.preimage_subset_iff
theorem image_eq_image {f : α → β} (hf : Injective f) : f '' s = f '' t ↔ s = t :=
Iff.symm <|
(Iff.intro fun eq => eq ▸ rfl) fun eq => by
rw [← preimage_image_eq s hf, ← preimage_image_eq t hf, eq]
#align set.image_eq_image Set.image_eq_image
theorem image_subset_image_iff {f : α → β} (hf : Injective f) : f '' s ⊆ f '' t ↔ s ⊆ t := by
refine' Iff.symm <| (Iff.intro (image_subset f)) fun h => _
rw [← preimage_image_eq s hf, ← preimage_image_eq t hf]
exact preimage_mono h
#align set.image_subset_image_iff Set.image_subset_image_iff
theorem prod_quotient_preimage_eq_image [s : Setoid α] (g : Quotient s → β) {h : α → β}
(Hh : h = g ∘ Quotient.mk'') (r : Set (β × β)) :
{ x : Quotient s × Quotient s | (g x.1, g x.2) ∈ r } =
(fun a : α × α => (⟦a.1⟧, ⟦a.2⟧)) '' ((fun a : α × α => (h a.1, h a.2)) ⁻¹' r) :=
Hh.symm ▸
Set.ext fun ⟨a₁, a₂⟩ =>
⟨Quot.induction_on₂ a₁ a₂ fun a₁ a₂ h => ⟨(a₁, a₂), h, rfl⟩, fun ⟨⟨b₁, b₂⟩, h₁, h₂⟩ =>
show (g a₁, g a₂) ∈ r from
have h₃ : ⟦b₁⟧ = a₁ ∧ ⟦b₂⟧ = a₂ := Prod.ext_iff.1 h₂
h₃.1 ▸ h₃.2 ▸ h₁⟩
#align set.prod_quotient_preimage_eq_image Set.prod_quotient_preimage_eq_image
theorem exists_image_iff (f : α → β) (x : Set α) (P : β → Prop) :
(∃ a : f '' x, P a) ↔ ∃ a : x, P (f a) :=
⟨fun ⟨a, h⟩ => ⟨⟨_, a.prop.choose_spec.1⟩, a.prop.choose_spec.2.symm ▸ h⟩, fun ⟨a, h⟩ =>
⟨⟨_, _, a.prop, rfl⟩, h⟩⟩
#align set.exists_image_iff Set.exists_image_iff
/-- Restriction of `f` to `s` factors through `s.imageFactorization f : s → f '' s`. -/
def imageFactorization (f : α → β) (s : Set α) : s → f '' s := fun p =>
⟨f p.1, mem_image_of_mem f p.2⟩
#align set.image_factorization Set.imageFactorization
theorem imageFactorization_eq {f : α → β} {s : Set α} :
Subtype.val ∘ imageFactorization f s = f ∘ Subtype.val :=
funext fun _ => rfl
#align set.image_factorization_eq Set.imageFactorization_eq
theorem surjective_onto_image {f : α → β} {s : Set α} : Surjective (imageFactorization f s) :=
fun ⟨_, ⟨a, ha, rfl⟩⟩ => ⟨⟨a, ha⟩, rfl⟩
#align set.surjective_onto_image Set.surjective_onto_image
/-- If the only elements outside `s` are those left fixed by `σ`, then mapping by `σ` has no effect.
-/
theorem image_perm {s : Set α} {σ : Equiv.Perm α} (hs : { a : α | σ a ≠ a } ⊆ s) : σ '' s = s := by
ext i
obtain hi | hi := eq_or_ne (σ i) i
· refine' ⟨_, fun h => ⟨i, h, hi⟩⟩
rintro ⟨j, hj, h⟩
rwa [σ.injective (hi.trans h.symm)]
· refine' iff_of_true ⟨σ.symm i, hs fun h => hi _, σ.apply_symm_apply _⟩ (hs hi)
|
convert congr_arg σ h
|
/-- If the only elements outside `s` are those left fixed by `σ`, then mapping by `σ` has no effect.
-/
theorem image_perm {s : Set α} {σ : Equiv.Perm α} (hs : { a : α | σ a ≠ a } ⊆ s) : σ '' s = s := by
ext i
obtain hi | hi := eq_or_ne (σ i) i
· refine' ⟨_, fun h => ⟨i, h, hi⟩⟩
rintro ⟨j, hj, h⟩
rwa [σ.injective (hi.trans h.symm)]
· refine' iff_of_true ⟨σ.symm i, hs fun h => hi _, σ.apply_symm_apply _⟩ (hs hi)
|
Mathlib.Data.Set.Image.635_0.IJFiTzmYGOCpPSd
|
/-- If the only elements outside `s` are those left fixed by `σ`, then mapping by `σ` has no effect.
-/
theorem image_perm {s : Set α} {σ : Equiv.Perm α} (hs : { a : α | σ a ≠ a } ⊆ s) : σ '' s = s
|
Mathlib_Data_Set_Image
|
case h.e'_2.h.e'_6
α : Type u_1
β : Type u_2
γ : Type u_3
ι : Sort u_4
ι' : Sort u_5
f : α → β
s✝ t s : Set α
σ : Equiv.Perm α
hs : {a | σ a ≠ a} ⊆ s
i : α
hi : σ i ≠ i
h : σ (σ.symm i) = σ.symm i
⊢ i = σ (σ.symm i)
|
/-
Copyright (c) 2014 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Leonardo de Moura
-/
import Mathlib.Data.Set.Basic
#align_import data.set.image from "leanprover-community/mathlib"@"001ffdc42920050657fd45bd2b8bfbec8eaaeb29"
/-!
# Images and preimages of sets
## Main definitions
* `preimage f t : Set α` : the preimage f⁻¹(t) (written `f ⁻¹' t` in Lean) of a subset of β.
* `range f : Set β` : the image of `univ` under `f`.
Also works for `{p : Prop} (f : p → α)` (unlike `image`)
## Notation
* `f ⁻¹' t` for `Set.preimage f t`
* `f '' s` for `Set.image f s`
## Tags
set, sets, image, preimage, pre-image, range
-/
set_option autoImplicit true
universe u v
open Function Set
namespace Set
variable {α β γ : Type*} {ι ι' : Sort*}
/-! ### Inverse image -/
/-- The preimage of `s : Set β` by `f : α → β`, written `f ⁻¹' s`,
is the set of `x : α` such that `f x ∈ s`. -/
def preimage {α : Type u} {β : Type v} (f : α → β) (s : Set β) : Set α :=
{ x | f x ∈ s }
#align set.preimage Set.preimage
/-- `f ⁻¹' t` denotes the preimage of `t : Set β` under the function `f : α → β`. -/
infixl:80 " ⁻¹' " => preimage
section Preimage
variable {f : α → β} {g : β → γ}
@[simp]
theorem preimage_empty : f ⁻¹' ∅ = ∅ :=
rfl
#align set.preimage_empty Set.preimage_empty
@[simp, mfld_simps]
theorem mem_preimage {s : Set β} {a : α} : a ∈ f ⁻¹' s ↔ f a ∈ s :=
Iff.rfl
#align set.mem_preimage Set.mem_preimage
theorem preimage_congr {f g : α → β} {s : Set β} (h : ∀ x : α, f x = g x) : f ⁻¹' s = g ⁻¹' s := by
congr with x
simp [h]
#align set.preimage_congr Set.preimage_congr
@[gcongr]
theorem preimage_mono {s t : Set β} (h : s ⊆ t) : f ⁻¹' s ⊆ f ⁻¹' t := fun _ hx => h hx
#align set.preimage_mono Set.preimage_mono
@[simp, mfld_simps]
theorem preimage_univ : f ⁻¹' univ = univ :=
rfl
#align set.preimage_univ Set.preimage_univ
theorem subset_preimage_univ {s : Set α} : s ⊆ f ⁻¹' univ :=
subset_univ _
#align set.subset_preimage_univ Set.subset_preimage_univ
@[simp, mfld_simps]
theorem preimage_inter {s t : Set β} : f ⁻¹' (s ∩ t) = f ⁻¹' s ∩ f ⁻¹' t :=
rfl
#align set.preimage_inter Set.preimage_inter
@[simp]
theorem preimage_union {s t : Set β} : f ⁻¹' (s ∪ t) = f ⁻¹' s ∪ f ⁻¹' t :=
rfl
#align set.preimage_union Set.preimage_union
@[simp]
theorem preimage_compl {s : Set β} : f ⁻¹' sᶜ = (f ⁻¹' s)ᶜ :=
rfl
#align set.preimage_compl Set.preimage_compl
@[simp]
theorem preimage_diff (f : α → β) (s t : Set β) : f ⁻¹' (s \ t) = f ⁻¹' s \ f ⁻¹' t :=
rfl
#align set.preimage_diff Set.preimage_diff
@[simp]
lemma preimage_symmDiff {f : α → β} (s t : Set β) : f ⁻¹' (s ∆ t) = (f ⁻¹' s) ∆ (f ⁻¹' t) :=
rfl
#align set.preimage_symm_diff Set.preimage_symmDiff
@[simp]
theorem preimage_ite (f : α → β) (s t₁ t₂ : Set β) :
f ⁻¹' s.ite t₁ t₂ = (f ⁻¹' s).ite (f ⁻¹' t₁) (f ⁻¹' t₂) :=
rfl
#align set.preimage_ite Set.preimage_ite
@[simp]
theorem preimage_setOf_eq {p : α → Prop} {f : β → α} : f ⁻¹' { a | p a } = { a | p (f a) } :=
rfl
#align set.preimage_set_of_eq Set.preimage_setOf_eq
@[simp]
theorem preimage_id_eq : preimage (id : α → α) = id :=
rfl
#align set.preimage_id_eq Set.preimage_id_eq
@[mfld_simps]
theorem preimage_id {s : Set α} : id ⁻¹' s = s :=
rfl
#align set.preimage_id Set.preimage_id
@[simp, mfld_simps]
theorem preimage_id' {s : Set α} : (fun x => x) ⁻¹' s = s :=
rfl
#align set.preimage_id' Set.preimage_id'
@[simp]
theorem preimage_const_of_mem {b : β} {s : Set β} (h : b ∈ s) : (fun _ : α => b) ⁻¹' s = univ :=
eq_univ_of_forall fun _ => h
#align set.preimage_const_of_mem Set.preimage_const_of_mem
@[simp]
theorem preimage_const_of_not_mem {b : β} {s : Set β} (h : b ∉ s) : (fun _ : α => b) ⁻¹' s = ∅ :=
eq_empty_of_subset_empty fun _ hx => h hx
#align set.preimage_const_of_not_mem Set.preimage_const_of_not_mem
theorem preimage_const (b : β) (s : Set β) [Decidable (b ∈ s)] :
(fun _ : α => b) ⁻¹' s = if b ∈ s then univ else ∅ := by
split_ifs with hb
exacts [preimage_const_of_mem hb, preimage_const_of_not_mem hb]
#align set.preimage_const Set.preimage_const
/-- If preimage of each singleton under `f : α → β` is either empty or the whole type,
then `f` is a constant. -/
lemma exists_eq_const_of_preimage_singleton [Nonempty β] {f : α → β}
(hf : ∀ b : β, f ⁻¹' {b} = ∅ ∨ f ⁻¹' {b} = univ) : ∃ b, f = const α b := by
rcases em (∃ b, f ⁻¹' {b} = univ) with ⟨b, hb⟩ | hf'
· exact ⟨b, funext fun x ↦ eq_univ_iff_forall.1 hb x⟩
· have : ∀ x b, f x ≠ b := fun x b ↦
eq_empty_iff_forall_not_mem.1 ((hf b).resolve_right fun h ↦ hf' ⟨b, h⟩) x
exact ⟨Classical.arbitrary β, funext fun x ↦ absurd rfl (this x _)⟩
theorem preimage_comp {s : Set γ} : g ∘ f ⁻¹' s = f ⁻¹' (g ⁻¹' s) :=
rfl
#align set.preimage_comp Set.preimage_comp
theorem preimage_comp_eq : preimage (g ∘ f) = preimage f ∘ preimage g :=
rfl
#align set.preimage_comp_eq Set.preimage_comp_eq
theorem preimage_iterate_eq {f : α → α} {n : ℕ} : Set.preimage f^[n] = (Set.preimage f)^[n] := by
induction' n with n ih; · simp
rw [iterate_succ, iterate_succ', preimage_comp_eq, ih]
#align set.preimage_iterate_eq Set.preimage_iterate_eq
theorem preimage_preimage {g : β → γ} {f : α → β} {s : Set γ} :
f ⁻¹' (g ⁻¹' s) = (fun x => g (f x)) ⁻¹' s :=
preimage_comp.symm
#align set.preimage_preimage Set.preimage_preimage
theorem eq_preimage_subtype_val_iff {p : α → Prop} {s : Set (Subtype p)} {t : Set α} :
s = Subtype.val ⁻¹' t ↔ ∀ (x) (h : p x), (⟨x, h⟩ : Subtype p) ∈ s ↔ x ∈ t :=
⟨fun s_eq x h => by
rw [s_eq]
simp, fun h => ext fun ⟨x, hx⟩ => by simp [h]⟩
#align set.eq_preimage_subtype_val_iff Set.eq_preimage_subtype_val_iff
theorem nonempty_of_nonempty_preimage {s : Set β} {f : α → β} (hf : (f ⁻¹' s).Nonempty) :
s.Nonempty :=
let ⟨x, hx⟩ := hf
⟨f x, hx⟩
#align set.nonempty_of_nonempty_preimage Set.nonempty_of_nonempty_preimage
@[simp] theorem preimage_singleton_true (p : α → Prop) : p ⁻¹' {True} = {a | p a} := by ext; simp
#align set.preimage_singleton_true Set.preimage_singleton_true
@[simp] theorem preimage_singleton_false (p : α → Prop) : p ⁻¹' {False} = {a | ¬p a} := by ext; simp
#align set.preimage_singleton_false Set.preimage_singleton_false
theorem preimage_subtype_coe_eq_compl {s u v : Set α} (hsuv : s ⊆ u ∪ v)
(H : s ∩ (u ∩ v) = ∅) : ((↑) : s → α) ⁻¹' u = ((↑) ⁻¹' v)ᶜ := by
ext ⟨x, x_in_s⟩
constructor
· intro x_in_u x_in_v
exact eq_empty_iff_forall_not_mem.mp H x ⟨x_in_s, ⟨x_in_u, x_in_v⟩⟩
· intro hx
exact Or.elim (hsuv x_in_s) id fun hx' => hx.elim hx'
#align set.preimage_subtype_coe_eq_compl Set.preimage_subtype_coe_eq_compl
end Preimage
/-! ### Image of a set under a function -/
section Image
variable {f : α → β} {s t : Set α}
-- Porting note: `Set.image` is already defined in `Init.Set`
#align set.image Set.image
/-- `f '' s` denotes the image of `s : Set α` under the function `f : α → β`. -/
infixl:80 " '' " => image
theorem mem_image_iff_bex {f : α → β} {s : Set α} {y : β} :
y ∈ f '' s ↔ ∃ (x : _) (_ : x ∈ s), f x = y :=
bex_def.symm
#align set.mem_image_iff_bex Set.mem_image_iff_bex
@[simp]
theorem mem_image (f : α → β) (s : Set α) (y : β) : y ∈ f '' s ↔ ∃ x ∈ s, f x = y :=
Iff.rfl
#align set.mem_image Set.mem_image
theorem image_eta (f : α → β) : f '' s = (fun x => f x) '' s :=
rfl
#align set.image_eta Set.image_eta
@[mfld_simps]
theorem mem_image_of_mem (f : α → β) {x : α} {a : Set α} (h : x ∈ a) : f x ∈ f '' a :=
⟨_, h, rfl⟩
#align set.mem_image_of_mem Set.mem_image_of_mem
theorem _root_.Function.Injective.mem_set_image {f : α → β} (hf : Injective f) {s : Set α} {a : α} :
f a ∈ f '' s ↔ a ∈ s :=
⟨fun ⟨_, hb, Eq⟩ => hf Eq ▸ hb, mem_image_of_mem f⟩
#align function.injective.mem_set_image Function.Injective.mem_set_image
theorem ball_image_iff {f : α → β} {s : Set α} {p : β → Prop} :
(∀ y ∈ f '' s, p y) ↔ ∀ x ∈ s, p (f x) := by simp
#align set.ball_image_iff Set.ball_image_iff
theorem ball_image_of_ball {f : α → β} {s : Set α} {p : β → Prop} (h : ∀ x ∈ s, p (f x)) :
∀ y ∈ f '' s, p y :=
ball_image_iff.2 h
#align set.ball_image_of_ball Set.ball_image_of_ball
theorem bex_image_iff {f : α → β} {s : Set α} {p : β → Prop} :
(∃ y ∈ f '' s, p y) ↔ ∃ x ∈ s, p (f x) := by simp
#align set.bex_image_iff Set.bex_image_iff
theorem mem_image_elim {f : α → β} {s : Set α} {C : β → Prop} (h : ∀ x : α, x ∈ s → C (f x)) :
∀ {y : β}, y ∈ f '' s → C y
| _, ⟨a, a_in, rfl⟩ => h a a_in
#align set.mem_image_elim Set.mem_image_elim
theorem mem_image_elim_on {f : α → β} {s : Set α} {C : β → Prop} {y : β} (h_y : y ∈ f '' s)
(h : ∀ x : α, x ∈ s → C (f x)) : C y :=
mem_image_elim h h_y
#align set.mem_image_elim_on Set.mem_image_elim_on
-- Porting note: used to be `safe`
@[congr]
theorem image_congr {f g : α → β} {s : Set α} (h : ∀ a ∈ s, f a = g a) : f '' s = g '' s := by
ext x
rw [mem_image, mem_image]
exact {
mp := by
rintro ⟨a, ha1, ha2⟩
exact ⟨a, ⟨ha1, (h a ha1) ▸ ha2⟩⟩,
mpr := by
rintro ⟨a, ha1, ha2⟩
exact ⟨a, ⟨ha1, (h a ha1) ▸ ha2⟩⟩
}
-- safe [ext_iff, iff_def]
#align set.image_congr Set.image_congr
/-- A common special case of `image_congr` -/
theorem image_congr' {f g : α → β} {s : Set α} (h : ∀ x : α, f x = g x) : f '' s = g '' s :=
image_congr fun x _ => h x
#align set.image_congr' Set.image_congr'
@[gcongr]
lemma image_mono (h : s ⊆ t) : f '' s ⊆ f '' t := by
rintro - ⟨a, ha, rfl⟩; exact mem_image_of_mem f (h ha)
theorem image_comp (f : β → γ) (g : α → β) (a : Set α) : f ∘ g '' a = f '' (g '' a) :=
Subset.antisymm (ball_image_of_ball fun _ ha => mem_image_of_mem _ <| mem_image_of_mem _ ha)
(ball_image_of_ball <| ball_image_of_ball fun _ ha => mem_image_of_mem _ ha)
#align set.image_comp Set.image_comp
theorem image_comp_eq {g : β → γ} : image (g ∘ f) = image g ∘ image f := by ext; simp
/-- A variant of `image_comp`, useful for rewriting -/
theorem image_image (g : β → γ) (f : α → β) (s : Set α) : g '' (f '' s) = (fun x => g (f x)) '' s :=
(image_comp g f s).symm
#align set.image_image Set.image_image
theorem image_comm {β'} {f : β → γ} {g : α → β} {f' : α → β'} {g' : β' → γ}
(h_comm : ∀ a, f (g a) = g' (f' a)) : (s.image g).image f = (s.image f').image g' := by
simp_rw [image_image, h_comm]
#align set.image_comm Set.image_comm
theorem _root_.Function.Semiconj.set_image {f : α → β} {ga : α → α} {gb : β → β}
(h : Function.Semiconj f ga gb) : Function.Semiconj (image f) (image ga) (image gb) := fun _ =>
image_comm h
#align function.semiconj.set_image Function.Semiconj.set_image
theorem _root_.Function.Commute.set_image {f g : α → α} (h : Function.Commute f g) :
Function.Commute (image f) (image g) :=
Function.Semiconj.set_image h
#align function.commute.set_image Function.Commute.set_image
/-- Image is monotone with respect to `⊆`. See `Set.monotone_image` for the statement in
terms of `≤`. -/
@[gcongr]
theorem image_subset {a b : Set α} (f : α → β) (h : a ⊆ b) : f '' a ⊆ f '' b := by
simp only [subset_def, mem_image]
exact fun x => fun ⟨w, h1, h2⟩ => ⟨w, h h1, h2⟩
#align set.image_subset Set.image_subset
/-- `Set.image` is monotone. See `Set.image_subset` for the statement in terms of `⊆`. -/
lemma monotone_image {f : α → β} : Monotone (image f) := fun _ _ => image_subset _
#align set.monotone_image Set.monotone_image
theorem image_union (f : α → β) (s t : Set α) : f '' (s ∪ t) = f '' s ∪ f '' t :=
ext fun x =>
⟨by rintro ⟨a, h | h, rfl⟩ <;> [left; right] <;> exact ⟨_, h, rfl⟩, by
rintro (⟨a, h, rfl⟩ | ⟨a, h, rfl⟩) <;> refine' ⟨_, _, rfl⟩ <;> [left; right] <;> exact h⟩
#align set.image_union Set.image_union
@[simp]
theorem image_empty (f : α → β) : f '' ∅ = ∅ := by
ext
simp
#align set.image_empty Set.image_empty
theorem image_inter_subset (f : α → β) (s t : Set α) : f '' (s ∩ t) ⊆ f '' s ∩ f '' t :=
subset_inter (image_subset _ <| inter_subset_left _ _) (image_subset _ <| inter_subset_right _ _)
#align set.image_inter_subset Set.image_inter_subset
theorem image_inter_on {f : α → β} {s t : Set α} (h : ∀ x ∈ t, ∀ y ∈ s, f x = f y → x = y) :
f '' (s ∩ t) = f '' s ∩ f '' t :=
(image_inter_subset _ _ _).antisymm
fun b ⟨⟨a₁, ha₁, h₁⟩, ⟨a₂, ha₂, h₂⟩⟩ ↦
have : a₂ = a₁ := h _ ha₂ _ ha₁ (by simp [*])
⟨a₁, ⟨ha₁, this ▸ ha₂⟩, h₁⟩
#align set.image_inter_on Set.image_inter_on
theorem image_inter {f : α → β} {s t : Set α} (H : Injective f) : f '' (s ∩ t) = f '' s ∩ f '' t :=
image_inter_on fun _ _ _ _ h => H h
#align set.image_inter Set.image_inter
theorem image_univ_of_surjective {ι : Type*} {f : ι → β} (H : Surjective f) : f '' univ = univ :=
eq_univ_of_forall <| by simpa [image]
#align set.image_univ_of_surjective Set.image_univ_of_surjective
@[simp]
theorem image_singleton {f : α → β} {a : α} : f '' {a} = {f a} := by
ext
simp [image, eq_comm]
#align set.image_singleton Set.image_singleton
@[simp]
theorem Nonempty.image_const {s : Set α} (hs : s.Nonempty) (a : β) : (fun _ => a) '' s = {a} :=
ext fun _ =>
⟨fun ⟨_, _, h⟩ => h ▸ mem_singleton _, fun h =>
(eq_of_mem_singleton h).symm ▸ hs.imp fun _ hy => ⟨hy, rfl⟩⟩
#align set.nonempty.image_const Set.Nonempty.image_const
@[simp, mfld_simps]
theorem image_eq_empty {α β} {f : α → β} {s : Set α} : f '' s = ∅ ↔ s = ∅ := by
simp only [eq_empty_iff_forall_not_mem]
exact ⟨fun H a ha => H _ ⟨_, ha, rfl⟩, fun H b ⟨_, ha, _⟩ => H _ ha⟩
#align set.image_eq_empty Set.image_eq_empty
-- Porting note: `compl` is already defined in `Init.Set`
theorem preimage_compl_eq_image_compl [BooleanAlgebra α] (S : Set α) :
HasCompl.compl ⁻¹' S = HasCompl.compl '' S :=
Set.ext fun x =>
⟨fun h => ⟨xᶜ, h, compl_compl x⟩, fun h =>
Exists.elim h fun _ hy => (compl_eq_comm.mp hy.2).symm.subst hy.1⟩
#align set.preimage_compl_eq_image_compl Set.preimage_compl_eq_image_compl
theorem mem_compl_image [BooleanAlgebra α] (t : α) (S : Set α) :
t ∈ HasCompl.compl '' S ↔ tᶜ ∈ S := by
simp [← preimage_compl_eq_image_compl]
#align set.mem_compl_image Set.mem_compl_image
@[simp]
theorem image_id_eq : image (id : α → α) = id := by ext; simp
/-- A variant of `image_id` -/
@[simp]
theorem image_id' (s : Set α) : (fun x => x) '' s = s := by
ext
simp
#align set.image_id' Set.image_id'
theorem image_id (s : Set α) : id '' s = s := by simp
#align set.image_id Set.image_id
lemma image_iterate_eq {f : α → α} {n : ℕ} : image (f^[n]) = (image f)^[n] := by
induction' n with n ih; · simp
rw [iterate_succ', iterate_succ',← ih, image_comp_eq]
theorem compl_compl_image [BooleanAlgebra α] (S : Set α) :
HasCompl.compl '' (HasCompl.compl '' S) = S := by
rw [← image_comp, compl_comp_compl, image_id]
#align set.compl_compl_image Set.compl_compl_image
theorem image_insert_eq {f : α → β} {a : α} {s : Set α} :
f '' insert a s = insert (f a) (f '' s) := by
ext
simp [and_or_left, exists_or, eq_comm, or_comm, and_comm]
#align set.image_insert_eq Set.image_insert_eq
theorem image_pair (f : α → β) (a b : α) : f '' {a, b} = {f a, f b} := by
simp only [image_insert_eq, image_singleton]
#align set.image_pair Set.image_pair
theorem image_subset_preimage_of_inverse {f : α → β} {g : β → α} (I : LeftInverse g f) (s : Set α) :
f '' s ⊆ g ⁻¹' s := fun _ ⟨a, h, e⟩ => e ▸ ((I a).symm ▸ h : g (f a) ∈ s)
#align set.image_subset_preimage_of_inverse Set.image_subset_preimage_of_inverse
theorem preimage_subset_image_of_inverse {f : α → β} {g : β → α} (I : LeftInverse g f) (s : Set β) :
f ⁻¹' s ⊆ g '' s := fun b h => ⟨f b, h, I b⟩
#align set.preimage_subset_image_of_inverse Set.preimage_subset_image_of_inverse
theorem image_eq_preimage_of_inverse {f : α → β} {g : β → α} (h₁ : LeftInverse g f)
(h₂ : RightInverse g f) : image f = preimage g :=
funext fun s =>
Subset.antisymm (image_subset_preimage_of_inverse h₁ s) (preimage_subset_image_of_inverse h₂ s)
#align set.image_eq_preimage_of_inverse Set.image_eq_preimage_of_inverse
theorem mem_image_iff_of_inverse {f : α → β} {g : β → α} {b : β} {s : Set α} (h₁ : LeftInverse g f)
(h₂ : RightInverse g f) : b ∈ f '' s ↔ g b ∈ s := by
rw [image_eq_preimage_of_inverse h₁ h₂]; rfl
#align set.mem_image_iff_of_inverse Set.mem_image_iff_of_inverse
theorem image_compl_subset {f : α → β} {s : Set α} (H : Injective f) : f '' sᶜ ⊆ (f '' s)ᶜ :=
Disjoint.subset_compl_left <| by simp [disjoint_iff_inf_le, ← image_inter H]
#align set.image_compl_subset Set.image_compl_subset
theorem subset_image_compl {f : α → β} {s : Set α} (H : Surjective f) : (f '' s)ᶜ ⊆ f '' sᶜ :=
compl_subset_iff_union.2 <| by
rw [← image_union]
simp [image_univ_of_surjective H]
#align set.subset_image_compl Set.subset_image_compl
theorem image_compl_eq {f : α → β} {s : Set α} (H : Bijective f) : f '' sᶜ = (f '' s)ᶜ :=
Subset.antisymm (image_compl_subset H.1) (subset_image_compl H.2)
#align set.image_compl_eq Set.image_compl_eq
theorem subset_image_diff (f : α → β) (s t : Set α) : f '' s \ f '' t ⊆ f '' (s \ t) := by
rw [diff_subset_iff, ← image_union, union_diff_self]
exact image_subset f (subset_union_right t s)
#align set.subset_image_diff Set.subset_image_diff
theorem subset_image_symmDiff : (f '' s) ∆ (f '' t) ⊆ f '' s ∆ t :=
(union_subset_union (subset_image_diff _ _ _) <| subset_image_diff _ _ _).trans
(superset_of_eq (image_union _ _ _))
#align set.subset_image_symm_diff Set.subset_image_symmDiff
theorem image_diff {f : α → β} (hf : Injective f) (s t : Set α) : f '' (s \ t) = f '' s \ f '' t :=
Subset.antisymm
(Subset.trans (image_inter_subset _ _ _) <| inter_subset_inter_right _ <| image_compl_subset hf)
(subset_image_diff f s t)
#align set.image_diff Set.image_diff
theorem image_symmDiff (hf : Injective f) (s t : Set α) : f '' s ∆ t = (f '' s) ∆ (f '' t) := by
simp_rw [Set.symmDiff_def, image_union, image_diff hf]
#align set.image_symm_diff Set.image_symmDiff
theorem Nonempty.image (f : α → β) {s : Set α} : s.Nonempty → (f '' s).Nonempty
| ⟨x, hx⟩ => ⟨f x, mem_image_of_mem f hx⟩
#align set.nonempty.image Set.Nonempty.image
theorem Nonempty.of_image {f : α → β} {s : Set α} : (f '' s).Nonempty → s.Nonempty
| ⟨_, x, hx, _⟩ => ⟨x, hx⟩
#align set.nonempty.of_image Set.Nonempty.of_image
@[simp]
theorem nonempty_image_iff {f : α → β} {s : Set α} : (f '' s).Nonempty ↔ s.Nonempty :=
⟨Nonempty.of_image, fun h => h.image f⟩
#align set.nonempty_image_iff Set.nonempty_image_iff
theorem Nonempty.preimage {s : Set β} (hs : s.Nonempty) {f : α → β} (hf : Surjective f) :
(f ⁻¹' s).Nonempty :=
let ⟨y, hy⟩ := hs
let ⟨x, hx⟩ := hf y
⟨x, mem_preimage.2 <| hx.symm ▸ hy⟩
#align set.nonempty.preimage Set.Nonempty.preimage
instance (f : α → β) (s : Set α) [Nonempty s] : Nonempty (f '' s) :=
(Set.Nonempty.image f nonempty_of_nonempty_subtype).to_subtype
/-- image and preimage are a Galois connection -/
@[simp]
theorem image_subset_iff {s : Set α} {t : Set β} {f : α → β} : f '' s ⊆ t ↔ s ⊆ f ⁻¹' t :=
ball_image_iff
#align set.image_subset_iff Set.image_subset_iff
theorem image_preimage_subset (f : α → β) (s : Set β) : f '' (f ⁻¹' s) ⊆ s :=
image_subset_iff.2 Subset.rfl
#align set.image_preimage_subset Set.image_preimage_subset
theorem subset_preimage_image (f : α → β) (s : Set α) : s ⊆ f ⁻¹' (f '' s) := fun _ =>
mem_image_of_mem f
#align set.subset_preimage_image Set.subset_preimage_image
@[simp]
theorem preimage_image_eq {f : α → β} (s : Set α) (h : Injective f) : f ⁻¹' (f '' s) = s :=
Subset.antisymm (fun _ ⟨_, hy, e⟩ => h e ▸ hy) (subset_preimage_image f s)
#align set.preimage_image_eq Set.preimage_image_eq
@[simp]
theorem image_preimage_eq {f : α → β} (s : Set β) (h : Surjective f) : f '' (f ⁻¹' s) = s :=
Subset.antisymm (image_preimage_subset f s) fun x hx =>
let ⟨y, e⟩ := h x
⟨y, (e.symm ▸ hx : f y ∈ s), e⟩
#align set.image_preimage_eq Set.image_preimage_eq
@[simp]
theorem preimage_eq_preimage {f : β → α} (hf : Surjective f) : f ⁻¹' s = f ⁻¹' t ↔ s = t :=
Iff.intro
fun eq => by rw [← image_preimage_eq s hf, ← image_preimage_eq t hf, eq]
fun eq => eq ▸ rfl
#align set.preimage_eq_preimage Set.preimage_eq_preimage
theorem image_inter_preimage (f : α → β) (s : Set α) (t : Set β) :
f '' (s ∩ f ⁻¹' t) = f '' s ∩ t := by
apply Subset.antisymm
· calc
f '' (s ∩ f ⁻¹' t) ⊆ f '' s ∩ f '' (f ⁻¹' t) := image_inter_subset _ _ _
_ ⊆ f '' s ∩ t := inter_subset_inter_right _ (image_preimage_subset f t)
· rintro _ ⟨⟨x, h', rfl⟩, h⟩
exact ⟨x, ⟨h', h⟩, rfl⟩
#align set.image_inter_preimage Set.image_inter_preimage
theorem image_preimage_inter (f : α → β) (s : Set α) (t : Set β) :
f '' (f ⁻¹' t ∩ s) = t ∩ f '' s := by simp only [inter_comm, image_inter_preimage]
#align set.image_preimage_inter Set.image_preimage_inter
@[simp]
theorem image_inter_nonempty_iff {f : α → β} {s : Set α} {t : Set β} :
(f '' s ∩ t).Nonempty ↔ (s ∩ f ⁻¹' t).Nonempty := by
rw [← image_inter_preimage, nonempty_image_iff]
#align set.image_inter_nonempty_iff Set.image_inter_nonempty_iff
theorem image_diff_preimage {f : α → β} {s : Set α} {t : Set β} : f '' (s \ f ⁻¹' t) = f '' s \ t :=
by simp_rw [diff_eq, ← preimage_compl, image_inter_preimage]
#align set.image_diff_preimage Set.image_diff_preimage
theorem compl_image : image (compl : Set α → Set α) = preimage compl :=
image_eq_preimage_of_inverse compl_compl compl_compl
#align set.compl_image Set.compl_image
theorem compl_image_set_of {p : Set α → Prop} : compl '' { s | p s } = { s | p sᶜ } :=
congr_fun compl_image p
#align set.compl_image_set_of Set.compl_image_set_of
theorem inter_preimage_subset (s : Set α) (t : Set β) (f : α → β) :
s ∩ f ⁻¹' t ⊆ f ⁻¹' (f '' s ∩ t) := fun _ h => ⟨mem_image_of_mem _ h.left, h.right⟩
#align set.inter_preimage_subset Set.inter_preimage_subset
theorem union_preimage_subset (s : Set α) (t : Set β) (f : α → β) :
s ∪ f ⁻¹' t ⊆ f ⁻¹' (f '' s ∪ t) := fun _ h =>
Or.elim h (fun l => Or.inl <| mem_image_of_mem _ l) fun r => Or.inr r
#align set.union_preimage_subset Set.union_preimage_subset
theorem subset_image_union (f : α → β) (s : Set α) (t : Set β) : f '' (s ∪ f ⁻¹' t) ⊆ f '' s ∪ t :=
image_subset_iff.2 (union_preimage_subset _ _ _)
#align set.subset_image_union Set.subset_image_union
theorem preimage_subset_iff {A : Set α} {B : Set β} {f : α → β} :
f ⁻¹' B ⊆ A ↔ ∀ a : α, f a ∈ B → a ∈ A :=
Iff.rfl
#align set.preimage_subset_iff Set.preimage_subset_iff
theorem image_eq_image {f : α → β} (hf : Injective f) : f '' s = f '' t ↔ s = t :=
Iff.symm <|
(Iff.intro fun eq => eq ▸ rfl) fun eq => by
rw [← preimage_image_eq s hf, ← preimage_image_eq t hf, eq]
#align set.image_eq_image Set.image_eq_image
theorem image_subset_image_iff {f : α → β} (hf : Injective f) : f '' s ⊆ f '' t ↔ s ⊆ t := by
refine' Iff.symm <| (Iff.intro (image_subset f)) fun h => _
rw [← preimage_image_eq s hf, ← preimage_image_eq t hf]
exact preimage_mono h
#align set.image_subset_image_iff Set.image_subset_image_iff
theorem prod_quotient_preimage_eq_image [s : Setoid α] (g : Quotient s → β) {h : α → β}
(Hh : h = g ∘ Quotient.mk'') (r : Set (β × β)) :
{ x : Quotient s × Quotient s | (g x.1, g x.2) ∈ r } =
(fun a : α × α => (⟦a.1⟧, ⟦a.2⟧)) '' ((fun a : α × α => (h a.1, h a.2)) ⁻¹' r) :=
Hh.symm ▸
Set.ext fun ⟨a₁, a₂⟩ =>
⟨Quot.induction_on₂ a₁ a₂ fun a₁ a₂ h => ⟨(a₁, a₂), h, rfl⟩, fun ⟨⟨b₁, b₂⟩, h₁, h₂⟩ =>
show (g a₁, g a₂) ∈ r from
have h₃ : ⟦b₁⟧ = a₁ ∧ ⟦b₂⟧ = a₂ := Prod.ext_iff.1 h₂
h₃.1 ▸ h₃.2 ▸ h₁⟩
#align set.prod_quotient_preimage_eq_image Set.prod_quotient_preimage_eq_image
theorem exists_image_iff (f : α → β) (x : Set α) (P : β → Prop) :
(∃ a : f '' x, P a) ↔ ∃ a : x, P (f a) :=
⟨fun ⟨a, h⟩ => ⟨⟨_, a.prop.choose_spec.1⟩, a.prop.choose_spec.2.symm ▸ h⟩, fun ⟨a, h⟩ =>
⟨⟨_, _, a.prop, rfl⟩, h⟩⟩
#align set.exists_image_iff Set.exists_image_iff
/-- Restriction of `f` to `s` factors through `s.imageFactorization f : s → f '' s`. -/
def imageFactorization (f : α → β) (s : Set α) : s → f '' s := fun p =>
⟨f p.1, mem_image_of_mem f p.2⟩
#align set.image_factorization Set.imageFactorization
theorem imageFactorization_eq {f : α → β} {s : Set α} :
Subtype.val ∘ imageFactorization f s = f ∘ Subtype.val :=
funext fun _ => rfl
#align set.image_factorization_eq Set.imageFactorization_eq
theorem surjective_onto_image {f : α → β} {s : Set α} : Surjective (imageFactorization f s) :=
fun ⟨_, ⟨a, ha, rfl⟩⟩ => ⟨⟨a, ha⟩, rfl⟩
#align set.surjective_onto_image Set.surjective_onto_image
/-- If the only elements outside `s` are those left fixed by `σ`, then mapping by `σ` has no effect.
-/
theorem image_perm {s : Set α} {σ : Equiv.Perm α} (hs : { a : α | σ a ≠ a } ⊆ s) : σ '' s = s := by
ext i
obtain hi | hi := eq_or_ne (σ i) i
· refine' ⟨_, fun h => ⟨i, h, hi⟩⟩
rintro ⟨j, hj, h⟩
rwa [σ.injective (hi.trans h.symm)]
· refine' iff_of_true ⟨σ.symm i, hs fun h => hi _, σ.apply_symm_apply _⟩ (hs hi)
convert congr_arg σ h <;>
|
exact (σ.apply_symm_apply _).symm
|
/-- If the only elements outside `s` are those left fixed by `σ`, then mapping by `σ` has no effect.
-/
theorem image_perm {s : Set α} {σ : Equiv.Perm α} (hs : { a : α | σ a ≠ a } ⊆ s) : σ '' s = s := by
ext i
obtain hi | hi := eq_or_ne (σ i) i
· refine' ⟨_, fun h => ⟨i, h, hi⟩⟩
rintro ⟨j, hj, h⟩
rwa [σ.injective (hi.trans h.symm)]
· refine' iff_of_true ⟨σ.symm i, hs fun h => hi _, σ.apply_symm_apply _⟩ (hs hi)
convert congr_arg σ h <;>
|
Mathlib.Data.Set.Image.635_0.IJFiTzmYGOCpPSd
|
/-- If the only elements outside `s` are those left fixed by `σ`, then mapping by `σ` has no effect.
-/
theorem image_perm {s : Set α} {σ : Equiv.Perm α} (hs : { a : α | σ a ≠ a } ⊆ s) : σ '' s = s
|
Mathlib_Data_Set_Image
|
case h.e'_3
α : Type u_1
β : Type u_2
γ : Type u_3
ι : Sort u_4
ι' : Sort u_5
f : α → β
s✝ t s : Set α
σ : Equiv.Perm α
hs : {a | σ a ≠ a} ⊆ s
i : α
hi : σ i ≠ i
h : σ (σ.symm i) = σ.symm i
⊢ i = σ (σ.symm i)
|
/-
Copyright (c) 2014 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Leonardo de Moura
-/
import Mathlib.Data.Set.Basic
#align_import data.set.image from "leanprover-community/mathlib"@"001ffdc42920050657fd45bd2b8bfbec8eaaeb29"
/-!
# Images and preimages of sets
## Main definitions
* `preimage f t : Set α` : the preimage f⁻¹(t) (written `f ⁻¹' t` in Lean) of a subset of β.
* `range f : Set β` : the image of `univ` under `f`.
Also works for `{p : Prop} (f : p → α)` (unlike `image`)
## Notation
* `f ⁻¹' t` for `Set.preimage f t`
* `f '' s` for `Set.image f s`
## Tags
set, sets, image, preimage, pre-image, range
-/
set_option autoImplicit true
universe u v
open Function Set
namespace Set
variable {α β γ : Type*} {ι ι' : Sort*}
/-! ### Inverse image -/
/-- The preimage of `s : Set β` by `f : α → β`, written `f ⁻¹' s`,
is the set of `x : α` such that `f x ∈ s`. -/
def preimage {α : Type u} {β : Type v} (f : α → β) (s : Set β) : Set α :=
{ x | f x ∈ s }
#align set.preimage Set.preimage
/-- `f ⁻¹' t` denotes the preimage of `t : Set β` under the function `f : α → β`. -/
infixl:80 " ⁻¹' " => preimage
section Preimage
variable {f : α → β} {g : β → γ}
@[simp]
theorem preimage_empty : f ⁻¹' ∅ = ∅ :=
rfl
#align set.preimage_empty Set.preimage_empty
@[simp, mfld_simps]
theorem mem_preimage {s : Set β} {a : α} : a ∈ f ⁻¹' s ↔ f a ∈ s :=
Iff.rfl
#align set.mem_preimage Set.mem_preimage
theorem preimage_congr {f g : α → β} {s : Set β} (h : ∀ x : α, f x = g x) : f ⁻¹' s = g ⁻¹' s := by
congr with x
simp [h]
#align set.preimage_congr Set.preimage_congr
@[gcongr]
theorem preimage_mono {s t : Set β} (h : s ⊆ t) : f ⁻¹' s ⊆ f ⁻¹' t := fun _ hx => h hx
#align set.preimage_mono Set.preimage_mono
@[simp, mfld_simps]
theorem preimage_univ : f ⁻¹' univ = univ :=
rfl
#align set.preimage_univ Set.preimage_univ
theorem subset_preimage_univ {s : Set α} : s ⊆ f ⁻¹' univ :=
subset_univ _
#align set.subset_preimage_univ Set.subset_preimage_univ
@[simp, mfld_simps]
theorem preimage_inter {s t : Set β} : f ⁻¹' (s ∩ t) = f ⁻¹' s ∩ f ⁻¹' t :=
rfl
#align set.preimage_inter Set.preimage_inter
@[simp]
theorem preimage_union {s t : Set β} : f ⁻¹' (s ∪ t) = f ⁻¹' s ∪ f ⁻¹' t :=
rfl
#align set.preimage_union Set.preimage_union
@[simp]
theorem preimage_compl {s : Set β} : f ⁻¹' sᶜ = (f ⁻¹' s)ᶜ :=
rfl
#align set.preimage_compl Set.preimage_compl
@[simp]
theorem preimage_diff (f : α → β) (s t : Set β) : f ⁻¹' (s \ t) = f ⁻¹' s \ f ⁻¹' t :=
rfl
#align set.preimage_diff Set.preimage_diff
@[simp]
lemma preimage_symmDiff {f : α → β} (s t : Set β) : f ⁻¹' (s ∆ t) = (f ⁻¹' s) ∆ (f ⁻¹' t) :=
rfl
#align set.preimage_symm_diff Set.preimage_symmDiff
@[simp]
theorem preimage_ite (f : α → β) (s t₁ t₂ : Set β) :
f ⁻¹' s.ite t₁ t₂ = (f ⁻¹' s).ite (f ⁻¹' t₁) (f ⁻¹' t₂) :=
rfl
#align set.preimage_ite Set.preimage_ite
@[simp]
theorem preimage_setOf_eq {p : α → Prop} {f : β → α} : f ⁻¹' { a | p a } = { a | p (f a) } :=
rfl
#align set.preimage_set_of_eq Set.preimage_setOf_eq
@[simp]
theorem preimage_id_eq : preimage (id : α → α) = id :=
rfl
#align set.preimage_id_eq Set.preimage_id_eq
@[mfld_simps]
theorem preimage_id {s : Set α} : id ⁻¹' s = s :=
rfl
#align set.preimage_id Set.preimage_id
@[simp, mfld_simps]
theorem preimage_id' {s : Set α} : (fun x => x) ⁻¹' s = s :=
rfl
#align set.preimage_id' Set.preimage_id'
@[simp]
theorem preimage_const_of_mem {b : β} {s : Set β} (h : b ∈ s) : (fun _ : α => b) ⁻¹' s = univ :=
eq_univ_of_forall fun _ => h
#align set.preimage_const_of_mem Set.preimage_const_of_mem
@[simp]
theorem preimage_const_of_not_mem {b : β} {s : Set β} (h : b ∉ s) : (fun _ : α => b) ⁻¹' s = ∅ :=
eq_empty_of_subset_empty fun _ hx => h hx
#align set.preimage_const_of_not_mem Set.preimage_const_of_not_mem
theorem preimage_const (b : β) (s : Set β) [Decidable (b ∈ s)] :
(fun _ : α => b) ⁻¹' s = if b ∈ s then univ else ∅ := by
split_ifs with hb
exacts [preimage_const_of_mem hb, preimage_const_of_not_mem hb]
#align set.preimage_const Set.preimage_const
/-- If preimage of each singleton under `f : α → β` is either empty or the whole type,
then `f` is a constant. -/
lemma exists_eq_const_of_preimage_singleton [Nonempty β] {f : α → β}
(hf : ∀ b : β, f ⁻¹' {b} = ∅ ∨ f ⁻¹' {b} = univ) : ∃ b, f = const α b := by
rcases em (∃ b, f ⁻¹' {b} = univ) with ⟨b, hb⟩ | hf'
· exact ⟨b, funext fun x ↦ eq_univ_iff_forall.1 hb x⟩
· have : ∀ x b, f x ≠ b := fun x b ↦
eq_empty_iff_forall_not_mem.1 ((hf b).resolve_right fun h ↦ hf' ⟨b, h⟩) x
exact ⟨Classical.arbitrary β, funext fun x ↦ absurd rfl (this x _)⟩
theorem preimage_comp {s : Set γ} : g ∘ f ⁻¹' s = f ⁻¹' (g ⁻¹' s) :=
rfl
#align set.preimage_comp Set.preimage_comp
theorem preimage_comp_eq : preimage (g ∘ f) = preimage f ∘ preimage g :=
rfl
#align set.preimage_comp_eq Set.preimage_comp_eq
theorem preimage_iterate_eq {f : α → α} {n : ℕ} : Set.preimage f^[n] = (Set.preimage f)^[n] := by
induction' n with n ih; · simp
rw [iterate_succ, iterate_succ', preimage_comp_eq, ih]
#align set.preimage_iterate_eq Set.preimage_iterate_eq
theorem preimage_preimage {g : β → γ} {f : α → β} {s : Set γ} :
f ⁻¹' (g ⁻¹' s) = (fun x => g (f x)) ⁻¹' s :=
preimage_comp.symm
#align set.preimage_preimage Set.preimage_preimage
theorem eq_preimage_subtype_val_iff {p : α → Prop} {s : Set (Subtype p)} {t : Set α} :
s = Subtype.val ⁻¹' t ↔ ∀ (x) (h : p x), (⟨x, h⟩ : Subtype p) ∈ s ↔ x ∈ t :=
⟨fun s_eq x h => by
rw [s_eq]
simp, fun h => ext fun ⟨x, hx⟩ => by simp [h]⟩
#align set.eq_preimage_subtype_val_iff Set.eq_preimage_subtype_val_iff
theorem nonempty_of_nonempty_preimage {s : Set β} {f : α → β} (hf : (f ⁻¹' s).Nonempty) :
s.Nonempty :=
let ⟨x, hx⟩ := hf
⟨f x, hx⟩
#align set.nonempty_of_nonempty_preimage Set.nonempty_of_nonempty_preimage
@[simp] theorem preimage_singleton_true (p : α → Prop) : p ⁻¹' {True} = {a | p a} := by ext; simp
#align set.preimage_singleton_true Set.preimage_singleton_true
@[simp] theorem preimage_singleton_false (p : α → Prop) : p ⁻¹' {False} = {a | ¬p a} := by ext; simp
#align set.preimage_singleton_false Set.preimage_singleton_false
theorem preimage_subtype_coe_eq_compl {s u v : Set α} (hsuv : s ⊆ u ∪ v)
(H : s ∩ (u ∩ v) = ∅) : ((↑) : s → α) ⁻¹' u = ((↑) ⁻¹' v)ᶜ := by
ext ⟨x, x_in_s⟩
constructor
· intro x_in_u x_in_v
exact eq_empty_iff_forall_not_mem.mp H x ⟨x_in_s, ⟨x_in_u, x_in_v⟩⟩
· intro hx
exact Or.elim (hsuv x_in_s) id fun hx' => hx.elim hx'
#align set.preimage_subtype_coe_eq_compl Set.preimage_subtype_coe_eq_compl
end Preimage
/-! ### Image of a set under a function -/
section Image
variable {f : α → β} {s t : Set α}
-- Porting note: `Set.image` is already defined in `Init.Set`
#align set.image Set.image
/-- `f '' s` denotes the image of `s : Set α` under the function `f : α → β`. -/
infixl:80 " '' " => image
theorem mem_image_iff_bex {f : α → β} {s : Set α} {y : β} :
y ∈ f '' s ↔ ∃ (x : _) (_ : x ∈ s), f x = y :=
bex_def.symm
#align set.mem_image_iff_bex Set.mem_image_iff_bex
@[simp]
theorem mem_image (f : α → β) (s : Set α) (y : β) : y ∈ f '' s ↔ ∃ x ∈ s, f x = y :=
Iff.rfl
#align set.mem_image Set.mem_image
theorem image_eta (f : α → β) : f '' s = (fun x => f x) '' s :=
rfl
#align set.image_eta Set.image_eta
@[mfld_simps]
theorem mem_image_of_mem (f : α → β) {x : α} {a : Set α} (h : x ∈ a) : f x ∈ f '' a :=
⟨_, h, rfl⟩
#align set.mem_image_of_mem Set.mem_image_of_mem
theorem _root_.Function.Injective.mem_set_image {f : α → β} (hf : Injective f) {s : Set α} {a : α} :
f a ∈ f '' s ↔ a ∈ s :=
⟨fun ⟨_, hb, Eq⟩ => hf Eq ▸ hb, mem_image_of_mem f⟩
#align function.injective.mem_set_image Function.Injective.mem_set_image
theorem ball_image_iff {f : α → β} {s : Set α} {p : β → Prop} :
(∀ y ∈ f '' s, p y) ↔ ∀ x ∈ s, p (f x) := by simp
#align set.ball_image_iff Set.ball_image_iff
theorem ball_image_of_ball {f : α → β} {s : Set α} {p : β → Prop} (h : ∀ x ∈ s, p (f x)) :
∀ y ∈ f '' s, p y :=
ball_image_iff.2 h
#align set.ball_image_of_ball Set.ball_image_of_ball
theorem bex_image_iff {f : α → β} {s : Set α} {p : β → Prop} :
(∃ y ∈ f '' s, p y) ↔ ∃ x ∈ s, p (f x) := by simp
#align set.bex_image_iff Set.bex_image_iff
theorem mem_image_elim {f : α → β} {s : Set α} {C : β → Prop} (h : ∀ x : α, x ∈ s → C (f x)) :
∀ {y : β}, y ∈ f '' s → C y
| _, ⟨a, a_in, rfl⟩ => h a a_in
#align set.mem_image_elim Set.mem_image_elim
theorem mem_image_elim_on {f : α → β} {s : Set α} {C : β → Prop} {y : β} (h_y : y ∈ f '' s)
(h : ∀ x : α, x ∈ s → C (f x)) : C y :=
mem_image_elim h h_y
#align set.mem_image_elim_on Set.mem_image_elim_on
-- Porting note: used to be `safe`
@[congr]
theorem image_congr {f g : α → β} {s : Set α} (h : ∀ a ∈ s, f a = g a) : f '' s = g '' s := by
ext x
rw [mem_image, mem_image]
exact {
mp := by
rintro ⟨a, ha1, ha2⟩
exact ⟨a, ⟨ha1, (h a ha1) ▸ ha2⟩⟩,
mpr := by
rintro ⟨a, ha1, ha2⟩
exact ⟨a, ⟨ha1, (h a ha1) ▸ ha2⟩⟩
}
-- safe [ext_iff, iff_def]
#align set.image_congr Set.image_congr
/-- A common special case of `image_congr` -/
theorem image_congr' {f g : α → β} {s : Set α} (h : ∀ x : α, f x = g x) : f '' s = g '' s :=
image_congr fun x _ => h x
#align set.image_congr' Set.image_congr'
@[gcongr]
lemma image_mono (h : s ⊆ t) : f '' s ⊆ f '' t := by
rintro - ⟨a, ha, rfl⟩; exact mem_image_of_mem f (h ha)
theorem image_comp (f : β → γ) (g : α → β) (a : Set α) : f ∘ g '' a = f '' (g '' a) :=
Subset.antisymm (ball_image_of_ball fun _ ha => mem_image_of_mem _ <| mem_image_of_mem _ ha)
(ball_image_of_ball <| ball_image_of_ball fun _ ha => mem_image_of_mem _ ha)
#align set.image_comp Set.image_comp
theorem image_comp_eq {g : β → γ} : image (g ∘ f) = image g ∘ image f := by ext; simp
/-- A variant of `image_comp`, useful for rewriting -/
theorem image_image (g : β → γ) (f : α → β) (s : Set α) : g '' (f '' s) = (fun x => g (f x)) '' s :=
(image_comp g f s).symm
#align set.image_image Set.image_image
theorem image_comm {β'} {f : β → γ} {g : α → β} {f' : α → β'} {g' : β' → γ}
(h_comm : ∀ a, f (g a) = g' (f' a)) : (s.image g).image f = (s.image f').image g' := by
simp_rw [image_image, h_comm]
#align set.image_comm Set.image_comm
theorem _root_.Function.Semiconj.set_image {f : α → β} {ga : α → α} {gb : β → β}
(h : Function.Semiconj f ga gb) : Function.Semiconj (image f) (image ga) (image gb) := fun _ =>
image_comm h
#align function.semiconj.set_image Function.Semiconj.set_image
theorem _root_.Function.Commute.set_image {f g : α → α} (h : Function.Commute f g) :
Function.Commute (image f) (image g) :=
Function.Semiconj.set_image h
#align function.commute.set_image Function.Commute.set_image
/-- Image is monotone with respect to `⊆`. See `Set.monotone_image` for the statement in
terms of `≤`. -/
@[gcongr]
theorem image_subset {a b : Set α} (f : α → β) (h : a ⊆ b) : f '' a ⊆ f '' b := by
simp only [subset_def, mem_image]
exact fun x => fun ⟨w, h1, h2⟩ => ⟨w, h h1, h2⟩
#align set.image_subset Set.image_subset
/-- `Set.image` is monotone. See `Set.image_subset` for the statement in terms of `⊆`. -/
lemma monotone_image {f : α → β} : Monotone (image f) := fun _ _ => image_subset _
#align set.monotone_image Set.monotone_image
theorem image_union (f : α → β) (s t : Set α) : f '' (s ∪ t) = f '' s ∪ f '' t :=
ext fun x =>
⟨by rintro ⟨a, h | h, rfl⟩ <;> [left; right] <;> exact ⟨_, h, rfl⟩, by
rintro (⟨a, h, rfl⟩ | ⟨a, h, rfl⟩) <;> refine' ⟨_, _, rfl⟩ <;> [left; right] <;> exact h⟩
#align set.image_union Set.image_union
@[simp]
theorem image_empty (f : α → β) : f '' ∅ = ∅ := by
ext
simp
#align set.image_empty Set.image_empty
theorem image_inter_subset (f : α → β) (s t : Set α) : f '' (s ∩ t) ⊆ f '' s ∩ f '' t :=
subset_inter (image_subset _ <| inter_subset_left _ _) (image_subset _ <| inter_subset_right _ _)
#align set.image_inter_subset Set.image_inter_subset
theorem image_inter_on {f : α → β} {s t : Set α} (h : ∀ x ∈ t, ∀ y ∈ s, f x = f y → x = y) :
f '' (s ∩ t) = f '' s ∩ f '' t :=
(image_inter_subset _ _ _).antisymm
fun b ⟨⟨a₁, ha₁, h₁⟩, ⟨a₂, ha₂, h₂⟩⟩ ↦
have : a₂ = a₁ := h _ ha₂ _ ha₁ (by simp [*])
⟨a₁, ⟨ha₁, this ▸ ha₂⟩, h₁⟩
#align set.image_inter_on Set.image_inter_on
theorem image_inter {f : α → β} {s t : Set α} (H : Injective f) : f '' (s ∩ t) = f '' s ∩ f '' t :=
image_inter_on fun _ _ _ _ h => H h
#align set.image_inter Set.image_inter
theorem image_univ_of_surjective {ι : Type*} {f : ι → β} (H : Surjective f) : f '' univ = univ :=
eq_univ_of_forall <| by simpa [image]
#align set.image_univ_of_surjective Set.image_univ_of_surjective
@[simp]
theorem image_singleton {f : α → β} {a : α} : f '' {a} = {f a} := by
ext
simp [image, eq_comm]
#align set.image_singleton Set.image_singleton
@[simp]
theorem Nonempty.image_const {s : Set α} (hs : s.Nonempty) (a : β) : (fun _ => a) '' s = {a} :=
ext fun _ =>
⟨fun ⟨_, _, h⟩ => h ▸ mem_singleton _, fun h =>
(eq_of_mem_singleton h).symm ▸ hs.imp fun _ hy => ⟨hy, rfl⟩⟩
#align set.nonempty.image_const Set.Nonempty.image_const
@[simp, mfld_simps]
theorem image_eq_empty {α β} {f : α → β} {s : Set α} : f '' s = ∅ ↔ s = ∅ := by
simp only [eq_empty_iff_forall_not_mem]
exact ⟨fun H a ha => H _ ⟨_, ha, rfl⟩, fun H b ⟨_, ha, _⟩ => H _ ha⟩
#align set.image_eq_empty Set.image_eq_empty
-- Porting note: `compl` is already defined in `Init.Set`
theorem preimage_compl_eq_image_compl [BooleanAlgebra α] (S : Set α) :
HasCompl.compl ⁻¹' S = HasCompl.compl '' S :=
Set.ext fun x =>
⟨fun h => ⟨xᶜ, h, compl_compl x⟩, fun h =>
Exists.elim h fun _ hy => (compl_eq_comm.mp hy.2).symm.subst hy.1⟩
#align set.preimage_compl_eq_image_compl Set.preimage_compl_eq_image_compl
theorem mem_compl_image [BooleanAlgebra α] (t : α) (S : Set α) :
t ∈ HasCompl.compl '' S ↔ tᶜ ∈ S := by
simp [← preimage_compl_eq_image_compl]
#align set.mem_compl_image Set.mem_compl_image
@[simp]
theorem image_id_eq : image (id : α → α) = id := by ext; simp
/-- A variant of `image_id` -/
@[simp]
theorem image_id' (s : Set α) : (fun x => x) '' s = s := by
ext
simp
#align set.image_id' Set.image_id'
theorem image_id (s : Set α) : id '' s = s := by simp
#align set.image_id Set.image_id
lemma image_iterate_eq {f : α → α} {n : ℕ} : image (f^[n]) = (image f)^[n] := by
induction' n with n ih; · simp
rw [iterate_succ', iterate_succ',← ih, image_comp_eq]
theorem compl_compl_image [BooleanAlgebra α] (S : Set α) :
HasCompl.compl '' (HasCompl.compl '' S) = S := by
rw [← image_comp, compl_comp_compl, image_id]
#align set.compl_compl_image Set.compl_compl_image
theorem image_insert_eq {f : α → β} {a : α} {s : Set α} :
f '' insert a s = insert (f a) (f '' s) := by
ext
simp [and_or_left, exists_or, eq_comm, or_comm, and_comm]
#align set.image_insert_eq Set.image_insert_eq
theorem image_pair (f : α → β) (a b : α) : f '' {a, b} = {f a, f b} := by
simp only [image_insert_eq, image_singleton]
#align set.image_pair Set.image_pair
theorem image_subset_preimage_of_inverse {f : α → β} {g : β → α} (I : LeftInverse g f) (s : Set α) :
f '' s ⊆ g ⁻¹' s := fun _ ⟨a, h, e⟩ => e ▸ ((I a).symm ▸ h : g (f a) ∈ s)
#align set.image_subset_preimage_of_inverse Set.image_subset_preimage_of_inverse
theorem preimage_subset_image_of_inverse {f : α → β} {g : β → α} (I : LeftInverse g f) (s : Set β) :
f ⁻¹' s ⊆ g '' s := fun b h => ⟨f b, h, I b⟩
#align set.preimage_subset_image_of_inverse Set.preimage_subset_image_of_inverse
theorem image_eq_preimage_of_inverse {f : α → β} {g : β → α} (h₁ : LeftInverse g f)
(h₂ : RightInverse g f) : image f = preimage g :=
funext fun s =>
Subset.antisymm (image_subset_preimage_of_inverse h₁ s) (preimage_subset_image_of_inverse h₂ s)
#align set.image_eq_preimage_of_inverse Set.image_eq_preimage_of_inverse
theorem mem_image_iff_of_inverse {f : α → β} {g : β → α} {b : β} {s : Set α} (h₁ : LeftInverse g f)
(h₂ : RightInverse g f) : b ∈ f '' s ↔ g b ∈ s := by
rw [image_eq_preimage_of_inverse h₁ h₂]; rfl
#align set.mem_image_iff_of_inverse Set.mem_image_iff_of_inverse
theorem image_compl_subset {f : α → β} {s : Set α} (H : Injective f) : f '' sᶜ ⊆ (f '' s)ᶜ :=
Disjoint.subset_compl_left <| by simp [disjoint_iff_inf_le, ← image_inter H]
#align set.image_compl_subset Set.image_compl_subset
theorem subset_image_compl {f : α → β} {s : Set α} (H : Surjective f) : (f '' s)ᶜ ⊆ f '' sᶜ :=
compl_subset_iff_union.2 <| by
rw [← image_union]
simp [image_univ_of_surjective H]
#align set.subset_image_compl Set.subset_image_compl
theorem image_compl_eq {f : α → β} {s : Set α} (H : Bijective f) : f '' sᶜ = (f '' s)ᶜ :=
Subset.antisymm (image_compl_subset H.1) (subset_image_compl H.2)
#align set.image_compl_eq Set.image_compl_eq
theorem subset_image_diff (f : α → β) (s t : Set α) : f '' s \ f '' t ⊆ f '' (s \ t) := by
rw [diff_subset_iff, ← image_union, union_diff_self]
exact image_subset f (subset_union_right t s)
#align set.subset_image_diff Set.subset_image_diff
theorem subset_image_symmDiff : (f '' s) ∆ (f '' t) ⊆ f '' s ∆ t :=
(union_subset_union (subset_image_diff _ _ _) <| subset_image_diff _ _ _).trans
(superset_of_eq (image_union _ _ _))
#align set.subset_image_symm_diff Set.subset_image_symmDiff
theorem image_diff {f : α → β} (hf : Injective f) (s t : Set α) : f '' (s \ t) = f '' s \ f '' t :=
Subset.antisymm
(Subset.trans (image_inter_subset _ _ _) <| inter_subset_inter_right _ <| image_compl_subset hf)
(subset_image_diff f s t)
#align set.image_diff Set.image_diff
theorem image_symmDiff (hf : Injective f) (s t : Set α) : f '' s ∆ t = (f '' s) ∆ (f '' t) := by
simp_rw [Set.symmDiff_def, image_union, image_diff hf]
#align set.image_symm_diff Set.image_symmDiff
theorem Nonempty.image (f : α → β) {s : Set α} : s.Nonempty → (f '' s).Nonempty
| ⟨x, hx⟩ => ⟨f x, mem_image_of_mem f hx⟩
#align set.nonempty.image Set.Nonempty.image
theorem Nonempty.of_image {f : α → β} {s : Set α} : (f '' s).Nonempty → s.Nonempty
| ⟨_, x, hx, _⟩ => ⟨x, hx⟩
#align set.nonempty.of_image Set.Nonempty.of_image
@[simp]
theorem nonempty_image_iff {f : α → β} {s : Set α} : (f '' s).Nonempty ↔ s.Nonempty :=
⟨Nonempty.of_image, fun h => h.image f⟩
#align set.nonempty_image_iff Set.nonempty_image_iff
theorem Nonempty.preimage {s : Set β} (hs : s.Nonempty) {f : α → β} (hf : Surjective f) :
(f ⁻¹' s).Nonempty :=
let ⟨y, hy⟩ := hs
let ⟨x, hx⟩ := hf y
⟨x, mem_preimage.2 <| hx.symm ▸ hy⟩
#align set.nonempty.preimage Set.Nonempty.preimage
instance (f : α → β) (s : Set α) [Nonempty s] : Nonempty (f '' s) :=
(Set.Nonempty.image f nonempty_of_nonempty_subtype).to_subtype
/-- image and preimage are a Galois connection -/
@[simp]
theorem image_subset_iff {s : Set α} {t : Set β} {f : α → β} : f '' s ⊆ t ↔ s ⊆ f ⁻¹' t :=
ball_image_iff
#align set.image_subset_iff Set.image_subset_iff
theorem image_preimage_subset (f : α → β) (s : Set β) : f '' (f ⁻¹' s) ⊆ s :=
image_subset_iff.2 Subset.rfl
#align set.image_preimage_subset Set.image_preimage_subset
theorem subset_preimage_image (f : α → β) (s : Set α) : s ⊆ f ⁻¹' (f '' s) := fun _ =>
mem_image_of_mem f
#align set.subset_preimage_image Set.subset_preimage_image
@[simp]
theorem preimage_image_eq {f : α → β} (s : Set α) (h : Injective f) : f ⁻¹' (f '' s) = s :=
Subset.antisymm (fun _ ⟨_, hy, e⟩ => h e ▸ hy) (subset_preimage_image f s)
#align set.preimage_image_eq Set.preimage_image_eq
@[simp]
theorem image_preimage_eq {f : α → β} (s : Set β) (h : Surjective f) : f '' (f ⁻¹' s) = s :=
Subset.antisymm (image_preimage_subset f s) fun x hx =>
let ⟨y, e⟩ := h x
⟨y, (e.symm ▸ hx : f y ∈ s), e⟩
#align set.image_preimage_eq Set.image_preimage_eq
@[simp]
theorem preimage_eq_preimage {f : β → α} (hf : Surjective f) : f ⁻¹' s = f ⁻¹' t ↔ s = t :=
Iff.intro
fun eq => by rw [← image_preimage_eq s hf, ← image_preimage_eq t hf, eq]
fun eq => eq ▸ rfl
#align set.preimage_eq_preimage Set.preimage_eq_preimage
theorem image_inter_preimage (f : α → β) (s : Set α) (t : Set β) :
f '' (s ∩ f ⁻¹' t) = f '' s ∩ t := by
apply Subset.antisymm
· calc
f '' (s ∩ f ⁻¹' t) ⊆ f '' s ∩ f '' (f ⁻¹' t) := image_inter_subset _ _ _
_ ⊆ f '' s ∩ t := inter_subset_inter_right _ (image_preimage_subset f t)
· rintro _ ⟨⟨x, h', rfl⟩, h⟩
exact ⟨x, ⟨h', h⟩, rfl⟩
#align set.image_inter_preimage Set.image_inter_preimage
theorem image_preimage_inter (f : α → β) (s : Set α) (t : Set β) :
f '' (f ⁻¹' t ∩ s) = t ∩ f '' s := by simp only [inter_comm, image_inter_preimage]
#align set.image_preimage_inter Set.image_preimage_inter
@[simp]
theorem image_inter_nonempty_iff {f : α → β} {s : Set α} {t : Set β} :
(f '' s ∩ t).Nonempty ↔ (s ∩ f ⁻¹' t).Nonempty := by
rw [← image_inter_preimage, nonempty_image_iff]
#align set.image_inter_nonempty_iff Set.image_inter_nonempty_iff
theorem image_diff_preimage {f : α → β} {s : Set α} {t : Set β} : f '' (s \ f ⁻¹' t) = f '' s \ t :=
by simp_rw [diff_eq, ← preimage_compl, image_inter_preimage]
#align set.image_diff_preimage Set.image_diff_preimage
theorem compl_image : image (compl : Set α → Set α) = preimage compl :=
image_eq_preimage_of_inverse compl_compl compl_compl
#align set.compl_image Set.compl_image
theorem compl_image_set_of {p : Set α → Prop} : compl '' { s | p s } = { s | p sᶜ } :=
congr_fun compl_image p
#align set.compl_image_set_of Set.compl_image_set_of
theorem inter_preimage_subset (s : Set α) (t : Set β) (f : α → β) :
s ∩ f ⁻¹' t ⊆ f ⁻¹' (f '' s ∩ t) := fun _ h => ⟨mem_image_of_mem _ h.left, h.right⟩
#align set.inter_preimage_subset Set.inter_preimage_subset
theorem union_preimage_subset (s : Set α) (t : Set β) (f : α → β) :
s ∪ f ⁻¹' t ⊆ f ⁻¹' (f '' s ∪ t) := fun _ h =>
Or.elim h (fun l => Or.inl <| mem_image_of_mem _ l) fun r => Or.inr r
#align set.union_preimage_subset Set.union_preimage_subset
theorem subset_image_union (f : α → β) (s : Set α) (t : Set β) : f '' (s ∪ f ⁻¹' t) ⊆ f '' s ∪ t :=
image_subset_iff.2 (union_preimage_subset _ _ _)
#align set.subset_image_union Set.subset_image_union
theorem preimage_subset_iff {A : Set α} {B : Set β} {f : α → β} :
f ⁻¹' B ⊆ A ↔ ∀ a : α, f a ∈ B → a ∈ A :=
Iff.rfl
#align set.preimage_subset_iff Set.preimage_subset_iff
theorem image_eq_image {f : α → β} (hf : Injective f) : f '' s = f '' t ↔ s = t :=
Iff.symm <|
(Iff.intro fun eq => eq ▸ rfl) fun eq => by
rw [← preimage_image_eq s hf, ← preimage_image_eq t hf, eq]
#align set.image_eq_image Set.image_eq_image
theorem image_subset_image_iff {f : α → β} (hf : Injective f) : f '' s ⊆ f '' t ↔ s ⊆ t := by
refine' Iff.symm <| (Iff.intro (image_subset f)) fun h => _
rw [← preimage_image_eq s hf, ← preimage_image_eq t hf]
exact preimage_mono h
#align set.image_subset_image_iff Set.image_subset_image_iff
theorem prod_quotient_preimage_eq_image [s : Setoid α] (g : Quotient s → β) {h : α → β}
(Hh : h = g ∘ Quotient.mk'') (r : Set (β × β)) :
{ x : Quotient s × Quotient s | (g x.1, g x.2) ∈ r } =
(fun a : α × α => (⟦a.1⟧, ⟦a.2⟧)) '' ((fun a : α × α => (h a.1, h a.2)) ⁻¹' r) :=
Hh.symm ▸
Set.ext fun ⟨a₁, a₂⟩ =>
⟨Quot.induction_on₂ a₁ a₂ fun a₁ a₂ h => ⟨(a₁, a₂), h, rfl⟩, fun ⟨⟨b₁, b₂⟩, h₁, h₂⟩ =>
show (g a₁, g a₂) ∈ r from
have h₃ : ⟦b₁⟧ = a₁ ∧ ⟦b₂⟧ = a₂ := Prod.ext_iff.1 h₂
h₃.1 ▸ h₃.2 ▸ h₁⟩
#align set.prod_quotient_preimage_eq_image Set.prod_quotient_preimage_eq_image
theorem exists_image_iff (f : α → β) (x : Set α) (P : β → Prop) :
(∃ a : f '' x, P a) ↔ ∃ a : x, P (f a) :=
⟨fun ⟨a, h⟩ => ⟨⟨_, a.prop.choose_spec.1⟩, a.prop.choose_spec.2.symm ▸ h⟩, fun ⟨a, h⟩ =>
⟨⟨_, _, a.prop, rfl⟩, h⟩⟩
#align set.exists_image_iff Set.exists_image_iff
/-- Restriction of `f` to `s` factors through `s.imageFactorization f : s → f '' s`. -/
def imageFactorization (f : α → β) (s : Set α) : s → f '' s := fun p =>
⟨f p.1, mem_image_of_mem f p.2⟩
#align set.image_factorization Set.imageFactorization
theorem imageFactorization_eq {f : α → β} {s : Set α} :
Subtype.val ∘ imageFactorization f s = f ∘ Subtype.val :=
funext fun _ => rfl
#align set.image_factorization_eq Set.imageFactorization_eq
theorem surjective_onto_image {f : α → β} {s : Set α} : Surjective (imageFactorization f s) :=
fun ⟨_, ⟨a, ha, rfl⟩⟩ => ⟨⟨a, ha⟩, rfl⟩
#align set.surjective_onto_image Set.surjective_onto_image
/-- If the only elements outside `s` are those left fixed by `σ`, then mapping by `σ` has no effect.
-/
theorem image_perm {s : Set α} {σ : Equiv.Perm α} (hs : { a : α | σ a ≠ a } ⊆ s) : σ '' s = s := by
ext i
obtain hi | hi := eq_or_ne (σ i) i
· refine' ⟨_, fun h => ⟨i, h, hi⟩⟩
rintro ⟨j, hj, h⟩
rwa [σ.injective (hi.trans h.symm)]
· refine' iff_of_true ⟨σ.symm i, hs fun h => hi _, σ.apply_symm_apply _⟩ (hs hi)
convert congr_arg σ h <;>
|
exact (σ.apply_symm_apply _).symm
|
/-- If the only elements outside `s` are those left fixed by `σ`, then mapping by `σ` has no effect.
-/
theorem image_perm {s : Set α} {σ : Equiv.Perm α} (hs : { a : α | σ a ≠ a } ⊆ s) : σ '' s = s := by
ext i
obtain hi | hi := eq_or_ne (σ i) i
· refine' ⟨_, fun h => ⟨i, h, hi⟩⟩
rintro ⟨j, hj, h⟩
rwa [σ.injective (hi.trans h.symm)]
· refine' iff_of_true ⟨σ.symm i, hs fun h => hi _, σ.apply_symm_apply _⟩ (hs hi)
convert congr_arg σ h <;>
|
Mathlib.Data.Set.Image.635_0.IJFiTzmYGOCpPSd
|
/-- If the only elements outside `s` are those left fixed by `σ`, then mapping by `σ` has no effect.
-/
theorem image_perm {s : Set α} {σ : Equiv.Perm α} (hs : { a : α | σ a ≠ a } ⊆ s) : σ '' s = s
|
Mathlib_Data_Set_Image
|
α : Type u_1
β : Type u_2
γ : Type u_3
ι : Sort u_4
ι' : Sort u_5
s : Set α
a : α
⊢ 𝒫 insert a s = 𝒫 s ∪ insert a '' 𝒫 s
|
/-
Copyright (c) 2014 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Leonardo de Moura
-/
import Mathlib.Data.Set.Basic
#align_import data.set.image from "leanprover-community/mathlib"@"001ffdc42920050657fd45bd2b8bfbec8eaaeb29"
/-!
# Images and preimages of sets
## Main definitions
* `preimage f t : Set α` : the preimage f⁻¹(t) (written `f ⁻¹' t` in Lean) of a subset of β.
* `range f : Set β` : the image of `univ` under `f`.
Also works for `{p : Prop} (f : p → α)` (unlike `image`)
## Notation
* `f ⁻¹' t` for `Set.preimage f t`
* `f '' s` for `Set.image f s`
## Tags
set, sets, image, preimage, pre-image, range
-/
set_option autoImplicit true
universe u v
open Function Set
namespace Set
variable {α β γ : Type*} {ι ι' : Sort*}
/-! ### Inverse image -/
/-- The preimage of `s : Set β` by `f : α → β`, written `f ⁻¹' s`,
is the set of `x : α` such that `f x ∈ s`. -/
def preimage {α : Type u} {β : Type v} (f : α → β) (s : Set β) : Set α :=
{ x | f x ∈ s }
#align set.preimage Set.preimage
/-- `f ⁻¹' t` denotes the preimage of `t : Set β` under the function `f : α → β`. -/
infixl:80 " ⁻¹' " => preimage
section Preimage
variable {f : α → β} {g : β → γ}
@[simp]
theorem preimage_empty : f ⁻¹' ∅ = ∅ :=
rfl
#align set.preimage_empty Set.preimage_empty
@[simp, mfld_simps]
theorem mem_preimage {s : Set β} {a : α} : a ∈ f ⁻¹' s ↔ f a ∈ s :=
Iff.rfl
#align set.mem_preimage Set.mem_preimage
theorem preimage_congr {f g : α → β} {s : Set β} (h : ∀ x : α, f x = g x) : f ⁻¹' s = g ⁻¹' s := by
congr with x
simp [h]
#align set.preimage_congr Set.preimage_congr
@[gcongr]
theorem preimage_mono {s t : Set β} (h : s ⊆ t) : f ⁻¹' s ⊆ f ⁻¹' t := fun _ hx => h hx
#align set.preimage_mono Set.preimage_mono
@[simp, mfld_simps]
theorem preimage_univ : f ⁻¹' univ = univ :=
rfl
#align set.preimage_univ Set.preimage_univ
theorem subset_preimage_univ {s : Set α} : s ⊆ f ⁻¹' univ :=
subset_univ _
#align set.subset_preimage_univ Set.subset_preimage_univ
@[simp, mfld_simps]
theorem preimage_inter {s t : Set β} : f ⁻¹' (s ∩ t) = f ⁻¹' s ∩ f ⁻¹' t :=
rfl
#align set.preimage_inter Set.preimage_inter
@[simp]
theorem preimage_union {s t : Set β} : f ⁻¹' (s ∪ t) = f ⁻¹' s ∪ f ⁻¹' t :=
rfl
#align set.preimage_union Set.preimage_union
@[simp]
theorem preimage_compl {s : Set β} : f ⁻¹' sᶜ = (f ⁻¹' s)ᶜ :=
rfl
#align set.preimage_compl Set.preimage_compl
@[simp]
theorem preimage_diff (f : α → β) (s t : Set β) : f ⁻¹' (s \ t) = f ⁻¹' s \ f ⁻¹' t :=
rfl
#align set.preimage_diff Set.preimage_diff
@[simp]
lemma preimage_symmDiff {f : α → β} (s t : Set β) : f ⁻¹' (s ∆ t) = (f ⁻¹' s) ∆ (f ⁻¹' t) :=
rfl
#align set.preimage_symm_diff Set.preimage_symmDiff
@[simp]
theorem preimage_ite (f : α → β) (s t₁ t₂ : Set β) :
f ⁻¹' s.ite t₁ t₂ = (f ⁻¹' s).ite (f ⁻¹' t₁) (f ⁻¹' t₂) :=
rfl
#align set.preimage_ite Set.preimage_ite
@[simp]
theorem preimage_setOf_eq {p : α → Prop} {f : β → α} : f ⁻¹' { a | p a } = { a | p (f a) } :=
rfl
#align set.preimage_set_of_eq Set.preimage_setOf_eq
@[simp]
theorem preimage_id_eq : preimage (id : α → α) = id :=
rfl
#align set.preimage_id_eq Set.preimage_id_eq
@[mfld_simps]
theorem preimage_id {s : Set α} : id ⁻¹' s = s :=
rfl
#align set.preimage_id Set.preimage_id
@[simp, mfld_simps]
theorem preimage_id' {s : Set α} : (fun x => x) ⁻¹' s = s :=
rfl
#align set.preimage_id' Set.preimage_id'
@[simp]
theorem preimage_const_of_mem {b : β} {s : Set β} (h : b ∈ s) : (fun _ : α => b) ⁻¹' s = univ :=
eq_univ_of_forall fun _ => h
#align set.preimage_const_of_mem Set.preimage_const_of_mem
@[simp]
theorem preimage_const_of_not_mem {b : β} {s : Set β} (h : b ∉ s) : (fun _ : α => b) ⁻¹' s = ∅ :=
eq_empty_of_subset_empty fun _ hx => h hx
#align set.preimage_const_of_not_mem Set.preimage_const_of_not_mem
theorem preimage_const (b : β) (s : Set β) [Decidable (b ∈ s)] :
(fun _ : α => b) ⁻¹' s = if b ∈ s then univ else ∅ := by
split_ifs with hb
exacts [preimage_const_of_mem hb, preimage_const_of_not_mem hb]
#align set.preimage_const Set.preimage_const
/-- If preimage of each singleton under `f : α → β` is either empty or the whole type,
then `f` is a constant. -/
lemma exists_eq_const_of_preimage_singleton [Nonempty β] {f : α → β}
(hf : ∀ b : β, f ⁻¹' {b} = ∅ ∨ f ⁻¹' {b} = univ) : ∃ b, f = const α b := by
rcases em (∃ b, f ⁻¹' {b} = univ) with ⟨b, hb⟩ | hf'
· exact ⟨b, funext fun x ↦ eq_univ_iff_forall.1 hb x⟩
· have : ∀ x b, f x ≠ b := fun x b ↦
eq_empty_iff_forall_not_mem.1 ((hf b).resolve_right fun h ↦ hf' ⟨b, h⟩) x
exact ⟨Classical.arbitrary β, funext fun x ↦ absurd rfl (this x _)⟩
theorem preimage_comp {s : Set γ} : g ∘ f ⁻¹' s = f ⁻¹' (g ⁻¹' s) :=
rfl
#align set.preimage_comp Set.preimage_comp
theorem preimage_comp_eq : preimage (g ∘ f) = preimage f ∘ preimage g :=
rfl
#align set.preimage_comp_eq Set.preimage_comp_eq
theorem preimage_iterate_eq {f : α → α} {n : ℕ} : Set.preimage f^[n] = (Set.preimage f)^[n] := by
induction' n with n ih; · simp
rw [iterate_succ, iterate_succ', preimage_comp_eq, ih]
#align set.preimage_iterate_eq Set.preimage_iterate_eq
theorem preimage_preimage {g : β → γ} {f : α → β} {s : Set γ} :
f ⁻¹' (g ⁻¹' s) = (fun x => g (f x)) ⁻¹' s :=
preimage_comp.symm
#align set.preimage_preimage Set.preimage_preimage
theorem eq_preimage_subtype_val_iff {p : α → Prop} {s : Set (Subtype p)} {t : Set α} :
s = Subtype.val ⁻¹' t ↔ ∀ (x) (h : p x), (⟨x, h⟩ : Subtype p) ∈ s ↔ x ∈ t :=
⟨fun s_eq x h => by
rw [s_eq]
simp, fun h => ext fun ⟨x, hx⟩ => by simp [h]⟩
#align set.eq_preimage_subtype_val_iff Set.eq_preimage_subtype_val_iff
theorem nonempty_of_nonempty_preimage {s : Set β} {f : α → β} (hf : (f ⁻¹' s).Nonempty) :
s.Nonempty :=
let ⟨x, hx⟩ := hf
⟨f x, hx⟩
#align set.nonempty_of_nonempty_preimage Set.nonempty_of_nonempty_preimage
@[simp] theorem preimage_singleton_true (p : α → Prop) : p ⁻¹' {True} = {a | p a} := by ext; simp
#align set.preimage_singleton_true Set.preimage_singleton_true
@[simp] theorem preimage_singleton_false (p : α → Prop) : p ⁻¹' {False} = {a | ¬p a} := by ext; simp
#align set.preimage_singleton_false Set.preimage_singleton_false
theorem preimage_subtype_coe_eq_compl {s u v : Set α} (hsuv : s ⊆ u ∪ v)
(H : s ∩ (u ∩ v) = ∅) : ((↑) : s → α) ⁻¹' u = ((↑) ⁻¹' v)ᶜ := by
ext ⟨x, x_in_s⟩
constructor
· intro x_in_u x_in_v
exact eq_empty_iff_forall_not_mem.mp H x ⟨x_in_s, ⟨x_in_u, x_in_v⟩⟩
· intro hx
exact Or.elim (hsuv x_in_s) id fun hx' => hx.elim hx'
#align set.preimage_subtype_coe_eq_compl Set.preimage_subtype_coe_eq_compl
end Preimage
/-! ### Image of a set under a function -/
section Image
variable {f : α → β} {s t : Set α}
-- Porting note: `Set.image` is already defined in `Init.Set`
#align set.image Set.image
/-- `f '' s` denotes the image of `s : Set α` under the function `f : α → β`. -/
infixl:80 " '' " => image
theorem mem_image_iff_bex {f : α → β} {s : Set α} {y : β} :
y ∈ f '' s ↔ ∃ (x : _) (_ : x ∈ s), f x = y :=
bex_def.symm
#align set.mem_image_iff_bex Set.mem_image_iff_bex
@[simp]
theorem mem_image (f : α → β) (s : Set α) (y : β) : y ∈ f '' s ↔ ∃ x ∈ s, f x = y :=
Iff.rfl
#align set.mem_image Set.mem_image
theorem image_eta (f : α → β) : f '' s = (fun x => f x) '' s :=
rfl
#align set.image_eta Set.image_eta
@[mfld_simps]
theorem mem_image_of_mem (f : α → β) {x : α} {a : Set α} (h : x ∈ a) : f x ∈ f '' a :=
⟨_, h, rfl⟩
#align set.mem_image_of_mem Set.mem_image_of_mem
theorem _root_.Function.Injective.mem_set_image {f : α → β} (hf : Injective f) {s : Set α} {a : α} :
f a ∈ f '' s ↔ a ∈ s :=
⟨fun ⟨_, hb, Eq⟩ => hf Eq ▸ hb, mem_image_of_mem f⟩
#align function.injective.mem_set_image Function.Injective.mem_set_image
theorem ball_image_iff {f : α → β} {s : Set α} {p : β → Prop} :
(∀ y ∈ f '' s, p y) ↔ ∀ x ∈ s, p (f x) := by simp
#align set.ball_image_iff Set.ball_image_iff
theorem ball_image_of_ball {f : α → β} {s : Set α} {p : β → Prop} (h : ∀ x ∈ s, p (f x)) :
∀ y ∈ f '' s, p y :=
ball_image_iff.2 h
#align set.ball_image_of_ball Set.ball_image_of_ball
theorem bex_image_iff {f : α → β} {s : Set α} {p : β → Prop} :
(∃ y ∈ f '' s, p y) ↔ ∃ x ∈ s, p (f x) := by simp
#align set.bex_image_iff Set.bex_image_iff
theorem mem_image_elim {f : α → β} {s : Set α} {C : β → Prop} (h : ∀ x : α, x ∈ s → C (f x)) :
∀ {y : β}, y ∈ f '' s → C y
| _, ⟨a, a_in, rfl⟩ => h a a_in
#align set.mem_image_elim Set.mem_image_elim
theorem mem_image_elim_on {f : α → β} {s : Set α} {C : β → Prop} {y : β} (h_y : y ∈ f '' s)
(h : ∀ x : α, x ∈ s → C (f x)) : C y :=
mem_image_elim h h_y
#align set.mem_image_elim_on Set.mem_image_elim_on
-- Porting note: used to be `safe`
@[congr]
theorem image_congr {f g : α → β} {s : Set α} (h : ∀ a ∈ s, f a = g a) : f '' s = g '' s := by
ext x
rw [mem_image, mem_image]
exact {
mp := by
rintro ⟨a, ha1, ha2⟩
exact ⟨a, ⟨ha1, (h a ha1) ▸ ha2⟩⟩,
mpr := by
rintro ⟨a, ha1, ha2⟩
exact ⟨a, ⟨ha1, (h a ha1) ▸ ha2⟩⟩
}
-- safe [ext_iff, iff_def]
#align set.image_congr Set.image_congr
/-- A common special case of `image_congr` -/
theorem image_congr' {f g : α → β} {s : Set α} (h : ∀ x : α, f x = g x) : f '' s = g '' s :=
image_congr fun x _ => h x
#align set.image_congr' Set.image_congr'
@[gcongr]
lemma image_mono (h : s ⊆ t) : f '' s ⊆ f '' t := by
rintro - ⟨a, ha, rfl⟩; exact mem_image_of_mem f (h ha)
theorem image_comp (f : β → γ) (g : α → β) (a : Set α) : f ∘ g '' a = f '' (g '' a) :=
Subset.antisymm (ball_image_of_ball fun _ ha => mem_image_of_mem _ <| mem_image_of_mem _ ha)
(ball_image_of_ball <| ball_image_of_ball fun _ ha => mem_image_of_mem _ ha)
#align set.image_comp Set.image_comp
theorem image_comp_eq {g : β → γ} : image (g ∘ f) = image g ∘ image f := by ext; simp
/-- A variant of `image_comp`, useful for rewriting -/
theorem image_image (g : β → γ) (f : α → β) (s : Set α) : g '' (f '' s) = (fun x => g (f x)) '' s :=
(image_comp g f s).symm
#align set.image_image Set.image_image
theorem image_comm {β'} {f : β → γ} {g : α → β} {f' : α → β'} {g' : β' → γ}
(h_comm : ∀ a, f (g a) = g' (f' a)) : (s.image g).image f = (s.image f').image g' := by
simp_rw [image_image, h_comm]
#align set.image_comm Set.image_comm
theorem _root_.Function.Semiconj.set_image {f : α → β} {ga : α → α} {gb : β → β}
(h : Function.Semiconj f ga gb) : Function.Semiconj (image f) (image ga) (image gb) := fun _ =>
image_comm h
#align function.semiconj.set_image Function.Semiconj.set_image
theorem _root_.Function.Commute.set_image {f g : α → α} (h : Function.Commute f g) :
Function.Commute (image f) (image g) :=
Function.Semiconj.set_image h
#align function.commute.set_image Function.Commute.set_image
/-- Image is monotone with respect to `⊆`. See `Set.monotone_image` for the statement in
terms of `≤`. -/
@[gcongr]
theorem image_subset {a b : Set α} (f : α → β) (h : a ⊆ b) : f '' a ⊆ f '' b := by
simp only [subset_def, mem_image]
exact fun x => fun ⟨w, h1, h2⟩ => ⟨w, h h1, h2⟩
#align set.image_subset Set.image_subset
/-- `Set.image` is monotone. See `Set.image_subset` for the statement in terms of `⊆`. -/
lemma monotone_image {f : α → β} : Monotone (image f) := fun _ _ => image_subset _
#align set.monotone_image Set.monotone_image
theorem image_union (f : α → β) (s t : Set α) : f '' (s ∪ t) = f '' s ∪ f '' t :=
ext fun x =>
⟨by rintro ⟨a, h | h, rfl⟩ <;> [left; right] <;> exact ⟨_, h, rfl⟩, by
rintro (⟨a, h, rfl⟩ | ⟨a, h, rfl⟩) <;> refine' ⟨_, _, rfl⟩ <;> [left; right] <;> exact h⟩
#align set.image_union Set.image_union
@[simp]
theorem image_empty (f : α → β) : f '' ∅ = ∅ := by
ext
simp
#align set.image_empty Set.image_empty
theorem image_inter_subset (f : α → β) (s t : Set α) : f '' (s ∩ t) ⊆ f '' s ∩ f '' t :=
subset_inter (image_subset _ <| inter_subset_left _ _) (image_subset _ <| inter_subset_right _ _)
#align set.image_inter_subset Set.image_inter_subset
theorem image_inter_on {f : α → β} {s t : Set α} (h : ∀ x ∈ t, ∀ y ∈ s, f x = f y → x = y) :
f '' (s ∩ t) = f '' s ∩ f '' t :=
(image_inter_subset _ _ _).antisymm
fun b ⟨⟨a₁, ha₁, h₁⟩, ⟨a₂, ha₂, h₂⟩⟩ ↦
have : a₂ = a₁ := h _ ha₂ _ ha₁ (by simp [*])
⟨a₁, ⟨ha₁, this ▸ ha₂⟩, h₁⟩
#align set.image_inter_on Set.image_inter_on
theorem image_inter {f : α → β} {s t : Set α} (H : Injective f) : f '' (s ∩ t) = f '' s ∩ f '' t :=
image_inter_on fun _ _ _ _ h => H h
#align set.image_inter Set.image_inter
theorem image_univ_of_surjective {ι : Type*} {f : ι → β} (H : Surjective f) : f '' univ = univ :=
eq_univ_of_forall <| by simpa [image]
#align set.image_univ_of_surjective Set.image_univ_of_surjective
@[simp]
theorem image_singleton {f : α → β} {a : α} : f '' {a} = {f a} := by
ext
simp [image, eq_comm]
#align set.image_singleton Set.image_singleton
@[simp]
theorem Nonempty.image_const {s : Set α} (hs : s.Nonempty) (a : β) : (fun _ => a) '' s = {a} :=
ext fun _ =>
⟨fun ⟨_, _, h⟩ => h ▸ mem_singleton _, fun h =>
(eq_of_mem_singleton h).symm ▸ hs.imp fun _ hy => ⟨hy, rfl⟩⟩
#align set.nonempty.image_const Set.Nonempty.image_const
@[simp, mfld_simps]
theorem image_eq_empty {α β} {f : α → β} {s : Set α} : f '' s = ∅ ↔ s = ∅ := by
simp only [eq_empty_iff_forall_not_mem]
exact ⟨fun H a ha => H _ ⟨_, ha, rfl⟩, fun H b ⟨_, ha, _⟩ => H _ ha⟩
#align set.image_eq_empty Set.image_eq_empty
-- Porting note: `compl` is already defined in `Init.Set`
theorem preimage_compl_eq_image_compl [BooleanAlgebra α] (S : Set α) :
HasCompl.compl ⁻¹' S = HasCompl.compl '' S :=
Set.ext fun x =>
⟨fun h => ⟨xᶜ, h, compl_compl x⟩, fun h =>
Exists.elim h fun _ hy => (compl_eq_comm.mp hy.2).symm.subst hy.1⟩
#align set.preimage_compl_eq_image_compl Set.preimage_compl_eq_image_compl
theorem mem_compl_image [BooleanAlgebra α] (t : α) (S : Set α) :
t ∈ HasCompl.compl '' S ↔ tᶜ ∈ S := by
simp [← preimage_compl_eq_image_compl]
#align set.mem_compl_image Set.mem_compl_image
@[simp]
theorem image_id_eq : image (id : α → α) = id := by ext; simp
/-- A variant of `image_id` -/
@[simp]
theorem image_id' (s : Set α) : (fun x => x) '' s = s := by
ext
simp
#align set.image_id' Set.image_id'
theorem image_id (s : Set α) : id '' s = s := by simp
#align set.image_id Set.image_id
lemma image_iterate_eq {f : α → α} {n : ℕ} : image (f^[n]) = (image f)^[n] := by
induction' n with n ih; · simp
rw [iterate_succ', iterate_succ',← ih, image_comp_eq]
theorem compl_compl_image [BooleanAlgebra α] (S : Set α) :
HasCompl.compl '' (HasCompl.compl '' S) = S := by
rw [← image_comp, compl_comp_compl, image_id]
#align set.compl_compl_image Set.compl_compl_image
theorem image_insert_eq {f : α → β} {a : α} {s : Set α} :
f '' insert a s = insert (f a) (f '' s) := by
ext
simp [and_or_left, exists_or, eq_comm, or_comm, and_comm]
#align set.image_insert_eq Set.image_insert_eq
theorem image_pair (f : α → β) (a b : α) : f '' {a, b} = {f a, f b} := by
simp only [image_insert_eq, image_singleton]
#align set.image_pair Set.image_pair
theorem image_subset_preimage_of_inverse {f : α → β} {g : β → α} (I : LeftInverse g f) (s : Set α) :
f '' s ⊆ g ⁻¹' s := fun _ ⟨a, h, e⟩ => e ▸ ((I a).symm ▸ h : g (f a) ∈ s)
#align set.image_subset_preimage_of_inverse Set.image_subset_preimage_of_inverse
theorem preimage_subset_image_of_inverse {f : α → β} {g : β → α} (I : LeftInverse g f) (s : Set β) :
f ⁻¹' s ⊆ g '' s := fun b h => ⟨f b, h, I b⟩
#align set.preimage_subset_image_of_inverse Set.preimage_subset_image_of_inverse
theorem image_eq_preimage_of_inverse {f : α → β} {g : β → α} (h₁ : LeftInverse g f)
(h₂ : RightInverse g f) : image f = preimage g :=
funext fun s =>
Subset.antisymm (image_subset_preimage_of_inverse h₁ s) (preimage_subset_image_of_inverse h₂ s)
#align set.image_eq_preimage_of_inverse Set.image_eq_preimage_of_inverse
theorem mem_image_iff_of_inverse {f : α → β} {g : β → α} {b : β} {s : Set α} (h₁ : LeftInverse g f)
(h₂ : RightInverse g f) : b ∈ f '' s ↔ g b ∈ s := by
rw [image_eq_preimage_of_inverse h₁ h₂]; rfl
#align set.mem_image_iff_of_inverse Set.mem_image_iff_of_inverse
theorem image_compl_subset {f : α → β} {s : Set α} (H : Injective f) : f '' sᶜ ⊆ (f '' s)ᶜ :=
Disjoint.subset_compl_left <| by simp [disjoint_iff_inf_le, ← image_inter H]
#align set.image_compl_subset Set.image_compl_subset
theorem subset_image_compl {f : α → β} {s : Set α} (H : Surjective f) : (f '' s)ᶜ ⊆ f '' sᶜ :=
compl_subset_iff_union.2 <| by
rw [← image_union]
simp [image_univ_of_surjective H]
#align set.subset_image_compl Set.subset_image_compl
theorem image_compl_eq {f : α → β} {s : Set α} (H : Bijective f) : f '' sᶜ = (f '' s)ᶜ :=
Subset.antisymm (image_compl_subset H.1) (subset_image_compl H.2)
#align set.image_compl_eq Set.image_compl_eq
theorem subset_image_diff (f : α → β) (s t : Set α) : f '' s \ f '' t ⊆ f '' (s \ t) := by
rw [diff_subset_iff, ← image_union, union_diff_self]
exact image_subset f (subset_union_right t s)
#align set.subset_image_diff Set.subset_image_diff
theorem subset_image_symmDiff : (f '' s) ∆ (f '' t) ⊆ f '' s ∆ t :=
(union_subset_union (subset_image_diff _ _ _) <| subset_image_diff _ _ _).trans
(superset_of_eq (image_union _ _ _))
#align set.subset_image_symm_diff Set.subset_image_symmDiff
theorem image_diff {f : α → β} (hf : Injective f) (s t : Set α) : f '' (s \ t) = f '' s \ f '' t :=
Subset.antisymm
(Subset.trans (image_inter_subset _ _ _) <| inter_subset_inter_right _ <| image_compl_subset hf)
(subset_image_diff f s t)
#align set.image_diff Set.image_diff
theorem image_symmDiff (hf : Injective f) (s t : Set α) : f '' s ∆ t = (f '' s) ∆ (f '' t) := by
simp_rw [Set.symmDiff_def, image_union, image_diff hf]
#align set.image_symm_diff Set.image_symmDiff
theorem Nonempty.image (f : α → β) {s : Set α} : s.Nonempty → (f '' s).Nonempty
| ⟨x, hx⟩ => ⟨f x, mem_image_of_mem f hx⟩
#align set.nonempty.image Set.Nonempty.image
theorem Nonempty.of_image {f : α → β} {s : Set α} : (f '' s).Nonempty → s.Nonempty
| ⟨_, x, hx, _⟩ => ⟨x, hx⟩
#align set.nonempty.of_image Set.Nonempty.of_image
@[simp]
theorem nonempty_image_iff {f : α → β} {s : Set α} : (f '' s).Nonempty ↔ s.Nonempty :=
⟨Nonempty.of_image, fun h => h.image f⟩
#align set.nonempty_image_iff Set.nonempty_image_iff
theorem Nonempty.preimage {s : Set β} (hs : s.Nonempty) {f : α → β} (hf : Surjective f) :
(f ⁻¹' s).Nonempty :=
let ⟨y, hy⟩ := hs
let ⟨x, hx⟩ := hf y
⟨x, mem_preimage.2 <| hx.symm ▸ hy⟩
#align set.nonempty.preimage Set.Nonempty.preimage
instance (f : α → β) (s : Set α) [Nonempty s] : Nonempty (f '' s) :=
(Set.Nonempty.image f nonempty_of_nonempty_subtype).to_subtype
/-- image and preimage are a Galois connection -/
@[simp]
theorem image_subset_iff {s : Set α} {t : Set β} {f : α → β} : f '' s ⊆ t ↔ s ⊆ f ⁻¹' t :=
ball_image_iff
#align set.image_subset_iff Set.image_subset_iff
theorem image_preimage_subset (f : α → β) (s : Set β) : f '' (f ⁻¹' s) ⊆ s :=
image_subset_iff.2 Subset.rfl
#align set.image_preimage_subset Set.image_preimage_subset
theorem subset_preimage_image (f : α → β) (s : Set α) : s ⊆ f ⁻¹' (f '' s) := fun _ =>
mem_image_of_mem f
#align set.subset_preimage_image Set.subset_preimage_image
@[simp]
theorem preimage_image_eq {f : α → β} (s : Set α) (h : Injective f) : f ⁻¹' (f '' s) = s :=
Subset.antisymm (fun _ ⟨_, hy, e⟩ => h e ▸ hy) (subset_preimage_image f s)
#align set.preimage_image_eq Set.preimage_image_eq
@[simp]
theorem image_preimage_eq {f : α → β} (s : Set β) (h : Surjective f) : f '' (f ⁻¹' s) = s :=
Subset.antisymm (image_preimage_subset f s) fun x hx =>
let ⟨y, e⟩ := h x
⟨y, (e.symm ▸ hx : f y ∈ s), e⟩
#align set.image_preimage_eq Set.image_preimage_eq
@[simp]
theorem preimage_eq_preimage {f : β → α} (hf : Surjective f) : f ⁻¹' s = f ⁻¹' t ↔ s = t :=
Iff.intro
fun eq => by rw [← image_preimage_eq s hf, ← image_preimage_eq t hf, eq]
fun eq => eq ▸ rfl
#align set.preimage_eq_preimage Set.preimage_eq_preimage
theorem image_inter_preimage (f : α → β) (s : Set α) (t : Set β) :
f '' (s ∩ f ⁻¹' t) = f '' s ∩ t := by
apply Subset.antisymm
· calc
f '' (s ∩ f ⁻¹' t) ⊆ f '' s ∩ f '' (f ⁻¹' t) := image_inter_subset _ _ _
_ ⊆ f '' s ∩ t := inter_subset_inter_right _ (image_preimage_subset f t)
· rintro _ ⟨⟨x, h', rfl⟩, h⟩
exact ⟨x, ⟨h', h⟩, rfl⟩
#align set.image_inter_preimage Set.image_inter_preimage
theorem image_preimage_inter (f : α → β) (s : Set α) (t : Set β) :
f '' (f ⁻¹' t ∩ s) = t ∩ f '' s := by simp only [inter_comm, image_inter_preimage]
#align set.image_preimage_inter Set.image_preimage_inter
@[simp]
theorem image_inter_nonempty_iff {f : α → β} {s : Set α} {t : Set β} :
(f '' s ∩ t).Nonempty ↔ (s ∩ f ⁻¹' t).Nonempty := by
rw [← image_inter_preimage, nonempty_image_iff]
#align set.image_inter_nonempty_iff Set.image_inter_nonempty_iff
theorem image_diff_preimage {f : α → β} {s : Set α} {t : Set β} : f '' (s \ f ⁻¹' t) = f '' s \ t :=
by simp_rw [diff_eq, ← preimage_compl, image_inter_preimage]
#align set.image_diff_preimage Set.image_diff_preimage
theorem compl_image : image (compl : Set α → Set α) = preimage compl :=
image_eq_preimage_of_inverse compl_compl compl_compl
#align set.compl_image Set.compl_image
theorem compl_image_set_of {p : Set α → Prop} : compl '' { s | p s } = { s | p sᶜ } :=
congr_fun compl_image p
#align set.compl_image_set_of Set.compl_image_set_of
theorem inter_preimage_subset (s : Set α) (t : Set β) (f : α → β) :
s ∩ f ⁻¹' t ⊆ f ⁻¹' (f '' s ∩ t) := fun _ h => ⟨mem_image_of_mem _ h.left, h.right⟩
#align set.inter_preimage_subset Set.inter_preimage_subset
theorem union_preimage_subset (s : Set α) (t : Set β) (f : α → β) :
s ∪ f ⁻¹' t ⊆ f ⁻¹' (f '' s ∪ t) := fun _ h =>
Or.elim h (fun l => Or.inl <| mem_image_of_mem _ l) fun r => Or.inr r
#align set.union_preimage_subset Set.union_preimage_subset
theorem subset_image_union (f : α → β) (s : Set α) (t : Set β) : f '' (s ∪ f ⁻¹' t) ⊆ f '' s ∪ t :=
image_subset_iff.2 (union_preimage_subset _ _ _)
#align set.subset_image_union Set.subset_image_union
theorem preimage_subset_iff {A : Set α} {B : Set β} {f : α → β} :
f ⁻¹' B ⊆ A ↔ ∀ a : α, f a ∈ B → a ∈ A :=
Iff.rfl
#align set.preimage_subset_iff Set.preimage_subset_iff
theorem image_eq_image {f : α → β} (hf : Injective f) : f '' s = f '' t ↔ s = t :=
Iff.symm <|
(Iff.intro fun eq => eq ▸ rfl) fun eq => by
rw [← preimage_image_eq s hf, ← preimage_image_eq t hf, eq]
#align set.image_eq_image Set.image_eq_image
theorem image_subset_image_iff {f : α → β} (hf : Injective f) : f '' s ⊆ f '' t ↔ s ⊆ t := by
refine' Iff.symm <| (Iff.intro (image_subset f)) fun h => _
rw [← preimage_image_eq s hf, ← preimage_image_eq t hf]
exact preimage_mono h
#align set.image_subset_image_iff Set.image_subset_image_iff
theorem prod_quotient_preimage_eq_image [s : Setoid α] (g : Quotient s → β) {h : α → β}
(Hh : h = g ∘ Quotient.mk'') (r : Set (β × β)) :
{ x : Quotient s × Quotient s | (g x.1, g x.2) ∈ r } =
(fun a : α × α => (⟦a.1⟧, ⟦a.2⟧)) '' ((fun a : α × α => (h a.1, h a.2)) ⁻¹' r) :=
Hh.symm ▸
Set.ext fun ⟨a₁, a₂⟩ =>
⟨Quot.induction_on₂ a₁ a₂ fun a₁ a₂ h => ⟨(a₁, a₂), h, rfl⟩, fun ⟨⟨b₁, b₂⟩, h₁, h₂⟩ =>
show (g a₁, g a₂) ∈ r from
have h₃ : ⟦b₁⟧ = a₁ ∧ ⟦b₂⟧ = a₂ := Prod.ext_iff.1 h₂
h₃.1 ▸ h₃.2 ▸ h₁⟩
#align set.prod_quotient_preimage_eq_image Set.prod_quotient_preimage_eq_image
theorem exists_image_iff (f : α → β) (x : Set α) (P : β → Prop) :
(∃ a : f '' x, P a) ↔ ∃ a : x, P (f a) :=
⟨fun ⟨a, h⟩ => ⟨⟨_, a.prop.choose_spec.1⟩, a.prop.choose_spec.2.symm ▸ h⟩, fun ⟨a, h⟩ =>
⟨⟨_, _, a.prop, rfl⟩, h⟩⟩
#align set.exists_image_iff Set.exists_image_iff
/-- Restriction of `f` to `s` factors through `s.imageFactorization f : s → f '' s`. -/
def imageFactorization (f : α → β) (s : Set α) : s → f '' s := fun p =>
⟨f p.1, mem_image_of_mem f p.2⟩
#align set.image_factorization Set.imageFactorization
theorem imageFactorization_eq {f : α → β} {s : Set α} :
Subtype.val ∘ imageFactorization f s = f ∘ Subtype.val :=
funext fun _ => rfl
#align set.image_factorization_eq Set.imageFactorization_eq
theorem surjective_onto_image {f : α → β} {s : Set α} : Surjective (imageFactorization f s) :=
fun ⟨_, ⟨a, ha, rfl⟩⟩ => ⟨⟨a, ha⟩, rfl⟩
#align set.surjective_onto_image Set.surjective_onto_image
/-- If the only elements outside `s` are those left fixed by `σ`, then mapping by `σ` has no effect.
-/
theorem image_perm {s : Set α} {σ : Equiv.Perm α} (hs : { a : α | σ a ≠ a } ⊆ s) : σ '' s = s := by
ext i
obtain hi | hi := eq_or_ne (σ i) i
· refine' ⟨_, fun h => ⟨i, h, hi⟩⟩
rintro ⟨j, hj, h⟩
rwa [σ.injective (hi.trans h.symm)]
· refine' iff_of_true ⟨σ.symm i, hs fun h => hi _, σ.apply_symm_apply _⟩ (hs hi)
convert congr_arg σ h <;> exact (σ.apply_symm_apply _).symm
#align set.image_perm Set.image_perm
end Image
/-! ### Lemmas about the powerset and image. -/
/-- The powerset of `{a} ∪ s` is `𝒫 s` together with `{a} ∪ t` for each `t ∈ 𝒫 s`. -/
theorem powerset_insert (s : Set α) (a : α) : 𝒫 insert a s = 𝒫 s ∪ insert a '' 𝒫 s := by
|
ext t
|
/-- The powerset of `{a} ∪ s` is `𝒫 s` together with `{a} ∪ t` for each `t ∈ 𝒫 s`. -/
theorem powerset_insert (s : Set α) (a : α) : 𝒫 insert a s = 𝒫 s ∪ insert a '' 𝒫 s := by
|
Mathlib.Data.Set.Image.651_0.IJFiTzmYGOCpPSd
|
/-- The powerset of `{a} ∪ s` is `𝒫 s` together with `{a} ∪ t` for each `t ∈ 𝒫 s`. -/
theorem powerset_insert (s : Set α) (a : α) : 𝒫 insert a s = 𝒫 s ∪ insert a '' 𝒫 s
|
Mathlib_Data_Set_Image
|
case h
α : Type u_1
β : Type u_2
γ : Type u_3
ι : Sort u_4
ι' : Sort u_5
s : Set α
a : α
t : Set α
⊢ t ∈ 𝒫 insert a s ↔ t ∈ 𝒫 s ∪ insert a '' 𝒫 s
|
/-
Copyright (c) 2014 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Leonardo de Moura
-/
import Mathlib.Data.Set.Basic
#align_import data.set.image from "leanprover-community/mathlib"@"001ffdc42920050657fd45bd2b8bfbec8eaaeb29"
/-!
# Images and preimages of sets
## Main definitions
* `preimage f t : Set α` : the preimage f⁻¹(t) (written `f ⁻¹' t` in Lean) of a subset of β.
* `range f : Set β` : the image of `univ` under `f`.
Also works for `{p : Prop} (f : p → α)` (unlike `image`)
## Notation
* `f ⁻¹' t` for `Set.preimage f t`
* `f '' s` for `Set.image f s`
## Tags
set, sets, image, preimage, pre-image, range
-/
set_option autoImplicit true
universe u v
open Function Set
namespace Set
variable {α β γ : Type*} {ι ι' : Sort*}
/-! ### Inverse image -/
/-- The preimage of `s : Set β` by `f : α → β`, written `f ⁻¹' s`,
is the set of `x : α` such that `f x ∈ s`. -/
def preimage {α : Type u} {β : Type v} (f : α → β) (s : Set β) : Set α :=
{ x | f x ∈ s }
#align set.preimage Set.preimage
/-- `f ⁻¹' t` denotes the preimage of `t : Set β` under the function `f : α → β`. -/
infixl:80 " ⁻¹' " => preimage
section Preimage
variable {f : α → β} {g : β → γ}
@[simp]
theorem preimage_empty : f ⁻¹' ∅ = ∅ :=
rfl
#align set.preimage_empty Set.preimage_empty
@[simp, mfld_simps]
theorem mem_preimage {s : Set β} {a : α} : a ∈ f ⁻¹' s ↔ f a ∈ s :=
Iff.rfl
#align set.mem_preimage Set.mem_preimage
theorem preimage_congr {f g : α → β} {s : Set β} (h : ∀ x : α, f x = g x) : f ⁻¹' s = g ⁻¹' s := by
congr with x
simp [h]
#align set.preimage_congr Set.preimage_congr
@[gcongr]
theorem preimage_mono {s t : Set β} (h : s ⊆ t) : f ⁻¹' s ⊆ f ⁻¹' t := fun _ hx => h hx
#align set.preimage_mono Set.preimage_mono
@[simp, mfld_simps]
theorem preimage_univ : f ⁻¹' univ = univ :=
rfl
#align set.preimage_univ Set.preimage_univ
theorem subset_preimage_univ {s : Set α} : s ⊆ f ⁻¹' univ :=
subset_univ _
#align set.subset_preimage_univ Set.subset_preimage_univ
@[simp, mfld_simps]
theorem preimage_inter {s t : Set β} : f ⁻¹' (s ∩ t) = f ⁻¹' s ∩ f ⁻¹' t :=
rfl
#align set.preimage_inter Set.preimage_inter
@[simp]
theorem preimage_union {s t : Set β} : f ⁻¹' (s ∪ t) = f ⁻¹' s ∪ f ⁻¹' t :=
rfl
#align set.preimage_union Set.preimage_union
@[simp]
theorem preimage_compl {s : Set β} : f ⁻¹' sᶜ = (f ⁻¹' s)ᶜ :=
rfl
#align set.preimage_compl Set.preimage_compl
@[simp]
theorem preimage_diff (f : α → β) (s t : Set β) : f ⁻¹' (s \ t) = f ⁻¹' s \ f ⁻¹' t :=
rfl
#align set.preimage_diff Set.preimage_diff
@[simp]
lemma preimage_symmDiff {f : α → β} (s t : Set β) : f ⁻¹' (s ∆ t) = (f ⁻¹' s) ∆ (f ⁻¹' t) :=
rfl
#align set.preimage_symm_diff Set.preimage_symmDiff
@[simp]
theorem preimage_ite (f : α → β) (s t₁ t₂ : Set β) :
f ⁻¹' s.ite t₁ t₂ = (f ⁻¹' s).ite (f ⁻¹' t₁) (f ⁻¹' t₂) :=
rfl
#align set.preimage_ite Set.preimage_ite
@[simp]
theorem preimage_setOf_eq {p : α → Prop} {f : β → α} : f ⁻¹' { a | p a } = { a | p (f a) } :=
rfl
#align set.preimage_set_of_eq Set.preimage_setOf_eq
@[simp]
theorem preimage_id_eq : preimage (id : α → α) = id :=
rfl
#align set.preimage_id_eq Set.preimage_id_eq
@[mfld_simps]
theorem preimage_id {s : Set α} : id ⁻¹' s = s :=
rfl
#align set.preimage_id Set.preimage_id
@[simp, mfld_simps]
theorem preimage_id' {s : Set α} : (fun x => x) ⁻¹' s = s :=
rfl
#align set.preimage_id' Set.preimage_id'
@[simp]
theorem preimage_const_of_mem {b : β} {s : Set β} (h : b ∈ s) : (fun _ : α => b) ⁻¹' s = univ :=
eq_univ_of_forall fun _ => h
#align set.preimage_const_of_mem Set.preimage_const_of_mem
@[simp]
theorem preimage_const_of_not_mem {b : β} {s : Set β} (h : b ∉ s) : (fun _ : α => b) ⁻¹' s = ∅ :=
eq_empty_of_subset_empty fun _ hx => h hx
#align set.preimage_const_of_not_mem Set.preimage_const_of_not_mem
theorem preimage_const (b : β) (s : Set β) [Decidable (b ∈ s)] :
(fun _ : α => b) ⁻¹' s = if b ∈ s then univ else ∅ := by
split_ifs with hb
exacts [preimage_const_of_mem hb, preimage_const_of_not_mem hb]
#align set.preimage_const Set.preimage_const
/-- If preimage of each singleton under `f : α → β` is either empty or the whole type,
then `f` is a constant. -/
lemma exists_eq_const_of_preimage_singleton [Nonempty β] {f : α → β}
(hf : ∀ b : β, f ⁻¹' {b} = ∅ ∨ f ⁻¹' {b} = univ) : ∃ b, f = const α b := by
rcases em (∃ b, f ⁻¹' {b} = univ) with ⟨b, hb⟩ | hf'
· exact ⟨b, funext fun x ↦ eq_univ_iff_forall.1 hb x⟩
· have : ∀ x b, f x ≠ b := fun x b ↦
eq_empty_iff_forall_not_mem.1 ((hf b).resolve_right fun h ↦ hf' ⟨b, h⟩) x
exact ⟨Classical.arbitrary β, funext fun x ↦ absurd rfl (this x _)⟩
theorem preimage_comp {s : Set γ} : g ∘ f ⁻¹' s = f ⁻¹' (g ⁻¹' s) :=
rfl
#align set.preimage_comp Set.preimage_comp
theorem preimage_comp_eq : preimage (g ∘ f) = preimage f ∘ preimage g :=
rfl
#align set.preimage_comp_eq Set.preimage_comp_eq
theorem preimage_iterate_eq {f : α → α} {n : ℕ} : Set.preimage f^[n] = (Set.preimage f)^[n] := by
induction' n with n ih; · simp
rw [iterate_succ, iterate_succ', preimage_comp_eq, ih]
#align set.preimage_iterate_eq Set.preimage_iterate_eq
theorem preimage_preimage {g : β → γ} {f : α → β} {s : Set γ} :
f ⁻¹' (g ⁻¹' s) = (fun x => g (f x)) ⁻¹' s :=
preimage_comp.symm
#align set.preimage_preimage Set.preimage_preimage
theorem eq_preimage_subtype_val_iff {p : α → Prop} {s : Set (Subtype p)} {t : Set α} :
s = Subtype.val ⁻¹' t ↔ ∀ (x) (h : p x), (⟨x, h⟩ : Subtype p) ∈ s ↔ x ∈ t :=
⟨fun s_eq x h => by
rw [s_eq]
simp, fun h => ext fun ⟨x, hx⟩ => by simp [h]⟩
#align set.eq_preimage_subtype_val_iff Set.eq_preimage_subtype_val_iff
theorem nonempty_of_nonempty_preimage {s : Set β} {f : α → β} (hf : (f ⁻¹' s).Nonempty) :
s.Nonempty :=
let ⟨x, hx⟩ := hf
⟨f x, hx⟩
#align set.nonempty_of_nonempty_preimage Set.nonempty_of_nonempty_preimage
@[simp] theorem preimage_singleton_true (p : α → Prop) : p ⁻¹' {True} = {a | p a} := by ext; simp
#align set.preimage_singleton_true Set.preimage_singleton_true
@[simp] theorem preimage_singleton_false (p : α → Prop) : p ⁻¹' {False} = {a | ¬p a} := by ext; simp
#align set.preimage_singleton_false Set.preimage_singleton_false
theorem preimage_subtype_coe_eq_compl {s u v : Set α} (hsuv : s ⊆ u ∪ v)
(H : s ∩ (u ∩ v) = ∅) : ((↑) : s → α) ⁻¹' u = ((↑) ⁻¹' v)ᶜ := by
ext ⟨x, x_in_s⟩
constructor
· intro x_in_u x_in_v
exact eq_empty_iff_forall_not_mem.mp H x ⟨x_in_s, ⟨x_in_u, x_in_v⟩⟩
· intro hx
exact Or.elim (hsuv x_in_s) id fun hx' => hx.elim hx'
#align set.preimage_subtype_coe_eq_compl Set.preimage_subtype_coe_eq_compl
end Preimage
/-! ### Image of a set under a function -/
section Image
variable {f : α → β} {s t : Set α}
-- Porting note: `Set.image` is already defined in `Init.Set`
#align set.image Set.image
/-- `f '' s` denotes the image of `s : Set α` under the function `f : α → β`. -/
infixl:80 " '' " => image
theorem mem_image_iff_bex {f : α → β} {s : Set α} {y : β} :
y ∈ f '' s ↔ ∃ (x : _) (_ : x ∈ s), f x = y :=
bex_def.symm
#align set.mem_image_iff_bex Set.mem_image_iff_bex
@[simp]
theorem mem_image (f : α → β) (s : Set α) (y : β) : y ∈ f '' s ↔ ∃ x ∈ s, f x = y :=
Iff.rfl
#align set.mem_image Set.mem_image
theorem image_eta (f : α → β) : f '' s = (fun x => f x) '' s :=
rfl
#align set.image_eta Set.image_eta
@[mfld_simps]
theorem mem_image_of_mem (f : α → β) {x : α} {a : Set α} (h : x ∈ a) : f x ∈ f '' a :=
⟨_, h, rfl⟩
#align set.mem_image_of_mem Set.mem_image_of_mem
theorem _root_.Function.Injective.mem_set_image {f : α → β} (hf : Injective f) {s : Set α} {a : α} :
f a ∈ f '' s ↔ a ∈ s :=
⟨fun ⟨_, hb, Eq⟩ => hf Eq ▸ hb, mem_image_of_mem f⟩
#align function.injective.mem_set_image Function.Injective.mem_set_image
theorem ball_image_iff {f : α → β} {s : Set α} {p : β → Prop} :
(∀ y ∈ f '' s, p y) ↔ ∀ x ∈ s, p (f x) := by simp
#align set.ball_image_iff Set.ball_image_iff
theorem ball_image_of_ball {f : α → β} {s : Set α} {p : β → Prop} (h : ∀ x ∈ s, p (f x)) :
∀ y ∈ f '' s, p y :=
ball_image_iff.2 h
#align set.ball_image_of_ball Set.ball_image_of_ball
theorem bex_image_iff {f : α → β} {s : Set α} {p : β → Prop} :
(∃ y ∈ f '' s, p y) ↔ ∃ x ∈ s, p (f x) := by simp
#align set.bex_image_iff Set.bex_image_iff
theorem mem_image_elim {f : α → β} {s : Set α} {C : β → Prop} (h : ∀ x : α, x ∈ s → C (f x)) :
∀ {y : β}, y ∈ f '' s → C y
| _, ⟨a, a_in, rfl⟩ => h a a_in
#align set.mem_image_elim Set.mem_image_elim
theorem mem_image_elim_on {f : α → β} {s : Set α} {C : β → Prop} {y : β} (h_y : y ∈ f '' s)
(h : ∀ x : α, x ∈ s → C (f x)) : C y :=
mem_image_elim h h_y
#align set.mem_image_elim_on Set.mem_image_elim_on
-- Porting note: used to be `safe`
@[congr]
theorem image_congr {f g : α → β} {s : Set α} (h : ∀ a ∈ s, f a = g a) : f '' s = g '' s := by
ext x
rw [mem_image, mem_image]
exact {
mp := by
rintro ⟨a, ha1, ha2⟩
exact ⟨a, ⟨ha1, (h a ha1) ▸ ha2⟩⟩,
mpr := by
rintro ⟨a, ha1, ha2⟩
exact ⟨a, ⟨ha1, (h a ha1) ▸ ha2⟩⟩
}
-- safe [ext_iff, iff_def]
#align set.image_congr Set.image_congr
/-- A common special case of `image_congr` -/
theorem image_congr' {f g : α → β} {s : Set α} (h : ∀ x : α, f x = g x) : f '' s = g '' s :=
image_congr fun x _ => h x
#align set.image_congr' Set.image_congr'
@[gcongr]
lemma image_mono (h : s ⊆ t) : f '' s ⊆ f '' t := by
rintro - ⟨a, ha, rfl⟩; exact mem_image_of_mem f (h ha)
theorem image_comp (f : β → γ) (g : α → β) (a : Set α) : f ∘ g '' a = f '' (g '' a) :=
Subset.antisymm (ball_image_of_ball fun _ ha => mem_image_of_mem _ <| mem_image_of_mem _ ha)
(ball_image_of_ball <| ball_image_of_ball fun _ ha => mem_image_of_mem _ ha)
#align set.image_comp Set.image_comp
theorem image_comp_eq {g : β → γ} : image (g ∘ f) = image g ∘ image f := by ext; simp
/-- A variant of `image_comp`, useful for rewriting -/
theorem image_image (g : β → γ) (f : α → β) (s : Set α) : g '' (f '' s) = (fun x => g (f x)) '' s :=
(image_comp g f s).symm
#align set.image_image Set.image_image
theorem image_comm {β'} {f : β → γ} {g : α → β} {f' : α → β'} {g' : β' → γ}
(h_comm : ∀ a, f (g a) = g' (f' a)) : (s.image g).image f = (s.image f').image g' := by
simp_rw [image_image, h_comm]
#align set.image_comm Set.image_comm
theorem _root_.Function.Semiconj.set_image {f : α → β} {ga : α → α} {gb : β → β}
(h : Function.Semiconj f ga gb) : Function.Semiconj (image f) (image ga) (image gb) := fun _ =>
image_comm h
#align function.semiconj.set_image Function.Semiconj.set_image
theorem _root_.Function.Commute.set_image {f g : α → α} (h : Function.Commute f g) :
Function.Commute (image f) (image g) :=
Function.Semiconj.set_image h
#align function.commute.set_image Function.Commute.set_image
/-- Image is monotone with respect to `⊆`. See `Set.monotone_image` for the statement in
terms of `≤`. -/
@[gcongr]
theorem image_subset {a b : Set α} (f : α → β) (h : a ⊆ b) : f '' a ⊆ f '' b := by
simp only [subset_def, mem_image]
exact fun x => fun ⟨w, h1, h2⟩ => ⟨w, h h1, h2⟩
#align set.image_subset Set.image_subset
/-- `Set.image` is monotone. See `Set.image_subset` for the statement in terms of `⊆`. -/
lemma monotone_image {f : α → β} : Monotone (image f) := fun _ _ => image_subset _
#align set.monotone_image Set.monotone_image
theorem image_union (f : α → β) (s t : Set α) : f '' (s ∪ t) = f '' s ∪ f '' t :=
ext fun x =>
⟨by rintro ⟨a, h | h, rfl⟩ <;> [left; right] <;> exact ⟨_, h, rfl⟩, by
rintro (⟨a, h, rfl⟩ | ⟨a, h, rfl⟩) <;> refine' ⟨_, _, rfl⟩ <;> [left; right] <;> exact h⟩
#align set.image_union Set.image_union
@[simp]
theorem image_empty (f : α → β) : f '' ∅ = ∅ := by
ext
simp
#align set.image_empty Set.image_empty
theorem image_inter_subset (f : α → β) (s t : Set α) : f '' (s ∩ t) ⊆ f '' s ∩ f '' t :=
subset_inter (image_subset _ <| inter_subset_left _ _) (image_subset _ <| inter_subset_right _ _)
#align set.image_inter_subset Set.image_inter_subset
theorem image_inter_on {f : α → β} {s t : Set α} (h : ∀ x ∈ t, ∀ y ∈ s, f x = f y → x = y) :
f '' (s ∩ t) = f '' s ∩ f '' t :=
(image_inter_subset _ _ _).antisymm
fun b ⟨⟨a₁, ha₁, h₁⟩, ⟨a₂, ha₂, h₂⟩⟩ ↦
have : a₂ = a₁ := h _ ha₂ _ ha₁ (by simp [*])
⟨a₁, ⟨ha₁, this ▸ ha₂⟩, h₁⟩
#align set.image_inter_on Set.image_inter_on
theorem image_inter {f : α → β} {s t : Set α} (H : Injective f) : f '' (s ∩ t) = f '' s ∩ f '' t :=
image_inter_on fun _ _ _ _ h => H h
#align set.image_inter Set.image_inter
theorem image_univ_of_surjective {ι : Type*} {f : ι → β} (H : Surjective f) : f '' univ = univ :=
eq_univ_of_forall <| by simpa [image]
#align set.image_univ_of_surjective Set.image_univ_of_surjective
@[simp]
theorem image_singleton {f : α → β} {a : α} : f '' {a} = {f a} := by
ext
simp [image, eq_comm]
#align set.image_singleton Set.image_singleton
@[simp]
theorem Nonempty.image_const {s : Set α} (hs : s.Nonempty) (a : β) : (fun _ => a) '' s = {a} :=
ext fun _ =>
⟨fun ⟨_, _, h⟩ => h ▸ mem_singleton _, fun h =>
(eq_of_mem_singleton h).symm ▸ hs.imp fun _ hy => ⟨hy, rfl⟩⟩
#align set.nonempty.image_const Set.Nonempty.image_const
@[simp, mfld_simps]
theorem image_eq_empty {α β} {f : α → β} {s : Set α} : f '' s = ∅ ↔ s = ∅ := by
simp only [eq_empty_iff_forall_not_mem]
exact ⟨fun H a ha => H _ ⟨_, ha, rfl⟩, fun H b ⟨_, ha, _⟩ => H _ ha⟩
#align set.image_eq_empty Set.image_eq_empty
-- Porting note: `compl` is already defined in `Init.Set`
theorem preimage_compl_eq_image_compl [BooleanAlgebra α] (S : Set α) :
HasCompl.compl ⁻¹' S = HasCompl.compl '' S :=
Set.ext fun x =>
⟨fun h => ⟨xᶜ, h, compl_compl x⟩, fun h =>
Exists.elim h fun _ hy => (compl_eq_comm.mp hy.2).symm.subst hy.1⟩
#align set.preimage_compl_eq_image_compl Set.preimage_compl_eq_image_compl
theorem mem_compl_image [BooleanAlgebra α] (t : α) (S : Set α) :
t ∈ HasCompl.compl '' S ↔ tᶜ ∈ S := by
simp [← preimage_compl_eq_image_compl]
#align set.mem_compl_image Set.mem_compl_image
@[simp]
theorem image_id_eq : image (id : α → α) = id := by ext; simp
/-- A variant of `image_id` -/
@[simp]
theorem image_id' (s : Set α) : (fun x => x) '' s = s := by
ext
simp
#align set.image_id' Set.image_id'
theorem image_id (s : Set α) : id '' s = s := by simp
#align set.image_id Set.image_id
lemma image_iterate_eq {f : α → α} {n : ℕ} : image (f^[n]) = (image f)^[n] := by
induction' n with n ih; · simp
rw [iterate_succ', iterate_succ',← ih, image_comp_eq]
theorem compl_compl_image [BooleanAlgebra α] (S : Set α) :
HasCompl.compl '' (HasCompl.compl '' S) = S := by
rw [← image_comp, compl_comp_compl, image_id]
#align set.compl_compl_image Set.compl_compl_image
theorem image_insert_eq {f : α → β} {a : α} {s : Set α} :
f '' insert a s = insert (f a) (f '' s) := by
ext
simp [and_or_left, exists_or, eq_comm, or_comm, and_comm]
#align set.image_insert_eq Set.image_insert_eq
theorem image_pair (f : α → β) (a b : α) : f '' {a, b} = {f a, f b} := by
simp only [image_insert_eq, image_singleton]
#align set.image_pair Set.image_pair
theorem image_subset_preimage_of_inverse {f : α → β} {g : β → α} (I : LeftInverse g f) (s : Set α) :
f '' s ⊆ g ⁻¹' s := fun _ ⟨a, h, e⟩ => e ▸ ((I a).symm ▸ h : g (f a) ∈ s)
#align set.image_subset_preimage_of_inverse Set.image_subset_preimage_of_inverse
theorem preimage_subset_image_of_inverse {f : α → β} {g : β → α} (I : LeftInverse g f) (s : Set β) :
f ⁻¹' s ⊆ g '' s := fun b h => ⟨f b, h, I b⟩
#align set.preimage_subset_image_of_inverse Set.preimage_subset_image_of_inverse
theorem image_eq_preimage_of_inverse {f : α → β} {g : β → α} (h₁ : LeftInverse g f)
(h₂ : RightInverse g f) : image f = preimage g :=
funext fun s =>
Subset.antisymm (image_subset_preimage_of_inverse h₁ s) (preimage_subset_image_of_inverse h₂ s)
#align set.image_eq_preimage_of_inverse Set.image_eq_preimage_of_inverse
theorem mem_image_iff_of_inverse {f : α → β} {g : β → α} {b : β} {s : Set α} (h₁ : LeftInverse g f)
(h₂ : RightInverse g f) : b ∈ f '' s ↔ g b ∈ s := by
rw [image_eq_preimage_of_inverse h₁ h₂]; rfl
#align set.mem_image_iff_of_inverse Set.mem_image_iff_of_inverse
theorem image_compl_subset {f : α → β} {s : Set α} (H : Injective f) : f '' sᶜ ⊆ (f '' s)ᶜ :=
Disjoint.subset_compl_left <| by simp [disjoint_iff_inf_le, ← image_inter H]
#align set.image_compl_subset Set.image_compl_subset
theorem subset_image_compl {f : α → β} {s : Set α} (H : Surjective f) : (f '' s)ᶜ ⊆ f '' sᶜ :=
compl_subset_iff_union.2 <| by
rw [← image_union]
simp [image_univ_of_surjective H]
#align set.subset_image_compl Set.subset_image_compl
theorem image_compl_eq {f : α → β} {s : Set α} (H : Bijective f) : f '' sᶜ = (f '' s)ᶜ :=
Subset.antisymm (image_compl_subset H.1) (subset_image_compl H.2)
#align set.image_compl_eq Set.image_compl_eq
theorem subset_image_diff (f : α → β) (s t : Set α) : f '' s \ f '' t ⊆ f '' (s \ t) := by
rw [diff_subset_iff, ← image_union, union_diff_self]
exact image_subset f (subset_union_right t s)
#align set.subset_image_diff Set.subset_image_diff
theorem subset_image_symmDiff : (f '' s) ∆ (f '' t) ⊆ f '' s ∆ t :=
(union_subset_union (subset_image_diff _ _ _) <| subset_image_diff _ _ _).trans
(superset_of_eq (image_union _ _ _))
#align set.subset_image_symm_diff Set.subset_image_symmDiff
theorem image_diff {f : α → β} (hf : Injective f) (s t : Set α) : f '' (s \ t) = f '' s \ f '' t :=
Subset.antisymm
(Subset.trans (image_inter_subset _ _ _) <| inter_subset_inter_right _ <| image_compl_subset hf)
(subset_image_diff f s t)
#align set.image_diff Set.image_diff
theorem image_symmDiff (hf : Injective f) (s t : Set α) : f '' s ∆ t = (f '' s) ∆ (f '' t) := by
simp_rw [Set.symmDiff_def, image_union, image_diff hf]
#align set.image_symm_diff Set.image_symmDiff
theorem Nonempty.image (f : α → β) {s : Set α} : s.Nonempty → (f '' s).Nonempty
| ⟨x, hx⟩ => ⟨f x, mem_image_of_mem f hx⟩
#align set.nonempty.image Set.Nonempty.image
theorem Nonempty.of_image {f : α → β} {s : Set α} : (f '' s).Nonempty → s.Nonempty
| ⟨_, x, hx, _⟩ => ⟨x, hx⟩
#align set.nonempty.of_image Set.Nonempty.of_image
@[simp]
theorem nonempty_image_iff {f : α → β} {s : Set α} : (f '' s).Nonempty ↔ s.Nonempty :=
⟨Nonempty.of_image, fun h => h.image f⟩
#align set.nonempty_image_iff Set.nonempty_image_iff
theorem Nonempty.preimage {s : Set β} (hs : s.Nonempty) {f : α → β} (hf : Surjective f) :
(f ⁻¹' s).Nonempty :=
let ⟨y, hy⟩ := hs
let ⟨x, hx⟩ := hf y
⟨x, mem_preimage.2 <| hx.symm ▸ hy⟩
#align set.nonempty.preimage Set.Nonempty.preimage
instance (f : α → β) (s : Set α) [Nonempty s] : Nonempty (f '' s) :=
(Set.Nonempty.image f nonempty_of_nonempty_subtype).to_subtype
/-- image and preimage are a Galois connection -/
@[simp]
theorem image_subset_iff {s : Set α} {t : Set β} {f : α → β} : f '' s ⊆ t ↔ s ⊆ f ⁻¹' t :=
ball_image_iff
#align set.image_subset_iff Set.image_subset_iff
theorem image_preimage_subset (f : α → β) (s : Set β) : f '' (f ⁻¹' s) ⊆ s :=
image_subset_iff.2 Subset.rfl
#align set.image_preimage_subset Set.image_preimage_subset
theorem subset_preimage_image (f : α → β) (s : Set α) : s ⊆ f ⁻¹' (f '' s) := fun _ =>
mem_image_of_mem f
#align set.subset_preimage_image Set.subset_preimage_image
@[simp]
theorem preimage_image_eq {f : α → β} (s : Set α) (h : Injective f) : f ⁻¹' (f '' s) = s :=
Subset.antisymm (fun _ ⟨_, hy, e⟩ => h e ▸ hy) (subset_preimage_image f s)
#align set.preimage_image_eq Set.preimage_image_eq
@[simp]
theorem image_preimage_eq {f : α → β} (s : Set β) (h : Surjective f) : f '' (f ⁻¹' s) = s :=
Subset.antisymm (image_preimage_subset f s) fun x hx =>
let ⟨y, e⟩ := h x
⟨y, (e.symm ▸ hx : f y ∈ s), e⟩
#align set.image_preimage_eq Set.image_preimage_eq
@[simp]
theorem preimage_eq_preimage {f : β → α} (hf : Surjective f) : f ⁻¹' s = f ⁻¹' t ↔ s = t :=
Iff.intro
fun eq => by rw [← image_preimage_eq s hf, ← image_preimage_eq t hf, eq]
fun eq => eq ▸ rfl
#align set.preimage_eq_preimage Set.preimage_eq_preimage
theorem image_inter_preimage (f : α → β) (s : Set α) (t : Set β) :
f '' (s ∩ f ⁻¹' t) = f '' s ∩ t := by
apply Subset.antisymm
· calc
f '' (s ∩ f ⁻¹' t) ⊆ f '' s ∩ f '' (f ⁻¹' t) := image_inter_subset _ _ _
_ ⊆ f '' s ∩ t := inter_subset_inter_right _ (image_preimage_subset f t)
· rintro _ ⟨⟨x, h', rfl⟩, h⟩
exact ⟨x, ⟨h', h⟩, rfl⟩
#align set.image_inter_preimage Set.image_inter_preimage
theorem image_preimage_inter (f : α → β) (s : Set α) (t : Set β) :
f '' (f ⁻¹' t ∩ s) = t ∩ f '' s := by simp only [inter_comm, image_inter_preimage]
#align set.image_preimage_inter Set.image_preimage_inter
@[simp]
theorem image_inter_nonempty_iff {f : α → β} {s : Set α} {t : Set β} :
(f '' s ∩ t).Nonempty ↔ (s ∩ f ⁻¹' t).Nonempty := by
rw [← image_inter_preimage, nonempty_image_iff]
#align set.image_inter_nonempty_iff Set.image_inter_nonempty_iff
theorem image_diff_preimage {f : α → β} {s : Set α} {t : Set β} : f '' (s \ f ⁻¹' t) = f '' s \ t :=
by simp_rw [diff_eq, ← preimage_compl, image_inter_preimage]
#align set.image_diff_preimage Set.image_diff_preimage
theorem compl_image : image (compl : Set α → Set α) = preimage compl :=
image_eq_preimage_of_inverse compl_compl compl_compl
#align set.compl_image Set.compl_image
theorem compl_image_set_of {p : Set α → Prop} : compl '' { s | p s } = { s | p sᶜ } :=
congr_fun compl_image p
#align set.compl_image_set_of Set.compl_image_set_of
theorem inter_preimage_subset (s : Set α) (t : Set β) (f : α → β) :
s ∩ f ⁻¹' t ⊆ f ⁻¹' (f '' s ∩ t) := fun _ h => ⟨mem_image_of_mem _ h.left, h.right⟩
#align set.inter_preimage_subset Set.inter_preimage_subset
theorem union_preimage_subset (s : Set α) (t : Set β) (f : α → β) :
s ∪ f ⁻¹' t ⊆ f ⁻¹' (f '' s ∪ t) := fun _ h =>
Or.elim h (fun l => Or.inl <| mem_image_of_mem _ l) fun r => Or.inr r
#align set.union_preimage_subset Set.union_preimage_subset
theorem subset_image_union (f : α → β) (s : Set α) (t : Set β) : f '' (s ∪ f ⁻¹' t) ⊆ f '' s ∪ t :=
image_subset_iff.2 (union_preimage_subset _ _ _)
#align set.subset_image_union Set.subset_image_union
theorem preimage_subset_iff {A : Set α} {B : Set β} {f : α → β} :
f ⁻¹' B ⊆ A ↔ ∀ a : α, f a ∈ B → a ∈ A :=
Iff.rfl
#align set.preimage_subset_iff Set.preimage_subset_iff
theorem image_eq_image {f : α → β} (hf : Injective f) : f '' s = f '' t ↔ s = t :=
Iff.symm <|
(Iff.intro fun eq => eq ▸ rfl) fun eq => by
rw [← preimage_image_eq s hf, ← preimage_image_eq t hf, eq]
#align set.image_eq_image Set.image_eq_image
theorem image_subset_image_iff {f : α → β} (hf : Injective f) : f '' s ⊆ f '' t ↔ s ⊆ t := by
refine' Iff.symm <| (Iff.intro (image_subset f)) fun h => _
rw [← preimage_image_eq s hf, ← preimage_image_eq t hf]
exact preimage_mono h
#align set.image_subset_image_iff Set.image_subset_image_iff
theorem prod_quotient_preimage_eq_image [s : Setoid α] (g : Quotient s → β) {h : α → β}
(Hh : h = g ∘ Quotient.mk'') (r : Set (β × β)) :
{ x : Quotient s × Quotient s | (g x.1, g x.2) ∈ r } =
(fun a : α × α => (⟦a.1⟧, ⟦a.2⟧)) '' ((fun a : α × α => (h a.1, h a.2)) ⁻¹' r) :=
Hh.symm ▸
Set.ext fun ⟨a₁, a₂⟩ =>
⟨Quot.induction_on₂ a₁ a₂ fun a₁ a₂ h => ⟨(a₁, a₂), h, rfl⟩, fun ⟨⟨b₁, b₂⟩, h₁, h₂⟩ =>
show (g a₁, g a₂) ∈ r from
have h₃ : ⟦b₁⟧ = a₁ ∧ ⟦b₂⟧ = a₂ := Prod.ext_iff.1 h₂
h₃.1 ▸ h₃.2 ▸ h₁⟩
#align set.prod_quotient_preimage_eq_image Set.prod_quotient_preimage_eq_image
theorem exists_image_iff (f : α → β) (x : Set α) (P : β → Prop) :
(∃ a : f '' x, P a) ↔ ∃ a : x, P (f a) :=
⟨fun ⟨a, h⟩ => ⟨⟨_, a.prop.choose_spec.1⟩, a.prop.choose_spec.2.symm ▸ h⟩, fun ⟨a, h⟩ =>
⟨⟨_, _, a.prop, rfl⟩, h⟩⟩
#align set.exists_image_iff Set.exists_image_iff
/-- Restriction of `f` to `s` factors through `s.imageFactorization f : s → f '' s`. -/
def imageFactorization (f : α → β) (s : Set α) : s → f '' s := fun p =>
⟨f p.1, mem_image_of_mem f p.2⟩
#align set.image_factorization Set.imageFactorization
theorem imageFactorization_eq {f : α → β} {s : Set α} :
Subtype.val ∘ imageFactorization f s = f ∘ Subtype.val :=
funext fun _ => rfl
#align set.image_factorization_eq Set.imageFactorization_eq
theorem surjective_onto_image {f : α → β} {s : Set α} : Surjective (imageFactorization f s) :=
fun ⟨_, ⟨a, ha, rfl⟩⟩ => ⟨⟨a, ha⟩, rfl⟩
#align set.surjective_onto_image Set.surjective_onto_image
/-- If the only elements outside `s` are those left fixed by `σ`, then mapping by `σ` has no effect.
-/
theorem image_perm {s : Set α} {σ : Equiv.Perm α} (hs : { a : α | σ a ≠ a } ⊆ s) : σ '' s = s := by
ext i
obtain hi | hi := eq_or_ne (σ i) i
· refine' ⟨_, fun h => ⟨i, h, hi⟩⟩
rintro ⟨j, hj, h⟩
rwa [σ.injective (hi.trans h.symm)]
· refine' iff_of_true ⟨σ.symm i, hs fun h => hi _, σ.apply_symm_apply _⟩ (hs hi)
convert congr_arg σ h <;> exact (σ.apply_symm_apply _).symm
#align set.image_perm Set.image_perm
end Image
/-! ### Lemmas about the powerset and image. -/
/-- The powerset of `{a} ∪ s` is `𝒫 s` together with `{a} ∪ t` for each `t ∈ 𝒫 s`. -/
theorem powerset_insert (s : Set α) (a : α) : 𝒫 insert a s = 𝒫 s ∪ insert a '' 𝒫 s := by
ext t
|
simp_rw [mem_union, mem_image, mem_powerset_iff]
|
/-- The powerset of `{a} ∪ s` is `𝒫 s` together with `{a} ∪ t` for each `t ∈ 𝒫 s`. -/
theorem powerset_insert (s : Set α) (a : α) : 𝒫 insert a s = 𝒫 s ∪ insert a '' 𝒫 s := by
ext t
|
Mathlib.Data.Set.Image.651_0.IJFiTzmYGOCpPSd
|
/-- The powerset of `{a} ∪ s` is `𝒫 s` together with `{a} ∪ t` for each `t ∈ 𝒫 s`. -/
theorem powerset_insert (s : Set α) (a : α) : 𝒫 insert a s = 𝒫 s ∪ insert a '' 𝒫 s
|
Mathlib_Data_Set_Image
|
case h
α : Type u_1
β : Type u_2
γ : Type u_3
ι : Sort u_4
ι' : Sort u_5
s : Set α
a : α
t : Set α
⊢ t ⊆ insert a s ↔ t ⊆ s ∨ ∃ x ⊆ s, insert a x = t
|
/-
Copyright (c) 2014 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Leonardo de Moura
-/
import Mathlib.Data.Set.Basic
#align_import data.set.image from "leanprover-community/mathlib"@"001ffdc42920050657fd45bd2b8bfbec8eaaeb29"
/-!
# Images and preimages of sets
## Main definitions
* `preimage f t : Set α` : the preimage f⁻¹(t) (written `f ⁻¹' t` in Lean) of a subset of β.
* `range f : Set β` : the image of `univ` under `f`.
Also works for `{p : Prop} (f : p → α)` (unlike `image`)
## Notation
* `f ⁻¹' t` for `Set.preimage f t`
* `f '' s` for `Set.image f s`
## Tags
set, sets, image, preimage, pre-image, range
-/
set_option autoImplicit true
universe u v
open Function Set
namespace Set
variable {α β γ : Type*} {ι ι' : Sort*}
/-! ### Inverse image -/
/-- The preimage of `s : Set β` by `f : α → β`, written `f ⁻¹' s`,
is the set of `x : α` such that `f x ∈ s`. -/
def preimage {α : Type u} {β : Type v} (f : α → β) (s : Set β) : Set α :=
{ x | f x ∈ s }
#align set.preimage Set.preimage
/-- `f ⁻¹' t` denotes the preimage of `t : Set β` under the function `f : α → β`. -/
infixl:80 " ⁻¹' " => preimage
section Preimage
variable {f : α → β} {g : β → γ}
@[simp]
theorem preimage_empty : f ⁻¹' ∅ = ∅ :=
rfl
#align set.preimage_empty Set.preimage_empty
@[simp, mfld_simps]
theorem mem_preimage {s : Set β} {a : α} : a ∈ f ⁻¹' s ↔ f a ∈ s :=
Iff.rfl
#align set.mem_preimage Set.mem_preimage
theorem preimage_congr {f g : α → β} {s : Set β} (h : ∀ x : α, f x = g x) : f ⁻¹' s = g ⁻¹' s := by
congr with x
simp [h]
#align set.preimage_congr Set.preimage_congr
@[gcongr]
theorem preimage_mono {s t : Set β} (h : s ⊆ t) : f ⁻¹' s ⊆ f ⁻¹' t := fun _ hx => h hx
#align set.preimage_mono Set.preimage_mono
@[simp, mfld_simps]
theorem preimage_univ : f ⁻¹' univ = univ :=
rfl
#align set.preimage_univ Set.preimage_univ
theorem subset_preimage_univ {s : Set α} : s ⊆ f ⁻¹' univ :=
subset_univ _
#align set.subset_preimage_univ Set.subset_preimage_univ
@[simp, mfld_simps]
theorem preimage_inter {s t : Set β} : f ⁻¹' (s ∩ t) = f ⁻¹' s ∩ f ⁻¹' t :=
rfl
#align set.preimage_inter Set.preimage_inter
@[simp]
theorem preimage_union {s t : Set β} : f ⁻¹' (s ∪ t) = f ⁻¹' s ∪ f ⁻¹' t :=
rfl
#align set.preimage_union Set.preimage_union
@[simp]
theorem preimage_compl {s : Set β} : f ⁻¹' sᶜ = (f ⁻¹' s)ᶜ :=
rfl
#align set.preimage_compl Set.preimage_compl
@[simp]
theorem preimage_diff (f : α → β) (s t : Set β) : f ⁻¹' (s \ t) = f ⁻¹' s \ f ⁻¹' t :=
rfl
#align set.preimage_diff Set.preimage_diff
@[simp]
lemma preimage_symmDiff {f : α → β} (s t : Set β) : f ⁻¹' (s ∆ t) = (f ⁻¹' s) ∆ (f ⁻¹' t) :=
rfl
#align set.preimage_symm_diff Set.preimage_symmDiff
@[simp]
theorem preimage_ite (f : α → β) (s t₁ t₂ : Set β) :
f ⁻¹' s.ite t₁ t₂ = (f ⁻¹' s).ite (f ⁻¹' t₁) (f ⁻¹' t₂) :=
rfl
#align set.preimage_ite Set.preimage_ite
@[simp]
theorem preimage_setOf_eq {p : α → Prop} {f : β → α} : f ⁻¹' { a | p a } = { a | p (f a) } :=
rfl
#align set.preimage_set_of_eq Set.preimage_setOf_eq
@[simp]
theorem preimage_id_eq : preimage (id : α → α) = id :=
rfl
#align set.preimage_id_eq Set.preimage_id_eq
@[mfld_simps]
theorem preimage_id {s : Set α} : id ⁻¹' s = s :=
rfl
#align set.preimage_id Set.preimage_id
@[simp, mfld_simps]
theorem preimage_id' {s : Set α} : (fun x => x) ⁻¹' s = s :=
rfl
#align set.preimage_id' Set.preimage_id'
@[simp]
theorem preimage_const_of_mem {b : β} {s : Set β} (h : b ∈ s) : (fun _ : α => b) ⁻¹' s = univ :=
eq_univ_of_forall fun _ => h
#align set.preimage_const_of_mem Set.preimage_const_of_mem
@[simp]
theorem preimage_const_of_not_mem {b : β} {s : Set β} (h : b ∉ s) : (fun _ : α => b) ⁻¹' s = ∅ :=
eq_empty_of_subset_empty fun _ hx => h hx
#align set.preimage_const_of_not_mem Set.preimage_const_of_not_mem
theorem preimage_const (b : β) (s : Set β) [Decidable (b ∈ s)] :
(fun _ : α => b) ⁻¹' s = if b ∈ s then univ else ∅ := by
split_ifs with hb
exacts [preimage_const_of_mem hb, preimage_const_of_not_mem hb]
#align set.preimage_const Set.preimage_const
/-- If preimage of each singleton under `f : α → β` is either empty or the whole type,
then `f` is a constant. -/
lemma exists_eq_const_of_preimage_singleton [Nonempty β] {f : α → β}
(hf : ∀ b : β, f ⁻¹' {b} = ∅ ∨ f ⁻¹' {b} = univ) : ∃ b, f = const α b := by
rcases em (∃ b, f ⁻¹' {b} = univ) with ⟨b, hb⟩ | hf'
· exact ⟨b, funext fun x ↦ eq_univ_iff_forall.1 hb x⟩
· have : ∀ x b, f x ≠ b := fun x b ↦
eq_empty_iff_forall_not_mem.1 ((hf b).resolve_right fun h ↦ hf' ⟨b, h⟩) x
exact ⟨Classical.arbitrary β, funext fun x ↦ absurd rfl (this x _)⟩
theorem preimage_comp {s : Set γ} : g ∘ f ⁻¹' s = f ⁻¹' (g ⁻¹' s) :=
rfl
#align set.preimage_comp Set.preimage_comp
theorem preimage_comp_eq : preimage (g ∘ f) = preimage f ∘ preimage g :=
rfl
#align set.preimage_comp_eq Set.preimage_comp_eq
theorem preimage_iterate_eq {f : α → α} {n : ℕ} : Set.preimage f^[n] = (Set.preimage f)^[n] := by
induction' n with n ih; · simp
rw [iterate_succ, iterate_succ', preimage_comp_eq, ih]
#align set.preimage_iterate_eq Set.preimage_iterate_eq
theorem preimage_preimage {g : β → γ} {f : α → β} {s : Set γ} :
f ⁻¹' (g ⁻¹' s) = (fun x => g (f x)) ⁻¹' s :=
preimage_comp.symm
#align set.preimage_preimage Set.preimage_preimage
theorem eq_preimage_subtype_val_iff {p : α → Prop} {s : Set (Subtype p)} {t : Set α} :
s = Subtype.val ⁻¹' t ↔ ∀ (x) (h : p x), (⟨x, h⟩ : Subtype p) ∈ s ↔ x ∈ t :=
⟨fun s_eq x h => by
rw [s_eq]
simp, fun h => ext fun ⟨x, hx⟩ => by simp [h]⟩
#align set.eq_preimage_subtype_val_iff Set.eq_preimage_subtype_val_iff
theorem nonempty_of_nonempty_preimage {s : Set β} {f : α → β} (hf : (f ⁻¹' s).Nonempty) :
s.Nonempty :=
let ⟨x, hx⟩ := hf
⟨f x, hx⟩
#align set.nonempty_of_nonempty_preimage Set.nonempty_of_nonempty_preimage
@[simp] theorem preimage_singleton_true (p : α → Prop) : p ⁻¹' {True} = {a | p a} := by ext; simp
#align set.preimage_singleton_true Set.preimage_singleton_true
@[simp] theorem preimage_singleton_false (p : α → Prop) : p ⁻¹' {False} = {a | ¬p a} := by ext; simp
#align set.preimage_singleton_false Set.preimage_singleton_false
theorem preimage_subtype_coe_eq_compl {s u v : Set α} (hsuv : s ⊆ u ∪ v)
(H : s ∩ (u ∩ v) = ∅) : ((↑) : s → α) ⁻¹' u = ((↑) ⁻¹' v)ᶜ := by
ext ⟨x, x_in_s⟩
constructor
· intro x_in_u x_in_v
exact eq_empty_iff_forall_not_mem.mp H x ⟨x_in_s, ⟨x_in_u, x_in_v⟩⟩
· intro hx
exact Or.elim (hsuv x_in_s) id fun hx' => hx.elim hx'
#align set.preimage_subtype_coe_eq_compl Set.preimage_subtype_coe_eq_compl
end Preimage
/-! ### Image of a set under a function -/
section Image
variable {f : α → β} {s t : Set α}
-- Porting note: `Set.image` is already defined in `Init.Set`
#align set.image Set.image
/-- `f '' s` denotes the image of `s : Set α` under the function `f : α → β`. -/
infixl:80 " '' " => image
theorem mem_image_iff_bex {f : α → β} {s : Set α} {y : β} :
y ∈ f '' s ↔ ∃ (x : _) (_ : x ∈ s), f x = y :=
bex_def.symm
#align set.mem_image_iff_bex Set.mem_image_iff_bex
@[simp]
theorem mem_image (f : α → β) (s : Set α) (y : β) : y ∈ f '' s ↔ ∃ x ∈ s, f x = y :=
Iff.rfl
#align set.mem_image Set.mem_image
theorem image_eta (f : α → β) : f '' s = (fun x => f x) '' s :=
rfl
#align set.image_eta Set.image_eta
@[mfld_simps]
theorem mem_image_of_mem (f : α → β) {x : α} {a : Set α} (h : x ∈ a) : f x ∈ f '' a :=
⟨_, h, rfl⟩
#align set.mem_image_of_mem Set.mem_image_of_mem
theorem _root_.Function.Injective.mem_set_image {f : α → β} (hf : Injective f) {s : Set α} {a : α} :
f a ∈ f '' s ↔ a ∈ s :=
⟨fun ⟨_, hb, Eq⟩ => hf Eq ▸ hb, mem_image_of_mem f⟩
#align function.injective.mem_set_image Function.Injective.mem_set_image
theorem ball_image_iff {f : α → β} {s : Set α} {p : β → Prop} :
(∀ y ∈ f '' s, p y) ↔ ∀ x ∈ s, p (f x) := by simp
#align set.ball_image_iff Set.ball_image_iff
theorem ball_image_of_ball {f : α → β} {s : Set α} {p : β → Prop} (h : ∀ x ∈ s, p (f x)) :
∀ y ∈ f '' s, p y :=
ball_image_iff.2 h
#align set.ball_image_of_ball Set.ball_image_of_ball
theorem bex_image_iff {f : α → β} {s : Set α} {p : β → Prop} :
(∃ y ∈ f '' s, p y) ↔ ∃ x ∈ s, p (f x) := by simp
#align set.bex_image_iff Set.bex_image_iff
theorem mem_image_elim {f : α → β} {s : Set α} {C : β → Prop} (h : ∀ x : α, x ∈ s → C (f x)) :
∀ {y : β}, y ∈ f '' s → C y
| _, ⟨a, a_in, rfl⟩ => h a a_in
#align set.mem_image_elim Set.mem_image_elim
theorem mem_image_elim_on {f : α → β} {s : Set α} {C : β → Prop} {y : β} (h_y : y ∈ f '' s)
(h : ∀ x : α, x ∈ s → C (f x)) : C y :=
mem_image_elim h h_y
#align set.mem_image_elim_on Set.mem_image_elim_on
-- Porting note: used to be `safe`
@[congr]
theorem image_congr {f g : α → β} {s : Set α} (h : ∀ a ∈ s, f a = g a) : f '' s = g '' s := by
ext x
rw [mem_image, mem_image]
exact {
mp := by
rintro ⟨a, ha1, ha2⟩
exact ⟨a, ⟨ha1, (h a ha1) ▸ ha2⟩⟩,
mpr := by
rintro ⟨a, ha1, ha2⟩
exact ⟨a, ⟨ha1, (h a ha1) ▸ ha2⟩⟩
}
-- safe [ext_iff, iff_def]
#align set.image_congr Set.image_congr
/-- A common special case of `image_congr` -/
theorem image_congr' {f g : α → β} {s : Set α} (h : ∀ x : α, f x = g x) : f '' s = g '' s :=
image_congr fun x _ => h x
#align set.image_congr' Set.image_congr'
@[gcongr]
lemma image_mono (h : s ⊆ t) : f '' s ⊆ f '' t := by
rintro - ⟨a, ha, rfl⟩; exact mem_image_of_mem f (h ha)
theorem image_comp (f : β → γ) (g : α → β) (a : Set α) : f ∘ g '' a = f '' (g '' a) :=
Subset.antisymm (ball_image_of_ball fun _ ha => mem_image_of_mem _ <| mem_image_of_mem _ ha)
(ball_image_of_ball <| ball_image_of_ball fun _ ha => mem_image_of_mem _ ha)
#align set.image_comp Set.image_comp
theorem image_comp_eq {g : β → γ} : image (g ∘ f) = image g ∘ image f := by ext; simp
/-- A variant of `image_comp`, useful for rewriting -/
theorem image_image (g : β → γ) (f : α → β) (s : Set α) : g '' (f '' s) = (fun x => g (f x)) '' s :=
(image_comp g f s).symm
#align set.image_image Set.image_image
theorem image_comm {β'} {f : β → γ} {g : α → β} {f' : α → β'} {g' : β' → γ}
(h_comm : ∀ a, f (g a) = g' (f' a)) : (s.image g).image f = (s.image f').image g' := by
simp_rw [image_image, h_comm]
#align set.image_comm Set.image_comm
theorem _root_.Function.Semiconj.set_image {f : α → β} {ga : α → α} {gb : β → β}
(h : Function.Semiconj f ga gb) : Function.Semiconj (image f) (image ga) (image gb) := fun _ =>
image_comm h
#align function.semiconj.set_image Function.Semiconj.set_image
theorem _root_.Function.Commute.set_image {f g : α → α} (h : Function.Commute f g) :
Function.Commute (image f) (image g) :=
Function.Semiconj.set_image h
#align function.commute.set_image Function.Commute.set_image
/-- Image is monotone with respect to `⊆`. See `Set.monotone_image` for the statement in
terms of `≤`. -/
@[gcongr]
theorem image_subset {a b : Set α} (f : α → β) (h : a ⊆ b) : f '' a ⊆ f '' b := by
simp only [subset_def, mem_image]
exact fun x => fun ⟨w, h1, h2⟩ => ⟨w, h h1, h2⟩
#align set.image_subset Set.image_subset
/-- `Set.image` is monotone. See `Set.image_subset` for the statement in terms of `⊆`. -/
lemma monotone_image {f : α → β} : Monotone (image f) := fun _ _ => image_subset _
#align set.monotone_image Set.monotone_image
theorem image_union (f : α → β) (s t : Set α) : f '' (s ∪ t) = f '' s ∪ f '' t :=
ext fun x =>
⟨by rintro ⟨a, h | h, rfl⟩ <;> [left; right] <;> exact ⟨_, h, rfl⟩, by
rintro (⟨a, h, rfl⟩ | ⟨a, h, rfl⟩) <;> refine' ⟨_, _, rfl⟩ <;> [left; right] <;> exact h⟩
#align set.image_union Set.image_union
@[simp]
theorem image_empty (f : α → β) : f '' ∅ = ∅ := by
ext
simp
#align set.image_empty Set.image_empty
theorem image_inter_subset (f : α → β) (s t : Set α) : f '' (s ∩ t) ⊆ f '' s ∩ f '' t :=
subset_inter (image_subset _ <| inter_subset_left _ _) (image_subset _ <| inter_subset_right _ _)
#align set.image_inter_subset Set.image_inter_subset
theorem image_inter_on {f : α → β} {s t : Set α} (h : ∀ x ∈ t, ∀ y ∈ s, f x = f y → x = y) :
f '' (s ∩ t) = f '' s ∩ f '' t :=
(image_inter_subset _ _ _).antisymm
fun b ⟨⟨a₁, ha₁, h₁⟩, ⟨a₂, ha₂, h₂⟩⟩ ↦
have : a₂ = a₁ := h _ ha₂ _ ha₁ (by simp [*])
⟨a₁, ⟨ha₁, this ▸ ha₂⟩, h₁⟩
#align set.image_inter_on Set.image_inter_on
theorem image_inter {f : α → β} {s t : Set α} (H : Injective f) : f '' (s ∩ t) = f '' s ∩ f '' t :=
image_inter_on fun _ _ _ _ h => H h
#align set.image_inter Set.image_inter
theorem image_univ_of_surjective {ι : Type*} {f : ι → β} (H : Surjective f) : f '' univ = univ :=
eq_univ_of_forall <| by simpa [image]
#align set.image_univ_of_surjective Set.image_univ_of_surjective
@[simp]
theorem image_singleton {f : α → β} {a : α} : f '' {a} = {f a} := by
ext
simp [image, eq_comm]
#align set.image_singleton Set.image_singleton
@[simp]
theorem Nonempty.image_const {s : Set α} (hs : s.Nonempty) (a : β) : (fun _ => a) '' s = {a} :=
ext fun _ =>
⟨fun ⟨_, _, h⟩ => h ▸ mem_singleton _, fun h =>
(eq_of_mem_singleton h).symm ▸ hs.imp fun _ hy => ⟨hy, rfl⟩⟩
#align set.nonempty.image_const Set.Nonempty.image_const
@[simp, mfld_simps]
theorem image_eq_empty {α β} {f : α → β} {s : Set α} : f '' s = ∅ ↔ s = ∅ := by
simp only [eq_empty_iff_forall_not_mem]
exact ⟨fun H a ha => H _ ⟨_, ha, rfl⟩, fun H b ⟨_, ha, _⟩ => H _ ha⟩
#align set.image_eq_empty Set.image_eq_empty
-- Porting note: `compl` is already defined in `Init.Set`
theorem preimage_compl_eq_image_compl [BooleanAlgebra α] (S : Set α) :
HasCompl.compl ⁻¹' S = HasCompl.compl '' S :=
Set.ext fun x =>
⟨fun h => ⟨xᶜ, h, compl_compl x⟩, fun h =>
Exists.elim h fun _ hy => (compl_eq_comm.mp hy.2).symm.subst hy.1⟩
#align set.preimage_compl_eq_image_compl Set.preimage_compl_eq_image_compl
theorem mem_compl_image [BooleanAlgebra α] (t : α) (S : Set α) :
t ∈ HasCompl.compl '' S ↔ tᶜ ∈ S := by
simp [← preimage_compl_eq_image_compl]
#align set.mem_compl_image Set.mem_compl_image
@[simp]
theorem image_id_eq : image (id : α → α) = id := by ext; simp
/-- A variant of `image_id` -/
@[simp]
theorem image_id' (s : Set α) : (fun x => x) '' s = s := by
ext
simp
#align set.image_id' Set.image_id'
theorem image_id (s : Set α) : id '' s = s := by simp
#align set.image_id Set.image_id
lemma image_iterate_eq {f : α → α} {n : ℕ} : image (f^[n]) = (image f)^[n] := by
induction' n with n ih; · simp
rw [iterate_succ', iterate_succ',← ih, image_comp_eq]
theorem compl_compl_image [BooleanAlgebra α] (S : Set α) :
HasCompl.compl '' (HasCompl.compl '' S) = S := by
rw [← image_comp, compl_comp_compl, image_id]
#align set.compl_compl_image Set.compl_compl_image
theorem image_insert_eq {f : α → β} {a : α} {s : Set α} :
f '' insert a s = insert (f a) (f '' s) := by
ext
simp [and_or_left, exists_or, eq_comm, or_comm, and_comm]
#align set.image_insert_eq Set.image_insert_eq
theorem image_pair (f : α → β) (a b : α) : f '' {a, b} = {f a, f b} := by
simp only [image_insert_eq, image_singleton]
#align set.image_pair Set.image_pair
theorem image_subset_preimage_of_inverse {f : α → β} {g : β → α} (I : LeftInverse g f) (s : Set α) :
f '' s ⊆ g ⁻¹' s := fun _ ⟨a, h, e⟩ => e ▸ ((I a).symm ▸ h : g (f a) ∈ s)
#align set.image_subset_preimage_of_inverse Set.image_subset_preimage_of_inverse
theorem preimage_subset_image_of_inverse {f : α → β} {g : β → α} (I : LeftInverse g f) (s : Set β) :
f ⁻¹' s ⊆ g '' s := fun b h => ⟨f b, h, I b⟩
#align set.preimage_subset_image_of_inverse Set.preimage_subset_image_of_inverse
theorem image_eq_preimage_of_inverse {f : α → β} {g : β → α} (h₁ : LeftInverse g f)
(h₂ : RightInverse g f) : image f = preimage g :=
funext fun s =>
Subset.antisymm (image_subset_preimage_of_inverse h₁ s) (preimage_subset_image_of_inverse h₂ s)
#align set.image_eq_preimage_of_inverse Set.image_eq_preimage_of_inverse
theorem mem_image_iff_of_inverse {f : α → β} {g : β → α} {b : β} {s : Set α} (h₁ : LeftInverse g f)
(h₂ : RightInverse g f) : b ∈ f '' s ↔ g b ∈ s := by
rw [image_eq_preimage_of_inverse h₁ h₂]; rfl
#align set.mem_image_iff_of_inverse Set.mem_image_iff_of_inverse
theorem image_compl_subset {f : α → β} {s : Set α} (H : Injective f) : f '' sᶜ ⊆ (f '' s)ᶜ :=
Disjoint.subset_compl_left <| by simp [disjoint_iff_inf_le, ← image_inter H]
#align set.image_compl_subset Set.image_compl_subset
theorem subset_image_compl {f : α → β} {s : Set α} (H : Surjective f) : (f '' s)ᶜ ⊆ f '' sᶜ :=
compl_subset_iff_union.2 <| by
rw [← image_union]
simp [image_univ_of_surjective H]
#align set.subset_image_compl Set.subset_image_compl
theorem image_compl_eq {f : α → β} {s : Set α} (H : Bijective f) : f '' sᶜ = (f '' s)ᶜ :=
Subset.antisymm (image_compl_subset H.1) (subset_image_compl H.2)
#align set.image_compl_eq Set.image_compl_eq
theorem subset_image_diff (f : α → β) (s t : Set α) : f '' s \ f '' t ⊆ f '' (s \ t) := by
rw [diff_subset_iff, ← image_union, union_diff_self]
exact image_subset f (subset_union_right t s)
#align set.subset_image_diff Set.subset_image_diff
theorem subset_image_symmDiff : (f '' s) ∆ (f '' t) ⊆ f '' s ∆ t :=
(union_subset_union (subset_image_diff _ _ _) <| subset_image_diff _ _ _).trans
(superset_of_eq (image_union _ _ _))
#align set.subset_image_symm_diff Set.subset_image_symmDiff
theorem image_diff {f : α → β} (hf : Injective f) (s t : Set α) : f '' (s \ t) = f '' s \ f '' t :=
Subset.antisymm
(Subset.trans (image_inter_subset _ _ _) <| inter_subset_inter_right _ <| image_compl_subset hf)
(subset_image_diff f s t)
#align set.image_diff Set.image_diff
theorem image_symmDiff (hf : Injective f) (s t : Set α) : f '' s ∆ t = (f '' s) ∆ (f '' t) := by
simp_rw [Set.symmDiff_def, image_union, image_diff hf]
#align set.image_symm_diff Set.image_symmDiff
theorem Nonempty.image (f : α → β) {s : Set α} : s.Nonempty → (f '' s).Nonempty
| ⟨x, hx⟩ => ⟨f x, mem_image_of_mem f hx⟩
#align set.nonempty.image Set.Nonempty.image
theorem Nonempty.of_image {f : α → β} {s : Set α} : (f '' s).Nonempty → s.Nonempty
| ⟨_, x, hx, _⟩ => ⟨x, hx⟩
#align set.nonempty.of_image Set.Nonempty.of_image
@[simp]
theorem nonempty_image_iff {f : α → β} {s : Set α} : (f '' s).Nonempty ↔ s.Nonempty :=
⟨Nonempty.of_image, fun h => h.image f⟩
#align set.nonempty_image_iff Set.nonempty_image_iff
theorem Nonempty.preimage {s : Set β} (hs : s.Nonempty) {f : α → β} (hf : Surjective f) :
(f ⁻¹' s).Nonempty :=
let ⟨y, hy⟩ := hs
let ⟨x, hx⟩ := hf y
⟨x, mem_preimage.2 <| hx.symm ▸ hy⟩
#align set.nonempty.preimage Set.Nonempty.preimage
instance (f : α → β) (s : Set α) [Nonempty s] : Nonempty (f '' s) :=
(Set.Nonempty.image f nonempty_of_nonempty_subtype).to_subtype
/-- image and preimage are a Galois connection -/
@[simp]
theorem image_subset_iff {s : Set α} {t : Set β} {f : α → β} : f '' s ⊆ t ↔ s ⊆ f ⁻¹' t :=
ball_image_iff
#align set.image_subset_iff Set.image_subset_iff
theorem image_preimage_subset (f : α → β) (s : Set β) : f '' (f ⁻¹' s) ⊆ s :=
image_subset_iff.2 Subset.rfl
#align set.image_preimage_subset Set.image_preimage_subset
theorem subset_preimage_image (f : α → β) (s : Set α) : s ⊆ f ⁻¹' (f '' s) := fun _ =>
mem_image_of_mem f
#align set.subset_preimage_image Set.subset_preimage_image
@[simp]
theorem preimage_image_eq {f : α → β} (s : Set α) (h : Injective f) : f ⁻¹' (f '' s) = s :=
Subset.antisymm (fun _ ⟨_, hy, e⟩ => h e ▸ hy) (subset_preimage_image f s)
#align set.preimage_image_eq Set.preimage_image_eq
@[simp]
theorem image_preimage_eq {f : α → β} (s : Set β) (h : Surjective f) : f '' (f ⁻¹' s) = s :=
Subset.antisymm (image_preimage_subset f s) fun x hx =>
let ⟨y, e⟩ := h x
⟨y, (e.symm ▸ hx : f y ∈ s), e⟩
#align set.image_preimage_eq Set.image_preimage_eq
@[simp]
theorem preimage_eq_preimage {f : β → α} (hf : Surjective f) : f ⁻¹' s = f ⁻¹' t ↔ s = t :=
Iff.intro
fun eq => by rw [← image_preimage_eq s hf, ← image_preimage_eq t hf, eq]
fun eq => eq ▸ rfl
#align set.preimage_eq_preimage Set.preimage_eq_preimage
theorem image_inter_preimage (f : α → β) (s : Set α) (t : Set β) :
f '' (s ∩ f ⁻¹' t) = f '' s ∩ t := by
apply Subset.antisymm
· calc
f '' (s ∩ f ⁻¹' t) ⊆ f '' s ∩ f '' (f ⁻¹' t) := image_inter_subset _ _ _
_ ⊆ f '' s ∩ t := inter_subset_inter_right _ (image_preimage_subset f t)
· rintro _ ⟨⟨x, h', rfl⟩, h⟩
exact ⟨x, ⟨h', h⟩, rfl⟩
#align set.image_inter_preimage Set.image_inter_preimage
theorem image_preimage_inter (f : α → β) (s : Set α) (t : Set β) :
f '' (f ⁻¹' t ∩ s) = t ∩ f '' s := by simp only [inter_comm, image_inter_preimage]
#align set.image_preimage_inter Set.image_preimage_inter
@[simp]
theorem image_inter_nonempty_iff {f : α → β} {s : Set α} {t : Set β} :
(f '' s ∩ t).Nonempty ↔ (s ∩ f ⁻¹' t).Nonempty := by
rw [← image_inter_preimage, nonempty_image_iff]
#align set.image_inter_nonempty_iff Set.image_inter_nonempty_iff
theorem image_diff_preimage {f : α → β} {s : Set α} {t : Set β} : f '' (s \ f ⁻¹' t) = f '' s \ t :=
by simp_rw [diff_eq, ← preimage_compl, image_inter_preimage]
#align set.image_diff_preimage Set.image_diff_preimage
theorem compl_image : image (compl : Set α → Set α) = preimage compl :=
image_eq_preimage_of_inverse compl_compl compl_compl
#align set.compl_image Set.compl_image
theorem compl_image_set_of {p : Set α → Prop} : compl '' { s | p s } = { s | p sᶜ } :=
congr_fun compl_image p
#align set.compl_image_set_of Set.compl_image_set_of
theorem inter_preimage_subset (s : Set α) (t : Set β) (f : α → β) :
s ∩ f ⁻¹' t ⊆ f ⁻¹' (f '' s ∩ t) := fun _ h => ⟨mem_image_of_mem _ h.left, h.right⟩
#align set.inter_preimage_subset Set.inter_preimage_subset
theorem union_preimage_subset (s : Set α) (t : Set β) (f : α → β) :
s ∪ f ⁻¹' t ⊆ f ⁻¹' (f '' s ∪ t) := fun _ h =>
Or.elim h (fun l => Or.inl <| mem_image_of_mem _ l) fun r => Or.inr r
#align set.union_preimage_subset Set.union_preimage_subset
theorem subset_image_union (f : α → β) (s : Set α) (t : Set β) : f '' (s ∪ f ⁻¹' t) ⊆ f '' s ∪ t :=
image_subset_iff.2 (union_preimage_subset _ _ _)
#align set.subset_image_union Set.subset_image_union
theorem preimage_subset_iff {A : Set α} {B : Set β} {f : α → β} :
f ⁻¹' B ⊆ A ↔ ∀ a : α, f a ∈ B → a ∈ A :=
Iff.rfl
#align set.preimage_subset_iff Set.preimage_subset_iff
theorem image_eq_image {f : α → β} (hf : Injective f) : f '' s = f '' t ↔ s = t :=
Iff.symm <|
(Iff.intro fun eq => eq ▸ rfl) fun eq => by
rw [← preimage_image_eq s hf, ← preimage_image_eq t hf, eq]
#align set.image_eq_image Set.image_eq_image
theorem image_subset_image_iff {f : α → β} (hf : Injective f) : f '' s ⊆ f '' t ↔ s ⊆ t := by
refine' Iff.symm <| (Iff.intro (image_subset f)) fun h => _
rw [← preimage_image_eq s hf, ← preimage_image_eq t hf]
exact preimage_mono h
#align set.image_subset_image_iff Set.image_subset_image_iff
theorem prod_quotient_preimage_eq_image [s : Setoid α] (g : Quotient s → β) {h : α → β}
(Hh : h = g ∘ Quotient.mk'') (r : Set (β × β)) :
{ x : Quotient s × Quotient s | (g x.1, g x.2) ∈ r } =
(fun a : α × α => (⟦a.1⟧, ⟦a.2⟧)) '' ((fun a : α × α => (h a.1, h a.2)) ⁻¹' r) :=
Hh.symm ▸
Set.ext fun ⟨a₁, a₂⟩ =>
⟨Quot.induction_on₂ a₁ a₂ fun a₁ a₂ h => ⟨(a₁, a₂), h, rfl⟩, fun ⟨⟨b₁, b₂⟩, h₁, h₂⟩ =>
show (g a₁, g a₂) ∈ r from
have h₃ : ⟦b₁⟧ = a₁ ∧ ⟦b₂⟧ = a₂ := Prod.ext_iff.1 h₂
h₃.1 ▸ h₃.2 ▸ h₁⟩
#align set.prod_quotient_preimage_eq_image Set.prod_quotient_preimage_eq_image
theorem exists_image_iff (f : α → β) (x : Set α) (P : β → Prop) :
(∃ a : f '' x, P a) ↔ ∃ a : x, P (f a) :=
⟨fun ⟨a, h⟩ => ⟨⟨_, a.prop.choose_spec.1⟩, a.prop.choose_spec.2.symm ▸ h⟩, fun ⟨a, h⟩ =>
⟨⟨_, _, a.prop, rfl⟩, h⟩⟩
#align set.exists_image_iff Set.exists_image_iff
/-- Restriction of `f` to `s` factors through `s.imageFactorization f : s → f '' s`. -/
def imageFactorization (f : α → β) (s : Set α) : s → f '' s := fun p =>
⟨f p.1, mem_image_of_mem f p.2⟩
#align set.image_factorization Set.imageFactorization
theorem imageFactorization_eq {f : α → β} {s : Set α} :
Subtype.val ∘ imageFactorization f s = f ∘ Subtype.val :=
funext fun _ => rfl
#align set.image_factorization_eq Set.imageFactorization_eq
theorem surjective_onto_image {f : α → β} {s : Set α} : Surjective (imageFactorization f s) :=
fun ⟨_, ⟨a, ha, rfl⟩⟩ => ⟨⟨a, ha⟩, rfl⟩
#align set.surjective_onto_image Set.surjective_onto_image
/-- If the only elements outside `s` are those left fixed by `σ`, then mapping by `σ` has no effect.
-/
theorem image_perm {s : Set α} {σ : Equiv.Perm α} (hs : { a : α | σ a ≠ a } ⊆ s) : σ '' s = s := by
ext i
obtain hi | hi := eq_or_ne (σ i) i
· refine' ⟨_, fun h => ⟨i, h, hi⟩⟩
rintro ⟨j, hj, h⟩
rwa [σ.injective (hi.trans h.symm)]
· refine' iff_of_true ⟨σ.symm i, hs fun h => hi _, σ.apply_symm_apply _⟩ (hs hi)
convert congr_arg σ h <;> exact (σ.apply_symm_apply _).symm
#align set.image_perm Set.image_perm
end Image
/-! ### Lemmas about the powerset and image. -/
/-- The powerset of `{a} ∪ s` is `𝒫 s` together with `{a} ∪ t` for each `t ∈ 𝒫 s`. -/
theorem powerset_insert (s : Set α) (a : α) : 𝒫 insert a s = 𝒫 s ∪ insert a '' 𝒫 s := by
ext t
simp_rw [mem_union, mem_image, mem_powerset_iff]
|
constructor
|
/-- The powerset of `{a} ∪ s` is `𝒫 s` together with `{a} ∪ t` for each `t ∈ 𝒫 s`. -/
theorem powerset_insert (s : Set α) (a : α) : 𝒫 insert a s = 𝒫 s ∪ insert a '' 𝒫 s := by
ext t
simp_rw [mem_union, mem_image, mem_powerset_iff]
|
Mathlib.Data.Set.Image.651_0.IJFiTzmYGOCpPSd
|
/-- The powerset of `{a} ∪ s` is `𝒫 s` together with `{a} ∪ t` for each `t ∈ 𝒫 s`. -/
theorem powerset_insert (s : Set α) (a : α) : 𝒫 insert a s = 𝒫 s ∪ insert a '' 𝒫 s
|
Mathlib_Data_Set_Image
|
case h.mp
α : Type u_1
β : Type u_2
γ : Type u_3
ι : Sort u_4
ι' : Sort u_5
s : Set α
a : α
t : Set α
⊢ t ⊆ insert a s → t ⊆ s ∨ ∃ x ⊆ s, insert a x = t
|
/-
Copyright (c) 2014 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Leonardo de Moura
-/
import Mathlib.Data.Set.Basic
#align_import data.set.image from "leanprover-community/mathlib"@"001ffdc42920050657fd45bd2b8bfbec8eaaeb29"
/-!
# Images and preimages of sets
## Main definitions
* `preimage f t : Set α` : the preimage f⁻¹(t) (written `f ⁻¹' t` in Lean) of a subset of β.
* `range f : Set β` : the image of `univ` under `f`.
Also works for `{p : Prop} (f : p → α)` (unlike `image`)
## Notation
* `f ⁻¹' t` for `Set.preimage f t`
* `f '' s` for `Set.image f s`
## Tags
set, sets, image, preimage, pre-image, range
-/
set_option autoImplicit true
universe u v
open Function Set
namespace Set
variable {α β γ : Type*} {ι ι' : Sort*}
/-! ### Inverse image -/
/-- The preimage of `s : Set β` by `f : α → β`, written `f ⁻¹' s`,
is the set of `x : α` such that `f x ∈ s`. -/
def preimage {α : Type u} {β : Type v} (f : α → β) (s : Set β) : Set α :=
{ x | f x ∈ s }
#align set.preimage Set.preimage
/-- `f ⁻¹' t` denotes the preimage of `t : Set β` under the function `f : α → β`. -/
infixl:80 " ⁻¹' " => preimage
section Preimage
variable {f : α → β} {g : β → γ}
@[simp]
theorem preimage_empty : f ⁻¹' ∅ = ∅ :=
rfl
#align set.preimage_empty Set.preimage_empty
@[simp, mfld_simps]
theorem mem_preimage {s : Set β} {a : α} : a ∈ f ⁻¹' s ↔ f a ∈ s :=
Iff.rfl
#align set.mem_preimage Set.mem_preimage
theorem preimage_congr {f g : α → β} {s : Set β} (h : ∀ x : α, f x = g x) : f ⁻¹' s = g ⁻¹' s := by
congr with x
simp [h]
#align set.preimage_congr Set.preimage_congr
@[gcongr]
theorem preimage_mono {s t : Set β} (h : s ⊆ t) : f ⁻¹' s ⊆ f ⁻¹' t := fun _ hx => h hx
#align set.preimage_mono Set.preimage_mono
@[simp, mfld_simps]
theorem preimage_univ : f ⁻¹' univ = univ :=
rfl
#align set.preimage_univ Set.preimage_univ
theorem subset_preimage_univ {s : Set α} : s ⊆ f ⁻¹' univ :=
subset_univ _
#align set.subset_preimage_univ Set.subset_preimage_univ
@[simp, mfld_simps]
theorem preimage_inter {s t : Set β} : f ⁻¹' (s ∩ t) = f ⁻¹' s ∩ f ⁻¹' t :=
rfl
#align set.preimage_inter Set.preimage_inter
@[simp]
theorem preimage_union {s t : Set β} : f ⁻¹' (s ∪ t) = f ⁻¹' s ∪ f ⁻¹' t :=
rfl
#align set.preimage_union Set.preimage_union
@[simp]
theorem preimage_compl {s : Set β} : f ⁻¹' sᶜ = (f ⁻¹' s)ᶜ :=
rfl
#align set.preimage_compl Set.preimage_compl
@[simp]
theorem preimage_diff (f : α → β) (s t : Set β) : f ⁻¹' (s \ t) = f ⁻¹' s \ f ⁻¹' t :=
rfl
#align set.preimage_diff Set.preimage_diff
@[simp]
lemma preimage_symmDiff {f : α → β} (s t : Set β) : f ⁻¹' (s ∆ t) = (f ⁻¹' s) ∆ (f ⁻¹' t) :=
rfl
#align set.preimage_symm_diff Set.preimage_symmDiff
@[simp]
theorem preimage_ite (f : α → β) (s t₁ t₂ : Set β) :
f ⁻¹' s.ite t₁ t₂ = (f ⁻¹' s).ite (f ⁻¹' t₁) (f ⁻¹' t₂) :=
rfl
#align set.preimage_ite Set.preimage_ite
@[simp]
theorem preimage_setOf_eq {p : α → Prop} {f : β → α} : f ⁻¹' { a | p a } = { a | p (f a) } :=
rfl
#align set.preimage_set_of_eq Set.preimage_setOf_eq
@[simp]
theorem preimage_id_eq : preimage (id : α → α) = id :=
rfl
#align set.preimage_id_eq Set.preimage_id_eq
@[mfld_simps]
theorem preimage_id {s : Set α} : id ⁻¹' s = s :=
rfl
#align set.preimage_id Set.preimage_id
@[simp, mfld_simps]
theorem preimage_id' {s : Set α} : (fun x => x) ⁻¹' s = s :=
rfl
#align set.preimage_id' Set.preimage_id'
@[simp]
theorem preimage_const_of_mem {b : β} {s : Set β} (h : b ∈ s) : (fun _ : α => b) ⁻¹' s = univ :=
eq_univ_of_forall fun _ => h
#align set.preimage_const_of_mem Set.preimage_const_of_mem
@[simp]
theorem preimage_const_of_not_mem {b : β} {s : Set β} (h : b ∉ s) : (fun _ : α => b) ⁻¹' s = ∅ :=
eq_empty_of_subset_empty fun _ hx => h hx
#align set.preimage_const_of_not_mem Set.preimage_const_of_not_mem
theorem preimage_const (b : β) (s : Set β) [Decidable (b ∈ s)] :
(fun _ : α => b) ⁻¹' s = if b ∈ s then univ else ∅ := by
split_ifs with hb
exacts [preimage_const_of_mem hb, preimage_const_of_not_mem hb]
#align set.preimage_const Set.preimage_const
/-- If preimage of each singleton under `f : α → β` is either empty or the whole type,
then `f` is a constant. -/
lemma exists_eq_const_of_preimage_singleton [Nonempty β] {f : α → β}
(hf : ∀ b : β, f ⁻¹' {b} = ∅ ∨ f ⁻¹' {b} = univ) : ∃ b, f = const α b := by
rcases em (∃ b, f ⁻¹' {b} = univ) with ⟨b, hb⟩ | hf'
· exact ⟨b, funext fun x ↦ eq_univ_iff_forall.1 hb x⟩
· have : ∀ x b, f x ≠ b := fun x b ↦
eq_empty_iff_forall_not_mem.1 ((hf b).resolve_right fun h ↦ hf' ⟨b, h⟩) x
exact ⟨Classical.arbitrary β, funext fun x ↦ absurd rfl (this x _)⟩
theorem preimage_comp {s : Set γ} : g ∘ f ⁻¹' s = f ⁻¹' (g ⁻¹' s) :=
rfl
#align set.preimage_comp Set.preimage_comp
theorem preimage_comp_eq : preimage (g ∘ f) = preimage f ∘ preimage g :=
rfl
#align set.preimage_comp_eq Set.preimage_comp_eq
theorem preimage_iterate_eq {f : α → α} {n : ℕ} : Set.preimage f^[n] = (Set.preimage f)^[n] := by
induction' n with n ih; · simp
rw [iterate_succ, iterate_succ', preimage_comp_eq, ih]
#align set.preimage_iterate_eq Set.preimage_iterate_eq
theorem preimage_preimage {g : β → γ} {f : α → β} {s : Set γ} :
f ⁻¹' (g ⁻¹' s) = (fun x => g (f x)) ⁻¹' s :=
preimage_comp.symm
#align set.preimage_preimage Set.preimage_preimage
theorem eq_preimage_subtype_val_iff {p : α → Prop} {s : Set (Subtype p)} {t : Set α} :
s = Subtype.val ⁻¹' t ↔ ∀ (x) (h : p x), (⟨x, h⟩ : Subtype p) ∈ s ↔ x ∈ t :=
⟨fun s_eq x h => by
rw [s_eq]
simp, fun h => ext fun ⟨x, hx⟩ => by simp [h]⟩
#align set.eq_preimage_subtype_val_iff Set.eq_preimage_subtype_val_iff
theorem nonempty_of_nonempty_preimage {s : Set β} {f : α → β} (hf : (f ⁻¹' s).Nonempty) :
s.Nonempty :=
let ⟨x, hx⟩ := hf
⟨f x, hx⟩
#align set.nonempty_of_nonempty_preimage Set.nonempty_of_nonempty_preimage
@[simp] theorem preimage_singleton_true (p : α → Prop) : p ⁻¹' {True} = {a | p a} := by ext; simp
#align set.preimage_singleton_true Set.preimage_singleton_true
@[simp] theorem preimage_singleton_false (p : α → Prop) : p ⁻¹' {False} = {a | ¬p a} := by ext; simp
#align set.preimage_singleton_false Set.preimage_singleton_false
theorem preimage_subtype_coe_eq_compl {s u v : Set α} (hsuv : s ⊆ u ∪ v)
(H : s ∩ (u ∩ v) = ∅) : ((↑) : s → α) ⁻¹' u = ((↑) ⁻¹' v)ᶜ := by
ext ⟨x, x_in_s⟩
constructor
· intro x_in_u x_in_v
exact eq_empty_iff_forall_not_mem.mp H x ⟨x_in_s, ⟨x_in_u, x_in_v⟩⟩
· intro hx
exact Or.elim (hsuv x_in_s) id fun hx' => hx.elim hx'
#align set.preimage_subtype_coe_eq_compl Set.preimage_subtype_coe_eq_compl
end Preimage
/-! ### Image of a set under a function -/
section Image
variable {f : α → β} {s t : Set α}
-- Porting note: `Set.image` is already defined in `Init.Set`
#align set.image Set.image
/-- `f '' s` denotes the image of `s : Set α` under the function `f : α → β`. -/
infixl:80 " '' " => image
theorem mem_image_iff_bex {f : α → β} {s : Set α} {y : β} :
y ∈ f '' s ↔ ∃ (x : _) (_ : x ∈ s), f x = y :=
bex_def.symm
#align set.mem_image_iff_bex Set.mem_image_iff_bex
@[simp]
theorem mem_image (f : α → β) (s : Set α) (y : β) : y ∈ f '' s ↔ ∃ x ∈ s, f x = y :=
Iff.rfl
#align set.mem_image Set.mem_image
theorem image_eta (f : α → β) : f '' s = (fun x => f x) '' s :=
rfl
#align set.image_eta Set.image_eta
@[mfld_simps]
theorem mem_image_of_mem (f : α → β) {x : α} {a : Set α} (h : x ∈ a) : f x ∈ f '' a :=
⟨_, h, rfl⟩
#align set.mem_image_of_mem Set.mem_image_of_mem
theorem _root_.Function.Injective.mem_set_image {f : α → β} (hf : Injective f) {s : Set α} {a : α} :
f a ∈ f '' s ↔ a ∈ s :=
⟨fun ⟨_, hb, Eq⟩ => hf Eq ▸ hb, mem_image_of_mem f⟩
#align function.injective.mem_set_image Function.Injective.mem_set_image
theorem ball_image_iff {f : α → β} {s : Set α} {p : β → Prop} :
(∀ y ∈ f '' s, p y) ↔ ∀ x ∈ s, p (f x) := by simp
#align set.ball_image_iff Set.ball_image_iff
theorem ball_image_of_ball {f : α → β} {s : Set α} {p : β → Prop} (h : ∀ x ∈ s, p (f x)) :
∀ y ∈ f '' s, p y :=
ball_image_iff.2 h
#align set.ball_image_of_ball Set.ball_image_of_ball
theorem bex_image_iff {f : α → β} {s : Set α} {p : β → Prop} :
(∃ y ∈ f '' s, p y) ↔ ∃ x ∈ s, p (f x) := by simp
#align set.bex_image_iff Set.bex_image_iff
theorem mem_image_elim {f : α → β} {s : Set α} {C : β → Prop} (h : ∀ x : α, x ∈ s → C (f x)) :
∀ {y : β}, y ∈ f '' s → C y
| _, ⟨a, a_in, rfl⟩ => h a a_in
#align set.mem_image_elim Set.mem_image_elim
theorem mem_image_elim_on {f : α → β} {s : Set α} {C : β → Prop} {y : β} (h_y : y ∈ f '' s)
(h : ∀ x : α, x ∈ s → C (f x)) : C y :=
mem_image_elim h h_y
#align set.mem_image_elim_on Set.mem_image_elim_on
-- Porting note: used to be `safe`
@[congr]
theorem image_congr {f g : α → β} {s : Set α} (h : ∀ a ∈ s, f a = g a) : f '' s = g '' s := by
ext x
rw [mem_image, mem_image]
exact {
mp := by
rintro ⟨a, ha1, ha2⟩
exact ⟨a, ⟨ha1, (h a ha1) ▸ ha2⟩⟩,
mpr := by
rintro ⟨a, ha1, ha2⟩
exact ⟨a, ⟨ha1, (h a ha1) ▸ ha2⟩⟩
}
-- safe [ext_iff, iff_def]
#align set.image_congr Set.image_congr
/-- A common special case of `image_congr` -/
theorem image_congr' {f g : α → β} {s : Set α} (h : ∀ x : α, f x = g x) : f '' s = g '' s :=
image_congr fun x _ => h x
#align set.image_congr' Set.image_congr'
@[gcongr]
lemma image_mono (h : s ⊆ t) : f '' s ⊆ f '' t := by
rintro - ⟨a, ha, rfl⟩; exact mem_image_of_mem f (h ha)
theorem image_comp (f : β → γ) (g : α → β) (a : Set α) : f ∘ g '' a = f '' (g '' a) :=
Subset.antisymm (ball_image_of_ball fun _ ha => mem_image_of_mem _ <| mem_image_of_mem _ ha)
(ball_image_of_ball <| ball_image_of_ball fun _ ha => mem_image_of_mem _ ha)
#align set.image_comp Set.image_comp
theorem image_comp_eq {g : β → γ} : image (g ∘ f) = image g ∘ image f := by ext; simp
/-- A variant of `image_comp`, useful for rewriting -/
theorem image_image (g : β → γ) (f : α → β) (s : Set α) : g '' (f '' s) = (fun x => g (f x)) '' s :=
(image_comp g f s).symm
#align set.image_image Set.image_image
theorem image_comm {β'} {f : β → γ} {g : α → β} {f' : α → β'} {g' : β' → γ}
(h_comm : ∀ a, f (g a) = g' (f' a)) : (s.image g).image f = (s.image f').image g' := by
simp_rw [image_image, h_comm]
#align set.image_comm Set.image_comm
theorem _root_.Function.Semiconj.set_image {f : α → β} {ga : α → α} {gb : β → β}
(h : Function.Semiconj f ga gb) : Function.Semiconj (image f) (image ga) (image gb) := fun _ =>
image_comm h
#align function.semiconj.set_image Function.Semiconj.set_image
theorem _root_.Function.Commute.set_image {f g : α → α} (h : Function.Commute f g) :
Function.Commute (image f) (image g) :=
Function.Semiconj.set_image h
#align function.commute.set_image Function.Commute.set_image
/-- Image is monotone with respect to `⊆`. See `Set.monotone_image` for the statement in
terms of `≤`. -/
@[gcongr]
theorem image_subset {a b : Set α} (f : α → β) (h : a ⊆ b) : f '' a ⊆ f '' b := by
simp only [subset_def, mem_image]
exact fun x => fun ⟨w, h1, h2⟩ => ⟨w, h h1, h2⟩
#align set.image_subset Set.image_subset
/-- `Set.image` is monotone. See `Set.image_subset` for the statement in terms of `⊆`. -/
lemma monotone_image {f : α → β} : Monotone (image f) := fun _ _ => image_subset _
#align set.monotone_image Set.monotone_image
theorem image_union (f : α → β) (s t : Set α) : f '' (s ∪ t) = f '' s ∪ f '' t :=
ext fun x =>
⟨by rintro ⟨a, h | h, rfl⟩ <;> [left; right] <;> exact ⟨_, h, rfl⟩, by
rintro (⟨a, h, rfl⟩ | ⟨a, h, rfl⟩) <;> refine' ⟨_, _, rfl⟩ <;> [left; right] <;> exact h⟩
#align set.image_union Set.image_union
@[simp]
theorem image_empty (f : α → β) : f '' ∅ = ∅ := by
ext
simp
#align set.image_empty Set.image_empty
theorem image_inter_subset (f : α → β) (s t : Set α) : f '' (s ∩ t) ⊆ f '' s ∩ f '' t :=
subset_inter (image_subset _ <| inter_subset_left _ _) (image_subset _ <| inter_subset_right _ _)
#align set.image_inter_subset Set.image_inter_subset
theorem image_inter_on {f : α → β} {s t : Set α} (h : ∀ x ∈ t, ∀ y ∈ s, f x = f y → x = y) :
f '' (s ∩ t) = f '' s ∩ f '' t :=
(image_inter_subset _ _ _).antisymm
fun b ⟨⟨a₁, ha₁, h₁⟩, ⟨a₂, ha₂, h₂⟩⟩ ↦
have : a₂ = a₁ := h _ ha₂ _ ha₁ (by simp [*])
⟨a₁, ⟨ha₁, this ▸ ha₂⟩, h₁⟩
#align set.image_inter_on Set.image_inter_on
theorem image_inter {f : α → β} {s t : Set α} (H : Injective f) : f '' (s ∩ t) = f '' s ∩ f '' t :=
image_inter_on fun _ _ _ _ h => H h
#align set.image_inter Set.image_inter
theorem image_univ_of_surjective {ι : Type*} {f : ι → β} (H : Surjective f) : f '' univ = univ :=
eq_univ_of_forall <| by simpa [image]
#align set.image_univ_of_surjective Set.image_univ_of_surjective
@[simp]
theorem image_singleton {f : α → β} {a : α} : f '' {a} = {f a} := by
ext
simp [image, eq_comm]
#align set.image_singleton Set.image_singleton
@[simp]
theorem Nonempty.image_const {s : Set α} (hs : s.Nonempty) (a : β) : (fun _ => a) '' s = {a} :=
ext fun _ =>
⟨fun ⟨_, _, h⟩ => h ▸ mem_singleton _, fun h =>
(eq_of_mem_singleton h).symm ▸ hs.imp fun _ hy => ⟨hy, rfl⟩⟩
#align set.nonempty.image_const Set.Nonempty.image_const
@[simp, mfld_simps]
theorem image_eq_empty {α β} {f : α → β} {s : Set α} : f '' s = ∅ ↔ s = ∅ := by
simp only [eq_empty_iff_forall_not_mem]
exact ⟨fun H a ha => H _ ⟨_, ha, rfl⟩, fun H b ⟨_, ha, _⟩ => H _ ha⟩
#align set.image_eq_empty Set.image_eq_empty
-- Porting note: `compl` is already defined in `Init.Set`
theorem preimage_compl_eq_image_compl [BooleanAlgebra α] (S : Set α) :
HasCompl.compl ⁻¹' S = HasCompl.compl '' S :=
Set.ext fun x =>
⟨fun h => ⟨xᶜ, h, compl_compl x⟩, fun h =>
Exists.elim h fun _ hy => (compl_eq_comm.mp hy.2).symm.subst hy.1⟩
#align set.preimage_compl_eq_image_compl Set.preimage_compl_eq_image_compl
theorem mem_compl_image [BooleanAlgebra α] (t : α) (S : Set α) :
t ∈ HasCompl.compl '' S ↔ tᶜ ∈ S := by
simp [← preimage_compl_eq_image_compl]
#align set.mem_compl_image Set.mem_compl_image
@[simp]
theorem image_id_eq : image (id : α → α) = id := by ext; simp
/-- A variant of `image_id` -/
@[simp]
theorem image_id' (s : Set α) : (fun x => x) '' s = s := by
ext
simp
#align set.image_id' Set.image_id'
theorem image_id (s : Set α) : id '' s = s := by simp
#align set.image_id Set.image_id
lemma image_iterate_eq {f : α → α} {n : ℕ} : image (f^[n]) = (image f)^[n] := by
induction' n with n ih; · simp
rw [iterate_succ', iterate_succ',← ih, image_comp_eq]
theorem compl_compl_image [BooleanAlgebra α] (S : Set α) :
HasCompl.compl '' (HasCompl.compl '' S) = S := by
rw [← image_comp, compl_comp_compl, image_id]
#align set.compl_compl_image Set.compl_compl_image
theorem image_insert_eq {f : α → β} {a : α} {s : Set α} :
f '' insert a s = insert (f a) (f '' s) := by
ext
simp [and_or_left, exists_or, eq_comm, or_comm, and_comm]
#align set.image_insert_eq Set.image_insert_eq
theorem image_pair (f : α → β) (a b : α) : f '' {a, b} = {f a, f b} := by
simp only [image_insert_eq, image_singleton]
#align set.image_pair Set.image_pair
theorem image_subset_preimage_of_inverse {f : α → β} {g : β → α} (I : LeftInverse g f) (s : Set α) :
f '' s ⊆ g ⁻¹' s := fun _ ⟨a, h, e⟩ => e ▸ ((I a).symm ▸ h : g (f a) ∈ s)
#align set.image_subset_preimage_of_inverse Set.image_subset_preimage_of_inverse
theorem preimage_subset_image_of_inverse {f : α → β} {g : β → α} (I : LeftInverse g f) (s : Set β) :
f ⁻¹' s ⊆ g '' s := fun b h => ⟨f b, h, I b⟩
#align set.preimage_subset_image_of_inverse Set.preimage_subset_image_of_inverse
theorem image_eq_preimage_of_inverse {f : α → β} {g : β → α} (h₁ : LeftInverse g f)
(h₂ : RightInverse g f) : image f = preimage g :=
funext fun s =>
Subset.antisymm (image_subset_preimage_of_inverse h₁ s) (preimage_subset_image_of_inverse h₂ s)
#align set.image_eq_preimage_of_inverse Set.image_eq_preimage_of_inverse
theorem mem_image_iff_of_inverse {f : α → β} {g : β → α} {b : β} {s : Set α} (h₁ : LeftInverse g f)
(h₂ : RightInverse g f) : b ∈ f '' s ↔ g b ∈ s := by
rw [image_eq_preimage_of_inverse h₁ h₂]; rfl
#align set.mem_image_iff_of_inverse Set.mem_image_iff_of_inverse
theorem image_compl_subset {f : α → β} {s : Set α} (H : Injective f) : f '' sᶜ ⊆ (f '' s)ᶜ :=
Disjoint.subset_compl_left <| by simp [disjoint_iff_inf_le, ← image_inter H]
#align set.image_compl_subset Set.image_compl_subset
theorem subset_image_compl {f : α → β} {s : Set α} (H : Surjective f) : (f '' s)ᶜ ⊆ f '' sᶜ :=
compl_subset_iff_union.2 <| by
rw [← image_union]
simp [image_univ_of_surjective H]
#align set.subset_image_compl Set.subset_image_compl
theorem image_compl_eq {f : α → β} {s : Set α} (H : Bijective f) : f '' sᶜ = (f '' s)ᶜ :=
Subset.antisymm (image_compl_subset H.1) (subset_image_compl H.2)
#align set.image_compl_eq Set.image_compl_eq
theorem subset_image_diff (f : α → β) (s t : Set α) : f '' s \ f '' t ⊆ f '' (s \ t) := by
rw [diff_subset_iff, ← image_union, union_diff_self]
exact image_subset f (subset_union_right t s)
#align set.subset_image_diff Set.subset_image_diff
theorem subset_image_symmDiff : (f '' s) ∆ (f '' t) ⊆ f '' s ∆ t :=
(union_subset_union (subset_image_diff _ _ _) <| subset_image_diff _ _ _).trans
(superset_of_eq (image_union _ _ _))
#align set.subset_image_symm_diff Set.subset_image_symmDiff
theorem image_diff {f : α → β} (hf : Injective f) (s t : Set α) : f '' (s \ t) = f '' s \ f '' t :=
Subset.antisymm
(Subset.trans (image_inter_subset _ _ _) <| inter_subset_inter_right _ <| image_compl_subset hf)
(subset_image_diff f s t)
#align set.image_diff Set.image_diff
theorem image_symmDiff (hf : Injective f) (s t : Set α) : f '' s ∆ t = (f '' s) ∆ (f '' t) := by
simp_rw [Set.symmDiff_def, image_union, image_diff hf]
#align set.image_symm_diff Set.image_symmDiff
theorem Nonempty.image (f : α → β) {s : Set α} : s.Nonempty → (f '' s).Nonempty
| ⟨x, hx⟩ => ⟨f x, mem_image_of_mem f hx⟩
#align set.nonempty.image Set.Nonempty.image
theorem Nonempty.of_image {f : α → β} {s : Set α} : (f '' s).Nonempty → s.Nonempty
| ⟨_, x, hx, _⟩ => ⟨x, hx⟩
#align set.nonempty.of_image Set.Nonempty.of_image
@[simp]
theorem nonempty_image_iff {f : α → β} {s : Set α} : (f '' s).Nonempty ↔ s.Nonempty :=
⟨Nonempty.of_image, fun h => h.image f⟩
#align set.nonempty_image_iff Set.nonempty_image_iff
theorem Nonempty.preimage {s : Set β} (hs : s.Nonempty) {f : α → β} (hf : Surjective f) :
(f ⁻¹' s).Nonempty :=
let ⟨y, hy⟩ := hs
let ⟨x, hx⟩ := hf y
⟨x, mem_preimage.2 <| hx.symm ▸ hy⟩
#align set.nonempty.preimage Set.Nonempty.preimage
instance (f : α → β) (s : Set α) [Nonempty s] : Nonempty (f '' s) :=
(Set.Nonempty.image f nonempty_of_nonempty_subtype).to_subtype
/-- image and preimage are a Galois connection -/
@[simp]
theorem image_subset_iff {s : Set α} {t : Set β} {f : α → β} : f '' s ⊆ t ↔ s ⊆ f ⁻¹' t :=
ball_image_iff
#align set.image_subset_iff Set.image_subset_iff
theorem image_preimage_subset (f : α → β) (s : Set β) : f '' (f ⁻¹' s) ⊆ s :=
image_subset_iff.2 Subset.rfl
#align set.image_preimage_subset Set.image_preimage_subset
theorem subset_preimage_image (f : α → β) (s : Set α) : s ⊆ f ⁻¹' (f '' s) := fun _ =>
mem_image_of_mem f
#align set.subset_preimage_image Set.subset_preimage_image
@[simp]
theorem preimage_image_eq {f : α → β} (s : Set α) (h : Injective f) : f ⁻¹' (f '' s) = s :=
Subset.antisymm (fun _ ⟨_, hy, e⟩ => h e ▸ hy) (subset_preimage_image f s)
#align set.preimage_image_eq Set.preimage_image_eq
@[simp]
theorem image_preimage_eq {f : α → β} (s : Set β) (h : Surjective f) : f '' (f ⁻¹' s) = s :=
Subset.antisymm (image_preimage_subset f s) fun x hx =>
let ⟨y, e⟩ := h x
⟨y, (e.symm ▸ hx : f y ∈ s), e⟩
#align set.image_preimage_eq Set.image_preimage_eq
@[simp]
theorem preimage_eq_preimage {f : β → α} (hf : Surjective f) : f ⁻¹' s = f ⁻¹' t ↔ s = t :=
Iff.intro
fun eq => by rw [← image_preimage_eq s hf, ← image_preimage_eq t hf, eq]
fun eq => eq ▸ rfl
#align set.preimage_eq_preimage Set.preimage_eq_preimage
theorem image_inter_preimage (f : α → β) (s : Set α) (t : Set β) :
f '' (s ∩ f ⁻¹' t) = f '' s ∩ t := by
apply Subset.antisymm
· calc
f '' (s ∩ f ⁻¹' t) ⊆ f '' s ∩ f '' (f ⁻¹' t) := image_inter_subset _ _ _
_ ⊆ f '' s ∩ t := inter_subset_inter_right _ (image_preimage_subset f t)
· rintro _ ⟨⟨x, h', rfl⟩, h⟩
exact ⟨x, ⟨h', h⟩, rfl⟩
#align set.image_inter_preimage Set.image_inter_preimage
theorem image_preimage_inter (f : α → β) (s : Set α) (t : Set β) :
f '' (f ⁻¹' t ∩ s) = t ∩ f '' s := by simp only [inter_comm, image_inter_preimage]
#align set.image_preimage_inter Set.image_preimage_inter
@[simp]
theorem image_inter_nonempty_iff {f : α → β} {s : Set α} {t : Set β} :
(f '' s ∩ t).Nonempty ↔ (s ∩ f ⁻¹' t).Nonempty := by
rw [← image_inter_preimage, nonempty_image_iff]
#align set.image_inter_nonempty_iff Set.image_inter_nonempty_iff
theorem image_diff_preimage {f : α → β} {s : Set α} {t : Set β} : f '' (s \ f ⁻¹' t) = f '' s \ t :=
by simp_rw [diff_eq, ← preimage_compl, image_inter_preimage]
#align set.image_diff_preimage Set.image_diff_preimage
theorem compl_image : image (compl : Set α → Set α) = preimage compl :=
image_eq_preimage_of_inverse compl_compl compl_compl
#align set.compl_image Set.compl_image
theorem compl_image_set_of {p : Set α → Prop} : compl '' { s | p s } = { s | p sᶜ } :=
congr_fun compl_image p
#align set.compl_image_set_of Set.compl_image_set_of
theorem inter_preimage_subset (s : Set α) (t : Set β) (f : α → β) :
s ∩ f ⁻¹' t ⊆ f ⁻¹' (f '' s ∩ t) := fun _ h => ⟨mem_image_of_mem _ h.left, h.right⟩
#align set.inter_preimage_subset Set.inter_preimage_subset
theorem union_preimage_subset (s : Set α) (t : Set β) (f : α → β) :
s ∪ f ⁻¹' t ⊆ f ⁻¹' (f '' s ∪ t) := fun _ h =>
Or.elim h (fun l => Or.inl <| mem_image_of_mem _ l) fun r => Or.inr r
#align set.union_preimage_subset Set.union_preimage_subset
theorem subset_image_union (f : α → β) (s : Set α) (t : Set β) : f '' (s ∪ f ⁻¹' t) ⊆ f '' s ∪ t :=
image_subset_iff.2 (union_preimage_subset _ _ _)
#align set.subset_image_union Set.subset_image_union
theorem preimage_subset_iff {A : Set α} {B : Set β} {f : α → β} :
f ⁻¹' B ⊆ A ↔ ∀ a : α, f a ∈ B → a ∈ A :=
Iff.rfl
#align set.preimage_subset_iff Set.preimage_subset_iff
theorem image_eq_image {f : α → β} (hf : Injective f) : f '' s = f '' t ↔ s = t :=
Iff.symm <|
(Iff.intro fun eq => eq ▸ rfl) fun eq => by
rw [← preimage_image_eq s hf, ← preimage_image_eq t hf, eq]
#align set.image_eq_image Set.image_eq_image
theorem image_subset_image_iff {f : α → β} (hf : Injective f) : f '' s ⊆ f '' t ↔ s ⊆ t := by
refine' Iff.symm <| (Iff.intro (image_subset f)) fun h => _
rw [← preimage_image_eq s hf, ← preimage_image_eq t hf]
exact preimage_mono h
#align set.image_subset_image_iff Set.image_subset_image_iff
theorem prod_quotient_preimage_eq_image [s : Setoid α] (g : Quotient s → β) {h : α → β}
(Hh : h = g ∘ Quotient.mk'') (r : Set (β × β)) :
{ x : Quotient s × Quotient s | (g x.1, g x.2) ∈ r } =
(fun a : α × α => (⟦a.1⟧, ⟦a.2⟧)) '' ((fun a : α × α => (h a.1, h a.2)) ⁻¹' r) :=
Hh.symm ▸
Set.ext fun ⟨a₁, a₂⟩ =>
⟨Quot.induction_on₂ a₁ a₂ fun a₁ a₂ h => ⟨(a₁, a₂), h, rfl⟩, fun ⟨⟨b₁, b₂⟩, h₁, h₂⟩ =>
show (g a₁, g a₂) ∈ r from
have h₃ : ⟦b₁⟧ = a₁ ∧ ⟦b₂⟧ = a₂ := Prod.ext_iff.1 h₂
h₃.1 ▸ h₃.2 ▸ h₁⟩
#align set.prod_quotient_preimage_eq_image Set.prod_quotient_preimage_eq_image
theorem exists_image_iff (f : α → β) (x : Set α) (P : β → Prop) :
(∃ a : f '' x, P a) ↔ ∃ a : x, P (f a) :=
⟨fun ⟨a, h⟩ => ⟨⟨_, a.prop.choose_spec.1⟩, a.prop.choose_spec.2.symm ▸ h⟩, fun ⟨a, h⟩ =>
⟨⟨_, _, a.prop, rfl⟩, h⟩⟩
#align set.exists_image_iff Set.exists_image_iff
/-- Restriction of `f` to `s` factors through `s.imageFactorization f : s → f '' s`. -/
def imageFactorization (f : α → β) (s : Set α) : s → f '' s := fun p =>
⟨f p.1, mem_image_of_mem f p.2⟩
#align set.image_factorization Set.imageFactorization
theorem imageFactorization_eq {f : α → β} {s : Set α} :
Subtype.val ∘ imageFactorization f s = f ∘ Subtype.val :=
funext fun _ => rfl
#align set.image_factorization_eq Set.imageFactorization_eq
theorem surjective_onto_image {f : α → β} {s : Set α} : Surjective (imageFactorization f s) :=
fun ⟨_, ⟨a, ha, rfl⟩⟩ => ⟨⟨a, ha⟩, rfl⟩
#align set.surjective_onto_image Set.surjective_onto_image
/-- If the only elements outside `s` are those left fixed by `σ`, then mapping by `σ` has no effect.
-/
theorem image_perm {s : Set α} {σ : Equiv.Perm α} (hs : { a : α | σ a ≠ a } ⊆ s) : σ '' s = s := by
ext i
obtain hi | hi := eq_or_ne (σ i) i
· refine' ⟨_, fun h => ⟨i, h, hi⟩⟩
rintro ⟨j, hj, h⟩
rwa [σ.injective (hi.trans h.symm)]
· refine' iff_of_true ⟨σ.symm i, hs fun h => hi _, σ.apply_symm_apply _⟩ (hs hi)
convert congr_arg σ h <;> exact (σ.apply_symm_apply _).symm
#align set.image_perm Set.image_perm
end Image
/-! ### Lemmas about the powerset and image. -/
/-- The powerset of `{a} ∪ s` is `𝒫 s` together with `{a} ∪ t` for each `t ∈ 𝒫 s`. -/
theorem powerset_insert (s : Set α) (a : α) : 𝒫 insert a s = 𝒫 s ∪ insert a '' 𝒫 s := by
ext t
simp_rw [mem_union, mem_image, mem_powerset_iff]
constructor
·
|
intro h
|
/-- The powerset of `{a} ∪ s` is `𝒫 s` together with `{a} ∪ t` for each `t ∈ 𝒫 s`. -/
theorem powerset_insert (s : Set α) (a : α) : 𝒫 insert a s = 𝒫 s ∪ insert a '' 𝒫 s := by
ext t
simp_rw [mem_union, mem_image, mem_powerset_iff]
constructor
·
|
Mathlib.Data.Set.Image.651_0.IJFiTzmYGOCpPSd
|
/-- The powerset of `{a} ∪ s` is `𝒫 s` together with `{a} ∪ t` for each `t ∈ 𝒫 s`. -/
theorem powerset_insert (s : Set α) (a : α) : 𝒫 insert a s = 𝒫 s ∪ insert a '' 𝒫 s
|
Mathlib_Data_Set_Image
|
case h.mp
α : Type u_1
β : Type u_2
γ : Type u_3
ι : Sort u_4
ι' : Sort u_5
s : Set α
a : α
t : Set α
h : t ⊆ insert a s
⊢ t ⊆ s ∨ ∃ x ⊆ s, insert a x = t
|
/-
Copyright (c) 2014 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Leonardo de Moura
-/
import Mathlib.Data.Set.Basic
#align_import data.set.image from "leanprover-community/mathlib"@"001ffdc42920050657fd45bd2b8bfbec8eaaeb29"
/-!
# Images and preimages of sets
## Main definitions
* `preimage f t : Set α` : the preimage f⁻¹(t) (written `f ⁻¹' t` in Lean) of a subset of β.
* `range f : Set β` : the image of `univ` under `f`.
Also works for `{p : Prop} (f : p → α)` (unlike `image`)
## Notation
* `f ⁻¹' t` for `Set.preimage f t`
* `f '' s` for `Set.image f s`
## Tags
set, sets, image, preimage, pre-image, range
-/
set_option autoImplicit true
universe u v
open Function Set
namespace Set
variable {α β γ : Type*} {ι ι' : Sort*}
/-! ### Inverse image -/
/-- The preimage of `s : Set β` by `f : α → β`, written `f ⁻¹' s`,
is the set of `x : α` such that `f x ∈ s`. -/
def preimage {α : Type u} {β : Type v} (f : α → β) (s : Set β) : Set α :=
{ x | f x ∈ s }
#align set.preimage Set.preimage
/-- `f ⁻¹' t` denotes the preimage of `t : Set β` under the function `f : α → β`. -/
infixl:80 " ⁻¹' " => preimage
section Preimage
variable {f : α → β} {g : β → γ}
@[simp]
theorem preimage_empty : f ⁻¹' ∅ = ∅ :=
rfl
#align set.preimage_empty Set.preimage_empty
@[simp, mfld_simps]
theorem mem_preimage {s : Set β} {a : α} : a ∈ f ⁻¹' s ↔ f a ∈ s :=
Iff.rfl
#align set.mem_preimage Set.mem_preimage
theorem preimage_congr {f g : α → β} {s : Set β} (h : ∀ x : α, f x = g x) : f ⁻¹' s = g ⁻¹' s := by
congr with x
simp [h]
#align set.preimage_congr Set.preimage_congr
@[gcongr]
theorem preimage_mono {s t : Set β} (h : s ⊆ t) : f ⁻¹' s ⊆ f ⁻¹' t := fun _ hx => h hx
#align set.preimage_mono Set.preimage_mono
@[simp, mfld_simps]
theorem preimage_univ : f ⁻¹' univ = univ :=
rfl
#align set.preimage_univ Set.preimage_univ
theorem subset_preimage_univ {s : Set α} : s ⊆ f ⁻¹' univ :=
subset_univ _
#align set.subset_preimage_univ Set.subset_preimage_univ
@[simp, mfld_simps]
theorem preimage_inter {s t : Set β} : f ⁻¹' (s ∩ t) = f ⁻¹' s ∩ f ⁻¹' t :=
rfl
#align set.preimage_inter Set.preimage_inter
@[simp]
theorem preimage_union {s t : Set β} : f ⁻¹' (s ∪ t) = f ⁻¹' s ∪ f ⁻¹' t :=
rfl
#align set.preimage_union Set.preimage_union
@[simp]
theorem preimage_compl {s : Set β} : f ⁻¹' sᶜ = (f ⁻¹' s)ᶜ :=
rfl
#align set.preimage_compl Set.preimage_compl
@[simp]
theorem preimage_diff (f : α → β) (s t : Set β) : f ⁻¹' (s \ t) = f ⁻¹' s \ f ⁻¹' t :=
rfl
#align set.preimage_diff Set.preimage_diff
@[simp]
lemma preimage_symmDiff {f : α → β} (s t : Set β) : f ⁻¹' (s ∆ t) = (f ⁻¹' s) ∆ (f ⁻¹' t) :=
rfl
#align set.preimage_symm_diff Set.preimage_symmDiff
@[simp]
theorem preimage_ite (f : α → β) (s t₁ t₂ : Set β) :
f ⁻¹' s.ite t₁ t₂ = (f ⁻¹' s).ite (f ⁻¹' t₁) (f ⁻¹' t₂) :=
rfl
#align set.preimage_ite Set.preimage_ite
@[simp]
theorem preimage_setOf_eq {p : α → Prop} {f : β → α} : f ⁻¹' { a | p a } = { a | p (f a) } :=
rfl
#align set.preimage_set_of_eq Set.preimage_setOf_eq
@[simp]
theorem preimage_id_eq : preimage (id : α → α) = id :=
rfl
#align set.preimage_id_eq Set.preimage_id_eq
@[mfld_simps]
theorem preimage_id {s : Set α} : id ⁻¹' s = s :=
rfl
#align set.preimage_id Set.preimage_id
@[simp, mfld_simps]
theorem preimage_id' {s : Set α} : (fun x => x) ⁻¹' s = s :=
rfl
#align set.preimage_id' Set.preimage_id'
@[simp]
theorem preimage_const_of_mem {b : β} {s : Set β} (h : b ∈ s) : (fun _ : α => b) ⁻¹' s = univ :=
eq_univ_of_forall fun _ => h
#align set.preimage_const_of_mem Set.preimage_const_of_mem
@[simp]
theorem preimage_const_of_not_mem {b : β} {s : Set β} (h : b ∉ s) : (fun _ : α => b) ⁻¹' s = ∅ :=
eq_empty_of_subset_empty fun _ hx => h hx
#align set.preimage_const_of_not_mem Set.preimage_const_of_not_mem
theorem preimage_const (b : β) (s : Set β) [Decidable (b ∈ s)] :
(fun _ : α => b) ⁻¹' s = if b ∈ s then univ else ∅ := by
split_ifs with hb
exacts [preimage_const_of_mem hb, preimage_const_of_not_mem hb]
#align set.preimage_const Set.preimage_const
/-- If preimage of each singleton under `f : α → β` is either empty or the whole type,
then `f` is a constant. -/
lemma exists_eq_const_of_preimage_singleton [Nonempty β] {f : α → β}
(hf : ∀ b : β, f ⁻¹' {b} = ∅ ∨ f ⁻¹' {b} = univ) : ∃ b, f = const α b := by
rcases em (∃ b, f ⁻¹' {b} = univ) with ⟨b, hb⟩ | hf'
· exact ⟨b, funext fun x ↦ eq_univ_iff_forall.1 hb x⟩
· have : ∀ x b, f x ≠ b := fun x b ↦
eq_empty_iff_forall_not_mem.1 ((hf b).resolve_right fun h ↦ hf' ⟨b, h⟩) x
exact ⟨Classical.arbitrary β, funext fun x ↦ absurd rfl (this x _)⟩
theorem preimage_comp {s : Set γ} : g ∘ f ⁻¹' s = f ⁻¹' (g ⁻¹' s) :=
rfl
#align set.preimage_comp Set.preimage_comp
theorem preimage_comp_eq : preimage (g ∘ f) = preimage f ∘ preimage g :=
rfl
#align set.preimage_comp_eq Set.preimage_comp_eq
theorem preimage_iterate_eq {f : α → α} {n : ℕ} : Set.preimage f^[n] = (Set.preimage f)^[n] := by
induction' n with n ih; · simp
rw [iterate_succ, iterate_succ', preimage_comp_eq, ih]
#align set.preimage_iterate_eq Set.preimage_iterate_eq
theorem preimage_preimage {g : β → γ} {f : α → β} {s : Set γ} :
f ⁻¹' (g ⁻¹' s) = (fun x => g (f x)) ⁻¹' s :=
preimage_comp.symm
#align set.preimage_preimage Set.preimage_preimage
theorem eq_preimage_subtype_val_iff {p : α → Prop} {s : Set (Subtype p)} {t : Set α} :
s = Subtype.val ⁻¹' t ↔ ∀ (x) (h : p x), (⟨x, h⟩ : Subtype p) ∈ s ↔ x ∈ t :=
⟨fun s_eq x h => by
rw [s_eq]
simp, fun h => ext fun ⟨x, hx⟩ => by simp [h]⟩
#align set.eq_preimage_subtype_val_iff Set.eq_preimage_subtype_val_iff
theorem nonempty_of_nonempty_preimage {s : Set β} {f : α → β} (hf : (f ⁻¹' s).Nonempty) :
s.Nonempty :=
let ⟨x, hx⟩ := hf
⟨f x, hx⟩
#align set.nonempty_of_nonempty_preimage Set.nonempty_of_nonempty_preimage
@[simp] theorem preimage_singleton_true (p : α → Prop) : p ⁻¹' {True} = {a | p a} := by ext; simp
#align set.preimage_singleton_true Set.preimage_singleton_true
@[simp] theorem preimage_singleton_false (p : α → Prop) : p ⁻¹' {False} = {a | ¬p a} := by ext; simp
#align set.preimage_singleton_false Set.preimage_singleton_false
theorem preimage_subtype_coe_eq_compl {s u v : Set α} (hsuv : s ⊆ u ∪ v)
(H : s ∩ (u ∩ v) = ∅) : ((↑) : s → α) ⁻¹' u = ((↑) ⁻¹' v)ᶜ := by
ext ⟨x, x_in_s⟩
constructor
· intro x_in_u x_in_v
exact eq_empty_iff_forall_not_mem.mp H x ⟨x_in_s, ⟨x_in_u, x_in_v⟩⟩
· intro hx
exact Or.elim (hsuv x_in_s) id fun hx' => hx.elim hx'
#align set.preimage_subtype_coe_eq_compl Set.preimage_subtype_coe_eq_compl
end Preimage
/-! ### Image of a set under a function -/
section Image
variable {f : α → β} {s t : Set α}
-- Porting note: `Set.image` is already defined in `Init.Set`
#align set.image Set.image
/-- `f '' s` denotes the image of `s : Set α` under the function `f : α → β`. -/
infixl:80 " '' " => image
theorem mem_image_iff_bex {f : α → β} {s : Set α} {y : β} :
y ∈ f '' s ↔ ∃ (x : _) (_ : x ∈ s), f x = y :=
bex_def.symm
#align set.mem_image_iff_bex Set.mem_image_iff_bex
@[simp]
theorem mem_image (f : α → β) (s : Set α) (y : β) : y ∈ f '' s ↔ ∃ x ∈ s, f x = y :=
Iff.rfl
#align set.mem_image Set.mem_image
theorem image_eta (f : α → β) : f '' s = (fun x => f x) '' s :=
rfl
#align set.image_eta Set.image_eta
@[mfld_simps]
theorem mem_image_of_mem (f : α → β) {x : α} {a : Set α} (h : x ∈ a) : f x ∈ f '' a :=
⟨_, h, rfl⟩
#align set.mem_image_of_mem Set.mem_image_of_mem
theorem _root_.Function.Injective.mem_set_image {f : α → β} (hf : Injective f) {s : Set α} {a : α} :
f a ∈ f '' s ↔ a ∈ s :=
⟨fun ⟨_, hb, Eq⟩ => hf Eq ▸ hb, mem_image_of_mem f⟩
#align function.injective.mem_set_image Function.Injective.mem_set_image
theorem ball_image_iff {f : α → β} {s : Set α} {p : β → Prop} :
(∀ y ∈ f '' s, p y) ↔ ∀ x ∈ s, p (f x) := by simp
#align set.ball_image_iff Set.ball_image_iff
theorem ball_image_of_ball {f : α → β} {s : Set α} {p : β → Prop} (h : ∀ x ∈ s, p (f x)) :
∀ y ∈ f '' s, p y :=
ball_image_iff.2 h
#align set.ball_image_of_ball Set.ball_image_of_ball
theorem bex_image_iff {f : α → β} {s : Set α} {p : β → Prop} :
(∃ y ∈ f '' s, p y) ↔ ∃ x ∈ s, p (f x) := by simp
#align set.bex_image_iff Set.bex_image_iff
theorem mem_image_elim {f : α → β} {s : Set α} {C : β → Prop} (h : ∀ x : α, x ∈ s → C (f x)) :
∀ {y : β}, y ∈ f '' s → C y
| _, ⟨a, a_in, rfl⟩ => h a a_in
#align set.mem_image_elim Set.mem_image_elim
theorem mem_image_elim_on {f : α → β} {s : Set α} {C : β → Prop} {y : β} (h_y : y ∈ f '' s)
(h : ∀ x : α, x ∈ s → C (f x)) : C y :=
mem_image_elim h h_y
#align set.mem_image_elim_on Set.mem_image_elim_on
-- Porting note: used to be `safe`
@[congr]
theorem image_congr {f g : α → β} {s : Set α} (h : ∀ a ∈ s, f a = g a) : f '' s = g '' s := by
ext x
rw [mem_image, mem_image]
exact {
mp := by
rintro ⟨a, ha1, ha2⟩
exact ⟨a, ⟨ha1, (h a ha1) ▸ ha2⟩⟩,
mpr := by
rintro ⟨a, ha1, ha2⟩
exact ⟨a, ⟨ha1, (h a ha1) ▸ ha2⟩⟩
}
-- safe [ext_iff, iff_def]
#align set.image_congr Set.image_congr
/-- A common special case of `image_congr` -/
theorem image_congr' {f g : α → β} {s : Set α} (h : ∀ x : α, f x = g x) : f '' s = g '' s :=
image_congr fun x _ => h x
#align set.image_congr' Set.image_congr'
@[gcongr]
lemma image_mono (h : s ⊆ t) : f '' s ⊆ f '' t := by
rintro - ⟨a, ha, rfl⟩; exact mem_image_of_mem f (h ha)
theorem image_comp (f : β → γ) (g : α → β) (a : Set α) : f ∘ g '' a = f '' (g '' a) :=
Subset.antisymm (ball_image_of_ball fun _ ha => mem_image_of_mem _ <| mem_image_of_mem _ ha)
(ball_image_of_ball <| ball_image_of_ball fun _ ha => mem_image_of_mem _ ha)
#align set.image_comp Set.image_comp
theorem image_comp_eq {g : β → γ} : image (g ∘ f) = image g ∘ image f := by ext; simp
/-- A variant of `image_comp`, useful for rewriting -/
theorem image_image (g : β → γ) (f : α → β) (s : Set α) : g '' (f '' s) = (fun x => g (f x)) '' s :=
(image_comp g f s).symm
#align set.image_image Set.image_image
theorem image_comm {β'} {f : β → γ} {g : α → β} {f' : α → β'} {g' : β' → γ}
(h_comm : ∀ a, f (g a) = g' (f' a)) : (s.image g).image f = (s.image f').image g' := by
simp_rw [image_image, h_comm]
#align set.image_comm Set.image_comm
theorem _root_.Function.Semiconj.set_image {f : α → β} {ga : α → α} {gb : β → β}
(h : Function.Semiconj f ga gb) : Function.Semiconj (image f) (image ga) (image gb) := fun _ =>
image_comm h
#align function.semiconj.set_image Function.Semiconj.set_image
theorem _root_.Function.Commute.set_image {f g : α → α} (h : Function.Commute f g) :
Function.Commute (image f) (image g) :=
Function.Semiconj.set_image h
#align function.commute.set_image Function.Commute.set_image
/-- Image is monotone with respect to `⊆`. See `Set.monotone_image` for the statement in
terms of `≤`. -/
@[gcongr]
theorem image_subset {a b : Set α} (f : α → β) (h : a ⊆ b) : f '' a ⊆ f '' b := by
simp only [subset_def, mem_image]
exact fun x => fun ⟨w, h1, h2⟩ => ⟨w, h h1, h2⟩
#align set.image_subset Set.image_subset
/-- `Set.image` is monotone. See `Set.image_subset` for the statement in terms of `⊆`. -/
lemma monotone_image {f : α → β} : Monotone (image f) := fun _ _ => image_subset _
#align set.monotone_image Set.monotone_image
theorem image_union (f : α → β) (s t : Set α) : f '' (s ∪ t) = f '' s ∪ f '' t :=
ext fun x =>
⟨by rintro ⟨a, h | h, rfl⟩ <;> [left; right] <;> exact ⟨_, h, rfl⟩, by
rintro (⟨a, h, rfl⟩ | ⟨a, h, rfl⟩) <;> refine' ⟨_, _, rfl⟩ <;> [left; right] <;> exact h⟩
#align set.image_union Set.image_union
@[simp]
theorem image_empty (f : α → β) : f '' ∅ = ∅ := by
ext
simp
#align set.image_empty Set.image_empty
theorem image_inter_subset (f : α → β) (s t : Set α) : f '' (s ∩ t) ⊆ f '' s ∩ f '' t :=
subset_inter (image_subset _ <| inter_subset_left _ _) (image_subset _ <| inter_subset_right _ _)
#align set.image_inter_subset Set.image_inter_subset
theorem image_inter_on {f : α → β} {s t : Set α} (h : ∀ x ∈ t, ∀ y ∈ s, f x = f y → x = y) :
f '' (s ∩ t) = f '' s ∩ f '' t :=
(image_inter_subset _ _ _).antisymm
fun b ⟨⟨a₁, ha₁, h₁⟩, ⟨a₂, ha₂, h₂⟩⟩ ↦
have : a₂ = a₁ := h _ ha₂ _ ha₁ (by simp [*])
⟨a₁, ⟨ha₁, this ▸ ha₂⟩, h₁⟩
#align set.image_inter_on Set.image_inter_on
theorem image_inter {f : α → β} {s t : Set α} (H : Injective f) : f '' (s ∩ t) = f '' s ∩ f '' t :=
image_inter_on fun _ _ _ _ h => H h
#align set.image_inter Set.image_inter
theorem image_univ_of_surjective {ι : Type*} {f : ι → β} (H : Surjective f) : f '' univ = univ :=
eq_univ_of_forall <| by simpa [image]
#align set.image_univ_of_surjective Set.image_univ_of_surjective
@[simp]
theorem image_singleton {f : α → β} {a : α} : f '' {a} = {f a} := by
ext
simp [image, eq_comm]
#align set.image_singleton Set.image_singleton
@[simp]
theorem Nonempty.image_const {s : Set α} (hs : s.Nonempty) (a : β) : (fun _ => a) '' s = {a} :=
ext fun _ =>
⟨fun ⟨_, _, h⟩ => h ▸ mem_singleton _, fun h =>
(eq_of_mem_singleton h).symm ▸ hs.imp fun _ hy => ⟨hy, rfl⟩⟩
#align set.nonempty.image_const Set.Nonempty.image_const
@[simp, mfld_simps]
theorem image_eq_empty {α β} {f : α → β} {s : Set α} : f '' s = ∅ ↔ s = ∅ := by
simp only [eq_empty_iff_forall_not_mem]
exact ⟨fun H a ha => H _ ⟨_, ha, rfl⟩, fun H b ⟨_, ha, _⟩ => H _ ha⟩
#align set.image_eq_empty Set.image_eq_empty
-- Porting note: `compl` is already defined in `Init.Set`
theorem preimage_compl_eq_image_compl [BooleanAlgebra α] (S : Set α) :
HasCompl.compl ⁻¹' S = HasCompl.compl '' S :=
Set.ext fun x =>
⟨fun h => ⟨xᶜ, h, compl_compl x⟩, fun h =>
Exists.elim h fun _ hy => (compl_eq_comm.mp hy.2).symm.subst hy.1⟩
#align set.preimage_compl_eq_image_compl Set.preimage_compl_eq_image_compl
theorem mem_compl_image [BooleanAlgebra α] (t : α) (S : Set α) :
t ∈ HasCompl.compl '' S ↔ tᶜ ∈ S := by
simp [← preimage_compl_eq_image_compl]
#align set.mem_compl_image Set.mem_compl_image
@[simp]
theorem image_id_eq : image (id : α → α) = id := by ext; simp
/-- A variant of `image_id` -/
@[simp]
theorem image_id' (s : Set α) : (fun x => x) '' s = s := by
ext
simp
#align set.image_id' Set.image_id'
theorem image_id (s : Set α) : id '' s = s := by simp
#align set.image_id Set.image_id
lemma image_iterate_eq {f : α → α} {n : ℕ} : image (f^[n]) = (image f)^[n] := by
induction' n with n ih; · simp
rw [iterate_succ', iterate_succ',← ih, image_comp_eq]
theorem compl_compl_image [BooleanAlgebra α] (S : Set α) :
HasCompl.compl '' (HasCompl.compl '' S) = S := by
rw [← image_comp, compl_comp_compl, image_id]
#align set.compl_compl_image Set.compl_compl_image
theorem image_insert_eq {f : α → β} {a : α} {s : Set α} :
f '' insert a s = insert (f a) (f '' s) := by
ext
simp [and_or_left, exists_or, eq_comm, or_comm, and_comm]
#align set.image_insert_eq Set.image_insert_eq
theorem image_pair (f : α → β) (a b : α) : f '' {a, b} = {f a, f b} := by
simp only [image_insert_eq, image_singleton]
#align set.image_pair Set.image_pair
theorem image_subset_preimage_of_inverse {f : α → β} {g : β → α} (I : LeftInverse g f) (s : Set α) :
f '' s ⊆ g ⁻¹' s := fun _ ⟨a, h, e⟩ => e ▸ ((I a).symm ▸ h : g (f a) ∈ s)
#align set.image_subset_preimage_of_inverse Set.image_subset_preimage_of_inverse
theorem preimage_subset_image_of_inverse {f : α → β} {g : β → α} (I : LeftInverse g f) (s : Set β) :
f ⁻¹' s ⊆ g '' s := fun b h => ⟨f b, h, I b⟩
#align set.preimage_subset_image_of_inverse Set.preimage_subset_image_of_inverse
theorem image_eq_preimage_of_inverse {f : α → β} {g : β → α} (h₁ : LeftInverse g f)
(h₂ : RightInverse g f) : image f = preimage g :=
funext fun s =>
Subset.antisymm (image_subset_preimage_of_inverse h₁ s) (preimage_subset_image_of_inverse h₂ s)
#align set.image_eq_preimage_of_inverse Set.image_eq_preimage_of_inverse
theorem mem_image_iff_of_inverse {f : α → β} {g : β → α} {b : β} {s : Set α} (h₁ : LeftInverse g f)
(h₂ : RightInverse g f) : b ∈ f '' s ↔ g b ∈ s := by
rw [image_eq_preimage_of_inverse h₁ h₂]; rfl
#align set.mem_image_iff_of_inverse Set.mem_image_iff_of_inverse
theorem image_compl_subset {f : α → β} {s : Set α} (H : Injective f) : f '' sᶜ ⊆ (f '' s)ᶜ :=
Disjoint.subset_compl_left <| by simp [disjoint_iff_inf_le, ← image_inter H]
#align set.image_compl_subset Set.image_compl_subset
theorem subset_image_compl {f : α → β} {s : Set α} (H : Surjective f) : (f '' s)ᶜ ⊆ f '' sᶜ :=
compl_subset_iff_union.2 <| by
rw [← image_union]
simp [image_univ_of_surjective H]
#align set.subset_image_compl Set.subset_image_compl
theorem image_compl_eq {f : α → β} {s : Set α} (H : Bijective f) : f '' sᶜ = (f '' s)ᶜ :=
Subset.antisymm (image_compl_subset H.1) (subset_image_compl H.2)
#align set.image_compl_eq Set.image_compl_eq
theorem subset_image_diff (f : α → β) (s t : Set α) : f '' s \ f '' t ⊆ f '' (s \ t) := by
rw [diff_subset_iff, ← image_union, union_diff_self]
exact image_subset f (subset_union_right t s)
#align set.subset_image_diff Set.subset_image_diff
theorem subset_image_symmDiff : (f '' s) ∆ (f '' t) ⊆ f '' s ∆ t :=
(union_subset_union (subset_image_diff _ _ _) <| subset_image_diff _ _ _).trans
(superset_of_eq (image_union _ _ _))
#align set.subset_image_symm_diff Set.subset_image_symmDiff
theorem image_diff {f : α → β} (hf : Injective f) (s t : Set α) : f '' (s \ t) = f '' s \ f '' t :=
Subset.antisymm
(Subset.trans (image_inter_subset _ _ _) <| inter_subset_inter_right _ <| image_compl_subset hf)
(subset_image_diff f s t)
#align set.image_diff Set.image_diff
theorem image_symmDiff (hf : Injective f) (s t : Set α) : f '' s ∆ t = (f '' s) ∆ (f '' t) := by
simp_rw [Set.symmDiff_def, image_union, image_diff hf]
#align set.image_symm_diff Set.image_symmDiff
theorem Nonempty.image (f : α → β) {s : Set α} : s.Nonempty → (f '' s).Nonempty
| ⟨x, hx⟩ => ⟨f x, mem_image_of_mem f hx⟩
#align set.nonempty.image Set.Nonempty.image
theorem Nonempty.of_image {f : α → β} {s : Set α} : (f '' s).Nonempty → s.Nonempty
| ⟨_, x, hx, _⟩ => ⟨x, hx⟩
#align set.nonempty.of_image Set.Nonempty.of_image
@[simp]
theorem nonempty_image_iff {f : α → β} {s : Set α} : (f '' s).Nonempty ↔ s.Nonempty :=
⟨Nonempty.of_image, fun h => h.image f⟩
#align set.nonempty_image_iff Set.nonempty_image_iff
theorem Nonempty.preimage {s : Set β} (hs : s.Nonempty) {f : α → β} (hf : Surjective f) :
(f ⁻¹' s).Nonempty :=
let ⟨y, hy⟩ := hs
let ⟨x, hx⟩ := hf y
⟨x, mem_preimage.2 <| hx.symm ▸ hy⟩
#align set.nonempty.preimage Set.Nonempty.preimage
instance (f : α → β) (s : Set α) [Nonempty s] : Nonempty (f '' s) :=
(Set.Nonempty.image f nonempty_of_nonempty_subtype).to_subtype
/-- image and preimage are a Galois connection -/
@[simp]
theorem image_subset_iff {s : Set α} {t : Set β} {f : α → β} : f '' s ⊆ t ↔ s ⊆ f ⁻¹' t :=
ball_image_iff
#align set.image_subset_iff Set.image_subset_iff
theorem image_preimage_subset (f : α → β) (s : Set β) : f '' (f ⁻¹' s) ⊆ s :=
image_subset_iff.2 Subset.rfl
#align set.image_preimage_subset Set.image_preimage_subset
theorem subset_preimage_image (f : α → β) (s : Set α) : s ⊆ f ⁻¹' (f '' s) := fun _ =>
mem_image_of_mem f
#align set.subset_preimage_image Set.subset_preimage_image
@[simp]
theorem preimage_image_eq {f : α → β} (s : Set α) (h : Injective f) : f ⁻¹' (f '' s) = s :=
Subset.antisymm (fun _ ⟨_, hy, e⟩ => h e ▸ hy) (subset_preimage_image f s)
#align set.preimage_image_eq Set.preimage_image_eq
@[simp]
theorem image_preimage_eq {f : α → β} (s : Set β) (h : Surjective f) : f '' (f ⁻¹' s) = s :=
Subset.antisymm (image_preimage_subset f s) fun x hx =>
let ⟨y, e⟩ := h x
⟨y, (e.symm ▸ hx : f y ∈ s), e⟩
#align set.image_preimage_eq Set.image_preimage_eq
@[simp]
theorem preimage_eq_preimage {f : β → α} (hf : Surjective f) : f ⁻¹' s = f ⁻¹' t ↔ s = t :=
Iff.intro
fun eq => by rw [← image_preimage_eq s hf, ← image_preimage_eq t hf, eq]
fun eq => eq ▸ rfl
#align set.preimage_eq_preimage Set.preimage_eq_preimage
theorem image_inter_preimage (f : α → β) (s : Set α) (t : Set β) :
f '' (s ∩ f ⁻¹' t) = f '' s ∩ t := by
apply Subset.antisymm
· calc
f '' (s ∩ f ⁻¹' t) ⊆ f '' s ∩ f '' (f ⁻¹' t) := image_inter_subset _ _ _
_ ⊆ f '' s ∩ t := inter_subset_inter_right _ (image_preimage_subset f t)
· rintro _ ⟨⟨x, h', rfl⟩, h⟩
exact ⟨x, ⟨h', h⟩, rfl⟩
#align set.image_inter_preimage Set.image_inter_preimage
theorem image_preimage_inter (f : α → β) (s : Set α) (t : Set β) :
f '' (f ⁻¹' t ∩ s) = t ∩ f '' s := by simp only [inter_comm, image_inter_preimage]
#align set.image_preimage_inter Set.image_preimage_inter
@[simp]
theorem image_inter_nonempty_iff {f : α → β} {s : Set α} {t : Set β} :
(f '' s ∩ t).Nonempty ↔ (s ∩ f ⁻¹' t).Nonempty := by
rw [← image_inter_preimage, nonempty_image_iff]
#align set.image_inter_nonempty_iff Set.image_inter_nonempty_iff
theorem image_diff_preimage {f : α → β} {s : Set α} {t : Set β} : f '' (s \ f ⁻¹' t) = f '' s \ t :=
by simp_rw [diff_eq, ← preimage_compl, image_inter_preimage]
#align set.image_diff_preimage Set.image_diff_preimage
theorem compl_image : image (compl : Set α → Set α) = preimage compl :=
image_eq_preimage_of_inverse compl_compl compl_compl
#align set.compl_image Set.compl_image
theorem compl_image_set_of {p : Set α → Prop} : compl '' { s | p s } = { s | p sᶜ } :=
congr_fun compl_image p
#align set.compl_image_set_of Set.compl_image_set_of
theorem inter_preimage_subset (s : Set α) (t : Set β) (f : α → β) :
s ∩ f ⁻¹' t ⊆ f ⁻¹' (f '' s ∩ t) := fun _ h => ⟨mem_image_of_mem _ h.left, h.right⟩
#align set.inter_preimage_subset Set.inter_preimage_subset
theorem union_preimage_subset (s : Set α) (t : Set β) (f : α → β) :
s ∪ f ⁻¹' t ⊆ f ⁻¹' (f '' s ∪ t) := fun _ h =>
Or.elim h (fun l => Or.inl <| mem_image_of_mem _ l) fun r => Or.inr r
#align set.union_preimage_subset Set.union_preimage_subset
theorem subset_image_union (f : α → β) (s : Set α) (t : Set β) : f '' (s ∪ f ⁻¹' t) ⊆ f '' s ∪ t :=
image_subset_iff.2 (union_preimage_subset _ _ _)
#align set.subset_image_union Set.subset_image_union
theorem preimage_subset_iff {A : Set α} {B : Set β} {f : α → β} :
f ⁻¹' B ⊆ A ↔ ∀ a : α, f a ∈ B → a ∈ A :=
Iff.rfl
#align set.preimage_subset_iff Set.preimage_subset_iff
theorem image_eq_image {f : α → β} (hf : Injective f) : f '' s = f '' t ↔ s = t :=
Iff.symm <|
(Iff.intro fun eq => eq ▸ rfl) fun eq => by
rw [← preimage_image_eq s hf, ← preimage_image_eq t hf, eq]
#align set.image_eq_image Set.image_eq_image
theorem image_subset_image_iff {f : α → β} (hf : Injective f) : f '' s ⊆ f '' t ↔ s ⊆ t := by
refine' Iff.symm <| (Iff.intro (image_subset f)) fun h => _
rw [← preimage_image_eq s hf, ← preimage_image_eq t hf]
exact preimage_mono h
#align set.image_subset_image_iff Set.image_subset_image_iff
theorem prod_quotient_preimage_eq_image [s : Setoid α] (g : Quotient s → β) {h : α → β}
(Hh : h = g ∘ Quotient.mk'') (r : Set (β × β)) :
{ x : Quotient s × Quotient s | (g x.1, g x.2) ∈ r } =
(fun a : α × α => (⟦a.1⟧, ⟦a.2⟧)) '' ((fun a : α × α => (h a.1, h a.2)) ⁻¹' r) :=
Hh.symm ▸
Set.ext fun ⟨a₁, a₂⟩ =>
⟨Quot.induction_on₂ a₁ a₂ fun a₁ a₂ h => ⟨(a₁, a₂), h, rfl⟩, fun ⟨⟨b₁, b₂⟩, h₁, h₂⟩ =>
show (g a₁, g a₂) ∈ r from
have h₃ : ⟦b₁⟧ = a₁ ∧ ⟦b₂⟧ = a₂ := Prod.ext_iff.1 h₂
h₃.1 ▸ h₃.2 ▸ h₁⟩
#align set.prod_quotient_preimage_eq_image Set.prod_quotient_preimage_eq_image
theorem exists_image_iff (f : α → β) (x : Set α) (P : β → Prop) :
(∃ a : f '' x, P a) ↔ ∃ a : x, P (f a) :=
⟨fun ⟨a, h⟩ => ⟨⟨_, a.prop.choose_spec.1⟩, a.prop.choose_spec.2.symm ▸ h⟩, fun ⟨a, h⟩ =>
⟨⟨_, _, a.prop, rfl⟩, h⟩⟩
#align set.exists_image_iff Set.exists_image_iff
/-- Restriction of `f` to `s` factors through `s.imageFactorization f : s → f '' s`. -/
def imageFactorization (f : α → β) (s : Set α) : s → f '' s := fun p =>
⟨f p.1, mem_image_of_mem f p.2⟩
#align set.image_factorization Set.imageFactorization
theorem imageFactorization_eq {f : α → β} {s : Set α} :
Subtype.val ∘ imageFactorization f s = f ∘ Subtype.val :=
funext fun _ => rfl
#align set.image_factorization_eq Set.imageFactorization_eq
theorem surjective_onto_image {f : α → β} {s : Set α} : Surjective (imageFactorization f s) :=
fun ⟨_, ⟨a, ha, rfl⟩⟩ => ⟨⟨a, ha⟩, rfl⟩
#align set.surjective_onto_image Set.surjective_onto_image
/-- If the only elements outside `s` are those left fixed by `σ`, then mapping by `σ` has no effect.
-/
theorem image_perm {s : Set α} {σ : Equiv.Perm α} (hs : { a : α | σ a ≠ a } ⊆ s) : σ '' s = s := by
ext i
obtain hi | hi := eq_or_ne (σ i) i
· refine' ⟨_, fun h => ⟨i, h, hi⟩⟩
rintro ⟨j, hj, h⟩
rwa [σ.injective (hi.trans h.symm)]
· refine' iff_of_true ⟨σ.symm i, hs fun h => hi _, σ.apply_symm_apply _⟩ (hs hi)
convert congr_arg σ h <;> exact (σ.apply_symm_apply _).symm
#align set.image_perm Set.image_perm
end Image
/-! ### Lemmas about the powerset and image. -/
/-- The powerset of `{a} ∪ s` is `𝒫 s` together with `{a} ∪ t` for each `t ∈ 𝒫 s`. -/
theorem powerset_insert (s : Set α) (a : α) : 𝒫 insert a s = 𝒫 s ∪ insert a '' 𝒫 s := by
ext t
simp_rw [mem_union, mem_image, mem_powerset_iff]
constructor
· intro h
|
by_cases hs : a ∈ t
|
/-- The powerset of `{a} ∪ s` is `𝒫 s` together with `{a} ∪ t` for each `t ∈ 𝒫 s`. -/
theorem powerset_insert (s : Set α) (a : α) : 𝒫 insert a s = 𝒫 s ∪ insert a '' 𝒫 s := by
ext t
simp_rw [mem_union, mem_image, mem_powerset_iff]
constructor
· intro h
|
Mathlib.Data.Set.Image.651_0.IJFiTzmYGOCpPSd
|
/-- The powerset of `{a} ∪ s` is `𝒫 s` together with `{a} ∪ t` for each `t ∈ 𝒫 s`. -/
theorem powerset_insert (s : Set α) (a : α) : 𝒫 insert a s = 𝒫 s ∪ insert a '' 𝒫 s
|
Mathlib_Data_Set_Image
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.