o
    *ήc                     @   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__ I/tmp/pip-target-vg8gfxp4/lib/python/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                       `   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   rJ   rK   r   r   r   r   r&   T   rM   zGenericZeroMatrix.colsc                 C   r1   rJ   rK   r   r   r   r   r   X   rM   zGenericZeroMatrix.shapec                 C   
   t |tS r   )
isinstancerF   r   otherr   r   r   __eq__]      
zGenericZeroMatrix.__eq__c                 C   
   | |k S r   r   rP   r   r   r   __ne__`   rS   zGenericZeroMatrix.__ne__c                    
   t   S r   r   __hash__r   r   r   r   rX   c   rS   zGenericZeroMatrix.__hash__r>   r?   r@   rA   r   rC   r'   r&   r   rR   rU   rX   rD   r   r   r   r   rF   D       


rF   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   r\   r]   r   r   r   r   r   r&      r^   zIdentity.colsc                 C   s   | j d | j d fS r]   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   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   re   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   r[   h   s*    



r[   c                       rE   )GenericIdentityz
    An identity matrix without a specified shape

    This exists primarily so MatMul() with no arguments can return something
    meaningful.
    c                    rG   r   )r   r[   r   rH   r   r   r   r      rI   zGenericIdentity.__new__c                 C   r1   Nz/GenericIdentity does not have a specified shaperK   r   r   r   r   r'      rM   zGenericIdentity.rowsc                 C   r1   rk   rK   r   r   r   r   r&      rM   zGenericIdentity.colsc                 C   r1   rk   rK   r   r   r   r   r      rM   zGenericIdentity.shapec                 C   rN   r   )rO   rj   rP   r   r   r   rR      rS   zGenericIdentity.__eq__c                 C   rT   r   r   rP   r   r   r   rU      rS   zGenericIdentity.__ne__c                    rV   r   rW   r   r   r   r   rX      rS   zGenericIdentity.__hash__rY   r   r   r   r   rj      rZ   rj   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   r[   r   r   )r   r   r   evaluate	conditionobjr   r   r   r      s   

zOneMatrix.__new__c                 C   ra   r   )_argsr   r   r   r   r      s   zOneMatrix.shapec                 C   s   |   dkS r_   )_is_1x1r   r   r   r   ri      s   zOneMatrix.is_Identityc                 C   s   ddl m} |j| j S )Nr   )ImmutableDenseMatrix)sympy.matrices.immutablerr   onesr   )r   rr   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>rm   )r   getfunc)r   r{   r   r   rz   r   rw      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    )
rq   r[   r	   r   r   integerr   rl   r   r#   r!   r   r   r   r#      s   zOneMatrix._eval_powerc                 C   r$   r   rl   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   re   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   rq     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)rq   r   re   r-   &sympy.matrices.expressions.determinantr   )r   rn   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)rq   r[   r	   inverser   )r   rn   r   r   r   r   r3     s   zOneMatrix._eval_inversec                 C   rb   r   rc   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   rh   r9   r   r   r   r=   &  r/   zOneMatrix._entry)F)r>   r?   r@   rA   r   rC   r   ri   ru   rw   r#   r(   r*   r.   rq   r0   r3   r5   r7   r=   rD   r   r   r   r   rl      s&    




rl   N)sympy.assumptions.askr   r   sympy.core.relationalr   sympy.core.singletonr   sympy.core.sympifyr   (sympy.functions.special.tensor_functionsr   sympy.matrices.commonr	   matexprr   r   rF   r[   rj   rl   r   r   r   r   <module>   s    :$F#