
prob(Sequence, P) :-
	start(Start),
	prob([Start|Sequence], 1.0, P).

prob([Last], P, P).
prob([S1,S2|States], P0, P) :-
  trans(S1, S2, P1),
  P2 is P0*P1,
  prob([S2|States], P2, P).

% next clause is needed if you do not want to interpret proof failure as zero probability  
% prob([S1,S2|_], P0, 0.0) :-
%   \+ trans(S1, S2, _).


start($).
trans($, h, 1.0).
trans(h, a, 1.0).
trans(a, h, 0.5).
trans(a, !, 0.5).
trans(!, h, 1.0).