Skip to content
This repository has been archived by the owner on Jan 30, 2023. It is now read-only.

Commit

Permalink
Merge #30229
Browse files Browse the repository at this point in the history
  • Loading branch information
mkoeppe committed Sep 2, 2022
2 parents ebc98d4 + 644933a commit a7c79de
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 13 deletions.
79 changes: 70 additions & 9 deletions src/sage/tensor/modules/finite_rank_free_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,11 @@ class :class:`~sage.modules.free_module.FreeModule_generic`
AUTHORS:
- Eric Gourgoulhon, Michal Bejger (2014-2015): initial version
- Travis Scrimshaw (2016): category set to Modules(ring).FiniteDimensional()
- Travis Scrimshaw (2016): category set to ``Modules(ring).FiniteDimensional()``
(:trac:`20770`)
- Michael Jung (2019): improve treatment of the zero element
- Eric Gourgoulhon (2021): unicode symbols for tensor and exterior products
- Matthias Koeppe (2022): ``FiniteRankFreeModule_abstract``, symmetric powers
REFERENCES:
Expand Down Expand Up @@ -519,16 +520,19 @@ class :class:`~sage.modules.free_module.FreeModule_generic`
[2, 0, -5]
"""
#******************************************************************************
# Copyright (C) 2015-2021 Eric Gourgoulhon <eric.gourgoulhon@obspm.fr>
# Copyright (C) 2015 Michal Bejger <bejger@camk.edu.pl>
# Copyright (C) 2016 Travis Scrimshaw <tscrimsh@umn.edu>
# ******************************************************************************
# Copyright (C) 2014-2021 Eric Gourgoulhon <eric.gourgoulhon@obspm.fr>
# 2014-2016 Travis Scrimshaw <tscrimsh@umn.edu>
# 2015 Michal Bejger <bejger@camk.edu.pl>
# 2016 Frédéric Chapoton
# 2020 Michael Jung
# 2020-2022 Matthias Koeppe
#
# Distributed under the terms of the GNU General Public License (GPL)
# as published by the Free Software Foundation; either version 2 of
# the License, or (at your option) any later version.
# https://www.gnu.org/licenses/
#******************************************************************************
# ******************************************************************************
from __future__ import annotations

from typing import Generator, Optional
Expand Down Expand Up @@ -645,13 +649,70 @@ def tensor_product(self, *others):
sage: M.tensor_module(1,1).tensor_product(M.tensor_module(1,2))
Free module of type-(2,3) tensors on the 2-dimensional vector space over the Rational Field
sage: Sym2M = M.tensor_module(2, 0, sym=range(2)); Sym2M
Free module of fully symmetric type-(2,0) tensors on the 2-dimensional vector space over the Rational Field
sage: Sym01x23M = Sym2M.tensor_product(Sym2M); Sym01x23M
Free module of type-(4,0) tensors on the 2-dimensional vector space over the Rational Field,
with symmetry on the index positions (0, 1), with symmetry on the index positions (2, 3)
sage: Sym01x23M._index_maps
((0, 1), (2, 3))
sage: N = M.tensor_module(3, 3, sym=[1, 2], antisym=[3, 4]); N
Free module of type-(3,3) tensors on the 2-dimensional vector space over the Rational Field,
with symmetry on the index positions (1, 2),
with antisymmetry on the index positions (3, 4)
sage: NxN = N.tensor_product(N); NxN
Free module of type-(6,6) tensors on the 2-dimensional vector space over the Rational Field,
with symmetry on the index positions (1, 2), with symmetry on the index positions (4, 5),
with antisymmetry on the index positions (6, 7), with antisymmetry on the index positions (9, 10)
sage: NxN._index_maps
((0, 1, 2, 6, 7, 8), (3, 4, 5, 9, 10, 11))
"""
from sage.modules.free_module_element import vector
from .comp import CompFullySym, CompFullyAntiSym, CompWithSym

base_module = self.base_module()
if not all(module.base_module() == base_module for module in others):
raise NotImplementedError('all factors must be tensor modules over the same base module')
tensor_type = sum(vector(module.tensor_type()) for module in [self] + list(others))
return base_module.tensor_module(*tensor_type)
factors = [self] + list(others)
result_tensor_type = sum(vector(factor.tensor_type()) for factor in factors)
index_maps = []
running_indices = vector([0, result_tensor_type[0]])
result_sym = []
result_antisym = []
for factor in factors:
tensor_type = factor.tensor_type()
index_map = tuple(i + running_indices[0] for i in range(tensor_type[0]))
index_map += tuple(i + running_indices[1] for i in range(tensor_type[1]))
index_maps.append(index_map)

if tensor_type[0] + tensor_type[1] > 1:
basis_sym = factor._basis_sym()
all_indices = tuple(range(tensor_type[0] + tensor_type[1]))
if isinstance(basis_sym, CompFullySym):
sym = [all_indices]
antisym = []
elif isinstance(basis_sym, CompFullyAntiSym):
sym = []
antisym = [all_indices]
elif isinstance(basis_sym, CompWithSym):
sym = basis_sym._sym
antisym = basis_sym._antisym
else:
sym = antisym = []

def map_isym(isym):
return tuple(index_map[i] for i in isym)

result_sym.extend(tuple(index_map[i] for i in isym) for isym in sym)
result_antisym.extend(tuple(index_map[i] for i in isym) for isym in antisym)

running_indices += vector(tensor_type)

result = base_module.tensor_module(*result_tensor_type,
sym=result_sym, antisym=result_antisym)
result._index_maps = tuple(index_maps)
return result

def rank(self) -> int:
r"""
Expand Down Expand Up @@ -760,7 +821,7 @@ def is_submodule(self, other):
EXAMPLES::
sage: M = FiniteRankFreeModule(ZZ, 3, name='M')
sage: N = FiniteRankFreeModule(ZZ, 4, name='M')
sage: N = FiniteRankFreeModule(ZZ, 4, name='N')
sage: M.is_submodule(M)
True
sage: M.is_submodule(N)
Expand Down
8 changes: 6 additions & 2 deletions src/sage/tensor/modules/tensor_free_submodule.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
r"""
Free submodules of tensor modules defined by monoterm symmetries
AUTHORS:
- Matthias Koeppe (2020-2022): initial version
"""

#******************************************************************************
# ******************************************************************************
# Copyright (C) 2020-2022 Matthias Koeppe
#
# Distributed under the terms of the GNU General Public License (GPL)
# as published by the Free Software Foundation; either version 2 of
# the License, or (at your option) any later version.
# http://www.gnu.org/licenses/
#******************************************************************************
# ******************************************************************************

import itertools

Expand Down
8 changes: 6 additions & 2 deletions src/sage/tensor/modules/tensor_free_submodule_basis.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
r"""
Standard bases of free submodules of tensor modules defined by some monoterm symmetries
AUTHORS:
- Matthias Koeppe (2020-2022): initial version
"""

#******************************************************************************
# ******************************************************************************
# Copyright (C) 2020-2022 Matthias Koeppe
#
# Distributed under the terms of the GNU General Public License (GPL)
# as published by the Free Software Foundation; either version 2 of
# the License, or (at your option) any later version.
# http://www.gnu.org/licenses/
#******************************************************************************
# ******************************************************************************

from sage.tensor.modules.free_module_basis import Basis_abstract

Expand Down

0 comments on commit a7c79de

Please sign in to comment.