"""
if not isinstance(name, str):
raise TypeError('name must be a string')
+ node = ast.parse(name)
+ try:
+ name = node.body[0].value.id
+ except (AttributeError, SyntaxError):
+ raise SyntaxError('invalid syntax')
self = object().__new__(cls)
- self._name = name.strip()
+ self._name = name
self._coefficients = {self: Fraction(1)}
self._constant = Fraction(0)
self._symbols = (self,)
raise TypeError('expr must be a sympy.Symbol instance')
+def symbols(names):
+ """
+ This function returns a tuple of symbols whose names are taken from a comma
+ or whitespace delimited string, or a sequence of strings. It is useful to
+ define several symbols at once.
+
+ >>> x, y = symbols('x y')
+ >>> x, y = symbols('x, y')
+ >>> x, y = symbols(['x', 'y'])
+ """
+ if isinstance(names, str):
+ names = names.replace(',', ' ').split()
+ return tuple(Symbol(name) for name in names)
+
+
class Dummy(Symbol):
"""
A variation of Symbol in which all symbols are unique and identified by
return '$${}_{{{}}}$$'.format(self.name, self._index)
-def symbols(names):
- """
- This function returns a tuple of symbols whose names are taken from a comma
- or whitespace delimited string, or a sequence of strings. It is useful to
- define several symbols at once.
-
- >>> x, y = symbols('x y')
- >>> x, y = symbols('x, y')
- >>> x, y = symbols(['x', 'y'])
- """
- if isinstance(names, str):
- names = names.replace(',', ' ').split()
- return tuple(Symbol(name) for name in names)
-
-
class Rational(LinExpr, Fraction):
"""
A particular case of linear expressions are rational values, i.e. linear