# Path: calculus/symbol.py
# class Symbol:
# class StringSymbol(Symbol):
#   def __init__(self, type):
#   def _generate_id(self):
#   def __eq__(self, other):
#   def __ne__(self):
#   def __hash__(self):
#   def __repr__(self):
#   def __init__(self, s, type, infix = None):
#   def __repr__(self):
# 
# Path: ui/render/text/primitives.py
# def newTextStack(color, s):
# def wrapVariableInfix(s):
# def holds():
# def surroundWithNot(s):
# def solidSquare(color, widths):
# def identical(covariant):
# def iff():
# def _dimension_for_variance(covariant):
# def _dual_dimension(dimension):
# def andDivider(covariant):
#   def f(length):
# def orDivider(covariant):
#   def f(length):
# def quantifierDivider(covariant, length):
# def divider(color, dimension, length, width, special_character = None):
# 
# Path: ui/render/text/colors.py
# def productPairsColor(i):
# def exponentialColor(isAlways):
# 
# Path: ui/render/text/distances.py

# 
# Path: ui/stack/stack.py
# def stack(self, dimension, other, spacing = 0):
#   if self._backend.stacks():
#     offset = [0 for i in range(self.dimension())]
#     offset[dimension] = spacing
#     coords = list(self._coords)
#     for i in range(len(coords)):
#       if i == dimension:
#         coords[i] += spacing + other._coords[i]
#       else:
#         coords[i] = max(coords[i], other._coords[i])
#     return Stack(coords, self._backend.stack(dimension, other._backend.shift(offset)))
#   else:
#     offset = [0 for i in range(self.dimension())]
#     offset[dimension] = self.widths()[dimension] + spacing
#     return self.below(other.shift(offset))


from sets import Set
from calculus import symbol
from ui.render.text import primitives, colors, distances
from ui.stack import stack
  # infix: either None, or a pair of symbols (a, b) such that when this variable holds
  #        of a variable v, v is a product variable over symbols a and b.
  def __init__(self, name, infix = None):
    self._generate_id()
    self._name = name
    self.infix = infix

  def relatedVariable(self):
    return StringVariable(name = self.name() + "'", infix = self.infix)

  def render(self):
    return primitives.newTextStack(colors.variableColor, repr(self))

  def name(self):
    return self._name

  def __repr__(self):
    return self.name()

  def updateVariables(self):
    return self.relatedVariable()

def renderInfix(productVariable, infixSymbols, infixVariable):
  (firstSymbol, secondSymbol) = infixSymbols
  assert(len(productVariable.symbol_variable_pairs) == 2)
  (aSymbol, aVariable) = productVariable.symbol_variable_pairs[0]
  (bSymbol, bVariable) = productVariable.symbol_variable_pairs[1]
  if aSymbol == secondSymbol:
    assert(bSymbol == firstSymbol)
    (firstSymbol, secondSymbol) = (secondSymbol, firstSymbol)

# Path: calculus/symbol.py
# class Symbol:
# class StringSymbol(Symbol):
#   def __init__(self, type):
#   def _generate_id(self):
#   def __eq__(self, other):
#   def __ne__(self):
#   def __hash__(self):
#   def __repr__(self):
#   def __init__(self, s, type, infix = None):
#   def __repr__(self):
# 
# Path: ui/render/text/primitives.py
# def newTextStack(color, s):
# def wrapVariableInfix(s):
# def holds():
# def surroundWithNot(s):
# def solidSquare(color, widths):
# def identical(covariant):
# def iff():
# def _dimension_for_variance(covariant):
# def _dual_dimension(dimension):
# def andDivider(covariant):
#   def f(length):
# def orDivider(covariant):
#   def f(length):
# def quantifierDivider(covariant, length):
# def divider(color, dimension, length, width, special_character = None):
# 
# Path: ui/render/text/colors.py
# def productPairsColor(i):
# def exponentialColor(isAlways):
# 
# Path: ui/render/text/distances.py

# 
# Path: ui/stack/stack.py
# def stack(self, dimension, other, spacing = 0):
#   if self._backend.stacks():
#     offset = [0 for i in range(self.dimension())]
#     offset[dimension] = spacing
#     coords = list(self._coords)
#     for i in range(len(coords)):
#       if i == dimension:
#         coords[i] += spacing + other._coords[i]
#       else:
#         coords[i] = max(coords[i], other._coords[i])
#     return Stack(coords, self._backend.stack(dimension, other._backend.shift(offset)))
#   else:
#     offset = [0 for i in range(self.dimension())]
#     offset[dimension] = self.widths()[dimension] + spacing
#     return self.below(other.shift(offset))


# Path: calculus/variable.py
from sets import Set
from calculus import symbol
from ui.render.text import primitives, colors, distances
from ui.stack import stack

  # infix: either None, or a pair of symbols (a, b) such that when this variable holds
  #        of a variable v, v is a product variable over symbols a and b.
  def __init__(self, name, infix = None):
    self._generate_id()
    self._name = name
    self.infix = infix

  def relatedVariable(self):
    return StringVariable(name = self.name() + "'", infix = self.infix)

  def render(self):
    return primitives.newTextStack(colors.variableColor, repr(self))

  def name(self):
    return self._name

  def __repr__(self):
    return self.name()

  def updateVariables(self):
    return self.relatedVariable()

def renderInfix(productVariable, infixSymbols, infixVariable):
  (firstSymbol, secondSymbol) = infixSymbols
  assert(len(productVariable.symbol_variable_pairs) == 2)
  (aSymbol, aVariable) = productVariable.symbol_variable_pairs[0]
  (bSymbol, bVariable) = productVariable.symbol_variable_pairs[1]
  if aSymbol == secondSymbol:
    assert(bSymbol == firstSymbol)
    (firstSymbol, secondSymbol) = (secondSymbol, firstSymbol)

  else: