input: Write a function to optimize an equation by simplifying repeated terms. For example, if the input equation is 'x + x + y + y + y', the output should be 'x^2 + y^3'. The function should return the optimized form of the given equation as a string. If the input equation 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 + b + b + b + b')=='a^2 + b^4'
  assert optimize_equation('x + x + x + y + y')=='x^3 + y^2'
  assert optimize_equation('')==''
  assert optimize_equation('m + n + m + m')=='m^3 + n'
output: def optimize_equation(equation):
      if not equation:
          return ''
      terms = equation.split(' + ')
      count = {}
      for term in terms:
          if term in count:
              count[term] += 1
          else:
              count[term] = 1
      result = []
      for term, freq in count.items():
          result.append(f"{term}^{freq}")
      return ' + '.join(result)