% query: dist([T1 $= a $| mul(T1,T1) $| plus(T1,T1)],[T2 $=MAX])
dist(a,a).
dist(mul(a,a),mul(a,a)).
dist(plus(X,Y),plus(U,V)):-dist(X,U),dist(Y,V).
dist(mul(X,plus(Y,Z)),T):- dist(plus(mul(X,Y),mul(X,Z)),T).
dist(mul(plus(X,Y),Z),T):- dist(plus(mul(X,Z),mul(Y,Z)),T).
