source: git/kernel/GBEngine/ratgring.cc @ 9f7665

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