What principle do we use in writing the formula of an ionic compound such as NaCl or MgI2? How do we know that two iodide ions are needed for each magnesium ion, whereas only one chloride ion is needed per sodium ion?