logn power algorithm: python and sml