Beispiel #1
0
	def _doReplace(self,norm_exp):
		#Search for the free variable in the norm_exp's terms
		pos=find_term(self.free_var,norm_exp.terms)

		#If we found the variable
		if None is not pos:
			#Get the variable to potentially be removed
			remove_var=norm_exp.terms[pos]

			#If we are removing equalities OR
			#If we are removing inequalities AND the var has the opposite sign of the found variable
			#remove the found var and add in the equivalent expression
			if self.remove_equality or (not self.remove_equality and self.free_var.coeff*-1==sign(remove_var.coeff)):
				#Multiply the expression to replace the free variable by its coefficient
				replace_exp=NormExp([],remove_var.coeff)*self.exp

				#Subtract off the variable
				new_exp=norm_exp-NormExp([remove_var],0)

				#Add in the replacement expression
				new_exp=new_exp+replace_exp

				#Update the current norm_exp with the new terms and constant
				norm_exp.terms=new_exp.terms
				norm_exp.const=new_exp.const

				self.replaced=True
				self.changed=True
Beispiel #2
0
	def inNormExp(self,node):
		new_terms=[]

		#Look at each term in the terms collection
		for term in node.terms:
			#Search for a similar term is present in the new_terms
			pos=find_term(term,new_terms)

			#If one is not found, append the term
			if None is pos:
				new_terms.append(term)
			else:
				#Otherwise update the located term's coefficient
				new_terms[pos].coeff+=term.coeff
				self.merged_terms=True
		node.terms=new_terms