def apply_to(self, expression: Expression) -> List[Expression]:
     if expression.to_expression_string(
     ) == 'Integral(u(x)*Derivative(v(x), x), x)':
         return [
             Expression(
                 'u(x) * v(x) - \\int (\\frac{d(u(x))}{dx} * v(x)) dx',
                 expression.variables)
         ]
     return []
    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
 def apply_to(self, expression: Expression) -> List[Expression]:
     if expression.to_expression_string(
     ) == 'u(x)*v(x) - Integral(v(x)*Derivative(u(x), x), x)':
         return [expression.replace_variables()]
     return []
 def there_is_a_chance_to_apply_to(self, expression: Expression):
     return expression.to_expression_string(
     ) == 'Integral(u(x)*Derivative(v(x), x), x)'
Exemplo n.º 5
0
 def test_solve_derivatives(self):
     exp = Expression("\\frac{d(x)}{dx}")
     exp = exp.solve_derivatives()
     self.assertEqual(exp.to_expression_string(), '1')