[sympy] Tensor expressions with canonicalization (#1699)

11 views
Skip to first unread message

pernici

unread,
Dec 20, 2012, 7:33:23 AM12/20/12
to sympy/sympy

It is implemented a tensor class with monoterm canonicalization
and algebraic operations on tensors.

There are two applications:

check of identities involving the cyclic symmetry of the Riemann tensor

>>> from sympy.tensor.tensor import TensorIndexType, tensor_indices, TensorSymmetry, TensorType, riemann_cyclic, riemann_bsgs
>>> Lorentz = TensorIndexType('Lorentz', dummy_fmt='L')
>>> i, j, k, l = tensor_indices('i,j,k,l', Lorentz)
>>> symr = TensorSymmetry(riemann_bsgs)
>>> R4 = TensorType([Lorentz]*4, symr)
>>> R = R4('R')
>>> t = R(i,j,k,l)*(R(-i,-j,-k,-l) - 2*R(-i,-k,-j,-l))
>>> riemann_cyclic(t)
0

gamma matrices in dimensional regularization

>>> from sympy import Symbol, S
>>> from sympy.tensor.tensor import (TensorIndexType, tensor_indices,\
        TensorSymmetry, get_symmetric_group_sgs, TensorType, Tensor)
>>> from sympy.tensor.dgamma_matr import GammaMatrices
>>> D = Symbol('D')
>>> Lorentz = TensorIndexType('Lorentz', dim=D, dummy_fmt='L')
>>> sym1 = TensorSymmetry(get_symmetric_group_sgs(1))
>>> S1 = TensorType([Lorentz], sym1)
>>> GM = GammaMatrices(Lorentz)
>>> gamma_trace = GM.gamma_trace
>>> G = GM.G
>>> m0, m1, m2, m3 = tensor_indices('m0,m1,m2,m3', Lorentz)
>>> gamma_trace(G(m0)*G(m1)*G(-m0)*G(m3))
(-4*D + 8)*metric(m1, m3)

>>> p, q = S1('p,q')
>>> t = G(m0)*G(m1)*G(m2)*G(m3)*p(-m1)*q(-m3)
>>> gamma_trace(t)
-4*metric(m0, m2)*p(L_0)*q(-L_0) + 4*p(m0)*q(m2) + 4*p(m2)*q(m0)

You can merge this Pull Request by running:

  git pull https://github.com/pernici/sympy can3

Or view, comment on, or merge it at:

  https://github.com/sympy/sympy/pull/1699

Commit Summary

  • pep8 tensor_can
  • reformat for sphinx
  • typo edit
  • Fixed a bug in canonicalize; corrected comments in test_tensor_can.py
  • Tensor expressions with canonicalization; riemann_cyclic implements
  • Added is_Tensor in basic.py; modified str.py to print tensors
  • Added metric and dim attributes to TensorIndexType; added contract_me…
  • gamma matrices in dimensional regularization
  • Improved the documentation
  • Tensor expressions with canonicalization
  • Fixed bug in the documentation.

File Changes

  • M doc/src/modules/tensor/index.rst (2)
  • M sympy/combinatorics/tensor_can.py (209)
  • M sympy/combinatorics/tests/test_tensor_can.py (14)
  • M sympy/core/basic.py (1)
  • M sympy/printing/str.py (6)
  • A sympy/tensor/dgamma_matr.py (532)
  • A sympy/tensor/tensor.py (1231)
  • A sympy/tensor/tests/test_dgamma_matr.py (278)
  • A sympy/tensor/tests/test_tensor.py (665)

Patch Links


Reply to this email directly or view it on GitHub.

Matthew Rocklin

unread,
Dec 20, 2012, 8:54:45 AM12/20/12
to sympy/sympy

I would like to review this but won't have time until this weekend. Also, @Krastanov might be interested.

Stefan Krastanov

unread,
Dec 20, 2012, 12:39:00 PM12/20/12
to sympy/sympy

This interests me a lot. I will try to look at it during the weekend.

Stefan Krastanov

unread,
Dec 20, 2012, 12:49:27 PM12/20/12
to sympy/sympy

@pernici, could you consider breaking this in three or more pull requests? It will help a lot with reviewing.

For instance pernici@36cbcd1 seems to be good enough to be a PR on its own. The stuff before it as another PR and the stuff afterwards as a third PR.

Or you can suggest other way to break up this in more manageable pieces.

Julien Rioux

unread,
Dec 20, 2012, 3:06:08 PM12/20/12
to sympy/sympy

SymPy Bot Summary: :red_circle: Failed after merging pernici/can3 (d48be8a) into master (d503614).
@pernici: Please fix the test failures.
:red_circle:PyPy 2.0.0-beta-1; 2.7.3-final-42: fail
:red_circle:Python 2.7.2-final-0: fail
:red_circle:Python 3.2.1-final-0: fail
:red_circle:Sphinx 1.1.3: fail
Docs build command: make clean && make html-errors && make latex && cd _build/latex && xelatex sympy-*.tex

Aaron Meurer

unread,
Dec 20, 2012, 3:09:48 PM12/20/12
to sympy/sympy

In sympy/tensor/tensor.py:

> +from functools import wraps
> +
> +from sympy.core import S, Symbol, sympify, Tuple, Integer, Basic
> +from sympy.core.decorators import call_highest_priority
> +from sympy.core.sympify import SympifyError
> +from sympy.matrices import ShapeError
> +from sympy.simplify import simplify
> +from sympy import cacheit
> +
> +class TensorIndexType(object):
> +    def __init__(self, name, metric_sym=0, dim=None, eps_dim = None,
> +                 dummy_fmt=None):
> +        """
> +        name   name of the tensor type
> +
> +        `metric\_sym`:

Use twoo backticks for variable names.

pernici

unread,
Dec 20, 2012, 5:39:20 PM12/20/12
to sympy/sympy

could you consider breaking this in three or more pull requests? It will help a lot with reviewing.

I have opened a PR #1700 which does not include gamma matrices.

pernici

unread,
Dec 22, 2012, 5:30:03 AM12/22/12
to sympy/sympy

Waiting for review of PR #1700 I update this PR to it, and I keep it open as a WIP PR, to which I plan to add related
things, and as a place for discussion.

Now I will implement the Kronecker delta; currently g(i, -j) behaves as a Kronecker delta, but there are
various reasons to implement it separately; for instance if metric_sym=None there is no metric, but there should
be the Kronecker delta. I will not add it to PR #1700 because it is already long enough to review.

Aaron Meurer

unread,
Dec 23, 2012, 9:37:33 PM12/23/12
to sympy/sympy

SymPy Bot Summary: :red_circle: Failed after merging pernici/can3 (0389c6d) into master (8083428).


@pernici: Please fix the test failures.

:red_circle:Python 2.5.0-final-0: fail
:red_circle:Python 2.6.6-final-0: fail


:red_circle:Python 2.7.2-final-0: fail

:eight_spoked_asterisk:Python 2.6.8-final-0: pass
:red_circle:Python 2.7.3-final-0: fail
:eight_spoked_asterisk:PyPy 2.0.0-beta-1; 2.7.3-final-42: pass
:eight_spoked_asterisk:Python 3.2.2-final-0: pass
:eight_spoked_asterisk:Python 3.3.0-final-0: pass
:eight_spoked_asterisk:Python 3.2.3-final-0: pass
:eight_spoked_asterisk:Python 3.3.0-final-0: pass
:eight_spoked_asterisk:Python 3.3.0-final-0: pass
:red_circle:**Sphinx 1.1.3:** fail

pernici

unread,
Jan 1, 2013, 2:09:45 PM1/1/13
to sympy/sympy

I started the module group_factors to compute group theoretical factors, which are useful in quantum field theory.
This topic is a good playground for adding matching and substitution rules for tensors.

Reply all
Reply to author
Forward
0 new messages