コード例 #1
0
def exp_factor_both(B):
    """
    Adds axioms of the form exp(c1 * t1 + ... + cn * tn) = exp(t1)^c1 * ... * exp(tn)^cn (also
    when n = 1).
    """
    exp_inds = [i for i in range(B.num_terms) if (isinstance(B.term_defs[i], terms.FuncTerm)
                                                  and B.term_defs[i].func == terms.exp)]

    for i in exp_inds:
        coeff, t = B.term_defs[i].args[0].coeff, B.term_defs[B.term_defs[i].args[0].term.index]
        if isinstance(t, terms.AddTerm):
            margs = [B.term_name((terms.exp(a) ** coeff).canonize().term) for a in t.args]
            t2 = reduce(lambda x, y: x*y, margs, 1).canonize()
            n = B.term_name(t2.term)
            B.assert_comparison(terms.IVar(i) == t2.coeff * n)
        elif coeff != 1:
            term2 = (terms.exp(t)**coeff).canonize()
            n = B.term_name(term2.term)
            B.assert_comparison(terms.IVar(i) == term2.coeff * n)
コード例 #2
0
def exp_factor_constant(B):
    """
    Takes a Blackboard B. For each i,
    If B.term_defs[i] is of the form exp(c*t), will declare that it is equal to exp(t)**c
    """
    exp_inds = [i for i in range(B.num_terms) if (isinstance(B.term_defs[i], terms.FuncTerm)
                                                  and B.term_defs[i].func == terms.exp)]
    for i in exp_inds:
        exponent = B.term_defs[i].args[0]
        if exponent.coeff != 1:
            term2 = (terms.exp(exponent.term)**exponent.coeff).canonize()
            n = B.term_name(term2.term)
            B.assert_comparison(terms.IVar(i) == term2.coeff * n)
コード例 #3
0
def exp_factor_constant(B):
    """
    Takes a Blackboard B. For each i,
    If B.term_defs[i] is of the form exp(c*t), will declare that it is equal to exp(t)**c
    """
    exp_inds = [i for i in range(B.num_terms) if (isinstance(B.term_defs[i], terms.FuncTerm)
                                                  and B.term_defs[i].func == terms.exp)]
    for i in exp_inds:
        exponent = B.term_defs[i].args[0]
        if exponent.coeff != 1:
            term2 = (terms.exp(exponent.term)**exponent.coeff).canonize()
            n = B.term_name(term2.term)
            B.assert_comparison(terms.IVar(i) == term2.coeff * n)
コード例 #4
0
 def update_blackboard(self, B):
     """
     Asserts identities about exp and log terms found in B.
     """
     timer.start(timer.EXP)
     messages.announce_module('exponential module')
     if any(isinstance(t, terms.FuncTerm) and t.func == terms.exp for t in B.term_defs.values()):
         B.assert_comparison(terms.exp(0) == 1)
     if any(isinstance(t, terms.FuncTerm) and t.func == terms.log for t in B.term_defs.values()):
         B.assert_comparison(terms.log(1) == 0)
     exp_factor_constant(B)
     exp_factor_sum(B)
     log_factor_exponent(B)
     log_factor_product(B)
     timer.stop(timer.EXP)
コード例 #5
0
 def update_blackboard(self, B):
     """
     Asserts identities about exp and log terms found in B.
     """
     timer.start(timer.EXP)
     messages.announce_module('exponential module')
     if any(isinstance(t, terms.FuncTerm) and t.func == terms.exp for t in B.term_defs.values()):
         B.assert_comparison(terms.exp(0) == 1)
     if any(isinstance(t, terms.FuncTerm) and t.func == terms.log for t in B.term_defs.values()):
         B.assert_comparison(terms.log(1) == 0)
     exp_factor_constant(B)
     exp_factor_sum(B)
     #exp_factor_both(B)
     log_factor_exponent(B)
     log_factor_product(B)
     timer.stop(timer.EXP)
コード例 #6
0
def exp_factor_sum(B):
    """
    Takes a Blackboard and a list of IVar indices, s.t. i in exp_inds implies B.term_defs[i] is an
    exponential function.
    Asserts a number of comparisons to B.
    If B.term_defs[i] is of the form exp(t_1 + ct_2 + ...), will declare that it is equal to
    exp(t_1)*exp(ct_2)*...
    """

    exp_inds = [i for i in range(B.num_terms) if (isinstance(B.term_defs[i], terms.FuncTerm)
                                                  and B.term_defs[i].func == terms.exp)]
    for i in exp_inds:
        coeff, t = B.term_defs[i].args[0].coeff, B.term_defs[B.term_defs[i].args[0].term.index]
        if isinstance(t, terms.AddTerm) and coeff == 1:
            margs = [B.term_name(terms.exp(a).canonize().term) for a in t.args]
            t2 = reduce(lambda x, y: x*y, margs, 1).canonize()
            n = B.term_name(t2.term)
            B.assert_comparison(terms.IVar(i) == t2.coeff * n)
コード例 #7
0
def exp_factor_sum(B):
    """
    Takes a Blackboard and a list of IVar indices, s.t. i in exp_inds implies B.term_defs[i] is an
    exponential function.
    Asserts a number of comparisons to B.
    If B.term_defs[i] is of the form exp(t_1 + ct_2 + ...), will declare that it is equal to
    exp(t_1)*exp(ct_2)*...
    """

    exp_inds = [i for i in range(B.num_terms) if (isinstance(B.term_defs[i], terms.FuncTerm)
                                                  and B.term_defs[i].func == terms.exp)]
    for i in exp_inds:
        coeff, t = B.term_defs[i].args[0].coeff, B.term_defs[B.term_defs[i].args[0].term.index]
        if isinstance(t, terms.AddTerm) and coeff == 1:
            margs = [B.term_name(terms.exp(a).canonize().term) for a in t.args]
            t2 = reduce(lambda x, y: x*y, margs, 1).canonize()
            n = B.term_name(t2.term)
            B.assert_comparison(terms.IVar(i) == t2.coeff * n)
コード例 #8
0
    def __init__(self, am):
        """
        The exponential module must be instantiated with an axiom module to add axioms to.
        Asserts a list of axioms to this module.
        """
        self.am = am
        x, y = terms.Vars('x y')
        self.am.add_axiom(formulas.Forall([x], terms.exp(x) > 0))
#        self.am.add_axiom(formulas.Forall([x], terms.exp(x) > x))
        self.am.add_axiom(formulas.Forall([x], formulas.Implies(x >= 0, terms.exp(x) >= 1)))
        self.am.add_axiom(formulas.Forall([x], formulas.Implies(x > 0, terms.exp(x) > 1)))
        self.am.add_axiom(formulas.Forall([x, y],
                                          formulas.Implies(x < y, terms.exp(x) < terms.exp(y))))
        self.am.add_axiom(formulas.Forall([x, y],
                                          formulas.Implies(x <= y, terms.exp(x) <= terms.exp(y))))
        self.am.add_axiom(formulas.Forall([x, y],
                                          formulas.Implies(x != y, terms.exp(x) != terms.exp(y))))
        self.am.add_axiom(formulas.Forall([x], formulas.Implies(x >= 1, terms.log(x) >= 0)))
        self.am.add_axiom(formulas.Forall([x], formulas.Implies(x > 1, terms.log(x) > 0)))
        self.am.add_axiom(formulas.Forall([x], formulas.Implies(x > 0, terms.log(x) < x)))
        self.am.add_axiom(formulas.Forall([x, y], formulas.Implies(formulas.And(x > 0, x < y),
                                                                   terms.log(x) < terms.log(y))))
        self.am.add_axiom(formulas.Forall([x, y], formulas.Implies(formulas.And(x > 0, x <= y),
                                                                   terms.log(x) <= terms.log(y))))
        self.am.add_axiom(formulas.Forall([x, y], formulas.Implies(formulas.And(x > 0, y > 0, x != y),
                                                                   terms.log(x) != terms.log(y))))
        self.am.add_axiom(formulas.Forall([x], formulas.Implies(x > 0, terms.exp(terms.log(x)) == x)))
        self.am.add_axiom(formulas.Forall([x], terms.log(terms.exp(x)) == x))
コード例 #9
0
ファイル: builtins_module.py プロジェクト: skaslev/polya
tan_axioms = [Forall([x], tan(x) == sin(x) / cos(x))]

floor_axioms = [Forall([x], And(floor(x) <= x, floor(x) > x-1))]

abs_axioms=[
    Forall([x, y], And(abs(x + y) >= abs(x) + abs(y), abs(x - y) >= abs(x) - abs(y))),
    formulas.Forall([x], terms.abs_val(x) >= 0),
    formulas.Forall([x], terms.abs_val(x) >= x),
    formulas.Forall([x], terms.abs_val(x) >= -x),
    formulas.Forall([x], formulas.Implies(x >= 0, terms.abs_val(x) == x)),
    formulas.Forall([x], formulas.Implies(x <= 0, terms.abs_val(x) == -x))
]

exp_axioms = [
    formulas.Forall([x], terms.exp(x) > 0),
    #formulas.Forall([x], terms.exp(x) > x),
    formulas.Forall([x], formulas.Implies(x >= 0, terms.exp(x) >= 1)),
    formulas.Forall([x], formulas.Implies(x > 0, terms.exp(x) > 1)),
    formulas.Forall([x, y],
                                      formulas.Implies(x < y, terms.exp(x) < terms.exp(y))),
    formulas.Forall([x, y],
                                      formulas.Implies(x <= y, terms.exp(x) <= terms.exp(y))),
    formulas.Forall([x, y],
                                      formulas.Implies(x != y, terms.exp(x) != terms.exp(y)))
]

log_axioms = [
    formulas.Forall([x], formulas.Implies(x >= 1, terms.log(x) >= 0)),
    formulas.Forall([x], formulas.Implies(x > 1, terms.log(x) > 0)),
    formulas.Forall([x], formulas.Implies(x > 0, terms.log(x) < x)),