Example #1
0
/*
* Copy Constructor
*/
Term::Term(Term &term)
{	
	this->free = term.free;
	this->type = term.type;
	this->name = new char[strlen(term.name) + 1];
	strcpy(this->name, term.getName());

	if (this->type == FUNC) {
		this->termList = new TermList();
		for (int i = 0; i < term.getTermList()->getList()->size(); i++) {
			Term *t = new Term(*(term.getTermList()->getList()->at(i)));
			this->termList->addTerm(t);
		}
	}
}
Example #2
0
void Formula::copy(TermList *frm, TermList *to)
{
	int sz = frm->getList()->size();
	for (int i = 0; i < sz; i++) {
		Term *t = frm->getList()->at(i);
		if (t->getType() == Term::CONS) {
			to->addTerm(t);
		}
		else if (t->getType() == Term::VAR) {
			if (t->isFree()) {
				to->addTerm(t);
			}
			else {
				Term *x = new Term(*t);
				to->addTerm(x);
			}
		}
		else {
			TermList *list = new TermList();
			this->copy(t->getTermList(), list);
			Term *f = new Term(t->getName(), list);
			to->addTerm(f);
		}
	}
}
Example #3
0
bool Term::operator ==(Term &term)
{
	if (this->type != term.type || strcmp(this->name, term.getName())) return false;
	if (this->type == FUNC) {
		return *(this->termList) == *(term.getTermList());
	}
	else {
		return true;
	}
}
Example #4
0
void TermList::getFreeVarList(TermList *list)
{
	int sz = this->list->size();
	for (int i = 0; i < sz; i++) {
		Term *t = this->list->at(i);
		if (t->getType() == Term::VAR && t->isFree()) {
			list->addTerm(t);
		}
		else if (t->getType() == Term::FUNC) {
			t->getTermList()->getFreeVarList(list);
		}
	}
}
Example #5
0
bool Prover::occursIn(Term *t, TermList *list)
{
	for (int i = 0; i < list->getList()->size(); i++) {
		Term *p = list->getList()->at(i);
		if (*t == *p) {
			return true;
		}
		else if ((p->getType() == Term::FUNC) && this->occursIn(t, p->getTermList())) {
			return true;
		}
	}
	return false;
}
Example #6
0
void TermList::replace(Term *oldV, Term *newV)
{
	int sz = this->list->size();
	for (int i = 0; i < sz; i++) {
		Term *t = this->list->at(i);
		if (*t == *oldV) {
			this->list->at(i) = newV;
			//delete t; //TO DO
		}
		else if (t->getType() == Term::FUNC) {
			t->getTermList()->replace(oldV, newV);
		}
	}
}