---
title: "Introduction to set theory"
description: "Use predicate indicator functions to filter sums, count matching cases, and translate logical conditions into piecewise numeric rules."
canonical_url: "https://fanout.sh/ml-math/lessons/sets-indicator-functions-for-predicates-t-1289tky"
md_url: "https://fanout.sh/ml-math/lessons/sets-indicator-functions-for-predicates-t-1289tky.md"
last_updated: "2026-12-01"
access: "public"
---

# Introduction to set theory

Use predicate indicator functions to filter sums, count matching cases, and translate logical conditions into piecewise numeric rules.

Learn to describe which values belong to a set, then use that description to count and select. Try the questions as you go.

## Indicator functions

So far a membership test answers yes or no. To count how many values pass a test, it helps to write yes as 1 and no as 0. A function is a rule that assigns one output to each allowed input. An indicator function applies this rule to membership.

Take real numbers as the allowed inputs and keep $S=\{-2,-1,0,1,2\}$. Its indicator is written $\mathbf1_S(x)$, read “the indicator of S at x”. The subscript names the set being tested.

$$\mathbf1_S(x)=\begin{cases}1&x\in S,\\0&x\notin S.\end{cases}$$

Use the first row for a member and the second row for any other allowed input.

In particular, $\mathbf1_S(0)=1$ because zero belongs to S, while $\mathbf1_S(1/2)=0$ because the fraction does not. Zero as an input and zero as an output mean different things. You can also recover a set from an indicator table: collect the inputs whose output is 1.

## Counting with indicators

Sometimes the question is simply whether a value is positive, without naming a set first. Write $\mathbf1[x>0]$: it is 1 when the statement inside the brackets is true and 0 when it is false. This is indicator bracket notation, also called Iverson notation. A set indicator is one instance: $\mathbf1_S(x)=\mathbf1[x\in S]$.

Choose four example measurements, $x_1=-2$, $x_2=0$, $x_3=2$ and $x_4=5$. The subscript labels the measurement's position. We want both the number of positive measurements and their total.

| Value $x_i$ | Positive? $\mathbf1[x_i>0]$ | Contribution $\mathbf1[x_i>0]x_i$ |
| --- | --- | --- |
| $-2$ | 0 | $0\cdot(-2)=0$ |
| 0 | 0 | $0\cdot0=0$ |
| 2 | 1 | $1\cdot2=2$ |
| 5 | 1 | $1\cdot5=5$ |

Add the indicator column to count: $0+0+1+1=2$. Add the contribution column for the total: $0+0+2+5=7$. Multiplying by the original value makes the difference. An indicator alone returns a number from $\{0,1\}$, never the selected measurement.

$$\sum_{i=1}^{4}\mathbf1[x_i>0]=2\qquad\sum_{i=1}^{4}\mathbf1[x_i>0]x_i=7$$

The large sigma means “add the terms”, here for positions i = 1 through 4.

We started with “does this object belong?” and arrived at a way to compute with the answer. In machine learning, a condition such as “predicted label equals recorded label” can similarly contribute 1 for a correct prediction and 0 otherwise. Before learning any larger formula built from indicators, read its condition and test one input by hand.

---
This representation contains public Fanout content only. Protected Pro lessons, account data, billing, checkout, and pricing are not included.

Browse the public content map: https://fanout.sh/sitemap.md
