Re: need help
- To: mathgroup at smc.vnet.net
- Subject: [mg87452] Re: need help
- From: Jean-Marc Gulliet <jeanmarc.gulliet at gmail.com>
- Date: Fri, 11 Apr 2008 01:41:40 -0400 (EDT)
- Organization: The Open University, Milton Keynes, UK
- References: <200804080938.FAA12123@smc.vnet.net> <D1F99877-4BD1-4A2E-AEE2-AEAB4CA94B72@mimuw.edu.pl> <ftkbb1$atp$1@smc.vnet.net>
Patrick Klitzke wrote:
> Andrzej Kozlowski wrote:
>> On 8 Apr 2008, at 18:38, Patrick Klitzke wrote:
>>> But the problem is, that for some numbers you need more than 4 squares:
>>> 96=9^2+3^2+2^2+1^2+1^2
>> A very famous theorem of Lagrange says that every positive integer is
>> a sum of at most 4 squares. This result can be found in virtually
>> every book on number theory (e.g. see K. Chandrasekharan,
>> "Introduction to Analytic number theory"). In the case of 96 we have
>>
>> PowersRepresentations[96, 4, 2]
>> {{0, 4, 4, 8}}
>>
>> in other words
>>
>> 96 = 0^2+4^2+4^2+8^2
>>
>> so in fact you only need 3 squares. Of course if you allow more
>> squares you will get more representations:
>>
>> PowersRepresentations[96, 5, 2]
>> {{0, 0, 4, 4, 8}, {1, 1, 2, 3, 9}, {1, 1, 3, 6, 7},
>> {1, 3, 5, 5, 6}, {2, 2, 4, 6, 6}, {2, 3, 3, 5, 7}}
>>
>> Also, the question of finding just one representation without
>> restriction on length is trivial since you can represent any number as
>> a sum of squares of 1's !
>>
>> Andrzej Kozlowski
>>
>>
>>
>>
> You are right, I used a very bad algorithm and so I could not find a
> solution for even 96.
> But I think he want to use the function PowersRepresentations like that:
> Sumf[x_] := (
> data = PowersRepresentations[x, 4, 2][[1]];
> If[data[[1]] == 1, data[[1]] = "1"];
> If[data[[2]] == 1, data[[2]] = "1"];
> If[data[[3]] == 1, data[[3]] = "1"];
> If[data[[4]] == 1, data[[4]] = "1"];
> Row[{data[[1]]^"2", data[[2]]^"2", data[[3]]^"2", data[[4]]^"2"},
> "+"]
> )
<snip>
Patrick,
Just a side note: a more compact version of the function above could be
written with *HoldForm* as in
Sumf[x_Integer] :=
Row[First[PowersRepresentations[x, 4, 2]]^HoldForm[2], "+"]
Regards,
-- Jean-Marc
- References:
- Re:need help
- From: Patrick Klitzke <philologos14@gmx.de>
- Re:need help