Exemplo n.º 1
0
Arquivo: MPolUnit.c Projeto: 8l/csolve
void mpolunit(MPOL *p, MINT *coef, MPOL *q)
{ 
  register i;
  MINT *resco,rem;
  MPOL res;


  if (p->nterms==0) {
	mpolfree(q);
	mset(0,coef);
	return;
  };
  
  MINIT(&rem);
  MFREE(coef);
  MCOPY(&(p->coefs[0]),coef);
  for (i=1;i<p->nterms;i++)
	mgcd(coef,&(p->coefs[i]),coef);

  MPOLINIT(&res);

  res.nterms = p->nterms;
  POL_ALLOC(&res,p->nterms); 
  resco = res.coefs;
  for (i=0;i<p->nterms;i++){
	MINIT(resco);
	mdiv(&(p->coefs[i]),coef,(resco++),&rem);
	expocopy(MEXPO(p,i),MEXPO(&res,i));
  }
  mpolfree(q);
  MPOLMOVEFREE(&res,q);
  MFREE(&rem);
}
Exemplo n.º 2
0
Arquivo: NewAddPol.c Projeto: spl/ivy
void new_mpolsetadd(polsettype *s, MPOL *p)
{
    register MPOL *pt1,*pt2;
    register short *pexp;

    pexp = MEXPO(p,0);
    pt1 = s->polp;
    switch (order_on_pols) {
    case 0:		/* No special order */
        p->next=NULL;
        if (s->polp==NULL)
            s->polp=p;
        else {
            while((pt1->next)!=NULL)
                pt1=pt1->next;
            pt1->next=p;
        }
        break;
    case 1:		/* Descending order */
        pt2=pt1;
        while((pt1!=NULL)&& ((*cmp_exp)(pexp,MEXPO(pt1,0),nvars)<0)) {
            pt2=pt1;
            pt1=pt1->next;
        }
        p->next=pt1;
        if(pt1!=pt2)
            pt2->next=p;
        else
            (s->polp)=p;
        break;
    case 2:		/* Ascending order */
        pt2=pt1;
        while((pt1!=NULL)&& ((*cmp_exp)(pexp,MEXPO(pt1,0),nvars)>0)) {
            pt2=pt1;
            pt1=pt1->next;
        }
        p->next=pt1;
        if(pt1!=pt2)
            pt2->next=p;
        else
            (s->polp)=p;
        break;
    case 3:		/* by ascending number of terms. */
        pt2=pt1;
        while((pt1!=NULL)&& (p->nterms>pt1->nterms)) {
            pt2=pt1;
            pt1=pt1->next;
        }
        p->next=pt1;
        if(pt1!=pt2)
            pt2->next=p;
        else
            (s->polp) =p;
        break;
    }
    s->npols++;
    return;
}
Exemplo n.º 3
0
Arquivo: MPolSub.c Projeto: 8l/csolve
void mpolsub(MPOL *p, MPOL *q, MPOL *r)
{

  register ip=0,iq=0,is=0;
  MPOL s;

  POL_ALLOC(&s,p->nterms + q->nterms);
  while ((ip<p->nterms)&&(iq<q->nterms)) {
#if (! INTR)
    (*PollPtr)();
#endif
    switch ((*cmp_exp)(MEXPO(p,ip),MEXPO(q,iq))) {
    case 1 : expocopy(MEXPO(p,ip),MEXPO(&s,is));
      MCOPY(&(p->coefs[ip]),&(s.coefs[is]));
      ip++;is++;break;
    case -1 : expocopy(MEXPO(q,iq),MEXPO(&s,is));
      MCOPY(&(q->coefs[iq]),&(s.coefs[is]));
      mnegate(&(s.coefs[is]));
      iq++;is++;break;
    case 0 : MCOPY(&(q->coefs[iq]),&(s.coefs[is]));
      mnegate(&(s.coefs[is]));
      madd(&(p->coefs[ip]),&(s.coefs[is]),&(s.coefs[is]));		
      if (mtest(&(s.coefs[is]))) {
	expocopy(MEXPO(p,ip),MEXPO(&s,is));
	is++;
      };
      ip++;iq++;
    };
  };
  while (ip<p->nterms) {
#if (! INTR)
    (*PollPtr)();
#endif
    expocopy(MEXPO(p,ip),MEXPO(&s,is));
    MCOPY(&(p->coefs[ip]),&(s.coefs[is]));
    ip++; is++;
  };
  while (iq<q->nterms) {
#if (! INTR)
    (*PollPtr)();
#endif
    expocopy(MEXPO(q,iq),MEXPO(&s,is));
    MCOPY(&(q->coefs[iq]),&(s.coefs[is]));
    mnegate(&(s.coefs[is]));
    iq++; is++;
  };
  s.nterms = is;
  if (is==0){
    xfree((char *)s.coefs);
    xfree((char *)s.expos);
  };

  mpolfree(r);	
  MPOLMOVEFREE(&s,r);
};