
9\c           @  si  d  Z  d d l m Z m Z d d l m Z d d l Z d d l Z d d l m	 Z	 m
 Z
 m Z d d l m Z m Z m Z m Z d d l m Z m Z m Z m Z m Z m Z d d l m Z m Z m Z m Z d d	 l m Z m Z d d
 l  m! Z! d d l" m# Z# m$ Z$ d d l% m& Z& m' Z' d d l( m) Z) d d l* m+ Z+ d d l, m- Z- d d l. Z. e! d d d d d d  d    Z/ d e& f d     YZ0 d   Z1 d e& f d     YZ2 e2   Z3 d e4 f d     YZ5 e5   Z6 d e f d     YZ7 d  e f d!     YZ8 d"   Z9 d# e f d$     YZ: d%   Z; d& e f d'     YZ< e= d( d)  Z> d* e f d+     YZ? d,   Z@ d- e f d.     YZA d/ eA e) f d0     YZB d1 eA f d2     YZC d3 eA e) f d4     YZD d5 eA f d6     YZE d7   ZF d8   ZG d9   ZH d:   ZI d;   ZJ d<   ZK d=   ZL d>   ZM d?   ZN d@   ZO eP dA  ZQ dB   ZR dC   ZS d S(D   s  
This module defines tensors with abstract index notation.

The abstract index notation has been first formalized by Penrose.

Tensor indices are formal objects, with a tensor type; there is no
notion of index range, it is only possible to assign the dimension,
used to trace the Kronecker delta; the dimension can be a Symbol.

The Einstein summation convention is used.
The covariant indices are indicated with a minus sign in front of the index.

For instance the tensor ``t = p(a)*A(b,c)*q(-c)`` has the index ``c``
contracted.

A tensor expression ``t`` can be called; called with its
indices in sorted order it is equal to itself:
in the above example ``t(a, b) == t``;
one can call ``t`` with different indices; ``t(c, d) == p(c)*A(d,a)*q(-a)``.

The contracted indices are dummy indices, internally they have no name,
the indices being represented by a graph-like structure.

Tensors are put in canonical form using ``canon_bp``, which uses
the Butler-Portugal algorithm for canonicalization using the monoterm
symmetries of the tensors.

If there is a (anti)symmetric metric, the indices can be raised and
lowered when the tensor is put in canonical form.
i(   t   print_functiont   division(   t   defaultdictN(   t   Rationalt   prodt   Integer(   t   get_symmetric_group_sgst   bsgs_direct_productt   canonicalizet   riemann_bsgs(   t   Basict   Exprt   sympifyt   Addt   Mult   S(   t   string_typest   reducet   ranget
   SYMPY_INTS(   t   Tuplet   Dict(   t
   deprecated(   t   Symbolt   symbols(   t   CantSympifyt   _sympify(   t   AssocOp(   t   eye(   t   SymPyDeprecationWarningt
   useinsteads   .replace_with_arrayst   issuei;  t   deprecated_since_versions   1.4c           C  s   d  S(   N(    (    (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyt   deprecate_data4   s    t   _IndexStructurec           B  s   e  Z d  Z e d  Z e d    Z e d    Z e d    Z d   Z	 e d    Z
 e d    Z e d    Z d	   Z d
   Z d   Z d   Z d   Z d   Z d   Z e d  Z d   Z RS(   s  
    This class handles the indices (free and dummy ones). It contains the
    algorithms to manage the dummy indices replacements and contractions of
    free indices under multiplications of tensor expressions, as well as stuff
    related to canonicalization sorting, getting the permutation of the
    expression and so on. It also includes tools to get the ``TensorIndex``
    objects corresponding to the given index structure.
    c         C  sa   | |  _  | |  _ | |  _ | |  _ t |  j   d t |  j  |  _ |  j j d d    d  S(   Ni   t   keyc         S  s   |  d S(   Ni    (    (   t   x(    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyt   <lambda>I   t    (   t   freet   dumt   index_typest   indicest   lent	   _ext_rankt   sort(   t   selfR'   R(   R)   R*   t   canon_bp(    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyt   __init__C   s    				#c          G  sY   t  j |    \ } } g  |  D] } | j ^ q } t  j |  | |  }  t  | | | |   S(   sh  
        Create a new ``_IndexStructure`` object from a list of ``indices``

        ``indices``     ``TensorIndex`` objects, the indices. Contractions are
                        detected upon construction.

        Examples
        ========

        >>> from sympy.tensor.tensor import TensorIndexType, tensor_indices, _IndexStructure
        >>> Lorentz = TensorIndexType('Lorentz', dummy_fmt='L')
        >>> m0, m1, m2, m3 = tensor_indices('m0,m1,m2,m3', Lorentz)
        >>> _IndexStructure.from_indices(m0, m1, -m1, m3)
        _IndexStructure([(m0, 0), (m3, 3)], [(1, 2)], [Lorentz, Lorentz, Lorentz, Lorentz])

        In case of many components the same indices have slightly different
        indexes:

        >>> _IndexStructure.from_indices(m0, m1, -m1, m3)
        _IndexStructure([(m0, 0), (m3, 3)], [(1, 2)], [Lorentz, Lorentz, Lorentz, Lorentz])
        (   R"   t   _free_dum_from_indicest   tensor_index_typet   _replace_dummy_names(   R*   R'   R(   t   iR)   (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyt   from_indicesK   s    c         C  sO   g  } x |  D] } | j  | j  q Wt j | | |  } t | | | |  S(   N(   t   extendR)   R"   t*   generate_indices_from_free_dum_index_types(   t
   componentsR'   R(   R)   t	   componentR*   (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyt   from_components_free_dumg   s
    c          G  s  t  |   } | d k r/ |  d d f g g  f St g t  |   } i  } g  } xt |   D]	\ } } | j } | j } | j }	 | | f | k rK| | | f \ }
 } |
 r |	 r t d | | f   qt | | <t | | <n3 |	 rt | | <t | | <n t d | | f   |	 r5| j | | f  qd| j | | f  q[ | j | f | | | f <q[ Wg  t |   D]" \ } } | | ru| | f ^ qu} | j	   | | f S(   s  
        Convert ``indices`` into ``free``, ``dum`` for single component tensor

        ``free``     list of tuples ``(index, pos, 0)``,
                     where ``pos`` is the position of index in
                     the list of indices formed by the component tensors

        ``dum``      list of tuples ``(pos_contr, pos_cov, 0, 0)``

        Examples
        ========

        >>> from sympy.tensor.tensor import TensorIndexType, tensor_indices,             _IndexStructure
        >>> Lorentz = TensorIndexType('Lorentz', dummy_fmt='L')
        >>> m0, m1, m2, m3 = tensor_indices('m0,m1,m2,m3', Lorentz)
        >>> _IndexStructure._free_dum_from_indices(m0, m1, -m1, m3)
        ([(m0, 0), (m3, 3)], [(1, 2)])
        i   i    s2   two equal contravariant indices in slots %d and %ds.   two equal covariant indices in slots %d and %d(
   R+   t   Truet	   enumeratet   _nameR2   t   _is_upt
   ValueErrort   Falset   appendR-   (   R*   t   nR'   t
   index_dictR(   R4   t   indext   namet   typt   contrt   is_contrt   pos(    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyR1   o   s8    			

5
c         C  s   |  j  S(   s_   
        Get a list of indices, creating new tensor indices to complete dummy indices.
        (   R*   (   R.   (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyt   get_indices   s    c         C  s   d  g t |   d t |  } x |  D] \ } } | | | <q( Wt j |   } xV | D]N \ } } | | }	 | |	  }
 t |
 |	 t  | | <t |
 |	 t  | | <qX Wt j | |  |  S(   Ni   (   t   NoneR+   R"   t    _get_generator_for_dummy_indicest   TensorIndexR;   R@   R3   (   R'   R(   R)   R*   t   idxRI   t   generate_dummy_namet   pos1t   pos2t   typ1t   indname(    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyR7      s    !
c           s   t  t    xt |  D]l \ } } | j j d  d | j j d  k r t   | j t | j j d  d  d    | j <q q W  f d   } | S(   Nt   _i    ii   c           s+   |  j  }   |  }   |  c d 7<| | S(   Ni   (   t	   dummy_fmt(   R2   t   fmtt   nd(   t   cdt(    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyt   dummy_fmt_gen   s    	
(   R   t   intR=   t   splitR2   RU   t   max(   R'   t   indxt   iposRY   (    (   RX   s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyRL      s    &>c   
      C  s   | j  d d    g  |  D] } | ^ q } t |   t |  d t |  k sX t  t j |  } xY | D]Q \ } } | | j } | |  }	 t |	 | t  | | <t |	 | t  | | <qn W| S(   NR#   c         S  s   |  d S(   Ni    (    (   R$   (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyR%      R&   i   (	   R-   R+   t   AssertionErrorR"   RL   R2   RM   R;   R@   (
   R*   R'   R(   t   indt   new_indicesRO   t   ipos1t   ipos2RR   RS   (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyR3      s    ,c         C  s3   t  |  j d d   } g  | D] } | d ^ q S(   s-   
        Get a list of free indices.
        R#   c         S  s   |  d S(   Ni   (    (   R$   (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyR%      R&   i    (   t   sortedR'   (   R.   R'   R4   (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyt   get_free_indices   s    c         C  s   d j  |  j |  j |  j  S(   Ns   _IndexStructure({0}, {1}, {2})(   t   formatR'   R(   R)   (   R.   (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyt   __str__   s    c         C  s
   |  j    S(   N(   Rg   (   R.   (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyt   __repr__   s    c         C  s!   |  j  } | j d d    | S(   NR#   c         S  s   |  d S(   Ni    (    (   R$   (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyR%      R&   (   R'   R-   (   R.   t   sorted_free(    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyt"   _get_sorted_free_indices_for_canon   s    
c         C  s   t  |  j d d   S(   NR#   c         S  s   |  d S(   Ni    (    (   R$   (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyR%      R&   (   Rd   R(   (   R.   (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyt!   _get_sorted_dum_indices_for_canon   s    c         C  sT   |  j    d } d  g |  j } x- t |  j  D] \ } } | | | |  <q0 W| S(   Ni    (   t   indices_canon_argsRK   R,   R<   R)   (   R.   t   permutationR)   R4   t   it(    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyt)   _get_lexicographically_sorted_index_types   s
    c         C  sT   |  j    d } d  g |  j } x- t |  j  D] \ } } | | | |  <q0 W| S(   Ni    (   Rl   RK   R,   R<   R*   (   R.   Rm   R*   R4   Rn   (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyt%   _get_lexicographically_sorted_indices   s
    c         C  s  g  |  j    D] } | d ^ q } |  j   } |  j   } t |  } |  j } g  t | | d  D] } d g d ^ qe }	 g  }
 d g | } d g | } x t |  D] } | | } | | | | <| | | | <| | k  r | | } | | | | j k s
t  |
 j	 | | f  q | | } t
 | d  \ } } | rV| |	 | d <q | |	 | d <q Wg  |	 D] } t |  ^ qo}	 t |
 |	 | |  S(   sJ  
        Returns a ``_IndexStructure`` instance corresponding to the permutation ``g``

        ``g``  permutation corresponding to the tensor in the representation
        used in canonicalization

        ``is_canon_bp``   if True, then ``g`` is the permutation
        corresponding to the canonical form of the tensor
        i    i   i   N(   Rj   Ro   Rp   R+   R,   R   RK   R2   R_   RA   t   divmodt   tupleR"   (   R.   t   gt   is_canon_bpR4   Ri   t   lex_index_typest   lex_indicest   nfreet   rankR(   R'   R)   R*   t   giR`   t   jt   idumt   covR$   (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyt   perm2tensor  s0    
#	.


c         C  s~  d d l  m } |  j } d g | | | d g } x0 t |  j    D] \ } \ } } | | | <qG Wt |  j  } t |  j  } g  }	 d }
 g  } g  } x |  j   D] \ } } | | | <| d | | <| d 7} |  j	 | } | |
 k r0| r|	 j
 |  n  | | d g } | }
 | j
 | j  n | j | | d g  | d 7} q W| rk|	 j
 |  n  | |  |	 | f S(   s   
        Returns ``(g, dummies, msym, v)``, the entries of ``canonicalize``

        see ``canonicalize`` in ``tensor_can.py``
        i(   t   _af_newi   i   N(   t    sympy.combinatorics.permutationsR~   R,   RK   R<   Rj   R+   R'   Rk   R)   RA   t   metric_antisymR6   (   R.   R~   RB   Rs   R4   R]   R^   RI   Rz   t   dummiest   prevt   at   msymRb   Rc   RF   (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyRl   *  s6    	%

(   t   __name__t
   __module__t   __doc__R@   R0   t   staticmethodR5   R:   R1   RJ   R7   RL   R3   Re   Rg   Rh   Rj   Rk   Ro   Rp   R}   Rl   (    (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyR"   9   s$   <								'c         C  s   g  } d  } xJ |  D]B } | | k r< | d d c d 7<q | } | j | d g  q Wg  } x{ | D]s \ } } | j d k s | j d k r | j } n t j | j | j  } | j | j j | j j | | f  qf W| S(   Nii   i    (   RK   RA   t   _commt   TensorManagert   get_commt	   _symmetryt   baset
   generators(   R8   t   numtypR   t   tt   vt   hRB   t   comm(    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyt   components_canon_argsU  s    )t   _TensorDataLazyEvaluatorc           B  s   e  Z d  Z e   Z e   Z d   Z d   Z e d    Z	 d   Z
 d   Z d   Z d   Z d   Z d	   Z d
   Z d   Z e d    Z e d    Z e d    Z e e d   Z e d    Z e d    Z e d    Z RS(   s  
    EXPERIMENTAL: do not rely on this class, it may change without deprecation
    warnings in future versions of SymPy.

    This object contains the logic to associate components data to a tensor
    expression. Components data are set via the ``.data`` property of tensor
    expressions, is stored inside this class as a mapping between the tensor
    expression and the ``ndarray``.

    Computations are executed lazily: whereas the tensor expressions can have
    contractions, tensor products, and additions, components data are not
    computed until they are accessed by reading the ``.data`` property
    associated to the tensor expression.
    c         C  s   |  j  |  } | d  k r d  Sd d l m } t | |  sB | S| j   d k r\ | d S| j   d k r t |  d k r | d S| S(   Ni   (   t	   NDimArrayi    (    (   t   _getRK   t   arrayR   t
   isinstanceRx   R+   (   R.   R#   t   datR   (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyt   __getitem__z  s    $c         C  s  | |  j  k r |  j  | St | t  r- d St | t  r t g  | j   D] } | j ^ qL  } | j f | } | |  j	 k r |  j	 | S|  j
 |  g } |  j | | j | j  St | t  rT| j } t |  d k r]t | d j  d k r]t g  | d j   D] } | j ^ q } | d j d f | } | |  j	 k r]|  j	 | Sn  g  | D]< } t | t  rdt | t  r|  j
 |  n | j ^ qd} t g  | D] } t | t  s| ^ q } t g  | D] } | d k ^ q rd St g  | D] } | d k ^ q r1t d   n  |  j | | j | j  }	 | |	 St | t  rg  } g  }
 xt | j D]i } t | t  r| j | j  |
 j g  | j D] } | d ^ q qy| j |  |
 j g   qyWt g  | D] } | d k ^ q rd St g  | D] } | d k ^ q rCt d   n  g  } d d l m } x t | |
  D]z \ } } t |  d k  r| j |  qid   t |  D } g  | j D] } | | ^ q} | j | | |   qiWt  d   |  Sd S(	   s4  
        Retrieve ``data`` associated with ``key``.

        This algorithm looks into ``self._substitutions_dict`` for all
        ``TensorHead`` in the ``TensExpr`` (or just ``TensorHead`` if key is a
        TensorHead instance). It reconstructs the components data that the
        tensor expression should have by performing on components data the
        operations that correspond to the abstract tensor operations applied.

        Metric tensor is handled in a different manner: it is pre-computed in
        ``self._substitutions_dict_tensmul``.
        i   i    sS   Mixing tensors with associated components data with tensors without components data(   t   permutedimsi   c         S  s   i  |  ] \ } } | |  q S(    (    (   t   .0R$   t   y(    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pys
   <dictcomp>  s   	 c         S  s   |  | S(   N(    (   R$   R   (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyR%     R&   N(!   t   _substitutions_dictR   t
   TensorHeadRK   t   TensorRr   RJ   t   is_upR9   t   _substitutions_dict_tensmult   data_from_tensort   data_contract_dumR(   t   ext_rankt   TensMult   argsR+   R8   t   TensExprt   dataR   t   allt   anyR?   t   TensAddRA   R'   R   R   t   zipR<   t	   free_argsR   (   R.   R#   R4   t	   signaturet   srcht
   array_listt   tensmul_argst	   data_listt   coefft   data_resultt   free_args_listt   argR$   t   sum_listR   R   R   t   free_args_post   axes(    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyR     sb    (	+,I.%%*%% c         C  sJ   d d l  m } m } m } t t | |    } | |   } | | |  S(   Ni   (   t   tensorproductt   tensorcontractiont   MutableDenseNDimArray(   R   R   R   R   t   listt   map(   t   ndarray_listR(   R   R   R   R   t   arrayst   prodarr(    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyR     s    c         C  s5   | d k r d S|  j | | j   | j | j t  S(   s   
        This method is used when assigning components data to a ``TensMul``
        object, it converts components data to a fully contravariant ndarray,
        which is then stored according to the ``TensorHead`` key.
        N(   RK   t   _correct_signature_from_indicesRJ   R'   R(   R;   (   R.   R   t   tensmult
   tensorhead(    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyt   data_tensorhead_from_tensmul  s    	c         C  sA   | j  } | j d k r d S|  j | j | j   | j | j  S(   s   
        This method corrects the components data to the right signature
        (covariant/contravariant) using the metric associated with each
        ``TensorIndexType``.
        N(   R9   R   RK   R   RJ   R'   R(   (   R.   t   tensorR   (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyR     s    		c         C  sn   t  | t  r t d   n  t | j  d k rB t d   n  | j d } |  j | | |  } | | f S(   Ns   cannot assign data to TensAddi   s6   cannot assign data to TensMul with multiple componentsi    (   R   R   R?   R+   R8   R   (   R.   R#   R   R   t   newdata(    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyt   _assign_data_to_tensor_expr  s    c         C  sL  d d l  m } t | t  r7 | j } | j j } n[ t | t  re | j } | j d j j } n- t | t	  r | j
 j } | j
 j j } n  x | D] } | |  | k r d 
n d } | } | }	 t t | t t |     }
 xV t | j   d  D]> } | | |
  } t |	 | |  r:t d   n  | }	 qWq Wd  S(   Ni   (   R   i    is'   Component data symmetry structure error(   R   R   R   R   Rx   t   symmetryR   R   R8   t   TensorIndexTypet   metricR   R   R   t   orderR   R?   (   R.   t   tensR   R   Rx   R   t   genert   sign_changet   data_swappedt	   last_datat   permute_axesR4   (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyt   _check_permutations_on_data  s(    		!c         C  s   t  j |  } |  j | |  t | t t f  sO |  j | |  \ } } n  t | t  r x t | j | j	  D]f \ } } | j
 d k r t d j |    n  | j d k r qt n  | | j k rt t d   qt qt Wn  | |  j | <d S(   s*  
        Set the components data of a tensor object/expression.

        Components data are transformed to the all-contravariant form and stored
        with the corresponding ``TensorHead`` object. If a ``TensorHead`` object
        cannot be uniquely identified, it will raise an error.
        sM   index type {} has no components data associated (needed to raise/lower index)s   wrong dimension of ndarrayN(   R   t
   parse_dataR   R   R   R   R   R   t   shapeR)   R   RK   R?   Rf   t   dimR   (   R.   R#   t   valueR   R   t	   indextype(    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyt   __setitem__)  s    "	c         C  s   |  j  | =d  S(   N(   R   (   R.   R#   (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyt   __delitem__E  s    c         C  s   | |  j  k S(   N(   R   (   R.   R#   (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyt   __contains__H  s    c         C  s   | |  j  | t t f <|  j |  } | |  j  | t t f <| j   } | j   } | | |  j  | t t f <| | |  j  | t t f <d S(   s  
        Assign data to the ``metric`` tensor. The metric tensor behaves in an
        anomalous way when raising and lowering indices.

        A fully covariant metric is the inverse transpose of the fully
        contravariant metric (it is meant matrix inverse). If the metric is
        symmetric, the transpose is not necessary and mixed
        covariant/contravariant metrics are Kronecker deltas.
        N(   R   R;   t   inverse_transpose_matrixR@   t   tomatrix(   R.   R   R   t   inverse_transposet   mt   invt(    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyt   add_metric_dataK  s    c         C  s   d d l  m } m } | j   } |  j   } | d k r_ | | | |   d | | f  }  n | | |  |  | | f  }  |  S(   Ni   (   R   R   i    (   R   R   R   Rx   (   R   R   RI   R   R   t   mdimt   ddim(    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyt   _flip_index_by_metricf  s    c         C  s   |  j    j   } t j |  S(   N(   R   t   invR   R   (   t   ndarrayR   (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyt   inverse_matrix  s    c         C  s"   |  j    j   j } t j |  S(   N(   R   R   t   TR   R   (   R   R   (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyR     s    c         C  s   x t  |  D]r \ } } | j rH | rH t j |  | j j |  }  q | j r | r t j |  t j | j j  |  }  q q W|  S(   s   
        Utility function to correct the values inside the components data
        ndarray according to whether indices are covariant or contravariant.

        It uses the metric matrix to lower values of covariant indices.
        (   R<   R   R   R   R2   R   R   (   R   R*   R'   R(   t   inverseR4   R]   (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyR     s    
c         C  s   d d l  m } |  j j   } g  |  j D] } | d ^ q) } g  | j D] } | d ^ qI } x t t |   D]p } xg t | t |   D]P } | | | | k r | | | | | | <| | <| | | | f  } Pq q Wqr W| S(   Ni   (   R   i    (   R   R   R   t   copyR'   R   R+   (   t   oldt   newR   t   new_dataR4   t   old_freet   new_freeRz   (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyt   _sort_data_axes  s      c           s&      f d   } |   t  j   <d  S(   Nc             s   t  j     S(   N(   R   R   (    (   t   new_tensmult   old_tensmul(    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyt   sorted_compo  s    (   R   R   (   R   R   R   (    (   R   R   s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyt   add_rearrange_tensmul_parts  s    c         C  sq   d d l  m } t |  |  sm t |   d k r^ t |  d d  r^ | |  d |  d  }  qm | |   }  n  |  S(   s  
        Transform ``data`` to array. The parameter ``data`` may
        contain data in various formats, e.g. nested lists, sympy ``Matrix``,
        and so on.

        Examples
        ========

        >>> from sympy.tensor.tensor import _TensorDataLazyEvaluator
        >>> _TensorDataLazyEvaluator.parse_data([1, 3, -6, 12])
        [1, 3, -6, 12]

        >>> _TensorDataLazyEvaluator.parse_data([[1, 2], [4, 7]])
        [[1, 2], [4, 7]]
        i   (   R   i   i    t   __call__(   R   R   R   R+   t   hasattr(   R   R   (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyR     s    %(   R   R   R   t   dictR   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R@   R   R   R   R   (    (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyR   h  s,   				P			
					t   _TensorManagerc           B  se   e  Z d  Z d   Z d   Z e d    Z d   Z d   Z d   Z	 d   Z
 d   Z d	   Z RS(
   s  
    Class to manage tensor properties.

    Notes
    =====

    Tensors belong to tensor commutation groups; each group has a label
    ``comm``; there are predefined labels:

    ``0``   tensors commuting with any other tensor

    ``1``   tensors anticommuting among themselves

    ``2``   tensors not commuting, apart with those with ``comm=0``

    Other groups can be defined using ``set_comm``; tensors in those
    groups commute with those with ``comm=0``; by default they
    do not commute with any other group.
    c         C  s   |  j    d  S(   N(   t
   _comm_init(   R.   (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyR0     s    c         C  s   g  t  d  D] } i  ^ q |  _ x6 t  d  D]( } d |  j d | <d |  j | d <q/ Wd |  j d d <d  |  j d d <d  |  j d d <i d d 6d d 6d d 6|  _ i d d 6d d 6d d 6|  _ d  S(   Ni   i    i   i   (   R   R   RK   t   _comm_symbols2it   _comm_i2symbol(   R.   R4   (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyR     s    "c         C  s   |  j  S(   N(   R   (   R.   (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyR     s    c         C  sy   | |  j  k rn t |  j  } |  j j i   d |  j | d <d |  j d | <| |  j  | <| |  j | <| S|  j  | S(   s   
        get the commutation group number corresponding to ``i``

        ``i`` can be a symbol or a number or a string

        If ``i`` is not already defined its commutation group number
        is set.
        i    (   R   R+   R   RA   R   (   R.   R4   RB   (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyt   comm_symbols2i  s    	c         C  s   |  j  | S(   sS   
        Returns the symbol corresponding to the commutation group number.
        (   R   (   R.   R4   (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyt   comm_i2symbol  s    c         C  s5  | d k r t d   n  | |  j k r t |  j  } |  j j i   d |  j | d <d |  j d | <| |  j | <| |  j | <n  | |  j k r t |  j  } |  j j i   d |  j d | <d |  j | d <| |  j | <| |  j | <n  |  j | } |  j | } | |  j | | <| |  j | | <d S(   sE  
        set the commutation parameter ``c`` for commutation groups ``i, j``

        Parameters
        ==========

        i, j : symbols representing commutation groups

        c  :  group commutation number

        Notes
        =====

        ``i, j`` can be symbols, strings or numbers,
        apart from ``0, 1`` and ``2`` which are reserved respectively
        for commuting, anticommuting tensors and tensors not commuting
        with any other group apart with the commuting tensors.
        For the remaining cases, use this method to set the commutation rules;
        by default ``c=None``.

        The group commutation number ``c`` is assigned in correspondence
        to the group commutation symbols; it can be

        0        commuting

        1        anticommuting

        None     no commutation property

        Examples
        ========

        ``G`` and ``GH`` do not commute with themselves and commute with
        each other; A is commuting.

        >>> from sympy.tensor.tensor import TensorIndexType, tensor_indices, tensorhead, TensorManager
        >>> Lorentz = TensorIndexType('Lorentz')
        >>> i0,i1,i2,i3,i4 = tensor_indices('i0:5', Lorentz)
        >>> A = tensorhead('A', [Lorentz], [[1]])
        >>> G = tensorhead('G', [Lorentz], [[1]], 'Gcomm')
        >>> GH = tensorhead('GH', [Lorentz], [[1]], 'GHcomm')
        >>> TensorManager.set_comm('Gcomm', 'GHcomm', 0)
        >>> (GH(i1)*G(i0)).canon_bp()
        G(i0)*GH(i1)
        >>> (G(i1)*G(i0)).canon_bp()
        G(i1)*G(i0)
        >>> (G(i1)*A(i0)).canon_bp()
        A(i0)*G(i1)
        i    i   s+   `c` can assume only the values 0, 1 or NoneN(   i    i   N(   RK   R?   R   R+   R   RA   R   (   R.   R4   Rz   t   cRB   t   nit   nj(    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyt   set_comm  s(    2c         G  s1   x* | D]" \ } } } |  j  | | |  q Wd S(   s   
        set the commutation group numbers ``c`` for symbols ``i, j``

        Parameters
        ==========

        args : sequence of ``(i, j, c)``
        N(   R  (   R.   R   R4   Rz   R   (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyt	   set_commsZ  s    	c         C  s5   |  j  | j | | d k s( | d k r. d n d  S(   s   
        Return the commutation parameter for commutation group numbers ``i, j``

        see ``_TensorManager.set_comm``
        i    N(   R   t   getRK   (   R.   R4   Rz   (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyR   f  s    c         C  s   |  j    d S(   s*   
        Clear the TensorManager.
        N(   R   (   R.   (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyt   clearn  s    (   R   R   R   R0   R   t   propertyR   R   R   R  R  R   R  (    (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyR     s   					H		R   c           B  sj  e  Z d  Z e d d d d  Z e e d d d d d d  d     Z e e d d d d d d  d	     Z	 e e d d d d d d  d
     Z
 e d    Z e j d    Z e j d    Z d   Z e d    Z e d    Z e d    Z e d    Z e d    Z e d    Z d   Z d   Z d   Z d   Z e Z d   Z RS(   sc  
    A TensorIndexType is characterized by its name and its metric.

    Parameters
    ==========

    name : name of the tensor type

    metric : metric symmetry or metric object or ``None``


    dim : dimension, it can be a symbol or an integer or ``None``

    eps_dim : dimension of the epsilon tensor

    dummy_fmt : name of the head of dummy indices

    Attributes
    ==========

    ``name``
    ``metric_name`` : it is 'metric' or metric.name
    ``metric_antisym``
    ``metric`` : the metric tensor
    ``delta`` : ``Kronecker delta``
    ``epsilon`` : the ``Levi-Civita epsilon`` tensor
    ``dim``
    ``eps_dim``
    ``dummy_fmt``
    ``data`` : a property to add ``ndarray`` values, to work in a specified basis.

    Notes
    =====

    The ``metric`` parameter can be:
    ``metric = False`` symmetric metric (in Riemannian geometry)

    ``metric = True`` antisymmetric metric (for spinor calculus)

    ``metric = None``  there is no metric

    ``metric`` can be an object having ``name`` and ``antisym`` attributes.


    If there is a metric the metric is used to raise and lower indices.

    In the case of antisymmetric metric, the following raising and
    lowering conventions will be adopted:

    ``psi(a) = g(a, b)*psi(-b); chi(-a) = chi(b)*g(-b, -a)``

    ``g(-a, b) = delta(-a, b); g(b, -a) = -delta(a, -b)``

    where ``delta(-a, b) = delta(b, -a)`` is the ``Kronecker delta``
    (see ``TensorIndex`` for the conventions on indices).

    If there is no metric it is not possible to raise or lower indices;
    e.g. the index of the defining representation of ``SU(N)``
    is 'covariant' and the conjugate representation is
    'contravariant'; for ``N > 2`` they are linearly independent.

    ``eps_dim`` is by default equal to ``dim``, if the latter is an integer;
    else it can be assigned (for use in naive dimensional regularization);
    if ``eps_dim`` is not an integer ``epsilon`` is ``None``.

    Examples
    ========

    >>> from sympy.tensor.tensor import TensorIndexType
    >>> Lorentz = TensorIndexType('Lorentz', dummy_fmt='L')
    >>> Lorentz.metric
    metric(Lorentz,Lorentz)
    c   
      C  s`  t  | t  r t |  } n  t j |  | | r9 t j n t j  } t |  | _	 | sm d | j
 | _ n d | | _ | d  k r d  | _ d  | _ n| | t t d d f k r d } | | _ n | j
 } | j | _ t t d | j   } t | g d |  }	 |	 |  | _ | | _ | j   | _ | r;| n | | _ | j   | _ g  | _ | S(   Ns   %s_%%di    i   R   i   (   R   R   R   R
   t   __new__R   t   Onet   Zerot   strR=   RE   t
   _dummy_fmtRK   R   R   R;   R@   t   antisymt   TensorSymmetryR   t
   TensorTypet   _dimt   get_kronecker_deltat   _deltat   _eps_dimt   get_epsilont   _epsilont   _autogenerated(
   t   clsRE   R   R   t   eps_dimRU   t   objt   metric_namet   sym2t   S2(    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyR    s0    '				R   RM   R   i92  R    s   1.1c         C  s+   t  |  d  s$ t d |   |  _ n  |  j S(   Nt   _auto_rightt
   auto_right(   R   RM   R  (   R.   (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyR    s    c         C  s+   t  |  d  s$ t d |   |  _ n  |  j S(   Nt
   _auto_leftt	   auto_left(   R   RM   R  (   R.   (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyR     s    c         C  s+   t  |  d  s$ t d |   |  _ n  |  j S(   Nt   _auto_indext
   auto_index(   R   RM   R!  (   R.   (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyR"    s    c         C  s   t    t |  S(   N(   R!   t   _tensor_data_substitution_dict(   R.   (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyR     s    c         C  s  t    d d l m } t j |  } | j   d k rG t d   n  | j   d k r |  j d  k	 r | j	 d } | |  j k r t d   q n  | j	 d } | j
 | |  } x* t |  D] \ } } | | | | f <q W| } n  | j	 \ } }	 | |	 k rt d   n  |  j d  k	 rE|  j | k rEt d   qEn  | t |  <t j |  j |  |  j   }
 t d |   } t d	 |   } t j t |   |
 | |  _ d  S(
   Ni   (   R   i   s1   data have to be of rank 1 (diagonal metric) or 2.i    s   Dimension mismatchs   Non-square matrix tensor.t   i1t   i2(   R!   R   R   R   R   Rx   R?   R   RK   R   t   zerosR<   R#  R   R   R  RM   R   R   (   R.   R   R   t   nda_dimR   t
   newndarrayR4   t   valt   dim1t   dim2t   deltaR$  R%  (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyR     s6    	
c         C  s=   t    |  t k r t |  =n  |  j t k r9 t |  j =n  d  S(   N(   R!   R#  R   (   R.   (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyR      s
    
c         C  s   d |  j  | S(   NR   (   RU   (   R.   t   number(    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyt   _get_matrix_fmt(  s    c         C  s   |  j  S(   N(   R=   (   R.   (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyRE   +  s    c         C  s   |  j  S(   N(   R  (   R.   (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyR   /  s    c         C  s   |  j  S(   N(   R  (   R.   (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyR,  3  s    c         C  s   |  j  S(   N(   R  (   R.   (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyR  7  s    c         C  s   |  j  S(   N(   R  (   R.   (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyt   epsilon;  s    c         C  s   |  j  S(   N(   R  (   R.   (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyRU   ?  s    c         C  s8   t  t d   } t |  g d |  } | d  } | S(   Ni   t   KD(   R  R   R  (   R.   R  R  R,  (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyR  C  s    c         C  s]   t  |  j t t f  s d  St t |  j d   } t |  g |  j |  } | d  } | S(   Ni   t   Eps(   R   R  R   R   RK   R  R   R  (   R.   t   symt   SdimR/  (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyR  I  s    c         C  s   |  j  | j  k  S(   N(   RE   (   R.   t   other(    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyt   __lt__Q  s    c         C  s   |  j  S(   N(   RE   (   R.   (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyRg   T  s    c         C  s   |  t  k r t  |  =n  d   } | |  j t t f  | |  j t t f  | |  j t t f  | |  j t t f  |  j   } | t  k r t  | =n  d S(   s   
        EXPERIMENTAL: do not rely on this API method.

        This destroys components data associated to the ``TensorIndexType``, if
        any, specifically:

        * metric tensor data
        * Kronecker tensor data
        c         S  s    |  t  j k r t  j |  =n  d  S(   N(   R#  R   (   R#   (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyt   delete_tensmul_dataf  s    N(   R#  R   R;   R@   R  (   R.   R6  R,  (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyt   _components_data_full_destroyY  s    

	N(   R   R   R   R@   RK   R  R  R   R  R   R"  R   t   settert   deleterR.  RE   R   R,  R  R/  RU   R  R  R5  Rg   Rh   R7  (    (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyR   x  s2   I	'''#					RM   c           B  s   e  Z d  Z e d  Z e d    Z e e d d d d d d  d	     Z e d
    Z	 e d    Z
 d   Z d   Z d   Z RS(   s  
    Represents an abstract tensor index.

    Parameters
    ==========

    name : name of the index, or ``True`` if you want it to be automatically assigned
    tensortype : ``TensorIndexType`` of the index
    is_up :  flag for contravariant index

    Attributes
    ==========

    ``name``
    ``tensortype``
    ``is_up``

    Notes
    =====

    Tensor indices are contracted with the Einstein summation convention.

    An index can be in contravariant or in covariant form; in the latter
    case it is represented prepending a ``-`` to the index name.

    Dummy indices have a name with head given by ``tensortype._dummy_fmt``


    Examples
    ========

    >>> from sympy.tensor.tensor import TensorIndexType, TensorIndex, TensorSymmetry, TensorType, get_symmetric_group_sgs
    >>> Lorentz = TensorIndexType('Lorentz', dummy_fmt='L')
    >>> i = TensorIndex('i', Lorentz); i
    i
    >>> sym1 = TensorSymmetry(*get_symmetric_group_sgs(1))
    >>> S1 = TensorType([Lorentz], sym1)
    >>> A, B = S1('A,B')
    >>> A(i)*B(-i)
    A(L_0)*B(-L_0)

    If you want the index name to be automatically assigned, just put ``True``
    in the ``name`` field, it will be generated using the reserved character
    ``_`` in front of its name, in order to avoid conflicts with possible
    existing indices:

    >>> i0 = TensorIndex(True, Lorentz)
    >>> i0
    _i0
    >>> i1 = TensorIndex(True, Lorentz)
    >>> i1
    _i1
    >>> A(i0)*B(-i1)
    A(_i0)*B(-_i1)
    >>> A(i0)*B(-i0)
    A(L_0)*B(-L_0)
    c         C  s   t  | t  r t |  } ng t  | t  r6 | } nO | t k ry d j t | j   } t |  } | j j |  n t d   t	 |  } t
 j |  | | |  } t |  | _ | | _ | | _ | S(   Ns   _i{0}s   invalid name(   R   R   R   R;   Rf   R+   R  RA   R?   R   R
   R  R  R=   t   _tensor_index_typeR>   (   R  RE   t
   tensortypeR   t   name_symbolR  (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyR    s    			c         C  s   |  j  S(   N(   R=   (   R.   (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyRE     s    R   R2   R   i92  R    s   1.1c         C  s   |  j  S(   N(   R2   (   R.   (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyR;    s    c         C  s   |  j  S(   N(   R:  (   R.   (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyR2     s    c         C  s   |  j  S(   N(   R>   (   R.   (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyR     s    c         C  s#   |  j  } |  j s d | } n  | S(   Ns   -%s(   R=   R>   (   R.   t   s(    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyt   _print  s    		c         C  s"   |  j  |  j f | j  | j f k  S(   N(   R2   R=   (   R.   R4  (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyR5    s    c         C  s    t  |  j |  j |  j  } | S(   N(   RM   RE   R2   R   (   R.   t   t1(    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyt   __neg__  s    (   R   R   R   R;   R  R  RE   R   R;  R2   R   R>  R5  R@  (    (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyRM   v  s   9'		c         C  s   t  |  t  r: g  t |  d t D] } | j ^ q" } n t d   g  | D] } t | |  ^ qM } t |  d k r | d S| S(   s  
    Returns list of tensor indices given their names and their types

    Parameters
    ==========

    s : string of comma separated names of indices

    typ : ``TensorIndexType`` of the indices

    Examples
    ========

    >>> from sympy.tensor.tensor import TensorIndexType, tensor_indices
    >>> Lorentz = TensorIndexType('Lorentz', dummy_fmt='L')
    >>> a, b, c, d = tensor_indices('a,b,c,d', Lorentz)
    t   seqs   expecting a stringi   i    (   R   R   R   R;   RE   R?   RM   R+   (   R=  RF   R$   R   R4   t   tilist(    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyt   tensor_indices  s    +"R  c           B  sD   e  Z d  Z d   Z e d    Z e d    Z e d    Z RS(   s  
    Monoterm symmetry of a tensor

    Parameters
    ==========

    bsgs : tuple ``(base, sgs)`` BSGS of the symmetry of the tensor

    Attributes
    ==========

    ``base`` : base of the BSGS
    ``generators`` : generators of the BSGS
    ``rank`` : rank of the tensor

    Notes
    =====

    A tensor can have an arbitrary monoterm symmetry provided by its BSGS.
    Multiterm symmetries, like the cyclic symmetry of the Riemann tensor,
    are not covered.

    See Also
    ========

    sympy.combinatorics.tensor_can.get_symmetric_group_sgs

    Examples
    ========

    Define a symmetric tensor

    >>> from sympy.tensor.tensor import TensorIndexType, TensorSymmetry, TensorType, get_symmetric_group_sgs
    >>> Lorentz = TensorIndexType('Lorentz', dummy_fmt='L')
    >>> sym2 = TensorSymmetry(get_symmetric_group_sgs(2))
    >>> S2 = TensorType([Lorentz]*2, sym2)
    >>> V = S2('V')
    c         O  s   t  |  d k r% | d \ } } n- t  |  d k rF | \ } } n t d   t | t  sp t |   } n  t | t  s t |   } n  t j |  | | |  } | S(   Ni   i    i   s:   bsgs required, either two separate parameters or one tuple(   R+   t	   TypeErrorR   R   R
   R  (   R  R   t   kw_argsR   R   R  (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyR  '  s    c         C  s   |  j  d S(   Ni    (   R   (   R.   (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyR   6  s    c         C  s   |  j  d S(   Ni   (   R   (   R.   (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyR   :  s    c         C  s   |  j  d d j d S(   Ni   i    i   (   R   t   size(   R.   (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyRx   >  s    (   R   R   R   R  R  R   R   Rx   (    (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyR     s
   &	c          G  s   d d l  m } d   } |  s; t t   t | d    St |   d k rn t |  d d |  rn t |   S| |  d  \ } } x? |  d D]3 } | |  \ } } t | | | |  \ } } q Wt t | |   S(   s1  
    Return a ``TensorSymmetry`` object.

    One can represent a tensor with any monoterm slot symmetry group
    using a BSGS.

    ``args`` can be a BSGS
    ``args[0]``    base
    ``args[1]``    sgs

    Usually tensors are in (direct products of) representations
    of the symmetric group;
    ``args`` can be a list of lists representing the shapes of Young tableaux

    Notes
    =====

    For instance:
    ``[[1]]``       vector
    ``[[1]*n]``     symmetric tensor of rank ``n``
    ``[[n]]``       antisymmetric tensor of rank ``n``
    ``[[2, 2]]``    monoterm slot symmetry of the Riemann tensor
    ``[[1],[1]]``   vector*vector
    ``[[2],[1],[1]`` (antisymmetric tensor)*vector*vector

    Notice that with the shape ``[2, 2]`` we associate only the monoterm
    symmetries of the Riemann tensor; this is an abuse of notation,
    since the shape ``[2, 2]`` corresponds usually to the irreducible
    representation characterized by the monoterm symmetries and by the
    cyclic symmetry.

    Examples
    ========

    Symmetric tensor using a Young tableau

    >>> from sympy.tensor.tensor import TensorIndexType, TensorType, tensorsymmetry
    >>> Lorentz = TensorIndexType('Lorentz', dummy_fmt='L')
    >>> sym2 = tensorsymmetry([1, 1])
    >>> S2 = TensorType([Lorentz]*2, sym2)
    >>> V = S2('V')

    Symmetric tensor using a ``BSGS`` (base, strong generator set)

    >>> from sympy.tensor.tensor import get_symmetric_group_sgs
    >>> sym2 = tensorsymmetry(*get_symmetric_group_sgs(2))
    >>> S2 = TensorType([Lorentz]*2, sym2)
    >>> V = S2('V')
    i(   t   Permutationc         S  s   t  |   d k r. |  d } t | d  } nR t d   |  D  r_ t  |   } t |  } n! |  d d g k rz t } n t  | S(   Ni   i    c         s  s   |  ] } | d  k Vq d S(   i   N(    (   R   R$   (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pys	   <genexpr>}  s    i   (   R+   R   R   R	   t   NotImplementedError(   R   RB   t   bsgs(    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyt   tableau2bsgsw  s    
	i   i   i    (   t   sympy.combinatoricsRG  R  R   R+   R   R   (   R   RG  RJ  R   t   sgsR   t   basext   sgsx(    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyt   tensorsymmetryC  s    2	)
R  c           B  s_   e  Z d  Z e Z d   Z e d    Z e d    Z e d    Z	 d   Z
 d d  Z RS(   si  
    Class of tensor types.

    Parameters
    ==========

    index_types : list of ``TensorIndexType`` of the tensor indices
    symmetry : ``TensorSymmetry`` of the tensor

    Attributes
    ==========

    ``index_types``
    ``symmetry``
    ``types`` : list of ``TensorIndexType`` without repetitions

    Examples
    ========

    Define a symmetric tensor

    >>> from sympy.tensor.tensor import TensorIndexType, tensorsymmetry, TensorType
    >>> Lorentz = TensorIndexType('Lorentz', dummy_fmt='L')
    >>> sym2 = tensorsymmetry([1, 1])
    >>> S2 = TensorType([Lorentz]*2, sym2)
    >>> V = S2('V')
    c         K  s=   | j  t |  k s t  t j |  t |   | |  } | S(   N(   Rx   R+   R_   R
   R  R   (   R  R)   R   RE  R  (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyR    s    c         C  s   |  j  d S(   Ni    (   R   (   R.   (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyR)     s    c         C  s   |  j  d S(   Ni   (   R   (   R.   (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyR     s    c         C  s   t  t |  j  d d   S(   NR#   c         S  s   |  j  S(   N(   RE   (   R$   (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyR%     R&   (   Rd   t   setR)   (   R.   (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyt   types  s    c         C  s$   d g  |  j  D] } t |  ^ q S(   Ns   TensorType(%s)(   R)   R  (   R.   R$   (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyRg     s    i    c         C  s   t  | t  r: g  t | d t D] } | j ^ q" } n t d   t |  d k rl t | d |  |  Sg  | D] } t | |  |  ^ qs Sd S(   s|  
        Return a TensorHead object or a list of TensorHead objects.

        ``s``  name or string of names

        ``comm``: commutation group number
        see ``_TensorManager.set_comm``

        Examples
        ========

        Define symmetric tensors ``V``, ``W`` and ``G``, respectively
        commuting, anticommuting and with no commutation symmetry

        >>> from sympy.tensor.tensor import TensorIndexType, tensor_indices, tensorsymmetry, TensorType, canon_bp
        >>> Lorentz = TensorIndexType('Lorentz', dummy_fmt='L')
        >>> a, b = tensor_indices('a,b', Lorentz)
        >>> sym2 = tensorsymmetry([1]*2)
        >>> S2 = TensorType([Lorentz]*2, sym2)
        >>> V = S2('V')
        >>> W = S2('W', 1)
        >>> G = S2('G', 2)
        >>> canon_bp(V(a, b)*V(-b, -a))
        V(L_0, L_1)*V(-L_0, -L_1)
        >>> canon_bp(W(a, b)*W(-b, -a))
        0
        RA  s   expecting a stringi   i    N(   R   R   R   R;   RE   R?   R+   R   (   R.   R=  R   R$   t   namesRE   (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyR     s    +(   R   R   R   R@   t   is_commutativeR  R  R)   R   RQ  Rg   R   (    (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyR    s   		i    c         C  se   | d k r7 g  t t |   D] } d g ^ q } n  t |   } t | |  } | |  |  } | S(   s  
    Function generating tensorhead(s).

    Parameters
    ==========

    name : name or sequence of names (as in ``symbol``)

    typ :  index types

    sym :  same as ``*args`` in ``tensorsymmetry``

    comm : commutation group number
    see ``_TensorManager.set_comm``


    Examples
    ========

    >>> from sympy.tensor.tensor import TensorIndexType, tensor_indices, tensorhead
    >>> Lorentz = TensorIndexType('Lorentz', dummy_fmt='L')
    >>> a, b = tensor_indices('a,b', Lorentz)
    >>> A = tensorhead('A', [Lorentz]*2, [[1]*2])
    >>> A(a, -b)
    A(a, -b)

    If no symmetry parameter is provided, assume there are not index
    symmetries:

    >>> B = tensorhead('B', [Lorentz, Lorentz])
    >>> B(a, -b)
    B(a, -b)

    i   N(   RK   R   R+   RO  R  (   RE   RF   R2  R   R4   R   t   th(    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyR     s    #+R   c           B  s   e  Z d  Z e Z d d  Z e d    Z e d    Z e d    Z	 e d    Z
 e d    Z e d    Z e d	    Z d
   Z d   Z d   Z d   Z d   Z e d    Z e j d    Z e j d    Z d   Z d   Z RS(   sk  
    Tensor head of the tensor

    Parameters
    ==========

    name : name of the tensor

    typ : list of TensorIndexType

    comm : commutation group number

    Attributes
    ==========

    ``name``
    ``index_types``
    ``rank``
    ``types``  :  equal to ``typ.types``
    ``symmetry`` : equal to ``typ.symmetry``
    ``comm`` : commutation group

    Notes
    =====

    A ``TensorHead`` belongs to a commutation group, defined by a
    symbol on number ``comm`` (see ``_TensorManager.set_comm``);
    tensors in a commutation group have the same commutation properties;
    by default ``comm`` is ``0``, the group of the commuting tensors.

    Examples
    ========

    >>> from sympy.tensor.tensor import TensorIndexType, tensorhead, TensorType
    >>> Lorentz = TensorIndexType('Lorentz', dummy_fmt='L')
    >>> A = tensorhead('A', [Lorentz, Lorentz], [[1],[1]])

    Examples with ndarray values, the components data assigned to the
    ``TensorHead`` object are assumed to be in a fully-contravariant
    representation. In case it is necessary to assign components data which
    represents the values of a non-fully covariant tensor, see the other
    examples.

    >>> from sympy.tensor.tensor import tensor_indices, tensorhead
    >>> from sympy import diag
    >>> i0, i1 = tensor_indices('i0:2', Lorentz)

    Specify a replacement dictionary to keep track of the arrays to use for
    replacements in the tensorial expression. The ``TensorIndexType`` is
    associated to the metric used for contractions (in fully covariant form):

    >>> repl = {Lorentz: diag(1, -1, -1, -1)}

    Let's see some examples of working with components with the electromagnetic
    tensor:

    >>> from sympy import symbols
    >>> Ex, Ey, Ez, Bx, By, Bz = symbols('E_x E_y E_z B_x B_y B_z')
    >>> c = symbols('c', positive=True)

    Let's define `F`, an antisymmetric tensor, we have to assign an
    antisymmetric matrix to it, because `[[2]]` stands for the Young tableau
    representation of an antisymmetric set of two elements:

    >>> F = tensorhead('F', [Lorentz, Lorentz], [[2]])

    Let's update the dictionary to contain the matrix to use in the
    replacements:

    >>> repl.update({F(-i0, -i1): [
    ... [0, Ex/c, Ey/c, Ez/c],
    ... [-Ex/c, 0, -Bz, By],
    ... [-Ey/c, Bz, 0, -Bx],
    ... [-Ez/c, -By, Bx, 0]]})

    Now it is possible to retrieve the contravariant form of the Electromagnetic
    tensor:

    >>> F(i0, i1).replace_with_arrays(repl, [i0, i1])
    [[0, -E_x/c, -E_y/c, -E_z/c], [E_x/c, 0, -B_z, B_y], [E_y/c, B_z, 0, -B_x], [E_z/c, -B_y, B_x, 0]]

    and the mixed contravariant-covariant form:

    >>> F(i0, -i1).replace_with_arrays(repl, [i0, -i1])
    [[0, E_x/c, E_y/c, E_z/c], [E_x/c, 0, B_z, -B_y], [E_y/c, -B_z, 0, B_x], [E_z/c, B_y, -B_x, 0]]

    Energy-momentum of a particle may be represented as:

    >>> from sympy import symbols
    >>> P = tensorhead('P', [Lorentz], [[1]])
    >>> E, px, py, pz = symbols('E p_x p_y p_z', positive=True)
    >>> repl.update({P(i0): [E, px, py, pz]})

    The contravariant and covariant components are, respectively:

    >>> P(i0).replace_with_arrays(repl, [i0])
    [E, p_x, p_y, p_z]
    >>> P(-i0).replace_with_arrays(repl, [-i0])
    [E, -p_x, -p_y, -p_z]

    The contraction of a 1-index tensor by itself:

    >>> expr = P(i0)*P(-i0)
    >>> expr.replace_with_arrays(repl, [])
    E**2 - p_x**2 - p_y**2 - p_z**2
    i    c         K  s   t  | t  r t |  } n$ t  | t  r6 | } n t d   t j |  } t j |  | | |  } | j d j	 | _
 t | j  | _ | j | _ | | _ | S(   Ns   invalid namei    (   R   R   R   R?   R   R   R
   R  R   RE   R=   R+   R)   t   _rankR   R   R   (   R  RE   RF   R   RE  R<  t   comm2iR  (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyR    s    		c         C  s   |  j  S(   N(   R=   (   R.   (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyRE     s    c         C  s   |  j  S(   N(   RU  (   R.   (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyRx     s    c         C  s   |  j  S(   N(   R   (   R.   (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyR     s    c         C  s   |  j  d S(   Ni   (   R   (   R.   (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyRF     s    c         C  s   |  j  S(   N(   R   (   R.   (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyR     s    c         C  s   |  j  d j S(   Ni   (   R   RQ  (   R.   (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyRQ    s    c         C  s   |  j  d j S(   Ni   (   R   R)   (   R.   (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyR)     s    c         C  s"   |  j  |  j f | j  | j f k  S(   N(   RE   R)   (   R.   R4  (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyR5    s    c         C  s   t  j |  j | j  } | S(   s   
        Returns ``0`` if ``self`` and ``other`` commute, ``1`` if they anticommute.

        Returns ``None`` if ``self`` and ``other`` neither commute nor anticommute.
        (   R   R   R   (   R.   R4  t   r(    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyt   commutes_with  s    c         C  s6   d |  j  d j g  |  j D] } t |  ^ q  f S(   Ns   %s(%s)t   ,(   RE   t   joinR)   R  (   R.   R$   (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyR>    s    c         O  s   t  |  | |  } | j   S(   s  
        Returns a tensor with indices.

        There is a special behavior in case of indices denoted by ``True``,
        they are considered auto-matrix indices, their slots are automatically
        filled, and confer to the tensor the behavior of a matrix or vector
        upon multiplication with another tensor containing auto-matrix indices
        of the same ``TensorIndexType``. This means indices get summed over the
        same way as in matrix multiplication. For matrix behavior, define two
        auto-matrix indices, for vector behavior define just one.

        Examples
        ========

        >>> from sympy.tensor.tensor import TensorIndexType, tensor_indices, tensorhead
        >>> Lorentz = TensorIndexType('Lorentz', dummy_fmt='L')
        >>> a, b = tensor_indices('a,b', Lorentz)
        >>> A = tensorhead('A', [Lorentz]*2, [[1]*2])
        >>> t = A(a, -b)
        >>> t
        A(a, -b)

        (   R   t   doit(   R.   R*   RE  R   (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyR     s    c   	      C  s   t  j   6 t  j d d t |  j d  k r> t d   n  Wd  QXt   d d l m	 } m
 } g  |  j d j d D] } | j ^ qv } |  j } | j   } xF | D]> } | | | |  } | | d | f | d | d f  } q W| t d d  | S(   Nt   ignoret   categorys   No power on abstract tensors.i   (   R   R   i    i   (   t   warningst   catch_warningst   filterwarningsR   R   RK   R?   R!   R   R   R   R   Rx   R   (	   R.   R4  R   R   RT   t   metricst   marrayt	   marraydimR   (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyt   __pow__  s    *	*c         C  s   t    t |  S(   N(   R!   R#  (   R.   (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyR     s    c         C  s   t    | t |  <d  S(   N(   R!   R#  (   R.   R   (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyR     s    c         C  s!   t    |  t k r t |  =n  d  S(   N(   R!   R#  (   R.   (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyR     s    c         C  s   t    |  j j   S(   N(   R!   R   t   __iter__(   R.   (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyRe    s    c         C  s-   |  j  d k r d S|  t k r) t |  =n  d S(   s   
        EXPERIMENTAL: do not rely on this API method.

        Destroy components data associated to the ``TensorHead`` object, this
        checks for attached components data, and destroys components data too.
        R0  N(   RE   R#  (   R.   (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyR7     s    	(   R   R   R   R@   RS  R  R  RE   Rx   R   RF   R   RQ  R)   R5  RX  R>  R   Rd  R   R8  R9  Re  R7  (    (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyR     s(   j							c         C  s"   x | D] } |  j  | }  q W|  S(   N(   R   (   t   exprRI   t   p(    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyt   _get_argtree_pos  s    R   c           B  s.  e  Z d  Z d Z e Z d   Z d   Z d   Z d   Z	 d   Z
 d   Z d   Z d	   Z d
   Z d   Z d   Z d   Z e Z e Z d   Z d   Z e d    Z d   Z d   Z d   Z d   Z d   Z e d    Z e d    Z e d    Z  e d    Z! d   Z" d   Z# RS(   sg  
    Abstract base class for tensor expressions

    Notes
    =====

    A tensor expression is an expression formed by tensors;
    currently the sums of tensors are distributed.

    A ``TensExpr`` can be a ``TensAdd`` or a ``TensMul``.

    ``TensAdd`` objects are put in canonical form using the Butler-Portugal
    algorithm for canonicalization under monoterm symmetries.

    ``TensMul`` objects are formed by products of component tensors,
    and include a coefficient, which is a SymPy expression.


    In the internal representation contracted indices are represented
    by ``(ipos1, ipos2, icomp1, icomp2)``, where ``icomp1`` is the position
    of the component tensor with contravariant index, ``ipos1`` is the
    slot which the index occupies in that component tensor.

    Contracted indices are therefore nameless in the internal representation.
    g      (@c         C  s   |  t  j S(   N(   R   t   NegativeOne(   R.   (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyR@  7  s    c         C  s
   t   d  S(   N(   RH  (   R.   (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyt   __abs__:  s    c         C  s   t  |  |  j   S(   N(   R   R[  (   R.   R4  (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyt   __add__=  s    c         C  s   t  | |   j   S(   N(   R   R[  (   R.   R4  (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyt   __radd__@  s    c         C  s   t  |  |  j   S(   N(   R   R[  (   R.   R4  (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyt   __sub__C  s    c         C  s   t  | |   j   S(   N(   R   R[  (   R.   R4  (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyt   __rsub__F  s    c         C  s   t  |  |  j   S(   s  
        Multiply two tensors using Einstein summation convention.

        If the two tensors have an index in common, one contravariant
        and the other covariant, in their product the indices are summed

        Examples
        ========

        >>> from sympy.tensor.tensor import TensorIndexType, tensor_indices, tensorhead
        >>> Lorentz = TensorIndexType('Lorentz', dummy_fmt='L')
        >>> m0, m1, m2 = tensor_indices('m0,m1,m2', Lorentz)
        >>> g = Lorentz.metric
        >>> p, q = tensorhead('p,q', [Lorentz], [[1]])
        >>> t1 = p(m0)
        >>> t2 = q(-m0)
        >>> t1*t2
        p(L_0)*q(-L_0)
        (   R   R[  (   R.   R4  (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyt   __mul__I  s    c         C  s   t  | |   j   S(   N(   R   R[  (   R.   R4  (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyt   __rmul___  s    c         C  sD   t  |  } t | t  r* t d   n  t |  t j |  j   S(   Ns   cannot divide by a tensor(   R   R   R   R?   R   R   R	  R[  (   R.   R4  (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyt   __div__b  s    c         C  s   t  d   d  S(   Ns   cannot divide by a tensor(   R?   (   R.   R4  (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyt   __rdiv__h  s    c         C  s   t  j   6 t  j d d t |  j d  k r> t d   n  Wd  QXt   d d l m	 } m
 } |  j } |  j } | j   } xJ | D]B } | | | | d j j |  d | f | d | d f  } q W| t d d  | S(   NR\  R]  s   No power without ndarray data.i   (   R   R   i    i   (   R^  R_  R`  R   R   RK   R?   R!   R   R   R   R'   Rx   R2   R   (   R.   R4  R   R   R'   Rb  R   R   (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyRd  k  s"    		$c         C  s
   t   d  S(   N(   RH  (   R.   R4  (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyt   __rpow__  s    c         G  sI   |  j  t |   } | j d   d    } | j d   d    } | S(   sZ  
        Return a tensor with free indices substituted according to ``index_tuples``

        ``index_types`` list of tuples ``(old_index, new_index)``

        Examples
        ========

        >>> from sympy.tensor.tensor import TensorIndexType, tensor_indices, tensorhead
        >>> Lorentz = TensorIndexType('Lorentz', dummy_fmt='L')
        >>> i, j, k, l = tensor_indices('i,j,k,l', Lorentz)
        >>> A, B = tensorhead('A,B', [Lorentz]*2, [[1]*2])
        >>> t = A(i, k)*B(-k, -j); t
        A(i, L_0)*B(-L_0, -j)
        >>> t.fun_eval((i, k),(-j, l))
        A(k, L_0)*B(-L_0, l)
        c         S  s   t  |  t  S(   N(   R   R   (   R$   (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyR%     R&   c         S  s   |  j  d |  j  d   S(   Ni    i   (   R   (   R$   (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyR%     R&   c         S  s   t  |  t t f  S(   N(   R   R   R   (   R$   (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyR%     R&   c         S  s   t  |  j   j   S(   N(   R   R   R[  (   R$   (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyR%     R&   (   t   xreplaceR   t   replace(   R.   t   index_tuplesRf  (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyt   fun_eval  s    c         C  s)  d d l  m } t   d |  j k  o1 d k n r|  j j d } |  j d k re |  j j d n d } |  j d k r g  | } x t |  D]E } | j g   x/ t |  D]! } | | j |  | | f  q Wq Wn2 d g | } x" t |  D] } |  | | | <q W| |  St	 d   d S(   s   
        DEPRECATED: do not use.

        Returns ndarray components data as a matrix, if components data are
        available and ndarray dimension does not exceed 2.
        i(   t   Matrixi    i   i   s-   missing multidimensional reduction to matrix.N(
   t   sympyRx  R!   Rx   R   R   R   RA   RK   RH  (   R.   Rx  t   rowst   columnst   mat_listR4   Rz   (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyt
   get_matrix  s"    %
&
c         C  s    g  | D] } |  j  |  ^ q S(   N(   RD   (   t   indices1t   indices2R4   (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyt   _get_indices_permutation  s    c         K  s   t  |  |  j   S(   N(   t   _expandR[  (   R.   t   hints(    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyt   expand  s    c         K  s   |  S(   N(    (   R.   t   kwargs(    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyR    s    c         C  sI   t  g   } x6 |  j D]+ } t | t  r | j | j    q q W| S(   N(   RP  R   R   R   t   updatet   _get_free_indices_set(   R.   t   indsetR   (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyR    s
    c         C  sI   t  g   } x6 |  j D]+ } t | t  r | j | j    q q W| S(   N(   RP  R   R   R   R  t   _get_dummy_indices_set(   R.   R  R   (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyR    s
    c         C  sI   t  g   } x6 |  j D]+ } t | t  r | j | j    q q W| S(   N(   RP  R   R   R   R  t   _get_indices_set(   R.   R  R   (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyR    s
    c           s+   |  j         f d     |  d  S(   Nc         3  s   t  |  t  r, |    k r |  | f Vq n^ t  |  t t f  r xF t |  j  D]2 \ } } x#  | | | f  D] } | Vqt WqQ Wn  d  S(   N(   R   RM   R   R   R<   R   (   Rf  RI   Rg  R   R4   (   t	   dummy_sett   recursor(    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyR    s    (    (   R  (   R.   (    (   R  R  s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyt   _iterate_dummy_indices  s    	c           s+   |  j         f d     |  d  S(   Nc         3  s   t  |  t  r, |    k r |  | f Vq n^ t  |  t t f  r xF t |  j  D]2 \ } } x#  | | | f  D] } | Vqt WqQ Wn  d  S(   N(   R   RM   R   R   R<   R   (   Rf  RI   Rg  R   R4   (   t   free_setR  (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyR    s    (    (   R  (   R.   (    (   R  R  s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyt   _iterate_free_indices  s    	c           s     f d       |  d  S(   Nc         3  s   t  |  t  r |  | f Vn^ t  |  t t f  r{ xF t |  j  D]2 \ } } x#   | | | f  D] } | Vqe WqB Wn  d  S(   N(   R   RM   R   R   R<   R   (   Rf  RI   Rg  R   R4   (   R  (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyR    s    (    (    (   R.   (    (   R  s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyt   _iterate_indices  s    c           s  d d l  m  m  m  g    D] } | j ^ q# } g  } g  } | } xt    D]\ }	 }
 |
 | k r | j |
  } d  | | <qX n  |
 | k r | j |
  } d  | | <|
 | | <|
 j r | j	 |  qe| j	 |  qX | |	 } | d  k rt
 d   | f   n  d  | |	 <|
 | |	 <|
 j | j ArX |
 j rU| j	 |	  qe| j	 |	  qX qX Wt t    t |  @ t    k  rt
 d   | f   n       f d   } x= | D]5 } | | | } t j |  } | | |  |  }  qWx. | D]& } | | | } | | |  |  }  q	W  r]t j |    }  |  |  }  n  t |  d  r|  j   d k r|  d }  n  | |  f S(   Ni   (   R   R   R   s   incompatible indices: %s and %sc           sd     |  |  d d | f  } t  t t      } | | | d | d <| | < | |  S(   Ni   i   i    (   R   R   R+   (   R   R   RI   t   permu(   t	   free_ind1R   R   R   (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyt   contract_and_permute(  s    "Rx   i    (    (   R   R   R   R   R2   R<   RD   RK   R   RA   R?   R+   RP  R   R   R   R  R   Rx   (   R   R  t	   free_ind2t   replacement_dictR4   t   index_types1t   pos2upt   pos2downt   free2remainingRP   t   index1RQ   t   index2R  RI   R   t   metric_inverseRm   (    (   R  R   R   R   s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyt    _match_indices_with_other_tensor  sT    


	


	(!c           sT  d d l  m     f d   | j   D } x | j   D] \ } } t | t  ry g  t d  D] } | j ^ qa } n g  | j D] } | j ^ q } t |  | j	   k s t
 g  t | | j  D]* \ } }	 | d k	 r | |	 k n t ^ q  r9 t d | | | j f   q9 q9 W|  j |  \ }
 } |  j | | |
 |  \ } } | S(   s\  
        Replace the tensorial expressions with arrays. The final array will
        correspond to the N-dimensional array with indices arranged according
        to ``indices``.

        Parameters
        ==========

        replacement_dict
            dictionary containing the replacement rules for tensors.
        indices
            the index order with respect to which the array is read.

        Examples
        ========

        >>> from sympy.tensor.tensor import TensorIndexType, tensor_indices
        >>> from sympy.tensor.tensor import tensorhead
        >>> from sympy import symbols, diag

        >>> L = TensorIndexType("L")
        >>> i, j = tensor_indices("i j", L)
        >>> A = tensorhead("A", [L], [[1]])
        >>> A(i).replace_with_arrays({A(i): [1, 2]}, [i])
        [1, 2]
        >>> expr = A(i)*A(j)
        >>> expr.replace_with_arrays({A(i): [1, 2]}, [i, j])
        [[1, 2], [2, 4]]

        For contractions, specify the metric of the ``TensorIndexType``, which
        in this case is ``L``, in its covariant form:

        >>> expr = A(i)*A(-i)
        >>> expr.replace_with_arrays({A(i): [1, 2], L: diag(1, -1)}, [])
        -3

        Symmetrization of an array:

        >>> H = tensorhead("H", [L, L], [[1], [1]])
        >>> a, b, c, d = symbols("a b c d")
        >>> expr = H(i, j)/2 + H(j, i)/2
        >>> expr.replace_with_arrays({H(i, j): [[a, b], [c, d]]}, [i, j])
        [[a, b/2 + c/2], [b/2 + c/2, d]]

        Anti-symmetrization of an array:

        >>> expr = H(i, j)/2 - H(j, i)/2
        >>> repl = {H(i, j): [[a, b], [c, d]]}
        >>> expr.replace_with_arrays(repl, [i, j])
        [[0, b/2 - c/2], [-b/2 + c/2, 0]]

        The same expression can be read as the transpose by inverting ``i`` and
        ``j``:

        >>> expr.replace_with_arrays(repl, [j, i])
        [[0, -b/2 + c/2], [b/2 - c/2, 0]]
        i   (   t   Arrayc           s%   i  |  ] \ } }   |  |  q S(    (    (   R   R   R   (   R  (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pys
   <dictcomp>}  s   	 i   sE   shapes for tensor %s expected to be %s, replacement array shape is %sN(   R   R  t   itemsR   R   R   R   R)   R+   Rx   R   R   R   RK   R;   R?   t   _extract_dataR  (   R.   R  R*   R   R   R4   t   expected_shapet
   index_typeR*  R+  t   ret_indicest   last_indices(    (   R  s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyt   replace_with_arraysA  s    :%>c   	      C  s{   d d l  m } |  j   } |  j } g  | D]- \ } } | | d | | j j d f ^ q, } | rw | | |  } n  | S(   Ni(   t   Sumi    i   (   Ry  R  RJ   R(   R2   R   (	   R.   Rf  t   index_symbolsR  R*   R(   R4   Rz   t   sum_indices(    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyt   _check_add_Sum  s    	7($   R   R   R   t   _op_priorityR@   RS  R@  Rj  Rk  Rl  Rm  Rn  Ro  Rp  Rq  Rr  Rd  Rs  t   __truediv__t   __rtruediv__Rw  R}  R   R  R  R  R  R  R  R  R  R  R  R  R  R  (    (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyR     s>   																			@	WR   c           B  s  e  Z d  Z d   Z d   Z e d    Z e d    Z e d    Z d   Z	 e
 d    Z e
 d    Z d	   Z d
   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z e
 d    Z e j d    Z e j d    Z d   Z d   Z RS(   sm  
    Sum of tensors

    Parameters
    ==========

    free_args : list of the free indices

    Attributes
    ==========

    ``args`` : tuple of addends
    ``rank`` : rank of the tensor
    ``free_args`` : list of the free indices in sorted order

    Notes
    =====

    Sum of more than one tensor are put automatically in canonical form.

    Examples
    ========

    >>> from sympy.tensor.tensor import TensorIndexType, tensorhead, tensor_indices
    >>> Lorentz = TensorIndexType('Lorentz', dummy_fmt='L')
    >>> a, b = tensor_indices('a,b', Lorentz)
    >>> p, q = tensorhead('p,q', [Lorentz], [[1]])
    >>> t = p(a) + q(a); t
    p(a) + q(a)
    >>> t(b)
    p(b) + q(b)

    Examples with components data added to the tensor expression:

    >>> from sympy import symbols, diag
    >>> x, y, z, t = symbols("x y z t")
    >>> repl = {}
    >>> repl[Lorentz] = diag(1, -1, -1, -1)
    >>> repl[p(a)] = [1, 2, 3, 4]
    >>> repl[q(a)] = [x, y, z, t]

    The following are: 2**2 - 3**2 - 2**2 - 7**2 ==> -58

    >>> expr = p(a) + q(a)
    >>> expr.replace_with_arrays(repl, [a])
    [x + 1, y + 2, z + 3, t + 4]
    c         O  sM   g  | D] } | r t  |  ^ q } t j |  } t j |  | |  } | S(   N(   R   R   t   _tensAdd_flattenR
   R  (   R  R   RE  R$   R  (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyR    s    %c         K  sS  | j  d t  } | r@ g  |  j D] } | j |   ^ q" } n	 |  j } | sV t j St |  d k r t | d t  r | d St	 j
 |  t |  d k r | d Sg  | D] } | r | ^ q } | s t j St |  d k r | d St	 j |  } d   } | j d |  | s&t j St |  d k r@| d S|  j |   } | S(   Nt   deepi   i    c         S  s>   t  |   } t |  t  s( g  g  g  f S|  j | j | j f S(   N(   t   get_index_structureR   R   R8   R'   R(   (   R   R$   (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyt   sort_key  s    R#   (   R  R;   R   R[  R   R
  R+   R   R   R   t   _tensAdd_checkt   _tensAdd_collect_termsR-   t   func(   R.   R  R  R   R   R$   R  R  (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyR[    s2    (	&	c         C  sx   g  } xI |  D]A } t  | t t f  rA | j t | j   q | j |  q Wg  | D] } | j rY | ^ qY }  |  S(   N(   R   R   R   R6   R   R   RA   R   (   R   R   R$   (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyR  	  s    "c           s   t  g  t |  d  j D] } | d ^ q    g  |  d D]2 } t  g  t |  j D] } | d ^ qT  ^ q; } t   f d   | D  s t d   n  d  S(   Ni    i   c         3  s   |  ] } |   k Vq d  S(   N(    (   R   R$   (   t   indices0(    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pys	   <genexpr> 	  s    s&   all tensors must have the same indices(   RP  R  R'   R   R?   (   R   R$   R   t   list_indices(    (   R  s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyR  	  s    0Cc         C  sm  t  t  } t j } t |  d t  rA t |  d j    } n t g   } x |  D] } t | t  s | t g   k r t d   n  | | 7} qT n  | t | j    k r t d   n  | | j	 j
 | j  qT Wg  | j   D]9 \ } } t |   d k r t t |   |  j   ^ q } t | t  rMt | j  | } n | d k ri| g | } n  | S(   Ni    s   wrong valence(   R   R   R   R
  R   R   RP  Re   R?   t   nocoeffRA   R   R  R   R   R[  R   (   R   t
   terms_dictt   scalarst   free_indicesR   R   R   t   new_args(    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyR  #	  s(    	
Lc         C  sP   g  } xC |  j  D]8 } | j g  t |  D] } | | k r) | ^ q)  q W| S(   N(   R   R6   RJ   (   R.   R*   R   R4   (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyRJ   @	  s    6c         C  s   |  j  d j S(   Ni    (   R   Rx   (   R.   (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyRx   F	  s    c         C  s   |  j  d j S(   Ni    (   R   R   (   R.   (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyR   J	  s    c         K  s)   t  g  |  j D] } t | |  ^ q   S(   N(   R   R   R  (   R.   R  R4   (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyR  N	  s    c         G  s   |  j  } t |  } g  | D] } | j ^ q g  | D] } | j ^ q5 k r\ t d   n  | | k rl |  St t | |   } g  |  j D]! } | j | j |   j   ^ q } t |   j	   } | S(   s  Returns tensor with ordered free indices replaced by ``indices``

        Parameters
        ==========

        indices

        Examples
        ========

        >>> from sympy import Symbol
        >>> from sympy.tensor.tensor import TensorIndexType, tensor_indices, tensorhead
        >>> D = Symbol('D')
        >>> Lorentz = TensorIndexType('Lorentz', dim=D, dummy_fmt='L')
        >>> i0,i1,i2,i3,i4 = tensor_indices('i0:5', Lorentz)
        >>> p, q = tensorhead('p,q', [Lorentz], [[1]])
        >>> g = Lorentz.metric
        >>> t = p(i0)*p(i1) + g(i0,i1)*q(i2)*q(-i2)
        >>> t(i0,i2)
        metric(i0, i2)*q(L_0)*q(-L_0) + p(i0)*p(i2)
        >>> from sympy.tensor.tensor import canon_bp
        >>> canon_bp(t(i0,i1) - t(i1,i0))
        0
        s   incompatible types(
   R   R   R2   R?   R   R   R  Rw  R   R[  (   R.   R*   R   R$   Rv  R   t   res(    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyR   Q	  s    	81c         C  sD   |  j    } g  | j D] } t |  ^ q } t |   j   } | S(   sz   
        canonicalize using the Butler-Portugal algorithm for canonicalization
        under monoterm symmetries.
        (   R  R   R/   R   R[  (   R.   Rf  R$   R   R  (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyR/   u	  s    "c         C  s   t  |  } t | t  rA | j d k rA t d   |  j D  St | t  ri |  j | j k ri t Sn  t | t	  r t
 |  j  t
 | j  k r t St Sn  |  | } t | t  s | d k St | t  r | j d k St d   | j D  Sd  S(   Ni    c         s  s   |  ] } | j  d  k Vq d S(   i    N(   t   _coeff(   R   R$   (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pys	   <genexpr>	  s    c         s  s   |  ] } | j  d  k Vq d S(   i    N(   R  (   R   R$   (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pys	   <genexpr>	  s    (   R   R   R   R  R   R   R   Rx   R@   R   RP  R;   (   R.   R4  R   (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyt   equals	  s     

c         C  s   t    |  j | S(   N(   R!   R   (   R.   t   item(    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyR   	  s    c         C  sA   g  |  j  D] } | j |  ^ q
 } t |   j   } t |  S(   N(   R   t   contract_deltaR   R[  R/   (   R.   R,  R$   R   R   (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyR  	  s    %c         C  sA   g  |  j  D] } t | |  ^ q
 } t |   j   } t |  S(   s0  
        Raise or lower indices with the metric ``g``

        Parameters
        ==========

        g :  metric

        contract_all : if True, eliminate all ``g`` which are contracted

        Notes
        =====

        see the ``TensorIndexType`` docstring for the contraction conventions
        (   R   t   contract_metricR   R[  R/   (   R.   Rs   R$   R   R   (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyR  	  s    %c         G  sL   |  j  } g  } x* | D]" } | j |   } | j |  q Wt |   j   S(   ss  
        Return a tensor with free indices substituted according to ``index_tuples``

        Parameters
        ==========

        index_types : list of tuples ``(old_index, new_index)``

        Examples
        ========

        >>> from sympy.tensor.tensor import TensorIndexType, tensor_indices, tensorhead
        >>> Lorentz = TensorIndexType('Lorentz', dummy_fmt='L')
        >>> i, j, k, l = tensor_indices('i,j,k,l', Lorentz)
        >>> A, B = tensorhead('A,B', [Lorentz]*2, [[1]*2])
        >>> t = A(i, k)*B(-k, -j) + A(i, -j)
        >>> t.fun_eval((i, k),(-j, l))
        A(k, L_0)*B(-L_0, l) + A(k, l)
        (   R   Rw  RA   R   R[  (   R.   Rv  R   t   args1R$   R   (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyRw  	  s    	c         G  sL   |  j  } g  } x* | D]" } | j |   } | j |  q Wt |   j   S(   s  
        Return a tensor with free indices substituted according to ``index_tuples``

        Parameters
        ==========

        index_types : list of tuples ``(old_index, new_index)``

        Examples
        ========

        >>> from sympy.tensor.tensor import TensorIndexType, tensor_indices, tensorhead
        >>> Lorentz = TensorIndexType('Lorentz', dummy_fmt='L')
        >>> i, j, k, l = tensor_indices('i,j,k,l', Lorentz)
        >>> A, B = tensorhead('A,B', [Lorentz]*2, [[1]*2])
        >>> t = A(i, k)*B(-k, -j); t
        A(i, L_0)*B(-L_0, -j)
        >>> t.substitute_indices((i,j), (j, k))
        A(j, L_0)*B(-L_0, -k)
        (   R   t   substitute_indicesRA   R   R[  (   R.   Rv  R   R  R$   R   (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyR  	  s    	c         C  sb   g  } |  j  } x! | D] } | j t |   q W| j   d j |  } | j d d  } | S(   Ns    + s   + -s   - (   R   RA   R  R-   RZ  Ru  (   R.   R   R   R$   R=  (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyR>  	  s    	
c         C  s  d d l  m } m } t g  |  j D]0 } t | t  rG | j |  n	 g  | f ^ q#   \ } } g  | D] } | |  ^ qi } | d } xV t d t	 |   D]? } | | }	 | | }
 t
 j |	 |  } | |
 |  | | <q W| t | | j |
 j    f S(   Ni(   R  R   i    i   (   t   sympy.tensor.arrayR  R   R   R   R   R   R  R   R+   R   R  t   sumR&  R   (   R.   R  R  R   R   t   args_indicesR   R4   t   ref_indicesR*   R   Rm   (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyR  	  s    F


c         C  s   t    t |  j   S(   N(   R!   R#  R  (   R.   (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyR   
  s    c         C  s   t    | t |  <d  S(   N(   R!   R#  (   R.   R   (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyR   
  s    c         C  s!   t    |  t k r t |  =n  d  S(   N(   R!   R#  (   R.   (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyR   
  s    c         C  s2   t    |  j s t d   n  |  j j   j   S(   Ns    No iteration on abstract tensors(   R!   R   R?   t   flattenRe  (   R.   (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyRe  
  s    	c         G  s   t  j |  S(   N(   R   t   fromiter(   R.   R   (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyt   _eval_rewrite_as_Indexed
  s    (   R   R   R   R  R[  R   R  R  R  RJ   R  Rx   R   R  R   R/   R  R   R  R  Rw  R  R>  R  R   R8  R9  Re  R  (    (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyR     s2   /		3			$	
							
		R   c           B  s'  e  Z d  Z e Z d   Z e d    Z d   Z e d    Z	 e d  Z
 d   Z d   Z d   Z d	   Z e d
    Z e d    Z e d    Z e d    Z e d    Z e d    Z e d    Z e d    Z e d    Z d   Z e d  Z d   Z e d    Z e d    Z e d    Z e d    Z e d    Z  d   Z! d   Z" d   Z# d   Z$ d   Z% d    Z& d!   Z' d"   Z( d#   Z) d$   Z* d%   Z+ e d&    Z, e, j- d'    Z, e, j. d(    Z, d)   Z/ d*   Z0 d+   Z1 d,   Z2 d-   Z3 RS(.   s  
    Base tensor class, i.e. this represents a tensor, the single unit to be
    put into an expression.

    This object is usually created from a ``TensorHead``, by attaching indices
    to it. Indices preceded by a minus sign are considered contravariant,
    otherwise covariant.

    Examples
    ========

    >>> from sympy.tensor.tensor import TensorIndexType, tensor_indices, tensorhead
    >>> Lorentz = TensorIndexType("Lorentz", dummy_fmt="L")
    >>> mu, nu = tensor_indices('mu nu', Lorentz)
    >>> A = tensorhead("A", [Lorentz, Lorentz], [[1], [1]])
    >>> A(mu, -nu)
    A(mu, -nu)
    >>> A(mu, -mu)
    A(L_0, -L_0)

    c         K  s   | j  d t  } |  j | |  } t j |  | t |   |  } t j |   | _ t	 | j j
    | _ | j t |  k r t d   n  | | _ | | _ t j | | j  | _ | S(   NRt   s   wrong number of indices(   t   popR@   t   _parse_indicesR
   R  R   R"   R5   t   _index_structureRP  Re   t   _free_indices_setRx   R+   R?   t   _indicest   _is_canon_bpR   t   _build_index_mapt
   _index_map(   R  t   tensor_headR*   RE  Rt   R  (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyR  5
  s    		c         C  s1   i  } x$ |  D] } |  j  |  f | | <q W| S(   N(   RD   (   R*   t   index_structuret	   index_mapRN   (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyR  B
  s    c         K  s&   t  j |  g  \ } } } } | d S(   Ni    (   R   t   _tensMul_contract_indices(   R.   R  R   R*   R'   R(   (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyR[  I
  s    c         C  s*  t  | t t t f  s1 t d t |    n  t |  } x t |  D] \ } } t  | t  r t | |  j	 | t
  | | <qJ t  | t  r | j   \ } } | d k r t  | t  r t | |  j	 | t  | | <q"t d |   qJ t  | t  sJ t d | t |  f   qJ qJ W| S(   Ns"   indices should be an array, got %sis   index not understood: %ss   wrong type for index: %s is %s(   R   Rr   R   R   RD  t   typeR<   R   RM   R)   R;   R   t   as_coeff_MulR@   R?   (   R  R*   R4   RD   R   t   e(    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyR  M
  s      #c         C  s   | j    } |  j d | |  S(   NRt   (   RJ   t   _set_indices(   R.   t   imRt   R*   (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyt   _set_new_index_structure_
  s    c         O  sS   t  |  |  j k r$ t d   n  |  j |  j d | d | j d t  j   S(   Ns   indices length mismatchi    Rt   (   R+   R   R?   R  R   R  R@   R[  (   R.   R*   RE  (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyR  c
  s    c         C  s'   t  g  |  j j D] } | d ^ q  S(   Ni    (   RP  R  R'   (   R.   R4   (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyR  h
  s    c           sB   t  t j |  j j      t    f d   t |  j d  D  S(   Nc         3  s'   |  ] \ } } |   k r | Vq d  S(   N(    (   R   R4   RN   (   t	   dummy_pos(    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pys	   <genexpr>m
  s    i   (   RP  t	   itertoolst   chainR  R(   R<   R   (   R.   (    (   R  s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyR  k
  s    c         C  s   t  |  j d j  S(   Ni   (   RP  R   (   R.   (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyR  o
  s    c         C  s   |  j  S(   N(   R  (   R.   (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyRt   r
  s    c         C  s   |  j  S(   N(   R  (   R.   (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyR*   v
  s    c         C  s   |  j  j S(   N(   R  R'   (   R.   (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyR'   z
  s    c         C  s)   g  |  j  D] \ } } | | d f ^ q
 S(   Ni    (   R'   (   R.   R`   RI   (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyt   free_in_args~
  s    c         C  s   |  j  j S(   N(   R  R(   (   R.   (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyR(   
  s    c         C  s,   g  |  j  D] \ } } | | d d f ^ q
 S(   Ni    (   R(   (   R.   t   p1t   p2(    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyt   dum_in_args
  s    c         C  s   t  |  j  S(   N(   R+   R'   (   R.   (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyRx   
  s    c         C  s
   |  j  j S(   N(   R  R,   (   R.   (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyR   
  s    c         C  s$   t  g  |  j D] } | d ^ q  S(   Ni    (   Rd   R'   (   R.   R$   (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyR   
  s    c         C  s9   t  | t  s d St  | t  r5 |  j j | j  St S(   s   
        :param other:
        :return:
            0  commute
            1  anticommute
            None  neither commute nor anticommute
        i    (   R   R   R   R9   RX  RH  (   R.   R4  (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyRX  
  s
    c         C  s   t  |  | |  S(   s   
        Returns the tensor corresponding to the permutation ``g``

        For further details, see the method in ``TIDS`` with the same name.
        (   R}   (   R.   Rs   Rt   (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyR}   
  s    c         C  s   |  j  r |  S|  j   } | j j   \ } } } t | j g  } t | | | |  } | d k rk t j S|  j	 | t
  } | S(   Ni    (   R  R  R  Rl   R   R9   R   R   R
  R}   R;   (   R.   Rf  Rs   R   R   R   t   canR   (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyR/   
  s    	c         C  s   t  |  j j  S(   N(   R   R9   R)   (   R.   (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyR)   
  s    c         C  s   t  j S(   N(   R   R	  (   R.   (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyR   
  s    c         C  s   |  S(   N(    (   R.   (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyR  
  s    c         C  s   |  j  d S(   Ni    (   R   (   R.   (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyR9   
  s    c         C  s   |  j  d g S(   Ni    (   R   (   R.   (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyR8   
  s    c         C  s   |  g S(   N(    (   R.   (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyR[   
  s    c         K  s   |  S(   N(    (   R.   R  (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyR  
  s    c         C  s   |  S(   N(    (   R.   (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyt   sorted_components
  s    c         C  s   t  |  j d  S(   sN   
        Get a list of indices, corresponding to those of the tensor.
        i   (   R   R   (   R.   (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyRJ   
  s    c         C  s   |  j  j   S(   sS   
        Get a list of free indices, corresponding to those of the tensor.
        (   R  Re   (   R.   (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyRe   
  s    c         C  s   |  t  j f S(   N(   R   R	  (   R.   (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyt   as_base_exp
  s    c         G  s   t  |  |  S(   N(   R  (   R.   Rv  (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyR  
  s    c         G  s   |  j  } t |  } g  | D] } | j ^ q g  | D] } | j ^ q5 k r\ t d   n  | | k rl |  S|  j t t | |     } t t d   | D   t |  k r | j | j	   S| S(   s  Returns tensor with ordered free indices replaced by ``indices``

        Examples
        ========

        >>> from sympy.tensor.tensor import TensorIndexType, tensor_indices, tensorhead
        >>> Lorentz = TensorIndexType('Lorentz', dummy_fmt='L')
        >>> i0,i1,i2,i3,i4 = tensor_indices('i0:5', Lorentz)
        >>> A = tensorhead('A', [Lorentz]*5, [[1]*5])
        >>> t = A(i2, i1, -i2, -i3, i4)
        >>> t
        A(L_0, i1, -L_0, -i3, i4)
        >>> t(i1, i2, i3)
        A(L_0, i1, -L_0, i2, i3)
        s   incompatible typesc         s  s%   |  ] } | j  r | n | Vq d  S(   N(   R   (   R   R4   (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pys	   <genexpr>  s    (
   R   R   R2   R?   Rw  R   R+   RP  R  R   (   R.   R*   R   R$   R   (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyR   
  s    	8(c         C  s   t    |  j j   S(   N(   R!   R   Re  (   R.   (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyRe    s    c         C  s   t    |  j | S(   N(   R!   R   (   R.   R  (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyR     s    c           s  d d l  m   xi | j   D]E \ } } t | t  r | j d |  j d k r | } | } Pq q Wt d |  | f     f d   | j   D }   |  } |  j } | j } t |  d k r x- | D]% } | | k r t	 d |   q q Wg  | D] } | | k r | ^ q } n  t |  d k r| j
   }	 i  }
 x' | D] \ } } |	 | |
 |	 | <qKW| j |
  j   } t j | g | t |	   } n  |  j   } | j   } |  j | | | |  S(   Ni   (   R  i    s   %s not found in %sc           s%   i  |  ] \ } }   |  |  q S(    (    (   R   t   kR   (   R  (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pys
   <dictcomp>  s   	 s'   %s with contractions is not implemented(   R   R  R  R   R   R   R?   R(   R+   RH  RJ   Rt  R[  R   R   Re   R  (   R.   R  R  R   R4  R   t   dum1t   dum2t   pairR  t   replR  R  R  R  (    (   R  s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyR    s4    )		(!c         C  s   t    t |  S(   N(   R!   R#  (   R.   (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyR   5  s    c         C  s   t    | t |  <d  S(   N(   R!   R#  (   R.   R   (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyR   :  s    c         C  s=   t    |  t k r t |  =n  |  j t k r9 t |  j =n  d  S(   N(   R!   R#  R   (   R.   (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyR   @  s
    
c         C  sc   g  |  j  D] } t |  ^ q
 } |  j } | j d k rT d | j d j |  f Sd | j Sd  S(   Ni    s   %s(%s)s   , s   %s(   R*   R  R9   Rx   RE   RZ  (   R.   R`   R*   R9   (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyR>  H  s
    "	c         C  sp   | d k r |  j  d k St |  } t | t  sQ |  j sD t  t j | k Sd   } | |   | |  k S(   Ni    c         S  sL   |  j    } | j t | j  t t | j   t t | j   f } | S(   N(   R/   R   Rr   R8   Rd   R'   R(   (   R.   R   RW  (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyt   _get_compar_compX  s    *(   R   R   R   R   R8   R_   R   R	  (   R.   R4  R  (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyR  P  s    	c         C  s   |  j  | k r |  St |  j  d k r, |  S| j d j } t j } | j d } | s | j d  k rv t	 d   n  | | j } nT | j d  k r t	 d   n  | | j } |  j
 d \ } } | | k  r | } n  | S(   Ni    s   dimension not assigned(   R9   R+   R'   R)   R   R   R	  R  RK   R?   R(   (   R.   Rs   R  t   signRF   t   dp0t   dp1(    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyR  `  s$    	
c         C  s   |  j  |  S(   N(   R  (   R.   R   (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyR  ~  s    c         C  s\   d d l  m } g  |  j   D] } | j d ^ q } | | j d |  } |  j | |  S(   Ni(   t   Indexedi    (   Ry  R  RJ   R   R  (   R.   R   R*   R  R4   R  Rf  (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyR    s    &(4   R   R   R   R@   RS  R  R   R  R[  R  R  R  R  R  R  R  Rt   R*   R'   R  R(   R  Rx   R   R   RX  R}   R/   R)   R   R  R9   R8   R[   R  R  RJ   Re   R  R  R   Re  R   R  R   R8  R9  R>  R  R  R  R  (    (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyR   
  s^   																 			%				R   c           B  sc  e  Z d  Z e j Z d   Z e d    Z e d    Z	 e e
 d   Z e d    Z e d    Z d   Z e d    Z e d	    Z d
   Z d   Z d   Z e d    Z e d    Z e d    Z e d    Z e d    Z e d    Z e d    Z e d    Z e d    Z e d    Z e d    Z d   Z  d   Z! d   Z" d   Z# d   Z$ d   Z% d   Z& d   Z' d    Z( d!   Z) e* d"  Z+ d#   Z, d$   Z- d%   Z. d&   Z/ e* d'  Z0 d(   Z1 e d)    Z2 d*   Z3 d+   Z4 d,   Z5 e d-    Z6 e6 j7 d.    Z6 e6 j8 d/    Z6 d0   Z9 d1   Z: RS(2   s  
    Product of tensors

    Parameters
    ==========

    coeff : SymPy coefficient of the tensor
    args

    Attributes
    ==========

    ``components`` : list of ``TensorHead`` of the component tensors
    ``types`` : list of nonrepeated ``TensorIndexType``
    ``free`` : list of ``(ind, ipos, icomp)``, see Notes
    ``dum`` : list of ``(ipos1, ipos2, icomp1, icomp2)``, see Notes
    ``ext_rank`` : rank of the tensor counting the dummy indices
    ``rank`` : rank of the tensor
    ``coeff`` : SymPy coefficient of the tensor
    ``free_args`` : list of the free indices in sorted order
    ``is_canon_bp`` : ``True`` if the tensor in in canonical form

    Notes
    =====

    ``args[0]``   list of ``TensorHead`` of the component tensors.

    ``args[1]``   list of ``(ind, ipos, icomp)``
    where ``ind`` is a free index, ``ipos`` is the slot position
    of ``ind`` in the ``icomp``-th component tensor.

    ``args[2]`` list of tuples representing dummy indices.
    ``(ipos1, ipos2, icomp1, icomp2)`` indicates that the contravariant
    dummy index is the ``ipos1``-th slot position in the ``icomp1``-th
    component tensor; the corresponding covariant index is
    in the ``ipos2`` slot position in the ``icomp2``-th component tensor.

    c         O  s5  | j  d t  } t t t |   } g  | D]: } t | t t f  rR | j n | g D] } | ^ qY q. } t j	 | d t \ } } } } g  | D] } | j
 ^ q }	 t | | |	 | d | }
 t j |  |  } | | _ |	 | _ |
 | _ t | j j  d t | j j  | _ t j | _ | | _ | S(   NRt   t   replace_indicesR/   i   (   R  R@   R   R   R   R   R   R   R   R  R2   R"   R   R  R  t   _index_typesR  R+   R'   R(   R,   R   R	  R  R  (   R  R   RE  Rt   R   R4   R*   R'   R(   R)   R  R  (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyR    s    G!			)	c         C  s  i  } i  } g  } g  } d } x!t  |   D]\ } } xt  |  D] \ } }	 t |	 t  sn t d   n  |	 | k r | j |	  }
 | j |	  } |	 j r | j |	 | |
 | | f  n | j |	 |
 | | | f  | j |	  n@ |	 | k rt d |	   n! | | |	 <| | |	 <| j |	  | d 7} qD Wq+ Wg  | j   D] \ } } | | f ^ qO} g  | j	   D] } | j
 ^ qz} | j d d    | | | | f S(   Ni    s   expected TensorIndexs   Repeated index: %si   R#   c         S  s   |  d S(   Ni   (    (   R$   (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyR%     R&   (   R<   R   RM   RD  R  R   RA   R?   R  t   keysRE   R-   (   R  t	   free2pos1t	   free2pos2t
   dummy_dataR*   RQ   RP   t   arg_indicest	   index_posRD   t
   other_pos1t
   other_pos2R4   Rg  R'   t
   free_names(    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyt   _indices_to_free_dum  s4    	

+"c         C  s,   g  |  D]! \ } } } } } | | f ^ q S(   N(    (   R  R4   t   p1at   p1bt   p2at   p2b(    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyt   _dummy_data_to_dum  s    c           s^  g  |  D] } i  ^ q } g  |  D] } t  |  ^ q  } t j |  \ } } } }	 t t      f d   }
 | r?x |	 D] \ } } } } } | j } x& t r |
 |  } | | k r Pq q Wt | | t  } | | | | <| | | | <| | | <| | | <q{ Wg  t |  |  D] \ } } | j	 |  ^ q}  n  t j
 |	  } |  | | | f S(   Nc           s+   |  j  }   |  }   |  c d 7<| | S(   Ni   (   RU   (   R2   RV   RW   (   RX   (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyRY     s    	
(   RJ   R   R  R   RZ   R2   R;   RM   R   Rt  R  (   R   R  RT   t   replacementsR   R  R*   R'   R  R  RY   t	   old_indext   pos1covt
   pos1contrat   pos2covt
   pos2contraR  t
   dummy_namet   dummyR  R(   (    (   RX   s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyR    s(    		
4c         C  sU   g  } xH |  D]@ } t  | t  s( q n  t  | t  r= q n  | j | j  q W| S(   sq   
        Get a list of ``Tensor`` objects having the same ``TIDS`` if multiplied
        by one another.
        (   R   R   R   R6   R8   (   R   R8   R   (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyt   _get_components_from_args  s    c         C  sx   | j    } d } x_ t |   D]Q \ } } t | t  s@ q n  | } | | j 7} t | j | | | ! |  | <q Wd  S(   Ni    (   RJ   R<   R   R   R   R   R9   (   R   R  R*   t   ind_posR4   R   t   prev_pos(    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyt   _rebuild_tensors_list,  s    c         K  s  |  j  } | j d t  } | rI g  |  j D] } | j |   ^ q+ } n	 |  j } g  | D] } | |  j k rY | ^ qY } t d   g  | D] } t | t  s | ^ q t	 j
  } g  | D] } t | t  r | ^ q } t |  d k r | S| |  j k r| g | } n  | d k r$t	 j St |  d k r>| d St j |  \ } } } }	 g  | D] }
 |
 j ^ q`} t | |	 | | d | } |  j |   } | | _ | | _ t | j j  d t | j j  | _ | | _ | | _  | S(   NR  c         S  s   |  | S(   N(    (   R   t   b(    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyR%   C  R&   i    i   R/   i   (   R  R  R;   R   R[  t   identityR   R   R   R   R	  R+   R
  R   R  R2   R"   R  R  R  R'   R(   R,   R  (   R.   R  Rt   R  R   R   R   R*   R'   R(   R4   R)   R  R  (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyR[  8  s4    	(	(:(		)		c         K  s%   t  |  t  j | | |  |  j   S(   N(   R   t%   _get_tensors_from_components_free_dumR[  (   R   R8   R'   R(   RE  (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyt	   from_dataa  s    c   
      C  s   t  j |  | |  } | j   } g  |  D] } d ^ q( } d } xG t |   D]9 \ } } | }	 | | j 7} t | | |	 | ! | | <qM W| S(   sv   
        Get a list of ``Tensor`` objects by distributing ``free`` and ``dum`` indices on the ``components``.
        i    N(   R"   R:   RJ   RK   R<   Rx   R   (
   R8   R'   R(   R  R*   R4   t   tensorsR	  R9   R
  (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyR  e  s    c         C  s$   t  g  |  j D] } | d ^ q  S(   Ni    (   RP  R'   (   R.   R4   (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyR  v  s    c           sA   t  t j |  j      t    f d   t |  j j    D  S(   Nc         3  s'   |  ] \ } } |   k r | Vq d  S(   N(    (   R   R4   RN   (   R  (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pys	   <genexpr>{  s    (   RP  R  R  R(   R<   R  RJ   (   R.   (    (   R  s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyR  y  s    c         C  s   g  t  |  j  D] } d  ^ q } d } xg t |  j  D]V \ } } t | t  sY q8 n  x% t  | j  D] } | | | | <qi W| | j 7} q8 W| S(   Ni    (   R   R   RK   R<   R   R   R   (   R.   R4   t
   arg_offsett   counterR   Rz   (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyt    _get_position_offset_for_indices}  s    "c         C  s$   t  g  |  j D] } | d ^ q  S(   Ni    (   Rd   R'   (   R.   R$   (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyR     s    c         C  s   |  j  |  j  S(   N(   R  R   (   R.   (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyR8     s    c         C  s   |  j  j S(   N(   R  R'   (   R.   (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyR'     s    c         C  sM   |  j    } |  j   } g  |  j D]' \ } } | | | | | | f ^ q" S(   N(   R  t   _get_indices_to_args_posR'   (   R.   R  t   argposR`   RI   (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyR    s    c         C  s   |  j  S(   N(   R  (   R.   (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyR     s    c         C  s8   |  j  g  |  j D] } t | t  r | ^ q   j   S(   N(   R  R   R   R   R[  (   R.   R   (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyR    s    c         C  s   |  j  j S(   N(   R  R(   (   R.   (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyR(     s    c         C  s\   |  j    } |  j   } g  |  j D]6 \ } } | | | | | | | | | | f ^ q" S(   N(   R  R  R(   (   R.   R  R  R  R  (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyR    s    c         C  s   t  |  j  S(   N(   R+   R'   (   R.   (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyRx     s    c         C  s   |  j  S(   N(   R,   (   R.   (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyR     s    c         C  s   |  j  S(   N(   R  (   R.   (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyR)     s    c         C  sg   | d k r |  j  d k St |  } t | t  sQ |  j sD t  |  j | k S|  j   | j   k S(   Ni    (   R   R   R   R   R8   R_   R  R/   (   R.   R4  (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyR    s    c         C  s   |  j  S(   s  
        Returns the list of indices of the tensor

        The indices are listed in the order in which they appear in the
        component tensors.
        The dummy indices are given a name which does not collide with
        the names of the free indices.

        Examples
        ========

        >>> from sympy.tensor.tensor import TensorIndexType, tensor_indices, tensorhead
        >>> Lorentz = TensorIndexType('Lorentz', dummy_fmt='L')
        >>> m0, m1, m2 = tensor_indices('m0,m1,m2', Lorentz)
        >>> g = Lorentz.metric
        >>> p, q = tensorhead('p,q', [Lorentz], [[1]])
        >>> t = p(m1)*g(m0,m2)
        >>> t.get_indices()
        [m1, m0, m2]
        >>> t2 = p(m1)*g(-m1, m2)
        >>> t2.get_indices()
        [L_0, -L_0, m2]
        (   R  (   R.   (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyRJ     s    c         C  s   |  j  j   S(   s  
        Returns the list of free indices of the tensor

        The indices are listed in the order in which they appear in the
        component tensors.

        Examples
        ========

        >>> from sympy.tensor.tensor import TensorIndexType, tensor_indices, tensorhead
        >>> Lorentz = TensorIndexType('Lorentz', dummy_fmt='L')
        >>> m0, m1, m2 = tensor_indices('m0,m1,m2', Lorentz)
        >>> g = Lorentz.metric
        >>> p, q = tensorhead('p,q', [Lorentz], [[1]])
        >>> t = p(m1)*g(m0,m2)
        >>> t.get_free_indices()
        [m1, m0, m2]
        >>> t2 = p(m1)*g(-m1, m2)
        >>> t2.get_free_indices()
        [m2]
        (   R  Re   (   R.   (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyRe     s    c         C  sm   |  j  d k r |  g Sg  } d } xD |  j  D]9 } t | t  r[ | j | |  d } q, | | 9} q, W| S(   s  
        Returns a list of tensors, whose product is ``self``

        Dummy indices contracted among different tensor components
        become free indices with the same name as the one used to
        represent the dummy indices.

        Examples
        ========

        >>> from sympy.tensor.tensor import TensorIndexType, tensor_indices, tensorhead
        >>> Lorentz = TensorIndexType('Lorentz', dummy_fmt='L')
        >>> a, b, c, d = tensor_indices('a,b,c,d', Lorentz)
        >>> A, B = tensorhead('A,B', [Lorentz]*2, [[1]*2])
        >>> t = A(a,b)*B(-b,c)
        >>> t
        A(a, L_0)*B(-L_0, c)
        >>> t.split()
        [A(a, L_0), B(-L_0, c)]
        i   (    (   R   R   R   RA   (   R.   t   splitpR  R   (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyR[     s    	c         K  s   g  |  j  D] } t | |  ^ q
 } g  | D]- } t | t t f  rP | j  n | f ^ q, } t g  t j |   D] } t |   ^ qr   S(   N(   R   R  R   R   R   R  t   productR   (   R.   R  R   R   R  R4   (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyR    s    %:c         C  s   t  t j |  d |  j j   S(   NRt   (   R   R   Ri  R  R[  (   R.   (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyR@    s    c         C  s   t    |  j | S(   N(   R!   R   (   R.   R  (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyR   !  s    c         C  sk   t  |  j  } |  j d k  t k r[ d } |  j t j k rI | d } qa | d | d <n d } | | f S(   Ni    t   -i   R&   (   R   R   R   R;   R   Ri  (   R.   R   R  (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyt!   _get_args_for_traditional_printer%  s    c   	      C  sJ  g  |  j  D] } t | t  r
 | ^ q
 } d } t |  d } x t |  D] } x t | | d  D] } | | d j | |  } | d k r qg n  | | d j j | | d j j f | | j j | | j j f k rg | | | | d | | d <| | <| r| } qqg qg WqN W| |  j	 } | d k rF| g | S| S(   s   
        Returns the ``args`` sorted according to the components commutation
        properties.

        The sorting is done taking into account the commutation group
        of the component tensors.
        i   ii    (   i    i   (
   R   R   R   R+   R   RX  R9   RQ  RE   R   (	   R.   R   t   cvR  RB   R4   Rz   R   R   (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyt    _sort_args_for_sorted_components2  s"    +%#%c         C  s   t  |  j     j   S(   sB   
        Returns a tensor product with sorted components.
        (   R   R  R[  (   R.   (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyR  O  s    c         C  s   t  |  | d | S(   s   
        Returns the tensor corresponding to the permutation ``g``

        For further details, see the method in ``TIDS`` with the same name.
        Rt   (   R}   (   R.   Rs   Rt   (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyR}   U  s    c   	      C  s   |  j  r |  S|  j   } t | t  r2 | j   S| j s? | S| j   } | j j   \ } } } t	 | j  } t
 | | | |  } | d k r t j S| j | t  } | S(   sX  
        Canonicalize using the Butler-Portugal algorithm for canonicalization
        under monoterm symmetries.

        Examples
        ========

        >>> from sympy.tensor.tensor import TensorIndexType, tensor_indices, tensorhead
        >>> Lorentz = TensorIndexType('Lorentz', dummy_fmt='L')
        >>> m0, m1, m2 = tensor_indices('m0,m1,m2', Lorentz)
        >>> A = tensorhead('A', [Lorentz]*2, [[2]])
        >>> t = A(m0,-m1)*A(m1,-m0)
        >>> t.canon_bp()
        -A(L_0, L_1)*A(-L_0, -L_1)
        >>> t = A(m0,-m1)*A(m1,-m2)*A(m2,-m0)
        >>> t.canon_bp()
        0
        i    (   R  R  R   R   R/   R8   R  R  Rl   R   R   R   R
  R}   R;   (	   R.   Rf  R   Rs   R   R   R   R  t   tmul(    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyR/   ]  s    	
	c         C  s   |  j  |  } | S(   N(   R  (   R.   R,  R   (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyR    s    c         C  s   t    } d } xu t |  j  D]d \ } } t | t  s@ q n  t | t  sU t  x+ t | j  D] } | | | <| d 7} qe Wq W| S(   sU   
        Get a dict mapping the index position to TensMul's argument number.
        i    i   (	   R   R<   R   R   R   R   R_   R   R   (   R.   t   pos_mapt   pos_countert   arg_iR   R4   (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyR    s    	
c         C  s  |  j    } |  | k r1 | j   } | j |  S|  j   } t |  j  } | j d j } g  t |  j  D]0 \ } } t	 | t
  rl | j | k rl | ^ ql } | s |  Sd }	 |  j }
 |  j } t   } x| D]} | | k r q n  g  | D]  } | | d | k r | ^ q } g  |
 D]4 } | | d | k sP| | d | k r"| ^ q"} | shq n  | j |  d | | <t |  d k r| s| \ } } | | d | k r| d } n
 | d } | | d | k r| d } n
 | d } |
 j | | f  qN| \ } } | | d | k rV| d } | d d k rz|	 }	 qzn$ | d } | d d k rz|	 }	 n  | | d | k r| d } |	 }	 n
 | d } |
 j | | f  nt |  d k rN| s~| d \ } } | | | | k r9| j d } | j d k r)t d   n  |	 | j }	 qK| | | k rR| } n | } | d \ } } | j | | f  qN| d \ } } | | | | k r| j d } | j d k rt d   n  |	 | j }	 | | k  rK|	 }	 qKqN| | | k r"| } | d k r(|	 }	 q(n | } | d \ } } | j | | f  n  g  |
 D] } | | k rU| ^ qU}
 g  | D] } | | k rz| ^ qz} q Wd } d g t |  } x@ t t |   D], } | | k r| d 7} qn  | | | <qWg  | D]4 \ } } | | | k r| | | | | f ^ q} g  t |
  D]V \ } \ } } | | | k rF| | | k rF| | | | | | | | f ^ qF}
 |	 t |   j   } t	 | t  s| St j | j | |
  } | j |  S(   s  
        Raise or lower indices with the metric ``g``

        Parameters
        ==========

        g : metric

        Notes
        =====

        see the ``TensorIndexType`` docstring for the contraction conventions

        Examples
        ========

        >>> from sympy.tensor.tensor import TensorIndexType, tensor_indices, tensorhead
        >>> Lorentz = TensorIndexType('Lorentz', dummy_fmt='L')
        >>> m0, m1, m2 = tensor_indices('m0,m1,m2', Lorentz)
        >>> g = Lorentz.metric
        >>> p, q = tensorhead('p,q', [Lorentz], [[1]])
        >>> t = p(m0)*q(m1)*g(-m0, -m1)
        >>> t.canon_bp()
        metric(L_0, L_1)*p(-L_0)*q(-L_1)
        >>> t.contract_metric(g).canon_bp()
        p(L_0)*q(-L_0)
        i    i   i   s   dimension not assignedN(   R  R/   R  R  R   R   R)   R   R<   R   R   R9   R(   R'   RP  t   addR+   RA   R  RK   R?   R   R   R[  R   R"   R:   R8   R  (   R.   Rs   Rf  R  R   R  R4   R$   t   gposR  R(   R'   t   elimt   gposxt   free1R  t   dum10t   dum11t   p0R  R  R  RF   R`   Rg  t   shiftt   shiftsR  R  (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyR    s    F

	-A








	%)
Aic         C  s   | j    } |  j d | |  S(   NRt   (   RJ   R  (   R.   R  Rt   R*   (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyR  3  s    c   	      O  s   t  |  |  j k r$ t d   n  t |  j  } d } | j d t  } xu t |  D]g \ } } t | t	  sz qY n  t | t
  s t  | j } | j | | | | !  | | <| | 7} qY Wt d | |  j   S(   Ns   indices length mismatchi    Rt   (   R+   R   R?   R   R   R  R@   R<   R   R   R   R_   R  R   R[  (	   R.   R*   RE  R   RI   Rt   R4   R   R   (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyR  7  s    	c         C  s?   x8 |  D]0 } t  | t  s" q n  t  | t  s t  q Wd  S(   N(   R   R   R   R_   (   R   R'   R(   R   (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyt&   _index_replacement_for_contract_metricF  s    c         G  s   t  |  |  S(   N(   R  (   R.   Rv  (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyR  M  s    c         G  s   |  j  } t |  } g  | D] } | j ^ q g  | D] } | j ^ q5 k r\ t d   n  | | k rl |  S|  j t t | |     } t t d   | D   t |  k r | j | j	   S| S(   s:  Returns tensor product with ordered free indices replaced by ``indices``

        Examples
        ========

        >>> from sympy import Symbol
        >>> from sympy.tensor.tensor import TensorIndexType, tensor_indices, tensorhead
        >>> D = Symbol('D')
        >>> Lorentz = TensorIndexType('Lorentz', dim=D, dummy_fmt='L')
        >>> i0,i1,i2,i3,i4 = tensor_indices('i0:5', Lorentz)
        >>> g = Lorentz.metric
        >>> p, q = tensorhead('p,q', [Lorentz], [[1]])
        >>> t = p(i0)*q(i1)*q(-i1)
        >>> t(i1)
        p(i1)*q(L_0)*q(-L_0)
        s   incompatible typesc         s  s%   |  ] } | j  r | n | Vq d  S(   N(   R   (   R   R4   (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pys	   <genexpr>k  s    (
   R   R   R2   R?   Rw  R   R+   RP  R  R   (   R.   R*   R   R$   R   (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyR   P  s    	8(c         C  s   t  g  |  j D]$ } t | t  r | j |  ^ q   \ } } t t j g  |  j D] } t | t  sS | ^ qS t j	  } t
 j |  \ } } }	 }
 t
 j |
  } |  j } | j d d    g  | D] } | d ^ q } | | t j | | |  f S(   NR#   c         S  s   |  d S(   Ni   (    (   R$   (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyR%   u  R&   i    (   R   R   R   R   R  R   t   operatort   mulR   R	  R   R  R  R   R-   R   R   (   R.   R  R   R  R   R   R   R*   R'   R  R  R(   R   R4   R  (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyR  o  s    @=	c         C  s   t    t |  j   } | S(   N(   R!   R#  R  (   R.   R   (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyR   y  s    c         C  s   t    t d   d  S(   Ns9   Not possible to set component data to a tensor expression(   R!   R?   (   R.   R   (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyR     s    c         C  s   t    t d   d  S(   Ns<   Not possible to delete component data to a tensor expression(   R!   R?   (   R.   (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyR     s    c         C  s2   t    |  j d  k r% t d   n  |  j j   S(   Ns    No iteration on abstract tensors(   R!   R   RK   R?   Re  (   R.   (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyRe    s    c         G  s   d d l  m } g  |  j   D] } | j d ^ q } g  | D]( } t | |  r_ | j d n | ^ q= } t j |  } |  j | |  S(   Ni(   R  i    (   Ry  R  RJ   R   R   R   R  R  (   R.   R   R  R4   R  R   Rf  (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyR    s
    &5(;   R   R   R   R   R	  R  R  R   R  R  R;   R  R  R  R[  R  R  R  R  R  R  R   R8   R'   R  R   R  R(   R  Rx   R   R)   R  RJ   Re   R[   R  R@  R   R  R  R  R@   R}   R/   R  R  R  R  R  R*  R  R   R  R   R8  R9  Re  R  (    (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyR     sh   &		/!	)				
			!								#							
	t   TensorElementc           B  sn   e  Z d  Z d   Z e d    Z e d    Z e d    Z e d    Z d   Z	 d   Z
 d   Z RS(	   s  
    Tensor with evaluated components.

    Examples
    ========

    >>> from sympy.tensor.tensor import TensorIndexType, tensorhead
    >>> from sympy import symbols
    >>> L = TensorIndexType("L")
    >>> i, j, k = symbols("i j k")
    >>> A = tensorhead("A", [L, L], [[1], [1]])
    >>> A(i, j).get_free_indices()
    [i, j]

    If we want to set component ``i`` to a specific value, use the
    ``TensorElement`` class:

    >>> from sympy.tensor.tensor import TensorElement
    >>> te = TensorElement(A(i, j), {i: 2})

    As index ``i`` has been accessed (``{i: 2}`` is the evaluation of its 3rd
    element), the free indices will only contain ``j``:

    >>> te.get_free_indices()
    [j]
    c           s   t  | t  s] t  | t  s1 t d |   n  | j g  | j D] } t | |  ^ qA   S| j     d     D   f d   | j   D }   f d   | j   D } t	 |  d k r | Sg    D] } | | j
   k r | ^ q } t |  } t j |  | |  } | | _ | S(   Ns   %s is not a tensor expressionc         S  s    i  |  ] } | | j  d   q S(   i    (   R   (   R   R4   (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pys
   <dictcomp>  s   	 c           s+   i  |  ]! \ } } |   j  | |   q S(    (   R  (   R   RD   R   (   t   name_translation(    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pys
   <dictcomp>  s   	 c           s+   i  |  ]! \ } } |   k r | |  q S(    (    (   R   RD   R   (   t   expr_free_indices(    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pys
   <dictcomp>  s   	 i    (   R   R   R   RD  R  R   R-  Re   R  R+   R  R   R  t   _free_indices(   R  Rf  R  R   R4   R  R  (    (   R/  R.  s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyR    s    ,+	c         C  s/   g  t  |  j    D] \ } } | | f ^ q S(   N(   R<   Re   (   R.   R4   RD   (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyR'     s    c         C  s   g  S(   N(    (   R.   (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyR(     s    c         C  s   |  j  d S(   Ni    (   t   _args(   R.   (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyRf    s    c         C  s   |  j  d S(   Ni   (   R1  (   R.   (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyR    s    c         C  s   |  j  S(   N(   R0  (   R.   (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyRe     s    c         C  s
   |  j    S(   N(   Re   (   R.   (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyRJ     s    c           s{   |  j  j |  \ } } |  j   t   f d   | D  } g  | D] } |   k rD | ^ qD } | j |  } | | f S(   Nc         3  s'   |  ] }   j  | t d    Vq d  S(   N(   R  t   sliceRK   (   R   R4   (   R  (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pys	   <genexpr>  s    (   Rf  R  R  Rr   R   (   R.   R  R  R   t   slice_tupleR4   (    (   R  s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyR    s    	%(   R   R   R   R  R  R'   R(   Rf  R  Re   RJ   R  (    (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyR-    s   			c         C  s   t  |  t  r |  j   S|  S(   s*   
    Butler-Portugal canonicalization
    (   R   R   R/   (   Rg  (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyR/     s    
c          G  sL   |  s t  j t j g  g  g   S|  d } x |  d D] } | | } q4 W| S(   s   
    product of tensors
    i    i   (   R   R  R   R	  (   R   R   t   tx(    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyt
   tensor_mul  s    
c         C  s   t  |  j d d   } g  | D] } | d ^ q \ } } } } t d  d |  } t d  d |  j | | f | | f | | f | | f  } t d  d |  j | | f | | f | | f | | f  }	 | | |	 }
 |
 S(   s   
    replace Riemann tensor with an equivalent expression

    ``R(m,n,p,q) -> 2/3*R(m,n,p,q) - 1/3*R(m,q,n,p) + 1/3*R(m,p,n,q)``

    R#   c         S  s   |  d S(   Ni   (    (   R$   (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyR%      R&   i    i   i   i   (   Rd   R'   R   R  (   t   t_rR'   R$   R   RB   Rg  t   qt   t0R?  t   t2t   t3(    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyt   riemann_cyclic_replace  s    )?>c   
      C  s   |  j    }  t |  t t f  r- |  g } n	 |  j } g  | D] } | j   ^ q= } g  | D]% } g  | D] } t |  ^ qi ^ q\ } g  | D] } t |   ^ q } t |   j	   }	 |	 s |	 St
 |	  Sd S(   s)  
    replace each Riemann tensor with an equivalent expression
    satisfying the cyclic identity.

    This trick is discussed in the reference guide to Cadabra.

    Examples
    ========

    >>> from sympy.tensor.tensor import TensorIndexType, tensor_indices, tensorhead, riemann_cyclic
    >>> Lorentz = TensorIndexType('Lorentz', dummy_fmt='L')
    >>> i, j, k, l = tensor_indices('i,j,k,l', Lorentz)
    >>> R = tensorhead('R', [Lorentz]*4, [[2, 2]])
    >>> t = R(i,j,k,l)*(R(-i,-j,-k,-l) - 2*R(-i,-k,-j,-l))
    >>> riemann_cyclic(t)
    0
    N(   R  R   R   R   R   R[   R;  R5  R   R[  R/   (
   R9  R   R$   t   a1R   R4  t   a2R   t   a3R:  (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyt   riemann_cyclic  s    	2c         C  so  d   } |  j  } i  } x |  j  D] } t | t  s= q" n  | | k rO q" n  | j } g  } x: t t |   D]& } | | | k rq | j |  qq qq Wt |  d k r t d |   n  t |  d k r" | | | <q" q" Wg  }	 g  }
 g  } x|  j D]\ } } } } | | | k r'q n  | | k rI|
 j | g  q n  | | | } | | | } | | k rwq n  | j	 |  | j	 |  k rt
  n  | | | } | | d k r| | f n	 | | f \ } } |	 } x |	 D] } | d | k r]| d | k rL| j	 t |   } | j |  |
 j | | | |   n | j |  Pq| d | k r| j d |  PqqW| j | | g  g  | D] } | | k r| ^ q}	 | |	  }	 q Wg  } x, |	 D]$ } x | D] } | j |  qWqWx, |
 D]$ } x | D] } | j |  qWq	Wg  t t |   D] } | | k rD| ^ qD} |	 |
 | f S(   s   
    returns ``(lines, traces, rest)`` for an index type,
    where ``lines`` is the list of list of positions of a matrix line,
    ``traces`` is the list of list of traced matrix lines,
    ``rest`` is the rest of the elements ot the tensor.
    c         S  s  d } x| t  |   k  r|  | } | d } | d } t } x| rt } xt | d t  |    D]r} | t  |   k r Pn  |  | d | k r t } | j |  | d  | d } |  j |  qh n  |  | d | k r1t } t |  | d  | |  | <|  | } |  | d } |  j |  qh n  |  | d | k rt } | j t |  | d    | d } |  j |  qh n  |  | d | k rh t } |  | d  | |  | <|  | } | d } |  j |  qh qh qh WqB W| d 7} q	 W|  S(   Ni    ii   (   R+   R;   R@   R   R6   R  t   reversed(   R   R4   R$   t   xendt   xstartt   hitRz   (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyt   _join_lines0  sN    


	 




i   s&   at most two indices of type %s allowedi   ii    (   R   R   R   R)   R   R+   RA   R?   R  RD   RH  t   mint   insert(   t   exR  RD  t	   argumentst   dtR   R)   R   R4   t   linest   tracest   traces1R'  R  t   c0t   c1t   ta0t   ta1t   b0t   b1t   lines1t   lineRB   R$   t   restR   (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyt	   get_lines)  st    	)			.%1c         C  s   t  |  t  s d S|  j   S(   N(    (   R   R   Re   (   R   (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyRe     s    c         C  s   t  |  t  s d S|  j   S(   N(    (   R   R   RJ   (   R   (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyRJ     s    c         C  s)   t  |  t  r |  j St g  g  g  g   S(   N(   R   R   R  R"   (   R   (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyR    s    c         C  sN   t  |  t  r t j St  |  t  r, |  j St  |  t  rJ t d   n  |  S(   Ns3   no coefficient associated to this tensor expression(   R   R   R   R	  R   R   R   R?   (   R   (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyt	   get_coeff  s    c         C  s    t  |  t  r |  j |  S|  S(   N(   R   R   R  (   R   Rs   (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyR    s    c         C  s   t  |  t  s |  St  |  t t f  r{ t |   j | d | } |  j | d | } | d t |  d k rw | S| St    d S(   s   
    Returns the tensor corresponding to the permutation ``g``

    For further details, see the method in ``TIDS`` with the same name.
    Rt   ii   N(	   R   R   R   R   R  R}   R  R+   RH  (   R   Rs   Rt   t   nimR  (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyR}     s    c         G  s   t  |  t  s |  S|  j } g  } x | D] \ } } x | D]p \ } } | j | j k r< | j | j k r< | j | j k r | j | | f  n | j | | f  Pq< q< W| j | | f  q) Wt j |  j	 |  j
 | |  j  }  |  S(   s  
    Return a tensor with free indices substituted according to ``index_tuples``

    ``index_types`` list of tuples ``(old_index, new_index)``

    Note: this method will neither raise or lower the indices, it will just replace their symbol.

    Examples
    ========

    >>> from sympy.tensor.tensor import TensorIndexType, tensor_indices, tensorhead
    >>> Lorentz = TensorIndexType('Lorentz', dummy_fmt='L')
    >>> i, j, k, l = tensor_indices('i,j,k,l', Lorentz)
    >>> A, B = tensorhead('A,B', [Lorentz]*2, [[1]*2])
    >>> t = A(i, k)*B(-k, -j); t
    A(i, L_0)*B(-L_0, -j)
    >>> t.substitute_indices((i,j), (j, k))
    A(j, L_0)*B(-L_0, -k)
    (   R   R   R'   R=   R2   R>   RA   R   R  R   R8   R(   (   R   Rv  R'   R$  Rz   R^   R4   R   (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyR    s    	$!c         K  s-   t  |  t  r |  j |   S|  j |   Sd  S(   N(   R   R   R  R  (   Rf  R  (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyR    s    (T   R   t
   __future__R    R   t   collectionsR   R+  R  Ry  R   R   R   t   sympy.combinatorics.tensor_canR   R   R   R	   t
   sympy.coreR
   R   R   R   R   R   t   sympy.core.compatibilityR   R   R   R   t   sympy.core.containersR   R   t   sympy.core.decoratorsR   t   sympy.core.symbolR   R   t   sympy.core.sympifyR   R   t   sympy.core.operationsR   t   sympy.matricesR   t   sympy.utilities.exceptionsR   R^  R!   R"   R   R   R#  t   objectR   R   R   RM   RC  R  RO  R  RK   R   R   Rh  R   R   R   R   R-  R/   R5  R;  R?  RV  Re   RJ   R  RW  R  R@   R}   R  R  (    (    (    s2   lib/python2.7/site-packages/sympy/tensor/tensor.pyt   <module>   st   "."$ 	 i		m	C	PX+	  z n   N				!	x							'