Exemplo n.º 1
0
bool VCCmd::evaluateNext()
{
readAgain:
  if(d_parser->done()) return false; // No more commands
  Expr e;
  try {
    TRACE_MSG("commands", "** [commands] Parsing command...");
    e = d_parser->next();
    TRACE("commands verbose", "evaluateNext(", e, ")");
  }
  catch(Exception& e) {
    cerr << "*** " << e << endl;
    IF_DEBUG(++(debugger.counter("parse errors"));)
  }
  // The parser may return a Null Expr in case of parse errors or end
  // of file.  The right thing to do is to ignore it and repeat
  // reading.
  if(e.isNull()) {
    TRACE_MSG("commands", "** [commands] Null command; read again");
    goto readAgain;
  }
  if( d_vc->getFlags()["parse-only"].getBool() ) {
    TRACE_MSG("commands", "** [commands] parse-only; skipping evaluateCommand");
    goto readAgain;
  }

  return evaluateCommand(e);
}
Exemplo n.º 2
0
void SymbolTable::bind(const std::string& name, Expr obj,
                       bool levelZero) throw() {
  PrettyCheckArgument(!obj.isNull(), obj, "cannot bind to a null Expr");
  ExprManagerScope ems(obj);
  if(levelZero) d_exprMap->insertAtContextLevelZero(name, obj);
  else d_exprMap->insert(name, obj);
}
Exemplo n.º 3
0
bool Expr::operator>(const Expr& e) const {
  Assert(d_node != NULL, "Unexpected NULL expression pointer!");
  Assert(e.d_node != NULL, "Unexpected NULL expression pointer!");
  if(isNull() && !e.isNull()) {
    return true;
  }
  ExprManagerScope ems(*this);
  return *d_node > *e.d_node;
}
Exemplo n.º 4
0
SatLiteral TheoryProxy::getNextReplayDecision() {
#ifdef CVC4_REPLAY
  if(options::replayStream() != NULL) {
    Expr e = options::replayStream()->nextExpr();
    if(!e.isNull()) { // we get null node when out of decisions to replay
      // convert & return
      ++d_replayedDecisions;
      return d_cnfStream->getLiteral(e);
    }
  }
#endif /* CVC4_REPLAY */
  return undefSatLiteral;
}
Exemplo n.º 5
0
 Expr conjunct_list() {
     if (lookahead == NUM || lookahead == ID) {
         // conjunct_list -> bool _conjunct_list
         Expr temp = boolean();
         Expr test = _conjunct_list();
         if (test.isNull()) {  // test lack a left node
             return temp;
         } else {
             test.setLeft(temp);
             return test;
         }
     } else {
         throw ParseError("Syntax error");
     }
 }
Exemplo n.º 6
0
Expr Parser::nextExpression() throw(ParserException) {
  Debug("parser") << "nextExpression()" << std::endl;
  Expr result;
  if(!done()) {
    try {
      result = d_input->parseExpr();
      setDone(result.isNull());
    } catch(ParserException& e) {
      setDone();
      throw;
    } catch(exception& e) {
      setDone();
      parseError(e.what());
    }
  }
  Debug("parser") << "nextExpression() => " << result << std::endl;
  return result;
}
Exemplo n.º 7
0
TypeNode NodeManager::mkPredicateSubtype(Expr lambda, Expr witness)
throw(TypeCheckingExceptionPrivate) {

    Node lambdan = Node::fromExpr(lambda);

    if(lambda.isNull()) {
        throw TypeCheckingExceptionPrivate(lambdan, "cannot make a predicate subtype based on null expression");
    }

    TypeNode tn = lambdan.getType();
    if(! tn.isPredicateLike() ||
            tn.getArgTypes().size() != 1) {
        stringstream ss;
        ss << "expected a predicate of one argument to define predicate subtype, but got type `" << tn << "'";
        throw TypeCheckingExceptionPrivate(lambdan, ss.str());
    }

    return TypeNode(mkTypeConst(Predicate(lambda, witness)));
}
Exemplo n.º 8
0
Expr Parser::nextExpression() throw(ParserException, UnsafeInterruptException) {
  Debug("parser") << "nextExpression()" << std::endl;
  const Options& options = d_exprManager->getOptions();
  d_resourceManager->spendResource(options.getParseStep());
  Expr result;
  if (!done()) {
    try {
      result = d_input->parseExpr();
      setDone(result.isNull());
    } catch (ParserException& e) {
      setDone();
      throw;
    } catch (exception& e) {
      setDone();
      parseError(e.what());
    }
  }
  Debug("parser") << "nextExpression() => " << result << std::endl;
  return result;
}
Exemplo n.º 9
0
    Expr _conjunct_list() {
        if (lookahead == AND) {
            // _conjunct_list -> AND bool _conjunct_list
            match(AND);
            Expr root(AND);

            Expr temp = boolean();
            Expr test = _conjunct_list();
            if (test.isNull()) {
                root.setRight(temp);
                return root;
            } else {
                test.setLeft(temp);
                root.setRight(test);
                return root;
            }
        } else if (lookahead == SEMICOLON || lookahead == END) {
            return NULL_EXPR;
        } else {
            throw ParseError("Syntax error");
        }
    }
Exemplo n.º 10
0
Theorem QuantTheoremProducer::universalInst(const Theorem& t1, const  vector<Expr>& terms, int quantLevel, Expr gterm){
  Expr e = t1.getExpr();
  const vector<Expr>& boundVars = e.getVars();

     for(unsigned int i=0; i<terms.size(); i++){
       if (d_theoryQuant->getBaseType(boundVars[i]) !=
 	  d_theoryQuant->getBaseType(terms[i])){
 	Proof pf;
 	return newRWTheorem(terms[i],terms[i], 
 			    Assumptions::emptyAssump(), pf);
       }
 //this is the same as return a TRUE theorem, which will be ignored immeridatele.  So, this is just return doing nothing. 
     }


  if(CHECK_PROOFS) {
    CHECK_SOUND(boundVars.size() == terms.size(),
		"Universal instantiation: size of terms array does "
		"not match quanitfied variables array size");
    CHECK_SOUND(e.isForall(),
		"universal instantiation: expr must be FORALL:\n"
		+e.toString());

    for(unsigned int i=0; i<terms.size(); i++)
      CHECK_SOUND(d_theoryQuant->getBaseType(boundVars[i]) ==
		  d_theoryQuant->getBaseType(terms[i]),
		  "Universal instantiation: type mismatch");
  }

  //build up a conjunction of type predicates for expression
  Expr tr = e.getEM()->trueExpr();
  Expr typePred = tr;
  //  unsigned qlevel, qlevelMax = 0;
  for(unsigned int i=0; i<terms.size(); i++) {
    Expr p = d_theoryQuant->getTypePred(boundVars[i].getType(),terms[i]);
    if(p!=tr) {
      if(typePred==tr)
	typePred = p;
      else
	typePred = typePred.andExpr(p);
    }
    //    qlevel = d_theoryQuant->theoryCore()->getQuantLevelForTerm(terms[i]);
    //    if (qlevel > qlevelMax) qlevel = qlevelMax;
  }


  //  Expr inst = e.getBody().substExprQuant(e.getVars(), terms);
  Expr inst = e.getBody().substExpr(e.getVars(), terms);

  //  Expr inst = e.getBody().substExpr(e.getVars(), terms);


  Proof pf;
  if(withProof()) {
    vector<Proof> pfs;
    vector<Expr> es;
    pfs.push_back(t1.getProof());
    es.push_back(e);
    es.push_back(Expr(RAW_LIST,terms));
    //    es.insert(es.end(), terms.begin(), terms.end());
    es.push_back(inst);
    if (gterm.isNull()) {
      es.push_back( d_theoryQuant->getEM()->newRatExpr(0));
    }
    else {es.push_back(gterm);
    }
    pf= newPf("universal_elimination1", es, pfs);
  }


  //   Expr inst = e.getBody().substExpr(e.getVars(), terms);


   Expr imp;
   if(typePred == tr ) //just for a easy life, yeting, change this assp
     imp = inst;
   else
     imp = typePred.impExpr(inst);
   Theorem ret = newTheorem(imp, t1.getAssumptionsRef(), pf);

   int thmLevel = t1.getQuantLevel();
   if(quantLevel  >= thmLevel) {
      ret.setQuantLevel(quantLevel+1);
    }
    else{
      ret.setQuantLevel(thmLevel+1);
    }

   //   ret.setQuantLevel(quantLevel+1);
   return ret;
}
Exemplo n.º 11
0
void CVC4Problem::insertAssertion(const Expr &e){
	if (!e.isNull()) {
		assertions.push_back(e);
	}
}
Exemplo n.º 12
0
void TheoryUF::assertFact(const Theorem& e)
{
  const Expr& expr = e.getExpr();
  switch (expr.getKind()) {
    case NOT:
      break;
    case APPLY:
      if (expr.getOpExpr().computeTransClosure()) {
	enqueueFact(d_rules->relToClosure(e));
      }
      else if (expr.getOpKind() == TRANS_CLOSURE) {
        // const Expr& rel = expr.getFun();
        DebugAssert(expr.isApply(), "Should be apply");
        Expr rel = resolveID(expr.getOpExpr().getName());
        DebugAssert(!rel.isNull(), "Expected known identifier");
        DebugAssert(rel.isSymbol() && rel.getKind()==UFUNC && expr.arity()==2,
                    "Unexpected use of transitive closure: "+expr.toString());

        // Insert into transitive closure table
        ExprMap<TCMapPair*>::iterator i = d_transClosureMap.find(rel);
        TCMapPair* pTable;
        if (i == d_transClosureMap.end()) {
          pTable = new TCMapPair();
          d_transClosureMap[rel] = pTable;
        }
        else {
          pTable = (*i).second;
        }

        ExprMap<CDList<Theorem>*>::iterator i2 = pTable->appearsFirstMap.find(expr[0]);
        CDList<Theorem>* pList;
        if (i2 == pTable->appearsFirstMap.end()) {
          pList = new(true) CDList<Theorem>(theoryCore()->getCM()->getCurrentContext());
          pTable->appearsFirstMap[expr[0]] = pList;
        }
        else {
          pList = (*i2).second;
        }
        pList->push_back(e);

        i2 = pTable->appearsSecondMap.find(expr[1]);
        if (i2 == pTable->appearsSecondMap.end()) {
          pList = new(true) CDList<Theorem>(theoryCore()->getCM()->getCurrentContext());
          pTable->appearsSecondMap[expr[1]] = pList;
        }
        else {
          pList = (*i2).second;
        }
        pList->push_back(e);

        // Compute transitive closure with existing relations
        size_t s,l;
        i2 = pTable->appearsFirstMap.find(expr[1]);
        if (i2 != pTable->appearsFirstMap.end()) {
          pList = (*i2).second;
          s = pList->size();
          for (l = 0; l < s; ++l) {
            enqueueFact(d_rules->relTrans(e,(*pList)[l]));
          }
        }

        i2 = pTable->appearsSecondMap.find(expr[0]);
        if (i2 != pTable->appearsSecondMap.end()) {
          pList = (*i2).second;
          s = pList->size();
          for (l = 0; l < s; ++l) {
            enqueueFact(d_rules->relTrans((*pList)[l],e));
          }
        }
      }
      break;
    default:
      break;
  }
}