1 | /**************************************** |
---|
2 | * Computer Algebra System SINGULAR * |
---|
3 | ****************************************/ |
---|
4 | /*************************************************************** |
---|
5 | * File: p_Merge_q__Template.cc |
---|
6 | * Purpose: template for p_Add_q |
---|
7 | * Author: obachman (Olaf Bachmann) |
---|
8 | * Created: 8/00 |
---|
9 | * Version: $Id: p_Merge_q__Template.cc,v 1.3 2000-12-07 15:03:58 obachman Exp $ |
---|
10 | *******************************************************************/ |
---|
11 | |
---|
12 | /*************************************************************** |
---|
13 | * |
---|
14 | * Returns: p merged with q |
---|
15 | * Destroys: p, q |
---|
16 | * |
---|
17 | ***************************************************************/ |
---|
18 | LINKAGE poly p_Merge_q(poly p, poly q, const ring r) |
---|
19 | { |
---|
20 | assume(p != NULL && q != NULL); |
---|
21 | p_Test(p, r); |
---|
22 | p_Test(q, r); |
---|
23 | #if PDEBUG > 0 |
---|
24 | int l = pLength(p) + pLength(q); |
---|
25 | #endif |
---|
26 | |
---|
27 | spolyrec rp; |
---|
28 | poly a = &rp; |
---|
29 | DECLARE_LENGTH(const unsigned long length = r->CmpL_Size); |
---|
30 | DECLARE_ORDSGN(const long* ordsgn = r->ordsgn); |
---|
31 | |
---|
32 | Top: // compare p and q w.r.t. monomial ordering |
---|
33 | p_MemCmp(p->exp, q->exp, length, ordsgn, goto Equal, goto Greater , goto Smaller); |
---|
34 | |
---|
35 | Equal: |
---|
36 | // should never get here |
---|
37 | dReportError("Equal monomials in p_Merge_q"); |
---|
38 | goto Finish; |
---|
39 | |
---|
40 | Greater: |
---|
41 | a = pNext(a) = p; |
---|
42 | pIter(p); |
---|
43 | if (p==NULL) { pNext(a) = q; goto Finish;} |
---|
44 | goto Top; |
---|
45 | |
---|
46 | Smaller: |
---|
47 | a = pNext(a) = q; |
---|
48 | pIter(q); |
---|
49 | if (q==NULL) { pNext(a) = p; goto Finish;} |
---|
50 | goto Top; |
---|
51 | |
---|
52 | Finish: |
---|
53 | |
---|
54 | p_Test(pNext(&rp), r); |
---|
55 | #if PDEBUG > 0 |
---|
56 | pAssume1(l - pLength(pNext(&rp)) == 0); |
---|
57 | #endif |
---|
58 | return pNext(&rp); |
---|
59 | } |
---|
60 | |
---|