Ejemplo n.º 1
0
def substitute(lhs,rhs,term):
	global substitutions
	substitutions.clear()
	if match_terms(lhs,term):
		term = Rule(rhs.string)
		term = substitute_helper(term)
		return True,term
	if term.object_type=='bfun':
		status1,result1 = substitute(lhs,rhs,term.parameter_1)
		if (status1):
			term.parameter_1 = result1
		status2,result2 = substitute(lhs,rhs,term.parameter_2)
		if (status2):
			term.parameter_2 = result2
		if (status1 or status2):
			term.string=term.function_type + "(" + term.parameter_1.string + "," + term.parameter_2.string +")"
			return True,term
	if term.object_type=='ufun':
		status,result=substitute(lhs,rhs,term.parameter_1)
		if (status == True):
			term.parameter_1=result
			term.string=term.function_type+"("+result.string+")"
			return True,term

	return False,term