ó
¡¼™\c           @   st   d  d l  m Z m Z m Z d  d l m Z d d l m Z m	 Z	 m
 Z
 d g Z d e f d „  ƒ  YZ d „  Z d S(	   iÿÿÿÿ(   t   sympifyt   Addt   ImmutableMatrix(   t   unicodei   (   t   VectorLatexPrintert   VectorPrettyPrintert   VectorStrPrintert   Dyadicc           B   s+  e  Z d  Z d „  Z d „  Z d „  Z d „  Z e Z d „  Z d „  Z	 d „  Z
 d „  Z d d	 „ Z d d
 „ Z d „  Z d „  Z d „  Z d d „ Z d „  Z d „  Z d „  Z e Z e Z e Z e Z e Z e	 Z d d „ Z d d „ Z d „  Z d „  Z d „  Z  d „  Z! d „  Z" e Z# e Z$ RS(   sy  A Dyadic object.

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

    A more powerful way to represent a rigid body's inertia. While it is more
    complex, by choosing Dyadic components to be in body fixed basis vectors,
    the resulting matrix is equivalent to the inertia tensor.

    c         C   sÔ  g  |  _  | d k r g  } n  xt | ƒ d k r>d } xË t |  j  ƒ D]º \ } } t | d d ƒ t |  j  | d ƒ k rI t | d d ƒ t |  j  | d ƒ k rI |  j  | d | d d | d d | d d f |  j  | <| j | d ƒ d } PqI qI W| d k r! |  j  j | d ƒ | j | d ƒ q! q! Wd } xˆ | t |  j  ƒ k  rÏ|  j  | d d k |  j  | d d k B|  j  | d d k BrÂ|  j  j |  j  | ƒ | d 8} n  | d 7} qHWd S(   s1  
        Just like Vector's init, you shouldn't call this unless creating a
        zero dyadic.

        zd = Dyadic(0)

        Stores a Dyadic as a list of lists; the inner list has the measure
        number and the two unit vectors; the outerlist holds each unique
        unit vector pair.

        i    i   i   N(   t   argst   lent	   enumeratet   strt   removet   append(   t   selft   inlistt   addedt   it   v(    (    s:   lib/python2.7/site-packages/sympy/physics/vector/dyadic.pyt   __init__   s.    		++#)c         C   s    t  | ƒ } t |  j | j ƒ S(   s   The add operator for Dyadic. (   t   _check_dyadicR   R   (   R   t   other(    (    s:   lib/python2.7/site-packages/sympy/physics/vector/dyadic.pyt   __add__<   s    c   	      C   s  d d l  m } m } t | t ƒ r¶ t | ƒ } t d ƒ } xÐ t |  j ƒ D]b \ } } xS t | j ƒ D]B \ } } | | d | d | d | d @| d | d B7} qi WqM WnZ | | ƒ } | d ƒ } x? t |  j ƒ D]. \ } } | | d | d | d | @7} qÞ W| S(   sò  The inner product operator for a Dyadic and a Dyadic or Vector.

        Parameters
        ==========

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

        Examples
        ========

        >>> from sympy.physics.vector import ReferenceFrame, outer
        >>> N = ReferenceFrame('N')
        >>> D1 = outer(N.x, N.y)
        >>> D2 = outer(N.y, N.y)
        >>> D1.dot(D2)
        (N.x|N.y)
        >>> D1.dot(N.y)
        N.x

        iÿÿÿÿ(   t   Vectort   _check_vectori    i   i   (   t   sympy.physics.vector.vectorR   R   t
   isinstanceR   R   R
   R   (	   R   R   R   R   t   olR   R   t   i2t   v2(    (    s:   lib/python2.7/site-packages/sympy/physics/vector/dyadic.pyt   __and__A   s    A&c         C   s   |  j  d | ƒ S(   s0   Divides the Dyadic by a sympifyable expression. i   (   t   __mul__(   R   R   (    (    s:   lib/python2.7/site-packages/sympy/physics/vector/dyadic.pyt   __div__e   s    c         C   s‡   | d k r t  d ƒ } n  t | ƒ } |  j g  k rI | j g  k rI t S|  j g  k sg | j g  k rk t St |  j ƒ t | j ƒ k S(   s[   Tests for equality.

        Is currently weak; needs stronger comparison testing

        i    (   R   R   R   t   Truet   Falset   set(   R   R   (    (    s:   lib/python2.7/site-packages/sympy/physics/vector/dyadic.pyt   __eq__k   s    c         C   sx   g  |  j  D] } | ^ q
 } xO t | ƒ D]A \ } } t | ƒ | | d | | d | | d f | | <q) Wt | ƒ S(   s…  Multiplies the Dyadic by a sympifyable expression.

        Parameters
        ==========

        other : Sympafiable
            The scalar to multiply this Dyadic with

        Examples
        ========

        >>> from sympy.physics.vector import ReferenceFrame, outer
        >>> N = ReferenceFrame('N')
        >>> d = outer(N.x, N.x)
        >>> 5 * d
        5*(N.x|N.x)

        i    i   i   (   R   R
   R    R   (   R   R   R   t   newlistR   (    (    s:   lib/python2.7/site-packages/sympy/physics/vector/dyadic.pyR   {   s
     c         C   s   |  | k S(   N(    (   R   R   (    (    s:   lib/python2.7/site-packages/sympy/physics/vector/dyadic.pyt   __ne__•   s    c         C   s   |  d S(   Niÿÿÿÿ(    (   R   (    (    s:   lib/python2.7/site-packages/sympy/physics/vector/dyadic.pyt   __neg__˜   s    c   
      C   sù  |  j  } t | ƒ d k r% t d ƒ Sg  } t ƒ  } xwt | ƒ D]i\ } } | | d d k rŸ | j d | j | | d ƒ d | j | | d ƒ ƒ qA | | d d k rñ | j d | j | | d ƒ d | j | | d ƒ ƒ qA | | d d k rA | j | | d ƒ } t | | d t ƒ r@d | } n  | j	 d	 ƒ rb| d } d } n d } | j | | | j | | d ƒ d | j | | d ƒ ƒ qA qA Wd
 j
 | ƒ }	 |	 j	 d ƒ rÙ|	 d }	 n |	 j	 d ƒ rõ|	 d }	 n  |	 S(   Ni    i   s    + s   \otimes i   iÿÿÿÿs    - s   (%s)t   -t    i   t    (   R   R	   R   R   R
   R   t   doprintR   R   t
   startswitht   join(
   R   t   printert   arR   t   mlpR   R   t   arg_strt	   str_startt   outstr(    (    s:   lib/python2.7/site-packages/sympy/physics/vector/dyadic.pyt   _latex›   s:    	
	"
	@c            s,   |  ‰  d t  f ‡  ‡ f d †  ƒ  Y} | ƒ  S(   Nt   Fakec              s    e  Z d  Z ‡  ‡ f d †  Z RS(   i    c      
      ss  ˆ  j  } ˆ r ˆ j n i  } ˆ r0 ˆ j } n d d l m } | ƒ  } ˆ rU ˆ n	 t | ƒ } t | ƒ d k r} t d ƒ S| r‰ d n d } g  }	 xt | ƒ D]‚\ }
 } | |
 d d k r |	 j	 d | j
 | |
 d ƒ | | j
 | |
 d ƒ g ƒ q¢ | |
 d d k rR|	 j	 d	 | j
 | |
 d ƒ | | j
 | |
 d ƒ g ƒ q¢ | |
 d d k r¢ t | |
 d t ƒ r¡| j | |
 d ƒ j ƒ  d } n | j
 | |
 d ƒ } | j d
 ƒ rÚ| d } d	 } n d } |	 j	 | | d | j
 | |
 d ƒ | | j
 | |
 d ƒ g ƒ q¢ q¢ Wd j |	 ƒ } | j d ƒ rS| d } n | j d ƒ ro| d } n  | S(   Niÿÿÿÿ(   t   pretty_use_unicodei    u   âŠ—t   |i   u    + i   u    - u   -u    u    i   R*   (   R   t	   _settingst   _use_unicodet&   sympy.printing.pretty.pretty_symbologyR6   R   R	   R   R
   t   extendR+   R   R   t   _printt   parensR,   R-   (   R   R   t   kwargsR/   t   settingst   use_unicodeR6   t   mppt   barR   R   R   R1   R2   R3   (   t   eR.   (    s:   lib/python2.7/site-packages/sympy/physics/vector/dyadic.pyt   renderÆ   sR    		
		
	"(   t   __name__t
   __module__t   baselineRD   (    (   RC   R.   (    s:   lib/python2.7/site-packages/sympy/physics/vector/dyadic.pyR5   Ã   s   (   t   object(   R   R.   R5   (    (   RC   R.   s:   lib/python2.7/site-packages/sympy/physics/vector/dyadic.pyt   _prettyÀ   s    8c         C   st   d d l  m } m } | | ƒ } | d ƒ } x? t |  j ƒ D]. \ } } | | d | d | d | @7} q> W| S(   s¯  The inner product operator for a Vector or Dyadic, and a Dyadic

        This is for: Vector dot Dyadic

        Parameters
        ==========

        other : Vector
            The vector we are dotting with

        Examples
        ========

        >>> from sympy.physics.vector import ReferenceFrame, dot, outer
        >>> N = ReferenceFrame('N')
        >>> d = outer(N.x, N.x)
        >>> dot(N.x, d)
        N.x

        iÿÿÿÿ(   R   R   i    i   i   (   R   R   R   R
   R   (   R   R   R   R   R   R   R   (    (    s:   lib/python2.7/site-packages/sympy/physics/vector/dyadic.pyt   __rand__ý   s    &c         C   s   d |  | S(   Niÿÿÿÿ(    (   R   R   (    (    s:   lib/python2.7/site-packages/sympy/physics/vector/dyadic.pyt   __rsub__  s    c         C   sn   d d l  m } | | ƒ } t d ƒ } x? t |  j ƒ D]. \ } } | | d | | d A| d B7} q8 W| S(   s–  For a cross product in the form: Vector x Dyadic

        Parameters
        ==========

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

        Examples
        ========

        >>> from sympy.physics.vector import ReferenceFrame, outer, cross
        >>> N = ReferenceFrame('N')
        >>> d = outer(N.x, N.x)
        >>> cross(N.y, d)
        - (N.z|N.x)

        iÿÿÿÿ(   R   i    i   i   (   R   R   R   R
   R   (   R   R   R   R   R   R   (    (    s:   lib/python2.7/site-packages/sympy/physics/vector/dyadic.pyt   __rxor__  s    &c   	      C   sò  |  j  } t | ƒ d k r% t d ƒ Sg  } xyt | ƒ D]k\ } } | | d d k r” | j d t | | d ƒ d t | | d ƒ d ƒ q8 | | d d k rä | j d t | | d ƒ d t | | d ƒ d ƒ q8 | | d d k r8 t ƒ  j | | d ƒ } t | | d t ƒ r6d	 | } n  | d d
 k rY| d } d } n d } | j | | d t | | d ƒ d t | | d ƒ d ƒ q8 q8 Wd j	 | ƒ } | j
 d ƒ rÒ| d } n | j
 d ƒ rî| d } n  | S(   s   Printing method. i    i   s    + (R7   i   t   )iÿÿÿÿs    - (s   (%s)R(   s    - s    + s   *(R)   i   R*   (   R   R	   R   R
   R   R   R+   R   R   R-   R,   (	   R   R.   R/   R   R   R   R1   R2   R3   (    (    s:   lib/python2.7/site-packages/sympy/physics/vector/dyadic.pyt   __str__8  s2    	
<<
	Bc         C   s   |  j  | d ƒ S(   s   The subtraction operator. iÿÿÿÿ(   R   (   R   R   (    (    s:   lib/python2.7/site-packages/sympy/physics/vector/dyadic.pyt   __sub__Y  s    c         C   sn   d d l  m } | | ƒ } t d ƒ } x? t |  j ƒ D]. \ } } | | d | d | d | AB7} q8 W| S(   s•  For a cross product in the form: Dyadic x Vector.

        Parameters
        ==========

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

        Examples
        ========

        >>> from sympy.physics.vector import ReferenceFrame, outer, cross
        >>> N = ReferenceFrame('N')
        >>> d = outer(N.x, N.x)
        >>> cross(d, N.y)
        (N.x|N.z)

        iÿÿÿÿ(   R   i    i   i   (   R   R   R   R
   R   (   R   R   R   R   R   R   (    (    s:   lib/python2.7/site-packages/sympy/physics/vector/dyadic.pyt   __xor__]  s    &c         C   s*   d d l  m } | |  d d ƒ} d | S(   s^  
        IPython/Jupyter LaTeX printing

        To change the behavior of this (e.g., pass in some settings to LaTeX),
        use init_printing(). init_printing() will also enable LaTeX printing
        for built in numeric types like ints and container types that contain
        SymPy objects, like lists and dictionaries of expressions.
        iÿÿÿÿ(   t   latext   modet   plains   $\displaystyle %s$(   t   sympy.printing.latexRQ   (   R   RQ   t   s(    (    s:   lib/python2.7/site-packages/sympy/physics/vector/dyadic.pyt   _repr_latex_|  s    	c         C   s    d d l  m } | |  | | ƒ S(   s´  Expresses this Dyadic in alternate frame(s)

        The first frame is the list side expression, the second frame is the
        right side; if Dyadic is in form A.x|B.y, you can express it in two
        different frames. If no second frame is given, the Dyadic is
        expressed in only one frame.

        Calls the global express function

        Parameters
        ==========

        frame1 : ReferenceFrame
            The frame to express the left side of the Dyadic in
        frame2 : ReferenceFrame
            If provided, the frame to express the right side of the Dyadic in

        Examples
        ========

        >>> from sympy.physics.vector import ReferenceFrame, outer, dynamicsymbols
        >>> N = ReferenceFrame('N')
        >>> q = dynamicsymbols('q')
        >>> B = N.orientnew('B', 'Axis', [q, N.z])
        >>> d = outer(N.x, N.x)
        >>> d.express(B, N)
        cos(q)*(B.x|N.x) - sin(q)*(B.y|N.x)

        iÿÿÿÿ(   t   express(   t   sympy.physics.vector.functionsRW   (   R   t   frame1t   frame2RW   (    (    s:   lib/python2.7/site-packages/sympy/physics/vector/dyadic.pyRW   ‘  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
        reference frames.

        Parameters
        ----------
        reference_frame : ReferenceFrame
            The reference frame that the rows and columns of the matrix
            correspond to. If a second reference frame is provided, this
            only corresponds to the rows of the matrix.
        second_reference_frame : ReferenceFrame, optional, default=None
            The reference frame that the columns of the matrix correspond
            to.

        Returns
        -------
        matrix : ImmutableMatrix, shape(3,3)
            The matrix that gives the 2D tensor form.

        Examples
        ========

        >>> from sympy import symbols
        >>> from sympy.physics.vector import ReferenceFrame, Vector
        >>> Vector.simp = True
        >>> from sympy.physics.mechanics import inertia
        >>> Ixx, Iyy, Izz, Ixy, Iyz, Ixz = symbols('Ixx, Iyy, Izz, Ixy, Iyz, Ixz')
        >>> N = ReferenceFrame('N')
        >>> inertia_dyadic = inertia(N, Ixx, Iyy, Izz, Ixy, Iyz, Ixz)
        >>> inertia_dyadic.to_matrix(N)
        Matrix([
        [Ixx, Ixy, Ixz],
        [Ixy, Iyy, Iyz],
        [Ixz, Iyz, Izz]])
        >>> beta = symbols('beta')
        >>> A = N.orientnew('A', 'Axis', (beta, N.x))
        >>> inertia_dyadic.to_matrix(A)
        Matrix([
        [                           Ixx,                                           Ixy*cos(beta) + Ixz*sin(beta),                                           -Ixy*sin(beta) + Ixz*cos(beta)],
        [ Ixy*cos(beta) + Ixz*sin(beta), Iyy*cos(2*beta)/2 + Iyy/2 + Iyz*sin(2*beta) - Izz*cos(2*beta)/2 + Izz/2,                 -Iyy*sin(2*beta)/2 + Iyz*cos(2*beta) + Izz*sin(2*beta)/2],
        [-Ixy*sin(beta) + Ixz*cos(beta),                -Iyy*sin(2*beta)/2 + Iyz*cos(2*beta) + Izz*sin(2*beta)/2, -Iyy*cos(2*beta)/2 + Iyy/2 - Iyz*sin(2*beta) + Izz*cos(2*beta)/2 + Izz/2]])

        i   N(   t   Nonet   Matrixt   dott   reshape(   R   t   reference_framet   second_reference_frameR   t   j(    (    s:   lib/python2.7/site-packages/sympy/physics/vector/dyadic.pyt	   to_matrix²  s    ,	c         K   sP   t  g  |  j D]3 } t | d j |   | d | d f g ƒ ^ q t d ƒ ƒ S(   s(   Calls .doit() on each term in the Dyadici    i   i   (   t   sumR   R   t   doit(   R   t   hintsR   (    (    s:   lib/python2.7/site-packages/sympy/physics/vector/dyadic.pyRd   ä  s    c         C   s   d d l  m } | |  | ƒ S(   sD  Take the time derivative of this Dyadic in a frame.

        This function calls the global time_derivative method

        Parameters
        ==========

        frame : ReferenceFrame
            The frame to take the time derivative in

        Examples
        ========

        >>> from sympy.physics.vector import ReferenceFrame, outer, dynamicsymbols
        >>> N = ReferenceFrame('N')
        >>> q = dynamicsymbols('q')
        >>> B = N.orientnew('B', 'Axis', [q, N.z])
        >>> d = outer(N.x, N.x)
        >>> d.dt(B)
        - q'*(N.y|N.x) - q'*(N.x|N.y)

        iÿÿÿÿ(   t   time_derivative(   RX   Rf   (   R   t   frameRf   (    (    s:   lib/python2.7/site-packages/sympy/physics/vector/dyadic.pyt   dté  s    c         C   sR   t  d ƒ } x? |  j D]4 } | t  | d j ƒ  | d | d f g ƒ 7} q W| S(   s   Returns a simplified Dyadic.i    i   i   (   R   R   t   simplify(   R   t   outR   (    (    s:   lib/python2.7/site-packages/sympy/physics/vector/dyadic.pyRi     s    2c         O   sS   t  g  |  j D]6 } t | d j | | Ž  | d | d f g ƒ ^ q t d ƒ ƒ S(   s5  Substitution on the Dyadic.

        Examples
        ========

        >>> from sympy.physics.vector import ReferenceFrame
        >>> from sympy import Symbol
        >>> N = ReferenceFrame('N')
        >>> s = Symbol('s')
        >>> a = s*(N.x|N.x)
        >>> a.subs({s: 2})
        2*(N.x|N.x)

        i    i   i   (   Rc   R   R   t   subs(   R   R   R>   R   (    (    s:   lib/python2.7/site-packages/sympy/physics/vector/dyadic.pyRk   
  s    c         C   s`   t  | ƒ s t d ƒ ‚ n  t d ƒ } x2 |  j D]' \ } } } | | | ƒ | | B7} q1 W| S(   s/   Apply a function to each component of a Dyadic.s   `f` must be callable.i    (   t   callablet	   TypeErrorR   R   (   R   t   fRj   t   at   bt   c(    (    s:   lib/python2.7/site-packages/sympy/physics/vector/dyadic.pyt	   applyfunc  s    N(%   RE   RF   t   __doc__R   R   R   R    t   __truediv__R$   R   R&   R'   R[   R4   RI   RJ   RK   RL   RN   RO   RP   RV   t   _repr_latex_origt	   _sympystrt
   _sympyreprt   __repr__t   __radd__t   __rmul__RW   Rb   Rd   Rh   Ri   Rk   Rr   R]   t   cross(    (    (    s:   lib/python2.7/site-packages/sympy/physics/vector/dyadic.pyR   	   sD   	&		$					%=			!			!2					
c         C   s"   t  |  t ƒ s t d ƒ ‚ n  |  S(   Ns   A Dyadic must be supplied(   R   R   Rm   (   R   (    (    s:   lib/python2.7/site-packages/sympy/physics/vector/dyadic.pyR   +  s    N(   t   sympy.core.backendR    R   R   R\   t   sympy.core.compatibilityR   t   printingR   R   R   t   __all__RH   R   R   (    (    (    s:   lib/python2.7/site-packages/sympy/physics/vector/dyadic.pyt   <module>   s   	ÿ ÿ $