Example #1
0
def prove(Eq):
    x = Symbol.x(real=True)
    a = Symbol.a(real=True)
    b = Symbol.b(real=True)
    Eq << apply(Unequal(x, 0), Unequal(x * a, b))

    Eq << Eq[1] / x

    Eq << (Eq[-1] & Eq[0]).split()
    def bayes_theorem(self, *given):
        if len(given) == 1:
            given = given[0]
            marginal_prob = self.marginalize(given)

            expr = marginal_prob.arg
            if expr.is_Conditioned and self.arg.is_Conditioned:
                given_probability = self.func(given, given=expr.rhs)
            else:
                given_probability = self.func(given)

            given_marginal_prob = self.func(expr, given=given)
            assert given_marginal_prob.arg.is_Conditioned

            if given_marginal_prob.arg.rhs.is_And:
                given_additions = given_marginal_prob.arg.rhs._argset - {
                    given.as_boolean()
                }
                inequality = Unequal(
                    self.func(given_probability.arg,
                              given=And(*given_additions)), 0)
            else:
                inequality = Unequal(given_probability, 0)

            return ForAll[given:inequality](Equality(
                self, given_probability * given_marginal_prob))
        else:
            marginal_prob = self
            cond = S.true
            for g in given:
                marginal_prob = marginal_prob.marginalize(g)
                cond &= g.as_boolean()

            expr = marginal_prob.arg
            if expr.is_Conditioned and self.arg.is_Conditioned:
                given_probability = self.func(cond, given=expr.rhs)
            else:
                given_probability = self.func(cond)

            given_marginal_prob = self.func(expr, given=cond)
            assert given_marginal_prob.arg.is_Conditioned

            if given_marginal_prob.arg.rhs.is_And:
                given_additions = given_marginal_prob.arg.rhs._argset - cond._argset
                inequality = Unequal(
                    self.func(given_probability.arg,
                              given=And(*given_additions)), 0)
            else:
                inequality = Unequal(given_probability, 0)

            return ForAll[given:inequality](Equality(
                self, given_probability * given_marginal_prob))
Example #3
0
def prove(Eq):
    x = Symbol.x(real=True, random=True)
    y = Symbol.y(real=True, random=True)
    z = Symbol.z(real=True, random=True)
        
    Eq << apply(x.is_independent_of(z), y.is_independent_of(z), Unequal(P(y), 0))
    
    Eq << bayes.equality.equality.product.apply(Eq[0])
    
    Eq.bayes_yz = bayes.equality.equality.product.apply(Eq[1])
    
    Eq.bayes_xyz = bayes.theorem.apply(Eq[0].domain_definition(), var=P(x, y))
    
    Eq << Eq[2].subs(Eq[1].reversed)
    
    Eq.given_addition = bayes.equality.equality.given_addition.condition_probability.apply(Eq[0], Eq[-1])
    
    Eq << bayes.inequality.inequality.joint.apply(Eq[-1])
    
    Eq << bayes.theorem.apply(Eq[-1], var=x)
    
    Eq << Eq.bayes_xyz.subs(Eq[-1])
    
    Eq << Eq[-1].subs(Eq.bayes_yz)
    
    Eq << algebre.scalar.inequality.equality.apply(Eq[-1], Eq[0].domain_definition())
    
    Eq << Eq[-1].subs(Eq.given_addition)
    
    Eq << bayes.theorem.apply(Eq[2], var=x)
    
    Eq << Eq[-2].subs(Eq[-1].reversed)
    
    Eq << Eq[-1].reversed
Example #4
0
def prove(Eq):
    n = Symbol.n(integer=True)
    A = Symbol.A(real=True, shape=(n, n), given=True)
    a = Symbol.a(real=True, shape=(n, ), given=True)
    b = Symbol.b(real=True, shape=(n, ), given=True)
    Eq << apply(Unequal(Determinant(A), 0), Unequal(a @ A, b))

    Eq << ~Eq[-1]

    Eq << Eq[-1].split()

    Eq << Eq[-2] @ A

    Eq <<= Eq[1].subs(Eq[-1])

    Eq <<= Eq[-2] & Eq[0]
Example #5
0
def apply(given):
    assert given.is_Unequality
    assert given.lhs.is_Probability
    assert given.rhs.is_zero
    eq = given.lhs.arg
    assert eq.is_Conditioned
    return Unequal(P(eq.lhs), 0, given=given)
Example #6
0
def prove(Eq):
    x = Symbol.x(real=True, random=True)

    Eq << apply(Unequal(P(x), 0))

    Eq << GreaterThan(P(x), 0, plausible=True)

    Eq <<= Eq[-1] & Eq[0]
Example #7
0
def apply(*given):
    unequality, eq = given
    assert eq.is_Unequality
    assert unequality.is_Unequality
    unequality.rhs.is_zero

    divisor = unequality.lhs
    return Unequal(eq.lhs / divisor, eq.rhs / divisor, given=given)
Example #8
0
def prove(Eq):
    x = Symbol.x(real=True, random=True)
    y = Symbol.y(real=True, random=True)

    Eq << apply(Unequal(P(x | y), 0))

    Eq << bayes.inequality.inequality.joint.apply(Eq[0])

    Eq << bayes.inequality.et.apply(Eq[-1]).split()
Example #9
0
def apply(given, wrt):
    assert given.is_Unequality
    assert given.lhs.is_Probability
    assert given.rhs.is_zero

    probability = given.lhs
    p = probability.marginalize(wrt)

    return Unequal(P(p.arg | wrt), 0, given=given)
Example #10
0
def prove(Eq):
    x = Symbol.x(real=True, random=True)
    y = Symbol.y(real=True, random=True)
    z = Symbol.z(real=True, random=True)
    
    Eq << apply(Equality(x | y, x), Unequal(P(y, z), 0))
    
    Eq << bayes.inequality.inequality.conditioned.apply(Eq[1], y)
    
    Eq << bayes.equality.equality.given_addition.condition_probability.apply(Eq[0], Eq[-1])
Example #11
0
def apply(given, wrt=None):
    assert given.is_Unequality
    assert given.lhs.is_Probability
    assert given.rhs.is_zero
    
    eqs = given.lhs.arg
    assert eqs.is_And
    if wrt is not None:
        lhs, rhs = [], []
        for eq in eqs.args:
            if eq.lhs in wrt:
                rhs.append(eq)
            else:
                lhs.append(eq)
        lhs = And(*lhs)
        rhs = And(*rhs)
        return And(Unequal(P(lhs), 0), Unequal(P(rhs), 0), given=given)            
    else:
        return And(*[Unequal(P(eq), 0) for eq in eqs.args], given=given)
Example #12
0
def prove(Eq):
    x = Symbol.x(real=True, random=True)
    y = Symbol.y(real=True, random=True)

    given = Equality(x | y, x)

    Eq << apply(given, Unequal(P(x), 0))

    Eq << bayes.equality.equality.product.apply(given)

    Eq << bayes.equality.equality.independence.apply(Eq[-1], Eq[1])
Example #13
0
def prove(Eq):
    n = Symbol.n(integer=True, domain=[2, oo])
    x = Symbol.x(real=True, shape=(n,), random=True)
    
    Eq << apply(Unequal(P(x), 0))
    
    t = Symbol.t(integer=True, domain=[1, n - 1])
    
    Eq << Eq[0].this.lhs.arg.bisect(Slice[:t])
     
    Eq << bayes.inequality.et.apply(Eq[-1]).split()
Example #14
0
def apply(given):
    assert given.is_Unequality
    assert given.lhs.is_Probability
    assert given.rhs.is_zero
    
    eq = given.lhs.arg
    x, _x = eq.args
    assert _x == pspace(x).symbol
    n = x.shape[0]
    t = Symbol.t(integer=True, domain=[1, n - 1])
    return Unequal(P(x[:t]), 0, given=given)
Example #15
0
def prove(Eq):
    x = Symbol.x(real=True, random=True)
    y = Symbol.y(real=True, random=True)

    given = Equality(x | y, x)

    Eq << apply(given, Unequal(P(x, y), 0))

    Eq << bayes.inequality.et.apply(Eq[1]).split()

    Eq << bayes.equality.equality.symmetry.apply(Eq[0], Eq[-2])
Example #16
0
def prove(Eq):
    n = Symbol.n(integer=True, positive=True)
    x = Symbol.x(complex=True, shape=(n, ))
    y = Symbol.y(complex=True, shape=(n, ))

    f = Function.f(nargs=(n, ), complex=True, shape=())
    g = Function.g(nargs=(n, ), complex=True, shape=())

    Eq << apply(Unequal(f(x), g(y)) | Equality(x, y), wrt=x)

    Eq << Eq[1].as_Or()
Example #17
0
def prove(Eq):
    x = Symbol.x(real=True, random=True)
    y = Symbol.y(real=True, random=True)
    z = Symbol.z(real=True, random=True)

    Eq << apply(x.is_independent_of(z), y.is_independent_of(z),
                Unequal(P(x, y), 0))

    Eq << bayes.inequality.et.apply(Eq[2]).split()

    Eq << bayes.equality.equality.conditional_joint_probability.nonzero.apply(
        Eq[0], Eq[1], Eq[-1])
Example #18
0
def apply(*given):
    unequality, eq = given
    if not unequality.is_Unequality:
        unequality, eq = eq, unequality
    assert unequality.is_Unequality
    unequality.rhs.is_zero

    assert unequality.lhs.is_Determinant
    divisor = unequality.lhs.arg
    return Unequal(eq.lhs @ Inverse(divisor),
                   eq.rhs @ Inverse(divisor),
                   given=given)
Example #19
0
def prove(Eq):
    t = Symbol.t(integer=True, positive=True)
    n = Symbol.n(integer=True, positive=True)
    m = Symbol.m(integer=True, positive=True)
    x = Symbol.x(real=True, shape=(n, ), random=True)
    y = Symbol.y(real=True, shape=(m, ), random=True)

    Eq << apply(Equal(x[t] | x[:t], x[t]), Unequal(P(x, y), 0))

    i = Eq[-1].lhs.variable
    j = Eq[-1].rhs.function.args[-1].variable

    Eq << bayes.inequality.et.apply(Eq[1]).split()
    Eq << bayes.theorem.apply(Eq[-2], var=y[i])

    Eq.y_given_x = algebre.scalar.inequality.equality.apply(Eq[-1],
                                                            Eq[-3]).reversed

    Eq << bayes.inequality.inequality.joint_slice.apply(Eq[1], [j, i])

    Eq << bayes.inequality.et.apply(Eq[-1]).split()

    Eq << bayes.theorem.apply(Eq[-1], var=x)

    Eq.y_given_x = Eq.y_given_x.subs(Eq[-1])

    Eq << Eq.y_given_x.argmax((i, ))

    Eq << bayes.inequality.inequality.joint_slice.apply(Eq[1], Slice[:t, i])

    Eq.xt_given_x_historic = bayes.equality.equality.given_addition.joint_probability.apply(
        Eq[0], Eq[-1])

    Eq.xt_given_yi_nonzero = bayes.inequality.inequality.conditioned.apply(
        Eq[-1], wrt=y[i])

    Eq << P(x[:t + 1] | y[i]).bayes_theorem(x[:t]).as_Or()
    Eq << (Eq[-1] & Eq.xt_given_yi_nonzero).split()

    Eq << Eq[-1].subs(Eq.xt_given_x_historic)

    Eq << algebre.scalar.inequality.equality.apply(Eq[-1],
                                                   Eq.xt_given_yi_nonzero)

    Eq << Eq[-1].product((t, 1, n - 1))

    t = Eq[-1].rhs.variable
    Eq << Eq[-1] / Eq[-1].lhs.args[-1]

    Eq << Eq[-1].this.rhs.limits_subs(t, j)

    Eq << Eq[2].subs(Eq[-1].reversed)
Example #20
0
def prove(Eq):
    x = Symbol.x(real=True, random=True)
    y = Symbol.y(real=True, random=True)

    given = Unequal(P(x), 0)

    Eq << apply(given, y)

    Eq << Eq[-1].lhs.bayes_theorem(x)

    Eq << Eq[-1].as_Or()

    Eq << (Eq[-1] & Eq[0]).split()
Example #21
0
def prove(Eq):
    x = Symbol.x(real=True, random=True)
    y = Symbol.y(real=True, random=True)

    Eq << apply(Unequal(P(x, y), 0), y)

    Eq << bayes.inequality.et.apply(Eq[0]).split()

    Eq << bayes.theorem.apply(Eq[-1], var=Eq[0].lhs)

    Eq << Eq[0].subs(Eq[-1])

    Eq << algebre.scalar.inequality.inequality.apply(Eq[-3], Eq[-1])
Example #22
0
def prove(Eq):
    x = Symbol.x(real=True, random=True)
    y = Symbol.y(real=True, random=True)

    Eq << apply(Unequal(P(x | y), 0))

    Eq << Eq[0].domain_definition()

    Eq << bayes.theorem.apply(Eq[-1], var=x)

    Eq << Eq[0] * Eq[2]

    Eq << Eq[-2].subs(Eq[-1])
Example #23
0
def prove(Eq):
    n = Symbol.n(integer=True, domain=[2, oo])
    x = Symbol.x(real=True, shape=(n, ), random=True)
    y = Symbol.y(real=True, shape=(n, ), random=True)
    t = Symbol.t(integer=True, domain=[1, n - 1])

    Eq << apply(Unequal(P(x, y), 0), Slice[:t, :t])

    Eq << Eq[0].this.lhs.arg.args[-1].bisect(Slice[:t])

    Eq << Eq[-1].this.lhs.arg.args[0].bisect(Slice[:t])

    Eq << bayes.inequality.et.apply(Eq[-1], wrt={x[:t], y[:t]}).split()
Example #24
0
def apply(given, indices):
    assert given.is_Unequality
    assert given.lhs.is_Probability
    assert given.rhs.is_zero

    eqs = given.lhs.arg
    assert eqs.is_And

    args = []
    for eq, t in zip(eqs.args, indices):
        x, _x = eq.args
        assert _x == pspace(x).symbol
        args.append(x[t])

    return Unequal(P(*args), 0, given=given)
Example #25
0
def prove(Eq):
    n = Symbol.n(integer=True, positive=True)
    A = Symbol.A(complex=True, shape=(n, n))
    Eq << apply(Unequal(Determinant(A), 0))
    
    Eq << algebre.matrix.determinant.adjugate.apply(A)
    
    Eq << algebre.scalar.inequality.equality.apply(Eq[0], Eq[-1])
    
    Eq << Eq[-1].inverse()
    
    Eq << algebre.scalar.inequality.equality.apply(Eq[0], Eq[-1])
    
    Eq << Eq[-1].lhs.args[0].base @ Eq[-1] 
    
    Eq << Eq[-1].reversed
Example #26
0
def assumptions():
    # d is the number of output labels
    # oo is the length of the sequence
    d = Symbol.d(integer=True, domain=[2, oo])
    n = Symbol.n(integer=True, domain=[2, oo])
    x = Symbol.x(shape=(n, d), real=True, random=True, given=True)
    y = Symbol.y(shape=(n, ),
                 integer=True,
                 domain=[0, d - 1],
                 random=True,
                 given=True)

    k = Symbol.k(integer=True, domain=[1, n - 1])
    return Equality(x[k] | x[:k].as_boolean() & y[:k].as_boolean(),
                    x[k]), Equality(y[k] | y[:k], y[k] | y[k - 1]), Equality(
                        y[k] | x[:k], y[k]), Unequal(P(x, y), 0)
Example #27
0
def prove(Eq):
    x = Symbol.x(real=True, random=True)
    y = Symbol.y(real=True, random=True)
    
    Eq << apply(Unequal(P(x, y), 0))
    
    Eq.x_marginal_probability, Eq.y_marginal_probability = P(x, y).total_probability_theorem(y), P(x, y).total_probability_theorem(x)
    
    _y = Eq.x_marginal_probability.lhs.variable
    _x = Eq.y_marginal_probability.lhs.variable
    
    Eq << bayes.inequality.strict_greater_than.apply(Eq[0])
    
    Eq <<= Eq[-1].integrate((_y,)), Eq[-1].integrate((_x,))
    
    Eq <<= Eq[-2].subs(Eq.x_marginal_probability), Eq[-1].subs(Eq.y_marginal_probability)
    
    Eq <<= algebre.scalar.strict_greater_than.inequality.apply(Eq[-1]) & algebre.scalar.strict_greater_than.inequality.apply(Eq[-2])
Example #28
0
def prove(Eq):
    n = Symbol.n(integer=True)
    A = Symbol.A(real=True, shape=(n, n))
    a = Symbol.a(real=True, shape=(n, ))
    b = Symbol.b(real=True, shape=(n, ))
    Eq << apply(Unequal(Determinant(A), 0), Equality(a @ A, b))

    Eq << Eq[1] @ Cofactors(A).T

    Eq << algebre.matrix.determinant.adjugate.apply(A)

    Eq << Eq[-2].subs(Eq[-1])

    Eq << algebre.scalar.inequality.equality.apply(Eq[0], Eq[-1])

    Eq << algebre.matrix.inequality.determinant.apply(Eq[0]) * Determinant(A)

    Eq << Eq[-2].subs(Eq[-1])
def prove(Eq):
    x = Symbol.x(real=True, random=True)
    y = Symbol.y(real=True, random=True)
    z = Symbol.z(real=True, random=True)

    Eq << apply(Equality(x | y, x), Unequal(P(z | y), 0))

    Eq << P(x | y, z).bayes_theorem(z)
    Eq << Eq[-1].as_Or()

    Eq << (Eq[-1] & Eq[1]).split()

    Eq << Eq[-1].subs(Eq[0])

    Eq << bayes.inequality.inequality.marginal.apply(Eq[1])

    Eq << bayes.theorem.apply(Eq[-1], var=x)

    Eq << Eq[-3].subs(Eq[-1])

    Eq << algebre.scalar.inequality.equality.apply(Eq[-1], Eq[-3])

    Eq << Eq[-1].reversed
Example #30
0
def prove(Eq):
    x = Symbol.x(real=True, random=True)
    y = Symbol.y(real=True, random=True)
    
    given = Equality(P(x, y), P(x) * P(y))
    
    Eq << apply(given, Unequal(P(x), 0))
    
    Eq << Eq[-1].simplify()
    
    Eq << bayes.theorem.apply(Eq[1], var=y)
    
    Eq << Eq[-1].subs(Eq[0])
    
    Eq << Eq[-1] - Eq[-1].rhs
    
    Eq << Eq[-1].this.lhs.collect(P(x))
    
    Eq << Eq[-1].as_Or()
    
    Eq << (Eq[-1] & Eq[1]).split()
    
    Eq << Eq[-1].reversed