/* * Special Copy Constructor * Only pointers to free vars are retained * Used for copying gamma formulas */ Formula::Formula(Formula &f) { this->type = f.getType(); this->cntv = f.getCntv(); if (f.isAtomic()) { TermList *list = new TermList(); this->copy(f.getPredicate()->getTermList(), list); this->predicate = new Predicate(f.getPredicate()->getName(), list); } else if (f.isNegated()) { this->nextFormula = new Formula(*f.getNext()); } else if (f.isQuantified()) { this->qVar = new Term(*f.getQVar()); this->nextFormula = new Formula(*f.getNext()); } else if (f.isCompound()) { this->formula1 = new Formula(*f.getLeft()); this->formula2 = new Formula(*f.getRight()); } }
bool Prover::expand(queue<Formula*> &q, int depth, int tabCount) { int sz = q.size(); //printf("\n\n============Expanding==============\n\n"); //this->print(q); this->print(q, tabCount); for (int i = 0; i < sz; ++i) { Formula *f = q.front(); q.pop(); if (f->isAtomic()) { q.push(f); /*if (this->isClosed(q)) { //printf("caught closeness early on!!"); this->print(q, tabCount); return true; }*/ } else if (f->isAlpha()) { //printf("Applying alpha rule for.."); //f->print(); //puts(""); this->printTab(tabCount + 2); printf("|alpha (%d)\n", i + 1); Formula *f1 = f->getAlpha1(); Formula *f2 = f->getAlpha2(); q.push(f1); q.push(f2); return expand(q, depth, tabCount); } else if (f->isBeta()) { //printf("Applying beta rule for.."); //f->print(); //puts(""); this->printTab(tabCount+2); printf("|beta (%d)\n", i + 1); Formula *f1 = f->getBeta1(); Formula *f2 = f->getBeta2(); queue<Formula*> q2(q); q.push(f1); q2.push(f2); return expand(q, depth, tabCount-4) && expand(q2, depth, tabCount+4); } else if (f->isGamma()) { //printf("Applying gamma rule for.."); //f->print(); //puts(""); this->printTab(tabCount+2); printf("|gamma (%d)\n", i + 1); depth--; Formula *cpy = NULL; if (depth > 0) { cpy = new Formula(*f); //printf("\n\ncopy formula1======\n"); //cpy->print(); } Term *newVar = new Term(Term::VAR, NULL); Formula *newFormula; newFormula = f->getGamma(newVar); //printf("got this.."); //newFormula->print(); //puts(""); q.push(newFormula); if (cpy != NULL) { q.push(cpy); //printf("\n\ncopy formula2======\n"); //cpy->print(); } return expand(q, depth, tabCount); } else if (f->isDelta()) { //printf("Applying delta rule for.."); //f->print(); //puts(""); this->printTab(tabCount + 2); printf("delta (%d)\n", i + 1); Formula *newFormula; newFormula = f->getDelta(); //printf("got this.."); //newFormula->print(); //puts(""); q.push(newFormula); return expand(q, depth, tabCount); } else if (f->isNegated()) { if (f->getNext()->isAtomic()) { q.push(f); } else if(f->getNext()->isNegated()) { //printf("Applying alpha rule for.."); //f->print(); //puts(""); this->printTab(tabCount + 2); printf("alpha (%d)\n", i + 1); q.push(f->getNext()->getNext()); return expand(q, depth, tabCount); } } } bool b = this->isClosed(q, tabCount); //if (b) printf("A closed branch..\n"); //else printf("An open branch..\n"); //if (b) this->print(q, tabCount); return b; }