o
    oh1%                     @   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   j/var/www/html/construction_image-detection-poc/venv/lib/python3.10/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   Oner   r   r   r   <lambda>   s    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                   @       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      t |}t| |}||_|S r   r   r   __new___exprclsr   objr   r   r   r)   +      zGradient.__new__c                 K      t | jddS NTdoit)gradientr*   selfhintsr   r   r   r2   1      zGradient.doitN__name__
__module____qualname____doc__r)   r2   r   r   r   r   r&          r&   c                   @   r%   )
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   r'   r   r(   r+   r   r   r   r)   D   r.   zDivergence.__new__c                 K   r/   r0   )
divergencer*   r4   r   r   r   r2   J   r7   zDivergence.doitNr8   r   r   r   r   r>   5   r=   r>   c                   @   r%   )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   r'   r   r(   r+   r   r   r   r)   ]   r.   zCurl.__new__c                 K   r/   r0   )curlr*   r4   r   r   r   r2   c   r7   z	Curl.doitNr8   r   r   r   r   r@   N   r=   r@   Tc                    s  t | }t|dkrtjS t|dkrtt|}| \}}}| \}}}| \}	}
}| 	|}| 	|}| 	|}tj}|t
|| |t
||
 | | |
|  7 }|t
||	 |t
|| | | |	|  7 }|t
||
 |t
||	 | | |
|	  7 }r| S |S t| ttfrddlm ztt|  fdd| jD }W n ty   | j}Y nw tfdd|D S t| ttfrd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| )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   )csrD   r   r   
<listcomp>   s    zcurl.<locals>.<listcomp>c                 3       | ]	}t | d V  qdS r1   N)rA   rG   r1   r   r   	<genexpr>       zcurl.<locals>.<genexpr>c                 S       g | ]}t |tttfr|qS r   r   r   r
   r&   rG   r   r   r   rJ           c                 s   $    | ]}t |tttfs|V  qd S r   rP   rG   r   r   r   rM         " r1   )r   lenr   zeronextiterbase_vectorsbase_scalarslame_coefficientsdotr   r2   r   r   r	   sympy.vectorrD   r    
ValueErrorfromiterr   r   r
   r3   rA   r@   r&   )vectr2   	coord_sysr   jkxyzh1h2h3vectxvectyvectzoutvecr    vectorscalarresr   )rI   r2   rD   r   rA   g   sn   



"rA   c                    s  t | }t|dkrtjS t|dkrxt| tttfrt| S t	t
|}| \}}}| \}}}| \}	}
}t| |||
||	|
 |  }t| ||||	|	|
 |  }t| |||	|
|	|
 |  }|| | } rv| S |S t| ttfrt fdd| jD S t| ttfrdd | jD d }tdd | jD }t|t||t| d  } r| S |S t| tttfrt| S t| )	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   rB   c                 3   rK   rL   )r?   rG   r1   r   r   rM      rN   zdivergence.<locals>.<genexpr>c                 S   rO   r   rP   rG   r   r   r   rJ      rQ   zdivergence.<locals>.<listcomp>c                 s   rR   r   rP   rG   r   r   r   rM      rS   r1   )r   rT   r   Zeror   r
   r@   r&   r>   rV   rW   rX   rY   rZ   _diff_conditionalr[   r2   r   r	   r^   r    r   r   r   r3   r?   )r_   r2   r`   r   ra   rb   rc   rd   re   rf   rg   rh   vxvyvzro   rm   rn   r   r1   r   r?      sF   


r?   c                    s  t  }t|dkrtjS t|dkr_tt|}| \}}}| \}}}| \}	}
}t	 |	| }t	 |
| }t	 || }|rS|| ||  ||  
 S || ||  ||  S t ttfrqtdd  jD S t ttfrt }t fdd|D S t 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   rB   c                 s   s    | ]}t |V  qd S r   r3   rG   r   r   r   rM   $  s    zgradient.<locals>.<genexpr>c                 3   s     | ]} | t | V  qd S r   ru   rG   scalar_fieldr   r   rM   '  s    )r   rT   r   rU   rV   rW   rZ   rX   rY   r   r2   r   r   r	   r^   r    r   r   r$   r&   )rw   r2   r`   rf   rg   rh   r   ra   rb   rc   rd   re   rr   rs   rt   sr   rv   r   r3      s(   r3   c                   @   r%   )	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   r'   r   r(   r+   r   r   r   r)   :  r.   zLaplacian.__new__c                 K   s   ddl m} || jS )Nr   )	laplacian)sympy.vector.functionsrz   r*   )r5   r6   rz   r   r   r   r2   @  s   
zLaplacian.doitNr8   r   r   r   r   ry   +  r=   ry   c                 C   s<   ddl m} || |jdd}|| | }|rt||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   rC   TrE   )r{   rD   systemr   r   rp   )r   base_scalarcoeff_1coeff_2rD   new_exprargr   r   r   rq   E  s   rq   )T)r   sympy.core.exprr   
sympy.corer   r   r   sympy.vector.coordsysrectr   sympy.vector.vectorr   r   r	   r
   r   sympy.core.functionr   sympy.core.addr   sympy.core.mulr   r   r$   r&   r>   r@   rA   r?   r3   ry   rq   r   r   r   r   <module>   s$    


K
C6