o
    ohK                     @   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__ v/var/www/html/construction_image-detection-poc/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 )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   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'