o
    GZhQ.                     @  s   d dl mZ d dlmZ d dlmZmZ d dl	m
Z
mZ d dlmZ d dlmZ d dlmZ d dlmZ d d	lmZmZmZ d d
lmZ erLd dlmZ G dd deZG dd deeZG dd deeZ G dd deZ!dS )    )annotations)TYPE_CHECKING)simplifytrigsimp)call_highest_priority
_sympifyit)	StdFactKBdiffIntegral)factor)SAddMul)Expr)
BaseVectorc                   @  s  e Zd ZU dZded< eddd Zeddd	 Zed
dd Zeddd Z	e
deeddd Ze
deeddd Zdd Ze
deeddd Zeddd Zd=d#d$Ze jejj7  _eZd%d& Ze jej7  _d'd( Ze jej7  _d)d* Zd+d, Zd-d. Zd/d0 Zd1d2 Zd3d4 Ze jej7  _d>d5d6Zd7d8 Z d9d: Z!e! je"j7  _d;d< Z#d S )?BasisDependentz
    Super class containing functionality common to vectors and
    dyadics.
    Named so because the representation of these quantities in
    sympy.vector is dependent on the basis they are expressed in.
    BasisDependentZerozero__radd__c                 C     |  | |S N	_add_funcselfother r   J/var/www/auris/lib/python3.10/site-packages/sympy/vector/basisdependent.py__add__      zBasisDependent.__add__r    c                 C     |  || S r   r   r   r   r   r   r      r!   zBasisDependent.__radd____rsub__c                 C  s   |  | | S r   r   r   r   r   r   __sub__#      zBasisDependent.__sub__r$   c                 C  s   |  ||  S r   r   r   r   r   r   r#   '   r%   zBasisDependent.__rsub__r   __rmul__c                 C  r   r   	_mul_funcr   r   r   r   __mul__+      zBasisDependent.__mul__r)   c                 C  r"   r   r'   r   r   r   r   r&   0   r*   zBasisDependent.__rmul__c                 C  s   |  tj| S r   )r(   r   ZNegativeOner   r   r   r   __neg__5   s   zBasisDependent.__neg____rtruediv__c                 C  
   |  |S r   )Z_div_helperr   r   r   r   __truediv__8   s   
zBasisDependent.__truediv__r/   c                 C  s   t dS )NzInvalid divisor for division)	TypeErrorr   r   r   r   r-   =   s   zBasisDependent.__rtruediv__   Nd   Fc                 C  sJ   ||||||d}| j }	| j D ]\}
}|	|j|fi ||
 7 }	q|	S )z
        Implements the SymPy evalf routine for this quantity.

        evalf's documentation
        =====================

        )subsmaxnchopstrictquadverbose)r   
componentsitemsevalf)r   nr3   r4   r5   r6   r7   r8   optionsZveckvr   r   r   r;   A   s   zBasisDependent.evalfc                   "    fdd| j  D }| j| S )z
        Implements the SymPy simplify routine for this quantity.

        simplify's documentation
        ========================

        c                   $   g | ]\}}t |fi  | qS r   )simp.0r>   r?   kwargsr   r   
<listcomp>\       z+BasisDependent.simplify.<locals>.<listcomp>r9   r:   r   )r   rF   Zsimp_componentsr   rE   r   r   T      

zBasisDependent.simplifyc                   r@   )z
        Implements the SymPy trigsimp routine, for this quantity.

        trigsimp's documentation
        ========================

        c                   rA   r   )tsimprC   optsr   r   rG   j   rH   z+BasisDependent.trigsimp.<locals>.<listcomp>rI   )r   rM   Ztrig_componentsr   rL   r   r   b   rJ   zBasisDependent.trigsimpc                 K     | j di |S Nr   )r   )r   rF   r   r   r   _eval_simplifyp      zBasisDependent._eval_simplifyc                 K  rN   rO   )r   )r   rM   r   r   r   _eval_trigsimps   rQ   zBasisDependent._eval_trigsimpc                 C  r.   r   r	   )r   Zwrtr   r   r   _eval_derivativev   s   
zBasisDependent._eval_derivativec                   $    fdd| j  D }| j| S )Nc                   s*   g | ]\}}t |gR i  | qS r   r   rC   assumptionssymbolsr   r   rG   z       z1BasisDependent._eval_Integral.<locals>.<listcomp>rI   )r   rW   rV   Zintegral_componentsr   rU   r   _eval_Integraly   s   
zBasisDependent._eval_Integralc                 C  s
   | t jfS )z
        Returns the expression as a tuple wrt the following
        transformation -

        expression -> a/b -> a, b

        r   Oner+   r   r   r   as_numer_denom~   s   
zBasisDependent.as_numer_denomc                   rT   )z
        Implements the SymPy factor routine, on the scalar parts
        of a basis-dependent expression.

        factor's documentation
        ========================

        c                   *   g | ]\}}t |g R i | qS r   )fctrrC   argsrF   r   r   rG      rX   z)BasisDependent.factor.<locals>.<listcomp>rI   )r   r`   rF   Zfctr_componentsr   r_   r   r      s   	
zBasisDependent.factorc                 C  s
   t j| fS )z1Efficiently extract the coefficient of a product.rZ   )r   Zrationalr   r   r   as_coeff_Mul   s   
zBasisDependent.as_coeff_Mulc                   s   dt  fdd jD fS )z3Efficiently extract the coefficient of a summation.r   c                 3  s    | ]
}| j |  V  qd S r   r9   rD   xr+   r   r   	<genexpr>   s    z.BasisDependent.as_coeff_add.<locals>.<genexpr>)tupler9   )r   depsr   r+   r   as_coeff_add   s   zBasisDependent.as_coeff_addc                   s@    D ]}t |trtdq fdd| j D }| j| S )z
        Implements the SymPy diff routine, for vectors.

        diff's documentation
        ========================

        zInvalid arg for differentiationc                   r]   r   )dfrC   r_   r   r   rG      rX   z'BasisDependent.diff.<locals>.<listcomp>)
isinstancer   r0   r9   r:   r   )r   r`   rF   rd   Zdiff_componentsr   r_   r   r
      s   

zBasisDependent.diffc                   s     fddj D }j| S )z(Calls .doit() on each term in the Dyadicc                   s&   g | ]}j | jd i  | qS )r   )r9   doitrc   hintsr   r   r   rG      s    z'BasisDependent.doit.<locals>.<listcomp>)r9   r   )r   rm   Zdoit_componentsr   rl   r   rk      s   
zBasisDependent.doit)r1   Nr2   FFNF)F)$__name__
__module____qualname____doc____annotations__r   r    r   r$   r#   r   NotImplementedr)   r&   r,   r/   r-   r;   r   r<   r   rB   r   rK   rP   rR   rS   rY   r\   r   r^   ra   rh   r
   ri   rk   r   r   r   r   r      sT   
 







r   c                      s    e Zd ZdZ fddZ  ZS )BasisDependentAddzt
    Denotes sum of basis dependent quantities such that they cannot
    be expressed as base or Mul instances.
    c           	        s8  i  |D ]A}t || js,t |tr| j|j }nt |tr$| j|j }ntt|d || j	kr2q|j
D ]} |d|j
|   |< q5qt  }|D ]} | dkrY |= qNt dkrc| j	S  fdd D }t j| g|R i |}t |tr| j|j S ddi}t||_ |_t  d j|_|S )Nz  cannot be interpreted correctlyr   c                   s   g | ]}| |  qS r   r   rc   rb   r   r   rG      s    z-BasisDependentAdd.__new__.<locals>.<listcomp>commutativeT)rj   
_expr_typer   r(   r`   r   r   r0   strr   r9   getlistkeyslensuper__new__r   _assumptions_components_sys)	clsr`   r=   argrd   tempnewargsobjrV   	__class__rb   r   r}      s>   





zBasisDependentAdd.__new__)rn   ro   rp   rq   r}   __classcell__r   r   r   r   rt      s    rt   c                      s<   e Zd ZdZdd Zdd Ze fddZdd	 Z  Z	S )
BasisDependentMulzJ
    Denotes product of base- basis dependent quantity with a scalar.
    c                 O  s   | j |i |}|S r   )_new)r   r`   r=   r   r   r   r   r}      s   zBasisDependentMul.__new__c                 G  s   t | | S r   )type)r   r`   r   r   r   _new_rawargs   s   zBasisDependentMul._new_rawargsc                   s  ddl m}m}m}m} d}tjd}g }	|D ]M}
t|
 jr&|d7 }d}q|
tj	kr.d}qt|
 j
 jfrD|d7 }|
j}|
j9 qt|
 jrQ|d7 }|
}qt|
||||fr`|	|
 q|
9 q|dkrmtd|dkrxt|i |S |r} jS t| jr fdd|jD } j| S t j |jg|	R i |}t|tr j|j S |j|_|_d	di}t||_|ji|_|jj|_|S )
Nr   )CrossDotCurlGradientF   TzInvalid multiplicationc                   s   g | ]}  |qS r   r'   rc   r   Zmeasure_numberr   r   rG     s    z*BasisDependentMul._new.<locals>.<listcomp>ru   )Zsympy.vectorr   r   r   r   r   r[   rj   
_zero_funcZeroZ
_base_funcr(   _base_instance_measure_numberr   append
ValueErrorr   r   r`   r|   r}   r   r   r~   r   r   )r   r`   r=   r   r   r   r   countZzeroflag
extra_argsr   exprr   r   rV   r   r   r   r      s`   






zBasisDependentMul._newc                 C  sD   | | j}d|v sd|v sd|v rd| d }|d | | j S )N(-+)*)Z_printr   r   )r   printerZmeasure_strr   r   r   	_sympystr1  s
   zBasisDependentMul._sympystr)
rn   ro   rp   rq   r}   r   classmethodr   r   r   r   r   r   r   r      s    :r   c                      s   e Zd ZU dZi Zded< ded<  fddZdd	 Zed
dd Z	e	Z
eddd Zeddd Zeddd Zeddd Zdd Zdd Zdd Z  ZS )r   z:
    Class to denote a zero basis dependent instance.
    zdict['BaseVector', Expr]r9   rw   Z_latex_formc                   s    t  | }tj| f |_|S r   )r|   r}   r   r   __hash___hash)r   r   r   r   r   r}   @  s   zBasisDependentZero.__new__c                 C  s   | j S r   )r   r+   r   r   r   r   G  s   zBasisDependentZero.__hash____req__c                 C  s   t || jS r   )rj   r   r   r   r   r   __eq__J  r!   zBasisDependentZero.__eq__r   c                 C     t || jr|S tdNz#Invalid argument types for additionrj   rv   r0   r   r   r   r   r    P     zBasisDependentZero.__add__r    c                 C  r   r   r   r   r   r   r   r   W  r   zBasisDependentZero.__radd__r#   c                 C  s   t || jr	| S tdNz&Invalid argument types for subtractionr   r   r   r   r   r$   ^  s   zBasisDependentZero.__sub__r$   c                 C  r   r   r   r   r   r   r   r#   e  r   zBasisDependentZero.__rsub__c                 C     | S r   r   r+   r   r   r   r,   l     zBasisDependentZero.__neg__c                 C  r   )z@
        Returns the normalized version of this vector.
        r   r+   r   r   r   	normalizeo  s   zBasisDependentZero.normalizec                 C  s   dS )N0r   )r   r   r   r   r   r   u  r   zBasisDependentZero._sympystr)rn   ro   rp   rq   r9   rr   r}   r   r   r   r   r    r   r$   r#   r,   r   r   r   r   r   r   r   r   9  s(   
 




r   N)"
__future__r   typingr   Zsympy.simplifyr   rB   r   rK   Zsympy.core.decoratorsr   r   Zsympy.core.assumptionsr   Zsympy.core.functionr
   ri   Zsympy.integrals.integralsr   Zsympy.polys.polytoolsr   r^   Z
sympy.corer   r   r   Zsympy.core.exprr   Zsympy.vector.vectorr   r   rt   r   r   r   r   r   r   <module>   s"     '0R