@@ -21,12 +21,14 @@ But since it is usually used to restrict a function to a certain set `s`,
21
21
we let the indicator function take the value `f x` for some function `f`, instead of `1`.
22
22
If the usual indicator function is needed, just set `f` to be the constant function `λx, 1`.
23
23
24
+ The indicator function is implemented non-computably, to avoid having to pass around `decidable`
25
+ arguments. This is in contrast with the design of `pi.single` or `set.piecewise`.
26
+
24
27
## Tags
25
28
indicator, characteristic
26
29
-/
27
30
28
- noncomputable theory
29
- open_locale classical big_operators
31
+ open_locale big_operators
30
32
open function
31
33
32
34
variables {α β ι M N : Type *}
@@ -37,30 +39,40 @@ section has_one
37
39
variables [has_one M] [has_one N] {s t : set α} {f g : α → M} {a : α}
38
40
39
41
/-- `indicator s f a` is `f a` if `a ∈ s`, `0` otherwise. -/
40
- def indicator {M} [has_zero M] (s : set α) (f : α → M) : α → M := λ x, if x ∈ s then f x else 0
42
+ noncomputable def indicator {M} [has_zero M] (s : set α) (f : α → M) : α → M
43
+ | x := by haveI := classical.dec_pred (∈ s); exact if x ∈ s then f x else 0
41
44
42
45
/-- `mul_indicator s f a` is `f a` if `a ∈ s`, `1` otherwise. -/
43
46
@[to_additive]
44
- def mul_indicator (s : set α) (f : α → M) : α → M := λ x, if x ∈ s then f x else 1
47
+ noncomputable def mul_indicator (s : set α) (f : α → M) : α → M
48
+ | x := by haveI := classical.dec_pred (∈ s); exact if x ∈ s then f x else 1
45
49
46
- @[simp, to_additive] lemma piecewise_eq_mul_indicator : s.piecewise f 1 = s.mul_indicator f := rfl
50
+ @[simp, to_additive] lemma piecewise_eq_mul_indicator [decidable_pred (∈ s)] :
51
+ s.piecewise f 1 = s.mul_indicator f :=
52
+ funext $ λ x, @if_congr _ _ _ _ (id _) _ _ _ _ iff.rfl rfl rfl
47
53
48
- @[to_additive] lemma mul_indicator_apply (s : set α) (f : α → M) (a : α) :
49
- mul_indicator s f a = if a ∈ s then f a else 1 := rfl
54
+ @[to_additive] lemma mul_indicator_apply (s : set α) (f : α → M) (a : α) [decidable (a ∈ s)] :
55
+ mul_indicator s f a = if a ∈ s then f a else 1 := by convert rfl
50
56
51
57
@[simp, to_additive] lemma mul_indicator_of_mem (h : a ∈ s) (f : α → M) :
52
- mul_indicator s f a = f a := if_pos h
58
+ mul_indicator s f a = f a :=
59
+ by { letI := classical.dec (a ∈ s), exact if_pos h }
53
60
54
61
@[simp, to_additive] lemma mul_indicator_of_not_mem (h : a ∉ s) (f : α → M) :
55
- mul_indicator s f a = 1 := if_neg h
62
+ mul_indicator s f a = 1 :=
63
+ by { letI := classical.dec (a ∈ s), exact if_neg h }
56
64
57
65
@[to_additive] lemma mul_indicator_eq_one_or_self (s : set α) (f : α → M) (a : α) :
58
66
mul_indicator s f a = 1 ∨ mul_indicator s f a = f a :=
59
- if h : a ∈ s then or.inr (mul_indicator_of_mem h f) else or.inl (mul_indicator_of_not_mem h f)
67
+ begin
68
+ by_cases h : a ∈ s,
69
+ { exact or.inr (mul_indicator_of_mem h f) },
70
+ { exact or.inl (mul_indicator_of_not_mem h f) }
71
+ end
60
72
61
73
@[simp, to_additive] lemma mul_indicator_apply_eq_self :
62
74
s.mul_indicator f a = f a ↔ (a ∉ s → f a = 1 ) :=
63
- ite_eq_left_iff.trans $ by rw [@eq_comm _ (f a)]
75
+ by letI := classical.dec (a ∈ s); exact ite_eq_left_iff.trans ( by rw [@eq_comm _ (f a)])
64
76
65
77
@[simp, to_additive] lemma mul_indicator_eq_self : s.mul_indicator f = f ↔ mul_support f ⊆ s :=
66
78
by simp only [funext_iff, subset_def, mem_mul_support, mul_indicator_apply_eq_self, not_imp_comm]
@@ -71,7 +83,7 @@ by { rw mul_indicator_eq_self at h1 ⊢, exact subset.trans h1 h2 }
71
83
72
84
@[simp, to_additive] lemma mul_indicator_apply_eq_one :
73
85
mul_indicator s f a = 1 ↔ (a ∈ s → f a = 1 ) :=
74
- ite_eq_right_iff
86
+ by letI := classical.dec (a ∈ s); exact ite_eq_right_iff
75
87
76
88
@[simp, to_additive] lemma mul_indicator_eq_one :
77
89
mul_indicator s f = (λ x, 1 ) ↔ disjoint (mul_support f) s :=
@@ -108,7 +120,7 @@ mul_indicator_eq_self.2 subset.rfl
108
120
109
121
@[simp, to_additive] lemma mul_indicator_range_comp {ι : Sort *} (f : ι → α) (g : α → M) :
110
122
mul_indicator (range f) g ∘ f = g ∘ f :=
111
- piecewise_range_comp _ _ _
123
+ by letI := classical.dec_pred (∈ range f); exact piecewise_range_comp _ _ _
112
124
113
125
@[to_additive] lemma mul_indicator_congr (h : eq_on f g s) :
114
126
mul_indicator s f = mul_indicator s g :=
@@ -142,9 +154,10 @@ funext $ λx, by { simp only [mul_indicator], split_ifs, repeat {simp * at * {co
142
154
mul_indicator (s ∩ mul_support f) f = mul_indicator s f :=
143
155
by rw [← mul_indicator_mul_indicator, mul_indicator_mul_support]
144
156
145
- @[to_additive] lemma comp_mul_indicator (h : M → β) (f : α → M) {s : set α} {x : α} :
157
+ @[to_additive] lemma comp_mul_indicator (h : M → β) (f : α → M) {s : set α} {x : α}
158
+ [decidable_pred (∈ s)] :
146
159
h (s.mul_indicator f x) = s.piecewise (h ∘ f) (const α (h 1 )) x :=
147
- s .apply_piecewise _ _ (λ _, h)
160
+ by letI := classical.dec_pred (∈ s); convert s .apply_piecewise f (const α 1 ) (λ _, h)
148
161
149
162
@[to_additive] lemma mul_indicator_comp_right {s : set α} (f : β → α) {g : α → M} {x : β} :
150
163
mul_indicator (f ⁻¹' s) (g ∘ f) x = mul_indicator s g (f x) :=
168
181
169
182
@[to_additive] lemma mul_indicator_preimage (s : set α) (f : α → M) (B : set M) :
170
183
(mul_indicator s f)⁻¹' B = s.ite (f ⁻¹' B) (1 ⁻¹' B) :=
171
- piecewise_preimage s f 1 B
184
+ by letI := classical.dec_pred (∈ s); exact piecewise_preimage s f 1 B
172
185
173
186
@[to_additive] lemma mul_indicator_preimage_of_not_mem (s : set α) (f : α → M)
174
187
{t : set M} (ht : (1 :M) ∉ t) :
264
277
265
278
/-- `set.mul_indicator` as a `monoid_hom`. -/
266
279
@[to_additive " `set.indicator` as an `add_monoid_hom`." ]
267
- def mul_indicator_hom {α} (M) [mul_one_class M] (s : set α) : (α → M) →* (α → M) :=
280
+ noncomputable def mul_indicator_hom {α} (M) [mul_one_class M] (s : set α) : (α → M) →* (α → M) :=
268
281
{ to_fun := mul_indicator s,
269
282
map_one' := mul_indicator_one M s,
270
283
map_mul' := mul_indicator_mul s }
@@ -374,7 +387,7 @@ lemma prod_mul_indicator_subset (f : α → M) {s t : finset α} (h : s ⊆ t) :
374
387
prod_mul_indicator_subset_of_eq_one _ (λ a b, b) h (λ _, rfl)
375
388
376
389
@[to_additive] lemma _root_.finset.prod_mul_indicator_eq_prod_filter
377
- (s : finset ι) (f : ι → α → M) (t : ι → set α) (g : ι → α) :
390
+ (s : finset ι) (f : ι → α → M) (t : ι → set α) (g : ι → α) [decidable_pred (λ i, g i ∈ t i)] :
378
391
∏ i in s, mul_indicator (t i) (f i) (g i) = ∏ i in s.filter (λ i, g i ∈ t i), f i (g i) :=
379
392
begin
380
393
refine (finset.prod_filter_mul_prod_filter_not s (λ i, g i ∈ t i) _).symm.trans _,
392
405
(s : ι → set α) {f : α → M} : (∀ (i ∈ I) (j ∈ I), i ≠ j → disjoint (s i) (s j)) →
393
406
mul_indicator (⋃ i ∈ I, s i) f = λ a, ∏ i in I, mul_indicator (s i) f a :=
394
407
begin
408
+ classical,
395
409
refine finset.induction_on I _ _,
396
410
{ intro h, funext, simp },
397
411
assume a I haI ih hI,
@@ -439,7 +453,11 @@ funext (λ _, by simpa only [← inter_indicator_mul, pi.mul_apply, pi.one_apply
439
453
440
454
lemma indicator_prod_one {s : set α} {t : set β} {x : α} {y : β} :
441
455
(s ×ˢ t : set _).indicator (1 : _ → M) (x, y) = s.indicator 1 x * t.indicator 1 y :=
442
- by simp [indicator, ← ite_and]
456
+ begin
457
+ letI := classical.dec_pred (∈ s),
458
+ letI := classical.dec_pred (∈ t),
459
+ simp [indicator_apply, ← ite_and],
460
+ end
443
461
444
462
end mul_zero_one_class
445
463
@@ -452,7 +470,11 @@ variables [has_le M]
452
470
453
471
@[to_additive] lemma mul_indicator_apply_le' (hfg : a ∈ s → f a ≤ y) (hg : a ∉ s → 1 ≤ y) :
454
472
mul_indicator s f a ≤ y :=
455
- if ha : a ∈ s then by simpa [ha] using hfg ha else by simpa [ha] using hg ha
473
+ begin
474
+ by_cases ha : a ∈ s,
475
+ { simpa [ha] using hfg ha },
476
+ { simpa [ha] using hg ha },
477
+ end
456
478
457
479
@[to_additive] lemma mul_indicator_le' (hfg : ∀ a ∈ s, f a ≤ g a) (hg : ∀ a ∉ s, 1 ≤ g a) :
458
480
mul_indicator s f ≤ g :=
@@ -540,6 +562,7 @@ lemma indicator_le_indicator_nonneg {β} [linear_order β] [has_zero β] (s : se
540
562
s.indicator f ≤ {x | 0 ≤ f x}.indicator f :=
541
563
begin
542
564
intro x,
565
+ classical,
543
566
simp_rw indicator_apply,
544
567
split_ifs,
545
568
{ exact le_rfl, },
0 commit comments