Text S2: The algebra of flexible cost functions