insert(X, [], [X]). insert(X, [Y | L], [X, Y | L]) :- X =< Y. insert(X, [Y|L], [Y | L1]) :- Y =< X, insert(X, L, L1). mysort([], []). mysort([X | L1], L2) :- mysort(L1, L3), insert(X, L3, L2). addelt(X, L, [X| L]). addelt(X, [H | T], [H | L]) :- addelt(X, T, L). permute([], []). permute([X | Xs], L) :- permute(Xs, U), addelt(X, U, L). declsort(L, S) :- permute(L,S), sorted(S). sorted([]). sorted([_]). sorted([X , Y | Ys]) :- X =< Y , sorted([Y | Ys]). val(g3, t, IV) :- val(g2, t, IV). val(g3, t, IV) :- val(g1, t, IV). val(g3, f, IV) :- val(g2, f, IV), val(g1, f, IV). val(g1, t, IV) :- input(i1, t, IV), input(i2, f, IV). val(g1, f, IV) :- input(i1, f, IV). val(g1, f, IV) :- input(i2, t, IV). val(g2, t, IV) :- input(i1, f, IV), input(i2, t, IV). val(g2, f, IV) :- input(i1, t, IV). val(g2, f, IV) :- input(i2, f, IV). input(i1, V, inputVector(V,_)). input(i2, V, inputVector(_,V)).