View source with raw comments or as raw
    1valid_stream(P,Data) :- 
    2     stream(P,Data), 
    3     not cancelled(P, Data).
    4cancelled(P, Data) :- 
    5     higher_prio(P1, P), 
    6     stream(P1, Data1), 
    7     incompt(Data, Data1).
    8higher_prio(PHi, PLo) :- 
    9     PHi .>. PLo.
   10incompt(p(X), q(X)).
   11incompt(q(X), p(X)).
   12
   13stream(1,p(X)).
   14stream(2,q(a)).
   15stream(2,q(b)).
   16stream(3,p(a)).
   17
   18?- valid_stream(P,Data).