Exemplo n.º 1
0
// bactkrack one level
static void test_backtrack(test_bench_t *bench) {
  assert(bench->decision_level > bench->base_level);

  printf("[%"PRIu32"]: TEST BACKTRACK to decision level %"PRIu32"\n", ctr, bench->decision_level - 1);
  equality_queue_backtrack(&bench->equeue);
  test_bench_undo_subst(bench);
  op_stack_backtrack(bench);
  bench->decision_level --;


  if (bench->show_details) {
    // print state after backtracking
    printf("AFTER BACKTRACK: decision level = %"PRIu32", base level = %"PRIu32"\n", bench->decision_level, bench->base_level);
    normalize_all(bench);
    printf("Active polys\n");
    print_active_polys(bench);
    printf("Assertions\n");
    print_all_equalities(bench);
    printf("Normal forms\n");
    print_normal_forms(bench);
  }

  offset_manager_backtrack(&bench->manager, bench->decision_level);

  ctr ++;
}
Exemplo n.º 2
0
static void test_pop(test_bench_t *bench) {
  assert(bench->base_level > 0);

  printf("[%"PRIu32"]: TEST POP to base level %"PRIu32"\n", ctr, bench->base_level - 1);

  if (bench->decision_level > bench->base_level) {
    // backtrack in the test_bench
    do {
      equality_queue_backtrack(&bench->equeue);
      test_bench_undo_subst(bench);
      op_stack_backtrack(bench);
      bench->decision_level --;
    } while (bench->decision_level > bench->base_level);

    // backtrack in offset_manager
    offset_manager_backtrack(&bench->manager, bench->decision_level);
  }

  // bactrack once more
  equality_queue_backtrack(&bench->equeue);
  test_bench_undo_subst(bench);
  test_bench_undo_activations(bench);
  bench->decision_level --;
  bench->base_level --;

  if (bench->show_details) {
    // print state after pop
    printf("AFTER POP: decision level = %"PRIu32", base level = %"PRIu32"\n", bench->decision_level, bench->base_level);
    normalize_all(bench);
    printf("Active polys\n");
    print_active_polys(bench);
    printf("Assertions\n");
    print_all_equalities(bench);
    printf("Normal forms\n");
    print_normal_forms(bench);
  }

  offset_manager_pop(&bench->manager);

  ctr ++;
}
Exemplo n.º 3
0
// Used assert_true instead of assert to prevent compiler warnings
int main(void) {
  uint32_t i;
  bool ok;

  init_rationals();
  build_polys();
  show_polys();

  init_offset_manager(&mngr, NULL, notify_equality);

  /*
   * FIRST TESTS
   */
  for (i=0; i<NPOLYS; i++) {
    record_offset_poly(&mngr, term[i], var[i], poly[i]);
  }

  printf("\n*** Initial state ****\n");
  print_var2poly(&mngr);
  print_var2offset_var(&mngr);
  print_ptable(&mngr);
  print_vtable(&mngr);


  ok = offset_manager_propagate(&mngr);
  printf("\n*** After propagate ****\n");
  print_ptable(&mngr);
  print_vtable(&mngr);
  assert_true(ok);

  offset_manager_increase_decision_level(&mngr);
  test_equality(var[3], var[4], 0, 123);
  ok = offset_manager_propagate(&mngr);

  printf("\n*** After propagate ****\n");
  print_ptable(&mngr);
  print_vtable(&mngr);
  assert_true(ok);

  offset_manager_backtrack(&mngr, 0);
  printf("\n*** After backtracking to level 0 ***\n");
  print_ptable(&mngr);
  print_vtable(&mngr);

  offset_manager_increase_decision_level(&mngr);
  test_equality(var[3], -1, 1, 234);
  test_equality(var[3], var[4], 0, 123);
  ok = offset_manager_propagate(&mngr);
  printf("\n*** After propagate ****\n");
  print_ptable(&mngr);
  print_vtable(&mngr);
  assert_true(ok);

  offset_manager_backtrack(&mngr, 0);
  ok = offset_manager_propagate(&mngr);
  printf("\n*** After backtracking to level 0 ***\n");
  print_ptable(&mngr);
  print_vtable(&mngr);
  assert_true(ok);

  /*
   * SECOND TEST
   */
  reset_offset_manager(&mngr);
  printf("\n*** After reset ****\n");
  print_var2poly(&mngr);
  print_var2offset_var(&mngr);
  print_ptable(&mngr);
  print_vtable(&mngr);


  for (i=0; i<NPOLYS/2; i++) {
    record_offset_poly(&mngr, term[i], var[i], poly[i]);
  }
  offset_manager_push(&mngr);

  printf("\n*** After push ****\n");
  print_var2poly(&mngr);
  print_var2offset_var(&mngr);
  print_ptable(&mngr);
  print_vtable(&mngr);

  while (i < NPOLYS) {
    record_offset_poly(&mngr, term[i], var[i], poly[i]);
    i ++;
  }

  printf("\n*** After adding all polys ****\n");
  print_ptable(&mngr);
  print_vtable(&mngr);


  test_equality(var[5], var[3], 10, 111);
  ok = offset_manager_propagate(&mngr);
  printf("\n*** After propagate ****\n");
  print_ptable(&mngr);
  print_vtable(&mngr);
  assert_true(ok);

  offset_manager_pop(&mngr);
  printf("\n*** After pop ****\n");
  print_var2poly(&mngr);
  print_var2offset_var(&mngr);
  print_ptable(&mngr);
  print_vtable(&mngr);

  test_equality(var[4], var[3], 10, 111);
  ok = offset_manager_propagate(&mngr);
  printf("\n*** After propagate ****\n");
  print_ptable(&mngr);
  print_vtable(&mngr);
  assert_true(ok);

  /*
   * THIRD TEST
   */
  reset_offset_manager(&mngr);
  printf("\n*** After reset ****\n");
  print_var2poly(&mngr);
  print_var2offset_var(&mngr);
  print_ptable(&mngr);
  print_vtable(&mngr);

  for (i=0; i<6; i++) {
    record_offset_poly(&mngr, term[i], var[i], poly[i]);
  }
  test_equality(var[5], var[3], 10, 111);
  ok = offset_manager_propagate(&mngr);
  printf("\n*** After propagate ****\n");
  print_ptable(&mngr);
  print_vtable(&mngr);
  assert_true(ok);

  offset_manager_push(&mngr);

  printf("\n*** After push ****\n");
  print_var2poly(&mngr);
  print_var2offset_var(&mngr);
  print_ptable(&mngr);
  print_vtable(&mngr);

  while (i < NPOLYS) {
    record_offset_poly(&mngr, term[i], var[i], poly[i]);
    i ++;
  }

  printf("\n*** After adding all polys ****\n");
  print_ptable(&mngr);
  print_vtable(&mngr);

  test_equality(var[4], var[3], 10, 111);
  test_equality(-1, var[3], 56, 122);
  ok = offset_manager_propagate(&mngr);
  printf("\n*** After propagate ****\n");
  print_ptable(&mngr);
  print_vtable(&mngr);
  assert_true(ok);

  offset_manager_pop(&mngr);

  printf("\n*** After pop ****\n");
  print_var2poly(&mngr);
  print_var2offset_var(&mngr);
  print_ptable(&mngr);
  print_vtable(&mngr);

  ok = offset_manager_propagate(&mngr);
  printf("\n*** After propagate ****\n");
  print_ptable(&mngr);
  print_vtable(&mngr);
  assert_true(ok);

  delete_offset_manager(&mngr);
  delete_polys();
  cleanup_rationals();

  return 0;
}