# When is taking an average (mean) an algebraic operation in the sense of monads?

Taking the average of a sequence of numbers is not an "algebraic" operation, in the following sense. Given sequences $X_1,X_2,\ldots,X_n$ of numbers, one could either take the average of each one, and then average the $n$ results, OR take the concatenation of these sequences and then average that big sequence. The two results are different. (Our term "algebraic" here is invoking the definition of monad algebras.) The child cannot correctly calculate the average salary of people in the world by averaging the average salaries of people in each country.

In order to fix this defect, one could consider sequences of "weighted values." For example, if $(A,+)$ is a commutative monoid and the ring R of real numbers is an $A$-algebra, let us consider the set of "$A$-weighted real numbers", an element of which is denoted $a\cdot b$, where $a\in A$ is called the weight and $b\in$ R is called the value. Define the average of a sequence by the formula $$(a_1\cdot r_1,a_2\cdot r_2,\ldots,a_n\cdot r_n)\leadsto (\sum_{i=1}^na_i)\cdot\frac{\sum_{j=1}^n(a_jr_j)}{\sum_{i=1}^na_i}$$ The weight of this average is the sum of the weights, and the value of this average is the usual mean". Now, given a sequence of sequences such as $$((1\cdot 4,2\cdot 7),(2\cdot 8))$$ I can compute the average of each interior sequence, giving $(3\cdot 6,2\cdot 8)$ and then compute the average of this, giving $5\cdot 6.8$ or I can simply compute the average of the concatenation $(1\cdot4,2\cdot7,2\cdot8)$, again giving $5\cdot 6.8$. We proclaim "the average is 6.8 with a weight of 5!"

But their are other ways to fix this defect. One could consider distributions on *R*$^n$ with finite total integral, rather than merely weighted numbers. Taking only $A$-multiples of "Dirac delta" distributions returns the above notion of "weighted values". There is an algebraic way to average sequences of such distributions, namely by adding the elements of the sequence. We think of the weight of such a distribution $D$ as its integral $\int D$ and of the value as the probability distribution $\frac{D}{\int D}$.

My question is: what are averages, category-theoretically? The following is perhaps a silly way to consider this problem, but I want to get across the spirit of the kind of answer I want. Let $Sym\colon Cat\to Cat$ denote the monad that sends each category $C$ to the free symmetric monoidal category on $C$. Then when would we call a $Sym$-algebra "averaging"? When $C$ is the set (discrete category) of $A$-weighted real numbers, then $Sym(C)$ is the set of (unordered) sequences of $A$-weighted real numbers and we have shown that the above "average" operation is algebraic, and I'd call it "averaging". I would say that there is no "averaging" algebraic structure $Sym($ Z $)\to$ Z on the set of integers.

Throughout science there is a need to aggregate large amounts of data using averages, but the results of this process are not "continuable". Once numbers are averaged, we lose the ability to work with the results correctly. Thus I believe this problem is important. The center of mass for a collection of objects should not just be a point, it should be a point with mass. My question is: how can we define this problem correctly, in the aesthetic of category theory?

-