1 :-use_module(library(clpfd)).
4 % N is the dot product of lists V1 and V2.
5 dot(V1, V2, N) :- maplist(product,V1,V2,P), sumlist(P,N).
6 product(N1,N2,N3) :- N3 is N1*N2.
8 % Matrix multiplication with matrices represented
9 % as lists of lists. M3 is the product of M1 and M2
10 mmult(M1, M2, M3) :- transpose(M2,MT), maplist(mm_helper(MT), M1, M3).
11 mm_helper(M2, I1, M3) :- maplist(dot(I1), M2, M3).
16 suml(L1,L2,[E1 + E2|R2]):-
31 flatten(List, Flattened):-
32 flatten(List, [], Flattened).
34 flatten([], Flattened, Flattened).
35 flatten([Item|Tail], L, Flattened):-
36 flatten(Item, L1, Flattened),
38 flatten(Item, Flattened, [Item|Flattened]):-
68 M=[[M0_0, M0_1, 0, M0_3], [M1_0, M1_1, 0, M1_3],
69 [M2_0, 0, M2_2, M2_3], [0, M3_1, M3_2, M3_3]],
70 [M0_0, M1_1, M2_2, M3_3] ins 0..2,
71 [M0_1, M0_3, M1_0, M1_3, M2_0, M2_3, M3_1, M3_2] ins 0..1,
72 M0_0+ M0_1+ M0_2 #=2, M1_0+ M1_1+ M1_3 #=2,
73 M2_0+ M2_2+ M2_3 #=2, M3_1+ M3_2+ M3_3 #=2,
74 M0_0+ M1_0+ M2_0 #=2, M0_1+ M1_1+ M3_1 #=2,
75 M0_2+ M2_2+ M3_2 #=2, M1_3+ M2_3+ M3_3 #=2,
83 label([M0_0, M0_1, M0_3, M1_0, M1_1, M1_3, M2_0, M2_2, M2_3, M3_1, M3_2, M3_3]),
85 open('res2.txt',append,Stream),
98 findall(X,bistoc(X),L),
101 write('but : '),writeln(DT).