本文整理汇总了C++中FunctionTerm::substitute方法的典型用法代码示例。如果您正苦于以下问题:C++ FunctionTerm::substitute方法的具体用法?C++ FunctionTerm::substitute怎么用?C++ FunctionTerm::substitute使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FunctionTerm
的用法示例。
在下文中一共展示了FunctionTerm::substitute方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: rename_variable
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);
}
}