Okay, it looks like you are building a nested expression. It might be getting huge and that could account for the speed issue. Given the use of machine doubles, large scales, and high degree exponents, I would be surprised if this was not numerically very poorly behaved in any case.