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))) from .type_evaluator import issubtype format_evaluator = pc.RewriteEvaluator(recursive=True,split_binary=True) format_evaluator.add_rule(s.x**-1,1/s.x) format_evaluator.add_rule(s.x ** -s.y, 1 / s.x ** s.y, lambda m:isinstance(m[s.y].value, pc.Number)) format_evaluator.add_rule(pc.e**s.x,pc.exp(s.x)) format_evaluator.add_rule(s.x**(1/pc.S(2)),pc.sqrt(s.x)) format_evaluator.add_rule(pc.sqrt(s.x)*pc.sqrt(s.y),pc.sqrt(s.x*s.y),condition=pc.Or(s.x>0,s.y>0))
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))) from .type_evaluator import issubtype format_evaluator = pc.RewriteEvaluator(recursive=True, split_binary=True) format_evaluator.add_rule(s.x**-1, 1 / s.x) format_evaluator.add_rule(s.x**-s.y, 1 / s.x**s.y, lambda m: isinstance(m[s.y].value, pc.Number)) format_evaluator.add_rule(pc.e**s.x, pc.exp(s.x)) format_evaluator.add_rule(s.x**(1 / pc.S(2)), pc.sqrt(s.x)) format_evaluator.add_rule(pc.sqrt(s.x) * pc.sqrt(s.y), pc.sqrt(s.x * s.y),
break if valid: break if valid == False: return False m[s.c] = (ma+mb).as_expression() evaluator.add_rule(s.x*s.y**s.n, s.c, evaluate_fraction,condition=issubtype(s.n,pc.Types.Integer)) evaluator.add_rule(pc.log(pc.e), 1) evaluator.add_rule(pc.log(1), 0) evaluator.add_rule(pc.sin(0), 0) evaluator.add_rule(pc.cos(0), 1) evaluator.add_rule(pc.tan(0), 0) evaluator.add_rule(pc.atan(0), 0) evaluator.add_rule(pc.Indicator(True), 1) evaluator.add_rule(pc.Indicator(False), 0) evaluator.add_rule(pc.InnerPiecewise((s.a,True),s.x),(s.a,True)) evaluator.add_rule(pc.InnerPiecewise((s.a,False),s.x),s.x) evaluator.add_rule(pc.InnerPiecewise(s.x,(s.a,False)),s.x) evaluator.add_rule(pc.InnerPiecewise((s.a,s.x),(s.b,s.x)),(s.a,s.x)) evaluator.add_rule(pc.InnerPiecewise((s.x,s.a),(s.x,s.b)),(s.x,pc.Or(s.a,s.b))) evaluator.add_rule(pc.InnerPiecewise(pc.InnerPiecewise(s.x)),pc.InnerPiecewise(s.x)) evaluator.add_rule(pc.OuterPiecewise((s.a,s.b)),s.a*pc.Indicator(s.b))
if valid == False: return False m[s.c] = (ma + mb).as_expression() evaluator.add_rule(s.x * s.y**s.n, s.c, evaluate_fraction, condition=issubtype(s.n, pc.Types.Integer)) evaluator.add_rule(pc.log(pc.e), 1) evaluator.add_rule(pc.log(1), 0) evaluator.add_rule(pc.sin(0), 0) evaluator.add_rule(pc.cos(0), 1) evaluator.add_rule(pc.tan(0), 0) evaluator.add_rule(pc.atan(0), 0) evaluator.add_rule(pc.Indicator(True), 1) evaluator.add_rule(pc.Indicator(False), 0) evaluator.add_rule(pc.InnerPiecewise((s.a, True), s.x), (s.a, True)) evaluator.add_rule(pc.InnerPiecewise((s.a, False), s.x), s.x) evaluator.add_rule(pc.InnerPiecewise(s.x, (s.a, False)), s.x) evaluator.add_rule(pc.InnerPiecewise((s.a, s.x), (s.b, s.x)), (s.a, s.x)) evaluator.add_rule(pc.InnerPiecewise((s.x, s.a), (s.x, s.b)), (s.x, pc.Or(s.a, s.b))) evaluator.add_rule(pc.InnerPiecewise(pc.InnerPiecewise(s.x)), pc.InnerPiecewise(s.x))