def analyze_exp_with_user_def_func_diff_sizes( self, template: Expression, template_conditions: List, expression: Expression, analysis: MatchAnalysisReport) -> MatchAnalysisReport: if template.children_amount() >= expression.children_amount(): return self.build_match_analysis_report(False, analysis, template, template_conditions, expression) possible_expression_children = expression.get_children_with_size( template.children_amount()) for children in possible_expression_children: if template.is_commutative(): new_analysis = self.analyze_commutative_children_eq_len( template.get_children(), template_conditions, children, analysis) else: new_analysis = self.analyze_children_non_commutative_eq_len( template.get_children(), template_conditions, children, analysis) if new_analysis.expression_match_template: return new_analysis return self.build_match_analysis_report(False, analysis, template, template_conditions, expression)
def analyze_children_non_commutative_eq_len( self, template: Expression, template_conditions: List, expression: Expression, analysis: MatchAnalysisReport) -> MatchAnalysisReport: result = analysis template_children = template.get_children() expression_children = expression.get_children() for i in range(0, len(template)): result = self.analyze_rec(template_children[i], template_conditions, expression_children[i], result) return result
def analyze_exp_with_user_def_func_eq_sizes( self, template: Expression, template_conditions: List, expression: Expression, analysis: MatchAnalysisReport) -> MatchAnalysisReport: if template.compare_func(expression): if template.is_commutative(): return self.analyze_commutative_children_eq_len( template.get_children(), template_conditions, expression.get_children(), analysis) else: return self.analyze_children_non_commutative_eq_len( template, template_conditions, expression, analysis)
def test_get_children_derivative(self): exp = Expression("x^3 + \\frac{d(x)}{dx} + \\frac{d(x^2)}{dx}") children = exp.get_children() self.assertEqual(3, len(children)) self.assertTrue(Expression("\\frac{d(x^2)}{dx}") in children) self.assertTrue(Expression("\\frac{d(x)}{dx}") in children) self.assertTrue(Expression("x^3") in children)
def test_get_children(self): exp = Expression("x + x^2") children = exp.get_children() self.assertEqual(2, len(children)) self.assertTrue(Expression("x") in children) self.assertTrue(Expression("x^2") in children)
def test_get_children_add_three_elements(self): exp = Expression("x + x^2 + x^3") children = exp.get_children() self.assertEqual(3, len(children)) self.assertTrue(Expression("x") in children) self.assertTrue(Expression("x^2") in children) self.assertTrue(Expression("x^3") in children)