Пример #1
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);
		}
	}
}
Пример #2
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);
		}
	}
}
Пример #3
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;
}
Пример #4
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);
		}
	}
}
Пример #5
0
//replaces all the constants in the clause by a new variable. Also, returns an 
//array of terms persent in the original clause (first the variable ids and 
//then the constant ids)
Array<int> * Clause::updateToVarClause()
{
  Array<int> * termIds = new Array<int>();
    //dummy values at position 0 - varIds start from 1
  termIds->append(0);

  const Predicate *pred;
     
    //first populate the variable ids to get a count
  for (int i = 0; i < predicates_->size(); i++)
  {
    pred = (*predicates_)[i];
    for (int j = 0; j < pred->getNumTerms(); j++)
    {
      const Term* t = pred->getTerm(j);
      if (t->getType() == Term::VARIABLE)
      {
        int id = t->getId();
        assert(id < 0);
        termIds->growToSize(-id+1);
        (*termIds)[-id] = id;
      }
    }
  }
    
    //now, convert all constants to variables while storing
    //their ids (constant values)
  for (int i = 0; i < predicates_->size(); i++)
  {
    pred = (*predicates_)[i];
    for (int j = 0; j < pred->getNumTerms(); j++)
    {
      Term* t = (Term *) pred->getTerm(j);
        //if its a variable - do not need to do anything
      if (t->getType() == Term::VARIABLE)
        continue;
      int constantId = t->getId();
      assert(constantId >= 0);
      termIds->append(constantId);
        
        //now convert this term to a new variable
      int varId = termIds->size()-1;
      t->setId(-varId);
    }
  }
  return termIds;
}
Пример #6
0
void Domain::changePredTermsToNewIds(Predicate* const & p,
                                     hash_map<int,int>& oldToNewConstIds)
{
    // p could be NULL
  if (p)
  {
    for (int j = 0; j < p->getNumTerms(); j++)
    {
      Term* t = (Term*) p->getTerm(j);
      if (t->getType() == Term::CONSTANT)
      {
        int oldId = t->getId();
        assert(oldToNewConstIds.find(oldId) != oldToNewConstIds.end());
        t->setId(oldToNewConstIds[oldId]);
      } 
    }
  }
} 
Пример #7
0
  bool equalTo(const Term & t) const
  {
    if(t->getType() != TT_FUNCTION)
      return false;

    if(_f != ((FunctionTerm *) t.get())->getSymbol())
      return false;

    const vector<Term> & t_ops = ((FunctionTerm *) t.get())->getOperands();

    if(_ops.size() != t_ops.size())
      return false;

    for(unsigned i = 0; i < _ops.size(); i++)
      if(!_ops[i]->equalTo(t_ops[i]))
        return false;

    return true;
  }
Пример #8
0
  virtual bool equalTo(const Term & t) const{
     return t->getType() == TT_VARIABLE &&
            ((VariableTerm *) t.get())->getVariable() == _v;
 }