o
    GZhK                     @   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 )
ZeroMatrixzThe 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__ Q/var/www/auris/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__Z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   rH   rI   r   r   r   r   r&   T   rK   zGenericZeroMatrix.colsc                 C   r1   rH   rI   r   r   r   r   r   X   rK   zGenericZeroMatrix.shapec                 C   
   t |tS r   )
isinstancerD   r   otherr   r   r   __eq__]      
zGenericZeroMatrix.__eq__c                 C   
   | |k S r   r   rN   r   r   r   __ne__`   rQ   zGenericZeroMatrix.__ne__c                    
   t   S r   r   __hash__r   r   r   r   rV   c   rQ   zGenericZeroMatrix.__hash__)r>   r?   r@   rA   r   rB   r'   r&   r   rP   rS   rV   rC   r   r   r   r   rD   D   s    


rD   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 )IdentityzThe 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   rX   rY   r   r   r   r   r   r&      rZ   zIdentity.colsc                 C   s   | j d | j d fS rY   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   rc   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   rB   r'   r&   r   r]   r(   r.   r3   r5   r7   r*   r=   r0   r#   rC   r   r   r   r   rW   h   s*    



rW   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                    rE   r   )r   rW   r   rF   r   r   r   r      rG   zGenericIdentity.__new__c                 C   r1   Nz/GenericIdentity does not have a specified shaperI   r   r   r   r   r'      rK   zGenericIdentity.rowsc                 C   r1   ri   rI   r   r   r   r   r&      rK   zGenericIdentity.colsc                 C   r1   ri   rI   r   r   r   r   r      rK   zGenericIdentity.shapec                 C   r[   r\   r   r   r   r   r   r]      r^   zGenericIdentity.is_squarec                 C   rL   r   )rM   rh   rN   r   r   r   rP      rQ   zGenericIdentity.__eq__c                 C   rR   r   r   rN   r   r   r   rS      rQ   zGenericIdentity.__ne__c                    rT   r   rU   r   r   r   r   rV      rQ   zGenericIdentity.__hash__)r>   r?   r@   rA   r   rB   r'   r&   r   r]   rP   rS   rV   rC   r   r   r   r   rh      s    



rh   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   rW   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   rg      s   zOneMatrix.is_Identityc                 C   s   ddl m} |j| j S )Nr   )ImmutableDenseMatrix)Zsympy.matrices.immutablerp   Zonesr   )r   rp   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>rk   )r   getfunc)r   rw   r   r   rv   r   rs      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    )
ro   rW   r	   r   r   integerr   rj   r   r#   r!   r   r   r   r#      s   zOneMatrix._eval_powerc                 C   r$   r   rj   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   rc   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   ro     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)ro   r   rc   r-   Z&sympy.matrices.expressions.determinantr}   )r   rl   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)ro   rW   r	   Zinverser~   )r   rl   r~   r   r   r   r3     s   zOneMatrix._eval_inversec                 C   r`   r   ra   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   rf   r9   r   r   r   r=   *  r/   zOneMatrix._entry)F)r>   r?   r@   rA   r   rB   r   rg   rq   rs   r#   r(   r*   r.   ro   r0   r3   r5   r7   r=   rC   r   r   r   r   rj      s&    




rj   N)Zsympy.assumptions.askr   r   Zsympy.core.relationalr   Zsympy.core.singletonr   Zsympy.core.sympifyr   Z(sympy.functions.special.tensor_functionsr   Zsympy.matrices.exceptionsr	   Zmatexprr   r   rD   rW   rh   rj   r   r   r   r   <module>   s    :$F'