U
    L?h                     @   s   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d	d
 ZG dd deZdd Zd dlmZmZ d dlmZ dd Zeed< dS )    )Basic)Expr)S)sympify)NonSquareMatrixError)
MatrixBasec                   @   s<   e Zd ZdZdZdd Zedd Zedd Zd	d
 Z	dS )Determinanta  Matrix Determinant

    Represents the determinant of a matrix expression.

    Examples
    ========

    >>> from sympy import MatrixSymbol, Determinant, eye
    >>> A = MatrixSymbol('A', 3, 3)
    >>> Determinant(A)
    Determinant(A)
    >>> Determinant(eye(3)).doit()
    1
    Tc                 C   s<   t |}|jstdt| |jdkr0tdt| |S )Nz&Input to Determinant, %s, not a matrixFzDet of a non-square matrix)r   	is_Matrix	TypeErrorstrZ	is_squarer   r   __new__clsZmat r   X/var/www/html/venv/lib/python3.8/site-packages/sympy/matrices/expressions/determinant.pyr      s    
zDeterminant.__new__c                 C   s
   | j d S Nr   argsselfr   r   r   arg$   s    zDeterminant.argc                 C   s
   | j jjS N)r   kindZelement_kindr   r   r   r   r   (   s    zDeterminant.kindc                 K   s6   | j }|ddr|jf |}| }|d k	r2|S | S )NdeepT)r   getdoitZ_eval_determinant)r   hintsr   resultr   r   r   r   ,   s    zDeterminant.doitN)
__name__
__module____qualname____doc__Zis_commutativer   propertyr   r   r   r   r   r   r   r   	   s   


r   c                 C   s   t |  S )z Matrix Determinant

    Examples
    ========

    >>> from sympy import MatrixSymbol, det, eye
    >>> A = MatrixSymbol('A', 3, 3)
    >>> det(A)
    Determinant(A)
    >>> det(eye(3))
    1
    )r   r   Zmatexprr   r   r   det8   s    r$   c                   @   s.   e Zd ZdZdd Zedd Zd
ddZd	S )	Permanenta  Matrix Permanent

    Represents the permanent of a matrix expression.

    Examples
    ========

    >>> from sympy import MatrixSymbol, Permanent, ones
    >>> A = MatrixSymbol('A', 3, 3)
    >>> Permanent(A)
    Permanent(A)
    >>> Permanent(ones(3, 3)).doit()
    6
    c                 C   s*   t |}|jstdt| t| |S )Nz$Input to Permanent, %s, not a matrix)r   r	   r
   r   r   r   r   r   r   r   r   X   s    zPermanent.__new__c                 C   s
   | j d S r   r   r   r   r   r   r   _   s    zPermanent.argFc                 K   s   t | jtr| j S | S d S r   )
isinstancer   r   per)r   expandr   r   r   r   r   c   s    
zPermanent.doitN)F)r   r   r    r!   r   r"   r   r   r   r   r   r   r%   H   s
   
r%   c                 C   s   t |  S )a   Matrix Permanent

    Examples
    ========

    >>> from sympy import MatrixSymbol, Matrix, per, ones
    >>> A = MatrixSymbol('A', 3, 3)
    >>> per(A)
    Permanent(A)
    >>> per(ones(5, 5))
    120
    >>> M = Matrix([1, 2, 5])
    >>> per(M)
    8
    )r%   r   r#   r   r   r   r'   i   s    r'   )askQ)handlers_dictc                 C   sL   t t| j|rtjS t t| j|r0tjS t t| j|rHtjS | S )z
    >>> from sympy import MatrixSymbol, Q, assuming, refine, det
    >>> X = MatrixSymbol('X', 2, 2)
    >>> det(X)
    Determinant(X)
    >>> with assuming(Q.orthogonal(X)):
    ...     print(refine(det(X)))
    1
    )	r)   r*   Z
orthogonalr   r   ZOneZsingularZZeroZunit_triangular)exprZassumptionsr   r   r   refine_Determinant   s    
r-   N)Zsympy.core.basicr   Zsympy.core.exprr   Zsympy.core.singletonr   Zsympy.core.sympifyr   Zsympy.matrices.exceptionsr   Zsympy.matrices.matrixbaser   r   r$   r%   r'   Zsympy.assumptions.askr)   r*   Zsympy.assumptions.refiner+   r-   r   r   r   r   <module>   s   /!