r/computerscience • u/dashdanw • May 27 '25
Discussion Does memoizing a function make it truly "idempotent"?
If you cache the result of a function, or say, for instance, check to see if its already been run, and skipping running it a second time make a function truly idempotent?
22
Upvotes
View all comments
Show parent comment
1
u/SirClueless May 29 '25
I don’t think the distinction you’re drawing makes much sense. Adding or removing memoization can change a procedure’s behavior, that’s true. But this is true of mathematically idempotent functions in practice too:
memoizedFibonacci(1000)takes 1ms to compute whilefibonacci(1000)takes trillions of times longer than the heat death of the universe, “just caching” is not something you can ever skip thinking about.