Example #1
0
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;
  }
}
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;
}
bool InstStrategySimplex::doInstantiation2( Node f, Node term, ArithVar x, InstMatch& m, Node var, bool minus_delta ){
  // make term ( beta - term )/coeff
  Node beta = getTableauxValue( x, minus_delta );
  Node instVal = NodeManager::currentNM()->mkNode( MINUS, beta, term );
  if( !d_ceTableaux[x][var].isNull() ){
    if( var.getType().isInteger() ){
      Assert( d_ceTableaux[x][var]==NodeManager::currentNM()->mkConst( Rational(-1) ) );
      instVal = NodeManager::currentNM()->mkNode( MULT, d_ceTableaux[x][var], instVal );
    }else{
      Node coeff = NodeManager::currentNM()->mkConst( Rational(1) / d_ceTableaux[x][var].getConst<Rational>() );
      instVal = NodeManager::currentNM()->mkNode( MULT, coeff, instVal );
    }
  }
  instVal = Rewriter::rewrite( instVal );
  //use as instantiation value for var
  m.set(var, instVal);
  Debug("quant-arith") << "Add instantiation " << m << std::endl;
  return d_quantEngine->addInstantiation( f, m );
}
Example #4
0
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 );
  }
}
Example #5
0
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;
}