Exemplo n.º 1
0
	BOOST_GPU_ENABLED
	static void evaluate(TYPE__ X, A &R, TYPE__ &f1,
			     const T &thread) {
	    TYPE__ y = X - 2.0;
	    polynomial::evaluate(R, y, R_CP, thread);
	    if (master(thread)) evaluate1(y, f1, F_CP);
	}
Exemplo n.º 2
0
int evaluate1(SyntaxTree tree)
{
  switch (tree->op ){
   case And: return evaluate1(tree->lchild) && evaluate1(tree->rchild);
   case Or: return evaluate1(tree->lchild) || evaluate1(tree->rchild);
   case Impl: return evaluate1(tree->lchild)?  (evaluate1(tree->rchild)): 1;
   case Equi: return evaluate1(tree->lchild) == evaluate1(tree->rchild);
   case Not: return  ! evaluate1(tree->lchild);
   case ConstKind: return tree->val.true_value;
   case Atom: return (tree->val.atom)->value;
   default:  printf("evaluate error!\n"); exit(0);
   }
}
Exemplo n.º 3
0
double SplineCubic::getAngleRad(float distance) const
{
	if(distance < 0.0) distance = getCursor();	// No parameter distance given, use cursor position

	QPointF abl1 = evaluate1(distance);
	double angleRad = atan2(abl1.y(), abl1.x());
// 	logger->Spline("getAnglerad(): got atan2(%.2F, %.2F) = %.4F.", abl1.y(), abl1.x(), angleRad);
	if(angleRad < 0.0) angleRad *= -1.0;
	else if(angleRad > 0.0) angleRad = 2*M_PI - angleRad;

	// mirror the angle on the x axis...
	return 2*M_PI - angleRad;
}
Exemplo n.º 4
0
RcppExport SEXP benchmarkEvals(SEXP bmS, SEXP parS, SEXP funS, SEXP envS) {

    Rcpp::List bm(bmS);
    int nsim = Rcpp::as<int>(bm["nsim"]);

    long neval = 0;
    Rcpp::NumericVector x(parS);

    Timer t;
    double v1 = 0, v2 = 0, v3 = 0, v4 = 0, v5 = 0, v6 = 0;
    t.Start();
    for (int i=0; i<nsim; i++)
        v1 = evaluate1(&neval, x.begin(), x.size(), funS, envS);
    t.Stop();
    double t1 = t.ElapsedTime();

    t.Reset();
    neval = 0;
    t.Start();
    for (int i=0; i<nsim; i++)
        v2 = evaluate2(&neval, x.begin(), x.size(), funS, envS);
    t.Stop();
    double t2 = t.ElapsedTime();

    Rcpp::Function fun(funS);
    Rcpp::Environment env(envS);

    t.Reset();
    neval = 0;
    t.Start();
    for (int i=0; i<nsim; i++)
        v3 = evaluate3(&neval, x.begin(), x.size(), fun, env);
    t.Stop();
    double t3 = t.ElapsedTime();

    t.Reset();
    neval = 0;
    t.Start();
    for (int i=0; i<nsim; i++)
        v4 = evaluate4(&neval, x.begin(), x.size(), fun, env);
    t.Stop();
    double t4 = t.ElapsedTime();

    t.Reset();
    neval = 0;
    t.Start();
    for (int i=0; i<nsim; i++)
        v5 = evaluate5(neval, x, fun, env);
    t.Stop();
    double t5 = t.ElapsedTime();

    t.Reset();
    neval = 0;
    Rcpp::Function fc(fun);
    Rcpp::Environment en(env);
    t.Start();
    for (int i=0; i<nsim; i++)
        v6 = evaluate6(neval, x, fc, en);
    t.Stop();
    double t6 = t.ElapsedTime();

    return Rcpp::DataFrame::create(Rcpp::Named("times", Rcpp::NumericVector::create(t1, t2, t3, t4, t5, t6)),
                                   Rcpp::Named("values", Rcpp::NumericVector::create(v1, v2, v3, v4, v5, v6)));

}
Exemplo n.º 5
0
void evaluate(SyntaxTree tree)
{
	char * and, * or;	/*析取范式与合取范式*/
	printf( "truth table:\n" );
	if( count == 0 )
	{
		int result = evaluate1( tree );
		printf( "\t\tresult\n" );
		printf( "pass = 0\t%d\n", result );
		if( result == 1 )
		{
			printf( "the disjunction normal form is:\n\n" );
			printf( "the number of miniterms is 1.\n\n\n" );
			printf( "the conjunction normal form is:\n" );
			printf( "(It's a tautology!)\n" );
		}
		else
		{
			printf( "the disjunction normal form is:\n" );
			printf( "It's a contradiction!\n\n\n" );
			printf( "the conjunction normal form is:\n" );
			printf( "()\n" );
			printf( "the number of maxterm is 1.\n\n" );
		}
	}
	else
	{
		int passNum = ( int )pow( 2, count );		
		int i, j, andN = 0, orN = 0 ;
		and = ( char * )malloc( 1024 );
		or = ( char * )malloc( 1024 );
		strcpy( and, "" );
		strcpy( or, "" );
		printf( "\t\t" );
		for( i = 0; i < count; i ++ )
			printf( "%s	", sym_table[i].name );
		printf( "reslut\n" );
		for( i = 0; i < passNum; i ++ )
		{
			int result;	/*声明结果*/
			int k = i;
			/*赋值*/
			for( j = 0; j < count; j ++ )
			{
				sym_table[count-1-j].value = k % 2;
				k = ( k - sym_table[count-1-j].value ) / 2;
			}

			result = evaluate1( tree );	/*求取结果*/
			
			/*打印每一次的复制以及赋值后的结果*/
			printf( "pass = %d\t", i );
			for( k = 0; k < count; k ++ )
				printf( "%d	", sym_table[k].value );
			printf( "%d\n", result );

			if( result == 1 )
			{
				orN ++;
				for( k = 0; k < count; k ++ )
				{
					if( sym_table[k].value == 1 )
					{
						strcat( or, sym_table[k].name );
						strcat( or, "&" );
					}
					else
					{
						strcat( or, "-" );
						strcat( or, sym_table[k].name );
						strcat( or, "&" );
					}
				}
				or[strlen(or)-1] = '\0';
				strcat( or, " | " );
			}
			else
			{
				andN ++;
				strcat( and, "(" );
				for( k = 0; k < count; k ++ )
				{
					if( sym_table[k].value == 0 )
					{
						strcat( and, sym_table[k].name );
						strcat( and, "|" );
					}
					else
					{
						strcat( and, "-" );
						strcat( and, sym_table[k].name );
						strcat( and, "|" );
					}
				}
				and[strlen(and)-1] = '\0';
				strcat( and, ")" );
				strcat( and, " & " );
			}
		}
		and[strlen(and)-2] = '\0';
		or[strlen(or)-2] = '\0';
		/*打印析取范式与合取范式*/
		printf( "the disjunction normal form is:\n" );
		printf( "%s\n", or );
		printf( "the number of miniterms is %d.\n\n", orN );

		printf( "the conjunction normal form is:\n" );
		printf( "%s\n", and );
		printf( "the number of maxterm is %d.\n\n", andN );
		count = 0;
		free( and ); free( or );
	}
}