Skip to content
This repository was archived by the owner on Feb 1, 2023. It is now read-only.

Commit 9d4f2d1

Browse files
author
Release Manager
committed
Trac #31140: use ⨂ for unicode of tensor symbol
URL: https://trac.sagemath.org/31140 Reported by: chapoton Ticket author(s): Frédéric Chapoton Reviewer(s): Travis Scrimshaw
2 parents 5a4ad12 + 191b830 commit 9d4f2d1

File tree

4 files changed

+38
-25
lines changed

4 files changed

+38
-25
lines changed

src/sage/categories/signed_tensor.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,21 @@
1+
# -*- coding: utf-8 -*-
12
"""
23
Signed Tensor Product Functorial Construction
34
45
AUTHORS:
56
67
- Travis Scrimshaw (2019-07): initial version
78
"""
8-
#*****************************************************************************
9+
# ****************************************************************************
910
# Copyright (C) 2019 Travis Scrimshaw <tcscrims at gamil.com>
1011
#
1112
# Distributed under the terms of the GNU General Public License (GPL)
1213
# http://www.gnu.org/licenses/
13-
#*****************************************************************************
14+
# ****************************************************************************
1415

1516
from sage.categories.covariant_functorial_construction import CovariantFunctorialConstruction, CovariantConstructionCategory
1617

18+
1719
class SignedTensorProductFunctor(CovariantFunctorialConstruction):
1820
"""
1921
A singleton class for the signed tensor functor.
@@ -53,6 +55,7 @@ class SignedTensorProductFunctor(CovariantFunctorialConstruction):
5355
_functor_name = "tensor"
5456
_functor_category = "SignedTensorProducts"
5557
symbol = " # "
58+
unicode_symbol = " ⨂ "
5659

5760
def _repr_(self):
5861
"""
@@ -66,8 +69,10 @@ def _repr_(self):
6669
# default _repr_
6770
return "The signed tensor functorial construction"
6871

72+
6973
tensor_signed = SignedTensorProductFunctor()
7074

75+
7176
class SignedTensorProductsCategory(CovariantConstructionCategory):
7277
r"""
7378
An abstract base class for all SignedTensorProducts's categories.
@@ -112,4 +117,3 @@ def base(self):
112117
Integer Ring
113118
"""
114119
return self.base_category().base()
115-

src/sage/categories/tensor.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,21 @@
1+
# -*- coding: utf-8 -*-
12
"""
23
Tensor Product Functorial Construction
34
45
AUTHORS:
56
6-
- Nicolas M. Thiery (2008-2010): initial revision and refactorization
7+
- Nicolas M. Thiéry (2008-2010): initial revision and refactorization
78
"""
8-
#*****************************************************************************
9-
# Copyright (C) 2008-2010 Nicolas M. Thiery <nthiery at users.sf.net>
9+
# ****************************************************************************
10+
# Copyright (C) 2008-2010 Nicolas M. Thiéry <nthiery at users.sf.net>
1011
#
1112
# Distributed under the terms of the GNU General Public License (GPL)
12-
# http://www.gnu.org/licenses/
13-
#*****************************************************************************
13+
# https://www.gnu.org/licenses/
14+
# ****************************************************************************
1415

1516
from sage.categories.covariant_functorial_construction import CovariantFunctorialConstruction, CovariantConstructionCategory
1617

18+
1719
class TensorProductFunctor(CovariantFunctorialConstruction):
1820
"""
1921
A singleton class for the tensor functor.
@@ -48,8 +50,12 @@ class TensorProductFunctor(CovariantFunctorialConstruction):
4850
_functor_name = "tensor"
4951
_functor_category = "TensorProducts"
5052
symbol = " # "
53+
unicode_symbol = " ⨂ "
54+
5155

5256
tensor = TensorProductFunctor()
57+
58+
5359
"""
5460
The tensor product functorial construction
5561
@@ -61,6 +67,7 @@ class TensorProductFunctor(CovariantFunctorialConstruction):
6167
The tensor functorial construction
6268
"""
6369

70+
6471
class TensorProductsCategory(CovariantConstructionCategory):
6572
r"""
6673
An abstract base class for all TensorProducts's categories
@@ -102,4 +109,3 @@ def base(self):
102109
Integer Ring
103110
"""
104111
return self.base_category().base()
105-

src/sage/combinat/free_module.py

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ def element_class(self):
351351
'sage.combinat.free_module'
352352
"""
353353
return self.__make_element_class__(self.Element,
354-
name="%s.element_class"%self.__class__.__name__,
354+
name="%s.element_class" % self.__class__.__name__,
355355
module=self.__class__.__module__,
356356
inherit=True)
357357

@@ -669,7 +669,7 @@ def _element_constructor_(self, x):
669669
if x == 0:
670670
return self.zero()
671671
else:
672-
raise TypeError("do not know how to make x (= %s) an element of %s"%(x, self))
672+
raise TypeError("do not know how to make x (= %s) an element of %s" % (x, self))
673673
#x is an element of the basis enumerated set;
674674
# This is a very ugly way of testing this
675675
elif ((hasattr(self._indices, 'element_class') and
@@ -685,7 +685,7 @@ def _element_constructor_(self, x):
685685
return self._coerce_end(x)
686686
except TypeError:
687687
pass
688-
raise TypeError("do not know how to make x (= %s) an element of self (=%s)"%(x,self))
688+
raise TypeError("do not know how to make x (= %s) an element of self (=%s)" % (x, self))
689689

690690
def _convert_map_from_(self, S):
691691
"""
@@ -1297,21 +1297,20 @@ def __classcall_private__(cls, modules, **options):
12971297
options['category'] = options['category'].FiniteDimensional()
12981298
return super(CombinatorialFreeModule.Tensor, cls).__classcall__(cls, modules, **options)
12991299

1300-
13011300
def __init__(self, modules, **options):
13021301
"""
13031302
TESTS::
13041303
13051304
sage: F = CombinatorialFreeModule(ZZ, [1,2]); F
13061305
F
13071306
"""
1308-
from sage.categories.tensor import tensor
13091307
self._sets = modules
13101308
indices = CartesianProduct_iters(*[module.basis().keys()
13111309
for module in modules]).map(tuple)
13121310
CombinatorialFreeModule.__init__(self, modules[0].base_ring(), indices, **options)
13131311
# the following is not the best option, but it's better than nothing.
1314-
self._print_options['tensor_symbol'] = options.get('tensor_symbol', tensor.symbol)
1312+
if 'tensor_symbol' in options:
1313+
self._print_options['tensor_symbol'] = options['tensor_symbol']
13151314

13161315
def _repr_(self):
13171316
r"""
@@ -1381,7 +1380,7 @@ def _unicode_art_(self, term):
13811380
sage: R = NonCommutativeSymmetricFunctions(QQ).R()
13821381
sage: Partitions.options(diagram_str="#", convention="french")
13831382
sage: s = unicode_art(tensor((R[1,2], R[3,1,2]))); s
1384-
R # R
1383+
R R
13851384
┌┐ ┌┬┬┐
13861385
├┼┐ └┴┼┤
13871386
└┴┘ ├┼┐
@@ -1395,9 +1394,9 @@ def _unicode_art_(self, term):
13951394
if hasattr(self, "_print_options"):
13961395
symb = self._print_options['tensor_symbol']
13971396
if symb is None:
1398-
symb = tensor.symbol
1397+
symb = tensor.unicode_symbol
13991398
else:
1400-
symb = tensor.symbol
1399+
symb = tensor.unicode_symbol
14011400
return unicode_art(*(module._unicode_art_term(t)
14021401
for module, t in zip(self._sets, term)),
14031402
sep=UnicodeArt([symb], breakpoints=[len(symb)]))
@@ -1495,10 +1494,11 @@ def tensor_constructor(self, modules):
14951494
# a list l such that l[i] is True if modules[i] is readily a tensor product
14961495
is_tensor = [isinstance(module, CombinatorialFreeModule_Tensor) for module in modules]
14971496
# the tensor_constructor, on basis elements
1498-
result = self.monomial * CartesianProductWithFlattening(is_tensor) #.
1497+
result = self.monomial * CartesianProductWithFlattening(is_tensor)
14991498
# TODO: make this into an element of Hom( A x B, C ) when those will exist
1500-
for i in range(0, len(modules)):
1501-
result = modules[i]._module_morphism(result, position = i, codomain = self)
1499+
for i in range(len(modules)):
1500+
result = modules[i]._module_morphism(result, position=i,
1501+
codomain=self)
15021502
return result
15031503

15041504
def _tensor_of_elements(self, elements):
@@ -1593,6 +1593,7 @@ def _coerce_map_from_(self, R):
15931593

15941594
return super(CombinatorialFreeModule_Tensor, self)._coerce_map_from_(R)
15951595

1596+
15961597
class CartesianProductWithFlattening(object):
15971598
"""
15981599
A class for Cartesian product constructor, with partial flattening
@@ -1754,7 +1755,7 @@ def cartesian_embedding(self, i):
17541755
"""
17551756
assert i in self._sets_keys()
17561757
return self._sets[i]._module_morphism(lambda t: self.monomial((i, t)),
1757-
codomain = self)
1758+
codomain=self)
17581759

17591760
summand_embedding = cartesian_embedding
17601761

@@ -1785,7 +1786,7 @@ def cartesian_projection(self, i):
17851786
"""
17861787
assert i in self._sets_keys()
17871788
module = self._sets[i]
1788-
return self._module_morphism(lambda j_t: module.monomial(j_t[1]) if i == j_t[0] else module.zero(), codomain = module)
1789+
return self._module_morphism(lambda j_t: module.monomial(j_t[1]) if i == j_t[0] else module.zero(), codomain=module)
17891790

17901791
summand_projection = cartesian_projection
17911792

@@ -1831,4 +1832,5 @@ def cartesian_factors(self):
18311832
class Element(CombinatorialFreeModule.Element): # TODO: get rid of this inheritance
18321833
pass
18331834

1835+
18341836
CombinatorialFreeModule.CartesianProduct = CombinatorialFreeModule_CartesianProduct

src/sage/structure/indexed_generators.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,13 @@ class IndexedGenerators(object):
7373
7474
- ``tensor_symbol`` -- string or ``None`` (default: ``None``),
7575
string to use for tensor product in the print representation. If
76-
``None``, use ``sage.categories.tensor.symbol``.
76+
``None``, use ``sage.categories.tensor.symbol`` and
77+
``sage.categories.tensor.unicode_symbol``.
7778
7879
- ``sorting_key`` -- a key function (default: ``lambda x: x``),
7980
to use for sorting elements in the output of elements
8081
81-
- ``sorting_reverse`` -- bool (default: ``False``), if ``True``
82+
- ``sorting_reverse`` -- bool (default: ``False``), if ``True``
8283
sort elements in reverse order in the output of elements
8384
8485
- ``string_quotes`` -- bool (default: ``True``), if ``True`` then

0 commit comments

Comments
 (0)