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

◆ p_Add_q__T()

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  n_InpAdd__T(n1,n2,r->cf);
45  t = n1;
46  n_Delete__T(&n2, r->cf);
47  q = p_LmFreeAndNext(q, r);
48 
49  if (n_IsZero__T(t, r->cf))
50  {
51  shorter += 2;
52  n_Delete__T(&t, r->cf);
53  p = p_LmFreeAndNext(p, r);
54  }
55  else
56  {
57  shorter++;
58  pSetCoeff0(p,t);
59  a = pNext(a) = p;
60  pIter(p);
61  }
62  if (p==NULL) { pNext(a) = q; goto Finish;}
63  if (q==NULL) { pNext(a) = p; goto Finish;}
64  goto Top;
65 
66  Greater:
67  a = pNext(a) = p;
68  pIter(p);
69  if (p==NULL) { pNext(a) = q; goto Finish;}
70  goto Top;
71 
72  Smaller:
73  a = pNext(a) = q;
74  pIter(q);
75  if (q==NULL) { pNext(a) = p; goto Finish;}
76  goto Top;
77 
78 
79  Finish:
80  Shorter = shorter;
81 
82  p_Test(pNext(&rp), r);
83 #if PDEBUG > 0
84  pAssume1(l - pLength(pNext(&rp)) == Shorter);
85 #endif
86  return pNext(&rp);
87 }
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:351
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 pIter(p)
Definition: monomials.h:44
const ring r
Definition: syzextra.cc:208
#define n_Delete__T(n, r)
Definition: p_polys.cc:4752
static poly p_LmFreeAndNext(poly p, ring)
Definition: p_polys.h:698
static unsigned pLength(poly a)
Definition: p_polys.h:189
#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