o
    8Va                     @   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                       sh   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  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__ D/usr/lib/python3/dist-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   Z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      t jS r   r   Zeror   r   r   r   _eval_trace.      zZeroMatrix._eval_tracec                 C   r(   r   r)   r   r   r   r   _eval_determinant1   r,   zZeroMatrix._eval_determinantc                 C      t d)N Matrix det == 0; not invertible.r   r   r   r   r   _eval_inverse4   s   zZeroMatrix._eval_inversec                 C      | S r   r   r   r   r   r   	conjugate7      zZeroMatrix.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   r2   r8   __classcell__r   r   r   r   r   
   s    
r   c                       `   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   E      zGenericZeroMatrix.__new__c                 C   r.   Nz1GenericZeroMatrix does not have a specified shape	TypeErrorr   r   r   r   r%   J      zGenericZeroMatrix.rowsc                 C   r.   rD   rE   r   r   r   r   r$   N   rG   zGenericZeroMatrix.colsc                 C   r.   rD   rE   r   r   r   r   r   R   rG   zGenericZeroMatrix.shapec                 C   
   t |tS r   )
isinstancer@   r   otherr   r   r   __eq__W      
zGenericZeroMatrix.__eq__c                 C   
   | |k S r   r   rJ   r   r   r   __ne__Z   rM   zGenericZeroMatrix.__ne__c                    
   t   S r   r   __hash__r   r   r   r   rR   ]   rM   zGenericZeroMatrix.__hash__r9   r:   r;   r<   r   r=   r%   r$   r   rL   rO   rR   r>   r   r   r   r   r@   >       


r@   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  ZS )IdentityzThe Matrix Identity I - multiplicative identity

    Examples
    ========

    >>> from sympy.matrices 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   q   s   
zIdentity.__new__c                 C   
   | j d S Nr   r   r   r   r   r   r%   w      
zIdentity.rowsc                 C   rV   rW   r   r   r   r   r   r$   {   rX   zIdentity.colsc                 C   s   | j d | j d fS rW   r   r   r   r   r   r      r   zIdentity.shapec                 C   s   dS NTr   r   r   r   r   	is_square   s   zIdentity.is_squarec                 C   r1   r   r   r   r   r   r   r&      r3   zIdentity._eval_transposec                 C      | j S r   )r%   r   r   r   r   r+      r,   zIdentity._eval_tracec                 C   r1   r   r   r   r   r   r   r0      r3   zIdentity._eval_inversec                 C   r1   r   r   r   r   r   r   r2      r3   zIdentity.conjugatec                 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OneZfalser*   r   r$   )r   r5   r6   r7   eqr   r   r   r8      s   


zIdentity._entryc                 C   r(   r   r   r]   r   r   r   r   r-      r,   zIdentity._eval_determinantc                 C   r1   r   r   r!   r   r   r   r"      r3   zIdentity._eval_power)r9   r:   r;   r<   is_Identityr   r=   r%   r$   r   rZ   r&   r+   r0   r2   r8   r-   r"   r>   r   r   r   r   rU   b   s&    



rU   c                       r?   )GenericIdentityz
    An identity matrix without a specified shape

    This exists primarily so MatMul() with no arguments can return something
    meaningful.
    c                    rA   r   )r   rU   r   rB   r   r   r   r      rC   zGenericIdentity.__new__c                 C   r.   Nz/GenericIdentity does not have a specified shaperE   r   r   r   r   r%      rG   zGenericIdentity.rowsc                 C   r.   rb   rE   r   r   r   r   r$      rG   zGenericIdentity.colsc                 C   r.   rb   rE   r   r   r   r   r      rG   zGenericIdentity.shapec                 C   rH   r   )rI   ra   rJ   r   r   r   rL      rM   zGenericIdentity.__eq__c                 C   rN   r   r   rJ   r   r   r   rO      rM   zGenericIdentity.__ne__c                    rP   r   rQ   r   r   r   r   rR      rM   zGenericIdentity.__hash__rS   r   r   r   r   ra      rT   ra   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  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   rU   r   r   )r   r   r   evaluate	conditionobjr   r   r   r      s   

zOneMatrix.__new__c                 C   r[   r   )Z_argsr   r   r   r   r      s   zOneMatrix.shapec                 C   s   |   dkS rY   )_is_1x1r   r   r   r   r`      s   zOneMatrix.is_Identityc                 C   s   ddl m} |j| j S )Nr   )ImmutableDenseMatrix)sympyrh   Zonesr   )r   rh   r   r   r   as_explicit   s   zOneMatrix.as_explicitc                    s4   | j } ddr fdd|D }| j|ddiS )NZdeepTc                    s   g | ]
}|j d i  qS )r   )doit).0ahintsr   r   
<listcomp>   s    z"OneMatrix.doit.<locals>.<listcomp>rd   )r   getfunc)r   ro   r   r   rn   r   rk      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    )
rg   rU   r	   r   r   Zintegerr   rc   r   r"   r!   r   r   r   r"      s   zOneMatrix._eval_powerc                 C   r#   r   )rc   r$   r%   r   r   r   r   r&      r'   zOneMatrix._eval_transposec                 C   s   t j| j S r   )r   r]   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   rg      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)rg   r   r]   r*   ri   rs   )r   re   rs   r   r   r   r-      s   zOneMatrix._eval_determinantc                 C   s<   |   }|dkrtdS |dkrtdddlm} || S )NTr
   Fr/   )Inverse)rg   rU   r	   Zinversert   )r   re   rt   r   r   r   r0     s   zOneMatrix._eval_inversec                 C   r1   r   r   r   r   r   r   r2     r3   zOneMatrix.conjugatec                 K   r(   r   r_   r4   r   r   r   r8     r,   zOneMatrix._entry)F)r9   r:   r;   r<   r   r=   r   r`   rj   rk   r"   r&   r+   rg   r-   r0   r2   r8   r>   r   r   r   r   rc      s"    




rc   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.commonr	   Zmatexprr   r   r@   rU   ra   rc   r   r   r   r   <module>   s    4$@#