
    EdU                        d dl mZ d dlmZ d dlmZ d dlmZ d dlm	Z	 d dl
mZ d dlmZmZ d dlmZmZmZmZmZmZmZmZmZ d d	lmZmZmZmZmZmZm Z  d d
l!m"Z"  G d de          Z#d Z$ G d d          Z% G d d          Z& G d d          Z'e%e'e'e&dZ( G d de e          Z) G d de)          Z*d Z+ G d de)          Z,d Z- G d de)          Z.d Z/ G d  d!e)          Z0d" Z1d#S )$    )prod)Basic)pi)S)exp)
multigamma)sympify_sympify)	ImmutableMatrixInverseTraceDeterminantMatrixSymbol
MatrixBase	Transpose	MatrixSetmatrix2numpy)_value_checkRandomMatrixSymbolNamedArgsMixinPSpace_symbol_converterMatrixDomainDistribution)import_modulec                       e Zd ZdZd Z ed           Z ed           Zed             Zed             Z	ed             Z
d ZddZdS )MatrixPSpacezD
    Represents probability space for
    Matrix Distributions.
    c                     t          |          }t          |          t          |          }}|j        r|j        st          d          t	          j        | ||||          S )NzDimensions should be integers)r   r
   
is_integer
ValueErrorr   __new__)clssymdistributiondim_ndim_ms        @lib/python3.11/site-packages/sympy/stats/matrix_distributions.pyr!   zMatrixPSpace.__new__   s`    $$u  	>U%5 	><===}S#|UEBBB    c                     | j         d         S )N   argsselfs    r'   <lambda>zMatrixPSpace.<lambda>    s    1 r(   c                     | j         d         S Nr   r+   r-   s    r'   r/   zMatrixPSpace.<lambda>!   s    49Q< r(   c                 @    t          | j        | j        j                  S N)r   symbolr$   setr-   s    r'   domainzMatrixPSpace.domain#   s    DK):)>???r(   c                 \    t          | j        | j        d         | j        d         |           S )N      )r   r4   r,   r-   s    r'   valuezMatrixPSpace.value'   s$    !$+ty|TYq\4PPPr(   c                     | j         hS r3   )r:   r-   s    r'   valueszMatrixPSpace.values+   s    
|r(   c                     |                     t                    }t          |          dk    st          |t                    st	          d          | j                            |          S )Nr*   ztCurrently, no algorithm has been implemented to handle general expressions containing multiple matrix distributions.)atomsr   len
isinstanceNotImplementedErrorr$   pdf)r.   exprr,   rmss       r'   compute_densityzMatrixPSpace.compute_density/   sh    jj+,,s88a< 	6
41C D D 	6% '5 6 6 6  $$T***r(    scipyNc                 J    | j         | j                            |||          iS )zu
        Internal sample method

        Returns dictionary mapping RandomMatrixSymbol to realization value.
        )libraryseed)r:   r$   sample)r.   sizerI   rJ   s       r'   rK   zMatrixPSpace.sample7   s*     
D-44T7QU4VVWWr(   rF   rG   N)__name__
__module____qualname____doc__r!   propertyr$   r4   r6   r:   r<   rE   rK   rF   r(   r'   r   r      s         C C C 85566LX//00F@ @ X@ Q Q XQ   X+ + +X X X X X Xr(   r   c                     t          t          t          |                    } || } |j        |  |j        }t          | ||d         |d                   }|j        S )Nr   r*   )listmapr	   check	dimensionr   r:   )r4   r"   r,   distdimpspaces         r'   rvr[   @   s]    GT""##D3:DDJ
.C&$AA77F<r(   c                   0    e Zd ZdZddZed             ZdS )SampleMatrixScipyz7Returns the sample from scipy of the given distributionNc                 0    |                      |||          S r3   )_sample_scipyr"   rX   rL   rJ   s       r'   r!   zSampleMatrixScipy.__new__K         tT222r(   c                   
 ddl m
 ddl}
fd
fdd}d d d}|                                }|j        j        |vrdS |t          |t                    r|j        	                    |	          }n|} ||j        j                 |t          |          |          }	|	                    | ||j        j                 |          z             S )
zSample from SciPy.r   )statsNc                     j                             t          | j                  t	          | j        t                    |          S )N)dfscalerL   )wishartrvsintnr   scale_matrixfloatrX   rL   
rand_statescipy_statss      r'   r/   z1SampleMatrixScipy._sample_scipy.<locals>.<lambda>U   sB    +BUBYBYtv;;l43De&L&LSW CZ CY CY r(   c                     j                             t          | j        t                    t          | j        t                    t          | j        t                    ||          S )N)meanrowcovcolcovrL   random_state)matrix_normalrh   r   location_matrixrl   scale_matrix_1scale_matrix_2rm   s      r'   r/   z1SampleMatrixScipy._sample_scipy.<locals>.<lambda>W   sZ    {G`GdGd!$"6>>#D$7??#D$7??dYc He He He r(   WishartDistributionMatrixNormalDistributionc                     | j         j        S r3   rk   shaperX   s    r'   r/   z1SampleMatrixScipy._sample_scipy.<locals>.<lambda>^       0A0G r(   c                     | j         j        S r3   rv   r~   r   s    r'   r/   z1SampleMatrixScipy._sample_scipy.<locals>.<lambda>_       d6J6P r(   rJ   )rG   rc   numpykeys	__class__rN   r@   ri   randomdefault_rngr   reshape)r"   rX   rL   rJ   r   scipy_rv_mapsample_shape	dist_listrn   sampro   s             @r'   r_   zSampleMatrixScipy._sample_scipyN   s(    	/.....$Y $Y $Y $Y)e )e )e )e
 
 $H#G)P)P
 

 !%%''	>")3 	4 	:dC00 	11t1<<JJJ4|DN34T4::zRR||D#H<0G#H#N#NNOOOr(   r3   )rN   rO   rP   rQ   r!   classmethodr_   rF   r(   r'   r]   r]   I   sN        AA3 3 3 3 P P [P P Pr(   r]   c                   0    e Zd ZdZddZed             ZdS )SampleMatrixNumpyz7Returns the sample from numpy of the given distributionNc                 0    |                      |||          S r3   )_sample_numpyr`   s       r'   r!   zSampleMatrixNumpy.__new__s   ra   r(   c                 z   i }i }|                                 }|j        j        |vrdS ddl}|t	          |t
                    r|j                            |          }n|} ||j        j                 |t          |          |          }	|		                    | ||j        j                 |          z             S )zSample from NumPy.Nr   r   )
r   r   rN   r   r@   ri   r   r   r   r   )
r"   rX   rL   rJ   numpy_rv_mapr   r   r   rn   r   s
             r'   r   zSampleMatrixNumpy._sample_numpyv   s    

 !%%''	>")3 	4 	:dC00 	11t1<<JJJ4|DN34T4::zRR||D#H<0G#H#N#NNOOOr(   r3   )rN   rO   rP   rQ   r!   r   r   rF   r(   r'   r   r   o   sN        AA3 3 3 3 P P [P P Pr(   r   c                   0    e Zd ZdZddZed             ZdS )SampleMatrixPymcz6Returns the sample from pymc of the given distributionNc                 0    |                      |||          S r3   )_sample_pymcr`   s       r'   r!   zSampleMatrixPymc.__new__   s    dD111r(   c           	      R  	 	 ddl 	n# t          $ r ddl	Y nw xY w	fd	fdd}d d d}|                                }|j        j        |vrdS ddl}|                    d	                              |j	                   	
                                5   ||j        j                 |           	                    t          |          d
d|dd          d         }ddd           n# 1 swxY w Y   |                    | ||j        j                 |          z             S )zSample from PyMC.r   Nc           	                               dt          | j        t                    t          | j        t                    t          | j        t                    | j        j                  S )NX)murr   rs   r~   )MatrixNormalr   rv   rl   rw   rx   r~   rX   pymcs    r'   r/   z/SampleMatrixPymc._sample_pymc.<locals>.<lambda>   sX    T5F5Fs 4e<<#D$7??#D$7??*0	 6G 62 62 r(   c                                          dt          | j                  t          | j        t
                              S )Nr   )nur   )WishartBartlettri   rj   r   rk   rl   r   s    r'   r/   z/SampleMatrixPymc._sample_pymc.<locals>.<lambda>   s;    0D0DStv;;,t/@%"H"H 1E 1J 1J r(   )r{   rz   c                     | j         j        S r3   r}   r   s    r'   r/   z/SampleMatrixPymc._sample_pymc.<locals>.<lambda>   r   r(   c                     | j         j        S r3   r   r   s    r'   r/   z/SampleMatrixPymc._sample_pymc.<locals>.<lambda>   r   r(   ry   r   r*   F)drawschainsprogressbarrandom_seedreturn_inferencedatacompute_convergence_checksr   )r   ImportErrorpymc3r   r   rN   logging	getLoggersetLevelERRORModelrK   r   r   )
r"   rX   rL   rJ   pymc_rv_mapr   r   r   sampsr   s
            @r'   r   zSampleMatrixPymc._sample_pymc   s   	!KKKK 	! 	! 	!      	!)2 )2 )2 )2
$J $J $J $J
 
 $H#G)P)P
 

  $$&&	>")3 	4&!!**7=999ZZ\\ 	d 	d0K/0666KKd4jj[_v{  Y^K  _  _  `c  dE	d 	d 	d 	d 	d 	d 	d 	d 	d 	d 	d 	d 	d 	d 	d }}T$IL1H$I$$O$OOPPPs    A
C--C14C1r3   )rN   rO   rP   rQ   r!   r   r   rF   r(   r'   r   r      sN        @@2 2 2 2 Q Q [Q Q Qr(   r   )rG   r   r   r   c                   <    e Zd ZdZd Zed             Zd Zd	dZdS )
MatrixDistributionz1
    Abstract class for Matrix Distribution.
    c                 >    d |D             }t          j        | g|R  S )Nc                 t    g | ]5}t          |t                    rt          |          nt          |          6S rF   )r@   rT   r   r
   ).0args     r'   
<listcomp>z.MatrixDistribution.__new__.<locals>.<listcomp>   sM     4 4 4'* )33(=(= #$$$c]]4 4 4r(   )r   r!   )r"   r,   s     r'   r!   zMatrixDistribution.__new__   s8    4 4.24 4 4}S(4((((r(   c                      d S r3   rF   r+   s    r'   rV   zMatrixDistribution.check   s    r(   c                 t    t          |t                    rt          |          }|                     |          S r3   )r@   rT   r   rB   )r.   rC   s     r'   __call__zMatrixDistribution.__call__   s1    dD!! 	)"4((Dxx~~r(   rF   rG   Nc                    g d}||vrt          dt          |          z            t          |          st          d|z            t	          |         | ||          }||S t          d| j        j        d|          )zo
        Internal sample method

        Returns dictionary mapping RandomSymbol to realization value.
        )rG   r   r   r   z&Sampling from %s is not supported yet.zFailed to import %sNzSampling for z# is not currently implemented from )rA   strr   r    _get_sample_class_matrixrvr   rN   )r.   rL   rI   rJ   	librariesr   s         r'   rK   zMatrixDistribution.sample   s     877	)# 	8%&N*-g,,'7 8 8 8W%% 	>2W<===*73D$EE 	L!!>***GG5  	r(   rM   )	rN   rO   rP   rQ   r!   staticmethodrV   r   rK   rF   r(   r'   r   r      sk         ) ) )
   \  
     r(   r   c                   Z    e Zd ZdZed             Zed             Zed             Zd Z	dS )MatrixGammaDistributionalphabetark   c                     t          |t                    st          |j        d           t          |j        d           t          | j        d           t          |j        d           d S )N+The shape matrix must be positive definite.Should be square matrix#Shape parameter should be positive.z#Scale parameter should be positive.r@   r   r   is_positive_definite	is_squareis_positiver   s      r'   rV   zMatrixGammaDistribution.check   sz    ,55 	5: =4 5 5 5\+ . 	 	 	U&(MNNNT%'LMMMMMr(   c                 \    | j         j        d         }t          ||t          j                  S r1   rk   r~   r   r   Realsr.   ks     r'   r5   zMatrixGammaDistribution.set   &    #A&Aqw'''r(   c                     | j         j        S r3   r}   r-   s    r'   rW   z!MatrixGammaDistribution.dimension       &&r(   c                 "   | j         | j        | j        }}}|j        d         }t	          |t
                    rt          |          }t	          |t          t          f          st          dt          |          z            t          |           |z  |z  }t          t          |                    |||z  z  t          ||          z  z  }t          |          | z  }t          |          |t!          |dz             dz  z
  z  }	||z  |	z  S )Nr   4%s should be an isinstance of Matrix or MatrixSymbolr*   r8   )r   r   rk   r~   r@   rT   r   r   r   r    r   r   r   r   r   r   r   )
r.   xr   r   rk   psigma_inv_xterm1term2term3s
             r'   rB   zMatrixGammaDistribution.pdf  s   $(J	4;L\tq!a 	#""A!j,788 	0 &(+A/ 0 0 0---a/$6E+&&''$5/Zq=Q=Q)QR\**uf5Q51QU88A:#56u}u$$r(   N
rN   rO   rP   	_argnamesr   rV   rR   r5   rW   rB   rF   r(   r'   r   r      sz        1IN N \N ( ( X( ' ' X'% % % % %r(   r   c                 |    t          |t                    rt          |          }t          | t          |||f          S )a  
    Creates a random variable with Matrix Gamma Distribution.

    The density of the said distribution can be found at [1].

    Parameters
    ==========

    alpha: Positive Real number
        Shape Parameter
    beta: Positive Real number
        Scale Parameter
    scale_matrix: Positive definite real square matrix
        Scale Matrix

    Returns
    =======

    RandomSymbol

    Examples
    ========

    >>> from sympy.stats import density, MatrixGamma
    >>> from sympy import MatrixSymbol, symbols
    >>> a, b = symbols('a b', positive=True)
    >>> M = MatrixGamma('M', a, b, [[2, 1], [1, 2]])
    >>> X = MatrixSymbol('X', 2, 2)
    >>> density(M)(X).doit()
    exp(Trace(Matrix([
    [-2/3,  1/3],
    [ 1/3, -2/3]])*X)/b)*Determinant(X)**(a - 3/2)/(3**a*sqrt(pi)*b**(2*a)*gamma(a)*gamma(a - 1/2))
    >>> density(M)([[1, 0], [0, 1]]).doit()
    exp(-4/(3*b))/(3**a*sqrt(pi)*b**(2*a)*gamma(a)*gamma(a - 1/2))


    References
    ==========

    .. [1] https://en.wikipedia.org/wiki/Matrix_gamma_distribution

    )r@   rT   r   r[   r   )r4   r   r   rk   s       r'   MatrixGammar     s>    V ,%% 5&|44f-t\/JKKKr(   c                   Z    e Zd ZdZed             Zed             Zed             Zd Z	dS )rz   rj   rk   c                     t          |t                    st          |j        d           t          |j        d           t          | j        d           d S )Nr   r   r   r   r   s     r'   rV   zWishartDistribution.checkL  se    ,55 	5: =4 5 5 5\+ . 	 	 	Q]$IJJJJJr(   c                 \    | j         j        d         }t          ||t          j                  S r1   r   r   s     r'   r5   zWishartDistribution.setU  r   r(   c                     | j         j        S r3   r}   r-   s    r'   rW   zWishartDistribution.dimensionZ  r   r(   c                    | j         | j        }}|j        d         }t          |t                    rt          |          }t          |t          t          f          st          dt          |          z            t          |           |z  t          d          z  }t          t          |                    d||z  t          d          z  z  t          |t          d          z  |          z  z  }t          |          | t          d          z  z  }t          |          t          ||z
  dz
            dz  z  }||z  |z  S )Nr   r   r8   r*   )rj   rk   r~   r@   rT   r   r   r   r    r   r   r   r   r   r   r   )	r.   r   rj   rk   r   r   r   r   r   s	            r'   rB   zWishartDistribution.pdf^  s,   &$"3<q!a 	#""A!j,788 	0 &(+A/ 0 0 0---a/!A$$6E+&&''!ac!A$$h-:a!fa;P;P)PQ\**qb1g6Q1QUQY<<>2u}u$$r(   Nr   rF   r(   r'   rz   rz   H  sz        %IK K \K ( ( X( ' ' X'% % % % %r(   rz   c                 z    t          |t                    rt          |          }t          | t          ||f          S )a  
    Creates a random variable with Wishart Distribution.

    The density of the said distribution can be found at [1].

    Parameters
    ==========

    n: Positive Real number
        Represents degrees of freedom
    scale_matrix: Positive definite real square matrix
        Scale Matrix

    Returns
    =======

    RandomSymbol

    Examples
    ========

    >>> from sympy.stats import density, Wishart
    >>> from sympy import MatrixSymbol, symbols
    >>> n = symbols('n', positive=True)
    >>> W = Wishart('W', n, [[2, 1], [1, 2]])
    >>> X = MatrixSymbol('X', 2, 2)
    >>> density(W)(X).doit()
    exp(Trace(Matrix([
    [-1/3,  1/6],
    [ 1/6, -1/3]])*X))*Determinant(X)**(n/2 - 3/2)/(2**n*3**(n/2)*sqrt(pi)*gamma(n/2)*gamma(n/2 - 1/2))
    >>> density(W)([[1, 0], [0, 1]]).doit()
    exp(-2/3)/(2**n*3**(n/2)*sqrt(pi)*gamma(n/2)*gamma(n/2 - 1/2))

    References
    ==========

    .. [1] https://en.wikipedia.org/wiki/Wishart_distribution

    )r@   rT   r   r[   rz   )r4   rj   rk   s      r'   Wishartr   l  s<    P ,%% 5&|44f)A|+<===r(   c                   Z    e Zd ZdZed             Zed             Zed             Zd Z	dS )r{   )rv   rw   rx   c           	      2   t          |t                    st          |j        d           t          |t                    st          |j        d           t          |j        d           t          |j        d           | j        d         }| j        d         }t          |j        d         |k    dt          |          dt          |                     t          |j        d         |k    dt          |          dt          |                     d S )	Nr   )Scale matrix 1 should be be square matrix)Scale matrix 2 should be be square matrixr   r*   "Scale matrix 1 should be of shape  x "Scale matrix 2 should be of shape )r@   r   r   r   r   r~   r   )rv   rw   rx   rj   r   s        r'   rV   zMatrixNormalDistribution.check  s:   .,77 	5< ?4 5 5 5.,77 	5< ?4 5 5 5^- 0 	 	 	^- 0 	 	 	!!$!!$^)!,11!!ffffc!fff4. 	/ 	/ 	/^)!,11!!ffffc!fff4. 	/ 	/ 	/ 	/ 	/r(   c                 V    | j         j        \  }}t          ||t          j                  S r3   rv   r~   r   r   r   r.   rj   r   s      r'   r5   zMatrixNormalDistribution.set  %    #)1Aqw'''r(   c                     | j         j        S r3   r   r-   s    r'   rW   z"MatrixNormalDistribution.dimension      #))r(   c                    | j         | j        | j        }}}|j        \  }}t	          |t
                    rt          |          }t	          |t          t          f          st          dt          |          z            t          |          t          ||z
            z  t          |          z  ||z
  z  }t          t          |           t          d          z            }dt           z  t          ||z            dz  z  t#          |          t          |          z  z  dz  t#          |          t          |          z  z  dz  }	||	z  S )Nr   r8   )rv   rw   rx   r~   r@   rT   r   r   r   r    r   r   r   r   r   r   r   r   )
r.   r   MUVrj   r   r   numdens
             r'   rB   zMatrixNormalDistribution.pdf  s*   &(;T=Pa1w1a 	#""A!j,788 	0 &(+A/ 0 0 0

9QU+++GAJJ6A>5<<-!$%%tq1vvax ;q>>1Q44#779KNNAaDD<PPQRR3wr(   Nr   rF   r(   r'   r{   r{     sw        GI/ / \/$ ( ( X( * * X*    r(   r{   c                    t          |t                    rt          |          }t          |t                    rt          |          }t          |t                    rt          |          }|||f}t          | t          |          S )a  
    Creates a random variable with Matrix Normal Distribution.

    The density of the said distribution can be found at [1].

    Parameters
    ==========

    location_matrix: Real ``n x p`` matrix
        Represents degrees of freedom
    scale_matrix_1: Positive definite matrix
        Scale Matrix of shape ``n x n``
    scale_matrix_2: Positive definite matrix
        Scale Matrix of shape ``p x p``

    Returns
    =======

    RandomSymbol

    Examples
    ========

    >>> from sympy import MatrixSymbol
    >>> from sympy.stats import density, MatrixNormal
    >>> M = MatrixNormal('M', [[1, 2]], [1], [[1, 0], [0, 1]])
    >>> X = MatrixSymbol('X', 1, 2)
    >>> density(M)(X).doit()
    2*exp(-Trace((Matrix([
    [-1],
    [-2]]) + X.T)*(Matrix([[-1, -2]]) + X))/2)/pi
    >>> density(M)([[3, 4]]).doit()
    2*exp(-4)/pi

    References
    ==========

    .. [1] https://en.wikipedia.org/wiki/Matrix_normal_distribution

    )r@   rT   r   r[   r{   )r4   rv   rw   rx   r,   s        r'   r   r     s    R /4(( ;)/::.$'' 9(88.$'' 9(88^^<Df.555r(   c                   Z    e Zd ZdZed             Zed             Zed             Zd Z	dS )MatrixStudentTDistribution)r   rv   rw   rx   c           	         t          |t                    st          |j        dk    d           t          |t                    st          |j        dk    d           t          |j        dk    d           t          |j        dk    d           |j        d         }|j        d         }t          |j        d         |k    dt          |          dt          |                     t          |j        d         |k    d	t          |          dt          |                     t          | j        dk    d
           d S )NFr   r   r   r   r*   r   r   r   z#Degrees of freedom must be positive)r@   r   r   r   r   r~   r   r   )r   rv   rw   rx   rj   r   s         r'   rV   z MatrixStudentTDistribution.check  s   .,77 	c<E Hb c c c.,77 	c<E Hb c c c^-6 9B 	C 	C 	C^-6 9B 	C 	C 	C!!$!!$^)!,11JMa&&&&RUVWRXRXRX4Z 	[ 	[ 	[^)!,11JMa&&&&RUVWRXRXRX4Z 	[ 	[ 	[R^u,.STTTTTr(   c                 V    | j         j        \  }}t          ||t          j                  S r3   r   r   s      r'   r5   zMatrixStudentTDistribution.set  r   r(   c                     | j         j        S r3   r   r-   s    r'   rW   z$MatrixStudentTDistribution.dimension  r   r(   c           	         ddl m} t          |t                    rt	          |          }t          |t
          t          f          st          dt          |          z            | j	        | j
        | j        | j        f\  }}}}|j        \  }}t          ||z   |z   dz
  dz  |          t          |          | dz  z  z  t          |          | dz  z  z  t           ||z  dz  z  t          ||z   dz
  dz  |          z  z  }	|	t           ||          t#          |          ||z
  z  t#          |          z  t%          ||z
            z  z             ||z   |z   dz
   dz  z  z  S )Nr   )eyer   r*   r8   )sympy.matrices.denser  r@   rT   r   r   r   r    r   r   rv   rw   rx   r~   r   r   r   r   r   )
r.   r   r  r   r   OmegaSigmarj   r   Ks
             r'   rB   zMatrixStudentTDistribution.pdf  s   ,,,,,,a 	#""A!j,788 	9 /14Q8 9 9 9"gt';T=PRVReeAuew1Q
Q)1--E0B0BaRT0JJ[Y^M_M_cdbdefbfMggac!e}z26A:q.!<<<>KAQ)?)NyYZ]^Y^O_O_)_ _``FQJM"1$& & 	&r(   Nr   rF   r(   r'   r  r    sz        MIU U \U& ( ( X( * * X*& & & & &r(   r  c                    t          |t                    rt          |          }t          |t                    rt          |          }t          |t                    rt          |          }||||f}t          | t          |          S )a  
    Creates a random variable with Matrix Gamma Distribution.

    The density of the said distribution can be found at [1].

    Parameters
    ==========

    nu: Positive Real number
        degrees of freedom
    location_matrix: Positive definite real square matrix
        Location Matrix of shape ``n x p``
    scale_matrix_1: Positive definite real square matrix
        Scale Matrix of shape ``p x p``
    scale_matrix_2: Positive definite real square matrix
        Scale Matrix of shape ``n x n``

    Returns
    =======

    RandomSymbol

    Examples
    ========

    >>> from sympy import MatrixSymbol,symbols
    >>> from sympy.stats import density, MatrixStudentT
    >>> v = symbols('v',positive=True)
    >>> M = MatrixStudentT('M', v, [[1, 2]], [[1, 0], [0, 1]], [1])
    >>> X = MatrixSymbol('X', 1, 2)
    >>> density(M)(X)
    gamma(v/2 + 1)*Determinant((Matrix([[-1, -2]]) + X)*(Matrix([
    [-1],
    [-2]]) + X.T) + Matrix([[1]]))**(-v/2 - 1)/(pi**1.0*gamma(v/2)*Determinant(Matrix([[1]]))**1.0*Determinant(Matrix([
    [1, 0],
    [0, 1]]))**0.5)

    References
    ==========

    .. [1] https://en.wikipedia.org/wiki/Matrix_t-distribution

    )r@   rT   r   r[   r  )r4   r   rv   rw   rx   r,   s         r'   MatrixStudentTr  /  s    X /4(( ;)/::.$'' 9(88.$'' 9(88@Df0$777r(   N)2mathr   sympy.core.basicr   sympy.core.numbersr   sympy.core.singletonr   &sympy.functions.elementary.exponentialr   'sympy.functions.special.gamma_functionsr   sympy.core.sympifyr	   r
   sympy.matricesr   r   r   r   r   r   r   r   r   sympy.stats.rvr   r   r   r   r   r   r   sympy.externalr   r   r[   r]   r   r   r   r   r   r   rz   r   r{   r   r  r  rF   r(   r'   <module>r     s         " " " " " " ! ! ! ! ! ! " " " " " " 6 6 6 6 6 6 > > > > > > 0 0 0 0 0 0 0 0* * * * * * * * * * * * * * * * * * * * * *K K K K K K K K K K K K K K K K K K ( ( ( ( ( ()X )X )X )X )X6 )X )X )XX  #P #P #P #P #P #P #P #PLP P P P P P P P>&Q &Q &Q &Q &Q &Q &Q &QR 	  ' ' ' ' '~ ' ' '`#% #% #% #% #%0 #% #% #%J-L -L -Ld"% "% "% "% "%, "% "% "%H*> *> *>^+ + + + +1 + + +Z06 06 06j.& .& .& .& .&!3 .& .& .&d38 38 38 38 38r(   