Indexed Generators¶
- class sage.structure.indexed_generators.IndexedGenerators(indices, prefix='x', **kwds)[source]¶
- Bases: - object- Abstract base class for parents whose elements consist of generators indexed by an arbitrary set. - Options controlling the printing of elements: - prefix– string, prefix used for printing elements of this module (default:- 'x'). With the default, a monomial indexed by ‘a’ would be printed as- x['a'].
- latex_prefix– string or- None, prefix used in the \(\LaTeX\) representation of elements (default:- None); if this is anything except the empty string, it prints the index as a subscript. If this is- None, it uses the setting for- prefix, so if- prefixis set to “B”, then a monomial indexed by ‘a’ would be printed as- B_{a}. If this is the empty string, then don’t print monomials as subscripts: the monomial indexed by ‘a’ would be printed as- a, or as- [a]if- latex_bracketis- True.
- names– dictionary with strings as values or list of strings (optional); a mapping from the indices of the generators to strings giving the generators explicit names. This is used instead of the print options- prefixand- bracketwhen- namesis specified.
- latex_names– dictionary with strings as values or list of strings (optional); same as- namesexcept using the \(\LaTeX\) representation
- bracket–- None, boolean, string, or list or tuple of strings (default:- None); if- None, use the value of the attribute- self._repr_option_bracket, which has default value- True. (- self._repr_option_bracketis available for backwards compatibility. Users should set- bracketinstead. If- bracketis set to anything except- None, it overrides the value of- self._repr_option_bracket.) If- False, do not include brackets when printing elements: a monomial indexed by ‘a’ would be printed as- B'a', and a monomial indexed by (1,2,3) would be printed as- B(1,2,3). If- True, use “[” and “]” as brackets. If it is one of “[”, “(”, or “{”, use it and its partner as brackets. If it is any other string, use it as both brackets. If it is a list or tuple of strings, use the first entry as the left bracket and the second entry as the right bracket.
- latex_bracket– boolean, string, or list or tuple of strings (default:- False); if- False, do not include brackets in the LaTeX representation of elements. This option is only relevant if- latex_prefixis the empty string; otherwise, brackets are not used regardless. If- True, use “left[” and “right]” as brackets. If this is one of “[”, “(”, “\{”, “|”, or “||”, use it and its partner, prepended with “left” and “right”, as brackets. If this is any other string, use it as both brackets. If this is a list or tuple of strings, use the first entry as the left bracket and the second entry as the right bracket.
- scalar_mult– string to use for scalar multiplication in the print representation (default:- '*')
- latex_scalar_mult– string or- None(default:- None); string to use for scalar multiplication in the latex representation. If- None, use the empty string if- scalar_multis set to “*”, otherwise use the value of- scalar_mult.
- tensor_symbol– string or- None(default:- None); string to use for tensor product in the print representation. If- None, use- sage.categories.tensor.symboland- sage.categories.tensor.unicode_symbol.
- sorting_key– a key function (default:- lambda x: x); to use for sorting elements in the output of elements
- sorting_reverse– boolean (default:- False); if- Truesort elements in reverse order in the output of elements
- string_quotes– boolean (default:- True); if- Truethen display string indices with quotes
- iterate_key– boolean (default:- False); iterate through the elements of the key and print the result as comma separated objects for string output
 - Note - These print options may also be accessed and modified using the - print_options()method, after the parent has been defined.- EXAMPLES: - We demonstrate a variety of the input options: - sage: from sage.structure.indexed_generators import IndexedGenerators sage: I = IndexedGenerators(ZZ, prefix='A') sage: I._repr_generator(2) 'A[2]' sage: I._latex_generator(2) 'A_{2}' sage: I = IndexedGenerators(ZZ, bracket='(') sage: I._repr_generator(2) 'x(2)' sage: I._latex_generator(2) 'x_{2}' sage: I = IndexedGenerators(ZZ, prefix='', latex_bracket='(') sage: I._repr_generator(2) '[2]' sage: I._latex_generator(2) \left( 2 \right) sage: I = IndexedGenerators(ZZ, bracket=['|', '>']) sage: I._repr_generator(2) 'x|2>' - >>> from sage.all import * >>> from sage.structure.indexed_generators import IndexedGenerators >>> I = IndexedGenerators(ZZ, prefix='A') >>> I._repr_generator(Integer(2)) 'A[2]' >>> I._latex_generator(Integer(2)) 'A_{2}' >>> I = IndexedGenerators(ZZ, bracket='(') >>> I._repr_generator(Integer(2)) 'x(2)' >>> I._latex_generator(Integer(2)) 'x_{2}' >>> I = IndexedGenerators(ZZ, prefix='', latex_bracket='(') >>> I._repr_generator(Integer(2)) '[2]' >>> I._latex_generator(Integer(2)) \left( 2 \right) >>> I = IndexedGenerators(ZZ, bracket=['|', '>']) >>> I._repr_generator(Integer(2)) 'x|2>' - indices()[source]¶
- Return the indices of - self.- EXAMPLES: - sage: F = CombinatorialFreeModule(QQ, ['a', 'b', 'c']) # needs sage.modules sage: F.indices() # needs sage.modules {'a', 'b', 'c'} - >>> from sage.all import * >>> F = CombinatorialFreeModule(QQ, ['a', 'b', 'c']) # needs sage.modules >>> F.indices() # needs sage.modules {'a', 'b', 'c'} 
 - prefix()[source]¶
- Return the prefix used when displaying elements of - self.- EXAMPLES: - sage: F = CombinatorialFreeModule(QQ, ['a', 'b', 'c']) # needs sage.modules sage: F.prefix() # needs sage.modules 'B' - >>> from sage.all import * >>> F = CombinatorialFreeModule(QQ, ['a', 'b', 'c']) # needs sage.modules >>> F.prefix() # needs sage.modules 'B' - sage: X = SchubertPolynomialRing(QQ) # needs sage.combinat sage.modules sage: X.prefix() # needs sage.combinat sage.modules 'X' - >>> from sage.all import * >>> X = SchubertPolynomialRing(QQ) # needs sage.combinat sage.modules >>> X.prefix() # needs sage.combinat sage.modules 'X' 
 - print_options(**kwds)[source]¶
- Return the current print options, or set an option. - INPUT: - All of the input is optional; if present, it should be in the form of keyword pairs, such as - latex_bracket='('. The allowable keywords are:- prefix
- latex_prefix
- names
- latex_names
- bracket
- latex_bracket
- scalar_mult
- latex_scalar_mult
- tensor_symbol
- string_quotes
- sorting_key
- sorting_reverse
- iterate_key
 - See the documentation for - IndexedGeneratorsfor descriptions of the effects of setting each of these options.- OUTPUT: if the user provides any input, set the appropriate option(s) and return nothing. Otherwise, return the dictionary of settings for print and LaTeX representations. - EXAMPLES: - sage: # needs sage.modules sage: F = CombinatorialFreeModule(ZZ, [1,2,3], prefix='x') sage: F.print_options() {...'prefix': 'x'...} sage: F.print_options(bracket='(') sage: F.print_options() {...'bracket': '('...} - >>> from sage.all import * >>> # needs sage.modules >>> F = CombinatorialFreeModule(ZZ, [Integer(1),Integer(2),Integer(3)], prefix='x') >>> F.print_options() {...'prefix': 'x'...} >>> F.print_options(bracket='(') >>> F.print_options() {...'bracket': '('...} 
 
- sage.structure.indexed_generators.parse_indices_names(names, index_set, prefix, kwds=None)[source]¶
- Parse the names, index set, and prefix input, along with setting default values for keyword arguments - kwds.- OUTPUT: - The triple - (N, I, p):- Nis the tuple of variable names,
- Iis the index set, and
- pis the prefix.
 - This modifies the dictionary - kwds.- Note - When the indices, names, or prefix have not been given, it should be passed to this function as - None.- Note - For handling default prefixes, if the result will be - Noneif it is not processed in this function.- EXAMPLES: - sage: from sage.structure.indexed_generators import parse_indices_names sage: d = {} sage: parse_indices_names('x,y,z', ZZ, None, d) (('x', 'y', 'z'), Integer Ring, None) sage: d {} sage: d = {} sage: parse_indices_names('x,y,z', None, None, d) (('x', 'y', 'z'), {'x', 'y', 'z'}, '') sage: d {'string_quotes': False} sage: d = {} sage: parse_indices_names(None, ZZ, None, d) (None, Integer Ring, None) sage: d {} - >>> from sage.all import * >>> from sage.structure.indexed_generators import parse_indices_names >>> d = {} >>> parse_indices_names('x,y,z', ZZ, None, d) (('x', 'y', 'z'), Integer Ring, None) >>> d {} >>> d = {} >>> parse_indices_names('x,y,z', None, None, d) (('x', 'y', 'z'), {'x', 'y', 'z'}, '') >>> d {'string_quotes': False} >>> d = {} >>> parse_indices_names(None, ZZ, None, d) (None, Integer Ring, None) >>> d {} - sage: d = {'string_quotes':True, 'bracket':'['} sage: parse_indices_names(['a','b','c'], ZZ, 'x', d) (('a', 'b', 'c'), Integer Ring, 'x') sage: d {'bracket': '[', 'string_quotes': True} sage: parse_indices_names('x,y,z', None, 'A', d) (('x', 'y', 'z'), {'x', 'y', 'z'}, 'A') sage: d {'bracket': '[', 'string_quotes': True} - >>> from sage.all import * >>> d = {'string_quotes':True, 'bracket':'['} >>> parse_indices_names(['a','b','c'], ZZ, 'x', d) (('a', 'b', 'c'), Integer Ring, 'x') >>> d {'bracket': '[', 'string_quotes': True} >>> parse_indices_names('x,y,z', None, 'A', d) (('x', 'y', 'z'), {'x', 'y', 'z'}, 'A') >>> d {'bracket': '[', 'string_quotes': True} 
- sage.structure.indexed_generators.split_index_keywords(kwds)[source]¶
- Split the dictionary - kwdsinto two dictionaries, one containing keywords for- IndexedGenerators, and the other is everything else.- OUTPUT: - The dictionary containing only they keywords for - IndexedGenerators. This modifies the dictionary- kwds.- Warning - This modifies the input dictionary - kwds.- EXAMPLES: - sage: from sage.structure.indexed_generators import split_index_keywords sage: d = {'string_quotes': False, 'bracket': None, 'base': QQ} sage: split_index_keywords(d) {'bracket': None, 'string_quotes': False} sage: d {'base': Rational Field} - >>> from sage.all import * >>> from sage.structure.indexed_generators import split_index_keywords >>> d = {'string_quotes': False, 'bracket': None, 'base': QQ} >>> split_index_keywords(d) {'bracket': None, 'string_quotes': False} >>> d {'base': Rational Field} 
- sage.structure.indexed_generators.standardize_names_index_set(names=None, index_set=None, ngens=None)[source]¶
- Standardize the - namesand- index_setinputs.- INPUT: - names– (optional) the variable names
- index_set– (optional) the index set
- ngens– (optional) the number of generators
 - If - ngensis a negative number, then this does not check that the number of variable names matches the size of the index set.- OUTPUT: - A pair - (names_std, index_set_std), where- names_stdis either- Noneor a tuple of strings, and where- index_set_stdis a finite enumerated set. The purpose of- index_set_stdis to index the generators of some object (e.g., the basis of a module); the strings in- names_std, when they exist, are used for printing these indices. The- ngens- If - namescontains exactly one name- Xand- ngensis greater than 1, then- names_stdare- Xifor- iin- range(ngens).