Skip to content
This repository was archived by the owner on Jul 24, 2024. It is now read-only.

Commit c3e40be

Browse files
committed
feat(data/equiv/local_equiv): define piecewise and disjoint_union (#6700)
Also change some lemmas to use `set.ite`.
1 parent 02f77ab commit c3e40be

File tree

7 files changed

+201
-24
lines changed

7 files changed

+201
-24
lines changed

src/data/equiv/local_equiv.lean

Lines changed: 153 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,11 @@ protected def symm : local_equiv β α :=
156156

157157
instance : has_coe_to_fun (local_equiv α β) := ⟨_, local_equiv.to_fun⟩
158158

159+
/-- See Note [custom simps projection] -/
160+
def simps.inv_fun (e : local_equiv α β) : β → α := e.symm
161+
162+
initialize_simps_projections local_equiv (to_fun → apply, inv_fun → symm_apply)
163+
159164
@[simp, mfld_simps] theorem coe_mk (f : α → β) (g s t ml mr il ir) :
160165
(local_equiv.mk f g s t ml mr il ir : α → β) = f := rfl
161166

@@ -200,6 +205,97 @@ protected def to_equiv : equiv (e.source) (e.target) :=
200205

201206
lemma image_source_eq_target : e '' e.source = e.target := e.bij_on.image_eq
202207

208+
/-- We say that `t : set β` is an image of `s : set α` under a local equivalence if
209+
any of the following equivalent conditions hold:
210+
211+
* `e '' (e.source ∩ s) = e.target ∩ t`;
212+
* `e.source ∩ e ⁻¹ t = e.source ∩ s`;
213+
* `∀ x ∈ e.source, e x ∈ t ↔ x ∈ s` (this one is used in the definition).
214+
-/
215+
def is_image (s : set α) (t : set β) : Prop := ∀ ⦃x⦄, x ∈ e.source → (e x ∈ t ↔ x ∈ s)
216+
217+
namespace is_image
218+
219+
variables {e} {s : set α} {t : set β} {x : α} {y : β}
220+
221+
lemma apply_mem_iff (h : e.is_image s t) (hx : x ∈ e.source) : e x ∈ t ↔ x ∈ s := h hx
222+
223+
lemma symm_apply_mem_iff (h : e.is_image s t) : ∀ ⦃y⦄, y ∈ e.target → (e.symm y ∈ s ↔ y ∈ t) :=
224+
by { rw [← e.image_source_eq_target, ball_image_iff], intros x hx, rw [e.left_inv hx, h hx] }
225+
226+
protected lemma symm (h : e.is_image s t) : e.symm.is_image t s := h.symm_apply_mem_iff
227+
228+
@[simp] lemma symm_iff : e.symm.is_image t s ↔ e.is_image s t := ⟨λ h, h.symm, λ h, h.symm⟩
229+
230+
protected lemma maps_to (h : e.is_image s t) : maps_to e (e.source ∩ s) (e.target ∩ t) :=
231+
λ x hx, ⟨e.maps_to hx.1, (h hx.1).2 hx.2
232+
233+
lemma symm_maps_to (h : e.is_image s t) : maps_to e.symm (e.target ∩ t) (e.source ∩ s) :=
234+
h.symm.maps_to
235+
236+
/-- Restrict a `local_equiv` to a pair of corresponding sets. -/
237+
@[simps] def restr (h : e.is_image s t) : local_equiv α β :=
238+
{ to_fun := e,
239+
inv_fun := e.symm,
240+
source := e.source ∩ s,
241+
target := e.target ∩ t,
242+
map_source' := h.maps_to,
243+
map_target' := h.symm_maps_to,
244+
left_inv' := e.left_inv_on.mono (inter_subset_left _ _),
245+
right_inv' := e.right_inv_on.mono (inter_subset_left _ _) }
246+
247+
lemma image_eq (h : e.is_image s t) : e '' (e.source ∩ s) = e.target ∩ t :=
248+
h.restr.image_source_eq_target
249+
250+
lemma symm_image_eq (h : e.is_image s t) : e.symm '' (e.target ∩ t) = e.source ∩ s :=
251+
h.symm.image_eq
252+
253+
lemma iff_preimage_eq : e.is_image s t ↔ e.source ∩ e ⁻¹' t = e.source ∩ s :=
254+
by simp only [is_image, set.ext_iff, mem_inter_eq, and.congr_right_iff, mem_preimage]
255+
256+
alias iff_preimage_eq ↔ local_equiv.is_image.preimage_eq local_equiv.is_image.of_preimage_eq
257+
258+
lemma iff_symm_preimage_eq : e.is_image s t ↔ e.target ∩ e.symm ⁻¹' s = e.target ∩ t :=
259+
symm_iff.symm.trans iff_preimage_eq
260+
261+
alias iff_symm_preimage_eq ↔ local_equiv.is_image.symm_preimage_eq
262+
local_equiv.is_image.of_symm_preimage_eq
263+
264+
lemma of_image_eq (h : e '' (e.source ∩ s) = e.target ∩ t) : e.is_image s t :=
265+
of_symm_preimage_eq $ eq.trans (of_symm_preimage_eq rfl).image_eq.symm h
266+
267+
lemma of_symm_image_eq (h : e.symm '' (e.target ∩ t) = e.source ∩ s) : e.is_image s t :=
268+
of_preimage_eq $ eq.trans (of_preimage_eq rfl).symm_image_eq.symm h
269+
270+
protected lemma compl (h : e.is_image s t) : e.is_image sᶜ tᶜ :=
271+
λ x hx, not_congr (h hx)
272+
273+
protected lemma inter {s' t'} (h : e.is_image s t) (h' : e.is_image s' t') :
274+
e.is_image (s ∩ s') (t ∩ t') :=
275+
λ x hx, and_congr (h hx) (h' hx)
276+
277+
protected lemma union {s' t'} (h : e.is_image s t) (h' : e.is_image s' t') :
278+
e.is_image (s ∪ s') (t ∪ t') :=
279+
λ x hx, or_congr (h hx) (h' hx)
280+
281+
protected lemma diff {s' t'} (h : e.is_image s t) (h' : e.is_image s' t') :
282+
e.is_image (s \ s') (t \ t') :=
283+
h.inter h'.compl
284+
285+
lemma left_inv_on_piecewise {e' : local_equiv α β} [∀ i, decidable (i ∈ s)] [∀ i, decidable (i ∈ t)]
286+
(h : e.is_image s t) (h' : e'.is_image s t) :
287+
left_inv_on (t.piecewise e.symm e'.symm) (s.piecewise e e') (s.ite e.source e'.source) :=
288+
begin
289+
rintro x (⟨he, hs⟩|⟨he, hs : x ∉ s⟩),
290+
{ rw [piecewise_eq_of_mem _ _ _ hs, piecewise_eq_of_mem _ _ _ ((h he).2 hs), e.left_inv he], },
291+
{ rw [piecewise_eq_of_not_mem _ _ _ hs, piecewise_eq_of_not_mem _ _ _ ((h'.compl he).2 hs),
292+
e'.left_inv he] }
293+
end
294+
295+
end is_image
296+
297+
lemma is_image_source_target : e.is_image e.source e.target := λ x hx, by simp [hx]
298+
203299
lemma image_source_inter_eq' (s : set α) :
204300
e '' (e.source ∩ s) = e.target ∩ e.symm ⁻¹' s :=
205301
by rw [inter_comm, e.left_inv_on.image_inter', image_source_eq_target, inter_comm]
@@ -257,20 +353,7 @@ end
257353

258354
/-- Restricting a local equivalence to e.source ∩ s -/
259355
protected def restr (s : set α) : local_equiv α β :=
260-
{ to_fun := e,
261-
inv_fun := e.symm,
262-
source := e.source ∩ s,
263-
target := e.target ∩ e.symm⁻¹' s,
264-
map_source' := λx hx, begin
265-
simp only with mfld_simps at hx,
266-
simp only [hx] with mfld_simps,
267-
end,
268-
map_target' := λy hy, begin
269-
simp only with mfld_simps at hy,
270-
simp only [hy] with mfld_simps,
271-
end,
272-
left_inv' := λx hx, e.left_inv hx.1,
273-
right_inv' := λy hy, e.right_inv hy.1 }
356+
(@is_image.of_symm_preimage_eq α β e s _ rfl).restr
274357

275358
@[simp, mfld_simps] lemma restr_coe (s : set α) : (e.restr s : α → β) = e := rfl
276359
@[simp, mfld_simps] lemma restr_coe_symm (s : set α) : ((e.restr s).symm : β → α) = e.symm := rfl
@@ -520,6 +603,62 @@ by ext x; simp [ext_iff]; tauto
520603

521604
end prod
522605

606+
/-- Combine two `local_equiv`s using `set.piecewise`. The source of the new `local_equiv` is
607+
`s.ite e.source e'.source = e.source ∩ s ∪ e'.source \ s`, and similarly for target. The function
608+
sends `e.source ∩ s` to `e.target ∩ t` using `e` and `e'.source \ s` to `e'.target \ t` using `e'`,
609+
and similarly for the inverse function. The definition assumes `e.is_image s t` and
610+
`e'.is_image s t`. -/
611+
@[simps] def piecewise (e e' : local_equiv α β) (s : set α) (t : set β)
612+
[∀ x, decidable (x ∈ s)] [∀ y, decidable (y ∈ t)] (H : e.is_image s t) (H' : e'.is_image s t) :
613+
local_equiv α β :=
614+
{ to_fun := s.piecewise e e',
615+
inv_fun := t.piecewise e.symm e'.symm,
616+
source := s.ite e.source e'.source,
617+
target := t.ite e.target e'.target,
618+
map_source' := H.maps_to.piecewise_ite H'.compl.maps_to,
619+
map_target' := H.symm.maps_to.piecewise_ite H'.symm.compl.maps_to,
620+
left_inv' := H.left_inv_on_piecewise H',
621+
right_inv' := H.symm.left_inv_on_piecewise H'.symm }
622+
623+
lemma symm_piecewise (e e' : local_equiv α β) {s : set α} {t : set β}
624+
[∀ x, decidable (x ∈ s)] [∀ y, decidable (y ∈ t)]
625+
(H : e.is_image s t) (H' : e'.is_image s t) :
626+
(e.piecewise e' s t H H').symm = e.symm.piecewise e'.symm t s H.symm H'.symm :=
627+
rfl
628+
629+
/-- Combine two `local_equiv`s with disjoint sources and disjoint targets. We do not reuse
630+
`local_equiv.piecewise` here to provide better formulas for `source` and `target`. -/
631+
@[simps] def disjoint_union (e e' : local_equiv α β) (hs : disjoint e.source e'.source)
632+
(ht : disjoint e.target e'.target) [∀ x, decidable (x ∈ e.source)]
633+
[∀ y, decidable (y ∈ e.target)] :
634+
local_equiv α β :=
635+
{ to_fun := e.source.piecewise e e',
636+
inv_fun := e.target.piecewise e.symm e'.symm,
637+
source := e.source ∪ e'.source,
638+
target := e.target ∪ e'.target,
639+
map_source' := λ x,
640+
have x ∈ e'.source → x ∉ e.source, from λ h' h, hs ⟨h, h'⟩,
641+
by rintro (he|he'); simp *,
642+
map_target' := λ y,
643+
have y ∈ e'.target → y ∉ e.target, from λ h' h, ht ⟨h, h'⟩,
644+
by rintro (he|he'); simp *,
645+
left_inv' := λ x,
646+
begin
647+
rintro (he|he'),
648+
{ simp * },
649+
{ have : x ∉ e.source ∧ e' x ∉ e.target,
650+
from ⟨λ h, hs ⟨h, he'⟩, λ h, ht ⟨h, e'.map_source he'⟩⟩,
651+
simp * }
652+
end,
653+
right_inv' := λ y,
654+
begin
655+
rintro (he|he'),
656+
{ simp * },
657+
{ have : y ∉ e.target ∧ e'.symm y ∉ e.source,
658+
from ⟨λ h, ht ⟨h, he'⟩, λ h, hs ⟨h, e'.map_target he'⟩⟩,
659+
simp * }
660+
end }
661+
523662
section pi
524663

525664
variables {ι : Type*} {αi βi : ι → Type*} (ei : Π i, local_equiv (αi i) (βi i))

src/data/indicator_function.lean

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,12 +129,12 @@ begin
129129
end
130130

131131
lemma indicator_preimage (s : set α) (f : α → β) (B : set β) :
132-
(indicator s f)⁻¹' B = sf ⁻¹' B ∪ sᶜ ∩ (λa:α, (0:β)) ⁻¹' B :=
132+
(indicator s f)⁻¹' B = s.ite (f ⁻¹' B) (0 ⁻¹' B) :=
133133
piecewise_preimage s f 0 B
134134

135135
lemma indicator_preimage_of_not_mem (s : set α) (f : α → β) {t : set β} (ht : (0:β) ∉ t) :
136-
(indicator s f)⁻¹' t = s ∩ f ⁻¹' t :=
137-
by simp [indicator_preimage, set.preimage_const_of_not_mem ht]
136+
(indicator s f)⁻¹' t = f ⁻¹' t ∩ s :=
137+
by simp [indicator_preimage, pi.zero_def, set.preimage_const_of_not_mem ht]
138138

139139
lemma mem_range_indicator {r : β} {s : set α} {f : α → β} :
140140
r ∈ range (indicator s f) ↔ (r = 0 ∧ s ≠ univ) ∨ (r ∈ f '' s) :=

src/data/set/basic.lean

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1046,6 +1046,12 @@ by simp [set.ite]
10461046
@[simp] lemma ite_univ (s s' : set α) : set.ite univ s s' = s :=
10471047
by simp [set.ite]
10481048

1049+
@[simp] lemma ite_empty_left (t s : set α) : t.ite ∅ s = s \ t :=
1050+
by simp [set.ite]
1051+
1052+
@[simp] lemma ite_empty_right (t s : set α) : t.ite s ∅ = s ∩ t :=
1053+
by simp [set.ite]
1054+
10491055
lemma ite_mono (t : set α) {s₁ s₁' s₂ s₂' : set α} (h : s₁ ⊆ s₂) (h' : s₁' ⊆ s₂') :
10501056
t.ite s₁ s₁' ⊆ t.ite s₂ s₂' :=
10511057
union_subset_union (inter_subset_inter_left _ h) (inter_subset_inter_left _ h')

src/data/set/function.lean

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -679,9 +679,36 @@ funext $ λ x, if hx : x ∈ s then by simp [hx] else by simp [hx]
679679
(range f).piecewise g₁ g₂ ∘ f = g₁ ∘ f :=
680680
comp_eq_of_eq_on_range $ piecewise_eq_on _ _ _
681681

682+
theorem maps_to.piecewise_ite {s s₁ s₂ : set α} {t t₁ t₂ : set β} {f₁ f₂ : α → β}
683+
[∀ i, decidable (i ∈ s)]
684+
(h₁ : maps_to f₁ (s₁ ∩ s) (t₁ ∩ t)) (h₂ : maps_to f₂ (s₂ ∩ sᶜ) (t₂ ∩ tᶜ)) :
685+
maps_to (s.piecewise f₁ f₂) (s.ite s₁ s₂) (t.ite t₁ t₂) :=
686+
begin
687+
refine (h₁.congr _).union_union (h₂.congr _),
688+
exacts [(piecewise_eq_on s f₁ f₂).symm.mono (inter_subset_right _ _),
689+
(piecewise_eq_on_compl s f₁ f₂).symm.mono (inter_subset_right _ _)]
690+
end
691+
692+
theorem eq_on_piecewise {f f' g : α → β} {t} :
693+
eq_on (s.piecewise f f') g t ↔ eq_on f g (t ∩ s) ∧ eq_on f' g (t ∩ sᶜ) :=
694+
begin
695+
simp only [eq_on, ← forall_and_distrib],
696+
refine forall_congr (λ a, _), by_cases a ∈ s; simp *
697+
end
698+
699+
theorem eq_on.piecewise_ite' {f f' g : α → β} {t t'} (h : eq_on f g (t ∩ s))
700+
(h' : eq_on f' g (t' ∩ sᶜ)) :
701+
eq_on (s.piecewise f f') g (s.ite t t') :=
702+
by simp [eq_on_piecewise, *]
703+
704+
theorem eq_on.piecewise_ite {f f' g : α → β} {t t'} (h : eq_on f g t)
705+
(h' : eq_on f' g t') :
706+
eq_on (s.piecewise f f') g (s.ite t t') :=
707+
(h.mono (inter_subset_left _ _)).piecewise_ite' s (h'.mono (inter_subset_left _ _))
708+
682709
lemma piecewise_preimage (f g : α → β) (t) :
683-
s.piecewise f g ⁻¹' t = sf ⁻¹' t ∪ sᶜ ∩ g ⁻¹' t :=
684-
ext $ λ x, by by_cases x ∈ s; simp *
710+
s.piecewise f g ⁻¹' t = s.ite (f ⁻¹' t) (g ⁻¹' t) :=
711+
ext $ λ x, by by_cases x ∈ s; simp [*, set.ite]
685712

686713
lemma comp_piecewise (h : β → γ) {f g : α → β} {x : α} :
687714
h (s.piecewise f g x) = s.piecewise (h ∘ f) (h ∘ g) x :=

src/measure_theory/integration.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,7 @@ by simp only [hs, coe_restrict]
412412

413413
theorem restrict_preimage (f : α →ₛ β) {s : set α} (hs : measurable_set s)
414414
{t : set β} (ht : (0:β) ∉ t) : restrict f s ⁻¹' t = s ∩ f ⁻¹' t :=
415-
by simp [hs, indicator_preimage_of_not_mem _ _ ht]
415+
by simp [hs, indicator_preimage_of_not_mem _ _ ht, inter_comm]
416416

417417
theorem restrict_preimage_singleton (f : α →ₛ β) {s : set α} (hs : measurable_set s)
418418
{r : β} (hr : r ≠ 0) : restrict f s ⁻¹' {r} = s ∩ f ⁻¹' {r} :=

src/measure_theory/measurable_space.lean

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,11 @@ by { rw inter_eq_compl_compl_union_compl, exact (h₁.compl.union h₂.compl).co
204204
measurable_set (s₁ \ s₂) :=
205205
h₁.inter h₂.compl
206206

207+
@[simp] lemma measurable_set.ite {t s₁ s₂ : set α} (ht : measurable_set t) (h₁ : measurable_set s₁)
208+
(h₂ : measurable_set s₂) :
209+
measurable_set (t.ite s₁ s₂) :=
210+
(h₁.inter ht).union (h₂.diff ht)
211+
207212
@[simp] lemma measurable_set.disjointed {f : ℕ → set α} (h : ∀ i, measurable_set (f i)) (n) :
208213
measurable_set (disjointed f n) :=
209214
disjointed_induct (h n) (assume t i ht, measurable_set.diff ht $ h _)
@@ -516,8 +521,8 @@ lemma measurable.piecewise {s : set α} {_ : decidable_pred s} {f g : α → β}
516521
measurable (piecewise s f g) :=
517522
begin
518523
intros t ht,
519-
simp only [piecewise_preimage],
520-
exact (hs.inter $ hf ht).union (hs.compl.inter $ hg ht)
524+
rw piecewise_preimage,
525+
exact hs.ite (hf ht) (hg ht)
521526
end
522527

523528
/-- this is slightly different from `measurable.piecewise`. It can be used to show

src/measure_theory/set_integral.lean

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -632,8 +632,8 @@ begin
632632
assume t ht,
633633
obtain ⟨u, u_open, hu⟩ : ∃ (u : set α), is_open u ∧ f ⁻¹' t ∩ s = u ∩ s :=
634634
_root_.continuous_on_iff'.1 hf t ht,
635-
rw [indicator_preimage, inter_comm, hu],
636-
exact (u_open.measurable_set.inter hs).union (hs.compl.inter (measurable_const ht.measurable_set))
635+
rw [indicator_preimage, set.ite, hu],
636+
exact (u_open.measurable_set.inter hs).union ((measurable_zero ht.measurable_set).diff hs)
637637
end
638638

639639
lemma continuous_on.integrable_at_nhds_within

0 commit comments

Comments
 (0)