1
Truth Functional Logic for Hackers - Part One
lagomor.phBob and Alice are two hackers working on an embedded system with a severe computational constraint - there is a bug in their low-cost microcontroller making OR operations significantly slower than any other operation on the chipset.
When they profiled their micropython code, they found that OR operations were up to 5x slower than any other operation.
Alice This is a big problem! We could replace the faulty chips with better ones, if they arrive before the deadline. Bob I don’t think we can afford to wait - the deadline is in 3 days. A better option is to rewrite the code to avoid the OR operation. Alice How could we do that? We’re using the OR operation in a lot of critical places. Look: def authorize_access(request): # A user is denied if they are on a blacklist OR # their account is expired if (user_is_blacklisted(request.user_id) or account_is_expired(request.account) return "Access denied" return "Access granted" Let’s take a moment to understand the problem. The authorize_access function is used to check if a user is authorized to access a resource. The or operation is used to combine the conditions. How could we rewrite this function to avoid the OR operation?
You must log in or register to comment.