input: Write a function to optimize an equation by collecting and summing like terms. The function should take a string representing the equation as input, where each term is separated by a '+' sign. Each term consists of a variable and its corresponding count. The function should return a new equation where like terms are summed and represented as 'variable^count'. If the input is empty, the function should return an empty string.
  assert optimize_equation('x + x + y + y + y')=='x^2 + y^3'
  assert optimize_equation('a + a + a + b')=='a^3 + b^1'
  assert optimize_equation('m + m + m')=='m^3'
  assert optimize_equation('')==''
output: def optimize_equation(equation):
      if not equation:
          return ''
      terms = equation.split(' + ')
      term_counts = {}
      for term in terms:
          if term in term_counts:
              term_counts[term] += 1
          else:
              term_counts[term] = 1
      result = []
      for term, count in term_counts.items():
          result.append(f'{term}^{count}')
      return ' + '.join(result)