
compute(A,Y) :- Y is A/2.
findmod(B,Z) :- Z is B mod 5.

test(S,T,U,V,W,X,Y,Z) :- X is 4 * 2, ((A is X*X, functor(U,f,5), compute(A,Y), functor(T,h,2) )  //
		 	          (B is 3*X, findmod(B,Z), functor(V,g,Z), functor(S,j,3))), 
		     W is Y + Z.

?- test(A,B,C,D,E,F,G,H).