
    \h                         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JrJrJr  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 S\5      r! " S S\\5      r"g)    )Sum)Basic)Lambda)Dummy)Integral)NamedArgsMixinrandom_symbols_symbol_converterPSpaceRandomSymbol	is_randomDistribution)ContinuousDistributionSingleContinuousPSpace)DiscreteDistributionSingleDiscretePSpace)SingleFiniteDistributionSingleFinitePSpace)ContinuousDistributionHandmade)DiscreteDistributionHandmade)FiniteDistributionHandmadec                       \ rS rSrSrS r\S 5       r\S 5       r\S 5       r	\S 5       r
\S 5       r\S	 5       r\S
 5       r\S 5       r\S 5       rSS jrS rSS.S jrSS.S jrSS jrSS.S jrSS.S jrSrg)CompoundPSpace   z
A temporary Probability Space for the Compound Distribution. After
Marginalization, this returns the corresponding Probability Space of the
parent distribution.
c                 L   [        U5      n[        U[        5      (       a  [        X5      $ [        U[        5      (       a  [        X5      $ [        U[        5      (       a  [        X5      $ [        U[        5      (       d  [        SU-  5      e[        R                  " XU5      $ )Nz2%s should be an isinstance of CompoundDistribution)r
   
isinstancer   r   r   r   r   r   CompoundDistribution
ValueErrorr   __new__)clssdistributions      O/var/www/auris/envauris/lib/python3.13/site-packages/sympy/stats/compound_rv.pyr   CompoundPSpace.__new__   s    a l$:;;)!::l$899'88l$<==%a66,(<== /0<> ? ?}}S\22    c                 .    [        U R                  U 5      $ N)r   symbolselfs    r#   valueCompoundPSpace.value$   s    DKK..r%   c                      U R                   S   $ Nr   argsr)   s    r#   r(   CompoundPSpace.symbol(       yy|r%   c                 .    U R                   R                  $ r'   )r"   is_Continuousr)   s    r#   r4   CompoundPSpace.is_Continuous,   s      ...r%   c                 .    U R                   R                  $ r'   )r"   	is_Finiter)   s    r#   r7   CompoundPSpace.is_Finite0   s      ***r%   c                 .    U R                   R                  $ r'   )r"   is_Discreter)   s    r#   r:   CompoundPSpace.is_Discrete4   s      ,,,r%   c                      U R                   S   $ )N   r/   r)   s    r#   r"   CompoundPSpace.distribution8   r2   r%   c                 L    U R                   R                  U R                  5      $ r'   )r"   pdfr(   r)   s    r#   r@   CompoundPSpace.pdf<   s      $$T[[11r%   c                 .    U R                   R                  $ r'   )r"   setr)   s    r#   rC   CompoundPSpace.set@   s      $$$r%   c                 6    U R                  5       R                  $ r'   )_get_newpspacedomainr)   s    r#   rG   CompoundPSpace.domainD   s    ""$+++r%   c                    [        S5      nU R                  R                  S   n[        X R                  R	                  X!5      5      nU R                  U R                  X45      nUb  U$ S[        U5      -  n[        U5      e)Nxr   3Compound Distribution for %s is not implemented yet)	r   r"   r0   r   r@   _transform_pspacer(   strNotImplementedError)r*   evaluaterJ   parent_distfunc
new_pspacemessages          r#   rF   CompoundPSpace._get_newpspaceH   sx    #J'',,Q/a**..q;<++DKKK
!H3{K[[!'**r%   c                 t   [        X" U5      5      nUR                  n[        U[        5      (       a  [	        U[        X45      5      $ [        U[        5      (       a  [        U[        X45      5      $ [        U[        5      (       a-  U Vs0 s H  oUU" U5      _M     nn[        U[        U5      5      $ gs  snf )zw
This function returns the new pspace of the distribution using handmade
Distributions and their corresponding pspace.
N)r   rC   r   r   r   r   r   r   r   r   r   r   )r*   symdistr@   _setkdenss          r#   rL    CompoundPSpace._transform_pspaceR   s    
 S#c(#xxd233)#/Mc/XYY233'-I#-TUU677'+,t!s1vItD,%c+Ed+KLL 8,s   B5T)compound_evaluatec                    U R                  U5      nUR                  U R                  UR                  05      nUR                  " U40 UD6$ r'   )rF   subsr+   compute_densityr*   exprr\   kwargsrR   s        r#   r_   CompoundPSpace.compute_densitya   sF    (():;
yy$**j&6&678))$9&99r%   c                    U R                  U5      nUR                  U R                  UR                  05      nUR                  " U40 UD6$ r'   )rF   r^   r+   compute_cdfr`   s        r#   re   CompoundPSpace.compute_cdff   sF    (():;
yy$**j&6&678%%d5f55r%   Nc                 F   U R                  U5      nUR                  U R                  UR                  05      nU(       a'  UR                  U R                  UR                  05      n[        U[        5      (       a  UR
                  " X40 UD6$ UR
                  " XU40 UD6$ r'   )rF   r^   r+   r   r   compute_expectation)r*   ra   rvsrO   rb   rR   s         r#   rh   "CompoundPSpace.compute_expectationk   s    ((2
yy$**j&6&678((DJJ
(8(89:Cj"45511$FvFF--dLVLLr%   c                    U R                  U5      nUR                  U R                  UR                  05      nUR                  U5      $ r'   )rF   r^   r+   probabilityr*   	conditionr\   rb   rR   s        r#   rl   CompoundPSpace.probabilityt   sA    (():;
NNDJJ
0@0@#AB	%%i00r%   c                    U R                  U5      nUR                  U R                  UR                  05      nUR                  U5      $ r'   )rF   r^   r+   conditional_spacerm   s        r#   rq    CompoundPSpace.conditional_spacey   sA    (():;
NNDJJ
0@0@#AB	++I66r%    F)NF)__name__
__module____qualname____firstlineno____doc__r   propertyr+   r(   r4   r7   r:   r"   r@   rC   rG   rF   rL   r_   re   rh   rl   rq   __static_attributes__rs   r%   r#   r   r      s    3 / /   / / + + - -   2 2 % % , ,+M :> :
 6: 6
M ;? 1
 AE 7 7r%   r   c                   ~    \ rS rSrSrS r\S 5       r\S 5       r\S 5       r	\S 5       r
SS jrS	 r\S
 5       rSrg)r      ap  
Class for Compound Distributions.

Parameters
==========

dist : Distribution
    Distribution must contain a random parameter

Examples
========

>>> from sympy.stats.compound_rv import CompoundDistribution
>>> from sympy.stats.crv_types import NormalDistribution
>>> from sympy.stats import Normal
>>> from sympy.abc import x
>>> X = Normal('X', 2, 4)
>>> N = NormalDistribution(X, 4)
>>> C = CompoundDistribution(N)
>>> C.set
Interval(-oo, oo)
>>> C.pdf(x, evaluate=True).simplify()
exp(-x**2/64 + x/16 - 1/16)/(8*sqrt(pi))

References
==========

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

c                     [        U[        [        [        45      (       d  S[	        U5      -  n[        U5      eU R                  U5      (       d  U$ [        R                  " X5      $ )NrK   )	r   r   r   r   rM   rN   _compound_checkr   r   )r    rW   rS   s      r#   r   CompoundDistribution.__new__   sa    $!7(*>!@ A AKcRViWG%g..""4((K}}S''r%   c                 4    U R                   S   R                  $ r.   )r0   rC   r)   s    r#   rC   CompoundDistribution.set   s    yy|r%   c                 <    [        U R                  S   [        5      $ r.   )r   r0   r   r)   s    r#   r4   "CompoundDistribution.is_Continuous   s    $))A,(>??r%   c                 <    [        U R                  S   [        5      $ r.   )r   r0   r   r)   s    r#   r7   CompoundDistribution.is_Finite   s    $))A,(@AAr%   c                 <    [        U R                  S   [        5      $ r.   )r   r0   r   r)   s    r#   r:    CompoundDistribution.is_Discrete   s    $))A,(<==r%   c                 z   U R                   S   nUR                    Vs/ s H  n[        U5      (       d  M  UPM     nn[        U[        5      (       a  [	        SSSS9nUR                  U5      nO[	        S5      nUR                  U5      nU H  nU R                  XtU5      nM     [        Xg5      " U5      $ s  snf )Nr   yTF)integernegative)	r0   r   r   r   r   pmfr@   _marginaliser   )r*   rJ   rO   rW   rvrandomsr   ra   s           r#   r@   CompoundDistribution.pdf   s    yy| $		;	"Yr]2	;d455c4%8A88A;Dc
A88A;DB$$Tx8D aq!! <s
   B8B8c                 Z   [        UR                  R                  [        5      (       a&  UR                  R                  R	                  U5      nO%UR                  R                  R                  U5      nUR                  R                  R                  nUR                  R                  (       d  UR                  R                  (       a%  [        X-  X%R                  UR                  45      nO$[        X-  X%R                  UR                  45      nU(       a  UR                  5       $ U$ r'   )r   pspacer"   r   r   r@   rG   rC   r:   r7   r   _inf_supr   doit)r*   ra   r   rO   rv_densrv_doms         r#   r   !CompoundDistribution._marginalise   s    bii,,.FGGii,,004Gii,,004G!!%%99  BII$7$7t|b++KK&! "D DL2{{KK+! "D99;r%   c                     / nUR                    H  nUR                  [        U5      5        M     [        U5      S:X  a  gg)z>
Checks if the given distribution contains random parameters.
r   FT)r0   extendr	   len)r*   rW   r   args       r#   r   $CompoundDistribution._compound_check   s:    
 99CNN>#./ w<1r%   rs   Nrt   )ru   rv   rw   rx   ry   r   rz   rC   r4   r7   r:   r@   r   classmethodr   r{   rs   r%   r#   r   r      s~    >(     @ @ B B > >"  	 	r%   r   N)#sympy.concrete.summationsr   sympy.core.basicr   sympy.core.functionr   sympy.core.symbolr   sympy.integrals.integralsr   sympy.stats.rvr   r	   r
   r   r   r   r   sympy.stats.crvr   r   sympy.stats.drvr   r   sympy.stats.frvr   r   sympy.stats.crv_typesr   sympy.stats.drv_typesr   sympy.stats.frv_typesr   r   r   rs   r%   r#   <module>r      sW    ) " & # .G G G J F H @ > <l7V l7^`< `r%   