def contains_evaluator(m):
    search = m[s.y]
    m[s.z] = pc.Or(*[contains_atomic(arg, search) for arg in m[s.x].args])
logic_evaluator.add_rule(contains_atomic(s.x, s.y),
                         s.z,
                         contains_evaluator,
                         condition=is_function(s.x))

logic_evaluator.add_rule(pc.Xor(False, False), False)
logic_evaluator.add_rule(pc.Xor(True, False), True)
logic_evaluator.add_rule(pc.Xor(False, True), True)
logic_evaluator.add_rule(pc.Xor(True, True), False)

logic_evaluator.add_rule(pc.Not(True), False)
logic_evaluator.add_rule(pc.Not(False), True)

logic_evaluator.add_rule(pc.And(s.x, True), s.x)
logic_evaluator.add_rule(pc.And(s.x, False), False)
logic_evaluator.add_rule(pc.Or(s.x, True), True)
logic_evaluator.add_rule(pc.Or(s.x, False), s.x)

logic_evaluator.add_rule(pc.Not(pc.Not(s.x)), s.x)
logic_evaluator.add_rule(pc.And(s.x, pc.Not(s.x)), False)
logic_evaluator.add_rule(pc.Or(s.x, pc.Not(s.x)), True)

logic_evaluator.add_rule(pc.And(s.x, s.x), s.x)
logic_evaluator.add_rule(pc.Or(s.x, s.x), s.x)

logic_evaluator.add_rule(pc.equal(s.x, s.x), True)

logic_evaluator.add_rule(-s.x < -s.y, s.y < s.x)
'''
logic_evaluator.add_rule(s.x<s.x,False);
logic_evaluator.add_rule(-s.x<-s.y,s.y<s.x);
Beispiel #3
0
from .type_evaluator import issubtype

evaluator.add_rule((s.x**s.a)**(s.a**-1),
                   abs(s.x),
                   condition=pc.And(issubtype(s.x, pc.Types.Real),
                                    is_even(s.a)))
evaluator.add_rule((s.x**s.a)**(s.a**-1),
                   s.x,
                   condition=pc.And(issubtype(s.x, pc.Types.Real),
                                    is_uneven(s.a)))

evaluator.add_rule((-s.x)**(s.a), s.x**s.a, condition=is_even(s.a))
evaluator.add_rule((-s.x)**(s.a), -(s.x)**s.a, condition=is_uneven(s.a))

factor_evaluator.add_rule(s.x**s.n * s.y**-s.n, (s.x * s.y**-1)**s.n,
                          condition=pc.Or(s.y > 0,
                                          issubtype(s.n, pc.Types.Integer)))

factor_evaluator.add_rule(s.x**s.a / s.y**s.a, (s.x / s.y)**s.a,
                          condition=pc.Or(s.x > 0, s.y > 0,
                                          issubtype(s.a, pc.Types.Integer)))
factor_evaluator.add_rule(s.x**s.a * s.y**s.a, (s.x * s.y)**s.a,
                          condition=pc.Or(s.x > 0, s.y > 0,
                                          issubtype(s.a, pc.Types.Integer)))
factor_evaluator.add_rule(s.x**s.a * s.y**-s.a, (s.x / s.y)**s.a,
                          condition=pc.Or(s.x > 0, s.y > 0,
                                          issubtype(s.a, pc.Types.Integer)))

factor_evaluator.add_rule(s.x**s.n * s.x, s.x**(s.n + 1))
factor_evaluator.add_rule(s.x**s.n * s.x**s.m, s.x**(s.n + s.m))

from .logic_evaluator import is_explicit_natural
Beispiel #4
0
canonical_form.add_rule(1 / s.x, s.x**-1)
canonical_form.add_rule(pc.exp(s.x), pc.e**s.x)
canonical_form.add_rule(s.x**s.y,
                        s.z,
                        normalize_exponentiation,
                        condition=pc.equal(
                            pc.DominantType(pc.Type(s.y), pc.Types.Real),
                            pc.Types.Real))

canonical_form.add_rule(pc.exp(s.x), pc.e**s.x)
canonical_form.add_rule(pc.sqrt(s.x), s.x**(1 / pc.S(2)))

canonical_form.add_rule(s.x > s.y, s.y < s.x)
canonical_form.add_rule(s.x >= s.y, s.y <= s.x)
canonical_form.add_rule(s.x <= s.y, pc.Or(s.x < s.y, pc.equal(s.x, s.y)))
canonical_form.add_rule(pc.unequal(s.x, s.y), pc.Not(pc.equal(s.x, s.y)))

canonical_form.add_rule(abs(s.x),
                        pc.Max(s.x, -s.x),
                        condition=pc.equal(
                            pc.DominantType(pc.Type(s.x), pc.Types.Real),
                            pc.Types.Real))

canonical_form.add_rule(pc.Max(s.a, s.b), -pc.Min(-s.a, -s.b))

canonical_form.add_rule(pc.tan(s.x), pc.sin(s.x) / pc.cos(s.x))
canonical_form.add_rule(pc.cot(s.x), pc.cos(s.x) / pc.sin(s.x))

#canonical_form.add_rule(abs(s.x)<s.y,pc.And(s.x<s.y,-s.x<s.y),condition=pc.And(s.y>0,pc.equal(pc.DominantType(pc.Type(s.x),pc.Types.Real),pc.Types.Real)))
Beispiel #5
0
                       pc.Types.Imaginary)
evaluator.add_rule(pc.OperationType(pc.Types.Imaginary * pc.Types.Imaginary),
                   pc.Types.Real)

evaluator.add_rule(pc.OperationType(s.x**pc.Types.Natural), s.x)
evaluator.add_rule(pc.OperationType(s.x**pc.Types.Integer),
                   pc.DominantType(s.x, pc.Types.Rational))
evaluator.add_rule(pc.OperationType(pc.Types.Natural**pc.Types.Rational),
                   pc.Types.Real)

evaluator.add_rule(pc.OperationType(s.x**s.y), pc.Types.Complex)

evaluator.add_rule(pc.OperationType(s.x * s.y),
                   pc.DominantType(s.x, s.y),
                   condition=pc.Not(
                       pc.Or(is_function_type(s.x, pc.Type),
                             is_function_type(s.y, pc.Type))))
evaluator.add_rule(pc.OperationType(s.x)**s.y,
                   pc.DominantType(s.x, s.y),
                   condition=pc.Not(
                       pc.Or(is_function_type(s.x, pc.Type),
                             is_function_type(s.y, pc.Type))))

evaluator.add_rule(pc.Type(s.x + s.y),
                   pc.DominantType(pc.Type(s.x), pc.Type(s.y)))
evaluator.add_rule(pc.Type(-s.x),
                   pc.DominantType(pc.Types.Integer, pc.Type(s.x)))
evaluator.add_rule(pc.Type(pc.pi), pc.Types.Real)
evaluator.add_rule(pc.Type(pc.e), pc.Types.Real)
evaluator.add_rule(pc.Type(pc.I), pc.Types.Imaginary)

evaluator.add_rule(pc.Type(pc.factorial(s.x)), pc.Types.Natural)