You selected r1729.pl

% the Hardy–Ramanujan number 

% r1729.pl
% 3 Jan 2011

% reference:
% Hardy, G. H.:
% Ramanujan: Twelve Lectures on Subjects Suggested by His Life and Work, 3rd ed.,
% New York: Chelsea, 1999.


% the Hardy–Ramanujan number (the Taxi-cab numbers)
% Z = X^3 + Y ^3 = P^3 + Q^3, 
% where X, Y, P, Q > 0 are integers, X < Y, P < Q, and not (X = P).
% (i.e., sums of 2 cubes in more than 1 way.)


i( X, Y):- length(L, Y), nth0( X, L,_).

c( X, Z, Y):- i( Z, Y), X is Z ^3.  

d( X, Y, [Z, W]):- 
	 c( P, Z, Y),
	 c( Q, W, Y),
	 P < Q,
	 X is P + Q.  


r(X, Y, [Z, W]):-
	 d(X, Y, Z),
	 d(X, Y, W),
	 Z @< W .


/*

 ?- [r1729].
% r1729 compiled 0.00 sec, 16 bytes

Yes

% the (first) Hardy–Ramanujan number.

 ?- r(X,Y,Z).

 ?- r(X,Y,Z).
X = 1729,
Y = 13,
Z = [[1, 12], [9, 10]] ;

X = 1729,
Y = 14,
Z = [[1, 12], [9, 10]] .

Yes

% the (second) Hardy–Ramanujan number.

 ?- r(X,Y,Z), X >1729.

X = 4104,
Y = 17,
Z = [[2, 16], [9, 15]] 

Yes

% the third Hardy–Ramanujan number.

 ?- r(X,Y,Z), Y>17, X>4104.
X = 13832,
Y = 25,
Z = [[2, 24], [18, 20]] ;
X = 13832,
Y = 26,
Z = [[2, 24], [18, 20]] .


% the 4th Hardy–Ramanujan number.

 ?- r(X,Y,Z), Y>25, X > 13832 .

X = 20683,
Y = 28,
Z = [[10, 27], [19, 24]] ;
X = 20683,
Y = 29,
Z = [[10, 27], [19, 24]] 

Yes


% the 5th Hardy–Ramanujan number.

 ?- r(X,Y,Z), Y>28, X>20683.
X = 32832,
Y = 33,
Z = [[4, 32], [18, 30]] ;
X = 32832,
Y = 34,
Z = [[4, 32], [18, 30]] 

Yes

% the 6th and 7th Hardy–Ramanujan numbers.

 ?- r(X,Y,Z), Y>33, X>32832.
X = 39312,
Y = 35,
Z = [[2, 34], [15, 33]] ;
X = 40033,
Y = 35,
Z = [[9, 34], [16, 33]] ;
X = 39312,
Y = 36,
Z = [[2, 34], [15, 33]] .



% the 8th Hardy–Ramanujan number.

 ?- r(X,Y,Z), Y>35, X > 40033.

X = 46683,
Y = 37,
Z = [[3, 36], [27, 30]] ;
X = 46683,
Y = 38,
Z = [[3, 36], [27, 30]] .

% the 9th and 10th Hardy–Ramanujan numbers.

 ?- r(X,Y,Z), Y>37, X>46683.
X = 64232,
Y = 40,
Z = [[17, 39], [26, 36]] ;
X = 65728,
Y = 41,
Z = [[12, 40], [31, 33]] ;
X = 64232,
Y = 41,
Z = [[17, 39], [26, 36]] .


% generate up to the 29th and 30th Hardy–Ramanujan numbers.


 ?- r(X,Y,Z), \+ (clause(h(P,Q,R),_), P>=X), assert(h(X,Y,Z)), findall(1, h(_,_,_), L), length(L, N), N>20.
X = 805688,
Y = 94,
Z = [[11, 93], [30, 92]],
L = [1, 1, 1, 1, 1, 1, 1, 1, 1|...],
N = 21 .


?- listing(h/3).

:- dynamic h/3.

h(110656, 49, [[4, 48], [36, 40]]).
h(110808, 49, [[6, 48], [27, 45]]).
h(134379, 52, [[12, 51], [38, 43]]).
h(149389, 54, [[8, 53], [29, 50]]).
h(165464, 55, [[20, 54], [38, 48]]).
h(171288, 56, [[17, 55], [24, 54]]).
h(195841, 59, [[9, 58], [22, 57]]).
h(216027, 61, [[3, 60], [22, 59]]).
h(216125, 61, [[5, 60], [45, 50]]).
h(262656, 65, [[8, 64], [36, 60]]).
h(327763, 68, [[30, 67], [51, 58]]).
h(402597, 70, [[42, 69], [56, 61]]).
h(439101, 77, [[5, 76], [48, 69]]).
h(443889, 77, [[17, 76], [38, 73]]).
h(513856, 79, [[34, 78], [52, 72]]).
h(515375, 81, [[15, 80], [54, 71]]).
h(525824, 81, [[24, 80], [62, 66]]).
h(558441, 82, [[30, 81], [57, 72]]).
h(684019, 83, [[51, 82], [64, 75]]).
h(704977, 90, [[2, 89], [41, 86]]).
h(805688, 94, [[11, 93], [30, 92]]).
true.


*/

%

return to front page.