My Project
Loading...
Searching...
No Matches
p_Add_q__T.cc
Go to the documentation of this file.
1/****************************************
2* Computer Algebra System SINGULAR *
3****************************************/
4/***************************************************************
5 * File: p_Add_q__Template.cc
6 * Purpose: template for p_Add_q
7 * Author: obachman (Olaf Bachmann)
8 * Created: 8/00
9 *******************************************************************/
10
11/***************************************************************
12 *
13 * Returns: p + q,
14 * Shorter, where Shorter == Length(p) + Length(q) - Length(p+q);
15 * Destroys: p, q
16 *
17 ***************************************************************/
18LINKAGE poly p_Add_q__T(poly p, poly q, int &Shorter, const ring r)
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 assume(p!=NULL && q!=NULL);
26
27 Shorter = 0;
28
29 number t, n1, n2;
30 int shorter = 0;
31 spolyrec rp;
32 poly a = &rp;
33 DECLARE_LENGTH(const unsigned long length = r->CmpL_Size);
34 DECLARE_ORDSGN(const long* ordsgn = r->ordsgn);
35
36 Top: // compare p and q w.r.t. monomial ordering
37 p_MemCmp__T(p->exp, q->exp, length, ordsgn, goto Equal, goto Greater , goto Smaller);
38
39 Equal:
40 n1 = pGetCoeff(p);
41 n2 = pGetCoeff(q);
42 n_InpAdd__T(n1,n2,r->cf);
43 t = n1;
44 n_Delete__T(&n2, r->cf);
45 q = p_LmFreeAndNext(q, r);
46
47 if (n_IsZero__T(t, r->cf))
48 {
49 shorter += 2;
50 n_Delete__T(&t, r->cf);
51 p = p_LmFreeAndNext(p, r);
52 }
53 else
54 {
55 shorter++;
56 pSetCoeff0(p,t);
57 a = pNext(a) = p;
58 pIter(p);
59 }
60 if (p==NULL) { pNext(a) = q; goto Finish;}
61 if (q==NULL) { pNext(a) = p; goto Finish;}
62 goto Top;
63
64 Greater:
65 a = pNext(a) = p;
66 pIter(p);
67 if (p==NULL) { pNext(a) = q; goto Finish;}
68 goto Top;
69
70 Smaller:
71 a = pNext(a) = q;
72 pIter(q);
73 if (q==NULL) { pNext(a) = p; goto Finish;}
74 goto Top;
75
76
77 Finish:
78 Shorter = shorter;
79
80 p_Test(pNext(&rp), r);
81#if PDEBUG > 0
82 pAssume1(l - pLength(pNext(&rp)) == Shorter);
83#endif
84 return pNext(&rp);
85}
86
int l
Definition: cfEzgcd.cc:100
int p
Definition: cfModGcd.cc:4078
static BOOLEAN Equal(number a, number b, const coeffs)
Definition: flintcf_Q.cc:324
static bool Greater(mono_type m1, mono_type m2)
static BOOLEAN length(leftv result, leftv arg)
Definition: interval.cc:257
#define assume(x)
Definition: mod2.h:389
#define LINKAGE
Definition: mod2.h:140
#define pIter(p)
Definition: monomials.h:37
#define pNext(p)
Definition: monomials.h:36
#define pAssume1(cond)
Definition: monomials.h:171
#define pSetCoeff0(p, n)
Definition: monomials.h:59
static number & pGetCoeff(poly p)
return an alias to the leading coefficient of p assumes that p != NULL NOTE: not copy
Definition: monomials.h:44
#define NULL
Definition: omList.c:12
LINKAGE poly p_Add_q__T(poly p, poly q, int &Shorter, const ring r)
Definition: p_Add_q__T.cc:18
#define n_Delete__T(n, r)
Definition: p_polys.cc:4841
static int pLength(poly a)
Definition: p_polys.h:188
static poly p_LmFreeAndNext(poly p, ring)
Definition: p_polys.h:709
#define p_Test(p, r)
Definition: p_polys.h:159