m(_,[],X,C) :- X is 0, !.
m(P,A,X,C) :- atom(A), val(P,A,V), X is V, C is 1, !.
m(P,[A|[]],X,C) :- atom(A), val(P,A,V), X is V, C is 1, !.
m(P,[A|[]],X,C) :- is_list(A), m(P,A,X,C), !.
m(P,[A|[B]],X,C) :- atom(A), atom(B), val(P,A,X1), number(X1), val(P,B,X2), number(X2), X is X1 + X2, C is 2, !.
m(P,[A|[B]],X,C) :- atom(A), number(B), val(P,A,V), number(V), X is V * B, C is B, !.
m(P,[A|[B]],X,C) :- number(A), atom(B), val(P,B,V), number(V), X is V * A, C is A, !.
m(P,[A|B],X,C) :- m(P,A,X1,C1), m(P,B,X2,C2), X is X1 + X2, C is C1 + C2, !.
m(A,B,C) :- m(A,B,C,_).
m(A,B) :- m(A,B,C,_), um(A,U), write(B), write(": "), write(A), write(" = "), write(C), write(" "), write(U).
% a
água(X) :- h2o(X).
% b
% c
% d
% e
% f
% g
% h
h2o(X) :- X = [[h,2],o].
h2so4(X) :- X = [[h,2],s,[o,4]].
% i
%
%
%
% m
mg2so4(X) :- X = [[mg,2],s,[o,4]].
% n
nacl(X) :- X = [na,cl].
naoh(X) :- X = [na,o,h].
% o
% p
% q
% r
% s
% t
% u
% v
% x
% w
% y
% z
:- op(900, xfy, <-).
R <- log2(Y) :- R is log(Y)/log(2), !.
R <- h2o :- h2o(R).