input: Write a function to optimize an equation by combining like terms. The function should take a string representing the equation as input and return a simplified string with combined terms. If the input equation is empty then return an empty string.
  
  def optimize_equation(equation):
      if not equation:
          return ""
      
      variables = {}
      for term in equation.split('+'):
          var = term.strip()
          if var in variables:
              variables[var] += 1
          else:
              variables[var] = 1
  
      new_equation = ""
      for var, count in variables.items():
          new_equation += (var + '^' + str(count)) + ' + '
      return new_equation[:-3]
  
  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('c + c + c + d')=='c^3 + d^1'
  assert optimize_equation('')==''
  assert optimize_equation('x + y + z')=='x^1 + y^1 + z^1'
output: def optimize_equation(equation):
      if not equation:
          return ""
      
      variables = {}
      for term in equation.split('+'):
          var = term.strip()
          if var in variables:
              variables[var] += 1
          else:
              variables[var] = 1
  
      new_equation = ""
      for var, count in variables.items():
          new_equation += (var + '^' + str(count)) + ' + '
      return new_equation[:-3]