o
    oÇh©  ã                   @   sD   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S )	é    )ÚS)Ú_sympify)ÚPolyé   )Ú
MatrixExprc                       s<   e Zd ZdZ‡ fdd„Zedd„ ƒZdd„ Zdd	„ Z‡  Z	S )
ÚCompanionMatrixaÎ  A symbolic companion matrix of a polynomial.

    Examples
    ========

    >>> from sympy import Poly, Symbol, symbols
    >>> from sympy.matrices.expressions import CompanionMatrix
    >>> x = Symbol('x')
    >>> c0, c1, c2, c3, c4 = symbols('c0:5')
    >>> p = Poly(c0 + c1*x + c2*x**2 + c3*x**3 + c4*x**4 + x**5, x)
    >>> CompanionMatrix(p)
    CompanionMatrix(Poly(x**5 + c4*x**4 + c3*x**3 + c2*x**2 + c1*x + c0,
    x, domain='ZZ[c0,c1,c2,c3,c4]'))
    c                    sp   t |ƒ}t|tƒstd |¡ƒ‚|jstd |¡ƒ‚|js$td |¡ƒ‚| ¡ dks1td |¡ƒ‚tƒ  	| |¡S )Nz{} must be a Poly instance.z{} must be a monic polynomial.z#{} must be a univariate polynomial.r   z${} must have degree not less than 1.)
r   Ú
isinstancer   Ú
ValueErrorÚformatÚis_monicÚis_univariateÚdegreeÚsuperÚ__new__)ÚclsÚpoly©Ú	__class__© úx/var/www/html/construction_image-detection-poc/venv/lib/python3.10/site-packages/sympy/matrices/expressions/companion.pyr      s   
ÿÿzCompanionMatrix.__new__c                 C   s   | j d }| ¡ }||fS )Nr   )Úargsr   )Úselfr   Úsizer   r   r   Úshape'   s   
zCompanionMatrix.shapec                 C   s>   || j d kr| jd  ¡ d|   S ||d krtjS tjS )Nr   r   éÿÿÿÿ)Úcolsr   Ú
all_coeffsr   ÚOneÚZero)r   ÚiÚjr   r   r   Ú_entry.   s
   zCompanionMatrix._entryc                 C   s   ddl m} | | jd ¡S )Nr   )ÚImmutableDenseMatrix)Úsympy.matrices.immutabler"   Ú	companionr   )r   r"   r   r   r   Úas_explicit6   s   zCompanionMatrix.as_explicit)
Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   Úpropertyr   r!   r%   Ú__classcell__r   r   r   r   r      s    
r   N)	Úsympy.core.singletonr   Úsympy.core.sympifyr   Úsympy.polys.polytoolsr   Úmatexprr   r   r   r   r   r   Ú<module>   s
    