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?
def
Finset.piecewise
{ι : Type u_1}
{Ļ : ι ā Sort u_2}
(s : Finset ι)
(f g : (i : ι) ā Ļ i)
[(j : ι) ā Decidable (j ā s)]
(i : ι)
:
Ļ i
s.piecewise f g is the function equal to f on the finset s, and to g on its
complement.
Instances For
theorem
Finset.piecewise_insert_self
{ι : Type u_1}
{Ļ : ι ā Sort u_2}
(s : Finset ι)
(f g : (i : ι) ā Ļ i)
[DecidableEq ι]
{j : ι}
[(i : ι) ā Decidable (i ā insert j s)]
:
(insert j s).piecewise f g j = f j
@[simp]
theorem
Finset.piecewise_empty
{ι : Type u_1}
{Ļ : ι ā Sort u_2}
(f g : (i : ι) ā Ļ i)
[(i : ι) ā Decidable (i ā ā
)]
:
ā
.piecewise f g = g
@[simp]
theorem
Finset.piecewise_eq_of_mem
{ι : Type u_1}
{Ļ : ι ā Sort u_2}
(s : Finset ι)
(f g : (i : ι) ā Ļ i)
[(j : ι) ā Decidable (j ā s)]
{i : ι}
(hi : i ā s)
:
s.piecewise f g i = f i
@[simp]
theorem
Finset.piecewise_eq_of_notMem
{ι : Type u_1}
{Ļ : ι ā Sort u_2}
(s : Finset ι)
(f g : (i : ι) ā Ļ i)
[(j : ι) ā Decidable (j ā s)]
{i : ι}
(hi : i ā s)
:
s.piecewise f g i = g i
@[simp]
theorem
Finset.piecewise_insert
{ι : Type u_1}
{Ļ : ι ā Sort u_2}
(s : Finset ι)
(f 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 g : (i : ι) ā Ļ i)
[DecidableEq ι]
(i : ι)
:
{i}.piecewise f g = Function.update g i (f i)
@[simp]
@[simp]
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 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 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_notMem
{ι : Type u_1}
{Ļ : ι ā Sort u_2}
(s : Finset ι)
(f 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)
theorem
Finset.piecewise_same
{ι : Type u_1}
{Ļ : ι ā Sort u_2}
(s : Finset ι)
(f : (i : ι) ā Ļ i)
[(j : ι) ā Decidable (j ā s)]
:
s.piecewise f f = f
@[simp]
@[simp]
theorem
Finset.piecewise_erase_univ
{ι : Type u_1}
{Ļ : ι ā Sort u_2}
[Fintype ι]
[DecidableEq ι]
(i : ι)
(f g : (i : ι) ā Ļ i)
:
(univ.erase i).piecewise f g = Function.update f i (g i)