Let $(X, d)$ be a metric space. In Sato - An alternative proof of Berg and Nikolaev’s characterization of CAT(0)-spaces via quadrilateral inequality it is stated that if $X$ is a geodesic space, then it is CAT(0) if and only if for every $\{ x_i \}_{i=0}^3 \subseteq X$ the following so-called "quadrilateral" inequality is satisfied: $$0 \leq d_{01}^2 + d_{13}^2 + d_{02}^2 + d_{23}^2 - d_{03}^2 - d_{12}^2,$$
where $d_{ij} = d(x_i, x_j)$. If $X$ is a subset of a Euclidean space, then the expression at the right hand side equals $\lVert x_0 - x_1 - x_2 + x_3 \rVert^2$, hence the inequality is true for all quadrilaterals with vertices $x_0, \dotsc, x_3$.
Now, suppose that we take a $2^d$-tuple $\{x_i\}_{i=0}^{2^d-1}$ of points from a Euclidean space and try to express $\lVert \sum_{i=0}^{2^d-1} (-1)^{\omega(i)} x_i \rVert^2$ in terms of distances between $x_i$s, where $\omega(i)$ is the number of $1$s in the binary expansion of $i$. Then we have: $$\lVert \sum_{i=0}^{2^d-1} (-1)^{\omega(i)} x_i \rVert^2 = \sum_{i,j=0}^{2^d-1} (-1)^{\omega(i)+\omega(j)+1} d_{ij}^2.$$ Note that the expression on the right hand side "makes sense" for any metric space.
Question
I wonder if expressions like the one in the right hand side of the last equation have been previously studied in a metric setting. If so, where can I find some books/articles that discuss this topic?