Indicator function
indicator (s : set α) (f : α → β) (a : α) is f a if a ∈ s and is 0 otherwise.
Implementation note
In mathematics, an indicator function or a characteristic function is a function used to indicate
membership of an element in a set s, having the value 1 for all elements of s and the value 0
otherwise. But since it is usually used to restrict a function to a certain set s, we let the
indicator function take the value f x for some function f, instead of 1. If the usual indicator
function is needed, just set f to be the constant function λx, 1.
Tags
indicator, characteristic
Consider a sum of g i (f i) over a finset. Suppose g is a
function such as multiplication, which maps a second argument of 0 to
- (A typical use case would be a weighted sum of
f i * h iorf i • h i, wherefgives the weights that are multiplied by some other functionh.) Then iffis replaced by the corresponding indicator function, thefinsetmay be replaced by a possibly largerfinsetwithout changing the value of the sum.
Summing an indicator function over a possibly larger finset is
the same as summing the original function over the original
finset.