Functions defined piecewise on a finset #
This file defines Finset.piecewise
: Given two functions f
, g
, s.piecewise f g
is a function
which is equal to f
on s
and g
on the complement.
TODO #
Should we deduplicate this from Set.piecewise
?
@[simp]
theorem
Finset.piecewise_insert
{ι : Type u_1}
{π : ι → Sort u_2}
(s : Finset ι)
(f : (i : ι) → π i)
(g : (i : ι) → π i)
[(j : ι) → Decidable (j ∈ s)]
[DecidableEq ι]
(j : ι)
[(i : ι) → Decidable (i ∈ insert j s)]
:
(insert j s).piecewise f g = Function.update (s.piecewise f g) j (f j)
theorem
Finset.piecewise_singleton
{ι : Type u_1}
{π : ι → Sort u_2}
(f : (i : ι) → π i)
(g : (i : ι) → π i)
[DecidableEq ι]
(i : ι)
:
{i}.piecewise f g = Function.update g i (f i)
theorem
Finset.piecewise_piecewise_of_subset_left
{ι : Type u_1}
{π : ι → Sort u_2}
{s : Finset ι}
{t : Finset ι}
[(i : ι) → Decidable (i ∈ s)]
[(i : ι) → Decidable (i ∈ t)]
(h : s ⊆ t)
(f₁ : (a : ι) → π a)
(f₂ : (a : ι) → π a)
(g : (a : ι) → π a)
:
s.piecewise (t.piecewise f₁ f₂) g = s.piecewise f₁ g
theorem
Finset.piecewise_piecewise_of_subset_right
{ι : Type u_1}
{π : ι → Sort u_2}
{s : Finset ι}
{t : Finset ι}
[(i : ι) → Decidable (i ∈ s)]
[(i : ι) → Decidable (i ∈ t)]
(h : t ⊆ s)
(f : (a : ι) → π a)
(g₁ : (a : ι) → π a)
(g₂ : (a : ι) → π a)
:
s.piecewise f (t.piecewise g₁ g₂) = s.piecewise f g₂
theorem
Finset.update_eq_piecewise
{ι : Type u_1}
{β : Type u_3}
[DecidableEq ι]
(f : ι → β)
(i : ι)
(v : β)
:
Function.update f i v = {i}.piecewise (fun (x : ι) => v) f
theorem
Finset.update_piecewise
{ι : Type u_1}
{π : ι → Sort u_2}
(s : Finset ι)
(f : (i : ι) → π i)
(g : (i : ι) → π i)
[(j : ι) → Decidable (j ∈ s)]
[DecidableEq ι]
(i : ι)
(v : π i)
:
Function.update (s.piecewise f g) i v = s.piecewise (Function.update f i v) (Function.update g i v)
theorem
Finset.update_piecewise_of_mem
{ι : Type u_1}
{π : ι → Sort u_2}
(s : Finset ι)
(f : (i : ι) → π i)
(g : (i : ι) → π i)
[(j : ι) → Decidable (j ∈ s)]
[DecidableEq ι]
{i : ι}
(hi : i ∈ s)
(v : π i)
:
Function.update (s.piecewise f g) i v = s.piecewise (Function.update f i v) g
theorem
Finset.update_piecewise_of_not_mem
{ι : Type u_1}
{π : ι → Sort u_2}
(s : Finset ι)
(f : (i : ι) → π i)
(g : (i : ι) → π i)
[(j : ι) → Decidable (j ∈ s)]
[DecidableEq ι]
{i : ι}
(hi : i ∉ s)
(v : π i)
:
Function.update (s.piecewise f g) i v = s.piecewise f (Function.update g i v)
@[simp]
theorem
Finset.piecewise_erase_univ
{ι : Type u_1}
{π : ι → Sort u_2}
[Fintype ι]
[DecidableEq ι]
(i : ι)
(f : (i : ι) → π i)
(g : (i : ι) → π i)
:
(Finset.univ.erase i).piecewise f g = Function.update f i (g i)
theorem
Finset.piecewise_le_piecewise'
{ι : Type u_1}
(s : Finset ι)
[(j : ι) → Decidable (j ∈ s)]
{π : ι → Type u_3}
{f : (i : ι) → π i}
{g : (i : ι) → π i}
{f' : (i : ι) → π i}
{g' : (i : ι) → π i}
[(i : ι) → Preorder (π i)]
(hf : ∀ x ∈ s, f x ≤ f' x)
(hg : ∀ x ∉ s, g x ≤ g' x)
:
s.piecewise f g ≤ s.piecewise f' g'