Esempio n. 1
0
 /**
    \brief extract the instantiation by searching for the first occurrence of a hyper-resolution
    rule that produces an instance.
  */
 void boogie_proof::get_subst(proof* p, subst& s) {
     ptr_vector<proof> todo;
     todo.push_back(p);
     ast_mark visited;
     std::cout << "get_subst\n" << mk_pp(p, m) << "\n";
     while (!todo.empty()) {
         proof* p = todo.back();
         todo.pop_back();
         if (visited.is_marked(p)) {
             continue;
         }
         visited.mark(p, true);
         proof_ref_vector premises(m);
         expr_ref conclusion(m);
         svector<std::pair<unsigned, unsigned> >  positions;
         vector<expr_ref_vector> substs;
         if (m.is_hyper_resolve(p, premises, conclusion, positions, substs)) {
             expr_ref_vector const& sub = substs[0];
             if (!sub.empty()) {
                 quantifier* q = to_quantifier(m.get_fact(premises[0].get()));
                 unsigned sz = sub.size();
                 SASSERT(sz == q->get_num_decls());
                 for (unsigned i = 0; i < sz; ++i) {
                     s.push_back(std::make_pair(q->get_decl_name(sz-1-i), sub[i]));
                 }
                 return;
             }
         }
         unsigned sz = m.get_num_parents(p);
         for (unsigned i = 0; i < sz; ++i) {
             todo.push_back(m.get_parent(p, i));
         }
     }
 }
Esempio n. 2
0
    void boogie_proof::pp_proof(std::ostream& out) {
        vector<step> steps;
        ptr_vector<proof> rules;
        rules.push_back(m_proof);
        steps.push_back(step());
        obj_map<proof, unsigned> index;
        index.insert(m_proof, 0);

        for (unsigned j = 0; j < rules.size(); ++j) {
            proof* p = rules[j];
            proof_ref_vector premises(m);
            expr_ref conclusion(m);
            svector<std::pair<unsigned, unsigned> >  positions;
            vector<expr_ref_vector> substs;

            expr* tmp;
            steps[j].m_fact = m.get_fact(p);
            m.is_implies(steps[j].m_fact, tmp, steps[j].m_fact);
            get_subst(p, steps[j].m_subst);
            get_labels(p, steps[j].m_labels);

            if (m.is_hyper_resolve(p, premises, conclusion, positions, substs)) {
                for (unsigned i = 1; i < premises.size(); ++i) {
                    proof* premise = premises[i].get();
                    unsigned position = 0;
                    if (!index.find(premise, position)) {
                        position = rules.size();
                        rules.push_back(premise);
                        steps.push_back(step());
                        index.insert(premise, position);
                    }
                    steps[j].m_refs.push_back(position);
                }
                get_rule_name(premises[0].get(), steps[j].m_rule_name);
            }
        }
        for (unsigned j = steps.size(); j > 0; ) {
            --j;
            step &s = steps[j];

            // TBD
            // s.m_labels;

            // set references, compensate for reverse ordering.
            for (unsigned i = 0; i < s.m_refs.size(); ++i) {
                s.m_refs[i] = rules.size()-1-s.m_refs[i];
            }
        }
        steps.reverse();
        pp_steps(out, steps);
    }
Esempio n. 3
0
    void mk_input_resolution(proof_ref& pr) {
        ast_manager& m = pr.get_manager();
        proof_ref pr1(m);
        proof_ref_vector premises1(m), premises2(m), premises(m);
        expr_ref conclusion1(m), conclusion2(m), conclusion(m);
        svector<std::pair<unsigned, unsigned> > positions1, positions2, positions;
        vector<expr_ref_vector> substs1, substs2, substs;

        if (m.is_hyper_resolve(pr, premises1, conclusion1, positions1, substs1) &&
            m.is_hyper_resolve(premises1[0].get(), premises, conclusion2, positions, substs2)) {
            for (unsigned i = 1; i < premises1.size(); ++i) {
                pr1 = premises1[i].get();
                mk_input_resolution(pr1);
                premises1[i] = pr1;
            }
            for (unsigned i = 0; i < premises.size(); ++i) {
                pr1 = premises[i].get();
                mk_input_resolution(pr1);
                premises[i] = pr1;
            }
            unsigned sz = premises.size();
            for (unsigned i = 1; i < sz; ++i) {
                proof* premise = premises[i].get();
                expr_ref_vector literals(m);
                expr* l1, *l2;
                if (!m.is_implies(premise, l1, l2)) {
                    continue;
                }
                qe::flatten_and(l1, literals);
                positions2.reset();
                premises2.reset();
                premises2.push_back(premise);
                substs2.reset();
                for (unsigned j = 0; j < literals.size(); ++j) {
                    expr* lit = literals[j].get();
                    for (unsigned k = 1; k < premises1.size(); ++k) {
                        if (m.get_fact(premises1[k].get()) == lit) {
                            premises2.push_back(premises1[k].get());
                            positions2.push_back(std::make_pair(j+1,0));
                            substs2.push_back(expr_ref_vector(m));
                            break;
                        }
                    }
                }
                premises[i] = m.mk_hyper_resolve(premises2.size(), premises2.c_ptr(), l2, positions2, substs2);
            }
            conclusion = conclusion1;
            pr = m.mk_hyper_resolve(premises.size(), premises.c_ptr(), conclusion, positions, substs);
        }
    }
Esempio n. 4
0
/* 
 * ===  FUNCTION  ======================================================================
 *         Name:  db_flush
 *  Description:  thread
 *  		  everyday first get inthis software, check table bill to make a
 *  		  conclusion for last day/month
 * =====================================================================================
 */
void *db_flush()
{
	/* pthread, use vars in local */
	char today[11]       = { 0 };	/* 03/01 */
	char bill_last[11]   = { 0 };	/* 02/27 */
	char daily_last[11]  = { 0 };	/* 02/28 */
	char monthly_last[8] = { 0 };	/* 01    */
	char sql[100] 	     = { 0 };
	/* today = get_date_time(GET_DATE); */
	strncpy(today, get_date_time(GET_DATE), 10);
	db_select_1_row(get_db_main(),
			"select date from bill order by date desc limit 1",
			1, SELECT_TEXT, bill_last);

	/*-----------------------------------------------------------------------------
	 *  whether insert into daily or not
	 *
	 *  [9] means the last one in '2010/02/28'
	 *  if no cmp with daily_last & bill_last,
	 *  the same daily conclusion will add to table daily alot of times
	 *-----------------------------------------------------------------------------*/
	if (today[9] != bill_last[9]) {
		db_select_1_row(get_db_main(),
				"select date from daily order by date desc limit 1",
				1, SELECT_TEXT, daily_last);

		if (daily_last[9] != bill_last[9]) {
			sprintf(sql, "select sales, cost, profil from bill "
				     "where date = '%s'", bill_last);
			/* 3 cols -- sales/ cost/ profil */
			int col_type[3] = { SELECT_DOUBLE, SELECT_DOUBLE, SELECT_DOUBLE };
			char **res = db_select(get_db_main(), sql, 3, col_type);
			struct daily_total *total = conclusion(res, 0);
			strncpy(monthly_last, bill_last, 7);
			sprintf(sql, "insert into daily "
				     "(date, month, count, sales, cost, profil) "
				     "values "
				     "('%s', '%s', %d, %.1f, %.1f, %.1f)",
				      /* 2010/02/28 */
				      bill_last,
				      /* 2010/02 */
				      monthly_last,
				      total->cnt,
				      total->sales,
				      total->cost,
				      total->profil);
			sqlite3_exec(get_db_main(), sql, 0, 0, 0);
		}
	}

	/*-----------------------------------------------------------------------------
	 *  whether insert into monthly or ont
	 *-----------------------------------------------------------------------------*/
	if (today[9] == '1') { 
		db_select_1_row(get_db_main(),
				"select month from monthly order by month desc limit 1",
				1, SELECT_TEXT, monthly_last);

		/* make sure daily_last has been inited */
		if ((daily_last[6] != monthly_last[6]) && daily_last[6]) {
			sprintf(sql, "select sales, cost, profil, count from daily "
				     "where month = '%s'", 
				/* has been 2010/02 */
				bill_last);
			/* 3 cols -- sales/ cost/ profil */
			int col_type[4] = { SELECT_DOUBLE, SELECT_DOUBLE, 
					    SELECT_DOUBLE, SELECT_INT };
			char **res = db_select(get_db_main(), sql, 4, col_type);
			struct daily_total *total = conclusion(res, 0);
			sprintf(sql, "insert into monthly "
				     "(month, count, sales, cost, profil) "
				     "values "
				     "('%s', %d, %.1f, %.1f, %.1f)",
				      bill_last,
				      total->cnt,
				      total->sales,
				      total->cost,
				      total->profil);
			sqlite3_exec(get_db_main(), sql, 0, 0, 0);
		}
	}
	return NULL;
	pthread_exit(NULL);
}
Esempio n. 5
0
bool Prover::prove(Diagram d1, Diagram d2)
{
  Diagram premise("p");
  Diagram conclusion("c");
  Diagram marker("EMPTY"); //marker for printing	
  Diagram localConc("c");
  Diagram localPre("p");

  premise =  d1;
  localPre = d1;

  conclusion = d2;
  localConc = d2; //holding conc for adding later
	
  holder.addDiagram(premise);
  
  //**************************************************

  Diagram afterPSZ = addMissingZones(premise);
  premise = afterPSZ; //update premise to new premise 
  
  Diagram afterPMC = addMissingContours(premise, conclusion);

  holder.addDiagram(marker);	

  Diagram afterCMZ = addMissingZones(conclusion);
  conclusion = afterCMZ; //update conclusion to new conclusion

  Diagram afterCMC = addMissingContours(conclusion, premise );

  //***************************************************

  holder.addDiagram(localConc);
  

  holder.displayAllDiagrams();

  vector<Zone> finalPSZ = afterPMC.getShadedZones(); // get shaded z of
  // last premise and
  // last conclusion
  vector<Zone> finalCSZ = afterCMC.getShadedZones();


//   for (int i =0; i< finalCSZ.size() ; i++)
//     {
//       cout << "zone in Conclusion :" << finalCSZ[i].getPair()<< endl;
//     }
//  for(int j =0; j< finalPSZ.size() ; j++)
//    {
//      cout << "zone in premise :" << finalPSZ[j].getPair()<< endl;
//    }
  vector<int> inds; // index holder

  //if final shaded zs of conclusion is a subset of the zones there is
  //a proof
  for (int i =0; i< finalCSZ.size() ; i++)
    {
      for(int j =0; j< finalPSZ.size() ; j++)
	{
	  if( finalCSZ[i].equals(finalPSZ[j]) )
	    {
	      inds.push_back(i);
	    }
	}
    }
  
  if(inds.size() == finalCSZ.size())
    return true;
  
  return false;
}