Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>In computing, an idempotent operation is one that has no additional effect if it is called more than once with the same input parameters. For example, removing an item from a set can be considered an idempotent operation on the set.</p> <p>In mathematics, an idempotent operation is one where <em>f(f(x)) = f(x)</em>. For example, the <code>abs()</code> function is idempotent because <code>abs(abs(x)) = abs(x)</code> for all <code>x</code>. </p> <p>These slightly different definitions can be reconciled by considering that <em>x</em> in the mathematical definition represents the state of an object, and <em>f</em> is an operation that may mutate that object. For example, consider the <a href="https://docs.python.org/2/library/stdtypes.html#set" rel="noreferrer">Python <code>set</code></a> and its <code>discard</code> method. The <code>discard</code> method removes an element from a set, and does nothing if the element does not exist. So:</p> <pre><code>my_set.discard(x) </code></pre> <p>has exactly the same effect as doing the same operation twice:</p> <pre><code>my_set.discard(x) my_set.discard(x) </code></pre> <p>Idempotent operations are often used in the design of network protocols, where a request to perform an operation is guaranteed to happen at least once, but might also happen more than once. If the operation is idempotent, then there is no harm in performing the operation two or more times.</p> <p>See the Wikipedia article on <a href="http://en.wikipedia.org/wiki/Idempotence" rel="noreferrer">idempotence</a> for more information.</p> <hr> <p><sup>The above answer previously had some incorrect and misleading examples. Comments below written before April 2014 refer to an older revision.</sup></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload