From 97dc5afc5f73441214320db32fe7eabcc36f6cc5 Mon Sep 17 00:00:00 2001 From: "mr.Shu" Date: Sun, 30 Dec 2012 09:25:32 +0100 Subject: [PATCH 1/6] implemented symbols('aa:z') --- sympy/core/symbol.py | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/sympy/core/symbol.py b/sympy/core/symbol.py index 20bbf32595e1..c47aba32ea27 100644 --- a/sympy/core/symbol.py +++ b/sympy/core/symbol.py @@ -251,6 +251,7 @@ def __call__(self, *args, **kwargs): _re_var_range = re.compile(r"^(.*?)(\d*):(\d+)$") _re_var_scope = re.compile(r"^(.):(.)$") +_re_var_ranged_scope = re.compile(r"^([^\W\d_]*?)(.):(.)$") _re_var_split = re.compile(r"\s*,\s*|\s+") @@ -360,7 +361,7 @@ def symbols(names, **args): cls = args.pop('cls', Symbol) seq = args.pop('seq', as_seq) - + for name in names: if not name: raise ValueError('missing symbol') @@ -399,6 +400,20 @@ def symbols(names, **args): seq = True continue + match = _re_var_ranged_scope.match(name) + + if match is not None: + name, start, end = match.groups() + + for subname in xrange(ord(start), ord(end) + 1): + symbol = cls(name + chr(subname), **args) + result.append(symbol) + + seq = True + continue + + + raise ValueError( "'%s' is not a valid symbol range specification" % name) From 0e530ae97fa2cb1d1798075b0c25dae07cfede5b Mon Sep 17 00:00:00 2001 From: "mr.Shu" Date: Sun, 30 Dec 2012 09:32:27 +0100 Subject: [PATCH 2/6] added test for new symbols feature --- sympy/core/tests/test_symbol.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/sympy/core/tests/test_symbol.py b/sympy/core/tests/test_symbol.py index 00b9fc052402..47917225c61b 100644 --- a/sympy/core/tests/test_symbol.py +++ b/sympy/core/tests/test_symbol.py @@ -330,6 +330,14 @@ def test_symbols(): assert symbols('a:d,x:z') == (a, b, c, d, x, y, z) assert symbols(('a:d', 'x:z')) == ((a, b, c, d), (x, y, z)) + aa = Symbol('aa') + ab = Symbol('ab') + ac = Symbol('ac') + ad = Symbol('ad') + + assert symbols('aa:d') == (aa, ab, ac, ad) + assert symbols('aa:d,x:z') == (aa, ab, ac, ad, x, y, z) + assert symbols(('aa:d','x:z')) == ((aa, ab, ac, ad), (x, y, z)) def test_call(): f = Symbol('f') From 0c60e0131f6116d3fd6ce91bc066e91a1b1ed717 Mon Sep 17 00:00:00 2001 From: "mr.Shu" Date: Sun, 30 Dec 2012 12:35:02 +0100 Subject: [PATCH 3/6] removed trailing whitespace --- sympy/core/symbol.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sympy/core/symbol.py b/sympy/core/symbol.py index c47aba32ea27..08adeab13a84 100644 --- a/sympy/core/symbol.py +++ b/sympy/core/symbol.py @@ -361,7 +361,7 @@ def symbols(names, **args): cls = args.pop('cls', Symbol) seq = args.pop('seq', as_seq) - + for name in names: if not name: raise ValueError('missing symbol') From b5aafeb359ad3a84389df88ebba8cb270f54cd36 Mon Sep 17 00:00:00 2001 From: "mr.Shu" Date: Tue, 1 Jan 2013 20:00:27 +0100 Subject: [PATCH 4/6] fixed symbols issues --- sympy/core/symbol.py | 31 ++++++++++--------------------- 1 file changed, 10 insertions(+), 21 deletions(-) diff --git a/sympy/core/symbol.py b/sympy/core/symbol.py index 08adeab13a84..ad97dd7b160c 100644 --- a/sympy/core/symbol.py +++ b/sympy/core/symbol.py @@ -10,7 +10,7 @@ from sympy.logic.boolalg import Boolean from sympy.utilities.exceptions import SymPyDeprecationWarning -import re +import re, string class Symbol(AtomicExpr, Boolean): @@ -250,8 +250,7 @@ def __call__(self, *args, **kwargs): raise TypeError("'%s' object is not callable" % type(self).__name__) _re_var_range = re.compile(r"^(.*?)(\d*):(\d+)$") -_re_var_scope = re.compile(r"^(.):(.)$") -_re_var_ranged_scope = re.compile(r"^([^\W\d_]*?)(.):(.)$") +_re_var_scope = re.compile(r"^(.*?|)(.):(.)(.*?|)$") _re_var_split = re.compile(r"\s*,\s*|\s+") @@ -391,29 +390,19 @@ def symbols(names, **args): match = _re_var_scope.match(name) if match is not None: - start, end = match.groups() - - for name in xrange(ord(start), ord(end) + 1): - symbol = cls(chr(name), **args) - result.append(symbol) - - seq = True - continue - - match = _re_var_ranged_scope.match(name) - - if match is not None: - name, start, end = match.groups() - - for subname in xrange(ord(start), ord(end) + 1): - symbol = cls(name + chr(subname), **args) + name, start, end, suffix = match.groups() + letters = list(string.letters) + + start = letters.index(start) + end = letters.index(end) + + for subname in xrange(start, end + 1): + symbol = cls(name + letters[subname] + suffix, **args) result.append(symbol) seq = True continue - - raise ValueError( "'%s' is not a valid symbol range specification" % name) From fb216dc6d5039edc0bbae0a30c7554e2d52374b4 Mon Sep 17 00:00:00 2001 From: "mr.Shu" Date: Tue, 1 Jan 2013 20:25:52 +0100 Subject: [PATCH 5/6] removed trailing space --- sympy/core/symbol.py | 1 - 1 file changed, 1 deletion(-) diff --git a/sympy/core/symbol.py b/sympy/core/symbol.py index ad97dd7b160c..01aa5ea6f9b0 100644 --- a/sympy/core/symbol.py +++ b/sympy/core/symbol.py @@ -392,7 +392,6 @@ def symbols(names, **args): if match is not None: name, start, end, suffix = match.groups() letters = list(string.letters) - start = letters.index(start) end = letters.index(end) From f910c1ff3a6e23c992670c12a4c1ce22f0c71186 Mon Sep 17 00:00:00 2001 From: "mr.Shu" Date: Tue, 1 Jan 2013 22:39:50 +0100 Subject: [PATCH 6/6] emulating string.letters for py3 --- sympy/core/symbol.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/sympy/core/symbol.py b/sympy/core/symbol.py index 01aa5ea6f9b0..bd9e0be23672 100644 --- a/sympy/core/symbol.py +++ b/sympy/core/symbol.py @@ -391,7 +391,8 @@ def symbols(names, **args): if match is not None: name, start, end, suffix = match.groups() - letters = list(string.letters) + letters = list(string.ascii_lowercase + string.ascii_uppercase + + string.digits) start = letters.index(start) end = letters.index(end)