3 ms·
Well, even in Wikipedia, the definition is quoted as being different for CS vs the unary operation you describe. "In computer science, the term idempotent is u
by kgen 11y ago
Well, even in Wikipedia, the definition is quoted as being different for CS vs the unary operation you describe.
"In computer science, the term idempotent is used more comprehensively to describe an operation that will produce the same results if executed once or multiple times."
Which is more that f(x) == f(x) == f(x) for the state affected by f.
- tobr 11y agoThank you for pointing this out, I was not aware that the word could be used this way. They are really quite different concepts.
- matchu 11y agoI'm not sure that they are. You just need to model the concept of state as the function's input/output, as functional programmers are eager to do :) If we start in state x, then apply operation f, the resulting state is f(x). If we apply operation f again, we'll be in state f(f(x)). If f is idempotent, then state f(x) and state f(f(x)) are identical.
- blt 11y agoThey are analogous if you represent side effects like this: new_state = f(old_state, x) then an idempotent operation is f(f(state, x), x) == f(state, x) In the context of drawing windows: draw(draw(fbuf, wnd, x, y), wnd, x, y) == draw(fbuf, wnd, x, y) but this is of course false if you allow alpha channel transparency...