% Query: p(g,f)
p(mul(X,mul(Y,Z)),T):- p(mul(mul(X,Y),Z),T).
p(mul(e,e),e).
p(mul(X,i(X)),e).
p(i(mul(X,Y)),Z):- p(mul(i(X),i(Y)),Z).
p(g(mul(X,Y),Y),Z):- p(f(mul(X,Y),X),Z).
p(f(e,Y),Y).