(condition, given_condition=None, numsamples=None,
                evaluate=True, **kwargs)
Probability that a condition is true, optionally given a second condition

    Parameters
    ==========

    expr : Relational containing RandomSymbols
        The condition of which you want to compute the probability
    given_condition : Relational containing RandomSymbols
        A conditional expression. P(X>1, X>0) is expectation of X>1 given X>0
    numsamples : int
        Enables sampling and approximates the probability with this many samples
    evalf : Bool (defaults to True)
        If sampling return a number rather than a complex expression
    evaluate : Bool (defaults to True)
        In case of continuous systems return unevaluated integral

    Examples
    ========

    >>> from sympy.stats import P, Die
    >>> from sympy import Eq
    >>> X, Y = Die('X', 6), Die('Y', 6)
    >>> P(X>3)
    1/2
    >>> P(Eq(X, 5), X>2) # Probability that X == 5 given that X > 2
    1/4
    >>> P(X>Y)
    5/12
Probability that a condition is true, optionally given a second condition
Probability that a condition is true optionally given a second condition
def probability(condition, given_condition=None, numsamples=None,
                evaluate=True, **kwargs):
    """
    Probability that a condition is true, optionally given a second condition

    Parameters
    ==========

    expr : Relational containing RandomSymbols
        The condition of which you want to compute the probability
    given_condition : Relational containing RandomSymbols
        A conditional expression. P(X>1, X>0) is expectation of X>1 given X>0
    numsamples : int
        Enables sampling and approximates the probability with this many samples
    evalf : Bool (defaults to True)
        If sampling return a number rather than a complex expression
    evaluate : Bool (defaults to True)
        In case of continuous systems return unevaluated integral

    Examples
    ========

    >>> from sympy.stats import P, Die
    >>> from sympy import Eq
    >>> X, Y = Die('X', 6), Die('Y', 6)
    >>> P(X>3)
    1/2
    >>> P(Eq(X, 5), X>2) # Probability that X == 5 given that X > 2
    1/4
    >>> P(X>Y)
    5/12
    """

    if numsamples:
        return sampling_P(condition, given_condition, numsamples=numsamples,
                **kwargs)
    if given_condition is not None:  # If there is a condition
        # Recompute on new conditional expr
        return probability(given(condition, given_condition, **kwargs), **kwargs)

    # Otherwise pass work off to the ProbabilitySpace
    result = pspace(condition).probability(condition, **kwargs)
    if evaluate and hasattr(result, 'doit'):
        return result.doit()
    else:
        return result
def probability ( condition , given_condition = None , numsamples = None , evaluate = True , * * kwargs ) : if numsamples : return sampling_P ( condition , given_condition , numsamples = numsamples , * * kwargs ) if given_condition is not None : # If there is a condition # Recompute on new conditional expr return probability ( given ( condition , given_condition , * * kwargs ) , * * kwargs ) # Otherwise pass work off to the ProbabilitySpace result = pspace ( condition ) . probability ( condition , * * kwargs ) if evaluate and hasattr ( result , 'doit' ) : return result . doit ( ) else : return result