a
    <bI                     @   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__ r/Users/vegardjervell/Documents/master/model/venv/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S r   r   Zeror   r   r   r   _eval_trace.   s    zZeroMatrix._eval_tracec                 C   s   t jS r   r&   r   r   r   r   _eval_determinant1   s    zZeroMatrix._eval_determinantc                 C   s   t dd S )N Matrix det == 0; not invertible.r   r   r   r   r   _eval_inverse4   s    zZeroMatrix._eval_inversec                 C   s   | S r   r   r   r   r   r   	conjugate7   s    zZeroMatrix.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,   r1   __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   E   s    zGenericZeroMatrix.__new__c                 C   s   t dd S Nz1GenericZeroMatrix does not have a specified shape	TypeErrorr   r   r   r   r$   J   s    zGenericZeroMatrix.rowsc                 C   s   t dd S r:   r;   r   r   r   r   r#   N   s    zGenericZeroMatrix.colsc                 C   s   t dd S r:   r;   r   r   r   r   r   R   s    zGenericZeroMatrix.shapec                 C   s
   t |tS r   )
isinstancer8   r   otherr   r   r   __eq__W   s    zGenericZeroMatrix.__eq__c                 C   s
   | |k S r   r   r>   r   r   r   __ne__Z   s    zGenericZeroMatrix.__ne__c                    s
   t   S r   r   __hash__r   r   r   r   rC   ]   s    zGenericZeroMatrix.__hash__r2   r3   r4   r5   r   r6   r$   r#   r   r@   rA   rC   r7   r   r   r   r   r8   >   s   


r8   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 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   s
   | j d S Nr   r   r   r   r   r   r$   w   s    zIdentity.rowsc                 C   s
   | j d S rF   r   r   r   r   r   r#   {   s    zIdentity.colsc                 C   s   | j d | j d fS rF   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   | S r   r   r   r   r   r   r,      s    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Onefalser'   r   r#   )r   r.   r/   r0   eqr   r   r   r1      s    


zIdentity._entryc                 C   s   t jS r   r   rJ   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)r2   r3   r4   r5   is_Identityr   r6   r$   r#   r   rH   r%   r(   r+   r,   r1   r)   r"   r7   r   r   r   r   rE   b   s$   



rE   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   rE   r   r9   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 rP   r;   r   r   r   r   r#      s    zGenericIdentity.colsc                 C   s   t dd S rP   r;   r   r   r   r   r      s    zGenericIdentity.shapec                 C   s
   t |tS r   )r=   rO   r>   r   r   r   r@      s    zGenericIdentity.__eq__c                 C   s
   | |k S r   r   r>   r   r   r   rA      s    zGenericIdentity.__ne__c                    s
   t   S r   rB   r   r   r   r   rC      s    zGenericIdentity.__hash__rD   r   r   r   r   rO      s   


rO   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 | }}| | | | |rNt|dt|d@ }|dkrNtdS t | ||}|S )Nr
   T)r   r   r   rE   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 rG   )_is_1x1r   r   r   r   rN      s    zOneMatrix.is_Identityc                 C   s   ddl m} |j| j S )Nr   )ImmutableDenseMatrix)Zsympy.matrices.immutablerW   Zonesr   )r   rW   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>rR   )r   getfunc)r   r^   r   r   r]   r   rZ      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   )
rV   rE   r	   r   r   integerr   rQ   r   r"   r    r   r   r   r"      s    zOneMatrix._eval_powerc                 C   s   t | j| jS r   )rQ   r#   r$   r   r   r   r   r%      s    zOneMatrix._eval_transposec                 C   s   t j| j S r   )r   rJ   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   rV      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)rV   r   rJ   r'   Z&sympy.matrices.expressions.determinantrd   )r   rS   rd   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)rV   rE   r	   Zinversere   )r   rS   re   r   r   r   r+     s    
zOneMatrix._eval_inversec                 C   s   | S r   r   r   r   r   r   r,     s    zOneMatrix.conjugatec                 K   s   t jS r   rM   r-   r   r   r   r1     s    zOneMatrix._entry)F)r2   r3   r4   r5   r   r6   r   rN   rX   rZ   r"   r%   r(   rV   r)   r+   r,   r1   r7   r   r   r   r   rQ      s    




rQ   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   r8   rE   rO   rQ   r   r   r   r   <module>   s   4$@#