
    Ǆgl                     p    d Z ddlZddlZddlZddlmZ ddlZddlm	Z
 dgZ G d dej                        Zy)a  
Abstract base class for the various polynomial Classes.

The ABCPolyBase class provides the methods needed to implement the common API
for the various polynomial classes. It operates as a mixin, but uses the
abc module from the stdlib, hence it is only available for Python >= 2.6.

    N)Callable   )	polyutilsABCPolyBasec                   V   e Zd ZdZdZdZdZej                  dddddd	d
dddd
      Z	ej                  ddddddddddd
      Z
ej                  dk(   Zed        Zeej"                  d               Zeej"                  d               Zeej"                  d               Zeej"                  d               Zeej"                  d               Zeej"                  d                Zeej"                  d!               Zeej"                  dhd"              Zeej"                  d#               Zeej"                  d$               Zeej"                  d%               Zeej"                  d&               Zeej"                  d'               Zeej"                  d(               Z eej"                  d)               Z!d* Z"d+ Z#d, Z$d- Z%d. Z&did0Z'd1 Z(d2 Z)d3 Z*d4 Z+e,d5        Z-e,d6        Z.e,d7        Z/edjd8       Z0d9e1d:e2d;e2fd<Z3d= Z4d> Z5d? Z6d@ Z7dA Z8dB Z9dC Z:dD Z;dE Z<dF Z=dG Z>dH Z?dI Z@dJ ZAdK ZBdL ZCdM ZDdN ZEdO ZFdP ZGdQ ZHdR ZIdS ZJdT ZKdU ZLdV ZMdW ZNdX ZOdY ZPdkdZZQd[ ZRdld\ZSd] ZTd^g dfd_ZUdmd`ZVda ZWdndbZXe,	 	 dodc       ZYe,g dd/fdd       ZZe,dide       Z[e,didf       Z\e,dpdg       Z]y)qr   a  An abstract base class for immutable series classes.

    ABCPolyBase provides the standard Python numerical methods
    '+', '-', '*', '//', '%', 'divmod', '**', and '()' along with the
    methods listed below.

    .. versionadded:: 1.9.0

    Parameters
    ----------
    coef : array_like
        Series coefficients in order of increasing degree, i.e.,
        ``(1, 2, 3)`` gives ``1*P_0(x) + 2*P_1(x) + 3*P_2(x)``, where
        ``P_i`` is the basis polynomials of degree ``i``.
    domain : (2,) array_like, optional
        Domain to use. The interval ``[domain[0], domain[1]]`` is mapped
        to the interval ``[window[0], window[1]]`` by shifting and scaling.
        The default value is the derived class domain.
    window : (2,) array_like, optional
        Window, see domain for its use. The default value is the
        derived class window.
    symbol : str, optional
        Symbol used to represent the independent variable in string 
        representations of the polynomial expression, e.g. for printing.
        The symbol must be a valid Python identifier. Default value is 'x'.

        .. versionadded:: 1.24

    Attributes
    ----------
    coef : (N,) ndarray
        Series coefficients in order of increasing degree.
    domain : (2,) ndarray
        Domain that is mapped to window.
    window : (2,) ndarray
        Window that domain is mapped to.
    symbol : str
        Symbol representing the independent variable.

    Class Attributes
    ----------------
    maxpower : int
        Maximum power allowed, i.e., the largest number ``n`` such that
        ``p(x)**n`` is allowed. This is to limit runaway polynomial size.
    domain : (2,) ndarray
        Default domain of the class.
    window : (2,) ndarray
        Default window of the class.

    Nd   u   ⁰   ¹   ²   ³u   ⁴u   ⁵u   ⁶u   ⁷u   ⁸u   ⁹)
0123456789u   ₀u   ₁u   ₂u   ₃u   ₄u   ₅u   ₆u   ₇u   ₈u   ₉ntc                     | j                   S N)_symbolselfs    b/home/mcse/projects/flask_80/flask-venv/lib/python3.12/site-packages/numpy/polynomial/_polybase.pysymbolzABCPolyBase.symbolo   s    ||    c                      y r    r   s    r   domainzABCPolyBase.domains        	r   c                      y r   r    r   s    r   windowzABCPolyBase.windowx   r"   r   c                      y r   r    r   s    r   
basis_namezABCPolyBase.basis_name}   r"   r   c                      y r   r    c1c2s     r   _addzABCPolyBase._add   r"   r   c                      y r   r    r(   s     r   _subzABCPolyBase._sub   r"   r   c                      y r   r    r(   s     r   _mulzABCPolyBase._mul   r"   r   c                      y r   r    r(   s     r   _divzABCPolyBase._div   r"   r   c                      y r   r    )cpowmaxpowers      r   _powzABCPolyBase._pow   r"   r   c                      y r   r    )xr3   s     r   _valzABCPolyBase._val   r"   r   c                      y r   r    )r3   mklbndscls        r   _intzABCPolyBase._int   r"   r   c                      y r   r    )r3   r;   r>   s      r   _derzABCPolyBase._der   r"   r   c                      y r   r    )r8   ydegrcondfulls        r   _fitzABCPolyBase._fit   r"   r   c                      y r   r    )offr>   s     r   _linezABCPolyBase._line   r"   r   c                      y r   r    )r3   s    r   _rootszABCPolyBase._roots   r"   r   c                      y r   r    )rs    r   
_fromrootszABCPolyBase._fromroots   r"   r   c                     t        | j                        t        |j                        k7  ryt        j                  | j                  |j                  k(        syy)aG  Check if coefficients match.

        .. versionadded:: 1.6.0

        Parameters
        ----------
        other : class instance
            The other class must have the ``coef`` attribute.

        Returns
        -------
        bool : boolean
            True if the coefficients are the same, False otherwise.

        FT)lencoefnpallr   others     r   has_samecoefzABCPolyBase.has_samecoef   s>      tyy>S_,		UZZ/0r   c                 Z    t        j                  | j                  |j                  k(        S )a?  Check if domains match.

        .. versionadded:: 1.6.0

        Parameters
        ----------
        other : class instance
            The other class must have the ``domain`` attribute.

        Returns
        -------
        bool : boolean
            True if the domains are the same, False otherwise.

        )rS   rT   r!   rU   s     r   has_samedomainzABCPolyBase.has_samedomain          vvdkkU\\122r   c                 Z    t        j                  | j                  |j                  k(        S )a?  Check if windows match.

        .. versionadded:: 1.6.0

        Parameters
        ----------
        other : class instance
            The other class must have the ``window`` attribute.

        Returns
        -------
        bool : boolean
            True if the windows are the same, False otherwise.

        )rS   rT   r$   rU   s     r   has_samewindowzABCPolyBase.has_samewindow   rZ   r   c                 .    t        || j                        S )a  Check if types match.

        .. versionadded:: 1.7.0

        Parameters
        ----------
        other : object
            Class instance.

        Returns
        -------
        bool : boolean
            True if other is same class as self

        )
isinstance	__class__rU   s     r   has_sametypezABCPolyBase.has_sametype   s      %00r   c                    t        |t              rt        || j                        st        d      t	        j
                  | j                  |j                  k(        st        d      t	        j
                  | j                  |j                  k(        st        d      | j                  |j                  k7  rt        d      |j                  S |S )a  Interpret other as polynomial coefficients.

        The `other` argument is checked to see if it is of the same
        class as self with identical domain and window. If so,
        return its coefficients, otherwise return `other`.

        .. versionadded:: 1.9.0

        Parameters
        ----------
        other : anything
            Object to be checked.

        Returns
        -------
        coef
            The coefficients of`other` if it is a compatible instance,
            of ABCPolyBase, otherwise `other`.

        Raises
        ------
        TypeError
            When `other` is an incompatible instance of ABCPolyBase.

        zPolynomial types differzDomains differzWindows differzPolynomial symbols differ)r^   r   r_   	TypeErrorrS   rT   r!   r$   r   
ValueErrorrR   rU   s     r   _get_coefficientszABCPolyBase._get_coefficients  s    4 e[)eT^^4 9::VVDKK5<<78 011VVDKK5<<78 011, !<==::r   r8   c                    t        j                  |gd      \  }|| _        |:t        j                  |gd      \  }t        |      dk7  rt	        d      || _        |:t        j                  |gd      \  }t        |      dk7  rt	        d      || _        	 |j                         st	        d      	 || _
        y # t        $ r t        d      w xY w)NFtrim   z$Domain has wrong number of elements.z$Window has wrong number of elements.z/Symbol string must be a valid Python identifierz!Symbol must be a non-empty string)pu	as_seriesrR   rQ   rc   r!   r$   isidentifierAttributeErrorrb   r   )r   rR   r!   r$   r   s        r   __init__zABCPolyBase.__init__1  s    tf51	||VH59HV6{a !GHH DK||VH59HV6{a !GHH DK		A&&( E  )   	A?@@	As   B? ?Cc           
          t        | j                        dd }t        | j                        dd }t        | j                        dd }| j                  j
                  }| d| d| d| d| j                   d
S )N   (z	, domain=z	, window=z
, symbol='z'))reprrR   r!   r$   r_   __name__r   )r   rR   r!   r$   names        r   __repr__zABCPolyBase.__repr__O  s    DIIq$dkk"1R(dkk"1R(~~&&&$y	& B;;-r+ 	,r   c                     |dk(  r| j                         S |dvrt        d| d| j                   d      |dk(  r| j                  | j                        S | j                  | j
                        S )N )asciiunicodezUnsupported format string 'z' passed to z4.__format__. Valid options are 'ascii' and 'unicode'rx   )__str__rc   r_   _generate_string_str_term_ascii_str_term_unicode)r   fmt_strs     r   
__format__zABCPolyBase.__format__W  s    b=<<>!..-gYl>>" #() 
 g(()=)=>>$$T%;%;<<r   c                     | j                   r| j                  | j                        S | j                  | j                        S r   )_use_unicoder{   r}   r|   r   s    r   rz   zABCPolyBase.__str__d  s9    (()?)?@@$$T%9%9::r   c                    t        j                         j                  dd      }|dk  rd}t        j                  | j
                  d         }| j                         \  }}| j                  t        j                  ||      \  }}|rd|z   dz   }t        | j
                  dd       D ]  \  }}	|dz  }t        |dz         }
	 |	dk\  rd	t        j                  |	d
      z   }ndt        j                  |	 d
      z   }| ||
|      z  }t        |j                  d      d         t        |      z   }|t        | j
                  dd       dz
  k  r|dz  }||k\  r|j                  ddd      }||z  } |S # t        $ r d	|	 }Y w xY w)z
        Generate the full string representation of the polynomial, using
        ``term_method`` to generate each polynomial term.
        	linewidthK   r   r   rq   )N z+ Tparensz- 
rp   rh   )rS   get_printoptionsgetri   format_floatrR   mapparms_format_term	enumeratestrrb   rQ   splitreplace)r   term_methodr   outrI   scalescaled_symbolneeds_parensirR   power	next_termline_lens                r   r{   zABCPolyBase._generate_stringi  s    '')--k2>	q=Ioodiil+]]_
U&*&7&78;U'D#|-/#5M 12/ 	GAt3JCAJE
(19 $rtD'I II $ruT'J JI UM::I399T?2./#i.@H 3tyy}%))A9$%--c4;	9C3	4 
  ( K	(s   ;E55FFc                     | j                   t        d      d| j                    |j                  | j                         d| dS )z
        String representation of single polynomial term using unicode
        characters for superscripts and subscripts.
        zZSubclasses must define either a basis_name, or override _str_term_unicode(cls, i, arg_str)   ·rq   r   )r&   NotImplementedError	translate_subscript_mappingclsr   arg_strs      r   r}   zABCPolyBase._str_term_unicode  sU     >>!%5  S^^$Q[[1G1G%H$IG9A 	 r   c                 \    | j                   t        d      d| j                    d| d| dS )z
        String representation of a single polynomial term using ** and _ to
        represent superscripts and subscripts, respectively.
        zXSubclasses must define either a basis_name, or override _str_term_ascii(cls, i, arg_str)r   _rq   r   r&   r   r   s      r   r|   zABCPolyBase._str_term_ascii  sB     >>!%3  3>>"!A3ay22r   c                 \    | j                   t        d      d| j                    d| d| dS )NzbSubclasses must define either a basis name, or override _repr_latex_term(i, arg_str, needs_parens){z}_{z}(r   r   )r   r   r   r   s       r   _repr_latex_termzABCPolyBase._repr_latex_term  s@    >>!%=> > CNN#53wiq99r   c                 N    dj                  t        j                  | |            S )Nz\text{{{}}}r   )formatri   r   )r8   r   s     r   _repr_latex_scalarzABCPolyBase._repr_latex_scalar  s      $$R__Qv%FGGr   scalar_formatrI   r   c                 
   |dk(  r|dk(  r| j                   }d}||fS |dk(  r ||       d| j                    }d}||fS |dk(  r ||       | j                    }d}||fS  ||       d ||       | j                    }d}||fS )z' Format a single term in the expansion r   r   F + T)r   )r   r   rI   r   termr   s         r   r   zABCPolyBase._format_term  s    !8
;;D L \!! aZ#C()T[[M:DL \!! AX#E*+DKK=9DL \!!	 !%&c '(7   L\!!r   c                    | j                         \  }}| j                  | j                  ||      \  }}dj                  }g }t	        | j
                        D ]  \  }}|dk(  r| j                  |       }	nct        |t        j                        sd| j                  |       d}	n3|dk\  rd| j                  |d       }	nd| j                  | d       }	| j                  |||      }
|
d	k(  r|	}n|	 d
|
 }|dk(  r ||      }|j                  |        |rdj                  |      }nd}d| j                   d| dS )Nz\color{{LightGray}}{{{}}}r   z + (r   r   Tr   z - r   z\,rw   r   $z	 \mapsto )r   r   r   r   r   rR   r^   numbersRealr   appendjoinr   )r   rI   r   r   r   mutepartsr   r3   coef_strterm_strpartbodys                r   _repr_latex_zABCPolyBase._repr_latex_  sf   ]]_
U!..t/F/F/2E;l ,22dii( 	DAqAv"55a897<<0!$"9"9!"<!=Q?a !8!84!8!H IJ !8!8!D!8!I JK ,,QlCH3#*Bxj1AvDzLL+	. 775>D DDKK=	$q11r   c                    | j                   j                         }| j                  j                         |d<   | j                  j                         |d<   | j                  j                         |d<   | j
                  |d<   |S )NrR   r!   r$   r   )__dict__copyrR   r!   r$   r   )r   rets     r   __getstate__zABCPolyBase.__getstate__   sf    mm  "iinn&F((*H((*HH
r   c                     || _         y r   )r   )r   dicts     r   __setstate__zABCPolyBase.__setstate__  s	    r   c                     t        j                  || j                  | j                        }| j	                  || j
                        S r   )ri   	mapdomainr!   r$   r9   rR   )r   args     r   __call__zABCPolyBase.__call__  s1    ll3T[[9yydii((r   c                 ,    t        | j                        S r   )iterrR   r   s    r   __iter__zABCPolyBase.__iter__  s    DIIr   c                 ,    t        | j                        S r   )rQ   rR   r   s    r   __len__zABCPolyBase.__len__  s    499~r   c                 |    | j                  | j                   | j                  | j                  | j                        S r   r_   rR   r!   r$   r   r   s    r   __neg__zABCPolyBase.__neg__  s.    ~~YYJT[[$++
 	
r   c                     | S r   r    r   s    r   __pos__zABCPolyBase.__pos__  s    r   c                     | j                  |      }	 | j                  | j                  |      }| j                  || j                  | j                  | j                        S # t        $ r	 t        cY S w xY wr   )	rd   r+   rR   	ExceptionNotImplementedr_   r!   r$   r   r   rV   	othercoefrR   s       r   __add__zABCPolyBase.__add__!  e    **51		"99TYY	2D ~~dDKKdkkJJ  	"!!	"   A! !A32A3c                     | j                  |      }	 | j                  | j                  |      }| j                  || j                  | j                  | j                        S # t        $ r	 t        cY S w xY wr   )	rd   r-   rR   r   r   r_   r!   r$   r   r   s       r   __sub__zABCPolyBase.__sub__)  r   r   c                     | j                  |      }	 | j                  | j                  |      }| j                  || j                  | j                  | j                        S # t        $ r	 t        cY S w xY wr   )	rd   r/   rR   r   r   r_   r!   r$   r   r   s       r   __mul__zABCPolyBase.__mul__1  r   r   c                     t        |t        j                        rt        |t              r$t	        dt        |        dt        |       d      | j                  |      S )Nz&unsupported types for true division: 'z', '')r^   r   Numberboolrb   type__floordiv__rU   s     r   __truediv__zABCPolyBase.__truediv__9  sZ     %0Jud4KJ<tDK=3    ''r   c                 B    | j                  |      }|t        u r|S |d   S Nr   
__divmod__r   r   rV   ress      r   r   zABCPolyBase.__floordiv__D  &    ooe$. J1vr   c                 B    | j                  |      }|t        u r|S |d   S Nr   r   r   s      r   __mod__zABCPolyBase.__mod__J  r   r   c                 p   | j                  |      }	 | j                  | j                  |      \  }}| j                  || j                  | j                  | j                        }| j                  || j                  | j                  | j                        }||fS # t        $ r  t        $ r	 t
        cY S w xY wr   )
rd   r1   rR   ZeroDivisionErrorr   r   r_   r!   r$   r   )r   rV   r   quorems        r   r   zABCPolyBase.__divmod__P  s    **51		"yyI6HC
 nnS$++t{{DKKHnnS$++t{{DKKHCx ! 	 	"!!	"s   B B54B5c                     | j                  | j                  || j                        }| j                  || j                  | j
                  | j                        }|S )N)r5   )r6   rR   r5   r_   r!   r$   r   )r   rV   rR   r   s       r   __pow__zABCPolyBase.__pow__\  sC    yyEDMMyBnnT4;;T[[I
r   c                     	 | j                  || j                        }| j	                  || j
                  | j                  | j                        S # t        $ r	 t        cY S w xY wr   )r+   rR   r   r   r_   r!   r$   r   r   rV   rR   s      r   __radd__zABCPolyBase.__radd__a  U    	"99UDII.D ~~dDKKdkkJJ  	"!!	"   A A"!A"c                     	 | j                  || j                        }| j	                  || j
                  | j                  | j                        S # t        $ r	 t        cY S w xY wr   )r-   rR   r   r   r_   r!   r$   r   r   s      r   __rsub__zABCPolyBase.__rsub__h  r   r   c                     	 | j                  || j                        }| j	                  || j
                  | j                  | j                        S # t        $ r	 t        cY S w xY wr   )r/   rR   r   r   r_   r!   r$   r   r   s      r   __rmul__zABCPolyBase.__rmul__o  r   r   c                 $    | j                  |      S r   )__rfloordiv__rU   s     r   __rdiv__zABCPolyBase.__rdiv__v  s    !!%((r   c                     t         S r   )r   rU   s     r   __rtruediv__zABCPolyBase.__rtruediv__z  s
     r   c                 B    | j                  |      }|t        u r|S |d   S r   __rdivmod__r   r   s      r   r  zABCPolyBase.__rfloordiv__  (    u%. J1vr   c                 B    | j                  |      }|t        u r|S |d   S r   r  r   s      r   __rmod__zABCPolyBase.__rmod__  r  r   c                 N   	 | j                  || j                        \  }}| j                  || j                  | j                  | j                        }| j                  || j                  | j                  | j                        }||fS # t        $ r  t        $ r	 t        cY S w xY wr   )	r1   rR   r   r   r   r_   r!   r$   r   )r   rV   r   r   s       r   r  zABCPolyBase.__rdivmod__  s    	"yy		2HC
 nnS$++t{{DKKHnnS$++t{{DKKHCx ! 	 	"!!	"s   B	 	B$#B$c                    t        || j                        xr t        j                  | j                  |j                  k(        xr t        j                  | j
                  |j
                  k(        xrv | j                  j                  |j                  j                  k(  xrG t        j                  | j                  |j                  k(        xr | j                  |j                  k(  }|S r   )	r^   r_   rS   rT   r!   r$   rR   shaper   r   s      r   __eq__zABCPolyBase.__eq__  s    %0 -vvdkkU\\12-vvdkkU\\12- 		5::#3#33- vvdii5::-.	-
 u||+ 	 
r   c                 &    | j                  |       S r   )r  rU   s     r   __ne__zABCPolyBase.__ne__  s    ;;u%%%r   c                 z    | j                  | j                  | j                  | j                  | j                        S )zoReturn a copy.

        Returns
        -------
        new_series : series
            Copy of self.

        r   r   s    r   r   zABCPolyBase.copy  s)     ~~diidkk4;;OOr   c                     t        |       dz
  S )u  The degree of the series.

        .. versionadded:: 1.5.0

        Returns
        -------
        degree : int
            Degree of the series, one less than the number of coefficients.

        Examples
        --------

        Create a polynomial object for ``1 + 7*x + 4*x**2``:

        >>> poly = np.polynomial.Polynomial([1, 7, 4])
        >>> print(poly)
        1.0 + 7.0·x + 4.0·x²
        >>> poly.degree()
        2

        Note that this method does not check for non-zero coefficients.
        You must trim the polynomial to remove any trailing zeroes:

        >>> poly = np.polynomial.Polynomial([1, 7, 0])
        >>> print(poly)
        1.0 + 7.0·x + 0.0·x²
        >>> poly.degree()
        2
        >>> poly.trim().degree()
        1

        r   )rQ   r   s    r   degreezABCPolyBase.degree  s    B 4y1}r   c                 *    | j                  |dz         S )a  Truncate series to the given degree.

        Reduce the degree of the series to `deg` by discarding the
        high order terms. If `deg` is greater than the current degree a
        copy of the current series is returned. This can be useful in least
        squares where the coefficients of the high degree terms may be very
        small.

        .. versionadded:: 1.5.0

        Parameters
        ----------
        deg : non-negative int
            The series is reduced to degree `deg` by discarding the high
            order terms. The value of `deg` must be a non-negative integer.

        Returns
        -------
        new_series : series
            New instance of series with reduced degree.

        r   )truncate)r   rD   s     r   cutdegzABCPolyBase.cutdeg  s    . }}S1W%%r   c                     t        j                  | j                  |      }| j                  || j                  | j
                  | j                        S )a  Remove trailing coefficients

        Remove trailing coefficients until a coefficient is reached whose
        absolute value greater than `tol` or the beginning of the series is
        reached. If all the coefficients would be removed the series is set
        to ``[0]``. A new series instance is returned with the new
        coefficients.  The current instance remains unchanged.

        Parameters
        ----------
        tol : non-negative number.
            All trailing coefficients less than `tol` will be removed.

        Returns
        -------
        new_series : series
            New instance of series with trimmed coefficients.

        )ri   trimcoefrR   r_   r!   r$   r   )r   tolrR   s      r   rg   zABCPolyBase.trim  s9    ( {{499c*~~dDKKdkkJJr   c                    t        |      }||k7  s|dk  rt        d      |t        | j                        k\  r| j                  }n| j                  d| }| j	                  || j
                  | j                  | j                        S )a  Truncate series to length `size`.

        Reduce the series to length `size` by discarding the high
        degree terms. The value of `size` must be a positive integer. This
        can be useful in least squares where the coefficients of the
        high degree terms may be very small.

        Parameters
        ----------
        size : positive int
            The series is reduced to length `size` by discarding the high
            degree terms. The value of `size` must be a positive integer.

        Returns
        -------
        new_series : series
            New instance of series with truncated coefficients.

        r   zsize must be a positive integerN)intrc   rQ   rR   r_   r!   r$   r   )r   sizeisizerR   s       r   r  zABCPolyBase.truncate  sp    ( D	D=EAI>??C		N"99D99Ve$D~~dDKKdkkJJr   c                     || j                   }||j                  }||j                  } | |j                  ||| j                              S )a  Convert series to a different kind and/or domain and/or window.

        Parameters
        ----------
        domain : array_like, optional
            The domain of the converted series. If the value is None,
            the default domain of `kind` is used.
        kind : class, optional
            The polynomial series type class to which the current instance
            should be converted. If kind is None, then the class of the
            current instance is used.
        window : array_like, optional
            The window of the converted series. If the value is None,
            the default window of `kind` is used.

        Returns
        -------
        new_series : series
            The returned class can be of different type than the current
            instance and/or have a different domain and/or different
            window.

        Notes
        -----
        Conversion between domains and class types can result in
        numerically ill defined series.

        )r$   r   )r_   r!   r$   identityr   )r   r!   kindr$   s       r   convertzABCPolyBase.convert!  sL    : <>>D>[[F>[[FDMM&MLMMr   c                 V    t        j                  | j                  | j                        S )a  Return the mapping parameters.

        The returned values define a linear map ``off + scl*x`` that is
        applied to the input arguments before the series is evaluated. The
        map depends on the ``domain`` and ``window``; if the current
        ``domain`` is equal to the ``window`` the resulting map is the
        identity.  If the coefficients of the series instance are to be
        used by themselves outside this class, then the linear function
        must be substituted for the ``x`` in the standard representation of
        the base polynomials.

        Returns
        -------
        off, scl : float or complex
            The mapping function is defined by ``off + scl*x``.

        Notes
        -----
        If the current domain is the interval ``[l1, r1]`` and the window
        is ``[l2, r2]``, then the linear mapping function ``L`` is
        defined by the equations::

            L(l1) = l2
            L(r1) = r2

        )ri   r   r!   r$   r   s    r   r   zABCPolyBase.mapparmsF  s    6 {{4;;44r   r   c                     | j                         \  }}|d}n|||z  z   }| j                  | j                  |||d|z        }| j                  || j                  | j
                  | j                        S )a  Integrate.

        Return a series instance that is the definite integral of the
        current series.

        Parameters
        ----------
        m : non-negative int
            The number of integrations to perform.
        k : array_like
            Integration constants. The first constant is applied to the
            first integration, the second to the second, and so on. The
            list of values must less than or equal to `m` in length and any
            missing values are set to zero.
        lbnd : Scalar
            The lower bound of the definite integral.

        Returns
        -------
        new_series : series
            A new series representing the integral. The domain is the same
            as the domain of the integrated series.

        r   g      ?)r   r?   rR   r_   r!   r$   r   )r   r;   r<   r=   rI   r>   rR   s          r   integzABCPolyBase.integc  si    2 ==?S<DT>DyyAq$37~~dDKKdkkJJr   c                     | j                         \  }}| j                  | j                  ||      }| j                  || j                  | j
                  | j                        S )a  Differentiate.

        Return a series instance of that is the derivative of the current
        series.

        Parameters
        ----------
        m : non-negative int
            Find the derivative of order `m`.

        Returns
        -------
        new_series : series
            A new series representing the derivative. The domain is the same
            as the domain of the differentiated series.

        )r   rA   rR   r_   r!   r$   r   )r   r;   rI   r>   rR   s        r   derivzABCPolyBase.deriv  sJ    $ ==?SyyAs+~~dDKKdkkJJr   c                     | j                  | j                        }t        j                  || j                  | j
                        S )a/  Return the roots of the series polynomial.

        Compute the roots for the series. Note that the accuracy of the
        roots decreases the further outside the `domain` they lie.

        Returns
        -------
        roots : ndarray
            Array containing the roots of the series.

        )rL   rR   ri   r   r$   r!   )r   rootss     r   r(  zABCPolyBase.roots  s1     DII&||E4;;<<r   c                 p    || j                   }t        j                  |d   |d   |      } | |      }||fS )a  Return x, y values at equally spaced points in domain.

        Returns the x, y values at `n` linearly spaced points across the
        domain.  Here y is the value of the polynomial at the points x. By
        default the domain is the same as that of the series instance.
        This method is intended mostly as a plotting aid.

        .. versionadded:: 1.5.0

        Parameters
        ----------
        n : int, optional
            Number of point pairs to return. The default value is 100.
        domain : {None, array_like}, optional
            If not None, the specified domain is used instead of that of
            the calling instance. It should be of the form ``[beg,end]``.
            The default is None which case the class domain is used.

        Returns
        -------
        x, y : ndarray
            x is equal to linspace(self.domain[0], self.domain[1], n) and
            y is the series evaluated at element of x.

        r   r   )r!   rS   linspace)r   nr!   r8   rC   s        r   r*  zABCPolyBase.linspace  s>    4 >[[FKKq	6!9a0G!tr   c
                 F   |t        j                  |      }n+t        |      t        u rt	        |      dk(  r| j
                  }|| j                  }t        j                  |||      }
| j                  |
|||||      }|r|\  }} | ||||	      |fS |} | ||||	      S )a4  Least squares fit to data.

        Return a series instance that is the least squares fit to the data
        `y` sampled at `x`. The domain of the returned instance can be
        specified and this will often result in a superior fit with less
        chance of ill conditioning.

        Parameters
        ----------
        x : array_like, shape (M,)
            x-coordinates of the M sample points ``(x[i], y[i])``.
        y : array_like, shape (M,)
            y-coordinates of the M sample points ``(x[i], y[i])``.
        deg : int or 1-D array_like
            Degree(s) of the fitting polynomials. If `deg` is a single integer
            all terms up to and including the `deg`'th term are included in the
            fit. For NumPy versions >= 1.11.0 a list of integers specifying the
            degrees of the terms to include may be used instead.
        domain : {None, [beg, end], []}, optional
            Domain to use for the returned series. If ``None``,
            then a minimal domain that covers the points `x` is chosen.  If
            ``[]`` the class domain is used. The default value was the
            class domain in NumPy 1.4 and ``None`` in later versions.
            The ``[]`` option was added in numpy 1.5.0.
        rcond : float, optional
            Relative condition number of the fit. Singular values smaller
            than this relative to the largest singular value will be
            ignored. The default value is ``len(x)*eps``, where eps is the
            relative precision of the float type, about 2e-16 in most
            cases.
        full : bool, optional
            Switch determining nature of return value. When it is False
            (the default) just the coefficients are returned, when True
            diagnostic information from the singular value decomposition is
            also returned.
        w : array_like, shape (M,), optional
            Weights. If not None, the weight ``w[i]`` applies to the unsquared
            residual ``y[i] - y_hat[i]`` at ``x[i]``. Ideally the weights are
            chosen so that the errors of the products ``w[i]*y[i]`` all have
            the same variance.  When using inverse-variance weighting, use
            ``w[i] = 1/sigma(y[i])``.  The default value is None.

            .. versionadded:: 1.5.0
        window : {[beg, end]}, optional
            Window to use for the returned series. The default
            value is the default class domain

            .. versionadded:: 1.6.0
        symbol : str, optional
            Symbol representing the independent variable. Default is 'x'.

        Returns
        -------
        new_series : series
            A series that represents the least squares fit to the data and
            has the domain and window specified in the call. If the
            coefficients for the unscaled and unshifted basis polynomials are
            of interest, do ``new_series.convert().coef``.

        [resid, rank, sv, rcond] : list
            These values are only returned if ``full == True``

            - resid -- sum of squared residuals of the least squares fit
            - rank -- the numerical rank of the scaled Vandermonde matrix
            - sv -- singular values of the scaled Vandermonde matrix
            - rcond -- value of `rcond`.

            For more details, see `linalg.lstsq`.

        r   )wrE   rF   r!   r$   r   )	ri   	getdomainr   listrQ   r!   r$   r   rG   )r   r8   rC   rD   r!   rE   rF   r-  r$   r   xnewr   rR   statuss                 r   fitzABCPolyBase.fit  s    R >\\!_F&\T!c&kQ&6ZZF>ZZF||Avv.hhtQqDhA NT6DvF  DtF6&IIr   c                 v   t        j                  |gd      \  }|t        j                  |      }n+t        |      t        u rt        |      dk(  r| j                  }|| j                  }t        |      }t        j                  ||      \  }}|||z  z   }| j                  |      ||z  z  }	 | |	|||      S )a  Return series instance that has the specified roots.

        Returns a series representing the product
        ``(x - r[0])*(x - r[1])*...*(x - r[n-1])``, where ``r`` is a
        list of roots.

        Parameters
        ----------
        roots : array_like
            List of roots.
        domain : {[], None, array_like}, optional
            Domain for the resulting series. If None the domain is the
            interval from the smallest root to the largest. If [] the
            domain is the class domain. The default is [].
        window : {None, array_like}, optional
            Window for the returned series. If None the class window is
            used. The default is None.
        symbol : str, optional
            Symbol representing the independent variable. Default is 'x'.

        Returns
        -------
        new_series : series
            Series with the specified roots.

        Frf   r   r.  )
ri   rj   r/  r   r0  rQ   r!   r$   r   rO   )
r   r(  r!   r$   r   rD   rI   r>   rnewrR   s
             r   	fromrootszABCPolyBase.fromroots%  s    8 ,,wU3>\\%(F&\T!c&kQ&6ZZF>ZZF%j;;vv.SSY~~d#c3h.4vfEEr   c                     || j                   }|| j                  }t        j                  ||      \  }}| j	                  ||      } | ||||      S )a  Identity function.

        If ``p`` is the returned series, then ``p(x) == x`` for all
        values of x.

        Parameters
        ----------
        domain : {None, array_like}, optional
            If given, the array must be of the form ``[beg, end]``, where
            ``beg`` and ``end`` are the endpoints of the domain. If None is
            given then the class domain is used. The default is None.
        window : {None, array_like}, optional
            If given, the resulting array must be if the form
            ``[beg, end]``, where ``beg`` and ``end`` are the endpoints of
            the window. If None is given then the class window is used. The
            default is None.
        symbol : str, optional
            Symbol representing the independent variable. Default is 'x'.

        Returns
        -------
        new_series : series
             Series of representing the identity.

        )r!   r$   ri   r   rJ   )r   r!   r$   r   rI   r>   rR   s          r   r  zABCPolyBase.identityP  sU    6 >ZZF>ZZF;;vv.Syyc"400r   c                     || j                   }|| j                  }t        |      }||k7  s|dk  rt        d       | dg|z  dgz   |||      S )a\  Series basis polynomial of degree `deg`.

        Returns the series representing the basis polynomial of degree `deg`.

        .. versionadded:: 1.7.0

        Parameters
        ----------
        deg : int
            Degree of the basis polynomial for the series. Must be >= 0.
        domain : {None, array_like}, optional
            If given, the array must be of the form ``[beg, end]``, where
            ``beg`` and ``end`` are the endpoints of the domain. If None is
            given then the class domain is used. The default is None.
        window : {None, array_like}, optional
            If given, the resulting array must be if the form
            ``[beg, end]``, where ``beg`` and ``end`` are the endpoints of
            the window. If None is given then the class window is used. The
            default is None.
        symbol : str, optional
            Symbol representing the independent variable. Default is 'x'.

        Returns
        -------
        new_series : series
            A series with the coefficient of the `deg` term set to one and
            all others zero.

        r   z deg must be non-negative integerr   )r!   r$   r  rc   )r   rD   r!   r$   r   idegs         r   basiszABCPolyBase.basiss  s_    > >ZZF>ZZF3x3;$(?@@A3t8qc>666::r   c                 `    || j                   }|| j                  }|j                  || |      S )a  Convert series to series of this class.

        The `series` is expected to be an instance of some polynomial
        series of one of the types supported by by the numpy.polynomial
        module, but could be some other class that supports the convert
        method.

        .. versionadded:: 1.7.0

        Parameters
        ----------
        series : series
            The series instance to be converted.
        domain : {None, array_like}, optional
            If given, the array must be of the form ``[beg, end]``, where
            ``beg`` and ``end`` are the endpoints of the domain. If None is
            given then the class domain is used. The default is None.
        window : {None, array_like}, optional
            If given, the resulting array must be if the form
            ``[beg, end]``, where ``beg`` and ``end`` are the endpoints of
            the window. If None is given then the class window is used. The
            default is None.

        Returns
        -------
        new_series : series
            A series of the same kind as the calling class and equal to
            `series` when evaluated.

        See Also
        --------
        convert : similar instance method

        )r!   r$   r!  )r   seriesr!   r$   s       r   castzABCPolyBase.cast  s4    H >ZZF>ZZF~~fc622r   r   )NNr8   )F)r   )NNN)r   )r   N)NNFNNr8   )NN)^rs   
__module____qualname____doc____hash____array_ufunc__r5   r   	maketrans_superscript_mappingr   osrt   r   propertyr   abcabstractmethodr!   r$   r&   staticmethodr+   r-   r/   r1   r6   r9   r?   rA   rG   rJ   rL   rO   rW   rY   r\   r`   rd   rm   ru   r   rz   r{   classmethodr}   r|   r   r   r   floatr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r  r  r
  r  r  r  r   r  r  rg   r  r!  r   r$  r&  r(  r*  r3  r6  r  r:  r=  r    r   r   r   r      s   1h H O H ==*  (   ww$&L                                              .3$3$1$$L<,=;
,\     
3 
3 : : H H
"( " "u "&&2X
)


KKK	(

KKK)
	&	P!F&2K.K:#NJ5: 2D KBK,=@ CGYJ YJv %'S (F (FT  1  1D &; &;P '3 '3r   )r@  rE  rG  r   typingr   numpyrS   rw   r   ri   __all__ABCr   r    r   r   <module>rP     s7    
 
    /q3#'' q3r   