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

Commit 0fc4e6a

Browse files
urkudkim-emmergify[bot]
authored
refactor(data/set/function): move function.restrict to set, redefine (#2243)
* refactor(data/set/function): move `function.restrict` to `set`, redefine We had `subtype.restrict` and `function.restrict` both defined in the same way using `subtype.val`. This PR moves `function.restrict` to `set.restrict` and makes it use `coe` instead of `subtype.val`. * Fix compile * Update src/data/set/function.lean Co-authored-by: Scott Morrison <scott@tqft.net> Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
1 parent fa36a8e commit 0fc4e6a

File tree

16 files changed

+88
-41
lines changed

16 files changed

+88
-41
lines changed

archive/sensitivity.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@ begin
373373
rw ← dim_eq_injective (g m) g_injective,
374374
apply dim_V },
375375
have dimW : dim W = card H,
376-
{ have li : linear_independent ℝ (restrict e H) :=
376+
{ have li : linear_independent ℝ (set.restrict e H) :=
377377
linear_independent.comp (dual_pair_e_ε _).is_basis.1 _ subtype.val_injective,
378378
have hdW := dim_span li,
379379
rw set.range_restrict at hdW,

src/analysis/complex/exponential.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1765,7 +1765,7 @@ begin
17651765
have : δ ≤ ε ^ (1 / q) := le_trans (min_le_left _ _) (min_le_right _ _),
17661766
have : δ < 1 := lt_of_le_of_lt (min_le_right _ _) (by norm_num),
17671767
use δ, use δ0, rintros ⟨⟨x, y⟩, hy⟩,
1768-
simp only [subtype.dist_eq, real.dist_eq, prod.dist_eq, sub_zero],
1768+
simp only [subtype.dist_eq, real.dist_eq, prod.dist_eq, sub_zero, subtype.coe_mk],
17691769
assume h, rw max_lt_iff at h, cases h with xδ yy₀,
17701770
have qy : q < y, calc q < y₀ / 2 : q_lt
17711771
... = y₀ - y₀ / 2 : (sub_half _).symm

src/data/set/basic.lean

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1432,7 +1432,7 @@ set.ext $ assume a,
14321432
⟨assume ⟨⟨a', ha'⟩, in_s, h_eq⟩, h_eq ▸ ⟨ha', in_s⟩,
14331433
assume ⟨ha, in_s⟩, ⟨⟨a, ha⟩, in_s, rfl⟩⟩
14341434

1435-
lemma val_range {p : α → Prop} :
1435+
@[simp] lemma val_range {p : α → Prop} :
14361436
set.range (@subtype.val _ p) = {x | p x} :=
14371437
by rw ← set.image_univ; simp [-set.image_univ, val_image]
14381438

@@ -1478,13 +1478,13 @@ section range
14781478

14791479
variable {α : Type*}
14801480

1481-
@[simp] lemma subtype.val_range {p : α → Prop} :
1482-
range (@subtype.val _ p) = {x | p x} :=
1483-
subtype.val_range
1484-
14851481
@[simp] lemma range_coe_subtype (s : set α) : range (coe : s → α) = s :=
14861482
subtype.val_range
14871483

1484+
theorem preimage_coe_eq_preimage_coe_iff {s t u : set α} :
1485+
((coe : s → α) ⁻¹' t = coe ⁻¹' u) ↔ t ∩ s = u ∩ s :=
1486+
subtype.preimage_val_eq_preimage_val_iff _ _ _
1487+
14881488
end range
14891489

14901490
/-! ### Lemmas about cartesian product of sets -/

src/data/set/countable.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ begin
8484
have : countable (univ : set s) := countable_encodable _,
8585
rcases countable_iff_exists_surjective.1 this with ⟨g, hg⟩,
8686
have : range g = univ := univ_subset_iff.1 hg,
87-
use subtype.val ∘ g,
87+
use coe ∘ g,
8888
rw [range_comp, this],
8989
simp
9090
end

src/data/set/function.lean

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import data.set.basic logic.function
99
1010
## Main definitions
1111
12+
### Predicate
13+
1214
* `eq_on f₁ f₂ s` : functions `f₁` and `f₂` are equal at every point of `s`;
1315
* `maps_to f s t` : `f` sends every point of `s` to a point of `t`;
1416
* `inj_on f s` : restriction of `f` to `s` is injective;
@@ -18,6 +20,13 @@ import data.set.basic logic.function
1820
* `right_inv_on f' f t` : for every `y ∈ t` we have `f (f' y) = y`;
1921
* `inv_on f' f s t` : `f'` is a two-side inverse of `f` on `s` and `t`, i.e.
2022
we have `left_inv_on f' f s` and `right_inv_on f' f t`.
23+
24+
### Functions
25+
26+
* `restrict f s` : restrict the domain of `f` to the set `s`;
27+
* `cod_restrict f s h` : given `h : ∀ x, f x ∈ s`, restrict the codomain of `f` to the set `s`;
28+
* `maps_to.restrict f s t h`: given `h : maps_to f s t`, restrict the domain of `f` to `s`
29+
and the codomain to `t`.
2130
-/
2231
universes u v w x y
2332

@@ -29,8 +38,25 @@ namespace set
2938

3039
/-! ### Restrict -/
3140

32-
lemma range_restrict (f : α → β) (s : set α) : set.range (restrict f s) = f '' s :=
33-
by { ext x, simp [restrict], refl }
41+
/-- Restrict domain of a function `f` to a set `s`. Same as `subtype.restrict` but this version
42+
takes an argument `↥s` instead of `subtype s`. -/
43+
def restrict (f : α → β) (s : set α) : s → β := λ x, f x
44+
45+
lemma restrict_eq (f : α → β) (s : set α) : s.restrict f = f ∘ coe := rfl
46+
47+
@[simp] lemma restrict_apply (f : α → β) (s : set α) (x : s) : restrict f s x = f x := rfl
48+
49+
@[simp] lemma range_restrict (f : α → β) (s : set α) : set.range (restrict f s) = f '' s :=
50+
range_comp.trans $ congr_arg (('') f) s.range_coe_subtype
51+
52+
/-- Restrict codomain of a function `f` to a set `s`. Same as `subtype.coind` but this version
53+
has codomain `↥s` instead of `subtype s`. -/
54+
def cod_restrict (f : α → β) (s : set β) (h : ∀ x, f x ∈ s) : α → s :=
55+
λ x, ⟨f x, h x⟩
56+
57+
@[simp] lemma coe_cod_restrict_apply (f : α → β) (s : set β) (h : ∀ x, f x ∈ s) (x : α) :
58+
(cod_restrict f s h x : β) = f x :=
59+
rfl
3460

3561
variables {s s₁ s₂ : set α} {t t₁ t₂ : set β} {p : set γ} {f f₁ f₂ f₃ : α → β} {g : β → γ}
3662
{f' f₁' f₂' : β → α} {g' : γ → β}

src/data/subtype.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ end subtype
3030
namespace subtype
3131
variables {α : Sort*} {β : Sort*} {γ : Sort*} {p : α → Prop}
3232

33-
lemma val_eq_coe (x : subtype p) : x.val = x := rfl
33+
lemma val_eq_coe : @val _ p = coe := rfl
3434

3535
protected lemma eq' : ∀ {a1 a2 : {x // p x}}, a1.val = a2.val → a1 = a2
3636
| ⟨x, h1⟩ ⟨.(x), h2⟩ rfl := rfl

src/linear_algebra/basis.lean

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ end
272272

273273
lemma linear_independent.restrict_of_comp_subtype {s : set ι}
274274
(hs : linear_independent R (v ∘ subtype.val : s → M)) :
275-
linear_independent R (function.restrict v s) :=
275+
linear_independent R (s.restrict v) :=
276276
begin
277277
have h_restrict : restrict v s = v ∘ (λ x, x.val) := rfl,
278278
rw [linear_independent_iff, h_restrict, finsupp.total_comp],
@@ -1134,7 +1134,7 @@ begin
11341134
rwa h₂ at h₁ },
11351135
rcases exists_subset_is_basis this with ⟨C, BC, hC⟩,
11361136
haveI : inhabited V := ⟨0⟩,
1137-
use hC.constr (function.restrict (inv_fun f) C : C → V),
1137+
use hC.constr (C.restrict (inv_fun f)),
11381138
apply @is_basis.ext _ _ _ _ _ _ _ _ _ _ _ _ hB,
11391139
intros b,
11401140
rw image_subset_iff at BC,
@@ -1153,7 +1153,7 @@ lemma exists_right_inverse_linear_map_of_surjective {f : V →ₗ[K] V'}
11531153
begin
11541154
rcases exists_is_basis K V' with ⟨C, hC⟩,
11551155
haveI : inhabited V := ⟨0⟩,
1156-
use hC.constr (function.restrict (inv_fun f) C : C → V),
1156+
use hC.constr (C.restrict (inv_fun f)),
11571157
apply @is_basis.ext _ _ _ _ _ _ _ _ _ _ _ _ hC,
11581158
intros c,
11591159
simp [constr_basis hC],

src/logic/function.lean

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -270,10 +270,6 @@ by funext ; refl
270270
lemma uncurry'_curry {α : Type*} {β : Type*} {γ : Type*} (f : α × β → γ) : uncurry' (curry f) = f :=
271271
by { funext, simp [curry, uncurry', prod.mk.eta] }
272272

273-
def restrict {α β} (f : α → β) (s : set α) : subtype s → β := λ x, f x.val
274-
275-
theorem restrict_eq {α β} (f : α → β) (s : set α) : function.restrict f s = f ∘ (@subtype.val _ s) := rfl
276-
277273
section bicomp
278274
variables {α : Type*} {β : Type*} {γ : Type*} {δ : Type*} {ε : Type*}
279275

src/measure_theory/integration.lean

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import
1313
measure_theory.measure_space
1414
measure_theory.borel_space
1515
noncomputable theory
16-
open set filter
16+
open set (hiding restrict restrict_apply) filter
1717
open_locale classical topological_space
1818

1919
namespace measure_theory
@@ -919,7 +919,7 @@ begin
919919
le_supr_of_le (s.restrict (- t)) $ le_supr_of_le _ _),
920920
{ assume a,
921921
by_cases a ∈ t;
922-
simp [h, simple_func.restrict_apply, ht.compl],
922+
simp [h, restrict_apply, ht.compl],
923923
exact le_trans (hfs a) (by_contradiction $ assume hnfg, h (hts hnfg)) },
924924
{ refine le_of_eq (s.integral_congr _ _),
925925
filter_upwards [this],

src/topology/constructions.lean

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ variables {α : Type u} {β : Type v} {γ : Type w} {δ : Type x}
4040
section constructions
4141

4242
instance {p : α → Prop} [t : topological_space α] : topological_space (subtype p) :=
43-
induced subtype.val t
43+
induced coe t
4444

4545
instance {r : α → α → Prop} [t : topological_space α] : topological_space (quot r) :=
4646
coinduced (quot.mk r) t
@@ -383,7 +383,7 @@ lemma is_open.is_open_map_subtype_val {s : set α} (hs : is_open s) :
383383
hs.open_embedding_subtype_val.is_open_map
384384

385385
lemma is_open_map.restrict {f : α → β} (hf : is_open_map f) {s : set α} (hs : is_open s) :
386-
is_open_map (function.restrict f s) :=
386+
is_open_map (s.restrict f) :=
387387
hf.comp hs.is_open_map_subtype_val
388388

389389
lemma is_closed.closed_embedding_subtype_val {s : set α} (hs : is_closed s) :

0 commit comments

Comments
 (0)