U
    ZÊ¹j1%  ã                   @   sî   d dl Z d dl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mZ d dlmZ d dlmZ d dlmZ d	d
„ Zdd„ ZG dd„ deƒZG dd„ deƒZG dd„ deƒZddd„Zddd„Zd dd„ZG dd„ deƒZdd„ ZdS )!é    N)ÚExpr)ÚsympifyÚSÚpreorder_traversal)Ú
CoordSys3D)ÚVectorÚ	VectorMulÚ	VectorAddÚCrossÚDot)Ú
Derivative)ÚAdd)ÚMulc                 C   s<   t | ƒ}tƒ }|D ] }t|tƒr| |¡ | ¡  qt|ƒS ©N)r   ÚsetÚ
isinstancer   ÚaddÚskipÚ	frozenset)ÚexprÚgÚretÚi© r   úU/var/www/html/bwave/python/venv/lib/python3.8/site-packages/sympy/vector/operators.pyÚ_get_coord_systems   s    


r   c                 C   s:   t  dd„ ¡}| jD ]}|t|ƒ  |9  < qt| ¡ ƒS )Nc                   S   s   t jS r   )r   ZOner   r   r   r   Ú<lambda>   ó    z._split_mul_args_wrt_coordsys.<locals>.<lambda>)ÚcollectionsÚdefaultdictÚargsr   ÚlistÚvalues)r   Údr   r   r   r   Ú_split_mul_args_wrt_coordsys   s    
r$   c                   @   s    e Zd ZdZdd„ Zdd„ ZdS )ÚGradientzß
    Represents unevaluated Gradient.

    Examples
    ========

    >>> from sympy.vector import CoordSys3D, Gradient
    >>> R = CoordSys3D('R')
    >>> s = R.x*R.y*R.z
    >>> Gradient(s)
    Gradient(R.x*R.y*R.z)

    c                 C   s   t |ƒ}t | |¡}||_|S r   ©r   r   Ú__new__Ú_expr©Úclsr   Úobjr   r   r   r'   +   s    zGradient.__new__c                 K   s   t | jdd�S ©NT©Údoit)Úgradientr(   ©ÚselfÚhintsr   r   r   r.   1   s    zGradient.doitN©Ú__name__Ú
__module__Ú__qualname__Ú__doc__r'   r.   r   r   r   r   r%      s   r%   c                   @   s    e Zd ZdZdd„ Zdd„ ZdS )Ú
Divergencea  
    Represents unevaluated Divergence.

    Examples
    ========

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

    c                 C   s   t |ƒ}t | |¡}||_|S r   r&   r)   r   r   r   r'   D   s    zDivergence.__new__c                 K   s   t | jdd�S r,   )Ú
divergencer(   r0   r   r   r   r.   J   s    zDivergence.doitNr3   r   r   r   r   r8   5   s   r8   c                   @   s    e Zd ZdZdd„ Zdd„ ZdS )ÚCurla  
    Represents unevaluated Curl.

    Examples
    ========

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

    c                 C   s   t |ƒ}t | |¡}||_|S r   r&   r)   r   r   r   r'   ]   s    zCurl.__new__c                 K   s   t | jdd�S r,   )Úcurlr(   r0   r   r   r   r.   c   s    z	Curl.doitNr3   r   r   r   r   r:   N   s   r:   Tc                    s$  t | ƒ}t|ƒdkrtjS t|ƒdk�rtt|ƒƒ}| ¡ \}}}| ¡ \}}}| ¡ \}	}
}|  	|¡}|  	|¡}|  	|¡}tj}|t
|| |ƒt
||
 |ƒ | |
|  7 }|t
||	 |ƒt
|| |ƒ | |	|  7 }|t
||
 |ƒt
||	 |ƒ | |
|	  7 }ˆ�r| ¡ S |S t| ttfƒ�r�ddlm‰ z&tt|ƒƒ‰ ‡ ‡fdd„| jD ƒ}W n tk
�rv   | j}Y nX t ‡fdd„|D ƒ¡S t| ttfƒ�rþdd„ | jD ƒd }t d	d„ | jD ƒ¡}tt|ƒ|ƒ ¡ |t|ˆd
�  }ˆ�rú| ¡ S |S t| tttfƒ�rt| ƒS t| ƒ‚dS )ao  
    Returns the curl of a vector field computed wrt the base scalars
    of the given coordinate system.

    Parameters
    ==========

    vect : Vector
        The vector operand

    doit : bool
        If True, the result is returned after calling .doit() on
        each component. Else, the returned expression contains
        Derivative instances

    Examples
    ========

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

    r   é   ©Úexpressc                    s   g | ]}ˆ|ˆ d d�‘qS )T©Ú	variablesr   ©Ú.0r   )Úcsr>   r   r   Ú
<listcomp>¡   s     zcurl.<locals>.<listcomp>c                 3   s   | ]}t |ˆ d �V  qdS ©r-   N)r;   rA   r-   r   r   Ú	<genexpr>¤   s     zcurl.<locals>.<genexpr>c                 S   s    g | ]}t |tttfƒr|‘qS r   ©r   r   r
   r%   rA   r   r   r   rD   ¦   s      c                 s   s"   | ]}t |tttfƒs|V  qd S r   rG   rA   r   r   r   rF   §   s      r-   N)r   Úlenr   ÚzeroÚnextÚiterÚbase_vectorsÚbase_scalarsÚlame_coefficientsÚdotr   r.   r   r   r	   Zsympy.vectorr>   r    Ú
ValueErrorÚfromiterr   r   r
   r/   r;   r:   r%   )Úvectr.   Ú	coord_sysr   ÚjÚkÚxÚyÚzÚh1Úh2Úh3ZvectxZvectyZvectzZoutvecr    ÚvectorÚscalarÚresr   )rC   r.   r>   r   r;   g   sl    


ÿÿÿÿÿÿÿÿÿ"r;   c                    sª  t | ƒ}t|ƒdkrtjS t|ƒdkrðt| tttfƒr>t| ƒS t	t
|ƒƒ}| ¡ \}}}| ¡ \}}}| ¡ \}	}
}t|  |¡||
|ƒ|	|
 |  }t|  |¡|||	ƒ|	|
 |  }t|  |¡||	|
ƒ|	|
 |  }|| | }ˆ rì| ¡ S |S t| ttfƒ�rt ‡ fdd„| jD ƒ¡S t| ttfƒ�r„dd„ | jD ƒd }t dd„ | jD ƒ¡}t|t|ƒƒ|t|ˆ d�  }ˆ �r€| ¡ S |S t| tttfƒ�ržt| ƒS t| ƒ‚d	S )
a  
    Returns the divergence of a vector field computed wrt the base
    scalars of the given coordinate system.

    Parameters
    ==========

    vector : Vector
        The vector operand

    doit : bool
        If True, the result is returned after calling .doit() on
        each component. Else, the returned expression contains
        Derivative instances

    Examples
    ========

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

    >>> divergence(v1)
    R.x*R.y + R.x*R.z + R.y*R.z
    >>> v2 = 2*R.y*R.z*R.j
    >>> divergence(v2)
    2*R.z

    r   r<   c                 3   s   | ]}t |ˆ d �V  qdS rE   )r9   rA   r-   r   r   rF   ç   s     zdivergence.<locals>.<genexpr>c                 S   s    g | ]}t |tttfƒr|‘qS r   rG   rA   r   r   r   rD   é   s      zdivergence.<locals>.<listcomp>c                 s   s"   | ]}t |tttfƒs|V  qd S r   rG   rA   r   r   r   rF   ê   s      r-   N)r   rH   r   ÚZeror   r
   r:   r%   r8   rJ   rK   rL   rM   rN   Ú_diff_conditionalrO   r.   r   r	   rQ   r    r   r   r   r/   r9   )rR   r.   rS   r   rT   rU   rV   rW   rX   rY   rZ   r[   ÚvxÚvyÚvzr^   r\   r]   r   r-   r   r9   ²   sF    
ÿ
ÿ
ÿr9   c                    s  t ˆ ƒ}t|ƒdkrtjS t|ƒdkr¾tt|ƒƒ}| ¡ \}}}| ¡ \}}}| ¡ \}	}
}t	ˆ |	ƒ| }t	ˆ |
ƒ| }t	ˆ |ƒ| }|r¦|| ||  ||   
¡ S || ||  ||  S tˆ ttfƒrât dd„ ˆ jD ƒ¡S tˆ ttfƒ�rtˆ ƒ}t ‡ fdd„|D ƒ¡S tˆ ƒS dS )a³  
    Returns the vector gradient of a scalar field computed wrt the
    base scalars of the given coordinate system.

    Parameters
    ==========

    scalar_field : SymPy Expr
        The scalar field to compute the gradient of

    doit : bool
        If True, the result is returned after calling .doit() on
        each component. Else, the returned expression contains
        Derivative instances

    Examples
    ========

    >>> from sympy.vector import CoordSys3D, gradient
    >>> R = CoordSys3D('R')
    >>> s1 = R.x*R.y*R.z
    >>> gradient(s1)
    R.y*R.z*R.i + R.x*R.z*R.j + R.x*R.y*R.k
    >>> s2 = 5*R.x**2*R.z
    >>> gradient(s2)
    10*R.x*R.z*R.i + 5*R.x**2*R.k

    r   r<   c                 s   s   | ]}t |ƒV  qd S r   ©r/   rA   r   r   r   rF   $  s     zgradient.<locals>.<genexpr>c                 3   s   | ]}ˆ | t |ƒ V  qd S r   rd   rA   ©Úscalar_fieldr   r   rF   '  s     N)r   rH   r   rI   rJ   rK   rN   rL   rM   r   r.   r   r   r	   rQ   r    r   r   r$   r%   )rf   r.   rS   rY   rZ   r[   r   rT   rU   rV   rW   rX   ra   rb   rc   Úsr   re   r   r/   õ   s(    r/   c                   @   s    e Zd ZdZdd„ Zdd„ ZdS )Ú	Laplacianzù
    Represents unevaluated Laplacian.

    Examples
    ========

    >>> from sympy.vector import CoordSys3D, Laplacian
    >>> R = CoordSys3D('R')
    >>> v = 3*R.x**3*R.y**2*R.z**3
    >>> Laplacian(v)
    Laplacian(3*R.x**3*R.y**2*R.z**3)

    c                 C   s   t |ƒ}t | |¡}||_|S r   r&   r)   r   r   r   r'   :  s    zLaplacian.__new__c                 K   s   ddl m} || jƒS )Nr   )Ú	laplacian)Úsympy.vector.functionsri   r(   )r1   r2   ri   r   r   r   r.   @  s    zLaplacian.doitNr3   r   r   r   r   rh   +  s   rh   c                 C   s<   ddl m} || |jdd�}|| | }|r6t||ƒS tjS )z¼
    First re-expresses expr in the system that base_scalar belongs to.
    If base_scalar appears in the re-expressed form, differentiates
    it wrt base_scalar.
    Else, returns 0
    r   r=   Tr?   )rj   r>   Úsystemr   r   r_   )r   Zbase_scalarZcoeff_1Zcoeff_2r>   Znew_exprÚargr   r   r   r`   E  s    r`   )T)T)T)r   Zsympy.core.exprr   Z
sympy.corer   r   r   Zsympy.vector.coordsysrectr   Zsympy.vector.vectorr   r   r	   r
   r   Zsympy.core.functionr   Zsympy.core.addr   Zsympy.core.mulr   r   r$   r%   r8   r:   r;   r9   r/   rh   r`   r   r   r   r   Ú<module>   s"   

K
C
6