def apply(self, name, value): terms_counter_analyzer = TermsCounterAnalyzer(self._term_list) terms = terms_counter_analyzer.get_variables_with_name(name) if len(terms) == 0: raise LookupError self._remove_terms(terms) for term in terms: term.multiply(value) self.add_term(ConstantBuilder().value(term.value).build())
def get_value_variable(self, name): terms_counter_analyzer = TermsCounterAnalyzer(self._term_list) terms = terms_counter_analyzer.get_variables_with_name(name) if 1 == len(terms): return terms[0].value elif 1 < len(terms): raise NotSimplified else: return 0
def apply_expression(self, name, expression): terms_counter_analyzer = TermsCounterAnalyzer(self._term_list) terms = terms_counter_analyzer.get_variables_with_name(name) if len(terms) == 0: raise LookupError self._remove_terms(terms) for term in terms: temp_expression = expression.clon() temp_expression.multiply(term.value) self.add_expression(temp_expression)
def simplify_variable(self, name): terms_counter_analyzer = TermsCounterAnalyzer(self._term_list) terms = terms_counter_analyzer.get_variables_with_name(name) if 0 == len(terms): return self._remove_terms(terms) variable_value = self._get_added_terms_value(terms) if 0 == variable_value: self.add_term(ConstantBuilder().value(variable_value).build()) else: self.add_term(Variable(name, variable_value))