3 ms·
ELI5? From Wikipedia, which agrees with you... > A unary operation (or function) is idempotent if, whenever it is applied twice to any value, it gives the sam
by michaelcampbell 11y ago
ELI5?
From Wikipedia, which agrees with you...
> A unary operation (or function) is idempotent if, whenever it is applied twice to any value, it gives the same result as if it were applied once; i.e., ƒ(ƒ(x)) ≡ ƒ(x). For example, the absolute value function, where abs(abs(x)) ≡ abs(x).
So is f(x) = x + 1 idempotent?
Under this part: "whenever it is applied twice to any value, it gives the same result as if it were applied once" it would appear so.
f(2) = 3
f(2) still = 3.
But under this part: "ƒ(ƒ(x)) ≡ ƒ(x)"
f(f(x)) == f(f(2)) == f(3) = 4
Where'd I go wrong?
- matchu 11y agoWhen they say "applied twice", they're not talking about two independent applications to the same initial value. (That's a test for functional purity, not idempotence.) Instead, they're referring to the following sequence of actions: 1. Update the value x according to the operation f. 2. Update the value x according to the operation f.
- michaelcampbell 11y agoUnderstood; thanks.