Functions
p_Add_q__T.cc File Reference

Go to the source code of this file.

Functions

LINKAGE poly p_Add_q__T (poly p, poly q, int &Shorter, const ring r)
 

Function Documentation

LINKAGE poly p_Add_q__T ( poly  p,
poly  q,
int &  Shorter,
const ring  r 
)

Definition at line 18 of file p_Add_q__T.cc.

19 {
20  p_Test(p, r);
21  p_Test(q, r);
22 #if PDEBUG > 0
23  int l = pLength(p) + pLength(q);
24 #endif
25 
26  // test for trivial cases
27  Shorter = 0;
28  if (q == NULL) return p;
29  if (p == NULL) return q;
30 
31  number t, n1, n2;
32  int shorter = 0;
33  spolyrec rp;
34  poly a = &rp;
35  DECLARE_LENGTH(const unsigned long length = r->CmpL_Size);
36  DECLARE_ORDSGN(const long* ordsgn = r->ordsgn);
37 
38  Top: // compare p and q w.r.t. monomial ordering
39  p_MemCmp__T(p->exp, q->exp, length, ordsgn, goto Equal, goto Greater , goto Smaller);
40 
41  Equal:
42  n1 = pGetCoeff(p);
43  n2 = pGetCoeff(q);
44  #if 0
45  t = n_Add__T(n1,n2, r->cf);
46  n_Delete__T(&n1, r->cf);
47  #else
48  n_InpAdd__T(n1,n2,r->cf);
49  t = n1;
50  #endif
51  n_Delete__T(&n2, r->cf);
52  q = p_LmFreeAndNext(q, r);
53 
54  if (n_IsZero__T(t, r->cf))
55  {
56  shorter += 2;
57  n_Delete__T(&t, r->cf);
58  p = p_LmFreeAndNext(p, r);
59  }
60  else
61  {
62  shorter++;
63  pSetCoeff0(p,t);
64  a = pNext(a) = p;
65  pIter(p);
66  }
67  if (p==NULL) { pNext(a) = q; goto Finish;}
68  if (q==NULL) { pNext(a) = p; goto Finish;}
69  goto Top;
70 
71  Greater:
72  a = pNext(a) = p;
73  pIter(p);
74  if (p==NULL) { pNext(a) = q; goto Finish;}
75  goto Top;
76 
77  Smaller:
78  a = pNext(a) = q;
79  pIter(q);
80  if (q==NULL) { pNext(a) = p; goto Finish;}
81  goto Top;
82 
83 
84  Finish:
85  Shorter = shorter;
86 
87  p_Test(pNext(&rp), r);
88 #if PDEBUG > 0
89  pAssume1(l - pLength(pNext(&rp)) == Shorter);
90 #endif
91  return pNext(&rp);
92 }
const poly a
Definition: syzextra.cc:212
return P p
Definition: myNF.cc:203
static BOOLEAN Equal(number a, number b, const coeffs r)
Definition: flintcf_Q.cc:355
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
static int pLength(poly a)
Definition: p_polys.h:189
#define pIter(p)
Definition: monomials.h:44
const ring r
Definition: syzextra.cc:208
#define n_Delete__T(n, r)
Definition: p_polys.cc:4674
static poly p_LmFreeAndNext(poly p, ring)
Definition: p_polys.h:699
#define p_Test(p, r)
Definition: p_polys.h:160
static bool Greater(mono_type m1, mono_type m2)
#define NULL
Definition: omList.c:10
#define pNext(p)
Definition: monomials.h:43
#define pSetCoeff0(p, n)
Definition: monomials.h:67
polyrec * poly
Definition: hilb.h:10
#define pAssume1(cond)
Definition: monomials.h:179
int l
Definition: cfEzgcd.cc:94