X-Git-Url: https://svn.cri.ensmp.fr/git/linpy.git/blobdiff_plain/2e558859456a109279713a2cbdd6c48a70a171c6..09190394388163ef7df51c76bb33077ec8fc0949:/linpy/linexprs.py?ds=sidebyside diff --git a/linpy/linexprs.py b/linpy/linexprs.py index 834c3b4..fce77a6 100644 --- a/linpy/linexprs.py +++ b/linpy/linexprs.py @@ -518,6 +518,21 @@ class Symbol(LinExpr): 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 @@ -571,21 +586,6 @@ class Dummy(Symbol): 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