] m[s.z] = pc.multiplication(*exponents) canonical_form.add_rule(pc.multiplication(s.x), s.x) canonical_form.add_rule(pc.addition(s.x), s.x) canonical_form.add_rule(pc.exponentiation(s.x), s.x) 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))
def issubtype(x, t): return pc.equal(pc.DominantType(pc.Type(x), t), t)
evaluator.add_rule(s.x * 1, s.x) evaluator.add_rule(s.x * 0, 0) evaluator.add_rule(s.x**1, s.x) evaluator.add_rule(s.x**0, 1) evaluator.add_rule(1**s.x, 1) evaluator.add_rule(0**s.x, 0, condition=s.x > 0) factor_evaluator.add_rule(s.x * s.x, s.x**2) evaluator.add_rule(s.x * s.x**-1, 1) evaluator.add_rule( (s.x**s.a)**s.b, s.x**(s.a * s.b), condition=pc.equal(pc.DominantType(pc.Type(s.b), pc.Types.Integer), pc.Types.Integer)) from .numeric_evaluator import is_even, is_uneven 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))
import expresso.pycas as pc from . import rule_symbols as s ordered_types = (pc.Types.Boolean, pc.Types.Natural, pc.Types.Integer, pc.Types.Rational, pc.Types.Real, pc.Types.Complex) evaluator = pc.RewriteEvaluator(recursive=True, split_binary=True) from .logic_evaluator import is_explicit_natural, is_function_type evaluator.add_rule(pc.DominantType(s.x), s.x) for i in range(len(ordered_types)): evaluator.add_rule(pc.DominantType(pc.Types.Imaginary, ordered_types[i]), pc.Types.Complex) evaluator.add_rule(pc.Type(ordered_types[i]), pc.Types.Type) for j in range(i): evaluator.add_rule(pc.DominantType(ordered_types[j], ordered_types[i]), ordered_types[i]) def eval_type_equality(m): tx = m[s.x] ty = m[s.y] if tx in ordered_types and ty in ordered_types: m[s.z] = tx == ty return True return False evaluator.add_rule(pc.equal(s.x, s.y), False, eval_type_equality)