/* Query benchmark in Picat. From http://www.jekejeke.ch/idatab/doclet/prod/en/docs/05_run/15_stdy/06_bench/09_programs/08_query/01_query.p.html Query population and area database to find countries of approximately equal population density. This Picat model was created by Hakan Kjellerstrand, hakank@gmail.com See also my Picat page: http://www.hakank.org/picat/ */ % import util. % import cp. main => go. /** * Prolog code for the database query benchmark. * * This is the benchmark of page 226 of: * Warren, D.H.D. (1983): Applied Logic – Its Use and * Implementation as a Programming Tool, * Technical Note 290, SRI International, 1983 * * We use integer division instead of float division, * Further complication by two temporary variables T1 and T2. * * Copyright 2010, XLOG Technologies GmbH, Switzerland * Jekejeke Prolog 0.8.3 (a fast and small prolog interpreter) */ index(-,-) pop(china, 8250). pop(india, 5863). pop(ussr, 2521). pop(usa, 2119). pop(indonesia, 1276). pop(japan, 1097). pop(brazil, 1042). pop(bangladesh, 750). pop(pakistan, 682). pop(w_germany, 620). pop(nigeria, 613). pop(mexico, 581). pop(uk, 559). pop(italy, 554). pop(france, 525). pop(philippines, 415). pop(thailand, 410). pop(turkey, 383). pop(egypt, 364). pop(spain, 352). pop(poland, 337). pop(s_korea, 335). pop(iran, 320). pop(ethiopia, 272). pop(argentina, 251). index(+,-) area(china, 3380). area(india, 1139). area(ussr, 8708). area(usa, 3609). area(indonesia, 570). area(japan, 148). area(brazil, 3288). area(bangladesh, 55). area(pakistan, 311). area(w_germany, 96). area(nigeria, 373). area(mexico, 764). area(uk, 86). area(italy, 116). area(france, 213). area(philippines, 90). area(thailand, 200). area(turkey, 296). area(egypt, 386). area(spain, 190). area(poland, 121). area(s_korea, 37). area(iran, 628). area(ethiopia, 350). area(argentina, 1080). density(C, D) => pop(C, P), area(C, A), D = P*100 // A. query => density(C1, D1), density(C2, D2), D1 > D2, T1 = 20 * D1, T2 = 21 * D2, T1 < T2, writeln([T1,T2]), writeln([D1,D2]), writeln([C1,C2]). go => query.