a
    RG5d                     @   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__ ^/var/www/html/django/DPS/env/lib/python3.9/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__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   rB   r   r   r   __ne__`   s    zGenericZeroMatrix.__ne__c                    s
   t   S r   r   __hash__r   r   r   r   rG   c   s    zGenericZeroMatrix.__hash__r5   r6   r7   r8   r   r:   r%   r$   r   rD   rE   rG   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 rJ   r   r   r   r   r   r$      s    zIdentity.colsc                 C   s   | j d | j d fS rJ   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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   r1   r2   r3   eqr   r   r   r4      s    


zIdentity._entryc                 C   s   t jS r   r   rO   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   r:   r%   r$   r   rL   r&   r*   r-   r.   r/   r'   r4   r+   r"   r;   r   r   r   r   rI   h   s(   



rI   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 )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   rI   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 rU   r?   r   r   r   r   r$      s    zGenericIdentity.colsc                 C   s   t dd S rU   r?   r   r   r   r   r      s    zGenericIdentity.shapec                 C   s
   t |tS r   )rA   rT   rB   r   r   r   rD      s    zGenericIdentity.__eq__c                 C   s
   | |k S r   r   rB   r   r   r   rE      s    zGenericIdentity.__ne__c                    s
   t   S r   rF   r   r   r   r   rG      s    zGenericIdentity.__hash__rH   r   r   r   r   rT      s   


rT   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   rI   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 rK   )_is_1x1r   r   r   r   rS      s    zOneMatrix.is_Identityc                 C   s   ddl m} |j| j S )Nr   )ImmutableDenseMatrix)sympy.matrices.immutabler\   onesr   )r   r\   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 i  qS r   )doit).0ahintsr   r   
<listcomp>       z"OneMatrix.doit.<locals>.<listcomp>rW   )r   getfunc)r   re   r   r   rd   r   ra      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   )
r[   rI   r	   r   r   integerr   rV   r   r"   r    r   r   r   r"      s    zOneMatrix._eval_powerc                 C   s   t | j| jS r   rV   r$   r%   r   r   r   r   r&      s    zOneMatrix._eval_transposec                 C   s   t | j| jS r   rk   r   r   r   r   r'     s    zOneMatrix._eval_adjointc                 C   s   t j| j S r   )r   rO   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   r[     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)r[   r   rO   r)   &sympy.matrices.expressions.determinantrl   )r   rX   rl   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)r[   rI   r	   inversern   )r   rX   rn   r   r   r   r-     s    
zOneMatrix._eval_inversec                 C   s   | t | j fS r   rM   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   rR   r0   r   r   r   r4   &  s    zOneMatrix._entry)F)r5   r6   r7   r8   r   r:   r   rS   r_   ra   r"   r&   r'   r*   r[   r+   r-   r.   r/   r4   r;   r   r   r   r   rV      s$   




rV   N)sympy.assumptions.askr   r   sympy.core.relationalr   Zsympy.core.singletonr   sympy.core.sympifyr   (sympy.functions.special.tensor_functionsr   sympy.matrices.commonr	   matexprr   r   r<   rI   rT   rV   r   r   r   r   <module>   s   :$F#