Math courses have different notions for representing similarity.
Consider the most basic structure in mathematics: a set. We can use a set to represent whether two objects ($\mathcal{A}$ and $\mathcal{B}$) are similar. We can think that if the two objects are in the same set then they are similar, and if they’re not in the same set (as in the figure below), than they’re not similar. For example, let’s say we’re comparing two houses. The set contains all houses in a specific neighborhood. Then we can say that $\mathcal{B}$ is similar to $\mathcal{A}$ if it’s in the same neighborhood and not similar if it’s in a different neighborhood.
With a single set, though, we are limited to a binary decision about whether $\mathcal{A}$ and $\mathcal{B}$ are similar. Borrowing an example from, The Joy of Abstraction, consider how we could use sets to represent how similar addition is to multiplication. These are binary operations where the order of the arguments, or the parentheses do not matter (Commutativity and Associativity respectively)
But they differ with respect to having an inverse element. For any number $x$, there exists a number $-x$ such that $x + (-x) = 0$, where $0$ is the identity element. However, there is no number $y$ such that $0 \times y = 1$, where $1$ is the identity element.
$$ f(x) = \sum a_i 1_{x \in A_i} $$