/** * Does the closure of the formula, by adding the variables to the list of * prefix sets * * @param prefix: list of second-order variables corresponding to the prefix * @param freeVars: list of free variables in formula * @param negationIsTopMost: whether the prefix had negation on left or no */ void closePrefix(PrefixListType & prefix, IdentList* freeVars, bool negationIsTopmost) { unsigned int quantifiedSize; unsigned value; unsigned int prefixSize = prefix.size(); // phi = neg exists X ... // we will add new level of quantification if (negationIsTopmost) { VariableSet set; quantifiedSize = freeVars->size(); for (unsigned i = 0; i < quantifiedSize; ++i) { value = freeVars->get(i); set.push_back(varMap[value]); } prefix.push_back(set); } else { int index = prefix.size() - 1; quantifiedSize = freeVars->size(); for (unsigned i = 0; i < quantifiedSize; ++i) { value = freeVars->get(i); prefix[index].insert(prefix[index].begin()+i, varMap[value]); } } }
/** * Takes formula, the prefix, and converts it to the set of sets of second * order variables, according to the variable map; * * @param formula: formula corresponding to the prefix * @return: list of lists of second-order variables */ PrefixListType convertPrefixFormulaToList(ASTForm* formula) { PrefixListType list; VariableSet set; unsigned int quantifiedSize; unsigned int value; bool isFirstNeg = true; // empty prefix is just one empty list if (formula->kind == aTrue) { list.push_front(set); return list; } ASTForm* iterator = formula; // while we are not at the end of the prefix while (iterator->kind != aTrue) { //iterator->dump(); //std::cout << "\n"; // Add to set if (iterator->kind == aEx2) { ASTForm_Ex2* exf = (ASTForm_Ex2*) iterator; quantifiedSize = (exf->vl)->size(); for (unsigned i = 0; i < quantifiedSize; ++i) { value = (exf->vl)->get(i); //std::cout << value << " -> " << varMap[value] << "\n"; set.push_back(varMap[value]); } iterator = exf->f; isFirstNeg = false; // Create new set } else if (iterator->kind == aNot) { if (!isFirstNeg) { list.push_front(set); set.clear(); } else { isFirstNeg = false; } ASTForm_Not* notf = (ASTForm_Not*) iterator; iterator = notf->f; // Fail, should not happen } else { assert(false); } } if (set.size() != 0) { list.push_front(set); } return list; }