ó
¡¼™\c           @  s•  d  d l  m Z m Z d  d l m Z d  d l m Z d  d l m Z m	 Z	 m
 Z
 m Z m Z m Z m Z m Z 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 d  d l m Z d  d	 l m Z d  d
 l m  Z  d  d l! m" Z" d e	 f d „  ƒ  YZ# d e	 f d „  ƒ  YZ$ d e	 f d „  ƒ  YZ% d e	 f d „  ƒ  YZ& d e f d „  ƒ  YZ' d e f d „  ƒ  YZ( d e
 f d „  ƒ  YZ) d e
 f d „  ƒ  YZ* d e
 f d „  ƒ  YZ+ d e+ f d „  ƒ  YZ, d  e
 f d! „  ƒ  YZ- d" e
 f d# „  ƒ  YZ. d$ e
 f d% „  ƒ  YZ/ d& e0 e1 d' „ Z2 e0 d( „ Z3 d) „  Z4 e1 d* „ Z5 e1 d+ „ Z6 d, „  Z7 d- „  Z8 d. „  Z9 d/ „  Z: d0 „  Z; d1 „  Z< d2 S(3   iÿÿÿÿ(   t   print_functiont   division(   t   permutations(   t   Permutation(   t
   AtomicExprt   Basict   Exprt   Dummyt   Functiont   sympifyt   difft   Powt   Mult   Addt   symbolst   Tuple(   t   ranget   reduce(   t   Zero(   t	   factorial(   t   Matrix(   t   simplify(   t   solve(   t   ImmutableDenseNDimArrayt   Manifoldc           B  s    e  Z d  Z d „  Z d „  Z RS(   s	  Object representing a mathematical manifold.

    The only role that this object plays is to keep a list of all patches
    defined on the manifold. It does not provide any means to study the
    topological characteristics of the manifold that it represents.

    c         C  sL   t  | ƒ } t  | ƒ } t j |  | | ƒ } | | _ | | _ g  | _ | S(   N(   R	   R   t   __new__t   namet   dimt   patches(   t   clsR   R   t   obj(    (    s6   lib/python2.7/site-packages/sympy/diffgeom/diffgeom.pyR      s    			c         G  s   d |  j  S(   Ns	   \text{%s}(   R   (   t   selft   printert   args(    (    s6   lib/python2.7/site-packages/sympy/diffgeom/diffgeom.pyt   _latex)   s    (   t   __name__t
   __module__t   __doc__R   R"   (    (    (    s6   lib/python2.7/site-packages/sympy/diffgeom/diffgeom.pyR      s   	t   Patchc           B  s/   e  Z d  Z d „  Z e d „  ƒ Z d „  Z RS(   sš  Object representing a patch on a manifold.

    On a manifold one can have many patches that do not always include the
    whole manifold. On these patches coordinate charts can be defined that
    permit the parameterization of any point on the patch in terms of a tuple
    of real numbers (the coordinates).

    This object serves as a container/parent for all coordinate system charts
    that can be defined on the patch it represents.

    Examples
    ========

    Define a Manifold and a Patch on that Manifold:

    >>> from sympy.diffgeom import Manifold, Patch
    >>> m = Manifold('M', 3)
    >>> p = Patch('P', m)
    >>> p in m.patches
    True

    c         C  sS   t  | ƒ } t j |  | | ƒ } | | _ | | _ | j j j | ƒ g  | _ | S(   N(   R	   R   R   R   t   manifoldR   t   appendt   coord_systems(   R   R   R'   R   (    (    s6   lib/python2.7/site-packages/sympy/diffgeom/diffgeom.pyR   F   s    			c         C  s
   |  j  j S(   N(   R'   R   (   R   (    (    s6   lib/python2.7/site-packages/sympy/diffgeom/diffgeom.pyR   Q   s    c         G  s    d |  j  |  j j | | Œ f S(   Ns   \text{%s}_{%s}(   R   R'   R"   (   R   R    R!   (    (    s6   lib/python2.7/site-packages/sympy/diffgeom/diffgeom.pyR"   U   s    (   R#   R$   R%   R   t   propertyR   R"   (    (    (    s6   lib/python2.7/site-packages/sympy/diffgeom/diffgeom.pyR&   -   s   	t   CoordSystemc           B  s¹   e  Z d  Z d d „ Z e d „  ƒ Z e 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 RS(   s_	  Contains all coordinate transformation logic.

    Examples
    ========

    Define a Manifold and a Patch, and then define two coord systems on that
    patch:

    >>> from sympy import symbols, sin, cos, pi
    >>> from sympy.diffgeom import Manifold, Patch, CoordSystem
    >>> from sympy.simplify import simplify
    >>> r, theta = symbols('r, theta')
    >>> m = Manifold('M', 2)
    >>> patch = Patch('P', m)
    >>> rect = CoordSystem('rect', patch)
    >>> polar = CoordSystem('polar', patch)
    >>> rect in patch.coord_systems
    True

    Connect the coordinate systems. An inverse transformation is automatically
    found by ``solve`` when possible:

    >>> polar.connect_to(rect, [r, theta], [r*cos(theta), r*sin(theta)])
    >>> polar.coord_tuple_transform_to(rect, [0, 2])
    Matrix([
    [0],
    [0]])
    >>> polar.coord_tuple_transform_to(rect, [2, pi/2])
    Matrix([
    [0],
    [2]])
    >>> rect.coord_tuple_transform_to(polar, [1, 1]).applyfunc(simplify)
    Matrix([
    [sqrt(2)],
    [   pi/4]])

    Calculate the jacobian of the polar to cartesian transformation:

    >>> polar.jacobian(rect, [r, theta])
    Matrix([
    [cos(theta), -r*sin(theta)],
    [sin(theta),  r*cos(theta)]])

    Define a point using coordinates in one of the coordinate systems:

    >>> p = polar.point([1, 3*pi/4])
    >>> rect.point_to_coords(p)
    Matrix([
    [-sqrt(2)/2],
    [ sqrt(2)/2]])

    Define a basis scalar field (i.e. a coordinate function), that takes a
    point and returns its coordinates. It is an instance of ``BaseScalarField``.

    >>> rect.coord_function(0)(p)
    -sqrt(2)/2
    >>> rect.coord_function(1)(p)
    sqrt(2)/2

    Define a basis vector field (i.e. a unit vector field along the coordinate
    line). Vectors are also differential operators on scalar fields. It is an
    instance of ``BaseVectorField``.

    >>> v_x = rect.base_vector(0)
    >>> x = rect.coord_function(0)
    >>> v_x(x)
    1
    >>> v_x(v_x(x))
    0

    Define a basis oneform field:

    >>> dx = rect.base_oneform(0)
    >>> dx(v_x)
    1

    If you provide a list of names the fields will print nicely:
    - without provided names:

    >>> x, v_x, dx
    (rect_0, e_rect_0, drect_0)

    - with provided names

    >>> rect = CoordSystem('rect', patch, ['x', 'y'])
    >>> rect.coord_function(0), rect.base_vector(0), rect.base_oneform(0)
    (x, e_x, dx)

    c         C  s   t  | ƒ } | sA g  t | j ƒ D] } d | | f ^ q" } n  t | t ƒ rk t j |  | | | ƒ } n* t t | ƒ Œ  } t j |  | | | ƒ } | | _ g  | j	 D] } t
 | ƒ ^ q¨ | _ | | _ | j j j | ƒ i  | _ g  | D] } t t
 | ƒ ƒ ^ qï | _ t ƒ  | _ | S(   Ns   %s_%d(   R	   R   R   t
   isinstanceR   R   R   R   R   R!   t   strt   _namest   patchR)   R(   t
   transformsR   t   _dummiest   _dummy(   R   R   R/   t   namest   iR   t   n(    (    s6   lib/python2.7/site-packages/sympy/diffgeom/diffgeom.pyR   µ   s    /	%		(c         C  s
   |  j  j S(   N(   R/   R   (   R   (    (    s6   lib/python2.7/site-packages/sympy/diffgeom/diffgeom.pyR   Ð   s    c         C  sm   t  | | ƒ \ } } t | ƒ t | ƒ f |  j | <| rV |  j | | ƒ | j |  <n  | ri |  j ƒ  n  d S(   s|  Register the transformation used to switch to another coordinate system.

        Parameters
        ==========

        to_sys
            another instance of ``CoordSystem``
        from_coords
            list of symbols in terms of which ``to_exprs`` is given
        to_exprs
            list of the expressions of the new coordinate tuple
        inverse
            try to deduce and register the inverse transformation
        fill_in_gaps
            try to deduce other transformation that are made
            possible by composing the present transformation with other already
            registered transformation

        N(   t   dummyfyR   R0   t   _inv_transft   _fill_gaps_in_transformations(   R   t   to_syst   from_coordst   to_exprst   inverset   fill_in_gaps(    (    s6   lib/python2.7/site-packages/sympy/diffgeom/diffgeom.pyt
   connect_toØ   s    c         C  s™   g  |  D] } | j  ƒ  ^ q } t g  t | | ƒ D] } | d | d ^ q2 t |  ƒ d t ƒd } g  |  D] } | | ^ qm } t | ƒ t | ƒ f S(   Ni    i   t   dict(   t   as_dummyR   t   zipt   listt   TrueR   (   R:   R;   R4   t   inv_fromt   tt   inv_tot   fc(    (    s6   lib/python2.7/site-packages/sympy/diffgeom/diffgeom.pyR7   õ   s    +c           C  s
   t  ‚ d  S(   N(   t   NotImplementedError(    (    (    s6   lib/python2.7/site-packages/sympy/diffgeom/diffgeom.pyR8   þ   s    c         C  sR   t  | ƒ } |  | k rN |  j | } | d j t t | d | ƒ ƒ ƒ } n  | S(   sl   Transform ``coords`` to coord system ``to_sys``.

        See the docstring of ``CoordSystem`` for examples.i   i    (   R   R0   t   subsRB   RA   (   R   R9   t   coordst   transf(    (    s6   lib/python2.7/site-packages/sympy/diffgeom/diffgeom.pyt   coord_tuple_transform_to  s
    )c         C  s@   |  j  | |  j ƒ j |  j ƒ } | j t t |  j | ƒ ƒ ƒ S(   s/   Return the jacobian matrix of a transformation.(   RL   R1   t   jacobianRI   RB   RA   (   R   R9   RJ   t   with_dummies(    (    s6   lib/python2.7/site-packages/sympy/diffgeom/diffgeom.pyRM     s    c         C  s   t  |  | ƒ S(   s×   Return a ``BaseScalarField`` that takes a point and returns one of the coords.

        Takes a point and returns its coordinate in this coordinate system.

        See the docstring of ``CoordSystem`` for examples.(   t   BaseScalarField(   R   t   coord_index(    (    s6   lib/python2.7/site-packages/sympy/diffgeom/diffgeom.pyt   coord_function  s    c         C  s)   g  t  |  j ƒ D] } |  j | ƒ ^ q S(   sv   Returns a list of all coordinate functions.

        For more details see the ``coord_function`` method of this class.(   R   R   RQ   (   R   R4   (    (    s6   lib/python2.7/site-packages/sympy/diffgeom/diffgeom.pyt   coord_functions  s    c         C  s   t  |  | ƒ S(   sÅ   Return a basis vector field.

        The basis vector field for this coordinate system. It is also an
        operator on scalar fields.

        See the docstring of ``CoordSystem`` for examples.(   t   BaseVectorField(   R   RP   (    (    s6   lib/python2.7/site-packages/sympy/diffgeom/diffgeom.pyt   base_vector%  s    c         C  s)   g  t  |  j ƒ D] } |  j | ƒ ^ q S(   sk   Returns a list of all base vectors.

        For more details see the ``base_vector`` method of this class.(   R   R   RT   (   R   R4   (    (    s6   lib/python2.7/site-packages/sympy/diffgeom/diffgeom.pyt   base_vectors.  s    c         C  s   t  |  j | ƒ ƒ S(   sÇ   Return a basis 1-form field.

        The basis one-form field for this coordinate system. It is also an
        operator on vector fields.

        See the docstring of ``CoordSystem`` for examples.(   t   DifferentialRQ   (   R   RP   (    (    s6   lib/python2.7/site-packages/sympy/diffgeom/diffgeom.pyt   base_oneform4  s    c         C  s)   g  t  |  j ƒ D] } |  j | ƒ ^ q S(   sm   Returns a list of all base oneforms.

        For more details see the ``base_oneform`` method of this class.(   R   R   RW   (   R   R4   (    (    s6   lib/python2.7/site-packages/sympy/diffgeom/diffgeom.pyt   base_oneforms=  s    c         C  s   t  |  | ƒ S(   s{   Create a ``Point`` with coordinates given in this coord system.

        See the docstring of ``CoordSystem`` for examples.(   t   Point(   R   RJ   (    (    s6   lib/python2.7/site-packages/sympy/diffgeom/diffgeom.pyt   pointG  s    c         C  s   | j  |  ƒ S(   sv   Calculate the coordinates of a point in this coord system.

        See the docstring of ``CoordSystem`` for examples.(   RJ   (   R   RZ   (    (    s6   lib/python2.7/site-packages/sympy/diffgeom/diffgeom.pyt   point_to_coordsM  s    c         G  s,   d |  j  |  j j  |  j j j | | Œ f S(   Ns   \text{%s}^{\text{%s}}_{%s}(   R   R/   R'   R"   (   R   R    R!   (    (    s6   lib/python2.7/site-packages/sympy/diffgeom/diffgeom.pyR"   W  s    N(   R#   R$   R%   t   NoneR   R*   R   RC   t   FalseR>   t   staticmethodR7   R8   RL   RM   RQ   RR   RT   RU   RW   RX   RZ   R[   R"   (    (    (    s6   lib/python2.7/site-packages/sympy/diffgeom/diffgeom.pyR+   Y   s"   Y		
	
								
		
RY   c           B  s2   e  Z d  Z d „  Z d d „ Z e d „  ƒ Z RS(   sc  Point in a Manifold object.

    To define a point you must supply coordinates and a coordinate system.

    The usage of this object after its definition is independent of the
    coordinate system that was used in order to define it, however due to
    limitations in the simplification routines you can arrive at complicated
    expressions if you use inappropriate coordinate systems.

    Examples
    ========

    Define the boilerplate Manifold, Patch and coordinate systems:

    >>> from sympy import symbols, sin, cos, pi
    >>> from sympy.diffgeom import (
    ...        Manifold, Patch, CoordSystem, Point)
    >>> r, theta = symbols('r, theta')
    >>> m = Manifold('M', 2)
    >>> p = Patch('P', m)
    >>> rect = CoordSystem('rect', p)
    >>> polar = CoordSystem('polar', p)
    >>> polar.connect_to(rect, [r, theta], [r*cos(theta), r*sin(theta)])

    Define a point using coordinates from one of the coordinate systems:

    >>> p = Point(polar, [r, 3*pi/4])
    >>> p.coords()
    Matrix([
    [     r],
    [3*pi/4]])
    >>> p.coords(rect)
    Matrix([
    [-sqrt(2)*r/2],
    [ sqrt(2)*r/2]])

    c         C  sD   t  t |  ƒ j ƒ  | |  _ t | ƒ |  _ |  j |  j f |  _ d  S(   N(   t   superRY   t   __init__t
   _coord_sysR   t   _coordst   _args(   R   t	   coord_sysRJ   (    (    s6   lib/python2.7/site-packages/sympy/diffgeom/diffgeom.pyR`   ‚  s    	c         C  s'   | r |  j  j | |  j ƒ S|  j Sd S(   sª   Coordinates of the point in a given coordinate system.

        If ``to_sys`` is ``None`` it returns the coordinates in the system in
        which the point was defined.N(   Ra   RL   Rb   (   R   R9   (    (    s6   lib/python2.7/site-packages/sympy/diffgeom/diffgeom.pyRJ   ˆ  s    c         C  s   t  ‚ |  j j S(   N(   RH   Rb   t   free_symbols(   R   (    (    s6   lib/python2.7/site-packages/sympy/diffgeom/diffgeom.pyRe   ’  s    N(   R#   R$   R%   R`   R\   RJ   R*   Re   (    (    (    s6   lib/python2.7/site-packages/sympy/diffgeom/diffgeom.pyRY   \  s   %	
RO   c           B  s8   e  Z d  Z e Z d „  Z d „  Z e ƒ  Z d „  Z	 RS(   sš  Base Scalar Field over a Manifold for a given Coordinate System.

    A scalar field takes a point as an argument and returns a scalar.

    A base scalar field of a coordinate system takes a point and returns one of
    the coordinates of that point in the coordinate system in question.

    To define a scalar field you need to choose the coordinate system and the
    index of the coordinate.

    The use of the scalar field after its definition is independent of the
    coordinate system in which it was defined, however due to limitations in
    the simplification routines you may arrive at more complicated
    expression if you use unappropriate coordinate systems.

    You can build complicated scalar fields by just building up SymPy
    expressions containing ``BaseScalarField`` instances.

    Examples
    ========

    Define boilerplate Manifold, Patch and coordinate systems:

    >>> from sympy import symbols, sin, cos, pi, Function
    >>> from sympy.diffgeom import (
    ...        Manifold, Patch, CoordSystem, Point, BaseScalarField)
    >>> r0, theta0 = symbols('r0, theta0')
    >>> m = Manifold('M', 2)
    >>> p = Patch('P', m)
    >>> rect = CoordSystem('rect', p)
    >>> polar = CoordSystem('polar', p)
    >>> polar.connect_to(rect, [r0, theta0], [r0*cos(theta0), r0*sin(theta0)])

    Point to be used as an argument for the filed:

    >>> point = polar.point([r0, 0])

    Examples of fields:

    >>> fx = BaseScalarField(rect, 0)
    >>> fy = BaseScalarField(rect, 1)
    >>> (fx**2+fy**2).rcall(point)
    r0**2

    >>> g = Function('g')
    >>> ftheta = BaseScalarField(polar, 1)
    >>> fg = g(ftheta-pi)
    >>> fg.rcall(point)
    g(-pi)

    c         C  s1   t  j |  | t | ƒ ƒ } | | _ | | _ | S(   N(   R   R   R	   Ra   t   _index(   R   Rd   t   indexR   (    (    s6   lib/python2.7/site-packages/sympy/diffgeom/diffgeom.pyR   Ï  s    		c         G  sY   | d } t  | ƒ d k s, t | t ƒ r0 |  S| j |  j ƒ } t | |  j ƒ j ƒ  S(   sf  Evaluating the field at a point or doing nothing.

        If the argument is a ``Point`` instance, the field is evaluated at that
        point. The field is returned itself if the argument is any other
        object. It is so in order to have working recursive calling mechanics
        for all fields (check the ``__call__`` method of ``Expr``).
        i    i   (   t   lenR,   RY   RJ   Ra   R   Rf   t   doit(   R   R!   RZ   RJ   (    (    s6   lib/python2.7/site-packages/sympy/diffgeom/diffgeom.pyt   __call__Õ  s
    
"c         C  s   |  S(   N(    (   R   (    (    s6   lib/python2.7/site-packages/sympy/diffgeom/diffgeom.pyRi   è  s    (
   R#   R$   R%   RC   t   is_commutativeR   Rj   t   setRe   Ri   (    (    (    s6   lib/python2.7/site-packages/sympy/diffgeom/diffgeom.pyRO   ˜  s   3			RS   c           B  s&   e  Z d  Z e Z d „  Z d „  Z RS(   s  Vector Field over a Manifold.

    A vector field is an operator taking a scalar field and returning a
    directional derivative (which is also a scalar field).

    A base vector field is the same type of operator, however the derivation is
    specifically done with respect to a chosen coordinate.

    To define a base vector field you need to choose the coordinate system and
    the index of the coordinate.

    The use of the vector field after its definition is independent of the
    coordinate system in which it was defined, however due to limitations in the
    simplification routines you may arrive at more complicated expression if you
    use unappropriate coordinate systems.

    Examples
    ========

    Use the predefined R2 manifold, setup some boilerplate.

    >>> from sympy import symbols, pi, Function
    >>> from sympy.diffgeom.rn import R2, R2_p, R2_r
    >>> from sympy.diffgeom import BaseVectorField
    >>> from sympy import pprint
    >>> x0, y0, r0, theta0 = symbols('x0, y0, r0, theta0')

    Points to be used as arguments for the field:

    >>> point_p = R2_p.point([r0, theta0])
    >>> point_r = R2_r.point([x0, y0])

    Scalar field to operate on:

    >>> g = Function('g')
    >>> s_field = g(R2.x, R2.y)
    >>> s_field.rcall(point_r)
    g(x0, y0)
    >>> s_field.rcall(point_p)
    g(r0*cos(theta0), r0*sin(theta0))

    Vector field:

    >>> v = BaseVectorField(R2_r, 1)
    >>> pprint(v(s_field))
    /  d              \|
    |-----(g(x, xi_2))||
    \dxi_2            /|xi_2=y
    >>> pprint(v(s_field).rcall(point_r).doit())
     d
    ---(g(x0, y0))
    dy0
    >>> pprint(v(s_field).rcall(point_p))
    /  d                           \|
    |-----(g(r0*cos(theta0), xi_2))||
    \dxi_2                         /|xi_2=r0*sin(theta0)

    c         C  s7   t  | ƒ } t j |  | | ƒ } | | _ | | _ | S(   N(   R	   R   R   Ra   Rf   (   R   Rd   Rg   R   (    (    s6   lib/python2.7/site-packages/sympy/diffgeom/diffgeom.pyR   *  s
    		c         C  s¡  t  | ƒ s t | ƒ r' t d ƒ ‚ n  | d k r7 |  St | j t ƒ ƒ } |  j j } g  t	 | ƒ D]" \ } } t
 d | ƒ | ƒ ^ qe } | j t t | | ƒ ƒ ƒ } | j | ƒ } |  j j } g  | D] }	 |	 j | ƒ ^ qÍ }
 g  } xC | D]; } |  j j | j | ƒ } | j | | j |  j f ƒ qõ W| j t t |
 | ƒ ƒ ƒ } | j t t | | ƒ ƒ ƒ } | j t t | |  j j ƒ  ƒ ƒ ƒ } | j ƒ  S(   sÆ   Apply on a scalar field.

        The action of a vector field on a scalar field is a directional
        differentiation.

        If the argument is not a scalar field an error is raised.
        sA   Only scalar fields can be supplied as arguments to vector fields.s   _#_%sN(   t   covariant_ordert   contravariant_ordert
   ValueErrorR\   RB   t   atomsRO   Ra   R2   t	   enumerateR   RI   RA   R
   R1   RM   R(   Rf   RR   Ri   (   R   t   scalar_fieldt   base_scalarst   d_varR4   t   bt   d_funcst   d_resultRJ   t   ft   d_funcs_derivt   d_funcs_deriv_subt   jact   result(    (    s6   lib/python2.7/site-packages/sympy/diffgeom/diffgeom.pyRj   1  s(    2"!'(   R#   R$   R%   R]   Rk   R   Rj   (    (    (    s6   lib/python2.7/site-packages/sympy/diffgeom/diffgeom.pyRS   ì  s   :	t
   Commutatorc           B  s)   e  Z d  Z d „  Z d „  Z d „  Z RS(   s5  Commutator of two vector fields.

    The commutator of two vector fields `v_1` and `v_2` is defined as the
    vector field `[v_1, v_2]` that evaluated on each scalar field `f` is equal
    to `v_1(v_2(f)) - v_2(v_1(f))`.

    Examples
    ========

    Use the predefined R2 manifold, setup some boilerplate.

    >>> from sympy.diffgeom.rn import R2
    >>> from sympy.diffgeom import Commutator
    >>> from sympy import pprint
    >>> from sympy.simplify import simplify

    Vector fields:

    >>> e_x, e_y, e_r = R2.e_x, R2.e_y, R2.e_r
    >>> c_xy = Commutator(e_x, e_y)
    >>> c_xr = Commutator(e_x, e_r)
    >>> c_xy
    0

    Unfortunately, the current code is not able to compute everything:

    >>> c_xr
    Commutator(e_x, e_r)

    >>> simplify(c_xr(R2.y**2))
    -2*y**2*cos(theta)/(x**2 + y**2)

    c         C  sß  t  | ƒ s< t | ƒ d k s< t  | ƒ s< t | ƒ d k rK t d ƒ ‚ n  | | k r^ t ƒ  St ƒ  j g  | | f D] } | j t ƒ ^ qt Œ  } t | ƒ d k r¿t	 d „  | | f Dƒ ƒ rÇ t ƒ  Sg  | | f D] } t
 | j t ƒ ƒ ^ qÔ \ } } g  | D] } | j ƒ  j | ƒ ^ q} g  | D] } | j ƒ  j | ƒ ^ q*}	 d }
 xg t | | ƒ D]V \ } } xG t |	 | ƒ D]6 \ } } |
 | | | ƒ | | | | ƒ | 7}
 q}WqaW|
 St t |  ƒ j |  | | ƒ Sd  S(   Ni   s0   Only commutators of vector fields are supported.c         s  s   |  ] } t  | t ƒ Vq d  S(   N(   R,   RS   (   t   .0t   v(    (    s6   lib/python2.7/site-packages/sympy/diffgeom/diffgeom.pys	   <genexpr>…  s    i    (   Rm   Rn   Ro   R   Rl   t   unionRp   R+   Rh   t   allRB   RS   t   expandt   coeffRA   R_   R}   R   (   R   t   v1t   v2R   Rd   t   bases_1t   bases_2Ru   t   coeffs_1t   coeffs_2t   rest   c1t   b1t   c2t   b2(    (    s6   lib/python2.7/site-packages/sympy/diffgeom/diffgeom.pyR   z  s(    41((2c         C  s8   t  t |  ƒ j ƒ  | | f |  _ | |  _ | |  _ d  S(   N(   R_   R}   R`   Rc   t   _v1t   _v2(   R   R„   R…   (    (    s6   lib/python2.7/site-packages/sympy/diffgeom/diffgeom.pyR`   “  s    	c         C  s,   |  j  |  j | ƒ ƒ |  j |  j  | ƒ ƒ S(   sd   Apply on a scalar field.

        If the argument is not a scalar field an error is raised.
        (   R   R   (   R   Rr   (    (    s6   lib/python2.7/site-packages/sympy/diffgeom/diffgeom.pyRj   ™  s    (   R#   R$   R%   R   R`   Rj   (    (    (    s6   lib/python2.7/site-packages/sympy/diffgeom/diffgeom.pyR}   X  s   !		RV   c           B  s/   e  Z d  Z e Z d „  Z d „  Z d „  Z RS(   s3  Return the differential (exterior derivative) of a form field.

    The differential of a form (i.e. the exterior derivative) has a complicated
    definition in the general case.

    The differential `df` of the 0-form `f` is defined for any vector field `v`
    as `df(v) = v(f)`.

    Examples
    ========

    Use the predefined R2 manifold, setup some boilerplate.

    >>> from sympy import Function
    >>> from sympy.diffgeom.rn import R2
    >>> from sympy.diffgeom import Differential
    >>> from sympy import pprint

    Scalar field (0-forms):

    >>> g = Function('g')
    >>> s_field = g(R2.x, R2.y)

    Vector fields:

    >>> e_x, e_y, = R2.e_x, R2.e_y

    Differentials:

    >>> dg = Differential(s_field)
    >>> dg
    d(g(x, y))
    >>> pprint(dg(e_x))
    /  d              \|
    |-----(g(xi_1, y))||
    \dxi_1            /|xi_1=x
    >>> pprint(dg(e_y))
    /  d              \|
    |-----(g(x, xi_2))||
    \dxi_2            /|xi_2=y

    Applying the exterior derivative operator twice always results in:

    >>> Differential(dg)
    0

    c         C  sN   t  | ƒ r t d ƒ ‚ n  t | t ƒ r1 t ƒ  St t |  ƒ j |  | ƒ Sd  S(   Ns;   A vector field was supplied as an argument to Differential.(   Rn   Ro   R,   RV   R   R_   R   (   R   t
   form_field(    (    s6   lib/python2.7/site-packages/sympy/diffgeom/diffgeom.pyR   Ô  s    c         C  s/   t  t |  ƒ j ƒ  | |  _ |  j f |  _ d  S(   N(   R_   RV   R`   t   _form_fieldRc   (   R   R‘   (    (    s6   lib/python2.7/site-packages/sympy/diffgeom/diffgeom.pyR`   Ý  s    	c   
      G  sZ  t  d „  | Dƒ ƒ r% t d ƒ ‚ n  t | ƒ } | d k r_ | d r[ | d j |  j ƒ S|  S|  j } | } d } xÛ t | ƒ D]Í } | | j | j | |  | | d Œ  ƒ } | d | | 7} x† t | d | ƒ D]q } t | | | | ƒ }	 |	 rÙ | j |	 f | |  | | d | !| | d Œ  } | d | | | 7} qÙ qÙ Wq W| Sd S(   su  Apply on a list of vector_fields.

        If the number of vector fields supplied is not equal to 1 + the order of
        the form field inside the differential the result is undefined.

        For 1-forms (i.e. differentials of scalar fields) the evaluation is
        done as `df(v)=v(f)`. However if `v` is ``None`` instead of a vector
        field, the differential is returned unchanged. This is done in order to
        permit partial contractions for higher forms.

        In the general case the evaluation is done by applying the form field
        inside the differential on a list with one less elements than the number
        of elements in the original list. Lowering the number of vector fields
        is achieved through replacing each pair of fields by their
        commutator.

        If the arguments are not vectors or ``None``s an error is raised.
        c         s  s9   |  ]/ } t  | ƒ d  k s' t | ƒ o0 | d k	 Vq d S(   i   N(   Rn   Rm   R\   (   R~   t   a(    (    s6   lib/python2.7/site-packages/sympy/diffgeom/diffgeom.pys	   <genexpr>õ  s   sH   The arguments supplied to Differential should be vector fields or Nones.i   i    iÿÿÿÿN(   t   anyRo   Rh   t   rcallR’   R   R}   (
   R   t   vector_fieldst   kRx   R   t   retR4   RE   t   jt   c(    (    s6   lib/python2.7/site-packages/sympy/diffgeom/diffgeom.pyRj   â  s(    	
	,5!(   R#   R$   R%   R]   Rk   R   R`   Rj   (    (    (    s6   lib/python2.7/site-packages/sympy/diffgeom/diffgeom.pyRV   ¡  s
   /			t   TensorProductc           B  s)   e  Z d  Z d „  Z d „  Z d „  Z RS(   sÆ  Tensor product of forms.

    The tensor product permits the creation of multilinear functionals (i.e.
    higher order tensors) out of lower order fields (e.g. 1-forms and vector
    fields). However, the higher tensors thus created lack the interesting
    features provided by the other type of product, the wedge product, namely
    they are not antisymmetric and hence are not form fields.

    Examples
    ========

    Use the predefined R2 manifold, setup some boilerplate.

    >>> from sympy.diffgeom.rn import R2
    >>> from sympy.diffgeom import TensorProduct

    >>> TensorProduct(R2.dx, R2.dy)(R2.e_x, R2.e_y)
    1
    >>> TensorProduct(R2.dx, R2.dy)(R2.e_y, R2.e_x)
    0
    >>> TensorProduct(R2.dx, R2.x*R2.dy)(R2.x*R2.e_x, R2.e_y)
    x**2
    >>> TensorProduct(R2.e_x, R2.e_y)(R2.x**2, R2.y**2)
    4*x*y
    >>> TensorProduct(R2.e_y, R2.dx)(R2.y)
    dx


    You can nest tensor products.

    >>> tp1 = TensorProduct(R2.dx, R2.dy)
    >>> TensorProduct(tp1, R2.dx)(R2.e_x, R2.e_y, R2.e_x)
    1

    You can make partial contraction for instance when 'raising an index'.
    Putting ``None`` in the second argument of ``rcall`` means that the
    respective position in the tensor product is left as it is.

    >>> TP = TensorProduct
    >>> metric = TP(R2.dx, R2.dx) + 3*TP(R2.dy, R2.dy)
    >>> metric.rcall(R2.e_y, None)
    3*dy

    Or automatically pad the args with ``None`` without specifying them.

    >>> metric.rcall(R2.e_y)
    3*dy

    c         G  s³   t  g  | D]( } t | ƒ t | ƒ d k r
 | ^ q
 Œ  } g  | D]" } t | ƒ t | ƒ rB | ^ qB } | r« t | ƒ d k rŽ | | d S| t t |  ƒ j |  | Œ S| Sd  S(   Ni    i   (   R   Rm   Rn   Rh   R_   R›   R   (   R   R!   t   mt   scalart   multifields(    (    s6   lib/python2.7/site-packages/sympy/diffgeom/diffgeom.pyR   D  s    ;/c         G  s    t  t |  ƒ j ƒ  | |  _ d  S(   N(   R_   R›   R`   Rc   (   R   R!   (    (    s6   lib/python2.7/site-packages/sympy/diffgeom/diffgeom.pyR`   N  s    c         G  s,  t  |  ƒ t |  ƒ } t | ƒ } | | k rL t | ƒ d g | | } n  g  |  j D] } t  | ƒ t | ƒ ^ qV } g  t t | ƒ d ƒ D] } t | | d  ƒ ^ q } g  t d g | | d g ƒ D] \ } } | | | !^ qÍ } g  t |  j | ƒ D] }	 |	 d j	 |	 d Œ  ^ qÿ }
 t
 |
 Œ  S(   s×  Apply on a list of fields.

        If the number of input fields supplied is not equal to the order of
        the tensor product field, the list of arguments is padded with ``None``'s.

        The list of arguments is divided in sublists depending on the order of
        the forms inside the tensor product. The sublists are provided as
        arguments to these forms and the resulting expressions are given to the
        constructor of ``TensorProduct``.
        i   i    N(   Rm   Rn   Rh   RB   R\   Rc   R   t   sumRA   R•   R›   (   R   t   fieldst	   tot_ordert   tot_argsRx   t   ordersR4   t   indicesR™   RE   t   multipliers(    (    s6   lib/python2.7/site-packages/sympy/diffgeom/diffgeom.pyRj   R  s    ,7=6(   R#   R$   R%   R   R`   Rj   (    (    (    s6   lib/python2.7/site-packages/sympy/diffgeom/diffgeom.pyR›     s   1	
	t   WedgeProductc           B  s   e  Z d  Z d „  Z RS(   sÙ  Wedge product of forms.

    In the context of integration only completely antisymmetric forms make
    sense. The wedge product permits the creation of such forms.

    Examples
    ========

    Use the predefined R2 manifold, setup some boilerplate.

    >>> from sympy.diffgeom.rn import R2
    >>> from sympy.diffgeom import WedgeProduct

    >>> WedgeProduct(R2.dx, R2.dy)(R2.e_x, R2.e_y)
    1
    >>> WedgeProduct(R2.dx, R2.dy)(R2.e_y, R2.e_x)
    -1
    >>> WedgeProduct(R2.dx, R2.x*R2.dy)(R2.x*R2.e_x, R2.e_y)
    x**2
    >>> WedgeProduct(R2.e_x,R2.e_y)(R2.y,None)
    -e_x

    You can nest wedge products.

    >>> wp1 = WedgeProduct(R2.dx, R2.dy)
    >>> WedgeProduct(wp1, R2.dx)(R2.e_x, R2.e_y, R2.e_x)
    0

    c         G  s¬   d „  |  j  Dƒ } d t d „  | Dƒ Œ  } t | ƒ } d „  t t t t | ƒ ƒ ƒ ƒ Dƒ } t |  j  Œ  } | t g  t | | ƒ D] } | | d Œ  | d ^ q† Œ  S(   s|   Apply on a list of vector_fields.

        The expression is rewritten internally in terms of tensor products and evaluated.c         s  s%   |  ] } t  | ƒ t | ƒ Vq d  S(   N(   Rm   Rn   (   R~   t   e(    (    s6   lib/python2.7/site-packages/sympy/diffgeom/diffgeom.pys	   <genexpr>Œ  s    i   c         s  s   |  ] } t  | ƒ Vq d  S(   N(   R   (   R~   t   o(    (    s6   lib/python2.7/site-packages/sympy/diffgeom/diffgeom.pys	   <genexpr>  s    c         s  s!   |  ] } t  | ƒ j ƒ  Vq d  S(   N(   R   t	   signature(   R~   t   p(    (    s6   lib/python2.7/site-packages/sympy/diffgeom/diffgeom.pys	   <genexpr>  s   i    (	   R!   R   R   RB   R   Rh   R›   R   RA   (   R   R    R£   t   mult   permst	   perms_part   tensor_prodRª   (    (    s6   lib/python2.7/site-packages/sympy/diffgeom/diffgeom.pyRj   ˆ  s    "(   R#   R$   R%   Rj   (    (    (    s6   lib/python2.7/site-packages/sympy/diffgeom/diffgeom.pyR¦   h  s   t   LieDerivativec           B  s)   e  Z d  Z d „  Z d „  Z d „  Z RS(   s•  Lie derivative with respect to a vector field.

    The transport operator that defines the Lie derivative is the pushforward of
    the field to be derived along the integral curve of the field with respect
    to which one derives.

    Examples
    ========

    >>> from sympy.diffgeom import (LieDerivative, TensorProduct)
    >>> from sympy.diffgeom.rn import R2
    >>> LieDerivative(R2.e_x, R2.y)
    0
    >>> LieDerivative(R2.e_x, R2.x)
    1
    >>> LieDerivative(R2.e_x, R2.e_x)
    0

    The Lie derivative of a tensor field by another tensor field is equal to
    their commutator:

    >>> LieDerivative(R2.e_x, R2.e_r)
    Commutator(e_x, e_r)
    >>> LieDerivative(R2.e_x + R2.e_y, R2.x)
    1
    >>> tp = TensorProduct(R2.dx, R2.dy)
    >>> LieDerivative(R2.e_x, tp)
    LieDerivative(e_x, TensorProduct(dx, dy))
    >>> LieDerivative(R2.e_x, tp)
    LieDerivative(e_x, TensorProduct(dx, dy))
    c         C  sŽ   t  | ƒ } t | ƒ d k s* t  | ƒ r9 t d ƒ ‚ n  | d k ra t t |  ƒ j |  | | ƒ S| j t ƒ r} t | | ƒ S| j	 | ƒ Sd  S(   Ni   sm   Lie derivatives are defined only with respect to vector fields. The supplied argument was not a vector field.i    (
   Rm   Rn   Ro   R_   R¯   R   Rp   RS   R}   R•   (   R   t   v_fieldt   exprt   expr_form_ord(    (    s6   lib/python2.7/site-packages/sympy/diffgeom/diffgeom.pyR   µ  s    c         C  s>   t  t |  ƒ j ƒ  | |  _ | |  _ |  j |  j f |  _ d  S(   N(   R_   R¯   R`   t   _v_fieldt   _exprRc   (   R   R°   R±   (    (    s6   lib/python2.7/site-packages/sympy/diffgeom/diffgeom.pyR`   Â  s    		c      	   G  s   |  j  } |  j } | | | Œ  ƒ } t g  t t | ƒ ƒ D]6 } t | |  t | | | ƒ f | | d Œ  ^ q: Œ  } | | S(   Ni   (   R³   R´   R   R   Rh   R   R}   (   R   R!   R   R±   t	   lead_termR4   t   rest(    (    s6   lib/python2.7/site-packages/sympy/diffgeom/diffgeom.pyRj   È  s    		O(   R#   R$   R%   R   R`   Rj   (    (    (    s6   lib/python2.7/site-packages/sympy/diffgeom/diffgeom.pyR¯   •  s   		t   BaseCovarDerivativeOpc           B  s    e  Z d  Z d „  Z d „  Z RS(   s  Covariant derivative operator with respect to a base vector.

    Examples
    ========

    >>> from sympy.diffgeom.rn import R2, R2_r
    >>> from sympy.diffgeom import BaseCovarDerivativeOp
    >>> from sympy.diffgeom import metric_to_Christoffel_2nd, TensorProduct
    >>> TP = TensorProduct
    >>> ch = metric_to_Christoffel_2nd(TP(R2.dx, R2.dx) + TP(R2.dy, R2.dy))
    >>> ch
    [[[0, 0], [0, 0]], [[0, 0], [0, 0]]]
    >>> cvd = BaseCovarDerivativeOp(R2_r, 0, ch)
    >>> cvd(R2.x)
    1
    >>> cvd(R2.x*R2.e_x)
    e_x
    c         C  sM   t  t |  ƒ j ƒ  | |  _ | |  _ | |  _ |  j |  j |  j f |  _ d  S(   N(   R_   R·   R`   Ra   Rf   t   _christoffelRc   (   R   Rd   Rg   t   christoffel(    (    s6   lib/python2.7/site-packages/sympy/diffgeom/diffgeom.pyR`   ä  s
    			c         C  sÆ  t  | ƒ d k r t ƒ  ‚ n  t | |  j ƒ } |  j j |  j ƒ } |  j j |  j ƒ } t | j t	 ƒ ƒ } g  t
 | ƒ D]" \ } } t d | ƒ | ƒ ^ q| } | j t t | | ƒ ƒ ƒ } | | ƒ } | j t t | | ƒ ƒ ƒ } g  }	 xl | D]d }
 t g  t |
 j j ƒ D]2 } |  j | | j |
 j f |
 j j | ƒ ^ qŒ  } |	 j | ƒ qù Wg  | D] } | | ƒ ^ qh} | j t t | |	 ƒ ƒ ƒ } | j t t | | ƒ ƒ ƒ } | j ƒ  S(   sÎ   Apply on a scalar field.

        The action of a vector field on a scalar field is a directional
        differentiation.

        If the argument is not a scalar field the behaviour is undefined.
        i    s   _#_%s(   Rm   RH   t   vectors_in_basisRa   RT   Rf   RQ   RB   Rp   RS   Rq   R   RI   RA   R   R   R   R¸   R(   Ri   (   R   t   fieldt
   wrt_vectort
   wrt_scalart   vectorsR4   Ru   Rv   Rw   t   derivsR   R—   t   dt   to_subsR|   (    (    s6   lib/python2.7/site-packages/sympy/diffgeom/diffgeom.pyRj   ë  s(    2K(   R#   R$   R%   R`   Rj   (    (    (    s6   lib/python2.7/site-packages/sympy/diffgeom/diffgeom.pyR·   Ñ  s   	t   CovarDerivativeOpc           B  s)   e  Z d  Z d „  Z d „  Z d „  Z RS(   sñ  Covariant derivative operator.

    Examples
    ========

    >>> from sympy.diffgeom.rn import R2
    >>> from sympy.diffgeom import CovarDerivativeOp
    >>> from sympy.diffgeom import metric_to_Christoffel_2nd, TensorProduct
    >>> TP = TensorProduct
    >>> ch = metric_to_Christoffel_2nd(TP(R2.dx, R2.dx) + TP(R2.dy, R2.dy))
    >>> ch
    [[[0, 0], [0, 0]], [[0, 0], [0, 0]]]
    >>> cvd = CovarDerivativeOp(R2.x*R2.e_x, ch)
    >>> cvd(R2.x)
    x
    >>> cvd(R2.x*R2.e_x)
    x*e_x

    c         C  s¢   t  t |  ƒ j ƒ  t t d „  | j t ƒ Dƒ ƒ ƒ d k rJ t ƒ  ‚ n  t | ƒ d k sh t	 | ƒ rw t
 d ƒ ‚ n  | |  _ | |  _ |  j |  j f |  _ d  S(   Nc         s  s   |  ] } | j  Vq d  S(   N(   Ra   (   R~   R   (    (    s6   lib/python2.7/site-packages/sympy/diffgeom/diffgeom.pys	   <genexpr>,  s    i   ss   Covariant derivatives are defined only with respect to vector fields. The supplied argument was not a vector field.(   R_   RÂ   R`   Rh   Rl   Rp   RS   RH   Rn   Rm   Ro   t   _wrtR¸   Rc   (   R   t   wrtR¹   (    (    s6   lib/python2.7/site-packages/sympy/diffgeom/diffgeom.pyR`   *  s    +		c         C  sn   t  |  j j t ƒ ƒ } g  | D]! } t | j | j |  j ƒ ^ q } |  j j t  t	 | | ƒ ƒ ƒ j
 | ƒ S(   N(   RB   RÃ   Rp   RS   R·   Ra   Rf   R¸   RI   RA   R•   (   R   R»   R¾   R   t   base_ops(    (    s6   lib/python2.7/site-packages/sympy/diffgeom/diffgeom.pyRj   6  s    +c         G  s   d | j  |  j ƒ S(   Ns   \mathbb{\nabla}_{%s}(   t   _printRÃ   (   R   R    R!   (    (    s6   lib/python2.7/site-packages/sympy/diffgeom/diffgeom.pyR"   <  s    (   R#   R$   R%   R`   Rj   R"   (    (    (    s6   lib/python2.7/site-packages/sympy/diffgeom/diffgeom.pyRÂ     s   		i   c           sä   t  ˆ ƒ d k s t ˆ ƒ r- t d ƒ ‚ n  ‡ f d †  ‰  ‡  ‡ ‡ ‡ f d †  } | r` | n ˆ j } | j ƒ  } g  | D] } | | ƒ ^ q| }	 | r½ g  t |	 Œ  D] }
 t |
 ƒ ^ q§ St g  |	 D] } t | ƒ ^ qÇ ƒ Sd S(   sm
  Return the series expansion for an integral curve of the field.

    Integral curve is a function `\gamma` taking a parameter in `R` to a point
    in the manifold. It verifies the equation:

    `V(f)\big(\gamma(t)\big) = \frac{d}{dt}f\big(\gamma(t)\big)`

    where the given ``vector_field`` is denoted as `V`. This holds for any
    value `t` for the parameter and any scalar field `f`.

    This equation can also be decomposed of a basis of coordinate functions

    `V(f_i)\big(\gamma(t)\big) = \frac{d}{dt}f_i\big(\gamma(t)\big) \quad \forall i`

    This function returns a series expansion of `\gamma(t)` in terms of the
    coordinate system ``coord_sys``. The equations and expansions are necessarily
    done in coordinate-system-dependent way as there is no other way to
    represent movement between points on the manifold (i.e. there is no such
    thing as a difference of points for a general manifold).

    See Also
    ========

    intcurve_diffequ

    Parameters
    ==========

    vector_field
        the vector field for which an integral curve will be given
    param
        the argument of the function `\gamma` from R to the curve
    start_point
        the point which corresponds to `\gamma(0)`
    n
        the order to which to expand
    coord_sys
        the coordinate system in which to expand
        coeffs (default False) - if True return a list of elements of the expansion

    Examples
    ========

    Use the predefined R2 manifold:

    >>> from sympy.abc import t, x, y
    >>> from sympy.diffgeom.rn import R2, R2_p, R2_r
    >>> from sympy.diffgeom import intcurve_series

    Specify a starting point and a vector field:

    >>> start_point = R2_r.point([x, y])
    >>> vector_field = R2_r.e_x

    Calculate the series:

    >>> intcurve_series(vector_field, t, start_point, n=3)
    Matrix([
    [t + x],
    [    y]])

    Or get the elements of the expansion in a list:

    >>> series = intcurve_series(vector_field, t, start_point, n=3, coeffs=True)
    >>> series[0]
    Matrix([
    [x],
    [y]])
    >>> series[1]
    Matrix([
    [t],
    [0]])
    >>> series[2]
    Matrix([
    [0],
    [0]])

    The series in the polar coordinate system:

    >>> series = intcurve_series(vector_field, t, start_point,
    ...             n=3, coord_sys=R2_p, coeffs=True)
    >>> series[0]
    Matrix([
    [sqrt(x**2 + y**2)],
    [      atan2(y, x)]])
    >>> series[1]
    Matrix([
    [t*x/sqrt(x**2 + y**2)],
    [   -t*y/(x**2 + y**2)]])
    >>> series[2]
    Matrix([
    [t**2*(-x**2/(x**2 + y**2)**(3/2) + 1/sqrt(x**2 + y**2))/2],
    [                                t**2*x*y/(x**2 + y**2)**2]])

    i   s*   The supplied field was not a vector field.c           s   t  d „  ˆ  g | |  ƒ S(   s=   Return ``vector_field`` called `i` times on ``scalar_field``.c         S  s   | j  |  ƒ S(   N(   R•   (   t   sR   (    (    s6   lib/python2.7/site-packages/sympy/diffgeom/diffgeom.pyt   <lambda>¨  t    (   R   (   Rr   R4   (   t   vector_field(    s6   lib/python2.7/site-packages/sympy/diffgeom/diffgeom.pyt   iter_vfield¦  s    c           sA   g  t  ˆ ƒ D]0 } ˆ | ˆ  |  | ƒ j ˆ ƒ t | ƒ ^ q S(   s-   Return the series for one of the coordinates.(   R   R•   R   (   RQ   R4   (   RË   R5   t   paramt   start_point(    s6   lib/python2.7/site-packages/sympy/diffgeom/diffgeom.pyt   taylor_terms_per_coordª  s    N(   Rn   Rm   Ro   Ra   RR   RA   R   RŸ   (   RÊ   RÌ   RÍ   R5   Rd   t   coeffsRÎ   RR   Rx   t   taylor_termsRE   Rš   (    (   RË   R5   RÌ   RÍ   RÊ   s6   lib/python2.7/site-packages/sympy/diffgeom/diffgeom.pyt   intcurve_seriesC  s    `#c         C  s$  t  |  ƒ d k s t |  ƒ r- t d ƒ ‚ n  | r9 | n | j } g  t | j j ƒ D] } t d | ƒ | ƒ ^ qU } t | | ƒ } | j ƒ  } g  | D]: } t	 t
 | j | ƒ | ƒ |  j | ƒ j | ƒ ƒ ^ q™ }	 g  | D]4 } t	 | j | ƒ j | d ƒ | j | ƒ ƒ ^ qà }
 |	 |
 f S(   s  Return the differential equation for an integral curve of the field.

    Integral curve is a function `\gamma` taking a parameter in `R` to a point
    in the manifold. It verifies the equation:

    `V(f)\big(\gamma(t)\big) = \frac{d}{dt}f\big(\gamma(t)\big)`

    where the given ``vector_field`` is denoted as `V`. This holds for any
    value `t` for the parameter and any scalar field `f`.

    This function returns the differential equation of `\gamma(t)` in terms of the
    coordinate system ``coord_sys``. The equations and expansions are necessarily
    done in coordinate-system-dependent way as there is no other way to
    represent movement between points on the manifold (i.e. there is no such
    thing as a difference of points for a general manifold).

    See Also
    ========

    intcurve_series

    Parameters
    ==========

    vector_field
        the vector field for which an integral curve will be given
    param
        the argument of the function `\gamma` from R to the curve
    start_point
        the point which corresponds to `\gamma(0)`
    coord_sys
        the coordinate system in which to give the equations

    Returns
    =======
    a tuple of (equations, initial conditions)

    Examples
    ========

    Use the predefined R2 manifold:

    >>> from sympy.abc import t
    >>> from sympy.diffgeom.rn import R2, R2_p, R2_r
    >>> from sympy.diffgeom import intcurve_diffequ

    Specify a starting point and a vector field:

    >>> start_point = R2_r.point([0, 1])
    >>> vector_field = -R2.y*R2.e_x + R2.x*R2.e_y

    Get the equation:

    >>> equations, init_cond = intcurve_diffequ(vector_field, t, start_point)
    >>> equations
    [f_1(t) + Derivative(f_0(t), t), -f_0(t) + Derivative(f_1(t), t)]
    >>> init_cond
    [f_0(0), f_1(0) - 1]

    The series in the polar coordinate system:

    >>> equations, init_cond = intcurve_diffequ(vector_field, t, start_point, R2_p)
    >>> equations
    [Derivative(f_0(t), t), Derivative(f_1(t), t) - 1]
    >>> init_cond
    [f_0(0) - 1, f_1(0) - pi/2]

    i   s*   The supplied field was not a vector field.s   f_%di    (   Rn   Rm   Ro   Ra   R   R   R   RY   RR   R   R
   R•   RI   (   RÊ   RÌ   RÍ   Rd   R4   t   gammast   arbitrary_pRR   t   cft	   equationst	   init_cond(    (    s6   lib/python2.7/site-packages/sympy/diffgeom/diffgeom.pyt   intcurve_diffequ·  s    E/D>c         C  sr   t  g  |  D] } | j ƒ  ^ q
 ƒ } t t |  | ƒ ƒ } t  g  | D] } t | ƒ j | ƒ ^ qD ƒ } | | f S(   N(   R   R@   R?   RA   R	   RI   (   R!   t   exprsRÇ   t   d_argst   repsR±   t   d_exprs(    (    s6   lib/python2.7/site-packages/sympy/diffgeom/diffgeom.pyR6     s    %.c         C  s„  t  |  t ƒ r` g  |  j D] } t | ƒ ^ q } t t | ƒ ƒ d k rX t d ƒ ‚ n  | d St  |  t ƒ ré g  |  j D] } t | ƒ ^ qy } g  | D] } | d k r˜ | ^ q˜ } t | ƒ d k r× t d ƒ ‚ n  | sá d S| d St  |  t ƒ r)t	 |  j
 ƒ st	 |  j ƒ r%t d ƒ ‚ n  d St  |  t ƒ r<d St  |  t ƒ rbt d „  |  j Dƒ ƒ S| sx|  j t ƒ r|d Sd Sd S(	   s_  Return the contravariant order of an expression.

    Examples
    ========

    >>> from sympy.diffgeom import contravariant_order
    >>> from sympy.diffgeom.rn import R2
    >>> from sympy.abc import a
    >>> contravariant_order(a)
    0
    >>> contravariant_order(a*R2.x + 2)
    0
    >>> contravariant_order(a*R2.x*R2.e_y + R2.e_x)
    1

    i   sF   Misformed expression containing contravariant fields of varying order.i    s?   Misformed expression containing multiplication between vectors.s4   Misformed expression containing a power of a vector.c         s  s   |  ] } t  | ƒ Vq d  S(   N(   Rn   (   R~   R“   (    (    s6   lib/python2.7/site-packages/sympy/diffgeom/diffgeom.pys	   <genexpr>>  s    iÿÿÿÿN(   R,   R   R!   Rn   Rh   Rl   Ro   R   R   Rm   t   baset   expRS   R›   RŸ   Rp   RO   (   R±   t   _strictR§   R£   R¨   t   not_zero(    (    s6   lib/python2.7/site-packages/sympy/diffgeom/diffgeom.pyRn     s.    ""%c         C  s‘  t  |  t ƒ r` g  |  j D] } t | ƒ ^ q } t t | ƒ ƒ d k rX t d ƒ ‚ n  | d St  |  t ƒ ré g  |  j D] } t | ƒ ^ qy } g  | D] } | d k r˜ | ^ q˜ } t | ƒ d k r× t d ƒ ‚ n  | sá d S| d St  |  t ƒ r)t |  j	 ƒ st |  j
 ƒ r%t d ƒ ‚ n  d St  |  t ƒ rIt |  j Œ  d St  |  t ƒ rot d „  |  j Dƒ ƒ S| s…|  j t ƒ r‰d Sd Sd S(	   sI  Return the covariant order of an expression.

    Examples
    ========

    >>> from sympy.diffgeom import covariant_order
    >>> from sympy.diffgeom.rn import R2
    >>> from sympy.abc import a
    >>> covariant_order(a)
    0
    >>> covariant_order(a*R2.x + 2)
    0
    >>> covariant_order(a*R2.x*R2.dy + R2.dx)
    1

    i   s=   Misformed expression containing form fields of varying order.i    s=   Misformed expression containing multiplication between forms.s2   Misformed expression containing a power of a form.c         s  s   |  ] } t  | ƒ Vq d  S(   N(   Rm   (   R~   R“   (    (    s6   lib/python2.7/site-packages/sympy/diffgeom/diffgeom.pys	   <genexpr>k  s    iÿÿÿÿN(   R,   R   R!   Rm   Rh   Rl   Ro   R   R   RÜ   RÝ   RV   R›   RŸ   Rp   RO   (   R±   RÞ   R§   R£   R¨   Rß   (    (    s6   lib/python2.7/site-packages/sympy/diffgeom/diffgeom.pyRm   E  s.    ""%c         C  s–   t  |  j t ƒ ƒ } g  } x\ | D]T } | j } | j | | j ƒ  ƒ } | j t | j ƒ  ƒ | j	 } | j
 | ƒ q" W|  j t  t | | ƒ ƒ ƒ S(   sñ  Transform all base vectors in base vectors of a specified coord basis.

    While the new base vectors are in the new coordinate system basis, any
    coefficients are kept in the old system.

    Examples
    ========

    >>> from sympy.diffgeom import vectors_in_basis
    >>> from sympy.diffgeom.rn import R2_r, R2_p
    >>> vectors_in_basis(R2_r.e_x, R2_p)
    x*e_r/sqrt(x**2 + y**2) - y*e_theta/(x**2 + y**2)
    >>> vectors_in_basis(R2_p.e_r, R2_r)
    sin(theta)*e_y + cos(theta)*e_x
    (   RB   Rp   RS   Ra   RM   RR   t   TR   RU   Rf   R(   RI   RA   (   R±   R9   R¾   t   new_vectorsR   t   csR{   t   new(    (    s6   lib/python2.7/site-packages/sympy/diffgeom/diffgeom.pyRº   u  s    	 c         C  sÃ   t  |  ƒ d k s t |  ƒ r- t d ƒ ‚ n  |  j t ƒ } t | ƒ d k r] t d ƒ ‚ n  | j ƒ  } | j ƒ  } |  j ƒ  }  g  | D]+ } g  | D] } |  j	 | | ƒ ^ q• ^ qˆ } t
 | ƒ S(   sè  Return the matrix representing the twoform.

    For the twoform `w` return the matrix `M` such that `M[i,j]=w(e_i, e_j)`,
    where `e_i` is the i-th base vector field for the coordinate system in
    which the expression of `w` is given.

    Examples
    ========

    >>> from sympy.diffgeom.rn import R2
    >>> from sympy.diffgeom import twoform_to_matrix, TensorProduct
    >>> TP = TensorProduct
    >>> twoform_to_matrix(TP(R2.dx, R2.dx) + TP(R2.dy, R2.dy))
    Matrix([
    [1, 0],
    [0, 1]])
    >>> twoform_to_matrix(R2.x*TP(R2.dx, R2.dx) + TP(R2.dy, R2.dy))
    Matrix([
    [x, 0],
    [0, 1]])
    >>> twoform_to_matrix(TP(R2.dx, R2.dx) + TP(R2.dy, R2.dy) - TP(R2.dx, R2.dy)/2)
    Matrix([
    [   1, 0],
    [-1/2, 1]])

    i   s'   The input expression is not a two-form.i   s   The input expression concerns more than one coordinate systems, hence there is no unambiguous way to choose a coordinate system for the matrix.(   Rm   Rn   Ro   Rp   R+   Rh   t   popRU   R‚   R•   R   (   R±   Rd   R¾   R…   R„   t   matrix_content(    (    s6   lib/python2.7/site-packages/sympy/diffgeom/diffgeom.pyt   twoform_to_matrix’  s    5c   	   
     s  t  |  ƒ } | j ƒ  s' t d ƒ ‚ n  |  j t ƒ j ƒ  } g  | j ƒ  D] ‰  | j ‡  f d †  ƒ ^ qI } t t	 | j
 ƒ ƒ } g  | D]h } g  | D]U } g  | D]B } | | | | f | | | | f | | | | f d ^ q£ ^ q– ^ q‰ } t | ƒ S(   sX  Return the nested list of Christoffel symbols for the given metric.

    This returns the Christoffel symbol of first kind that represents the
    Levi-Civita connection for the given metric.

    Examples
    ========

    >>> from sympy.diffgeom.rn import R2
    >>> from sympy.diffgeom import metric_to_Christoffel_1st, TensorProduct
    >>> TP = TensorProduct
    >>> metric_to_Christoffel_1st(TP(R2.dx, R2.dx) + TP(R2.dy, R2.dy))
    [[[0, 0], [0, 0]], [[0, 0], [0, 0]]]
    >>> metric_to_Christoffel_1st(R2.x*TP(R2.dx, R2.dx) + TP(R2.dy, R2.dy))
    [[[1/2, 0], [0, 0]], [[0, 0], [0, 0]]]

    s6   The two-form representing the metric is not symmetric.c           s
   ˆ  |  ƒ S(   N(    (   R“   (   RÀ   (    s6   lib/python2.7/site-packages/sympy/diffgeom/diffgeom.pyRÈ   Ó  RÉ   i   (   Ræ   t   is_symmetricRo   Rp   R+   Rä   RU   t	   applyfuncRB   R   R   R   (	   R±   t   matrixRd   t   deriv_matricesR¤   R4   R™   R—   R¹   (    (   RÀ   s6   lib/python2.7/site-packages/sympy/diffgeom/diffgeom.pyt   metric_to_Christoffel_1st¼  s    .rc         C  s@  t  |  ƒ } |  j t ƒ j ƒ  } t t | j ƒ ƒ } t |  ƒ } t ƒ  } x$ | D] } | j	 | j t
 ƒ ƒ qR Wt | ƒ } | j } | j t t | | ƒ ƒ ƒ j ƒ  j t t | | ƒ ƒ ƒ } g  | D]f } g  | D]S }	 g  | D]@ }
 t g  | D]' } | | | f | | |	 |
 f ^ qô Œ  ^ qä ^ q× ^ qÊ } t | ƒ S(   s]  Return the nested list of Christoffel symbols for the given metric.

    This returns the Christoffel symbol of second kind that represents the
    Levi-Civita connection for the given metric.

    Examples
    ========

    >>> from sympy.diffgeom.rn import R2
    >>> from sympy.diffgeom import metric_to_Christoffel_2nd, TensorProduct
    >>> TP = TensorProduct
    >>> metric_to_Christoffel_2nd(TP(R2.dx, R2.dx) + TP(R2.dy, R2.dy))
    [[[0, 0], [0, 0]], [[0, 0], [0, 0]]]
    >>> metric_to_Christoffel_2nd(R2.x*TP(R2.dx, R2.dx) + TP(R2.dy, R2.dy))
    [[[1/(2*x), 0], [0, 0]], [[0, 0], [0, 0]]]

    (   Rë   Rp   R+   Rä   RB   R   R   Ræ   Rl   t   updateRO   R1   RI   RA   t   invR   R   (   R±   t   ch_1stRd   R¤   Ré   t   s_fieldsR§   t   dumsR4   R™   R—   t   lR¹   (    (    s6   lib/python2.7/site-packages/sympy/diffgeom/diffgeom.pyt   metric_to_Christoffel_2ndÝ  s    		<pc         C  sB  t  |  ƒ } |  j t ƒ j ƒ  } t t | j ƒ ƒ } g  | D]^ } g  | D]K } g  | D]8 } g  | j ƒ  D] } | | | | | f ƒ ^ qj ^ qW ^ qJ ^ q= } g  | D]i }	 g  | D]V }
 g  | D]C } g  | D]0 } | |	 |
 | | | |	 |
 | | ^ qÏ ^ qÂ ^ qµ ^ q¨ } g  | D]ž }	 g  | D]‹ }
 g  | D]x } g  | D]e } t g  | D]L } | |	 | | f | | |
 | f | |	 | | f | | |
 | f ^ qUŒ  ^ qE^ q8^ q+^ q} g  | D]i }	 g  | D]V }
 g  | D]C } g  | D]0 } | |	 |
 | | | |	 |
 | | ^ qð^ qã^ qÖ^ qÉ} t	 | ƒ S(   s  Return the components of the Riemann tensor expressed in a given basis.

    Given a metric it calculates the components of the Riemann tensor in the
    canonical basis of the coordinate system in which the metric expression is
    given.

    Examples
    ========

    >>> from sympy import exp
    >>> from sympy.diffgeom.rn import R2
    >>> from sympy.diffgeom import metric_to_Riemann_components, TensorProduct
    >>> TP = TensorProduct
    >>> metric_to_Riemann_components(TP(R2.dx, R2.dx) + TP(R2.dy, R2.dy))
    [[[[0, 0], [0, 0]], [[0, 0], [0, 0]]], [[[0, 0], [0, 0]], [[0, 0], [0, 0]]]]

    >>> non_trivial_metric = exp(2*R2.r)*TP(R2.dr, R2.dr) +         R2.r**2*TP(R2.dtheta, R2.dtheta)
    >>> non_trivial_metric
    r**2*TensorProduct(dtheta, dtheta) + exp(2*r)*TensorProduct(dr, dr)
    >>> riemann = metric_to_Riemann_components(non_trivial_metric)
    >>> riemann[0, :, :, :]
    [[[0, 0], [0, 0]], [[0, r*exp(-2*r)], [-r*exp(-2*r), 0]]]
    >>> riemann[1, :, :, :]
    [[[0, -1/r], [1/r, 0]], [[0, 0], [0, 0]]]

    (
   Rò   Rp   R+   Rä   RB   R   R   RU   R   R   (   R±   t   ch_2ndRd   R¤   R4   R™   R—   RÀ   t   deriv_cht   rhot   sigt   mut   nut	   riemann_aRñ   t	   riemann_bt   riemann(    (    s6   lib/python2.7/site-packages/sympy/diffgeom/diffgeom.pyt   metric_to_Riemann_components  s    hs¨sc         C  s•   t  |  ƒ } |  j t ƒ j ƒ  } t t | j ƒ ƒ } g  | D]H } g  | D]5 } t g  | D] } | | | | | f ^ qZ Œ  ^ qJ ^ q= } t | ƒ S(   sO  Return the components of the Ricci tensor expressed in a given basis.

    Given a metric it calculates the components of the Ricci tensor in the
    canonical basis of the coordinate system in which the metric expression is
    given.

    Examples
    ========

    >>> from sympy import exp
    >>> from sympy.diffgeom.rn import R2
    >>> from sympy.diffgeom import metric_to_Ricci_components, TensorProduct
    >>> TP = TensorProduct
    >>> metric_to_Ricci_components(TP(R2.dx, R2.dx) + TP(R2.dy, R2.dy))
    [[0, 0], [0, 0]]

    >>> non_trivial_metric = exp(2*R2.r)*TP(R2.dr, R2.dr) +                              R2.r**2*TP(R2.dtheta, R2.dtheta)
    >>> non_trivial_metric
    r**2*TensorProduct(dtheta, dtheta) + exp(2*r)*TensorProduct(dr, dr)
    >>> metric_to_Ricci_components(non_trivial_metric)
    [[1/r, 0], [0, r*exp(-2*r)]]

    (	   Rü   Rp   R+   Rä   RB   R   R   R   R   (   R±   Rû   Rd   R¤   R4   R™   R—   t   ricci(    (    s6   lib/python2.7/site-packages/sympy/diffgeom/diffgeom.pyt   metric_to_Ricci_components:  s    RN(=   t
   __future__R    R   t	   itertoolsR   t   sympy.combinatoricsR   t
   sympy.coreR   R   R   R   R   R	   R
   R   R   R   R   R   t   sympy.core.compatibilityR   R   t   sympy.core.numbersR   t   sympy.functionsR   t   sympy.matricesR   t   sympy.simplifyR   t   sympy.solversR   t   sympy.tensor.arrayR   R   R&   R+   RY   RO   RS   R}   RV   R›   R¦   R¯   R·   RÂ   R\   R]   RÑ   R×   R6   Rn   Rm   Rº   Ræ   Rë   Rò   Rü   Rþ   (    (    (    s6   lib/python2.7/site-packages/sympy/diffgeom/diffgeom.pyt   <module>   sF   R,ÿ <TlIqV-<E-tV	-0		*	!	'	6