From: janos on
To be on the safe side:
ClearAll[d, n, x, a, SumOfSquaresRepresentations];

Take this from the help:
SumOfSquaresRepresentations[d_, n_] :=
Module[{x,
a}, (a = Array[x, d]) /. {ToRules[Reduce[a.a == n, a, Integers]]}]

Let's apply it:
SumOfSquaresRepresentations[3, 15]
{x$110[1], x$110[2], x$110[3]}

And this is the only case that you get this funny result
writing any integer between 1 and 200 in the place of 15.

Any idea?

Thank you.

J=E1nos

From: Andrzej Kozlowski on
First of all, you do not need to define yourself a function that does
this, since one already exists:

PowersRepresentations[15, 3, 2]

{}

Now, this also tells you the solution to your problem! The solution is
that there are no solutions and you have written your program assuming
that there always are going to be any. Really, to see that all you
needed was to look at the output of:

With[{a = Array[x, 3]}, Reduce[a.a == 15, a, Integers]]

False

Actually, your program will also not work correctly in other cases
when there are no solutions. Here are the numbers of ways of
representing the first 10 integers as sum of squares

SquaresR[3, Range[10]]

{6,12,8,6,24,24,0,12,30,24}

We can see that for n = 7 there are no solutions and your code will
produce:


Module[{x,
a}, (a = Array[x, 3]) /. {ToRules[Reduce[a.a == 7, a, Integers]]}]

{x$2267(1),x$2267(2),x$2267(3)}

So how come you claim that 15 is the only integer between 1 and 200
for which this happens??


Andrzej Kozlowski


On 24 Sep 2009, at 12:51, janos wrote:

> To be on the safe side:
> ClearAll[d, n, x, a, SumOfSquaresRepresentations];
>
> Take this from the help:
> SumOfSquaresRepresentations[d_, n_] :=
> Module[{x,
> a}, (a = Array[x, d]) /. {ToRules[Reduce[a.a == n, a, Integers]]}]
>
> Let's apply it:
> SumOfSquaresRepresentations[3, 15]
> {x$110[1], x$110[2], x$110[3]}
>
> And this is the only case that you get this funny result
> writing any integer between 1 and 200 in the place of 15.
>
> Any idea?
>
> Thank you.
>
> J=E1nos
>


From: Bob Hanlon on

You just need to handle the case when there is no solution

SumOfSquaresRepresentations[d_, n_] :=
Module[{x, a, rules},
a = Array[x, d];
rules = {ToRules[Reduce[a.a == n, a, Integers]]};
If[rules == {}, {}, a /. rules]]


Bob Hanlon

---- janos <janostothmeister(a)gmail.com> wrote:

=============
To be on the safe side:
ClearAll[d, n, x, a, SumOfSquaresRepresentations];

Take this from the help:
SumOfSquaresRepresentations[d_, n_] :=
Module[{x,
a}, (a = Array[x, d]) /. {ToRules[Reduce[a.a == n, a, Integers]]}]

Let's apply it:
SumOfSquaresRepresentations[3, 15]
{x$110[1], x$110[2], x$110[3]}

And this is the only case that you get this funny result
writing any integer between 1 and 200 in the place of 15.

Any idea?

Thank you.

J=E1nos


From: Carl Woll on
janos wrote:
> To be on the safe side:
> ClearAll[d, n, x, a, SumOfSquaresRepresentations];
>
> Take this from the help:
> SumOfSquaresRepresentations[d_, n_] :=
> Module[{x,
> a}, (a = Array[x, d]) /. {ToRules[Reduce[a.a == n, a, Integers]]}]
>
> Let's apply it:
> SumOfSquaresRepresentations[3, 15]
> {x$110[1], x$110[2], x$110[3]}
>
> And this is the only case that you get this funny result
> writing any integer between 1 and 200 in the place of 15.
>
> Any idea?
>
> Thank you.
>
> J=E1nos
>
>
Things are going wrong because there are no such representations.

If you have version 6/7, then you can use the built in function
PowersRepresentations instead. For example:

In[36]:= PowersRepresentations[15, 3, 2]

Out[36]= {}

showing you that there are no such representations.

Carl

From: janos on
Thank to All,

To All,

This is not MY program, I have taken it from the help, more precisely
from here: Compatibility/tutorial/NumberTheory/NumberTheoryFunctions

To Andrzej,

You are right in the last point: there are 32 integers with no
decompositions between 1 and 200,
and not one, my claim was well founded by a mistake.
Still, a function like the one I have taken from the help, IS needed, because
PowersRepresentations only gives the numbers of different
representations.

To Bob,
Thanks for fixing the problem, it should be included into the help
and into the corresponding item of mathworld as well.

Best wishes,

J=E1nos

On szept. 24, 13:50, Andrzej Kozlowski <a...(a)mimuw.edu.pl> wrote:
> First of all, you do not need to define yourself a function that does
> this, since one already exists:
>
> PowersRepresentations[15, 3, 2]
>
> {}
>
> Now, this also tells you the solution to your problem! The solution is =

> that there are no solutions and you have written your program assuming =

> that there always are going to be any. Really, to see that all you
> needed was to look at the output of:
>
> With[{a = Array[x, 3]}, Reduce[a.a == 15, a, Integers]]
>
> False
>
> Actually, your program will also not work correctly in other cases
> when there are no solutions. Here are the numbers of ways of
> representing the first 10 integers as sum of squares
>
> SquaresR[3, Range[10]]
>
> {6,12,8,6,24,24,0,12,30,24}
>
> We can see that for n = 7 there are no solutions and your code will
> produce:
>
> Module[{x,
> a}, (a = Array[x, 3]) /. {ToRules[Reduce[a.a == 7, a, Intege=
rs]]}]
>
> {x$2267(1),x$2267(2),x$2267(3)}
>
> So how come you claim that 15 is the only integer between 1 and 200
> for which this happens??
>
> Andrzej Kozlowski
>
> On 24 Sep 2009, at 12:51, janos wrote:
>
> > To be on the safe side:
> > ClearAll[d, n, x, a, SumOfSquaresRepresentations];
>
> > Take this from the help:
> > SumOfSquaresRepresentations[d_, n_] :=
> > Module[{x,
> > a}, (a = Array[x, d]) /. {ToRules[Reduce[a.a == n, a, Integer=
s]]}]
>
> > Let's apply it:
> > SumOfSquaresRepresentations[3, 15]
> > {x$110[1], x$110[2], x$110[3]}
>
> > And this is the only case that you get this funny result
> > writing any integer between 1 and 200 in the place of 15.
>
> > Any idea?
>
> > Thank you.
>
> > J=E1nos