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 apply_to_children(self, expression: Expression, from_side: Expression, to_side: Expression) -> List[Expression]: application_possibilities = [] template = from_side already_tried = set() # try applying to groups of children # for example in x + y + z # try with: x + y ; x + z : y + z if expression.can_group_children(): logger.info("Trying to apply: " + self.name + " to a group children: " + str(expression)) for size in range(2, expression.children_amount() + 1): children_of_size_n_possibilities = expression.get_child_with_size_possibilities( size) for child_of_size_n in children_of_size_n_possibilities: if str(child_of_size_n) not in already_tried: analysis = self.analyzer.analyze( template, self.conditions, child_of_size_n) if analysis.expression_match_template: application_possibilities.append(TheoremApplication( child_of_size_n, self.transform_side(to_side, analysis.equalities))) already_tried.add(str(child_of_size_n)) return application_possibilities
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