o
    §ƒðjK  ã                   @   s¬   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 ddlmZ G d	d
„ d
eƒZG dd„ deƒZG dd„ deƒZG dd„ deƒZG dd„ deƒZdS )é    )ÚaskÚQ)ÚEq)ÚS)Ú_sympify)ÚKroneckerDelta©ÚNonInvertibleMatrixErroré   )Ú
MatrixExprc                       sx   e Zd ZdZdZ‡ fdd„Zedd„ ƒZdd„ Zd	d
„ Z	dd„ Z
dd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Z‡  ZS )Ú
ZeroMatrixzâThe Matrix Zero 0 - additive identity

    Examples
    ========

    >>> from sympy import MatrixSymbol, ZeroMatrix
    >>> A = MatrixSymbol('A', 3, 5)
    >>> Z = ZeroMatrix(3, 5)
    >>> A + Z
    A
    >>> Z*A.T
    0
    Tc                    s6   t |ƒt |ƒ}}|  |¡ |  |¡ tƒ  | ||¡S ©N©r   Ú
_check_dimÚsuperÚ__new__)ÚclsÚmÚn©Ú	__class__© ú¤/tmp/claude-1000/-var-www-html-academy/3f42efd1-c2b7-4d08-9b05-30d86bb35479/scratchpad/piper/venv/lib/python3.10/site-packages/sympy/matrices/expressions/special.pyr      s   

zZeroMatrix.__new__c                 C   s   | j d | j d fS ©Nr   r
   ©Úargs©Úselfr   r   r   Úshape!   ó   zZeroMatrix.shapec                 C   s   |dk dkr
t dƒ‚| S )Nr   TúMatrix det == 0; not invertibler   ©r   Úexpr   r   r   Ú_eval_power%   s   zZeroMatrix._eval_powerc                 C   ó   t | j| jƒS r   ©r   ÚcolsÚrowsr   r   r   r   Ú_eval_transpose+   ó   zZeroMatrix._eval_transposec                 C   r$   r   r%   r   r   r   r   Ú_eval_adjoint.   r)   zZeroMatrix._eval_adjointc                 C   ó   t jS r   ©r   ÚZeror   r   r   r   Ú_eval_trace1   ó   zZeroMatrix._eval_tracec                 C   r+   r   r,   r   r   r   r   Ú_eval_determinant4   r/   zZeroMatrix._eval_determinantc                 C   ó   t dƒ‚)Nú Matrix det == 0; not invertible.r   r   r   r   r   Ú_eval_inverse7   ó   zZeroMatrix._eval_inversec                 C   s   | | fS r   r   r   r   r   r   Ú_eval_as_real_imag:   r4   zZeroMatrix._eval_as_real_imagc                 C   ó   | S r   r   r   r   r   r   Ú_eval_conjugate=   ó   zZeroMatrix._eval_conjugatec                 K   r+   r   r,   ©r   ÚiÚjÚkwargsr   r   r   Ú_entry@   r/   zZeroMatrix._entry)Ú__name__Ú
__module__Ú__qualname__Ú__doc__Úis_ZeroMatrixr   Úpropertyr   r#   r(   r*   r.   r0   r3   r5   r7   r=   Ú__classcell__r   r   r   r   r   
   s    
r   c                       s`   e Zd ZdZ‡ fdd„Zedd„ ƒZedd„ ƒZedd	„ ƒZd
d„ Z	dd„ Z
‡ fdd„Z‡  ZS )ÚGenericZeroMatrixz�
    A zero matrix without a specified shape

    This exists primarily so MatAdd() with no arguments can return something
    meaningful.
    c                    ó   t t| ƒ | ¡S r   )r   r   r   ©r   r   r   r   r   K   ó   zGenericZeroMatrix.__new__c                 C   r1   ©Nz1GenericZeroMatrix does not have a specified shape©Ú	TypeErrorr   r   r   r   r'   P   ó   zGenericZeroMatrix.rowsc                 C   r1   rI   rJ   r   r   r   r   r&   T   rL   zGenericZeroMatrix.colsc                 C   r1   rI   rJ   r   r   r   r   r   X   rL   zGenericZeroMatrix.shapec                 C   ó
   t |tƒS r   )Ú
isinstancerE   ©r   Úotherr   r   r   Ú__eq__]   ó   
zGenericZeroMatrix.__eq__c                 C   ó
   | |k S r   r   rO   r   r   r   Ú__ne__`   rR   zGenericZeroMatrix.__ne__c                    ó
   t ƒ  ¡ S r   ©r   Ú__hash__r   r   r   r   rW   c   rR   zGenericZeroMatrix.__hash__)r>   r?   r@   rA   r   rC   r'   r&   r   rQ   rT   rW   rD   r   r   r   r   rE   D   s    


rE   c                       sœ   e Zd ZdZdZ‡ fdd„Zedd„ ƒZedd„ ƒZed	d
„ ƒZ	edd„ ƒZ
dd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Z‡  ZS )ÚIdentityzÏThe Matrix Identity I - multiplicative identity

    Examples
    ========

    >>> from sympy import Identity, MatrixSymbol
    >>> A = MatrixSymbol('A', 3, 5)
    >>> I = Identity(3)
    >>> I*A
    A
    Tc                    s    t |ƒ}|  |¡ tƒ  | |¡S r   r   )r   r   r   r   r   r   w   s   
zIdentity.__new__c                 C   ó
   | j d S ©Nr   r   r   r   r   r   r'   }   ó   
zIdentity.rowsc                 C   rY   rZ   r   r   r   r   r   r&   �   r[   zIdentity.colsc                 C   s   | j d | j d fS rZ   r   r   r   r   r   r   …   r   zIdentity.shapec                 C   ó   dS ©NTr   r   r   r   r   Ú	is_square‰   ó   zIdentity.is_squarec                 C   r6   r   r   r   r   r   r   r(   �   r8   zIdentity._eval_transposec                 C   ó   | j S r   )r'   r   r   r   r   r.   �   r/   zIdentity._eval_tracec                 C   r6   r   r   r   r   r   r   r3   “   r8   zIdentity._eval_inversec                 C   ó   | t | jŽ fS r   ©r   r   r   r   r   r   r5   –   r)   zIdentity._eval_as_real_imagc                 C   r6   r   r   r   r   r   r   r7   ™   r8   zIdentity._eval_conjugatec                 C   r6   r   r   r   r   r   r   r*   œ   r8   zIdentity._eval_adjointc                 K   s@   t ||ƒ}|tju rtjS |tju rtjS t||d| jd fƒS r   )r   r   ÚtrueÚOneÚfalser-   r   r&   )r   r:   r;   r<   Úeqr   r   r   r=   Ÿ   s   


zIdentity._entryc                 C   r+   r   ©r   rd   r   r   r   r   r0   §   r/   zIdentity._eval_determinantc                 C   r6   r   r   r!   r   r   r   r#   ª   r8   zIdentity._eval_power)r>   r?   r@   rA   Úis_Identityr   rC   r'   r&   r   r^   r(   r.   r3   r5   r7   r*   r=   r0   r#   rD   r   r   r   r   rX   h   s*    



rX   c                       sl   e Zd ZdZ‡ fdd„Zedd„ ƒZedd„ ƒZedd	„ ƒZed
d„ ƒZ	dd„ Z
dd„ Z‡ fdd„Z‡  ZS )ÚGenericIdentityz”
    An identity matrix without a specified shape

    This exists primarily so MatMul() with no arguments can return something
    meaningful.
    c                    rF   r   )r   rX   r   rG   r   r   r   r   µ   rH   zGenericIdentity.__new__c                 C   r1   ©Nz/GenericIdentity does not have a specified shaperJ   r   r   r   r   r'   º   rL   zGenericIdentity.rowsc                 C   r1   rj   rJ   r   r   r   r   r&   ¾   rL   zGenericIdentity.colsc                 C   r1   rj   rJ   r   r   r   r   r   Â   rL   zGenericIdentity.shapec                 C   r\   r]   r   r   r   r   r   r^   Æ   r_   zGenericIdentity.is_squarec                 C   rM   r   )rN   ri   rO   r   r   r   rQ   Ë   rR   zGenericIdentity.__eq__c                 C   rS   r   r   rO   r   r   r   rT   Î   rR   zGenericIdentity.__ne__c                    rU   r   rV   r   r   r   r   rW   Ñ   rR   zGenericIdentity.__hash__)r>   r?   r@   rA   r   rC   r'   r&   r   r^   rQ   rT   rW   rD   r   r   r   r   ri   ®   s    



ri   c                       sž   e Zd ZdZd!‡ fdd„	Zedd„ ƒZedd„ ƒZd	d
„ Zdd„ Z	‡ fdd„Z
dd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd „ Z‡  ZS )"Ú	OneMatrixz,
    Matrix whose all entries are ones.
    Fc                    sb   t |ƒt |ƒ}}|  |¡ |  |¡ |r't|dƒt|dƒ@ }|dkr'tdƒS tƒ  | ||¡}|S )Nr
   T)r   r   r   rX   r   r   )r   r   r   ÚevaluateÚ	conditionÚobjr   r   r   r   Ù   s   

zOneMatrix.__new__c                 C   r`   r   )Ú_argsr   r   r   r   r   æ   s   zOneMatrix.shapec                 C   s   |   ¡ dkS r]   )Ú_is_1x1r   r   r   r   rh   ê   s   zOneMatrix.is_Identityc                 C   s   ddl m} |j| jŽ S )Nr   )ÚImmutableDenseMatrix)Úsympy.matrices.immutablerq   Úonesr   )r   rq   r   r   r   Úas_explicitî   s   zOneMatrix.as_explicitc                    s4   | j }ˆ  dd¡r‡ fdd„|D ƒ}| j|ddiŽS )NÚdeepTc                    s   g | ]
}|j d i ˆ ¤Ž‘qS )r   )Údoit)Ú.0Úa©Úhintsr   r   Ú
<listcomp>õ   s    z"OneMatrix.doit.<locals>.<listcomp>rl   )r   ÚgetÚfunc)r   rz   r   r   ry   r   rv   ò   s   zOneMatrix.doitc                    s^   |   ¡ dkr
tdƒS |dk dkrtdƒ‚tt |¡ƒr)| jd |d  t| jŽ  S tƒ  	|¡S )NTr
   r   r    )
rp   rX   r	   r   r   Úintegerr   rk   r   r#   r!   r   r   r   r#   ø   s   zOneMatrix._eval_powerc                 C   r$   r   ©rk   r&   r'   r   r   r   r   r(     r)   zOneMatrix._eval_transposec                 C   r$   r   r   r   r   r   r   r*     r)   zOneMatrix._eval_adjointc                 C   s   t j| j S r   )r   rd   r'   r   r   r   r   r.     s   zOneMatrix._eval_tracec                 C   s"   | j }t|d dƒt|d dƒ@ S )z-Returns true if the matrix is known to be 1x1r   r
   )r   r   )r   r   r   r   r   rp     s   zOneMatrix._is_1x1c                 C   s8   |   ¡ }|dkrtjS |dkrtjS ddlm} || ƒS )NTFr   )ÚDeterminant)rp   r   rd   r-   Ú&sympy.matrices.expressions.determinantr€   )r   rm   r€   r   r   r   r0     s   zOneMatrix._eval_determinantc                 C   s<   |   ¡ }|dkrtdƒS |dkrtdƒ‚ddlm} || ƒS )NTr
   Fr2   )ÚInverse)rp   rX   r	   Úinverser‚   )r   rm   r‚   r   r   r   r3     s   zOneMatrix._eval_inversec                 C   ra   r   rb   r   r   r   r   r5   $  r)   zOneMatrix._eval_as_real_imagc                 C   r6   r   r   r   r   r   r   r7   '  r8   zOneMatrix._eval_conjugatec                 K   r+   r   rg   r9   r   r   r   r=   *  r/   zOneMatrix._entry)F)r>   r?   r@   rA   r   rC   r   rh   rt   rv   r#   r(   r*   r.   rp   r0   r3   r5   r7   r=   rD   r   r   r   r   rk   Õ   s&    




rk   N)Úsympy.assumptions.askr   r   Úsympy.core.relationalr   Úsympy.core.singletonr   Úsympy.core.sympifyr   Ú(sympy.functions.special.tensor_functionsr   Úsympy.matrices.exceptionsr	   Úmatexprr   r   rE   rX   ri   rk   r   r   r   r   Ú<module>   s    :$F'