Esempio n. 1
0
Term* UniversalInstantiator::instantiate_term(Term* t,
			map<int, Term*> &sub_map)
{
	if(t->get_term_type() == CONSTANT_TERM)
		return t;
	if(t->get_term_type() == VARIABLE_TERM){
		VariableTerm *vt = (VariableTerm*)t;
		if(sub_map.count(vt->get_var_id()) == 0)
			return vt;
		return sub_map[vt->get_var_id()];
	}
	if(t->get_term_type() == ARITHMETIC_TERM) {
		ArithmeticTerm* at = (ArithmeticTerm*)t;
		bool changed = false;
		map<Term*, long int> new_elems;
		map<Term*, long int>::const_iterator it = at->get_elems().begin();
		for(; it!= at->get_elems().end(); it++) {
			Term* new_t = instantiate_term(it->first, sub_map);
			if(new_t != t) changed = true;
			new_elems[new_t] = it->second;
		}
		if(!changed) return at;
		return ArithmeticTerm::make(new_elems, at->get_constant());
	}
	FunctionTerm *ft = (FunctionTerm*)t;
	vector<Term*> new_args;
	for(unsigned int i=0; i < ft->get_args().size(); i++)
	{
		Term* cur = instantiate_term(ft->get_args()[i], sub_map);
		new_args.push_back(cur);
	}
	return FunctionTerm::make(ft->get_id(), new_args, ft->is_invertible());
}
Esempio n. 2
0
void Term::get_vars(set<Term*>& vars)
{


	term_type tt = get_term_type();
	if (tt == CONSTANT_TERM)
		return;
	if (tt == VARIABLE_TERM) {
		VariableTerm* vt = (VariableTerm*) this;
		vars.insert(vt);
		return;
	}
	if (tt == FUNCTION_TERM) {
		FunctionTerm* ft = (FunctionTerm*) this;
		for (unsigned int i = 0; i < ft->get_args().size(); i++) {
			ft->get_args()[i]->get_vars(vars);
		}
	} else {
		assert(tt == ARITHMETIC_TERM);
		ArithmeticTerm* at = (ArithmeticTerm*) this;
		map<Term*, long int>::const_iterator it = at->get_elems().begin();
		for (; it != at->get_elems().end(); it++) {
			it->first->get_vars(vars);
		}
	}
}
Esempio n. 3
0
void Term::get_all_fun_ids(set<int> & ids)
{
	switch(this->get_term_type())
	{
	case CONSTANT_TERM:
	case VARIABLE_TERM:
		return;
	case FUNCTION_TERM:
	{
		FunctionTerm* ft = (FunctionTerm*)this;
		ids.insert(ft->get_id());
		for(unsigned int i=0; i < ft->get_args().size(); i++)
		{
			ft->get_args()[i]->get_all_fun_ids(ids);
		}
		return;
	}
	case ARITHMETIC_TERM:
	{
		ArithmeticTerm* at = (ArithmeticTerm*) this;
		const map<Term*, long int>& elems = at->get_elems();
		map<Term*, long int>::const_iterator it = elems.begin();
		for(; it!=elems.end(); it++)
		{
			it->first->get_all_fun_ids(ids);

		}
		return;
	}
	default:
		assert(false);
	}
}
Esempio n. 4
0
Term* Term::evalute_term(map<Term*, SatValue>& assignments)
{
	switch(this->get_term_type())
	{
	case CONSTANT_TERM:
		return this;
	case VARIABLE_TERM:
	{
		if(assignments.count(this) > 0){
			return ConstantTerm::make(assignments[this].value.to_int());
		}
		return this;
	}
	case FUNCTION_TERM:
	{
		if(assignments.count(this) > 0){
			return ConstantTerm::make(assignments[this].value.to_int());
		}
		vector<Term*> new_args;
		FunctionTerm* ft = (FunctionTerm*) this;
		for(unsigned int i = 0; i < ft->get_args().size(); i++)
		{
			Term* arg = ft->get_args()[i];
			arg = arg->evalute_term(assignments);
			new_args.push_back(arg);
		}
		Term* new_t =
				FunctionTerm::make(ft->get_id(), new_args, ft->is_invertible());

		if(assignments.count(new_t) > 0)
			return ConstantTerm::make(assignments[new_t].value.to_int());
		return new_t;

	}
	case ARITHMETIC_TERM:
	{
		ArithmeticTerm* at = (ArithmeticTerm*) this;
		Term* res = ConstantTerm::make(at->get_constant());
		const map<Term*, long int>& elems = at->get_elems();
		map<Term*, long int>::const_iterator it = elems.begin();
		for(; it!=elems.end(); it++)
		{
			Term* t = it->first;
			Term* val = t->evalute_term(assignments);
			res = res->add(val->multiply(it->second));
		}
		if(assignments.count(res) > 0)
			return ConstantTerm::make(assignments[res].value.to_int());

		return res;
	}
	default:
		assert(false);
	}
}
Esempio n. 5
0
/*
 * Cdr's down terms to build the index set.
 * This can only be called if the term is not in index guard.
 */
bool  UniversalInstantiator::build_index_set_term(Term* t, set<int> &qvars,
		int fun_id, int arg_num)
{
	if(t->get_term_type() == FUNCTION_TERM)
	{
		FunctionTerm* ft = (FunctionTerm*)t;
		bool contains_uvar = false;
		for(unsigned int i=0; i < ft->get_args().size(); i++) {
			bool res =
				build_index_set_term(ft->get_args()[i], qvars, ft->get_id(), i);
			if(res) contains_uvar = true;
		}
		if(contains_uvar) return true;
	}
	if(t->get_term_type() == ARITHMETIC_TERM)
	{
		bool contains_uvar = false;
		ArithmeticTerm* at = (ArithmeticTerm*) t;
		map<Term*, long int>::const_iterator it = at->get_elems().begin();
		for(; it!=at->get_elems().end(); it++){
			bool res = build_index_set_term(it->first, qvars, -1, -1);
			if(res) contains_uvar = true;
		}
		if(contains_uvar) return true;
	}


	pair<int, int> key(fun_id, arg_num);
	if(reverse_fun_arg_universal.count(key) ==0) return false;
	if(t->get_term_type() == VARIABLE_TERM){
		VariableTerm* vt = (VariableTerm*) t;
		if(qvars.count(vt->get_var_id()) != 0){
			return true;
		}
	}

	Term* se = t;
	set<qvar>* val = reverse_fun_arg_universal[key];
	if(val->size() == 0) {
		return false;
	}
	bool added = false;
	set<qvar>::iterator it = val->begin();
	for(; it!= val->end(); it++){
		set<Term*>* s = index_set[*it];
		if(s == NULL){
			s= new set<Term*>();
			index_set[*it] =s;
		}
		unsigned int old_size = s->size();
		s->insert(se);
		if(s->size() > old_size) added = true;
	}
	return false;
}
Esempio n. 6
0
bool Term::contains_term(Term* t)
{
	if(this == t) return true;
	switch(this->get_term_type())
	{
	case CONSTANT_TERM:
		return false;
	case VARIABLE_TERM:
	{
		return false;
	}
	case FUNCTION_TERM:
	{
		FunctionTerm* ft = (FunctionTerm*) this;
		const vector<Term*>& args = ft->get_args();
		for(unsigned int i=0; i< args.size(); i++) {
			if(args[i]->contains_term(t)) return true;
		}
		return false;
	}
	case ARITHMETIC_TERM:
	{
		ArithmeticTerm* at = (ArithmeticTerm*) this;
		const map<Term*, long int>& elems = at->get_elems();
		map<Term*, long int>::const_iterator it = elems.begin();
		for(; it!= elems.end(); it++) {
			if(it->first->contains_term(t)) return true;
		}
		return false;
	}
	default:
		assert(false);
	}
}
Esempio n. 7
0
void Term::clear_representatives()
{
	this->representative = NULL;
	switch(this->get_term_type())
	{
	case CONSTANT_TERM:
	case VARIABLE_TERM:
		return;
	case FUNCTION_TERM:
	{
		FunctionTerm* ft = (FunctionTerm*) this;
		const vector<Term*>& args = ft->get_args();
		for(unsigned int i=0; i< args.size(); i++) {
			Term* t = args[i];
			t->clear_representatives();
		}
		return;
	}
	case ARITHMETIC_TERM:
	{
		ArithmeticTerm* at = (ArithmeticTerm*) this;
		const map<Term*, long int>& elems = at->get_elems();
		map<Term*, long int>::const_iterator it = elems.begin();
		for(; it!= elems.end(); it++)
		{
			Term* t = it->first;
			t->clear_representatives();
		}
		return;
	}
	default:
		assert(false);
	}
}
Esempio n. 8
0
bool Term::contains_var(int var_id)
{
	switch(this->get_term_type())
	{
	case CONSTANT_TERM:
		return false;
	case VARIABLE_TERM:
	{
		VariableTerm* vt = (VariableTerm*) this;
		return(vt->get_var_id() == var_id);
	}
	case FUNCTION_TERM:
	{
		FunctionTerm* ft = (FunctionTerm*) this;
		const vector<Term*>& args = ft->get_args();
		for(unsigned int i=0; i<args.size(); i++) {
			Term* cur_arg = args[i];
			if(cur_arg->contains_var(var_id)) return true;
		}
		return false;
	}
	case ARITHMETIC_TERM:
	{
		ArithmeticTerm* at = (ArithmeticTerm*) this;
		const map<Term*, long int>& elems = at->get_elems();
		map<Term*, long int>::const_iterator it = elems.begin();
		for(; it!= elems.end(); it++) {
			if(it->first->contains_var(var_id)) return true;
		}
		return false;
	}
	default:
		assert(false);
	}
}
Esempio n. 9
0
Term* Term::substitute(Term* (*sub_func)(Term* t, void* data), void* my_data)
{
	Term* new_t = (*sub_func)(this, my_data);
	if(new_t != this) {
		return new_t;
	}
	Term* res = NULL;
	switch (get_term_type()) {
		case CONSTANT_TERM:
		case VARIABLE_TERM: {
			res=  this;
			break;
		}
		case FUNCTION_TERM: {
			FunctionTerm* ft = (FunctionTerm*) this;
			const vector<Term*>& args = ft->get_args();
			vector<Term*> new_args;
			bool changed = false;
			for (unsigned int i = 0; i < args.size(); i++) {
				Term* new_arg = args[i]->substitute(sub_func, my_data);
				if (new_arg != args[i])
					changed = true;
				new_args.push_back(new_arg);
			}

			if (!changed) {
				res = this;
				break;
			}
			res= FunctionTerm::make(ft->get_id(), new_args, ft->is_invertible());

			break;

		}
		case ARITHMETIC_TERM: {
			ArithmeticTerm* at = (ArithmeticTerm*) this;
			bool changed = false;
			map<Term*, long int> new_elems;
			map<Term*, long int>::const_iterator it = at->get_elems().begin();
			for (; it != at->get_elems().end(); it++) {
				Term* new_t = it->first->substitute(sub_func, my_data);
				if (new_t != it->first)
					changed = true;
				new_elems[new_t]+= it->second;
			}
			if (!changed) {
				res =  at;
				break;
			}
			res = ArithmeticTerm::make(new_elems, at->get_constant());
			break;
		}
		default:
			assert(false);
	}
	return res;
}
Esempio n. 10
0
Term* Term::replace_argument(int fun_id, int arg_num, Term* replacement)
{
	switch(this->get_term_type())
	{
	case CONSTANT_TERM:
	case VARIABLE_TERM:
		return this;
	case FUNCTION_TERM:
	{
		FunctionTerm* ft = (FunctionTerm*)this;
		const vector<Term*>& args = ft->get_args();
		bool changed = false;
		vector<Term*> new_args;
		for(unsigned int i=0; i < args.size(); i++)
		{
			Term* cur = args[i];
			Term* new_cur = cur->replace_argument(fun_id, arg_num, replacement);
			if(cur != new_cur) {
				changed = true;
			}
			new_args.push_back(new_cur);
		}
		if(ft->get_id() == fun_id )
		{
			changed = true;
			new_args[arg_num] = replacement;
		}
		if(!changed) return this;
		return FunctionTerm::make(ft->get_id(), new_args, ft->is_invertible());

	}
	case ARITHMETIC_TERM:
	{
		ArithmeticTerm* at = (ArithmeticTerm*) this;
		const map<Term*, long int>& elems = at->get_elems();
		map<Term*, long int>::const_iterator it = elems.begin();
		bool changed = false;
		map<Term*, long int> new_elems;
		for(; it!=elems.end(); it++)
		{
			Term* t = it->first;
			long int c = it->second;
			Term* new_t = t->replace_argument(fun_id, arg_num, replacement);
			new_elems[new_t] = c;
			if(t!= new_t) changed = true;

		}
		if(!changed) return this;
		return ArithmeticTerm::make(new_elems, at->get_constant());
	}
	default:
		assert(false);
	}
}
Esempio n. 11
0
Term* Term::rename_variables(map<int, int>& replacements)
{
	switch (get_term_type()) {
		case CONSTANT_TERM:
			return this;
		case VARIABLE_TERM: {
			VariableTerm* vt = (VariableTerm*) this;
			int var_id = vt->get_var_id();
			if (replacements.count(var_id)==0)
				return this;
			Term* res= VariableTerm::make(replacements[var_id]);
			return res;
		}
		case FUNCTION_TERM: {
			FunctionTerm* ft = (FunctionTerm*) this;
			const vector<Term*>& args = ft->get_args();
			vector<Term*> new_args;
			bool changed = false;
			for (unsigned int i = 0; i < args.size(); i++) {
				Term* new_arg = args[i]->rename_variables(replacements);
				if (new_arg != args[i])
					changed = true;
				new_args.push_back(new_arg);
			}

			if (!changed)
				return this;
			Term* res= FunctionTerm::make(ft->get_id(), new_args,
					ft->is_invertible());
			return res;

		}
		case ARITHMETIC_TERM: {
			ArithmeticTerm* at = (ArithmeticTerm*) this;
			bool changed = false;
			map<Term*, long int> new_elems;
			map<Term*, long int>::const_iterator it = at->get_elems().begin();
			for (; it != at->get_elems().end(); it++) {
				Term* new_t = it->first->rename_variables(replacements);
				if (new_t != it->first)
					changed = true;
				new_elems[new_t] += it->second;
			}
			if (!changed)
				return at;
			Term* res= ArithmeticTerm::make(new_elems, at->get_constant());
			return res;
		}
		default:
			assert(false);
	}
}
Esempio n. 12
0
Term* Term::rename_variable(int old_var_id, int new_var_id)
{
	switch (get_term_type()) {
		case CONSTANT_TERM:
			return this;
		case VARIABLE_TERM: {
			VariableTerm* vt = (VariableTerm*) this;
			if (old_var_id != vt->get_var_id())
				return this;
			Term* res = VariableTerm::make(new_var_id);
			return res;
		}
		case FUNCTION_TERM: {
			FunctionTerm* ft = (FunctionTerm*) this;
			const vector<Term*>& args = ft->get_args();
			map<Term*, Term*> old_to_new;
			bool changed = false;
			for (unsigned int i = 0; i < args.size(); i++) {
				Term* old_arg = args[i];
				Term* new_arg = args[i]->rename_variable(old_var_id, new_var_id);
				if (new_arg != args[i])
					changed = true;
				old_to_new[old_arg] = new_arg;
			}

			if (!changed)
				return this;
			Term* res = ft->substitute(old_to_new);
			return res;

		}
		case ARITHMETIC_TERM: {
			ArithmeticTerm* at = (ArithmeticTerm*) this;
			bool changed = false;
			map<Term*, long int> new_elems;
			map<Term*, long int>::const_iterator it = at->get_elems().begin();
			for (; it != at->get_elems().end(); it++) {
				Term* new_t = it->first->rename_variable(old_var_id, new_var_id);
				if (new_t != it->first)
					changed = true;
				new_elems[new_t] += it->second;
			}
			if (!changed)
				return at;
			Term* res = ArithmeticTerm::make(new_elems, at->get_constant());
			return res;
		}
		default:
			assert(false);
	}
}
Esempio n. 13
0
void Term::get_all_arguments(int fun_id, int arg_num, set<Term*> & args)
{
	switch(this->get_term_type())
	{
	case CONSTANT_TERM:
	case VARIABLE_TERM:
		return;
	case FUNCTION_TERM:
	{
		FunctionTerm* ft = (FunctionTerm*)this;
		if(ft->get_id() == fun_id){
			assert((int) ft->get_args().size() > arg_num);
			args.insert(ft->get_args()[arg_num]);
		}
		for(unsigned int i=0; i < ft->get_args().size(); i++)
		{
			ft->get_args()[i]->get_all_arguments(fun_id, arg_num, args);
		}
		return;
	}
	case ARITHMETIC_TERM:
	{
		ArithmeticTerm* at = (ArithmeticTerm*) this;
		const map<Term*, long int>& elems = at->get_elems();
		map<Term*, long int>::const_iterator it = elems.begin();
		for(; it!=elems.end(); it++)
		{
			it->first->get_all_arguments(fun_id, arg_num, args);

		}
		return;
	}
	default:
		assert(false);
	}
}
Esempio n. 14
0
void Term::get_all_first_arguments(set<int>& fn_ids, map<int, set<Term*> >&
		fn_id_to_first_arg)
{
	switch(this->get_term_type())
	{
	case CONSTANT_TERM:
	case VARIABLE_TERM:
		return;
	case FUNCTION_TERM:
	{

		FunctionTerm* ft = (FunctionTerm*)this;
		const vector<Term*>& args = ft->get_args();
		int my_id = ft->get_id();
		if(fn_ids.count(my_id) > 0) {
			Term* arg = args[0];
			fn_id_to_first_arg[my_id].insert(arg);
		}

		for(unsigned int i=0; i < args.size(); i++)
		{
			Term* cur = args[i];
			cur->get_all_first_arguments(fn_ids, fn_id_to_first_arg);
		}
		return;

	}
	case ARITHMETIC_TERM:
	{
		ArithmeticTerm* at = (ArithmeticTerm*) this;
		const map<Term*, long int>& elems = at->get_elems();
		map<Term*, long int>::const_iterator it = elems.begin();
		for(; it!=elems.end(); it++)
		{
			Term* t = it->first;
			t->get_all_first_arguments(fn_ids, fn_id_to_first_arg);

		}
		return;
	}
	default:
		assert(false);
	}
}
Esempio n. 15
0
void Term::get_attributes(set<CNode*> & attributes)
{
	CNode* attrib_c = NULL;
	if(attribute == TERM_ATTRIB_GEQZ) {
		attrib_c = ILPLeaf::make(this, ConstantTerm::make(0), ILP_GEQ);
	}

	else if(attribute == TERM_ATTRIB_GTZ) {

		attrib_c = ILPLeaf::make(this, ConstantTerm::make(0), ILP_GT);
	}
	if(attrib_c != NULL) attributes.insert(attrib_c);


	switch(get_term_type())
	{
	case FUNCTION_TERM:
	{
		FunctionTerm* ft = (FunctionTerm*) this;
		const vector<Term*> & args = ft->get_args();
		for(unsigned int i=0; i<args.size(); i++)
		{
			Term* t = args[i];
			t->get_attributes(attributes);
		}
		break;
	}
	case ARITHMETIC_TERM:
	{
		ArithmeticTerm* at = (ArithmeticTerm*) this;
		const map<Term*, long int> & elems = at->get_elems();
		map<Term*, long int>::const_iterator it= elems.begin();
		for(; it!= elems.end(); it++)
		{
			Term* t = it->first;
			t->get_attributes(attributes);
		}
		break;
	}
	default:
		break;
	}

}
Esempio n. 16
0
void VariableEliminator::get_direct_parents(Term* t, set<FunctionTerm*>& parents,
		map<Term*, set<Term*> >& eq_members)
{
	map<Term*, set<Term*> >::iterator it = eq_members.begin();
	for(; it!= eq_members.end(); it++)
	{
		set<Term*>& eq_class = it->second;
		set<Term*>::iterator it = eq_class.begin();
		for(; it!= eq_class.end(); it++){
			Term* cur_t = *it;
			if(cur_t->get_term_type() != FUNCTION_TERM) continue;
			FunctionTerm* ft = (FunctionTerm*) cur_t;
			const vector<Term*>& args = ft->get_args();
			for(unsigned int i=0; i< args.size(); i++) {
				if(args[i] == t) parents.insert(ft);
			}
		}

	}
}
Esempio n. 17
0
void Term::get_nested_vars(set<int>& vars)
{
	switch(this->get_term_type())
	{
	case CONSTANT_TERM:
	{
		return;
	}
	case VARIABLE_TERM:
	{
		VariableTerm* vt = (VariableTerm*) this;
		vars.insert(vt->get_var_id());
		return;
	}
	case FUNCTION_TERM:
	{
		FunctionTerm* ft = (FunctionTerm*) this;
		const vector<Term*>& args = ft->get_args();
		for(unsigned int i=0; i< args.size(); i++) {
			Term* t = args[i];
			t->get_nested_vars(vars);
		}
		return;
	}
	case ARITHMETIC_TERM:
	{
		ArithmeticTerm* at = (ArithmeticTerm*) this;
		const map<Term*, long int>& elems = at->get_elems();
		map<Term*, long int>::const_iterator it = elems.begin();
		for(; it!= elems.end(); it++)
		{
			Term* t = it->first;
			t->get_nested_vars(vars);
		}
		return;
	}
	default:
		assert(false);
	}
}
Esempio n. 18
0
void Term::get_nested_terms(set<Term*>& terms, bool include_function_subterms,
		bool include_constants)
{
	if(! include_constants && get_term_type() == CONSTANT_TERM) return;
	if(terms.count(this) > 0) return;
	terms.insert(this);
	switch(this->get_term_type())
	{
	case CONSTANT_TERM:
	case VARIABLE_TERM:
		return;
	case FUNCTION_TERM: {
		if(!include_function_subterms) return;
		FunctionTerm* ft = (FunctionTerm*) this;
		const vector<Term*>& args = ft->get_args();
		for(unsigned int i=0; i< args.size(); i++) {
			args[i]->get_nested_terms(terms, include_function_subterms,
					include_constants);
		}
		return;
	}
	case ARITHMETIC_TERM:
	{
		ArithmeticTerm* at = (ArithmeticTerm*) this;
		const map<Term*, long int>& elems = at->get_elems();
		map<Term*, long int>::const_iterator it = elems.begin();
		for(; it!= elems.end(); it++) {
			it->first->get_nested_terms(terms, include_function_subterms,
					include_constants);
		}
		return;
	}
	default:
		assert(false);
	}
}
Esempio n. 19
0
/*
 * Substitutes variables if there are any
 * active subtituitons & byuilds the fun_arg_universal
 * and reverse_fun_arg universal maps. This is
 * recursive since we need to cdr down
 * nested function terms.
 */
Term* UniversalInstantiator::process_term(Term* t, map<int,int> & var_subs,
		int fun_id, int arg_num, QuantifiedLeaf* ql)
{
	if(t->get_term_type() == CONSTANT_TERM) return t;

	if(t->get_term_type() == VARIABLE_TERM){
		VariableTerm* vt = (VariableTerm*)t;
		int var_id = vt->get_var_id();
		if(var_subs.count(var_id)>0){
			Term* new_vt = VariableTerm::make(var_subs[var_id]);
			return new_vt;
		}
		else if(fun_id != -1 && ql!= NULL &&
				ql->get_quantified_vars().count(var_id) >0)
		{
			assert(arg_num != -1);
			qvar qv;

			//qv.orig_id = ql->get_orig_id();
			qv.id = (long int) ql;
			qv.var_id = var_id;

			map<int, int> *fun_map = NULL;
			if(fun_arg_universal.count(qv)>0) {
				fun_map = fun_arg_universal[qv];
			}
			else
			{
				fun_map = new map<int, int>();
				fun_arg_universal[qv] = fun_map;
			}
			if(fun_map->count(fun_id) == 0){
				(*fun_map)[fun_id] = arg_num;
				pair<int, int> key(fun_id, arg_num);
				set<qvar>* val = reverse_fun_arg_universal[key];
				if(val == NULL){
					val = new set<qvar>();
					reverse_fun_arg_universal[key] = val;

				}
				val->insert(qv);
			}
			else {
				if((*fun_map)[fun_id] != arg_num)
					return NULL;
			}
		}
		return t;
	}
	if(t->get_term_type() == FUNCTION_TERM)
	{
		FunctionTerm* ft = (FunctionTerm*)t;
		vector<Term*> new_args;
		for(unsigned int i=0; i < ft->get_args().size(); i++)
		{
			Term* cur_arg = process_term(ft->get_args()[i], var_subs,
					ft->get_id(), i, ql);
			if(cur_arg == NULL){
				return NULL;
			}
			new_args.push_back(cur_arg);
		}
		Term* new_ft = FunctionTerm::make(ft->get_id(), new_args,
				ft->is_invertible());
		return new_ft;
	}
	else {
		assert(t->get_term_type() == ARITHMETIC_TERM);
		ArithmeticTerm* at = (ArithmeticTerm*) t;
		bool changed = false;
		map<Term*, long int> new_elems;
		map<Term*, long int>::const_iterator it = at->get_elems().begin();
		for(; it!= at->get_elems().end(); it++){
			Term* new_t = process_term(it->first, var_subs, -1, -1, ql);
			if(new_t == NULL) return NULL;
			new_elems[new_t] = it->second;
		}
		if(!changed) return at;
		Term* new_at = ArithmeticTerm::make(new_elems, at->get_constant());
		return new_at;
	}


}