コード例 #1
0
ファイル: explicit.c プロジェクト: sbenning42/42
static int			exp_handle_x(t_dtab *token)
{
	t_tok			tmp;
	unsigned int	i;

	i = 0;
	get_coef(&tmp);
	while (++i < token->size)
	{
		if (TDATA[i].type == TOK_X)
		{
			if (TDATA[i].val == 1.0)
			{
				if (!dtab_insert(token, i + 1, &tmp))
					return (ERR_ML);
			}
			if (INS_COEF_RULES)
			{
				if (!dtab_insert(token, i++, &tmp))
					return (ERR_ML);
			}
		}
	}
	return (NO_ERR);
}
コード例 #2
0
ファイル: contains.c プロジェクト: loiluu/smc
/*
Build GF for strstr(S, pattern) = position
 */
void count_strstr(CONFIGURE *conf, MLINK lp, char* pattern, int position, bounds* results){
   if (position < 0){
      // printf("%d %s\n", position, pattern);
      count_contains(conf, lp, pattern, results);      
      return;
   }
   int n = strlen(pattern), i, j;
   int ctable[n];
   compute_correlation_table(pattern, ctable, n);
   
   bounds F0;
   char* E;
   count_not_contains(conf, lp, pattern, &F0);
   get_coef(conf, lp, F0.upperBound, position, &E);
   
   for (i = 1; i < n; i++){
      if (i > position) break;
      if (ctable[i] == 1){
            bounds fi;
            char* tmp;
            count_strstr(conf, lp, pattern, position-i, &fi);
            get_coef(conf, lp, fi.upperBound, n+position-i, &tmp);
            char* tmp2 = malloc(strlen(tmp) + strlen(E) + 5);
            sprintf(tmp2, "%s - %s", E, tmp);
            send_to_mathematica(lp, tmp2, &E);
            
            free(tmp);
            free(tmp2);
         }
   }
   char* query =  malloc(strlen(E) + 30);
   sprintf(query, "(%s)X^%d*X^%d/(1-%dX)", E, position, n, conf->alphabet_size);
   char* sresult;
   send_to_mathematica(lp, query, &sresult);
   
   if (DEBUG)
      printf("Result = %s\n", sresult);
   copy_bounds_concrete(sresult, sresult, results);

   free(query);
   free(sresult);
   free(E);
}
コード例 #3
0
ファイル: cw3b-pretty.cpp プロジェクト: oferoze/Automarking
void print_polynomial( )
{
   int i;
   if ( get_degree( ) == -1 )
   {
      return ;
   }   
   
   if ( get_degree( ) == 0 )
   {
      printf("The polynomial is %d\n",get_coef(get_degree()));
      return ;
   }   
   
   if ( get_coef(get_degree()) == -1)	
			printf("The polynomial is -x^%d",get_degree());
   else if( get_coef(get_degree()) == 1)
   				printf("The polynomial is x^%d",get_degree());
   			else		
   		    printf("The polynomial is %d x^%d",get_coef(get_degree()),get_degree());
   	
   for (i = get_degree() - 1; i > 1; i--)
   {  	
      if ( get_coef(i) > 0){ 	
      		printf(" + ");  
      	if( get_coef(i) == 1)	
      		printf("x^%d",i);
      	else 
      		printf("%d x^%d",get_coef(i),i);    	
      }else if ( get_coef(i) < 0){ 
      		printf(" - ");
      	if( get_coef(i) == -1)	
      		printf("x^%d",i);
      	else 
      		printf("%d x^%d",-get_coef(i),i);			
      }     		
   }
 
   if( get_coef(i) > 0 ){ 	
      		printf(" + ");  
      	if( get_coef(i) == 1)	
      		printf("x");
      	else 
      		printf("%d x",get_coef(i));    	
   }else if ( get_coef(i) < 0){ 
      		printf(" - ");
      	if( get_coef(i) == -1)	
      		printf("x");
      	else 
      		printf("%d x",-get_coef(i));	
   }	
      
   i--;	   
     		
   if ( get_coef(i) > 0){ 	
      		printf(" + ");  
      		printf("%d",get_coef(i));    	
   }else if ( get_coef(i) < 0){ 
      		printf(" - ");
      		printf("%d",-get_coef(i));			
   }     		
   printf("\n");
}
コード例 #4
0
ファイル: cw3b-pretty.cpp プロジェクト: oferoze/Automarking
void print_derivative( )
{
	 int i;
   if ( get_degree( ) == -1 )
   {
      return ;
   }   
   
   if ( get_degree( ) == 0 )
   {
      printf("The derivative is %d\n",0);
      return ;
   }   
   
   if ( get_degree( ) == 1 )
   {
      printf("The derivative is %d\n",get_coef(get_degree())*get_degree());
      return ;
   } 
   
   if((get_degree()-1) == 1){
   		if ( get_coef(get_degree()) == -1)	
					printf("The derivative is -%dx",get_degree());
   		else if ( get_coef(get_degree()) == 1)	
   				printf("The derivative is %dx",get_degree());
   		else
   			printf("The derivative is %d x",get_coef(get_degree())*get_degree());
   }else{	
   		if ( get_coef(get_degree()) == -1)	
				printf("The derivative is -%dx^%d",get_degree(),get_degree()-1);
   		else if ( get_coef(get_degree()) == 1)	
   				printf("The derivative is %dx^%d",get_degree(),get_degree()-1);
   		else
   			printf("The derivative is %d x^%d",get_coef(get_degree())*get_degree(),get_degree()-1);
   }	
   
   for (i = get_degree() - 1; i > 2; i--)
   {  	
      if ( get_coef(i) > 0){ 	
      		printf(" + ");  
      	if( get_coef(i) == 1)	
      		printf("x^%d",i);
      	else 
      		printf("%d x^%d",get_coef(i)*i,i - 1);    	
      }else if ( get_coef(i) < 0){ 
      		printf(" - ");
      	if( get_coef(i) == -1)	
      		printf("x^%d",i);
      	else 
      		printf("%d x^%d",-get_coef(i)*i,i -1);			
      }     		
   }
	 
	 if(i == 2){
	 	if ( get_coef(i) > 0){ 	
      		printf(" + ");  
      	if( get_coef(i) == 1)	
      		printf("x");
      	else 
      		printf("%d x",get_coef(i)*i);    	
   	}else if ( get_coef(i) < 0){ 
      		printf(" - ");
      	if( get_coef(i) == -1)	
      		printf("x");
      	else 
      		printf("%d x",-get_coef(i)*i);			
   	} 
       		
   	i--;
   }
      
	 if ( get_coef(i) > 0){ 	
      		printf(" + ");  
      		printf("%d",get_coef(i));    	
   }else if ( get_coef(i) < 0){ 
      		printf(" - ");
      		printf("%d",-get_coef(i));			
   }    
   printf("\n");
}