
    \hL'                         S SK JrJr  S SKJrJr  S SKJrJr  S SK	J
r
  S SKJr  S SKJr  S rS r\" S	S
9S 5       rS rS rg)    )Ssympify)Dummysymbols)	Piecewisepiecewise_fold)And)Interval)	lru_cachec                     [        U [        5      (       aQ  [        U R                  5      S:X  a8  U R                  u  p#UR                  U:X  a  X2p2UR                  UR
                  4$ [        SU -  5      e)zreturn 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       X/var/www/auris/envauris/lib/python3.13/site-packages/sympy/functions/special/bsplines.py_ivlr   
   s^     $TYY1!4yy55A:quuaee|
.5
66    c                 "   [         R                  X4;   a  [        X#-  5      nUR                  5       $ [         R                  X24;   a  [        X-  5      nUR                  5       $ / n[        X-  5      n[        X#-  5      n[        UR                  SS 5      n	UR                  SS  H  n
U
R
                  nU
R                  n[        X5      S   n[        U	5       H^  u  pUR
                  nUR                  n[        UU5      u  nnUU:X  a	  UU-  nX	   O'UU:  d  MC  UU::  d  MK  UR                  U5        X	   O   UR                  X45        M     UR                  U	5        UR                  S5        [        USS06nUR                  5       $ )zConstruct c*b1 + d*b2.Nr   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}    	vv"AF#h 99;g 
B7	AF#d 99;a AF#AF# bggcrl# 773B<C88D88DM!$E %V,				#'q> D=EMD	u_E)9 OOD)	% -* OOTL)9  > 	 		"15199;r      )maxsizec           	         Un[        5       n[        S U 5       5      n[        U 5      n [        U5      n[        U5      nUS-
  nX -   S-   U:  a  [	        S5      eU S:X  a=  [        [        R                  [        X   XS-      5      R                  U5      4S5      nOU S:  a  XU -   S-      XS-      -
  nU[        R                  :w  a$  XU -   S-      U-
  U-  n	[        U S-
  XS-   U5      n
O[        R                  =pXU -      X   -
  nU[        R                  :w  a  X1U   -
  U-  n[        U S-
  XU5      nO[        R                  =p[        XXU5      nO[	        SU-  5      eUR                  X405      $ )aL  
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   8   #    U  H  n[        U5      v   M     g 7fN)r   ).0ks     r   	<genexpr> bspline_basis.<locals>.<genexpr>   s     ,e'!**es      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%jGA+Kuqy;CDDAvUUHUXuU|4==a@A9
 
Q!eai 5Q</AFF?1uqy!A%.Aq1ueUA6BVVOB!eux'AFF?1X&Aq1ue2BVVOBaQA.:Q>?? ??A9%%r   c           	          [        U5      U -
  S-
  n[        U5       Vs/ s H  n[        U [        U5      XB5      PM     sn$ s  snf )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   )r   rangerG   rB   )r(   rI   r   	n_splinesr1   s        r   bspline_basis_setrU      sC    ` E
Q"I:?	:JK:JQM!U5\10:JKKKs    Ac                   ^ SSK Jn  SSKJn  [	        U 5      n U R
                  (       a  U R                  (       d  [        SU -  5      e[        U5      [        U5      :w  a  [        S5      e[        U5      U S-   :  a  [        S5      e[        S [        X"SS	 5       5       5      (       d  [        S
5      eU Vs/ s H  n[	        U5      PM     nnU R                  (       a  U S-   S-  nX'U*  nO6U S-  n[        X'U* S-
   X'S-   U*  5       V	V
s/ s H  u  pX-   S-  PM     nn	n
US   /U S-   -  [        U5      -   US   /U S-   -  -   n[        XT5      nU VV
s/ s H$  o V
s/ s H  oR                  TU5      PM     sn
PM&     nnn
U" U" U5      U" U5      4[        SR!                  [        U5      5      ["        S95      n[        U5      S   nU V
VVs1 s H#  oR$                    H  u  nnUS:w  d  M  UiM     M%     nnn
n['        UU4S jS9nU V
VVs/ s H%  oR$                   VVs0 s H	  u  nnUU_M     snnPM'     nnn
n/ nU Hq  n[)        [        UU5       VV s/ s H)  u  nn UU R+                  U[,        R.                  5      -  PM+     sn n[,        R.                  5      nUR1                  UU45        Ms     [3        U6 $ s  snf s  sn
n	f s  sn
f s  sn
nf s  snnn
f s  snnf s  snnn
f s  sn nf )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   .   #    U  H  u  pX:  v   M     g 7fr<    )r=   r   r   s      r   r?   'interpolating_spline.<locals>.<genexpr>9  s     /qus   Nz.The x-coordinates must be strictly increasing.r   r   zc0:{})clsTc                    > [        U T5      $ r<   )r   )r&   r   s    r   <lambda>&interpolating_spline.<locals>.<lambda>S  s    Q
r   )key)sympy.solvers.solvesetrW   sympy.matrices.denserX   r   
is_Integeris_positiverD   r   allzipis_oddr    rU   subsr   formatr   r   sortedsumgetr   r   r#   r   )r(   r   XYrW   rX   r1   jinterior_knotsr   r   rI   basisvrQ   coeffer&   	intervalsbasis_dictssplinepieces    `                    r   interpolating_splinery      s   \ 0+ 	
ALLQ]]LqPQQ
1vQJKK
1vA~QRR/Q!"///IJJQQA 	xxUqLaRF"%aQBFmQ1ur]"C
"C$!QUAI"C 	 
 qTFa!etN33qugQ6GGEa*E0121	&1&&A,	&A2fQi+WW^^CF5KQV-WXEKNE!DEqfq!!t)EID y&:;I8=>1vv.vVaAqDv.K>F03E;0GH0Gfq!Qq!&&!!0GH!&&
 	uaj!	 
 fC 	 
 
'2 E /> IsN   ;KK	K&KKK#:
K#K00K* K0'0K7K*K0N)
sympy.corer   r   sympy.core.symbolr   r   sympy.functionsr   r   sympy.logic.boolalgr	   sympy.sets.setsr
   	functoolsr   r   r7   rG   rU   ry   rZ   r   r   <module>r      sK    ! . 5 # $ 78v 3t& t&n1Lh\r   