Headnote A: my apologies for the long winded exposition; I couldn't find a more compact way to convey what I'm looking for, why I'm looking for it, and what have I tried myself. Suggestions for whittling it down are welcome ☺
Headnote B: I am very unsure about my choice of tag (or of title, for that matter). Feel free to edit to a more suitable one.
Let $\mathbb{R}^+$ denote the free semigroup on $\mathbb{R}$ (namely finite, non-empty sequences of real numbers under concatenation), and consider the sum, product, and arithmetic mean as (set) functions from (the underlying set of) $\mathbb{R}^+$ to $\mathbb{R}$. The first two can be seen as homomorphisms into two different semigroups on $\mathbb{R}$ (addition and multiplication, respectively). The third one, however, can't—given the means of two sequences, we cannot combine them together to get the mean of their concatenation unless we know the length of each sequence as well.
On the other hand, it is known that it can be factored through an homomorphism into a suitable chosen semigroup. For example, in (1) they use the product of $\mathbb{R}$ with the positive integers (each under its respective addition), and the map $r\mapsto\left(\sum r, \left|r\right|\right)$. The mean is then recovered by dividing.
Of course, it is not the only such factorization. For example, we can take the identity on $\mathbb{R}^+$ as a homomorphism and we obtain a trivial factorization. Intuitively, however, the first one seems to be "better" in the sense that it saves less information about the original sequence. So a "best" solution would be one that saves the least possible amount of information that still allows us to extract the mean and preserve the semigroup structure.
So the point of the question is how to make precise the word "best" here. My first attempt was this universal property:
Call a pair $p,\mathsf{h}$ a valid factorization if $p\circ\mathsf{h}$ is the map $r\mapsto\bar{r}$ and $\mathsf{h}$ is a semigroup homomorphism. Call a valid factorization $\pi,\mathsf{a}$ universal if for every valid factorization $p,\mathsf{h}$ there is a unique semigroup homomorphism $\mathsf{u}$ such that $\mathsf{a}=\mathsf{u}\circ\mathsf{h}$ and $p=\pi\circ\mathsf{u}$.
Now we show the (valid) factorization from (1) is universal in this sense, call it a day and go have a beer, right? Well, no. We can make a counterexample by taking the same product semigroup and throwing in an additional absorbent element, call it $(\infty,\infty)$. If we map this element into any arbitrary real number (say $0$) and leave the rest of the factorization intact, we still obtain a valid factorization; but now there is no consistent way to define $\mathsf{u}$ to make everything commute.
However, we can make it work with a restriction:
Call a pair $p,\mathsf{h}$ a nice factorization if $p\circ\mathsf{h}$ is the map $r\mapsto\bar{r}$ and $\mathsf{h}$ is a surjective semigroup homomorphism. Call a nice factorization $\pi,\mathsf{a}$ universal if for every nice factorization $p,\mathsf{h}$ there is a unique semigroup homomorphism $\mathsf{u}$ such that $\mathsf{a}=\mathsf{u}\circ\mathsf{h}$ and $p=\pi\circ\mathsf{u}$.
The factorization from (1) is nice, and indeed universal. To see why, it suffices to see that in any valid factorization $p,\mathsf{h}$, if $x=\mathsf{h}r$ for some $r\in\mathbb{R}^+$, we can recover the length of $r$ from $x$ alone. The trick is to take the one-element sequence $\rho_x=(px+1)$ and observe that the element $x'=x\oplus\mathsf{h}\rho_x$ must be the image under $\mathsf{h}$ of the sequence $r\oplus\rho_x$, and therefore $px'=px+\tfrac{1}{w+1}$ (where $w$ is the length of $r$), whence $w$ can be extracted. Now, if $\mathsf{h}$ is surjective, we can do this process for every $x$ in its codomain, and from here it's easy to construct $\mathsf{u}$ and check that it is indeed a homomorphism. Uniqueness of $\mathsf{u}$ follows readily from $\mathsf{a}=\mathsf{u}\mathsf{h}$.
So why not call it a day now? Here's where I'm stuck: the restriction to "nice" factorizations feels rather artificial and ad-hoc. Stated otherwise, if I hadn't been trying to make the example work in the first place, I don't see a "natural" reason to restrict myself to surjective homomorphisms; what I am looking for is such a reason. Alternatively, I would accept a more natural requirement than surjectivity that still makes the example work, or which has its own universal solution.
Some observations:
The property stated above looked for a terminal factorization. The initial factorization is just the trivial one (taking $\mathsf{h}$ to be the identity).
The whole argument seems to work pretty much the same if we move from semigroups to monoids, adding identities where needed, and dealing with the empty sequence by allowing $p$ to be partial (or some equivalent trick). The whole exploration was actually triggered by trying to find a structure where the mean of an empty sequence can have a consistent value.
I don't know whether a "universal valid factorization" as defined above exists. At this point I'm inclined to think that it doesn't.