Ticket #9370: trac_9370-module-elt-repr-third.v2.patch

File trac_9370-module-elt-repr-third.v2.patch, 9.8 KB (added by jhpalmieri, 10 years ago)

apply on top of other two patches instead of ...-third.patch

  • sage/combinat/combinatorial_algebra.py

    # HG changeset patch
    # User J. H. Palmieri <palmieri@math.washington.edu>
    # Date 1299818519 28800
    # Node ID d1c9635ef70597f46e5058f9dfb7b58cc5f79748
    # Parent  e523dcbab916dfe69dc1522d299129c93289934a
    #9370: third patch
    
    diff -r e523dcbab916 -r d1c9635ef705 sage/combinat/combinatorial_algebra.py
    a b symmetric functions. 
    4141The important things to define are ._basis_keys which
    4242specifies the combinatorial class that indexes the basis elements,
    4343._one which specifies the identity element in the algebra, ._name
    44 which specifies the name of the algebra, ps.print_options is used to set
     44which specifies the name of the algebra, .print_options is used to set
    4545the print options for the elements, and finally a _multiply
    46 or _multiply basis method that defines the multiplication in the
     46or _multiply_basis method that defines the multiplication in the
    4747algebra.
    4848"""
    4949#*****************************************************************************
  • sage/combinat/free_module.py

    diff -r e523dcbab916 -r d1c9635ef705 sage/combinat/free_module.py
    a b class CombinatorialFreeModuleElement(Ele 
    189189            v.sort()
    190190        except StandardError: # Sorting the output is a plus, but if we can't, no big deal
    191191            pass
    192         latex_prefix = self.parent()._print_options.get('latex_prefix')
    193         latex_term = self.parent()._latex_term
     192
     193        alg = self.parent()
     194        latex_term = alg._latex_term
    194195        v = [ (latex_term(m), x) for (m, x) in v ]
    195196        if v:
    196197            mons, cffs = zip(*v)
    197198        else:
    198199            mons = cffs = []
    199         ast = self.parent()._print_options.get('latex_scalar_mult')
     200        ast = alg._print_options.get('latex_scalar_mult')
    200201        if ast is None:
    201             ast = self.parent()._print_options.get('scalar_mult')
     202            ast = alg._print_options.get('scalar_mult')
    202203            if ast == '*':
    203204                ast = ''
    204205        ast_replace = ast if ast else ''
    class CombinatorialFreeModule(UniqueRepr 
    752753      module (optional, default 'B').  With the default, a monomial
    753754      indexed by 'a' would be printed as ``B['a']``.
    754755
    755     - ``latex_prefix`` - string, prefix used in the LaTeX
    756       representation of elements (optional, default same value as
    757       ``prefix``).  With the default, a monomial indexed by 'a' would
    758       be printed as ``B_{a}``.  If this is the empty string, then
     756    - ``latex_prefix`` - string or None, prefix used in the LaTeX
     757      representation of elements (optional, default None). If this is
     758      anything except the empty string, it prints the index as a
     759      subscript.  If this is None, it uses the setting for ``prefix``,
     760      so if ``prefix`` is set to "B", then a monomial indexed by 'a'
     761      would be printed as ``B_{a}``.  If this is the empty string, then
    759762      don't print monomials as subscripts: the monomial indexed by 'a'
    760763      would be printed as ``a``, or as ``[a]`` if ``latex_bracket`` is
    761764      True.
    class CombinatorialFreeModule(UniqueRepr 
    791794    - ``scalar_mult`` - string to use for scalar multiplication in
    792795      the print representation (optional, default "*")
    793796
     797    - ``latex_scalar_mult`` - string or None (optional, default None),
     798      string to use for scalar multiplication in the latex
     799      representation.  If None, use the empty string if ``scalar_mult``
     800      is set to "*", otherwise use the value of ``scalar_mult``.
     801
     802    - ``tensor_symbol`` - string or None (optional, default None),
     803      string to use for tensor product in the print representation. If
     804      None, use the ``sage.categories.tensor.symbol``.
     805
    794806    These print options may also be accessed and modified using the
    795807    :meth:`print_options` method, after the module has been defined.
    796808
    class CombinatorialFreeModule(UniqueRepr 
    10191031
    10201032        self._order = None
    10211033
    1022         # printing options for elements.
    1023         # (set when initializing self) and self._repr_option_bracket
    1024         # (declared to be True by default, needs to be overridden
    1025         # explicitly).
     1034        # printing options for elements (set when initializing self).
     1035        # This includes self._repr_option_bracket (kept for backwards
     1036        # compatibility, declared to be True by default, needs to be
     1037        # overridden explicitly).
    10261038        self._print_options = {}
    10271039        self._print_options['prefix'] = prefix
    10281040        # 'bracket': its default value here is None, meaning that
    class CombinatorialFreeModule(UniqueRepr 
    10341046        # using 'bracket' instead of _repr_option_bracket.
    10351047        self._print_options['bracket'] = kwds.get('bracket', None)
    10361048        self._print_options['latex_bracket'] = kwds.get('latex_bracket', False)
    1037         self._print_options['latex_prefix'] = kwds.get('latex_prefix', prefix)
     1049        self._print_options['latex_prefix'] = kwds.get('latex_prefix', None)
    10381050        self._print_options['scalar_mult'] = kwds.get('scalar_mult', "*")
    10391051        self._print_options['latex_scalar_mult'] = kwds.get('latex_scalar_mult', None)
     1052        self._print_options['tensor_symbol'] = kwds.get('tensor_symbol', None)
    10401053
    10411054    # mostly for backward compatibility
    10421055    @lazy_attribute
    class CombinatorialFreeModule(UniqueRepr 
    14081421        - ``bracket``
    14091422        - ``latex_bracket``
    14101423        - ``scalar_mult``
     1424        - ``latex_scalar_mult``
    14111425        - ``tensor_symbol``
    14121426
    14131427        See the documentation for :class:`CombinatorialFreeModule` for
    class CombinatorialFreeModule(UniqueRepr 
    14211435
    14221436            sage: F = CombinatorialFreeModule(ZZ, [1,2,3], prefix='x')
    14231437            sage: F.print_options()
    1424             {'latex_prefix': 'x', 'scalar_mult': '*', 'prefix': 'x', 'bracket': None, 'latex_bracket': False, 'latex_scalar_mult': None}
     1438            {'latex_prefix': None, 'scalar_mult': '*', 'prefix': 'x', 'bracket': None, 'latex_bracket': False, 'latex_scalar_mult': None, 'tensor_symbol': None}
    14251439            sage: F.print_options(bracket='(')
    14261440            sage: F.print_options()
    1427             {'latex_prefix': 'x', 'scalar_mult': '*', 'prefix': 'x', 'bracket': '(', 'latex_bracket': False, 'latex_scalar_mult': None}
     1441            {'latex_prefix': None, 'scalar_mult': '*', 'prefix': 'x', 'bracket': '(', 'latex_bracket': False, 'latex_scalar_mult': None, 'tensor_symbol': None}
    14281442        """
    14291443        # don't just use kwds.get(...) because I want to distinguish
    14301444        # between an argument like "option=None" and the option not
    class CombinatorialFreeModule(UniqueRepr 
    14321446        args = False
    14331447
    14341448        for option in kwds:
    1435             if option in ['prefix','latex_prefix', 'bracket', 'latex_bracket',
    1436                        'scalar_mult', 'latex_scalar_mult', 'tensor_symbol']:
     1449            if option in ['prefix', 'latex_prefix', 'bracket', 'latex_bracket',
     1450                          'scalar_mult', 'latex_scalar_mult', 'tensor_symbol']:
    14371451                args = True
    14381452                self._print_options[option] = kwds[option]
    14391453            else:
    1440                 raise ValueError, 'The input option is not a valid print option.'
    1441 
     1454                raise ValueError, '%s is not a valid print option.' % option
    14421455        if not args:
    14431456            return self._print_options
    14441457        return
    class CombinatorialFreeModule(UniqueRepr 
    16081621        else:
    16091622            left = bracket
    16101623            right = bracket
    1611         prefix = self._print_options.get('latex_prefix', self.prefix())
     1624        prefix = self._print_options.get('latex_prefix')
     1625        if prefix is None:
     1626            prefix = self._print_options.get('prefix')
    16121627        if prefix == "":
    16131628            return left + s + right
    16141629        return "%s_{%s}" % (prefix, s)
    class CombinatorialFreeModule_Tensor(Com 
    20722087            from sage.categories.tensor import tensor
    20732088            if hasattr(self, "_print_options"):
    20742089                symb = self._print_options['tensor_symbol']
     2090                if symb is None:
     2091                    symb = tensor.symbol
    20752092            else:
    20762093                symb = tensor.symbol
    20772094            return symb.join(["%s"%module for module in self._sets])
    class CombinatorialFreeModule_Tensor(Com 
    21102127            from sage.categories.tensor import tensor
    21112128            if hasattr(self, "_print_options"):
    21122129                symb = self._print_options['tensor_symbol']
     2130                if symb is None:
     2131                    symb = tensor.symbol
    21132132            else:
    21142133                symb = tensor.symbol
    21152134            return symb.join(module._repr_term(t) for (module, t) in zip(self._sets, term))
  • sage/misc/misc.py

    diff -r e523dcbab916 -r d1c9635ef705 sage/misc/misc.py
    a b def repr_lincomb(symbols, coeffs, is_lat 
    680680    - ``symbols`` -- list of symbols
    681681    - ``coeffs`` -- list of coefficients of the symbols
    682682    - ``scalar_mult`` -- (default:'*') string representing the multiplication
    683     - `` latex_scalar_mult`` -- (default:None) None or string representing the multiplication in latex
    684                                 if None and the scalar_mult is '*': empty string '' is used
    685                                 if None and the scaler_mult is not '*': scalar_mult string is used
    686                                 otherwise: latex_scalar_mult is used
     683    - ``latex_scalar_mult`` -- (default:None) None or a string representing
     684      the multiplication in latex
     685
     686        - if None and ``scalar_mult`` is '*', the empty string '' is used
     687        - if None and ``scalar_mult`` is not '*', ``scalar_mult`` is used
     688        - otherwise: ``latex_scalar_mult`` is used
    687689
    688690    OUTPUT:
    689691
    def repr_lincomb(symbols, coeffs, is_lat 
    691693
    692694    EXAMPLES:
    693695
    694     - examples without scalar_mult or latex_scaler_mult::
     696    - examples without scalar_mult or latex_scalar_mult::
    695697
    696698        sage: repr_lincomb(['a','b','c'], [1,2,3])
    697699        'a + 2*b + 3*c'