Here is a relational version:
repetitions(N, [First|Rest]) :-
phrase(repetitions_(First, 1, N), Rest).
repetitions_(_, N, N) --> [].
repetitions_(First, N0, N) --> [First],
{ N1 #= N0 + 1 },
repetitions_(First, N1, N).
repetitions_(First, N, N) --> [Other], { dif(First, Other) }, ... .
... --> [] | [_], ... .
The test case works as required:
?- repetitions(N, [a,a,a,a,a,b,c,a]).
N = 5 ;
false.
And moreover, we can also use this in other directions.
For example, what about a list with 3 element in general:
?- Ls = [A,B,C], repetitions(N, Ls).
Ls = [C, C, C],
A = B, B = C,
N = 3 ;
Ls = [B, B, C],
A = B,
N = 2,
dif(B, C) ;
Ls = [A, B, C],
N = 1,
dif(A, B) ;
false.
And what about all possible answers, fairly enumerated by iterative deepening:
?- length(Ls, _), repetitions(N, Ls).
Ls = [_8248],
N = 1 ;
Ls = [_8248, _8248],
N = 2 ;
Ls = [_8734, _8740],
N = 1,
dif(_8734, _8740) ;
Ls = [_8248, _8248, _8248],
N = 3 ;
Ls = [_8740, _8740, _8752],
N = 2,
dif(_8740, _8752) ;
etc.
It is a major attraction of logic programs that they can often be used in several directions.
See dcg, prolog-dif and clpfd for more information about the mechanisms I used to achieve this generality.
We can also use this to answer the following question
What does a list look like such that there are 3 repetitions of its first element?
Example:
?- repetitions(3, Ls).
Ls = [_2040, _2040, _2040] ;
Ls = [_2514, _2514, _2514, _2532],
dif(_2514, _2532) ;
Ls = [_2526, _2526, _2526, _2544, _2550],
dif(_2526, _2544) ;
Ls = [_2538, _2538, _2538, _2556, _2562, _2568],
dif(_2538, _2556) .
This requires only that a single further constraint be added to the solution above. I leave this as an easy exercise.