gen_mt(N) :-
    functor(X,*,N),
    functor(Y,*,N),
    functor(Z,*,N),
    gen_mt(N,X,Y,Z,true,Body),
    portray_clause((mt(X,Y,Z) :- Body)).

gen_mt(0,_,_,_,Body,Body) :-!.
gen_mt(N,X,Y,Z,Body0,Body) :-
    arg(N,X,Xn),
    arg(N,Y,Yn),
    arg(N,Z,Zn),
    M is N-1,
    gen_mt(M,X,Y,Z,(m(Xn,Yn,Zn),Body0),Body).

g1(*(0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2)).
g2(*(0,0,0,1,1,1,2,2,2,0,0,0,1,1,1,2,2,2,0,0,0,1,1,1,2,2,2)).
g3(*(0,1,2,0,1,2,0,1,2,0,1,2,0,1,2,0,1,2,0,1,2,0,1,2,0,1,2)).
 
