source: git/kernel/GBEngine/ratgring.cc @ 7b9b8e5

spielwiese
Last change on this file since 7b9b8e5 was 7b9b8e5, checked in by Hans Schoenemann <hannes@…>, 8 years ago
fix: Werror -> WerrorS if possible
  • Property mode set to 100644
File size: 16.6 KB
Line 
1/****************************************
2*  Computer Algebra System SINGULAR     *
3****************************************/
4/***************************************************************
5 *  File:    ratgring.cc
6 *  Purpose: Ore-noncommutative kernel procedures
7 *  Author:  levandov (Viktor Levandovsky)
8 *  Created: 8/00 - 11/00
9 *******************************************************************/
10
11
12
13#include <kernel/mod2.h>
14#include <kernel/GBEngine/ratgring.h>
15#ifdef HAVE_RATGRING
16#include <polys/nc/nc.h>
17#include <polys/monomials/ring.h>
18#include <kernel/polys.h>
19#include <coeffs/numbers.h>
20#include <kernel/ideals.h>
21#include <polys/matpol.h>
22#include <polys/kbuckets.h>
23#include <kernel/GBEngine/kstd1.h>
24#include <polys/sbuckets.h>
25#include <polys/prCopy.h>
26#include <polys/operations/p_Mult_q.h>
27#include <polys/clapsing.h>
28#include <misc/options.h>
29
30void pLcmRat(poly a, poly b, poly m, int rat_shift)
31{
32  /* rat_shift is the last exp one should count with */
33  int i;
34  for (i=(currRing->N); i>=rat_shift; i--)
35  {
36    pSetExp(m,i, si_max( pGetExp(a,i), pGetExp(b,i)));
37  }
38  pSetComp(m, si_max(pGetComp(a), pGetComp(b)));
39  /* Don't do a pSetm here, otherwise hres/lres chockes */
40}
41
42// void pLcmRat(poly a, poly b, poly m, poly pshift)
43// {
44//   /* shift is the exp of rational elements */
45//   int i;
46//   for (i=(currRing->N); i; i--)
47//   {
48//     if (!pGetExp(pshift,i))
49//     {
50//       pSetExp(m,i, si_max( pGetExp(a,i), pGetExp(b,i)));
51//     }
52//     else
53//     {
54//       /* do we really need it? */
55//       pSetExp(m,i,0);
56//     }
57//   }
58//   pSetComp(m, si_max(pGetComp(a), pGetComp(b)));
59//   /* Don't do a pSetm here, otherwise hres/lres chockes */
60// }
61
62/* returns a subpoly of p, s.t. its monomials have the same D-part */
63
64poly p_HeadRat(poly p, int ishift, ring r)
65{
66  poly q   = pNext(p);
67  if (q == NULL) return p;
68  poly res = p_Head(p,r);
69  const long cmp = p_GetComp(p, r);
70  while ( (q!=NULL) && (p_Comp_k_n(p, q, ishift+1, r)) && (p_GetComp(q, r) == cmp) )
71  {
72    res = p_Add_q(res,p_Head(q,r),r);
73    q   = pNext(q);
74  }
75  p_SetCompP(res,cmp,r);
76  return res;
77}
78
79/* to test!!! */
80/* ExpVector(pr) = ExpVector(p1) - ExpVector(p2) */
81void p_ExpVectorDiffRat(poly pr, poly p1, poly p2, int ishift, ring r)
82{
83  p_LmCheckPolyRing1(p1, r);
84  p_LmCheckPolyRing1(p2, r);
85  p_LmCheckPolyRing1(pr, r);
86  int i;
87  poly t=pr;
88  int e1,e2;
89  for (i=ishift+1; i<=r->N; i++)
90  {
91    e1 = p_GetExp(p1, i, r);
92    e2 = p_GetExp(p2, i, r);
93    //    pAssume1(p_GetExp(p1, i, r) >= p_GetExp(p2, i, r));
94    if (e1 < e2)
95    {
96#ifdef PDEBUG
97      PrintS("negative ExpVectorDiff\n");
98#endif
99      p_Delete(&t,r);
100      break;
101    }
102    else
103    {
104      p_SetExp(t,i, e1-e2,r);
105    }
106  }
107  p_Setm(t,r);
108}
109
110/* returns ideal (u,v) s.t. up + vq = 0 */
111
112ideal ncGCD2(poly p, poly q, const ring r)
113{
114  // todo: must destroy p,q
115  intvec *w = NULL;
116  ideal h = idInit(2,1);
117  h->m[0] = p_Copy(p,r);
118  h->m[1] = p_Copy(q,r);
119#ifdef PDEBUG
120  PrintS("running syzygy comp. for nc_GCD:\n");
121#endif
122  ideal sh = idSyzygies(h, testHomog, &w);
123#ifdef PDEBUG
124  PrintS("done syzygy comp. for nc_GCD\n");
125#endif
126  /* in comm case, there is only 1 syzygy */
127  /*   singclap_gcd(); */
128  poly K, K1, K2;
129  K  = sh->m[0]; /* take just the first element - to be enhanced later */
130  K1 = pTakeOutComp(&K, 1); // 1st component is taken out from K
131//  pShift(&K,-2); // 2nd component to 0th comp.
132  K2 = pTakeOutComp(&K, 1);
133//  K2 = K;
134
135  PrintS("syz1: "); p_wrp(K1,r);
136  PrintS("syz2: "); p_wrp(K2,r);
137
138  /* checking signs before multiplying */
139  number ck1 = p_GetCoeff(K1,r);
140  number ck2 = p_GetCoeff(K2,r);
141  BOOLEAN bck1, bck2;
142  bck1 = n_GreaterZero(ck1,r);
143  bck2 = n_GreaterZero(ck2,r);
144  /* K1 <0, K2 <0 (-K1,-K2)    */
145//   if ( !(bck1 && bck2) ) /* - , - */
146//   {
147//     K1 = p_Neg(K1,r);
148//     K2 = p_Neg(K2,r);
149//   }
150  id_Delete(&h,r);
151  h = idInit(2,1);
152  h->m[0] = p_Copy(K1,r);
153  h->m[1] = p_Copy(K2,r);
154  id_Delete(&sh,r);
155  return(h);
156}
157
158/* returns ideal (u,v) s.t. up + vq = 0 */
159
160ideal ncGCD(poly p, poly q, const ring r)
161{
162  // destroys p and q
163  // assume: p,q are in the comm. ring
164  // to be used in the coeff business
165#ifdef PDEBUG
166  PrintS(" GCD_start:");
167#endif
168  poly g = singclap_gcd(p_Copy(p,r),p_Copy(q,r), r);
169#ifdef PDEBUG
170  p_wrp(g,r);
171  PrintS(" GCD_end;\n");
172#endif
173  poly u = singclap_pdivide(q, g, r); //q/g
174  poly v = singclap_pdivide(p, g, r); //p/g
175  v = p_Neg(v,r);
176  p_Delete(&p,r);
177  p_Delete(&q,r);
178  ideal h = idInit(2,1);
179  h->m[0] = u; // p_Copy(u,r);
180  h->m[1] = v; // p_Copy(v,r);
181  return(h);
182}
183
184/* PINLINE1 void p_ExpVectorDiff
185   remains as is -> BUT we can do memory shift on smaller number of exp's */
186
187
188/*4 - follow the numbering of gring.cc
189* creates the S-polynomial of p1 and p2
190* do not destroy p1 and p2
191*/
192// poly nc_rat_CreateSpoly(poly p1, poly p2, poly spNoether, int ishift, const ring r)
193// {
194//   if ((p_GetComp(p1,r)!=p_GetComp(p2,r))
195//   && (p_GetComp(p1,r)!=0)
196//   && (p_GetComp(p2,r)!=0))
197//   {
198// #ifdef PDEBUG
199//     Print("nc_CreateSpoly : different components!");
200// #endif
201//     return(NULL);
202//   }
203//   /* prod. crit does not apply yet */
204// //   if ((r->nc->type==nc_lie) && pHasNotCF(p1,p2)) /* prod crit */
205// //   {
206// //     return(nc_p_Bracket_qq(pCopy(p2),p1));
207// //   }
208//   poly pL=pOne();
209//   poly m1=pOne();
210//   poly m2=pOne();
211//   /* define shift */
212//   int is = ishift; /* TODO */
213//   pLcmRat(p1,p2,pL,is);
214//   p_Setm(pL,r);
215//   poly pr1 = p_GetExp_k_n(p1,1,ishift-1,r); /* rat D-exp of p1 */
216//   poly pr2 = p_GetExp_k_n(p2,1,ishift-1,r); /* rat D-exp of p2 */
217// #ifdef PDEBUG
218//   p_Test(pL,r);
219// #endif
220//   p_ExpVectorDiff(m1,pL,p1,r); /* purely in D part by construction */
221//   //p_SetComp(m1,0,r);
222//   //p_Setm(m1,r);
223// #ifdef PDEBUG
224//   p_Test(m1,r);
225// #endif
226//   p_ExpVectorDiff(m2,pL,p2,r); /* purely in D part by construction */
227//   //p_SetComp(m2,0,r);
228//   //p_Setm(m2,r);
229// #ifdef PDEBUG
230//   p_Test(m2,r);
231// #endif
232//   p_Delete(&pL,r);
233//   /* zero exponents ! */
234
235//   /* EXTRACT LEADCOEF */
236
237//   poly H1  = p_HeadRat(p1,is,r);
238//   poly M1  = r->nc->p_Procs.mm_Mult_p(m1,p_Copy(H1,r),r);
239
240//   /* POLY:  number C1  = n_Copy(p_GetCoeff(M1,r),r); */
241//   /* RAT: */
242
243//   poly C1  = p_GetCoeffRat(M1,ishift,r);
244
245//   poly H2  = p_HeadRat(p2,is,r);
246//   poly M2  = r->nc->p_Procs.mm_Mult_p(m2,p_Copy(H2,r),r);
247
248//   /* POLY:  number C2  = n_Copy(p_GetCoeff(M2,r),r); */
249//   /* RAT: */
250
251//   poly C2  = p_GetCoeffRat(M2,ishift,r);
252
253// /* we do not assume that X's commute */
254// /* we just run NC syzygies */
255
256// /* NEW IDEA: change the ring to K<X>, map things there
257//    and return the result back; seems to be a good optimization */
258// /* to be done later */
259// /* problem: map to subalgebra. contexts, induced (non-unique) orderings etc. */
260
261//   intvec *w = NULL;
262//   ideal h = idInit(2,1);
263//   h->m[0] = p_Copy(C1,r);
264//   h->m[1] = p_Copy(C2,r);
265// #ifdef PDEBUG
266//   Print("running syzygy comp. for coeffs");
267// #endif
268//   ideal sh = idSyzygies(h, testHomog, &w);
269//   /* in comm case, there is only 1 syzygy */
270//   /*   singclap_gcd(); */
271//   poly K,K1,K2;
272//   K  = sh->m[0];
273//   K1 = pTakeOutComp(&K, 1); // 1st component is taken out from K
274//   pShift(&K,-2); // 2nd component to 0th comp.
275//   K2 = K;
276
277//   /* checking signs before multiplying */
278//   number ck1 = p_GetCoeff(K1,r);
279//   number ck2 = p_GetCoeff(K2,r);
280//   BOOLEAN bck1, bck2;
281//   bck1 = n_GreaterZero(ck1,r);
282//   bck2 = n_GreaterZero(ck2,r);
283//   /* K1 >0, K2 >0 (K1,-K2)    */
284//   /* K1 >0, K2 <0 (K1,-K2)    */
285//   /* K1 <0, K2 >0 (-K1,K2)    */
286//   /* K1 <0, K2 <0 (-K1,K2)    */
287//   if ( (bck1) && (bck2) ) /* +, + */
288//   {
289//     K2 = p_Neg(K2,r);
290//   }
291//   if ( (bck1) && (!bck2) ) /* + , - */
292//   {
293//     K2 = p_Neg(K2,r);
294//   }
295//   if ( (!bck1) && (bck2) ) /* - , + */
296//   {
297//     K1 = p_Neg(K1,r);
298//   }
299//   if ( !(bck1 && bck2) ) /* - , - */
300//   {
301//     K1 = p_Neg(K1,r);
302//   }
303
304//   poly P1,P2;
305
306//   //  p_LmDeleteRat(M1,ishift,r); // get tail(D^(gamma-alpha) * lm(p1)) = h_f
307//   P1 = p_Copy(p1,r);
308//   p_LmDeleteAndNextRat(P1,ishift,r); // get tail(p1) = t_f
309//   P1 = r->nc->p_Procs.mm_Mult_p(m1,P1,r);
310//   P1 = p_Add_q(P1,M1,r);
311
312//   //  p_LmDeleteRat(M2,ishift,r);
313//   P2 = p_Copy(p2,r);
314//   p_LmDeleteAndNextRat(P2,ishift,r);// get tail(p2)=t_g
315//   P2 = r->nc->p_Procs.mm_Mult_p(m2,P2,r);
316//   P2 = p_Add_q(P2,M2,r);
317
318//   /* coeff business */
319
320//   P1 = p_Mult_q(P1,K1,r);
321//   P2 = p_Mult_q(P2,K2,r);
322//   P1 = p_Add_q(P1,P2,r);
323
324//   /* cleaning up */
325
326// #ifdef PDEBUG
327//   p_Test(p1,r);
328// #endif
329//   /* questionable: */
330//   if (P1!=NULL) pCleardenom(P1);
331//   if (P1!=NULL) pContent(P1);
332//   return(P1);
333// }
334
335#undef CC
336
337/*4 - follow the numbering of gring.cc
338* creates the S-polynomial of p1 and p2
339* do not destroy p1 and p2
340*/
341poly nc_rat_CreateSpoly(poly pp1, poly pp2, int ishift, const ring r)
342{
343
344  poly p1 = p_Copy(pp1,r);
345  poly p2 = p_Copy(pp2,r);
346
347  const long lCompP1 = p_GetComp(p1,r);
348  const long lCompP2 = p_GetComp(p2,r);
349
350  if ((lCompP1!=lCompP2) && (lCompP1!=0) && (lCompP2!=0))
351  {
352#ifdef PDEBUG
353    WerrorS("nc_rat_CreateSpoly: different non-zero components!");
354#endif
355    return(NULL);
356  }
357
358  if ( (p_LmIsConstantRat(p1,r)) || (p_LmIsConstantRat(p2,r)) )
359  {
360    p_Delete(&p1,r);
361    p_Delete(&p2,r);
362    return( NULL );
363  }
364
365
366/* note: prod. crit does not apply! */
367  poly pL=pOne();
368  poly m1=pOne();
369  poly m2=pOne();
370  int is = ishift; /* TODO */
371  pLcmRat(p1,p2,pL,is);
372  p_Setm(pL,r);
373#ifdef PDEBUG
374  p_Test(pL,r);
375#endif
376  poly pr1 = p_GetExp_k_n(p1,1,ishift,r); /* rat D-exp of p1 */
377  poly pr2 = p_GetExp_k_n(p2,1,ishift,r); /* rat D-exp of p2 */
378  p_ExpVectorDiff(m1,pL,pr1,r); /* purely in D part by construction */
379  p_ExpVectorDiff(m2,pL,pr2,r); /* purely in D part by construction */
380  p_Delete(&pr1,r);
381  p_Delete(&pr2,r);
382  p_Delete(&pL,r);
383#ifdef PDEBUG
384  p_Test(m1,r);
385  PrintS("d^{gamma-alpha} = "); p_wrp(m1,r); PrintLn();
386  p_Test(m2,r);
387  PrintS("d^{gamma-beta} = "); p_wrp(m2,r); PrintLn();
388#endif
389
390  poly HF = NULL;
391  HF = p_HeadRat(p1,is,r); // lm_D(f)
392  HF  = nc_mm_Mult_p(m1, HF, r); // // d^{gamma-alpha} lm_D(f)
393  poly C  = p_GetCoeffRat(HF,  is, r); // c = lc_D(h_f) in the paper
394
395  poly HG = NULL;
396  HG = p_HeadRat(p2,is,r); // lm_D(g)
397  HG  = nc_mm_Mult_p(m2, HG, r); // // d^{gamma-beta} lm_D(g)
398  poly K  = p_GetCoeffRat(HG,  is, r); // k = lc_D(h_g) in the paper
399
400#ifdef PDEBUG
401  PrintS("f: "); p_wrp(p1,r); PrintS("\n");
402  PrintS("c: "); p_wrp(C,r); PrintS("\n");
403  PrintS("g: "); p_wrp(p2,r); PrintS("\n");
404  PrintS("k: "); p_wrp(K,r); PrintS("\n");
405#endif
406
407  ideal ncsyz = ncGCD(C,K,r);
408  poly KK = ncsyz->m[0]; ncsyz->m[0]=NULL; //p_Copy(ncsyz->m[0],r); // k'
409  poly CC = ncsyz->m[1]; ncsyz->m[1]= NULL; //p_Copy(ncsyz->m[1],r); // c'
410  id_Delete(&ncsyz,r);
411
412  p_LmDeleteAndNextRat(&p1, is, r); // t_f
413  p_LmDeleteAndNextRat(&HF, is, r); // r_f = h_f - lt_D(h_f)
414
415  p_LmDeleteAndNextRat(&p2, is, r); // t_g
416  p_LmDeleteAndNextRat(&HG, is, r); // r_g = h_g - lt_D(h_g)
417
418
419#ifdef PDEBUG
420  PrintS(" t_f: "); p_wrp(p1,r); PrintS("\n");
421  PrintS(" t_g: "); p_wrp(p2,r); PrintS("\n");
422  PrintS(" r_f: "); p_wrp(HF,r); PrintS("\n");
423  PrintS(" r_g: "); p_wrp(HG,r); PrintS("\n");
424  PrintS(" c': "); p_wrp(CC,r); PrintS("\n");
425  PrintS(" k': "); p_wrp(KK,r); PrintS("\n");
426
427#endif
428
429  // k'(r_f + d^{gamma-alpha} t_f)
430
431  p1 = p_Mult_q(m1, p1, r); // p1 = d^{gamma-alpha} t_f
432  p1 = p_Add_q(p1,HF,r); // p1 = r_f + d^{gamma-alpha} t_f
433  p1 = p_Mult_q(KK,p1,r); // p1 = k'(r_f + d^{gamma-alpha} t_f)
434
435  // c'(r_f + d^{gamma-beta} t_g)
436
437  p2 = p_Mult_q(m2, p2, r); // p2 = d^{gamma-beta} t_g
438  p2 = p_Add_q(p2,HG,r); // p2 = r_g + d^{gamma-beta} t_g
439  p2 = p_Mult_q(CC,p2,r); // p2 = c'(r_g + d^{gamma-beta} t_g)
440
441#ifdef PDEBUG
442  p_Test(p1,r);
443  p_Test(p2,r);
444  PrintS(" k'(r_f + d^{gamma-alpha} t_f): "); p_wrp(p1,r);
445  PrintS(" c'(r_g + d^{gamma-beta} t_g): "); p_wrp(p2,r);
446#endif
447
448  poly out = p_Add_q(p1,p2,r); // delete p1, p2; // the sum
449
450#ifdef PDEBUG
451  p_Test(out,r);
452#endif
453
454  //  if ( out!=NULL ) pContent(out); // postponed to enterS
455  return(out);
456}
457
458
459/*2
460* reduction of p2 with p1
461* do not destroy p1, but p2
462* p1 divides p2 -> for use in NF algorithm
463* works in an integer fashion
464*/
465
466poly nc_rat_ReduceSpolyNew(const poly p1, poly p2, int ishift, const ring r)
467{
468  const long lCompP1 = p_GetComp(p1,r);
469  const long lCompP2 = p_GetComp(p2,r);
470
471  if ((lCompP1!=lCompP2) && (lCompP1!=0) && (lCompP2!=0))
472  {
473#ifdef PDEBUG
474    WerrorS("nc_rat_ReduceSpolyNew: different non-zero components!");
475#endif
476    return(NULL);
477  }
478
479  if (p_LmIsConstantRat(p1,r))
480  {
481    return( NULL );
482  }
483
484
485  int is = ishift; /* TODO */
486
487  poly m = pOne();
488  p_ExpVectorDiffRat(m, p2, p1, ishift, r); // includes X and D parts
489  //p_Setm(m,r);
490  //  m = p_GetExp_k_n(m,1,ishift,r); /* rat D-exp of m */
491#ifdef PDEBUG
492  p_Test(m,r);
493  PrintS("d^alpha = "); p_wrp(m,r); PrintLn();
494#endif
495
496  /* pSetComp(m,r)=0? */
497  poly HH = NULL;
498  poly H  = NULL;
499  HH = p_HeadRat(p1,is,r); //p_Copy(p_HeadRat(p1,is,r),r); // lm_D(g)
500//  H  = r->nc->p_Procs.mm_Mult_p(m, p_Copy(HH, r), r); // d^aplha lm_D(g)
501  H  = nc_mm_Mult_p(m, HH, r); // d^aplha lm_D(g) == h_g in the paper
502
503  poly K  = p_GetCoeffRat(H,  is, r); //p_Copy( p_GetCoeffRat(H,  is, r), r); // k in the paper
504  poly P  = p_GetCoeffRat(p2, is, r); //p_Copy( p_GetCoeffRat(p2, is, r), r); // lc_D(p_2) == lc_D(f)
505
506#ifdef PDEBUG
507  PrintS("k: "); p_wrp(K,r); PrintS("\n");
508  PrintS("p: "); p_wrp(P,r); PrintS("\n");
509  PrintS("f: "); p_wrp(p2,r); PrintS("\n");
510  PrintS("g: "); p_wrp(p1,r); PrintS("\n");
511#endif
512  // alt:
513  poly out = p_Copy(p1,r);
514  p_LmDeleteAndNextRat(&out, is, r); // out == t_g
515
516  ideal ncsyz = ncGCD(P,K,r);
517  poly KK = ncsyz->m[0]; ncsyz->m[0]=NULL; //p_Copy(ncsyz->m[0],r); // k'
518  poly PP = ncsyz->m[1]; ncsyz->m[1]= NULL; //p_Copy(ncsyz->m[1],r); // p'
519
520#ifdef PDEBUG
521  PrintS("t_g: "); p_wrp(out,r);
522  PrintS("k': "); p_wrp(KK,r); PrintS("\n");
523  PrintS("p': "); p_wrp(PP,r); PrintS("\n");
524#endif
525  id_Delete(&ncsyz,r);
526  p_LmDeleteAndNextRat(&p2, is, r); // t_f
527  p_LmDeleteAndNextRat(&H, is, r); // r_g = h_g - lt_D(h_g)
528
529#ifdef PDEBUG
530  PrintS(" t_f: "); p_wrp(p2,r);
531  PrintS(" r_g: "); p_wrp(H,r);
532#endif
533
534  p2 = p_Mult_q(KK, p2, r); // p2 = k' t_f
535
536#ifdef PDEBUG
537  p_Test(p2,r);
538  PrintS(" k' t_f: "); p_wrp(p2,r);
539#endif
540
541//  out = r->nc->p_Procs.mm_Mult_p(m, out, r); // d^aplha t_g
542  out = nc_mm_Mult_p(m, out, r); // d^aplha t_g
543  p_Delete(&m,r);
544
545#ifdef PDEBUG
546  PrintS(" d^a t_g: "); p_wrp(out,r);
547  PrintS(" end reduction\n");
548#endif
549
550  out = p_Add_q(H, out, r); // r_g + d^a t_g
551
552#ifdef PDEBUG
553  p_Test(out,r);
554#endif
555  out = p_Mult_q(PP, out, r); // p' (r_g + d^a t_g)
556  out = p_Add_q(p2,out,r); // delete out, p2; // the sum
557
558#ifdef PDEBUG
559  p_Test(out,r);
560#endif
561
562  //  if ( out!=NULL ) pContent(out); // postponed to enterS
563  return(out);
564}
565
566// return: FALSE, if there exists i in ishift..r->N,
567//                 such that a->exp[i] > b->exp[i]
568//         TRUE, otherwise
569
570BOOLEAN p_DivisibleByRat(poly a, poly b, int ishift, const ring r)
571{
572#ifdef PDEBUG
573  PrintS("invoke p_DivByRat with a = ");
574  p_wrp(p_Head(a,r),r);
575  PrintS(" and b= ");
576  p_wrp(p_Head(b,r),r);
577  PrintLn();
578#endif
579  int i;
580  for(i=r->N; i>ishift; i--)
581  {
582#ifdef PDEBUG
583    Print("i=%d,",i);
584#endif
585    if (p_GetExp(a,i,r) > p_GetExp(b,i,r)) return FALSE;
586  }
587  return ((p_GetComp(a,r)==p_GetComp(b,r)) || (p_GetComp(a,r)==0));
588}
589/*2
590*reduces h with elements from reducer choosing the best possible
591* element in t with respect to the given red_length
592* arrays reducer and red_length are [0..(rl-1)]
593*/
594int redRat (poly* h, poly *reducer, int *red_length, int rl, int ishift, ring r)
595{
596  if ((*h)==NULL) return 0;
597
598  int j,i,l;
599
600  loop
601  {
602    j=rl;l=MAX_INT_VAL;
603    for(i=rl-1;i>=0;i--)
604    {
605      //      Print("test %d, l=%d (curr=%d, l=%d\n",i,red_length[i],j,l);
606      if ((l>red_length[i]) && (p_DivisibleByRat(reducer[i],*h,ishift,r)))
607      {
608        j=i; l=red_length[i];
609        //        PrintS(" yes\n");
610      }
611      //      else PrintS(" no\n");
612    }
613    if (j >=rl)
614    {
615      return 1; // not reducible
616    }
617
618    if (TEST_OPT_DEBUG)
619    {
620      PrintS("reduce ");
621      p_wrp(*h,r);
622      PrintS(" with ");
623      p_wrp(reducer[j],r);
624    }
625    poly hh=nc_rat_ReduceSpolyNew(reducer[j], *h, ishift, r);
626    //    p_Delete(h,r);
627    *h=hh;
628    if (TEST_OPT_DEBUG)
629    {
630      PrintS(" to ");
631      p_wrp(*h,r);
632      PrintLn();
633    }
634    if ((*h)==NULL)
635    {
636      return 0;
637    }
638  }
639}
640
641// test if monomial is a constant, i.e. if all exponents and the component
642// is zero
643BOOLEAN p_LmIsConstantRat(const poly p, const ring r)
644{
645  if (p_LmIsConstantCompRat(p, r))
646    return (p_GetComp(p, r) == 0);
647  return FALSE;
648}
649
650// test if the monomial is a constant as a vector component
651// i.e., test if all exponents are zero
652BOOLEAN p_LmIsConstantCompRat(const poly p, const ring r)
653{
654  int i = r->real_var_end;
655
656  while ( (p_GetExp(p,i,r)==0) && (i>=r->real_var_start))
657  {
658    i--;
659  }
660  return ( i+1 == r->real_var_start );
661}
662
663#endif
Note: See TracBrowser for help on using the repository browser.