/*-------------------------------------------------------------------------*/ /* Benchmark (Finite Domain) */ /* */ /* Name : partit.pl */ /* Title : integer partitionning */ /* Original Source: Daniel Diaz - INRIA France */ /* Adapted by : Daniel Diaz for GNU Prolog */ /* Date : September 1993 (modified March 1997) */ /* */ /* Partition numbers 1,2,...,N into two groups A and B such that: */ /* a) A and B have the same length, */ /* b) sum of numbers in A = sum of numbers in B, */ /* c) sum of squares of numbers in A = sum of squares of numbers in B. */ /* */ /* This problem admits a solution if N is a multiple of 8. */ /* */ /* Note: finding a partition of 1,2...,N into 2 groups A and B such that: */ /* */ /* Sum (k^p) = Sum l^p */ /* k in A l in B */ /* */ /* admits a solution if N mod 2^(p+1) = 0 (N is a multiple of 2^(p+1)). */ /* Condition a) is a special case where p=0, b) where p=1 and c) where p=2.*/ /* */ /* Two redundant constraints are used: */ /* */ /* - in order to avoid duplicate solutions (permutations) we impose */ /* A1 X1. ascending_order([X|L]):- ascending_order(L,X). ascending_order([],_). ascending_order([Y|L],X):- Y #> X, ascending_order(L,Y). half_sums(N,HS1,HS2):- S1 is N*(N+1)//2, S2 is S1*(2*N+1)//3, HS1 is S1//2, HS2 is S2//2.