source: git/Singular/p_Add_q__Template.cc @ a6a239

spielwiese
Last change on this file since a6a239 was a6a239, checked in by Olaf Bachmann <obachman@…>, 24 years ago
* new implementation of polys git-svn-id: file:///usr/local/Singular/svn/trunk@4580 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 2.0 KB
Line 
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 *  Version: $Id: p_Add_q__Template.cc,v 1.2 2000-09-12 16:01:05 obachman Exp $
10 *******************************************************************/
11
12/***************************************************************
13 *
14 * Returns:  p + q,
15 *           Shorter, where Shorter == Length(p) + Length(q) - Length(p+q);
16 * Destroys: p, q
17 *
18 ***************************************************************/
19poly p_Add_q(poly p, poly q, int &Shorter, const ring r)
20{
21  pTest(p);
22  pTest(q);
23#ifdef PDEBUG
24  int l = pLength(p) + pLength(q);
25#endif
26 
27  // test for trivial cases
28  Shorter = 0;
29  if (q == NULL) return p;
30  if (p == NULL) return q;
31 
32  number t, n1, n2;
33  int shorter = 0;
34  spolyrec rp;
35  poly a = &rp;
36  DECLARE_LENGTH(const unsigned long length = r->pCompLSize);
37  DECLARE_ORDSGN(const long* ordsgn = r->ordsgn);
38
39  Top:     // compare p and q w.r.t. monomial ordering
40  p_MemCmp(p->exp, q->exp, length, ordsgn, goto Equal, goto Greater , goto Smaller );
41
42  Equal:
43  n1 = pGetCoeff(p);
44  n2 = pGetCoeff(q);
45  t = p_nAdd(n1,n2, r);
46  p_nDelete(&n1, r);
47  p_nDelete(&n2, r);
48  FreeAndAdvance(q);
49 
50  if (p_nIsZero(t, r))
51  {
52    shorter += 2;
53    p_nDelete(&t, r);
54    FreeAndAdvance(p);
55  }
56  else
57  {
58    shorter++;
59    pSetCoeff0(p,t);
60    a = pNext(a) = p;
61    pIter(p);
62  }
63  if (p==NULL) { pNext(a) = q; goto Finish;}
64  if (q==NULL) { pNext(a) = p; goto Finish;}
65  goto Top;
66     
67  Greater:
68  a = pNext(a) = p;
69  pIter(p);
70  if (p==NULL) { pNext(a) = q; goto Finish;}
71  goto Top;
72   
73  Smaller:
74  a = pNext(a) = q;
75  pIter(q);
76  if (q==NULL) { pNext(a) = p; goto Finish;}
77  goto Top;
78 
79
80  Finish:
81  Shorter = shorter;
82
83  pTest(pNext(&rp));
84#ifdef PDEBUG 
85  assume(l - pLength(pNext(&rp)) == Shorter);
86#endif 
87  return pNext(&rp);
88}
89
Note: See TracBrowser for help on using the repository browser.