matches(ε, []).
matches(X, [X]) :- atom(X), !.
matches(∪(A, _), X) :- matches(A, X).
matches(∪(_, B), X) :- matches(B, X).
matches(·(X, Y), List) :- append(S1, S2, List), matches(X, S1), matches(Y, S2), !.
matches(*(_), []).
matches(*(X), List) :- append(S1, S2, List), not(S1 == []), matches(X, S1), matches(*(X), S2).
delete([X|L], X, L).
delete([X|L], Y, [X|R]) :- delete(L, Y, R).

remove([(C,A)|R], C, [(C,A1)|R]) :- A > 0, A1 is A-1.
remove([C|R], M, [C|E]) :- remove(R, M, E).

put([], C, [(C,1)]).
put([(C,A)|R], C, [(C,A1)|R]) :- A1 is A+1, !.
put([C|R], M, [C|E]) :- put(R, M, E).






