Ejemplo n.º 1
0
void egg_test()
{
    {
        ::regular_check(regular(bll::_1 != 'c'));
        ::regular_check(regular(bll::_1 += 1));
    }
}
Ejemplo n.º 2
0
static bool enclosed(const long dims[2], const long strs[2])
{
	assert(regular(dims[0], strs[0]));
	assert(regular(dims[1], strs[1]));

	return (strs[1] >= dims[0] * strs[0]);
}
Ejemplo n.º 3
0
int main()
{
	/* test 1 (small test) */
	printf("Test 1, size = 15:\n");
	int a1[20] = {0};
	regular(a1, 20);
	print_array(a1, 20);
	
	/* test 2 (large test) */
	printf("\nTest 2, size = 500:\n");
	int a2[500] = {0};
	regular(a2, 500);
	print_array(a2, 500);
	
   system("PAUSE");
   return 0;
}
Ejemplo n.º 4
0
void info_manager::get_info_record(environment const & env, options const & o, io_state const & ios, pos_info pos,
                                   json & record, std::function<bool (info_data const &)> pred) const {
    type_context_old tc(env, o);
    io_state_stream out = regular(env, ios, tc).update_options(o);
    get_line_info_set(pos.first).for_each([&](unsigned c, list<info_data> const & ds) {
        if (c == pos.second) {
            for (auto const & d : ds) {
                if (!pred || pred(d))
                    d.report(out, record);
            }
        }
    });
}
Ejemplo n.º 5
0
int
main (int argc, char *argv[])
{
  tests_start_mpfr ();

  bug20090519 ();

  test_generic (2, 100, 100);

  special ();
  regular ();

  tests_end_mpfr ();
  return 0;
}
Ejemplo n.º 6
0
Direction AI::decideMovement(D3DXVECTOR3 position)
{
	switch(state)
	{
	case S_REGULAR:
		{
			regular(position);
			break;
		}
	case S_DEAD:
		{
			dead(position);
			break;
		}
	case S_FLEE:
		{
			flee(position);
			break;
		}
	}
	
	if(getTileClosestAt(position) == destination || !destination)
	{
		for(int i = 0; i < 1000000; i++)
		{
			destination = tiles->at( rand()%tiles->size() );
			if(calcRoute(getTileClosestAt(position),destination))
				break;
		}
	}
	if(!route.empty())
	{
		Direction dir = route.front();
		route.pop_front();
		return dir;
	}
	return D_SIZE;
}
Ejemplo n.º 7
0
tactic check_expr_tactic(elaborate_fn const & elab, expr const & e,
                         std::string const & fname, pair<unsigned, unsigned> const & pos) {
    return tactic01([=](environment const & env, io_state const & ios, proof_state const & s) {
            goals const & gs = s.get_goals();
            if (empty(gs)) {
                throw_no_goal_if_enabled(s);
                return none_proof_state();
            }
            goal const & g      = head(gs);
            name_generator ngen = s.get_ngen();
            expr new_e = std::get<0>(elab(g, ios.get_options(), ngen.mk_child(), e, none_expr(), s.get_subst(), false));
            auto tc = mk_type_checker(env, ngen.mk_child());
            expr new_t = tc->infer(new_e).first;
            auto out = regular(env, ios);
            flycheck_information info(out);
            if (info.enabled()) {
                out << fname << ":" << pos.first << ":" << pos.second << ": information: ";
                out << "check result:\n";
            }
            out << new_e << " : " << new_t << endl;
            return some_proof_state(s);
        });
}
int main() {

Movie regular("Regular movie", Movie::REGULAR);
Movie newRelease("New release", Movie::NEW_RELEASE);
Movie children("Children's Movie", Movie::CHILDRENS);

	// Test Constructor & Correct Movie Pointer
	{
		// Create rentals of these movies
		Rental r1(regular, 10);
		assert("Regular movie" == r1.getMovie().getTitle());
	}

	// Test Days
	{
		// Create rentals of these movies
		Rental r1(regular, 10);
		assert(r1.getDaysRented() == 10);
	}

	// Test getCharge
	{
		// Create rentals of each type
		Rental r1(regular, 10); 	// Regular price code.
		Rental r2(newRelease, 12);	// New Release price code.
		Rental r3(children, 15);	// Children price code.

		// Test logic of getCharge() function
		assert(r1.getCharge() ==  (2 + (r1.getDaysRented() - 2) * 1.5));
		assert(r2.getCharge() == (r2.getDaysRented() * 3));
		assert(r3.getCharge() ==  (1.5 + (r3.getDaysRented() - 3) * 1.5));

	}

  return 0;
}
Ejemplo n.º 9
0
void parser_imp::show_tactic_prompt() {
    if (m_interactive) {
        regular(m_io_state) << "## ";
        regular(m_io_state).flush();
    }
}
Ejemplo n.º 10
0
void parser_imp::show_prompt(bool interactive, io_state const & ios) {
    if (interactive) {
        regular(ios) << "# ";
        regular(ios).flush();
    }
}
Ejemplo n.º 11
0
void actualizarPVS(){
	pvs = regular(&r,nivel);
}
Ejemplo n.º 12
0
char*
pathfind(const char* name, const char* lib, const char* type, char* buf, size_t size)
{
	register Dir_t*		dp;
	register char*		s;
	char			tmp[PATH_MAX];
	struct stat		st;

	if (((s = strrchr(name, '/')) || (s = (char*)name)) && strchr(s, '.'))
		type = 0;

	/*
	 * always check the unadorned path first
	 * this handles . and absolute paths
	 */

	if (regular(name, &st))
	{
		strncopy(buf, name, size);
		return buf;
	}
	if (type)
	{
		sfsprintf(buf, size, "%s.%s", name, type);
		if (regular(buf, &st))
			return buf;
	}
	if (*name == '/')
		return 0;

	/*
	 * check the directory of the including file
	 * on the assumption that error_info.file is properly stacked
	 */

	if (error_info.file && (s = strrchr(error_info.file, '/')))
	{
		sfsprintf(buf, size, "%-.*s%s", s - error_info.file + 1, error_info.file, name);
		if (regular(buf, &st))
			return buf;
		if (type)
		{
			sfsprintf(buf, size, "%-.*s%s%.s", s - error_info.file + 1, error_info.file, name, type);
			if (regular(buf, &st))
				return buf;
		}
	}

	/*
	 * check the include dir list
	 */

	for (dp = state.head; dp; dp = dp->next)
	{
		sfsprintf(tmp, sizeof(tmp), "%s/%s", dp->dir, name);
		if (pathpath(tmp, "", PATH_REGULAR, buf, size))
			return buf;
		if (type)
		{
			sfsprintf(tmp, sizeof(tmp), "%s/%s.%s", dp->dir, name, type);
			if (pathpath(tmp, "", PATH_REGULAR, buf, size))
				return buf;
		}
	}

	/*
	 * finally a lib related search on PATH
	 */

	if (lib)
	{
		if (s = strrchr((char*)lib, ':'))
			lib = (const char*)s + 1;
		sfsprintf(tmp, sizeof(tmp), "lib/%s/%s", lib, name);
		if (pathpath(tmp, "", PATH_REGULAR, buf, size))
			return buf;
		if (type)
		{
			sfsprintf(tmp, sizeof(tmp), "lib/%s/%s.%s", lib, name, type);
			if (pathpath(tmp, "", PATH_REGULAR, buf, size))
				return buf;
		}
	}
	return 0;
}
Ejemplo n.º 13
0
static int MCAntithetic(double s, NumFunc_1 *p, double t, double r, double divid, double sigma, long N, int generator, double inc, double confidence,int delta_met, double *ptprice, double *ptdelta, double *pterror_price, double *pterror_delta, double *inf_price, double *sup_price, double *inf_delta, double *sup_delta)
{
  short flag;
  long i;
  double g;
  int simulation_dim= 1;
  int init_mc;
  double mean_price, mean_delta, var_price, var_delta,forward, forward_stock,exp_sigmaxwt1, exp_sigmaxwt2, S_T1, U_T1, S_T2, U_T2, price1, price2,
  price_sample, delta_sample=0., price_sample_plus1, s_plus, price_sample_minus1, s_minus,
  price_sample_plus2, price_sample_minus2, brown, K1, K2,sigma_sqrt;
  double alpha, z_alpha;
  double g_reg,g_reg_der,eps=1.0;

  /* Value to construct the confidence interval */
  alpha= (1.- confidence)/2.;
  z_alpha= pnl_inv_cdfnor(1.- alpha);

  /*Initialisation*/
  flag= 0;
  s_plus= s*(1.+inc);
  s_minus= s*(1.-inc);
  mean_price= 0.0;
  mean_delta= 0.0;
  var_price= 0.0;
  var_delta= 0.0;

  /* CallSpread */
  K1= p->Par[0].Val.V_PDOUBLE;
  K2= p->Par[1].Val.V_PDOUBLE;

  /*Median forward stock and delta values*/
  sigma_sqrt=sigma*sqrt(t);
  forward= exp(((r-divid)-SQR(sigma)/2.0)*t);
  forward_stock= s*forward;

  /* Change a Call into a Put to apply the Call-Put parity */
  if((p->Compute) == &Call)
    {
      (p->Compute) = &Put;
      flag= 1;
    }

  /*MC sampling with Antithetic Variables */
  init_mc= pnl_rand_init(generator, simulation_dim,N);
  /* Test after initialization for the generator */
  if(init_mc == OK)
    {


      /* Begin N iterations */
      for(i=1 ; i<=N ; i++)
        {
          /* Simulation of a gaussian variable according to the generator type,
           that is Monte Carlo or Quasi Monte Carlo. */
          g= pnl_rand_normal(generator);
          brown= sigma_sqrt*g;

          /* Antithetic Variables */
          exp_sigmaxwt1=exp(brown);
          exp_sigmaxwt2= 1./exp_sigmaxwt1;

          S_T1= forward_stock*exp_sigmaxwt1;
          U_T1= forward*exp_sigmaxwt1;
          S_T2= forward_stock*exp_sigmaxwt2;
          U_T2= forward*exp_sigmaxwt2;

          /*Price*/
          price1= (p->Compute)(p->Par,S_T1);
          price2= (p->Compute)(p->Par,S_T2);
          price_sample= 0.5*(price1 + price2);

          /*Delta*/

          /*Digit*/
          if ((p->Compute) ==  &Digit) 
            {
              if (delta_met==1){
                price_sample_plus1= (p->Compute)(p->Par, U_T1*s_plus);
                price_sample_minus1= (p->Compute)(p->Par, U_T1*s_minus);
                price_sample_plus2= (p->Compute)(p->Par, U_T2*s_plus);
                price_sample_minus2= (p->Compute)(p->Par, U_T2*s_minus);
                delta_sample= (price_sample_plus1-price_sample_minus1+price_sample_plus2-price_sample_minus2)/(4.*s*inc);
              }
              if (delta_met==2){
                /*Malliavin Global*/
                delta_sample=((price1*g*sqrt(t))/(s*sigma*t)-(price2*g*sqrt(t))/(s*sigma*t))/2.;
              }
              if(delta_met==3){
                /*Malliavin Local*/
                g_reg=K2*exp(-r*t)*regular(eps,S_T1-K1);
                g_reg_der=K2*exp(-r*t)*der_regular(eps,S_T1-K1);
                delta_sample+=((price_sample-g_reg)*g*sqrt(t))/(s*sigma*t)+g_reg_der*S_T1/s;
                g_reg=K2*exp(-r*t)*regular(eps,S_T2-K1);
                g_reg_der=K2*exp(-r*t)*der_regular(eps,S_T2-K1);
                delta_sample+=-((price_sample-g_reg)*g*sqrt(t))/(s*sigma*t)+g_reg_der*S_T1/s;
                delta_sample*=0.5;
              }
            }

          /* CallSpread */
          else 
            if ((p->Compute) ==  &CallSpread ) 
              {
                if(delta_met==1){
                  delta_sample= 0.;
                  if(S_T1 > K1)
                    delta_sample += U_T1;
                  if(S_T1 > K2)
                    delta_sample -= U_T1;
                  if(S_T2 > K1)
                    delta_sample += U_T2;
                  if(S_T2 > K2)
                    delta_sample -= U_T2;         
                  delta_sample/= 2.;
                }
                if (delta_met==2)
                  /*Malliavin Global*/
                  delta_sample=((price1*g*sqrt(t))/(s*sigma*t)-(price2*g*sqrt(t))/(s*sigma*t))/2.;
                if (delta_met==3){
                  delta_sample=0.0;
                  g_reg=reg_call(eps,S_T1,K1);
                  g_reg_der=exp(-r*t)*F_reg_call(eps,S_T1,K1);
                  delta_sample+=g_reg*U_T1+g_reg_der*sqrt(t)*g/(s*sigma*t);

                  g_reg=reg_call(eps,S_T1,K2);
                  g_reg_der=exp(-r*t)*F_reg_call(eps,S_T1,K2);
                  delta_sample-=g_reg*U_T1+g_reg_der*sqrt(t)*g/(s*sigma*t);

                  g_reg=reg_call(eps,S_T2,K1);
                  g_reg_der=exp(-r*t)*F_reg_call(eps,S_T2,K1);
                  delta_sample+=g_reg*U_T2-g_reg_der*sqrt(t)*g/(s*sigma*t);

                  g_reg=reg_call(eps,S_T2,K2);
                  g_reg_der=exp(-r*t)*F_reg_call(eps,S_T2,K2);
                  delta_sample-=g_reg*U_T2-g_reg_der*sqrt(t)*g/(s*sigma*t);
                  delta_sample/=2.;

                }
              }

          /*Call-Put*/
            else
              if ((p->Compute) ==  &Put)
                {
                  if (delta_met==1){
                    delta_sample= 0.0;
                    if (price1 > 0.)
                      delta_sample+= -U_T1;          
                    if (price2 > 0.)
                      delta_sample+= -U_T2;          
                    delta_sample/= 2.;
                  }
                  if (delta_met==2)
                    /*Malliavin Global*/
                    delta_sample=((price1*g*sqrt(t))/(s*sigma*t)-(price2*g*sqrt(t))/(s*sigma*t))/2.;
                  if(delta_met==3){
                    /*Malliavin Local*/
                    delta_sample=0.0;
                    g_reg=reg_put(eps,S_T1,K1);
                    g_reg_der=exp(-r*t)*F_reg_put(eps,S_T1,K1);
                    delta_sample+=-(g_reg*U_T1)+g_reg_der*g*sqrt(t)/(s*sigma*t);

                    g_reg=reg_put(eps,S_T2,K1);
                    g_reg_der=exp(-r*t)*F_reg_put(eps,S_T2,K1);
                    delta_sample+=-(g_reg*U_T2)-g_reg_der*g*sqrt(t)/(s*sigma*t);

                    delta_sample/=2.;
                  }
                }

          /*Sum*/
          mean_price+= price_sample;
          mean_delta+= delta_sample;

          /*Sum of squares*/
          var_price+= SQR(price_sample);
          var_delta+= SQR(delta_sample);
        }
      /* End N iterations */


      /* Price */
      *ptprice= exp(-r*t)*(mean_price/(double) N);
      *pterror_price= sqrt(exp(-2.0*r*t)*var_price/(double)N - SQR(*ptprice))/sqrt(N-1);

      /*Delta*/
      *ptdelta= exp(-r*t)*mean_delta/(double) N;
      *pterror_delta= sqrt(exp(-2.0*r*t)*(var_delta/(double)N-SQR(*ptdelta)))/sqrt((double)N-1);

      /* Call Price and Delta with the Call Put Parity */
      if(flag == 1)
        {
          *ptprice+= s*exp(-divid*t)- p->Par[0].Val.V_DOUBLE*exp(-r*t);
          *ptdelta+= exp(-divid*t);
          (p->Compute)= &Call;
          flag = 0;
        }

      /* Price Confidence Interval */
      *inf_price= *ptprice - z_alpha*(*pterror_price);
      *sup_price= *ptprice + z_alpha*(*pterror_price);

      /* Delta Confidence Interval */
      *inf_delta= *ptdelta - z_alpha*(*pterror_delta);
      *sup_delta= *ptdelta + z_alpha*(*pterror_delta);
    } 
  return init_mc;
}
Ejemplo n.º 14
0
tactic contradiction_tactic() {
    auto fn = [=](environment const & env, io_state const & ios, proof_state const & s) {
        goals const & gs = s.get_goals();
        if (empty(gs)) {
            throw_no_goal_if_enabled(s);
            return optional<proof_state>();
        }
        goal const & g      = head(gs);
        expr const & t      = g.get_type();
        substitution subst  = s.get_subst();
        auto tc             = mk_type_checker(env);
        auto conserv_tc     = mk_type_checker(env, UnfoldReducible);
        buffer<expr> hyps;
        g.get_hyps(hyps);
        for (expr const & h : hyps) {
            expr h_type = mlocal_type(h);
            h_type      = tc->whnf(h_type).first;
            expr lhs, rhs, arg;
            if (is_false(env, h_type)) {
                assign(subst, g, mk_false_rec(*tc, h, t));
                return some_proof_state(proof_state(s, tail(gs), subst));
            } else if (is_not(env, h_type, arg)) {
                optional<expr> h_pos;
                for (expr const & h_prime : hyps) {
                    constraint_seq cs;
                    if (conserv_tc->is_def_eq(arg, mlocal_type(h_prime), justification(), cs) && !cs) {
                        h_pos = h_prime;
                        break;
                    }
                }
                if (h_pos) {
                    assign(subst, g, mk_absurd(*tc, t, *h_pos, h));
                    return some_proof_state(proof_state(s, tail(gs), subst));
                }
            } else if (is_eq(h_type, lhs, rhs)) {
                lhs = tc->whnf(lhs).first;
                rhs = tc->whnf(rhs).first;
                optional<name> lhs_c = is_constructor_app(env, lhs);
                optional<name> rhs_c = is_constructor_app(env, rhs);
                if (lhs_c && rhs_c && *lhs_c != *rhs_c) {
                    if (optional<name> I_name = inductive::is_intro_rule(env, *lhs_c)) {
                        name no_confusion(*I_name, "no_confusion");
                        try {
                            expr I      = tc->whnf(tc->infer(lhs).first).first;
                            buffer<expr> args;
                            expr I_fn   = get_app_args(I, args);
                            if (is_constant(I_fn)) {
                                level t_lvl = sort_level(tc->ensure_type(t).first);
                                expr V = mk_app(mk_app(mk_constant(no_confusion, cons(t_lvl, const_levels(I_fn))), args),
                                                t, lhs, rhs, h);
                                if (auto r = lift_down_if_hott(*tc, V)) {
                                    check_term(*tc, *r);
                                    assign(subst, g, *r);
                                    return some_proof_state(proof_state(s, tail(gs), subst));
                                }
                            }
                        } catch (kernel_exception & ex) {
                            regular(env, ios) << ex << "\n";
                        }
                    }
                }
            }
        }
        return none_proof_state();
    };
    return tactic01(fn);
}