Forums before death by AOL, social media and spammers... "We can't have nice things"
|    sci.math.symbolic    |    Symbolic algebra discussion    |    10,432 messages    |
[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]
|    Message 9,480 of 10,432    |
|    Rosario19 to All    |
|    composition of math expressions in C Lan    |
|    15 Jun 17 12:05:40    |
   
   XPost: comp.lang.c   
   From: Ros@invalid.invalid   
      
   /*   
   Do you like this   
   function that would find sub expression for composition of math   
   expressions?   
      
   for example:   
    Input output   
   [3*(x+4)^2+3*(x+4)^3] [3*y_^2+3*y_^3] [(x+4)]   
   [3*(x+4) +3*(x+4)+2] [y_+y_+2] [3*(x+4)]   
   [3*(x+4)*(x+4)+3] [3*y_*y_+3] [(x+4)]   
   [3*(x+4)+(x+4)^3] [3*y_+y_^3] [(x+4)]   
   [x^3+4^2+x^3+4+7] [y_+4^2+y_+4+7] [x^3]   
   [x^3+4^2+x^3+4^2] [y_+y_] [x^3+4^2]   
   [x^3+(4)^2+x^3+(4)^3] [y_+(4)^2+y_+(4)^3] [x^3]   
   [x^3+4444^2+x^3+4444^3] [y_+4444^2+y_+4444^3] [x^3]   
   [3*(x+4*x^3)^2+3*(x+4*x^3)^3] [3*y_^2+3*y_^3] [(x+4*x^3)]   
   [3*(x^2+4*x) +3*(x^2+4*x)+2] [y_+y_+2] [3*(x^2+4*x)]   
   [3*(x+4*x)+(x+4*x)^3] [3*y_+y_^3] [(x+4*x)]   
   [x^3+x^9+4^2+x^3+x^9+4+7] [y_+4^2+y_+4+7] [x^3+x^9]   
   [x^3+4^2+x^3+4^2] [y_+y_] [x^3+4^2]   
   [x^3+(4)^2+x^3+(4)^3] [y_+(4)^2+y_+(4)^3] [x^3]   
   [x^3+4444^2+x^3+4444^3] [y_+4444^2+y_+4444^3] [x^3]   
   [sin(x)^2+9+sin(x)^2] [y_+9+y_] [sin(x)^2]   
   [3*sin(x)^2+9+3*sin(x)^2+9+1] [y_+y_+1] [3*sin(x)^2+9]   
      
   where it would find the max lenght decomposition of the string in   
   input where   
   appear x with such decompositio different from x itself   
   ["x^2+x" can not have the valid for me, decomposition "y_^2+y_", "x"]   
      
   can you suggest some math expression where this little function fail?   
   can you show some C language error [or some logic error]?   
      
   it is only one little try, possible the way of see the problem is   
   wrong...   
      
   thank you   
   */   
      
      
   #define F for   
   #define R return   
   #define G(a,b) if(a)goto b   
      
   int a[256];   
   void init(void)   
   {int i;   
    F(i='0';i<='9';++i)a[i]=1;   
    F(i='A';i<='Z';++i)a[i|32]=2,a[i]=3;   
    a['_']=4;   
    a['?']=5;   
   // a['<']=a['>']=a['=']=6; //l'espressione non e' una uguaglianza ma   
   l'espressione di una funzione   
    a['&']=a['|']=7;   
    a['+']=a['-']=8;   
    a['*']=a['/']=a['%']=a[':']=9;   
    a['^']=10;   
    a['~']=11;a['!']=12;   
    a[')']=13; // 13+3=16=a['(']   
    a[']']=14; // 14+3=17=a['[']   
    a['}']=15; // 15+3=18=a['{']   
    a['(']=16;   
    a['[']=17;   
    a['{']=18;   
   }   
      
   int isOpr(int x){R a[x]<13&&a[x]>4;}   
   int isAlphaNum(int x){R a[x]<5;}   
      
   /*   
      
    Input:   
    # ww == una stringa espressione matematica   
    con i seguenti operatori matematici e parentesi   
    /+-(){}[]:%* [^ inteso come elevamento a potenza]sin() cos()   
   tan() e   
    tutti gli operatori matematici con la loro precedenza nelle   
   espressioni matematiche   
      
    # xx == una stringa che contiene il valore di una variabile   
   dell'espressione   
      
    output:   
    # return -1 se il processo individua un errore oppure non c'e   
   altra sostituzione da fare   
    che g==x per esempio come in xx="x" ed "sin(x)+cos(x)+x^3"   
      
    # return +1 il processo individua la massima sottostringa di ww   
   che contiene la varabile in xx   
    che e' espressione matematica, posta in g   
    un altra espressione matematica posta in f   
    tali che: in f non compare la variabile in xx   
    in f compare la sottostringa[variabile] "y_"   
    che sostituendo ad y_, g in f si ottiene ww   
   ww=f(g(x))   
      
   Assegna puntatori ad ogni x   
   scorre a destra e a sinistra per vedere il massimo che si puo'   
   prendere   
    fa considerazioni sulla massima stringa ottenuta e sull'ultimo   
   operatore trovato   
   leva tale stringa dalla string ww   
   se la stringa differenza non ha x allora la decomposizione e' valida   
   altrimenti fail   
   */   
   int doComp(char**f, char**g, char*ww,char*xx)   
   {static char   
   Ff[10000],Gg[10000],*pt[1024],pl[1024],pr[1024],w[10000],led;   
    int i,j,k,pwlen,h,gstart,gend,c,d,lastOpr,kSup,ld;   
    char *p,*we,*pp,*g1,*p1,*p2;   
      
    if(led==0){led=1;init();}   
    if(f==0||g==0||w==0) R -1;   
      
    // toglie gli spazi e tutti i caratteri non riconosciuti dalla   
   stringa di partenza   
    F(j=i=0;ww[i]&&i<10000;++i)   
    if(a[ww[i]])w[j++]=ww[i]; // non e' ammesso altro tipo di   
   carattere   
    if(j>=10000)R-1;   
    w[j]=0;   
      
    // Trova le stringhe variablile e mette un puntatore all'inizio   
    F(k=i=0; w[i];++i)   
    {F(j=0;xx[j]&&w[i+j];++j)   
    if(xx[j]!=w[i+j])break;   
    if(xx[j]==0)   
    {if(k>=1024)R-1;   
    pt[k++]=w+i;   
    }   
    }   
      
    g1=Gg+5000; pwlen=k; we=w+i;   
    F(i=0;i
|
[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]
(c) 1994, bbs@darkrealms.ca