_Posted on July 20, 2024_
In the 1985 paper [Distributed Operating Systems](https://dl.acm.org/doi/pdf/10.1145/6041.6074) by Tanenbaum and Renesse, section 2.1.3 covers error handling during remote procedure calls (RPCs). One such error occurs when an RPC is invoked and the client cannot tell whether the server has crashed or otherwise failed to execute the procedure (e.g. caused by a delayed response). A solution is presented which only works in certain cases: "waiting until the server is rebooted and trying again." This solution is garunteed to work when the procedure is _idempotent_:
>Calls that may be repeated without harm... are said to be idempotent.... Any call that causes action to occur in the outside world, such as transferring money, printing lines, or opening a valve in an automated chocolate factory just long enough to fill exactly one vat, is likely to cause trouble if performed twice.
>- Tanenbaum and Renesse, _Distributed Operating Systems_
This "definition", while providing a good application of the concept (i.e. when a client does not know whether the server has crashed, an idempotent operation can always be run again without negative consequences), is not quite comprehensive enough for a general understanding of the term. In mathematics, an idempotent function $f$ is one where $f \circ f = f$. In computer science, an idempotent _procedure_ is broader: applying the procedure multiple times with the same input parameters always results in the same output.
In a theoretical sense, we would ideally inherit the mathematical definition of idempotence. I mean by this that if we consider all relevant input and output _states_ in the procedure definition as a mathematical function, the mathematical definition of idempotence is likely more accurate. For example, suppose our procedure opens a valve in an automated chocolate factory long enough to fill one vat. Let us attempt to define this as a mathematical function $g$. Suppose that $S$ is the set of room-chocolate states. We define the function $g$ (for a particular valve) as $g:S \rightarrow S$, whereupon opening the valve under a certain room-chocolate state, a new room-chocolate state is reached. Clearly, opening the valve the first time will result in one room-chocolate state, and another the second time. This is because the room-chocolate state changed, and so the input was actually different upon the second application. Under the mathematical definition of idempotence, $g$ is clearly _not_ idempotent (the classification given by Tanenbaum and Renesse). However, under the computer science definition, this function would be classified as idempotent. Given the same room-chocolate state (i.e., the same input parameters), opening the valve for a set time will consistently result in the same "output" room-chocolate state (within tolerance). This leads us to the conclusion mentioned above; that "if we consider all relevant input and output _states_ in the procedure definition as a mathematical function, the mathematical definition of idempotence is... more accurate" than the computer science definition.
In reality, the valve opening procedure is not aware of the room-chocolate state[^1]. Thus, there is actually no explicit input to this procedure as implemented in the real world. Any two applications of the procedure will almost always result in different output, breaking idempotency under the computer science definition. Note that as a function, this would be defined something like $h:\{\}\rightarrow S$, which is not composable (except trivially), so that the mathematical definition of idempotence would be meaningless.
In conclusion, given the practical limitations inherent in most computing systems, the current computer science definition of idempotence is very effective. This definition pragmatically focuses on the _result_ of operations within a given state context, rather than attempting to incorporate the entire relevant system state as _both_ the input and output of procedures.
[^1]: If it is aware of this, then the client could know upon server reboot whether the procedure has ran.