I am new to Prolog and not a native speaker, so if you do not understand me, I am sorry.
My question is how can I find if a and b from a list appears equally?
For example, [a,a,b,b] should give me true but if either one appears more than the other it should give false. ex: [a,a,a,b,b].
Can anyone help me please? This is what I have so far and I know it is wrong but I am trying.
count(N,[],0).
count(N,[N|T],U) :-
!,
count(N,T,U1),
U is U1+1.
count(N,[H|T],U) :-
count(N,T,U).
occurrences([],[]).
occurrences([H|T],[[H,X]|Y]) :-
count(H,[H|T],X),
occurrences(T1,Y).
Instead of counting, you could pick a matching element from list' tail - it must exist - while visiting.
The recursion base case will be the simplest you can think of... and select/3 is the built in that will enable a really compact solution to your problem.
edit
well, the code is easy...
note: on success, R will be the empty list