U
    L?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s4td||jsHtd|| dksbt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formatZis_monicZis_univariatedegreesuper__new__)clspoly	__class__ V/var/www/html/venv/lib/python3.8/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r8tjS tjS )Nr   r   )colsr   Z
all_coeffsr   ZOneZZero)r   ijr   r   r   _entry.   s
    zCompanionMatrix._entryc                 C   s   ddl m} || jd S )Nr   )ImmutableDenseMatrix)Zsympy.matrices.immutabler   Z	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)	Zsympy.core.singletonr   Zsympy.core.sympifyr   Zsympy.polys.polytoolsr   Zmatexprr   r   r   r   r   r   <module>   s   