Abstract: This paper was inspired by the work of Herbert Hauptman, a leading figure in X-ray crystallography and a 1985 Nobel laureate in chemistry. From a mathematician's point of view, the situation is roughly as follows. To determine the structure of a physical crystal, one needs to know certain quantities, called ``phases". In practice, these cannot be measured directly; however, one can measure another set of quantities called ``observables" or ``magnitudes". The question then becomes: if the ``magnitudes" are known, can one recover the ``phases", and if so, what is the most efficient way to carry out the computations? Hauptman and his collaborators pioneered a probabilistic approach to this problem. If the number n of atoms in the unit cell of a crystal is large, these methods work very well. For smaller n, Hauptman suggested a direct algebraic approach, i.e., looking for explicit formulas expressing the magnitudes as rational functions in the observables. He found such formulas for n <= 3 and asked if similar formulas exist for other values of n. We show that the answer is ``yes" by rephrasing the problem as a question about multiplicative invariants of a particular finite group action. Our proofs are constructive, but the resulting algorithms are, for the most part, too slow to be of practical significance. For n <= 4, we develop a faster algorithm, using SAGBI bases. As a result, we obtain new explicit formulas for n = 4. We also consider several related problems and algorithms.