Trace Elements in Magmas: A Theoretical Treatment