§
    OŠtjL'  ã                   óœ   — d dl mZmZ d dlmZmZ d dlmZmZ d dl	m
Z
 d dlmZ d dlmZ d„ Zd„ Z ed	¬
¦  «        d„ ¦   «         Zd„ Zd„ ZdS )é    )ÚSÚsympify)ÚDummyÚsymbols)Ú	PiecewiseÚpiecewise_fold)ÚAnd)ÚInterval)Ú	lru_cachec                 óÎ   — t          | t          ¦  «        r?t          | j        ¦  «        dk    r'| j        \  }}|j        |k    r||}}|j        |j        fS t          d| z  ¦  «        ‚)zÒreturn the interval corresponding to the condition

    Conditions in spline's Piecewise give the range over
    which an expression is valid like (lo <= x) & (x <= hi).
    This function returns (lo, hi).
    é   zunexpected cond type: %s)Ú
isinstancer	   ÚlenÚargsÚltsÚgtsÚ	TypeError)ÚcondÚxÚaÚbs       ú^/var/www/html/CA-Chatbot/venv/lib/python3.11/site-packages/sympy/functions/special/bsplines.pyÚ_ivlr   
   si   € õ �$�ÑÔð ¥ T¤Y¡¤°1Ò!4Ð!4ØŒy‰ˆˆ1ØŒ5�AŠ:ˆ:Ø�aˆqˆAØŒu�a”eˆ|ÐÝ
Ð.°Ñ5Ñ
6Ô
6Ð6ó    c                 ó  — t           j        || fv rt          ||z  ¦  «        }�nUt           j        ||fv rt          | |z  ¦  «        }�n1g }t          | |z  ¦  «        }t          ||z  ¦  «        }t          |j        dd…         ¦  «        }	|j        dd…         D ]©}
|
j        }|
j        }t          ||¦  «        d         }t          |	¦  «        D ]\\  }}|j        }|j        }t          ||¦  «        \  }}||k    r
||z  }|	|=  n'||k     r ||k    r| 	                    |¦  «         |	|=  nŒ]| 	                    ||f¦  «         Œª| 
                    |	¦  «         | 	                    d¦  «         t          |ddiŽ}|                     ¦   «         S )zConstruct c*b1 + d*b2.Néÿÿÿÿr   ©r   TÚevaluateF)r   ÚZeror   Úlistr   Úexprr   r   Ú	enumerateÚappendÚextendr   Úexpand)ÚcÚb1ÚdÚb2r   ÚrvÚnew_argsÚp1Úp2Úp2argsÚargr!   r   ÚlowerÚiÚarg2Úexpr2Úcond2Úlower_2Úupper_2s                       r   Ú_add_splinesr7      s¹  € õ 	„v�"�a�ÐÐÝ˜A ™FÑ#Ô#ˆ‰Ý	
Œ�B˜�7Ð	Ð	Ý˜A ™FÑ#Ô#ˆ‰àˆå˜A ™FÑ#Ô#ˆÝ˜A ™FÑ#Ô#ˆõ �b”g˜c˜r˜c”lÑ#Ô#ˆð ”7˜3˜B˜3”<ð 	*ð 	*ˆCØ”8ˆDØ”8ˆDå˜˜q‘M”M !Ô$ˆEõ % VÑ,Ô,ð ð ‘��4Øœ	�Øœ	�å#'¨¨q¡>¤>Ñ �˜Ø˜D’=�=à˜E‘M�Dà˜q˜	à�EØ˜u’_�_¨°EÒ)9Ð)9ð —O’O DÑ)Ô)Ð)Ø˜q˜	Ø�Eøð �OŠO˜T 4˜LÑ)Ô)Ð)Ð)ð 	�Š˜ÑÔÐð 	�Š˜	Ñ"Ô"Ð"å˜Ð1¨5Ð1Ð1ˆà�9Š9‰;Œ;Ðr   é€   )Úmaxsizec           	      ó�  — |}t          ¦   «         }t          d„ |D ¦   «         ¦  «        }t          | ¦  «        } t          |¦  «        }t          |¦  «        }|dz
  }|| z   dz   |k    rt	          d¦  «        ‚| dk    rMt          t          j        t          ||         ||dz            ¦  «         	                    |¦  «        fd¦  «        }nç| dk    rÏ||| z   dz            ||dz            z
  }|t          j
        k    r-||| z   dz            |z
  |z  }	t          | dz
  ||dz   |¦  «        }
nt          j
        x}
}	||| z            ||         z
  }|t          j
        k    r$|||         z
  |z  }t          | dz
  |||¦  «        }nt          j
        x}}t          |||	|
|¦  «        }nt	          d|z  ¦  «        ‚|                     ||i¦  «        S )a0  
    The $n$-th B-spline at $x$ of degree $d$ with knots.

    Explanation
    ===========

    B-Splines are piecewise polynomials of degree $d$. They are defined on a
    set of knots, which is a sequence of integers or floats.

    Examples
    ========

    The 0th degree splines have a value of 1 on a single interval:

        >>> from sympy import bspline_basis
        >>> from sympy.abc import x
        >>> d = 0
        >>> knots = tuple(range(5))
        >>> bspline_basis(d, knots, 0, x)
        Piecewise((1, (x >= 0) & (x <= 1)), (0, True))

    For a given ``(d, knots)`` there are ``len(knots)-d-1`` B-splines
    defined, that are indexed by ``n`` (starting at 0).

    Here is an example of a cubic B-spline:

        >>> bspline_basis(3, tuple(range(5)), 0, x)
        Piecewise((x**3/6, (x >= 0) & (x <= 1)),
                  (-x**3/2 + 2*x**2 - 2*x + 2/3,
                  (x >= 1) & (x <= 2)),
                  (x**3/2 - 4*x**2 + 10*x - 22/3,
                  (x >= 2) & (x <= 3)),
                  (-x**3/6 + 2*x**2 - 8*x + 32/3,
                  (x >= 3) & (x <= 4)),
                  (0, True))

    By repeating knot points, you can introduce discontinuities in the
    B-splines and their derivatives:

        >>> d = 1
        >>> knots = (0, 0, 2, 3, 4)
        >>> bspline_basis(d, knots, 0, x)
        Piecewise((1 - x/2, (x >= 0) & (x <= 2)), (0, True))

    It is quite time consuming to construct and evaluate B-splines. If
    you need to evaluate a B-spline many times, it is best to lambdify them
    first:

        >>> from sympy import lambdify
        >>> d = 3
        >>> knots = tuple(range(10))
        >>> b0 = bspline_basis(d, knots, 0, x)
        >>> f = lambdify(x, b0)
        >>> y = f(0.5)

    Parameters
    ==========

    d : integer
        degree of bspline

    knots : list of integer values
        list of knots points of bspline

    n : integer
        $n$-th B-spline

    x : symbol

    See Also
    ========

    bspline_basis_set

    References
    ==========

    .. [1] https://en.wikipedia.org/wiki/B-spline

    c              3   ó4   K  — | ]}t          |¦  «        V — Œd S ©N©r   )Ú.0Úks     r   ú	<genexpr>z bspline_basis.<locals>.<genexpr>ª   s(   è è € Ð,Ð, •'˜!‘*”*Ð,Ð,Ð,Ð,Ð,Ð,r   é   z(n + d + 1 must not exceed len(knots) - 1r   r   zdegree must be non-negative: %r)r   ÚtupleÚintr   Ú
ValueErrorr   r   ÚOner
   Úcontainsr   Úbspline_basisr7   Úxreplace)r(   ÚknotsÚnr   ÚxvarÚn_knotsÚn_intervalsÚresultÚdenomÚBr)   ÚAr'   s                r   rG   rG   T   sØ  € ðf €DÝ‰Œ€AåÐ,Ð, eÐ,Ñ,Ô,Ñ,Ô,€EÝˆA‰Œ€AÝˆA‰Œ€AÝ�%‰jŒj€GØ˜A‘+€KØˆ1�uˆq�y�;ÒÐÝÐCÑDÔDÐDØˆA‚v€vÝÝŒU•H˜U 1œX u¨Q°©U¤|Ñ4Ô4×=Ò=¸aÑ@Ô@ÐAÀ9ñ
ô 
ˆˆð 
ˆQŠˆØ�a˜!‘e˜a‘iÔ  5¨¨Q©¤<Ñ/ˆØ•A”FŠ?ˆ?Ø�q˜1‘u˜q‘yÔ! AÑ%¨Ñ.ˆAÝ˜q 1™u e¨Q°©U°AÑ6Ô6ˆBˆBå”VˆOˆB�à�a˜!‘e”˜u QœxÑ'ˆØ•A”FŠ?ˆ?Ø�U˜1”X‘ Ñ&ˆAÝ˜q 1™u e¨Q°Ñ2Ô2ˆBˆBå”VˆOˆB�å˜a  Q¨¨AÑ.Ô.ˆˆåÐ:¸QÑ>Ñ?Ô?Ð?ð �?Š?˜A˜t˜9Ñ%Ô%Ð%r   c                 ól   ‡ ‡‡— t          ‰¦  «        ‰ z
  dz
  }ˆ ˆˆfd„t          |¦  «        D ¦   «         S )a|  
    Return the ``len(knots)-d-1`` B-splines at *x* of degree *d*
    with *knots*.

    Explanation
    ===========

    This function returns a list of piecewise polynomials that are the
    ``len(knots)-d-1`` B-splines of degree *d* for the given knots.
    This function calls ``bspline_basis(d, knots, n, x)`` for different
    values of *n*.

    Examples
    ========

    >>> from sympy import bspline_basis_set
    >>> from sympy.abc import x
    >>> d = 2
    >>> knots = range(5)
    >>> splines = bspline_basis_set(d, knots, x)
    >>> splines
    [Piecewise((x**2/2, (x >= 0) & (x <= 1)),
               (-x**2 + 3*x - 3/2, (x >= 1) & (x <= 2)),
               (x**2/2 - 3*x + 9/2, (x >= 2) & (x <= 3)),
               (0, True)),
    Piecewise((x**2/2 - x + 1/2, (x >= 1) & (x <= 2)),
              (-x**2 + 5*x - 11/2, (x >= 2) & (x <= 3)),
              (x**2/2 - 4*x + 8, (x >= 3) & (x <= 4)),
              (0, True))]

    Parameters
    ==========

    d : integer
        degree of bspline

    knots : list of integers
        list of knots points of bspline

    x : symbol

    See Also
    ========

    bspline_basis

    rA   c                 óN   •— g | ]!}t          ‰t          ‰¦  «        |‰¦  «        ‘Œ"S © )rG   rB   )r>   r1   r(   rI   r   s     €€€r   ú
<listcomp>z%bspline_basis_set.<locals>.<listcomp>ý   s-   ø€ ÐKÐKÐK°Q�M˜!�U 5™\œ\¨1¨aÑ0Ô0ÐKÐKÐKr   )r   Úrange)r(   rI   r   Ú	n_spliness   ``` r   Úbspline_basis_setrX   Ì   sD   øøø€ õ` �E‘
”
˜Q‘ Ñ"€IØKÐKÐKÐKÐKÐK½%À	Ñ:JÔ:JÐKÑKÔKÐKr   c           
      óÜ  ‡‡‡— ddl m} ddlm} t	          | ¦  «        } | j        r| j        st          d| z  ¦  «        ‚t          |¦  «        t          |¦  «        k    rt          d¦  «        ‚t          |¦  «        | dz   k     rt          d¦  «        ‚t          d„ t          ||dd	…         ¦  «        D ¦   «         ¦  «        st          d
¦  «        ‚d„ |D ¦   «         }| j        r| dz   dz  }||| …         }n7| dz  }d„ t          ||| dz
  …         ||dz   | …         ¦  «        D ¦   «         }|d         g| dz   z  t          |¦  «        z   |d         g| dz   z  z   }t          | |‰¦  «        Šˆˆfd„|D ¦   «         }	 | ||	¦  «         ||¦  «        ft          d                     t          |¦  «        ¦  «        t           ¬¦  «        ¦  «        }
t          |
¦  «        d         }
d„ ‰D ¦   «         }t#          |ˆfd„¬¦  «        }d„ ‰D ¦   «         }g }|D ]MŠt%          ˆfd„t          |
|¦  «        D ¦   «         t&          j        ¦  «        }|                     |‰f¦  «         ŒNt-          |Ž S )a  
    Return spline of degree *d*, passing through the given *X*
    and *Y* values.

    Explanation
    ===========

    This function returns a piecewise function such that each part is
    a polynomial of degree not greater than *d*. The value of *d*
    must be 1 or greater and the values of *X* must be strictly
    increasing.

    Examples
    ========

    >>> from sympy import interpolating_spline
    >>> from sympy.abc import x
    >>> interpolating_spline(1, x, [1, 2, 4, 7], [3, 6, 5, 7])
    Piecewise((3*x, (x >= 1) & (x <= 2)),
            (7 - x/2, (x >= 2) & (x <= 4)),
            (2*x/3 + 7/3, (x >= 4) & (x <= 7)))
    >>> interpolating_spline(3, x, [-2, 0, 1, 3, 4], [4, 2, 1, 1, 3])
    Piecewise((7*x**3/117 + 7*x**2/117 - 131*x/117 + 2, (x >= -2) & (x <= 1)),
            (10*x**3/117 - 2*x**2/117 - 122*x/117 + 77/39, (x >= 1) & (x <= 4)))

    Parameters
    ==========

    d : integer
        Degree of Bspline strictly greater than equal to one

    x : symbol

    X : list of strictly increasing real values
        list of X coordinates through which the spline passes

    Y : list of real values
        list of corresponding Y coordinates through which the spline passes

    See Also
    ========

    bspline_basis_set, interpolating_poly

    r   )Úlinsolve)ÚMatrixz1Spline degree must be a positive integer, not %s.z/Number of X and Y coordinates must be the same.rA   z6Degree must be less than the number of control points.c              3   ó(   K  — | ]\  }}||k     V — Œd S r<   rT   ©r>   r   r   s      r   r@   z'interpolating_spline.<locals>.<genexpr>9  s*   è è € Ð/Ð/™˜˜Aˆq�1ŠuÐ/Ð/Ð/Ð/Ð/Ð/r   Nz.The x-coordinates must be strictly increasing.c                 ó,   — g | ]}t          |¦  «        ‘ŒS rT   r=   )r>   r1   s     r   rU   z(interpolating_spline.<locals>.<listcomp>;  s   € ÐÐÐ˜��‰ŒÐÐÐr   r   c                 ó$   — g | ]\  }}||z   d z  ‘ŒS )r   rT   r]   s      r   rU   z(interpolating_spline.<locals>.<listcomp>C  s1   € ð 
ð 
ð 
Ù˜!˜QˆQ�‰U�A‰Ið
ð 
ð 
r   r   c                 ó0   •‡— g | ]Šˆˆfd „‰D ¦   «         ‘ŒS )c                 ó<   •— g | ]}|                      ‰‰¦  «        ‘ŒS rT   )Úsubs)r>   r   Úvr   s     €€r   rU   z3interpolating_spline.<locals>.<listcomp>.<listcomp>K  s%   ø€ Ð	&Ð	&Ð	&˜1ˆ!�&Š&��A‰,Œ,Ð	&Ð	&Ð	&r   rT   )r>   rc   Úbasisr   s    @€€r   rU   z(interpolating_spline.<locals>.<listcomp>K  s2   øø€ Ð2Ð2Ð2¨1Ð	&Ð	&Ð	&Ð	&Ð	& Ð	&Ñ	&Ô	&Ð2Ð2Ð2r   zc0:{})Úclsc                 ó8   — h | ]}|j         D ]\  }}|d k    ¯|’ŒŒS )T©r   )r>   r   Úer&   s       r   ú	<setcomp>z'interpolating_spline.<locals>.<setcomp>O  s/   € ÐDÐDÐD�q°´ÐDÐD¡f q¨!¸!¸tº)¸)�¸)¸)¸)¸)r   c                 ó$   •— t          | ‰¦  «        S r<   )r   )r&   r   s    €r   ú<lambda>z&interpolating_spline.<locals>.<lambda>S  s   ø€ µ°Q¸±
´
€ r   )Úkeyc                 ó0   — g | ]}d „ |j         D ¦   «         ‘ŒS )c                 ó   — i | ]\  }}||“Œ	S rT   rT   )r>   rh   r&   s      r   ú
<dictcomp>z3interpolating_spline.<locals>.<listcomp>.<dictcomp>U  s   € Ð.Ð.Ð.™V˜a �A�qÐ.Ð.Ð.r   rg   )r>   r   s     r   rU   z(interpolating_spline.<locals>.<listcomp>U  s)   € Ð>Ð>Ð>°1Ð.Ð. q¤vÐ.Ñ.Ô.Ð>Ð>Ð>r   c                 ó\   •— g | ](\  }}||                      ‰t          j        ¦  «        z  ‘Œ)S rT   )Úgetr   r   )r>   r&   r(   r1   s      €r   rU   z(interpolating_spline.<locals>.<listcomp>Y  s2   ø€ ÐHÐHÐH¡f q¨!ˆQ�—’�q�!œ&Ñ!Ô!Ñ!ÐHÐHÐHr   )Úsympy.solvers.solvesetrZ   Úsympy.matrices.denser[   r   Ú
is_IntegerÚis_positiverD   r   ÚallÚzipÚis_oddr    rX   r   Úformatr   ÚsortedÚsumr   r   r#   r   )r(   r   ÚXÚYrZ   r[   ÚjÚinterior_knotsrI   rQ   ÚcoeffÚ	intervalsÚbasis_dictsÚsplineÚpiecerd   r1   s    `             @@r   Úinterpolating_spliner…      sÞ  øøø€ ð\ 0Ð/Ð/Ð/Ð/Ð/Ø+Ð+Ð+Ð+Ð+Ð+õ 	�‰
Œ
€AØŒLð R˜Qœ]ð RÝÐLÈqÑPÑQÔQÐQÝ
ˆ1�v„v•�Q‘”ÒÐÝÐJÑKÔKÐKÝ
ˆ1�v„v��A‘‚~€~ÝÐQÑRÔRÐRÝÐ/Ð/¥ Q¨¨!¨"¨"¬¡¤Ð/Ñ/Ô/Ñ/Ô/ð KÝÐIÑJÔJÐJØÐ˜QÐÑÔ€Að 	„xð 
Ø�‰U�q‰LˆØ˜1˜a˜R˜4œˆˆà�‰Fˆð
ð 
Ý"% a¨¨Q¨B°©F¨
¤m°Q°q¸1±uÀ¸r°z´]Ñ"CÔ"Cð
ñ 
ô 
ˆð ˆqŒTˆF�a˜!‘eÑ�t NÑ3Ô3Ñ3°q¸´u°gÀÀQÁÑ6GÑG€Eå˜a ¨Ñ*Ô*€Eà2Ð2Ð2Ð2Ð2°Ð2Ñ2Ô2€AàˆH�f�f˜Q‘i”i  ¨¡¤Ð+­W°W·^²^ÅCÈÁFÄFÑ5KÔ5KÕQVÐ-WÑ-WÔ-WÑXÔX€EÝ�‰KŒK˜ŒN€EØDÐD˜EÐDÑDÔD€Iõ �yÐ&:Ð&:Ð&:Ð&:Ð;Ñ;Ô;€Ià>Ð>¸Ð>Ñ>Ô>€KØ€FØð "ð "ˆÝØHÐHÐHÐHµ°E¸;Ñ0GÔ0GÐHÑHÔHÍ!Ì&ñ
ô 
ˆð 	�Š�u˜a�jÑ!Ô!Ð!Ð!Ý�fÐÐr   N)Ú
sympy.corer   r   Úsympy.core.symbolr   r   Úsympy.functionsr   r   Úsympy.logic.boolalgr	   Úsympy.sets.setsr
   Ú	functoolsr   r   r7   rG   rX   r…   rT   r   r   ú<module>rŒ      s   ðØ !Ð !Ð !Ð !Ð !Ð !Ð !Ð !Ø .Ð .Ð .Ð .Ð .Ð .Ð .Ð .Ø 5Ð 5Ð 5Ð 5Ð 5Ð 5Ð 5Ð 5Ø #Ð #Ð #Ð #Ð #Ð #Ø $Ð $Ð $Ð $Ð $Ð $à Ð Ð Ð Ð Ð ð7ð 7ð 7ð8ð 8ð 8ðv €�3ÐÑÔðt&ð t&ñ Ôðt&ðn1Lð 1Lð 1Lðh\ð \ð \ð \ð \r   