log calculus optimization