7
$\begingroup$

Or rephrased, is there a way to make a list of numbers whose sample variance is a square number? I'm interested in sequences of arbitrary length with integer elements.

(I come from a computer science background so my apologies if this question is a poor one).

$\endgroup$
6
  • 1
    $\begingroup$ I've run into this problem in trying to come up with exercises in statistics classes where the arithmetic will work out nicely. If you're interested in small lists of short integers, one way is to just pick random lists and compute their standard deviations. $\endgroup$ Commented Nov 6, 2020 at 18:29
  • $\begingroup$ I guess brute force is always an option :) $\endgroup$
    – George
    Commented Nov 6, 2020 at 18:41
  • 1
    $\begingroup$ I guess 0 is always an option. $\endgroup$
    – RaphaelB4
    Commented Nov 6, 2020 at 22:38
  • 2
    $\begingroup$ George, are you using the sample variance formula where you divide by $n$, or the one where you divide by $n-1$? $\endgroup$ Commented Nov 6, 2020 at 23:10
  • 1
    $\begingroup$ Sample variance corresponds with $n-1$ doesn't it? $\endgroup$
    – George
    Commented Nov 7, 2020 at 14:06

2 Answers 2

7
$\begingroup$

Essentially, this problem is to generate integers $n,s,a_1,\dots,a_n$ such that $n\ge1$ and $$(n-1)s^2=a_1^2+\dots+a_n^2.\tag{1}$$ To do this, let $k:=\lfloor n/4\rfloor$ and take any nonnegative integers $t_1,\dots,t_k$ such that
$$(n-1)s^2=t_1+\dots+t_k.\tag{2}$$ For each $j\in[k]:=\{1,\dots,k\}$, by Lagrange's four-square theorem, there exist integers $a_{j1},\dots,a_{j4}$ such that $$t_j=\sum_{i=1}^4 a_{ji}^2,$$ so that $$(n-1)s^2=\sum_{j=1}^k\sum_{i=1}^4 a_{ji}^2.\tag{3}$$ The latter expression is the sum of $4k\le n$ squares of nonnegative integers. Complementing this sum by the sum of $n-4k$ squares of $0$, we get representation (1) -- for any given natural $n$ and integer $s$.


This is illustrated by the the following image of a Mathematica notebook, finding a representation (1) for $n=15$ and $s=5$; $$(15-1)5^2=4^2 + 0^2 + 8^2 + 6^2 + 10^2 + 0^2 + 4^2 + 2^2 + 5^2 + 0^2 + 8^2 + 5^2 + 0^2 + 0^2 + 0^2.$$

enter image description here


Of course, the $a_i$'s in (1) are the deviations of the sample values from the sample mean. Previously, I forgot to take into account that the sum of the $a_i$'s must of course be $0$.

$\newcommand\ep\epsilon$One way to get that is to try to attach "signs" $\ep_i\in\{-1,1\}$ to the $a_i$'s so that $\sum_{i=1}^m\ep_i a_i=0$. I think usually this will be possible to do when $\sum_{i=1}^m a_i$ is even, as is the case with the above example (continued below). Otherwise, repeat with other $t_1,\dots,t_k$ in (2) and/or with other instances of the $a_{j1},\dots,a_{j4}$'s.

enter image description here

The problem of the existence of "balancing" signs $\ep_i\in\{-1,1\}$ is obviously equivalent to the so-called partition problem, which is easily solved for not too big values $n$ and $\sum_{i=1}^m a_i$ in view of the simple recurrence relation, whose application to the particular $a_i$'s considered in the mentioned Mathematica notebook is illustrated here:

enter image description here

This again confirms that for our particular $a_i$'s "balancing" signs $\ep_i\in\{-1,1\}$ exist.

The problem of actually finding an appropriate partition (which is equivalent to finding "balancing" signs $\ep_i\in\{-1,1\}$) was solved by Korf.

For our particular $a_i$'s there actually are $18$ different "balancing" sign assignments $(\ep_i)$, not counting sign assignments to the $0$'s.


Another way to make the sum of the deviations $0$ is as follows. If $(n-1)s^2$ is even, find integers $b_1,\dots,b_{4l}$ such that $$(n-1)s^2/2=b_1^2+\dots+b_{4l}^2$$ (cf. (3)), where $l:=\lfloor n/8\rfloor$. Then, letting $$(a_1,\dots,a_n):=(b_1,\dots,b_{4l},-b_1,\dots,-b_{4l},0,\dots,0),$$ we have both (1) and the balance condition $\sum_{i\in[n]}a_i=0$ satisfied. Of course, one can also replace $(a_1,\dots,a_n)$ by any permutation of this $n$-tuple.

$\endgroup$
3
  • 1
    $\begingroup$ Modulo arithmetical errors, the sequence $4,0,8,6,10,0,4,2,5,0,8,5,0,0,0$ has $n=15$, $A=\Sigma x_i=52$, $B=\Sigma x_i^2=350$ and sample variance $(1/14)(B-(1/15)A^2)=1003/105$ (or, using a different formula, $(1/15)(B-(1/15)A^2)=2546/225$), not an integer. $\endgroup$ Commented Nov 6, 2020 at 23:09
  • 1
    $\begingroup$ @GerryMyerson : At the end of the second line in your comment, should the numerator of the fraction be 1273 rather than 1003 ? Anyway, it's still not an integer. $\endgroup$ Commented Nov 7, 2020 at 8:51
  • $\begingroup$ @GerryMyerson : Thank you for your comment. I have now tried to address it. $\endgroup$ Commented Nov 8, 2020 at 1:00
2
$\begingroup$

Alternatively, given rational numbers $u_1,\dotsc,u_n$ you can define $v=\sum_iu_i^2$ and $w_i=2u_i/(1+v)$ for $i\leq n$ and $w_{n+1}=(1-v)/(1+v)$. Then the numbers $w_j$ are rational with $\sum_jw_j^2=1$. By clearing denominators you get an equation $\sum_{j=1}^{n+1}a_j^2=b^2$ in integers.

$\endgroup$
3
  • 4
    $\begingroup$ But you want that last sum to come to $nb^2$, not $b^2$, no? $\endgroup$ Commented Nov 6, 2020 at 22:36
  • $\begingroup$ @Gerry Myerson. Or $(n-1)b^2$ I thought was agreed on... $\endgroup$ Commented Nov 8, 2020 at 16:01
  • $\begingroup$ @Yaakov I'm happy either way. It seems OP had $n-1$ in mind. $\endgroup$ Commented Nov 8, 2020 at 21:52

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .