ó
¡¼™\c           @   s-  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 d  d l 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 „  Z e e _ e e _ e e _ e e _ e e _ e e _ e ƒ  e _ d S(   iÿÿÿÿ(   t   BasisDependentt   BasisDependentAddt   BasisDependentMult   BasisDependentZero(   t   St   Pow(   t
   AtomicExpr(   t   ImmutableMatrixNt   Dyadicc           B   sk   e  Z d  Z d Z e d „  ƒ Z d „  Z d „  Z e j e _ d „  Z d „  Z	 e j e	 _ d d „ Z RS(	   så   
    Super class for all Dyadic-classes.

    References
    ==========

    .. [1] https://en.wikipedia.org/wiki/Dyadic_tensor
    .. [2] Kane, T., Levinson, D. Dynamics Theory and Applications. 1985
           McGraw-Hill

    g      *@c         C   s   |  j  S(   s®   
        Returns the components of this dyadic in the form of a
        Python dictionary mapping BaseDyadic instances to the
        corresponding measure numbers.

        (   t   _components(   t   self(    (    s2   lib/python2.7/site-packages/sympy/vector/dyadic.pyt
   components   s    
c         C   s]  t  j j } t | t ƒ r" | j St | | ƒ r | j } xL |  j j ƒ  D]; \ } } | j d j	 | ƒ } | | | | j d 7} qJ W| St | t
 ƒ r9t
 j } x |  j j ƒ  D]| \ } }	 xm | j j ƒ  D]\ \ }
 } | j d j	 |
 j d ƒ } | j d j |
 j d ƒ } | | |	 | | 7} qÑ Wqµ W| St d t t | ƒ ƒ d ƒ ‚ d S(   s„  
        Returns the dot product(also called inner product) of this
        Dyadic, with another Dyadic or Vector.
        If 'other' is a Dyadic, this returns a Dyadic. Else, it returns
        a Vector (unless an error is encountered).

        Parameters
        ==========

        other : Dyadic/Vector
            The other Dyadic or Vector to take the inner product with

        Examples
        ========

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

        i   i    s!   Inner product is not defined for s    and Dyadics.N(   t   sympyt   vectort   Vectort
   isinstanceR   t   zeroR   t   itemst   argst   dotR   t   outert	   TypeErrort   strt   type(   R
   t   otherR   t   outvect   kt   vt   vect_dott   outdyadt   k1t   v1t   k2t   v2t   outer_product(    (    s2   lib/python2.7/site-packages/sympy/vector/dyadic.pyR   $   s&    		c         C   s   |  j  | ƒ S(   N(   R   (   R
   R   (    (    s2   lib/python2.7/site-packages/sympy/vector/dyadic.pyt   __and__T   s    c         C   s¼   t  j j } | | j k r" t j St | | ƒ r˜ t j } xW |  j j ƒ  D]F \ } } | j d j	 | ƒ } | j d j
 | ƒ } | | | 7} qJ W| St t t | ƒ ƒ d d ƒ ‚ d S(   s§  
        Returns the cross product between this Dyadic, and a Vector, as a
        Vector instance.

        Parameters
        ==========

        other : Vector
            The Vector that we are crossing this Dyadic with

        Examples
        ========

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

        i   i    s    not supported for s   cross with dyadicsN(   R   R   R   R   R   R   R   R   R   t   crossR   R   R   R   (   R
   R   R   R   R   R   t   cross_productR   (    (    s2   lib/python2.7/site-packages/sympy/vector/dyadic.pyR$   Y   s    	c         C   s   |  j  | ƒ S(   N(   R$   (   R
   R   (    (    s2   lib/python2.7/site-packages/sympy/vector/dyadic.pyt   __xor__}   s    c         C   s]   | d k r | } n  t g  | D]+ } | D] } | j |  ƒ j | ƒ ^ q) q ƒ j d d ƒ S(   s%  
        Returns the matrix form of the dyadic with respect to one or two
        coordinate systems.

        Parameters
        ==========

        system : CoordSys3D
            The coordinate system that the rows and columns of the matrix
            correspond to. If a second system is provided, this
            only corresponds to the rows of the matrix.
        second_system : CoordSys3D, optional, default=None
            The coordinate system that the columns of the matrix correspond
            to.

        Examples
        ========

        >>> from sympy.vector import CoordSys3D
        >>> N = CoordSys3D('N')
        >>> v = N.i + 2*N.j
        >>> d = v.outer(N.i)
        >>> d.to_matrix(N)
        Matrix([
        [1, 0, 0],
        [2, 0, 0],
        [0, 0, 0]])
        >>> from sympy import Symbol
        >>> q = Symbol('q')
        >>> P = N.orient_new_axis('P', q, N.k)
        >>> d.to_matrix(N, P)
        Matrix([
        [  cos(q),   -sin(q), 0],
        [2*cos(q), -2*sin(q), 0],
        [       0,         0, 0]])

        i   N(   t   Nonet   MatrixR   t   reshape(   R
   t   systemt   second_systemt   it   j(    (    s2   lib/python2.7/site-packages/sympy/vector/dyadic.pyt	   to_matrix‚   s    '	N(   t   __name__t
   __module__t   __doc__t   _op_priorityt   propertyR   R   R#   R$   R&   R'   R.   (    (    (    s2   lib/python2.7/site-packages/sympy/vector/dyadic.pyR   	   s   	0		$	t
   BaseDyadicc           B   s/   e  Z d  Z d „  Z d d „ Z e Z e Z RS(   s9   
    Class to denote a base dyadic tensor component.
    c         C   s  t  j j } t  j j } t  j j } t | | | f ƒ sP t | | | f ƒ rc t d d ƒ ‚ n% | | j k s | | j k rˆ t j St	 t
 |  ƒ j |  | | ƒ } | | _ d | _ i t d ƒ | 6| _ | j | _ d | j d | j d | _ d | j d | j d | _ | S(	   Ns*   BaseDyadic cannot be composed of non-base t   vectorsi   u   (t   |t   )t   (s   {|}(   R   R   R   t
   BaseVectort
   VectorZeroR   R   R   R   t   superR4   t   __new__t   _base_instancet   _measure_numberR   R	   t   _syst   _pretty_formt   _latex_form(   t   clst   vector1t   vector2R   R9   R:   t   obj(    (    s2   lib/python2.7/site-packages/sympy/vector/dyadic.pyR<   µ   s"    		c         C   s.   d t  |  j d ƒ d t  |  j d ƒ d S(   NR8   i    R6   i   R7   (   R   R   (   R
   t   printer(    (    s2   lib/python2.7/site-packages/sympy/vector/dyadic.pyt   __str__Î   s    N(   R/   R0   R1   R<   R'   RG   t	   _sympystrt
   _sympyrepr(    (    (    s2   lib/python2.7/site-packages/sympy/vector/dyadic.pyR4   °   s
   	t	   DyadicMulc           B   s5   e  Z d  Z d „  Z e d „  ƒ Z e d „  ƒ Z RS(   s%    Products of scalars and BaseDyadics c         O   s   t  j |  | | Ž } | S(   N(   R   R<   (   RB   R   t   optionsRE   (    (    s2   lib/python2.7/site-packages/sympy/vector/dyadic.pyR<   Ø   s    c         C   s   |  j  S(   s)    The BaseDyadic involved in the product. (   R=   (   R
   (    (    s2   lib/python2.7/site-packages/sympy/vector/dyadic.pyt   base_dyadicÜ   s    c         C   s   |  j  S(   sU    The scalar expression involved in the definition of
        this DyadicMul.
        (   R>   (   R
   (    (    s2   lib/python2.7/site-packages/sympy/vector/dyadic.pyt   measure_numberá   s    (   R/   R0   R1   R<   R3   RL   RM   (    (    (    s2   lib/python2.7/site-packages/sympy/vector/dyadic.pyRJ   Õ   s   	t	   DyadicAddc           B   s/   e  Z d  Z d „  Z d d „ Z e Z e Z RS(   s    Class to hold dyadic sums c         O   s   t  j |  | | Ž } | S(   N(   R   R<   (   RB   R   RK   RE   (    (    s2   lib/python2.7/site-packages/sympy/vector/dyadic.pyR<   ì   s    c         C   sn   d } t  |  j j ƒ  ƒ } | j d d „  ƒ x5 | D]- \ } } | | } | | j | ƒ d 7} q5 W| d  S(   Nt    t   keyc         S   s   |  d j  ƒ  S(   Ni    (   RG   (   t   x(    (    s2   lib/python2.7/site-packages/sympy/vector/dyadic.pyt   <lambda>ó   RO   s    + iýÿÿÿ(   t   listR   R   t   sortRG   (   R
   RF   t   ret_strR   R   R   t	   temp_dyad(    (    s2   lib/python2.7/site-packages/sympy/vector/dyadic.pyRG   ð   s    
N(   R/   R0   R1   R<   R'   RG   t   __repr__RH   (    (    (    s2   lib/python2.7/site-packages/sympy/vector/dyadic.pyRN   é   s
   		t
   DyadicZeroc           B   s)   e  Z d  Z d Z d Z d Z d „  Z RS(   s'   
    Class to denote a zero dyadic
    g333333*@u   (0|0)s#   (\mathbf{\hat{0}}|\mathbf{\hat{0}})c         C   s   t  j |  ƒ } | S(   N(   R   R<   (   RB   RE   (    (    s2   lib/python2.7/site-packages/sympy/vector/dyadic.pyR<     s    (   R/   R0   R1   R2   R@   RA   R<   (    (    (    s2   lib/python2.7/site-packages/sympy/vector/dyadic.pyRX   ý   s
   c         C   se   t  |  t ƒ r- t  | t ƒ r- t d ƒ ‚ n4 t  |  t ƒ rU t |  t | t j ƒ ƒ St d ƒ ‚ d S(   s'    Helper for division involving dyadics s   Cannot divide two dyadicss   Cannot divide by a dyadicN(   R   R   R   RJ   R   R   t   NegativeOne(   t   oneR   (    (    s2   lib/python2.7/site-packages/sympy/vector/dyadic.pyt	   _dyad_div  s
    (   t   sympy.vector.basisdependentR    R   R   R   t
   sympy.coreR   R   t   sympy.core.exprR   R   R   R(   t   sympy.vectorR   R4   RJ   RN   RX   R[   t
   _expr_typet	   _mul_funct	   _add_funct
   _zero_funct
   _base_funct   _div_helperR   (    (    (    s2   lib/python2.7/site-packages/sympy/vector/dyadic.pyt   <module>   s"   "§%	
						