source: git/kernel/kspoly.cc @ 7b8818

spielwiese
Last change on this file since 7b8818 was 2e4ec14, checked in by Yue Ren <ren@…>, 11 years ago
fix: -Wunused-parameter warnings
  • Property mode set to 100644
File size: 20.3 KB
Line 
1/****************************************
2*  Computer Algebra System SINGULAR     *
3****************************************/
4/*
5*  ABSTRACT -  Routines for Spoly creation and reductions
6*/
7
8// #define PDEBUG 2
9#include "config.h"
10#include <kernel/mod2.h>
11#include <misc/options.h>
12#include <kernel/kutil.h>
13#include <coeffs/numbers.h>
14#include <polys/monomials/p_polys.h>
15#include <polys/templates/p_Procs.h>
16#include <polys/nc/nc.h>
17#ifdef KDEBUG
18#include <kernel/febase.h>
19#endif
20#ifdef HAVE_RINGS
21#include <kernel/polys.h>
22#endif
23
24#ifdef KDEBUG
25int red_count = 0;
26int create_count = 0;
27// define this if reductions are reported on TEST_OPT_DEBUG
28#define TEST_OPT_DEBUG_RED
29#endif
30
31/***************************************************************
32 *
33 * Reduces PR with PW
34 * Assumes PR != NULL, PW != NULL, Lm(PW) divides Lm(PR)
35 *
36 ***************************************************************/
37int ksReducePoly(LObject* PR,
38                 TObject* PW,
39                 poly spNoether,
40                 number *coef,
41                 kStrategy strat)
42{
43#ifdef KDEBUG
44  red_count++;
45#ifdef TEST_OPT_DEBUG_RED
46  if (TEST_OPT_DEBUG)
47  {
48    Print("Red %d:", red_count); PR->wrp(); Print(" with:");
49    PW->wrp();
50  }
51#endif
52#endif
53  int ret = 0;
54  ring tailRing = PR->tailRing;
55  assume(kTest_L(PR));
56  assume(kTest_T(PW));
57
58  poly p1 = PR->GetLmTailRing();   // p2 | p1
59  poly p2 = PW->GetLmTailRing();   // i.e. will reduce p1 with p2; lm = LT(p1) / LM(p2)
60  poly t2 = pNext(p2), lm = p1;    // t2 = p2 - LT(p2); really compute P = LC(p2)*p1 - LT(p1)/LM(p2)*p2
61  assume(p1 != NULL && p2 != NULL);// Attention, we have rings and there LC(p2) and LC(p1) are special
62  p_CheckPolyRing(p1, tailRing);
63  p_CheckPolyRing(p2, tailRing);
64
65  pAssume1(p2 != NULL && p1 != NULL &&
66           p_DivisibleBy(p2,  p1, tailRing));
67
68  pAssume1(p_GetComp(p1, tailRing) == p_GetComp(p2, tailRing) ||
69           (p_GetComp(p2, tailRing) == 0 &&
70            p_MaxComp(pNext(p2),tailRing) == 0));
71
72#ifdef HAVE_PLURAL
73  if (rIsPluralRing(currRing))
74  {
75    // for the time being: we know currRing==strat->tailRing
76    // no exp-bound checking needed
77    // (only needed if exp-bound(tailring)<exp-b(currRing))
78    if (PR->bucket!=NULL)  nc_kBucketPolyRed(PR->bucket, p2,coef);
79    else 
80    {
81      poly _p = (PR->t_p != NULL ? PR->t_p : PR->p);
82      assume(_p != NULL);
83      nc_PolyPolyRed(_p, p2,coef, currRing);
84      if (PR->t_p!=NULL) PR->t_p=_p; else PR->p=_p;
85      PR->pLength=0; // usually not used, GetpLength re-computes it if needed
86    }
87    return 0;
88  }
89#endif
90
91  if (t2==NULL)           // Divisor is just one term, therefore it will
92  {                       // just cancel the leading term
93    PR->LmDeleteAndIter();
94    if (coef != NULL) *coef = n_Init(1, tailRing);
95    return 0;
96  }
97
98  p_ExpVectorSub(lm, p2, tailRing); // Calculate the Monomial we must multiply to p2
99
100  if (tailRing != currRing)
101  {
102    // check that reduction does not violate exp bound
103    while (PW->max != NULL && !p_LmExpVectorAddIsOk(lm, PW->max, tailRing))
104    {
105      // undo changes of lm
106      p_ExpVectorAdd(lm, p2, tailRing);
107      if (strat == NULL) return 2;
108      if (! kStratChangeTailRing(strat, PR, PW)) return -1;
109      tailRing = strat->tailRing;
110      p1 = PR->GetLmTailRing();
111      p2 = PW->GetLmTailRing();
112      t2 = pNext(p2);
113      lm = p1;
114      p_ExpVectorSub(lm, p2, tailRing);
115      ret = 1;
116    }
117  }
118
119  // take care of coef buisness
120  if (! n_IsOne(pGetCoeff(p2), tailRing))
121  {
122    number bn = pGetCoeff(lm);
123    number an = pGetCoeff(p2);
124    int ct = ksCheckCoeff(&an, &bn, tailRing->cf);    // Calculate special LC
125    p_SetCoeff(lm, bn, tailRing);
126    if ((ct == 0) || (ct == 2))
127      PR->Tail_Mult_nn(an);
128    if (coef != NULL) *coef = an;
129    else n_Delete(&an, tailRing);
130  }
131  else
132  {
133    if (coef != NULL) *coef = n_Init(1, tailRing);
134  }
135
136
137  // and finally,
138  PR->Tail_Minus_mm_Mult_qq(lm, t2, PW->GetpLength() - 1, spNoether);
139  assume(PW->GetpLength() == pLength(PW->p != NULL ? PW->p : PW->t_p));
140  PR->LmDeleteAndIter();
141
142  // the following is commented out: shrinking
143#ifdef HAVE_SHIFTBBA_NONEXISTENT
144  if ( (currRing->isLPring) && (!strat->homog) )
145  {
146    // assume? h->p in currRing
147    PR->GetP();
148    poly qq = p_Shrink(PR->p, currRing->isLPring, currRing);
149    PR->Clear(); // does the right things
150    PR->p = qq; 
151    PR->t_p = NULL;
152    PR->SetShortExpVector();
153  }
154#endif
155 
156#if defined(KDEBUG) && defined(TEST_OPT_DEBUG_RED)
157  if (TEST_OPT_DEBUG)
158  {
159    Print(" to: "); PR->wrp(); Print("\n");
160  }
161#endif
162  return ret;
163}
164
165/***************************************************************
166 *
167 * Reduces PR with PW
168 * Assumes PR != NULL, PW != NULL, Lm(PW) divides Lm(PR)
169 *
170 ***************************************************************/
171int ksReducePolySig(LObject* PR,
172                 TObject* PW,
173                 long /*idx*/,
174                 poly spNoether,
175                 number *coef,
176                 kStrategy strat)
177{
178#ifdef KDEBUG
179  red_count++;
180#ifdef TEST_OPT_DEBUG_RED
181  if (TEST_OPT_DEBUG)
182  {
183    Print("Red %d:", red_count); PR->wrp(); Print(" with:");
184    PW->wrp();
185  }
186#endif
187#endif
188  int ret = 0;
189  ring tailRing = PR->tailRing;
190  assume(kTest_L(PR));
191  assume(kTest_T(PW));
192
193  // signature-based stuff:
194  // checking for sig-safeness first
195  // NOTE: This has to be done in the current ring
196  //
197  /**********************************************
198   *
199   * TODO:
200   * --------------------------------------------
201   * if strat->incremental
202   * Since we are subdividing lower index and
203   * current index reductions it is enough to
204   * look at the polynomial part of the signature
205   * for a check. This should speed-up checking
206   * a lot!
207   * if !strat->incremental
208   * We are not subdividing lower and current index
209   * due to the fact that we are using the induced
210   * Schreyer order
211   *
212   * nevertheless, this different behaviour is
213   * taken care of by is_sigsafe
214   * => one reduction procedure can be used for
215   * both, the incremental and the non-incremental
216   * attempt!
217   * --------------------------------------------
218   *
219   *********************************************/
220  //printf("COMPARE IDX: %ld -- %ld\n",idx,strat->currIdx);
221  if (!PW->is_sigsafe)
222  {
223    poly f1 = p_Copy(PR->GetLmCurrRing(),currRing);
224    poly f2 = PW->GetLmCurrRing();
225    poly sigMult = pCopy(PW->sig);   // copy signature of reducer
226    p_ExpVectorSub(f1, f2, currRing); // Calculate the Monomial we must multiply to p2
227//#if 1
228#ifdef DEBUGF5
229    printf("IN KSREDUCEPOLYSIG: \n");
230    pWrite(pHead(f1));
231    pWrite(pHead(f2));
232    pWrite(sigMult);
233    printf("--------------\n");
234#endif
235    sigMult = pp_Mult_qq(f1,sigMult,currRing);
236//#if 1
237#ifdef DEBUGF5
238    printf("------------------- IN KSREDUCEPOLYSIG: --------------------\n");
239    pWrite(pHead(f1));
240    pWrite(pHead(f2));
241    pWrite(sigMult);
242    pWrite(PR->sig);
243    printf("--------------\n");
244#endif
245    int sigSafe = p_LmCmp(PR->sig,sigMult,currRing);
246    // now we can delete the copied polynomial data used for checking for
247    // sig-safeness of the reduction step
248//#if 1
249#ifdef DEBUGF5
250    printf("%d -- %d sig\n",sigSafe,PW->is_sigsafe);
251
252#endif
253    pDelete(&f1);
254    pDelete(&sigMult);
255    // go on with the computations only if the signature of p2 is greater than the
256    // signature of fm*p1
257    if(sigSafe != 1)
258    { 
259      PR->is_redundant = TRUE;
260      return 3;
261    }
262    PW->is_sigsafe  = TRUE;
263  }
264  PR->is_redundant = FALSE;
265  poly p1 = PR->GetLmTailRing();   // p2 | p1
266  poly p2 = PW->GetLmTailRing();   // i.e. will reduce p1 with p2; lm = LT(p1) / LM(p2)
267  poly t2 = pNext(p2), lm = p1;    // t2 = p2 - LT(p2); really compute P = LC(p2)*p1 - LT(p1)/LM(p2)*p2
268  assume(p1 != NULL && p2 != NULL);// Attention, we have rings and there LC(p2) and LC(p1) are special
269  p_CheckPolyRing(p1, tailRing);
270  p_CheckPolyRing(p2, tailRing);
271
272  pAssume1(p2 != NULL && p1 != NULL &&
273      p_DivisibleBy(p2,  p1, tailRing));
274
275  pAssume1(p_GetComp(p1, tailRing) == p_GetComp(p2, tailRing) ||
276      (p_GetComp(p2, tailRing) == 0 &&
277       p_MaxComp(pNext(p2),tailRing) == 0));
278
279#ifdef HAVE_PLURAL
280  if (rIsPluralRing(currRing))
281  {
282    // for the time being: we know currRing==strat->tailRing
283    // no exp-bound checking needed
284    // (only needed if exp-bound(tailring)<exp-b(currRing))
285    if (PR->bucket!=NULL)  nc_kBucketPolyRed(PR->bucket, p2,coef);
286    else 
287    {
288      poly _p = (PR->t_p != NULL ? PR->t_p : PR->p);
289      assume(_p != NULL);
290      nc_PolyPolyRed(_p, p2, coef, currRing);
291      if (PR->t_p!=NULL) PR->t_p=_p; else PR->p=_p;
292      PR->pLength=0; // usaully not used, GetpLength re-comoutes it if needed
293    }
294    return 0;
295  }
296#endif
297
298  if (t2==NULL)           // Divisor is just one term, therefore it will
299  {                       // just cancel the leading term
300    PR->LmDeleteAndIter();
301    if (coef != NULL) *coef = n_Init(1, tailRing);
302    return 0;
303  }
304
305  p_ExpVectorSub(lm, p2, tailRing); // Calculate the Monomial we must multiply to p2
306
307  if (tailRing != currRing)
308  {
309    // check that reduction does not violate exp bound
310    while (PW->max != NULL && !p_LmExpVectorAddIsOk(lm, PW->max, tailRing))
311    {
312      // undo changes of lm
313      p_ExpVectorAdd(lm, p2, tailRing);
314      if (strat == NULL) return 2;
315      if (! kStratChangeTailRing(strat, PR, PW)) return -1;
316      tailRing = strat->tailRing;
317      p1 = PR->GetLmTailRing();
318      p2 = PW->GetLmTailRing();
319      t2 = pNext(p2);
320      lm = p1;
321      p_ExpVectorSub(lm, p2, tailRing);
322      ret = 1;
323    }
324  }
325
326  // take care of coef buisness
327  if (! n_IsOne(pGetCoeff(p2), tailRing))
328  {
329    number bn = pGetCoeff(lm);
330    number an = pGetCoeff(p2);
331    int ct = ksCheckCoeff(&an, &bn, tailRing->cf);    // Calculate special LC
332    p_SetCoeff(lm, bn, tailRing);
333    if ((ct == 0) || (ct == 2))
334      PR->Tail_Mult_nn(an);
335    if (coef != NULL) *coef = an;
336    else n_Delete(&an, tailRing);
337  }
338  else
339  {
340    if (coef != NULL) *coef = n_Init(1, tailRing);
341  }
342
343
344  // and finally,
345  PR->Tail_Minus_mm_Mult_qq(lm, t2, PW->GetpLength() - 1, spNoether);
346  assume(PW->GetpLength() == pLength(PW->p != NULL ? PW->p : PW->t_p));
347  PR->LmDeleteAndIter();
348
349  // the following is commented out: shrinking
350#ifdef HAVE_SHIFTBBA_NONEXISTENT
351  if ( (currRing->isLPring) && (!strat->homog) )
352  {
353    // assume? h->p in currRing
354    PR->GetP();
355    poly qq = p_Shrink(PR->p, currRing->isLPring, currRing);
356    PR->Clear(); // does the right things
357    PR->p = qq; 
358    PR->t_p = NULL;
359    PR->SetShortExpVector();
360  }
361#endif
362
363#if defined(KDEBUG) && defined(TEST_OPT_DEBUG_RED)
364  if (TEST_OPT_DEBUG)
365  {
366    Print(" to: "); PR->wrp(); Print("\n");
367  }
368#endif
369  return ret;
370}
371
372/***************************************************************
373 *
374 * Creates S-Poly of p1 and p2
375 *
376 *
377 ***************************************************************/
378void ksCreateSpoly(LObject* Pair,   poly spNoether,
379                   int use_buckets, ring tailRing,
380                   poly m1, poly m2, TObject** R)
381{
382#ifdef KDEBUG
383  create_count++;
384#endif
385  assume(kTest_L(Pair));
386  poly p1 = Pair->p1;
387  poly p2 = Pair->p2;
388  Pair->tailRing = tailRing;
389
390  assume(p1 != NULL);
391  assume(p2 != NULL);
392  assume(tailRing != NULL);
393
394  poly a1 = pNext(p1), a2 = pNext(p2);
395  number lc1 = pGetCoeff(p1), lc2 = pGetCoeff(p2);
396  int co=0/*, ct = ksCheckCoeff(&lc1, &lc2, currRing->cf)*/; // gcd and zero divisors
397  (void) ksCheckCoeff(&lc1, &lc2, currRing->cf);
398
399  int l1=0, l2=0;
400
401  if (p_GetComp(p1, currRing)!=p_GetComp(p2, currRing))
402  {
403    if (p_GetComp(p1, currRing)==0)
404    {
405      co=1;
406      p_SetCompP(p1,p_GetComp(p2, currRing), currRing, tailRing);
407    }
408    else
409    {
410      co=2;
411      p_SetCompP(p2, p_GetComp(p1, currRing), currRing, tailRing);
412    }
413  }
414
415  // get m1 = LCM(LM(p1), LM(p2))/LM(p1)
416  //     m2 = LCM(LM(p1), LM(p2))/LM(p2)
417  if (m1 == NULL)
418    k_GetLeadTerms(p1, p2, currRing, m1, m2, tailRing);
419
420  pSetCoeff0(m1, lc2);
421  pSetCoeff0(m2, lc1);  // and now, m1 * LT(p1) == m2 * LT(p2)
422
423  if (R != NULL)
424  {
425    if (Pair->i_r1 == -1)
426    {
427      l1 = pLength(p1) - 1;
428    }
429    else
430    {
431      l1 = (R[Pair->i_r1])->GetpLength() - 1;
432    }
433    if (Pair->i_r2 == -1)
434    {
435      l2 = pLength(p2) - 1;
436    }
437    else
438    {
439      l2 = (R[Pair->i_r2])->GetpLength() - 1;
440    }
441  }
442
443  // get m2 * a2
444  if (spNoether != NULL)
445  {
446    l2 = -1;
447    a2 = tailRing->p_Procs->pp_Mult_mm_Noether(a2, m2, spNoether, l2, tailRing);
448    assume(l2 == pLength(a2));
449  }
450  else
451    a2 = tailRing->p_Procs->pp_Mult_mm(a2, m2, tailRing);
452#ifdef HAVE_RINGS
453  if (!(rField_is_Domain(currRing))) l2 = pLength(a2);
454#endif
455
456  Pair->SetLmTail(m2, a2, l2, use_buckets, tailRing);
457
458  // get m2*a2 - m1*a1
459  Pair->Tail_Minus_mm_Mult_qq(m1, a1, l1, spNoether);
460
461  // Clean-up time
462  Pair->LmDeleteAndIter();
463  p_LmDelete(m1, tailRing);
464
465  if (co != 0)
466  {
467    if (co==1)
468    {
469      p_SetCompP(p1,0, currRing, tailRing);
470    }
471    else
472    {
473      p_SetCompP(p2,0, currRing, tailRing);
474    }
475  }
476
477  // the following is commented out: shrinking
478#ifdef HAVE_SHIFTBBA_NONEXISTENT
479  if (currRing->isLPring)
480  {
481    // assume? h->p in currRing
482    Pair->GetP();
483    poly qq = p_Shrink(Pair->p, currRing->isLPring, currRing);
484    Pair->Clear(); // does the right things
485    Pair->p = qq; 
486    Pair->t_p = NULL;
487    Pair->SetShortExpVector();
488  }
489#endif
490
491}
492
493int ksReducePolyTail(LObject* PR, TObject* PW, poly Current, poly spNoether)
494{
495  BOOLEAN ret;
496  number coef;
497  poly Lp =     PR->GetLmCurrRing();
498  poly Save =   PW->GetLmCurrRing();
499
500  assume(kTest_L(PR));
501  assume(kTest_T(PW));
502  pAssume(pIsMonomOf(Lp, Current));
503
504  assume(Lp != NULL && Current != NULL && pNext(Current) != NULL);
505  assume(PR->bucket == NULL);
506
507  LObject Red(pNext(Current), PR->tailRing);
508  TObject With(PW, Lp == Save);
509
510  pAssume(!pHaveCommonMonoms(Red.p, With.p));
511  ret = ksReducePoly(&Red, &With, spNoether, &coef);
512
513  if (!ret)
514  {
515    if (! n_IsOne(coef, currRing))
516    {
517      pNext(Current) = NULL;
518      if (Current == PR->p && PR->t_p != NULL)
519        pNext(PR->t_p) = NULL;
520      PR->Mult_nn(coef);
521    }
522
523    n_Delete(&coef, currRing);
524    pNext(Current) = Red.GetLmTailRing();
525    if (Current == PR->p && PR->t_p != NULL)
526      pNext(PR->t_p) = pNext(Current);
527  }
528
529  if (Lp == Save)
530    With.Delete();
531
532  // the following is commented out: shrinking
533#ifdef HAVE_SHIFTBBA_NONEXISTENT
534  if (currRing->isLPring)
535  {
536    // assume? h->p in currRing
537    PR->GetP();
538    poly qq = p_Shrink(PR->p, currRing->isLPring, currRing);
539    PR->Clear(); // does the right things
540    PR->p = qq; 
541    PR->t_p = NULL;
542    PR->SetShortExpVector();
543  }
544#endif
545
546  return ret;
547}
548
549/***************************************************************
550 *
551 * Auxillary Routines
552 *
553 *
554 ***************************************************************/
555
556/*2
557* creates the leading term of the S-polynomial of p1 and p2
558* do not destroy p1 and p2
559* remarks:
560*   1. the coefficient is 0 (nNew)
561*   1. a) in the case of coefficient ring, the coefficient is calculated
562*   2. pNext is undefined
563*/
564//static void bbb() { int i=0; }
565poly ksCreateShortSpoly(poly p1, poly p2, ring tailRing)
566{
567  poly a1 = pNext(p1), a2 = pNext(p2);
568  long c1=p_GetComp(p1, currRing),c2=p_GetComp(p2, currRing);
569  long c;
570  poly m1,m2;
571  number t1 = NULL,t2 = NULL;
572  int cm,i;
573  BOOLEAN equal;
574
575#ifdef HAVE_RINGS
576  BOOLEAN is_Ring=rField_is_Ring(currRing);
577  number lc1 = pGetCoeff(p1), lc2 = pGetCoeff(p2);
578  if (is_Ring)
579  {
580    ksCheckCoeff(&lc1, &lc2, currRing->cf); // gcd and zero divisors
581    if (a1 != NULL) t2 = nMult(pGetCoeff(a1),lc2);
582    if (a2 != NULL) t1 = nMult(pGetCoeff(a2),lc1);
583    while (a1 != NULL && nIsZero(t2))
584    {
585      pIter(a1);
586      nDelete(&t2);
587      if (a1 != NULL) t2 = nMult(pGetCoeff(a1),lc2);
588    }
589    while (a2 != NULL && nIsZero(t1))
590    {
591      pIter(a2);
592      nDelete(&t1);
593      if (a2 != NULL) t1 = nMult(pGetCoeff(a2),lc1);
594    }
595  }
596#endif
597
598  if (a1==NULL)
599  {
600    if(a2!=NULL)
601    {
602      m2=p_Init(currRing);
603x2:
604      for (i = (currRing->N); i; i--)
605      {
606        c = p_GetExpDiff(p1, p2,i, currRing);
607        if (c>0)
608        {
609          p_SetExp(m2,i,(c+p_GetExp(a2,i,tailRing)),currRing);
610        }
611        else
612        {
613          p_SetExp(m2,i,p_GetExp(a2,i,tailRing),currRing);
614        }
615      }
616      if ((c1==c2)||(c2!=0))
617      {
618        p_SetComp(m2,p_GetComp(a2,tailRing), currRing);
619      }
620      else
621      {
622        p_SetComp(m2,c1,currRing);
623      }
624      p_Setm(m2, currRing);
625#ifdef HAVE_RINGS
626      if (is_Ring)
627      {
628          nDelete(&lc1);
629          nDelete(&lc2);
630          nDelete(&t2);
631          pSetCoeff0(m2, t1);
632      }
633      else
634#endif
635        nNew(&(pGetCoeff(m2)));
636      return m2;
637    }
638    else
639    {
640#ifdef HAVE_RINGS
641      if (is_Ring)
642      {
643        nDelete(&lc1);
644        nDelete(&lc2);
645        nDelete(&t1);
646        nDelete(&t2);
647      }
648#endif
649      return NULL;
650    }
651  }
652  if (a2==NULL)
653  {
654    m1=p_Init(currRing);
655x1:
656    for (i = (currRing->N); i; i--)
657    {
658      c = p_GetExpDiff(p2, p1,i,currRing);
659      if (c>0)
660      {
661        p_SetExp(m1,i,(c+p_GetExp(a1,i, tailRing)),currRing);
662      }
663      else
664      {
665        p_SetExp(m1,i,p_GetExp(a1,i, tailRing), currRing);
666      }
667    }
668    if ((c1==c2)||(c1!=0))
669    {
670      p_SetComp(m1,p_GetComp(a1,tailRing),currRing);
671    }
672    else
673    {
674      p_SetComp(m1,c2,currRing);
675    }
676    p_Setm(m1, currRing);
677#ifdef HAVE_RINGS
678    if (is_Ring)
679    {
680      pSetCoeff0(m1, t2);
681      nDelete(&lc1);
682      nDelete(&lc2);
683      nDelete(&t1);
684    }
685    else
686#endif
687      nNew(&(pGetCoeff(m1)));
688    return m1;
689  }
690  m1 = p_Init(currRing);
691  m2 = p_Init(currRing);
692  loop
693  {
694    for (i = (currRing->N); i; i--)
695    {
696      c = p_GetExpDiff(p1, p2,i,currRing);
697      if (c > 0)
698      {
699        p_SetExp(m2,i,(c+p_GetExp(a2,i,tailRing)), currRing);
700        p_SetExp(m1,i,p_GetExp(a1,i, tailRing), currRing);
701      }
702      else
703      {
704        p_SetExp(m1,i,(p_GetExp(a1,i,tailRing)-c), currRing);
705        p_SetExp(m2,i,p_GetExp(a2,i, tailRing), currRing);
706      }
707    }
708    if(c1==c2)
709    {
710      p_SetComp(m1,p_GetComp(a1, tailRing), currRing);
711      p_SetComp(m2,p_GetComp(a2, tailRing), currRing);
712    }
713    else
714    {
715      if(c1!=0)
716      {
717        p_SetComp(m1,p_GetComp(a1, tailRing), currRing);
718        p_SetComp(m2,c1, currRing);
719      }
720      else
721      {
722        p_SetComp(m2,p_GetComp(a2, tailRing), currRing);
723        p_SetComp(m1,c2, currRing);
724      }
725    }
726    p_Setm(m1,currRing);
727    p_Setm(m2,currRing);
728    cm = p_LmCmp(m1, m2,currRing);
729    if (cm!=0)
730    {
731      if(cm==1)
732      {
733        p_LmFree(m2,currRing);
734#ifdef HAVE_RINGS
735        if (is_Ring)
736        {
737          pSetCoeff0(m1, t2);
738          nDelete(&lc1);
739          nDelete(&lc2);
740          nDelete(&t1);
741        }
742        else
743#endif
744          nNew(&(pGetCoeff(m1)));
745        return m1;
746      }
747      else
748      {
749        p_LmFree(m1,currRing);
750#ifdef HAVE_RINGS
751        if (is_Ring)
752        {
753          pSetCoeff0(m2, t1);
754          nDelete(&lc1);
755          nDelete(&lc2);
756          nDelete(&t2);
757        }
758        else
759#endif
760          nNew(&(pGetCoeff(m2)));
761        return m2;
762      }
763    }
764#ifdef HAVE_RINGS
765    if (is_Ring)
766    {
767      equal = nEqual(t1,t2);
768    }
769    else
770#endif
771    {
772      t1 = nMult(pGetCoeff(a2),pGetCoeff(p1));
773      t2 = nMult(pGetCoeff(a1),pGetCoeff(p2));
774      equal = nEqual(t1,t2);
775      nDelete(&t2);
776      nDelete(&t1);
777    }
778    if (!equal)
779    {
780      p_LmFree(m2,currRing);
781#ifdef HAVE_RINGS
782      if (is_Ring)
783      {
784          pSetCoeff0(m1, nSub(t1, t2));
785          nDelete(&lc1);
786          nDelete(&lc2);
787          nDelete(&t1);
788          nDelete(&t2);
789      }
790      else
791#endif
792        nNew(&(pGetCoeff(m1)));
793      return m1;
794    }
795    pIter(a1);
796    pIter(a2);
797#ifdef HAVE_RINGS
798    if (is_Ring)
799    {
800      if (a2 != NULL)
801      {
802        nDelete(&t1);
803        t1 = nMult(pGetCoeff(a2),lc1);
804      }
805      if (a1 != NULL)
806      {
807        nDelete(&t2);
808        t2 = nMult(pGetCoeff(a1),lc2);
809      }
810      while ((a1 != NULL) && nIsZero(t2))
811      {
812        pIter(a1);
813        if (a1 != NULL)
814        {
815          nDelete(&t2);
816          t2 = nMult(pGetCoeff(a1),lc2);
817        }
818      }
819      while ((a2 != NULL) && nIsZero(t1))
820      {
821        pIter(a2);
822        if (a2 != NULL)
823        {
824          nDelete(&t1);
825          t1 = nMult(pGetCoeff(a2),lc1);
826        }
827      }
828    }
829#endif
830    if (a2==NULL)
831    {
832      p_LmFree(m2,currRing);
833      if (a1==NULL)
834      {
835#ifdef HAVE_RINGS
836        if (is_Ring)
837        {
838          nDelete(&lc1);
839          nDelete(&lc2);
840          nDelete(&t1);
841          nDelete(&t2);
842        }
843#endif
844        p_LmFree(m1,currRing);
845        return NULL;
846      }
847      goto x1;
848    }
849    if (a1==NULL)
850    {
851      p_LmFree(m1,currRing);
852      goto x2;
853    }
854  }
855}
Note: See TracBrowser for help on using the repository browser.