Commits (1)
 ... ... @@ -32,6 +32,7 @@ import sage.data_structures.blas_dict as blas from sage.typeset.ascii_art import AsciiArt from sage.typeset.unicode_art import UnicodeArt from sage.misc.superseded import deprecation from sage.categories.cartesian_product import cartesian_product import six ... ... @@ -1244,7 +1245,7 @@ class CombinatorialFreeModule_Tensor(CombinatorialFreeModule): The basis of T is indexed by tuples of basis indices of F and G:: sage: T.basis().keys() Image of Cartesian product of {1, 2}, {3, 4} by <... 'tuple'> The Cartesian product of ({1, 2}, {3, 4}) sage: T.basis().keys().list() [(1, 3), (1, 4), (2, 3), (2, 4)] ... ... @@ -1257,6 +1258,11 @@ class CombinatorialFreeModule_Tensor(CombinatorialFreeModule): sage: list(T.basis()) [B[1] # B[3], B[1] # B[4], B[2] # B[3], B[2] # B[4]] sage: T.basis()[(1,4)] B[1] # B[4] sage: T.basis()[(1,4)].coefficient((1,4)) 1 The tensor product is associative and flattens sub tensor products:: sage: H = CombinatorialFreeModule(ZZ, [5,6]); H.rename("H") ... ... @@ -1335,8 +1341,8 @@ class CombinatorialFreeModule_Tensor(CombinatorialFreeModule): """ from sage.categories.tensor import tensor self._sets = modules indices = CartesianProduct_iters(*[module.basis().keys() for module in modules]).map(tuple) indices = cartesian_product([module.basis().keys() for module in modules]) CombinatorialFreeModule.__init__(self, modules[0].base_ring(), indices, **options) # the following is not the best option, but it's better than nothing. self._print_options['tensor_symbol'] = options.get('tensor_symbol', tensor.symbol) ... ... @@ -1567,8 +1573,8 @@ class CombinatorialFreeModule_Tensor(CombinatorialFreeModule): TESTS:: sage: C = CombinatorialFreeModule(ZZ, ZZ) sage: C2 = CombinatorialFreeModule(ZZ, NN) sage: C = CombinatorialFreeModule(ZZ, Set([-2,-1,0,1])) sage: C2 = CombinatorialFreeModule(ZZ, Set([0,1,2])) sage: M = C.module_morphism(lambda x: C2.monomial(abs(x)), codomain=C2) sage: M.register_as_coercion() sage: C2(C.basis()[3]) ... ... @@ -1582,9 +1588,9 @@ class CombinatorialFreeModule_Tensor(CombinatorialFreeModule): sage: S.has_coerce_map_from(S2) False sage: S.an_element() 3*B[0] # B[-1] + 2*B[0] # B[0] + 2*B[0] # B[1] 2*B[0] # B[1] + 3*B[0] # B[-2] + 2*B[0] # B[0] sage: S2(S.an_element()) 2*B[0] # B[0] + 5*B[0] # B[1] 2*B[0] # B[0] + 2*B[0] # B[1] + 3*B[0] # B[2] :: ... ... @@ -1592,15 +1598,15 @@ class CombinatorialFreeModule_Tensor(CombinatorialFreeModule): sage: D = CombinatorialFreeModule(ZZ, Set([2,4])) sage: f = C.module_morphism(on_basis=lambda x: D.monomial(2*x), codomain=D) sage: f.register_as_coercion() sage: T = tensor((C,C)) sage: p = D.an_element() sage: T(tensor((p,p))) sage: TC = tensor((C,C)) sage: d = D.an_element() sage: TC(tensor( (d, d) )) Traceback (most recent call last): ... NotImplementedError sage: T = tensor((D,D)) sage: p = C.an_element() sage: T(tensor((p,p))) TypeError: do not know how to make x (= ...) an element of self (=Free module generated by {1, 2} over Integer Ring # Free module generated by {1, 2} over Integer Ring) sage: TD = tensor((D,D)) sage: c = C.an_element() sage: TD(tensor( (c, c) )) 4*B[2] # B[2] + 4*B[2] # B[4] + 4*B[4] # B[2] + 4*B[4] # B[4] """ if R in ModulesWithBasis(self.base_ring()).TensorProducts() \ ... ...