input: Write a function to optimize an equation by reducing the repeated terms and representing them in a simpler form. For example, the equation 'x + x + y + y + y' should be optimized to 'x^2 + y^3'. If the input equation is empty then return an empty string. 
  assert optimize_equation('x + x + y + y + y')=='x^2 + y^3'
  assert optimize_equation('a + a + a + b + b')=='a^3 + b^2'
  assert optimize_equation('')==''
  assert optimize_equation('x + y + z + x')=='x^2 + y^1 + z^1'
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():
          if freq > 1:
              result.append(f"{term}^{freq}")
          else:
              result.append(f"{term}^1")
      return ' + '.join(result)