math: handle ORs better in handle_logical()