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