Density-functional theory for ensembles of fractionally occupied states. I. Basic formalism | Synapse