
    Ui                     `    d dl Z d dlZd dlmZ d dlmZmZ d dlmZ  G d de          Z	d Z
dS )    N)cached_property)array_namespace	np_compat)NestedFixedRulec                   F    e Zd ZdZddZed             Zed             ZdS )	GenzMalikCubaturea  
    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                     |dk     rt          d          |dk    s|dk    rt          d          || _        || _        || _        |t
          }t          |                    d                    | _        d S )N   z1Genz-Malik cubature is only defined for ndim >= 2r	   r
   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        z/var/www/development/aibuddy-work/election-extract/venv/lib/python3.11/site-packages/scipy/integrate/_rules/_genz_malik.py__init__zGenzMalikCubature.__init__;   s    !88PQQQQ;;,!++% 'E F F F 	(:B!"((1++..    c                    t          j        d          }t          j        d          }t          j        d          }t          j        d          }t          j        d| j        z  gt          |fd| j        dz
  z  z             t          | fd| j        dz
  z  z             t          |fd| j        dz
  z  z             t          | fd| j        dz
  z  z             t          ||fd| j        dz
  z  z             t          || fd| j        dz
  z  z             t          | | fd| j        dz
  z  z             t          j        || f| j                  	  	        }dd| j        dz   z  | j        z  z   d| j        z  z   }| j                            t          t          |           | j        j                  }| j                            || j        |f          }|j        }d| j        z  d	d
| j        z  z
  d| j        dz  z  z   z  dz  }d| j        z  dz  dz  }	d| j        z  dd| j        z  z
  z  dz  }
d| j        z  dz  }d}| j                            | j                            |gdz  | j        j                  | j                            |	gd| j        z  z  | j        j                  | j                            |
gd| j        z  z  | j        j                  | j                            |gd| j        dz
  z  | j        z  z  | j        j                  | j                            |gd| j        z  z  | j        j                  g          }||fS )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_weightsz#GenzMalikCubature.nodes_and_weightsL   s?    iooiooiooioooDI"C6DDIM,B#BCC"SD7TTY]-C#CDD"C6DDIM,B#BCC"SD7TTY]-C#CDD"C:	A0F#FGG"C#;Q1G#GHH"SD3$<$$)a-2H#HIIsSDk$)<<<

 

 !ty1}-	9:Q	\I
cOO'/   
 

 	:'>??
  	\ed49n4dil8JKLuT 	 $)|s"4'$)|sTY 67%?$)|,'..GOOSEAITW_O==GOOSEQ]347?OKKGOOSEQ]347?OKKGOOdi!m,ty89go    GOOSEQ	\2$'/OJJ	"
 	 	 g~r   c                    t          j        d          }t          j        d          }t          j        d          }t          j        d| j        z  gt          |fd| j        dz
  z  z             t          | fd| j        dz
  z  z             t          |fd| j        dz
  z  z             t          | fd| j        dz
  z  z             t          ||fd| j        dz
  z  z             t          || fd| j        dz
  z  z             t          | | fd| j        dz
  z  z                       }dd| j        dz   z  | j        z  z   }| j                            t          t          |           | j        j
                  }| j                            || j        |f          }|j        }d| j        z  dd| j        z  z
  d	| j        dz  z  z   z  dz  }d| j        z  d
z  }d| j        z  dd| j        z  z
  z  dz  }	d| j        z  dz  }
| j                            | j                            |gdz  | j        j
                  | j                            |gd| j        z  z  | j        j
                  | j                            |	gd| j        z  z  | j        j
                  | j                            |
gd| j        dz
  z  | j        z  z  | j        j
                  g          }||fS )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-   r.   r/   r1   r2   r3   r4   r5   r6   r7   r9   s               r   lower_nodes_and_weightsz)GenzMalikCubature.lower_nodes_and_weights   s    iooiooioooDI"C6DDIM,B#BCC"SD7TTY]-C#CDD"C6DDIM,B#BCC"SD7TTY]-C#CDD"C:	A0F#FGG"C#;Q1G#GHH"SD3$<$$)a-2H#HII	
 	
 !ty1}-	9:
S#YtwGG	:'>?? $)|c$)m 3bAo EFL$)|	*$)|c$)m 34t;$)|)'..GOOSEAITW_O==GOOSEQ]347?OKKGOOSEQ]347?OKKGOOdi!m,ty89go   	"
   g~r   )r	   r
   N)__name__
__module____qualname____doc__r   r   r:   r>    r   r   r   r      sj        - -^/ / / /" 5 5 _5n + + _+ + +r   r   c              #   x  K   t          |           }t          |          }	 t          |          V  t          |dz
  dd          D ]}||         ||dz            k     r ndS t          |dz
  |d          D ]}||         ||         k     r n||         ||         c||<   ||<   |d||z
  d         ||dz   d<   )zM
    Find the number of distinct permutations of elements of `iterable`.
    Tr   r   N)sortedlentuplerange)iterableitemssizeijs        r   r$   r$      s      8Eu::D(Ell taxR(( 	 	AQx%A,&& '
 F taxB'' 	 	AQx%("" #
 #1XuQxa%(JQtVBJ'acdd+(r   )r    r"   	functoolsr   scipy._lib._array_apir   r   scipy.integrate._rulesr   r   r$   rC   r   r   <module>rR      s         % % % % % % < < < < < < < < 2 2 2 2 2 2e e e e e e e eP( ( ( ( (r   