Example #1
0
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)
evaluator.add_rule(pc.Type(pc.sign(s.x)),pc.Types.Integer)
evaluator.add_rule(pc.Type(pc.floor(s.x)),pc.Types.Integer)
evaluator.add_rule(pc.Type(pc.ceil(s.x)),pc.Types.Integer)
evaluator.add_rule(pc.Type(pc.round(s.x)),pc.Types.Integer)
evaluator.add_rule(pc.Type(pc.mod(s.x,s.y)),pc.Types.Integer)

evaluator.add_rule(pc.Type(pc.Abs(s.x)),pc.OperationType(pc.Abs(pc.Type(s.x))))
evaluator.add_rule(pc.OperationType(pc.Abs(pc.Types.Complex)),pc.Types.Real)
evaluator.add_rule(pc.OperationType(pc.Abs(pc.Types.Imaginary)),pc.Types.Real)
evaluator.add_rule(pc.OperationType(pc.Abs(pc.Types.Real)),pc.Types.Real)
evaluator.add_rule(pc.OperationType(pc.Abs(pc.Types.Rational)),pc.Types.Rational)
evaluator.add_rule(pc.OperationType(pc.Abs(pc.Types.Integer)),pc.Types.Natural)
evaluator.add_rule(pc.OperationType(pc.Abs(pc.Types.Natural)),pc.Types.Natural)


evaluator.add_rule(pc.Type(pc.real(s.x)),pc.Types.Real)
Example #2
0
                   condition=pc.And(is_pure_numeric(s.a),
                                    is_explicit_natural(s.c)))

evaluator.add_rule((s.a + s.b)**2, (s.a**2 + 2 * s.a * s.b + s.b**2),
                   condition=pc.And(is_numeric(s.a), is_numeric(s.b)))
evaluator.add_rule(s.a * (s.b + s.c),
                   s.a * s.b + s.a * s.c,
                   condition=pc.And(is_pure_numeric(s.a), is_numeric(s.b),
                                    is_numeric(s.c)))

evaluator.add_rule(pc.I**s.n, (-1)**(s.n / 2), condition=is_even(s.n))
evaluator.add_rule(pc.I**s.n,
                   pc.I * (-1)**(s.n / 2 - 0.5),
                   condition=is_uneven(s.n))

evaluator.add_rule(pc.sign(-s.x), -1, condition=is_explicit_natural(s.x))
evaluator.add_rule(pc.sign(s.x), 1, condition=is_explicit_natural(s.x))

import fractions


def evaluate_fraction(m):
    vx = m[s.x].value
    vy = m[s.y].value
    res = fractions.Fraction(vx, vy)
    if (res.numerator, res.denominator) == (vx, vy):
        return False
    m[s.a] = res.numerator
    m[s.b] = res.denominator

Example #3
0
    common = ma.intersection(mb)
    if len(common) == 0:
        return False

    for v,mul in common:
        if v.function == pc.sign:
            return False

    m[s.a] = (ma-common).as_expression()
    m[s.b] = (mb-common).as_expression()
    m[s.c] = common.as_expression()

evaluator.add_rule(-s.x<-s.y, s.y<s.x)


evaluator.add_rule(s.x<s.y, pc.sign(s.c)*s.a<pc.sign(s.c)*s.b, extract_comp_mul_intersection)
evaluator.add_rule(s.x<-s.y, pc.sign(s.c)*s.a<-pc.sign(s.c)*s.b, extract_comp_mul_intersection)
evaluator.add_rule(-s.x<s.y, -pc.sign(s.c)*s.a<pc.sign(s.c)*s.b, extract_comp_mul_intersection)


evaluator.add_rule(pc.sign(s.a),1,condition=s.a>=0)
evaluator.add_rule(pc.sign(s.a),-1,condition=s.a<0)
evaluator.add_rule(pc.sign(s.a*s.b),pc.sign(s.a)*pc.sign(s.b))

evaluator.add_rule(pc.sign(s.a**s.n),1,condition=is_even(s.n))
evaluator.add_rule(pc.sign(s.a**s.n),pc.sign(s.a),condition=is_uneven(s.n))




from .logic_evaluator import is_function_type
Example #4
0
    if len(common) == 0:
        return False

    for v, mul in common:
        if v.function == pc.sign:
            return False

    m[s.a] = (ma - common).as_expression()
    m[s.b] = (mb - common).as_expression()
    m[s.c] = common.as_expression()


evaluator.add_rule(-s.x < -s.y, s.y < s.x)

evaluator.add_rule(s.x < s.y,
                   pc.sign(s.c) * s.a < pc.sign(s.c) * s.b,
                   extract_comp_mul_intersection)
evaluator.add_rule(s.x < -s.y,
                   pc.sign(s.c) * s.a < -pc.sign(s.c) * s.b,
                   extract_comp_mul_intersection)
evaluator.add_rule(-s.x < s.y, -pc.sign(s.c) * s.a < pc.sign(s.c) * s.b,
                   extract_comp_mul_intersection)

evaluator.add_rule(pc.sign(s.a), 1, condition=s.a >= 0)
evaluator.add_rule(pc.sign(s.a), -1, condition=s.a < 0)
evaluator.add_rule(pc.sign(s.a * s.b), pc.sign(s.a) * pc.sign(s.b))

evaluator.add_rule(pc.sign(s.a**s.n), 1, condition=is_even(s.n))
evaluator.add_rule(pc.sign(s.a**s.n), pc.sign(s.a), condition=is_uneven(s.n))

from .logic_evaluator import is_function_type
Example #5
0
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)
evaluator.add_rule(pc.Type(pc.sign(s.x)), pc.Types.Integer)
evaluator.add_rule(pc.Type(pc.floor(s.x)), pc.Types.Integer)
evaluator.add_rule(pc.Type(pc.ceil(s.x)), pc.Types.Integer)
evaluator.add_rule(pc.Type(pc.round(s.x)), pc.Types.Integer)
evaluator.add_rule(pc.Type(pc.mod(s.x, s.y)), pc.Types.Integer)

evaluator.add_rule(pc.Type(pc.Abs(s.x)),
                   pc.OperationType(pc.Abs(pc.Type(s.x))))
evaluator.add_rule(pc.OperationType(pc.Abs(pc.Types.Complex)), pc.Types.Real)
evaluator.add_rule(pc.OperationType(pc.Abs(pc.Types.Imaginary)), pc.Types.Real)
evaluator.add_rule(pc.OperationType(pc.Abs(pc.Types.Real)), pc.Types.Real)
evaluator.add_rule(pc.OperationType(pc.Abs(pc.Types.Rational)),
                   pc.Types.Rational)
evaluator.add_rule(pc.OperationType(pc.Abs(pc.Types.Integer)),
                   pc.Types.Natural)
evaluator.add_rule(pc.OperationType(pc.Abs(pc.Types.Natural)),
from .logic_evaluator import is_pure_numeric,is_numeric

evaluator.add_rule(s.a+s.b*s.c**-1,(s.a*s.c+s.b)*s.c**-1,condition=pc.And(is_pure_numeric(s.a),are_explicit_numbers(s.b,s.c)))
evaluator.add_rule(s.a-s.b*s.c**-1,(s.a*s.c-s.b)*s.c**-1,condition=pc.And(is_pure_numeric(s.a),are_explicit_numbers(s.b,s.c)))

evaluator.add_rule(s.a+s.c**-1,(s.a*s.c+1)*s.c**-1,condition=pc.And(is_pure_numeric(s.a),is_explicit_natural(s.c)))
evaluator.add_rule(s.a-s.c**-1,(s.a*s.c-1)*s.c**-1,condition=pc.And(is_pure_numeric(s.a),is_explicit_natural(s.c)))


evaluator.add_rule((s.a+s.b)**2,(s.a**2+2*s.a*s.b+s.b**2),condition=pc.And(is_numeric(s.a),is_numeric(s.b)))
evaluator.add_rule(s.a*(s.b+s.c),s.a*s.b+s.a*s.c,condition=pc.And(is_pure_numeric(s.a),is_numeric(s.b),is_numeric(s.c)))

evaluator.add_rule(pc.I**s.n,(-1)**(s.n/2),condition=is_even(s.n))
evaluator.add_rule(pc.I**s.n,pc.I*(-1)**(s.n/2-0.5),condition=is_uneven(s.n))

evaluator.add_rule(pc.sign(-s.x),-1,condition=is_explicit_natural(s.x))
evaluator.add_rule(pc.sign(s.x),1,condition=is_explicit_natural(s.x))

import fractions

def evaluate_fraction(m):
    vx = m[s.x].value
    vy = m[s.y].value
    res = fractions.Fraction(vx,vy)
    if (res.numerator,res.denominator) == (vx,vy):
        return False
    m[s.a] = res.numerator
    m[s.b] = res.denominator

evaluator.add_rule(s.x*s.y**-1,s.a*s.b**-1,evaluate_fraction,condition=are_explicit_numbers(s.x, s.y))