input: Write a function to optimize an equation by reducing duplicate terms and returning the optimized form of the equation. The input will be a string representing the equation and the output will be the optimized form of the equation. 
  
  def optimize_equation(equation):
      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 + c + c + c + c') == 'a^2 + b^3 + c^4'
  assert optimize_equation('x + y + z') == 'x^1 + y^1 + z^1'
  assert optimize_equation('') == ''
  assert optimize_equation('w + w + w + w + w') == 'w^5'
output: def optimize_equation(equation):
      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():
          if count > 1:
              new_equation += (var + '^' + str(count)) + ' + '
          else:
              new_equation += var + ' + '
      return new_equation[:-3] if new_equation else ''