U
    -eG                     @   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__ c/var/www/html/Darija-Ai-Train/env/lib/python3.8/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!   s    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   s   t | j| jS r   r   colsrowsr   r   r   r   _eval_transpose+   s    zZeroMatrix._eval_transposec                 C   s   t | j| jS r   r#   r   r   r   r   _eval_adjoint.   s    zZeroMatrix._eval_adjointc                 C   s   t jS r   r   Zeror   r   r   r   _eval_trace1   s    zZeroMatrix._eval_tracec                 C   s   t jS r   r(   r   r   r   r   _eval_determinant4   s    zZeroMatrix._eval_determinantc                 C   s   t dd S )N Matrix det == 0; not invertible.r   r   r   r   r   _eval_inverse7   s    zZeroMatrix._eval_inversec                 C   s   | | fS r   r   r   r   r   r   _eval_as_real_imag:   s    zZeroMatrix._eval_as_real_imagc                 C   s   | S r   r   r   r   r   r   _eval_conjugate=   s    zZeroMatrix._eval_conjugatec                 K   s   t jS r   r(   r   ijkwargsr   r   r   _entry@   s    zZeroMatrix._entry)__name__
__module____qualname____doc__Zis_ZeroMatrixr   propertyr   r"   r&   r'   r*   r+   r-   r.   r/   r4   __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                    s   t t| | S r   )r   r   r   r   r   r   r   r   K   s    zGenericZeroMatrix.__new__c                 C   s   t dd S Nz1GenericZeroMatrix does not have a specified shape	TypeErrorr   r   r   r   r%   P   s    zGenericZeroMatrix.rowsc                 C   s   t dd S r=   r>   r   r   r   r   r$   T   s    zGenericZeroMatrix.colsc                 C   s   t dd S r=   r>   r   r   r   r   r   X   s    zGenericZeroMatrix.shapec                 C   s
   t |tS r   )
isinstancer;   r   otherr   r   r   __eq__]   s    zGenericZeroMatrix.__eq__c                 C   s
   | |k S r   r   rA   r   r   r   __ne__`   s    zGenericZeroMatrix.__ne__c                    s
   t   S r   r   __hash__r   r   r   r   rF   c   s    zGenericZeroMatrix.__hash__)r5   r6   r7   r8   r   r9   r%   r$   r   rC   rD   rF   r:   r   r   r   r   r;   D   s   


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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   s
   | j d S Nr   r   r   r   r   r   r%   }   s    zIdentity.rowsc                 C   s
   | j d S rH   r   r   r   r   r   r$      s    zIdentity.colsc                 C   s   | j d | j d fS rH   r   r   r   r   r   r      s    zIdentity.shapec                 C   s   dS NTr   r   r   r   r   	is_square   s    zIdentity.is_squarec                 C   s   | S r   r   r   r   r   r   r&      s    zIdentity._eval_transposec                 C   s   | j S r   )r%   r   r   r   r   r*      s    zIdentity._eval_tracec                 C   s   | S r   r   r   r   r   r   r-      s    zIdentity._eval_inversec                 C   s   | t | j fS r   r   r   r   r   r   r   r.      s    zIdentity._eval_as_real_imagc                 C   s   | S r   r   r   r   r   r   r/      s    zIdentity._eval_conjugatec                 C   s   | S r   r   r   r   r   r   r'      s    zIdentity._eval_adjointc                 K   s@   t ||}|tjkrtjS |tjkr*tjS t||d| jd fS r   )r   r   trueOnefalser)   r   r$   )r   r1   r2   r3   eqr   r   r   r4      s    


zIdentity._entryc                 C   s   t jS r   r   rM   r   r   r   r   r+      s    zIdentity._eval_determinantc                 C   s   | S r   r   r    r   r   r   r"      s    zIdentity._eval_power)r5   r6   r7   r8   is_Identityr   r9   r%   r$   r   rJ   r&   r*   r-   r.   r/   r'   r4   r+   r"   r:   r   r   r   r   rG   h   s(   



rG   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                    s   t t| | S r   )r   rG   r   r<   r   r   r   r      s    zGenericIdentity.__new__c                 C   s   t dd S Nz/GenericIdentity does not have a specified shaper>   r   r   r   r   r%      s    zGenericIdentity.rowsc                 C   s   t dd S rS   r>   r   r   r   r   r$      s    zGenericIdentity.colsc                 C   s   t dd S rS   r>   r   r   r   r   r      s    zGenericIdentity.shapec                 C   s   dS rI   r   r   r   r   r   rJ      s    zGenericIdentity.is_squarec                 C   s
   t |tS r   )r@   rR   rA   r   r   r   rC      s    zGenericIdentity.__eq__c                 C   s
   | |k S r   r   rA   r   r   r   rD      s    zGenericIdentity.__ne__c                    s
   t   S r   rE   r   r   r   r   rF      s    zGenericIdentity.__hash__)r5   r6   r7   r8   r   r9   r%   r$   r   rJ   rC   rD   rF   r:   r   r   r   r   rR      s   



rR   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 | }}| | | | |rNt|dt|d@ }|dkrNtdS t | ||}|S )Nr
   T)r   r   r   rG   r   r   )r   r   r   evaluate	conditionobjr   r   r   r      s    

zOneMatrix.__new__c                 C   s   | j S r   )_argsr   r   r   r   r      s    zOneMatrix.shapec                 C   s   |   dkS rI   )_is_1x1r   r   r   r   rQ      s    zOneMatrix.is_Identityc                 C   s   ddl m} |j| j S )Nr   )ImmutableDenseMatrix)Zsympy.matrices.immutablerZ   Zonesr   )r   rZ   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 f  qS r   )doit).0ahintsr   r   
<listcomp>   s     z"OneMatrix.doit.<locals>.<listcomp>rU   )r   getfunc)r   ra   r   r   r`   r   r]      s    zOneMatrix.doitc                    s^   |   dkrtdS |dk dkr(tdtt|rR| jd |d  t| j  S t 	|S )NTr
   r   r   )
rY   rG   r	   r   r   integerr   rT   r   r"   r    r   r   r   r"      s    zOneMatrix._eval_powerc                 C   s   t | j| jS r   rT   r$   r%   r   r   r   r   r&     s    zOneMatrix._eval_transposec                 C   s   t | j| jS r   rf   r   r   r   r   r'     s    zOneMatrix._eval_adjointc                 C   s   t j| j S r   )r   rM   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   rY     s    zOneMatrix._is_1x1c                 C   s<   |   }|dkrtjS |dkr$tjS ddlm} || S d S )NTFr   )Determinant)rY   r   rM   r)   Z&sympy.matrices.expressions.determinantrg   )r   rV   rg   r   r   r   r+     s    zOneMatrix._eval_determinantc                 C   sB   |   }|dkrtdS |dkr*tdnddlm} || S d S )NTr
   Fr,   )Inverse)rY   rG   r	   Zinverserh   )r   rV   rh   r   r   r   r-     s    
zOneMatrix._eval_inversec                 C   s   | t | j fS r   rK   r   r   r   r   r.   $  s    zOneMatrix._eval_as_real_imagc                 C   s   | S r   r   r   r   r   r   r/   '  s    zOneMatrix._eval_conjugatec                 K   s   t jS r   rP   r0   r   r   r   r4   *  s    zOneMatrix._entry)F)r5   r6   r7   r8   r   r9   r   rQ   r[   r]   r"   r&   r'   r*   rY   r+   r-   r.   r/   r4   r:   r   r   r   r   rT      s$   




rT   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;   rG   rR   rT   r   r   r   r   <module>   s   :$F'