Beispiel #1
0
// make order of eval. explicit
int fact2 (int x) {
  int tmp;
  if (x == 1)
    return x;
  else {
    tmp = fact2(x-1);
    return x * tmp;
  }
}
Beispiel #2
0
void factorial(long nb, long k) 
{


	if ( (nb % k)!=0)
	{
		printf("%ld", fact2(nb, k, l));
	}
	if ( (nb % k)==0)
	{
		printf("%ld", fact1(nb, k, l));
	}
}
int I_WRAP_SONAME_FNNAME_ZU(NONE,fact1) ( int n )
{
   int    r;
   OrigFn fn;
   VALGRIND_GET_ORIG_FN(fn);
   printf("in wrapper1-pre:  fact(%d)\n", n);
   addMoreLard();
   CALL_FN_W_W(r, fn, n);
   addMoreLard();
   printf("in wrapper1-post: fact(%d) = %d\n", n, r);
   if (n >= 3) r += fact2(2);
   return r;
}
Beispiel #4
0
/**
 * must compile optioin '-lm' 
 */
int main(int argc, char *argv[])
{
	double	num,per;
	int		n = 23;
	
//	num = pow(2,128);
	
//	per = 1 - (fact(365) / ( pow(365,n)*fact(365-n) ));
	
	per = 1 - ( fact2(365, n) / pow(365, n) ) ;
	
	printf("%lf\n",per);
	
	return 0;
}
Beispiel #5
0
int fact2(int n) {
	return n>1?n*fact2(n-1):1;
}
Beispiel #6
0
int fact1 ( int n )
{
   if (n == 0) return 1; else return mul(n, fact2(n-1));
}
Beispiel #7
0
Datei: 07B.c Projekt: neotaso/pp
double mac(int n){
  int i;
  double sum=0;
  for(i=0;i<n;i++)sum+=xn2(i)/fact2(i);
  return sum;
}
int fact1 ( int n )
{
   addMoreLard();
   if (n == 0) return 1; else return mul(n, fact2(n-1));
}
Beispiel #9
0
double fact2(double n, double to)
{
	return (n>to+1) ? n*fact2(n-1,to) : 1;
}
    void test_smt_relation_unit() {
        ast_manager m;
        reg_decl_plugins(m);
        arith_util a(m);
        sort* int_sort = a.mk_int();
        sort* real_sort = a.mk_real();
        front_end_params params;
        context ctx(m, params);    
        relation_manager & rm = ctx.get_rmanager();
        relation_signature sig1;
        sig1.push_back(int_sort);
        sig1.push_back(int_sort);
        sig1.push_back(real_sort);
        
        smt_relation_plugin plugin(rm);
        
        scoped_rel<relation_base> r1 = plugin.mk_empty(sig1);

        // add_fact
        relation_fact fact1(m);
        fact1.push_back(a.mk_numeral(rational(1), true));
        fact1.push_back(a.mk_numeral(rational(2), true));
        fact1.push_back(a.mk_numeral(rational(3), false));

        relation_fact fact2(m);
        fact2.push_back(a.mk_numeral(rational(2), true));
        fact2.push_back(a.mk_numeral(rational(2), true));
        fact2.push_back(a.mk_numeral(rational(3), false));
                        
        r1->add_fact(fact1);
        r1->display(std::cout << "r1: ");


        // contains_fact
        SASSERT(r1->contains_fact(fact1));
        SASSERT(!r1->contains_fact(fact2));

        // empty
        scoped_rel<relation_base> r2 = plugin.mk_empty(sig1);
        SASSERT(!r1->empty());
        SASSERT(r2->empty());

        // clone
        scoped_rel<relation_base> r3 = r1->clone();

        // complement?
        r2->add_fact(fact2);
        scoped_rel<relation_base> r4 = dynamic_cast<smt_relation&>(*r2).complement(0);
        r4->display(std::cout << "complement r4: " );

        // join
        unsigned col_cnt = 2;
        unsigned cols1[2] = {1, 2};
        unsigned cols2[2] = {0, 2};
        scoped_ptr<relation_join_fn> joinfn = plugin.mk_join_fn(*r1, *r4, col_cnt, cols1, cols2);
        scoped_rel<relation_base> r5 = (*joinfn)(*r1, *r4);
        r5->display(std::cout<< "join r5: ");

        relation_fact fact3(m);
        fact3.push_back(a.mk_numeral(rational(1), true));
        fact3.push_back(a.mk_numeral(rational(2), true));
        fact3.push_back(a.mk_numeral(rational(3), false));
        fact3.push_back(a.mk_numeral(rational(2), true));
        fact3.push_back(a.mk_numeral(rational(2), true));
        fact3.push_back(a.mk_numeral(rational(3), false));
        SASSERT(!r5->contains_fact(fact3));
        fact3[5] = a.mk_numeral(rational(4), false);
        SASSERT(!r5->contains_fact(fact3));
        fact3[5] = a.mk_numeral(rational(3), false);
        fact3[4] = a.mk_numeral(rational(3), true);
        SASSERT(r5->contains_fact(fact3));

        // project
        unsigned removed_cols[2] = { 1, 4 };
        scoped_ptr<relation_transformer_fn> projfn = plugin.mk_project_fn(*r5, col_cnt, removed_cols);
        scoped_rel<relation_base> r6 = (*projfn)(*r5);
        r6->display(std::cout<< "project r6: ");

        // rename
        unsigned cycle[3] = { 0, 2, 4 };
        unsigned cycle_len = 3;
        scoped_rel<relation_transformer_fn> renamefn = plugin.mk_rename_fn(*r5, cycle_len, cycle);
        scoped_rel<relation_base> r7 = (*renamefn)(*r5);
        r7->display(std::cout << "rename r7: ");

        // union
        // widen
        relation_base* delta = 0;
        scoped_ptr<relation_union_fn> widenfn = plugin.mk_widen_fn(*r1, *r2, delta);
        scoped_ptr<relation_union_fn> unionfn = plugin.mk_union_fn(*r1, *r2, delta);
        scoped_rel<relation_base> r8 = r1->clone();
        (*unionfn)(*r8,*r2,0);
        r8->display(std::cout << "union r8: ");

        // filter_identical
        unsigned identical_cols[2] = { 1, 3 };
        scoped_ptr<relation_mutator_fn> filti = plugin.mk_filter_identical_fn(*r5, col_cnt, identical_cols);
        scoped_rel<relation_base> r9 = r1->clone();
        (*filti)(*r9);
        r9->display(std::cout << "filter identical r9: ");

        // filter_equal
        app_ref value(m);
        value = m.mk_const(symbol("x"), int_sort);
        scoped_rel<relation_mutator_fn> eqn = plugin.mk_filter_equal_fn(*r5, value.get(), 3);
        scoped_rel<relation_base> r10 = r1->clone();
        (*eqn)(*r10);
        r10->display(std::cout << "filter equal r10: ");


        // filter_interpreted
        app_ref cond(m);
        cond = a.mk_lt(m.mk_var(3, int_sort), m.mk_var(4, int_sort));
        scoped_rel<relation_mutator_fn> filtint = plugin.mk_filter_interpreted_fn(*r5, cond);
        scoped_rel<relation_base> r11 = r5->clone();
        (*filtint)(*r11);
        r11->display(std::cout << "filter interpreted r11: ");
                       
    }