+ try:
+ return self._symbols[n]
+ except KeyError:
+ self._symbols[n] = self._create_symbol_(n)
+ return self._symbols[n]
+
+
+ def _subscript_slice_(self, s):
+ """
+ We were given a slice. Clean up some of its properties
+ 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')
+ sage: a._subscript_slice_(slice(1,3))
+ [a_1, a_2]
+
+ """
+ (start, step) = (s.start, s.step)
+ if start is None:
+ start = 0
+ if s.stop is None:
+ # Would otherwise loop forever since our "length" is
+ # undefined.
+ raise ValueError('You must supply an terminal index')
+ if step is None:
+ step = 1
+
+ # If the user asks for a slice, we'll be returning a list
+ # of symbols.
+ return [ self._subscript_integer_(idx)
+ for idx in range(start, s.stop, step) ]
+
+
+
+ def _subscript_tuple_(self, args):
+ """
+ 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::
+
+ sage: a = SymbolSequence('a')
+ sage: a._subscript_tuple_((1,8))
+ a_1_8
+
+ Nested tuples::
+
+ sage: a._subscript_tuple_(( (1,2), (3,(4,5,6)) ))
+ a_1_2_3_4_5_6
+
+ """
+
+ # We never call this method without an argument.
+ key = args[0]
+ args = args[1:] # Peel off the first arg, which we've called 'key'
+
+ # We don't know the type of 'key', but __getitem__ will figure
+ # it out and dispatch properly.
+ v = self[key]