ó
¡¼™\c           @   sÉ  d  d l  m Z d  d l m Z m Z m Z d  d l m Z m Z d  d l	 m
 Z
 m Z d  d l m Z m Z m Z d  d l m Z d  d l m Z m Z m Z m Z d  d l m Z m Z m Z d	 e f d
 „  ƒ  YZ d e e f d „  ƒ  YZ d e e f d „  ƒ  YZ d e e f d „  ƒ  YZ d e e f d „  ƒ  YZ  d e f d „  ƒ  YZ! d e f d „  ƒ  YZ" d „  Z# d „  Z$ d „  Z% e e _& e e _' e e _( e  e _) e e _* e% e _+ e  ƒ  e _, d S(   iÿÿÿÿ(   t	   StdFactKB(   t   St   Powt   sympify(   t
   AtomicExprt   Expr(   t   ranget   default_sort_key(   t   sqrtt   ImmutableMatrixt   Add(   t
   CoordSys3D(   t   BasisDependentt   BasisDependentAddt   BasisDependentMult   BasisDependentZero(   t
   BaseDyadict   Dyadict	   DyadicAddt   Vectorc           B   sÂ   e  Z d  Z e Z d Z e d „  ƒ Z d „  Z d „  Z	 d „  Z
 d „  Z e
 j e _ d „  Z d „  Z e j e _ d	 „  Z e d
 „ Z e d „  ƒ Z d „  Z e j e _ d „  Z d „  Z RS(   s   
    Super class for all Vector classes.
    Ideally, neither this class nor any of its subclasses should be
    instantiated by the user.
    g      (@c         C   s   |  j  S(   s‚  
        Returns the components of this vector in the form of a
        Python dictionary mapping BaseVector instances to the
        corresponding measure numbers.

        Examples
        ========

        >>> from sympy.vector import CoordSys3D
        >>> C = CoordSys3D('C')
        >>> v = 3*C.i + 4*C.j + 5*C.k
        >>> v.components
        {C.i: 3, C.j: 4, C.k: 5}

        (   t   _components(   t   self(    (    s2   lib/python2.7/site-packages/sympy/vector/vector.pyt
   components   s    c         C   s   t  |  |  @ƒ S(   s7   
        Returns the magnitude of this vector.
        (   R   (   R   (    (    s2   lib/python2.7/site-packages/sympy/vector/vector.pyt	   magnitude+   s    c         C   s   |  |  j  ƒ  S(   s@   
        Returns the normalized version of this vector.
        (   R   (   R   (    (    s2   lib/python2.7/site-packages/sympy/vector/vector.pyt	   normalize1   s    c            sý   t  | t ƒ r t  ˆ  t ƒ r% t j St j } xL | j j ƒ  D]; \ } } | j d j ˆ  ƒ } | | | | j d 7} q> W| Sd d l	 m
 } t  | t ƒ rÎ t  | | ƒ rÎ t t | ƒ d d ƒ ‚ n  t  | | ƒ rð ‡  f d †  } | St ˆ  | ƒ S(   sN  
        Returns the dot product of this Vector, either with another
        Vector, or a Dyadic, or a Del operator.
        If 'other' is a Vector, returns the dot product scalar (Sympy
        expression).
        If 'other' is a Dyadic, the dot product is returned as a Vector.
        If 'other' is an instance of Del, returns the directional
        derivative operator as a Python function. If this function is
        applied to a scalar expression, it returns the directional
        derivative of the scalar field wrt this Vector.

        Parameters
        ==========

        other: Vector/Dyadic/Del
            The Vector or Dyadic we are dotting with, or a Del operator .

        Examples
        ========

        >>> from sympy.vector import CoordSys3D, Del
        >>> C = CoordSys3D('C')
        >>> delop = Del()
        >>> C.i.dot(C.j)
        0
        >>> C.i & C.i
        1
        >>> v = 3*C.i + 4*C.j + 5*C.k
        >>> v.dot(C.k)
        5
        >>> (C.i & delop)(C.x*C.y*C.z)
        C.y*C.z
        >>> d = C.i.outer(C.i)
        >>> C.i.dot(d)
        C.i

        i    i   iÿÿÿÿ(   t   Dels    is not a vector, dyadic or s   del operatorc            s   d d l  m } | |  ˆ  ƒ S(   Niÿÿÿÿ(   t   directional_derivative(   t   sympy.vector.functionsR   (   t   fieldR   (   R   (    s2   lib/python2.7/site-packages/sympy/vector/vector.pyR   n   s    (   t
   isinstanceR   t
   VectorZeroR   t   zeroR   t   itemst   argst   dott   sympy.vector.deloperatorR   t	   TypeErrort   str(   R   t   othert   outvect   kt   vt   vect_dotR   R   (    (   R   s2   lib/python2.7/site-packages/sympy/vector/vector.pyR"   7   s     (	 c         C   s   |  j  | ƒ S(   N(   R"   (   R   R&   (    (    s2   lib/python2.7/site-packages/sympy/vector/vector.pyt   __and__u   s    c         C   s™   t  | t ƒ rŒ t  |  t ƒ r% t j St j } xW | j j ƒ  D]F \ } } |  j | j d ƒ } | j | j d ƒ } | | | 7} q> W| St |  | ƒ S(   sÃ  
        Returns the cross product of this Vector with another Vector or
        Dyadic instance.
        The cross product is a Vector, if 'other' is a Vector. If 'other'
        is a Dyadic, this returns a Dyadic instance.

        Parameters
        ==========

        other: Vector/Dyadic
            The Vector or Dyadic we are crossing with.

        Examples
        ========

        >>> from sympy.vector import CoordSys3D
        >>> C = CoordSys3D('C')
        >>> C.i.cross(C.j)
        C.k
        >>> C.i ^ C.i
        0
        >>> v = 3*C.i + 4*C.j + 5*C.k
        >>> v ^ C.i
        5*C.j + (-4)*C.k
        >>> d = C.i.outer(C.i)
        >>> C.j.cross(d)
        (-1)*(C.k|C.i)

        i    i   (	   R   R   R   R   R   R    t   crossR!   t   outer(   R   R&   t   outdyadR(   R)   t   cross_productR-   (    (    s2   lib/python2.7/site-packages/sympy/vector/vector.pyR,   z   s     	c         C   s   |  j  | ƒ S(   N(   R,   (   R   R&   (    (    s2   lib/python2.7/site-packages/sympy/vector/vector.pyt   __xor__¦   s    c         C   s±   t  | t ƒ s t d ƒ ‚ n% t  |  t ƒ s< t  | t ƒ rC t j Sg  } x[ |  j j ƒ  D]J \ } } x; | j j ƒ  D]* \ } } | j | | t	 | | ƒ ƒ qu WqY Wt
 | Œ  S(   s±  
        Returns the outer product of this vector with another, in the
        form of a Dyadic instance.

        Parameters
        ==========

        other : Vector
            The Vector with respect to which the outer product is to
            be computed.

        Examples
        ========

        >>> from sympy.vector import CoordSys3D
        >>> N = CoordSys3D('N')
        >>> N.i.outer(N.j)
        (N.i|N.j)

        s!   Invalid operand for outer product(   R   R   R$   R   R   R   R   R    t   appendR   R   (   R   R&   R!   t   k1t   v1t   k2t   v2(    (    s2   lib/python2.7/site-packages/sympy/vector/vector.pyR-   «   s    &c         C   sh   |  j  t j ƒ r& | r t j St j S| rF |  j | ƒ |  j |  ƒ S|  j | ƒ |  j |  ƒ |  Sd S(   sê  
        Returns the vector or scalar projection of the 'other' on 'self'.

        Examples
        ========

        >>> from sympy.vector.coordsysrect import CoordSys3D
        >>> from sympy.vector.vector import Vector, BaseVector
        >>> C = CoordSys3D('C')
        >>> i, j, k = C.base_vectors()
        >>> v1 = i + j + k
        >>> v2 = 3*i + 4*j
        >>> v1.projection(v2)
        7/3*C.i + 7/3*C.j + 7/3*C.k
        >>> v1.projection(v2, scalar=True)
        7/3

        N(   t   equalsR   R   R   R"   (   R   R&   t   scalar(    (    s2   lib/python2.7/site-packages/sympy/vector/vector.pyt
   projectionÑ   s
    c         C   s‚   d d l  m } t |  t ƒ r> t d ƒ t d ƒ t d ƒ f St t | |  ƒ ƒ ƒ j ƒ  } t g  | D] } |  j	 | ƒ ^ qf ƒ S(   sé  
        Returns the components of this vector but the output includes
        also zero values components.

        Examples
        ========

        >>> from sympy.vector import CoordSys3D, Vector
        >>> C = CoordSys3D('C')
        >>> v1 = 3*C.i + 4*C.j + 5*C.k
        >>> v1._projections
        (3, 4, 5)
        >>> v2 = C.x*C.y*C.z*C.i
        >>> v2._projections
        (C.x*C.y*C.z, 0, 0)
        >>> v3 = Vector.zero
        >>> v3._projections
        (0, 0, 0)
        iÿÿÿÿ(   t   _get_coord_sys_from_expri    (
   t   sympy.vector.operatorsR9   R   R   R   t   nextt   itert   base_vectorst   tupleR"   (   R   R9   t   base_vect   i(    (    s2   lib/python2.7/site-packages/sympy/vector/vector.pyt   _projectionsì   s
    c         C   s   |  j  | ƒ S(   N(   R-   (   R   R&   (    (    s2   lib/python2.7/site-packages/sympy/vector/vector.pyt   __or__  s    c         C   s,   t  g  | j ƒ  D] } |  j | ƒ ^ q ƒ S(   s  
        Returns the matrix form of this vector with respect to the
        specified coordinate system.

        Parameters
        ==========

        system : CoordSys3D
            The system wrt which the matrix form is to be computed

        Examples
        ========

        >>> from sympy.vector import CoordSys3D
        >>> C = CoordSys3D('C')
        >>> from sympy.abc import a, b, c
        >>> v = a*C.i + b*C.j + c*C.k
        >>> v.to_matrix(C)
        Matrix([
        [a],
        [b],
        [c]])

        (   t   MatrixR=   R"   (   R   t   systemt   unit_vec(    (    s2   lib/python2.7/site-packages/sympy/vector/vector.pyt	   to_matrix  s    c         C   sQ   i  } xD |  j  j ƒ  D]3 \ } } | j | j t j ƒ | | | | j <q W| S(   sÅ  
        The constituents of this vector in different coordinate systems,
        as per its definition.

        Returns a dict mapping each CoordSys3D to the corresponding
        constituent Vector.

        Examples
        ========

        >>> from sympy.vector import CoordSys3D
        >>> R1 = CoordSys3D('R1')
        >>> R2 = CoordSys3D('R2')
        >>> v = R1.i + R2.i
        >>> v.separate() == {R1: R1.i, R2: R2.i}
        True

        (   R   R    t   getRD   R   R   (   R   t   partst   vectt   measure(    (    s2   lib/python2.7/site-packages/sympy/vector/vector.pyt   separate*  s
    (   t   __name__t
   __module__t   __doc__t   Truet	   is_Vectort   _op_priorityt   propertyR   R   R   R"   R+   R,   R0   R-   t   FalseR8   RA   RB   RF   RK   (    (    (    s2   lib/python2.7/site-packages/sympy/vector/vector.pyR      s&   			>		,		&		t
   BaseVectorc           B   sS   e  Z d  Z d d d „ Z e d „  ƒ Z d d „ Z e d „  ƒ Z e Z	 e Z
 RS(   sl   
    Class to denote a base vector.

    Unicode pretty forms in Python 2 should use the prefix ``u``.

    c         C   s`  | d  k r d j | ƒ } n  | d  k r< d j | ƒ } n  t | ƒ } t | ƒ } | t d d ƒ k rx t d ƒ ‚ n  t | t ƒ s– t d ƒ ‚ n  | j | } t	 t
 |  ƒ j |  t | ƒ | ƒ } | | _ i t d ƒ | 6| _ t d ƒ | _ | j d | | _ d	 | | _ | | _ | | _ | | f | _ i t d
 6} t | ƒ | _ | | _ | S(   Ns   x{0}s   x_{0}i    i   s   index must be 0, 1 or 2s   system should be a CoordSys3Di   t   .u    t   commutative(   t   Nonet   formatR%   R   t
   ValueErrorR   R   R$   t   _vector_namest   superRT   t   __new__R   t   _base_instanceR   t   _measure_numbert   _namet   _pretty_formt   _latex_formt   _systemt   _idRO   R    t   _assumptionst   _sys(   t   clst   indexRD   t
   pretty_strt	   latex_strt   namet   objt   assumptions(    (    s2   lib/python2.7/site-packages/sympy/vector/vector.pyR\   M  s0    $				c         C   s   |  j  S(   N(   Rb   (   R   (    (    s2   lib/python2.7/site-packages/sympy/vector/vector.pyRD   p  s    c         C   s   |  j  S(   N(   R_   (   R   t   printer(    (    s2   lib/python2.7/site-packages/sympy/vector/vector.pyt   __str__t  s    c         C   s   |  h S(   N(    (   R   (    (    s2   lib/python2.7/site-packages/sympy/vector/vector.pyt   free_symbolsw  s    N(   RL   RM   RN   RW   R\   RR   RD   Rn   Ro   t   __repr__t	   _sympystr(    (    (    s2   lib/python2.7/site-packages/sympy/vector/vector.pyRT   E  s   #t	   VectorAddc           B   s/   e  Z d  Z d „  Z d d „ Z e Z e Z RS(   s2   
    Class to denote sum of Vector instances.
    c         O   s   t  j |  | | Ž } | S(   N(   R   R\   (   Rf   R!   t   optionsRk   (    (    s2   lib/python2.7/site-packages/sympy/vector/vector.pyR\   „  s    c   	      C   s§   d } t  |  j ƒ  j ƒ  ƒ } | j d d „  ƒ xk | D]c \ } } | j ƒ  } xH | D]@ } | | j k rW |  j | | } | | j | ƒ d 7} qW qW Wq8 W| d  S(   Nt    t   keyc         S   s   |  d j  ƒ  S(   Ni    (   Rn   (   t   x(    (    s2   lib/python2.7/site-packages/sympy/vector/vector.pyt   <lambda>‹  Rt   s    + iýÿÿÿ(   t   listRK   R    t   sortR=   R   Rn   (	   R   Rm   t   ret_strR    RD   RI   t
   base_vectsRv   t	   temp_vect(    (    s2   lib/python2.7/site-packages/sympy/vector/vector.pyRn   ˆ  s    "N(   RL   RM   RN   R\   RW   Rn   Rp   Rq   (    (    (    s2   lib/python2.7/site-packages/sympy/vector/vector.pyRr     s
   	t	   VectorMulc           B   s5   e  Z d  Z d „  Z e d „  ƒ Z e d „  ƒ Z RS(   s>   
    Class to denote products of scalars and BaseVectors.
    c         O   s   t  j |  | | Ž } | S(   N(   R   R\   (   Rf   R!   Rs   Rk   (    (    s2   lib/python2.7/site-packages/sympy/vector/vector.pyR\     s    c         C   s   |  j  S(   s)    The BaseVector involved in the product. (   R]   (   R   (    (    s2   lib/python2.7/site-packages/sympy/vector/vector.pyt   base_vector¡  s    c         C   s   |  j  S(   sU    The scalar expression involved in the definition of
        this VectorMul.
        (   R^   (   R   (    (    s2   lib/python2.7/site-packages/sympy/vector/vector.pyt   measure_number¦  s    (   RL   RM   RN   R\   RR   R~   R   (    (    (    s2   lib/python2.7/site-packages/sympy/vector/vector.pyR}   ˜  s   	R   c           B   s)   e  Z d  Z d Z d Z d Z d „  Z RS(   s'   
    Class to denote a zero vector
    g333333(@u   0s   \mathbf{\hat{0}}c         C   s   t  j |  ƒ } | S(   N(   R   R\   (   Rf   Rk   (    (    s2   lib/python2.7/site-packages/sympy/vector/vector.pyR\   ·  s    (   RL   RM   RN   RQ   R`   Ra   R\   (    (    (    s2   lib/python2.7/site-packages/sympy/vector/vector.pyR   ®  s
   t   Crossc           B   s    e  Z d  Z d „  Z d „  Z RS(   sŒ  
    Represents unevaluated Cross product.

    Examples
    ========

    >>> from sympy.vector import CoordSys3D, Cross
    >>> R = CoordSys3D('R')
    >>> v1 = R.i + R.j + R.k
    >>> v2 = R.x * R.i + R.y * R.j + R.z * R.k
    >>> Cross(v1, v2)
    Cross(R.i + R.j + R.k, R.x*R.i + R.y*R.j + R.z*R.k)
    >>> Cross(v1, v2).doit()
    (-R.y + R.z)*R.i + (R.x - R.z)*R.j + (-R.x + R.y)*R.k

    c         C   si   t  | ƒ } t  | ƒ } t | ƒ t | ƒ k r> t | | ƒ St j |  | | ƒ } | | _ | | _ | S(   N(   R   R   R€   R   R\   t   _expr1t   _expr2(   Rf   t   expr1t   expr2Rk   (    (    s2   lib/python2.7/site-packages/sympy/vector/vector.pyR\   Î  s    		c         K   s   t  |  j |  j ƒ S(   N(   R,   R   R‚   (   R   t   kwargs(    (    s2   lib/python2.7/site-packages/sympy/vector/vector.pyt   doitØ  s    (   RL   RM   RN   R\   R†   (    (    (    s2   lib/python2.7/site-packages/sympy/vector/vector.pyR€   ¼  s   	
t   Dotc           B   s    e  Z d  Z d „  Z d „  Z RS(   s  
    Represents unevaluated Dot product.

    Examples
    ========

    >>> from sympy.vector import CoordSys3D, Dot
    >>> from sympy import symbols
    >>> R = CoordSys3D('R')
    >>> a, b, c = symbols('a b c')
    >>> v1 = R.i + R.j + R.k
    >>> v2 = a * R.i + b * R.j + c * R.k
    >>> Dot(v1, v2)
    Dot(R.i + R.j + R.k, a*R.i + b*R.j + c*R.k)
    >>> Dot(v1, v2).doit()
    a + b + c

    c         C   sa   t  | ƒ } t  | ƒ } t | | g d t ƒ\ } } t j |  | | ƒ } | | _ | | _ | S(   NRu   (   R   t   sortedR   R   R\   R   R‚   (   Rf   Rƒ   R„   Rk   (    (    s2   lib/python2.7/site-packages/sympy/vector/vector.pyR\   ð  s    		c         K   s   t  |  j |  j ƒ S(   N(   R"   R   R‚   (   R   R…   (    (    s2   lib/python2.7/site-packages/sympy/vector/vector.pyR†   ù  s    (   RL   RM   RN   R\   R†   (    (    (    s2   lib/python2.7/site-packages/sympy/vector/vector.pyR‡   Ü  s   		c            s  t  ˆ  t ƒ r/ t j ‡ f d †  ˆ  j Dƒ ƒ St  ˆ t ƒ r^ t j ‡  f d †  ˆ j Dƒ ƒ St  ˆ  t ƒ rXt  ˆ t ƒ rXˆ  j ˆ j k rˆ  j d } ˆ j d } | | k r» t j Sd d d h j	 | | h ƒ j
 ƒ  } | d d | k rù d n d } | ˆ  j j ƒ  | Sy- d d l m } t | ˆ  ˆ j ƒ ˆ ƒ SWqXt ˆ  ˆ ƒ SXn  t  ˆ  t ƒ svt  ˆ t ƒ r}t j St  ˆ  t ƒ r¾t t ˆ  j j ƒ  ƒ ƒ \ } } | t | ˆ ƒ St  ˆ t ƒ rÿt t ˆ j j ƒ  ƒ ƒ \ }	 }
 |
 t ˆ  |	 ƒ St ˆ  ˆ ƒ S(	   s^  
    Returns cross product of two vectors.

    Examples
    ========

    >>> from sympy.vector import CoordSys3D
    >>> from sympy.vector.vector import cross
    >>> R = CoordSys3D('R')
    >>> v1 = R.i + R.j + R.k
    >>> v2 = R.x * R.i + R.y * R.j + R.z * R.k
    >>> cross(v1, v2)
    (-R.y + R.z)*R.i + (R.x - R.z)*R.j + (-R.x + R.y)*R.k

    c         3   s   |  ] } t  | ˆ  ƒ Vq d  S(   N(   R,   (   t   .0R@   (   t   vect2(    s2   lib/python2.7/site-packages/sympy/vector/vector.pys	   <genexpr>  s    c         3   s   |  ] } t  ˆ  | ƒ Vq d  S(   N(   R,   (   R‰   R@   (   t   vect1(    s2   lib/python2.7/site-packages/sympy/vector/vector.pys	   <genexpr>  s    i    i   i   i   iÿÿÿÿ(   t   express(   R   R
   Rr   t   fromiterR!   RT   Re   R   R   t
   differencet   popR=   t	   functionsRŒ   R,   R€   R   R}   R;   R<   R   R    (   R‹   RŠ   t   n1t   n2t   n3t   signRŒ   R3   t   m1R5   t   m2(    (   R‹   RŠ   s2   lib/python2.7/site-packages/sympy/vector/vector.pyR,   ý  s6      $ !!c            s   t  ˆ  t ƒ r/ t j ‡ f d †  ˆ  j Dƒ ƒ St  ˆ t ƒ r^ t j ‡  f d †  ˆ j Dƒ ƒ St  ˆ  t ƒ rì t  ˆ t ƒ rì ˆ  j ˆ j k r¨ ˆ  ˆ k r¡ t j St j Sy- d d l	 m
 } t ˆ  | ˆ ˆ  j ƒ ƒ SWqì t ˆ  ˆ ƒ SXn  t  ˆ  t ƒ s
t  ˆ t ƒ rt j St  ˆ  t ƒ rRt t ˆ  j j ƒ  ƒ ƒ \ } } | t | ˆ ƒ St  ˆ t ƒ r“t t ˆ j j ƒ  ƒ ƒ \ } } | t ˆ  | ƒ St ˆ  ˆ ƒ S(   s2  
    Returns dot product of two vectors.

    Examples
    ========

    >>> from sympy.vector import CoordSys3D
    >>> from sympy.vector.vector import dot
    >>> R = CoordSys3D('R')
    >>> v1 = R.i + R.j + R.k
    >>> v2 = R.x * R.i + R.y * R.j + R.z * R.k
    >>> dot(v1, v2)
    R.x + R.y + R.z

    c         3   s   |  ] } t  | ˆ  ƒ Vq d  S(   N(   R"   (   R‰   R@   (   RŠ   (    s2   lib/python2.7/site-packages/sympy/vector/vector.pys	   <genexpr><  s    c         3   s   |  ] } t  ˆ  | ƒ Vq d  S(   N(   R"   (   R‰   R@   (   R‹   (    s2   lib/python2.7/site-packages/sympy/vector/vector.pys	   <genexpr>>  s    i   (   RŒ   (   R   R
   R   R!   RT   Re   R   t   Onet   ZeroR   RŒ   R"   R‡   R   R}   R;   R<   R   R    (   R‹   RŠ   RŒ   R3   R•   R5   R–   (    (   R‹   RŠ   s2   lib/python2.7/site-packages/sympy/vector/vector.pyR"   +  s*      !!c         C   sƒ   t  |  t ƒ r- t  | t ƒ r- t d ƒ ‚ nR t  |  t ƒ rs | t j k rZ t d ƒ ‚ n  t |  t | t j ƒ ƒ St d ƒ ‚ d S(   s(    Helper for division involving vectors. s   Cannot divide two vectorss   Cannot divide a vector by zeros#   Invalid division involving a vectorN(	   R   R   R$   R   R˜   RY   R}   R   t   NegativeOne(   t   oneR&   (    (    s2   lib/python2.7/site-packages/sympy/vector/vector.pyt	   _vect_divS  s    N(-   t   sympy.core.assumptionsR    t
   sympy.coreR   R   R   t   sympy.core.exprR   R   t   sympy.core.compatibilityR   R   t   sympyR   R	   RC   R
   t   sympy.vector.coordsysrectR   t   sympy.vector.basisdependentR   R   R   R   t   sympy.vector.dyadicR   R   R   R   RT   Rr   R}   R   R€   R‡   R,   R"   R›   t
   _expr_typet	   _mul_funct	   _add_funct
   _zero_funct
   _base_funct   _div_helperR   (    (    (    s2   lib/python2.7/site-packages/sympy/vector/vector.pyt   <module>   s2   "ÿ :: !	.	(							