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).
35 flatten(List, Flattened):-
36 flatten(List, [], Flattened).
38 flatten([], Flattened, Flattened).
39 flatten([Item|Tail], L, Flattened):-
40 flatten(Item, L1, Flattened),
42 flatten(Item, Flattened, [Item|Flattened]):-