• Mathematics with huge numbers

 

I have a question about efficiency in linear equations.

Imagine I have to evaluate: 2^11 + 2^8 + 2^3 + 2^2

What is the most efficient way to calculate this? I am thinking about using memoized recursion and apply the function for x in [11, 8, 3, 2]

@memoized
def f(x):
  if x==0:
    return 1
  if x==1:
    return 2
  elif x==2:
    return 4

  return 2^2 + f(x-1)

Is it more efficient than evaluating all the expresion in one step? Is it possible to solve it in a more efficient way?