
    -i                     X    S SK r S SKrS SKJr  S SKJrJr  S SKJr   " S S\5      r	S r
g)    N)cached_property)array_namespace	np_compat)NestedFixedRulec                   B    \ rS rSrSrSS jr\S 5       r\S 5       rSr	g)	GenzMalikCubature   a  
Genz-Malik cubature.

Genz-Malik is only defined for integrals of dimension >= 2.

Parameters
----------
ndim : int
    The spatial dimension of the integrand.

xp : array_namespace, optional
    The namespace for the node and weight arrays. Default is None, where NumPy is
    used.

Attributes
----------
higher : Cubature
    Higher-order rule.

lower : Cubature
    Lower-order rule.

References
----------
.. [1] A.C. Genz, A.A. Malik, Remarks on algorithm 006: An adaptive algorithm for
    numerical integration over an N-dimensional rectangular region, Journal of
    Computational and Applied Mathematics, Volume 6, Issue 4, 1980, Pages 295-302,
    ISSN 0377-0427, https://doi.org/10.1016/0771-050X(80)90039-X.

Examples
--------
Evaluate a 3D integral:

>>> import numpy as np
>>> from scipy.integrate import cubature
>>> from scipy.integrate._rules import GenzMalikCubature
>>> def f(x):
...     # f(x) = cos(x_1) + cos(x_2) + cos(x_3)
...     return np.sum(np.cos(x), axis=-1)
>>> rule = GenzMalikCubature(3) # Use 3D Genz-Malik
>>> a, b = np.array([0, 0, 0]), np.array([1, 1, 1])
>>> rule.estimate(f, a, b) # True value 3*sin(1), approximately 2.5244
 np.float64(2.5244129547230862)
>>> rule.estimate_error(f, a, b)
 np.float64(1.378269656626685e-06)
Nc                     US:  a  [        S5      eUS:w  d  US:w  a  [        S5      eXl        X l        X0l        Uc  [
        n[        UR                  S5      5      U l        g )N   z1Genz-Malik cubature is only defined for ndim >= 2      zKGenz-Malik cubature is currently only supportedfor degree=7, lower_degree=5r   )	
ValueErrorNotImplementedErrorndimdegreelower_degreer   r   emptyxp)selfr   r   r   r   s        U/var/www/html/venv/lib/python3.13/site-packages/scipy/integrate/_rules/_genz_malik.py__init__GenzMalikCubature.__init__;   sh    !8PQQQ;,!+% 'E F F 	(:B!"((1+.    c                    [         R                  " S5      n[         R                  " S5      n[         R                  " S5      n[         R                  " S5      n[        R                  " SU R                  -  /[        U4SU R                  S-
  -  -   5      [        U* 4SU R                  S-
  -  -   5      [        U4SU R                  S-
  -  -   5      [        U* 4SU R                  S-
  -  -   5      [        X34SU R                  S-
  -  -   5      [        X3* 4SU R                  S-
  -  -   5      [        U* U* 4SU R                  S-
  -  -   5      [        R                  " XD* 4U R                  S95	      nSSU R                  S-   -  U R                  -  -   SU R                  -  -   nU R                  R                  [        [        U6 5      U R                  R                  S9nU R                  R                  XpR                  U45      nUR                  nSU R                  -  S	S
U R                  -  -
  SU R                  S-  -  -   -  S-  nSU R                  -  S-  S-  n	SU R                  -  SSU R                  -  -
  -  S-  n
SU R                  -  S-  nSnU R                  R                  U R                  R                  U/S-  U R                  R                  S9U R                  R                  U	/SU R                  -  -  U R                  R                  S9U R                  R                  U
/SU R                  -  -  U R                  R                  S9U R                  R                  U/SU R                  S-
  -  U R                  -  -  U R                  R                  S9U R                  R                  U/SU R                  -  -  U R                  R                  S9/5      nX}4$ )NPuPu??g5P?r      r   )repeatdtypei2  i#  i  iL  i  i  i  gSgQτ?gbM?)mathsqrt	itertoolschainr   _distinct_permutationsproductr   asarraylistzipfloat64reshapeTconcat)r   l_2l_3l_4l_5its
nodes_sizenodesw_1w_2w_3w_4w_5weightss                 r   nodes_and_weights#GenzMalikCubature.nodes_and_weightsL   sV    iioiioiioiioooDII"C6DDIIM,B#BC"SD7TTYY]-C#CD"C6DDIIM,B#BC"SD7TTYY]-C#CD"C:		A0F#FG"C;Q1G#GH"SD3$<$$))a-2H#HIsDk$))<

 !tyy1}-		9:Q		\I
cO''//   

 		:'>?
  		\ed499n4diil8JKLuT 	 $))|s"4'$))|sTYY 67%?$))|,''..GGOOSEAITWW__O=GGOOSEQ]3477??OKGGOOSEQ]3477??OKGGOOdii!m,tyy89ggoo   GGOOSEQ		\2$''//OJ	"
 	 ~r   c                    [         R                  " S5      n[         R                  " S5      n[         R                  " S5      n[        R                  " SU R                  -  /[        U4SU R                  S-
  -  -   5      [        U* 4SU R                  S-
  -  -   5      [        U4SU R                  S-
  -  -   5      [        U* 4SU R                  S-
  -  -   5      [        X34SU R                  S-
  -  -   5      [        X3* 4SU R                  S-
  -  -   5      [        U* U* 4SU R                  S-
  -  -   5      5      nSSU R                  S-   -  U R                  -  -   nU R                  R                  [        [        U6 5      U R                  R                  S9nU R                  R                  X`R                  U45      nUR                  nSU R                  -  SSU R                  -  -
  S	U R                  S-  -  -   -  S-  nSU R                  -  S
-  nSU R                  -  SSU R                  -  -
  -  S-  n	SU R                  -  S-  n
U R                  R                  U R                  R                  U/S-  U R                  R                  S9U R                  R                  U/SU R                  -  -  U R                  R                  S9U R                  R                  U	/SU R                  -  -  U R                  R                  S9U R                  R                  U
/SU R                  S-
  -  U R                  -  -  U R                  R                  S9/5      nXk4$ )Nr   r   r   r   r   r    i  i  2   gQA!?i	  d   i  g>쎡?)r"   r#   r$   r%   r   r&   r   r(   r)   r*   r+   r,   r-   r.   )r   r/   r0   r1   r3   r4   r5   r6   r7   r8   r9   r;   s               r   lower_nodes_and_weights)GenzMalikCubature.lower_nodes_and_weights   s    iioiioiioooDII"C6DDIIM,B#BC"SD7TTYY]-C#CD"C6DDIIM,B#BC"SD7TTYY]-C#CD"C:		A0F#FG"C;Q1G#GH"SD3$<$$))a-2H#HI	
 !tyy1}-		9:
S#YtwwG		:'>? $))|c$))m 3bAo EFL$))|	*$))|c$))m 34t;$))|)''..GGOOSEAITWW__O=GGOOSEQ]3477??OKGGOOSEQ]3477??OKGGOOdii!m,tyy89ggoo  	"
  ~r   )r   r   r   r   )r   r   N)
__name__
__module____qualname____firstlineno____doc__r   r   r<   rA   __static_attributes__ r   r   r   r      s6    -^/" 5 5n + +r   r   c              #   $  #    [        U 5      n[        U5      n [        U5      v   [        US-
  SS5       H  nX   XS-      :  d  M    O   g[        US-
  US5       H  nX   X   :  d  M    O   UW   X   sX'   X'   USX2-
  S2   XS-   S& Mv  7f)zE
Find the number of distinct permutations of elements of `iterable`.
r   r   N)sortedlentuplerange)iterableitemssizeijs        r   r&   r&      s      8Eu:D
El taxR(Ax%A,& )  taxB'Ax%(" ( #1Xux%(JQVBJ'cd+ s   AB	 B-#B)r"   r$   	functoolsr   scipy._lib._array_apir   r   scipy.integrate._rulesr   r   r&   rI   r   r   <module>rX      s(      % < 2e eP(r   