
    \h;                     8   S SK Jr  S SKJr  S SKJr  S SK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 S	KJr  S S
KJr  S SKJr  S SKJr  S SKJr  S SKJr  S SKJr  S SKJ r J!r!J"r"J#r#  S SK$J%r%  S SK&J'r'  S SK(J)r)  / SQr*\#RV                  " \"5      S 5       r, " S S\5      r- " S S\-5      r. " S S\.5      r/ " S S\.5      r0 " S S\.5      r1S  r2S! r3S" r4S# r5 " S$ S%\-5      r6 " S& S'\65      r7 " S( S)\65      r8 " S* S+\65      r9S, r:S- r;S. r<S/ r=S0 r>S1 r?S2 r@g3)4    )Product)Sum)Basic)Lambda)Ipi)S)Dummy)Abs)exp)gamma)Integral)MatrixSymbol)Trace)IndexedBase)_sympify)_symbol_converterDensityRandomMatrixSymbol	is_random)JointDistributionHandmade)RandomMatrixPSpace)ArrayComprehension)CircularEnsembleCircularUnitaryEnsembleCircularOrthogonalEnsembleCircularSymplecticEnsembleGaussianEnsembleGaussianUnitaryEnsembleGaussianOrthogonalEnsembleGaussianSymplecticEnsemblejoint_eigen_distributionJointEigenDistributionlevel_spacing_distributionc                     g)NT )xs    X/var/www/auris/envauris/lib/python3.13/site-packages/sympy/stats/random_matrix_models.py_r)   #   s        c                   R    \ rS rSrSrS
S jr\" S 5      r\" S 5      rS r	S r
S	rg)RandomMatrixEnsembleModel(   z
Base class for random matrix ensembles.
It acts as an umbrella and contains
the methods common to all the ensembles
defined in sympy.stats.random_matrix_models.
Nc                     [        U5      [        U5      p!UR                  S:X  a  [        SU-  5      e[        R
                  " XU5      $ )NFzGDimension of the random matrices must be integers, received %s instead.)r   r   
is_integer
ValueErrorr   __new__)clssymdims      r(   r1   !RandomMatrixEnsembleModel.__new__/   sM    $S)8C=S>>U" ABEG H H}}Ss++r*   c                      U R                   S   $ )Nr   argsselfs    r(   <lambda>"RandomMatrixEnsembleModel.<lambda>6   s    499Q<r*   c                      U R                   S   $ )N   r7   r9   s    r(   r;   r<   7   s    diilr*   c                     [        U5      $ N)r   r:   exprs     r(   density!RandomMatrixEnsembleModel.density9   s    t}r*   c                 $    U R                  U5      $ r@   )rC   rA   s     r(   __call__"RandomMatrixEnsembleModel.__call__<   s    ||D!!r*   r&   r@   )__name__
__module____qualname____firstlineno____doc__r1   propertysymbol	dimensionrC   rF   __static_attributes__r&   r*   r(   r,   r,   (   s.    , /0F23I"r*   r,   c                   $    \ rS rSrSrS rS rSrg)GaussianEnsembleModel?   z
Abstract class for Gaussian ensembles.
Contains the properties common to all the
gaussian ensembles.

References
==========

.. [1] https://en.wikipedia.org/wiki/Random_matrix#Gaussian_ensembles
.. [2] https://arxiv.org/pdf/1712.07903.pdf
c                    ^ [        U5      nU4S jn[        SSSS9n[        U" U5      USU45      R                  5       nSTU-  -  TU-  US-
  -  S-  US-  -   -  nS[        -  US-  -  nXV-  U-  $ )z
Helper function for computing normalization
constant for joint probability density of eigen
values of Gaussian ensembles.

References
==========

.. [1] https://en.wikipedia.org/wiki/Selberg_integral#Mehta's_integral
c                    > [        ST[        U 5      -  S-  -   5      [        [        R                  T[        S5      -  -   5      -  $ )Nr>      )r   r	   One)jbetas    r(   r;   GGaussianEnsembleModel._compute_normalization_constant.<locals>.<lambda>W   s5    eAQqT	!O4U1554!9;L5MMr*   rX   Tintegerpositiver>   rV      )r	   r
   r   doitr   )r:   rY   n	prod_termrX   term1term2term3s    `      r(   _compute_normalization_constant5GaussianEnsembleModel._compute_normalization_constantK   s     aDM	#td3	!q!Qi0557DFtAvq1u~a/!A#5621}u$$r*   c           
      @   U R                   nU R                  X5      n[        S5      n[        SSSS9n[        SSSS9n[        SSSS9n[	        [        U5      * S-  [        XG   S-  USU45      R                  5       -  5      n[        U[        [        XF   XE   -
  5      U-  XeS-   U45      5      n	[        U	" U5      R                  5       USUS-
  45      R                  5       n
[        XG   USU45      R                  5       n[        [        U5      X-  U-  5      $ )	zh
Helper function for computing the joint
probability distribution of eigen values
of the random matrix.
liTr[   rX   krV   r>   )rO   re   r   r
   r   r	   r   r_   r   r   r   r   tuple)r:   rY   r`   Zbnrh   ri   rX   rj   rb   sub_termrc   symss               r(   !_compute_joint_eigen_distribution7GaussianEnsembleModel._compute_joint_eigen_distribution^   s    NN224;#td3#td3#td3adU1WAD!GaAY 7 < < >>?!WS%5t%;aQ]KL((*Q1q5M:??A!!$Aq	2779eDkEM3#677r*   r&   N)rH   rI   rJ   rK   rL   re   ro   rP   r&   r*   r(   rR   rR   ?   s    
%&8r*   rR   c                   6    \ rS rSr\S 5       rS rS rS rSr	g)GaussianUnitaryEnsembleModelp   c                 n    U R                   nS[        U5      S-  -  [        [        US-  5      S-  -  -  $ NrV   )rO   r	   r   )r:   r`   s     r(   normalization_constant3GaussianUnitaryEnsembleModel.normalization_constantq   s2    NN1Q46{R!AqD'!)_,,r*   c           
          U R                   U R                  p2[        SU S9n[        SX"US9n[	        U[        [        U5      * S-  [        US-  5      -  5      U-  5      " U5      $ NPmodelHpspacerV   rO   rv   r   r   r   r   r	   r   )r:   rB   r`   ZGUEh_pspacer}   s         r(   rC   $GaussianUnitaryEnsembleModel.densityv   `    ..$"="=4%c6sA:aadU1WuQT{23D89$??r*   c                 6    U R                  [        S5      5      $ ru   ro   r	   r9   s    r(   r"   5GaussianUnitaryEnsembleModel.joint_eigen_distribution|       55ad;;r*   c                     [        S5      nS[        S-  -  US-  -  [        S[        -  US-  -  5      -  n[        X5      $ )Ns    rV   r
   r   r   r   r:   r   fs      r(   r$   7GaussianUnitaryEnsembleModel.level_spacing_distribution   sA    #JAX1c2b5!Q$,//a|r*   r&   N
rH   rI   rJ   rK   rM   rv   rC   r"   r$   rP   r&   r*   r(   rr   rr   p   s$    - -@<r*   rr   c                   6    \ rS rSr\S 5       rS rS rS rSr	g)GaussianOrthogonalEnsembleModel   c           	          U R                   n[        SX5      n[        [        [	        U5      * S-  [        US-  5      -  5      5      $ )N_Hr^   rV   rO   r   r   r   r	   r   r:   r`   r   s      r(   rv   6GaussianOrthogonalEnsembleModel.normalization_constant   s>    NN$%QqTE!GeBEl2344r*   c           
          U R                   U R                  p2[        SU S9n[        SX"US9n[	        U[        [        U5      * S-  [        US-  5      -  5      U-  5      " U5      $ )Nrz   r{   r}   r~   r^   rV   r   )r:   rB   r`   ZGOEr   r}   s         r(   rC   'GaussianOrthogonalEnsembleModel.density   r   r*   c                 @    U R                  [        R                  5      $ r@   ro   r	   rW   r9   s    r(   r"   8GaussianOrthogonalEnsembleModel.joint_eigen_distribution       55aee<<r*   c                 z    [        S5      n[        S-  U-  [        [        * S-  US-  -  5      -  n[        X5      $ )Nr   rV   r^   r   r   s      r(   r$   :GaussianOrthogonalEnsembleModel.level_spacing_distribution   s:    #JT1HS2#a%A&&a|r*   r&   Nr   r&   r*   r(   r   r      s$    5 5
@=r*   r   c                   6    \ rS rSr\S 5       rS rS rS rSr	g)GaussianSymplecticEnsembleModel   c           	          U R                   n[        SX5      n[        [        [	        U5      * [        US-  5      -  5      5      $ )Nr   rV   r   r   s      r(   rv   6GaussianSymplecticEnsembleModel.normalization_constant   s:    NN$%QqTEE"a%L0122r*   c           
          U R                   U R                  p2[        SU S9n[        SX"US9n[	        U[        [        U5      * [        US-  5      -  5      U-  5      " U5      $ ry   r   )r:   rB   r`   ZGSEr   r}   s         r(   rC   'GaussianSymplecticEnsembleModel.density   s\    ..$"="=4%c6sA:aadUU1a4[01$67==r*   c                 6    U R                  [        S5      5      $ Nr^   r   r9   s    r(   r"   8GaussianSymplecticEnsembleModel.joint_eigen_distribution   r   r*   c                     [        S5      n[        S5      S-  [        S5      S-  [        S-  -  -  US-  -  [        SS[        -  -  US-  -  5      -  n[	        X5      $ )	Nr   rV            r^   i	   )r
   r	   r   r   r   r   s      r(   r$   :GaussianSymplecticEnsembleModel.level_spacing_distribution   s\    #JdBh!A$'BE*+ad3CadQT8I4JJa|r*   r&   Nr   r&   r*   r(   r   r      s#    3 3
><r*   r   c                 h    [        U 5      [        U5      p[        X5      n[        XS9n[	        XXS9$ Nr{   r~   )r   r   rR   r   r   r3   r4   r|   rmps       r(   r   r      3     %x}!#+E
S
.Cc88r*   c                 h    [        U 5      [        U5      p[        X5      n[        XS9n[	        XXS9$ )a  
Represents Gaussian Unitary Ensembles.

Examples
========

>>> from sympy.stats import GaussianUnitaryEnsemble as GUE, density
>>> from sympy import MatrixSymbol
>>> G = GUE('U', 2)
>>> X = MatrixSymbol('X', 2, 2)
>>> density(G)(X)
exp(-Trace(X**2))/(2*pi**2)
r{   r~   )r   r   rr   r   r   r   s       r(   r   r      s5     !%x}(2E
S
.Cc88r*   c                 h    [        U 5      [        U5      p[        X5      n[        XS9n[	        XXS9$ )a&  
Represents Gaussian Orthogonal Ensembles.

Examples
========

>>> from sympy.stats import GaussianOrthogonalEnsemble as GOE, density
>>> from sympy import MatrixSymbol
>>> G = GOE('U', 2)
>>> X = MatrixSymbol('X', 2, 2)
>>> density(G)(X)
exp(-Trace(X**2)/2)/Integral(exp(-Trace(_H**2)/2), _H)
r{   r~   )r   r   r   r   r   r   s       r(   r    r       5     !%x}+C5E
S
.Cc88r*   c                 h    [        U 5      [        U5      p[        X5      n[        XS9n[	        XXS9$ )a&  
Represents Gaussian Symplectic Ensembles.

Examples
========

>>> from sympy.stats import GaussianSymplecticEnsemble as GSE, density
>>> from sympy import MatrixSymbol
>>> G = GSE('U', 2)
>>> X = MatrixSymbol('X', 2, 2)
>>> density(G)(X)
exp(-2*Trace(X**2))/Integral(exp(-2*Trace(_H**2)), _H)
r{   r~   )r   r   r   r   r   r   s       r(   r!   r!      r   r*   c                   $    \ rS rSrSrS rS rSrg)CircularEnsembleModel   z
Abstract class for Circular ensembles.
Contains the properties and methods
common to all the circular ensembles.

References
==========

.. [1] https://en.wikipedia.org/wiki/Circular_ensemble
c                     [        SU -  5      e)NzeSupport for Haar measure hasn't been implemented yet, therefore the density of %s cannot be computed.)NotImplementedErrorrA   s     r(   rC   CircularEnsembleModel.density   s!     " #;<@#B C 	Cr*   c                 2   U R                   nS[        -  U-  [        X-  S-  S-   5      [        [        US-  S-   5      5      U-  -  -  n[	        S5      n[        SSS9[        SSS9[        SSS9pvn[        XE   USU45      R                  5       n[        [        [        [        [        XG   -  5      [        [        XF   -  5      -
  5      U-  XgS-   U45      R                  5       USUS-
  45      R                  5       n	[        [        U5      X-  5      $ )	z
Helper function to compute the joint distribution of phases
of the complex eigen values of matrices belonging to any
circular ensembles.
rV   r>   tri   T)r\   rX   rj   )rO   r   r   r	   r   r
   r   r_   r   r   r   r   r   rk   )
r:   rY   r`   rl   r   ri   rX   rj   rn   r   s
             r(   ro   7CircularEnsembleModel._compute_joint_eigen_distribution   s    NN"qy5A.qtAvz1B/CQ/FFGd+U3-Ed+ !!$Aq	2779GCAadFc!AD&k 9:D@1!eQ-PUUW1q5M##'46 	
eDk15))r*   r&   N)rH   rI   rJ   rK   rL   rC   ro   rP   r&   r*   r(   r   r      s    	C*r*   r   c                       \ rS rSrS rSrg)CircularUnitaryEnsembleModeli  c                 6    U R                  [        S5      5      $ ru   r   r9   s    r(   r"   5CircularUnitaryEnsembleModel.joint_eigen_distribution  r   r*   r&   NrH   rI   rJ   rK   r"   rP   r&   r*   r(   r   r         <r*   r   c                       \ rS rSrS rSrg)CircularOrthogonalEnsembleModeli  c                 @    U R                  [        R                  5      $ r@   r   r9   s    r(   r"   8CircularOrthogonalEnsembleModel.joint_eigen_distribution  r   r*   r&   Nr   r&   r*   r(   r   r     s    =r*   r   c                       \ rS rSrS rSrg)CircularSymplecticEnsembleModeli  c                 6    U R                  [        S5      5      $ r   r   r9   s    r(   r"   8CircularSymplecticEnsembleModel.joint_eigen_distribution  r   r*   r&   Nr   r&   r*   r(   r   r     r   r*   r   c                 h    [        U 5      [        U5      p[        X5      n[        XS9n[	        XXS9$ r   )r   r   r   r   r   r   s       r(   r   r     r   r*   c                 h    [        U 5      [        U5      p[        X5      n[        XS9n[	        XXS9$ )a   
Represents Circular Unitary Ensembles.

Examples
========

>>> from sympy.stats import CircularUnitaryEnsemble as CUE
>>> from sympy.stats import joint_eigen_distribution
>>> C = CUE('U', 1)
>>> joint_eigen_distribution(C)
Lambda(t[1], Product(Abs(exp(I*t[_j]) - exp(I*t[_k]))**2, (_j, _k + 1, 1), (_k, 1, 0))/(2*pi))

Note
====

As can be seen above in the example, density of CiruclarUnitaryEnsemble
is not evaluated because the exact definition is based on haar measure of
unitary group which is not unique.
r{   r~   )r   r   r   r   r   r   s       r(   r   r   !  s5    ( !%x}(2E
S
.Cc88r*   c                 h    [        U 5      [        U5      p[        X5      n[        XS9n[	        XXS9$ )a  
Represents Circular Orthogonal Ensembles.

Examples
========

>>> from sympy.stats import CircularOrthogonalEnsemble as COE
>>> from sympy.stats import joint_eigen_distribution
>>> C = COE('O', 1)
>>> joint_eigen_distribution(C)
Lambda(t[1], Product(Abs(exp(I*t[_j]) - exp(I*t[_k])), (_j, _k + 1, 1), (_k, 1, 0))/(2*pi))

Note
====

As can be seen above in the example, density of CiruclarOrthogonalEnsemble
is not evaluated because the exact definition is based on haar measure of
unitary group which is not unique.
r{   r~   )r   r   r   r   r   r   s       r(   r   r   :  5    ( !%x}+C5E
S
.Cc88r*   c                 h    [        U 5      [        U5      p[        X5      n[        XS9n[	        XXS9$ )a	  
Represents Circular Symplectic Ensembles.

Examples
========

>>> from sympy.stats import CircularSymplecticEnsemble as CSE
>>> from sympy.stats import joint_eigen_distribution
>>> C = CSE('S', 1)
>>> joint_eigen_distribution(C)
Lambda(t[1], Product(Abs(exp(I*t[_j]) - exp(I*t[_k]))**4, (_j, _k + 1, 1), (_k, 1, 0))/(2*pi))

Note
====

As can be seen above in the example, density of CiruclarSymplecticEnsemble
is not evaluated because the exact definition is based on haar measure of
unitary group which is not unique.
r{   r~   )r   r   r   r   r   r   s       r(   r   r   S  r   r*   c                     [        U [        5      (       d  [        SU -  5      eU R                  R                  R                  5       $ )a  
For obtaining joint probability distribution
of eigen values of random matrix.

Parameters
==========

mat: RandomMatrixSymbol
    The matrix symbol whose eigen values are to be considered.

Returns
=======

Lambda

Examples
========

>>> from sympy.stats import GaussianUnitaryEnsemble as GUE
>>> from sympy.stats import joint_eigen_distribution
>>> U = GUE('U', 2)
>>> joint_eigen_distribution(U)
Lambda((l[1], l[2]), exp(-l[1]**2 - l[2]**2)*Product(Abs(l[_i] - l[_j])**2, (_j, _i + 1, 2), (_i, 1, 1))/pi)
z&%s is not of type, RandomMatrixSymbol.)
isinstancer   r0   r   r|   r"   mats    r(   r"   r"   l  s<    2 c-..A3GHH::4466r*   c                     U R                  SS9n[        S [        U5       5       5      (       d  [        S5      e[	        U6 $ )aZ  
Creates joint distribution of eigen values of matrices with random
expressions.

Parameters
==========

mat: Matrix
    The matrix under consideration.

Returns
=======

JointDistributionHandmade

Examples
========

>>> from sympy.stats import Normal, JointEigenDistribution
>>> from sympy import Matrix
>>> A = [[Normal('A00', 0, 1), Normal('A01', 0, 1)],
... [Normal('A10', 0, 1), Normal('A11', 0, 1)]]
>>> JointEigenDistribution(Matrix(A))
JointDistributionHandmade(-sqrt(A00**2 - 2*A00*A11 + 4*A01*A10 + A11**2)/2
+ A00/2 + A11/2, sqrt(A00**2 - 2*A00*A11 + 4*A01*A10 + A11**2)/2 + A00/2 + A11/2)

T)multiplec              3   8   #    U  H  n[        U5      v   M     g 7fr@   )r   ).0eigenvals     r(   	<genexpr>)JointEigenDistribution.<locals>.<genexpr>  s     B>xy"">s   zWEigen values do not have any random expression, joint distribution cannot be generated.)	eigenvalsallsetr0   r   )r   r   s     r(   r#   r#     sI    8 t,IB3y>BBB C D 	D$i00r*   c                 J    U R                   R                  R                  5       $ )a3  
For obtaining distribution of level spacings.

Parameters
==========

mat: RandomMatrixSymbol
    The random matrix symbol whose eigen values are
    to be considered for finding the level spacings.

Returns
=======

Lambda

Examples
========

>>> from sympy.stats import GaussianUnitaryEnsemble as GUE
>>> from sympy.stats import level_spacing_distribution
>>> U = GUE('U', 2)
>>> level_spacing_distribution(U)
Lambda(_s, 32*_s**2*exp(-4*_s**2/pi)/pi**2)

References
==========

.. [1] https://en.wikipedia.org/wiki/Random_matrix#Distribution_of_level_spacings
)r   r|   r$   r   s    r(   r$   r$     s    < ::6688r*   N)Asympy.concrete.productsr   sympy.concrete.summationsr   sympy.core.basicr   sympy.core.functionr   sympy.core.numbersr   r   sympy.core.singletonr	   sympy.core.symbolr
   $sympy.functions.elementary.complexesr   &sympy.functions.elementary.exponentialr   'sympy.functions.special.gamma_functionsr   sympy.integrals.integralsr   "sympy.matrices.expressions.matexprr    sympy.matrices.expressions.tracer   sympy.tensor.indexedr   sympy.core.sympifyr   sympy.stats.rvr   r   r   r   sympy.stats.joint_rv_typesr   sympy.stats.random_matrixr   sympy.tensor.arrayr   __all__registerr)   r,   rR   rr   r   r   r   r   r    r!   r   r   r   r   r   r   r   r   r"   r#   r$   r&   r*   r(   <module>r      s   + ) " & & " # 4 6 9 . ; 2 , ' T T @ 8 1 &' (" "./85 /8b#8 (&; *&; *99&9&9& *5  *D<#8 <=&; =<&; <99292927: 1D9r*   