MathGroup Archive 2009

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: SumOfSquaresRepresentations

  • To: mathgroup at smc.vnet.net
  • Subject: [mg103490] Re: [mg103475] SumOfSquaresRepresentations
  • From: Bob Hanlon <hanlonr at cox.net>
  • Date: Thu, 24 Sep 2009 07:51:33 -0400 (EDT)
  • Reply-to: hanlonr at cox.net

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 at 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



  • Prev by Date: Re: Showing the Current Value of a Slider in Manipulate
  • Next by Date: Re: SumOfSquaresRepresentations
  • Previous by thread: Re: SumOfSquaresRepresentations
  • Next by thread: A question about parallel computation in mathematica