Theory of electrochemical effects in alloys