Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Lagrange's four-square theorem

26 views
Skip to first unread message

Merciadri Luca

unread,
Apr 22, 2012, 2:16:30 PM4/22/12
to
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi,

When doing some Scheme exercises past week, an exercise resisted to my
(potential) sagacity. It is asked to write a `lagrange' function, taking
as only argument a natural number n, and which returns the list of all the
4-uples of natural integers (a, b, c, d) such that a^2+b^2+c^2+d^2=n.

The order in which the quadruples are enumerated has no sort of
importance.

I immediately thought about the two following particular cases:
* if one of the monomials squared equals n, all the others can be set
to 0,
* for n=0, we have ((0 0 0 0)) (trivial case).

However, I'm stuck when trying to link (lagrange n) to (lagrange (+ n
1)): the recursive step. Does somebody have any idea about this?

Here is an example:

(lagrange 13) ==>
((3 2 0 0) (3 0 2 0) (3 0 0 2) (2 3 0 0) (2 2 2 1) (2 2 1 2) (2 1 2 2)
(2 0 3 0) (2 0 0 3) (1 2 2 2) (0 3 2 0) (0 3 0 2) (0 2 3 0) (0 2 0 3)
(0 0 3 2) (0 0 2 3))

Thanks.
- --
Merciadri Luca
See http://www.student.montefiore.ulg.ac.be/~merciadri/
- --

Education is the best provision for the journey to old age. (Aristotle)
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)
Comment: Processed by Mailcrypt 3.5.8 <http://mailcrypt.sourceforge.net/>

iEYEARECAAYFAk+USv4ACgkQM0LLzLt8MhyFYQCdG2f9o6X8doNXPZnVP47DONjA
88kAnRmZD2jqPN415NeadWqVSQmSzQCF
=WkoI
-----END PGP SIGNATURE-----

Jussi Piitulainen

unread,
Apr 22, 2012, 2:27:33 PM4/22/12
to
Merciadri Luca writes:

> (potential) sagacity. It is asked to write a `lagrange' function,
> taking as only argument a natural number n, and which returns the
> list of all the 4-uples of natural integers (a, b, c, d) such that
> a^2+b^2+c^2+d^2=n.
>
> The order in which the quadruples are enumerated has no sort of
> importance.
>
> I immediately thought about the two following particular cases:
> * if one of the monomials squared equals n, all the others can be set
> to 0,
> * for n=0, we have ((0 0 0 0)) (trivial case).
>
> However, I'm stuck when trying to link (lagrange n) to (lagrange (+
> n 1)): the recursive step. Does somebody have any idea about this?

Think sideways: Try all suitable a^2. Find all three squares that add
up to n - a^2.

Merciadri Luca

unread,
Apr 24, 2012, 3:28:13 PM4/24/12
to
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Thanks!
Every cloud has a silver lining.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)
Comment: Processed by Mailcrypt 3.5.8 <http://mailcrypt.sourceforge.net/>

iEYEARECAAYFAk+W/s0ACgkQM0LLzLt8Mhzz1ACfQqyCCp/kbnw27d750r4U9X+T
J5kAnAso2HPtOa69kTm8JrBglVgZMeAp
=iXRX
-----END PGP SIGNATURE-----
0 new messages