We consider the number of ways to write an integer as a sum of squares, a problem with a long history going back at least to Fermat. The previous studies in this area generally fix the number of squares which may occur and then either use algebraic techniques or connect these to coefficients of certain complex analytic functions with many symmetries known as modular forms, from which one may use techniques in complex and real analysis to study these numbers. In this paper, we consider sums with arbitrarily many squares, but give a certain natural weighting to each representation. Although there are a very large number of such representations of each integer, we see that the weighting induces massive cancellation, and we furthermore prove that these weighted sums are again coefficients of modular forms, giving precise formulas for them in terms of sums of divisors of the integer being represented.
Keywords: Jacobi triple product identity; modular forms; polygonal numbers; representations of integers; weighted representations.