コード例 #1
0
ファイル: quantifiers_engine.cpp プロジェクト: xcodevn/CVC4
bool QuantifiersEngine::addInstantiation( Node f, InstMatch& m, bool modEq, bool modInst, bool mkRep ){
  Trace("inst-add-debug") << "Add instantiation: " << m << std::endl;
  //make sure there are values for each variable we are instantiating
  for( size_t i=0; i<f[0].getNumChildren(); i++ ){
    Node ic = d_term_db->getInstantiationConstant( f, i );
    Node val = m.getValue( ic );
    if( val.isNull() ){
      val = d_term_db->getFreeVariableForInstConstant( ic );
      Trace("inst-add-debug") << "mkComplete " << val << std::endl;
      m.set( ic, val );
    }
    //make it representative, this is helpful for recognizing duplication
    if( mkRep ){
      //pick the best possible representative for instantiation, based on past use and simplicity of term
      Node r = d_eq_query->getInternalRepresentative( val, f, i );
      Trace("inst-add-debug") << "mkRep " << r << " " << val << std::endl;
      m.set( ic, r );
    }
  }
  //check for duplication modulo equality
  inst::CDInstMatchTrie* imt;
  std::map< Node, inst::CDInstMatchTrie* >::iterator it = d_inst_match_trie.find( f );
  if( it!=d_inst_match_trie.end() ){
    imt = it->second;
  }else{
    imt = new CDInstMatchTrie( getUserContext() );
    d_inst_match_trie[f] = imt;
  }
  Trace("inst-add-debug") << "Adding into inst trie" << std::endl;
  if( !imt->addInstMatch( this, f, m, getUserContext(), modEq, modInst ) ){
    Trace("inst-add-debug") << " -> Already exists." << std::endl;
    ++(d_statistics.d_inst_duplicate);
    return false;
  }
  Trace("inst-add-debug") << "compute terms" << std::endl;
  //compute the vector of terms for the instantiation
  std::vector< Node > terms;
  for( size_t i=0; i<d_term_db->d_inst_constants[f].size(); i++ ){
    Node n = m.getValue( d_term_db->d_inst_constants[f][i] );
    Assert( !n.isNull() );
    terms.push_back( n );
  }
  //add the instantiation
  bool addedInst = addInstantiation( f, d_term_db->d_vars[f], terms );
  //report the result
  if( addedInst ){
    Trace("inst-add") << "Added instantiation for " << f << ": " << std::endl;
    Trace("inst-add") << "   " << m << std::endl;
    Trace("inst-add-debug") << " -> Success." << std::endl;
    return true;
  }else{
    Trace("inst-add-debug") << " -> Lemma already exists." << std::endl;
    return false;
  }
}
コード例 #2
0
ファイル: inst_strategy_cbqi.cpp プロジェクト: kyledewey/CVC4
bool InstStrategySimplex::doInstantiation2( Node f, Node ic, Node term, ArithVar x, InstMatch& m, Node var, bool minus_delta ){
  // make term ( beta - term )/coeff
  bool vIsInteger = var.getType().isInteger();
  Node beta = getTableauxValue( x, minus_delta );
  if( !vIsInteger || beta.getType().isInteger() ){
    Node instVal = NodeManager::currentNM()->mkNode( MINUS, beta, term );
    if( !d_ceTableaux[ic][x][var].isNull() ){
      if( vIsInteger ){
        Assert( d_ceTableaux[ic][x][var]==NodeManager::currentNM()->mkConst( Rational(-1) ) );
        instVal = NodeManager::currentNM()->mkNode( MULT, d_ceTableaux[ic][x][var], instVal );
      }else{
        Assert( d_ceTableaux[ic][x][var].getKind()==CONST_RATIONAL );
        Node coeff = NodeManager::currentNM()->mkConst( Rational(1) / d_ceTableaux[ic][x][var].getConst<Rational>() );
        instVal = NodeManager::currentNM()->mkNode( MULT, coeff, instVal );
      }
    }
    instVal = Rewriter::rewrite( instVal );
    //use as instantiation value for var
    int vn = var.getAttribute(InstVarNumAttribute());
    m.setValue( vn, instVal );
    Debug("quant-arith") << "Add instantiation " << m << std::endl;
    return d_quantEngine->addInstantiation( f, m );
  }else{
    return false;
  }
}
コード例 #3
0
ファイル: model_engine.cpp プロジェクト: xcodevn/CVC4
void ModelEngine::exhaustiveInstantiate( Node f, int effort ){
  //first check if the builder can do the exhaustive instantiation
  d_builder->d_triedLemmas = 0;
  d_builder->d_addedLemmas = 0;
  d_builder->d_incomplete_check = false;
  if( d_builder->doExhaustiveInstantiation( d_quantEngine->getModel(), f, effort ) ){
    d_triedLemmas += d_builder->d_triedLemmas;
    d_addedLemmas += d_builder->d_addedLemmas;
    d_incomplete_check = d_incomplete_check || d_builder->d_incomplete_check;
  }else{
    Trace("inst-fmf-ei") << "Exhaustive instantiate " << f << ", effort = " << effort << "..." << std::endl;
    Debug("inst-fmf-ei") << "   Instantiation Constants: ";
    for( size_t i=0; i<f[0].getNumChildren(); i++ ){
      Debug("inst-fmf-ei") << d_quantEngine->getTermDatabase()->getInstantiationConstant( f, i ) << " ";
    }
    Debug("inst-fmf-ei") << std::endl;
    //create a rep set iterator and iterate over the (relevant) domain of the quantifier
    RepSetIterator riter( d_quantEngine, &(d_quantEngine->getModel()->d_rep_set) );
    if( riter.setQuantifier( f ) ){
      Debug("inst-fmf-ei") << "Begin instantiation..." << std::endl;
      int triedLemmas = 0;
      int addedLemmas = 0;
      while( !riter.isFinished() && ( addedLemmas==0 || !options::fmfOneInstPerRound() ) ){
        //instantiation was not shown to be true, construct the match
        InstMatch m;
        for( int i=0; i<riter.getNumTerms(); i++ ){
          m.set( d_quantEngine, f, riter.d_index_order[i], riter.getTerm( i ) );
        }
        Debug("fmf-model-eval") << "* Add instantiation " << m << std::endl;
        triedLemmas++;
        //add as instantiation
        if( d_quantEngine->addInstantiation( f, m ) ){
          addedLemmas++;
        }else{
          Debug("fmf-model-eval") << "* Failed Add instantiation " << m << std::endl;
        }
        riter.increment();
      }
      d_addedLemmas += addedLemmas;
      d_triedLemmas += triedLemmas;
    }
    //if the iterator is incomplete, we will return unknown instead of sat if no instantiations are added this round
    d_incomplete_check = d_incomplete_check || riter.d_incomplete;
  }
}
コード例 #4
0
ファイル: quantifiers_engine.cpp プロジェクト: xcodevn/CVC4
void QuantifiersEngine::computeTermVector( Node f, InstMatch& m, std::vector< Node >& vars, std::vector< Node >& terms ){
  for( size_t i=0; i<d_term_db->d_inst_constants[f].size(); i++ ){
    Node n = m.getValue( d_term_db->d_inst_constants[f][i] );
    if( !n.isNull() ){
      vars.push_back( f[0][i] );
      terms.push_back( n );
    }
  }
}
コード例 #5
0
ファイル: quantifiers_engine.cpp プロジェクト: jgorzny/CVC4
void QuantifiersEngine::computeTermVector( Node f, InstMatch& m, std::vector< Node >& vars, std::vector< Node >& terms ) {
    for( size_t i=0; i<f[0].getNumChildren(); i++ ) {
        Node n = m.get( i );
        if( !n.isNull() ) {
            vars.push_back( f[0][i] );
            terms.push_back( n );
        }
    }
}
コード例 #6
0
int InstStrategyDatatypesValue::process( Node f, Theory::Effort effort, int e ){
  Debug("quant-datatypes") << "Datatypes: Try to solve (" << e << ") for " << f << "... " << std::endl;
  if( e<2 ){
    return InstStrategy::STATUS_UNFINISHED;
  }else if( e==2 ){
    InstMatch m;
    for( int j = 0; j<(int)d_quantEngine->getTermDatabase()->getNumInstantiationConstants( f ); j++ ){
      Node i = d_quantEngine->getTermDatabase()->getInstantiationConstant( f, j );
      if( i.getType().isDatatype() ){
        Node n = getValueFor( i );
        Debug("quant-datatypes-debug") << "Value for " << i << " is " << n << std::endl;
        m.set(i,n);
      }
    }
    //d_quantEngine->addInstantiation( f, m );
  }
  return InstStrategy::STATUS_UNKNOWN;
}
コード例 #7
0
ファイル: model_builder.cpp プロジェクト: Fininvest/CVC4
void QModelBuilderInstGen::getParentQuantifierMatch( InstMatch& mp, Node fp, InstMatch& m, Node f ){
  if( f!=fp ){
    //std::cout << "gpqm " << fp << " " << f << " " << m << std::endl;
    //std::cout << "     " << fp[0].getNumChildren() << " " << f[0].getNumChildren() << std::endl;
    int counter = 0;
    for( size_t i=0; i<fp[0].getNumChildren(); i++ ){
      if( (int)counter< (int)f[0].getNumChildren() ){
        if( fp[0][i]==f[0][counter] ){
          Node n = m.get( counter );
          if( !n.isNull() ){
            mp.set( d_qe, i, n );
          }
          counter++;
        }
      }
    }
    mp.add( d_sub_quant_inst[f] );
  }else{
    mp.add( m );
  }
}
コード例 #8
0
ファイル: quantifiers_engine.cpp プロジェクト: jgorzny/CVC4
bool QuantifiersEngine::addInstantiation( Node f, InstMatch& m, bool mkRep, bool modEq, bool modInst ) {
    std::vector< Node > terms;
    //make sure there are values for each variable we are instantiating
    for( size_t i=0; i<f[0].getNumChildren(); i++ ) {
        Node val = m.get( i );
        if( val.isNull() ) {
            Node ic = d_term_db->getInstantiationConstant( f, i );
            val = d_term_db->getFreeVariableForInstConstant( ic );
            Trace("inst-add-debug") << "mkComplete " << val << std::endl;
        }
        terms.push_back( val );
    }
    return addInstantiation( f, terms, mkRep, modEq, modInst );
}
コード例 #9
0
ファイル: inst_gen.cpp プロジェクト: neuroo/CVC4
bool InstGenProcess::getMatch( EqualityQuery* q, int i, InstMatch& m ) {
    //FIXME: is this correct? (query may not be accurate)
    return m.merge( q, d_matches[i] );
}
コード例 #10
0
ファイル: model_engine.cpp プロジェクト: bobot/CVC4.old-svn
int ModelEngine::exhaustiveInstantiate( Node f, bool useRelInstDomain ){
  int addedLemmas = 0;
  Debug("inst-fmf-ei") << "Exhaustive instantiate " << f << "..." << std::endl;
  Debug("inst-fmf-ei") << "   Instantiation Constants: ";
  for( size_t i=0; i<f[0].getNumChildren(); i++ ){
    Debug("inst-fmf-ei") << d_quantEngine->getTermDatabase()->getInstantiationConstant( f, i ) << " ";
  }
  Debug("inst-fmf-ei") << std::endl;

  //create a rep set iterator and iterate over the (relevant) domain of the quantifier
  RepSetIterator riter( &(d_quantEngine->getModel()->d_rep_set) );
  if( riter.setQuantifier( f ) ){
    //set the domain for the iterator (the sufficient set of instantiations to try)
    if( useRelInstDomain ){
      riter.setDomain( d_rel_domain.d_quant_inst_domain[f] );
    }
    d_quantEngine->getModel()->resetEvaluate();
    int tests = 0;
    int triedLemmas = 0;
    while( !riter.isFinished() && ( addedLemmas==0 || !optOneInstPerQuantRound() ) ){
      d_testLemmas++;
      int eval = 0;
      int depIndex;
      if( d_builder->optUseModel() ){
        //see if instantiation is already true in current model
        Debug("fmf-model-eval") << "Evaluating ";
        riter.debugPrintSmall("fmf-model-eval");
        Debug("fmf-model-eval") << "Done calculating terms." << std::endl;
        tests++;
        //if evaluate(...)==1, then the instantiation is already true in the model
        //  depIndex is the index of the least significant variable that this evaluation relies upon
        depIndex = riter.getNumTerms()-1;
        eval = d_quantEngine->getModel()->evaluate( d_quantEngine->getTermDatabase()->getInstConstantBody( f ), depIndex, &riter );
        if( eval==1 ){
          Debug("fmf-model-eval") << "  Returned success with depIndex = " << depIndex << std::endl;
        }else{
          Debug("fmf-model-eval") << "  Returned " << (eval==-1 ? "failure" : "unknown") << ", depIndex = " << depIndex << std::endl;
        }
      }
      if( eval==1 ){
        //instantiation is already true -> skip
        riter.increment2( depIndex );
      }else{
        //instantiation was not shown to be true, construct the match
        InstMatch m;
        for( int i=0; i<riter.getNumTerms(); i++ ){
          m.set( d_quantEngine->getTermDatabase()->getInstantiationConstant( f, riter.d_index_order[i] ), riter.getTerm( i ) );
        }
        Debug("fmf-model-eval") << "* Add instantiation " << m << std::endl;
        triedLemmas++;
        d_triedLemmas++;
        //add as instantiation
        if( d_quantEngine->addInstantiation( f, m ) ){
          addedLemmas++;
          //if the instantiation is show to be false, and we wish to skip multiple instantiations at once
          if( eval==-1 && optExhInstEvalSkipMultiple() ){
            riter.increment2( depIndex );
          }else{
            riter.increment();
          }
        }else{
          Debug("fmf-model-eval") << "* Failed Add instantiation " << m << std::endl;
          riter.increment();
        }
      }
    }
    //print debugging information
    d_statistics.d_eval_formulas += d_quantEngine->getModel()->d_eval_formulas;
    d_statistics.d_eval_uf_terms += d_quantEngine->getModel()->d_eval_uf_terms;
    d_statistics.d_eval_lits += d_quantEngine->getModel()->d_eval_lits;
    d_statistics.d_eval_lits_unknown += d_quantEngine->getModel()->d_eval_lits_unknown;
    int relevantInst = 1;
    for( size_t i=0; i<f[0].getNumChildren(); i++ ){
      relevantInst = relevantInst * (int)riter.d_domain[i].size();
    }
    d_relevantLemmas += relevantInst;
    Debug("inst-fmf-ei") << "Finished: " << std::endl;
    //Debug("inst-fmf-ei") << "   Inst Total: " << totalInst << std::endl;
    Debug("inst-fmf-ei") << "   Inst Relevant: " << relevantInst << std::endl;
    Debug("inst-fmf-ei") << "   Inst Tried: " << triedLemmas << std::endl;
    Debug("inst-fmf-ei") << "   Inst Added: " << addedLemmas << std::endl;
    Debug("inst-fmf-ei") << "   # Tests: " << tests << std::endl;
    if( addedLemmas>1000 ){
      Trace("model-engine-warn") << "WARNING: many instantiations produced for " << f << ": " << std::endl;
      //Trace("model-engine-warn") << "   Inst Total: " << totalInst << std::endl;
      Trace("model-engine-warn") << "   Inst Relevant: " << relevantInst << std::endl;
      Trace("model-engine-warn") << "   Inst Tried: " << triedLemmas << std::endl;
      Trace("model-engine-warn") << "   Inst Added: " << addedLemmas << std::endl;
      Trace("model-engine-warn") << "   # Tests: " << tests << std::endl;
      Trace("model-engine-warn") << std::endl;
    }
  }
   //if the iterator is incomplete, we will return unknown instead of sat if no instantiations are added this round
  d_incomplete_check = d_incomplete_check || riter.d_incomplete;
  return addedLemmas;
}