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 analyze_rec(self, template: Expression, template_conditions: List, expression: Expression, analysis: MatchAnalysisReport) -> MatchAnalysisReport: if not analysis.expression_match_template: return analysis # Handle two simpy expressions if not template.contains_user_defined_funct( ) and not expression.contains_user_defined_funct(): # TODO: REFACTOR conditions = template_conditions.get( template.to_expression_string()) if conditions != None and "IS_CONSTANT" in conditions: match = expression.is_constant() else: match = template.is_equivalent_to(expression) analysis = self.build_match_analysis_report( match, analysis, template, template_conditions, expression) elif template.is_user_defined_func(): match = template.free_symbols_match(expression) analysis = self.build_match_analysis_report( match, analysis, template, template_conditions, expression) elif not template.compare_func(expression): analysis = self.build_match_analysis_report( False, analysis, template, template_conditions, expression) # Handle non leaves with at least one user defined function elif template.children_amount() == expression.children_amount(): analysis = self.analyze_exp_with_user_def_func_eq_sizes( template, template_conditions, expression, analysis) # Handle different size children. for example f(x) = x + x^2 else: analysis = self.analyze_exp_with_user_def_func_diff_sizes( template, template_conditions, expression, analysis) return analysis