o
    oÇh“  ã                   @   st   d dl mZ d dlmZmZ d dlmZ d dlmZ G dd„ deƒZ	d dl
mZmZ d dlmZ d	d
„ Zeed< dS )é    )Ú_sympify)ÚSÚBasic)ÚNonSquareMatrixError)ÚMatPowc                   @   sx   e Zd ZdZdZejZejf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S )ÚInversea  
    The multiplicative inverse of a matrix expression

    This is a symbolic object that simply stores its argument without
    evaluating it. To actually compute the inverse, use the ``.inverse()``
    method of matrices.

    Examples
    ========

    >>> from sympy import MatrixSymbol, Inverse
    >>> A = MatrixSymbol('A', 3, 3)
    >>> B = MatrixSymbol('B', 3, 3)
    >>> Inverse(A)
    A**(-1)
    >>> A.inverse() == Inverse(A)
    True
    >>> (A*B).inverse()
    B**(-1)*A**(-1)
    >>> Inverse(A*B)
    (A*B)**(-1)

    Tc                 C   sB   t |ƒ}t |ƒ}|jstdƒ‚|jdu rtd| ƒ‚t | ||¡S )Nzmat should be a matrixFzInverse of non-square matrix %s)r   Ú	is_MatrixÚ	TypeErrorÚ	is_squarer   r   Ú__new__)ÚclsÚmatÚexp© r   úv/var/www/html/construction_image-detection-poc/venv/lib/python3.10/site-packages/sympy/matrices/expressions/inverse.pyr   #   s   
zInverse.__new__c                 C   s
   | j d S ©Nr   )Úargs©Úselfr   r   r   Úarg.   s   
zInverse.argc                 C   s   | j jS ©N)r   Úshaper   r   r   r   r   2   s   zInverse.shapec                 C   s   | j S r   )r   r   r   r   r   Ú_eval_inverse6   s   zInverse._eval_inversec                 C   ó   t | j ¡ ƒS r   )r   r   Ú	transposer   r   r   r   Ú_eval_transpose9   ó   zInverse._eval_transposec                 C   r   r   )r   r   Úadjointr   r   r   r   Ú_eval_adjoint<   r   zInverse._eval_adjointc                 C   r   r   )r   r   Ú	conjugater   r   r   r   Ú_eval_conjugate?   r   zInverse._eval_conjugatec                 C   s   ddl m} d|| jƒ S )Nr   )Údeté   )Ú&sympy.matrices.expressions.determinantr!   r   )r   r!   r   r   r   Ú_eval_determinantB   s   zInverse._eval_determinantc                 K   sB   d|v r|d dkr| S | j }| dd¡r|jdi |¤Ž}| ¡ S )NÚ
inv_expandFÚdeepTr   )r   ÚgetÚdoitÚinverse)r   Úhintsr   r   r   r   r(   F   s   zInverse.doitc                 C   sB   | j d }| |¡}|D ]}| j| j 9  _| j| 9  _q|S r   )r   Ú_eval_derivative_matrix_linesÚfirst_pointerÚTÚsecond_pointer)r   Úxr   ÚlinesÚliner   r   r   r+   P   s   

z%Inverse._eval_derivative_matrix_linesN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__Ú
is_Inverser   ÚNegativeOner   r   Úpropertyr   r   r   r   r   r    r$   r(   r+   r   r   r   r   r      s     


r   )ÚaskÚQ)Úhandlers_dictc                 C   sT   t t | ¡|ƒr| jjS t t | ¡|ƒr| j ¡ S t t | ¡|ƒr(td| j ƒ‚| S )zÌ
    >>> from sympy import MatrixSymbol, Q, assuming, refine
    >>> X = MatrixSymbol('X', 2, 2)
    >>> X.I
    X**(-1)
    >>> with assuming(Q.orthogonal(X)):
    ...     print(refine(X.I))
    X.T
    zInverse of singular matrix %s)	r9   r:   Ú
orthogonalr   r-   Úunitaryr   ÚsingularÚ
ValueError)ÚexprÚassumptionsr   r   r   Úrefine_Inverse]   s   

rB   N)Úsympy.core.sympifyr   Ú
sympy.corer   r   Úsympy.matrices.exceptionsr   Ú!sympy.matrices.expressions.matpowr   r   Úsympy.assumptions.askr9   r:   Úsympy.assumptions.refiner;   rB   r   r   r   r   Ú<module>   s    Q