Thermodynamics of formation of yttrium-magnesium intermediate phases