old.gring.cc
Go to the documentation of this file.
1 /****************************************
2 * Computer Algebra System SINGULAR *
3 ****************************************/
4 /***************************************************************
5  * File: gring.cc
6  * Purpose: noncommutative kernel procedures
7  * Author: levandov (Viktor Levandovsky)
8  * Created: 8/00 - 11/00
9  *******************************************************************/
10 
11 #define MYTEST 0
12 #define OUTPUT 0
13 
14 #if MYTEST
15 #define OM_CHECK 4
16 #define OM_TRACK 5
17 #endif
18 
19 
20 
21 
22 #include <misc/auxiliary.h>
23 
24 #ifdef HAVE_PLURAL
25 
26 # define PLURAL_INTERNAL_DECLARATIONS
27 #include "nc.h"
28 #include "sca.h"
29 #include "gb_hack.h"
30 
31 #include <polys/monomials/ring.h>
32 
33 #include <coeffs/numbers.h>
34 
35 // #include <polys/febase.h>
36 #include <misc/options.h>
37 
38 #include <polys/monomials/ring.h>
40 
41 #include <polys/simpleideals.h>
42 #include <polys/matpol.h>
43 
44 #include <polys/kbuckets.h>
45 #include <polys/sbuckets.h>
46 
47 // #include <polys/kstd1.h>
48 #include <polys/prCopy.h>
49 
51 
52 // #include <polys/pInline1.h>
53 
54 
55 #include "summator.h"
56 
57 #include "ncSAMult.h" // for CMultiplier etc classes
58 #include "ncSAFormula.h" // for CFormulaPowerMultiplier and enum Enum_ncSAType
59 
60 // #ifdef HAVE_RATGRING
61 // #include <polys/ratgring.h>
62 // #endif
63 
64 static poly NF_Proc_Dummy(ideal, ideal, poly, int, int, const ring)
65 { WerrorS("nc_NF not defined"); return NULL; }
66 static ideal BBA_Proc_Dummy (const ideal, const ideal, const intvec *, const intvec *, kStrategy, const ring)
67 { WerrorS("nc_NF not defined"); return NULL; }
68 
69 // the following funtion poiters are quasi-static:
70 // they will be set in siInit and never changes afterwards:
77 
78 /* copy : */
79 poly nc_p_CopyGet(poly a, const ring r);
80 poly nc_p_CopyPut(poly a, const ring r);
81 
82 poly nc_p_Bracket_qq(poly p, const poly q, const ring r);
83 
84 // only SCA can be used by default, formulas are off by default
86 
88 {
89  return (iNCExtensions);
90 }
91 
92 int setNCExtensions(int iMask)
93 {
94  const int iOld = getNCExtensions();
95  getNCExtensions() = iMask;
96  return (iOld);
97 }
98 
99 bool ncExtensions(int iMask) // = 0x0FFFF
100 {
101  return ((getNCExtensions() & iMask) == iMask);
102 }
103 
104 /* global nc_macros : */
105 
106 #define freeT(A,v) omFreeSize((ADDRESS)A,(v+1)*sizeof(int))
107 #define freeN(A,k) omFreeSize((ADDRESS)A,k*sizeof(number))
108 
109 
110 // some forward declarations:
111 
112 
113 // polynomial multiplication functions for p_Procs :
114 poly gnc_pp_Mult_mm(const poly p, const poly m, const ring r, poly &last);
115 poly gnc_p_Mult_mm(poly p, const poly m, const ring r);
116 poly gnc_mm_Mult_p(const poly m, poly p, const ring r);
117 poly gnc_mm_Mult_pp(const poly m, const poly p, const ring r);
118 
119 
120 /* syzygies : */
121 poly gnc_CreateSpolyOld(const poly p1, const poly p2/*, poly spNoether*/, const ring r);
122 poly gnc_ReduceSpolyOld(const poly p1, poly p2/*, poly spNoether*/, const ring r);
123 
124 poly gnc_CreateSpolyNew(const poly p1, const poly p2/*, poly spNoether*/, const ring r);
125 poly gnc_ReduceSpolyNew(const poly p1, poly p2/*, poly spNoether*/, const ring r);
126 
127 
128 
129 void gnc_kBucketPolyRedNew(kBucket_pt b, poly p, number *c);
130 void gnc_kBucketPolyRed_ZNew(kBucket_pt b, poly p, number *c);
131 
132 void gnc_kBucketPolyRedOld(kBucket_pt b, poly p, number *c);
133 void gnc_kBucketPolyRed_ZOld(kBucket_pt b, poly p, number *c);
134 
135 
136 // poly gnc_ReduceSpolyNew(poly p1, poly p2, poly spNoether, const ring r);
137 // void gnc_ReduceSpolyTail(poly p1, poly q, poly q2, poly spNoether, const ring r);
138 
139 // void nc_kBucketPolyRed(kBucket_pt b, poly p);
140 
141 void nc_CleanUp(nc_struct* p); // just free memory!
142 void nc_rCleanUp(ring r); // smaller than kill: just free mem
143 
144 
145 #if 0
146 // deprecated functions:
147 // poly gnc_p_Minus_mm_Mult_qq_ign(poly p, const poly m, poly q, int & d1, poly d2, const ring ri, poly &d3);
148 // poly gnc_p_Minus_mm_Mult_qq(poly p, const poly m, poly q, const ring r);
149 // poly nc_p_Minus_mm_Mult_qq(poly p, const poly m, const poly q, int &lp, int lq, const ring r);
150 // poly nc_p_Plus_mm_Mult_qq (poly p, const poly m, const poly q, int &lp, int lq, const ring r);
151 #endif
152 
153 
154 ///////////////////////////////////////////////////////////////////////////////
155 poly nc_p_Minus_mm_Mult_qq(poly p, const poly m, const poly q, int &shorter,
156  const poly, const ring r)
157 {
158  poly mc = p_Neg( p_Copy(m, r), r );
159  poly mmc = nc_mm_Mult_pp( mc, q, r );
160  p_Delete(&mc, r);
161 
162  int org_p=pLength(p);
163  int org_q=pLength(q);
164 
165  p = p_Add_q(p, mmc, r);
166 
167  shorter = pLength(p)-org_p-org_q; // ring independent!
168 
169  return(p);
170 }
171 
172 // returns p + m*q destroys p, const: q, m
173 poly nc_p_Plus_mm_Mult_qq(poly p, const poly m, const poly q, int &lp,
174  const int, const ring r)
175 {
176  p = p_Add_q(p, nc_mm_Mult_pp( m, q, r ), r);
177 
178  lp = pLength(p);
179 
180  return(p);
181 }
182 
183 #if 0
184 poly gnc_p_Minus_mm_Mult_qq_ign(poly p, const poly m, poly q, int & d1, poly d2, const ring r, poly &d3)
185 {
186  poly t;
187  int i;
188 
189  return gnc_p_Minus_mm_Mult_qq(p, m, q, d1, i, t, r);
190 }
191 #endif
192 
193 
194 //----------- auxiliary routines--------------------------
195 poly _gnc_p_Mult_q(poly p, poly q, const int copy, const ring r) // not used anymore!
196  /* destroy p,q unless copy=1 */
197 {
198  poly res=NULL;
199  poly qq,pp;
200  if (copy)
201  {
202  qq=p_Copy(q,r);
203  pp=p_Copy(p,r);
204  }
205  else
206  {
207  qq=q;
208  pp=p;
209  }
210  while (qq!=NULL)
211  {
212  res=p_Add_q(res, pp_Mult_mm(pp, qq, r), r); // p_Head(qq, r)?
213  qq=p_LmDeleteAndNext(qq,r);
214  }
215  p_Delete(&pp,r);
216  return(res);
217 }
218 
219 // return pPolyP * pPolyQ; destroy or reuse pPolyP and pPolyQ
220 poly _nc_p_Mult_q(poly pPolyP, poly pPolyQ, const ring rRing)
221 {
222  assume( rIsPluralRing(rRing) );
223 #ifdef PDEBUG
224  p_Test(pPolyP, rRing);
225  p_Test(pPolyQ, rRing);
226 #endif
227 #ifdef RDEBUG
228  rTest(rRing);
229 #endif
230 
231  int lp, lq;
232 
233  pqLength(pPolyP, pPolyQ, lp, lq, MIN_LENGTH_BUCKET);
234 
235  bool bUsePolynomial = TEST_OPT_NOT_BUCKETS || (si_max(lp, lq) < MIN_LENGTH_BUCKET); // ???
236 
237  CPolynomialSummator sum(rRing, bUsePolynomial);
238 
239  if (lq <= lp) // ?
240  {
241  // always length(q) times "p * q[j]"
242  for( ; pPolyQ!=NULL; pPolyQ = p_LmDeleteAndNext( pPolyQ, rRing ) )
243  sum += pp_Mult_mm( pPolyP, pPolyQ, rRing);
244 
245  p_Delete( &pPolyP, rRing );
246  } else
247  {
248  // always length(p) times "p[i] * q"
249  for( ; pPolyP!=NULL; pPolyP = p_LmDeleteAndNext( pPolyP, rRing ) )
250  sum += nc_mm_Mult_pp( pPolyP, pPolyQ, rRing);
251 
252  p_Delete( &pPolyQ, rRing );
253  }
254 
255  return(sum);
256 }
257 
258 // return pPolyP * pPolyQ; preserve pPolyP and pPolyQ
259 poly _nc_pp_Mult_qq(const poly pPolyP, const poly pPolyQ, const ring rRing)
260 {
261  assume( rIsPluralRing(rRing) );
262 #ifdef PDEBUG
263  p_Test(pPolyP, rRing);
264  p_Test(pPolyQ, rRing);
265 #endif
266 #ifdef RDEBUG
267  rTest(rRing);
268 #endif
269 
270  int lp, lq;
271 
272  pqLength(pPolyP, pPolyQ, lp, lq, MIN_LENGTH_BUCKET);
273 
274  bool bUsePolynomial = TEST_OPT_NOT_BUCKETS || (si_max(lp, lq) < MIN_LENGTH_BUCKET); // ???
275 
276  CPolynomialSummator sum(rRing, bUsePolynomial);
277 
278  if (lq <= lp) // ?
279  {
280  // always length(q) times "p * q[j]"
281  for( poly q = pPolyQ; q !=NULL; q = pNext(q) )
282  sum += pp_Mult_mm(pPolyP, q, rRing);
283  } else
284  {
285  // always length(p) times "p[i] * q"
286  for( poly p = pPolyP; p !=NULL; p = pNext(p) )
287  sum += nc_mm_Mult_pp( p, pPolyQ, rRing);
288  }
289 
290  return(sum);
291 }
292 
293 
294 
295 poly gnc_mm_Mult_nn (int *F, int *G, const ring r);
296 poly gnc_mm_Mult_uu (int *F,int jG,int bG, const ring r);
297 
298 /* #define nc_uu_Mult_ww nc_uu_Mult_ww_vert */
299 poly gnc_uu_Mult_ww (int i, int a, int j, int b, const ring r);
300 /* poly nc_uu_Mult_ww_vert (int i, int a, int j, int b, const ring r); */
301 /* poly nc_uu_Mult_ww_horvert (int i, int a, int j, int b, const ring r); */
302 /* poly nc_uu_Mult_ww_hvdiag (int i, int a, int j, int b, const ring r); */
303 /* not written yet */
304 
305 
306 poly gnc_p_Mult_mm_Common(poly p, const poly m, int side, const ring r)
307 /* p is poly, m is mono with coeff, destroys p */
308 /* if side==1, computes p_Mult_mm; otherwise, mm_Mult_p */
309 {
310  if ((p==NULL) || (m==NULL)) return NULL;
311  /* if (pNext(p)==NULL) return(nc_mm_Mult_nn(p,pCopy(m),r)); */
312  /* excluded - the cycle will do it anyway - OK. */
313  if (p_IsConstant(m,r)) return(p_Mult_nn(p,p_GetCoeff(m,r),r));
314 
315 #ifdef PDEBUG
316  p_Test(p,r);
317  p_Test(m,r);
318 #endif
319  poly v=NULL;
320  int rN=r->N;
321  int *P=(int *)omAlloc0((rN+1)*sizeof(int));
322  int *M=(int *)omAlloc0((rN+1)*sizeof(int));
323  /* coefficients: */
324  number cP,cM,cOut;
325  p_GetExpV(m, M, r);
326  cM=p_GetCoeff(m,r);
327  /* components:*/
328  const int expM=p_GetComp(m,r);
329  int expP=0;
330  int expOut=0;
331  /* bucket constraints: */
332  int UseBuckets=1;
333  if (pLength(p)< MIN_LENGTH_BUCKET || TEST_OPT_NOT_BUCKETS) UseBuckets=0;
334 
335  CPolynomialSummator sum(r, UseBuckets == 0);
336 
337  while (p!=NULL)
338  {
339 #ifdef PDEBUG
340  p_Test(p,r);
341 #endif
342  expP=p_GetComp(p,r);
343  if (expP==0)
344  {
345  expOut=expM;
346  }
347  else
348  {
349  if (expM==0)
350  {
351  expOut=expP;
352 #ifdef PDEBUG
353 // if (side)
354 // {
355 // PrintS("gnc_p_Mult_mm: Multiplication in the left module from the right");
356 // }
357 #endif
358  }
359  else
360  {
361  /* REPORT_ERROR */
362 #ifdef PDEBUG
363  const char* s;
364  if (side==1) s="gnc_p_Mult_mm";
365  else s="gnc_mm_Mult_p";
366  Print("%s: exponent mismatch %d and %d\n",s,expP,expM);
367 #endif
368  expOut=0;
369  }
370  }
371  p_GetExpV(p,P,r);
372  cP=pGetCoeff(p);
373  cOut=n_Mult(cP,cM,r->cf);
374  if (side==1)
375  {
376  v = gnc_mm_Mult_nn(P, M, r);
377  }
378  else
379  {
380  v = gnc_mm_Mult_nn(M, P, r);
381  }
382  v = p_Mult_nn(v,cOut,r);
383  n_Delete(&cOut,r->cf);
384  p_SetCompP(v,expOut,r);
385 
386  sum += v;
387 
388  p_LmDelete(&p,r);
389  }
390  freeT(P,rN);
391  freeT(M,rN);
392 
393  return(sum);
394 }
395 
396 /* poly functions defined in p_Procs : */
397 poly gnc_pp_Mult_mm(const poly p, const poly m, const ring r)
398 {
399  return( gnc_p_Mult_mm_Common(p_Copy(p,r), m, 1, r) );
400 }
401 
402 poly gnc_p_Mult_mm(poly p, const poly m, const ring r)
403 {
404  return( gnc_p_Mult_mm_Common(p, m, 1, r) );
405 }
406 
407 poly gnc_mm_Mult_p(const poly m, poly p, const ring r)
408 {
409  return( gnc_p_Mult_mm_Common(p, m, 0, r) );
410 }
411 
412 poly gnc_mm_Mult_pp(const poly m, const poly p, const ring r)
413 {
414  return( gnc_p_Mult_mm_Common(p_Copy(p,r), m, 0, r) );
415 }
416 
417 
418 
419 poly gnc_mm_Mult_nn(int *F0, int *G0, const ring r)
420 /* destroys nothing, no coeffs and exps */
421 {
422  poly out=NULL;
423  int i,j;
424  int iF,jG,iG;
425  int rN=r->N;
426 
427  int *F=(int *)omAlloc0((rN+1)*sizeof(int));
428  int *G=(int *)omAlloc0((rN+1)*sizeof(int));
429 
430  memcpy(F, F0,(rN+1)*sizeof(int));
431  // pExpVectorCopy(F,F0);
432  memcpy(G, G0,(rN+1)*sizeof(int));
433  // pExpVectorCopy(G,G0);
434  F[0]=0;
435  G[0]=0;
436 
437  iF=rN;
438  while ((F[iF]==0)&&(iF>=1)) iF--; /* last exp_num of F */
439  if (iF==0) /* F0 is zero vector */
440  {
441  out=p_One(r);
442  p_SetExpV(out,G0,r);
443  p_Setm(out,r);
444  freeT(F,rN);
445  freeT(G,rN);
446  return(out);
447  }
448  jG=1;
449  while ((G[jG]==0)&&(jG<rN)) jG++; /* first exp_num of G */
450  iG=rN;
451  while ((G[iG]==0)&&(iG>1)) iG--; /* last exp_num of G */
452 
453  out=p_One(r);
454 
455  if (iF<=jG)
456  /* i.e. no mixed exp_num , MERGE case */
457  {
458  { for(int ii=rN;ii>0;ii--) F[ii]+=G[ii]; }
459  p_SetExpV(out,F,r);
460  p_Setm(out,r);
461  freeT(F,rN);
462  freeT(G,rN);
463  return(out);
464  }
465 
466  number cff=n_Init(1,r->cf);
467  number tmp_num=NULL;
468  int cpower=0;
469 
470  if (ncRingType(r)==nc_skew)
471  {
472  if (r->GetNC()->IsSkewConstant==1)
473  {
474  int tpower=0;
475  for(j=jG; j<=iG; j++)
476  {
477  if (G[j]!=0)
478  {
479  cpower = 0;
480  for(i=j+1; i<=iF; i++)
481  {
482  cpower = cpower + F[i];
483  }
484  cpower = cpower*G[j]; // bug! here may happen an arithmetic overflow!!!
485  tpower = tpower + cpower;
486  }
487  }
488  cff = n_Copy(pGetCoeff(MATELEM(r->GetNC()->COM,1,2)),r->cf);
489  n_Power(cff,tpower,&tmp_num, r->cf);
490  n_Delete(&cff,r->cf);
491  cff = tmp_num;
492  }
493  else /* skew commutative with nonequal coeffs */
494  {
495  number totcff=n_Init(1,r->cf);
496  for(j=jG; j<=iG; j++)
497  {
498  if (G[j]!=0)
499  {
500  cpower = 0;
501  for(i=j+1; i<=iF; i++)
502  {
503  if (F[i]!=0)
504  {
505  cpower = F[i]*G[j]; // bug! overflow danger!!!
506  cff = n_Copy(pGetCoeff(MATELEM(r->GetNC()->COM,j,i)),r->cf);
507  n_Power(cff,cpower,&tmp_num, r->cf);
508  cff = n_Mult(totcff,tmp_num, r->cf);
509  n_Delete(&totcff, r->cf);
510  n_Delete(&tmp_num, r->cf);
511  totcff = n_Copy(cff,r->cf);
512  n_Delete(&cff,r->cf);
513  }
514  } /* end 2nd for */
515  }
516  }
517  cff=totcff;
518  }
519  { for(int ii=rN;ii>0;ii--) F[ii]+=G[ii]; }
520  p_SetExpV(out,F,r);
521  p_Setm(out,r);
522  p_SetCoeff(out,cff,r);
523  freeT(F,rN);
524  freeT(G,rN);
525  return(out);
526  } /* end nc_skew */
527 
528  /* now we have to destroy out! */
529  p_Delete(&out,r);
530 
531  if (iG==jG)
532  /* g is univariate monomial */
533  {
534  /* if (ri->GetNC()->type==nc_skew) -- postpone to TU */
535  out = gnc_mm_Mult_uu(F,jG,G[jG],r);
536  freeT(F,rN);
537  freeT(G,rN);
538  return(out);
539  }
540 
541  int *Prv=(int *)omAlloc0((rN+1)*sizeof(int));
542  int *Nxt=(int *)omAlloc0((rN+1)*sizeof(int));
543 
544  int *log=(int *)omAlloc0((rN+1)*sizeof(int));
545  int cnt=0; int cnf=0;
546 
547  /* splitting F wrt jG */
548  for (i=1;i<=jG;i++)
549  {
550  Prv[i]=F[i]; Nxt[i]=0; /* mult at the very end */
551  if (F[i]!=0) cnf++;
552  }
553 
554  if (cnf==0) freeT(Prv,rN);
555 
556  for (i=jG+1;i<=rN;i++)
557  {
558  Nxt[i]=F[i];
559  /* if (cnf!=0) Prv[i]=0; */
560  if (F[i]!=0)
561  {
562  cnt++;
563  } /* effective part for F */
564  }
565  freeT(F,rN);
566  cnt=0;
567 
568  for (i=1;i<=rN;i++)
569  {
570  if (G[i]!=0)
571  {
572  cnt++;
573  log[cnt]=i;
574  } /* lG for G */
575  }
576 
577 /* ---------------------- A C T I O N ------------------------ */
578  poly D=NULL;
579  poly Rout=NULL;
580  number *c=(number *)omAlloc0((rN+1)*sizeof(number));
581  c[0]=n_Init(1,r->cf);
582 
583  int *Op=Nxt;
584  int *On=G;
585  int *U=(int *)omAlloc0((rN+1)*sizeof(int));
586 
587  for (i=jG;i<=rN;i++) U[i]=Nxt[i]+G[i]; /* make leadterm */
588  Nxt=NULL;
589  G=NULL;
590  cnt=1;
591  int t=0;
592  poly w=NULL;
593  poly Pn=p_One(r);
594  p_SetExpV(Pn,On,r);
595  p_Setm(Pn,r);
596 
597  while (On[iG]!=0)
598  {
599  t=log[cnt];
600 
601  w=gnc_mm_Mult_uu(Op,t,On[t],r);
602  c[cnt]=n_Mult(c[cnt-1],pGetCoeff(w),r->cf);
603  D = pNext(w); /* getting coef and rest D */
604  p_LmDelete(&w,r);
605  w=NULL;
606 
607  Op[t] += On[t]; /* update exp_vectors */
608  On[t] = 0;
609 
610  if (t!=iG) /* not the last step */
611  {
612  p_SetExpV(Pn,On,r);
613  p_Setm(Pn,r);
614 #ifdef PDEBUG
615  p_Test(Pn,r);
616 #endif
617 
618 // if (pNext(D)==0)
619 // is D a monomial? could be postponed higher
620 // {
621 // Rout=nc_mm_Mult_nn(D,Pn,r);
622 // }
623 // else
624 // {
625  Rout=gnc_p_Mult_mm(D,Pn,r);
626 // }
627  }
628  else
629  {
630  Rout=D;
631  D=NULL;
632  }
633 
634  if (Rout!=NULL)
635  {
636  Rout=p_Mult_nn(Rout,c[cnt-1],r); /* Rest is ready */
637  out=p_Add_q(out,Rout,r);
638  Rout=NULL;
639  }
640  cnt++;
641  }
642  freeT(On,rN);
643  freeT(Op,rN);
644  p_Delete(&Pn,r);
645  omFreeSize((ADDRESS)log,(rN+1)*sizeof(int));
646 
647  /* leadterm and Prv-part */
648 
649  Rout=p_One(r);
650  /* U is lead.monomial */
651  U[0]=0;
652  p_SetExpV(Rout,U,r);
653  p_Setm(Rout,r); /* use again this name Rout */
654 #ifdef PDEBUG
655  p_Test(Rout,r);
656 #endif
657  p_SetCoeff(Rout,c[cnt-1],r);
658  out=p_Add_q(out,Rout,r);
659  freeT(U,rN);
660  freeN(c,rN+1);
661  if (cnf!=0) /* Prv is non-zero vector */
662  {
663  Rout=p_One(r);
664  Prv[0]=0;
665  p_SetExpV(Rout,Prv,r);
666  p_Setm(Rout,r);
667 #ifdef PDEBUG
668  p_Test(Rout,r);
669 #endif
670  out=gnc_mm_Mult_p(Rout,out,r); /* getting the final result */
671  freeT(Prv,rN);
672  p_Delete(&Rout,r);
673  }
674  return (out);
675 }
676 
677 
678 poly gnc_mm_Mult_uu(int *F,int jG,int bG, const ring r)
679 /* f=mono(F),g=(x_iG)^bG */
680 {
681  poly out=NULL;
682  int i;
683  number num=NULL;
684 
685  int rN=r->N;
686  int iF=r->N;
687  while ((F[iF]==0)&&(iF>0)) iF-- ; /* last exponent_num of F */
688 
689  if (iF==0) /* F==zero vector in other words */
690  {
691  out=p_One(r);
692  p_SetExp(out,jG,bG,r);
693  p_Setm(out,r);
694  return(out);
695  }
696 
697  int jF=1;
698  while ((F[jF]==0)&&(jF<=rN)) jF++; /* first exp of F */
699 
700  if (iF<=jG) /* i.e. no mixed exp_num */
701  {
702  out=p_One(r);
703  F[jG]=F[jG]+bG;
704  p_SetExpV(out,F,r);
705  p_Setm(out,r);
706  return(out);
707  }
708 
709  if (iF==jF) /* uni times uni */
710  {
711  out=gnc_uu_Mult_ww(iF,F[iF],jG,bG,r);
712  return(out);
713  }
714 
715  /* Now: F is mono with >=2 exponents, jG<iF */
716  /* check the quasi-commutative case */
717 // matrix LCOM=r->GetNC()->COM;
718 // number rescoef=n_Init(1,r);
719 // number tmpcoef=n_Init(1,r);
720 // int tmpint;
721 // i=iF;
722 // while (i>=jG+1)
723 // /* all the non-zero exponents */
724 // {
725 // if (MATELEM(LCOM,jG,i)!=NULL)
726 // {
727 // tmpcoef=pGetCoeff(MATELEM(LCOM,jG,i));
728 // tmpint=(int)F[i];
729 // nPower(tmpcoef,F[i],&tmpcoef);
730 // rescoef=nMult(rescoef,tmpcoef);
731 // i--;
732 // }
733 // else
734 // {
735 // if (F[i]!=0) break;
736 // }
737 // }
738 // if (iF==i)
739 // /* no action took place*/
740 // {
741 
742 // }
743 // else /* power the result up to bG */
744 // {
745 // nPower(rescoef,bG,&rescoef);
746 // /* + cleanup, post-processing */
747 // }
748 
749  int *Prv=(int*)omAlloc0((rN+1)*sizeof(int));
750  int *Nxt=(int*)omAlloc0((rN+1)*sizeof(int));
751  int *lF=(int *)omAlloc0((rN+1)*sizeof(int));
752 
753  int cnt=0; int cnf=0;
754  /* splitting F wrt jG */
755  for (i=1;i<=jG;i++) /* mult at the very end */
756  {
757  Prv[i]=F[i]; Nxt[i]=0;
758  if (F[i]!=0) cnf++;
759  }
760 
761  if (cnf==0)
762  {
763  freeT(Prv,rN); Prv = NULL;
764  }
765 
766  for (i=jG+1;i<=rN;i++)
767  {
768  Nxt[i]=F[i];
769  if (cnf!=0) { Prv[i]=0;}
770  if (F[i]!=0)
771  {
772  cnt++;
773  lF[cnt]=i;
774  } /* eff_part,lF_for_F */
775  }
776 
777  if (cnt==1) /* Nxt consists of 1 nonzero el-t only */
778  {
779  int q=lF[1];
780  poly Rout=p_One(r);
781  out=gnc_uu_Mult_ww(q,Nxt[q],jG,bG,r);
782 
783  freeT(Nxt,rN); Nxt = NULL;
784 
785  if (cnf!=0)
786  {
787  Prv[0]=0;
788  p_SetExpV(Rout,Prv,r);
789  p_Setm(Rout,r);
790 
791 #ifdef PDEBUG
792  p_Test(Rout,r);
793 #endif
794 
795  freeT(Prv,rN);
796  Prv = NULL;
797 
798  out=gnc_mm_Mult_p(Rout,out,r); /* getting the final result */
799  }
800 
801  freeT(lF,rN);
802  lF = NULL;
803 
804  p_Delete(&Rout,r);
805 
806  assume(Nxt == NULL);
807  assume(lF == NULL);
808  assume(Prv == NULL);
809 
810  return (out);
811  }
812 /* -------------------- MAIN ACTION --------------------- */
813 
814  poly D=NULL;
815  poly Rout=NULL;
816  number *c=(number *)omAlloc0((cnt+2)*sizeof(number));
817  c[cnt+1]=n_Init(1,r->cf);
818  i=cnt+2; /* later in freeN */
819  int *Op=Nxt;
820 
821  int *On=(int *)omAlloc0((rN+1)*sizeof(int));
822  int *U=(int *)omAlloc0((rN+1)*sizeof(int));
823 
824 
825  // pExpVectorCopy(U,Nxt);
826  memcpy(U, Nxt,(rN+1)*sizeof(int));
827  U[jG] = U[jG] + bG;
828 
829  /* Op=Nxt and initial On=(0); */
830  Nxt=NULL;
831 
832  poly Pp;
833  poly Pn;
834  int t=0;
835  int first=lF[1];
836  int nlast=lF[cnt];
837  int kk=0;
838  /* cnt--; */
839  /* now lF[cnt] should be <=iF-1 */
840 
841  while (Op[first]!=0)
842  {
843  t=lF[cnt]; /* cnt as it was computed */
844 
845  poly w=gnc_uu_Mult_ww(t,Op[t],jG,bG,r);
846  c[cnt]=n_Copy(pGetCoeff(w),r->cf);
847  D = pNext(w); /* getting coef and rest D */
848  p_LmDelete(&w,r);
849  w=NULL;
850 
851  Op[t]= 0;
852  Pp=p_One(r);
853  p_SetExpV(Pp,Op,r);
854  p_Setm(Pp,r);
855 
856  if (t<nlast)
857  {
858  kk=lF[cnt+1];
859  On[kk]=F[kk];
860 
861  Pn=p_One(r);
862  p_SetExpV(Pn,On,r);
863  p_Setm(Pn,r);
864 
865  if (t!=first) /* typical expr */
866  {
867  w=gnc_p_Mult_mm(D,Pn,r);
868  Rout=gnc_mm_Mult_p(Pp,w,r);
869  w=NULL;
870  }
871  else /* last step */
872  {
873  On[t]=0;
874  p_SetExpV(Pn,On,r);
875  p_Setm(Pn,r);
876  Rout=gnc_p_Mult_mm(D,Pn,r);
877  }
878 #ifdef PDEBUG
879  p_Test(Pp,r);
880 #endif
881  p_Delete(&Pn,r);
882  }
883  else /* first step */
884  {
885  Rout=gnc_mm_Mult_p(Pp,D,r);
886  }
887 #ifdef PDEBUG
888  p_Test(Pp,r);
889 #endif
890  p_Delete(&Pp,r);
891  num=n_Mult(c[cnt+1],c[cnt],r->cf);
892  n_Delete(&c[cnt],r->cf);
893  c[cnt]=num;
894  Rout=p_Mult_nn(Rout,c[cnt+1],r); /* Rest is ready */
895  out=p_Add_q(out,Rout,r);
896  Pp=NULL;
897  cnt--;
898  }
899  /* only to feel safe:*/
900  Pn=Pp=NULL;
901  freeT(On,rN);
902  freeT(Op,rN);
903 
904 /* leadterm and Prv-part with coef 1 */
905 /* U[0]=exp; */
906 /* U[jG]=U[jG]+bG; */
907 /* make leadterm */
908 /* ??????????? we have done it already :-0 */
909 
910  Rout=p_One(r);
911  p_SetExpV(Rout,U,r);
912  p_Setm(Rout,r); /* use again this name */
913  p_SetCoeff(Rout,c[cnt+1],r); /* last computed coef */
914 
915  out=p_Add_q(out,Rout,r);
916 
917  Rout=NULL;
918 
919  freeT(U, rN);
920  freeN(c, i);
921  freeT(lF, rN);
922 
923  if (cnf!=0)
924  {
925  Rout=p_One(r);
926  p_SetExpV(Rout,Prv,r);
927  p_Setm(Rout,r);
928  freeT(Prv, rN);
929  out=gnc_mm_Mult_p(Rout,out,r); /* getting the final result */
930  p_Delete(&Rout,r);
931  }
932 
933  return (out);
934 }
935 
936 poly gnc_uu_Mult_ww_vert (int i, int a, int j, int b, const ring r)
937 {
938  int k,m;
939  int rN=r->N;
940  const int cMTindex = UPMATELEM(j,i,rN);
941  matrix cMT=r->GetNC()->MT[cMTindex]; /* cMT=current MT */
942 
943  poly x=p_One(r);p_SetExp(x,j,1,r);p_Setm(x,r);
944 /* var(j); */
945  poly y=p_One(r);p_SetExp(y,i,1,r);p_Setm(y,r);
946 /*var(i); for convenience */
947 #ifdef PDEBUG
948  p_Test(x,r);
949  p_Test(y,r);
950 #endif
951  poly t=NULL;
952 /* ------------ Main Cycles ----------------------------*/
953 
954  for (k=2;k<=a;k++)
955  {
956  t = MATELEM(cMT,k,1);
957 
958  if (t==NULL) /* not computed yet */
959  {
960  t = nc_p_CopyGet(MATELEM(cMT,k-1,1),r);
961  // t=p_Copy(MATELEM(cMT,k-1,1),r);
962  t = gnc_mm_Mult_p(y,t,r);
963  cMT=r->GetNC()->MT[cMTindex]; // since multiplication can change the MT table...
964  assume( t != NULL );
965 #ifdef PDEBUG
966  p_Test(t,r);
967 #endif
968  MATELEM(cMT,k,1) = nc_p_CopyPut(t,r);
969  // omCheckAddr(cMT->m);
970  p_Delete(&t,r);
971  }
972  t=NULL;
973  }
974 
975  for (m=2;m<=b;m++)
976  {
977  t = MATELEM(cMT,a,m);
978  // t=MATELEM(cMT,a,m);
979  if (t==NULL) //not computed yet
980  {
981  t = nc_p_CopyGet(MATELEM(cMT,a,m-1),r);
982  assume( t != NULL );
983  // t=p_Copy(MATELEM(cMT,a,m-1),r);
984  t = gnc_p_Mult_mm(t,x,r);
985  cMT=r->GetNC()->MT[cMTindex]; // since multiplication can change the MT table...
986 #ifdef PDEBUG
987  p_Test(t,r);
988 #endif
989  MATELEM(cMT,a,m) = nc_p_CopyPut(t,r);
990  // MATELEM(cMT,a,m) = t;
991  // omCheckAddr(cMT->m);
992  p_Delete(&t,r);
993  }
994  t=NULL;
995  }
996  p_Delete(&x,r);
997  p_Delete(&y,r);
998  t=MATELEM(cMT,a,b);
999  assume( t != NULL );
1000 
1001  t= nc_p_CopyGet(t,r);
1002 #ifdef PDEBUG
1003  p_Test(t,r);
1004 #endif
1005  // return(p_Copy(t,r));
1006  /* since the last computed element was cMT[a,b] */
1007  return(t);
1008 }
1009 
1010 
1011 static inline poly gnc_uu_Mult_ww_formula (int i, int a, int j, int b, const ring r)
1012 {
1014  return gnc_uu_Mult_ww_vert(i, a, j, b, r);
1015 
1016  CFormulaPowerMultiplier* FormulaMultiplier = GetFormulaPowerMultiplier(r);
1018 
1019  if( FormulaMultiplier != NULL )
1020  PairType = FormulaMultiplier->GetPair(j, i);
1021 
1022 
1023  if( PairType == _ncSA_notImplemented )
1024  return gnc_uu_Mult_ww_vert(i, a, j, b, r);
1025 
1026 
1027  // return FormulaMultiplier->Multiply(j, i, b, a);
1028  poly t = CFormulaPowerMultiplier::Multiply( PairType, j, i, b, a, r);
1029 
1030  int rN=r->N;
1031  matrix cMT = r->GetNC()->MT[UPMATELEM(j,i,rN)]; /* cMT=current MT */
1032 
1033 
1034  MATELEM(cMT, a, b) = nc_p_CopyPut(t,r);
1035 
1036  // t=MATELEM(cMT,a,b);
1037 // t= nc_p_CopyGet(MATELEM(cMT,a,b),r);
1038  // return(p_Copy(t,r));
1039  /* since the last computed element was cMT[a,b] */
1040  return(t);
1041 }
1042 
1043 
1044 poly gnc_uu_Mult_ww (int i, int a, int j, int b, const ring r)
1045  /* (x_i)^a times (x_j)^b */
1046  /* x_i = y, x_j = x ! */
1047 {
1048  /* Check zero exceptions, (q-)commutativity and is there something to do? */
1049  assume(a!=0);
1050  assume(b!=0);
1051  poly out=p_One(r);
1052  if (i<=j)
1053  {
1054  p_SetExp(out,i,a,r);
1055  p_AddExp(out,j,b,r);
1056  p_Setm(out,r);
1057  return(out);
1058  }/* zero exeptions and usual case */
1059  /* if ((a==0)||(b==0)||(i<=j)) return(out); */
1060 
1061  if (MATELEM(r->GetNC()->COM,j,i)!=NULL)
1062  /* commutative or quasicommutative case */
1063  {
1064  p_SetExp(out,i,a,r);
1065  p_AddExp(out,j,b,r);
1066  p_Setm(out,r);
1067  if (n_IsOne(pGetCoeff(MATELEM(r->GetNC()->COM,j,i)),r->cf)) /* commutative case */
1068  {
1069  return(out);
1070  }
1071  else
1072  {
1073  number tmp_number=pGetCoeff(MATELEM(r->GetNC()->COM,j,i)); /* quasicommutative case */
1074  n_Power(tmp_number,a*b,&tmp_number, r->cf); // BUG! ;-(
1075  p_SetCoeff(out,tmp_number,r);
1076  return(out);
1077  }
1078  }/* end_of commutative or quasicommutative case */
1079  p_Delete(&out,r);
1080 
1081 
1082  if(ncExtensions(NOCACHEMASK) && !ncExtensions(NOFORMULAMASK)) // don't use cache whenever possible!
1083  { // without cache!?
1084  CFormulaPowerMultiplier* FormulaMultiplier = GetFormulaPowerMultiplier(r);
1086 
1087  if( FormulaMultiplier != NULL )
1088  PairType = FormulaMultiplier->GetPair(j, i);
1089 
1090  if( PairType != _ncSA_notImplemented )
1091  // // return FormulaMultiplier->Multiply(j, i, b, a);
1092  return CFormulaPowerMultiplier::Multiply( PairType, j, i, b, a, r);
1093  }
1094 
1095 
1096  /* we are here if i>j and variables do not commute or quasicommute */
1097  /* in fact, now a>=1 and b>=1; and j<i */
1098  /* now check whether the polynomial is already computed */
1099  int rN=r->N;
1100  int vik = UPMATELEM(j,i,rN);
1101  int cMTsize=r->GetNC()->MTsize[vik];
1102  int newcMTsize=0;
1103  newcMTsize=si_max(a,b);
1104 
1105  if (newcMTsize<=cMTsize)
1106  {
1107  out = nc_p_CopyGet(MATELEM(r->GetNC()->MT[vik],a,b),r);
1108  if (out !=NULL) return (out);
1109  }
1110  int k,m;
1111  if (newcMTsize > cMTsize)
1112  {
1113  int inM=(((newcMTsize+6)/7)*7);
1114  assume (inM>=newcMTsize);
1115  newcMTsize = inM;
1116  // matrix tmp = (matrix)omAlloc0(inM*inM*sizeof(poly));
1117  matrix tmp = mpNew(newcMTsize,newcMTsize);
1118 
1119  for (k=1;k<=cMTsize;k++)
1120  {
1121  for (m=1;m<=cMTsize;m++)
1122  {
1123  out = MATELEM(r->GetNC()->MT[UPMATELEM(j,i,rN)],k,m);
1124  if ( out != NULL )
1125  {
1126  MATELEM(tmp,k,m) = out;/*MATELEM(r->GetNC()->MT[UPMATELEM(j,i,rN)],k,m)*/
1127  // omCheckAddr(tmp->m);
1128  MATELEM(r->GetNC()->MT[UPMATELEM(j,i,rN)],k,m)=NULL;
1129  // omCheckAddr(r->GetNC()->MT[UPMATELEM(j,i,rN)]->m);
1130  out=NULL;
1131  }
1132  }
1133  }
1134  id_Delete((ideal *)&(r->GetNC()->MT[UPMATELEM(j,i,rN)]),r);
1135  r->GetNC()->MT[UPMATELEM(j,i,rN)] = tmp;
1136  tmp=NULL;
1137  r->GetNC()->MTsize[UPMATELEM(j,i,rN)] = newcMTsize;
1138  }
1139  /* The update of multiplication matrix is finished */
1140 
1141 
1142  return gnc_uu_Mult_ww_formula(i, a, j, b, r);
1143 
1144  out = gnc_uu_Mult_ww_vert(i, a, j, b, r);
1145  // out = nc_uu_Mult_ww_horvert(i, a, j, b, r);
1146  return(out);
1147 }
1148 
1149 poly gnc_uu_Mult_ww_horvert (int i, int a, int j, int b, const ring r)
1150 
1151 {
1152  int k,m;
1153  int rN=r->N;
1154  matrix cMT=r->GetNC()->MT[UPMATELEM(j,i,rN)]; /* cMT=current MT */
1155 
1156  poly x=p_One(r);p_SetExp(x,j,1,r);p_Setm(x,r);/* var(j); */
1157  poly y=p_One(r);p_SetExp(y,i,1,r);p_Setm(y,r); /*var(i); for convenience */
1158 #ifdef PDEBUG
1159  p_Test(x,r);
1160  p_Test(y,r);
1161 #endif
1162 
1163  poly t=NULL;
1164 
1165  int toXY;
1166  int toYX;
1167 
1168  if (a==1) /* y*x^b, b>=2 */
1169  {
1170  toXY=b-1;
1171  while ( (MATELEM(cMT,1,toXY)==NULL) && (toXY>=2)) toXY--;
1172  for (m=toXY+1;m<=b;m++)
1173  {
1174  t=MATELEM(cMT,1,m);
1175  if (t==NULL) /* remove after debug */
1176  {
1177  t = p_Copy(MATELEM(cMT,1,m-1),r);
1178  t = gnc_p_Mult_mm(t,x,r);
1179  MATELEM(cMT,1,m) = t;
1180  /* omCheckAddr(cMT->m); */
1181  }
1182  else
1183  {
1184  /* Error, should never get there */
1185  WarnS("Error: a=1; MATELEM!=0");
1186  }
1187  t=NULL;
1188  }
1189  return(p_Copy(MATELEM(cMT,1,b),r));
1190  }
1191 
1192  if (b==1) /* y^a*x, a>=2 */
1193  {
1194  toYX=a-1;
1195  while ( (MATELEM(cMT,toYX,1)==NULL) && (toYX>=2)) toYX--;
1196  for (m=toYX+1;m<=a;m++)
1197  {
1198  t=MATELEM(cMT,m,1);
1199  if (t==NULL) /* remove after debug */
1200  {
1201  t = p_Copy(MATELEM(cMT,m-1,1),r);
1202  t = gnc_mm_Mult_p(y,t,r);
1203  MATELEM(cMT,m,1) = t;
1204  /* omCheckAddr(cMT->m); */
1205  }
1206  else
1207  {
1208  /* Error, should never get there */
1209  WarnS("Error: b=1, MATELEM!=0");
1210  }
1211  t=NULL;
1212  }
1213  return(p_Copy(MATELEM(cMT,a,1),r));
1214  }
1215 
1216 /* ------------ Main Cycles ----------------------------*/
1217  /* a>1, b>1 */
1218 
1219  int dXY=0; int dYX=0;
1220  /* dXY = distance for computing x-mult, then y-mult */
1221  /* dYX = distance for computing y-mult, then x-mult */
1222  int toX=a-1; int toY=b-1; /* toX = to axe X, toY = to axe Y */
1223  toXY=b-1; toYX=a-1;
1224  /* if toX==0, toXY = dist. to computed y * x^toXY */
1225  /* if toY==0, toYX = dist. to computed y^toYX * x */
1226  while ( (MATELEM(cMT,toX,b)==NULL) && (toX>=1)) toX--;
1227  if (toX==0) /* the whole column is not computed yet */
1228  {
1229  while ( (MATELEM(cMT,1,toXY)==NULL) && (toXY>=1)) toXY--;
1230  /* toXY >=1 */
1231  dXY=b-1-toXY;
1232  }
1233  dXY=dXY+a-toX; /* the distance to nearest computed y^toX x^b */
1234 
1235  while ( (MATELEM(cMT,a,toY)==NULL) && (toY>=1)) toY--;
1236  if (toY==0) /* the whole row is not computed yet */
1237  {
1238  while ( (MATELEM(cMT,toYX,1)==NULL) && (toYX>=1)) toYX--;
1239  /* toYX >=1 */
1240  dYX=a-1-toYX;
1241  }
1242  dYX=dYX+b-toY; /* the distance to nearest computed y^a x^toY */
1243 
1244  if (dYX>=dXY)
1245  {
1246  /* first x, then y */
1247  if (toX==0) /* start with the row*/
1248  {
1249  for (m=toXY+1;m<=b;m++)
1250  {
1251  t=MATELEM(cMT,1,m);
1252  if (t==NULL) /* remove after debug */
1253  {
1254  t = p_Copy(MATELEM(cMT,1,m-1),r);
1255  t = gnc_p_Mult_mm(t,x,r);
1256  MATELEM(cMT,1,m) = t;
1257  /* omCheckAddr(cMT->m); */
1258  }
1259  else
1260  {
1261  /* Error, should never get there */
1262  WarnS("dYX>=dXY,toXY; MATELEM==0");
1263  }
1264  t=NULL;
1265  }
1266  toX=1; /* y*x^b is computed */
1267  }
1268  /* Now toX>=1 */
1269  for (k=toX+1;k<=a;k++)
1270  {
1271  t=MATELEM(cMT,k,b);
1272  if (t==NULL) /* remove after debug */
1273  {
1274  t = p_Copy(MATELEM(cMT,k-1,b),r);
1275  t = gnc_mm_Mult_p(y,t,r);
1276  MATELEM(cMT,k,b) = t;
1277  /* omCheckAddr(cMT->m); */
1278  }
1279  else
1280  {
1281  /* Error, should never get there */
1282  WarnS("dYX>=dXY,toX; MATELEM==0");
1283  }
1284  t=NULL;
1285  }
1286  } /* endif (dYX>=dXY) */
1287 
1288 
1289  if (dYX<dXY)
1290  {
1291  /* first y, then x */
1292  if (toY==0) /* start with the column*/
1293  {
1294  for (m=toYX+1;m<=a;m++)
1295  {
1296  t=MATELEM(cMT,m,1);
1297  if (t==NULL) /* remove after debug */
1298  {
1299  t = p_Copy(MATELEM(cMT,m-1,1),r);
1300  t = gnc_mm_Mult_p(y,t,r);
1301  MATELEM(cMT,m,1) = t;
1302  /* omCheckAddr(cMT->m); */
1303  }
1304  else
1305  {
1306  /* Error, should never get there */
1307  WarnS("dYX<dXY,toYX; MATELEM==0");
1308  }
1309  t=NULL;
1310  }
1311  toY=1; /* y^a*x is computed */
1312  }
1313  /* Now toY>=1 */
1314  for (k=toY+1;k<=b;k++)
1315  {
1316  t=MATELEM(cMT,a,k);
1317  if (t==NULL) /* remove after debug */
1318  {
1319  t = p_Copy(MATELEM(cMT,a,k-1),r);
1320  t = gnc_p_Mult_mm(t,x,r);
1321  MATELEM(cMT,a,k) = t;
1322  /* omCheckAddr(cMT->m); */
1323  }
1324  else
1325  {
1326  /* Error, should never get there */
1327  WarnS("dYX<dXY,toY; MATELEM==0");
1328  }
1329  t=NULL;
1330  }
1331  } /* endif (dYX<dXY) */
1332 
1333  p_Delete(&x,r);
1334  p_Delete(&y,r);
1335  t=p_Copy(MATELEM(cMT,a,b),r);
1336  return(t); /* since the last computed element was cMT[a,b] */
1337 }
1338 
1339 
1340 /* ----------------------------- Syzygies ---------------------- */
1341 
1342 /*2
1343 * reduction of p2 with p1
1344 * do not destroy p1, but p2
1345 * p1 divides p2 -> for use in NF algorithm
1346 */
1347 poly gnc_ReduceSpolyOld(const poly p1, poly p2/*,poly spNoether*/, const ring r)
1348 {
1349  assume(p_LmDivisibleBy(p1, p2, r));
1350 
1351 #ifdef PDEBUG
1352  if (p_GetComp(p1,r)!=p_GetComp(p2,r)
1353  && (p_GetComp(p1,r)!=0)
1354  && (p_GetComp(p2,r)!=0))
1355  {
1356  dReportError("nc_ReduceSpolyOld: different components");
1357  return(NULL);
1358  }
1359 #endif
1360  poly m = p_One(r);
1361  p_ExpVectorDiff(m,p2,p1,r);
1362  //p_Setm(m,r);
1363 #ifdef PDEBUG
1364  p_Test(m,r);
1365 #endif
1366  /* pSetComp(m,r)=0? */
1367  poly N = nc_mm_Mult_p(m, p_Head(p1,r), r);
1368  number C = p_GetCoeff(N, r);
1369  number cF = p_GetCoeff(p2, r);
1370  /* GCD stuff */
1371  number cG = n_SubringGcd(C, cF, r->cf);
1372  if ( !n_IsOne(cG,r->cf) )
1373  {
1374  cF = n_Div(cF, cG, r->cf); n_Normalize(cF, r->cf);
1375  C = n_Div(C, cG, r->cf); n_Normalize(C, r->cf);
1376  }
1377  else
1378  {
1379  cF = n_Copy(cF, r->cf);
1380  C = n_Copy(C, r->cf);
1381  }
1382  n_Delete(&cG,r->cf);
1383  p2 = p_Mult_nn(p2, C, r);
1384  poly out = nc_mm_Mult_pp(m, pNext(p1), r);
1385  N = p_Add_q(N, out, r);
1386  p_Test(p2,r);
1387  p_Test(N,r);
1388  if (!n_IsMOne(cF,r->cf))
1389  {
1390  cF = n_InpNeg(cF,r->cf);
1391  N = p_Mult_nn(N, cF, r);
1392  p_Test(N,r);
1393  }
1394  out = p_Add_q(p2,N,r);
1395  p_Test(out,r);
1396  if ( out!=NULL ) p_Content(out,r);
1397  p_Delete(&m,r);
1398  n_Delete(&cF,r->cf);
1399  n_Delete(&C,r->cf);
1400  return(out);
1401 }
1402 
1403 poly gnc_ReduceSpolyNew(const poly p1, poly p2, const ring r)
1404 {
1405  assume(p_LmDivisibleBy(p1, p2, r));
1406 
1407  const long lCompP1 = p_GetComp(p1,r);
1408  const long lCompP2 = p_GetComp(p2,r);
1409 
1410  if ((lCompP1!=lCompP2) && (lCompP1!=0) && (lCompP2!=0))
1411  {
1412 #ifdef PDEBUG
1413  WerrorS("gnc_ReduceSpolyNew: different non-zero components!");
1414 #endif
1415  return(NULL);
1416  }
1417 
1418  poly m = p_One(r);
1419  p_ExpVectorDiff(m, p2, p1, r);
1420  //p_Setm(m,r);
1421 #ifdef PDEBUG
1422  p_Test(m,r);
1423 #endif
1424 
1425  /* pSetComp(m,r)=0? */
1426  poly N = nc_mm_Mult_p(m, p_Head(p1,r), r);
1427 
1428  number C = p_GetCoeff(N, r);
1429  number cF = p_GetCoeff(p2, r);
1430 
1431  /* GCD stuff */
1432  number cG = n_SubringGcd(C, cF, r->cf);
1433 
1434  if (!n_IsOne(cG, r->cf))
1435  {
1436  cF = n_Div(cF, cG, r->cf); n_Normalize(cF, r->cf);
1437  C = n_Div(C, cG, r->cf); n_Normalize(C, r->cf);
1438  }
1439  else
1440  {
1441  cF = n_Copy(cF, r->cf);
1442  C = n_Copy(C, r->cf);
1443  }
1444  n_Delete(&cG,r->cf);
1445 
1446  p2 = p_Mult_nn(p2, C, r); // p2 !!!
1447  p_Test(p2,r);
1448  n_Delete(&C,r->cf);
1449  n_Delete(&cG,r->cf);
1450 
1451  poly out = nc_mm_Mult_pp(m, pNext(p1), r);
1452  p_Delete(&m,r);
1453 
1454  N = p_Add_q(N, out, r);
1455  p_Test(N,r);
1456 
1457  if (!n_IsMOne(cF,r->cf)) // ???
1458  {
1459  cF = n_InpNeg(cF,r->cf);
1460  N = p_Mult_nn(N, cF, r);
1461  p_Test(N,r);
1462  }
1463  n_Delete(&cF,r->cf);
1464 
1465  out = p_Add_q(p2,N,r); // delete N, p2
1466  p_Test(out,r);
1467  if ( out!=NULL ) p_Content(out,r);
1468  return(out);
1469 }
1470 
1471 
1472 /*4
1473 * creates the S-polynomial of p1 and p2
1474 * do not destroy p1 and p2
1475 */
1476 poly gnc_CreateSpolyOld(poly p1, poly p2/*,poly spNoether*/, const ring r)
1477 {
1478 #ifdef PDEBUG
1479  if ((p_GetComp(p1,r)!=p_GetComp(p2,r))
1480  && (p_GetComp(p1,r)!=0)
1481  && (p_GetComp(p2,r)!=0))
1482  {
1483  dReportError("gnc_CreateSpolyOld : different components!");
1484  return(NULL);
1485  }
1486 #endif
1487  if ((ncRingType(r)==nc_lie) && p_HasNotCF(p1,p2, r)) /* prod crit */
1488  {
1489  return(nc_p_Bracket_qq(p_Copy(p2, r),p1, r));
1490  }
1491  poly pL=p_One(r);
1492  poly m1=p_One(r);
1493  poly m2=p_One(r);
1494  pL = p_Lcm(p1,p2,r);
1495  p_Setm(pL,r);
1496 #ifdef PDEBUG
1497  p_Test(pL,r);
1498 #endif
1499  p_ExpVectorDiff(m1,pL,p1,r);
1500  //p_SetComp(m1,0,r);
1501  //p_Setm(m1,r);
1502 #ifdef PDEBUG
1503  p_Test(m1,r);
1504 #endif
1505  p_ExpVectorDiff(m2,pL,p2,r);
1506  //p_SetComp(m2,0,r);
1507  //p_Setm(m2,r);
1508 #ifdef PDEBUG
1509  p_Test(m2,r);
1510 #endif
1511  p_Delete(&pL,r);
1512  /* zero exponents ! */
1513  poly M1 = nc_mm_Mult_p(m1,p_Head(p1,r),r);
1514  number C1 = p_GetCoeff(M1,r);
1515  poly M2 = nc_mm_Mult_p(m2,p_Head(p2,r),r);
1516  number C2 = p_GetCoeff(M2,r);
1517  /* GCD stuff */
1518  number C = n_SubringGcd(C1,C2,r->cf);
1519  if (!n_IsOne(C,r->cf))
1520  {
1521  C1=n_Div(C1,C, r->cf);n_Normalize(C1,r->cf);
1522  C2=n_Div(C2,C, r->cf);n_Normalize(C2,r->cf);
1523  }
1524  else
1525  {
1526  C1=n_Copy(C1, r->cf);
1527  C2=n_Copy(C2, r->cf);
1528  }
1529  n_Delete(&C,r->cf);
1530  M1=p_Mult_nn(M1,C2,r);
1531  p_SetCoeff(m1,C2,r);
1532  if (n_IsMOne(C1,r->cf))
1533  {
1534  M2=p_Add_q(M1,M2,r);
1535  }
1536  else
1537  {
1538  C1=n_InpNeg(C1,r->cf);
1539  M2=p_Mult_nn(M2,C1,r);
1540  M2=p_Add_q(M1,M2,r);
1541  p_SetCoeff(m2,C1,r);
1542  }
1543  /* M1 is killed, M2=res = C2 M1 - C1 M2 */
1544  poly tmp=p_Copy(p1,r);
1545  tmp=p_LmDeleteAndNext(tmp,r);
1546  M1=nc_mm_Mult_p(m1,tmp,r);
1547  tmp=p_Copy(p2,r);
1548  tmp=p_LmDeleteAndNext(tmp,r);
1549  M2=p_Add_q(M2,M1,r);
1550  M1=nc_mm_Mult_p(m2,tmp,r);
1551  M2=p_Add_q(M2,M1,r);
1552  p_Delete(&m1,r);
1553  p_Delete(&m2,r);
1554  // n_Delete(&C1,r);
1555  // n_Delete(&C2,r);
1556 #ifdef PDEBUG
1557  p_Test(M2,r);
1558 #endif
1559  if (M2!=NULL) M2=p_Cleardenom(M2,r);
1560  //if (M2!=NULL) p_Content(M2); // done by pCleardenom
1561  return(M2);
1562 }
1563 
1564 poly gnc_CreateSpolyNew(poly p1, poly p2/*,poly spNoether*/, const ring r)
1565 {
1566 #ifdef PDEBUG
1567  p_Test(p1, r);
1568  p_Test(p2, r);
1569 #if MYTEST
1570  PrintS("p1: "); p_Write(p1, r);
1571  PrintS("p2: "); p_Write(p2, r);
1572 #endif
1573 #endif
1574 
1575  const long lCompP1 = p_GetComp(p1,r);
1576  const long lCompP2 = p_GetComp(p2,r);
1577 
1578  if ((lCompP1!=lCompP2) && (lCompP1!=0) && (lCompP2!=0))
1579  {
1580 #ifdef PDEBUG
1581  WerrorS("gnc_CreateSpolyNew: different non-zero components!");
1582  assume(0);
1583 #endif
1584  return(NULL);
1585  }
1586 
1587 // if ((r->GetNC()->type==nc_lie) && pHasNotCF(p1,p2)) /* prod crit */
1588 // {
1589 // return(nc_p_Bracket_qq(pCopy(p2),p1));
1590 // }
1591 
1592 // poly pL=p_One( r);
1593 
1594  poly m1=p_One( r);
1595  poly m2=p_One( r);
1596 
1597  poly pL = p_Lcm(p1,p2,r); // pL = lcm( lm(p1), lm(p2) )
1598 
1599 
1600 #ifdef PDEBUG
1601 // p_Test(pL,r);
1602 #endif
1603 
1604  p_ExpVectorDiff(m1, pL, p1, r); // m1 = pL / lm(p1)
1605  //p_SetComp(m1,0,r);
1606  //p_Setm(m1,r);
1607 
1608 #ifdef PDEBUG
1609  p_Test(m1,r);
1610 #endif
1611 // assume(p_GetComp(m1,r) == 0);
1612 
1613  p_ExpVectorDiff(m2, pL, p2, r); // m2 = pL / lm(p2)
1614 
1615  //p_SetComp(m2,0,r);
1616  //p_Setm(m2,r);
1617 #ifdef PDEBUG
1618  p_Test(m2,r);
1619 #endif
1620 
1621 #ifdef PDEBUG
1622 #if MYTEST
1623  PrintS("m1: "); pWrite(m1);
1624  PrintS("m2: "); pWrite(m2);
1625 #endif
1626 #endif
1627 
1628 
1629 // assume(p_GetComp(m2,r) == 0);
1630 
1631 #ifdef PDEBUG
1632 #if 0
1633  if( (p_GetComp(m2,r) != 0) || (p_GetComp(m1,r) != 0) )
1634  {
1635  WarnS("gnc_CreateSpolyNew: wrong monomials!");
1636 
1637 
1638 #ifdef RDEBUG
1639  PrintS("m1 = "); p_Write(m1, r);
1640  p_DebugPrint(m1, r);
1641 
1642  PrintS("m2 = "); p_Write(m2, r);
1643  p_DebugPrint(m2, r);
1644 
1645  PrintS("p1 = "); p_Write(p1, r);
1646  p_DebugPrint(p1, r);
1647 
1648  PrintS("p2 = "); p_Write(p2, r);
1649  p_DebugPrint(p2, r);
1650 
1651  PrintS("pL = "); p_Write(pL, r);
1652  p_DebugPrint(pL, r);
1653 #endif
1654 
1655  }
1656 
1657 #endif
1658 #endif
1659 
1660  p_Delete(&pL,r);
1661 
1662  /* zero exponents !? */
1663  poly M1 = nc_mm_Mult_p(m1,p_Head(p1,r),r); // M1 = m1 * lt(p1)
1664  poly M2 = nc_mm_Mult_p(m2,p_Head(p2,r),r); // M2 = m2 * lt(p2)
1665 
1666 #ifdef PDEBUG
1667  p_Test(M1,r);
1668  p_Test(M2,r);
1669 
1670 #if MYTEST
1671  PrintS("M1: "); pWrite(M1);
1672  PrintS("M2: "); pWrite(M2);
1673 #endif
1674 #endif
1675 
1676  if(M1 == NULL || M2 == NULL)
1677  {
1678 #ifdef PDEBUG
1679  PrintS("\np1 = ");
1680  p_Write(p1, r);
1681 
1682  PrintS("m1 = ");
1683  p_Write(m1, r);
1684 
1685  PrintS("p2 = ");
1686  p_Write(p2, r);
1687 
1688  PrintS("m2 = ");
1689  p_Write(m2, r);
1690 
1691  WerrorS("ERROR in nc_CreateSpoly: result of multiplication is Zero!\n");
1692 #endif
1693  return(NULL);
1694  }
1695 
1696  number C1 = p_GetCoeff(M1,r); // C1 = lc(M1)
1697  number C2 = p_GetCoeff(M2,r); // C2 = lc(M2)
1698 
1699  /* GCD stuff */
1700  number C = n_SubringGcd(C1, C2, r->cf); // C = gcd(C1, C2)
1701 
1702  if (!n_IsOne(C, r->cf)) // if C != 1
1703  {
1704  C1=n_Div(C1, C, r->cf);n_Normalize(C1,r->cf); // C1 = C1 / C
1705  C2=n_Div(C2, C, r->cf);n_Normalize(C2,r->cf); // C2 = C2 / C
1706  }
1707  else
1708  {
1709  C1=n_Copy(C1,r->cf);
1710  C2=n_Copy(C2,r->cf);
1711  }
1712 
1713  n_Delete(&C,r->cf); // destroy the number C
1714 
1715  C1=n_InpNeg(C1,r->cf);
1716 
1717 // number MinusOne=n_Init(-1,r);
1718 // if (n_Equal(C1,MinusOne,r)) // lc(M1) / gcd( lc(M1), lc(M2)) == -1 ????
1719 // {
1720 // M2=p_Add_q(M1,M2,r); // ?????
1721 // }
1722 // else
1723 // {
1724  M1=p_Mult_nn(M1,C2,r); // M1 = (C2*lc(p1)) * (lcm(lm(p1),lm(p2)) / lm(p1)) * lm(p1)
1725 
1726 #ifdef PDEBUG
1727  p_Test(M1,r);
1728 #endif
1729 
1730  M2=p_Mult_nn(M2,C1,r); // M2 =(-C1*lc(p2)) * (lcm(lm(p1),lm(p2)) / lm(p2)) * lm(p2)
1731 
1732 
1733 
1734 #ifdef PDEBUG
1735  p_Test(M2,r);
1736 
1737 #if MYTEST
1738  PrintS("M1: "); pWrite(M1);
1739  PrintS("M2: "); pWrite(M2);
1740 #endif
1741 #endif
1742 
1743 
1744  M2=p_Add_q(M1,M2,r); // M1 is killed, M2 = spoly(lt(p1), lt(p2)) = C2*M1 - C1*M2
1745 
1746 #ifdef PDEBUG
1747  p_Test(M2,r);
1748 
1749 #if MYTEST
1750  PrintS("M2: "); pWrite(M2);
1751 #endif
1752 
1753 #endif
1754 
1755 // M2 == 0 for supercommutative algebras!
1756 // }
1757 // n_Delete(&MinusOne,r);
1758 
1759  p_SetCoeff(m1,C2,r); // lc(m1) = C2!!!
1760  p_SetCoeff(m2,C1,r); // lc(m2) = C1!!!
1761 
1762 #ifdef PDEBUG
1763  p_Test(m1,r);
1764  p_Test(m2,r);
1765 #endif
1766 
1767 // poly tmp = p_Copy(p1,r); // tmp = p1
1768 // tmp=p_LmDeleteAndNext(tmp,r); // tmp = tail(p1)
1769 //#ifdef PDEBUG
1770 // p_Test(tmp,r);
1771 //#endif
1772 
1773  M1 = nc_mm_Mult_pp(m1, pNext(p1), r); // M1 = m1 * tail(p1), delete tmp // ???
1774 
1775 #ifdef PDEBUG
1776  p_Test(M1,r);
1777 
1778 #if MYTEST
1779  PrintS("M1: "); pWrite(M1);
1780 #endif
1781 
1782 #endif
1783 
1784  M2=p_Add_q(M2,M1,r); // M2 = spoly(lt(p1), lt(p2)) + m1 * tail(p1), delete M1
1785 #ifdef PDEBUG
1786  M1=NULL;
1787  p_Test(M2,r);
1788 
1789 #if MYTEST
1790  PrintS("M2: "); pWrite(M2);
1791 #endif
1792 
1793 #endif
1794 
1795 // tmp=p_Copy(p2,r); // tmp = p2
1796 // tmp=p_LmDeleteAndNext(tmp,r); // tmp = tail(p2)
1797 
1798 //#ifdef PDEBUG
1799 // p_Test(tmp,r);
1800 //#endif
1801 
1802  M1 = nc_mm_Mult_pp(m2, pNext(p2), r); // M1 = m2 * tail(p2), detele tmp
1803 
1804 #ifdef PDEBUG
1805  p_Test(M1,r);
1806 
1807 #if MYTEST
1808  PrintS("M1: "); pWrite(M1);
1809 #endif
1810 
1811 #endif
1812 
1813  M2 = p_Add_q(M2,M1,r); // M2 = spoly(lt(p1), lt(p2)) + m1 * tail(p1) + m2*tail(p2)
1814 
1815 #ifdef PDEBUG
1816  M1=NULL;
1817  p_Test(M2,r);
1818 
1819 #if MYTEST
1820  PrintS("M2: "); pWrite(M2);
1821 #endif
1822 
1823 #endif
1824 
1825  p_Delete(&m1,r); // => n_Delete(&C1,r);
1826  p_Delete(&m2,r); // => n_Delete(&C2,r);
1827 
1828 #ifdef PDEBUG
1829  p_Test(M2,r);
1830 #endif
1831 
1832  if (M2!=NULL) p_Cleardenom(M2,r);
1833 
1834  return(M2);
1835 }
1836 
1837 
1838 
1839 
1840 #if 0
1841 /*5
1842 * reduction of tail(q) with p1
1843 * lead(p1) divides lead(pNext(q2)) and pNext(q2) is reduced
1844 * do not destroy p1, but tail(q)
1845 */
1846 void gnc_ReduceSpolyTail(poly p1, poly q, poly q2, poly spNoether, const ring r)
1847 {
1848  poly a1=p_Head(p1,r);
1849  poly Q=pNext(q2);
1850  number cQ=p_GetCoeff(Q,r);
1851  poly m=p_One(r);
1852  p_ExpVectorDiff(m,Q,p1,r);
1853  // p_SetComp(m,0,r);
1854  //p_Setm(m,r);
1855 #ifdef PDEBUG
1856  p_Test(m,r);
1857 #endif
1858  /* pSetComp(m,r)=0? */
1859  poly M = nc_mm_Mult_pp(m, p1,r);
1860  number C=p_GetCoeff(M,r);
1861  M=p_Add_q(M,nc_mm_Mult_p(m,p_LmDeleteAndNext(p_Copy(p1,r),r),r),r); // _pp?
1862  q=p_Mult_nn(q,C,r);
1863  number MinusOne=n_Init(-1,r->cf);
1864  if (!n_Equal(cQ,MinusOne,r->cf))
1865  {
1866  cQ=nInpNeg(cQ);
1867  M=p_Mult_nn(M,cQ,r);
1868  }
1869  Q=p_Add_q(Q,M,r);
1870  pNext(q2)=Q;
1871 
1872  p_Delete(&m,r);
1873  n_Delete(&C,r->cf);
1874  n_Delete(&cQ,r->cf);
1875  n_Delete(&MinusOne,r->cf);
1876  /* return(q); */
1877 }
1878 #endif
1879 
1880 
1881 /*6
1882 * creates the commutative lcm(lm(p1),lm(p2))
1883 * do not destroy p1 and p2
1884 */
1886 {
1887 #ifdef PDEBUG
1888  p_Test(p1, r);
1889  p_Test(p2, r);
1890 #endif
1891 
1892  const long lCompP1 = p_GetComp(p1,r);
1893  const long lCompP2 = p_GetComp(p2,r);
1894 
1895  if ((lCompP1!=lCompP2) && (lCompP1!=0) && (lCompP2!=0))
1896  {
1897 #ifdef PDEBUG
1898  WerrorS("nc_CreateShortSpoly: wrong module components!"); // !!!!
1899 #endif
1900  return(NULL);
1901  }
1902 
1903  poly m;
1904 
1905 #ifdef HAVE_RATGRING
1906  if ( rIsRatGRing(r))
1907  {
1908  /* rational version */
1909  m = p_LcmRat(p1, p2, si_max(lCompP1, lCompP2), r);
1910  } else
1911 #endif
1912  {
1913  m = p_Lcm(p1, p2, r);
1914  }
1915 
1916 // n_Delete(&p_GetCoeff(m, r), r->cf);
1917 // pSetCoeff0(m, NULL);
1918 
1919 #ifdef PDEBUG
1920 // p_Test(m,r);
1921 #endif
1922 
1923  return(m);
1924 }
1925 
1927 {
1928  const ring r = b->bucket_ring;
1929  // b will not be multiplied by any constant in this impl.
1930  // ==> *c=1
1931  if (c!=NULL) *c=n_Init(1, r->cf);
1932  poly m=p_One(r);
1934  //pSetm(m);
1935 #ifdef PDEBUG
1936  p_Test(m, r);
1937 #endif
1938  poly pp= nc_mm_Mult_pp(m,p, r);
1939  assume(pp!=NULL);
1940  p_Delete(&m, r);
1941  number n=pGetCoeff(pp);
1942  number nn;
1943  if (!n_IsMOne(n, r->cf))
1944  {
1945  nn=n_InpNeg(n_Invers(n, r->cf), r->cf);
1946  n= n_Mult(nn,pGetCoeff(kBucketGetLm(b)), r->cf);
1947  n_Delete(&nn, r->cf);
1948  pp=p_Mult_nn(pp,n,r);
1949  n_Delete(&n, r->cf);
1950  }
1951  else
1952  {
1954  }
1955  int l=pLength(pp);
1956  kBucket_Add_q(b,pp,&l);
1957 }
1958 
1960 {
1961  const ring r = b->bucket_ring;
1962 #ifdef PDEBUG
1963 // PrintS(">*");
1964 #endif
1965 
1966 #ifdef KDEBUG
1967  if( !kbTest(b) ) WerrorS("nc_kBucketPolyRed: broken bucket!");
1968 #endif
1969 
1970 #ifdef PDEBUG
1971  p_Test(p, r);
1972 #if MYTEST
1973  PrintS("p: "); p_Write(p, r);
1974 #endif
1975 #endif
1976 
1977  // b will not be multiplied by any constant in this impl.
1978  // ==> *c=1
1979  if (c!=NULL) *c=n_Init(1, r->cf);
1980  poly m = p_One(r);
1981  const poly pLmB = kBucketGetLm(b); // no new copy!
1982 
1983  assume( pLmB != NULL );
1984 
1985 #ifdef PDEBUG
1986  p_Test(pLmB, r);
1987 
1988 #if MYTEST
1989  PrintS("pLmB: "); p_Write(pLmB, r);
1990 #endif
1991 #endif
1992 
1993  p_ExpVectorDiff(m, pLmB, p, r);
1994  //pSetm(m);
1995 
1996 #ifdef PDEBUG
1997  p_Test(m, r);
1998 #if MYTEST
1999  PrintS("m: "); p_Write(m, r);
2000 #endif
2001 #endif
2002 
2003  poly pp = nc_mm_Mult_pp(m, p, r);
2004  p_Delete(&m, r);
2005 
2006  assume( pp != NULL );
2007  const number n = pGetCoeff(pp); // bug!
2008 
2009  if (!n_IsMOne(n, r->cf) ) // does this improve performance??!? also see below... // TODO: check later on.
2010  // if n == -1 => nn = 1 and -1/n
2011  {
2012  number nn=n_InpNeg(n_Invers(n, r->cf), r->cf);
2013  number t = n_Mult(nn,pGetCoeff(pLmB), r->cf);
2014  n_Delete(&nn, r->cf);
2015  pp = p_Mult_nn(pp,t,r);
2016  n_Delete(&t, r->cf);
2017  }
2018  else
2019  {
2020  pp = p_Mult_nn(pp,p_GetCoeff(pLmB, r), r);
2021  }
2022 
2023  int l = pLength(pp);
2024 
2025 #ifdef PDEBUG
2026  p_Test(pp, r);
2027 // PrintS("PP: "); pWrite(pp);
2028 #endif
2029 
2030  kBucket_Add_q(b,pp,&l);
2031 
2032 
2033 #ifdef PDEBUG
2034 // PrintS("*>");
2035 #endif
2036 }
2037 
2038 
2040 {
2041  const ring r = b->bucket_ring;
2042  // b is multiplied by a constant in this impl.
2043  number ctmp;
2044  poly m=p_One(r);
2046  //pSetm(m);
2047 #ifdef PDEBUG
2048  p_Test(m, r);
2049 #endif
2050  if(p_IsConstant(m,r))
2051  {
2052  p_Delete(&m, r);
2053  ctmp = kBucketPolyRed(b,p,pLength(p),NULL);
2054  }
2055  else
2056  {
2057  poly pp = nc_mm_Mult_pp(m,p,r);
2058  number c2;
2059  p_Cleardenom_n(pp,r,c2);
2060  p_Delete(&m, r);
2061  ctmp = kBucketPolyRed(b,pp,pLength(pp),NULL);
2062  //cc=*c;
2063  //*c=nMult(*c,c2);
2064  n_Delete(&c2, r->cf);
2065  //nDelete(&cc);
2066  p_Delete(&pp, r);
2067  }
2068  if (c!=NULL) *c=ctmp;
2069  else n_Delete(&ctmp, r->cf);
2070 }
2071 
2073 {
2074  const ring r = b->bucket_ring;
2075  // b is multiplied by a constant in this impl.
2076  number ctmp;
2077  poly m=p_One(r);
2079  //pSetm(m);
2080 #ifdef PDEBUG
2081  p_Test(m, r);
2082 #endif
2083 
2084  if(p_IsConstant(m,r))
2085  {
2086  p_Delete(&m, r);
2087  ctmp = kBucketPolyRed(b,p,pLength(p),NULL);
2088  }
2089  else
2090  {
2091  poly pp = nc_mm_Mult_pp(m,p,r);
2092  number c2;
2093  p_Cleardenom_n(pp,r,c2);
2094  p_Delete(&m, r);
2095  ctmp = kBucketPolyRed(b,pp,pLength(pp),NULL);
2096  //cc=*c;
2097  //*c=nMult(*c,c2);
2098  n_Delete(&c2, r->cf);
2099  //nDelete(&cc);
2100  p_Delete(&pp, r);
2101  }
2102  if (c!=NULL) *c=ctmp;
2103  else n_Delete(&ctmp, r->cf);
2104 }
2105 
2106 
2107 inline void nc_PolyPolyRedOld(poly &b, poly p, number *c, const ring r)
2108  // reduces b with p, do not delete both
2109 {
2110  // b will not by multiplied by any constant in this impl.
2111  // ==> *c=1
2112  if (c!=NULL) *c=n_Init(1, r->cf);
2113  poly m=p_One(r);
2114  p_ExpVectorDiff(m,p_Head(b, r),p, r);
2115  //pSetm(m);
2116 #ifdef PDEBUG
2117  p_Test(m, r);
2118 #endif
2119  poly pp=nc_mm_Mult_pp(m,p,r);
2120  assume(pp!=NULL);
2121 
2122  p_Delete(&m, r);
2123  number n=pGetCoeff(pp);
2124  number nn;
2125  if (!n_IsMOne(n, r->cf))
2126  {
2127  nn=n_InpNeg(n_Invers(n, r->cf), r->cf);
2128  n =n_Mult(nn,pGetCoeff(b), r->cf);
2129  n_Delete(&nn, r->cf);
2130  pp=p_Mult_nn(pp,n,r);
2131  n_Delete(&n, r->cf);
2132  }
2133  else
2134  {
2135  pp=p_Mult_nn(pp,p_GetCoeff(b, r),r);
2136  }
2137  b=p_Add_q(b,pp,r);
2138 }
2139 
2140 
2141 inline void nc_PolyPolyRedNew(poly &b, poly p, number *c, const ring r)
2142  // reduces b with p, do not delete both
2143 {
2144 #ifdef PDEBUG
2145  p_Test(b, r);
2146  p_Test(p, r);
2147 #endif
2148 
2149 #if MYTEST
2150  PrintS("nc_PolyPolyRedNew(");
2151  p_Write0(b, r);
2152  PrintS(", ");
2153  p_Write0(p, r);
2154  PrintS(", *c): ");
2155 #endif
2156 
2157  // b will not by multiplied by any constant in this impl.
2158  // ==> *c=1
2159  if (c!=NULL) *c=n_Init(1, r->cf);
2160 
2161  poly pp = NULL;
2162 
2163  // there is a problem when p is a square(=>0!)
2164 
2165  while((b != NULL) && (pp == NULL))
2166  {
2167 
2168 // poly pLmB = p_Head(b, r);
2169  poly m = p_One(r);
2170  p_ExpVectorDiff(m, b, p, r);
2171 // pDelete(&pLmB);
2172  //pSetm(m);
2173 
2174 #ifdef PDEBUG
2175  p_Test(m, r);
2176  p_Test(b, r);
2177 #endif
2178 
2179  pp = nc_mm_Mult_pp(m, p, r);
2180 
2181 #if MYTEST
2182  PrintS("\n{b': ");
2183  p_Write0(b, r);
2184  PrintS(", m: ");
2185  p_Write0(m, r);
2186  PrintS(", pp: ");
2187  p_Write0(pp, r);
2188  PrintS(" }\n");
2189 #endif
2190 
2191  p_Delete(&m, r); // one m for all tries!
2192 
2193 // assume( pp != NULL );
2194 
2195  if( pp == NULL )
2196  {
2197  b = p_LmDeleteAndNext(b, r);
2198 
2199  if( !p_DivisibleBy(p, b, r) )
2200  return;
2201 
2202  }
2203  }
2204 
2205 #if MYTEST
2206  PrintS("{b': ");
2207  p_Write0(b, r);
2208  PrintS(", pp: ");
2209  p_Write0(pp, r);
2210  PrintS(" }\n");
2211 #endif
2212 
2213 
2214  if(b == NULL) return;
2215 
2216 
2217  assume(pp != NULL);
2218 
2219  const number n = pGetCoeff(pp); // no new copy
2220 
2221  number nn;
2222 
2223  if (!n_IsMOne(n, r->cf)) // TODO: as above.
2224  {
2225  nn=n_InpNeg(n_Invers(n, r->cf), r->cf);
2226  number t = n_Mult(nn, pGetCoeff(b), r->cf);
2227  n_Delete(&nn, r->cf);
2228  pp=p_Mult_nn(pp, t, r);
2229  n_Delete(&t, r->cf);
2230  }
2231  else
2232  {
2233  pp=p_Mult_nn(pp, pGetCoeff(b), r);
2234  }
2235 
2236 
2237  b=p_Add_q(b,pp,r);
2238 
2239 }
2240 
2241 void nc_PolyPolyRed(poly &b, poly p, number *c, const ring r)
2242 {
2243 #if 0
2244  nc_PolyPolyRedOld(b, p, c, r);
2245 #else
2246  nc_PolyPolyRedNew(b, p, c, r);
2247 #endif
2248 }
2249 
2250 
2251 poly nc_mm_Bracket_nn(poly m1, poly m2, const ring r);
2252 
2253 /// returns [p,q], destroys p
2254 poly nc_p_Bracket_qq(poly p, const poly q, const ring r)
2255 {
2256  assume(p != NULL && q!= NULL);
2257 
2258  if (!rIsPluralRing(r)) return(NULL);
2259  if (p_ComparePolys(p,q, r)) return(NULL);
2260  /* Components !? */
2261  poly Q=NULL;
2262  number coef=NULL;
2263  poly pres=NULL;
2264  int UseBuckets=1;
2265  if (((pLength(p)< MIN_LENGTH_BUCKET/2) && (pLength(q)< MIN_LENGTH_BUCKET/2))
2267  UseBuckets=0;
2268 
2269 
2270  CPolynomialSummator sum(r, UseBuckets == 0);
2271 
2272  while (p!=NULL)
2273  {
2274  Q=q;
2275  while(Q!=NULL)
2276  {
2277  pres=nc_mm_Bracket_nn(p,Q, r); /* since no coeffs are taken into account there */
2278  if (pres!=NULL)
2279  {
2280  coef = n_Mult(pGetCoeff(p),pGetCoeff(Q), r->cf);
2281  pres = p_Mult_nn(pres,coef,r);
2282 
2283  sum += pres;
2284  n_Delete(&coef, r->cf);
2285  }
2286  pIter(Q);
2287  }
2288  p=p_LmDeleteAndNext(p, r);
2289  }
2290  return(sum);
2291 }
2292 
2293 /// returns [m1,m2] for two monoms, destroys nothing
2294 /// without coeffs
2295 poly nc_mm_Bracket_nn(poly m1, poly m2, const ring r)
2296 {
2297  if (p_LmIsConstant(m1, r) || p_LmIsConstant(m1, r)) return(NULL);
2298  if (p_LmCmp(m1,m2, r)==0) return(NULL);
2299  int rN=r->N;
2300  int *M1=(int *)omAlloc0((rN+1)*sizeof(int));
2301  int *M2=(int *)omAlloc0((rN+1)*sizeof(int));
2302  int *aPREFIX=(int *)omAlloc0((rN+1)*sizeof(int));
2303  int *aSUFFIX=(int *)omAlloc0((rN+1)*sizeof(int));
2304  p_GetExpV(m1,M1, r);
2305  p_GetExpV(m2,M2, r);
2306  poly res=NULL;
2307  poly ares=NULL;
2308  poly bres=NULL;
2309  poly prefix=NULL;
2310  poly suffix=NULL;
2311  int nMin,nMax;
2312  number nTmp=NULL;
2313  int i,j,k;
2314  for (i=1;i<=rN;i++)
2315  {
2316  if (M2[i]!=0)
2317  {
2318  ares=NULL;
2319  for (j=1;j<=rN;j++)
2320  {
2321  if (M1[j]!=0)
2322  {
2323  bres=NULL;
2324  /* compute [ x_j^M1[j],x_i^M2[i] ] */
2325  if (i<j) {nMax=j; nMin=i;} else {nMax=i; nMin=j;}
2326  if ( (i==j) || ((MATELEM(r->GetNC()->COM,nMin,nMax)!=NULL) && n_IsOne(pGetCoeff(MATELEM(r->GetNC()->C,nMin,nMax)), r->cf) )) /* not (the same exp. or commuting exps)*/
2327  { bres=NULL; }
2328  else
2329  {
2330  if (i<j) { bres=gnc_uu_Mult_ww(j,M1[j],i,M2[i], r); }
2331  else bres=gnc_uu_Mult_ww(i,M2[i],j,M1[j], r);
2332  if (n_IsOne(pGetCoeff(bres), r->cf))
2333  {
2334  bres=p_LmDeleteAndNext(bres, r);
2335  }
2336  else
2337  {
2338  nTmp=n_Sub(pGetCoeff(bres),n_Init(1, r->cf), r->cf);
2339  p_SetCoeff(bres,nTmp, r); /* only lc ! */
2340  }
2341 #ifdef PDEBUG
2342  p_Test(bres, r);
2343 #endif
2344  if (i>j) bres=p_Neg(bres, r);
2345  }
2346  if (bres!=NULL)
2347  {
2348  /* now mult (prefix, bres, suffix) */
2349  memcpy(aSUFFIX, M1,(rN+1)*sizeof(int));
2350  memcpy(aPREFIX, M1,(rN+1)*sizeof(int));
2351  for (k=1;k<=j;k++) aSUFFIX[k]=0;
2352  for (k=j;k<=rN;k++) aPREFIX[k]=0;
2353  aSUFFIX[0]=0;
2354  aPREFIX[0]=0;
2355  prefix=p_One(r);
2356  suffix=p_One(r);
2357  p_SetExpV(prefix,aPREFIX, r);
2358  p_Setm(prefix, r);
2359  p_SetExpV(suffix,aSUFFIX, r);
2360  p_Setm(suffix, r);
2361  if (!p_LmIsConstant(prefix, r)) bres = gnc_mm_Mult_p(prefix, bres, r);
2362  if (!p_LmIsConstant(suffix, r)) bres = gnc_p_Mult_mm(bres, suffix, r);
2363  ares=p_Add_q(ares, bres, r);
2364  /* What to give free? */
2365  /* Do we have to free aPREFIX/aSUFFIX? it seems so */
2366  p_Delete(&prefix, r);
2367  p_Delete(&suffix, r);
2368  }
2369  }
2370  }
2371  if (ares!=NULL)
2372  {
2373  /* now mult (prefix, bres, suffix) */
2374  memcpy(aSUFFIX, M2,(rN+1)*sizeof(int));
2375  memcpy(aPREFIX, M2,(rN+1)*sizeof(int));
2376  for (k=1;k<=i;k++) aSUFFIX[k]=0;
2377  for (k=i;k<=rN;k++) aPREFIX[k]=0;
2378  aSUFFIX[0]=0;
2379  aPREFIX[0]=0;
2380  prefix=p_One(r);
2381  suffix=p_One(r);
2382  p_SetExpV(prefix,aPREFIX, r);
2383  p_Setm(prefix, r);
2384  p_SetExpV(suffix,aSUFFIX, r);
2385  p_Setm(suffix, r);
2386  bres=ares;
2387  if (!p_LmIsConstant(prefix, r)) bres = gnc_mm_Mult_p(prefix, bres, r);
2388  if (!p_LmIsConstant(suffix, r)) bres = gnc_p_Mult_mm(bres, suffix, r);
2389  res=p_Add_q(res, bres, r);
2390  p_Delete(&prefix, r);
2391  p_Delete(&suffix, r);
2392  }
2393  }
2394  }
2395  freeT(M1, rN);
2396  freeT(M2, rN);
2397  freeT(aPREFIX, rN);
2398  freeT(aSUFFIX, rN);
2399 #ifdef PDEBUG
2400  p_Test(res, r);
2401 #endif
2402  return(res);
2403 }
2404 /// returns matrix with the info on noncomm multiplication
2405 matrix nc_PrintMat(int a, int b, ring r, int metric)
2406 {
2407 
2408  if ( (a==b) || !rIsPluralRing(r) ) return(NULL);
2409  int i;
2410  int j;
2411  if (a>b) {j=b; i=a;}
2412  else {j=a; i=b;}
2413  /* i<j */
2414  int rN=r->N;
2415  int size=r->GetNC()->MTsize[UPMATELEM(i,j,rN)];
2416  matrix M = r->GetNC()->MT[UPMATELEM(i,j,rN)];
2417  /* return(M); */
2418 /*
2419  int sizeofres;
2420  if (metric==0)
2421  {
2422  sizeofres=sizeof(int);
2423  }
2424  if (metric==1)
2425  {
2426  sizeofres=sizeof(number);
2427  }
2428 */
2430  int s;
2431  int t;
2432  int length;
2433  long totdeg;
2434  poly p;
2435  for(s=1;s<=size;s++)
2436  {
2437  for(t=1;t<=size;t++)
2438  {
2439  p=MATELEM(M,s,t);
2440  if (p==NULL)
2441  {
2442  MATELEM(res,s,t)=0;
2443  }
2444  else
2445  {
2446  length = pLength(p);
2447  if (metric==0) /* length */
2448  {
2449  MATELEM(res,s,t)= p_ISet(length,r);
2450  }
2451  else if (metric==1) /* sum of deg divided by the length */
2452  {
2453  totdeg=0;
2454  while (p!=NULL)
2455  {
2456  totdeg=totdeg+p_Deg(p,r);
2457  pIter(p);
2458  }
2459  number ntd = n_Init(totdeg, r->cf);
2460  number nln = n_Init(length, r->cf);
2461  number nres= n_Div(ntd,nln, r->cf);
2462  n_Delete(&ntd, r->cf);
2463  n_Delete(&nln, r->cf);
2464  MATELEM(res,s,t)=p_NSet(nres,r);
2465  }
2466  }
2467  }
2468  }
2469  return(res);
2470 }
2471 
2472 inline void nc_CleanUp(nc_struct* p)
2473 {
2474  assume(p != NULL);
2475  omFreeSize((ADDRESS)p,sizeof(nc_struct));
2476 }
2477 
2478 inline void nc_CleanUp(ring r)
2479 {
2480  /* small CleanUp of r->GetNC() */
2481  assume(r != NULL);
2482  nc_CleanUp(r->GetNC());
2483  r->GetNC() = NULL;
2484 }
2485 
2486 void nc_rKill(ring r)
2487 // kills the nc extension of ring r
2488 {
2489  if( r->GetNC()->GetGlobalMultiplier() != NULL )
2490  {
2491  delete r->GetNC()->GetGlobalMultiplier();
2492  r->GetNC()->GetGlobalMultiplier() = NULL;
2493  }
2494 
2495  if( r->GetNC()->GetFormulaPowerMultiplier() != NULL )
2496  {
2497  delete r->GetNC()->GetFormulaPowerMultiplier();
2498  r->GetNC()->GetFormulaPowerMultiplier() = NULL;
2499  }
2500 
2501 
2502  int i,j;
2503  int rN=r->N;
2504  if ( rN > 1 )
2505  {
2506  for(i=1;i<rN;i++)
2507  {
2508  for(j=i+1;j<=rN;j++)
2509  {
2510  id_Delete((ideal *)&(r->GetNC()->MT[UPMATELEM(i,j,rN)]),r);
2511  }
2512  }
2513  omFreeSize((ADDRESS)r->GetNC()->MT,rN*(rN-1)/2*sizeof(matrix));
2514  omFreeSize((ADDRESS)r->GetNC()->MTsize,rN*(rN-1)/2*sizeof(int));
2515  id_Delete((ideal *)&(r->GetNC()->COM),r);
2516  }
2517  id_Delete((ideal *)&(r->GetNC()->C),r);
2518  id_Delete((ideal *)&(r->GetNC()->D),r);
2519 
2520  if( rIsSCA(r) && (r->GetNC()->SCAQuotient() != NULL) )
2521  {
2522  id_Delete(&r->GetNC()->SCAQuotient(), r); // Custom SCA destructor!!!
2523  }
2524 
2525 
2526  nc_CleanUp(r);
2527 }
2528 
2529 
2530 ////////////////////////////////////////////////////////////////////////////////////////////////
2531 
2532 // deprecated:
2533 /* for use in getting the mult. matrix elements*/
2534 /* ring r must be a currRing! */
2535 /* for consistency, copies a poly from the comm. r->GetNC()->basering */
2536 /* to its image in NC ring */
2537 poly nc_p_CopyGet(poly a, const ring r)
2538 {
2539 #ifndef PDEBUG
2540  p_Test(a, r);
2541 #endif
2542 
2543 // if (r != currRing)
2544 // {
2545 //#ifdef PDEBUF
2546 // WerrorS("nc_p_CopyGet call not in currRing");
2547 //#endif
2548 // return(NULL);
2549 // }
2550  return(p_Copy(a,r));
2551 }
2552 
2553 // deprecated:
2554 /* for use in defining the mult. matrix elements*/
2555 /* ring r must be a currRing! */
2556 /* for consistency, puts a polynomial from the NC ring */
2557 /* to its presentation in the comm. r->GetNC()->basering */
2558 poly nc_p_CopyPut(poly a, const ring r)
2559 {
2560 #ifndef PDEBUG
2561  p_Test(a, r);
2562 #endif
2563 
2564 // if (r != currRing)
2565 // {
2566 //#ifdef PDEBUF
2567 // WerrorS("nc_p_CopyGet call not in currRing");
2568 //#endif
2569 // return(NULL);
2570 // }
2571 
2572  return(p_Copy(a,r));
2573 }
2574 
2575 /* returns TRUE if there were errors */
2576 /* checks whether product of vars from PolyVar defines */
2577 /* an admissible subalgebra of r */
2578 /* r is indeed currRing and assumed to be noncomm. */
2580 {
2581 // ring save = currRing;
2582 // int WeChangeRing = 0;
2583 // if (currRing != r)
2584 // rChangeCurrRing(r);
2585 // WeChangeRing = 1;
2586 // }
2587  int rN=r->N;
2588  int *ExpVar=(int*)omAlloc0((rN+1)*sizeof(int));
2589  int *ExpTmp=(int*)omAlloc0((rN+1)*sizeof(int));
2590  p_GetExpV(PolyVar, ExpVar, r);
2591  int i; int j; int k;
2592  poly test=NULL;
2593  int OK=1;
2594  for (i=1; i<rN; i++)
2595  {
2596  if (ExpVar[i]==0) /* i.e. not in PolyVar */
2597  {
2598  for (j=i+1; j<=rN; j++)
2599  {
2600  if (ExpVar[j]==0)
2601  {
2602  test = MATELEM(r->GetNC()->D,i,j);
2603  while (test!=NULL)
2604  {
2605  p_GetExpV(test, ExpTmp, r);
2606  OK=1;
2607  for (k=1;k<=rN;k++)
2608  {
2609  if (ExpTmp[k]!=0)
2610  {
2611  if (ExpVar[k]!=0) OK=0;
2612  }
2613  }
2614  if (!OK)
2615  {
2616 // if ( WeChangeRing )
2617 // rChangeCurrRing(save);
2618  return(TRUE);
2619  }
2620  pIter(test);
2621  }
2622  }
2623  }
2624  }
2625  }
2626  freeT(ExpVar,rN);
2627  freeT(ExpTmp,rN);
2628 // if ( WeChangeRing )
2629 // rChangeCurrRing(save);
2630  return(FALSE);
2631 }
2632 
2633 
2634 /* returns TRUE if there were errors */
2635 /* checks whether the current ordering */
2636 /* is admissible for r and D == r->GetNC()->D */
2637 /* to be executed in a currRing */
2639 {
2640  /* analyze D: an upper triangular matrix of polys */
2641  /* check the ordering condition for D */
2642 // ring save = currRing;
2643 // int WeChangeRing = 0;
2644 // if (r != currRing)
2645 // {
2646 // rChangeCurrRing(r);
2647 // WeChangeRing = 1;
2648 // }
2649  poly p,q;
2650  int i,j;
2651  int report = 0;
2652  for(i=1; i<r->N; i++)
2653  {
2654  for(j=i+1; j<=r->N; j++)
2655  {
2656  p = nc_p_CopyGet(MATELEM(D,i,j),r);
2657  if ( p != NULL)
2658  {
2659  q = p_One(r);
2660  p_SetExp(q,i,1,r);
2661  p_SetExp(q,j,1,r);
2662  p_Setm(q,r);
2663  if (p_LmCmp(q,p,r) != 1) /* i.e. lm(p)==xy < lm(q)==D_ij */
2664  {
2665  Werror("Bad ordering at %d,%d\n",i,j);
2666 #if 0 /*Singularg should not differ from Singular except in error case*/
2667  p_Write(p,r);
2668  p_Write(q,r);
2669 #endif
2670  report = 1;
2671  }
2672  p_Delete(&q,r);
2673  p_Delete(&p,r);
2674  p = NULL;
2675  }
2676  }
2677  }
2678 // if ( WeChangeRing )
2679 // rChangeCurrRing(save);
2680  return(report);
2681 }
2682 
2683 
2684 
2685 BOOLEAN gnc_InitMultiplication(ring r, bool bSetupQuotient = false); // just for a moment
2686 
2687 /// returns TRUE if there were errors
2688 /// analyze inputs, check them for consistency
2689 /// detects nc_type, DO NOT initialize multiplication but call for it at the end
2690 /// checks the ordering condition and evtl. NDC
2691 /// NOTE: all the data belong to the curr,
2692 /// we change r which may be the same ring, and must have the same representation!
2694  poly CCN, poly DDN,
2695  ring r,
2696  bool bSetupQuotient, bool bCopyInput, bool bBeQuiet,
2697  ring curr, bool dummy_ring /*=false*/)
2698 {
2699  assume( r != NULL );
2700  assume( curr != NULL );
2701 
2702  if( !bSetupQuotient)
2703  assume( (r->qideal == NULL) ); // The basering must NOT be a qring!??
2704 
2705  assume( rSamePolyRep(r, curr) || bCopyInput ); // wrong assumption?
2706 
2707 
2708  if( r->N == 1 ) // clearly commutative!!!
2709  {
2710  assume(
2711  ( (CCC != NULL) && (MATCOLS(CCC) == 1) && (MATROWS(CCC) == 1) && (MATELEM(CCC,1,1) == NULL) ) ||
2712  ( (CCN == NULL) )
2713  );
2714 
2715  assume(
2716  ( (DDD != NULL) && (MATCOLS(DDD) == 1) && (MATROWS(DDD) == 1) && (MATELEM(DDD,1,1) == NULL) ) ||
2717  ( (DDN == NULL) )
2718  );
2719  if(!dummy_ring)
2720  {
2721  WarnS("commutative ring with 1 variable");
2722  return FALSE;
2723  }
2724  }
2725 
2726  // there must be:
2727  assume( (CCC != NULL) != (CCN != NULL) ); // exactly one data about coeffs (C).
2728  assume( !((DDD != NULL) && (DDN != NULL)) ); // at most one data about tails (D).
2729 
2730 // ring save = currRing;
2731 // if( save != curr )
2732 // rChangeCurrRing(curr);
2733 
2734 
2735 #if OUTPUT
2736  if( CCC != NULL )
2737  {
2738  PrintS("nc_CallPlural(), Input data, CCC: \n");
2739  iiWriteMatrix(CCC, "C", 2, curr, 4);
2740  }
2741  if( DDD != NULL )
2742  {
2743  PrintS("nc_CallPlural(), Input data, DDD: \n");
2744  iiWriteMatrix(DDD, "D", 2, curr, 4);
2745  }
2746 #endif
2747 
2748 
2749 #ifndef SING_NDEBUG
2750  if (CCC!=NULL) id_Test((ideal)CCC, curr);
2751  if (DDD!=NULL) id_Test((ideal)DDD, curr);
2752  p_Test(CCN, curr);
2753  p_Test(DDN, curr);
2754 #endif
2755 
2756  if( (!bBeQuiet) && (r->GetNC() != NULL) )
2757  WarnS("going to redefine the algebra structure");
2758 
2759 // if( currRing != r )
2760 // rChangeCurrRing(r);
2761 
2762  matrix CC = NULL;
2763  poly CN = NULL;
2764  matrix C; bool bCnew = false;
2765 
2766  matrix DD = NULL;
2767  poly DN = NULL;
2768  matrix D; bool bDnew = false;
2769 
2770  number nN, pN, qN;
2771 
2772  bool IsSkewConstant = false, tmpIsSkewConstant;
2773  int i, j;
2774 
2775  nc_type nctype = nc_undef;
2776 
2777  //////////////////////////////////////////////////////////////////
2778  // check the correctness of arguments, without any real chagnes!!!
2779 
2780 
2781 
2782  // check C
2783  if ((CCC != NULL) && ( (MATCOLS(CCC)==1) || MATROWS(CCC)==1 ) )
2784  {
2785  CN = MATELEM(CCC,1,1);
2786  }
2787  else
2788  {
2789  if ((CCC != NULL) && ( (MATCOLS(CCC)!=r->N) || (MATROWS(CCC)!=r->N) ))
2790  {
2791  Werror("Square %d x %d matrix expected", r->N, r->N);
2792 
2793 // if( currRing != save )
2794 // rChangeCurrRing(save);
2795  return TRUE;
2796  }
2797  }
2798  if (( CCC != NULL) && (CC == NULL)) CC = CCC; // mp_Copy(CCC, ?); // bug!?
2799  if (( CCN != NULL) && (CN == NULL)) CN = CCN;
2800 
2801  // check D
2802  if ((DDD != NULL) && ( (MATCOLS(DDD)==1) || MATROWS(DDD)==1 ) )
2803  {
2804  DN = MATELEM(DDD,1,1);
2805  }
2806  else
2807  {
2808  if ((DDD != NULL) && ( (MATCOLS(DDD)!=r->N) || (MATROWS(DDD)!=r->N) ))
2809  {
2810  Werror("Square %d x %d matrix expected",r->N,r->N);
2811 
2812 // if( currRing != save )
2813 // rChangeCurrRing(save);
2814  return TRUE;
2815  }
2816  }
2817 
2818  if (( DDD != NULL) && (DD == NULL)) DD = DDD; // mp_Copy(DDD, ?); // ???
2819  if (( DDN != NULL) && (DN == NULL)) DN = DDN;
2820 
2821  // further checks and some analysis:
2822  // all data in 'curr'!
2823  if (CN != NULL) /* create matrix C = CN * Id */
2824  {
2825  if (!p_IsConstant(CN,curr))
2826  {
2827  WerrorS("Incorrect input : non-constants are not allowed as coefficients (first argument)");
2828  return TRUE;
2829  }
2830  assume(p_IsConstant(CN,curr));
2831 
2832  nN = pGetCoeff(CN);
2833  if (n_IsZero(nN, curr->cf))
2834  {
2835  WerrorS("Incorrect input : zero coefficients are not allowed");
2836 
2837 // if( currRing != save )
2838 // rChangeCurrRing(save);
2839  return TRUE;
2840  }
2841 
2842  if (n_IsOne(nN, curr->cf))
2843  nctype = nc_lie;
2844  else
2845  nctype = nc_general;
2846 
2847  IsSkewConstant = true;
2848 
2849  C = mpNew(r->N,r->N); // ring independent!
2850  bCnew = true;
2851 
2852  for(i=1; i<r->N; i++)
2853  for(j=i+1; j<=r->N; j++)
2854  MATELEM(C,i,j) = prCopyR_NoSort(CN, curr, r); // nc_p_CopyPut(CN, r); // copy CN from curr into r
2855 
2856 #ifndef SING_NDEBUG
2857  id_Test((ideal)C, r);
2858 #endif
2859 
2860  } else
2861  if ( (CN == NULL) && (CC != NULL) ) /* copy matrix C */
2862  {
2863  /* analyze C */
2864 
2865  pN = NULL; /* check the consistency later */
2866 
2867  if( r->N > 1 )
2868  if ( MATELEM(CC,1,2) != NULL )
2869  pN = p_GetCoeff(MATELEM(CC,1,2), curr);
2870 
2871  tmpIsSkewConstant = true;
2872 
2873  for(i=1; i<r->N; i++)
2874  for(j=i+1; j<=r->N; j++)
2875  {
2876  if (MATELEM(CC,i,j) == NULL)
2877  qN = NULL;
2878  else
2879  {
2880  if (!p_IsConstant(MATELEM(CC,i,j),curr))
2881  {
2882  Werror("Incorrect input : non-constants are not allowed as coefficients (first argument at [%d, %d])", i, j);
2883  return TRUE;
2884  }
2885  assume(p_IsConstant(MATELEM(CC,i,j),curr));
2886  qN = p_GetCoeff(MATELEM(CC,i,j),curr);
2887  }
2888 
2889 
2890  if ( qN == NULL ) /* check the consistency: Cij!=0 */
2891  // find also illegal pN
2892  {
2893  WerrorS("Incorrect input : matrix of coefficients contains zeros in the upper triangle");
2894 
2895 // if( currRing != save )
2896 // rChangeCurrRing(save);
2897  return TRUE;
2898  }
2899 
2900  if (!n_Equal(pN, qN, curr->cf)) tmpIsSkewConstant = false;
2901  }
2902 
2903  if( bCopyInput )
2904  {
2905  C = mp_Copy(CC, curr, r); // Copy C into r!!!???
2906 #ifndef SING_NDEBUG
2907  id_Test((ideal)C, r);
2908 #endif
2909  bCnew = true;
2910  }
2911  else
2912  C = CC;
2913 
2914  IsSkewConstant = tmpIsSkewConstant;
2915 
2916  if ( tmpIsSkewConstant && n_IsOne(pN, curr->cf) )
2917  nctype = nc_lie;
2918  else
2919  nctype = nc_general;
2920  }
2921 
2922  /* initialition of the matrix D */
2923  if ( DD == NULL ) /* we treat DN only (it could also be NULL) */
2924  {
2925  D = mpNew(r->N,r->N); bDnew = true;
2926 
2927  if (DN == NULL)
2928  {
2929  if ( (nctype == nc_lie) || (nctype == nc_undef) )
2930  nctype = nc_comm; /* it was nc_skew earlier */
2931  else /* nc_general, nc_skew */
2932  nctype = nc_skew;
2933  }
2934  else /* DN != NULL */
2935  for(i=1; i<r->N; i++)
2936  for(j=i+1; j<=r->N; j++)
2937  MATELEM(D,i,j) = prCopyR_NoSort(DN, curr, r); // project DN into r->GetNC()->basering!
2938 #ifndef SING_NDEBUG
2939  id_Test((ideal)D, r);
2940 #endif
2941  }
2942  else /* DD != NULL */
2943  {
2944  bool b = true; // DD == null ?
2945 
2946  for(int i = 1; (i < r->N) && b; i++)
2947  for(int j = i+1; (j <= r->N) && b; j++)
2948  if (MATELEM(DD, i, j) != NULL)
2949  {
2950  b = false;
2951  break;
2952  }
2953 
2954  if (b) // D == NULL!!!
2955  {
2956  if ( (nctype == nc_lie) || (nctype == nc_undef) )
2957  nctype = nc_comm; /* it was nc_skew earlier */
2958  else /* nc_general, nc_skew */
2959  nctype = nc_skew;
2960  }
2961 
2962  if( bCopyInput )
2963  {
2964  D = mp_Copy(DD, curr, r); // Copy DD into r!!!
2965 #ifndef SING_NDEBUG
2966  id_Test((ideal)D, r);
2967 #endif
2968  bDnew = true;
2969  }
2970  else
2971  D = DD;
2972  }
2973 
2974  assume( C != NULL );
2975  assume( D != NULL );
2976 
2977 #if OUTPUT
2978  PrintS("nc_CallPlural(), Computed data, C: \n");
2979  iiWriteMatrix(C, "C", 2, r, 4);
2980 
2981  PrintS("nc_CallPlural(), Computed data, D: \n");
2982  iiWriteMatrix(D, "D", 2, r, 4);
2983 
2984  Print("\nTemporary: type = %d, IsSkewConstant = %d\n", nctype, IsSkewConstant);
2985 #endif
2986 
2987 
2988  // check the ordering condition for D (both matrix and poly cases):
2989  if ( gnc_CheckOrdCondition(D, r) )
2990  {
2991  if( bCnew ) mp_Delete( &C, r );
2992  if( bDnew ) mp_Delete( &D, r );
2993 
2994  WerrorS("Matrix of polynomials violates the ordering condition");
2995 
2996 // if( currRing != save )
2997 // rChangeCurrRing(save);
2998  return TRUE;
2999  }
3000 
3001  // okay now we are ready for this!!!
3002 
3003  // create new non-commutative structure
3004  nc_struct *nc_new = (nc_struct *)omAlloc0(sizeof(nc_struct));
3005 
3006  ncRingType(nc_new, nctype);
3007 
3008  nc_new->C = C; // if C and D were given by matrices at the beginning they are in r
3009  nc_new->D = D; // otherwise they should be in r->GetNC()->basering(polynomial * Id_{N})
3010 
3011  nc_new->IsSkewConstant = (IsSkewConstant?1:0);
3012 
3013  // Setup new NC structure!!!
3014  if (r->GetNC() != NULL)
3015  {
3016 #ifndef SING_NDEBUG
3017  WarnS("Changing the NC-structure of an existing NC-ring!!!");
3018 #endif
3019  nc_rKill(r);
3020  }
3021 
3022  r->GetNC() = nc_new;
3023 
3024  r->ext_ref=NULL;
3025 
3026 // if( currRing != save )
3027 // rChangeCurrRing(save);
3028 
3029  return gnc_InitMultiplication(r, bSetupQuotient);
3030 }
3031 
3032 //////////////////////////////////////////////////////////////////////////////
3033 
3034 bool nc_rCopy(ring res, const ring r, bool bSetupQuotient)
3035 {
3036  if (nc_CallPlural(r->GetNC()->C, r->GetNC()->D, NULL, NULL, res, bSetupQuotient, true, true, r))
3037  {
3038  WarnS("Error occurred while coping/setuping the NC structure!"); // No reaction!???
3039  return true; // error
3040  }
3041 
3042  return false;
3043 }
3044 
3045 //////////////////////////////////////////////////////////////////////////////
3046 BOOLEAN gnc_InitMultiplication(ring r, bool bSetupQuotient)
3047 {
3048  /* returns TRUE if there were errors */
3049  /* initialize the multiplication: */
3050  /* r->GetNC()->MTsize, r->GetNC()->MT, r->GetNC()->COM, */
3051  /* and r->GetNC()->IsSkewConstant for the skew case */
3052  if (rVar(r)==1)
3053  {
3054  ncRingType(r, nc_comm);
3055  r->GetNC()->IsSkewConstant=1;
3056  return FALSE;
3057  }
3058 
3059 // ring save = currRing;
3060 // int WeChangeRing = 0;
3061 
3062 // if (currRing!=r)
3063 // {
3064 // rChangeCurrRing(r);
3065 // WeChangeRing = 1;
3066 // }
3067 // assume( (currRing == r)
3068 // && (currRing->GetNC()!=NULL) ); // otherwise we cannot work with all these matrices!
3069 
3070  int i,j;
3071  r->GetNC()->MT = (matrix *)omAlloc0((r->N*(r->N-1))/2*sizeof(matrix));
3072  r->GetNC()->MTsize = (int *)omAlloc0((r->N*(r->N-1))/2*sizeof(int));
3073  id_Test((ideal)r->GetNC()->C, r);
3074  matrix COM = mp_Copy(r->GetNC()->C, r);
3075  poly p,q;
3076  short DefMTsize=7;
3077  int IsNonComm=0;
3078 // bool tmpIsSkewConstant = false;
3079 
3080  for(i=1; i<r->N; i++)
3081  {
3082  for(j=i+1; j<=r->N; j++)
3083  {
3084  if ( MATELEM(r->GetNC()->D,i,j) == NULL ) /* quasicommutative case */
3085  {
3086  /* 1x1 mult.matrix */
3087  r->GetNC()->MTsize[UPMATELEM(i,j,r->N)] = 1;
3088  r->GetNC()->MT[UPMATELEM(i,j,r->N)] = mpNew(1,1);
3089  }
3090  else /* pure noncommutative case */
3091  {
3092  /* TODO check the special multiplication properties */
3093  IsNonComm = 1;
3094  p_Delete(&(MATELEM(COM,i,j)),r);
3095  //MATELEM(COM,i,j) = NULL; // done by p_Delete
3096  r->GetNC()->MTsize[UPMATELEM(i,j,r->N)] = DefMTsize; /* default sizes */
3097  r->GetNC()->MT[UPMATELEM(i,j,r->N)] = mpNew(DefMTsize, DefMTsize);
3098  }
3099  /* set MT[i,j,1,1] to c_i_j*x_i*x_j + D_i_j */
3100  p = p_One(r);
3101  if (MATELEM(r->GetNC()->C,i,j)!=NULL)
3102  p_SetCoeff(p,n_Copy(pGetCoeff(MATELEM(r->GetNC()->C,i,j)),r->cf),r);
3103  p_SetExp(p,i,1,r);
3104  p_SetExp(p,j,1,r);
3105  p_Setm(p,r);
3106  p_Test(MATELEM(r->GetNC()->D,i,j),r);
3107  q = nc_p_CopyGet(MATELEM(r->GetNC()->D,i,j),r);
3108  p = p_Add_q(p,q,r);
3109  MATELEM(r->GetNC()->MT[UPMATELEM(i,j,r->N)],1,1) = nc_p_CopyPut(p,r);
3110  p_Delete(&p,r);
3111  // p = NULL;// done by p_Delete
3112  }
3113  }
3114  if (ncRingType(r)==nc_undef)
3115  {
3116  if (IsNonComm==1)
3117  {
3118  // assume(pN!=NULL);
3119  // if ((tmpIsSkewConstant==1) && (nIsOne(pGetCoeff(pN)))) r->GetNC()->type=nc_lie;
3120  // else r->GetNC()->type=nc_general;
3121  }
3122  if (IsNonComm==0)
3123  {
3124  ncRingType(r, nc_skew); // TODO: check whether it is commutative
3125  r->GetNC()->IsSkewConstant = 0; // true; //tmpIsSkewConstant; // BUG???
3126  } else
3127  assume( FALSE );
3128  }
3129  r->GetNC()->COM=COM;
3130 
3131  nc_p_ProcsSet(r, r->p_Procs);
3132 
3133  if(bSetupQuotient) // Test me!!!
3134  nc_SetupQuotient(r, NULL, false); // no copy!
3135 
3136 
3137 // if (save != currRing)
3138 // rChangeCurrRing(save);
3139 
3140  return FALSE;
3141 }
3142 
3143 
3144 // set pProcs for r and global variable p_Procs as for general non-commutative algebras.
3145 static inline
3146 void gnc_p_ProcsSet(ring rGR, p_Procs_s* p_Procs)
3147 {
3148  // "commutative"
3149  p_Procs->p_Mult_mm = rGR->p_Procs->p_Mult_mm = gnc_p_Mult_mm;
3150  p_Procs->pp_Mult_mm = rGR->p_Procs->pp_Mult_mm = gnc_pp_Mult_mm;
3151  p_Procs->p_Minus_mm_Mult_qq = rGR->p_Procs->p_Minus_mm_Mult_qq = nc_p_Minus_mm_Mult_qq;
3152 
3153  // non-commutaitve multiplication by monomial from the left
3154  rGR->GetNC()->p_Procs.mm_Mult_p = gnc_mm_Mult_p;
3155  rGR->GetNC()->p_Procs.mm_Mult_pp = gnc_mm_Mult_pp;
3156 
3157 #if 0
3158  // Previous Plural's implementation...
3159  rGR->GetNC()->p_Procs.SPoly = gnc_CreateSpolyOld;
3160  rGR->GetNC()->p_Procs.ReduceSPoly = gnc_ReduceSpolyOld;
3161 
3162  rGR->GetNC()->p_Procs.BucketPolyRed = gnc_kBucketPolyRedOld;
3163  rGR->GetNC()->p_Procs.BucketPolyRed_Z= gnc_kBucketPolyRed_ZOld;
3164 #else
3165  // A bit cleaned up and somewhat rewritten functions...
3166  rGR->GetNC()->p_Procs.SPoly = gnc_CreateSpolyNew;
3167  rGR->GetNC()->p_Procs.ReduceSPoly = gnc_ReduceSpolyNew;
3168 
3169  rGR->GetNC()->p_Procs.BucketPolyRed = gnc_kBucketPolyRedNew;
3170  rGR->GetNC()->p_Procs.BucketPolyRed_Z= gnc_kBucketPolyRed_ZNew;
3171 #endif
3172 
3173  // warning: ISO C++ forbids casting between pointer-to-function and pointer-to-object?
3174  if (rHasLocalOrMixedOrdering(rGR))
3175  rGR->GetNC()->p_Procs.GB = cast_A_to_vptr(gnc_gr_mora);
3176  else
3177  rGR->GetNC()->p_Procs.GB = cast_A_to_vptr(gnc_gr_bba);
3178 
3179 /////////// rGR->GetNC()->p_Procs.GB = gnc_gr_bba; // bba even for local case!
3180 // old /// r->GetNC()->GB() = gnc_gr_bba;
3181 // rGR->GetNC()->p_Procs.GlobalGB = gnc_gr_bba;
3182 // rGR->GetNC()->p_Procs.LocalGB = gnc_gr_mora;
3183 // const ring save = currRing; if( save != r ) rChangeCurrRing(r);
3184 // ideal res = gnc_gr_bba(F, Q, w, hilb, strat/*, r*/);
3185 // if( save != r ) rChangeCurrRing(save); return (res);
3186 
3187 
3188 #if 0
3189  // Old Stuff
3190  p_Procs->p_Mult_mm = gnc_p_Mult_mm;
3191  _p_procs->p_Mult_mm = gnc_p_Mult_mm;
3192 
3193  p_Procs->pp_Mult_mm = gnc_pp_Mult_mm;
3194  _p_procs->pp_Mult_mm = gnc_pp_Mult_mm;
3195 
3196  p_Procs->p_Minus_mm_Mult_qq = NULL; // gnc_p_Minus_mm_Mult_qq_ign;
3197  _p_procs->p_Minus_mm_Mult_qq= NULL; // gnc_p_Minus_mm_Mult_qq_ign;
3198 
3199  r->GetNC()->mmMultP() = gnc_mm_Mult_p;
3200  r->GetNC()->mmMultPP() = gnc_mm_Mult_pp;
3201 
3202  r->GetNC()->SPoly() = gnc_CreateSpoly;
3203  r->GetNC()->ReduceSPoly() = gnc_ReduceSpoly;
3204 
3205 #endif
3206 }
3207 
3208 
3209 // set pProcs table for rGR and global variable p_Procs
3210 void nc_p_ProcsSet(ring rGR, p_Procs_s* p_Procs)
3211 {
3212  assume(rIsPluralRing(rGR));
3213  assume(p_Procs!=NULL);
3214 
3215  gnc_p_ProcsSet(rGR, p_Procs);
3216 
3217  if(rIsSCA(rGR) && ncExtensions(SCAMASK) )
3218  {
3219  sca_p_ProcsSet(rGR, p_Procs);
3220  }
3221 
3222  if( ncExtensions(NOPLURALMASK) )
3224 
3225  if(!rIsSCA(rGR) && !ncExtensions(NOFORMULAMASK))
3227 
3228 }
3229 
3230 
3231 /// substitute the n-th variable by e in p
3232 /// destroy p
3233 /// e is not a constant
3234 poly nc_pSubst(poly p, int n, poly e, const ring r)
3235 {
3236  int rN = r->N;
3237  int *PRE = (int *)omAlloc0((rN+1)*sizeof(int));
3238  int *SUF = (int *)omAlloc0((rN+1)*sizeof(int));
3239  int i,pow;
3240  number C;
3241  poly suf,pre;
3242  poly res = NULL;
3243  poly out = NULL;
3244  while ( p!= NULL )
3245  {
3246  C = p_GetCoeff(p, r);
3247  p_GetExpV(p, PRE, r); /* faster splitting? */
3248  pow = PRE[n]; PRE[n]=0;
3249  res = NULL;
3250  if (pow!=0)
3251  {
3252  for (i=n+1; i<=rN; i++)
3253  {
3254  SUF[i] = PRE[i];
3255  PRE[i] = 0;
3256  }
3257  res = p_Power(p_Copy(e, r),pow, r);
3258  /* multiply with prefix */
3259  pre = p_One(r);
3260  p_SetExpV(pre,PRE, r);
3261  p_Setm(pre, r);
3262  res = nc_mm_Mult_p(pre,res, r);
3263  /* multiply with suffix */
3264  suf = p_One(r);
3265  p_SetExpV(suf,SUF, r);
3266  p_Setm(suf, r);
3267  res = p_Mult_mm(res,suf, r);
3268  res = p_Mult_nn(res,C, r);
3269  p_SetComp(res,PRE[0], r);
3270  }
3271  else /* pow==0 */
3272  {
3273  res = p_Head(p, r);
3274  }
3275  p = p_LmDeleteAndNext(p, r);
3276  out = p_Add_q(out,res, r);
3277  }
3278  freeT(PRE,rN);
3279  freeT(SUF,rN);
3280  return(out);
3281 }
3282 
3283 
3284 // creates a commutative nc extension; "converts" comm.ring to a Plural ring
3286 {
3287  if (rIsPluralRing(r)) return r;
3288 
3289  ring rr = rCopy(r);
3290 
3291  matrix C = mpNew(rr->N,rr->N); // ring-independent!?!
3292  matrix D = mpNew(rr->N,rr->N);
3293 
3294  for(int i=1; i<rr->N; i++)
3295  for(int j=i+1; j<=rr->N; j++)
3296  MATELEM(C,i,j) = p_One(rr);
3297 
3298  if (nc_CallPlural(C, D, NULL, NULL, rr, false, true, false, rr, TRUE)) // TODO: what about quotient ideal?
3299  WarnS("Error initializing multiplication!"); // No reaction!???
3300 
3301  return rr;
3302 }
3303 
3304  /* NOT USED ANYMORE: replaced by maFindPerm in ring.cc */
3305  /* for use with embeddings: currRing is a sum of smaller rings */
3306  /* and srcRing is one of such smaller rings */
3307  /* shift defines the position of a subring in srcRing */
3308  /* par_shift defines the position of a subfield in basefield of CurrRing */
3309 poly p_CopyEmbed(poly p, ring srcRing, int shift, int /*par_shift*/, ring dstRing)
3310 {
3311  if (dstRing == srcRing)
3312  {
3313  return(p_Copy(p,dstRing));
3314  }
3315  nMapFunc nMap=n_SetMap(srcRing->cf, dstRing->cf);
3316  poly q;
3317  // if ( nMap == nCopy)
3318  // {
3319  // q = prCopyR(p,srcRing);
3320  // }
3321  // else
3322  {
3323  int *perm = (int *)omAlloc0((rVar(srcRing)+1)*sizeof(int));
3324  int *par_perm = (int *)omAlloc0((rPar(srcRing)+1)*sizeof(int));
3325  // int *par_perm = (int *)omAlloc0((rPar(srcRing)+1)*sizeof(int));
3326  int i;
3327  // if (srcRing->P > 0)
3328  // {
3329  // for (i=0; i<srcRing->P; i++)
3330  // par_perm[i]=-i;
3331  // }
3332  if ((shift<0) || (shift > rVar(srcRing))) // ???
3333  {
3334  WerrorS("bad shifts in p_CopyEmbed");
3335  return(0);
3336  }
3337  for (i=1; i<= srcRing->N; i++)
3338  {
3339  perm[i] = shift+i;
3340  }
3341  q = p_PermPoly(p,perm,srcRing, dstRing, nMap,par_perm, rPar(srcRing));
3342  }
3343  return(q);
3344 }
3345 
3346 BOOLEAN rIsLikeOpposite(ring rBase, ring rCandidate)
3347 {
3348  /* the same basefield */
3349  int diagnose = TRUE;
3350  nMapFunc nMap = n_SetMap(rCandidate->cf, rBase->cf); // reverse?
3351 
3352 ////// if (nMap != nCopy) diagnose = FALSE;
3353  if (nMap == NULL) diagnose = FALSE;
3354 
3355 
3356  /* same number of variables */
3357  if (rBase->N != rCandidate->N) diagnose = FALSE;
3358  /* nc and comm ring */
3359  if ( rIsPluralRing(rBase) != rIsPluralRing(rCandidate) ) diagnose = FALSE;
3360  /* both are qrings */
3361  /* NO CHECK, since it is used in building opposite qring */
3362  /* if ( ((rBase->qideal != NULL) && (rCandidate->qideal == NULL)) */
3363  /* || ((rBase->qideal == NULL) && (rCandidate->qideal != NULL)) ) */
3364  /* diagnose = FALSE; */
3365  /* TODO: varnames are e->E etc */
3366  return diagnose;
3367 }
3368 
3369 
3370 
3371 
3372 /// opposes a vector p from Rop to currRing (dst!)
3373 poly pOppose(ring Rop, poly p, const ring dst)
3374 {
3375  /* the simplest case:*/
3376  if ( Rop == dst ) return(p_Copy(p, dst));
3377  /* check Rop == rOpposite(currRing) */
3378 
3379 
3380  if ( !rIsLikeOpposite(dst, Rop) )
3381  {
3382  WarnS("an opposite ring should be used");
3383  return NULL;
3384  }
3385 
3386  nMapFunc nMap = n_SetMap(Rop->cf, dst->cf); // reverse?
3387 
3388  /* nMapFunc nMap = nSetMap(Rop);*/
3389  /* since we know that basefields coinside! */
3390 
3391  // coinside???
3392 
3393  int *perm=(int *)omAlloc0((Rop->N+1)*sizeof(int));
3394  if (!p_IsConstantPoly(p, Rop))
3395  {
3396  /* we know perm exactly */
3397  int i;
3398  for(i=1; i<=Rop->N; i++)
3399  {
3400  perm[i] = Rop->N+1-i;
3401  }
3402  }
3403  poly res = p_PermPoly(p, perm, Rop, dst, nMap);
3404  omFreeSize((ADDRESS)perm,(Rop->N+1)*sizeof(int));
3405 
3406  p_Test(res, dst);
3407 
3408  return res;
3409 }
3410 
3411 /// opposes a module I from Rop to currRing(dst)
3412 ideal idOppose(ring Rop, ideal I, const ring dst)
3413 {
3414  /* the simplest case:*/
3415  if ( Rop == dst ) return id_Copy(I, dst);
3416 
3417  /* check Rop == rOpposite(currRing) */
3418  if (!rIsLikeOpposite(dst, Rop))
3419  {
3420  WarnS("an opposite ring should be used");
3421  return NULL;
3422  }
3423  int i;
3424  ideal idOp = idInit(I->ncols, I->rank);
3425  for (i=0; i< (I->ncols)*(I->nrows); i++)
3426  {
3427  idOp->m[i] = pOppose(Rop,I->m[i], dst);
3428  }
3429  id_Test(idOp, dst);
3430  return idOp;
3431 }
3432 
3433 
3434 bool nc_SetupQuotient(ring rGR, const ring rG, bool bCopy)
3435 {
3436  if( rGR->qideal == NULL )
3437  return false; // no quotient = no work! done!? What about factors of SCA?
3438 
3439  bool ret = true;
3440  // currently only super-commutative extension deals with factors.
3441 
3442  if( ncExtensions(SCAMASK) )
3443  {
3444  bool sca_ret = sca_SetupQuotient(rGR, rG, bCopy);
3445 
3446  if(sca_ret) // yes it was dealt with!
3447  ret = false;
3448  }
3449 
3450  if( bCopy )
3451  {
3452  assume(rIsPluralRing(rGR) == rIsPluralRing(rG));
3453  assume((rGR->qideal==NULL) == (rG->qideal==NULL));
3454  assume(rIsSCA(rGR) == rIsSCA(rG));
3455  assume(ncRingType(rGR) == ncRingType(rG));
3456  }
3457 
3458  return ret;
3459 }
3460 
3461 
3462 
3463 // int Commutative_Context(ring r, leftv expression)
3464 // /* returns 1 if expression consists */
3465 // /* of commutative elements */
3466 // {
3467 // /* crucial: poly -> ideal, module, matrix */
3468 // }
3469 
3470 // int Comm_Context_Poly(ring r, poly p)
3471 // {
3472 // poly COMM=r->GetNC()->COMM;
3473 // poly pp=pOne();
3474 // memset(pp->exp,0,r->ExpL_Size*sizeof(long));
3475 // while (p!=NULL)
3476 // {
3477 // for (i=0;i<=r->ExpL_Size;i++)
3478 // {
3479 // if ((p->exp[i]) && (pp->exp[i])) return(FALSE);
3480 // /* nonzero exponent of non-comm variable */
3481 // }
3482 // pIter(p);
3483 // }
3484 // return(TRUE);
3485 // }
3486 
3487 #endif
3488 
3489 
3490 
BOOLEAN rHasLocalOrMixedOrdering(const ring r)
Definition: ring.h:752
static FORCE_INLINE number n_Sub(number a, number b, const coeffs r)
return the difference of &#39;a&#39; and &#39;b&#39;, i.e., a-b
Definition: coeffs.h:673
static poly NF_Proc_Dummy(ideal, ideal, poly, int, int, const ring)
Definition: old.gring.cc:64
BOOLEAN kbTest(kBucket_pt bucket)
Tests
Definition: kbuckets.cc:181
poly(* NF_Proc)(ideal, ideal, poly, int, int, const ring _currRing)
Definition: ring.h:251
NF_Proc nc_NF
Definition: old.gring.cc:71
ideal idOppose(ring Rop, ideal I, const ring dst)
opposes a module I from Rop to currRing(dst)
Definition: old.gring.cc:3412
const CanonicalForm int s
Definition: facAbsFact.cc:55
poly nc_mm_Bracket_nn(poly m1, poly m2, const ring r)
returns [m1,m2] for two monoms, destroys nothing without coeffs
Definition: old.gring.cc:2295
const CanonicalForm int const CFList const Variable & y
Definition: facAbsFact.cc:57
void p_DebugPrint(poly p, const ring r)
Definition: ring.cc:4217
ideal(* BBA_Proc)(const ideal, const ideal, const intvec *, const intvec *, kStrategy strat, const ring)
Definition: ring.h:252
#define D(A)
Definition: gentable.cc:123
CFArray copy(const CFList &list)
write elements of list into an array
poly prCopyR_NoSort(poly p, ring src_r, ring dest_r)
Definition: prCopy.cc:78
const poly a
Definition: syzextra.cc:212
poly _gnc_p_Mult_q(poly p, poly q, const int copy, const ring r)
Definition: old.gring.cc:195
#define Print
Definition: emacs.cc:83
static poly p_LmDeleteAndNext(poly p, const ring r)
Definition: p_polys.h:720
static CFormulaPowerMultiplier * GetFormulaPowerMultiplier(const ring r)
Definition: ncSAFormula.h:95
void nc_rKill(ring r)
complete destructor
Definition: old.gring.cc:2486
BOOLEAN p_ComparePolys(poly p1, poly p2, const ring r)
returns TRUE if p1 is a skalar multiple of p2 assume p1 != NULL and p2 != NULL
Definition: p_polys.cc:4431
CanonicalForm num(const CanonicalForm &f)
#define FALSE
Definition: auxiliary.h:94
return P p
Definition: myNF.cc:203
number kBucketPolyRed(kBucket_pt bucket, poly p1, int l1, poly spNoether)
Definition: kbuckets.cc:1053
ideal id_Copy(ideal h1, const ring r)
copy an ideal
static FORCE_INLINE BOOLEAN n_IsOne(number n, const coeffs r)
TRUE iff &#39;n&#39; represents the one element.
Definition: coeffs.h:472
static int rPar(const ring r)
(r->cf->P)
Definition: ring.h:590
static poly p_Mult_mm(poly p, poly m, const ring r)
Definition: p_polys.h:968
poly p_NSet(number n, const ring r)
returns the poly representing the number n, destroys n
Definition: p_polys.cc:1444
poly p_CopyEmbed(poly p, ring srcRing, int shift, int, ring dstRing)
Definition: old.gring.cc:3309
#define id_Test(A, lR)
Definition: simpleideals.h:80
void nc_p_ProcsSet(ring rGR, p_Procs_s *p_Procs)
Definition: old.gring.cc:3210
static unsigned long p_SetComp(poly p, unsigned long c, ring r)
Definition: p_polys.h:242
struct p_Procs_s p_Procs_s
Definition: ring.h:29
#define p_GetComp(p, r)
Definition: monomials.h:72
poly gnc_CreateSpolyOld(const poly p1, const poly p2, const ring r)
Definition: old.gring.cc:1476
poly pOppose(ring Rop, poly p, const ring dst)
opposes a vector p from Rop to currRing (dst!)
Definition: old.gring.cc:3373
void nc_PolyPolyRedNew(poly &b, poly p, number *c, const ring r)
Definition: old.gring.cc:2141
static poly last
Definition: hdegree.cc:1077
static BOOLEAN rIsRatGRing(const ring r)
Definition: ring.h:415
static FORCE_INLINE number n_Init(long i, const coeffs r)
a number representing i in the given coeff field/ring r
Definition: coeffs.h:542
static void p_GetExpV(poly p, int *ev, const ring r)
Definition: p_polys.h:1443
#define omFreeSize(addr, size)
Definition: omAllocDecl.h:260
poly nc_p_Minus_mm_Mult_qq(poly p, const poly m, const poly q, int &shorter, const poly, const ring r)
for p_Minus_mm_Mult_qq in pInline2.h
Definition: old.gring.cc:155
const poly kBucketGetLm(kBucket_pt bucket)
Definition: kbuckets.cc:480
static short rVar(const ring r)
#define rVar(r) (r->N)
Definition: ring.h:583
void id_Delete(ideal *h, ring r)
deletes an ideal/module/matrix
#define MIN_LENGTH_BUCKET
Definition: p_Mult_q.h:22
poly gnc_mm_Mult_nn(int *F, int *G, const ring r)
Definition: old.gring.cc:419
gmp_float log(const gmp_float &a)
Definition: mpr_complex.cc:345
void p_Lcm(const poly a, const poly b, poly m, const ring r)
Definition: p_polys.cc:1616
#define COM(f)
Definition: transext.cc:70
static poly pp_Mult_mm(poly p, poly m, const ring r)
Definition: p_polys.h:957
#define TRUE
Definition: auxiliary.h:98
bool nc_SetupQuotient(ring rGR, const ring rG, bool bCopy)
Definition: old.gring.cc:3434
static poly gnc_uu_Mult_ww_formula(int i, int a, int j, int b, const ring r)
Definition: old.gring.cc:1011
poly gnc_p_Mult_mm_Common(poly p, const poly m, int side, const ring r)
Definition: old.gring.cc:306
static FORCE_INLINE void n_Normalize(number &n, const coeffs r)
inplace-normalization of n; produces some canonical representation of n;
Definition: coeffs.h:582
void * ADDRESS
Definition: auxiliary.h:115
void pWrite(poly p)
Definition: polys.h:290
BBA_Proc gnc_gr_mora
Definition: old.gring.cc:73
void WerrorS(const char *s)
Definition: feFopen.cc:24
int k
Definition: cfEzgcd.cc:93
#define Q
Definition: sirandom.c:25
static number & pGetCoeff(poly p)
return an alias to the leading coefficient of p assumes that p != NULL NOTE: not copy ...
Definition: monomials.h:51
#define WarnS
Definition: emacs.cc:81
poly gnc_pp_Mult_mm(const poly p, const poly m, const ring r, poly &last)
Definition: nc.h:83
static TreeM * G
Definition: janet.cc:38
nc_type
Definition: nc.h:20
static number p_SetCoeff(poly p, number n, ring r)
Definition: p_polys.h:407
int & getNCExtensions()
Definition: old.gring.cc:87
BOOLEAN nc_CheckSubalgebra(poly PolyVar, ring r)
Definition: old.gring.cc:2579
Definition: nc.h:25
static void p_SetExpV(poly p, int *ev, const ring r)
Definition: p_polys.h:1451
Enum_ncSAType GetPair(int i, int j) const
Definition: ncSAFormula.h:46
poly nc_CreateShortSpoly(poly p1, poly p2, const ring r)
Definition: old.gring.cc:1885
static poly p_Copy(poly p, const ring r)
returns a copy of p
Definition: p_polys.h:804
poly pp
Definition: myNF.cc:296
poly gnc_ReduceSpolyNew(const poly p1, poly p2, const ring r)
Definition: old.gring.cc:1403
BOOLEAN rIsLikeOpposite(ring rBase, ring rCandidate)
checks whether rings rBase and rCandidate could be opposite to each other returns TRUE if it is so ...
Definition: old.gring.cc:3346
void iiWriteMatrix(matrix im, const char *n, int dim, const ring r, int spaces)
set spaces to zero by default
Definition: matpol.cc:743
static poly Multiply(Enum_ncSAType type, const int i, const int j, const int n, const int m, const ring r)
Definition: ncSAFormula.cc:696
#define TEST_OPT_NOT_BUCKETS
Definition: options.h:100
void nc_CleanUp(nc_struct *p)
Definition: old.gring.cc:2472
static BOOLEAN p_LmIsConstant(const poly p, const ring r)
Definition: p_polys.h:949
void p_Cleardenom_n(poly ph, const ring r, number &c)
Definition: p_polys.cc:2883
#define pIter(p)
Definition: monomials.h:44
poly res
Definition: myNF.cc:322
static FORCE_INLINE number n_Mult(number a, number b, const coeffs r)
return the product of &#39;a&#39; and &#39;b&#39;, i.e., a*b
Definition: coeffs.h:640
#define freeN(A, k)
Definition: old.gring.cc:107
#define M
Definition: sirandom.c:24
void gnc_kBucketPolyRed_ZNew(kBucket_pt b, poly p, number *c)
Definition: old.gring.cc:2072
static poly nc_mm_Mult_p(const poly m, poly p, const ring r)
Definition: nc.h:250
static poly p_Head(poly p, const ring r)
Definition: p_polys.h:812
bool nc_rCopy(ring res, const ring r, bool bSetupQuotient)
Definition: old.gring.cc:3034
long p_Deg(poly a, const ring r)
Definition: p_polys.cc:588
const ring r
Definition: syzextra.cc:208
poly p_LcmRat(const poly a, const poly b, const long lCompM, const ring r)
Definition: p_polys.cc:1638
poly p_PermPoly(poly p, const int *perm, const ring oldRing, const ring dst, nMapFunc nMap, const int *par_perm, int OldPar, BOOLEAN use_mult)
Definition: p_polys.cc:3985
poly _nc_p_Mult_q(poly pPolyP, poly pPolyQ, const ring rRing)
general NC-multiplication with destruction
Definition: old.gring.cc:220
poly gnc_uu_Mult_ww_vert(int i, int a, int j, int b, const ring r)
Definition: old.gring.cc:936
static void p_SetCompP(poly p, int i, ring r)
Definition: p_polys.h:249
Definition: intvec.h:14
const CanonicalForm CFMap CFMap & N
Definition: cfEzgcd.cc:49
poly p_One(const ring r)
Definition: p_polys.cc:1314
int j
Definition: myNF.cc:70
poly nc_p_Bracket_qq(poly p, const poly q, const ring r)
returns [p,q], destroys p
Definition: old.gring.cc:2254
#define assume(x)
Definition: mod2.h:394
static BOOLEAN rIsPluralRing(const ring r)
we must always have this test!
Definition: ring.h:404
static BOOLEAN p_IsConstant(const poly p, const ring r)
Definition: p_polys.h:1876
Definition: nc.h:27
poly gnc_mm_Mult_p(const poly m, poly p, const ring r)
Definition: old.gring.cc:407
BBA_Proc sca_gr_bba
Definition: old.gring.cc:76
void nc_rCleanUp(ring r)
poly nc_p_CopyGet(poly a, const ring r)
Definition: old.gring.cc:2537
#define nInpNeg(n)
Definition: numbers.h:21
number(* nMapFunc)(number a, const coeffs src, const coeffs dst)
maps "a", which lives in src, into dst
Definition: coeffs.h:73
poly gnc_CreateSpolyNew(const poly p1, const poly p2, const ring r)
Definition: old.gring.cc:1564
poly gnc_mm_Mult_pp(const poly m, const poly p, const ring r)
Definition: old.gring.cc:412
void gnc_kBucketPolyRedOld(kBucket_pt b, poly p, number *c)
Definition: old.gring.cc:1926
ip_smatrix * matrix
BBA_Proc sca_mora
Definition: old.gring.cc:75
#define rTest(r)
Definition: ring.h:777
static BOOLEAN p_DivisibleBy(poly a, poly b, const ring r)
Definition: p_polys.h:1777
All the auxiliary stuff.
static int p_LmCmp(poly p, poly q, const ring r)
Definition: p_polys.h:1467
static FORCE_INLINE number n_Invers(number a, const coeffs r)
return the multiplicative inverse of &#39;a&#39;; raise an error if &#39;a&#39; is not invertible ...
Definition: coeffs.h:568
int m
Definition: cfEzgcd.cc:119
BOOLEAN rSamePolyRep(ring r1, ring r2)
returns TRUE, if r1 and r2 represents the monomials in the same way FALSE, otherwise this is an analo...
Definition: ring.cc:1677
static FORCE_INLINE number n_InpNeg(number n, const coeffs r)
in-place negation of n MUST BE USED: n = n_InpNeg(n) (no copy is returned)
Definition: coeffs.h:561
void On(int sw)
switches
static int si_max(const int a, const int b)
Definition: auxiliary.h:120
void gnc_kBucketPolyRedNew(kBucket_pt b, poly p, number *c)
Definition: old.gring.cc:1959
BOOLEAN gnc_InitMultiplication(ring r, bool bSetupQuotient=false)
Definition: old.gring.cc:3046
int i
Definition: cfEzgcd.cc:123
Definition: nc.h:24
void PrintS(const char *s)
Definition: reporter.cc:284
static poly p_Mult_nn(poly p, number n, const ring r)
Definition: p_polys.h:895
void sca_p_ProcsSet(ring rGR, p_Procs_s *p_Procs)
Definition: sca.cc:1238
poly gnc_uu_Mult_ww_horvert(int i, int a, int j, int b, const ring r)
Definition: old.gring.cc:1149
poly gnc_mm_Mult_uu(int *F, int jG, int bG, const ring r)
Definition: old.gring.cc:678
const int NOCACHEMASK
Definition: nc.h:357
static unsigned pLength(poly a)
Definition: p_polys.h:189
void p_Content(poly ph, const ring r)
Definition: p_polys.cc:2255
static FORCE_INLINE BOOLEAN n_IsZero(number n, const coeffs r)
TRUE iff &#39;n&#39; represents the zero element.
Definition: coeffs.h:468
static BOOLEAN p_LmDivisibleBy(poly a, poly b, const ring r)
Definition: p_polys.h:1768
void mp_Delete(matrix *a, const ring r)
Definition: matpol.cc:789
static FORCE_INLINE nMapFunc n_SetMap(const coeffs src, const coeffs dst)
set the mapping function pointers for translating numbers from src to dst
Definition: coeffs.h:725
BOOLEAN pqLength(poly p, poly q, int &lp, int &lq, const int min)
Definition: p_Mult_q.cc:27
#define p_Test(p, r)
Definition: p_polys.h:160
int size(const CanonicalForm &f, const Variable &v)
int size ( const CanonicalForm & f, const Variable & v )
Definition: cf_ops.cc:600
BOOLEAN p_HasNotCF(poly p1, poly p2, const ring r)
Definition: p_polys.cc:1330
BOOLEAN nc_CallPlural(matrix CCC, matrix DDD, poly CCN, poly DDN, ring r, bool bSetupQuotient, bool bCopyInput, bool bBeQuiet, ring curr, bool dummy_ring)
returns TRUE if there were errors analyze inputs, check them for consistency detects nc_type...
Definition: old.gring.cc:2693
matrix mpNew(int r, int c)
create a r x c zero-matrix
Definition: matpol.cc:44
CanonicalForm test
Definition: cfModGcd.cc:4037
void p_Write0(poly p, ring lmRing, ring tailRing)
Definition: polys0.cc:196
static void p_Delete(poly *p, const ring r)
Definition: p_polys.h:843
ideal idInit(int idsize, int rank)
initialise an ideal / module
Definition: simpleideals.cc:38
const Variable & v
< [in] a sqrfree bivariate poly
Definition: facBivar.h:37
static void p_ExpVectorDiff(poly pr, poly p1, poly p2, const ring r)
Definition: p_polys.h:1397
ring rCopy(ring r)
Definition: ring.cc:1614
BOOLEAN gnc_CheckOrdCondition(matrix D, ring r)
Definition: old.gring.cc:2638
static unsigned long p_SetExp(poly p, const unsigned long e, const unsigned long iBitmask, const int VarOffset)
set a single variable exponent : VarOffset encodes the position in p->exp
Definition: p_polys.h:483
static FORCE_INLINE void n_Power(number a, int b, number *res, const coeffs r)
fill res with the power a^b
Definition: coeffs.h:636
#define MATCOLS(i)
Definition: matpol.h:28
#define NULL
Definition: omList.c:10
static FORCE_INLINE number n_Copy(number n, const coeffs r)
return a copy of &#39;n&#39;
Definition: coeffs.h:455
void * cast_A_to_vptr(A a)
Definition: auxiliary.h:384
int iNCExtensions
Definition: old.gring.cc:85
Definition: nc.h:23
matrix D
Definition: nc.h:92
poly gnc_ReduceSpolyOld(const poly p1, poly p2, const ring r)
Definition: old.gring.cc:1347
static FORCE_INLINE number n_Div(number a, number b, const coeffs r)
return the quotient of &#39;a&#39; and &#39;b&#39;, i.e., a/b; raises an error if &#39;b&#39; is not invertible in r exceptio...
Definition: coeffs.h:619
void nc_PolyPolyRedOld(poly &b, poly p, number *c, const ring r)
Definition: old.gring.cc:2107
poly _nc_pp_Mult_qq(const poly pPolyP, const poly pPolyQ, const ring rRing)
general NC-multiplication without destruction
Definition: old.gring.cc:259
poly nc_pSubst(poly p, int n, poly e, const ring r)
substitute the n-th variable by e in p destroy p e is not a constant
Definition: old.gring.cc:3234
poly gnc_uu_Mult_ww(int i, int a, int j, int b, const ring r)
Definition: old.gring.cc:1044
const CanonicalForm & w
Definition: facAbsFact.cc:55
bool sca_SetupQuotient(ring rGR, ring rG, bool bCopy)
Definition: sca.cc:921
static p_Procs_s * _p_procs
Definition: p_Procs_Set.h:113
Variable x
Definition: cfModGcd.cc:4023
static BOOLEAN p_IsConstantPoly(const poly p, const ring r)
Definition: p_polys.h:1890
const int SCAMASK
Definition: nc.h:341
static bool rIsSCA(const ring r)
Definition: nc.h:206
#define pNext(p)
Definition: monomials.h:43
static FORCE_INLINE BOOLEAN n_Equal(number a, number b, const coeffs r)
TRUE iff &#39;a&#39; and &#39;b&#39; represent the same number; they may have different representations.
Definition: coeffs.h:464
BOOLEAN ncInitSpecialPairMultiplication(ring r)
Definition: ncSAMult.cc:266
const int NOPLURALMASK
Definition: nc.h:355
static void p_Setm(poly p, const ring r)
Definition: p_polys.h:228
bool ncInitSpecialPowersMultiplication(ring r)
Definition: ncSAFormula.cc:50
static long p_AddExp(poly p, int v, long ee, ring r)
Definition: p_polys.h:601
#define p_GetCoeff(p, r)
Definition: monomials.h:57
matrix mp_Copy(matrix a, const ring r)
copies matrix a (from ring r to r)
Definition: matpol.cc:71
static nc_type & ncRingType(nc_struct *p)
Definition: nc.h:175
static FORCE_INLINE number n_SubringGcd(number a, number b, const coeffs r)
Definition: coeffs.h:692
matrix C
Definition: nc.h:91
int dReportError(const char *fmt,...)
Definition: dError.cc:45
void gnc_kBucketPolyRed_ZOld(kBucket_pt b, poly p, number *c)
Definition: old.gring.cc:2039
static poly p_Neg(poly p, const ring r)
Definition: p_polys.h:1013
static void p_LmDelete(poly p, const ring r)
Definition: p_polys.h:706
BBA_Proc sca_bba
Definition: old.gring.cc:74
static poly nc_mm_Mult_pp(const poly m, const poly p, const ring r)
Definition: nc.h:240
END_NAMESPACE const void * p2
Definition: syzextra.cc:202
static FORCE_INLINE void n_Delete(number *p, const coeffs r)
delete &#39;p&#39;
Definition: coeffs.h:459
static FORCE_INLINE BOOLEAN n_IsMOne(number n, const coeffs r)
TRUE iff &#39;n&#39; represents the additive inverse of the one element, i.e. -1.
Definition: coeffs.h:476
void p_Write(poly p, ring lmRing, ring tailRing)
Definition: polys0.cc:206
static void gnc_p_ProcsSet(ring rGR, p_Procs_s *p_Procs)
Definition: old.gring.cc:3146
#define MATROWS(i)
Definition: matpol.h:27
int IsSkewConstant
Definition: nc.h:101
kBucketDestroy & P
Definition: myNF.cc:191
CPolynomialSummator: unifies bucket and polynomial summation as the later is brocken in buckets :(...
Definition: summator.h:29
polyrec * poly
Definition: hilb.h:10
#define freeT(A, v)
Definition: old.gring.cc:106
static poly p_Add_q(poly p, poly q, const ring r)
Definition: p_polys.h:877
void nc_PolyPolyRed(poly &b, poly p, number *c, const ring r)
Definition: old.gring.cc:2241
poly nc_p_Plus_mm_Mult_qq(poly p, const poly m, const poly q, int &lp, const int, const ring r)
Definition: old.gring.cc:173
const int NOFORMULAMASK
Definition: nc.h:356
Rational pow(const Rational &a, int e)
Definition: GMPrat.cc:418
ring nc_rCreateNCcomm(ring r)
Definition: old.gring.cc:3285
int BOOLEAN
Definition: auxiliary.h:85
poly nc_p_CopyPut(poly a, const ring r)
Definition: old.gring.cc:2558
const poly b
Definition: syzextra.cc:213
poly p_Cleardenom(poly p, const ring r)
Definition: p_polys.cc:2755
static ideal BBA_Proc_Dummy(const ideal, const ideal, const intvec *, const intvec *, kStrategy, const ring)
Definition: old.gring.cc:66
poly gnc_p_Mult_mm(poly p, const poly m, const ring r)
Definition: old.gring.cc:402
poly p_ISet(long i, const ring r)
returns the poly representing the integer i
Definition: p_polys.cc:1298
BBA_Proc gnc_gr_bba
Definition: old.gring.cc:72
poly p_Power(poly p, int i, const ring r)
Definition: p_polys.cc:2158
void Werror(const char *fmt,...)
Definition: reporter.cc:189
bool ncExtensions(int iMask)
Definition: old.gring.cc:99
matrix nc_PrintMat(int a, int b, ring r, int metric)
returns matrix with the info on noncomm multiplication
Definition: old.gring.cc:2405
#define omAlloc0(size)
Definition: omAllocDecl.h:211
int l
Definition: cfEzgcd.cc:94
int setNCExtensions(int iMask)
Definition: old.gring.cc:92
Definition: nc.h:26
Enum_ncSAType
Definition: ncSAFormula.h:17
#define UPMATELEM(i, j, nVar)
Definition: nc.h:44
#define MATELEM(mat, i, j)
Definition: matpol.h:29
void kBucket_Add_q(kBucket_pt bucket, poly q, int *l)
Add to Bucket a poly ,i.e. Bpoly == q+Bpoly
Definition: kbuckets.cc:628