:- op(800,xfx,&). :- op(900,xfx,==>). grammar([start ==> xa & (xb & xc), xa ==> (a, xa), xa, xb ==> (a, a, xb), xb, xc ==> (a, a, a, xc), xc ]). /* the order (and multiplicity) of the answers is not important - but execution of these queries should be finite ?- cong(10,L), write(L), nl, fail. [] ?- cong(20,L), write(L), nl, fail. [a,a,a,a,a,a] [] ?- cong(30,L), write(L), nl, fail. [a,a,a,a,a,a,a,a,a,a,a,a] [a,a,a,a,a,a] [] */