Esempio n. 1
0
//Add new numerical assignment to the building clause
void CVC4Problem::AddConditionToCluase(const assignment* numericalAssignment, FastEnvironment *env, int significantTimePoint){
	ExpressionConvertor variableConvertor(env, this, significantTimePoint);
	Expr variable = variableConvertor.convertExpressionToCVC4Expr(numericalAssignment->getFTerm());
	if (variable.isConst()){
		//This case is happening just in initial case when initial state determine the value of a static variable
		return;
	}
	ExpressionConvertor expressionConvertor(env, this, significantTimePoint - 1);
	Expr result = expressionConvertor.convertExpressionToCVC4Expr(numericalAssignment->getExpr());

	Kind assignmentOperator = kind::EQUAL;
	switch (numericalAssignment->getOp()){
	case E_INCREASE:
		assignmentOperator = kind::PLUS;
		break;
	case E_DECREASE:
		assignmentOperator = kind::MINUS;
		break;
	case E_SCALE_UP:
		assignmentOperator = kind::MULT;
		break;
	case E_SCALE_DOWN:
		assignmentOperator = kind::DIVISION;
		break;
	case E_ASSIGN:
		break;
	case E_ASSIGN_CTS:
		cerr << "Oops!!!, I don't know what is \"E_ASSIGN_CTS\"" << endl;
		exit(1);
		break;
	default:
		cerr << numericalAssignment->getOp() << endl;
		cerr << "I think the program should never reach at this line, BTW we just was processing a numerical assignment!" << endl;
		exit (1);
	}

	if (assignmentOperator != kind::EQUAL){
		Expr variableInPreviousTime = expressionConvertor.convertExpressionToCVC4Expr(numericalAssignment->getFTerm());
		result = em.mkExpr(assignmentOperator, variableInPreviousTime, result);
	}

	buildingClause.push_back(em.mkExpr(kind::EQUAL, variable, result));
}
Esempio n. 2
0
ArrayStoreAll::ArrayStoreAll(const ArrayType& type, const Expr& expr)
    : d_type(), d_expr() {
  // this check is stronger than the assertion check in the expr manager that
  // ArrayTypes are actually array types
  // because this check is done in production builds too
  PrettyCheckArgument(
      type.isArray(), type,
      "array store-all constants can only be created for array types, not `%s'",
      type.toString().c_str());

  PrettyCheckArgument(
      expr.getType().isComparableTo(type.getConstituentType()), expr,
      "expr type `%s' does not match constituent type of array type `%s'",
      expr.getType().toString().c_str(), type.toString().c_str());

  PrettyCheckArgument(expr.isConst(), expr,
                      "ArrayStoreAll requires a constant expression");

  // Delay allocation until the checks above have been performed. If these fail,
  // the memory for d_type and d_expr should not leak. The alternative is catch,
  // delete and re-throw.
  d_type.reset(new ArrayType(type));
  d_expr.reset(new Expr(expr));
}
Esempio n. 3
0
void translate_to_redlog(const map<Expr, unsigned>& variables, const Expr& assertion) {
  bool first;
  
  unsigned n = assertion.getNumChildren();
  
  if (n == 0) {
    if (assertion.isConst()) {
      if (assertion.getConst<bool>()) {
        cout << "(1 > 0)";
      } else {
        cout << "(1 < 0)";
      }
    } else {
      assert(false);
    }
  } else {
    
    std::string op;
    bool binary = false;
    bool theory = false;
    
    switch (assertion.getKind()) {
      case kind::NOT: 
        cout << "(not ";
        translate_to_redlog(variables, assertion[0]);
        cout << ")";
        break;
      case kind::OR:
        first = true;
        cout << "(";
        for (unsigned i = 0; i < n; ++ i) {
          if (!first) {
            cout << " or ";
          }
          first = false;
          translate_to_redlog(variables, assertion[i]);
        }
        cout << ")";
        break;
      case kind::AND:
        first = true;
        cout << "(";
        for (unsigned i = 0; i < n; ++ i) {
          if (!first) {
            cout << " and ";
          }
          first = false;
          translate_to_redlog(variables, assertion[i]);
        }
        cout << ")";
        break;      
      case kind::IMPLIES:
        cout << "(";
        translate_to_redlog(variables, assertion[0]);
        cout << " impl ";
        translate_to_redlog(variables, assertion[1]);
        cout << ")";
        break;
      case kind::IFF:
        cout << "(";
        translate_to_redlog(variables, assertion[0]);
        cout << " equiv ";
        translate_to_redlog(variables, assertion[1]);
        cout << ")";
        break;            
      case kind::EQUAL:
        op = "=";
        theory = true;
	break;
      case kind::LT:
        op = "<";
        theory = true;
        break;
      case kind::LEQ:
        op = "<=";
        theory = true;
        break;
      case kind::GT:
        op = ">";
        theory = true;
        break;
      case kind::GEQ:
        op = ">=";
        theory = true;
        break;
      default:
        assert(false);
        break;
    }

    if (binary) {
      cout << "(";
      translate_to_redlog(variables, assertion[0]);
      cout << " " << op << " ";
      translate_to_redlog(variables, assertion[1]);
      cout << ")";
    }      

    if (theory) {
      cout << "(";
      translate_to_redlog_term(variables, assertion[0]);
      cout << " " << op << " ";
      translate_to_redlog_term(variables, assertion[1]);
      cout << ")";
    }      
  }  
}