예제 #1
0
파일: main.c 프로젝트: clconway/cvc3-debian
void test6()
{
  Flags flags = vc_createFlags();
  VC vc;
  Expr p, p3, p32;
  char *x;

  //  vc_setBoolFlag(flags, "proofs", 1);
  vc_setBoolFlag(flags, "dagify-exprs", 0);
  vc = vc_createValidityChecker(flags);

  //  p = vc_getProofOfFile(vc,"benchmarks/add1.cvc");
  check_error("Failed to check file");

  //  vc_deleteExpr(p);
  vc_destroyValidityChecker(vc);
  vc_deleteFlags(flags);

/*   p3 = getChild(p,3); */
/*   p32 = getChild(p3,2); */

/*   if (isLambda(p32)) */
/*     printf("The expression is Lambda\n"); */
/*   else */
/*     printf("The expression is not Lambda\n"); */

/*   x = exprString(p32); */

  /*  printf("Test expr,%s",x);*/

}
예제 #2
0
파일: main.c 프로젝트: clconway/cvc3-debian
void test5()
{
  Flags flags = vc_createFlags();
  VC vc;
  Type r;
  Expr x, xEQx, p;

  //  vc_setBoolFlag(flags, "proofs", TRUE);
  vc = vc_createValidityChecker(flags);

  r = vc_realType(vc);
  x = vc_varExpr(vc, "x", r);
  xEQx = vc_eqExpr(vc, x, x);

  vc_query(vc, xEQx);

  //  p = vc_getProof(vc);

  //  vc_printExpr(vc, p);

  vc_deleteType(r);
  vc_deleteExpr(x);
  vc_deleteExpr(xEQx);
  //  vc_deleteExpr(p);

  vc_destroyValidityChecker(vc);
  vc_deleteFlags(flags);
}
예제 #3
0
파일: main.c 프로젝트: clconway/cvc3-debian
void test11()
{
  Flags flags = vc_createFlags();
  VC vc = vc_createValidityChecker(flags);
  Type a = vc_createType(vc, "a");
  Type aa = vc_funType1(vc, a, a);
  Op f = vc_createOp(vc, "f", aa);
  Expr x = vc_varExpr(vc, "x", a);
  Expr fx = vc_funExpr1(vc, f, x);
  Expr ffx = vc_funExpr1(vc, f, fx);
  Expr e = vc_eqExpr(vc, x, fx);
  Expr expectE = vc_eqExpr(vc, fx, ffx);
  Expr newE = vc_substExpr(vc, e, &x, 1, &fx, 1);
  FatalAssert(expectE == newE, "Expected equal");
  vc_destroyValidityChecker(vc);
}
예제 #4
0
파일: main.c 프로젝트: clconway/cvc3-debian
void test10()
{
  Flags flags = vc_createFlags();
  VC vc = vc_createValidityChecker(flags);
  Type a = vc_createType(vc, "a");
  Type aa = vc_funType1(vc, a, a);
  Op f1 = vc_createOp(vc, "f", aa);
  Type aa2;
  Op f2 = vc_lookupOp(vc, "f", &aa2);
  FatalAssert(f2 != NULL, "Expected f2 not NULL");
  FatalAssert(f1 == f2, "Expected equal");
  Expr x = vc_varExpr(vc, "x", a);
  Expr f1x = vc_funExpr1(vc, f1, x);
  Expr f2x = vc_funExpr1(vc, f2, x);
  Expr eq = vc_eqExpr(vc, f1x, f2x);
  int res = vc_query(vc, eq);
  printf("eq: %d\n", res);
  vc_destroyValidityChecker(vc);
}
예제 #5
0
파일: main.c 프로젝트: clconway/cvc3-debian
void test1()
{
  Flags flags = vc_createFlags();
  VC vc;
  Type b;
  Expr p, np, e;
  Type r, real2real;
  Expr x, y, fx, fy, xeqy, fxeqfy, w, z, weqx, yeqz, one, two, xeqone, xeqtwo,
    simp, simp2;
  Op f;
  Expr* assertions;
  int i, size, res;
  Kind k;

  vc_setStringFlag(flags, "dump-log", ".testc1.cvc");
  vc_setStrSeqFlag(flags, "trace", "pushpop", 1);

  vc = vc_createValidityChecker(flags);

  // Check p OR ~p

  b = vc_boolType(vc);
  p = vc_varExpr(vc, "p", vc_boolType(vc));
  np = vc_notExpr(vc, p);
  e = vc_orExpr(vc, p, np);

  res = check(vc, e);
  FatalAssert(res == 1, "Expected Valid");

  FatalAssert(vc_getKind(e) == OR, "Expected TRUE for kind check");
  FatalAssert(vc_getKind(vc_getType(vc, e)) == BOOLEAN, "Expected TRUE for type kind check");

  vc_deleteType(b);
  vc_deleteExpr(p);
  vc_deleteExpr(np);
  vc_deleteExpr(e);

  /* Check x = y -> f(x) = f(y) */

  r = vc_realType(vc);

  x = vc_varExpr(vc, "x", r);
  y = vc_varExpr(vc, "y", r);

  real2real = vc_funType1(vc, r, r);
  f = vc_createOp(vc, "f", real2real);

  fx = vc_funExpr1(vc, f, x);
  fy = vc_funExpr1(vc, f, y);
  
  xeqy = vc_eqExpr(vc, x, y);
  fxeqfy = vc_eqExpr(vc, fx, fy);

  e = vc_impliesExpr(vc, xeqy, fxeqfy);
  res = check(vc, e);
  FatalAssert(res == 1, "Expected Valid");

  vc_deleteType(real2real);
  vc_deleteExpr(e);

  // Check f(x) = f(y) -> x = y

  e = vc_impliesExpr(vc, fxeqfy, xeqy);
  vc_push(vc);
  res = check(vc, e);
  FatalAssert(res == 0, "Expected Invalid");
  vc_deleteExpr(e);

  // Get counter-example

  printf("Stack level: %d\n", vc_stackLevel(vc));
  printf("Counter-example:\n");
  assertions = vc_getCounterExample(vc, &size);
  
  for (i = 0; i < size; ++i) {
    vc_printExpr(vc, assertions[i]);
  }
  vc_deleteVector(assertions);
  printf("End of counter-example\n\n");

  printf("Concrete model:\n");
  assertions = vc_getConcreteModel(vc, &size);
  
  for (i = 0; i < size; ++i) {
    vc_printExpr(vc, assertions[i]);
  }
  vc_deleteVector(assertions);
  printf("End of concrete model\n\n");

  // Reset to initial scope
  printf("Resetting\n");
  vc_pop(vc);
  printf("Stack level: %d\n\n", vc_stackLevel(vc));

  // Check w = x & x = y & y = z & f(x) = f(y) & x = 1 & z = 2

  w = vc_varExpr(vc, "w", r);
  z = vc_varExpr(vc, "z", r);

  printf("Push Scope\n\n");
  vc_push(vc);

  weqx = vc_eqExpr(vc, w, x);
  yeqz = vc_eqExpr(vc, y, z);
  
  one = vc_ratExpr(vc, 1, 1);
  two = vc_ratExpr(vc, 2, 1);
  xeqone = vc_eqExpr(vc, x, one);
  xeqtwo = vc_eqExpr(vc, x, two);

  newAssertion(vc, weqx);
  newAssertion(vc, xeqy);
  newAssertion(vc, yeqz);
  newAssertion(vc, fxeqfy);
  newAssertion(vc, xeqone);
  newAssertion(vc, xeqtwo);

  printf("\nsimplify(w) = ");

  simp = vc_simplify(vc, w);

  char* str = vc_printExprString(vc, simp);
  printf("%s\n", str);
  vc_deleteString(str);

  printf("Inconsistent?: %d\n", vc_inconsistent(vc, &assertions, &size));
  check_error("Error occured during inconsistency check");

  printf("Assumptions Used:\n");
  for (i = 0; i < size; ++i) {
    vc_printExpr(vc, assertions[i]);
  }
  vc_deleteVector(assertions);

  printf("\nPop Scope\n\n");
  vc_pop(vc);

  printf("simplify(w) = ");

  simp2 = vc_simplify(vc, w);
  vc_printExpr(vc, simp2);
  printf("\n");

  printf("Inconsistent?: %d\n", vc_inconsistent(vc, &assertions, &size));
  vc_deleteVector(assertions);

  vc_deleteType(r);
  vc_deleteExpr(x);
  vc_deleteExpr(y);
  vc_deleteOp(f);
  vc_deleteExpr(fx);
  vc_deleteExpr(fy);
  vc_deleteExpr(xeqy);
  vc_deleteExpr(fxeqfy);
  vc_deleteExpr(w);
  vc_deleteExpr(z);
  vc_deleteExpr(weqx);
  vc_deleteExpr(yeqz);
  vc_deleteExpr(one);
  vc_deleteExpr(two);
  vc_deleteExpr(xeqone);
  vc_deleteExpr(xeqtwo);
  vc_deleteExpr(simp);
  vc_deleteExpr(simp2);

  vc_destroyValidityChecker(vc);
  vc_deleteFlags(flags);
}
예제 #6
0
파일: main.c 프로젝트: clconway/cvc3-debian
void test8 (void)
{
  Flags flags = vc_createFlags();
/*   vc_setStrSeqFlag(flags, "trace", "pushpop", 1); */
/*   vc_setStrSeqFlag(flags, "trace", "assertLit", 1); */
/*   vc_setStrSeqFlag(flags, "trace", "assertFactCore", 1); */
/*   vc_setStrSeqFlag(flags, "trace", "assertFormula", 1); */

  VC vc = vc_createValidityChecker (flags);
  Type bv32 = vc_bvType (vc, 32);
  Expr zero = vc_bvConstExprFromInt (vc, 32, 0);
  Expr one = vc_bvConstExprFromInt (vc, 32, 1);
  Expr a = vc_varExpr (vc, "a", bv32);
  Expr three = vc_bvConstExprFromInt (vc, 32, 3);
  Expr prod = vc_bvMultExpr (vc, 32, a, three);
  {
    Expr a64 = vc_bvSignExtend (vc, a, 64);
    Expr three64 = vc_bvSignExtend (vc, three, 64);
    Expr prod64 = vc_bvMultExpr (vc, 64, a64, three64);
    Expr max = vc_bvConstExprFromInt (vc, 32, 2147483647);
    Expr min = vc_bvConstExprFromInt (vc, 32, (-2147483647 - 1));
    Expr prod64_sge_min = vc_bvSGeExpr (vc, prod64, min);
    Expr prod64_sle_max = vc_bvSLeExpr (vc, prod64, max);
    Expr prod64_sge_min_and_sle_max =
      vc_andExpr (vc, prod64_sge_min, prod64_sle_max);
    vc_assertFormula (vc, prod64_sge_min_and_sle_max);
  }
  Expr D4 = vc_varExpr (vc, "D4", bv32);
  {
    Expr cond = vc_bvSLtExpr (vc, a, prod);
    Expr test = vc_iteExpr (vc, cond, one, zero);
    Expr D4_eq_test = vc_eqExpr (vc, D4, test);
    vc_assertFormula (vc, D4_eq_test);
  }
  Expr D6 = vc_varExpr (vc, "D6", bv32);
  {
    Expr cond = vc_bvSLeExpr (vc, a, prod);
    Expr test = vc_iteExpr (vc, cond, one, zero);
    Expr D6_eq_test = vc_eqExpr (vc, D6, test);
    vc_assertFormula (vc, D6_eq_test);
  }
  vc_push (vc);
  vc_pop (vc);
  vc_push (vc);
  {
    Expr cond = vc_bvSLtExpr (vc, a, zero);
    Expr test = vc_iteExpr (vc, cond, one, zero);
    Expr test_eq_one = vc_eqExpr (vc, test, one);
    vc_assertFormula (vc, test_eq_one);
    vc_push (vc);
    {
      Expr D4_eq_one = vc_eqExpr (vc, D4, one);
      vc_query (vc, D4_eq_one);
    }
    vc_pop (vc);
    vc_push (vc);
    vc_pop (vc);
    vc_push (vc);
    vc_pop (vc);
  }
  vc_pop (vc);
  {
    Expr cond = vc_eqExpr (vc, a, zero);
    Expr test = vc_iteExpr (vc, cond, one, zero);
    Expr test_eq_one = vc_eqExpr (vc, test, one);
    vc_assertFormula (vc, test_eq_one);
    vc_push (vc);
    vc_pop (vc);
    {
      Expr zero_eq_one = vc_eqExpr (vc, zero, one);
      vc_query (vc, zero_eq_one);
    }
  }
  vc_destroyValidityChecker(vc);
}
예제 #7
0
value caml_vc_createFlags(value unit)
{
  CAMLparam1(unit);
  CAMLreturn(alloc_Flags(vc_createFlags()));
}