# Are two sequences equal if the sums and sums of squares are equal?

Are two sequences $(x_i)_{i=1,\ldots,n}$ and $(y_i)_{i=1,\ldots,n}$ equal if $\sum_{i=1}^nx_i=\sum_{i=1}^ny_i$ and $\sum_{i=1}^nx_i^2=\sum_{i=1}^ny_i^2$?

## migrated from stats.stackexchange.comOct 25 '16 at 23:38

This question came from our site for people interested in statistics, machine learning, data analysis, data mining, and data visualization.

• Consider two random variables $X$ and $Y$ that take on values $x_1, x_2, \ldots, x_n$ and $y_1, y_2, \ldots, y_n$ respectively with equal probabilities $1/n$. Then, your question effectively asks whether $E[X]=E[Y]$ and var$(X) =$ var$(Y)$ suffices to guarantee that the two random variables have the same distribution. Ponder whether such a result is plausible... – Dilip Sarwate Oct 25 '16 at 21:23
• It's a simple matter to construct data sets (i.e. multisets) for which the first $k$ moments are the same but which data sets are not identical, for any $k$ (though admittedly it gets tedious for large $k$; I have constructed cases up to the ninth moment before, for example, and if I had reason to, could progress further). A number of questions on site deal with the related problem of whether all moments - an infinite sequence - are sufficient to characterize a distribution. The answer turns out to be "not in general" ... ctd – Glen_b Oct 25 '16 at 22:05
• ctd ... and specific counterexamples are known (and some are described on site). The basic test is "does the MGF exist in a neighborhood of 0?" -- if it does then the moment sequence identifies the distribution, but if it doesn't then you may have more than one distribution with the same moment sequence. – Glen_b Oct 25 '16 at 22:05
• Is this on-topic though? – Firebug Oct 25 '16 at 22:22
• I'm a bit puzzled why this has so many upvotes? – Matthew Gunn Oct 25 '16 at 22:27

No.

$$x = (1,1,1,-3)$$ $$y = (-1,-1,-1,3)$$

$$\sum x_i = \sum y_i = 0$$ $$\sum x_i^2 = \sum y_i^2 =12$$

• Both are multisets, not sets. – Rodrigo de Azevedo Oct 25 '16 at 15:14
• @RodrigodeAzevedo: the OP's notation suggested to me that he is interested in vectors or sequences, not sets as such. – Stephan Kolassa Oct 25 '16 at 15:15
• Here is the counterexample for sets: $X=\{1,2,3,-4\}$ and $Y=\{-1,2,-3,4\}$. – Stephan Kolassa Oct 25 '16 at 15:17
• @StephanKolassas Yes, you are right. Sorry for the clunky notation. Im changing it to sequences. – Syltherien Oct 25 '16 at 15:21
• @StephanKolassa: a set example closer to you original might be $\{1,2,-3\}$ and $\{-1,-2,3\}$ – Henry Oct 25 '16 at 17:31

No! You need $n$ polynomial equations.

If I remember correctly, given a set of $n$ distinct real numbers $\mathcal Y :=\{y_1, y_2, \dots, y_n\}$, the following system of $n$ polynomial equations

$$\begin{array}{rl} x_1 + x_2 + \dots + x_n &= c_1\\ x_1^2 + x_2^2 + \dots + x_n^2 &= c_2\\ \vdots \\ x_1^n + x_2^n + \dots + x_n^n &= c_n\end{array}$$

where

$$c_k := y_1^k + y_2^k + \dots + y_n^k$$

has $n!$ solutions, namely, all $n!$ permutations of the $n$ distinct elements of $\mathcal Y$. One can use algebraic geometry to prove this. I vaguely recall this being related to moment problems.

Example

Let $\mathcal Y := \{1,3,6\}$. Intersecting the plane with the sphere,

$$\begin{array}{rl} x_1 + x_2 + x_3 &= 10\\ x_1^2 + x_2^2 + x_3^2 &= 46\end{array}$$

we obtain a circle on the plane, as depicted below

However, intersecting these two with the cubic surface,

$$\begin{array}{rl} x_1 + x_2 + x_3 &= 10\\ x_1^2 + x_2^2 + x_3^2 &= 46\\ x_1^3 + x_2^3 + x_3^3 &= 244\end{array}$$

we obtain the $3!=6$ permutations of the elements of $\mathcal Y$, which are colored in red

If we plot the quadratic and the cubic surfaces, but not the plane,

and, from another point of view, we have what looks like a stylish hat

To consider an even more basic counterexample. What happens if you simply reorder your sequence? Take $x = (0,1)$ and $y = (1,0)$. (I assume you're talking about sequences, so above $x \neq y$; of course, as sets, $\{0,1\} = \{1,0\}$.)

There are many examples. Here's the first in a long sequence: $$(1,4,6,7) \quad (2,3,5,8).$$ This comes from the first eight entries in the Thue Morse sequence (third line below). The fourth line specifies two sets of eight numbers with the same sum, sum of squares and sum of cubes.

AB
AB BA
ABBA BAAB
ABBABAAB BAABABBA
...


The Prouhet-Tarry-Escott problem and generalized Thue-Morse sequences. J. Comb. 7 (2016), no. 1, 117--133, [Bolker, Ethan D. and Offner, Carl and Richman, Robert and Zara, Catalin]

Here's the preprint: https://arxiv.org/abs/1304.6756

Something interesting. On all $3 \times 3$ magic squares, the sums of the top and bottom rows is the same (of course) but, also, the sums of the squares of the top and bottom rows is the same. For example

\begin{array}{|c|c|c|} \hline 8 & 3 & 4 \\ \hline 1 & 5 & 9 \\ \hline 6 & 7 & 2 \\ \hline \end{array}

$8 + 3 + 4 = 6 + 7 + 2 = 15$

$8^2 + 3^2 + 4^2 = 6^2 + 7^2 + 2^2 = 89$

Also

$8 + 1 + 6 = 4 + 9 + 2 = 15$

$8^2 + 1^2 + 6^2 = 4^2 + 9^2 + 2^2 = 101$

This seems to work for some families of larger order magic squares, but I haven't been able to prove it.

• Is this still a magic square if I swap row 2 and 3? If so, then your statement the sums of the squares of the top and bottom rows is the same does not hold. $1^2+5^2+9^2 = 107 \neq 89$ – Therkel Oct 26 '16 at 8:39
• @Therkel. No it's not. the diagonals have to also sum to 15 (or whatever). – steven gregory Oct 26 '16 at 8:41
• Using this answer I wrote last May, you can easily prove it for $3 \times 3$ magic squares. I am tempted to post a question on this. Do I have your permission? – Rodrigo de Azevedo Oct 26 '16 at 9:30
• The sum of the Hadamard product of the 1st and 2nd rows $$8 + 3 \cdot 5 + 4 \cdot 9 = 59$$ is also equal to the sum of the Hadamard product of the 2nd and 3rd rows $$6 + 5 \cdot 7 + 9 \cdot 2 = 59$$ – Rodrigo de Azevedo Oct 26 '16 at 9:43
• The sums of the squares of the 1st and 3rd columns are also equal. – Rodrigo de Azevedo Oct 26 '16 at 9:55