]> gitweb.michael.orlitzky.com - sage.d.git/blobdiff - mjo/symbol_sequence.py
mjo: replace xrange() with range() for python-3.x compatibility.
[sage.d.git] / mjo / symbol_sequence.py
index cd9e02dc675f0bea6f05d64ba277fab5aa1d8564..563bab6ad4d190f0cbcaa82e428acc6ea86e2ddf 100644 (file)
@@ -1,7 +1,7 @@
 from sage.all import *
 
 class SymbolSequence:
 from sage.all import *
 
 class SymbolSequence:
-    """
+    r"""
     An iterable object which acts like a sequence of symbolic
     expressions (variables).
 
     An iterable object which acts like a sequence of symbolic
     expressions (variables).
 
@@ -20,6 +20,10 @@ class SymbolSequence:
 
     An iterable object containing symbolic expressions.
 
 
     An iterable object containing symbolic expressions.
 
+    SETUP::
+
+        sage: from mjo.symbol_sequence import SymbolSequence
+
     EXAMPLES:
 
     The simplest use case::
     EXAMPLES:
 
     The simplest use case::
@@ -34,7 +38,7 @@ class SymbolSequence:
     degree::
 
         sage: a = SymbolSequence('a')
     degree::
 
         sage: a = SymbolSequence('a')
-        sage: p = sum([ a[i]*x^i for i in range(0,5)])
+        sage: p = sum( a[i]*x^i for i in range(5) )
         sage: p
         a_4*x^4 + a_3*x^3 + a_2*x^2 + a_1*x + a_0
 
         sage: p
         a_4*x^4 + a_3*x^3 + a_2*x^2 + a_1*x + a_0
 
@@ -53,7 +57,7 @@ class SymbolSequence:
         a_0_1_2
         sage: latex(a[0,1,2])
         a_{0}_{1}_{2}
         a_0_1_2
         sage: latex(a[0,1,2])
         a_{0}_{1}_{2}
-        sage: [ a[i,j] for i in range(0,2) for j in range(0,2) ]
+        sage: [ a[i,j] for i in range(2) for j in range(2) ]
         [a_0_0, a_0_1, a_1_0, a_1_1]
 
     You can pass slices instead of integers to obtain a list of
         [a_0_0, a_0_1, a_1_0, a_1_1]
 
     You can pass slices instead of integers to obtain a list of
@@ -117,6 +121,10 @@ class SymbolSequence:
         appropriate name and latex_name before delegating to
         SR.symbol().
 
         appropriate name and latex_name before delegating to
         SR.symbol().
 
+        SETUP::
+
+            sage: from mjo.symbol_sequence import SymbolSequence
+
         EXAMPLES::
 
             sage: a = SymbolSequence('a', 'alpha', 'real')
         EXAMPLES::
 
             sage: a = SymbolSequence('a', 'alpha', 'real')
@@ -147,6 +155,10 @@ class SymbolSequence:
         more than can be said about some of the snappier solutions of
         lore.
 
         more than can be said about some of the snappier solutions of
         lore.
 
+        SETUP::
+
+            sage: from mjo.symbol_sequence import SymbolSequence
+
         EXAMPLES::
 
             sage: a = SymbolSequence('a')
         EXAMPLES::
 
             sage: a = SymbolSequence('a')
@@ -163,9 +175,10 @@ class SymbolSequence:
         result = []
 
         for item in l:
         result = []
 
         for item in l:
-            if isinstance(item, list):
+            try:
+                item = iter(item)
                 result += self._flatten_list_(item)
                 result += self._flatten_list_(item)
-            else:
+            except TypeError:
                 result += [item]
 
         return result
                 result += [item]
 
         return result
@@ -177,6 +190,10 @@ class SymbolSequence:
         tuples. It just hands off the real work to
         self._subscript_foo_().
 
         tuples. It just hands off the real work to
         self._subscript_foo_().
 
+        SETUP::
+
+            sage: from mjo.symbol_sequence import SymbolSequence
+
         EXAMPLES:
 
         An integer argument::
         EXAMPLES:
 
         An integer argument::
@@ -215,6 +232,10 @@ class SymbolSequence:
         The subscript is a single integer, or something that acts like
         one.
 
         The subscript is a single integer, or something that acts like
         one.
 
+        SETUP::
+
+            sage: from mjo.symbol_sequence import SymbolSequence
+
         EXAMPLES::
 
             sage: a = SymbolSequence('a')
         EXAMPLES::
 
             sage: a = SymbolSequence('a')
@@ -239,6 +260,10 @@ class SymbolSequence:
         first. The start/step are default for lists. We make
         copies of these because they're read-only.
 
         first. The start/step are default for lists. We make
         copies of these because they're read-only.
 
+        SETUP::
+
+            sage: from mjo.symbol_sequence import SymbolSequence
+
         EXAMPLES::
 
             sage: a = SymbolSequence('a')
         EXAMPLES::
 
             sage: a = SymbolSequence('a')
@@ -268,6 +293,10 @@ class SymbolSequence:
         When we have more than one level of subscripts, we pick off
         the first one and generate the rest recursively.
 
         When we have more than one level of subscripts, we pick off
         the first one and generate the rest recursively.
 
+        SETUP::
+
+            sage: from mjo.symbol_sequence import SymbolSequence
+
         EXAMPLES:
 
         A simple two-tuple::
         EXAMPLES:
 
         A simple two-tuple::
@@ -300,11 +329,11 @@ class SymbolSequence:
         # corresponding to the second coordinate, with the first
         # coordinate(s) fixed.
         if isinstance(key, slice):
         # corresponding to the second coordinate, with the first
         # coordinate(s) fixed.
         if isinstance(key, slice):
-            ss = [ SymbolSequence(w._repr_(), w._latex_(), self._domain)
-                   for w in v ]
+            ss = ( SymbolSequence(w._repr_(), w._latex_(), self._domain)
+                   for w in v )
 
             # This might be nested...
 
             # This might be nested...
-            maybe_nested_list = [ s._subscript_tuple_(args) for s in ss ]
+            maybe_nested_list = ( s._subscript_tuple_(args) for s in ss )
             return self._flatten_list_(maybe_nested_list)
 
         else:
             return self._flatten_list_(maybe_nested_list)
 
         else: